malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <iostream>   #include <string>   #include <vector>      constexpr int N = 1000005;   constexpr int p = 1000000007;      inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }   inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }   inline int mul(int x, int y) { return (long long)x * y % p; }   inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }      int n, q, k;   std::string s0, t, w;   int pow2[N], nxt[N];   int sum[N][26];   std::vector<std::string> str;      int main() {       std::ios::sync_with_stdio(false), std::cin.tie(nullptr);       std::cin >> n >> q;       std::cin >> s0 >> t;       pow2[0] = 1;       for (int i = 1; i <= n; ++i) pow2[i] = add(pow2[i - 1], pow2[i - 1]);       for (int i = 1; i <= n; ++i) {           for (int j = 0; j < 26; ++j) sum[i][j] = sum[i - 1][j];           sum[i][t[i - 1] -  a ] = add(sum[i][t[i - 1] -  a ], power(pow2[i], p - 2));       }       std::string tmp = s0;       str.push_back(tmp);       int x = 0;       while (tmp.length() < N << 1) {           tmp = tmp + t[x++] + tmp;           str.push_back(tmp);       }       while (q--) {           std::cin >> k >> w;           int x = 0;           while (str[x].length() < w.length() && x < k) ++x;           nxt[0] = -1;           int now = -1;           for (int i = 1; i < w.length(); ++i) {               while (~now && w[now + 1] != w[i]) now = nxt[now];               if (w[now + 1] == w[i]) ++now;               nxt[i] = now;           }           now = -1;           int cnt0 = 0;           std::string& s = str[x];           for (int i = 0; i < s.length(); ++i) {               while (~now && w[now + 1] != s[i]) now = nxt[now];               if (w[now + 1] == s[i]) ++now;               if (now == w.length() - 1) {                   ++cnt0;                   now = nxt[now];               }           }           int index = s.length();           int ans = mul(cnt0, power(pow2[x], p - 2));           for (int i = 0; i < 26; ++i) {               int cnt = -cnt0 << 1;               now = -1;               for (int j = 0; j < str[x + 1].length(); ++j) {                   char tmp = str[x + 1][j];                   if (j == index) tmp =  a  + i;                   while (~now && w[now + 1] != tmp) now = nxt[now];                   if (w[now + 1] == tmp) ++now;                   if (now == w.length() - 1) {                       ++cnt;                       now = nxt[now];                   }               }               ans = add(ans, mul(cnt, sub(sum[k][i], sum[x][i])));           }           std::cout << mul(ans, pow2[k]) <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   int a[] = {0,       2,       3,       5,       7,        13,      17,              19,      31,      61,      89,      107,      127,     521,              607,     1279,    2203,    2281,    3217,     4253,    4423,              9689,    9941,    11213,   19937,   21701,    23209,   44497,              86243,   110503,  132049,  216091,  756839,   859433,  1257787,              1398269, 2976221, 3021377, 6972593, 13466917, 20996011};   int main() {     int n, p = 1;     long long ans = 1;     scanf( %d , &n);     a[n]--;     while (p <= a[n]) p <<= 1;     p >>= 1;     while (p) {       ans = ans * ans % 1000000007;       if (p & a[n]) ans = ans * 2 % 1000000007;       p >>= 1;     }     ans = (ans + 1000000006) % 1000000007;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     if (s.length() == 0) return vector<string>();     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) {       v.emplace_back(x);     }     return std::move(v);   }   vector<int> splitInt(const string& s, char c) {     if (s.length() == 0) return vector<int>();     vector<int> v;     stringstream ss(s);     int x;     string str;     while (getline(ss, str, c)) {       stringstream si(str);       si >> x;       v.emplace_back(x);     }     return std::move(v);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 0;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       vector<int> arr(n, 0);       for (int i = 0; i < n; ++i) cin >> arr[i];       vector<long long> seen(3001, 0);       vector<vector<long long>> left(3001);       for (int i = 0; i < n; ++i) {         seen[arr[i]]++;         left[i] = seen;       }       seen = vector<long long>(3001, 0);       vector<vector<long long>> right(3001);       for (int i = n - 1; i >= 0; --i) {         seen[arr[i]]++;         right[i] = seen;       }       long long count = 0;       for (int j = 1; j < n; ++j) {         for (int k = j + 1; k + 1 < n; ++k) {           int aj = arr[j];           int ak = arr[k];           if (j - 1 >= 0 && k + 1 < n) {             count += left[j - 1][ak] * right[k + 1][aj];           }         }       }       cout << count <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int compare(const void* x1, const void* x2) { return (*(int*)x1 - *(int*)x2); }   int main() {     int n, a;     cin >> n >> a;     int k = n / 2;     if (a % 2 == 1)       cout << a / 2 + 1;     else       cout << (k - a / 2 + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, d, T;   int main() {     cin >> T;     while (T--) {       cin >> n >> x >> y >> d;       int sum;       if ((abs(y - x)) % d == 0 || (n - y) % d == 0 || (y - 1) % d == 0) {         if ((abs(y - x)) % d == 0)           sum = (abs(y - x)) / d;         else {           int sxl, sxr;           if ((x - 1) % d)             sxl = (x - 1) / d + 1;           else             sxl = (x - 1) / d;           if ((n - x) % d)             sxr = (n - x) / d + 1;           else             sxr = (n - x) / d;           int fl = (y - 1) % d, fr = (n - y) % d;           if (fl == 0 && fr != 0) sum = sxl + (y - 1) / d;           if (fl != 0 && fr == 0) sum = sxr + (n - y) / d;           if (fl == 0 && fr == 0) {             sum = min(sxl + (y - 1) / d, sxr + (n - y) / d);           }         }         cout << sum << endl;       } else         cout <<  -1  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[100001];     int a[100001], m, l, r;     scanf( %s%d , s, &m);     int len = strlen(s);     a[1] = 0;     for (int i = 1; i < len; ++i) {       if (s[i] == s[i - 1]) {         a[i + 1] = a[i] + 1;       } else {         a[i + 1] = a[i];       }     }     while (m--) {       scanf( %d%d , &l, &r);       printf( %d n , a[r] - a[l]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int vocala(char c) {     if (c ==  a  || c ==  A  || c ==  e  || c ==  E  || c ==  i  || c ==  I  ||         c ==  o  || c ==  O  || c ==  u  || c ==  U )       return 1;     if (c ==  y  || c ==  Y ) return 1;     return 0;   }   int isprime(long long n) {     if (n <= 1) return 0;     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   int isfibo(long long n) {     long long a = 5 * n * n + 4;     long long b = a - 8;     if (sqrt(a) == int(sqrt(a)) || sqrt(b) == int(sqrt(b))) return 1;     return 0;   }   int gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   ifstream in( input.txt );   ofstream out( output.txt );   long long const nrmax = 1e18;   long long v[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     long long cnt = 3e9;     sort(v + 1, v + n + 1);     cnt = min(cnt, v[n] - v[2]);     cnt = min(cnt, v[n - 1] - v[1]);     cout << cnt <<   n ;     in.close();     out.close();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using vv = vector<vector<T>>;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &t) {     os <<  { ;     for (int(i) = 0; (i) < (t.size()); ++(i)) {       os << t[i] <<  , ;     }     os <<  }  << endl;     return os;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &t) {     return os <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <class T>   inline bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   vector<string> s_p_l_i_t(const string &s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void e_r_r(vector<string>::iterator it) {}   template <typename T, typename... Args>   void e_r_r(vector<string>::iterator it, T a, Args... args) {     if (*it ==   1  || *it ==  1 )       cerr << endl;     else       cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     e_r_r(++it, args...);   }   const long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(0);     int n;     cin >> n;     cout <<  YES  << endl;     int a, b, c, d;     for (int(i) = 0; (i) < (n); ++(i)) {       cin >> a >> b >> c >> d;       cout << abs(a) % 2 * 2 + abs(b) % 2 + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     cin >> n >> p;     string s;     cin >> s;     if (p > s.length() / 2) {       reverse(s.begin(), s.end());       p = (n - p) + 1;     }     int sum = 0;     int t[n], l = -1, r = 0;     for (int i = 0; i < s.length() / 2; i++) {       if (abs(int(s[i]) - int(s[n - i - 1])) > 13) {         t[i] = 26 - abs(int(s[i]) - int(s[n - i - 1]));       } else {         t[i] = abs(int(s[i]) - int(s[n - i - 1]));       }       if (t[i] > 0) {         r = i;         if (l < 0) {           l = i;         }       }       sum += t[i];     }     p--;     if (l <= p && p <= r && p - l > r - p) {       sum += r - p + r - l;     } else if (l <= p && p <= r && p - l <= r - p) {       sum += p - l + r - l;     } else if (p <= l) {       sum += r - p;     } else if (r <= p) {       sum += p - l;     }     if (l < 0) {       cout << 0;     } else {       cout << sum;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d, x, y, g, h, i, j, k, n, t, z = 0, l, r, u;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) cout << 1 <<    ;       cout << endl;     }   }
#include<bits/stdc++.h>   #define mp make_pair   #define pr pair<int,int>   #define pb push_back   using namespace std;   int k[100005],all[200005];   vector<int>a[100005];   struct nd{    int val,id;    nd(){}    nd(int val,int id):val(val),id(id){}    bool operator <(const nd &x)const{     return val<x.val;    }   };   vector<nd>w[200005];   int prew[200005];   int vis[200005];   int main(){    int t;    scanf( %d ,&t);    while(t--){     int n;     scanf( %d ,&n);     for(int i=0;i<n;i++)a[i].clear();     for(int i=0;i<n;i++){      scanf( %d ,&k[i]);      a[i].resize(k[i]);      for(int j=0;j<k[i];j++)scanf( %d ,&a[i][j]);   //   for(int j=0;j<k[i];j++){   //    int x;   //    scanf( %d ,&x);   //    a[i].pb(x);   //   }      sort(a[i].begin(),a[i].end());     }     int m=0;     for(int i=0;i<n;i++)for(int j=0;j<k[i];j++)all[m++]=a[i][j];     sort(all,all+m);     int len=unique(all,all+m)-all;     for(int i=0;i<len;i++)w[i].clear();     for(int i=0;i<n;i++)for(int j=0;j<k[i];j++)a[i][j]=lower_bound(all,all+len,a[i][j])-all;     int D=sqrt(m)/6;     int flag=0;     for(int i=0;i<len;i++)vis[i]=0;     for(int i=0;i<n;i++){      if(k[i]>D){       for(int j=0;j<k[i];j++)vis[a[i][j]]=1;       for(int j=0;j<n;j++)if(j!=i){        int cnt=0;        for(int l=0;l<k[j];l++)if(vis[a[j][l]])cnt++;        if(cnt>=2){         flag=1;         printf( %d %d n ,i+1,j+1);         break;        }       }       if(flag)break;       for(int j=0;j<k[i];j++)vis[a[i][j]]=0;      }     }      if(flag)continue;   //  for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)prew[a[i][j]]++;   //  for(int i=0;i<len;i++)w[i].resize(prew[i]);   //  for(int i=0;i<len;i++)prew[i]=0;   //  for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)w[a[i][j]][prew[a[i][j]]++]=mp(a[i][l],i);     for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)w[a[i][j]].pb(nd(a[i][l],i));     for(int i=0;i<len;i++)sort(w[i].begin(),w[i].end());     for(int i=0;i<len;i++){      int l=w[i].size();      for(int j=0;j<l-1;j++)if(w[i][j].val==w[i][j+1].val && w[i][j].id!=w[i][j+1].id){       flag=1;       printf( %d %d n ,w[i][j].id+1,w[i][j+1].id+1);       break;      }       if(flag)break;     }     if(!flag)printf( -1 n );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   vector<int> v[maxn], w[maxn];   long long a[maxn];   bool d[maxn];   long long c[maxn][5];   long long n, m;   bool mark[maxn][2];   void dfs1(long long i) {     c[i][0] = 1;     mark[i][0] = 1;     for (long long y = 0; y < v[i].size(); y++) {       if (!mark[v[i][y]][0]) {         dfs1(v[i][y]);       }     }   }   void dfs2(long long i) {     mark[i][1] = 1;     c[i][1] = 1;     if (a[i] == 1) return;     for (long long y = 0; y < w[i].size(); y++) {       if (!mark[w[i][y]][1]) {         dfs2(w[i][y]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (long long y = 1; y <= n; y++) {       cin >> a[y];       if (a[y] == 1) {         v[100000 + 1].push_back(y);       }       if (a[y] == 2) {         w[100000 + 1].push_back(y);       }     }     while (m--) {       long long i, j;       cin >> i >> j;       v[i].push_back(j);       w[j].push_back(i);     }     dfs1(100000 + 1);     dfs2(100000 + 1);     for (long long y = 1; y <= n; y++) {       cout << (c[y][0] && c[y][1]) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p1, p2, tot1, tot2;   long long L, W, ans, a[100005], b[100005];   int main() {     scanf( %d%lld%lld , &n, &L, &W);     long long t;     int v;     for (int i = 1; i <= n; ++i) {       scanf( %lld%d , &t, &v);       if (v == 1)         a[++tot1] = t;       else         b[++tot2] = t;     }     sort(a + 1, a + tot1 + 1), sort(b + 1, b + tot2 + 1);     for (p1 = p2 = 1; p1 <= tot1; ++p1) {       while (p2 <= tot2 && (b[p2] - a[p1] + L) * W <= abs(b[p2] + a[p1] + L) &&              (p2++, 1))         ;       ans += tot2 - p2 + 1;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 1e2 + 10;   vector<long long> g[N];   void dfs(long long node, long long par, long long dd, vector<long long>& fre) {     fre[dd]++;     for (auto x : g[node])       if (x != par) dfs(x, node, dd + 1, fre);   }   long long n, k;   long long get(vector<long long>& arr) {     vector<long long> cur(k + 1, 0);     cur[0] = 1;     for (auto x : arr) {       for (long long i = k; i >= 1; i--) {         cur[i] += cur[i - 1] * x;         cur[i] %= MOD;       }     }     return cur[k];   }   long long solve(long long x) {     long long sz = g[x].size();     vector<vector<long long> > go(sz, vector<long long>(n + 1, 0));     for (long long i = 0; i < sz; i++) dfs(g[x][i], x, 1, go[i]);     long long res = 0;     for (long long i = 1; i <= n; i++) {       vector<long long> arr;       for (auto v : go)         if (v[i] > 0) arr.push_back(v[i]);       res += get(arr);       res %= MOD;     }     return res;   }   void solve() {     cin >> n >> k;     long long u, v;     for (long long i = 0; i < n - 1; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     long long res = 0;     if (k == 2) {       res = (n * (n - 1)) / 2;       res %= MOD;     } else {       for (long long i = 1; i <= n; i++) {         res += solve(i);         res %= MOD;       }     }     cout << res <<   n ;     for (long long i = 1; i <= n; i++) g[i].clear();   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return a < b ? b : a;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   const char lf =   n ;   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0;     int b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 123, mo = 1000000007;   int n, m, ps, cnts[_] = {0};   long long ans = 0;   bitset<_> alls;   inline bitset<_> rshl(bitset<_> a, int d) {     d %= m;     return ((a << d) | (a >> (m - d))) & alls;   }   inline bitset<_> rshr(bitset<_> a, int d) {     d %= m;     return ((a >> d) | (a << (m - d))) & alls;   }   void dfs(bitset<_> now, int las, long long d) {     ans = (ans + d) % mo;     for (int i = las; i + i <= m; i++)       if (cnts[i] && !now[i] && !now[m - i])         dfs(now | rshl(now, i) | rshr(now, i), i + 1, d * cnts[i] % mo);   }   int main() {     ios::sync_with_stdio(0), cout.tie(nullptr);     n = ty(), m = ty(), ps = ty();     for (int i = 1; i <= ps; i++) {       int a = ty() % m;       cnts[min(a, m - a)]++;     }     bitset<_> temp = 0;     temp[0] = 1;     alls = 0;     for (int i = 0; i < m; i++) alls[i] = 1;     dfs(temp, 0, 1), cout << ans << lf;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long price[200002];   long long a, b, x, y, k;   long long gcd(long long aa, long long bb) {     return (bb != 0) ? gcd(bb, aa % bb) : aa;   }   bool check(long long mid) {     long long tt = mid / (a * b / gcd(a, b));     long long ta = mid / a;     long long tb = mid / b;     long long total = 0;     for (int i = 1; i <= tt; i++) {       total += price[i] * (x + y);     }     for (int i = tt + 1; i <= ta; i++) {       total += price[i] * x;     }     for (int i = ta + 1; i <= ta + tb - tt; i++) {       total += price[i] * y;     }     if (total >= k) {       return true;     }     return false;   }   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> price[i + 1];         price[i + 1] /= 100;       }       sort(price + 1, price + n + 1, greater<int>());       cin >> x >> a >> y >> b;       cin >> k;       if (x < y) {         swap(x, y);         swap(a, b);       }       int l = 1, r = n, res = -1;       while (l <= r) {         int mid = (l + r) >> 1;         if (check(mid)) {           res = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 2005;   long long n, K, ans, sum, sum2, f[N][N], g[N];   long long kuai(long long a, long long b) {     if (b == 0) return 1ll;     if (b == 1) return a;     long long x = kuai(a, b / 2);     if (b % 2 == 0) return x * x % mod;     return x * x % mod * a % mod;   }   signed main() {     scanf( %lld%lld , &n, &K);     K--;     for (long long i = 1; i <= n; i++) {       sum = 2;       f[i][1] = 2;       for (long long j = 2; j <= i; j++) {         f[i][j] = f[i][j - 1] * 2 % mod;         sum = (sum + f[i][j]) % mod;       }       for (long long j = i + 1; j <= n; j++) {         f[i][j] = sum;         sum = ((sum - f[i][j - i] + f[i][j]) % mod + mod) % mod;       }     }     for (long long i = 1; i <= n; i++) {       long long k = K / i;       k = min(k, n);       if (k == 0) continue;       sum2 = 2;       g[1] = 2;       for (long long j = 2; j <= k; j++) {         g[j] = g[j - 1] * 2 % mod;         sum2 = (sum2 + g[j]) % mod;       }       for (long long j = k + 1; j <= n; j++) {         g[j] = sum2;         sum2 = ((sum2 - g[j - k] + g[j]) % mod + mod) % mod;       }       ans = (ans + g[n] * (f[i][n] - f[i - 1][n] + mod) % mod) % mod;     }     cout << ans * kuai(2, mod - 2) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string ss[100];     int n, ans = 0, cur;     cin >> n;     for (int i = 0; i < n; i++) cin >> ss[i];     for (char a =  a ; a <=  z ; a++)       for (char b =  a ; b <=  z ; b++) {         cur = 0;         for (int i = 0; i < n; i++) {           int l = ss[i].length();           bool ok = true;           while (l--) {             if (ss[i][l] != a && ss[i][l] != b) ok = false;           }           if (ok) cur += ss[i].length();         }         ans = max(ans, cur);       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int N;     cin >> N;     int suma = 0;     vector<int> a(N);     for (int i = 0; i < N; ++i) {       cin >> a[i];       suma += a[i];     }     if (suma == 1) {       cout << -1 << endl;     } else {       long long answer = LONG_LONG_MAX;       for (int tk = 2; tk <= suma; ++tk) {         if (suma % tk == 0) {           int currenti = 0;           long long cans = 0;           while (currenti < N) {             int currentsum = 0;             int median = -1;             int starti = currenti;             while (currentsum < tk) {               currentsum += a[currenti];               if (a[currenti] == 1 && currentsum == (tk + 1) / 2) {                 median = currenti;               }               currenti++;             }             long long steps = 0;             for (int i = starti; i < currenti; ++i) {               if (a[i] == 1) {                 steps += abs(median - i);               }             }             cans += steps;           }           answer = min(answer, cans);         }       }       cout << answer << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long DIM = 2e5 + 7;   long long n, used[27][DIM], a[DIM], tests;   int in;   int main() {     in = scanf( %lld , &tests);     for (long long test = 1; test <= tests; test++) {       in = scanf( %lld , &n);       long long result = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= 26; j++) {           used[j][i] = used[j][i - 1];         }         in = scanf( %lld , &a[i]);         used[a[i]][i]++;       }       for (long long i = 1; i <= 26; i++) result = max(result, used[i][n]);       long long cntin = 0, cntout = 0;       for (long long l = 1; l <= n; l++) {         for (long long r = l; r <= n; r++) {           cntin = 0;           cntout = 0;           for (long long x = 1; x <= 26; x++) {             cntin = max(cntin, used[x][r] - used[x][l - 1]);           }           for (long long x = 1; x <= 26; x++)             cntout =                 max(cntout, min(used[x][l - 1], used[x][n] - used[x][r]) * 2);           result = max(result, cntout + cntin);         }       }       printf( %lld n , result);       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= 26; j++) {           used[j][i] = 0;         }       }     }     return 0;   }