malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n, w;     cin >> n >> w;     vector<long long> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     long long tot = 0, al = 0;     long long minimum = 1e18, maximum = 0;     for (int i = 0; i < n; i++) {       tot += v[i];       minimum = min(minimum, tot);       maximum = max(maximum, tot);     }     long long left = w - maximum;     if (minimum < 0) al = abs(minimum);     if (left < 0 || left < al)       cout << 0;     else       cout << left - al + 1;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   double res;   double x[60006], v[60006];   bool ok(double t) {     double l, r;     l = 1e-9;     r = 1e9;     for (int i = 1; i <= n; ++i) {       double m = t * v[i];       l = max(l, x[i] - m);       r = min(r, x[i] + m);     }     return (l <= r);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) cin >> x[i];     for (int i = 1; i <= n; ++i) cin >> v[i];     double l, r, mid;     l = 0.0, r = 1e9;     while (abs(l - r) > 1e-6) {       mid = (l + r) / 2;       if (ok(mid)) {         res = mid;         r = mid;       } else         l = mid;     }     cout << fixed << setprecision(20) << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 500004, inf = 0x3f3f3f3f;   int a[MAX];   int no[102];   int nex[MAX][102];   int f[102][102 * 102];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k, p;     cin >> n >> k >> p;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] += a[i - 1];       a[i] %= p;     }     for (int i = 0; i < p; i++) no[i] = n + 1;     for (int i = n; i >= 0; i--) {       for (int j = 0; j < p; j++) {         nex[i][j] = no[j];       }       no[a[i]] = i;     }     int M = (p - 1) * k;     memset(f, 0x3f, sizeof f);     f[0][0] = 0;     for (int i = 1; i <= k; i++) {       for (int j = 0; j <= M; j++) {         for (int u = min(p - 1, j); u >= 0; u--) {           if (f[i - 1][j - u] <= n)             f[i][j] = min(nex[f[i - 1][j - u]][j % p], f[i][j]);         }       }     }     for (int j = a[n]; j <= M; j += p)       if (f[k][j] <= n) {         cout << j;         return 0;       }   }
#include <bits/stdc++.h>   using namespace std;   long double F(int A, int B) {     long double S = 1;     for (int i = 0; i < B; i++) S = S * (A - i) / (i + 1);     return S;   }   int main() {     int N;     scanf( %d , &N);     static int C[100000], Max[100000];     static long double P[100000][101];     memset(P, 0, sizeof(P));     for (int i = 0; i < N; i++) {       scanf( %d , &C[i]);       Max[i] = C[i];       P[i][C[i]] = 1;     }     int Query;     scanf( %d , &Query);     long double Ans = 0;     for (int i = 0; i < N; i++)       if (!C[i]) Ans++;     while (Query--) {       int a, b, K;       scanf( %d%d%d , &a, &b, &K);       a--;       b--;       static long double DP[101];       memset(DP, 0, sizeof(DP));       long double All = F(C[a], K);       for (int i = 0; i <= C[a] && i <= Max[a]; i++)         for (int j = max(0, K - C[a] + i); j <= K && j <= i; j++)           DP[i - j] += P[a][i] * F(i, j) * F(C[a] - i, K - j) / All;       Ans += DP[0] - P[a][0];       for (int i = 0; i <= Max[a]; i++) P[a][i] = DP[i];       C[a] -= K;       C[b] += K;       printf( %0.10lf n , (double)Ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int input[n];       for (int i = (0); i < (n); i++) cin >> input[i];       sort(input, input + n);       vector<int> ans(n);       for (int i = (0); i < (n / 2); i++) {         ans[i * 2] = i;         ans[i * 2 + 1] = n - 1 - i;       }       if (n & 1) ans[n - 1] = n / 2;       for (int i = (n)-1; i >= (0); --i) cout << input[ans[i]] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char cell;     short r, c, rr, cc, e;     int res = 0, i, cat[100], cnt = 0;     cin >> r >> c;     rr = r;     cc = c;     for (i = 0; i < r; i++) {       e = 0;       for (int I = 0; I < c; I++) {         cin >> cell;         if (cell ==  S ) {           e++;           cat[cnt] = I;           cnt++;         }       }       if (e == 0) {         res += c;         rr--;       }     }     cc -= cnt;     sort(cat, cat + cnt);     for (i = 1; i < cnt; i++)       if (cat[i] == cat[i - 1]) cc++;     res += cc * rr;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 3, M = 1e6 + 3, O = 2e6 + 3;   int c[N], a[N], b[N], id[O], tp;   bool f[N];   struct P {     int f, sz;   } d[M], st[O];   int gf(int x) { return d[x].f == x ? x : gf(d[x].f); }   void mg(int x, int y) {     int u = gf(x), v = gf(y);     if (d[u].sz > d[v].sz) swap(u, v);     st[++tp] = d[u], id[tp] = u, st[++tp] = d[v], id[tp] = v;     d[v].sz += d[u].sz, d[u].f = v;   }   map<pair<int, int>, int> mp;   vector<int> vc[N];   int main() {     int n, m, k, i, j, l, u, v, w, uu, vv, tt, uuu, vvv;     long long ans = 0;     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; ++i) scanf( %d , c + i);     for (i = 1; i <= n * 2; ++i) d[i].f = i, d[i].sz = 1;     for (i = 1; i <= m; ++i) scanf( %d%d , a + i, b + i);     for (i = 1; i <= m; ++i)       if (c[a[i]] == c[b[i]]) {         u = gf(a[i]), v = gf(b[i]);         if (u == v)           f[c[a[i]]] = 1;         else           mg(a[i], b[i] + n), mg(b[i], a[i] + n);       }     for (i = 1, j = 0; i <= m; ++i)       if (c[a[i]] != c[b[i]] && !f[c[a[i]]] && !f[c[b[i]]]) {         u = c[a[i]], v = c[b[i]];         if (u > v) swap(u, v);         l = mp[{u, v}];         if (!l) l = mp[{u, v}] = ++j;         vc[l].push_back(i);       }     for (auto o : mp) {       u = o.first.first, v = o.first.second, w = o.second, tt = tp;       for (int o2 : vc[w]) {         uu = a[o2], vv = b[o2], uuu = gf(uu), vvv = gf(vv);         if (uuu == vvv) {           --ans;           break;         }         mg(uu, vv + n), mg(uu + n, vv);       }       while (tp != tt) d[id[tp]] = st[tp], --tp;     }     for (i = 1, j = 0; i <= k; ++i)       if (!f[i]) ++j;     ans += j * 1ll * (j - 1) / 2;     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     string s;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s;       if (s ==  Tetrahedron ) sum += 4;       if (s ==  Cube ) sum += 6;       if (s ==  Octahedron ) sum += 8;       if (s ==  Dodecahedron ) sum += 12;       if (s ==  Icosahedron ) sum += 20;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     char d[m][n];     int ub = m, lb = 0, lfb = n, rb = 0;     for (int r = 0; r < m; r++) {       for (int c = 0; c < n; c++) {         cin >> d[r][c];         if (d[r][c] ==  * ) {           if (ub > r) ub = r;           if (lb < r) lb = r;           if (rb < c) rb = c;           if (lfb > c) lfb = c;         }       }     }     for (int r = ub; r <= lb; r++) {       for (int c = lfb; c <= rb; c++) cout << d[r][c];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t, i, j, r, k, x, y, n, m, l, a, b, c, d = 0;     cin >> t;     string s, cm =  abacaba ;     while (t--) {       cin >> l >> r;       if (2 * l <= r) {         cout << l <<     << 2 * l <<   n ;       } else         cout <<  -1 -1 n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     s.resize(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     int ans = 0;     for (int i = 0; i < 7; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (s[j][i] ==  1 ) cnt++;       }       ans = max(ans, cnt);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[12], k, c = 0, a = 0;     cin >> k;     for (int i = 0; i < 12; i++) {       cin >> arr[i];     }     sort(arr, arr + 12);     for (int i = 11; i >= 0; i--) {       if (c < k) {         c += arr[i];         a++;       }     }     if (c < k)       cout <<  -1 ;     else       cout << a;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 1e6 + 5;   const int maxm = 1e5 + 5;   using namespace std;   int rd() {     int x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x;   }   int n, head[maxn], tot, a, b, c, d, cnt, Node, rk[maxn], len, lst[maxn], top;   int lena, lenb, lenc, lend, mx;   vector<int> vec[maxn];   bitset<maxm> res;   struct node {     int v, nxt;   } e[maxn << 1];   void add(int u, int v) {     e[++tot].v = v;     e[tot].nxt = head[u];     head[u] = tot;   }   void dfs(int u, int y) {     bool flag = true;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (v == y) continue;       if (u == 1) ++cnt;       flag = false;       dfs(v, u);     }     if (flag) vec[cnt].push_back(u), rk[u] = cnt;   }   bool check() {     lena = ((int)vec[rk[a]].size());     lenb = ((int)vec[rk[b]].size());     lenc = ((int)vec[rk[c]].size());     lend = ((int)vec[rk[d]].size());     for (int i = max(0, len - lena - lenb); i <= len - 2; i++) {       if (lenc <= i && res[i - lenc]) return true;       if (lend <= i && res[i - lend]) return true;     }     for (int i = max(0, len - lenc - lend); i <= len - 2; i++) {       if (lena <= i && res[i - lena]) return true;       if (lenb <= i && res[i - lenb]) return true;     }     return false;   }   int main() {     n = rd();     a = rd();     b = rd();     c = rd();     d = rd();     for (int i = 2, u; i <= n; i++) {       u = rd();       add(u, i);       add(i, u);     }     dfs(1, 0);     for (int i = 1; i <= cnt; i++) {       Node += ((int)vec[i].size());       if (i != rk[a] && i != rk[b] && i != rk[c] && i != rk[d])         lst[++top] = ((int)vec[i].size()), mx = max(mx, ((int)vec[i].size()));     }     if (Node & 1) {       puts( No );       return 0;     }     len = Node / 2 + 1;     if (rk[a] == rk[b]) {       puts( No );       return 0;     }     if (rk[c] == rk[d]) {       puts( No );       return 0;     }     if (((int)vec[rk[a]].size()) > Node - len ||         ((int)vec[rk[b]].size()) > Node - len ||         ((int)vec[rk[c]].size()) > Node - len ||         ((int)vec[rk[d]].size()) > Node - len || mx > Node - len) {       puts( No );       return 0;     }     res.set(0);     for (int i = 1; i <= top; i++) res |= res << lst[i];     puts(check() ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, i;     long long sum = 0, x = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     for (i = 0; i < (n / 2); i++) {       x += a[i];     }     cout << x * x + (sum - x) * (sum - x) << endl;     return 0;   }
#include <bits/stdc++.h>   const int inf = 2 * 1e9;   const int mod = 1e9 + 7;   const long long infll = (long long)1e18;   const long double eps = 1e-9;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, -1, 0, 1};   const int MAXY = 1005000;   using namespace std;   int n, m;   vector<vector<pair<int, int>>> g;   vector<bool> used;   vector<int> topsort;   void dfs(int v, int time) {     used[v] = true;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i].first;       int edgeTime = g[v][i].second;       if (edgeTime <= time) {         if (!used[to]) dfs(to, time);       }     }     topsort.push_back(v);   }   bool check(int time) {     used.assign(n, false);     topsort.clear();     for (int i = 0; i < n; i++) {       if (!used[i]) dfs(i, time);     }     reverse(topsort.begin(), topsort.end());     for (int i = 0; i < (n - 1); i++) {       int cur = topsort[i];       int nxt = topsort[i + 1];       bool ok = false;       for (int j = 0; j < g[cur].size(); j++) {         if (g[cur][j].second <= time) ok = ok || g[cur][j].first == nxt;       }       if (!ok) return false;     }     return true;   }   void solve() {     cin >> n >> m;     g.resize(n);     used.resize(n);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(make_pair(y, i));     }     if (!check(m - 1)) {       cout << -1;       return;     }     int tl = 0;     int tr = m - 1;     while (tr - tl > 1) {       int tm = (tl + tr) / 2;       if (check(tm))         tr = tm;       else         tl = tm;     }     cout << tr + 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     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--) {       int n, k;       cin >> n >> k;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int d = unique(a.begin(), a.end()) - a.begin();       if (k > d)         cout << 1 <<   n ;       else if (k == 1) {         if (d == 1)           cout << 1 <<   n ;         else           cout << -1 <<   n ;       } else {         int ans = 1;         d -= k;         ans += (d + k - 2) / (k - 1);         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};   int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};   int a[500], c[500];   int main() {     int t = 0, z = 0, len;     int n, k = 0, m = 0, bam = 0, dan = 0, ans = 0;     scanf( %d %d , &n, &m);     for (int l = 1; l < n + 1; l++) {       scanf( %d , &a[l]);       a[l] += a[l - 1];     }     for (int l = 0; l < m; l++) {       int x, y;       scanf( %d %d , &x, &y);       c[l] = a[y] - a[x - 1];     }     k = 0;     sort(c, c + m);     for (int l = m - 1; l > -1; l--) {       k += c[l];       ans = max(ans, k);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   int edge[2222][2222];   int deg[2222];   int n;   char s[2222];   int id[2222];   int ok() {     for (int i = 1; i <= n; i++) id[i] = i;     sort(id + 1, id + n + 1, [&](int u, int v) { return deg[u] < deg[v]; });     for (int i = 1, sum = 0; i < n; i++) {       sum += deg[id[i]];       if (sum == i * (i - 1) / 2) return 0;     }     return 1;   }   int small_solve() {     int mn = n + 1, cnt = 0;     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++)         if ((i >> j) & 1) {           for (int k = 1; k <= n; k++)             if (k != j + 1) {               if (edge[k][j + 1])                 deg[k]--, deg[j + 1]++;               else                 deg[k]++, deg[j + 1]--;               edge[k][j + 1] ^= 1;               edge[j + 1][k] ^= 1;             }         }       if (ok()) {         if (mn > __builtin_popcount(i))           mn = __builtin_popcount(i), cnt = 1;         else if (mn == __builtin_popcount(i))           cnt++;       }       for (int j = 0; j < n; j++)         if ((i >> j) & 1) {           for (int k = 1; k <= n; k++)             if (k != j + 1) {               if (edge[k][j + 1])                 deg[k]--, deg[j + 1]++;               else                 deg[k]++, deg[j + 1]--;               edge[k][j + 1] ^= 1;               edge[j + 1][k] ^= 1;             }         }     }     for (int i = 1; i <= mn; i++) cnt *= i;     if (mn == n + 1)       cout << -1 << endl;     else       cout << mn <<     << cnt << endl;     exit(0);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n; j++)         if (s[j] ==  1 ) {           edge[i][j] = 1;           deg[i]++;         }     }     if (ok()) {       cout << 0 <<     << 1 << endl;       return 0;     }     if (n <= 6) small_solve();     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (j != i) {           if (edge[i][j])             deg[i]--, deg[j]++;           else             deg[i]++, deg[j]--;         }       if (ok()) cnt++;       for (int j = 1; j <= n; j++)         if (j != i) {           if (!edge[i][j])             deg[i]--, deg[j]++;           else             deg[i]++, deg[j]--;         }     }     cout << 1 <<     << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long linf = 1e18 + 5;   long long int gcd(long long int a, long long int b) {     return (b == 0 ? a : gcd(b, a % b));   }   long long int lcm(int a, int b) { return (a * (b / gcd(a, b))); }   long long int max(long long int a, long long int b, long long int c) {     return max(a, max(b, c));   }   long long int power(long long int x, long long int y) {     long long int ans = 1;     while (y > 0) {       if (y & 1) ans = (ans * x) % 1000000007;       x = (x * x) % 1000000007;       y /= 2;     }     return ans;   }   inline int read() {     int ret = 0, temp = 1;     int c = getchar();     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ret = (ret << 3) + (ret << 1) + c -  0 ;       c = getchar();     }     return ret;   }   string solve(int n) {     string s;     while (n > 0) {       s = char(n % 10 + 48) + s;       n /= 10;     }     return s;   }   double X[N], Y[N], A[N], B[N];   double dist(pair<long long int, long long int> a,               pair<long long int, long long int> b) {     return sqrt((a.first - b.first) * (a.first - b.first) +                 (a.second - b.second) * (a.second - b.second));   }   set<pair<double, int> > Adist, Bdist;   int main() {     int n;     double ax, ay, bx, by, tx, ty, x, y;     cin >> ax >> ay >> bx >> by >> tx >> ty;     cin >> n;     double add = 0.0;     for (int i = 0; i < n; i++) {       cin >> x >> y;       X[i] = x;       Y[i] = y;       add += 2 * dist({x, y}, {tx, ty});       A[i] = dist({x, y}, {ax, ay}) - dist({x, y}, {tx, ty});       B[i] = dist({x, y}, {bx, by}) - dist({x, y}, {tx, ty});       Adist.insert({A[i], i});       Bdist.insert({B[i], i});     }     double onlyA = 0.0, onlyB = 0.0, bothAB = 0.0;     onlyA = add + Adist.begin()->first;     onlyB = add + Bdist.begin()->first;     bothAB = add;     if (n == 1) {       printf( %.10lf n , min(onlyA, onlyB));     } else {       if (Adist.begin()->second == Bdist.begin()->second) {         auto it1 = Adist.begin();         it1++;         auto it2 = Bdist.begin();         it2++;         double ans = min(Adist.begin()->first + it2->first,                          Bdist.begin()->first + it1->first);         bothAB += ans;       } else         bothAB += (Adist.begin()->first + Bdist.begin()->first);       printf( %.10lf , min(min(onlyA, onlyB), bothAB));     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, s, arr[4005][4005] = {}, x = 2000, ex[9][4], song[100005], res = 0;   int main() {     cin >> n >> m >> k >> s;     for (int i = 0; i < 9; i++) {       ex[i][0] = -999999999;       ex[i][1] = 999999999;       ex[i][2] = -999999999;       ex[i][3] = 999999999;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i + j][i - j + x];         int c = arr[i + j][i - j + x] - 1;         for (int k = 0; k < 9; k++) {           ex[c][0] = max(ex[c][0], i + j);           ex[c][1] = min(ex[c][1], i + j);           ex[c][2] = max(ex[c][2], i - j + x);           ex[c][3] = min(ex[c][3], i - j + x);         }       }     }     for (int i = 0; i < s; i++) cin >> song[i], song[i]--;     for (int i = 1; i < s; i++) {       int a = song[i - 1], b = song[i];       res = max(res, max(max(ex[a][0] - ex[b][1], ex[b][0] - ex[a][1]),                          max(ex[a][2] - ex[b][3], ex[b][2] - ex[a][3])));     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long MAX = 200005;   bool prime[MAX];   void sieve() {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long p = 2; p * p <= MAX; p++) {       if (prime[p] == true) {         for (long long i = p * 2; i <= MAX; i += p) prime[i] = false;       }     }   }   long long power(long long a, long long b, long long m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long t = power(a, b / 2, m);     t = (t * t) % m;     if (b & 1) t = (t * a) % m;     return t;   }   long long modInverse(long long a, long long m) { return power(a, m - 2, m); }   long long __gcd(long long a, long long b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   bool cmp(const pair<long long, long long> &l,            const pair<long long, long long> &r) {     return l.first < r.first;   }   long long n, q;   vector<vector<long long> > g;   long long visited[MAX];   long long num[MAX];   long long cnt[MAX];   long long k;   long long dfs(long long node) {     visited[node] = 1;     num[node] = k;     k++;     long long p = 0, flag = 0;     for (auto i : g[node]) {       if (!visited[i]) {         flag = 1;         p += dfs(i);       }     }     if (flag) {       cnt[node] = p;       return 1 + p;     } else {       cnt[node] = 0;       return 1;     }   }   void solve() {     cin >> n >> q;     g.resize(n + 1, vector<long long>());     long long x;     for (long long i = 2; i <= n; i++) {       cin >> x;       g[i].push_back(x);       g[x].push_back(i);     }     memset(visited, 0, sizeof(visited));     memset(num, 0, sizeof(num));     memset(cnt, 0, sizeof(cnt));     k = 1;     dfs(1);     map<long long, long long> m;     for (long long i = 0; i < MAX; i++) m[num[i]] = i;     while (q--) {       long long x, y;       cin >> x >> y;       if (cnt[x] < y - 1)         cout <<  -1               <<   n ;       else {         long long w = num[x];         cout << m[w + y - 1] <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long t;     t = 1;     while (t--) {       solve();       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     long long a, b, f, k;     cin >> a >> b >> f >> k;     if (b / a >= k) {       cout << 0 << endl;       return 0;     }     v.push_back(f);     for (long long i = 2;; i += 2) {       long long r1 = i * a - f;       long long r2 = i * a + f;       if (r1 > k * a) break;       if (r1 <= k * a) v.push_back(r1);       if (r2 <= k * a) v.push_back(r2);     }     v.push_back(k * a);     if (b < f) {       cout << -1;       return 0;     }     long long last = 0;     long long has = b;     int sum = 0;     for (int i = 0; i < v.size(); i++) {       long long dis = v[i] - last;       if (dis > has) {         has = b;         sum++;       }       if (has < dis) {         cout << -1 << endl;         return 0;       }       has -= dis;       last = v[i];     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     int n;     long long sum = 0;     cin >> n;     memset(a, -1, sizeof(a));     for (int i = n; i >= 0; i--) {       if (a[i] != -1)         continue;       else {         for (int tt = 1;; tt *= 2) {           if (tt - 1 >= i) {             a[i] = tt - 1 - i;             a[tt - 1 - i] = i;             sum = sum + 2 * (tt - 1);             break;           }         }       }     }     cout << sum << endl;     for (int i = 0; i <= n; i++) {       if (i != 0) printf(   );       printf( %d , a[i]);     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a;     map<int, int> mp;     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> a;       mp[a]++;     }     for (auto it : mp) {       mx = max(mx, it.second);     }     cout << n - mx;   }