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 <iostream>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=120005;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll n,k,a[35005];
struct Item{
	ll min,add;
}s[maxn];
void build(int u,int L,int R){
	s[u].add=0;
	if(L==R){s[u].min=a[L];return;}
	int M=(L+R)/2;
	build(u*2,L,M);build(u*2+1,M+1,R);
	s[u].min=min(s[u*2].min,s[u*2+1].min);
}
void pushdown(int u,int L,int R){
	s[u].min+=s[u].add;
	if(L!=R){s[u*2].add+=s[u].add;s[u*2+1].add+=s[u].add;}
	s[u].add=0;
}
void update(int u,int L,int R,int ql,int qr,int v){
	if(ql<=L&&R<=qr){
		s[u].add+=v;
		pushdown(u,L,R);return;
	}int M=(L+R)/2;
	if(ql<=M)update(u*2,L,M,ql,qr,v);
	if(M<qr)update(u*2+1,M+1,R,ql,qr,v);
	pushdown(u*2,L,M);pushdown(u*2+1,M+1,R);
	s[u].min=min(s[u*2].min,s[u*2+1].min);
}
ll query(int u,int L,int R,int ql,int qr){
	if(s[u].add!=0)pushdown(u,L,R);
	if(ql<=L&&R<=qr)return s[u].min;
	int M=(L+R)/2;ll ans=inf;
	if(ql<=M)ans=min(ans,query(u*2,L,M,ql,qr));
	if(M<qr)ans=min(ans,query(u*2+1,M+1,R,ql,qr));
	return ans;
}

int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	map<int,int>mp;int last[n+5];
	for(int i=1;i<=n;i++){
		if(!mp.count(a[i]))last[i]=-1;
		else last[i]=mp[a[i]];
		mp[a[i]]=i;
	}ll d[k+5][n+5];
	d[1][1]=0;
	for(int j=2;j<=n;j++){
		d[1][j]=d[1][j-1];
		if(last[j]!=-1)d[1][j]+=j-last[j];
	}for(int i=2;i<=k;i++){
		for(int j=1;j<=n;j++)a[j]=d[i-1][j];
		build(1,1,n);
		for(int j=1;j<i;j++)d[i][j]=inf;
		d[i][i]=0;
		for(int j=i+1;j<=n;j++){
			if(last[j]!=-1&&i-1<=last[j]-1)
				update(1,1,n,i-1,last[j]-1,j-last[j]);
			d[i][j]=query(1,1,n,i-1,j-1);
		}
	}cout<<d[k][n]<<endl;
	return 0;
}