malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long calWhite(long long x1, long long y1, long long x2, long long y2) {     if (x1 == 0 || y1 == 0 || x2 == 0 || y2 == 0) {       return 0;     }     long long tmp = (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1);     long long res = tmp / 2;     if (tmp % 2 == 1 && (x1 * y1 % 2 == 1 || (x1 % 2 == 0 && y1 % 2 == 0))) {       res++;     }     return res;   }   long long calBlack(long long x1, long long y1, long long x2, long long y2) {     if (x1 == 0 || y1 == 0 || x2 == 0 || y2 == 0) {       return 0;     }     return (x2 - x1 + 1) * (y2 - y1 + 1) - calWhite(x1, y1, x2, y2);   }   int main() {     long long t;     scanf( %I64d , &t);     while (t--) {       long long n, m;       long long x1, x2, y1, y2;       long long x3, x4, y3, y4;       scanf( %I64d%I64d , &n, &m);       scanf( %I64d%I64d%I64d%I64d , &x1, &y1, &x2, &y2);       scanf( %I64d%I64d%I64d%I64d , &x3, &y3, &x4, &y4);       long long answ = calWhite(1, 1, n, m);       answ += calBlack(x1, y1, x2, y2);       answ -= calWhite(x3, y3, x4, y4);       long long x5, y5, x6, y6;       if (x1 <= x3 && x3 <= x2) {         x5 = x3;         x6 = min(x2, x4);       } else if (x1 <= x4 && x4 <= x2) {         x5 = max(x1, x3);         x6 = x4;       } else if (x3 <= x1 && x2 <= x4) {         x5 = x1;         x6 = x2;       } else {         x5 = x6 = 0;       }       if (y1 <= y3 && y3 <= y2) {         y5 = y3;         y6 = min(y2, y4);       } else if (y1 <= y4 && y4 <= y2) {         y5 = max(y1, y3);         y6 = y4;       } else if (y3 <= y1 && y2 <= y4) {         y5 = y1;         y6 = y2;       } else {         y5 = y6 = 0;       }       answ -= calBlack(x5, y5, x6, y6);       printf( %I64d %I64d n , answ, n * m - answ);     }   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1000000007;   const int N = 1010000;   int fail[N];   int go[N][26], len[N], diff[N], anc[N], lst;   int n;   char str[N];   int p;   int s[N];   int f[N], g[N];   void addChar(int c, int ww) {     int x = lst;     while (s[ww] != s[ww - len[x] - 1]) {       x = fail[x];     }     if (!go[x][c]) {       len[p] = len[x] + 2;       int k = fail[x];       while (s[ww] != s[ww - len[k] - 1]) k = fail[k];       fail[p] = go[k][c];       go[x][c] = p;       diff[p] = len[p] - len[fail[p]];       if (diff[p] == diff[fail[p]])         anc[p] = anc[fail[p]];       else         anc[p] = fail[p];       p++;     }     lst = go[x][c];   }   void init() {     p = 2;     len[0] = 0;     len[1] = -1;     fail[0] = 1;     fail[1] = 0;     f[0] = 1;     lst = 1;   }   int main() {     scanf( %s , str + 1);     n = strlen(str + 1);     if (n & 1) {       printf( 0 n );       return 0;     }     for (int i = (int)1; i <= (int)n / 2; i++) {       s[i * 2 - 1] = str[i] -  a ;       s[i * 2] = str[n + 1 - i] -  a ;     }     s[0] = -1;     init();     for (int i = (int)1; i <= (int)n; i++) {       addChar(s[i], i);       for (int x = lst; x; x = anc[x]) {         g[x] = f[i - (len[anc[x]] + diff[x])];         if (anc[x] != fail[x]) {           g[x] = (g[x] + g[fail[x]]) % P;         }         if (i % 2 == 0) f[i] = (f[i] + g[x]) % P;       }     }     printf( %d n , f[n]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, c = 0;     char s[500];     scanf( %d %s , &n, s);     for (i = 0; i < n - 1; i++) {       if (((s[i] ==  R ) && (s[i + 1] ==  U )) ||           ((s[i] ==  U ) && (s[i + 1] ==  R ))) {         c++;         i++;       }     }     printf( %d n , n - c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 250000;   int n, dfn[N], size[N], cnt, Q;   struct node {     int tag, sum;   } t[N << 2];   vector<int> V[N];   void dfs(int x) {     dfn[x] = ++cnt;     size[x] = 1;     for (int i = 0, s = V[x].size(); i < s; i++)       dfs(V[x][i]), size[x] += size[V[x][i]];   }   void pushdown(int i, int l, int r) {     if (!t[i].tag) return;     int mid = (l + r) >> 1, ls = i << 1, rs = ls | 1;     t[ls].tag ^= 1;     t[rs].tag ^= 1;     t[ls].sum = (mid - l + 1 - t[ls].sum);     t[rs].sum = (r - mid - t[rs].sum);     t[i].tag = 0;   }   void update(int i, int l, int r, int x, int y) {     if (l >= x && r <= y) {       t[i].tag ^= 1;       t[i].sum = (r - l + 1 - t[i].sum);       return;     }     pushdown(i, l, r);     int mid = (l + r) >> 1;     if (mid >= x) update(i << 1, l, mid, x, y);     if (mid < y) update(i << 1 | 1, mid + 1, r, x, y);     t[i].sum = t[i << 1].sum + t[i << 1 | 1].sum;   }   int query(int i, int l, int r, int x, int y) {     if (l >= x && r <= y) return t[i].sum;     pushdown(i, l, r);     int mid = (l + r) >> 1, ans = 0;     if (mid >= x) ans += query(i << 1, l, mid, x, y);     if (mid < y) ans += query(i << 1 | 1, mid + 1, r, x, y);     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int x;       scanf( %d , &x);       V[x].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; i++) {       char s = getchar();       while (s <  0  || s >  1 ) s = getchar();       if (s ==  1 ) update(1, 1, n, dfn[i], dfn[i]);     }     scanf( %d , &Q);     while (Q--) {       int x, opt;       char s = getchar();       while (!isalpha(s)) s = getchar();       if (s ==  g )         opt = 2;       else         opt = 1;       while (isalpha(s)) s = getchar();       scanf( %d , &x);       if (opt == 1)         update(1, 1, n, dfn[x], dfn[x] + size[x] - 1);       else         printf( %d n , query(1, 1, n, dfn[x], dfn[x] + size[x] - 1));     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, ans = 0, a, b = 0, N;     cin >> N;     for (long long i = 1; i <= 1e6; i++) {       n = N;       a = i * 2;       n -= a;       b = ((i - 1) * (i * 3) / 2);       n -= b;       if (n < 0) break;       if (n % 3 == 0) ans++;     }     cout << ans;     return 0;   }
/* 2013-08-11 10:03:33.914034 */#include<iostream>   #include<cstdio>   #include<cstdlib>   #include<ctime>   #include<cmath>   #include<cctype>   #include<cstring>   #include<algorithm>      #include<map>   #include<set>   #include<vector>   #include<string>   #include<queue>      using namespace std;      char s[1011][1011];   bool u[1011][1011];   char c[1011][1011];   int n,m;   const int dx[]={1,0,-1,0};   const int dy[]={0,1,0,-1};   inline bool fitr(int x,int y){    return s[x][y+1]== b &&s[x][y+2]== w &&!u[x][y+1]&&!u[x][y+2];   }   inline bool fitc(int x,int y){    return s[x+1][y]== b &&s[x+2][y]== w &&!u[x+1][y]&&!u[x+2][y];   }   char choosec(int a,int b,int ax,int ay){    int opt=0;    for(int i=0;i<3;++i)    {     for(int k=0;k<4;++k)     {      int nx=a+dx[k],ny=b+dy[k];      if(nx>0&&nx<=n&&ny>0&&ny<=m)      {       if(c[nx][ny]!= . ) opt|=1<<(c[nx][ny]- a );      }     }     a+=ax,b+=ay;    }    for(int i=0;;++i)    {     if(((1<<i)&opt)==0) return i+ a ;    }   }   int main(){    scanf( %d%d ,&n,&m);    for(int i=1;i<=n;++i)    {     scanf( %s ,s[i]+1);     for(int j=1;j<=m;++j) c[i][j]= . ;    }    for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(!u[i][j]&&s[i][j]!= . )    {     if(s[i][j]== b )     {      printf( NO n );      return 0;     }     else     {      if(fitr(i,j))      {       u[i][j]=u[i][j+1]=u[i][j+2]=1;       char co=choosec(i,j,0,1);       c[i][j]=c[i][j+1]=c[i][j+2]=co;      }      else      {       if(fitc(i,j))       {        u[i][j]=u[i+1][j]=u[i+2][j]=1;        char co=choosec(i,j,1,0);        c[i][j]=c[i+1][j]=c[i+2][j]=co;       }       else       {        printf( NO n );        return 0;       }      }     }    }    printf( YES n );    for(int i=1;i<=n;++i) printf( %s n ,c[i]+1);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a;     if (a == 1) {       cout <<  1 ;       return 0;     }     if (a == 2) {       cout <<  13 ;       return 0;     }     long long sol = 1;     sol += 1LL * 6 * a * (a + 1) / 2;     sol += 1LL * 6 * ((a - 2) * (a - 1) / 2 - 1);     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, x[3], y[3], xx, yy, jump[111111];   pair<long long, long long> dist[111111];   long long maxR2[111111], ans = LONG_LONG_MAX;   int main() {     scanf( %d %d %d %d %d , &N, &x[1], &y[1], &x[2], &y[2]);     for (int i = 1; i <= N; i++) {       scanf( %d %d , &xx, &yy);       dist[i].first =           1LL * (xx - x[1]) * (xx - x[1]) + 1LL * (yy - y[1]) * (yy - y[1]);       dist[i].second =           1LL * (xx - x[2]) * (xx - x[2]) + 1LL * (yy - y[2]) * (yy - y[2]);     }     sort(dist + 1, dist + N + 1);     for (int i = N; i >= 0; i--) {       maxR2[i] = max(maxR2[i + 1], dist[i].second);       jump[i] = (dist[i].first == dist[i + 1].first) ? jump[i + 1] : (i + 1);     }     for (int i = 0; i <= N; i++) ans = min(ans, dist[i].first + maxR2[jump[i]]);     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   string run(vector<string> &vec) {     vector<bool> used(vec.size(), false);     vector<char> ans(100,  1 );     for (int i = 0; i < vec[0].size(); ++i) {       ans[50 + i] = vec[0][i];     }     used[0] = true;     while (true) {       int count = 0;       for (int i = 1; i < vec.size(); ++i) {         if (not used[i]) {           bool thr = false;           for (int p = 0; p < vec[i].size() && !thr; ++p) {             for (int k = 0; k < ans.size() && !thr; ++k) {               if (ans[k] == vec[i][p]) {                 int in = k - p;                 for (int np = 0; np < vec[i].size(); ++np) {                   ans[in + np] = vec[i][np];                 }                 used[i] = true;                 count += 1;                 thr = true;               }             }           }         }       }       if (count == 0) break;     }     int sz = 0;     for (int i = 0; i < vec.size(); ++i) {       if (not used[i]) {         vec[sz] = vec[i];         ++sz;       }     }     vec.resize(sz);     string ret;     for (int i = 0; i < ans.size(); ++i) {       if (ans[i] !=  1 ) {         ret += ans[i];       }     }     return ret;   }   int main() {     int n;     cin >> n;     vector<string> vs(n);     for (int i = 0; i < n; ++i) {       cin >> vs[i];     }     string ans;     while (not vs.empty()) {       string c1 = run(vs);       ans += c1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const long long int MAXN = 3e3 + 5;   const long long int inf = 1e17;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<char> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       long long int a = v.back() -  0 ;       while (a % 2 == 0) {         v.pop_back();         if (v.size() > 0)           a = v.back() -  0 ;         else           break;       }       if (v.size() < 2) {         cout <<  -1  << endl;         continue;       }       long long int sum = 0;       for (int i = 0; i < v.size(); i++) {         a = v[i] -  0 ;         sum += a;       }       if (sum % 2 == 0) {         for (auto i : v) cout << i;         cout << endl;         continue;       }       long long int ind = -1;       for (int i = v.size() - 2; i > -1; i--) {         a = v[i] -  0 ;         if (a % 2) {           ind = i;           break;         }       }       if (ind == 0 && v[1] ==  0 ) ind = -1;       if (ind != 0 && v[0] ==  0 ) ind = -1;       if (ind == -1)         cout <<  -1  << endl;       else {         for (int i = 0; i < v.size(); i++) {           if (i != ind) cout << v[i];         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 4.0 * atan(1.0);   int64_t num;   queue<int64_t> qu;   bool ifgood(int64_t x) {     int64_t a, b;     a = 0;     b = 0;     while (x) {       if (x % 10 == 4)         ++a;       else if (x % 10 == 7)         ++b;       else         return false;       x /= 10;     }     if (a == b) return true;     return false;   }   void bfs() {     while (!qu.empty()) qu.pop();     int64_t a, b, k;     a = 0;     qu.push(a);     while (!qu.empty()) {       b = qu.front();       if (b > num && ifgood(b)) return;       qu.pop();       k = b;       b = b * 10 + 4;       qu.push(b);       k = k * 10 + 7;       qu.push(k);     }     return;   }   int main() {     cin >> num;     if (ifgood(num))       cout << num << endl;     else {       bfs();       cout << qu.front() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     long long A, B, n;     cin >> A >> B >> n;     while (n--) {       long long l, t, m;       cin >> l >> t >> m;       if (t < A + (l - 1) * B) {         cout << -1 << endl;         continue;       }       long long low = l, high = 1e7 * 1ll;       while (low < high) {         long long mi = (low + high + 1) / 2;         long long res = (mi - l + 1) * A;         res += (((mi - 1) * mi) / 2 - max(0ll, ((l - 2) * (l - 1)) / 2)) * B;         if (res <= t * m && A + (mi - 1) * B <= t) {           low = mi;         } else {           high = mi - 1;         }       }       cout << low << endl;     }     return 0;   }
#include <bits/stdc++.h>   struct f {     int pos;     int num;   } a[108];   int cmp(const void *a, const void *b) {     return (*(struct f *)a).num - (*(struct f *)b).num;   }   int main() {     int n, k;     while (scanf( %d%d , &n, &k) == 2) {       int i;       for (i = 0; i < n; i++) {         scanf( %d , &a[i].num);         a[i].pos = i + 1;       }       qsort(a, n, sizeof(a[0]), cmp);       int sum = 0;       int count = 0;       for (i = 0; i < n; i++) {         if (i == 0 && a[i].num > k) break;         sum += a[i].num;         if (sum > k) break;         count++;       }       printf( %d n , count);       for (i = 0; i < count; i++) {         if (i != 0)           printf(  %d , a[i].pos);         else           printf( %d , a[i].pos);       }       if (count) printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, max = -100000;     int a[200], inter[200], exter[200];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         int sum = 0;         vector<int> inter, exter;         inter.clear();         exter.clear();         for (int m = i; m < j + 1; m++) {           sum += a[m];           inter.push_back(a[m]);         }         for (int m = 0; m < i; m++) exter.push_back(a[m]);         for (int m = j + 1; m < n; m++) exter.push_back(a[m]);         sort(inter.begin(), inter.end());         sort(exter.begin(), exter.end());         for (int m = 0; m < k; m++) {           if (m >= inter.size() || exter.size() < m + 1) break;           if (exter[exter.size() - 1 - m] > inter[m])             sum += exter[exter.size() - 1 - m] - inter[m];         }         max = max > sum ? max : sum;       }     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _d {     int r1, c1, r2, c2;   };   int n, m;   char arr[500][501];   bool ans[600000];   _d queries[600000];   bitset<500> DPU[500][500], DPD[500][500];   void dnc(int l, int r, vector<int> &qid) {     if (l > r) return;     int mid = (l + r) / 2;     vector<int> ql, qr;     for (int i = 0; i < qid.size(); i++) {       if (queries[qid[i]].r2 < mid) {         ql.push_back(qid[i]);         qid[i] = qid.back(), qid.pop_back(), --i;       } else if (queries[qid[i]].r1 > mid) {         qr.push_back(qid[i]);         qid[i] = qid.back(), qid.pop_back(), --i;       }     }     if (!qid.empty()) {       for (int i = m - 1; i >= 0; i--) {         DPU[mid][i] = i != m - 1 && arr[mid][i + 1] ==  .  ? DPU[mid][i + 1]                                                            : bitset<500>();         DPU[mid][i][i] = 1;       }       for (int i = 0; i < m; i++) {         DPD[mid][i] =             i && arr[mid][i - 1] ==  .  ? DPD[mid][i - 1] : bitset<500>();         DPD[mid][i][i] = 1;       }       for (int i = mid - 1; i >= l; i--) {         for (int j = m - 1; j >= 0; j--) {           DPU[i][j] = arr[i + 1][j] ==  .  ? DPU[i + 1][j] : bitset<500>();           if (j != m - 1 && arr[i][j + 1] ==  . ) DPU[i][j] |= DPU[i][j + 1];         }       }       for (int i = mid + 1; i <= r; i++) {         for (int j = 0; j < m; j++) {           DPD[i][j] = arr[i - 1][j] ==  .  ? DPD[i - 1][j] : bitset<500>();           if (j && arr[i][j - 1] ==  . ) DPD[i][j] |= DPD[i][j - 1];         }       }       for (int i : qid) {         auto cq = queries[i];         ans[i] = (DPU[cq.r1][cq.c1] & DPD[cq.r2][cq.c2]).any();       }     }     if (!ql.empty()) dnc(l, mid - 1, ql);     if (!qr.empty()) dnc(mid + 1, r, qr);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , arr[i]);     int q;     scanf( %d , &q);     vector<int> qid(q);     for (int i = 0; i < q; i++) {       int r1, c1, r2, c2;       scanf( %d%d%d%d , &r1, &c1, &r2, &c2);       queries[i] = {r1 - 1, c1 - 1, r2 - 1, c2 - 1};       qid[i] = i;     }     dnc(0, n - 1, qid);     for (int i = 0; i < q; i++) printf(ans[i] ?  Yes n  :  No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int N = 1e5 + 7;   int pre[N], sz[N], cnt[N], n, lencnt, dx, one;   pair<int, int> a[N];   void init() { memset(pre, -1, sizeof(pre)); }   int fd(int n) { return pre[n] == -1 ? n : pre[n] = fd(pre[n]); }   void mg(int a, int b) {     a = fd(a), b = fd(b);     if (a != b) {       pre[b] = a;       sz[a] += sz[b];       sz[b] = 0;     }   }   void solve(int x) {     int v = x + 1;     if (v <= n && sz[fd(v)]) {       if (--cnt[sz[fd(v)]] == 0) --lencnt;       if (--cnt[sz[x]] == 0) --lencnt;       mg(x, v);       if (++cnt[sz[fd(v)]] == 1) ++lencnt;     }     v = x - 1;     if (v >= 1 && sz[fd(v)]) {       if (--cnt[sz[fd(v)]] == 0) --lencnt;       if (--cnt[sz[fd(x)]] == 0) --lencnt;       mg(x, v);       if (++cnt[sz[fd(v)]] == 1) ++lencnt;     }     one = cnt[sz[fd(x)]];   }   int main(void) {     int i;     scanf( %d , &n);     init();     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + 1 + n);     int ans = 1;     for (i = 1; i <= n; ++i) {       sz[a[i].second] = 1;       if (++cnt[1] == 1) ++lencnt;       solve(a[i].second);       if (lencnt == 1 && one > dx) {         ans = a[i].first + 1;         dx = one;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int i, count = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 1; i < n - 1; i++) {       if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) {         count++;         i += 2;       }     }     printf( %d , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, v[5000], d[5000], p[5000], f[5000], ans;   queue<int> q;   void work() {     int i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d%d%d , &v[i], &d[i], &p[i]);     for (i = 1; i <= n; i++) {       if (f[i] == 0) {         f[i] = 1;         for (j = i + 1, k = v[i]; j <= n && k > 0; j++, k--) {           p[j] -= k;           if (f[j] == -1) k++;           if (p[j] < 0 && f[j] != -1) q.push(j), f[j] = -1;         }         while (q.size() != 0) {           k = q.front();           q.pop();           for (j = k + 1; j <= n; j++) {             p[j] -= d[k];             if (p[j] < 0 && f[j] != -1) f[j] = -1, q.push(j);           }         }       }     }     ans = 0;     for (i = 1; i <= n; i++) ans += f[i] == 1;     printf( %d n , ans);     for (i = 1; i <= n; i++)       if (f[i] == 1) printf( %d  , i);   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 34;   int n, m;   int f[MAXN][MAXN], s[MAXN][MAXN];   int work2(int j) {     s[m][m + 1 + j] = s[m][j] * s[m][m];     int tot = s[m][j] * f[m][j] + s[m][m + 1 + j] * f[m][m + 1 + j];     for (int i = 0; i < m; ++i) {       int x = f[i][j] + s[i][m] * f[i][m + j + 1] + s[m][j] * f[m + i + 1][j] +               s[i][m] * s[m][m + j + 1] * f[m + i + 1][m + j + 1];       tot += abs(x);     }     return tot;   }   int work1() {     int tot = 0;     for (int i = 0, x1, x2; i < m; ++i) {       s[m][i] = 1, x1 = work2(i);       s[m][i] = -1, x2 = work2(i);       tot += max(x1, x2);     }     return tot;   }   int main() {     scanf( %d , &n), m = n >> 1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) scanf( %d , f[i] + j);     int mx = 0;     for (int mask = 0, lim = 1 << (m + 1); mask < lim; ++mask) {       for (int i = 0; i <= m; ++i) s[i][m] = (mask & 1 << i) ? -1 : 1;       for (int i = m + 1; i < n; ++i) s[i][m] = s[m][m] * s[i - m - 1][m];       int cc = 0;       for (int i = 0; i < n; ++i) cc += s[i][m] * f[i][m];       mx = max(mx, work1() + cc);     }     printf( %d n , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void PLAY() {     cout << fixed << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int min(int a, int b) {     if (a < b) return a;     return b;   }   long long fx4[] = {-1, 1, 0, 0};   long long fy4[] = {0, 0, -1, 1};   long long fx8[] = {-1, -1, -1, 0, 1, 1, 1, 0};   long long fy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};   const double PI = 3.141592653589793;   const long long N = 2e5 + 5;   const long long mod = 1000000007;   long long m, n;   long long ar[N];   vector<long long> arr;   long long dp[5005][5005];   long long func(long long l, long long r) {     if (l == r)       return 0;     else if (l + 1 == r)       return 1;     long long &ans = dp[l][r];     if (ans != -1) return ans;     ans = 0;     long long op1 = INT_MAX;     long long op2 = INT_MAX;     long long op3 = INT_MAX;     if (arr[l] == arr[r])       op1 = 1 + func(l + 1, r - 1);     else {       op2 = 1 + func(l, r - 1);       op3 = 1 + func(l + 1, r);     }     ans = min(op1, min(op2, op3));     return ans;   }   int32_t main() {     PLAY();     cin >> m;     for (long long i = 0; i < m; i++) cin >> ar[i];     arr.push_back(ar[0]);     for (long long i = 1; i < m;) {       while (ar[i] == ar[i - 1]) i++;       if (i < m) arr.push_back(ar[i]);       i++;     }     memset(dp, -1, sizeof(dp));     n = arr.size();     cout << func(0, n - 1) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void _dbg(string) { cout << endl; }   template <class H, class... T>   void _dbg(string s, H h, T... t) {     int l = s.find( , );     cout << s.substr(0, l) <<   =   << h <<  ,  ;     _dbg(s.substr(l + 1), t...);   }   template <class T, class U>   ostream& operator<<(ostream& o, const pair<T, U>& p) {     o <<  (  << p.first <<  ,  << p.second <<  ) ;     return o;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  [ ;     for (T t : v) {       o << t <<  , ;     }     o <<  ] ;     return o;   }   const int N = 100000;   int n, m;   bool used[N + 5];   char s[N + 5];   int hoge(char c) {     int crnt = 0;     int last = -1;     int ret = 0;     for (int i = (int)(0); i < (int)(n); i++) {       crnt++;       if (s[i] == c) last = i;       if (used[i]) crnt = 0;       if (crnt == m) {         if (i - last >= m) return -1;         crnt = i - last;         used[last] = true;         ret++;       }     }     return ret;   }   int main() {     cin >> m >> s;     n = strlen(s);     for (int i = (int)(0); i < (int)(26); i++) {       char c = i +  a ;       int r = hoge(c);       if (r == -1) {         r = 0;         for (int j = (int)(0); j < (int)(n); j++)           if (s[j] == c) {             r++;             used[j] = true;           }       } else {         i = 100;       }       for (int j = (int)(0); j < (int)(r); j++) printf( %c , c);     }     cout << endl;     return 0;   }