func_code_string: #include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int Max = 35010;   const ll INF  = 1e17 + 10;      bool sw; ll dp[2][Max];   int A[Max];      int L , R , F;   deque<int> dq[Max];      void moveto(int l , int r)   {    //cout <<  to   << l <<  ,  << r <<   n ;    while(L > l)    {     L--;     if(dq[A[L]].size() > 0) F += dq[A[L]].front();     dq[A[L]].push_front(L);     if(dq[A[L]].size() > 1) F -= dq[A[L]].front();    }    while(R < r)    {     R++;     if(dq[A[R]].size() > 0) F -= dq[A[R]].back();     dq[A[R]].push_back(R);     if(dq[A[R]].size() > 1) F += dq[A[R]].back();    }    while(R > r)    {     if(dq[A[R]].size() > 1) F -= dq[A[R]].back();     dq[A[R]].pop_back();     if(dq[A[R]].size() > 0) F += dq[A[R]].back();     R--;    }    while(L < l)    {     if(dq[A[L]].size() > 1) F += dq[A[L]].front();     dq[A[L]].pop_front();     if(dq[A[L]].size() > 0) F -= dq[A[L]].front();     L++;    }   }      void solve(int l , int r , int tl , int tr)   {    if(r < l) return;    int mid = (l + r) >> 1;    int opt = -1; ll ans = INF;    for(int i = min(tr , mid - 1) ; i >= tl ; i--)    {     //cout <<  res   << i + 1 <<  ,  << mid <<   =  ;     moveto(i + 1 , mid);     //cout << F <<   n ;     ll nans = F + dp[!sw][i];     if(nans <= ans) opt = i , ans = nans;    }    dp[sw][mid] = ans;       moveto(opt + 1 , mid);    solve(l , mid - 1 , tl , opt);    moveto(opt + 1 , mid);    solve(mid + 1 , r , opt , tr);   }   int main()   {    int n , k; cin >> n >> k;    for(int i = 1 ; i <= n ; i++) cin >> A[i];    //for(int i = 1 ; i <= n ; i++) dp[sw][i] = INF;       L = 1 , R = 1 , F = 0 , dq[A[1]].push_back(1);           for(int i = 1 ; i <= n ; i++)    {     moveto(1 , i);     dp[sw][i] = F;    }    //cout <<   n ;    for(int i = 1 ; i < k ; i++)    {     moveto(1 , n);     sw = !sw;     solve(1 , n , 0 , n - 1);     //for(int i = 1 ; i <= n ; i++) cout << dp[sw][i] <<    ; cout <<   n ;    }    cout << dp[sw][n] <<   n ;   }   