malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5007;   const int MX = 1e9 + 7;   const long long int INF = 1e18 + 9LL;   int n, m;   int in[N];   vector<int> cows[N];   int Left[N], Right[N];   int take[N], poss[N], New[N];   void update(int t) {     int canTake = 0;     if (cows[t][0] <= Left[t] || cows[t][0] <= Right[t]) canTake = 1;     if (cows[t].size() >= 2) {       int mn = min(Left[t], Right[t]);       int mx = max(Left[t], Right[t]);       if (cows[t][0] <= mn && cows[t][1] <= mx) canTake = 2;     }     if (canTake == 0) {       if (take[t] == 0) return;       take[t] = 0, poss[t] = 1, New[t] = 1;       return;     }     if (canTake == 1) {       int xd = 0;       for (auto v : cows[t]) {         if (v <= Left[t]) ++xd;         if (v <= Right[t]) ++xd;       }       if (take[t] != canTake) {         take[t] = 1;         poss[t] = New[t] = xd;       } else {         poss[t] = xd;         for (auto v : cows[t])           if (v == Left[t]) New[t] = 1;       }       return;     }     int prawo = 0;     poss[t] = 0;     for (auto v : cows[t])       if (v <= Right[t]) ++prawo;     for (int i = 0; i < (int)cows[t].size(); ++i)       if (cows[t][i] <= Left[t]) {         poss[t] += prawo;         if (cows[t][i] <= Right[t]) --poss[t];       }     if (canTake != take[t]) {       take[t] = 2;       New[t] = poss[t];       return;     }     for (int i = 0; i < (int)cows[t].size(); ++i)       if (cows[t][i] == Left[t]) {         New[t] = prawo;         if (cows[t][i] <= Right[t]) --New[t];       }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &in[i]);     for (int i = 1; i <= m; ++i) {       int f, h;       scanf( %d %d , &f, &h);       cows[f].push_back(h);     }     for (int i = 1; i <= n; ++i) sort(cows[i].begin(), cows[i].end());     for (int i = 1; i <= n; ++i) {       Right[in[i]]++;       poss[i] = 1;     }     int ans = 0, ans2 = 1;     for (int i = 1; i <= n; ++i) {       if (cows[i].size() == 0) continue;       update(i);       ans += take[i];       ans2 = (1LL * ans2 * poss[i]) % MX;     }     for (int i = 1; i <= n; ++i) {       Right[in[i]]--;       Left[in[i]]++;       for (int j = 1; j <= n; ++j) New[j] = 0;       if (cows[in[i]].size()) update(in[i]);       int now = 0;       for (int j = 1; j <= n; ++j) now += take[j];       if (now < ans) continue;       if (now > ans) {         ans = now;         ans2 = 0;       }       int tmp1 = 1, tmp2 = 1;       for (int j = 1; j <= n; ++j) {         tmp1 = (1LL * tmp1 * poss[j]) % MX;         tmp2 = (1LL * tmp2 * (poss[j] - New[j])) % MX;       }       ans2 = (1LL * ans2 + tmp1 + MX - tmp2) % MX;     }     printf( %d %d n , ans, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int inf = 0x3fffffff;   const int maxn = 200005;   int n;   unsigned long long m;   struct P {     int x, y;   } p[maxn];   bool cmp(P a, P b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   int main() {     scanf( %d , &n);     int y = 1;     for (int i = 1; i <= 2 * n; i++) {       int x;       scanf( %d , &x);       p[i].x = x, p[i].y = y;       y++;       if (y > n) y = 1;     }     scanf( %I64u , &m);     sort(p + 1, p + 2 * n + 1, cmp);     unsigned long long ans = 1, tmpans = 1, cnt = 0;     int now = -1;     for (int i = 1; i <= 2 * n; i++) {       if (now != p[i].x) {         now = p[i].x;         ans *= tmpans;         tmpans = 1LL;         ans %= m;         cnt = 0LL;       }       if (i < 2 * n) {         if (p[i + 1].x != p[i].x) {           tmpans *= (cnt + 1LL);           tmpans %= m;         } else {           if (p[i + 1].y != p[i].y) {             tmpans *= (cnt + 1LL);             tmpans %= m;             cnt++;           } else {             unsigned long long tmp1 = cnt + 1LL, tmp2 = cnt + 2LL;             if (tmp1 % 2LL == 0LL)               tmp1 /= 2LL;             else               tmp2 /= 2LL;             tmpans *= tmp1;             tmpans %= m;             tmpans *= tmp2;             tmpans %= m;             cnt += 2LL;             i++;             if (i == 2 * n) {               ans *= tmpans;               ans %= m;               break;             }           }         }       } else {         tmpans *= (cnt + 1LL);         tmpans %= m;         ans *= tmpans;         ans %= m;         break;       }     }     printf( %I64u n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void show(const vector<T> &a) {     for (T x : a) cout << x <<    ;     cout <<   n ;   }   const long long N = 1e5 + 10, oo = 1e18 + 500;   const long long mod = 1e9 + 7;   const long double eps = 1e-9, PI = 2 * acos(0.0);   long long n, m, k;   long long cnt = 0;   vector<long long> g[N];   vector<long long> rg[N];   vector<long long> visit(N, 0);   vector<vector<long long> > dp(N, vector<long long>(150, -oo));   signed main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> m >> k;     vector<vector<long long> > a(n, vector<long long>(m + 1));     for (long long i = 0; i < n; i++) {       cin >> a[i][0];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) cin >> a[i][j + 1];     }     sort(a.rbegin(), a.rend());     dp[0][0] = a[0][0];     for (long long j = 0; j < m; j++) {       dp[0][(1 << j)] = a[0][j + 1];     }     for (long long i = 1; i < n; i++) {       for (long long mask = 0; mask < (1 << m); mask++) {         long long ex = 0;         for (long long j = 0; j < m; j++) {           if (mask & (1 << j)) {             ex++;           }         }         long long add = 0;         if (i < k + ex) add = a[i][0];         if (dp[i][mask] < dp[i - 1][mask] + add) {           dp[i][mask] = dp[i - 1][mask] + add;         }         for (long long j = 0; j < m; j++) {           if (!(mask & (1 << j))) {             if (dp[i][mask | (1 << j)] < dp[i - 1][mask] + a[i][j + 1]) {               dp[i][mask | (1 << j)] = dp[i - 1][mask] + a[i][j + 1];             }           }         }       }     }     long long ans = dp[n - 1][(1 << m) - 1];     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 100;   int x[maxn][maxn], p[maxn], tx[maxn];   int n;   int ask(int i, int j) {     cout <<  ?   << i <<     << j << endl;     int r;     cin >> r;     return r;   }   void answer(int k) {     cout <<  !  << endl;     cout << k << endl;     for (int i = 0; i < n; ++i) cout << p[i] <<    ;     cout << endl;     exit(0);   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       int xo = ask(0, i);       x[0][i] = xo;     }     for (int i = 1; i < n; ++i) {       int xo = ask(i, i);       for (int j = 0; j < n; ++j) {         x[i][j] = xo ^ x[0][i] ^ x[0][j];       }     }     int xn = 0;     for (int i = 0; i < n; ++i) xn ^= i;     if (n & 1) {       for (int i = 0; i < n; ++i) {         int xnow = 0;         for (int j = 0; j < n; ++j) xnow ^= x[i][j];         xnow ^= xn;         p[i] = xnow;       }       answer(1);       return 0;     }     for (int i = 0; i < n; ++i) tx[i] = (x[0][0] ^ x[i][0]);     int ans = 0;     for (int i = 0; i < n; ++i) {       vector<int> tp(maxn);       tp[0] = i;       for (int j = 1; j < n; ++j) tp[j] = (tx[j] ^ tp[0]);       bitset<maxn> v;       bool good = true;       vector<int> tb(maxn);       for (int j = 0; j < n && good; ++j) {         if (tp[j] >= n || tp[j] < 0) {           good = false;           break;         }         tb[tp[j]] = j;       }       for (int j = 0; j < n; ++j) {         if ((tb[j] ^ tp[j]) != x[j][j]) good = false;       }       for (int j = 0; j < n && good; ++j) {         if (tp[j] >= n || tp[j] < 0) {           good = false;           break;         }         if (v[tp[j]]) good = false;         v[tp[j]] = true;       }       if (good) {         ++ans;         for (int j = 0; j < n; ++j) p[j] = tp[j];       }     }     answer(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 2222;   int n, K;   long long sum[N][N], tail[N], f[N][N];   char s[N];   long long work() {     long long ret = 0;     tail[n + 1] = 1;     for (int i = n; i >= 1; i--) tail[i] = tail[i + 1] * (s[i] -  a  + 1) % MOD;     if (K == 0) return tail[1];     f[0][0] = 1;     sum[0][0] = 1;     for (int i = 1; i <= n; i++) {       int dt = n - i + 1;       for (int j = 0; j <= K; j++) {         for (int k = i - 1; k >= 0 && (i - k) * dt <= j; k--) {           f[i][j] = (f[i][j] + f[k][j - (i - k) * dt]) % MOD;         }         f[i][j] = f[i][j] * ( z  - s[i]) % MOD;       }       for (int j = 0; j <= K; j++) {         f[i][j] = (f[i][j] + sum[i - 1][j] * (s[i] -  a ) % MOD) % MOD;         sum[i][j] = (sum[i - 1][j] + f[i][j]) % MOD;       }     }     ret = sum[n][K];     return ret;   }   int main() {     scanf( %d%d%s , &n, &K, s + 1);     printf( %I64d n , work());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int kd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, i, j;   char s[666666];   int cnt[42][42][42];   int mx, ad, am, ay;   int main() {     scanf( %s , s);     int n = strlen(s);     memset(cnt, 0, sizeof(cnt));     for (i = 0; i + 9 < n; i++) {       if (s[i + 2] !=  -  || s[i + 5] !=  - ) continue;       int ok = 1;       for (j = 0; j < 10; j++)         if (j != 2 && j != 5 && s[i + j] ==  - ) ok = 0;       if (!ok) continue;       int dd = (s[i] - 48) * 10 + (s[i + 1] - 48);       int mm = (s[i + 3] - 48) * 10 + (s[i + 4] - 48);       if (s[i + 6] !=  2  || s[i + 7] !=  0  || s[i + 8] !=  1 ) continue;       int yy = s[i + 9] - 48;       if (yy < 3 || yy > 5) continue;       if (mm < 1 || mm > 12) continue;       if (dd < 1 || dd > kd[mm]) continue;       cnt[dd][mm][yy]++;       if (cnt[dd][mm][yy] > mx) {         mx = cnt[dd][mm][yy];         ad = dd;         am = mm;         ay = yy;       }     }     printf( %d%d-%d%d-%d n , ad / 10, ad % 10, am / 10, am % 10, 2010 + ay);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000100], b[1000100], cnt[32];   int solve(int n, int m) {     int i, j, k, ret = 0;     memset(cnt, 0, sizeof(cnt));     for (i = 0; i < n; ++i) {       for (j = 0; (1 << j) <= a[i]; ++j) {         if (a[i] & (1 << j)) ++cnt[j];       }     }     sort(b, b + m);     for (i = 0; i < m; ++i) {       for (j = b[i]; j < 32 && !cnt[j]; ++j)         ;       if (j == 32) break;       ++ret;       --cnt[j];       for (k = b[i]; k < j; ++k) ++cnt[k];     }     return ret;   }   int main() {     int n, m, i;     while (~scanf( %d %d , &n, &m)) {       for (i = 0; i < n; ++i) scanf( %d , &a[i]);       for (i = 0; i < m; ++i) scanf( %d , &b[i]);       printf( %d n , solve(n, m));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10;   const long long BINF = 1e18 + 10;   long long get(long long l, long long r) {     if (l > r) {       swap(l, r);     }     return r * (r + 1) / 2 - l * (l - 1) / 2;   }   long long solve(long long a, long long b, long long lim) {     long long res = 0;     if (a > lim) {       if (b >= lim) {         res += lim * (a - b + 1);       } else {         res += get(b, lim) + lim * (a - lim);       }     } else {       res += get(a, b);     }     return res;   }   void source() {     long long n, x, y, need;     cin >> n >> x >> y >> need;     if (need <= 1) {       cout << 0;       exit(0);     }     long long l = 0, r = 2 * n + 10;     long long mx_up = n - y + 1, mx_down = y;     while (r - l > 1) {       long long mid = (l + r) / 2, sum = 0;       long long left = max(x - mid, 1ll), right = min(x + mid, n);       long long a = mid + 1, vl = a - (x - left), vr = a - (right - x);       sum = solve(a, vl, mx_up) + solve(a, vr, mx_up) - min(mx_up, a);       sum += solve(a, vl, mx_down) + solve(a, vr, mx_down) - min(mx_down, a);       sum -= right - left + 1;       if (sum >= need) {         r = mid;       } else {         l = mid;       }     }     cout << r;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     source();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     int arr[110];     cin >> num;     for (int i = 0; i < num; i++) {       cin >> arr[i];     }     for (int i = 1; i <= num; i++) {       for (int j = 0; j < num; j++) {         if (arr[j] == i) {           cout << j + 1 <<    ;         }       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string we, ns, sol =   ;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     fast();     cin >> n >> m;     cin >> we;     cin >> ns;     sol += we[0];     sol += we.back();     sol += ns[0];     sol += ns.back();     if (sol ==  <>v^  || sol ==  ><^v ) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long logN = 20;   const long long M = 1000000007;   const long long INF = 1e12;   const long long N = 100005;   void solve() {     long long n, k;     cin >> n >> k;     set<long long> s;     while (s.size() < 30 and s.size() < (n - 1)) {       long long i = rand() % n + 1;       if (i != 1 and s.find(i) == s.end()) {         s.insert(i);         cout <<  ? 1 1  << endl;         cout << 1 << endl;         cout << i << endl;         string gt;         cin >> gt;         if (gt ==  SECOND ) {           cout <<  ! 1  << endl;           return;         }       }     }     long long l = 2, r = 2;     for (long long i = 0; i < 10; i++) {       long long dif = (r - l + 1);       cout <<  ?   << dif <<     << dif << endl;       for (long long i = 1; i < dif + 1; i++) cout << i <<    ;       cout << endl;       for (long long i = l; i < l + dif; i++) cout << i <<    ;       cout << endl;       string s;       cin >> s;       if (s ==  FIRST ) break;       l = r + 1;       r = 2 * r;       r = min(r, n);     }     while (r > l) {       long long m = (l + r) / 2;       long long dif = (m - l + 1);       cout <<  ?   << dif <<     << dif << endl;       for (long long i = 1; i < dif + 1; i++) cout << i <<    ;       cout << endl;       for (long long i = l; i < l + dif; i++) cout << i <<    ;       cout << endl;       string s;       cin >> s;       if (s ==  EQUAL )         l = m + 1;       else         r = m;     }     cout <<  !   << l << endl;     return;   }   int main() {     long long no;     cin >> no;     while (no--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sum[100010], bsum[100010], arr2[100010];   pair<long long int, long long int> arr[100010];   void scanStr(char *str) {     long long int i = 1;     char ch;     for (ch = getchar(); ch !=   n  && ch !=    ; ch = getchar()) str[i++] = ch;     str[i] =   0 ;     return;   }   inline void fastOut(long long int n) {     if (n < 10) {       putchar(n +  0 );       return;     }     fastOut(n / 10);     putchar(n % 10 +  0 );     return;   }   long long int powerFast(long long int a, long long int b) {     long long int i = a, j = 1, k = 1;     while (b) {       if (b & 1) {         k = ((k * i) < 1000000007 ? (k * i) : (k * i) % 1000000007);       }       i = ((i * i) < 1000000007 ? (i * i) : (i * i) % 1000000007);       b = b >> 1;     }     return k;   }   inline long long int scan() {     long long int n = 0;     char c;     for (c = getchar(); c ==     || c ==   n  || c ==   t ; c = getchar())       ;     for (; c > 0x2f && c < 0x3a; c = getchar()) n = (n * 10) + (c & 0x0f);     return n;   }   bool comp(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     if (a.first < b.first) return false;     return true;   }   int main() {     long long int N, A, cf, cm, M, i, j, K, t, tmin, tnA, maxx;     N = scan();     A = scan();     cf = scan();     cm = scan();     M = scan();     for (i = 1; i <= N; i++) {       arr[i].first = scan();       arr[i].second = i;     }     sort(arr + 1, arr + N + 1,          std::greater<pair<long long int, long long int> >());     for (i = 1; i <= N; i++) {       sum[i] = sum[i - 1] + arr[i].first;     }     long long int loc1, loc2, val;     maxx = LONG_MIN;     j = 1;     for (i = 0; i <= N; i++) {       K = M - (A * i - sum[i]);       if (K < 0) {         break;       }       tnA = i;       tmin = A;       for (j = max(i + 1, j); j <= N; j++) {         t = arr[j].first * (N - j + 1);         t = t - (sum[N] - sum[j - 1]);         if (t <= K) {           t = K - t;           tmin = min(arr[j].first + t / (N - j + 1), A);           break;         }       }       if ((cf * tnA + cm * tmin) >= maxx) {         maxx = cf * tnA + cm * tmin;         loc1 = i;         loc2 = j;         val = tmin;       }     }     cout << maxx <<   n ;     for (i = 1; i <= loc1; i++) {       arr2[arr[i].second] = A;     }     for (i = loc1 + 1; i < loc2; i++) {       arr2[arr[i].second] = arr[i].first;     }     for (i = loc2; i <= N; i++) {       arr2[arr[i].second] = val;     }     for (i = 1; i <= N; i++) {       fastOut(arr2[i]);       putchar(   );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   long long n, m, li, ns, i, j, k, l, mod = 1e9 + 7, x, y, dp[123456][12][3],                                       vis[123456];   vector<long long> e[123456];   void dfs(int x, int fa) {     long long i;     if (vis[x]) return;     vis[x] = 1;     dp[x][0][2] = ns - 1;     dp[x][1][1] = 1;     dp[x][0][0] = m - ns;     for (i = 0; i < e[x].size(); i++) {       if (e[x][i] == fa) continue;       dfs(e[x][i], x);       for (j = li; ~j; j--) {         long long mem[3] = {0, 0, 0};         for (k = 0; k <= j; k++) {           (mem[0] +=            (dp[x][j - k][0] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][2]))) %= mod;           (mem[1] += (dp[x][j - k][1] * (dp[e[x][i]][k][2]))) %= mod;           (mem[2] += (dp[x][j - k][2] * (dp[e[x][i]][k][0] + dp[e[x][i]][k][1] +                                          dp[e[x][i]][k][2]))) %= mod;         }         for (k = 0; k < 3; k++) dp[x][j][k] = mem[k];       }     }   }   int main() {     readll(n);     readll(m);     for (i = 1; i < n; i++) {       readll(x);       readll(y);       e[x].push_back(y);       e[y].push_back(x);     }     readll(ns);     readll(li);     dfs(1, 0);     long long res = 0;     for (i = 0; i <= li; i++)       (res += dp[1][i][0] + dp[1][i][1] + dp[1][i][2]) %= mod;     writell(res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T = 1;     while (T--) {       int n, m;       cin >> n >> m;       map<int, int> mp;       vector<pair<int, int> > pp;       for (int i = 0; i < m; i++) {         int a, b;         cin >> a >> b;         pp.push_back({a, b});         if (a != b) {           mp[a]++;           mp[b]++;         } else           mp[a]++;       }       vector<pair<int, int> > maxi;       for (auto x : mp) {         maxi.push_back({x.second, x.first});       }       sort(maxi.rbegin(), maxi.rend());       int mm = min(4, int((maxi).size()));       for (int q = 0; q < mm; q++) {         vector<int> v(m, 0);         int cnt = 0;         for (int i = 0; i < m; i++) {           if (pp[i].first == maxi[q].second || pp[i].second == maxi[q].second) {             v[i] = 1;             cnt++;           }         }         cnt = m - cnt;         if (cnt == 0) {           cout <<  YES ;           exit(0);         }         mp.clear();         for (int i = 0; i < m; i++) {           if (v[i] == 0) {             if (pp[i].first != pp[i].second) {               mp[pp[i].first]++;               mp[pp[i].second]++;             } else               mp[pp[i].first]++;           }         }         for (auto x : mp) {           if (x.second == cnt) {             cout <<  YES ;             exit(0);           }         }       }       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   map<int, int> l, r;   int a[maxn << 1];   int sum[maxn << 1];   int main() {     int t;     cin >> t;     while (t--) {       l.clear();       r.clear();       int n;       cin >> n;       for (int i = 1; i <= 2 * n; i++) cin >> a[i];       for (int i = 1; i <= 2 * n; i++) {         a[i] = (a[i] == 2 ? 1 : -1);       }       for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];       sum[2 * n + 1] = 0;       for (int i = 2 * n; i >= n + 1; i--) sum[i] = sum[i + 1] + a[i];       r[0] = 2 * n + 1;       l[0] = 0;       for (int i = 1; i <= n; i++) l[sum[i]] = max(l[sum[i]], i);       for (int i = 2 * n; i >= n + 1; i--)         r[sum[i]] ? r[sum[i]] = min(r[sum[i]], i) : r[sum[i]] = i;       int ans = 2 * n;       for (int i = 0; i <= n; i++) {         if (!r[-sum[i]]) continue;         ans = min(r[-sum[i]] - l[sum[i]] - 1, ans);       }       for (int i = 2 * n + 1; i >= n + 1; i--) {         if (!l[-sum[i]] && sum[i]) continue;         ans = min(ans, r[sum[i]] - l[-sum[i]] - 1);       }       cout << ans << endl;     }     return 0;     ;   }
#include <bits/stdc++.h>   using namespace std;   int m[10000000];   int func(int v) {     int r = 1;     while (v != 1) {       if (v % 2 == 0) {         v /= 2;       } else {         v--;         r++;       }     }     return r;   }   int main() {     int n, a;     long long r = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       m[func(a)]++;     }     for (int i = 0; i < 10000000; i++) {       r += (long long)(((long long)m[i] * (long long)(m[i] - 1)) / 2);     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long solve(long long A, long long B, long long C) {     if (B == 0) {       return 0;     }     long long N = A % B;     long long X = solve(B, N, C);     long long Y = (-C - A * X) / B;     if (A != 0) {       Y %= A;     }     return Y;   }   int abs(int a) { return a > 0 ? a : -a; }   int _gcd(int a, int b) {     if (b == 0) return a;     return _gcd(b, a % b);   }   int A, B, C;   int main() {     scanf( %d %d %d , &A, &B, &C);     int gcd = _gcd(abs(A), abs(B));     if (C % gcd == 0) {       long long Y = solve(A, B, C);       long long X = 0;       if (A != 0) {         X = (-B * Y - C) / A;       }       printf( %I64d %I64d n , X, Y);     } else {       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     bool flag = false;     for (int i = 1; i < n - 1; i++) {       if ((1ll * (a[i] - a[0]) * (a[i] - a[i + 1])) > 0) {         cout << 3 <<   n ;         cout << 1 <<     << (i + 1) <<     << (i + 2) <<   n ;         flag = true;         break;       }     }     if (!flag) cout << 0 <<   n ;   }