malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void upmin(T &x, T y) {     y < x ? x = y : 0;   }   template <typename T>   inline void upmax(T &x, T y) {     x < y ? x = y : 0;   }   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long OO = 1e18;   const int N = 1e5 + 100;   int gi() {     int w = 0;     bool q = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) q = 0, c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return q ? w : -w;   }   int w[N];   int p[N];   inline int phi(int n) {     int ans = n;     for (int i = 2; i <= n; i++)       if (!(n % i)) {         ans = ans / i * (i - 1);         while (!(n % i)) n /= i;       }     return ans;   }   inline int mul(int x, int y, int mod) {     return 1LL * x * y >= mod ? 1LL * x * y % mod + mod : x * y;   }   inline int qpow(int x, int y, int mod) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x, mod);       x = mul(x, x, mod);       y >>= 1;     }     return ans;   }   int main() {     int n = gi(), i, Q, m, l, r, ans;     p[0] = gi();     for (m = 0; p[m] != 1; p[m + 1] = phi(p[m]), m++)       ;     p[m + 1] = 1;     for (i = 1; i <= n; i++) w[i] = gi();     Q = gi();     while (Q--) {       l = gi(), r = gi();       ans = 1;       for (i = min(r - l, m); ~i; i--) ans = qpow(w[i + l], ans, p[i]);       cout << ans % p[0] << endl;     }     return 0;   }
#include <bits/stdc++.h>   int a[100006];   int vis[100006];   int visyu[100006];   int main() {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vis[a[i]]++;       if (vis[a[i]] == 2) {         printf( 0 n );         return 0;       }     }     int mans = -1;     for (int i = 1; i <= n; i++) {       visyu[a[i] & x]++;       if (visyu[a[i] & x] && vis[a[i] & x] && ((a[i] & x) != a[i])) {         printf( 1 n );         return 0;       } else if (visyu[a[i] & x] == 2) {         mans = 2;       }     }     printf( %d n , mans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void Read(T &cn) {     char c;     int sig = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) sig = -1;     cn = c - 48;     while (isdigit(c = getchar())) cn = cn * 10 + c - 48;     cn *= sig;   }   template <typename T>   void Write(T cn) {     if (cn < 0) {       putchar( - );       cn = 0 - cn;     }     int wei = 0;     T cm = 0;     int cx = cn % 10;     cn /= 10;     while (cn) wei++, cm = cm * 10 + cn % 10, cn /= 10;     while (wei--) putchar(cm % 10 + 48), cm /= 10;     putchar(cx + 48);   }   template <typename T>   void Max(T &cn, T cm) {     cn = cn < cm ? cm : cn;   }   template <typename T>   void Min(T &cn, T cm) {     cn = cn < cm ? cn : cm;   }   struct qwe {     long long v, c;     void getit() {       Read(v);       Read(c);     }     inline friend bool operator<(qwe a, qwe b) {       return a.v == b.v ? a.c > b.c : a.v < b.v;     }   };   struct xian {     long long k, b;     long long suan(long long cn) { return (cn - b + k - 1) / k; }     void mk(long long cn, long long cm) {       k = cn;       b = cm;     }   };   qwe a[200100 + 1];   int n;   long long m;   int xu[200100 + 1], xlen;   long long f[200100 + 1], g[200100 + 1];   xian zhan[200100 + 1];   int l, r;   int jiao_z(long long cn, xian A, xian B) {     return cn * (A.k - B.k) <= (B.b - A.b);   }   int jiao(xian A, xian B, xian C) {     double db1 = (B.b - A.b), db2 = (C.b - B.b);     double dk1 = (A.k - B.k), dk2 = (B.k - C.k);     return db1 * dk2 >= db2 * dk1;   }   long long qiu(int cn, int cm) {     while (l < r && jiao_z(zhan[l].suan(cn), zhan[l], zhan[l + 1])) l++;     if (l > r) return -10000000000000000;     return -zhan[l].suan(cn) * (cm - zhan[l].k) - cn + zhan[l].b;   }   void zeng(int ck, long long cb) {     xian lin;     lin.mk(ck, cb);     while (l < r && jiao(zhan[r - 1], zhan[r], lin)) r--;     zhan[++r] = lin;   }   int main() {     Read(n);     Read(m);     for (int i = 1; i <= n; i++) a[i].getit();     sort(a + 1, a + n + 1);     xlen = 0;     for (int i = 1; i <= n; i++) {       if (a[i].v <= 0) continue;       while (xlen && a[xu[xlen]].c > a[i].c) xlen--;       xu[++xlen] = i;     }     for (int i = 1; i <= xlen; i++) a[i] = a[xu[i]];     n = xlen;     f[0] = 0;     a[0].v = a[0].c = 0;     l = 1;     r = 0;     f[1] = 0;     zeng(a[1].v, f[1]);     long long ans = (m + a[1].v - 1) / a[1].v;     for (int i = 2; i <= n; i++) {       f[i] = qiu(a[i].c, a[i].v);       zeng(a[i].v, f[i]);       Min(ans, (m - f[i] + a[i].v - 1) / a[i].v);     }     Write(ans);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 400010;   int c[maxn];   int ans[maxn];   void upd(int n, int k) {     n++;     while (n < maxn) c[n] += k, n += n & (-n);   }   int get(int n) {     n++;     int ans = 0;     while (n) ans += c[n], n -= n & (-n);     return ans;   }   int BS(int n) {     int l = 0, r = maxn - 1, mid;     while (l < r) {       mid = (l + r) / 2;       if (get(mid) >= n)         r = mid;       else         l = mid + 1;     }     return l;   }   int arr[maxn];   int a[maxn], b[maxn];   int main() {     int n, i, j, k;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) {       arr[i] += get(a[i]) - 1;       upd(a[i], -1);     }     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) {       arr[i] += get(b[i]) - 1;       upd(b[i], -1);     }     for (i = n - 1; i >= 0; i--) {       if (arr[i] <= n - i - 1)         ;       else {         arr[i] %= n - i;         if (i) arr[i - 1]++;       }     }     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) ans[i] = BS(arr[i] + 1), upd(ans[i], -1);     for (i = 0; i < n; i++) cout << ans[i] <<    ;     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   long long n, l, x, y;   long long a[100100];   int main() {     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) cin >> a[i];     bool fx = false, fy = false;     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + x)) {         fx = true;         break;       }     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + y)) {         fy = true;         break;       }     }     if (fx && fy) {       printf( 0 n );       return 0;     }     if (fx && !fy) {       printf( 1 n );       cout << y << endl;       return 0;     }     if (!fx && fy) {       printf( 1 n );       cout << x << endl;       return 0;     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + x + y)) {         printf( 1 n );         cout << a[i] + x << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + y - x)) {         if (a[i] + y > l && a[i] - x < 0) continue;         if (a[i] + y <= l) {           printf( 1 n );           cout << a[i] + y << endl;         } else {           printf( 1 n );           cout << a[i] - x << endl;         }         return 0;       }     }     printf( 2 n );     cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 500010;   int n, m;   int seg[MAX];   int vis[MAX];   int p[MAX];   int in[MAX], out[MAX];   int aux = 0;   vector<int> adj[MAX];   set<int> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int x, s;     cin >> x >> s;     if (!s) {       if (x == 1)         cout <<  0 0 n ;       else         cout <<  -1 -1 n ;       return 0;     }     if (9 * x < s) {       cout <<  -1 -1 n ;       return 0;     }     string sb;     int s1 = s;     for (int i = 1; i <= x; i++) {       if (s > 9)         sb +=  9 , s -= 9;       else if (i == x)         sb +=  0  + s;       else if (s > 1)         sb +=  0  + (s - 1), s = 1;       else         sb +=  0 ;     }     reverse(sb.begin(), sb.end());     cout << sb <<   n ;     string st;     for (int i = 1; i <= x; i++) {       if (s1 >= 9)         st +=  9 , s1 -= 9;       else         st += s1 +  0 , s1 = 0;     }     cout << st <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n, k;   long long a[N];   bool check(long double x) {     long double ans1 = 0, ans2 = 0;     for (long long i = 0; i < n; i++) {       if (a[i] > x) ans1 += (long double)(a[i] - x);       if (x > a[i]) ans2 += (long double)(x - a[i]);     }     return ans1 * (100 - k) * 0.01 >= ans2;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];     long double l = *min_element(a, a + n), r = *max_element(a, a + n) + 1;     for (long long i = 0; i < 300; i++) {       long double mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     cout << fixed << setprecision(12);     cout << l <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100000];   int main() {     long long n;     long long cnt = 0;     scanf( %I64d , &n);     for (long long i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       for (long long j = 0; j < i; j++)         if (a[j] > a[i]) cnt++;     }     cout << (cnt % 2 + (cnt / 2) * 4) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v;   map<int, int> a, b;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     int m = n / 2;     if (n % 2 != 0) {       m++;     }     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       a[x]++;       if (x != y) {         b[y]++;       }       v.push_back(x);       v.push_back(y);     }     int ans = 1e9;     for (int i = 0; i < 2 * n; i++) {       int cur = v[i];       int cnt = a[cur];       int need = max(0, m - cnt);       if (b[cur] >= need) {         ans = min(ans, need);       }     }     if (ans == 1e9) {       cout << -1;       return 0;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int arr[n];     int count = 0;     int count1 = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] & 1) {         count++;       }     }     int f[n];     int sum = 0;     for (int i = 0; i < n; i++) {       f[i] = floor(double(arr[i]) / 2);       sum += f[i];     }     for (int i = 0; i < n; i++) {       if (sum == 0) break;       if (arr[i] & 1) {         sum++;         f[i]++;       }     }     for (int i = 0; i < n; i++) {       cout << f[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mnt[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int mntl[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int main() {     int y1, y2, m1, m2, d1, d2, i, j, k, l, ans = 0;     scanf( %d:%d:%d , &y1, &m1, &d1);     scanf( %d:%d:%d , &y2, &m2, &d2);     if (y1 == y2 && m1 == m2)       cout << abs(d1 - d2);     else {       int chk1 = y1 * 365 + m1 * 30 + d1;       int chk2 = y2 * 365 + m2 * 30 + d2;       if (chk2 < chk1) {         int tmp;         tmp = y1;         y1 = y2;         y2 = tmp;         tmp = m1;         m1 = m2;         m2 = tmp;         tmp = d1;         d1 = d2;         d2 = tmp;       }       for (i = y1 + 1; i < y2; i++) {         ans += 365;         if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) ans += 1;       }       if ((y1 % 4 == 0 && y1 % 100 != 0) || (y1 % 400 == 0)) {         int lm = 13;         if (y1 == y2) lm = m2;         for (i = m1 + 1; i < lm; i++) {           ans += mntl[i - 1];         }         ans += mntl[m1 - 1] - d1 + 1;       } else {         int lm = 13;         if (y1 == y2) lm = m2;         for (i = m1 + 1; i < lm; i++) {           ans += mnt[i - 1];         }         ans += mnt[m1 - 1] - d1 + 1;       }       if ((y2 % 4 == 0 && y2 % 100 != 0) || (y2 % 400 == 0)) {         int lm = 1;         if (y1 != y2) {           for (i = lm; i < m2; i++) {             ans += mntl[i - 1];           }         }         ans += d2 - 1;       } else {         int lm = 1;         if (y1 != y2) {           for (i = lm; i < m2; i++) {             ans += mnt[i - 1];           }         }         ans += d2 - 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   long long I() {     long long a;     cin >> a;     return a;   }   void PV(vector<long long> v) {     for (long long i = 0; i < (long long)v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void PA(long long v[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cout << v[i] <<    ;     cout <<   n ;   }   void IA(long long a[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cin >> a[i];   }   const long long N = (2e5) + 7, N1 = 1e9 + 7, MOD = 1e9 + 7, INF = (1e17 + 7);   long long fact[N];   long long power(long long a, long long b) {     long long k = 1;     for (; b; b /= 2, a = a * a % MOD)       if (b % 2 == 1) k = k * a % MOD;     return k % MOD;   }   void pre() {     fact[0] = 1;     for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % N1;   }   void solve() {     long long n;     cin >> n;     long long ans = fact[2 * n] * (power(2, N1 - 2));     ans %= MOD;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t1 = 1, x0 = 1;     pre();     cin >> t1;     while (t1--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   stack<int> sk;   int main() {     int T;     string s;     cin >> T;     while (T--) {       while (sk.size()) sk.pop();       cin >> s;       int cnt = 0;       for (int i = 0; i < s.size(); ++i) {         if (sk.empty()) {           sk.push(s[i] -  0 );           continue;         }         if (s[i] ==  0  && sk.top() == 1) {           cnt++;           sk.pop();         } else if (s[i] ==  1  && sk.top() == 0) {           cnt++;           sk.pop();         } else           sk.push(s[i] -  0 );       }       if (cnt % 2)         puts( DA );       else         puts( NET );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, chng_cnt;     cin >> n >> m;     int ara1[n + 1], ara2[n + 1], cnt[m + 1], maximizedMin;     memset(cnt, 0, sizeof(cnt));     memset(ara1, 0, sizeof(ara1));     memset(ara2, 0, sizeof(ara2));     for (i = 1; i <= n; i++) {       cin >> ara1[i];     }     maximizedMin = n / m;     for (i = 1; i <= n; i++) {       if (ara1[i] > m) {         ara2[i] = -1;       } else {         cnt[ara1[i]]++;         if (cnt[ara1[i]] <= maximizedMin) {           ara2[i] = ara1[i];         } else {           ara2[i] = -1;         }       }     }     chng_cnt = 0;     for (i = 1; i <= m; i++) {       if (cnt[i] < maximizedMin) {         for (j = 1; j <= n; j++) {           if (cnt[i] == maximizedMin) break;           if (ara2[j] == -1) {             ara2[j] = i;             cnt[i]++;             chng_cnt++;           }         }       }     }     for (i = 1; i <= n; i++) {       if (ara2[i] == -1) {         ara2[i] = ara1[i];       }     }     printf( %d %d n , maximizedMin, chng_cnt);     for (i = 1; i <= n; i++) {       if (i == n)         printf( %d n , ara2[i]);       else         printf( %d  , ara2[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, arr[200010];     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     long long sum = arr[n - 1];     for (i = n - 1; i > 0; i--) {       if (arr[i] <= arr[i - 1] && arr[i - 1] != 0) {         if (arr[i] == 0)           arr[i - 1] = arr[i];         else           arr[i - 1] = arr[i] - 1;       }       sum += arr[i - 1];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0) {       cout << s;       return 0;     }     if (s.length() == 1) {       if (k > 0) {         cout <<  0 ;         return 0;       }     }     if (s[0] !=  1 ) {       s[0] =  1 ;       k--;     }     for (long long i = 1; i < n; i++) {       if (k > 0)         if (s[i] !=  0 ) {           s[i] =  0 ;           k--;         }     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     scanf( %d , &test);     while (test--) {       int fuck;       string str;       scanf( %d , &fuck);       cin >> str;       string ans =   ;       for (auto &x : str) {         if ((x -  0 ) % 2 == 1) {           ans += x;           if (ans.size() == 2) {             break;           }         }       }       if (ans.size() == 2) {         puts(ans.c_str());         continue;       }       puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, int> MP;   int Q = 1;   vector<pair<int, int> > adj[500005];   long long C[500005];   set<int> S;   int p[500005];   long long pw(int x) {     if (!x) return 1LL;     if (x & 1) return 2 * pw(x - 1) % 1000000007;     long long hf = pw(x / 2);     return hf * hf % 1000000007;   }   int par(int x) {     if (p[x] == x) return x;     return p[x] = par(p[x]);   }   int main() {     int N, M, K;     scanf( %d%d%d , &N, &M, &K);     long long X = (1LL << K);     for (int i = 1; i <= N; i++) scanf( %lld , &C[i]);     for (int i = 0; i < M; i++) {       int u, v;       scanf( %d%d , &u, &v);       long long x = C[u] ^ C[v];       int t = MP[x];       if (!t) {         MP[x] = Q;         adj[Q].push_back(pair<int, int>(u, v));         Q++;       } else {         adj[t].push_back(pair<int, int>(u, v));       }     }     int ans = 0;     for (int i = 1; i <= N; i++) p[i] = i;     for (int i = 1; i < Q; i++) {       int sz = N;       for (pair<int, int> j : adj[i]) {         int u = j.first, v = j.second;         S.insert(u);         S.insert(v);         if (par(u) != par(v)) {           sz--;           p[p[v]] = p[u];         }       }       ans = (ans + pw(sz)) % 1000000007;       while (S.size()) {         int now = *(S.begin());         p[now] = now;         S.erase(S.begin());       }     }     printf( %lld n ,            ((X - Q + 1) % 1000000007 * pw(N) % 1000000007 + ans) % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename L>   bool smax(T &x, L y) {     return x < y ? (x = y, true) : false;   }   struct Q {     int p, id;   };   int get(int, int);   void dfs(int);   void sack(int, bool);   const int MAXN = 1e5 + 15, LG = 20;   int h[MAXN], cnt[MAXN];   int st[MAXN], ft[MAXN], add[MAXN];   int ans[MAXN];   int par[LG][MAXN];   vector<int> adj[MAXN];   vector<Q> node[MAXN];   int n, m;   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cerr <<  HELLO WORLD :) n ;     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       adj[tmp].push_back(i);     }     dfs(0);     cin >> m;     for (int i = 1; i <= m; i++) {       int p, v;       cin >> v >> p;       node[get(v, p)].push_back({p, i});     }     sack(0, 0);     for (int i = 1; i <= m; i++) cout << ans[i] <<    ;     return cout <<   n , false;   }   void dfs(int v) {     static int t = 0;     st[v] = t++;     add[st[v]] = v;     for (int i = 1; i < LG; i++) par[i][v] = par[i - 1][par[i - 1][v]];     for (auto u : adj[v]) {       h[u] = h[v] + 1;       par[0][u] = v;       dfs(u);     }     ft[v] = t;   }   int get(int v, int p) {     int u = v;     for (int i = LG - 1; ~i; i--)       if (p >> i & 1) u = par[i][u];     return u;   }   void sack(int v, bool keep) {     int id = -1, mx = -1;     for (auto u : adj[v])       if (smax(mx, ft[u] - st[u])) id = u;     for (auto u : adj[v])       if (u != id) sack(u, 0);     if (id != -1) sack(id, 1);     for (auto u : adj[v])       if (u != id)         for (int i = st[u]; i < ft[u]; i++) cnt[h[add[i]]]++;     cnt[h[v]]++;     if (v)       for (auto u : node[v]) ans[u.id] = cnt[h[v] + u.p] - 1;     if (!keep)       for (int i = st[v]; i < ft[v]; i++) cnt[h[add[i]]]--;   }
#include <bits/stdc++.h>   using namespace std;   const long long int conv[][3] = {{1, 2, 3}, {2, 3, 1}, {3, 1, 2}};   void solve(long long int n) {     int r = n % 3;     if (r != 0) n = (n / 3 + 1) * 3;     if (r == 0)       r = 2;     else       r = r - 1;     int k = 0;     long long int cnt = 3;     while (cnt < n) {       k++;       cnt += 3 * pow(4, k);     }     cnt -= 3 * pow(4, k);     cnt = n - cnt;     vector<int> v(k + 1);     v[0] = 1;     int j;     for (int i = 1; i < k + 1; i++) {       for (j = 0; j < 4; j++) {         cnt -= 3 * pow(4, k - i);         if (cnt <= 0) {           cnt += 3 * pow(4, k - i);           break;         }       }       v[i] = j;     }     long long int ans = 0;     for (int i = 0; i < k + 1; i++) {       if (v[i] > 0) {         ans += conv[v[i] - 1][r] << (2 * (k - i));       }     }     printf( %lld n , ans);   }   int main() {     int t;     long long int n;     scanf( %d , &t);     while (t--) {       scanf( %lld , &n);       solve(n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 9.2e18;   const int maxn = 1e6 + 70;   const int INF = 2.1e9;   const int maxm = 1e6 + 70;   const int MOD = 1e9 + 7;   const double eps = 1e-7;   const double PI = acos(-1.0);   int n, m, k;   vector<int> G[maxn];   int dep[maxn], mind[maxn], dp[maxn];   int dfs(int u) {     if (!G[u].size()) {       mind[u] = dep[u] - k;       dp[u] = 1;       return 1;     } else {       int mx = 0;       mind[u] = dep[u];       dp[u] = 0;       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         dep[v] = dep[u] + 1;         int val = dfs(v);         mind[u] = min(mind[u], mind[v]);         if (mind[v] <= dep[u]) {           dp[u] += dp[v];           mx = max(mx, val - dp[v]);         } else {           mx = max(mx, val);         }       }       return dp[u] + mx;     }   }   int main() {     while (cin >> n >> k) {       for (int i = 1; i <= n; i++) G[i].clear();       for (int i = 2; i <= n; i++) {         int f;         scanf( %d , &f);         G[f].push_back(i);       }       dep[1] = 0;       int ans = dfs(1);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, d, a, b, x, y;     cin >> n >> d >> a >> b;     pair<long long, long long> arr[n];     for (int i = 0; i < n; i++) {       cin >> x >> y;       x *= a;       y *= b;       arr[i] = {x + y, i + 1};     }     sort(arr, arr + n);     vector<int> vec;     for (int i = 0; i < n; i++) {       if (d >= arr[i].first) {         d -= arr[i].first;         vec.push_back(arr[i].second);       } else         break;     }     cout << vec.size() << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   const int maxn = 5e4 + 9;   int p[1009], a[1009];   bool vis[1009];   int dfs(int i) {     if (vis[i]) return i;     vis[i] = 1;     int id = dfs(p[i]);     return id;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       a[i] = dfs(i);     }     for (int i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }