malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const int maxn = 21;   const int dx[4] = {0, 0, 1, -1};   const int dy[4] = {1, -1, 0, 0};   int Map[maxn][maxn], Value[maxn], X[maxn], Y[maxn], XX[maxn], YY[maxn];   int vis[maxn][maxn][260][129], VV[maxn][maxn][260][129],       inq[maxn][maxn][260][129];   int ans, num, N, M, D;   const int Maxn = 3020120;   char s[30];   struct Point {     int x, y, z, value, num;   } Q[Maxn];   void BFS(int sx, int sy) {     int x, y, z, V, u, v, w, NOW, value, NNN, head, tail;     Q[head = tail = 1] = (Point){sx, sy, 0, 0, 0};     memset(vis, 0, sizeof(vis));     vis[sx][sy][0][0] = 1;     while (head <= tail) {       x = Q[head].x;       y = Q[head].y;       z = Q[head].z;       V = Q[head].value;       NOW = Q[head].num;       inq[x][y][z][V] = 0;       ++head;       V--;       for (int i = 0; i < 4; i++) {         u = x + dx[i], v = y + dy[i], w = z, value = V, NNN = NOW;         if (!u || !v || u > N || v > M) continue;         if (!Map[u][v]) continue;         for (int k = 1; k <= D; k++)           if (u == X[k] && v > Y[k] && x == X[k] + 1 ||               u == X[k] + 1 && v > Y[k] && x == X[k]) {             w = w ^ (1 << k - 1);             if (w & (1 << k - 1))               value += Value[k];             else               value -= Value[k];           }         for (int k = 1; k <= num; k++) {           if (u == XX[k] && v > YY[k] && x == XX[k] + 1) NNN = NNN ^ (1 << k - 1);           if (u == XX[k] + 1 && v > YY[k] && x == XX[k]) NNN = NNN ^ (1 << k - 1);         }         if (NNN == 1) NNN = 1;         if (value > VV[u][v][w][NNN])           VV[u][v][w][NNN] = value;         else           continue;         if (!vis[u][v][w][NNN])           Q[++tail] = (Point){u, v, w, value, NNN};         else           continue;         if (u == sx && v == sy && value > ans && NNN == 0) ans = max(ans, value);         inq[u][v][w][NNN] = 1;       }     }   }   int main() {     cin >> N >> M;     memset(VV, 235, sizeof(VV));     for (int i = 1; i <= N; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= M; j++) {         if (s[j] >  0  && s[j] !=  #  && s[j] !=  .  && s[j] !=  S  &&             s[j] !=  B )           X[s[j] - 48] = i, Y[s[j] - 48] = j, D = max(D, s[j] - 48);         if (s[j] ==  . ) Map[i][j] = 1;         if (s[j] ==  S ) Map[i][j] = 2;         if (s[j] ==  B ) {           XX[++num] = i;           YY[num] = j;         }       }     }     for (int i = 1; i <= D; i++) scanf( %d , &Value[i]);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++)         if (Map[i][j] == 2) BFS(i, j);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, m, dp[250][1 << 15][2][2];   char g[250][251];   int calc(int r, int c, int left, int up, int emp) {     if (r == n) {       for (int i = 0; i < 15; i++)         if (c + 1 < m && (left & (1 << i)) && g[i][c + 1] ==  x )           left &= ~(1 << i);       return calc(0, c + 1, left, 0, emp);     }     if (c == m) return 1;     int &ret = dp[r * m + c][left][up][emp];     if (ret != -1) return ret;     ret = 0;     if (g[r][c] ==  x ) {       ret = calc(r + 1, c, left, 0, emp);     } else {       if (up || (left & (1 << r)))         ret = (ret + calc(r + 1, c, left, up, emp)) % MOD;       else if (!emp)         ret = (ret + calc(r + 1, c, left, up, 1)) % MOD;       ret = (ret + calc(r + 1, c, left | (1 << r), 1, emp)) % MOD;     }     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , g[i]);     if (n > m) {       char tmp[250][251];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) tmp[j][i] = g[i][j];       swap(n, m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) g[i][j] = tmp[i][j];     }     memset(dp, -1, sizeof(dp));     printf( %d n , calc(0, 0, 0, 0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int A[5][5], x, y, p, q, sum;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> A[i][j];         if (A[i][j] == 1) {           x = i;           y = j;         }       }       cout << endl;     }     if (x == 2 && y == 2) {       p = 0;       q = 0;     } else if (x >= 2 && y >= 2) {       p = x - 2;       q = y - 2;     } else if (x >= 2 && y <= 2) {       p = x - 2;       q = 2 - y;     } else if (x <= 2 && y >= 2) {       p = 2 - x;       q = y - 2;     } else if (x <= 2 && y <= 2) {       p = 2 - x;       q = 2 - y;     }     sum = p + q;     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005], m[100005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     m[1] = a[1] - b[1];     for (int i = 2; i <= n; i++) m[i] = m[i - 1] + a[i] - b[i];     int min = 1000000001;     for (int i = 1; i <= n; i++)       if (min > m[i]) min = m[i];     vector<int> d;     for (int i = 1; i <= n; i++) {       if (min >= 0) d.push_back(i);       min -= a[i] - b[i];     }     m[n + 1] = a[1] - b[n];     m[1] = a[1] - b[n];     for (int i = n; i >= 2; i--) m[i] = m[i + 1] + a[i] - b[i - 1];     min = 1000000001;     for (int i = 1; i <= n; i++)       if (min > m[i]) min = m[i];     if (min >= 0) d.push_back(1);     min -= a[1] - b[n];     for (int i = n; i >= 2; i--) {       if (min >= 0) d.push_back(i);       min -= a[i] - b[i - 1];     }     sort(d.begin(), d.end());     int i = 1;     for (size_t j = 1; j < d.size(); j++)       if (d[j] != d[j - 1]) d[i++] = d[j];     cout << i << endl;     for (int j = 0; j < i; j++)       if (j != i - 1)         cout << d[j] <<    ;       else         cout << d[j] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int inf = 1e9;   int n, m;   int mp[3][N];   char ch[N];   struct node {     int d1, d2, d3, d4;   };   struct tree {     int l, r;     node d;   } t[N * 5];   node merge(node a, node b) {     node tmp;     tmp.d1 = min(inf, min(a.d1 + b.d1, a.d2 + b.d3) + 1);     tmp.d2 = min(inf, min(a.d1 + b.d2, a.d2 + b.d4) + 1);     tmp.d3 = min(inf, min(a.d3 + b.d1, a.d4 + b.d3) + 1);     tmp.d4 = min(inf, min(a.d3 + b.d2, a.d4 + b.d4) + 1);     return tmp;   }   inline void build(int x, int l, int r) {     t[x].l = l, t[x].r = r;     if (l == r) {       t[x].d.d1 = t[x].d.d2 = t[x].d.d3 = t[x].d.d4 = inf;       if (mp[1][l]) t[x].d.d1 = 0;       if (mp[2][l]) t[x].d.d4 = 0;       if (mp[1][l] && mp[2][l]) t[x].d.d2 = t[x].d.d3 = 1;       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     t[x].d = merge(t[x << 1].d, t[x << 1 | 1].d);   }   inline node query(int x, int l, int r) {     if (l == t[x].l && r == t[x].r) return t[x].d;     int mid = (t[x].l + t[x].r) >> 1;     if (r <= mid)       return query(x << 1, l, r);     else if (l > mid)       return query(x << 1 | 1, l, r);     else       return merge(query(x << 1, l, mid), query(x << 1 | 1, mid + 1, r));   }   inline int ask(int x, int y) {     int a = (x - 1) % n + 1, b = (y - 1) % n + 1;     if (a > b) {       swap(x, y);       swap(a, b);     }     node tmp = query(1, a, b);     if (x <= n && y <= n) return tmp.d1;     if (x <= n && y > n) return tmp.d2;     if (x > n && y <= n) return tmp.d3;     if (x > n && y > n) return tmp.d4;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= 2; i++) {       scanf( %s , ch);       for (int j = 1; j <= n; j++)         if (ch[j - 1] ==  . ) mp[i][j] = 1;     }     build(1, 1, n);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       int ans = ask(x, y);       if (ans < inf)         printf( %d n , ans);       else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 0;     cin >> t;     for (int i = 0; i < t; i++) {       long long m = 0;       int n = 0;       cin >> n;       for (int j = n; j > 2; j -= 2) {         m += (2 * pow((j - 1), 2));       }       cout << m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q, a[100010], l[100010], r[100010];   int st[100010], top;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     n--;     for (int i = 1; i <= n; i++) a[i] = abs(a[i + 1] - a[i]);     for (int i = 1; i <= n; i++) {       while (top && a[st[top]] < a[i]) top--;       l[i] = st[top];       st[++top] = i;     }     top = 0;     st[top] = n + 1;     for (int i = n; i >= 1; i--) {       while (top && a[st[top]] <= a[i]) top--;       r[i] = st[top];       st[++top] = i;     }     for (int i = 1; i <= q; i++) {       int L, R;       long long ans = 0;       scanf( %d%d , &L, &R);       if (L >= R) {         puts( 0 );         continue;       }       R--;       for (int j = L; j <= R; j++) {         ans += (long long)(j - max(l[j], L - 1)) * (min(r[j], R + 1) - j) * a[j];       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long b) {     long long t = 1;     if (b == 0) return t;     if (b % 2) {       t = t * a;     }     t %= 1000000009;     long long x = pw(a, b / 2);     x = x * x;     x %= 1000000009;     t *= x;     t %= 1000000009;     return t;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long ti = 1;     for (long long io = 0; io < ti; io++) {       long long n, m, k;       cin >> n >> m >> k;       long long oc = 0, rm;       oc = n / k;       rm = n % k;       long long ans = 0;       if (m > (n - oc)) {         long long x = m - n + oc;         long long y;         y = k;         y = y * ((pw(2, x + 1) - 2) % 1000000009);         y %= 1000000009;         ans += y;         y = k - 1;         y *= (oc - x);         y %= 1000000009;         ans += y;         ans += rm;       } else {         ans = m;       }       ans %= 1000000009;       ans += 1000000009;       ans %= 1000000009;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Solution() {     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; ++i) cnt += (s[i] ==  H );     s += s;     int ans = 0x7fffffff;     for (int i = 0; i < n; ++i) {       int dif = 0;       for (int j = 0; j < cnt; ++j)         if (s[i + j] !=  H ) ++dif;       if (dif < ans) ans = dif;     }     cout << ans << endl;     return 0;   }   int main() {     Solution();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int lcm(int x, int y) { return x * y / gcd(x, y); }   string in;   int check(string s) {     int ret = 0;     while (true) {       bool beforem = s[0] ==  M ;       bool changed = false;       for (int i = 1; i < s.size(); ++i) {         if (s[i] ==  F ) {           if (beforem) {             s[i - 1] =  F ;             s[i] =  M ;             changed = true;           }           beforem = false;         } else {           beforem = true;         }       }       if (!changed) break;       ++ret;     }     return ret;   }   int main() {     cin >> in;     vector<int> times;     int fcnt = 0;     for (int i = 0; i < in.size(); ++i) {       if (in[i] ==  F ) {         if (times.size() == 0) {           if (i == fcnt) {             times.push_back(0);           } else {             times.push_back(i);           }         } else {           if (i == fcnt) {             times.push_back(0);           } else {             int move = i - fcnt;             if (times[times.size() - 1] + 1 <= move) {               times.push_back(move);             } else {               times.push_back(times[times.size() - 1] + 1);             }           }         }         ++fcnt;       }     }     int ret = 0;     for (int i = 0; i < times.size(); ++i) ret = max(ret, times[i]);     printf( %d , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n], cnt = 0, l = 0, r = -1, l3, r3;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] == 0) cnt++;       if (cnt <= k) r++;     }     long long ans = r - l + 1;     l3 = l;     r3 = r;     for (long long i = r + 1; i < n; ++i) {       if (r == n - 1) break;       if (a[i] == 0) {         if (ans < r - l + 1) {           ans = r - l + 1;           l3 = l;           r3 = r;         }         long long l1 = l;         for (long long j = l1; j < n; ++j) {           l++;           if (a[j] == 0) break;         }         r++;       } else         r++;     }     if (ans < r - l + 1) {       ans = r - l + 1;       l3 = l;       r3 = r;     }     cout << ans <<   n ;     for (long long i = 0; i < n; ++i) {       if (i >= l3 && i <= r3)         cout << 1 <<    ;       else         cout << a[i] <<    ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int xd[] = {0, 1, 0, -1};   int yd[] = {1, 0, -1, 0};   int xx[] = {0, 1, 0, -1, 1, -1, 1, -1};   int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};   int kx[] = {-2, -1, -2, -1, 1, 2, 2, 1};   int ky[] = {1, 2, -1, -2, -2, -1, 1, 2};   bool islucky(int x) {     int four = 0, seven = 0;     while (x) {       if (x % 10 != 7 && x % 10 != 4) return false;       if (x % 10 == 7)         seven++;       else         four++;       x = x / 10;     }     return four == seven;   }   bool is_prime(long long x) {     if (x == 1) return false;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   long long C(int k, int l) {     if (l == k) return 1;     if (l * 2 > k) l = k - l;     long long res = 1, temp = l;     for (int i = k - l + 1; i <= k; i++) {       res *= i / temp;       temp--;     }     return res;   }   long long sumOfDigit(int x) {     int res = 0;     while (x) {       res += x % 10;       x /= 10;     }     return res;   }   uint64_t bigPow(uint64_t base, uint64_t p) {     uint64_t temp = 1;     while (p--) {       temp *= base;     }     return temp;   }   vector<int> soso;   bool prime[10000001] = {0};   void SieveOfEratosthenes(int n) {     soso.push_back(2);     for (int p = 3; p * p <= n; p += 2) {       if (prime[p] == false) {         for (int i = p * 2; i <= n; i += p) prime[i] = true;       }     }     for (int i = 3; i <= n; i += 2)       if (!prime[i]) soso.push_back(i);   }   vector<vector<int> > AdjList;   bool visited[100005];   void dfs(int s) {     if (visited[s]) return;     visited[s] = 1;     for (int i = 0; i < AdjList[s].size(); i++) dfs(AdjList[s][i]);     return;   }   long long gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   unsigned long long fact(long long a) {     unsigned long long ans = 1;     for (int i = 1; i <= a; i++) ans *= i;     return ans;   }   bool lucky(int x) {     while (x) {       if (x % 10 == 7) return true;       x /= 10;     }     return false;   }   int main() {     int t;     cin >> t;     while (t--) {       vector<pair<pair<int, int>, int> > q;       int n;       cin >> n;       for (int i = 0; i < n; i++) {         int l, r;         cin >> l >> r;         q.push_back(make_pair(make_pair(l, i), r));       }       sort(q.begin(), q.end());       int w = 0, last = 0;       vector<pair<int, int> > turn;       for (int i = 0; i < q.size(); i++) {         if (q[i].second < max(q[i].first.first, last + 1)) {           turn.push_back(make_pair(q[i].first.second, 0));           w++;         } else {           turn.push_back(               make_pair(q[i].first.second, max(q[i].first.first, last + 1)));           last = max(q[i].first.first, last + 1);         }       }       sort(turn.begin(), turn.end());       for (int i = 0; i < turn.size(); i++) cout << turn[i].second <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int D[100010];   int TN[100010];   vector<int> G[100010];   vector<int> T[100010];   vector<long long int> TS[100010];   map<int, double> S[100010];   struct Furthest {     int s, t, x, maxl, N;     void DFS1(int u, int f, int l) {       if (l > maxl) {         x = u;         maxl = l;       }       TN[u] = N;       for (auto it = G[u].begin(); it != G[u].end(); ++it) {         int v = *it;         if (v != f) DFS1(v, u, l + 1);       }     }     void DFS2(int u, int f, int l) {       if (l > maxl) {         x = u;         maxl = l;       }       if (l > D[u]) D[u] = l;       for (auto it = G[u].begin(); it != G[u].end(); ++it) {         int v = *it;         if (v != f) DFS2(v, u, l + 1);       }     }     void DFS3(int u, int f, int l) {       if (l > D[u]) D[u] = l;       T[N].push_back(D[u]);       for (auto it = G[u].begin(); it != G[u].end(); ++it) {         int v = *it;         if (v != f) DFS3(v, u, l + 1);       }     }     void Find(int u, int n) {       N = n;       maxl = -1;       DFS1(u, -1, 0);       s = x;       maxl = -1;       DFS2(s, -1, 0);       t = x;       DFS3(t, -1, 0);       sort(T[N].begin(), T[N].end());       TS[N].push_back(0);       for (int i = 1; i <= T[N].size(); ++i)         TS[N].push_back(T[N][i - 1] + TS[N][i - 1]);       if (D[t] != D[s]) cout <<  Wrong!  << endl;     }   };   Furthest fest;   int main() {     ios::sync_with_stdio(false);     int n, m, q, i, j, k, x, y, cnt, u, v;     cin >> n >> m >> q;     for (i = 0; i < m; ++i) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     cnt = 0;     memset(D, 0xFF, sizeof(D));     for (i = 1; i <= n; ++i)       if (D[i] < 0) fest.Find(i, cnt++);     for (i = 0; i < q; ++i) {       cin >> u >> v;       x = TN[u];       y = TN[v];       if (x == y)         cout << -1 << endl;       else {         if (T[x].size() > T[y].size()) swap(x, y);         if (S[x].find(y) != S[x].end())           cout << S[x][y] << endl;         else {           int minv, maxl;           double sum = 0;           for (j = 0; j < T[x].size(); ++j) {             u = T[x][j];             maxl = max(*T[x].rbegin(), *T[y].rbegin());             minv = maxl - u;             k = lower_bound(T[y].begin(), T[y].end(), minv) - T[y].begin();             sum += (long long int)maxl * k + *TS[y].rbegin() - TS[y][k] +                    (T[y].size() - k) * (u + 1);           }           sum /= T[x].size() * T[y].size();           S[x][y] = sum;           cout << fixed << setprecision(10) << sum << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char s[111];   void dfs(int id, int d) {     if (id >= n) return;     if (s[id] ==  * )       cnt++;     else       return;     dfs(id + d, d);   }   int main() {     scanf( %d n , &n);     gets(s);     bool fl = 0;     for (int i = 0; i < n; ++i) {       for (int d = 1; d <= n; ++d) {         cnt = 0;         dfs(i, d);         if (cnt >= 5) fl = 1;       }     }     if (fl) {       puts( yes );     } else       puts( no );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NR = 5005;   void Min(int& x, int y) { x = min(x, y); }   void Max(int& x, int y) { x = max(x, y); }   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int n, m;   char s[NR << 1];   int sa[NR << 1], id[NR << 1];   int rk[NR << 1], lark[NR << 1];   int cnt[NR];   int h[NR << 1];   int dp[NR << 1];   int mn[NR][NR];   void work() {     memset(s, 0, sizeof(s));     memset(sa, 0, sizeof(sa));     memset(rk, 0, sizeof(rk));     n = read(), scanf( %s , s + 1);     m = max(n, 300);     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; i++) cnt[rk[i] = s[i]]++;     for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];     for (int i = n; i >= 1; i--) sa[cnt[rk[i]]--] = i;     for (int w = 1; w < n; w <<= 1) {       memset(cnt, 0, sizeof(cnt));       int p = 0;       for (int i = n - w + 1; i <= n; i++) id[++p] = i;       for (int i = 1; i <= n; i++)         if (sa[i] > w) id[++p] = sa[i] - w;       for (int i = 1; i <= n; i++) cnt[rk[id[i]]]++;       for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];       for (int i = n; i >= 1; i--) sa[cnt[rk[id[i]]]--] = id[i];       memcpy(lark, rk, sizeof(lark));       rk[sa[1]] = m = 1;       for (int i = 2; i <= n; i++) {         if (lark[sa[i]] == lark[sa[i - 1]] &&             lark[sa[i] + w] == lark[sa[i - 1] + w])           rk[sa[i]] = m;         else           rk[sa[i]] = ++m;       }     }     memset(h, 0, sizeof(h));     int lcp = 0;     for (int i = 1; i <= n; i++) {       if (lcp) lcp--;       while (s[i + lcp] == s[sa[rk[i] - 1] + lcp]) lcp++;       h[rk[i]] = lcp;     }     for (int i = 1; i <= n; i++) {       mn[i][i] = h[i];       for (int j = i + 1; j <= n; j++) mn[i][j] = min(mn[i][j - 1], h[j]);     }     int ans = 0;     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++) {       int len = dp[i] = n - i + 1;       for (int j = 1; j < i; j++) {         if (rk[i] < rk[j]) continue;         dp[i] = max(dp[i], dp[j] + len - mn[rk[j] + 1][rk[i]]);       }       ans = max(ans, dp[i]);     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) mn[i][j] = 0;   }   int main() {     int T = read();     while (T--) work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long n, a[100010];   int main() {     long long n, mx = 0, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > mx) mx = a[i];       sum += a[i];     }     long long s = (sum + n - 2) / (n - 1);     if (mx > s) s = mx;     cout << s <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, tr;     cin >> n >> m;     vector<long long> a, b;     for (int i = 1; i <= n; i++) {       cin >> tr;       a.push_back(tr);     }     for (int i = 1; i <= m; i++) {       cin >> tr;       b.push_back(tr);     }     long long max, ans = LONG_LONG_MAX;     for (int i = 0; i < n; i++) {       max = LONG_LONG_MIN;       for (int j = 0; j < n; j++) {         if (j == i) continue;         for (int k = 0; k < m; k++) {           if (a[j] * b[k] > max) max = a[j] * b[k];         }       }       if (max < ans) ans = max;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> m;   int main() {     int n, k;     cin >> n >> k;     int e = 0;     for (int i = 1; i < k; i++) {       string t =   ;       t += char( A  + e / 26);       t += char( a  + e % 26);       e++;       m.push_back(t);     }     for (int i = k; i <= n; i++) {       string s;       cin >> s;       if (s ==  YES ) {         string t =   ;         t += char( A  + e / 26);         t += char( a  + e % 26);         e++;         m.push_back(t);       } else {         m.push_back(m[i - k]);       }     }     for (string &s : m) std::cout << s <<    ;   }