malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int iinf = 0x3f3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const int N = 1e4, M = 1e5;   int n, m, p, a[N], b[M];   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int mypow(int a, int first = p - 2, int res = 1) {     for (; first; first >>= 1, a = 1ll * a * a % p)       (first & 1) && (res = 1ll * res * a % p);     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> m >> p;     int phi = p - 1, g = phi;     for (int i(0); i < (n); ++i) cin >> a[i];     for (int i(0); i < (m); ++i) cin >> b[i], g = gcd(g, b[i]);     vector<int> c;     for (int d = 1; d * d <= phi; ++d)       if (phi % d == 0)         c.push_back(d), d *d < phi ? c.push_back(phi / d) : void();     sort(c.begin(), c.end());     vector<int> mb;     for (int i(0); i < (n); ++i) {       int mn_c = -1;       for (int &u : c)         if (mypow(a[i], 1ll * g * u % phi) == 1) {           mb.push_back(phi / u);           break;         }     }     sort(mb.begin(), mb.end());     mb.erase(unique(mb.begin(), mb.end()), mb.end());     vector<int> f(int((mb).size()), 0);     int ns = 0;     for (int i((int((mb).size())) - 1); i >= 0; --i) {       f[i] = phi / mb[i];       for (int j = i + 1; j < int((mb).size()); ++j)         if (mb[j] % mb[i] == 0) f[i] -= f[j];       ns += f[i];     }     cout << ns <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double p[101], f[101], ans = 0, last = 1;   double Calc(int x) { return 1 - (1 - f[x]) * (1 - p[x]); }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       p[i] = f[i] = x / 100.0;       last *= p[i];     }     ans += last * n;     for (int i = n + 1; i <= 300000; i++) {       int x = 1;       for (int j = 1; j <= n; j++) {         if (Calc(j) / f[j] > Calc(x) / f[x]) x = j;       }       double now = last * Calc(x) / f[x];       f[x] = Calc(x);       ans += (now - last) * i;       last = now;     }     printf( %.8f n , ans);   }
#include <bits/stdc++.h>   using namespace std;   pair<double, double> p[100100];   double dt[100100];   double db[100100];   double da[100100];   int main() {     double ax, ay, bx, by, tx, ty;     int n;     cin >> ax >> ay >> bx >> by >> tx >> ty;     cin >> n;     double ans = 0;     scanf( %lf %lf , &p[0].first, &p[0].second);     ans += sqrt((p[0].first - tx) * (p[0].first - tx) +                 (p[0].second - ty) * (p[0].second - ty));     dt[0] = ans;     for (int i = 1; i < n; i++) {       scanf( %lf %lf , &p[i].first, &p[i].second);       dt[i] = sqrt((p[i].first - tx) * (p[i].first - tx) +                    (p[i].second - ty) * (p[i].second - ty));       ans += dt[i];     }     ans *= 2;     for (int i = 0; i < n; i++) {       da[i] = sqrt((p[i].first - ax) * (p[i].first - ax) +                    (p[i].second - ay) * (p[i].second - ay));       db[i] = sqrt((p[i].first - bx) * (p[i].first - bx) +                    (p[i].second - by) * (p[i].second - by));     }     double p1, p2, p3, p4;     double Da = 1.7976931348623158e+308, Db = 1.7976931348623158e+308;     int indexofa = -1;     int indexofb = -1;     for (int i = 0; i < n; i++) {       if (da[i] - dt[i] < Da) {         Da = da[i] - dt[i];         indexofa = i;       }     }     for (int i = 0; i < n; i++) {       if (db[i] - dt[i] < Db && i != indexofa) {         Db = db[i] - dt[i];         indexofb = i;       }     }     p1 = Da + Db;     Da = 1.7976931348623158e+308, Db = 1.7976931348623158e+308;     indexofa = -1;     indexofb = -1;     for (int i = 0; i < n; i++) {       if (db[i] - dt[i] < Db) {         Db = db[i] - dt[i];         indexofb = i;       }     }     for (int i = 0; i < n; i++) {       if (da[i] - dt[i] < Da && i != indexofb) {         Da = da[i] - dt[i];         indexofa = i;       }     }     p2 = Da + Db;     Db = 1.7976931348623158e+308;     indexofb = -1;     for (int i = 0; i < n; i++) {       if (db[i] - dt[i] < Db) {         Db = db[i] - dt[i];         indexofb = i;       }     }     p3 = Db;     Da = 1.7976931348623158e+308;     indexofa = -1;     for (int i = 0; i < n; i++) {       if (da[i] - dt[i] < Da) {         Da = da[i] - dt[i];         indexofa = i;       }     }     p4 = Da;     printf( %.12lf , min(min(p1, p2), min(p3, p4)) + ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     while (~scanf( %d%d%d%d , &a, &b, &c, &n)) {       if (c > a || c > b || n - (a + b - c) < 1)         printf( -1 n );       else         printf( %d n , n - (a + b - c));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int count = 0, wc = 0;       bool flag = 0;       int m = n;       while (n--) {         string s;         cin >> s;         int l = s.size();         if (l % 2 == 1) flag = 1;         int zeroc = 0, onec = 0;         for (int i = 0; i < l; i++) {           if (s[i] ==  0 ) {             zeroc++;           } else {             onec++;           }         }         if (onec % 2 == 1 && zeroc % 2 == 1) {           wc++;         } else {           count++;         }       }       if (flag == 1)         cout << m << endl;       else {         count = count + 2 * (wc / 2);         cout << count << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int cost = 0, ans = 0, a[n];     vector<pair<long long int, long long int>> pr(n);     for (long long int(i) = 0; (i) < (n); (i)++) {       long long int a;       cin >> a;       pr[i] = make_pair(a, i + 1);     }     sort(pr.begin(), pr.end());     vector<long long int> v;     for (long long int(i) = 0; (i) < (n); (i)++) {       if ((cost > k) || (cost + pr[i].first > k))         break;       else {         cost += pr[i].first;         ans++;         v.push_back(pr[i].second);       }     }     cout << ans <<   n ;     sort(v.begin(), v.end());     for (long long int(i) = 0; (i) < (ans); (i)++) {       cout << v[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     string ans;     for (int i = 0; i < n; i++) ans +=  U ;     for (int i = 0; i < m; i++) ans +=  L ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m - 1; j++) {         ans += (i % 2 ?  L  :  R );       }       if (i < n - 1) ans +=  D ;     }     cout << ans.size() <<   n  << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2010, mod = 998244353;   int sm[2][N], n, f[N][N], a[N][N], ans;   void add(int x, int y, int z) {     for (; x <= n; x += x & -x) sm[z][x] += y;   }   int query(int x, int z) {     int ret = 0;     for (; x; x -= x & -x) ret += sm[z][x];     return ret;   }   void Init() {     f[0][0] = 1;     for (int i = 1; i <= n; ++i) {       f[i][0] = (long long)f[i - 1][0] * i % mod;       for (int j = 1; j <= i; ++j)         f[i][j] = (f[i][j - 1] - f[i - 1][j - 1] + mod) % mod;     }   }   int p[N], q[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     Init();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) cin >> a[i][j];     for (int i = 1; i <= n; ++i) {       int les = n;       ans = (long long)ans * f[n][n] % mod;       memset(sm, 0, sizeof sm);       memset(p, 0, sizeof p);       memset(q, 0, sizeof q);       for (int j = 1; j <= n; ++j) {         int u = query(a[i][j] - 1, 0);         p[a[i - 1][j]] = 1;         if (q[a[i - 1][j]])           ++les;         else if (a[i - 1][j])           add(a[i - 1][j], 1, 0), add(a[i - 1][j], 1, 1);         int v = a[i][j] - 1 - query(a[i][j] - 1, 1);         les -= 2;         if (i == 1)           ans = (ans + (long long)v * f[n - j][0]) % mod;         else           ans = (ans + (long long)u * f[n - j][les + 1] +                  (long long)v * f[n - j][les]) %                 mod;         q[a[i][j]] = 1;         if (p[a[i][j]])           add(a[i][j], -1, 0), ++les;         else           add(a[i][j], 1, 1);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       vector<int> p0;       vector<int> p1;       vector<int> ans(n);       for (int i = 0; i < n; i++) {         int newpos = p0.size() + p1.size();         if (s[i] ==  0 ) {           if (p1.empty()) {             p0.push_back(newpos);           } else {             newpos = p1.back();             p0.push_back(newpos);             p1.pop_back();           }         } else {           if (p0.empty()) {             p1.push_back(newpos);           } else {             newpos = p0.back();             p1.push_back(newpos);             p0.pop_back();           }         }         ans[i] = newpos + 1;       }       cout << p0.size() + p1.size() << endl;       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       string s;       cin >> s;       reverse(s.begin(), s.end());       if (s.substr(0, 2) ==  op ) {         cout <<  FILIPINO n ;       } else if (s.substr(0, 4) ==  used  || s.substr(0, 4) ==  usam ) {         cout <<  JAPANESE n ;       } else if (s.substr(0, 5) ==  adinm ) {         cout <<  KOREAN n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char field[1000][1000];   int deltas[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   int n, m;   int si, sj, ti, tj;   bool possible;   void go(int i, int j, char num) {     for (auto d : deltas) {       int ii = i;       int jj = j;       while (true) {         ii += d[0];         jj += d[1];         if (ii < 0 || jj < 0 || ii >= n || jj >= m) break;         if (field[ii][jj] ==  T ) possible = true;         if (field[ii][jj] !=  . ) break;         field[ii][jj] = num;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       string line;       cin >> line;       for (int j = 0; j < m; j++) {         field[i][j] = line[j];         if (line[j] ==  T ) {           ti = i;           tj = j;         }         if (line[j] ==  S ) {           si = i;           sj = j;         }       }     }     go(si, sj,  0 );     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (field[i][j] ==  0 ) {           go(i, j,  1 );         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (field[i][j] ==  1 ) {           go(i, j,  2 );         }       }     }     if (possible)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int powe(long long int n, long long int m) {     if (m == 0) return 1;     long long int t = powe(n, m / 2);     if (m % 2 == 0) return (t * t);     return (((t * t)) * n);   }   long long int mpowe(long long int n, long long int m) {     if (m == 0) return 1;     long long int t = powe(n, m / 2);     t %= 1000000007;     if (m % 2 == 0) return (t * t) % 1000000007;     return (((t * t) % 1000000007) * n) % 1000000007;   }   long long int logtwo(long long int n) {     if (n == 1) return 0;     return logtwo(n / 2) + 1;   }   long long int A[200000 + 1];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long int n, d, i, sum = 0, dt;       cin >> n >> d;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       ;       long long int c;       for (i = 1; i < n; i++) {         c = i;         dt = d / c;         if (a[i] < dt) {           sum += a[i];           d -= (a[i] * c);         } else {           sum += dt;           break;         }       }       sum += a[0];       cout << sum <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const double PI = 3.1415926535897932;   const int dir[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};   const int maxn = 2e5 + 5;   const int MOD = 998244353;   int n, m;   long long A[maxn], invA[maxn];   int w[maxn];   bool vis[maxn];   bool del[maxn];   int B[maxn];   int pos[maxn];   int pre[maxn], nex[maxn];   bool judge(int x) {     if (x == 0 || x == n + 1) return 0;     if (vis[w[x]]) return 0;     return 1;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; i++) {         del[i] = vis[i] = false;         pre[i] = i - 1;         nex[i] = i + 1;       }       for (int i = 1; i <= n; i++) scanf( %d , &w[i]), pos[w[i]] = i;       for (int i = 1; i <= m; i++) {         scanf( %d , &B[i]);         vis[B[i]] = true;       }       long long ans = 1;       for (int i = 1; i <= m; i++) {         int x = pos[B[i]];         int cnt = 0;         cnt += judge(pre[x]);         cnt += judge(nex[x]);         ans = ans * cnt % MOD;         vis[w[x]] = false;         nex[pre[x]] = nex[x];         pre[nex[x]] = pre[x];       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, m, i, j, k, sum;     long long int a[100001];     cin >> n >> k;     bool yo = false;     for (i = 1; i <= k; i++) cin >> a[i];     sum = LONG_LONG_MAX;     for (i = 1; i <= k; i++) {       if (n % a[i] < sum) {         sum = n % a[i];         j = i;         m = n / a[i];       }     }     cout << j <<     << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigmod(p, e / 2, M);       return (T)((t * t) % M);     }     return (T)((long long int)bigmod(p, e - 1, M) * (long long int)p) % M;   }   template <class T>   inline T bigexp(T p, T e) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigexp(p, e / 2);       return (T)((t * t));     }     return (T)((long long int)bigexp(p, e - 1) * (long long int)p);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   int dx4[] = {1, 0, -1, 0};   int dy4[] = {0, 1, 0, -1};   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int nx8[] = {1, 1, -1, -1, 2, 2, -2, -2};   int ny8[] = {2, -2, 2, -2, 1, -1, 1, -1};   int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, q, m, a[200005], b[105], c[105], d[200005], sz, q1[200005][3], t, r[105];   int main() {     scanf( %d , &n);     scanf( %d %d , &q, &m);     for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (__typeof(q) i = (1); i <= (q); i++)       scanf( %d %d %d , &q1[i][0], &q1[i][1], &q1[i][2]);     for (__typeof(m) i = (1); i <= (m); i++) {       scanf( %d , &t);       d[t] = 1;       b[i] = t;     }     for (__typeof(n) i = (1); i <= (n); i++)       if (d[i] > 0) {         c[++sz] = i;         r[sz] = c[sz];       }     for (__typeof(1) i = (q); i >= (1); i--) {       if (q1[i][0] == 1) {         for (int j = 1; j <= sz; j++) {           if (r[j] >= q1[i][1] && r[j] <= q1[i][2]) {             r[j]--;             if (r[j] < q1[i][1]) r[j] = q1[i][2];           }         }       } else {         int l1, r1;         for (int j = 1; j <= sz; j++) {           if (r[j] >= q1[i][1] && r[j] <= q1[i][2]) {             int mid = (q1[i][1] + q1[i][2]) / 2;             if (r[j] <= mid) {               l1 = r[j] - q1[i][1];               r[j] = q1[i][2] - l1;             } else {               l1 = q1[i][2] - r[j];               r[j] = q1[i][1] + l1;             }           }         }       }     }     for (__typeof(m) i = (1); i <= (m); i++)       for (__typeof(sz) j = (1); j <= (sz); j++)         if (b[i] == c[j]) {           cout << a[r[j]] <<    ;           break;         }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int big = 1e7 + 5;   long long int arr[big];   void minDivsieve() {     for (long long int i = 0; i <= big; ++i) arr[i] = i;     for (long long int i = 2; i <= big; ++i) {       if (arr[i] != i) continue;       for (long long int j = i; j <= big; j += i) arr[j] = min(arr[j], i);     }   }   long long int fac[1000001];   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, int p) { return power(n, p - 2, p); }   long long int nCrModPFermat(unsigned long long n, long long int r,                               long long int p) {     if (r == 0) return 1;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   int dp[2][1048577];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int test = 1;     while (test--) {       int n;       cin >> n;       long long int arr[n];       for (int i = 0; i < n; ++i) cin >> arr[i];       long long int res = 0;       long long int currxor = 0;       dp[1][0] = 1;       for (int i = 0; i < n; ++i) {         currxor = currxor ^ arr[i];         res += dp[i % 2][currxor];         dp[i % 2][currxor] += 1;       }       cout << res;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, val = 0, q[1000010];   char d[1000010];   void build(int now, int x, int y) {     if (x == y) return;     int mid = (x + y) / 2;     build(2 * now, x, mid);     build(2 * now, mid + 1, y);   }   int main() {     build(1, 1, 1000);     cin >> x >> y;     while (1) {       if (x == y && x > 1) {         cout <<  Impossible ;         return 0;       }       if (x == y && x == 1) {         for (int i = 1; i <= val; i++) {           cout << q[i] << d[i];         }         return 0;       }       if (x > y) {         long long k = (x - 1) / y;         x -= k * y;         q[++val] = k;         d[val] =  A ;         continue;       }       if (x < y) {         long long k = (y - 1) / x;         y -= k * x;         q[++val] = k;         d[val] =  B ;         continue;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double EPS = 1e-6;   const int INF = 0x3f3f3f3f;   inline int readint() {     int sum = 0;     char c = getchar();     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     if (f) return -sum;     return sum;   }   inline long long readLL() {     long long sum = 0;     char c = getchar();     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     if (f) return -sum;     return sum;   }   const int maxn = 250015;   long long inv[maxn], p[maxn];   void CNumberInit(int MAXNUM, long long mod) {     inv[0] = inv[1] = 1;     p[0] = p[1] = 1;     for (int i = 2; i <= MAXNUM; i++) {       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       p[i] = p[i - 1] * i % mod;     }     for (int i = 2; i <= MAXNUM; i++) inv[i] = inv[i - 1] * inv[i] % mod;   }   long long qmod(long long a, long long b, long long c) {     long long ret = 1;     for (; b; b >>= 1) {       if (b & 1) ret = ret * a % c;       a = a * a % c;     }     return ret;   }   vector<int> megumi;   long long mod;   int k;   long long dp[20][250005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n >> k >> mod;     CNumberInit(n + 5, mod);     if (n % 2) {       cout << qmod(k, n, mod) << endl;     } else {       for (int i = 2; i <= n; i += 2) {         if ((i & n) == i) megumi.push_back(i);       }       long long ans = 0;       dp[0][n] = 1;       for (int i = 1; i <= min(17, k); i++) {         int tmpans = 0;         for (int j = 0; j < megumi.size(); j++) {           if (!dp[i - 1][megumi[j]]) continue;           int Megumi = megumi[j] & (megumi[j] - 1);           int step = Megumi ^ megumi[j];           for (int k = step; k <= Megumi; k += step) {             if ((k & Megumi) == k) {               dp[i][k] += dp[i - 1][megumi[j]] * p[megumi[j]] % mod * inv[k] %                           mod * inv[megumi[j] - k] % mod;               dp[i][k] %= mod;             }           }           tmpans = (tmpans + dp[i - 1][megumi[j]]) % mod;         }         ans += tmpans * inv[k - i] % mod;       }       ans = ans * p[k] % mod;       ans = qmod(k, n, mod) - ans;       ans = (ans % mod + mod) % mod;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n, d;     cin >> n >> d;     pair<long long, long long> s[n];     deque<long long> p;     long long ind, cnt = 1;     for (long long i = 0; i < n; i++) {       cin >> s[i].first;       s[i].second = i;     }     for (long long i = 0; i < n; i++) {       long long tmp;       cin >> tmp;       p.push_back(tmp);     }     s[d - 1].first += p[0];     long long num = s[d - 1].first;     p.pop_front();     for (long long i = 0; i < n; i++) {       if (s[i].second != d - 1 && s[i].first + p[p.size() - 1] <= num) {         s[i].first += p[p.size() - 1];         p.pop_back();       } else if (s[i].second != d - 1) {         s[i].first += p[0];         p.pop_front();       }     }     sort(s, s + n);     for (long long i = n - 1; s[i].second != d - 1; i--) {       if (s[i].first != num) {         cnt++;       }     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     long long p[n + 1];     p[1] = -1;     for (long long i = 2; i <= n; i++) cin >> p[i];     vector<long long> ans;     long long x = n;     while (p[x] != -1) {       ans.push_back(p[x]);       x = p[x];     }     reverse(ans.begin(), ans.end());     for (long long i : ans) cout << i <<    ;     cout << n << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (scanf( %d , &n) != EOF) {       if (n & 1) {         int d = (n - 1) / 2;         printf( %d n , d * 2 + d * d - d);         for (int i = 2; i < n; i += 2) {           for (int j = 2; j < i; j += 2) {             printf( 4 %d %d %d %d n , j, i, j + 1, i + 1);             printf( 4 %d %d %d %d n , j, i, j + 1, i + 1);           }           printf( 3 1 %d %d n , i, i + 1);           printf( 3 1 %d %d n , i, i + 1);         }       } else {         int d = (n - 2) / 2;         printf( %d n , 4 + (d - 1) * 3 + d * d - d);         printf( 3 1 2 3 n );         printf( 3 1 2 4 n );         printf( 3 3 4 1 n );         printf( 3 3 4 2 n );         for (int i = 5; i < n; i += 2) {           for (int j = 1; j < i - 2; j += 2) {             printf( 4 %d %d %d %d n , j, i, j + 1, i + 1);             printf( 4 %d %d %d %d n , j, i, j + 1, i + 1);           }           printf( 4 %d %d %d %d n , i - 2, i, i - 1, i + 1);           printf( 3 %d %d %d n , i - 2, i, i + 1);           printf( 3 %d %d %d n , i - 1, i, i + 1);         }       }     }     return 0;   }