#include<bits/stdc++.h>
using namespace std;
#define MAXN 35005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
#define lson (rt<<1)
#define rson (rt<<1|1)
typedef long long LL;
typedef unsigned long long uLL;
const LL INF=0x7f7f7f7f7f7f;
const LL jzm=2333;
const int zero=2;
const int mo=1e9+7;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,k,a[MAXN],head[MAXN];
struct node{
	LL sum;int times;
	friend bool operator < (const node &x,const node &y){
		if(x.sum==y.sum)return x.times<y.times;
		return x.sum<y.sum;
	}
}dp[MAXN];
class SegmentTree{
	private:
		node tr[MAXN<<2];int lzy[MAXN<<2];
	public:
		void build(int rt,int l,int r){
			tr[rt]=(node){INF,0};lzy[rt]=0;
			if(l==r)return ;int mid=l+r>>1;
			build(lson,l,mid);build(rson,mid+1,r);
		}
		void pushdown(int rt){
			if(lzy[rt]){
				lzy[lson]+=lzy[rt];tr[lson].sum+=1ll*lzy[rt];
				lzy[rson]+=lzy[rt];tr[rson].sum+=1ll*lzy[rt];
				lzy[rt]=0;
			}
		}
		void insert(int rt,int l,int r,int ai,node aw){
			if(l>ai||r<ai||l>r)return ;int mid=l+r>>1;
			if(l==r){tr[rt]=aw;return ;}pushdown(rt);
			if(ai<=mid)insert(lson,l,mid,ai,aw);
			if(ai>mid)insert(rson,mid+1,r,ai,aw);
			tr[rt]=min(tr[lson],tr[rson]);
		}
		void modify(int rt,int l,int r,int al,int ar,int aw){
			if(l>ar||r<al||l>r||al>ar)return ;int mid=l+r>>1;
			if(al<=l&&r<=ar){tr[rt].sum+=1ll*aw;lzy[rt]+=aw;return ;}pushdown(rt);
			if(al<=mid)modify(lson,l,mid,al,ar,aw);
			if(ar>mid)modify(rson,mid+1,r,al,ar,aw);
			tr[rt]=min(tr[lson],tr[rson]);
		}
		node Query(){return tr[1];}
}T;
bool sakura(int mid){
	T.build(1,0,n);dp[0]=(node){0,0};T.insert(1,0,n,0,dp[0]);
	for(int i=1;i<=n;i++)dp[i]=(node){INF,0},head[i]=0;
	for(int i=1;i<=n;i++){
		T.modify(1,0,n,0,head[a[i]]-1,-head[a[i]]);
		T.modify(1,0,n,0,head[a[i]]-1,i);head[a[i]]=i;
		dp[i]=T.Query();dp[i].times++;dp[i].sum+=1ll*mid;
		T.insert(1,0,n,i,dp[i]);
		//printf("%d %d:%lld %d\n",mid,i,dp[i].sum,dp[i].times);
	}
	return dp[n].times<=k;
}
signed main(){
	read(n);read(k);for(int i=1;i<=n;i++)read(a[i]);
	int l=-1e9,r=1e9;while(l<r){int mid=l+r>>1;if(sakura(mid))r=mid;else l=mid+1;}
	sakura(l);printf("%lld\n",dp[n].sum-1ll*k*l);
	return 0;
}
/*

*/

### Prompt

In CPP, your task is to solve 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>
using namespace std;
#define MAXN 35005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
#define lson (rt<<1)
#define rson (rt<<1|1)
typedef long long LL;
typedef unsigned long long uLL;
const LL INF=0x7f7f7f7f7f7f;
const LL jzm=2333;
const int zero=2;
const int mo=1e9+7;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,k,a[MAXN],head[MAXN];
struct node{
	LL sum;int times;
	friend bool operator < (const node &x,const node &y){
		if(x.sum==y.sum)return x.times<y.times;
		return x.sum<y.sum;
	}
}dp[MAXN];
class SegmentTree{
	private:
		node tr[MAXN<<2];int lzy[MAXN<<2];
	public:
		void build(int rt,int l,int r){
			tr[rt]=(node){INF,0};lzy[rt]=0;
			if(l==r)return ;int mid=l+r>>1;
			build(lson,l,mid);build(rson,mid+1,r);
		}
		void pushdown(int rt){
			if(lzy[rt]){
				lzy[lson]+=lzy[rt];tr[lson].sum+=1ll*lzy[rt];
				lzy[rson]+=lzy[rt];tr[rson].sum+=1ll*lzy[rt];
				lzy[rt]=0;
			}
		}
		void insert(int rt,int l,int r,int ai,node aw){
			if(l>ai||r<ai||l>r)return ;int mid=l+r>>1;
			if(l==r){tr[rt]=aw;return ;}pushdown(rt);
			if(ai<=mid)insert(lson,l,mid,ai,aw);
			if(ai>mid)insert(rson,mid+1,r,ai,aw);
			tr[rt]=min(tr[lson],tr[rson]);
		}
		void modify(int rt,int l,int r,int al,int ar,int aw){
			if(l>ar||r<al||l>r||al>ar)return ;int mid=l+r>>1;
			if(al<=l&&r<=ar){tr[rt].sum+=1ll*aw;lzy[rt]+=aw;return ;}pushdown(rt);
			if(al<=mid)modify(lson,l,mid,al,ar,aw);
			if(ar>mid)modify(rson,mid+1,r,al,ar,aw);
			tr[rt]=min(tr[lson],tr[rson]);
		}
		node Query(){return tr[1];}
}T;
bool sakura(int mid){
	T.build(1,0,n);dp[0]=(node){0,0};T.insert(1,0,n,0,dp[0]);
	for(int i=1;i<=n;i++)dp[i]=(node){INF,0},head[i]=0;
	for(int i=1;i<=n;i++){
		T.modify(1,0,n,0,head[a[i]]-1,-head[a[i]]);
		T.modify(1,0,n,0,head[a[i]]-1,i);head[a[i]]=i;
		dp[i]=T.Query();dp[i].times++;dp[i].sum+=1ll*mid;
		T.insert(1,0,n,i,dp[i]);
		//printf("%d %d:%lld %d\n",mid,i,dp[i].sum,dp[i].times);
	}
	return dp[n].times<=k;
}
signed main(){
	read(n);read(k);for(int i=1;i<=n;i++)read(a[i]);
	int l=-1e9,r=1e9;while(l<r){int mid=l+r>>1;if(sakura(mid))r=mid;else l=mid+1;}
	sakura(l);printf("%lld\n",dp[n].sum-1ll*k*l);
	return 0;
}
/*

*/

```