malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #define fo(a,b,c) for (a=b; a<=c; a++)   #define fd(a,b,c) for (a=b; a>=c; a--)   #define fu(x) (((x)&1)?-1:1)   #define add(a,b) a=((a)+(b))%mod   #define min(a,b) (a<b?a:b)   #define max(a,b) (a>b?a:b)   #define mod 998244353   #define Mod 998244351   #define ll long long   //#define file   using namespace std;      int n,K,i,j,k,l,ii;   int a[51];   ll C[2001][2001],jc[2001],Jc[2001];   ll f[51][2001][51];   ll ans,p0,p1,Len,LEN,L;      ll qpower(ll a,int b) {ll ans=1; while (b) {if (b&1) ans=ans*a%mod;a=a*a%mod;b>>=1;} return ans;}   ll E(ll p,ll a,ll b) {return p*qpower(qpower(1-b,a+1),Mod)%mod;} //p*x^a*e^b      int main()   {    #ifdef file    freopen( CF1477F.in , r ,stdin);    #endif        scanf( %d%d ,&n,&K);    fo(i,1,n) scanf( %d ,&a[i]),Len+=a[i];LEN=qpower(Len,Mod);        C[0][0]=1;    fo(i,1,2000)    {     C[i][0]=C[i][i]=1;     fo(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;    }    jc[0]=1;    fo(i,1,2000) jc[i]=jc[i-1]*i%mod;    Jc[2000]=qpower(jc[2000],Mod);    fd(i,2000-1,0) Jc[i]=Jc[i+1]*(i+1)%mod;        f[0][0][0]=1;    fo(l,1,n)    {     L=a[l],ii=(L-1)/K;     fo(i,0,ii)     {      p0=qpower((L-i*K)*LEN%mod,i)*fu(i)*Jc[i]%mod;      if (i)      p1=qpower((L-i*K)*LEN%mod,i-1)*fu(i)*Jc[i-1]%mod;      fo(j,0,Len)      {       fo(k,0,l-1)       if (f[l-1][j][k])       {        add(f[l][j+i][k],f[l-1][j][k]*p0);        if (i)        add(f[l][j+i][k+1],f[l-1][j][k]*p1);       }      }     }    }    fo(j,0,Len) fo(k,0,n) f[n][j][k]=-f[n][j][k];    add(f[n][0][0],1);    assert(!f[n][0][0]);        fo(j,0,Len) fo(k,0,n) if (f[n][j][k])    add(ans,E(f[n][j][k],j-k,(Len-j*K)*LEN%mod)*jc[j-k]);    printf( %lld n ,(ans+mod)%mod);        fclose(stdin);    fclose(stdout);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   const long long int INF = 2e15;   const long long int MAXN = 2e5 + 5;   long long int fastexpo(long long int b, long long int exp) {     if (exp == 0) return 1;     if (exp == 1) return b;     long long int ans = (fastexpo(b, exp / 2) % MOD);     ans *= ans;     ans %= MOD;     if (exp % 2 == 1) {       ans *= b;     }     ans %= MOD;     return ans;   }   long long int n;   vector<long long int> a;   long long int dp[MAXN][4];   long long int solve(long long int idx, vector<long long int> nice,                       long long int which) {     if (idx < 0) {       return 0;     }     if (nice.size() == 1) {       return 0;     }     vector<long long int> o, z;     for (long long int i = 0; i < nice.size(); i++) {       if ((1LL << idx) & nice[i]) {         o.push_back(nice[i]);       } else {         z.push_back(nice[i]);       }     }     long long int lo = o.size();     long long int lz = z.size();     if (min(lo, lz) <= 1) {       if (max(lo, lz) <= 1) {         return 0;       } else {         if (lo <= 1) {           return solve(idx - 1, z, 0);         } else {           return solve(idx - 1, o, 1);         }       }     }     return dp[idx][which] =                min(solve(idx - 1, o, 1) + max((lz - 1), (long long int)0),                    solve(idx - 1, z, 0) + max((lo - 1), (long long int)0));   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     memset(dp, -1, sizeof(dp));     ;     long long int mx = 0;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       a.push_back(x);       mx = max(mx, (long long int)log2(x));     }     cout << solve(mx, a, 2) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long tg, ans[22];   int state[22][22], fa_inc[22][22], fa_n4[22][22], fa_n7[22][22];   int t, cs = 0, dg[22];   int main() {     scanf( %d , &t);     for (cs = 1; cs <= t; ++cs) {       scanf( %I64d , &tg);       for (int i = 0; i < 19; ++i) dg[i] = tg % 10, tg /= 10;       state[0][0] = cs;       for (int i = 0; i < 19; ++i) {         for (int j = 0; j < 10; ++j) {           if (state[i][j] != cs) continue;           for (int n4 = 0; n4 <= 6; ++n4) {             for (int n7 = 0; n7 + n4 <= 6; ++n7) {               int nj = (j + n4 * 4 + n7 * 7);               if (nj % 10 == dg[i]) {                 state[i + 1][nj / 10] = cs;                 fa_inc[i + 1][nj / 10] = j;                 fa_n4[i + 1][nj / 10] = n4;                 fa_n7[i + 1][nj / 10] = n7;               }             }           }         }       }       if (state[19][0] == cs) {         for (int i = 0; i < 6; ++i) ans[i] = 0;         for (int i = 19, j = 0; i > 0; --i) {           int n4 = fa_n4[i][j], n7 = fa_n7[i][j];           for (int pos = 0; pos < 6; ++pos) {             ans[pos] *= 10;             if (pos < n4)               ans[pos] += 4;             else if (pos < n4 + n7)               ans[pos] += 7;           }           j = fa_inc[i][j];         }         for (int i = 0; i < 5; ++i) printf( %I64d  , ans[i]);         printf( %I64d n , ans[5]);       } else         puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[200005][4];   vector<int> v[200005];   int mod = 998244353;   void dfs(int first, int f) {     dp[first][0] = 1;     int visf = 0;     for (auto it : v[first]) {       if (it != f) {         dfs(it, first);         if (visf) {           dp[first][1] *= (dp[it][0] + dp[it][2] + dp[it][1]);           dp[first][1] %= mod;           dp[first][2] = (dp[first][2] * (dp[it][0] + dp[it][1] + dp[it][2]) +                           dp[first][0] * (dp[it][2] + dp[it][0])) %                          mod;           dp[first][3] *= (dp[it][0] + dp[it][1] + dp[it][2]);           dp[first][3] %= mod;         } else {           dp[first][1] = (dp[first][1] * (dp[it][0] + dp[it][1] + dp[it][2]) +                           dp[first][0] * (dp[it][2] + dp[it][0])) %                          mod;         }         dp[first][0] *= (dp[it][1] + dp[it][3]);         dp[first][0] %= mod;       } else {         visf = 1;         dp[first][3] = dp[first][0];       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int first, second;       scanf( %d %d , &first, &second);       v[first].push_back(second);       v[second].push_back(first);     }     dfs(1, 0);     printf( %lld n , (dp[1][0] + dp[1][1] + dp[1][2] + dp[1][3]) % mod);   }
#include <bits/stdc++.h>   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   long long int gcd(long long int a, long long int b) {     return (a ? gcd(b % a, a) : b);   }   long long int modPow(long long int a, long long int b, long long int MOD) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % MOD;       }       b /= 2;       y = (y * y) % MOD;     }     return x;   }   long long int modInverse(long long int a, long long int p) {     return modPow(a, p - 2, p);   }   using namespace std;   int A[26];   int marked[26];   bool check(int ex) {     int i, ctr;     ctr = 0;     for (i = 0; i < (26); i++) {       if (A[i] == ex) ctr++;     }     if (ctr == 1)       return true;     else       return false;   }   int main() {     int n, i, j, k;     cin >> n;     char ch;     int inf = -999999;     string str;     int ans, ex, f;     ans = ex = f = 0;     for (i = (1); i <= (n); i++) {       cin >> ch >> str;       int len = str.size();       if (f) {         if (i == n) continue;         if (ch ==  !  || ch ==  ? ) ans++;       }       if (ch ==  ! ) {         memset(marked, 0, sizeof(marked));         ex++;         for (j = 0; j < (len); j++) {           if (A[str[j] -  a ] != inf && !marked[str[j] -  a ]) A[str[j] -  a ]++;           marked[str[j] -  a ]++;         }       } else if (ch ==  . ) {         for (j = 0; j < (len); j++) A[str[j] -  a ] = inf;       } else         A[str[0] -  a ] = inf;       if (check(ex) && !f) f++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int v1, v2, v3, vm;   inline long long readll() {     int sign = 1;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       if (c ==  - ) sign = -sign;     long long res = c -  0 ;     for (c = getchar(); isdigit(c); c = getchar()) res = res * 10 + c -  0 ;     return sign * res;   }   void writell(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) writell(x / 10);     putchar(x % 10 +  0 );   }   void inp() { cin >> v1 >> v2 >> v3 >> vm; }   void out() {     if (vm < v2 && vm <= 2 * v3 && v3 <= 2 * vm) {       writell(v1 * 2);       putchar(  n );       writell(v2 * 2);       putchar(  n );       writell(min(v3 * 2, vm * 2));     } else {       putchar( - );       putchar( 1 );     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp();     out();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[105];   int main() {     int n, p, q;     cin >> n >> p;     for (int i = 0; i < p; ++i) cin >> x[i];     cin >> q;     for (int i = p; i < p + q; ++i) cin >> x[i];     sort(x, x + p + q);     int k = 0;     for (int i = 0; i < p + q; ++i) {       if (x[i] == k + 1) ++k;     }     if (k == n)       cout <<  I become the guy.  << endl;     else       cout <<  Oh, my keyboard!  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1505;   int n, k;   map<tuple<int, int, int>, bool> memo;   bool query(int a, int b, int c) {     if (b == a || b == c) return 1;     if (a > c) swap(a, c);     auto s = make_tuple(a, b, c);     if (memo.count(s)) return memo[s];     cout <<  ?   << a + 1 <<     << b + 1 <<     << c + 1 << endl;     cout.flush();     string ans;     cin >> ans;     return memo[s] = (ans[0] ==  Y );   }   bool alive[N], done;   int GOAL;   int closer(int u, int v) {     for (int w = 0; w < int(n); w++)       if (alive[w] && w != u && w != v && query(u, w, v)) v = w;     return v;   }   int iter(int u) {     vector<int> nodes;     for (int w = 0; w < int(n); w++)       if (w != u && alive[w]) nodes.push_back(w);     int sz = nodes.size();     auto w = nodes[rand() % sz];     w = closer(u, w);     vector<int> u_friends, w_friends;     u_friends.push_back(u);     w_friends.push_back(w);     for (auto v : nodes)       if (v != w) {         if (query(u, w, v))           w_friends.push_back(v);         else           u_friends.push_back(u);       }     int ans;     if (u_friends.size() > w_friends.size()) {       ans = u;       if (u_friends.size() == GOAL) done = 1;       for (auto v : w_friends) alive[v] = 0;     } else {       ans = w;       if (w_friends.size() == GOAL) done = 1;       for (auto v : u_friends) alive[v] = 0;     }     return ans;   }   int main() {     srand(time(0));     cin >> n >> k;     fill_n(alive, n, 1);     GOAL = 1;     while (GOAL * k <= n) GOAL *= k;     int u = 0;     while (!done) u = iter(u);     cout <<  !   << u + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long x, y, m;     cin >> x >> y >> m;     if (x <= 0 && y <= 0) {       if (max(x, y) >= m)         cout <<  0 ;       else         cout <<  -1 ;       return 0;     }     if (x > y) swap(x, y);     long long odp = 0;     if (x < 0 && y > 0) {       if (y < m) {         long long ile = abs(x) / y;         odp += ile;         x += ile * y;       }     }     while (max(x, y) < m) {       if (x < y)         x += y;       else         y += x;       ++odp;     }     cout << odp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, h;     cin >> n >> d >> h;     if (d > 2 * h || d < h) {       cout <<  -1  << endl;       return 0;     }     if (d == 1 && h == 1 && n != 2) {       cout <<  -1  << endl;       return 0;     }     vector<pair<int, int> > p;     for (int i = 0; i < h; i++) {       p.push_back(pair<int, int>(i + 1, i + 2));     }     if (d - h > 0) {       p.push_back(pair<int, int>(1, h + 2));       for (int i = 1; i < d - h; i++) {         p.push_back(pair<int, int>(h + 1 + i, h + 2 + i));       }     }     if (d + 1 > n) {       cout <<  -1  << endl;       return 0;     }     if (h != 1) {       for (int i = d + 2; i <= n; i++) {         p.push_back(pair<int, int>(2, i));       }     } else {       for (int i = d + 2; i <= n; i++) {         p.push_back(pair<int, int>(1, i));       }     }     for (int i = 0; i < p.size(); i++) {       cout << p[i].first <<     << p[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x1, x2, x3;   int Y1, y2, y3;   int main() {     cin >> x1 >> Y1 >> x2 >> y2;     x3 = (x1 <= x2 ? x2 + 1 : x2 - 1);     y3 = (Y1 <= y2 ? y2 + 1 : y2 - 1);     int r = 0;     if (x1 == x2 || Y1 == y2) r = 2;     cout << r + 2 * abs(x1 - x3) + 2 * abs(Y1 - y3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[569], sq[250069], zs, inf = 1e18;   void cyc(long long x) {     swap(a[x + 1], a[x + 2]);     swap(a[x], a[x + 1]);     zs++;     sq[zs] = x;   }   int main() {     long long t, rr, i, j, ii, e;     pair<long long, long long> mne;     scanf( %lld , &t);     for (rr = 0; rr < t; rr++) {       scanf( %lld , &n);       for (i = 1; i <= n; i++) {         scanf( %lld , a + i);       }       zs = 0;       for (i = 1; i <= n - 2; i++) {         mne = {inf, -1};         for (j = i; j <= n; j++) {           mne = min(mne, {a[j], j});         }         e = mne.second;         for (j = e - 2; j >= i; j -= 2) {           cyc(j);         }         if (j == i - 1) {           for (ii = 0; ii < 2; ii++) {             cyc(i);           }         }       }       if (a[n - 1] > a[n]) {         for (i = n - 2; i; i--) {           cyc(i);           if (a[i] <= a[i + 1]) {             break;           }         }         if (!i) {           zs = -1;         }       }       printf( %lld n , zs);       for (i = 1; i <= zs; i++) {         printf( %lld%c , sq[i],    n [i == zs]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 1;   struct Node {     int t, x, l, c;   } pnt[maxN];   long long t, pos[maxN];   int m, n;   int solve(long long t) {     int l, r, m;     while (t > 0) {       l = 1, r = n + 1;       while (l + 1 < r) {         m = (l + r) >> 1;         if (pos[m] < t)           l = m;         else           r = m;       }       if (pnt[l].t == 1) return pnt[l].x;       t = ((t - pos[l] - 1) % pnt[l].l) + 1;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &pnt[i].t);       if (pnt[i].t == 1) {         scanf( %d , &pnt[i].x);         pos[i + 1] = pos[i] + 1;       } else {         scanf( %d%d , &pnt[i].l, &pnt[i].c);         pos[i + 1] = pos[i] + pnt[i].l * pnt[i].c;       }     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %I64d , &t);       printf( %d , solve(t));       if (i < m)         printf(   );       else         printf(  n );     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const long double pi = acos(-1);   const long long int mod = 1e9 + 7;   bool debug = false;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1, n, i, j, k, len, x, y, z, c, f, flag, p, q, mx, mn, l, r,                   sum, ans, tmp, it, pos, avg, m, cnt;     string s;     char ch;     vector<long long int> v;     vector<pair<long long int, long long int>> vec;     unordered_map<long long int, long long int> mappu;     pair<long long int, long long int> pr;     {       f = 0;       sum = 0;       flag = 0;       ans = 0;       cnt = 0;       v.clear();       mappu.clear();       vec.clear();       string s2;       cin >> s >> s2;       if (s == s2)         cout << s;       else         cout << 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   tuple<long long, long long, long long> adj[400001];   long long cnt;   long long nm;   int main() {     long long k, a, x, y, m, n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> k >> a >> x >> y >> m;       long long t = 0;       for (long long j = 1; j <= k; j++, adj[nm++] = make_tuple(t, a, i),                      (a > ((a * x + y) % m) && j != k + 1) ? t++ : t,                      a = (a * x + y) % m)         ;       cnt = max(cnt, t);     }     cout << cnt <<   n ;     sort(adj, adj + nm);     for (long long i = 0; i < nm; i++)       cout << get<1>(adj[i]) <<     << get<2>(adj[i]) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   const int mod = 1e9 + 7;   long long n, k, arr[MAX], ans = 0;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     if (n == 1) {       cout << 0;       exit(0);     }     bool moded = true;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     long long modu = arr[0] % k;     for (int i = 0; i < n; i++)       if (arr[i] % k != modu) moded = false;     if (moded)       for (int i = 0; i < n; i++) ans += (arr[i] - arr[0]) / k;     else       ans = -1;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100005;   char str[Maxn];   int slen;   int cnt[Maxn];   bool was[Maxn];   int Z[Maxn];   vector<pair<int, int> > res;   int main() {     scanf( %s , str);     slen = strlen(str);     cnt[slen]++;     was[slen] = true;     int L = -1, R = -1;     for (int i = 1; i < slen; i++) {       if (i <= R) Z[i] = min(R - i + 1, Z[i - L]);       while (i + Z[i] < slen && str[Z[i]] == str[i + Z[i]]) Z[i]++;       if (i + Z[i] - 1 > R) {         L = i;         R = i + Z[i] - 1;       }       if (i + Z[i] == slen) was[Z[i]] = true;       cnt[Z[i]]++;     }     for (int i = slen - 1; i >= 0; i--) cnt[i] += cnt[i + 1];     for (int i = 1; i <= slen; i++)       if (was[i]) res.push_back(pair<int, int>(i, cnt[i]));     printf( %d n , res.size());     for (int i = 0; i < res.size(); i++)       printf( %d %d n , res[i].first, res[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[1000000];   long long bank;   vector<int> t;   int main() {     cin >> n >> m;     for (int i = 0, k; i < n; i++) {       cin >> k;       int p = -1;       bool q = false;       for (int j = 0; j < k; j++) {         cin >> a[j];         if (a[j] < m) p = 1;       }       if (p == true) {         t.push_back(i);         bank++;       }     }     cout << bank << endl;     for (int i = 0; i < t.size(); i++) cout << t[i] + 1 <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int p[200001];   int a[200001];   vector<int> cur[200001];   int pos[200001];   int par[200001][21];   struct cmp {     bool operator()(pair<int, int> a, pair<int, int> b) {       return a.second > b.second;     }   };   priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> h;   struct Q {     int l, r, id;   };   vector<Q> Query;   bool cmp(Q a, Q b) { return a.l < b.l; }   int ans[200001];   int Process(int pos) {     int k = n - 1;     for (int i = 20; i >= 0; i--) {       if (k & (1 << i)) {         if (par[pos][i] == -1) return -1;         pos = par[pos][i];       }     }     return pos;   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> p[i];       pos[p[i]] = i;     }     for (int i = 1; i <= m; i++) {       cin >> a[i];     }     memset(par, -1, sizeof par);     for (int i = 1; i <= m; i++) {       int x = pos[a[i]];       int y;       if (x == 1)         y = p[n];       else         y = p[x - 1];       for (auto k : cur[y]) {         par[k][0] = i;       }       cur[y].clear();       cur[a[i]].push_back(i);     }     for (int j = 1; j <= 20; j++) {       for (int i = 1; i <= m; i++) {         if (par[i][j - 1] != -1) par[i][j] = par[par[i][j - 1]][j - 1];       }     }     for (int i = 1; i <= q; i++) {       int l, r;       cin >> l >> r;       Query.push_back({l, r, i});     }     sort(Query.begin(), Query.end(), cmp);     for (int i = 1; i <= m; i++) {       int r = Process(i);       if (r != -1) h.push({i, r});     }     for (auto x : Query) {       int id = x.id;       while (!h.empty() && h.top().first < x.l) h.pop();       if (h.empty() || h.top().second > x.r)         ans[id] = 0;       else         ans[id] = 1;     }     for (int i = 1; i <= q; i++) cout << ans[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   vector<int> adj[N];   int a[N], d[N], din[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d %d , a + i, d + i);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (d[i] < 0) {           if (make_pair(a[i], -i) > make_pair(a[j], -j) &&               make_pair(a[j], -j) > make_pair(a[i] + d[i], -i) &&               make_pair(a[i] + d[i], -i) > make_pair(a[j] + d[j], -j))             adj[i].push_back(j);         } else {           if (make_pair(a[i], -i) < make_pair(a[j], -j) &&               make_pair(a[j], -j) < make_pair(a[i] + d[i], -i) &&               make_pair(a[i] + d[i], -i) < make_pair(a[j] + d[j], -j))             adj[i].push_back(j);         }       }     }     memset(din, 0, sizeof din);     for (int i = 0; i < n; i++) {       for (int u : adj[i]) din[u]++;     }     stack<int> st;     for (int i = 0; i < n; i++)       if (din[i] == 0) {         st.push(i);       }     vector<int> order;     while (!st.empty()) {       int u = st.top();       st.pop();       order.push_back(u);       for (int v : adj[u]) {         din[v]--;         if (din[v] == 0) st.push(v);       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       int cnt1, cnt2;       cnt1 = cnt2 = 0;       for (int j = 0; j < n; j++) {         if (j == order[i]) continue;         cnt1 += (make_pair(a[j], -j) < make_pair(a[order[i]], -order[i]));         cnt2 += (make_pair(a[j], -j) <                  make_pair(a[order[i]] + d[order[i]], -order[i]));       }       ans += abs(cnt1 - cnt2);       a[order[i]] += d[order[i]];     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100005];   long long sum[100005];   map<int, long long> f;   long long solve(int n, int k) {     if (f.count(k)) return f[k];     long long ret = 0;     long long cur = n - 2;     long long p = k;     while (cur >= 0) {       ret += sum[cur];       cur -= p;       p *= k;     }     return f[k] = ret;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]);     sort(arr, arr + n);     sum[0] = arr[0];     for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + arr[i];     int q, a;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       scanf( %d , &a);       if (i) printf(   );       printf( %I64d , solve(n, a));     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   int main() {     int n, m;     cin >> n;     int ara[2 * n + 7];     for (int i = 0; i < 2 * n; i++) {       cin >> ara[i];     }     sort(ara, ara + (2 * n));     if (ara[n - 1] == ara[n]) {       cout <<  NO ;     } else {       cout <<  YES ;     }   }