malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int quick_pow(int a, int b, int MOD) {     a %= MOD;     int res = 1;     while (b) {       if (b & 1) res = (res * a) % MOD;       b /= 2;       a = (a * a) % MOD;     }     return res;   }   const int maxn = 200000 + 10;   const int MOD = 1e9 + 7;   const int INF = 1e9;   int a[maxn], dp[maxn];   priority_queue<int, vector<int>, greater<int> > que1, que2[maxn];   typedef struct Segment {     int sum[maxn * 4];     void pushUp(int k) { sum[k] = min(sum[k * 2], sum[k * 2 + 1]); }     void build(int k, int l, int r) {       sum[k] = INF;       if (l == r) return;       int m = (l + r) / 2;       build(k * 2, l, m);       build(k * 2 + 1, m + 1, r);     }     void update(int p, int v, int k, int l, int r) {       if (l == r) {         sum[k] = min(sum[k], v);         return;       }       int m = (l + r) / 2;       if (p <= m)         update(p, v, k * 2, l, m);       else         update(p, v, k * 2 + 1, m + 1, r);       pushUp(k);     }     int ask(int a, int b, int k, int l, int r) {       if (a <= l && r <= b) return sum[k];       int m = (l + r) / 2, res = INF;       if (a <= m) res = min(res, ask(a, b, k * 2, l, m));       if (b > m) res = min(res, ask(a, b, k * 2 + 1, m + 1, r));       return res;     }   } Tree;   Tree tree;   int main() {     int i, j, n, m;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     tree.build(1, 1, n);     printf( 0 );     int now = 0;     tree.update(a[1], a[1] + 1, 1, 1, n);     now = -1;     for (i = 2; i <= n; i++) {       int res = now + i;       res = min(res, tree.ask(i, n, 1, 1, n) - i);       printf(  %d , res);       tree.update(a[i], res + 1 + a[i], 1, 1, n);       now = min(now, res - i);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pai = acos(-1);   const double eps = 1e-8;   const long long mod = 1e9 + 7;   const int MXN = 1e6 + 5;   vector<int> v[MXN];   int c[MXN];   int suf[MXN];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int le;       scanf( %d , &le);       while (le--) {         int aa;         scanf( %d , &aa);         v[i].push_back(aa);       }       int mi = INT_MAX;       for (auto j : v[i]) {         if (j > mi) c[i] = 1;         mi = min(mi, j);       }       sort(v[i].begin(), v[i].end());     }     long long gg = 0;     for (int i = 1; i <= n; i++) {       if (c[i]) {         gg++;         continue;       }       suf[v[i].back()]++;     }     for (int i = 1e6 - 1; i >= 0; i--) suf[i] = suf[i] + suf[i + 1];     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (c[i])         ans = ans + (long long)n;       else         ans = ans + (long long)suf[v[i][0] + 1] + gg;     }     cout << ans <<   n ;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long      int main()   {      ll int n,q;      string s;      cin>>n>>q;      ll int cum[n+2];      cin>>s;      cum[0]=s[0]- a +1;      for(int i=1;i<n;i++)      {             cum[i]=cum[i-1]+s[i]- a +1;      }         for(ll int i=0;i<q;i++)      {   ll int a,b,ans=0;          cin>>a>>b;             if (a==1)          {cout<<cum[b-1]<<endl;}          else          {cout<<cum[b-1]-cum[a-2]<<endl;}         }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   void __never(int a) { printf(  nOPS %d , a); }   const int INF = 1000000000;   bool was[6][26][6][11][16][21];   int dp[6][26][6][11][16][21];   struct Edge {     int a, l, h;   };   int n;   Edge graf[7][7];   int mask[7];   void dfs(int a, int b, int rest, int cost, vector<int>& v,            vector<pair<vector<int>, int> >& res) {     if (b == n + 1) {       if (rest != 0) return;       vector<int> v2(5);       for (int(i) = (a); (i) <= (n - 2); ++(i)) v2[i] = v[i] + mask[i + 1];       res.push_back(make_pair(v2, cost));       return;     }     for (int(i) = (graf[a][b].l); (i) <= (graf[a][b].h); ++(i)) {       if (i > rest) break;       mask[b] = i;       dfs(a, b + 1, rest - i, cost + ((i > 0) ? graf[a][b].a : 0) + i * i, v,           res);     }   }   int get(vector<int> v, int st) {     if (was[st][v[0]][v[1]][v[2]][v[3]][v[4]])       return dp[st][v[0]][v[1]][v[2]][v[3]][v[4]];     was[st][v[0]][v[1]][v[2]][v[3]][v[4]] = true;     int& res = dp[st][v[0]][v[1]][v[2]][v[3]][v[4]];     if (v[0] + v[1] + v[2] + v[3] + v[4] == 0 && st == n - 1) return res = 0;     vector<pair<vector<int>, int> > vv;     dfs(st + 1, st + 2, v[st], 0, v, vv);     res = -INF;     for (int(i) = (0); (i) <= ((int)((vv).size()) - 1); ++(i)) {       int h = get(vv[i].first, st + 1);       if (h > -INF) res = max(res, h + vv[i].second);     }     return res;   }   void init() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void sol() {     cin >> n;     int a, b;     for (int(i) = (1); (i) <= ((n * (n - 1)) / 2); ++(i)) {       cin >> a >> b;       cin >> graf[a][b].l >> graf[a][b].h >> graf[a][b].a;     }     bool zero = true;     for (int(i) = (1); (i) <= (n); ++(i))       for (int(j) = (i + 1); (j) <= (n); ++(j)) zero &= graf[i][j].l == 0;     if (zero) {       printf( 0 0 );       return;     }     int hi = 0;     for (int(i) = (2); (i) <= (n); ++(i)) hi += graf[1][i].h;     vector<int> v(5);     for (int(I) = (1); (I) <= (hi); ++(I)) {       v[0] = I;       if (get(v, 0) > 0) {         printf( %d %d , I, get(v, 0));         return;       }     }     printf( -1 -1 );   }   void gen() {     int n = 6;     printf( %d , n);     for (int(i) = (1); (i) <= (n); ++(i))       for (int(j) = (i + 1); (j) <= (n); ++(j))         printf(  n%d %d %d %d %d , i, j, rand() & 1, 5, rand() & 15);   }   int main() {     sol();     return 0;   }
#include <bits/stdc++.h>   const int MOD = 1000000007;   const int MAX = 10000005;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n;     cin >> n;     long long b, d;     long long max = -1;     long long y = 0;     vector<pair<long long, long long> > vecx, vecy;     for (long long i = 0; i < n; i++) {       cin >> b >> d;       vecx.push_back(make_pair(b, d));       vecy.push_back(make_pair(d, b));     }     sort(vecx.begin(), vecx.end());     sort(vecy.begin(), vecy.end());     long long pointer1 = 0;     long long pointer2 = 0;     long long sum = 0;     for (long long i = 0; i < 2 * vecx.size(); i++) {       if (pointer1 == vecx.size() || pointer2 == vecx.size()) {         goto ab;       }       if (vecx[pointer1].first < vecy[pointer2].first) {         sum++;         if (sum > max) {           max = sum;           y = vecx[pointer1].first;         }         pointer1++;       } else if (vecx[pointer1].first > vecy[pointer2].first) {         sum--;         pointer2++;       } else {         sum--;         pointer2++;       }     }   ab:;     cout << y <<     << max <<    ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long N = 2e5 + 10, alp = 26;   const long double pi = 3.14159265358979;   void solve() {     long long n, m;     cin >> n >> m;     vector<vector<long long> > g1(n), rg1(n), g2(n), rg2(n);     for (long long i = 0; i < m; ++i) {       long long u, v, t;       cin >> u >> v >> t;       --u;       --v;       if (t)         g1[u].push_back(v), rg1[v].push_back(u);       else         g2[u].push_back(v), rg2[v].push_back(u);     }     vector<long long> ans(n, -1), len(n, -1);     ans[n - 1] = 0;     len[n - 1] = 0;     queue<long long> q;     q.push(n - 1);     while (q.size()) {       long long u = q.front();       q.pop();       set<long long> s1, s2;       for (long long to : rg1[u])         if (ans[to] == 1 && len[to] == -1) len[to] = len[u] + 1, q.push(to);       for (long long to : rg2[u])         if (ans[to] == 2 && len[to] == -1) len[to] = len[u] + 1, q.push(to);       for (long long to : rg1[u])         if (ans[to] == -1) s1.insert(to);       for (long long to : rg2[u])         if (ans[to] == -1) s2.insert(to);       for (long long x : s1)         if (!s2.count(x)) ans[x] = 2;       for (long long x : s2)         if (!s1.count(x)) ans[x] = 1;       for (long long x : s1)         if (s2.count(x) && len[x] == -1)           ans[x] = 1, len[x] = len[u] + 1, q.push(x);     }     cout << len[0] <<   n ;     for (long long i = 0; i < n; ++i) cout << (ans[i] == 1 ? 1 : 0);   }   int32_t main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 212345;   int n, a[maxn], f[maxn], pre[maxn];   vector<int> b;   int F(int x) { return x == f[x] ? x : f[x] = F(f[x]); }   inline void U(int a, int b) { f[min(F(a), F(b))] = max(F(a), F(b)); }   inline void go(int l, int r) {     for (int i = l, j;; i = j) {       j = F(i) + 1;       if (j > r) return;       U(i, j);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) b.push_back(a[i]);     for (int i = 1; i <= n; ++i) f[i] = i;     sort(b.begin(), b.end());     b.erase(unique(b.begin(), b.end()), b.end());     for (int i = 1; i <= n; ++i)       a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();     for (int i = 1; i <= n; ++i) {       if (pre[a[i]]) go(pre[a[i]], i);       pre[a[i]] = i;     }     long long res = 1, cnt = 0;     for (int i = 1; i <= n; ++i)       if (F(i) == i) {         if (cnt) res = (res + res) % mod;         ++cnt;       }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, y, a[(int)1e5 + 4];   unsigned long long x, sum;   void error() {     puts( -1 );     exit(0);   }   int main() {     scanf( %d%I64d%d , &n, &x, &y);     sum = (unsigned long long)n;     if (n > y || (n == y && sum < x)) error();     for (int i = 0; i < n; i++) a[i] = 1;     a[n - 1] += (y - n);     if (sum - 1LL + (unsigned long long)a[n - 1] * (unsigned long long)a[n - 1] <         x)       error();     for (int i = 0; i < n; i++) printf( %d n , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long counter;   long long n, r, l, x;   vector<long long> a;   long long sum, rr;   bool cheake(long long mask) {     long long nmax = -1;     long long nmin = 10000000000;     long long i = 0;     rr = 0;     sum = 0;     while ((mask >> i) != 0) {       if ((mask >> i) % 2 == 1) {         rr++;         sum = sum + a[i];         nmax = max(a[i], nmax);         nmin = min(a[i], nmin);       }       i++;     }     if ((rr >= 2) && (sum >= l) && (sum <= r) && (nmax - nmin) >= x)       return true;     else       return false;   }   void solv(long long i, long long mask) {     if (i == n) return;     solv(i + 1, mask);     long long nmask = mask | (1 << i);     solv(i + 1, nmask);     if (cheake(nmask)) counter++;   }   int main() {     long long k;     cin >> n >> l >> r >> x;     for (long long i = 0; i < n; i++) {       cin >> k;       a.push_back(k);     }     solv(0, 0);     cout << counter;   }
#include<iostream>   #include<cstdio>   #include<cstring>   #include<cmath>   #include<algorithm>   #include<vector>   #include<stack>   #include<queue>   #include<set>   #include<map>   //#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int maxn = 1e5+5;   const int inf = 0x3f3f3f3f;   const ll INF = 1e18;   const ll mod = 998244353;      #define for1(i,n) for(int i=1;i<=n;i++)   #define forn(i,n) for(int i=0;i<n;i++)   #define m_p(x,y) make_pair(x,y)      inline int read(){//ll??       int x=0,f=1;char ch=getchar();       while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}       while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();}       return x*f;   }      int main(){    int t=read(); while(t--){     int x=read(), y=read();     if(abs(x-y)<=1) cout << x+y << endl;     else cout << x+y+abs(x-y)-1 << endl;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p, s;   vector<int> v1, v2;   pair<int, pair<int, int>> arr[3005];   bool cmp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {     if (a.second.first == b.second.first)       return a.second.second < b.second.second;     return a.second.first > b.second.first;   }   int dp[3005][3005];   int solve(int x, int taken) {     if (x == n) {       if (taken == p) return 0;       return -1e9;     }     int &ret = dp[x][taken];     if (ret != -1) return ret;     ret = 0;     if (taken < p) {       ret = max(ret, arr[x].second.second + solve(x + 1, taken + 1));     }     int lef = min(s, x - taken);     if (lef < s) {       ret = max(ret, arr[x].second.first + solve(x + 1, taken));     }     ret = max(ret, solve(x + 1, taken));     return ret;   }   void trace(int x, int taken) {     if (x == n) return;     int &ret = dp[x][taken];     if (taken < p && ret == arr[x].second.second + solve(x + 1, taken + 1)) {       v2.push_back(arr[x].first);       trace(x + 1, taken + 1);       return;     }     int lef = min(s, x - taken);     if (lef < s) {       if (ret == arr[x].second.first + solve(x + 1, taken)) {         v1.push_back(arr[x].first);         trace(x + 1, taken);         return;       }     }     trace(x + 1, taken);   }   int main() {     cin >> n >> p >> s;     swap(p, s);     for (int i = 0; i < n; i++) {       cin >> arr[i].second.first;       arr[i].first = i + 1;     }     for (int i = 0; i < n; i++) {       cin >> arr[i].second.second;     }     sort(arr, arr + n, cmp);     memset(dp, -1, sizeof dp);     cout << solve(0, 0) <<   n ;     trace(0, 0);     for (auto i : v1) cout << i <<    ;     cout <<   n ;     for (auto i : v2) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e5 + 100;   const int MAX = (int)1e5 + 1;   int l[maxN], d[maxN], cnt[maxN], q[maxN];   vector<int> pool[maxN];   multiset<int> p;   void solveTask() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> l[i];     for (int i = 1; i <= n; ++i) cin >> d[i];     for (int i = 1; i <= n; ++i)       q[l[i]] += d[i], cnt[l[i]] += 1, pool[l[i]].push_back(d[i]);     int answer = 0;     int all_sum = 0;     for (int i = 1; i <= MAX; ++i) {       if (cnt[i] == 0) continue;       int possibleCnt = cnt[i] - 1;       int cur_sum = 0;       for (set<int>::iterator it = p.begin(); it != p.end(); ++it) {         if (possibleCnt == 0) break;         cur_sum -= *it;         --possibleCnt;       }       answer = max(answer, cur_sum + q[i]);       all_sum += q[i];       for (int j = 0; j < pool[i].size(); ++j) {         p.insert(-pool[i][j]);       }     }     cout << all_sum - answer << endl;   }   int main() {     solveTask();     ios_base::sync_with_stdio(false);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long get(long long n) {     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) return i;     return n;   }   int main() {     long long n;     scanf( %lld , &n);     long long cnt = 0;     if (n % 2 != 0) {       n -= get(n);       ++cnt;     }     printf( %lld n , cnt + n / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x, m = 0;     char a[1000];     int s[26];     cin >> n;     while (n--) {       cin >> a;       m = 0;       int mi = 1000, mx = -1;       for (i = 0; i < 26; i++) {         s[i] = 0;       }       x = strlen(a);       for (i = 0; i < x; i++) {         s[a[i] -  a ]++;         mi = min(mi, (a[i] -  a ));         mx = max(mx, (a[i] -  a ));       }       for (i = 0; i < 26; i++) {         if (s[i] > 1) {           cout <<  No  << endl;           m = 1;           break;         }       }       for (i = mi; i <= mx; i++) {         if (s[i] != 1 && m != 1) {           cout <<  No  << endl;           m = 1;           break;         }       }       if (m == 0) cout <<  Yes  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int ar[500009], br[500009];   int main() {     long long int a, b, c, i, j = 0, k = 9999999999999;     string s;     cin >> a;     getchar();     cin >> s;     for (i = 0; i < a; i++) {       cin >> ar[i];     }     for (i = 0; i < a - 1; i++) {       if (s[i] ==  R  && s[i + 1] ==  L ) {         k = min(k, (ar[i + 1] - ar[i]));       }     }     if (k == 9999999999999) {       cout <<  -1 ;     } else       cout << (k / 2) << endl;   }
#include <bits/stdc++.h>   #pragma diag_suppress 177   using namespace std;   const int MM = 220000;   int m, n, k, p1, p2, p3, f, a[MM], pr[MM], af[MM], tree[4 * MM];   string s, s1, s2;   int MINN = 0;   int func(int aa, int bb) { return (aa | bb); }   void build(int node, int start, int end) {     if (start == end)       tree[node] = a[start];     else {       int mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       tree[node] = func(tree[2 * node], tree[2 * node + 1]);     }   }   int query(int node, int start, int end, int l, int r) {     if (r < start or end < l) return MINN;     if (l <= start and end <= r) return tree[node];     int mid = (start + end) / 2;     int px1 = query(2 * node, start, mid, l, r);     int px2 = query(2 * node + 1, mid + 1, end, l, r);     return func(px1, px2);   }   bool chk(int hi, int mid, int val) {     return (query(1, 0, n - 1, mid, hi) > val);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int cur;     priority_queue<pair<int, int> > pq;     vector<int> ind;     for (int i = 0; i < n; i++) {       cur = i;       while (!ind.empty() && a[ind.back()] <= a[i]) {         cur = pr[ind.back()];         ind.pop_back();       }       pr[i] = cur;       ind.push_back(i);     }     ind.clear();     for (int i = n - 1; i >= 0; i--) {       cur = i;       while (!ind.empty() && a[ind.back()] < a[i]) {         cur = af[ind.back()];         ind.pop_back();       }       af[i] = cur;       ind.push_back(i);     }     long long ans = 0;     build(1, 0, n - 1);     int ls, rs, hi, lo, mid, xx, yy;     for (int i = 0; i < n; i++) {       ls = i - pr[i] + 1;       rs = af[i] - i + 1;       hi = i;       lo = pr[i];       while (hi > lo) {         mid = (hi + lo) / 2;         if (chk(i, mid, a[i]))           lo = mid + 1;         else           hi = mid;       }       xx = i - lo + 1;       ans += (long long)ls * (long long)rs;       hi = af[i];       lo = i;       while (hi > lo) {         mid = (hi + lo) / 2;         if (chk(mid, i, a[i]))           hi = mid;         else           lo = mid + 1;       }       if (chk(lo, i, a[i])) lo--;       yy = lo - i + 1;       ans -= (long long)xx * (long long)yy;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   const int INF = 1e9 + 9;   const int B = 1e9 + 7;   long long n;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n;     long long pwr = 1;     for (;;) {       long long x = (n + (pwr - 1)) / pwr;       if (n % pwr != 0) {         cout << x <<   n ;         return 0;       }       if (x == 1) {         cout << x <<   n ;         return 0;       }       if (x == 2 && pwr * 3 < n) {         cout << x <<   n ;         return 0;       }       pwr *= 3;     }     assert(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       int n;       long long a = 0, b;       cin >> n;       b = pow(2, n);       for (int i = 1; i < n / 2; i++) b += pow(2, i);       for (int i = n / 2; i < n; i++) a += pow(2, i);       cout << abs(b - a) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       int a, h, sum = 0;       cin >> a;       for (int i = 2; i < a; i++) {         int n = a;         while (n >= i) {           sum += n % i;           n = n / i;         }         sum += n;       }       h = gcd(sum, a - 2);       cout << sum / h <<  /  << (a - 2) / h << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int i, arr[n];       for (i = 0; i < n; i++) cin >> arr[i];       int ap{0}, bp{n}, asize{arr[0]}, bsize{}, moves{1}, left = n - 1;       bool a = 1;       while (left != 0) {         if (a) {           while (bsize <= asize && left != 0) {             bsize += arr[bp - 1];             bp--;             left--;           }           moves++;           asize = 0;           a = 0;         } else {           while (asize <= bsize && left != 0) {             asize += arr[ap + 1];             ap++;             left--;           }           moves++;           bsize = 0;           a = 1;         }       }       cout << moves <<    ;       asize = 0;       for (i = 0; i <= ap; i++) asize += arr[i];       cout << asize <<    ;       bsize = 0;       for (; i < n; i++) bsize += arr[i];       cout << bsize << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   ll hell = 998244353;   int main() {     ll n;     cin >> n;     vector<ll> v[n];     for (ll i = 0; i < n; ++i) {       ll x;       cin >> x;       for (ll j = 0; j < x; ++j) {         ll y;         cin >> y;         v[i].push_back(y);       }       v[i].push_back(100009);       sort(v[i].begin(), v[i].end());     }     ll ans = 0;     for (ll i = 0; i < n; ++i) {       ll e = (i != 0) ? i - 1 : n - 1;       ll f = (i != n - 1) ? i + 1 : 0;       for (ll j = 1; j < v[i].size() - 1; ++j) {         ll v1 = v[i][j];         ll v2 = v[i][j - 1];         ll c1 = lower_bound(v[e].begin(), v[e].end(), v1) -                 lower_bound(v[e].begin(), v[e].end(), v2);         ll c2 = lower_bound(v[f].begin(), v[f].end(), v1) -                 lower_bound(v[f].begin(), v[f].end(), v2);         if (c1 != c2) ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(  n );   }   template <typename T>   inline void Mx(T &x, T y) {     x < y && (x = y, 0);   }   template <typename T>   inline void Mn(T &x, T y) {     x > y && (x = y);   }   const int N = 2005;   int m, n;   double f[N][N];   int main() {     read(n), read(m);     int mx = max(n, m);     for (int i = 0; i <= mx; i++) f[i][0] = 1;     for (int i = 1; i <= mx; i++) f[0][i] = 1.0 / (i + 1);     for (int i = 2; i <= n + m; i++) {       for (int j = 1; j < i; j++) {         if (i - j < 1) continue;         int x = j, y = i - j;         double inv = 1.0 / (y + 1);         double c = inv * y * (1 - f[y - 1][x]), b = (1 - f[y][x - 1]);         double d = c + inv;         double p = (1.0 - b) / (1 - c + d - b);         f[x][y] = p * c + (1 - p);       }     }     printf( %.9lf %.9lf n , f[n][m], 1 - f[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, ns[10005] = {};     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       ns[a]++;     }     int ans = 0;     for (int i = 0; i < 10000; i++) {       int j = i + 1;       while (ns[i] > 1) {         for (; j < 10000 && ns[j] != 0; j++)           ;         ns[j]++;         ns[i]--;         ans += j - i;       }     }     cout << ans << endl;     return 0;   }