malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long a, long long b) {     if (b == 0) return 1;     if (!(b & 1)) {       long long ret = bigmod(a, b / 2);       return ((ret % 1000000007) * (ret % 1000000007)) % 1000000007;     } else       return ((a % 1000000007) * (bigmod(a, b - 1) % 1000000007)) % 1000000007;   }   bool cmp(pair<int, int> p1, pair<int, int> p2) {     if (p1.first != p2.first) return p1.first < p1.first;     return p1.second < p2.second;   }   bool approximatelyEqual(float a, float b, float epsilon) {     return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool essentiallyEqual(float a, float b, float epsilon) {     return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool definitelyGreaterThan(float a, float b, float epsilon) {     return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool definitelyLessThan(float a, float b, float epsilon) {     return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool cmp1(pair<int, int> p1, pair<int, int> p2) {     return p1.second < p2.second;   }   bool cmp2(pair<int, int> p1, pair<int, int> p2) {     return p1.second > p2.second;   }   int main() {     int t, tc = 1, a, b, c, m, n, i, j, k, p, q;     char s[500000];     vector<pair<int, int> > u, v;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &c);       u.push_back(pair<int, int>(i, c));       v.push_back(pair<int, int>(i, c));     }     getchar();     scanf( %s , s);     sort(u.begin(), u.end(), cmp1);     k = 0, b = 0;     vector<int> ans;     stack<int> st;     int oc[200001] = {0};     int pp;     for (i = 0; s[i]; i++) {       if (s[i] ==  0 ) {         ans.push_back(u[k].first + 1);         st.push(k);         k++;       } else {         int xx = st.top();         st.pop();         ans.push_back(u[xx].first + 1);       }     }     for (i = 0; i < ans.size(); i++) {       i != ans.size() - 1 ? printf( %d  , ans[i]) : printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fact[100005];   bitset<100005> p;   int cnt[100005];   int best[100005];   int arr[100005];   int bestFactor(int n) {     if (fact[n] == 0) {       return n;     }     int curFactor = fact[n];     int bestChildFactor = bestFactor(n / curFactor);     if (best[curFactor] == -1) {       return bestChildFactor;     }     if (best[bestChildFactor] == -1) {       return curFactor;     }     if (cnt[best[curFactor]] > cnt[best[bestChildFactor]]) {       return curFactor;     }     return bestChildFactor;   }   void updateFactors(int n, int idx) {     if (fact[n] == 0) {       best[n] = idx;       return;     }     best[fact[n]] = idx;     return updateFactors(n / fact[n], idx);   }   int main() {     memset(best, -1, sizeof best);     p.set();     p[0] = p[1] = false;     for (int i = 2, to = sqrt(100005) + 1; i <= to; i++) {       if (p[i]) {         for (int j = i * i; j < 100005; j += i) {           if (fact[j] == 0) fact[j] = i;           p[j] = false;         }       }     }     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       cnt[i] = 1;     }     updateFactors(arr[0], 0);     int maxi = 1;     for (int i = 1; i < n; i++) {       int bestFact = bestFactor(arr[i]);       if (best[bestFact] != -1) {         cnt[i] = cnt[best[bestFact]] + 1;         maxi = max(maxi, cnt[i]);       }       updateFactors(arr[i], i);     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     cin >> t;     while (t--) {       string n, k;       cin >> n >> k;       string A, B, C, other;       for (int i = 0; i < n.size(); i++) {         if (n[i] ==  a )           A.push_back( a );         else if (n[i] ==  b )           B.push_back( b );         else if (n[i] ==  c )           C.push_back( c );         else           other.push_back(n[i]);       }       sort(n.begin(), n.end());       sort(other.begin(), other.end());       if (A.size() == 0 || B.size() == 0 || C.size() == 0)         cout << n;       else {         if (k[0] ==  a ) {           if (k[1] ==  b )             cout << A << C << B;           else             cout << A << B << C;         } else {           cout << A << B << C;         }         if (other.size() != 0) cout << other;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         if (j % i == 0 && i * j > n && j < n * i) return cout << j <<     << i, 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     int n;     cin >> n;     vector<long long> v(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long ans = (v[n - 1] - v[0]) * (v[2 * n - 1] - v[n]);     long long minx = 1e9 + 10;     for (int i = 0; i < n; i++) {       long long k = v[n + i - 1] - v[i];       minx = min(minx, k);     }     long long k = (v[2 * n - 1] - v[0]) * minx;     cout << (long long)min(ans, k);   }
#include <bits/stdc++.h>   using namespace std;   int facts[1002][3], v[1002];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> facts[i][0] >> facts[i][1] >> facts[i][2];       if (facts[i][0] == 1) {         for (int j = facts[i][1]; j < facts[i][2]; ++j) v[j] = 1;       }     }     for (int i = 1; i <= m; ++i) {       bool verif = false;       if (facts[i][0] == 0) {         for (int j = facts[i][1]; j < facts[i][2]; ++j)           if (v[j] == 0) {             verif = true;             break;           }         if (verif == false) {           cout <<  NO  << endl;           return 0;         }       }     }     int y = n + 1;     cout <<  YES  << endl;     for (int i = 1; i <= n; ++i) {       if (v[i - 1] == 1)         cout << y <<    ;       else         cout << --y <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(int cases) {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int su = 0;     for (int i = 0; i < n; i++) su += a[i];     sort(a, a + n);     if (su == 0) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     if (su > 0) {       for (int i = 0; i < n; i++) cout << a[n - 1 - i] <<    ;       cout <<   n ;       return;     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int cases = 1;     int t = 1;     cin >> t;     while (t--) {       solve(cases++);     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, c;     cin >> a >> b >> c;     if (a + c <= b)       puts( 0 );     else {       int a2 = max(((a + b + c) >> 1) + 1, a);       a += c;       cout << a - a2 + 1 << endl;     }     return;   }   int main() {     int T;     cin >> T;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int NN = 111 * 1000;   int n, a, d;   int t[NN], v[NN];   int main() {     ios::sync_with_stdio(false);     cin >> n >> a >> d;     for (int i = 0; i < n; i++) {       cin >> t[i] >> v[i];     }     double Max = -1.;     for (int i = 0; i < n; i++) {       double v2 = (double)v[i] * v[i];       double dx = v2 / a / 2.;       dx = min((double)d, dx);       double tl = sqrt(dx * 2. / a);       double tr = (d - dx) / v[i];       double t_cur = t[i] + tl + tr;       Max = max(Max, t_cur);       printf( %.16f n , Max);     }   }
#include <bits/stdc++.h>   using namespace std;   using ld = long double;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   const int oo = 1e9 + 7;   const ll loo = 1e18;   ll modpow(ll a, ll b) {     ll res = 1;     while (b) {       if (b & 1) res = res * a % oo;       a = a * a % oo;       b /= 2;     }     return res;   }   ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 5e5 + 7;   int n, k, m;   using point = complex<ll>;   point p[N];   ld dist[N];   vector<int> arms[N];   int gr[N];   int num;   ld cross(point a, point b) { return (conj(a) * b).imag(); }   ld dot(point a, point b) { return (conj(a) * b).real(); }   void input() {     map<pair<ll, ll>, int> id;     m = 0;     for (int i = 0; i < n; i++) {       ll a, b;       cin >> a >> b;       p[i] = point(a, b);       dist[i] = sqrt(dot(p[i], p[i]));       if (a == 0 && b == 0) continue;       ll g = gcd(abs(a), abs(b));       pair<ll, ll> ash = make_pair(a / g, b / g);       if (!id.count(ash)) id[ash] = m++;       arms[id[ash]].push_back(i);       gr[i] = id[ash];     }     for (int i = 0; i < m; i++) {       sort(begin(arms[i]), end(arms[i]),            [&](int i, int j) { return dist[i] < dist[j]; });     }   }   ld option1() {     priority_queue<pair<ld, int>> pq;     for (int i = 0; i < m; i++) {       for (int t = 0; t < min(k / 2, (int)arms[i].size()); t++) {         ld wei = (k - 2 * t - 1) * dist[arms[i][arms[i].size() - 1 - t]];         pq.push(make_pair(wei, arms[i][arms[i].size() - 1 - t]));       }     }     for (int i = 0; i < n; i++)       if (p[i] == point(0)) {         pq.push(make_pair(0, i));       }     ld ans = 0;     while (pq.size() && num < k) {       auto pp = pq.top();       pq.pop();       ans += pp.first;       num++;     }     return ans;   }   ld option2(int i, ld ans) {     int half = k / 2;     int s = num - half;     for (int t = 0; t < arms[i].size() - half; t++) {       ans += dist[arms[i][t]] * ((t + s) - (k - 1 - t - s));       if (t + 1 + num == k) break;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     input();     ld ans = option1();     if (num < k) {       ld res = 0;       for (int i = 0; i < m; i++)         if (2 * (n - arms[i].size()) <= k) {           res = max(res, option2(i, ans));         }       ans = res;     }     cout << setprecision(40) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Size = 1024;   const int mod = 998244353;   const int INF = 2147483647;   const int maxn = 1e5 + 15;   int a[maxn];   int main() {     int n, x, y, i, f, j;     scanf( %d%d%d , &n, &x, &y);     for (i = 1; n >= i; i++) {       scanf( %d , &a[i]);     }     for (i = 1; n >= i; i++) {       f = 0;       for (j = 1; x >= j && i - j >= 1; j++) {         if (a[i] < a[i - j])           continue;         else           f = 1;       }       for (j = 1; y >= j && i + j <= n; j++) {         if (a[i] < a[i + j])           continue;         else           f = 1;       }       if (f == 0) {         printf( %d n , i);         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n, w, b;   const long long int mod = 1000000009;   int C[4005][4005];   int main() {     for (int i = 0; i < 4003; ++i) {       C[i][0] = 1;       for (int j = 0; j < i; ++j)         C[i][j + 1] = (C[i - 1][j + 1] + C[i - 1][j]) % mod;     }     cin >> n >> w >> b;     long long int res = 0;     for (int l = 1; l < n - 1; ++l)       for (int r = l + 1; r < n; ++r) {         int len = r - l, wlen = n - len;         if (b - len < 0 || w - wlen < 0) continue;         res += C[b - 1][b - len] * (long long int)C[w - 1][w - wlen] % mod;         res %= mod;       }     for (int i = 0; i < w; ++i) res = res * (i + 1) % mod;     for (int i = 0; i < b; ++i) res = res * (i + 1) % mod;     cout << res << endl;     return 0;   }
#include<bits/stdc++.h>   #define fo(i,a,b) for(int i=(a);i<=(b);++i)   #define fd(i,a,b) for(int i=(a);i>=(b);--i)   #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)   using namespace std;   typedef long long ll;   const int maxn = 1e6 + 5;   const ll mod = 1e9 + 7;   int t, m, n, k;   vector<int>e[maxn];   int d[maxn], val[maxn];   void D() {    queue<int>q;    q.push(1);    while (!q.empty()) {     int u = q.front(); q.pop();     for (auto& v : e[u]) {      if (d[v] == -1) {       d[v] = d[u] + 1;       q.push(v);      }     }    }   }   int f(int u) {    if (val[u] != -1)return val[u];    val[u] = d[u];    for (auto& v : e[u]) {     if (d[v] > d[u])val[u] = min(val[u], f(v));     else val[u] = min(val[u], d[v]);    }    return val[u];   }   int main() {    IOS;    cin >> t;    while (t--) {     cin >> n >> m;     fo(i, 1, n)e[i].clear(), d[i] = val[i] = -1;     fo(i, 1, m) {      int u, v;      cin >> u >> v;      e[u].push_back(v);     }     d[1] = 0;     D();     fo(i, 1, n)cout << f(i) <<    ; cout << endl;    }    return 0;   }   /*      */
#include <bits/stdc++.h>   using namespace std;   struct IO {     char buf[(1 << 20)], *p1, *p2;     char pbuf[(1 << 20)], *pp;     IO() : p1(buf), p2(buf), pp(pbuf) {}     inline char gc() {       return getchar();       if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);       return p1 == p2 ?     : *p1++;     }     inline bool blank(char ch) {       return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;     }     template <class T>     inline void read(T &x) {       register double tmp = 1;       register bool sign = 0;       x = 0;       register char ch = gc();       for (; !(ch >=  0  && ch <=  9 ); ch = gc())         if (ch ==  - ) sign = 1;       for (; (ch >=  0  && ch <=  9 ); ch = gc()) x = x * 10 + (ch -  0 );       if (ch ==  . )         for (ch = gc(); (ch >=  0  && ch <=  9 ); ch = gc())           tmp /= 10.0, x += tmp * (ch -  0 );       if (sign) x = -x;     }     inline void read(char *s) {       register char ch = gc();       for (; blank(ch); ch = gc())         ;       for (; !blank(ch); ch = gc()) *s++ = ch;       *s = 0;     }     inline void read(char &c) {       for (c = gc(); blank(c); c = gc())         ;     }     template <class t>     inline void write(t x) {       if (x < 0)         putchar( - ), write(-x);       else {         if (x > 9) write(x / 10);         putchar( 0  + x % 10);       }     }   } io;   const int mod = 1e9 + 7;   const int mo = 998244353;   const int N = 5e5 + 5;   int n, m, a[N], b[N], c[N], stak[N], gs, ans;   inline int get(int l, int r) {     int top = 0;     for (int i = (l); i <= (r); i++) {       if (a[i] < a[l] || a[i] > a[r]) continue;       if (!top || a[i] >= stak[top])         stak[++top] = a[i];       else {         int p = upper_bound(stak + 1, stak + top + 1, a[i]) - stak;         stak[p] = a[i];       }     }     return top;   }   int main() {     io.read(n), io.read(m);     for (int i = (1); i <= (n); i++) io.read(a[i]), a[i] = a[i] - i + 1;     for (int i = (1); i <= (n); i++) b[i] = a[i];     a[++n] = 2e9, b[n] = 2e9;     sort(b + 1, b + n + 1);     gs = unique(b + 1, b + n + 1) - b - 1;     for (int i = (1); i <= (n); i++)       a[i] = lower_bound(b + 1, b + gs + 1, a[i]) - b;     for (int i = (1); i <= (m); i++) io.read(b[i]);     for (int i = (2); i <= (m); i++)       if (a[b[i - 1]] > a[b[i]]) ans = -1;     if (ans == -1) return puts( -1 ), 0;     b[0] = 0, b[m + 1] = n;     ans = 0;     for (int i = (0); i <= (m); i++)       ans += b[i + 1] - b[i] + 1 - get(b[i], b[i + 1]);     io.write(ans), puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6;   int n, k, a[mxN], l[mxN];   struct dsu {     int p[mxN], ld[mxN], lb[mxN];     void init() {       iota(p, p + n, 0);       iota(lb, lb + n, 0);     }     int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }     void join(int x, int y) {       x = find(x), y = find(y);       p[x] = y;       lb[y] = lb[x];       ld[y] += ld[x];     }     void upd(int i, int j) {       i = find(i);       ++ld[i];       if (j < n) --ld[j];       while (ld[i] >= 0 && lb[i]) join(lb[i] - 1, i);     }     void upd2(int i) {       if (i < k) return;       int j = find(i - k + 1);       while (lb[j] > i - k) join(lb[j] - 1, j);     }     int qry() { return ld[find(0)]; }   } d;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     d.init();     for (int i = 0; i < n; ++i) {       d.upd2(i);       l[i] = i - 1;       while (l[i] >= 0 && a[l[i]] < a[i]) {         l[i] = l[l[i]];       }       d.upd(l[i] + 1, i + 1);       if (i >= k - 1) cout << d.qry() <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void result() {     set<int> s;     s.insert(0);     int i = 1;     while (i * i <= n) {       int d = n / i;       s.insert(d);       s.insert(n / d);       i++;     }     cout << s.size() <<   n ;     for (auto v : s) {       cout << v <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n;       result();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sub_tern(int c, int a) {     int temp_c;     int temp_a;     int diff;     long sum = 0;     int three_power = 1;     while (c > 0 || a > 0) {       temp_c = c % 3;       c = c / 3;       temp_a = a % 3;       a = a / 3;       diff = temp_c - temp_a;       if (diff < 0) {         diff += 3;       }       sum += (long)diff * (long)three_power;       three_power *= 3;     }     return sum;   }   int main() {     int a;     int c;     cin >> a >> c;     if (a == c) {       cout <<  0 n ;       return 0;     }     cout << sub_tern(c, a) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m;     while (cin >> n >> m) {       long c = 0;       if (n * 2 >= m) {         for (int i = 0; i < m; i++) {           cout << i + 1 <<    ;         }       } else {         c = 1;         for (int i = 2 * n + 1; i <= m; i++) {           cout << i <<     << c <<    ;           c++;         }         for (int i = c; i <= 2 * n; i++) {           cout << i <<    ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   template <typename T>   struct Point {     T x, y;     Point() {}     Point(T xx, T yy) : x(xx), y(yy) {}   };   template <typename T>   bool operator<(const Point<T> &p1, const Point<T> &p2) {     return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;   }   char c =  a  - 1;   char NextChar() {     c++;     if (c >  z ) c =  a ;     return c;   }   vector<vector<char> > v;   int main() {     int n;     cin >> n;     if (n == 2) {       cout <<  aa  << endl;       cout <<  bb  << endl;       cout <<  cc  << endl;       cout <<  dd  << endl;       return 0;     }     v.assign(4, vector<char>(n));     v[2][0] = v[3][0] = NextChar();     for (int(i) = 0; (i) < (n - 1); (i)++) {       if (i % 2 == 0) {         v[0][i] = v[0][i + 1] = NextChar();         v[1][i] = v[1][i + 1] = NextChar();       } else {         v[2][i] = v[2][i + 1] = NextChar();         v[3][i] = v[3][i + 1] = NextChar();       }     }     if (n % 2 == 0) {       v[2][n - 1] = v[3][n - 1] = NextChar();     } else {       v[0][n - 1] = v[1][n - 1] = NextChar();     }     for (int(i) = 0; (i) < (4); (i)++) {       for (int(j) = 0; (j) < (n); (j)++) {         cout << v[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   const int maxn = 40 + 7;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, m, cur, cnt;   bitset<100000> b[41];   map<string, int> hh;   int g[maxn][maxn];   int dp1[(1 << 20) + 7], dp2[(1 << 20) + 7];   inline void max(int &x, int y) {     if (x < y) x = y;   }   int main() {     n = read(), m = read();     string name;     for (int i = 1; i <= n; ++i) {       int op = read();       if (op == 1)         ++cur;       else {         cin >> name;         if (hh.count(name) == 0) hh[name] = ++cnt;         b[hh[name]][cur] = 1;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = i + 1; j <= m; ++j) {         if ((b[i] & b[j]).count()) g[i - 1][j - 1] = g[j - 1][i - 1] = 1;       }     }     int n2 = m / 2, n1 = m - n2;     for (int i = 0; i < n1; ++i) dp1[1 << i] = 1;     for (int s = 3; s < 1 << n1; ++s) {       for (int i = 0; i < n1; ++i)         if (s >> i & 1) {           int f = 1;           for (int j = 0; j < n1; ++j)             if ((s >> j & 1) && g[i][j]) f = 0;           max(dp1[s], dp1[s ^ (1 << i)] + f);         }     }     for (int i = 0; i < n2; ++i) dp2[1 << i] = 1;     for (int s = 3; s < 1 << n2; ++s) {       for (int i = 0; i < n2; ++i)         if (s >> i & 1) {           int f = 1;           for (int j = 0; j < n2; ++j)             if ((s >> j & 1) && g[n1 + i][n1 + j]) f = 0;           max(dp2[s], dp2[s ^ (1 << i)] + f);         }     }     int ans = 0;     for (int s = 0; s < 1 << n1; ++s) {       int s2 = (1 << n2) - 1;       for (int i = 0; i < n1; ++i)         if (s >> i & 1) {           for (int j = 0; j < n2; ++j)             if ((s2 >> j & 1) && g[i][n1 + j]) s2 ^= 1 << j;         }       max(ans, dp1[s] + dp2[s2]);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int q, n, a[505];   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       bool pd = 1;       for (int i = 1; i < n; i++) {         int xx = a[i] + 1;         if (xx > n) xx = 1;         if (xx != a[i + 1]) {           pd = 0;           break;         }       }       if (pd) {         cout <<  YES  << endl;         continue;       }       pd = 1;       for (int i = 1; i < n; i++) {         int xx = a[i] - 1;         if (xx == 0) xx = n;         if (xx != a[i + 1]) {           pd = 0;           break;         }       }       if (pd)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include<bits/stdc++.h>   #define ll long long int   #define mod 1000000007   using namespace std;      int main()   {       int t;       cin>>t;       while(t--)       {          int n;          cin>>n;          int A[n];          for(int i=0;i<n;i++)          {              cin>>A[i];          }          bool flag=true;          for(int i=0;i<n;i++) if(A[i]!=i+1) {flag=false; break;}          if(flag) cout<< 0 <<endl;          else if((A[0]==1)||(A[n-1]==n)) cout<< 1 <<endl;          else if((A[0]==n)&&(A[n-1]==1)) cout<< 3 <<endl;          else cout<< 2 <<endl;       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     cin >> k;     if (n < k) {       cout << -1;       return 0;     }     if (k == 1) {       if (n == 1)         cout <<  a ;       else         cout << -1;       return 0;     }     if (k == 2) {       for (int i = 0; i < n >> 1; i++) cout <<  ab ;       if (n & 1) cout <<  a ;       return 0;     } else {       string temp =  cdefghijklmnopqrstuvwxyz ;       for (int i = 0; i < (n - k + 2) >> 1; i++) cout <<  ab ;       if ((n - k + 2) & 1) cout <<  a ;       for (int j = 0; j < (k - 2); j++) cout << temp[j];     }     cout << endl;     return 0;   }