#include <bits/stdc++.h>
#define MOD 998244353
#define INF 1000000000
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
#define lz lazup(l, u, i);
#define mp(x, y) make_pair(x, y)
using namespace std;
const int N = 35005;
int seg[4*N], lazy[4*N];
const int MAX = 35000*35000;
void lazup(int l, int u, int i){
    if(lazy[i] == 0) return;
    seg[i] += lazy[i];
    if(l!=u){
        lazy[lchild(i)] += lazy[i];
        lazy[rchild(i)] += lazy[i];
    }
    lazy[i] = 0;
}
int update(int l, int u, int i, int ll, int uu, int x){
    lz
    if(l>=ll && u<=uu){
        lazy[i] += x;
        lz
        return seg[i];
    }
    if(l>uu || u<ll) return seg[i];
    return seg[i] = min(update(l, mid(l, u), lchild(i), ll, uu, x), update(mid(l, u)+1, u, rchild(i), ll, uu, x));
}
int query(int l, int u, int i, int ll, int uu){
    lz
    if(l>=ll && u<=uu) return seg[i];
    if(l>uu || u<ll) return MAX;
    return min(query(l, mid(l, u), lchild(i), ll, uu), query(mid(l, u)+1, u, rchild(i), ll, uu));
}
int reset(int l, int u, int i){
    lazy[i] = 0;
    if(l==u) return seg[i] = MAX;
    reset(l, mid(l, u), lchild(i));
    reset(mid(l, u)+1, u, rchild(i));
    return seg[i] = MAX;
}
signed main(){ //fast io
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin>>n>>k;
    int prev[n+1];
    int a[n+1];
    map<int, int> mp;
    int dp[n+1];
    dp[0] = 0;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        prev[i] = mp[a[i]];
        mp[a[i]] = i;
        dp[i] = dp[i-1];
        if(prev[i] > 0) dp[i] += (i - prev[i]);
    }
    int ans = dp[n];
    k--;
    while(k--){
        reset(1, n, 0);
        for(int i = 1;i<=n;i++){
            update(1, n, 0, i, i, dp[i-1] - MAX);
        }
        dp[1] = 0;
        for(int i = 2;i<=n;i++){
            if(prev[i] > 0) update(1, n, 0, 1, prev[i], i - prev[i]);
            dp[i] = query(1, n, 0, 1, i);
        }
        ans = dp[n];
    }
    cout<<ans<<'\n';
}
### Prompt

Create a solution in cpp for the following problem:

You are given an array a of n integers. Define the cost of some array t as follows:

$$$cost(t) = ∑_{x ∈ set(t) } last(x) - first(x),$$$ 

where set(t) is the set of all values in t without repetitions, first(x), and last(x) are the indices of the first and last occurrence of x in t, respectively. In other words, we compute the distance between the first and last occurrences for each distinct element and sum them up.

You need to split the array a into k consecutive segments such that each element of a belongs to exactly one segment and the sum of the cost of individual segments is minimum.

Input

The first line contains two integers n, k (1 ≤ n ≤ 35 000, 1 ≤ k ≤ min(n,100)).

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n).

Output

Output the minimum sum of the cost of individual segments.

Examples

Input


7 2
1 6 6 4 6 6 6


Output


3


Input


7 4
5 5 5 5 2 3 3


Output


1

Note

In the first example, we can divide the array into [1,6,6,4] and [6,6,6]. Cost of [1,6,6,4] will be (1-1) + (3 - 2) + (4-4) = 1 and cost of [6,6,6] will be 3-1 = 2. Total cost would be 1 + 2 = 3.

In the second example, divide the array into [5,5],[5],[5,2,3] and [3]. Total Cost would be 1 + 0 + 0 + 0 = 1.

### Response

```cpp
#include <bits/stdc++.h>
#define MOD 998244353
#define INF 1000000000
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
#define lz lazup(l, u, i);
#define mp(x, y) make_pair(x, y)
using namespace std;
const int N = 35005;
int seg[4*N], lazy[4*N];
const int MAX = 35000*35000;
void lazup(int l, int u, int i){
    if(lazy[i] == 0) return;
    seg[i] += lazy[i];
    if(l!=u){
        lazy[lchild(i)] += lazy[i];
        lazy[rchild(i)] += lazy[i];
    }
    lazy[i] = 0;
}
int update(int l, int u, int i, int ll, int uu, int x){
    lz
    if(l>=ll && u<=uu){
        lazy[i] += x;
        lz
        return seg[i];
    }
    if(l>uu || u<ll) return seg[i];
    return seg[i] = min(update(l, mid(l, u), lchild(i), ll, uu, x), update(mid(l, u)+1, u, rchild(i), ll, uu, x));
}
int query(int l, int u, int i, int ll, int uu){
    lz
    if(l>=ll && u<=uu) return seg[i];
    if(l>uu || u<ll) return MAX;
    return min(query(l, mid(l, u), lchild(i), ll, uu), query(mid(l, u)+1, u, rchild(i), ll, uu));
}
int reset(int l, int u, int i){
    lazy[i] = 0;
    if(l==u) return seg[i] = MAX;
    reset(l, mid(l, u), lchild(i));
    reset(mid(l, u)+1, u, rchild(i));
    return seg[i] = MAX;
}
signed main(){ //fast io
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin>>n>>k;
    int prev[n+1];
    int a[n+1];
    map<int, int> mp;
    int dp[n+1];
    dp[0] = 0;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        prev[i] = mp[a[i]];
        mp[a[i]] = i;
        dp[i] = dp[i-1];
        if(prev[i] > 0) dp[i] += (i - prev[i]);
    }
    int ans = dp[n];
    k--;
    while(k--){
        reset(1, n, 0);
        for(int i = 1;i<=n;i++){
            update(1, n, 0, i, i, dp[i-1] - MAX);
        }
        dp[1] = 0;
        for(int i = 2;i<=n;i++){
            if(prev[i] > 0) update(1, n, 0, 1, prev[i], i - prev[i]);
            dp[i] = query(1, n, 0, 1, i);
        }
        ans = dp[n];
    }
    cout<<ans<<'\n';
}
```