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.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs rt<<1|1
#define LL long long
#define PI acos(-1.0)
#define eps 1e-8
#define Pair pair<double,double>
// notice
#define mod 1000000007
#define MAXN 1e18
#define MS 35009
 
LL n,m;
LL a[MS];
LL tpos[MS];
LL pre[MS];
LL la[MS<<2];
LL p[MS<<2];
LL dp[109][MS];

void build(int l,int r,int rt){
	p[rt] = la[rt] = 0;
	if(l == r) return;
	int m = l+r>>1;
	build(l,m,ls);
	build(m+1,r,rs);
}

void push_up(int rt){
	p[rt] = min(p[ls],p[rs]);
}

void push_down(int rt){
	if(la[rt]){
		p[ls] += la[rt];
		p[rs] += la[rt];
		la[ls] += la[rt];
		la[rs] += la[rt];
		la[rt] = 0;
	}
}

void update(int L,int R,int l,int r,int rt,LL val){
	if(L <= l && r <= R){
		p[rt] += val;
		la[rt] += val;
		return;
	}
	push_down(rt);
	int m = l+r>>1;
	if(m >= L) update(L,R,l,m,ls,val);
	if(m <  R) update(L,R,m+1,r,rs,val);
	push_up(rt);
}

LL query(int L,int R,int l,int r,int rt){
	if(L <= l && r <= R){
		return p[rt];
	}
	push_down(rt);
	int m = l+r>>1;
	LL ans = MAXN;
	if(m >= L) ans = min(ans,query(L,R,l,m,ls));
	if(m <  R) ans = min(ans,query(L,R,m+1,r,rs));
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		pre[i] = tpos[a[i]];
		tpos[a[i]] = i;
	}
	for(int i=1;i<=m;i++){
		build(0,n,1);
		for(int j=1;j<=n;j++){
			update(j,j,0,n,1,dp[i-1][j]);
		}
		for(int j=1;j<=n;j++){
			if(pre[j]) update(0,pre[j]-1,0,n,1,j-pre[j]);
			if(i == 1) dp[i][j] = query(0,0,0,n,1);
			else dp[i][j] = query(0,j-1,0,n,1);
		}
		
//		cout << "==== " << i << " ====\n";
//		for(int j=1;j<=n;j++){
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
		
	}
	cout << dp[m][n] << "\n";

	return 0;
}