malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int cross(const complex<int>& a, const complex<int>& b) {     return a.real() * b.imag() - a.imag() * b.real();   }   int hypot2(const complex<int>& a) {     return a.real() * a.real() + a.imag() * a.imag();   }   int N;   vector<complex<int> > pt;   vector<complex<int> > hull(const vector<complex<int> >& p) {     int n = p.size(), k = 0;     if (n < 3) return p;     vector<complex<int> > h(2 * n);     for (int i = 0; i < n; ++i) {       while (k >= 2 && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k;       h[k++] = p[i];     }     for (int i = n - 2, e = k + 1; i >= 0; --i) {       while (k >= e && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k;       h[k++] = p[i];     }     h.resize(k);     h.pop_back();     return h;   }   bool with_one(const complex<int>& o, int m) {     vector<complex<int> > p;     copy_if(pt.begin(), pt.end(), back_inserter(p),             [&](const complex<int>& a) { return hypot2(a - o) >= m; });     auto h = hull(p);     switch (h.size()) {       case 0:       case 1:         return false;       case 2:         return hypot2(h[1] - h[0]) >= m;     }     int n = h.size();     auto nx = [&](int i) { return i + 1 == n ? 0 : i + 1; };     auto cal = [&](int i) { return h[nx(i)] - h[i]; };     for (int i = 0, j = 0; i < n; ++i) {       while (cross(cal(i), cal(j)) >= 0) {         j = nx(j);         if (hypot2(h[j] - h[i]) >= m) return true;       }     }     return false;   }   bool ok(int m) {     for (const complex<int>& p : pt) {       if (with_one(p, m)) return true;     }     return false;   }   int main() {     cout.precision(20);     cout << fixed;     cin >> N;     for (int i = 0, x, y; i < N; ++i) {       cin >> x >> y;       pt.push_back({x, y});     }     sort(pt.begin(), pt.end(), [](const complex<int>& a, const complex<int>& b) {       return a.real() < b.real() || a.real() == b.real() && a.imag() < b.imag();     });     int l = 0, h = 1e9;     while (l + 1 < h) {       int m = (l + h) / 2;       if (ok(m))         l = m;       else         h = m;     }     cout << sqrt(l) / 2 <<   n ;     return 0;   }
#include<bits/stdc++.h>   #define rb(a,b,c) for(int a=b;a<=c;++a)   #define rl(a,b,c) for(int a=b;a>=c;--a)   #define LL long long   #define IT iterator   #define PB push_back   #define II(a,b) make_pair(a,b)   #define FIR first   #define SEC second   #define FREO freopen( check.out , w ,stdout)   #define rep(a,b) for(int a=0;a<b;++a)   #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())   #define random(a) rng()%a   #define ALL(a) a.begin(),a.end()   #define POB pop_back   #define ff fflush(stdout)   #define fastio ios::sync_with_stdio(false)   #define check_min(a,b) a=min(a,b)   #define check_max(a,b) a=max(a,b)   using namespace std;   //inline int read(){   //    int x=0;   //    char ch=getchar();   //    while(ch< 0 ||ch> 9 ){   //        ch=getchar();   //    }   //    while(ch>= 0 &&ch<= 9 ){   //        x=(x<<1)+(x<<3)+(ch^48);   //        ch=getchar();   //    }   //    return x;   //}   const int INF=0x3f3f3f3f;   typedef pair<int,int> mp;   /*}   */   const int MAXN=505;   int t,n,a[MAXN<<1][MAXN];   bool era[MAXN<<1],cho[MAXN<<1];   int cnt[MAXN][MAXN];   int fa[MAXN<<1];   int root(int x){    return fa[x]=(x==fa[x]? x:root(fa[x]));   }   vector<int> g[MAXN<<1];   bool col[MAXN<<1];   bool vis[MAXN<<1];   void dfs(int now){    vis[now]=1;    for(auto it:g[now]){     if(!vis[it]){      col[it]=col[now]^1;      dfs(it);     }    }   }   void solve(){    scanf( %d ,&n);    rb(i,1,n*2) rb(j,1,n) scanf( %d ,&a[i][j]);    memset(era,0,sizeof(era));    memset(vis,0,sizeof(vis));    memset(cho,0,sizeof(cho));    memset(cnt,0,sizeof(cnt));    memset(col,0,sizeof(col));    rb(i,1,n*2) rb(j,1,n) cnt[j][a[i][j]]++;    rb(T,1,n){     mp Tmp=II(-1,-1);     rb(j,1,n){      rb(k,1,n) if(cnt[j][k]==1){       Tmp=II(j,k);       break;      }      if(Tmp.FIR!=-1) break;     }     if(Tmp.FIR==-1) break;     int x;     rb(j,1,2*n){      if(!era[j]&&a[j][Tmp.FIR]==Tmp.SEC){       x=j;       break;      }     }     cho[x]=1;     rb(j,1,2*n) if(!era[j]&&j!=x){      rb(k,1,n) if(j!=x&&a[j][k]==a[x][k]) era[j]=1;      if(era[j]){       rb(k,1,n) cnt[k][a[j][k]]--;      }     }     rb(k,1,n) cnt[k][a[x][k]]--;    }    rb(i,1,n*2) g[i].clear(),fa[i]=i;    rb(i,1,n*2) era[i]|=cho[i];    rb(i,1,n*2) if(!era[i]) rb(j,i+1,n*2) if(!era[j]) {     bool E=0;     rb(k,1,n) if(a[i][k]==a[j][k]){      E=1;      break;     }     if(E){      g[i].PB(j);      g[j].PB(i);      fa[root(i)]=root(j);     }    }    rb(i,1,n*2) if(!era[i]&&!vis[i]) dfs(i);    int ans=1;    vector<int> res;    rb(i,1,n*2){     if(!era[i]&&col[i]==0){      res.PB(i);     }    }    rb(i,1,n*2) if(!era[i]&&root(i)==i) ans=(ans+ans)%998244353;    rb(i,1,2*n) if(cho[i]) res.PB(i);    printf( %d n ,ans);    for(auto it:res){     printf( %d  ,it);    }    puts(  );   }   int main(){    scanf( %d ,&t);    while(t--) solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n];       long long int b[n];       int pos = 1;       for (int i = 0; i < n; ++i) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       reverse(b, b + n);       for (int i = 0; i < n; i++) {         if (b[i] != a[i]) {           pos = 0;           break;         }         if (i != 0 && b[i] == b[i - 1]) pos = 0;       }       if (!pos)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int a[2210], b[2210];   int cnt[2210];   long long func(void) {     int i, j = N;     int aans = -1, bans = -1, bid = -1;     long long best = (1ll << 60);     for (i = N - 1; i >= 0; i--) {       while (j > i || (j > 0 && cnt[j - 1] > 0)) {         j--;         if (b[j] > 0 && (bid == -1 || b[j] < b[bid])) bid = j;       }       if (a[i] > 0 && bid != -1 && a[i] + b[bid] < best) {         best = a[i] + b[bid];         aans = i;         bans = bid;       }     }     if (aans < bans) {       for (i = aans; i < bans; i++) cnt[i]++;     } else {       for (i = aans - 1; i >= bans; i--) cnt[i]--;     }     a[aans] = b[bans] = 0;     return best;   }   int main(void) {     int i;     cin >> N >> K;     for ((i) = 0; (i) < (int)(N); (i)++) cin >> a[i];     for ((i) = 0; (i) < (int)(N); (i)++) cin >> b[i];     long long ans = 0;     for ((i) = 0; (i) < (int)(K); (i)++) ans += func();     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 2;   const int mod = 998244353;   void inc(int& x, const int& y) { (x += y) >= mod ? x -= mod : 0; }   void dec(int& x, const int& y) { x < y ? x += mod - y : x -= y; }   void cmax(int& x, const int& y) { x = x > y ? x : y; }   int n, k, m;   int l[N], r[N], x[N], pos[N], a[N], f[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k >> m;     for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> x[i];     int ans = 1;     for (int p = 0; p <= k - 1; p++) {       for (int i = 1; i <= n + 1; i++) pos[i] = a[i] = 0;       for (int i = 1; i <= m; i++)         if (x[i] >> p & 1)           ++a[l[i]], --a[r[i] + 1];         else           cmax(pos[r[i] + 1], l[i]);       for (int i = 2; i <= n + 1; i++) a[i] += a[i - 1], cmax(pos[i], pos[i - 1]);       f[0] = 1;       int sum = 1, l = 0;       for (int i = 1; i <= n + 1; i++) {         while (l < pos[i]) dec(sum, f[l]), f[l++] = 0;         f[i] = a[i] ? 0 : sum, inc(sum, f[i]);       }       ans = 1ll * ans * f[n + 1] % mod;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Solution() {     int n, k;     cin >> n >> k;     int a[n];     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (5 - a[i] >= k) {         v.push_back(a[i]);       }     }     cout << v.size() / 3 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     Solution();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, x, y;   long long r;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long binsearch(long long i, long long j, long long w, long long m) {     if (i == j) {       if (i * w <= a && i * m <= b) return i;       return -1;     }     if (i == j - 1) {       if (j * w <= a && j * m <= b) return j;       if (i * w <= a && i * m <= b) return i;       return -1;     }     long long mid = (i + j) / 2;     if (mid * w <= a && mid * m <= b) return binsearch(mid, j, w, m);     return binsearch(i, mid - 1, w, m);   }   int main() {     cin >> a >> b >> x >> y;     r = x / y;     long long h = gcd(x, y);     long long k = binsearch(0, 2000000000, x / h, y / h);     if (k == -1) {       cout << 0 <<     << 0;       return 0;     }     cout << k * (x / h) <<     << k * (y / h);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   int n, k, l[1000002], r[1000002];   point a[1000002];   bool cmp(point a, point b) { return a.x < b.x; }   void nhap() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i].x;       l[i] = 0;       r[i] = 0;     }     for (int i = 1; i <= n; ++i) cin >> a[i].y;     sort(a + 1, a + n + 1, cmp);   }   void sol1() {     int cur = 1, st = 1;     l[1] = 1;     for (int i = 2; i <= n; ++i) {       if (a[i].x - a[st].x <= k)         cur++;       else {         while (a[i].x - a[st].x > k) {           ++st;         }         cur = i - st + 1;       }       l[i] = max(l[i - 1], cur);     }   }   void sol2() {     int cur = 1, st = n;     r[n] = 1;     for (int i = n - 1; i >= 1; --i) {       if (a[st].x - a[i].x <= k)         cur++;       else {         while (a[st].x - a[i].x > k) --st;         cur = st - i + 1;       }       r[i] = max(r[i + 1], cur);     }   }   void xuly() {     int kq = 0;     for (int i = 1; i < n; ++i) kq = max(kq, l[i] + r[i + 1]);     if (kq == 0) ++kq;     cout << kq <<   n ;   }   int main(int argc, const char* argv[]) {     int t;     cin >> t;     for (int i = 1; i <= t; ++i) {       nhap();       sol1();       sol2();       xuly();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   int n;   int a[N], b[N];   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       int p = 1;       for (int i = 1; i <= n; i += 2) {         b[i] = a[p++];       }       for (int i = 2; i <= n; i += 2) {         b[i] = a[p++];       }       bool flag = 1;       for (int i = 1; i <= n; i += 2) {         if (i < n) {           if (b[i] > b[i + 1]) flag = 0;         }         if (i > 1) {           if (b[i] > b[i - 1]) flag = 0;         }       }       if (!flag)         puts( Impossible );       else {         for (int i = 1; i <= n; ++i) printf( %d  , b[i]);         puts(  );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n, k, a[N];   long long seg[4 * N + 4], dp[N + 1][12];   void update(int p, int l, int r, int indx, long long val) {     if (l == r) {       seg[p] = val;       return;     }     int mid = l + (r - l) / 2;     if (indx <= mid)       update(p * 2, l, mid, indx, val);     else       update(p * 2 + 1, mid + 1, r, indx, val);     seg[p] = seg[p * 2] + seg[p * 2 + 1];   }   long long get(int p, int l, int r, int a, int b) {     if (l >= a && r <= b) {       return seg[p];     }     if (l > b || r < a) {       return 0;     }     int mid = l + (r - l) / 2;     return get(p * 2, l, mid, a, b) + get(p * 2 + 1, mid + 1, r, a, b);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int i = 0; i <= N; ++i) dp[i][1] = 1;     for (int j = 2; j <= k + 1; ++j) {       memset(seg, 0, sizeof seg);       for (int i = 0; i < n; ++i) {         dp[i][j] = get(1, 0, n - 1, 1, a[i] - 1);         update(1, 0, n - 1, a[i], dp[i][j - 1]);       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans += dp[i][k + 1];     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 61);   const int inf = (1 << 30);   const int nmax = 1e3 + 50;   const int mod = 1e9 + 7;   using namespace std;   int n, m, i, j, a[nmax][nmax], aa[nmax][nmax], b[nmax][nmax], bb[nmax][nmax],       ca[nmax][nmax], cb[nmax][nmax], mn;   char c[nmax][nmax];   vector<pair<pair<int, int>, int> > ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) cin >> c[i][j];     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++)         if (c[i][j] ==  * ) a[i][j] = a[i][j - 1] + 1;       for (j = m; j >= 1; j--)         if (c[i][j] ==  * ) aa[i][j] = aa[i][j + 1] + 1;     }     for (i = 1; i <= m; i++) {       for (j = 1; j <= n; j++)         if (c[j][i] ==  * ) b[j][i] = b[j - 1][i] + 1;       for (j = n; j >= 1; j--)         if (c[j][i] ==  * ) bb[j][i] = bb[j + 1][i] + 1;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (c[i][j] ==  * ) {           mn = min(min(a[i][j], aa[i][j]), min(b[i][j], bb[i][j]));           if (mn > 1) {             ca[i][j - mn + 1]++;             ca[i][j + mn]--;             cb[i - mn + 1][j]++;             cb[i + mn][j]--;             ans.push_back({{i, j}, mn - 1});           }         }       }     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) ca[i][j] += ca[i][j - 1];     for (i = 1; i <= m; i++)       for (j = 1; j <= n; j++) cb[j][i] += cb[j - 1][i];     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++)         if (c[i][j] ==  *  && !ca[i][j] && !cb[i][j])           return cout << -1 << endl, 0;     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++)       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class trio {    public:     long long first, second, third;   };   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     long long res = (x % m + m) % m;     return res;   }   long long power(long long x, long long y) {     long long ans = 1, second = x;     while (y) {       if (y & 1) {         ans *= second;         ans %= 1000000007;       }       second *= second;       second %= 1000000007;       y >>= 1;     }     return ans;   }   const long long N = 51;   long long dp1[N];   long long dp3[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     __int128 val = 1;     dp1[0] = 1;     dp1[1] = 1;     dp1[2] = 1;     for (long long i = 3; i < N; ++i) {       val *= (i - 2);       val = min(val, (__int128)1000000000000000001);       dp1[i] = val;     }     dp3[0] = 1;     dp3[1] = 1;     for (long long i = 2; i < N; ++i) {       val = 0;       for (long long j = 1; j < i + 1; ++j) {         val += (__int128)dp3[i - j] * dp1[j];         val = min(val, (__int128)1000000000000000001);       }       dp3[i] = val;     }     long long third;     cin >> third;     while (third--) {       long long n, k;       cin >> n >> k;       long long arr[N] = {0};       if (dp3[n] < k) {         cout << -1 <<   n ;         continue;       }       for (long long i = 1; i <= n;) {         long long len, left, st;         __int128 count;         for (long long j = i; j <= n; ++j) {           len = j - i + 1;           left = n - i - len + 1;           st = j;           count = (__int128)dp1[len] * dp3[left];           count = min(count, (__int128)1000000000000000001);           if (count < k) {             k -= (count);           } else {             break;           }         }         arr[i] = st;         set<long long> available;         for (long long j = i; j < i + len; ++j) {           available.insert(j);         }         available.erase(st);         for (long long j = i + 1; j < i + len; ++j) {           if (j == i + len - 1) {             arr[j] = *(available.begin());             break;           }           for (auto it : available) {             long long cur = it;             while (cur != j && cur) {               cur = arr[cur];             }             if (cur == j) continue;             count = (__int128)dp1[len - (j - i)] * dp3[left];             count = min(count, (__int128)1000000000000000001);             if (count < k) {               k -= (count);             } else {               arr[j] = it;               break;             }           }           available.erase(arr[j]);         }         i += len;       }       for (long long i = 1; i < n + 1; ++i) {         cout << arr[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   int cond = (long long)1;   void _main() {     int n, w, m;     scanf( %d%d%d , &n, &w, &m);     int guests = m;     int usedbottles = 0;     int botid = 1;     int fuel = m;     int used = 0;     bool ok = 1;     vector<vector<pair<int, int> > > sol;     for (int i = (0); i < (m); ++i) {       int needfuel = n;       vector<pair<int, int> > result;       while (needfuel > 0) {         if (fuel > 0) {           int use = min(fuel, needfuel);           result.push_back(pair<int, int>(botid, use));           fuel -= use;           needfuel -= use;           ++used;           if (used > 2) ok = 0;           if (fuel == 0) {             botid++;             fuel = m;             used = 0;           }         } else           assert(0);       }       sol.push_back(result);     }     if (!ok) cout <<  NO  << endl;     cout.precision(6);     if (ok) {       cout <<  YES  << endl;       for (int i = (0); i < (m); ++i) {         for (int j = (0); j < ((int)(sol[i]).size()); ++j) {           if (j) cout <<    ;           long double myfuel = (long double)sol[i][j].second * w / m;           cout << fixed << sol[i][j].first <<     << myfuel;         }         cout << endl;       }     }   }   int main(int argc, char **argv) {     string p =  ../gcj/source/  + string(  ) + argv[0][strlen(argv[0]) - 1];     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  1n ) == 0) {         freopen( 1.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  2n ) == 0) {         freopen( 2.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  3n ) == 0) {         freopen( 3.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  4n ) == 0) {         freopen( 4.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  5n ) == 0) {         freopen( 5.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s0 ) == 0) {         freopen((p +  -small-0.in ).c_str(),  r , stdin);         freopen((p +  -small-0.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s1 ) == 0) {         freopen((p +  -small-1.in ).c_str(),  r , stdin);         freopen((p +  -small-1.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s2 ) == 0) {         freopen((p +  -small-2.in ).c_str(),  r , stdin);         freopen((p +  -small-2.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  l0 ) == 0) {         freopen((p +  -large-0.in ).c_str(),  r , stdin);         freopen((p +  -large-0.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  q ) == 0) cond = 1 << 30;     _main();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x;   int a[255];   long long dp[255][255][255];   int main() {     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= k; j++) {         for (int p = 0; p <= x; p++) {           dp[i][j][p] = -LLONG_MAX;         }       }     dp[0][1][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 1; j <= k; j++)         for (int choose = 0; choose <= x; choose++) {           if (dp[i][j][choose] == -LLONG_MAX) continue;           if (j != k) {             dp[i + 1][j + 1][choose] =                 max(dp[i + 1][j + 1][choose], dp[i][j][choose]);           }           dp[i + 1][1][choose + 1] =               max(dp[i + 1][1][choose + 1], dp[i][j][choose] + a[i]);         }     }     long long res = -LLONG_MAX;     for (int i = 0; i <= k; i++) res = max(res, dp[n][i][x]);     if (res == -LLONG_MAX) res = -1;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 11, mod = 998244353;   int ans, n, k, blo, bel[N], f[N], g[N], a[N], L[N], R[N], las[N], bef[N],       lim[N], sum[411][N], Sum[411];   inline void inc(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void deal(int l, int r, int x) {     int o = bel[l];     for (register int i = l; i <= r; ++i) {       if (f[i] <= lim[o]) inc(Sum[o], mod - g[i - 1]);       inc(sum[o][f[i]], mod - g[i - 1]);       f[i] += x;       inc(sum[o][f[i]], g[i - 1]);       if (f[i] <= lim[o]) inc(Sum[o], g[i - 1]);     }   }   inline void modify(int l, int r, int x) {     int o;     if (bel[l] == bel[r]) {       deal(l, r, x);       return;     }     o = bel[l];     deal(l, R[o], x);     o = bel[r];     deal(L[o], r, x);     for (register int i = bel[l] + 1; i <= bel[r] - 1; ++i) {       if (x == 1) inc(Sum[i], mod - sum[i][lim[i]]);       lim[i] -= x;       if (x == -1) inc(Sum[i], sum[i][lim[i]]);     }   }   int main() {     scanf( %d%d , &n, &k);     blo = sqrt(n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , a + i), bel[i] = (i - 1) / blo + 1;       las[i] = bef[a[i]];       bef[a[i]] = i;     }     for (register int i = 1; i <= n; ++i) {       if (!L[bel[i]]) L[bel[i]] = i;       R[bel[i]] = i;     }     for (register int i = 1; i <= bel[n]; ++i) lim[i] = k;     g[0] = 1;     for (register int i = 1; i <= n; ++i) {       inc(sum[bel[i]][0], g[i - 1]), inc(Sum[bel[i]], g[i - 1]);       modify(las[i] + 1, i, 1);       if (las[i]) modify(las[las[i]] + 1, las[i], -1);       ans = 0;       for (register int j = 1; j <= bel[i]; ++j) inc(ans, Sum[j]);       g[i] = ans;     }     printf( %d n , g[n]);     return 0;   }