malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int i, j, n, ans = 0, k1, k2;       cin >> n;       long long int arr[n];       vector<vector<long long int> > vec(26);       for (i = 0; i < n; i++) {         cin >> arr[i];         vec[arr[i] - 1].push_back(i);       }       long long int dp1[n][26], dp2[n][26];       for (i = 0; i < n; i++)         for (j = 0; j < 26; j++) {           dp1[i][j] = 0;           dp2[i][j] = 0;         }       dp1[0][arr[0] - 1]++;       for (i = 1; i < n; i++) {         for (j = 0; j < 26; j++)           if (arr[i] == j + 1)             dp1[i][j] += dp1[i - 1][j] + 1;           else             dp1[i][j] += dp1[i - 1][j];       }       dp2[n - 1][arr[n - 1] - 1]++;       for (i = n - 2; i >= 0; i--) {         for (j = 0; j < 26; j++)           if (arr[i] == j + 1)             dp2[i][j] += dp2[i + 1][j] + 1;           else             dp2[i][j] += dp2[i + 1][j];       }       for (i = 0; i < 26; i++) {         long long int dd = vec[i].size();         ans = max(ans, dd);       }       for (i = 0; i < 26; i++) {         for (k1 = 0; k1 < vec[i].size(); k1++) {           for (k2 = k1; k2 < vec[i].size(); k2++) {             long long int d1 = vec[i][k1], d2 = vec[i][k2];             for (j = 0; j < 26; j++)               if (i != j)                 ans = max(ans, k2 - k1 + 1 + 2 * min(dp1[d1][j], dp2[d2][j]));           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 500005;   long long a[MAX], pre[MAX], suf[MAX], t;   int main() {     int ans = -1, pos = 0, n;     scanf( %d , &n);     for (register int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       pre[i] = pre[i - 1] | a[i];     }     for (register int i = n; i >= 1; i--) suf[i] = suf[i + 1] | a[i];     for (register int i = 1; i <= n; i++) {       t = pre[i - 1] | suf[i + 1];       if ((a[i] | t) - t > ans) {         ans = (a[i] | t) - t;         pos = i;       }     }     printf( %lld  , a[pos]);     for (register int i = 1; i <= n; i++)       if (i != pos) printf( %lld  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, string> > all[10010];   int main() {     int n, m;     cin >> n >> m;     string name;     int reg, sc;     for (int i = 0; i < n; i++) {       cin >> name >> reg >> sc;       all[reg].push(make_pair(sc, name));     }     for (int i = 1; i <= m; i++) {       int tt[4];       int tool = 0;       pair<int, string> p[4];       while (all[i].size()) {         p[tool] = all[i].top();         all[i].pop();         tt[tool++] = p[tool].first;         if (tool == 3) break;       }       if (tool == 2) {         cout << p[0].second <<     << p[1].second << endl;       } else {         if (p[0].first == p[2].first || p[1].first == p[2].first) {           cout <<  ?  << endl;         } else {           cout << p[0].second <<     << p[1].second << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n = 1009;   int LG2(int N) {     int ans = 0;     while (N) {       N >>= 1;       ans++;     }     return ans - 1;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n;     cin >> n;     map<string, int> M;     int o = 1;     vector<long long> v(n);     vector<string> vv(n);     int ans = 0;     for (int i = 0; i < (n); i++) {       string s;       cin >> s;       ans += s.length();       vv[i] = s;       if (M[s]) {         v[i] = M[s];       } else {         M[s] = o;         v[i] = o;         o++;       }     }     ans += n - 1;     int L = ans;     for (int f = 0; f < n; f++) {       int len = 0;       vector<long long> p;       for (int l = f; l < n; l++) {         len += vv[l].length();         if (l > f) len++;         p.push_back(v[l]);         int pL = l - f + 1;         int cntP = 0;         for (int i = l + 1; i < n; i++) {           int o = i + pL - 1;           if (o > n) continue;           int c = 0;           bool b = 1;           for (int j = i; j <= o; j++) {             if (v[j] == p[c]) {             } else {               b = 0;               break;             }             c++;           }           if (b) {             cntP++;             i = o;           }         }         if (!cntP) continue;         int rB = (len - pL) * (cntP + 1);         ans = min(ans, L - rB);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define INF 1000000009      int get(int i){       cout <<  ?   << i+1 << endl;       cout.flush();       int a; cin >> a;       int b;       if(i == 0) b = INF;       else{           cout <<  ?   << i << endl;           cout.flush();           cin >> b;       }       return b-a;   }      int main(){       // freopen( input.txt ,  r , stdin);       // freopen( output.txt ,  w , stdout);       ios_base::sync_with_stdio(false);       cin.tie(0);       int n; cin >> n;       if(n == 1){           cout <<  !   << 1 << endl;           cout.flush();           return 0;       }       if(get(1) < 0){           cout <<  !   << 1 << endl;           cout.flush();           return 0;       }       if(get(n-1) > 0){           cout <<  !   << n << endl;           cout.flush();           return 0;       }       int lo = 0, hi = n-1;       while(lo < hi){           int mid = lo+(hi-lo)/2;           if(get(mid) > 0) lo = mid+1;           else hi = mid;       }       cout <<  !   << lo << endl;       cout.flush();   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int timew, cnt;   stack<int> si;   int low[2000005], dep[2000005], siz[2000005], dfn[2000005], nex[2000005],       las[2000005], Arrive[2000005], st[2000005], cnt1;   bool isin[2000005];   void jt(int xx, int yy) {     cnt++;     nex[cnt] = las[xx];     las[xx] = cnt;     Arrive[cnt] = yy;   }   void tarjan(int noww) {     timew++;     low[noww] = dfn[noww] = timew;     si.push(noww);     isin[noww] = true;     for (int i = las[noww]; i; i = nex[i]) {       if (!dfn[Arrive[i]]) {         tarjan(Arrive[i]);         low[noww] = min(low[noww], low[Arrive[i]]);       } else if (isin[Arrive[i]])         low[noww] = min(low[noww], dfn[Arrive[i]]);     }     if (low[noww] == dfn[noww]) {       cnt1++;       int k = -1;       while (k != noww) {         k = si.top();         si.pop();         isin[k] = false;         st[k] = cnt1;         siz[cnt1]++;       }     }   }   void Clear() {     cnt = 0;     cnt1 = 0;     timew = 0;     for (int i = 1; i <= N; i++)       las[i] = dep[i] = st[i] = siz[i] = dfn[i] = low[i] = dep[i] = 0;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &N, &M);       Clear();       for (int i = 1; i <= M; i++) {         int u, v;         scanf( %d%d , &u, &v);         if (u != v) jt(u, v);       }       for (int i = 1; i <= N; i++)         if (!dfn[i]) tarjan(i);       if (siz[st[1]] == N) {         puts( No );         continue;       }       for (int i = 1; i <= N; i++)         for (int j = las[i]; j; j = nex[j])           if (st[i] != st[Arrive[j]]) dep[st[i]]++;       bool flag = false;       for (int i = 1; i <= cnt1; i++) {         if (!dep[i] && siz[i]) {           flag = true;           puts( Yes );           vector<int> ans[2];           for (int j = 1; j <= N; j++) ans[st[j] == i].push_back(j);           printf( %d %d n , ans[1].size(), ans[0].size());           for (auto &i : ans[1]) printf( %d  , i);           cout <<   n ;           for (auto &i : ans[0]) printf( %d  , i);           cout <<   n ;           break;         }       }       if (!flag) puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const int inf = 1e9 + 100;   int a[N + 100], b[N + 100];   vector<pair<int, int> > mon[N + 100];   int tree[N * 4 + 100], lazy[N * 4 + 100];   void build(int v, int tl, int tr) {     if (tl == tr) {       tree[v] = -b[tl + 1];       return;     }     int tm = (tl + tr) / 2;     build(v * 2, tl, tm);     build(v * 2 + 1, tm + 1, tr);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   void push(int v) {     tree[v * 2] += lazy[v];     tree[v * 2 + 1] += lazy[v];     lazy[v * 2] += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   void update(int v, int tl, int tr, int l, int r, int addend) {     if (l > r) {       return;     }     if (tl == l && tr == r) {       tree[v] += addend;       lazy[v] += addend;       return;     }     push(v);     int tm = (tl + tr) / 2;     update(v * 2, tl, tm, l, min(r, tm), addend);     update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   int query(int v, int tl, int tr, int l, int r) {     if (l > r) {       return -inf;     }     if (tl == l && tr == r) {       return tree[v];     }     push(v);     int tm = (tl + tr) / 2;     return max(query(v * 2, tl, tm, l, min(r, tm)),                query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));   }   int main() {     for (int i = 1; i <= N + 1; i++) {       a[i] = b[i] = inf;     }     int n, m, p;     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) {       int cur, cost;       scanf( %d%d , &cur, &cost);       a[cur] = min(cost, a[cur]);     }     int mx = 0;     for (int i = 1; i <= m; i++) {       int cur, cost;       scanf( %d%d , &cur, &cost);       b[cur] = min(cost, b[cur]);       mx = max(mx, cur);     }     for (int i = 1; i <= p; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       mon[x].push_back(make_pair(y, z));     }     for (int i = 1; i <= N; i++) {       sort(mon[i].begin(), mon[i].end());     }     for (int i = N; i > 0; i--) {       a[i] = min(a[i], a[i + 1]);       b[i] = min(b[i], b[i + 1]);     }     build(1, 1, N);     int ans = -a[1] - b[1];     int total = 0;     for (int i = 1; i <= N; i++) {       if (a[i + 1] == inf) {         break;       }       for (auto it : mon[i]) {         update(1, 1, N, it.first, N, it.second);         ans = max(ans, query(1, 1, N, 1, mx - 1) - a[i + 1]);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   char s[500][500];   int di[4] = {-1, 1, 0, 0};   int dj[4] = {0, 0, -1, 1};   typedef int int2d[500][500];   int2d p[26];   int2d d;   struct Pos {     int r, c;     Pos(int r = 0, int c = 0) : r(r), c(c) {}     void init(int r, int c) {       this->r = r;       this->c = c;     }     bool operator<(const Pos& p) const {       int d1 = d[r][c], d2 = d[p.r][p.c];       return d1 < d2 || d1 == d2 && (r < p.r || r == p.r && c < p.c);     }   } wh[27];   int n, m;   bool isDigit(char c) { return c >=  0  && c <=  9 ; }   set<Pos> heap;   void calc(int i, int j, int2d& par) {     memset(d, 127, sizeof(d));     d[i][j] = 0;     heap.insert(Pos(i, j));     while (!heap.empty()) {       Pos p = *heap.begin();       heap.erase(heap.begin());       char ch = s[p.r][p.c];       if (!isDigit(ch) && ch != s[i][j]) {         continue;       }       int cost = (isDigit(ch) ? ch -  0  : 1) + d[p.r][p.c];       for (int dir = 0; dir < 4; dir++) {         int r = p.r + di[dir], c = p.c + dj[dir];         if (r >= 0 && c >= 0 && r < n && c < m && s[r][c] !=  # ) {           if (d[r][c] > cost) {             heap.erase(Pos(r, c));             d[r][c] = cost;             heap.insert(Pos(r, c));             par[r][c] = dir;           }         }       }     }   }   char sm[10000];   int main() {     int k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] >=  a  && s[i][j] <=  z ) {           wh[s[i][j] -  a ].init(i, j);           calc(i, j, p[s[i][j] -  a ]);         }       }     }     int r, c;     int r2, c2;     scanf( %d %d %s %d %d , &r, &c, sm, &r2, &c2);     r--, c--;     r2--, c2--;     calc(r2, c2, p[26]);     int len = strlen(sm);     for (int i = 0; i < len && k;) {       char ch = s[r][c];       if (ch == sm[i]) {         i++;         continue;       }       int cost = (isDigit(ch) ? ch -  0  : 1);       int dir = p[sm[i] -  a ][r][c];       if (cost > k) {         k = 0;         break;       }       k -= cost;       r -= di[dir];       c -= dj[dir];     }     while (k > 0 && (r != r2 || c != c2)) {       char ch = s[r][c];       int cost = (isDigit(ch) ? ch -  0  : 1);       if (cost > k) {         k = cost;         exit(1);         break;       }       k -= cost;       int dir = p[26][r][c];       r -= di[dir];       c -= dj[dir];     }     printf( %d %d n , r + 1, c + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   const int tt = 75;   int n;   int m;   int x[100];   int y[100];   int z[100];   vector<int> v;   vector<int> w[300];   int res[301][301][2];   int was[301][301][2];   map<int, int> num;   int f[300];   int calc() {     vector<pair<int, int> > v;     for (int i = 0; i < n; i++)       if (z[i]) {         v.push_back(make_pair(x[i], 1));         v.push_back(make_pair(x[i] + y[i], -1));       } else {         v.push_back(make_pair(x[i] - y[i], 1));         v.push_back(make_pair(x[i], -1));       }     sort((v).begin(), (v).end());     int cur = 0, bal = 0;     for (int i = 0; i + 1 < 2 * n; i++) {       bal += v[i].second;       if (bal) cur += v[i + 1].first - v[i].first;     }     return cur;   }   int go(int i, int j, int t) {     if (j < i) {       t = 0;       j = i;     }     if (i == ((int)(v).size())) return 0;     if (was[i][j][t]) return res[i][j][t];     was[i][j][t] = 1;     int cur = go(i + 1, j, t);     if ((!t || i < j) && f[i] > j)       cur = max(cur, go((t ? j : i) + 1, f[i], 0) + (v[f[i]] - v[j]));     for (int k = 0; k < ((int)(w[i]).size()); k++)       if (w[i][k] > j)         cur = max(cur, go((t ? j : i) + 1, w[i][k], 1) + (v[w[i][k]] - v[j]));     return res[i][j][t] = cur;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       v.push_back(x[i] - y[i]);       v.push_back(x[i]);       v.push_back(x[i] + y[i]);     }     sort((v).begin(), (v).end());     v.resize(unique((v).begin(), (v).end()) - v.begin());     for (int i = 0; i < ((int)(v).size()); i++) num[v[i]] = i;     for (int i = 0; i < n; i++) {       int a = num[x[i] - y[i]];       int b = num[x[i]];       int c = num[x[i] + y[i]];       f[b] = c;       w[a].push_back(b);     }     printf( %d n , go(0, 0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main()   {        ios_base :: sync_with_stdio(false); cin.tie(NULL);        int t ; cin >> t ; while(t--)        {            int a , b ; cin >> a >> b ;      a-=b ;      while(b--) cout <<  a  ;      string d =  cba  ;      for(int i = 0 ; i < a ; i++)      {          cout << d[i % 3] ;      }      cout << endl ;        }      }
#include <bits/stdc++.h>   using namespace std;   long long n, m, rr[10][10];   long long func(long long), dp[(1 << 21)];   map<long long, pair<long long, long long> > mr;   long long check(long long i, long long j) {     return (abs(mr[i].first - mr[j].first) + abs(mr[i].second - mr[j].second)) ==            3;   }   int main() {     scanf( %lld %lld , &n, &m);     if (n > m) swap(n, m);     if (n * m <= 21) {       long long x = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           mr[x++] = make_pair(i, j);         }       memset(dp, -1, sizeof(dp));       cout << func(0);     } else {       long long ans = 0;       if (n == 1) {         ans += m - m % 6;         m = m % 6;         ans += (m >= 3 ? 2 * (m - 3) : 0);       } else         ans = n * m - (n * m) % 2;       cout << ans <<   n ;     }   }   long long func(long long mask) {     if (dp[mask] != -1) return dp[mask];     long long ans = 0;     for (int i = 0; i < n * m; i++) {       for (int j = i + 1; j < n * m; j++) {         if ((mask & (1 << i)) == 0 && (mask & (1 << j)) == 0 && check(i, j)) {           ans = max(ans, 2 + func(mask | (1 << i) | (1 << j)));         }       }     }     return dp[mask] = ans;   }
#include <bits/stdc++.h>   using namespace std;   bool f(int n, int h, int c, int t) {     return (2 * n + 1ll) * abs(1ll * n * (h + c - 2 * t) + t - c) <=            (2 * n - 1ll) * (1ll * n * (h + c - 2 * t) + h - t);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       int h, c, t;       cin >> h >> c >> t;       if (2 * t <= h + c)         cout <<  2               <<   n ;       else {         int a = h - t;         int b = 2 * t - c - h;         int k = 2 * (a / b) + 1;         long long val1 =             abs(k / 2 * 1ll * c + (k + 1) / 2 * 1ll * h - t * 1ll * k);         long long val2 = abs((k + 2) / 2 * 1ll * c + (k + 3) / 2 * 1ll * h -                              t * 1ll * (k + 2));         if (val1 * (k + 2) <= val2 * k)           cout << k <<   n ;         else           cout << k + 2 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   #define sim template < class c   #define ris return * this   #define dor > debug & operator <<   #define eni(x) sim > typename      enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {   sim > struct rge { c b, e; };   sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }   sim > auto dud(c* x) -> decltype(cerr << *x, 0);   sim > char dud(...);   struct debug {   #ifndef ONLINE_JUDGE   ~debug() { cerr << endl; }   eni(!=) cerr << boolalpha << i; ris; }   eni(==) ris << range(begin(i), end(i)); }   sim, class b dor(pair < b, c > d) {     ris <<  (  << d.first <<  ,   << d.second <<  ) ;   }   sim dor(rge<c> d) {     *this <<  [ ;     for (auto it = d.b; it != d.e; ++it)       *this <<  ,   + 2 * (it == d.b) << *it;     ris <<  ] ;   }   #else   sim dor(const c&) { ris; }   #endif   };   #define imie(...)   [  << #__VA_ARGS__  :   << (__VA_ARGS__) <<  ]        #define ll long long      const ll mod = 998244353;      long long power(long long x, ll y, ll p)   {       long long res = 1; // Initialize result           x = x % p; // Update x if it is more than or       // equal to p           while (y > 0)       {                   // If y is odd, multiply x with result           if (y & 1)               res = (res * x) % p;               // y must be even now           y = y >> 1; // y = y/2           x = (x * x) % p;       }       return res;   }       // Returns n^(-1) mod p   long long modInverse(long long n, int p)   {       return power(n, p - 2, p);   }       // Returns nCr % p using Fermat s little   // theorem.   long long nCrModPFermat(long long n,int r, int p)   {       // If n<r, then nCr should return 0       if (n < r)           return 0;       // Base case       if (r == 0)           return 1;           // Fill factorial array so that we       // can find all factorial of r, n       // and n-r       long long fac[n + 1];       fac[0] = 1;       for (int i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;           return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;   }      void test_case() {       ll n;       cin >> n;       string s;       cin >> s;       ll cnt = 0, cnt2 = 0, tmp = 0;       for(ll i = 0; i < n; ++i) {           if(s[i] ==  0 ) {               cnt2 = cnt2 + (tmp) / 2;               tmp = 0;               cnt++;           } else {               tmp++;           }       }       cnt2 = cnt2 + (tmp) / 2;       cout << nCrModPFermat(cnt + cnt2, cnt, mod) << endl;   }       int main()   {       ll T;        cin >> T;       for(ll i = 1; i <= T; ++i) {           test_case();       }       return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   int rd() {     int k = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) k = k * 10 + c -  0 , c = getchar();     return k;   }   const int N = 300000, M = 600001;   int T, x, y, f[M], sx[M], sy[M];   long long ans;   vector<pair<int, int> > v[M << 1];   map<pair<int, int>, int> mp;   pair<int, int> p;   int F(int x) {     while (x != f[x]) x = f[x];     return x;   }   void Add(int x, int l, int r, int s, int t, pair<int, int> p) {     if (s <= l && r <= t) {       v[x].push_back(p);       return;     }     if (s <= ((l + r) >> 1)) Add((x << 1), l, ((l + r) >> 1), s, t, p);     if (((l + r) >> 1) < t) Add((x << 1 | 1), ((l + r) >> 1) + 1, r, s, t, p);   }   void Solve(int x, int l, int r) {     long long pre = ans;     stack<int> S;     for (int i = 0; i < v[x].size(); ++i) {       int a = F(v[x][i].first), b = F(v[x][i].second + N);       if (a == b) continue;       if (sx[a] + sy[a] > sx[b] + sy[b]) {         int t = a;         a = b, b = t;       }       ans -= (long long)sx[a] * sy[a] + (long long)sx[b] * sy[b],           f[a] = b, sx[b] += sx[a], sy[b] += sy[a];       ans += (long long)sx[b] * sy[b], S.push(a);     }     if (l == r)       printf( %lld  , ans);     else       Solve((x << 1), l, ((l + r) >> 1)),           Solve((x << 1 | 1), ((l + r) >> 1) + 1, r);     while (!S.empty()) {       int t = S.top(), z = f[t];       S.pop(), f[t] = t, sx[z] -= sx[t], sy[z] -= sy[t];     }     ans = pre;   }   int main() {     T = rd();     for (int i = 1; i <= T; ++i) {       x = rd(), y = rd(), p = make_pair(x, y);       if (mp.count(p))         Add(1, 1, T, mp[p], i - 1, p), mp.erase(p);       else         mp[p] = i;     }     for (auto t : mp) Add(1, 1, T, t.second, T, t.first);     for (int i = 1; i <= N; ++i) sx[f[i] = i] = 1;     for (int i = N + 1; i < M; ++i) sy[f[i] = i] = 1;     Solve(1, 1, T);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100007][2];   long long ecnt[100007][2] = {0};   long long ss[100007] = {0};   long long sum = 0;   long long n, m, q;   int main() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       --a;       --b;       if (a > b) swap(a, b);       adj[a][0].push_back(b);       adj[b][1].push_back(a);       ecnt[a][0]++;       ecnt[b][1]++;     }     for (long long i = 0; i < n; i++) {       ss[i] = ecnt[i][0] * ecnt[i][1];       sum += ss[i];     }     cin >> q;     cout << sum << endl;     while (q--) {       long long v;       cin >> v;       --v;       sum -= ss[v];       ss[v] = 0;       ecnt[v][1] += ecnt[v][0];       ecnt[v][0] = 0;       for (auto i : adj[v][0]) {         sum -= ecnt[i][0] * ecnt[i][1];         ecnt[i][1]--;         ecnt[i][0]++;         sum += ecnt[i][0] * ecnt[i][1];         ss[i] = ecnt[i][0] * ecnt[i][1];         adj[i][0].push_back(v);       }       adj[v][0].clear();       cout << sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int maxdp[27];   int dp[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     string str;     cin >> n >> str;     for (int i = 0; i < n; ++i) {       for (int c = 26; c > str[i] -  a ; --c)         maxdp[str[i] -  a ] = max(maxdp[c] + 1, maxdp[str[i] -  a ]);       dp[i] = maxdp[str[i] -  a ];     }     cout << *max_element(dp, dp + n) << endl;     for (int i = 0; i < n; ++i) {       cout << dp[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1e2 + 5;   int main() {     int n, m, c;     string s[SIZE], extract, f;     c = 0, f =  acef ;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         extract.push_back(s[i][j]);         extract.push_back(s[i + 1][j]);         extract.push_back(s[i][j + 1]);         extract.push_back(s[i + 1][j + 1]);         sort(extract.begin(), extract.end());         if (extract == f) c++;         extract.clear();       }     }     cout << c << endl;     return 0;   }