malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   set<int> s;   const int nax = 5e5 + 4;   int link[nax];   set<pair<int, int>> edge;   vector<vector<int>> group;   inline void make_set(int i) { link[i] = i; }   int Find(int a) {     if (link[a] == a) return a;     return (link[a] = Find(link[a]));   }   void Unite(int a, int b) {     a = Find(a);     b = Find(b);     if (a == b) return;     link[a] = b;   }   int component() {     set<int> had;     for (int i = 1; i <= n; ++i) {       had.insert(Find(i));       group[Find(i)].push_back(i);     }     return ((int)had.size());   }   void bfs(int i) {     queue<int> q;     q.push(i);     while (!q.empty()) {       int u = q.front();       q.pop();       s.erase(u);       vector<int> temp;       for (auto &c : s) {         if (edge.find({min(u, c), max(u, c)}) == edge.end()) {           Unite(u, c);           q.push(c);           temp.push_back(c);         }       }       for (auto &c : temp) s.erase(c);     }   }   void solve() {     cin >> n >> m;     group.resize(n + 1);     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       edge.insert({min(u, v), max(u, v)});     }     for (int i = 1; i <= n; ++i) make_set(i);     for (int i = 1; i <= n; ++i) s.insert(i);     for (int i = 1; i <= n; ++i) {       if (s.find(i) != s.end()) bfs(i);     }     cout << component() <<   n ;     for (int i = 1; i <= n; ++i) {       if (!group[i].empty()) {         cout << group[i].size() <<    ;         for (auto &c : group[i]) cout << c <<    ;         cout <<   n ;       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     int an;     cin >> an;     for (int i = 0; i < an; ++i) {       int t;       cin >> t;       a[t] = 1;     }     int bn;     cin >> bn;     for (int i = 0; i < bn; ++i) {       int t;       cin >> t;       b[t] = 1;     }     int lim = n * m;     while (1) {       bool ch = false;       for (int i = 0; i < lim; ++i) {         if (a[i % n] != b[i % m]) {           ch = true;           a[i % n] = b[i % m] = 1;         }       }       if (!ch) break;     }     bool ans = true;     for (int i = 0; i < n; ++i) ans &= a[i];     for (int i = 0; i < m; ++i) ans &= b[i];     cout << (ans ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, out;     cin >> s;     for (int i = 0; s[i] !=   0 ; i++) {       s[i] = tolower(s[i]);       if (s[i] ==  o  || s[i] ==  u  || s[i] ==  i  || s[i] ==  e  ||           s[i] ==  a  || s[i] ==  y )         ;       else {         out +=  . ;         out += s[i];       }     }     cout << out;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int ans = 0, flag = 1;     for (int i = 0; i < n; i++) {       if (s[i] !=  ? ) {         if (s[i] == s[i + 1]) {           flag = 0;         }       } else if (i == 0 || i == n - 1 || s[i + 1] == s[i - 1] || s[i + 1] ==  ? )         ans = 1;     }     if (flag && ans)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 50 + 10;   int n, m, vis[maxn][maxn], need[maxn][maxn];   struct node {     int x, y, a, b;   } p[maxn];   vector<node> vec;   inline void move(int id, int x, int y) {     vec.push_back((node){p[id].x, p[id].y, p[id].x + x, p[id].y + y});     vis[p[id].x][p[id].y] = 0;     p[id].x += x;     p[id].y += y;     vis[p[id].x][p[id].y] = id;   }   inline void work1() {     int cnt = 0;     for (int i = 1; i <= n; ++i)       if (vis[1][i]) {         ++cnt;         int id = vis[1][i];         while (p[id].y > cnt) move(id, 0, -1);       }     for (int i = 2; i <= n; ++i)       for (int j = n; j; --j)         if (vis[i][j]) {           ++cnt;           int id = vis[i][j];           while (p[id].y < cnt) move(id, 0, 1);           while (p[id].x > 1) move(id, -1, 0);           while (p[id].y > cnt) move(id, 0, -1);         }   }   inline void work2() {     int cnt = 0;     for (int i = n; i > 2; --i)       for (int j = n; j; --j)         if (need[i][j]) {           int id = need[i][j];           move(id, 1, 0);           while (p[id].y < j) move(id, 0, 1);           while (p[id].y > j) move(id, 0, -1);           while (p[id].x < i) move(id, 1, 0);         }     for (int i = 1; i <= n; ++i)       if (vis[1][i]) {         ++cnt;         int id = vis[1][i];         while (p[id].y > cnt) move(id, 0, -1);       }     for (int i = n, cntt = cnt; i; --i)       for (int j = 1; j <= 2; ++j)         if (need[j][i]) {           int id = need[j][i];           move(id, 1, 0);           for (int k = p[id].y + 1; k <= cntt; ++k) move(vis[1][k], 0, -1);           while (p[id].y < cntt) move(id, 0, 1);           move(id, -1, 0);           --cntt;         }     for (int i = 1; i <= cnt; ++i)       if (p[vis[1][i]].a == 2) move(vis[1][i], 1, 0);     for (int i = 1; i <= 2; ++i) {       for (int j = 1; j <= n; ++j)         if (vis[i][j]) {           int id = vis[i][j];           while (p[id].y > p[id].b) move(id, 0, -1);         }       for (int j = n; j; --j)         if (vis[i][j]) {           int id = vis[i][j];           while (p[id].y < p[id].b) move(id, 0, 1);         }     }   }   int main() {     cin >> n >> m;     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 1; i <= m; ++i) {       cin >> p[i].x >> p[i].y;       vis[p[i].x][p[i].y] = i;     }     for (int i = 1; i <= m; ++i) {       cin >> p[i].a >> p[i].b;       need[p[i].a][p[i].b] = i;     }     work1();     work2();     cout << vec.size() << endl;     for (int i = 0; i < vec.size(); ++i)       cout << vec[i].x <<     << vec[i].y <<     << vec[i].a <<     << vec[i].b            << endl;     return 0;   }
#include<cmath>   #include<iostream>   #include<sstream>   #include<cstdio>   #include<cstring>   #include<string>   #include<cstdlib>   #include<istream>   #include<vector>   #include<stack>   #include<set>   //#include<unordered_map>   #include<map>   #include<algorithm>   #include<queue>   #define mmp make_pair   #define inf 0x3f3f3f3f   #define llinf 0x7fffffffffffffff   using namespace std;   typedef long long ll;   typedef pair<ll,ll> PP;   typedef double ld;   vector<int>hh[200010];   int ID[200010];   bool orz[200010];   ll siz[200010];   queue<int>q;   void topsort(int n) {       while(!q.empty()) q.pop();       for(int i=1;i<=n;++i) {           if(ID[i]==1) {               q.push(i);               orz[i]=true;           }       }       while(!q.empty()) {           int temp=q.front();           q.pop();           orz[temp]=true;           for(int i=0;i<hh[temp].size();++i) {               int uu=hh[temp][i];               if(orz[uu]) continue;               ID[uu]--;               ID[temp]--;               if(ID[uu]==1) {                   q.push(uu);               }           }       }   }   void dfs(int u,int f) {       siz[u]=1;       for(int i=0;i<hh[u].size();++i) {           int v=hh[u][i];           if(orz[v]==0 || v==f) continue;           dfs(v,u);           siz[u]+=siz[v];       }   }   int main() {       int T;       scanf( %d ,&T);       while(T--) {           int n;           scanf( %d ,&n);           for(int i=1;i<=n;++i) {               hh[i].clear();               ID[i]=orz[i]=siz[i]=0;           }           for(int i=1;i<=n;++i) {               int x,y; scanf( %d %d ,&x,&y);               hh[x].push_back(y); hh[y].push_back(x);               ++ID[x]; ++ID[y];           }           topsort(n);           ll cnt=0;           for(int i=1;i<=n;++i) {               if(orz[i]==0) {                   ++cnt;                   dfs(i,0);               }           }           ll sum=0;           ll ans=cnt*(cnt-1);           for(int i=1;i<=n;++i) {               if(!orz[i]) {                   ans+=1ll*(cnt-1)*2*(siz[i]-1);                   ans+=1ll*(siz[i]-1)*siz[i]/2;                   sum+=siz[i]-1;               }           }           for(int i=1;i<=n;++i) {               if(!orz[i]) {                   ans+=1ll*(sum-siz[i]+1)*(siz[i]-1);               }           }           printf( %lld n ,ans);       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1000000007;   const int inv3 = (mod + 1) / 3;   const int maxn = 3003003;   int fac[maxn], ifac[maxn];   int qpow(int a, int n) {     int ans = 1;     for (; n; n >>= 1, a = (ll)a * a % mod)       if (n & 1) ans = (ll)ans * a % mod;     return ans;   }   int C(int n, int m) {     return fac[n] * (ll)ifac[m] % mod * (ll)ifac[n - m] % mod;   }   int f[maxn], g[maxn];   int main(void) {     int n, q;     scanf( %d%d , &n, &q);     fac[0] = 1;     for (int i = 1; i <= 3 * n + 3; i++) fac[i] = fac[i - 1] * (ll)i % mod;     ifac[3 * n + 3] = qpow(fac[3 * n + 3], mod - 2);     for (int i = 3 * n + 2; i >= 0; i--)       ifac[i] = ifac[i + 1] * (ll)(i + 1) % mod;     for (int i = 0; i < 3 * n + 3; i++) f[i] = C(3 * n + 3, i + 1);     g[0] = n + 1;     g[1] = 3ll * n * (n + 1) / 2 % mod;     for (int i = 2; i <= 3 * n; i++) {       g[i] = ((f[i] - 3ll * g[i - 1] % mod + mod) % mod - g[i - 2] + mod) % mod *              inv3 % mod;     }     for (int i = 0; i < q; i++) {       int x;       scanf( %d , &x);       printf( %d n , g[x]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string mt[1226], sc[1226], s[51], q1, q2;   int n, k1, k2, c;   map<string, int> O, Z, P;   pair<pair<pair<int, int>, int>, string> p[51];   vector<string> v;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];     }     for (int i = 1; i <= n * (n - 1) / 2; i++) {       cin >> mt[i] >> sc[i];       c = 0;       k1 = 0;       k2 = 0;       q1 =   ;       q2 =   ;       for (int j = 0; j < sc[i].size(); j++) {         if (sc[i][j] ==  : ) {           c++;           continue;         }         if (c == 0) {           k1 += sc[i][j] -  0 ;           k1 *= 10;         } else {           k2 += sc[i][j] -  0 ;           k2 *= 10;         }       }       k1 /= 10;       k2 /= 10;       c = 0;       for (int j = 0; j < mt[i].size(); j++) {         if (mt[i][j] ==  - ) {           c++;           continue;         }         if (c == 0) {           q1 += mt[i][j];         }         if (c == 1) {           q2 += mt[i][j];         }       }       if (k1 > k2) {         O[q1] += 3;       } else if (k1 < k2) {         O[q2] += 3;       } else {         O[q1]++;         O[q2]++;       }       Z[q1] += k1;       Z[q2] += k2;       P[q1] += k2;       P[q2] += k1;     }     for (int i = 1; i <= n; i++) {       p[i] = make_pair(make_pair(make_pair(O[s[i]], Z[s[i]] - P[s[i]]), Z[s[i]]),                        s[i]);     }     sort(p + 1, p + 1 + n);     for (int i = n; i >= n / 2 + 1; i--) {       v.push_back(p[i].second);     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   vector<int> l, r, x, y;   vector<long long> sum;   double ans(int x1, int y1, int x, int y) {     long long a = y1 - y;     long long b = x - x1;     long long c = -a * x - b * y;     double xs = -1.0 * c / a;     int ll = 0, rr = n - 1;     while (ll <= rr) {       int md = (ll + rr) / 2;       if (r[md] < xs)         ll = md + 1;       else         rr = md - 1;     }     if (ll == n) return sum[n - 1];     double ans = 0;     if (ll != 0) ans = sum[ll - 1];     if (l[ll] < xs) ans += xs - l[ll];     return ans;   }   int main() {     int y1, a, b;     cin >> y1 >> a >> b;     cin >> n;     l.resize(n);     r.resize(n);     for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];     cin >> q;     x.resize(q);     y.resize(q);     for (int i = 0; i < q; ++i) cin >> x[i] >> y[i];     sum.resize(n);     sum[0] = r[0] - l[0];     for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + r[i] - l[i];     for (int i = 0; i < q; ++i) {       cout << fixed << setprecision(10)            << (ans(b, y1, x[i], y[i]) - ans(a, y1, x[i], y[i])) * (y[i] - y1) /                   y[i]            <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   char s[2000006];   long long dp[2000006][5];   int main() {     int i, j, k, l;     int n;     while (cin >> s) {       memset(dp, 0, sizeof(dp));       int len = strlen(s);       if (s[0] ==  ? ) {         dp[0][0] = dp[0][3] = dp[0][4] = 1;       } else if (s[0] ==  0 ) {         dp[0][0] = 1;       } else if (s[0] ==  1 ) {         dp[0][4] = 1;       } else if (s[0] ==  * ) {         dp[0][3] = 1;       } else {         puts( 0 );         continue;       }       for (i = 1; i < len; i++) {         if (s[i] ==  * ) {           dp[i][3] = (dp[i][3] + dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][4]) %                      1000000007;         } else if (s[i] ==  0 ) {           dp[i][0] = (dp[i][0] + dp[i - 1][0] + dp[i - 1][1]) % 1000000007;         } else if (s[i] ==  1 ) {           dp[i][1] = (dp[i][1] + dp[i - 1][3]) % 1000000007;           dp[i][4] = (dp[i][4] + dp[i - 1][0] + dp[i - 1][1]) % 1000000007;         } else if (s[i] ==  2 ) {           dp[i][2] = (dp[i][2] + dp[i - 1][3]) % 1000000007;         } else {           dp[i][3] = (dp[i][3] + dp[i - 1][2] + dp[i - 1][3] + dp[i - 1][4]) %                      1000000007;           dp[i][0] = (dp[i][0] + dp[i - 1][0] + dp[i - 1][1]) % 1000000007;           dp[i][1] = (dp[i][1] + dp[i - 1][3]) % 1000000007;           dp[i][4] = (dp[i][4] + dp[i - 1][0] + dp[i - 1][1]) % 1000000007;           dp[i][2] = (dp[i][2] + dp[i - 1][3]) % 1000000007;         }       }       long long ans =           (dp[len - 1][0] + dp[len - 1][1] + dp[len - 1][3]) % 1000000007;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int p = 1000000007;   int c[1105][1105], d[1005], f[1005][50][1005];   int h, i, j, k, m, n, s, t;   int main() {     d[0] = 1;     for (i = 1; i <= 1001; i++) d[i] = 1LL * i * d[i - 1] % p;     for (i = 0; i <= 1100; i++)       for (j = 0; j <= i; j++)         if ((j == 0) && (j == i))           c[i][j] = 1;         else           c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;     f[0][0][1] = 1;     for (j = 0; j < 50; j++)       for (i = 0; i <= 1000; i++)         for (k = 1; k <= 1001; k++) {           f[i][j][k] = (f[i][j][k] + f[i][j][k - 1]) % p;           if (i + k <= 1000)             f[i + k][j + 1][k + 1] = (f[i + k][j + 1][k + 1] + f[i][j][k]) % p;         }     scanf( %d , &t);     for (h = 1; h <= t; h++) {       scanf( %d%d , &n, &m);       if (m >= 50)         printf( 0 n );       else {         s = 0;         for (i = 0; i <= n; i++)           s = (s + 1LL * f[i][m][1001] * d[m] % p * c[n - i + m][m] % p) % p;         printf( %d n , s);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long n, s, ans, ans2, ret;   struct Node {     long long val, tmp;     int id;   } node[N];   bool cmp(Node A, Node B) { return A.tmp < B.tmp; }   bool check(int x) {     for (int i = 1; i <= n; i++) {       node[i].tmp = node[i].val + node[i].id * 1ll * x;     }     sort(node + 1, node + 1 + n, cmp);     ret = 0;     for (int i = 1; i <= x; i++) {       ret += node[i].tmp;     }     if (ret <= s) {       return 1;     }     return 0;   }   int main() {     scanf( %lld%lld , &n, &s);     for (int i = 1; i <= n; i++) {       scanf( %lld , &node[i].val);       node[i].id = i;     }     int L = 0, R = n, mid;     while (L <= R) {       mid = (L + R) >> 1;       if (check(mid)) {         ans = mid;         ans2 = ret;         L = mid + 1;       } else {         R = mid - 1;       }     }     cout << ans <<     << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int val;     int mx[32];   };   int n, k, p;   vector<int> a[200005];   node st[4 * 200005];   int b[5];   void build(int si, int ss, int se) {     if (ss == se) {       st[si].val = 0;       for (int i = 0; i < p; i++) {         int val = 0;         for (int j = 0; j < k; j++) {           if (i & (1 << j)) {             val += a[ss][j];           } else {             val -= a[ss][j];           }         }         st[si].mx[i] = val;       }       return;     }     int mid = (ss + se) >> 1;     build(2 * si + 1, ss, mid);     build(2 * si + 2, mid + 1, se);     st[si].val = max(st[2 * si + 1].val, st[2 * si + 2].val);     for (int i = 0; i < p; i++) {       st[si].mx[i] = max(st[2 * si + 1].mx[i], st[2 * si + 2].mx[i]);       st[si].val =           max(st[si].val, st[2 * si + 1].mx[i] + st[2 * si + 2].mx[(p - 1) ^ i]);     }     return;   }   void update(int si, int ss, int se, int ind) {     if (ind < ss || ind > se) {       return;     }     if (ss == se) {       st[si].val = 0;       for (int i = 0; i < p; i++) {         int val = 0;         for (int j = 0; j < k; j++) {           if (i & (1 << j)) {             val += b[j];           } else {             val -= b[j];           }         }         st[si].mx[i] = val;       }       return;     }     int mid = (ss + se) >> 1;     update(2 * si + 1, ss, mid, ind);     update(2 * si + 2, mid + 1, se, ind);     st[si].val = max(st[2 * si + 1].val, st[2 * si + 2].val);     for (int i = 0; i < p; i++) {       st[si].mx[i] = max(st[2 * si + 1].mx[i], st[2 * si + 2].mx[i]);       st[si].val =           max(st[si].val, st[2 * si + 1].mx[i] + st[2 * si + 2].mx[(p - 1) ^ i]);     }     return;   }   node query(int si, int ss, int se, int l, int r) {     if (r < ss || l > se) {       node ans;       ans.val = -(k * 1e6 + 5);       for (int i = 0; i < p; i++) {         ans.mx[i] = -k * 1e6 + 5;       }       return ans;     }     if (ss >= l && se <= r) {       return st[si];     }     int mid = (ss + se) >> 1;     node x = query(2 * si + 1, ss, mid, l, r);     node y = query(2 * si + 2, mid + 1, se, l, r);     node ans;     ans.val = max(x.val, y.val);     for (int i = 0; i < p; i++) {       ans.mx[i] = max(x.mx[i], y.mx[i]);       ans.val = max(ans.val, x.mx[i] + y.mx[(p - 1) ^ i]);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     p = (1 << k);     for (int i = 0; i < n; i++) {       a[i].resize(k);       for (int j = 0; j < k; j++) {         cin >> a[i][j];       }     }     build(0, 0, n - 1);     int q;     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1) {         int ind;         cin >> ind;         ind--;         for (int i = 0; i < k; i++) {           cin >> b[i];         }         update(0, 0, n - 1, ind);       } else {         int l, r;         cin >> l >> r;         l--, r--;         cout << query(0, 0, n - 1, l, r).val << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   struct Seg {     const T ID = 0;     T comb(T a, T b) { return a + b; }     long long n;     vector<T> seg;     void init(long long _n) {       n = _n;       seg.assign(2 * n, ID);     }     void pull(long long p) { seg[p] = comb(seg[2 * p], seg[2 * p + 1]); }     void upd(long long p, T val) {       seg[p += n] = val;       for (p /= 2; p; p /= 2) pull(p);     }     T query(long long l, long long r) {       T ra = ID, rb = ID;       for (l += n, r += n + 1; l < r; l /= 2, r /= 2) {         if (l & 1) ra = comb(ra, seg[l++]);         if (r & 1) rb = comb(seg[--r], rb);       }       return comb(ra, rb);     }   };   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long m;     cin >> m;     string s;     cin >> s;     long long n = s.size();     long long a[n];     for (long long i = 0; i < n; ++i) {       a[i] = s[i] -  a ;     }     vector<long long> ans;     set<array<long long, 2>> ranges;     Seg<long long> st;     st.init(n);     for (long long i = 0; i < n; ++i) {       if (i + m - 1 >= n) break;       ranges.insert({i, i + m - 1});     }     for (long long i = 0; i < 26; ++i) {       bool fin = 1;       for (long long j = 0; j < n; ++j) {         if (a[j] == i) {           st.upd(j, 1);         }       }       for (auto [l, r] : ranges) {         fin &= st.query(l, r) > 0;       }       if (fin) {         vector<long long> pos;         for (long long j = 0; j < n; ++j) {           if (a[j] == i) {             st.upd(j, 0);             pos.push_back(j);           }         }         for (auto [l, r] : ranges) {           if (st.query(l, r)) continue;           auto lb = --(lower_bound((pos).begin(), (pos).end(), r + 1));           st.upd(*lb, 1);           ans.push_back(i);         }         break;       } else {         for (long long j = 0; j < n; ++j) {           if (a[j] == i) {             ans.push_back(i);           }         }         vector<array<long long, 2>> rem;         for (auto [l, r] : ranges) {           if (st.query(l, r)) {             rem.push_back({l, r});           }         }         for (auto [l, r] : rem) {           ranges.erase({l, r});         }       }     }     for (long long i : ans) {       cout << (char)(i +  a );     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 0, t = 0;     string road;     cin >> n >> road;     for (int i = 1; i < n; ++i) {       if (road[i] ==  L ) {         t = i;         for (int j = i + 1; j < n; ++j) {           if (road[j] ==  . ) {             s = j;             break;           }         }         break;       } else if (road[i] ==  R ) {         s = i + 1;         for (int j = i + 1; j < n; ++j) {           if (road[j] !=  R ) {             t = (road[j] ==  .  ? j + 1 : j);             break;           }         }         break;       }     }     cout << s <<     << t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void in(T &x) {     x = 0;     bool f = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     if (f) x = -x;   }   char s[1005];   int n, p;   char can(int x) {     for (register int i = s[x] + 1; i <=  a  + p - 1; ++i)       if (i != s[x - 1] && i != s[x - 2]) return i;     return 0;   }   signed main() {     in(n), in(p);     scanf( %s , s + 1);     int pos = 0;     for (register int i = n; i >= 1; --i) {       if (can(i)) {         s[i] = can(i);         pos = i;         break;       }     }     if (!pos) {       puts( NO );       return 0;     }     for (register int i = pos + 1; i <= n; ++i) {       for (register int j =  a ; j <=  a  + p - 1; ++j)         if (j != s[i - 1] && j != s[i - 2]) {           s[i] = j;           break;         }     }     for (register int i = 1; i <= n; ++i) putchar(s[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, n;     cin >> T;     double R1, R2, R3;     while (T--) {       scanf( %lf%lf%d , &R1, &R2, &n);       R3 = R1 - R2;       double k1 = -1 / R1;       double k2 = 1 / R2;       double k3 = 1 / R3;       double k4 = k1 + k2 + k3;       double ans;       for (int i = 1; i <= n; i++) {         double R4 = 1 / k4;         ans = R4;         double k5 = 2 * (k1 + k2 + k4) - k3;         k3 = k4;         k4 = k5;       }       printf( %0.10lf n , fabs(ans));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> s;       for (int i = 0, x; i < n; i++) {         cin >> x;         s.insert(((x + i) % n + n) % n);       }       puts(s.size() == n ?  YES  :  NO );     }     return 0;   }