malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, vmx;   long long seed;   struct node {     int l, r;     mutable long long val;     bool operator<(const node &x) const { return l < x.l; }   };   set<node> tr;   set<node>::iterator split(int pos) {     set<node>::iterator iter = tr.lower_bound((node){pos});     if (iter != tr.end() && iter->l == pos) return iter;     iter--;     int L = iter->l, R = iter->r;     long long Val = iter->val;     tr.erase(iter);     tr.insert((node){L, pos - 1, Val});     return tr.insert((node){pos, R, Val}).first;   }   void assign(int l, int r, long long val) {     set<node>::iterator R = split(r + 1), L = split(l);     tr.erase(L, R);     tr.insert((node){l, r, val});     return;   }   void add(int l, int r, long long val) {     set<node>::iterator R = split(r + 1), L = split(l);     for (; L != R; ++L) L->val = L->val + val;     return;   }   struct Lsh {     long long val;     int sum;   } ls[N];   inline bool Lscmp(Lsh a, Lsh b) { return a.val < b.val; }   inline long long rnk(int l, int r, int x) {     set<node>::iterator R = split(r + 1), L = split(l);     int tot = 0;     for (; L != R; ++L) ls[++tot].val = L->val, ls[tot].sum = (L->r - L->l + 1);     sort(ls + 1, ls + tot + 1, Lscmp);     for (int i = 1; i <= tot; i++) {       x -= ls[i].sum;       if (x <= 0) return ls[i].val;     }   }   inline long long ksm(long long a, long long b, long long mod) {     a %= mod;     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   inline long long calc(int l, int r, int x, int y) {     set<node>::iterator R = split(r + 1), L = split(l);     long long ans = 0;     for (; L != R; ++L)       ans = (ans + ksm(L->val, x, y) * (L->r - L->l + 1) % y) % y;     return ans;   }   inline int rnd() {     int ret = seed;     seed = (seed * 7 + 13) % 1000000007;     return ret;   }   int op, l, r, x, y;   int tot;   int main() {     scanf( %d%d%lld%d , &n, &m, &seed, &vmx);     for (int i = 1; i <= n; i++) tr.insert((node){i, i, rnd() % vmx + 1});     tr.insert((node){n + 1, n + 1, 0});     for (int i = 1; i <= m; i++) {       op = rnd() % 4 + 1;       l = rnd() % n + 1;       r = rnd() % n + 1;       if (l > r) swap(l, r);       if (op == 3)         x = rnd() % (r - l + 1) + 1;       else         x = rnd() % vmx + 1;       if (op == 4) y = rnd() % vmx + 1;       if (op == 1)         add(l, r, x);       else if (op == 2)         assign(l, r, x);       else if (op == 3)         printf( %lld n , rnk(l, r, x));       else         printf( %lld n , calc(l, r, x, y));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double a[200005], b[200005];   double l = -10001, r = 10001;   const double eps = 2e-12;   double solve(double x) {     for (int i = 1; i <= n; ++i) b[i] = a[i] - x;     double res = 0, tmp = 0;     for (int i = 1; i <= n; ++i) {       if (tmp < 0) tmp = 0;       tmp += b[i];       res = max(res, tmp);     }     tmp = 0;     for (int i = 1; i <= n; ++i) {       if (tmp < 0) tmp = 0;       tmp -= b[i];       res = max(res, tmp);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf , &a[i]);     }     while (r > eps + l) {       double ll = (2 * l + r) / 3, rr = (l + 2 * r) / 3;       double lll = solve(ll);       double rrr = solve(rr);       if (lll < rrr)         r = rr;       else         l = ll;     }     cout << fixed << setprecision(12) << solve((l + r) / 2) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c, i;     cin >> n >> m;     c = 2 * n;     i = 1;     while (i <= 2 * n) {       if (m > c) {         c++;         cout << c <<    ;       }       cout << i <<    ;       i++;       if (m < i) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, sx, sy, ex, ey;   int e, s, n, w;   string ch;   int main() {     cin >> t >> sx >> sy >> ex >> ey;     if (sx < ex)       e = ex - sx;     else       w = sx - ex;     if (sy < ey)       n = ey - sy;     else       s = sy - ey;     cin >> ch;     long long d = 1;     for (long long i = 0; i < t; i++) {       if (ch[i] ==  S )         s--;       else if (ch[i] ==  N )         n--;       else if (ch[i] ==  E )         e--;       else         w--;       if ((s <= 0 && n <= 0) && (e <= 0 && w <= 0)) {         d = 0;         cout << i + 1 << endl;         break;       }     }     if (d == 1) cout << -1 << endl;   }
#include<bits/stdc++.h>   using namespace std;   #define read(x) scanf( %d ,&x)   const int N=1e5+10;   string s;   int main()   {        int t; read(t);    while(t--)    {     cin>>s;     for(int i=0;i<s.size();i++)     {      if(i%2==0)      {       if(s[i]!= a ) s[i]= a ;       else s[i]= b ;      }      else      {       if(s[i]!= z ) s[i]= z ;       else s[i]= y ;      }     }     cout<<s<<endl;    }       return 0;    }
#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   void solve() {     long long n;     cin >> n;     if (n % 2 == 0) {       cout << (10 + n) <<   10 ;     } else {       cout << (9 + n) <<   9 ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  inline ,  -ffast-math )   #pragma GCC target( avx,sse2,sse3,sse4,mmx )   inline long long read() {     long long s(0);     bool w(1);     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   long long l, r, n, m, x, y, num;   int main() {     n = read(), x = read();     for (int i = 1; i <= n; i++) {       num = read();       l = l * x + num;     }     scanf( %lld%lld , &m, &y);     for (int i = 1; i <= m; i++) {       num = read();       r = r * y + num;     }     puts(l == r ?  =  : (l > r ?  >  :  < ));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c = 0;     cin >> a;     for (int i = 0; i < a; ++i) {       cin >> b;       if (b == 1) {         c = 1;       }     }     if (c == 0) {       cout <<  EASY n ;     } else {       cout <<  HARD n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 4e3 + 5;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double pi = asin(1.0) * 2;   const double e = 2.718281828459;   bool Finish_read;   template <class T>   inline void read(T &x) {     Finish_read = 0;     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) {         f = -1;       }       if (ch == EOF) {         return;       }       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;     Finish_read = 1;   };   int main(int argc, char *argv[]) {     int n, m;     read(n);     read(m);     vector<int> a;     a.push_back(0);     for (int i = 1, x; i <= n; ++i) {       read(x);       a.push_back(x);     }     a.push_back(m);     vector<int> f[2];     f[0].assign(a.size(), 0);     f[1].assign(a.size(), 0);     for (int i = int(a.size()) - 2; i >= 0; --i) {       f[0][i] = f[1][i + 1];       f[1][i] = (a[i + 1] - a[i]) + f[0][i + 1];     }     int ans = f[1][0];     for (int i = 0; i + 1 < int(a.size()); ++i) {       if (a[i + 1] - a[i] < 2) {         continue;       }       int tp = (i & 1) ^ 1;       int pSum = f[1][0] - f[tp][i];       ans = max(ans, pSum + (a[i + 1] - a[i] - 1) + f[tp][i + 1]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> Q[123];   int stk[123];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       for (int j = 0; j < x; j++) {         int u;         scanf( %d , &u);         Q[i].push_back(u);       }     }     int cnt = 0;     int A = 0, B = 0;     for (int i = 0; i < n; i++) {       if (Q[i].size() % 2 == 1) {         stk[cnt++] = Q[i][Q[i].size() / 2];       }       for (int j = 0; j < Q[i].size() / 2; j++) A += Q[i][j];       for (int j = 0; j < Q[i].size() / 2; j++) B += Q[i][Q[i].size() - 1 - j];     }     sort(stk, stk + cnt);     for (int i = cnt - 2; i > -1; i -= 2) B += stk[i];     for (int i = cnt - 1; i > -1; i -= 2) A += stk[i];     cout << A <<     << B <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       int T;       in >> T;       for (int _t = 0; _t < (int)(T); ++_t) {         int n, s, t;         in >> n >> s >> t;         int res = n - min(s, t) + 1;         out << res << endl;       }     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2001];   int ou, ji;   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ans += a[i];       if (a[i] % 2 == 0)         ou++;       else         ji++;     }     if (ou > ji)       ou = ji + 1;     else if (ji > ou)       ji = ou + 1;     sort(a + 1, a + 1 + n);     for (int i = n; i >= 1; i--) {       if (a[i] % 2 == 0 && ou) {         ans -= a[i];         ou--;       } else if (a[i] % 2 != 0 && ji) {         ans -= a[i];         ji--;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace FGF {   const int N = 2e5 + 5;   int n, m;   long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) w = -w;       ch = getchar();     }     while (isdigit(ch)) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   struct Node {     long long a, b, tim;     Node(){};     Node(long long _a, long long _b, long long _t) : a(_a), b(_b), tim(_t){};   } c[N];   bool operator<(Node x, Node y) { return x.tim > y.tim; }   bool check(long long x) {     priority_queue<Node> q;     while (q.size()) q.pop();     for (int i = 1; i <= n; i++)       if (c[i].tim < m) q.push(c[i]);     if (q.empty()) return 1;     for (int i = 0; i < m; i++) {       Node u = q.top();       q.pop();       if (u.tim < i) return 0;       u.a += x;       u.tim = u.a / u.b;       if (u.tim < m) q.push(u);       if (q.empty()) return 1;     }     return 1;   }   void work() {     n = read(), m = read();     for (int i = 1; i <= n; i++) c[i].a = read();     for (int i = 1; i <= n; i++) c[i].b = read(), c[i].tim = c[i].a / c[i].b;     long long l = 0, r = 5e12, ans = -1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %lld n , ans);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const long long SEED = 19260817;   const long long MOD = 1e9 + 9;   const int maxn = 2e5 + 11;   int N, M, T;   char a[maxn];   long long cnt[maxn][26], dif[maxn], cx[maxn], cy[maxn];   void solve(int x, int y, int l) {     for (int i = 0; i < 26; i++) {       cx[i] = (cnt[x + l - 1][i] - cnt[x - 1][i] * dif[l] % MOD + MOD) % MOD;       cy[i] = (cnt[y + l - 1][i] - cnt[y - 1][i] * dif[l] % MOD + MOD) % MOD;     }     sort(cx, cx + 26);     sort(cy, cy + 26);     for (int i = 0; i < 26; i++)       if (cx[i] != cy[i]) {         puts( NO );         return;       }     puts( YES );     return;   }   int main() {     cin >> N >> M;     scanf( %s , a + 1);     dif[0] = 1;     for (int i = 1; i <= N; i++) {       dif[i] = (dif[i - 1] * SEED) % MOD;       for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j] * SEED % MOD;       cnt[i][a[i] -  a ] = (cnt[i][a[i] -  a ] + 1) % MOD;     }     while (M--) {       int x, y, l;       scanf( %d%d%d , &x, &y, &l);       solve(x, y, l);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 10;   long long tree[MAXN * 4][7][11], s[6][MAXN], a[MAXN];   void Pushup(long long u, long long len) {     long long z, i, j;     for (z = 2; z <= 6; z++)       for (i = 0; i < 2 * (z - 1); i++)         tree[u][z][i] =             tree[u * 2][z][i] + tree[u * 2 + 1][z][(i + len) % (2 * (z - 1))];     return;   }   void Build(long long u, long long l, long long r) {     long long z, i;     if (l == r) {       for (z = 2; z <= 6; z++)         for (i = 0; i < (z - 1) * 2; i++) tree[u][z][i] = a[l] * s[z][i];       return;     }     long long mid = (l + r) >> 1;     Build(u * 2, l, mid);     Build(u * 2 + 1, mid + 1, r);     Pushup(u, mid - l + 1);   }   void Update(long long u, long long l, long long r, long long pos,               long long val) {     long long z, i;     if (l == r) {       for (z = 2; z <= 6; z++)         for (i = 0; i < 2 * (z - 1); i++) tree[u][z][i] = val * s[z][i];       return;     }     long long mid = (l + r) >> 1;     if (pos <= mid)       Update(u * 2, l, mid, pos, val);     else       Update(u * 2 + 1, mid + 1, r, pos, val);     Pushup(u, mid - l + 1);   }   long long Query(long long u, long long L, long long R, long long l, long long r,                   long long z, long long i) {     if (L == l && R == r) return tree[u][z][i];     long long mid = (L + R) >> 1;     if (r <= mid) return Query(u * 2, L, mid, l, r, z, i);     if (l > mid) return Query(u * 2 + 1, mid + 1, R, l, r, z, i);     return Query(u * 2, L, mid, l, mid, z, i) +            Query(u * 2 + 1, mid + 1, R, mid + 1, r, z,                  (i + mid - l + 1) % (2 * (z - 1)));   }   int main() {     long long n, m, z, i, j;     scanf( %lld , &n);     for (i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (z = 2; z <= 6; z++) {       long long mod = 2 * (z - 1);       for (i = 1; i <= 100000; i++) {         if (i % mod == 0)           s[z][i - 1] = 2;         else if (i % mod <= z)           s[z][i - 1] = i % mod;         else           s[z][i - 1] = (z * 2) - (i % mod);       }     }     Build(1, 1, n);     scanf( %lld , &m);     for (i = 1; i <= m; i++) {       long long op;       scanf( %lld , &op);       if (op == 1) {         long long pos, val;         scanf( %lld %lld , &pos, &val);         Update(1, 1, n, pos, val);       } else {         long long l, r, z;         scanf( %lld %lld %lld , &l, &r, &z);         printf( %lld n , Query(1, 1, n, l, r, z, 0));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void miz(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void maz(T &a, T b) {     if (b > a) a = b;   }   template <class T>   void clear(T &x) {     T t;     x.swap(t);   }   template <class T>   T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T sqr(T x) {     return x * x;   }   unsigned HASH(const char *p) {     unsigned r = 0;     while (*p) r = r * 257 + 1 + *p++;     return r;   }   int ROUND(double x) { return x >= 0 ? x + 0.5 : x - 0.5; }   int cnt[1000005];   int main() {     int k, c, i, now = 0;     long long ans = 0;     scanf( %d  , &k);     cnt[0] = 1;     for (i = 1; (c = getchar()) !=   n ; i++) {       if (c ==  1 ) now++;       if (now >= k) ans += cnt[now - k];       cnt[now]++;     }     cout << ans << endl;     return 0;   }
/*   西江月·证明   即得易见平凡，仿照上例显然；留作习题答案略，读者自证不难。   反之亦然同理，推论自然成立；略去过程Q.E.D.，由上可知证毕。      result of thinking: Pure.    主要是非内、外向树的情形容易遗漏.       AC:   */   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef long double ldouble;   template<class T> bool chmin(T &x, const T &y) {     return x > y ? (x = y, true) : false;   }   template<class T> bool chmax(T &x, const T &y) {     return x < y ? (x = y, true) : false;   }      #define maxn 1000005   const ll mod = 998244353;   const ll inv2 = 499122177;   const ll inv6 = 166374059;   int n;   ll f[maxn], r[maxn], df[maxn];      int main() {     scanf( %d , &n);     f[0] = r[0] = 1;     for (int i = 1; i <= n; i++) {       f[i] = (f[i - 1] * f[i - 1] % mod * inv2 + 3 * f[i - 1] * inv2 + 1) % mod;       r[i] = (f[i] + (f[i - 1] * f[i - 1] % mod * f[i - 1]                       + f[i - 1] * f[i - 1] * 3                       + f[i - 1] * 2) % mod * inv6) % mod;     }     ll ans = ((r[n] - r[n - 1]) * 2 - 1) % mod;     df[0] = f[0];     for (int i = 1; i <= n; i++)       df[i] = f[i] - f[i - 1];     for (int i = 1; i <= n - 2; i++) {       (ans += (df[i] - df[i - 1]) * (df[n - 1 - i] - 1)) %= mod;     }     printf( %lld n , (ans + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 201;   set<int> graph[N];   map<pair<int, int>, int> edges;   pair<int, int> bfs(int node) {     int dist[N] = {0};     int vis[N] = {0};     queue<pair<int, int> > q;     q.push({0, node});     while (!q.empty()) {       int top = q.front().second;       q.pop();       if (vis[top]) continue;       vis[top] = true;       for (set<int>::iterator it = graph[top].begin(); it != graph[top].end();            it++) {         int to = *it;         if (vis[to]) continue;         dist[to] = dist[top] + 1;         q.push({dist[to], to});       }     }     pair<int, int> temp = {node, 0};     for (int i = 1; i <= N; i++) {       if (dist[i] > temp.second) {         temp.second = dist[i];         temp.first = i;       }     }     return temp;   }   int find_dia(int node) {     pair<int, int> temp = bfs(node);     temp = bfs(temp.first);     return temp.second;   }   int main(void) {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       graph[u].insert(v);       graph[v].insert(u);       edges[{u, v}] = 1;     }     int ans = 0;     for (map<pair<int, int>, int>::iterator it = edges.begin(); it != edges.end();          it++) {       int u = (*it).first.first;       int v = (*it).first.second;       graph[u].erase(v);       graph[v].erase(u);       ans = max(ans, find_dia(v) * find_dia(u));       graph[u].insert(v);       graph[v].insert(u);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, n1, n2;     scanf( %d%d%d , &n, &n1, &n2);     if (n1 > n2) swap(n1, n2);     vector<double> X;     double x;     for (int i = 0; i < n; i++) {       scanf( %lf , &x);       X.push_back(x);     }     sort(X.begin(), X.end());     double sum1 = 0, sum2 = 0;     for (int i = n - n1 - n2; i < n; i++) {       if (i < n - n1)         sum2 += X[i];       else         sum1 += X[i];     }     sum1 /= n1;     sum2 /= n2;     printf( %.8lf , sum1 + sum2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100100, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998244353,                   sq = 450, base = 727, lg = 30;   long long n, m, x, y, z, w, ans, t, l[N], r[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];       if (i == 0) {         x = l[i];         y = r[i];         continue;       }       x = min(x, l[i]);       y = max(y, r[i]);     }     for (int i = 0; i < n; i++) {       if (l[i] == x && r[i] == y) return cout << i + 1, 0;     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (m == 0) {       cout << n <<   n ;       return 0;     }     string hint[m];     getline(cin, hint[0]);     vector<vector<string> > h(m);     for (int i = 0; i < m; i++) {       getline(cin, hint[i]);       stringstream ss(hint[i]);       string w;       while (ss >> w) h[i].push_back(w);     }     int i;     int ans = 0;     for (i = 0; i < n; i++) {       bool yes = true;       for (int j = 0; j < m; j++) {         if (h[j][2] ==  left ) {           int k = atoi(h[j][4].c_str()) - 1;           if (i >= k) {             yes = false;             break;           }         } else if (h[j][2] ==  right ) {           int k = atoi(h[j][4].c_str()) - 1;           if (i <= k) {             yes = false;             break;           }         }       }       if (yes) ans++;     }     if (ans == 0) ans = -1;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200], n, i, s = 0;     scanf( %d , &n);     for (i = 0; i < 2 * n - 1; i++) {       scanf( %d , &a[i]);       if (a[i] < 0)         s -= a[i];       else         s += a[i];     }     if (n % 2 == 0) {       sort(a, a + 2 * n - 1);       for (i = 0; i < 2 * n - 1; i++) {         if (a[i] > 0) break;       }       if (i % 2 == 1) {         if (a[i - 1] + a[i] < -a[i - 1] - a[i] || a[i] < 0)           s -= fabs(2 * a[i]);         else           s += 2 * a[i - 1];       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[200005], b[200005], c[200005];   int num = 0;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]]++;     }     for (int i = 1; i <= n; i++) {       if (b[i] == 0) c[++num] = i;     }     cout << num << endl;     sort(c + 1, c + 1 + num);     int tot = 0;     int hson[200005];     memset(hson, 0, sizeof(hson));     for (int i = 1; i <= n; i++) {       if (b[a[i]] > 1) {         if (c[tot + 1] > a[i] && hson[a[i]] == 0) {           hson[a[i]]++;           continue;         }         tot++;         b[a[i]]--;         a[i] = c[tot];       }     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b;   stack<long long int> st;   bool dfs(long long int n) {     if (n > b) {       return false;     }     if (n == b) {       return true;     }     bool a1, a2;     a1 = dfs(n * 2);     if (a1) {       st.push(n * 2);       return true;     }     a2 = dfs((n * 10) + 1);     if (a2) {       st.push((n * 10) + 1);       return true;     }     return false;   }   int main() {     cin >> a >> b;     if (dfs(a)) {       cout <<  YES n ;       cout << st.size() + 1 <<   n ;       cout << a <<    ;       while (!st.empty()) {         cout << st.top() <<    ;         st.pop();       }     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void printV(vector<int> &S) {     for (int s : S) {       cout << s;     }     cout << endl;   }   void solve() {     int x;     cin >> x;     string T;     cin >> T;     vector<int> S;     for (int i = 0; i < (int)T.size(); i++) {       S.push_back(T[i] -  0 );     }     int l = 0;     while (x > (int)S.size()) {       int end = (int)S.size();       for (int rp = 0; rp < S[l] - 1; rp++) {         for (int i = l + 1; i < end; i++) {           S.push_back(S[i]);         }       }       l++;     }     long long len = (long long)S.size() - l - 1;     for (int i = l; i < x; i++) {       len *= S[i];       len--;       len %= MOD;     }     cout << (len + x + 1 + MOD) % MOD << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   int a[10010];   int n, cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++)       if (a[a[i]] == i && a[i] <= i) cnt++;     cout << cnt << endl;     return 0;   }