func_code_string: #include <bits/stdc++.h>   #define ff first   #define ss second   #define endl   n    using namespace std;   const long long INF = (long long) 1e18;   const int mod = (int) 1e9+7;   const int MAXN = (int) 3.5e4+5;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   ll n, lst[MAXN], nx[MAXN], pr[MAXN], a[MAXN];   set<ll> idx[MAXN];   ll dp[105][MAXN];   ll t[101][4*MAXN], lazy[101][4*MAXN];   int x;   void push(int v){       if(lazy[x][v] == 0)           return;       lazy[x][2*v] += lazy[x][v];       lazy[x][2*v + 1] += lazy[x][v];       t[x][2*v] += lazy[x][v];       t[x][2*v + 1] += lazy[x][v];       lazy[x][v] = 0;   }      void upd(int v, int tl, int tr, int l, int r, ll val){       if(l > r)           return;       if(tl == l && tr == r){           t[x][v] += val;           lazy[x][v] += val;       }else{           push(v);           int tm = (tl + tr) / 2;           upd(2*v, tl, tm, l, min(tm, r), val);           upd(2*v+1, tm + 1, tr, max(tm + 1, l), r, val);           t[x][v] = max(t[x][2*v], t[x][2*v + 1]);       }   }      ll que(int v, int tl, int tr, int l, int r){       if(l > r)           return -INF;       if(tl == l && tr == r)           return t[x][v];       else {           push(v);           int tm = (tl + tr) / 2;           return max(que(2*v, tl, tm, l, min(tm, r)), que(2*v+1, tm + 1, tr, max(tm + 1, l), r));       }   }   int main(){       ios_base::sync_with_stdio(false);       cin.tie(nullptr);cout.tie(nullptr);          #ifdef Local           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt , r ,stdin);           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt , w ,stdout);       #endif       ll k;       cin>>n>>k;       ll top = 0;       for(ll i = 1; i <= n; i++){           cin>>a[i];           if(lst[a[i]] != 0)               top += i - lst[a[i]];           pr[i] = lst[a[i]];           lst[a[i]] = i;       }       memset(lst, 0x7f, sizeof(lst));          for(int i = n; i >= 1; i--){           nx[i] = min(n + 1, lst[a[i]]);           lst[a[i]] = i;       }          memset(dp, 0xf7, sizeof(dp));       dp[0][0] = 0;       ll mx = 0;       for(int i = 1; i < k; i++){           x = i - 1;           ll cev = 0;           for(ll j = 1; j <= n; j++){               if(j != 1)                   if(pr[j - 1] != 0)                       upd(1, 0, n, pr[j - 1] + 1, j - 1, j - 1 - pr[j - 1]);               dp[i][j] = que(1, 0, n, 0, j - 1) + cev;               upd(1, 0, n, j, j, dp[i - 1][j] - cev);               //cerr<<dp[i][j]<<   ;               mx = max(mx, dp[i][j]);                  if(pr[j] != 0)                   cev -= j - pr[j];               if(nx[j] != n + 1)                   cev += nx[j] - j;           }       }          cout<<top - mx<<endl;             #ifdef Local           cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<<   milliseconds  ;       #endif   }