#include <bits/stdc++.h>   using namespace std;   struct ii {     int a, b;     bool operator<(ii o) const { return make_tuple(a, b) < make_tuple(o.a, o.b); }   };   struct iii {     int a, b, c;     bool operator<(iii o) const {       return make_tuple(a, b, c) < make_tuple(o.a, o.b, o.c);     }   };   int TC, N, M, K, Q, x, y, z;   int arr[35005], par[35005], now[35005], st[4 * 35005], lz[4 * 35005],       dp[55][35005];   void build(int p, int l, int r, int rem) {     if (l == r) {       st[p] = dp[rem][l];       lz[p] = 0;       return;     }     int m = (l + r) >> 1;     build(p << 1, l, m, rem);     build(p << 1 | 1, m + 1, r, rem);     st[p] = max(st[p << 1], st[p << 1 | 1]);     lz[p] = 0;   }   void update(int p, int l, int r, int b1, int b2, int v) {     if (lz[p]) {       st[p] += lz[p];       if (l < r) {         lz[p << 1] += lz[p];         lz[p << 1 | 1] += lz[p];       }       lz[p] = 0;     }     if (b1 <= l && r <= b2) {       st[p] += v;       if (l < r) {         lz[p << 1] += v;         lz[p << 1 | 1] += v;       }       return;     }     if (r < b1 || b2 < l) return;     int m = (l + r) >> 1;     update(p << 1, l, m, b1, b2, v);     update(p << 1 | 1, m + 1, r, b1, b2, v);     st[p] = max(st[p << 1], st[p << 1 | 1]);   }   int query(int p, int l, int r, int b1, int b2) {     if (lz[p]) {       st[p] += lz[p];       if (l < r) {         lz[p << 1] += lz[p];         lz[p << 1 | 1] += lz[p];       }       lz[p] = 0;     }     if (b1 <= l && r <= b2) {       return st[p];     }     if (r < b1 || b2 < l) return 0;     int m = (l + r) >> 1;     return max(query(p << 1, l, m, b1, b2), query(p << 1 | 1, m + 1, r, b1, b2));   }   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i <= N; i++) now[i] = N;     for (int i = 0; i < N; i++) scanf( %d , &arr[i]);     for (int i = N - 1; i >= 0; i--) {       par[i] = now[arr[i]];       now[arr[i]] = i;     }     for (int rem = 1; rem <= K; rem++) {       build(1, 0, N, rem - 1);       for (int pos = N; pos >= 0; pos--) {         if (pos == N) {           dp[rem][pos] = 0;         } else {           update(1, 0, N, pos + 1, par[pos], 1);           dp[rem][pos] = query(1, 0, N, pos + 1, N - rem + 1);         }       }     }     printf( %d n , dp[K][0]);     return 0;   }   