malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const double EPS = 1e-9;   const int INT_INF = 1 << 31 - 1;   const long long I64_INF = 1ll << 63 - 1ll;   const double PI = acos(-1.0);   using namespace std;   struct person {     int c, first;     person(int _c = 0, int _f = 0) {       c = _c;       first = _f;     }     friend bool operator<(const person& a, const person& b) {       return a.first < b.first;     }   };   int n, d, S;   vector<person> a;   vector<person> b;   vector<int> sumb;   int maxCNT = 0;   int minS = 0;   void upd(int a, int b) {     if (a > maxCNT || a == maxCNT && b < minS) {       maxCNT = a;       minS = b;     }   }   pair<int, int> go(int free, int second) {     if (free >= (int)b.size()) return make_pair((int)b.size(), 0);     if (b[0].first > second) return make_pair(free, 0);     int r = (int)b.size() - free;     int l = 0;     while (l != r - 1) {       int m = (l + r) >> 1;       if (sumb[m] <= second)         l = m;       else         r = m;     }     return make_pair(free + l + 1, sumb[l]);   }   int main() {     scanf( %d%d%d , &n, &d, &S);     for (int i = 0; i < (int)n; i++) {       int c, first, l;       scanf( %d%d%d , &c, &first, &l);       if (l < d) first = S + 1;       if (!c)         b.push_back(person(c, first));       else         a.push_back(person(c, first));     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     if (!b.empty()) sumb.push_back(b[0].first);     for (int i = 1; i < (int)b.size(); i++)       if (*sumb.rbegin() > S)         sumb.push_back(S + 1);       else         sumb.push_back(*sumb.rbegin() + b[i].first);     pair<int, int> r = go(0, S);     upd(r.first, r.second);     int k = 0;     int sum = 0;     int Sum = 0;     for (int i = 0; i < (int)a.size(); i++) {       Sum += a[i].c;       if (Sum > n + n) break;     }     for (int i = 0; i < (int)a.size(); i++) {       k++;       sum += a[i].first;       if (sum > S) break;       int x = Sum - (int)a.size() + k;       pair<int, int> r = go(x, S - sum);       upd((int)a.size() + r.first, sum + r.second);     }     printf( %d %d n , maxCNT, minS);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n), cum(n + 1);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       cum[i + 1] = a[i] + cum[i];     }     int bits = 32 - __builtin_clz(n);     vector<vector<int>> dp(bits + 1, vector<int>(n));     auto sum = [&](int l, int r) { return (cum[r] - cum[l]) % 10; };     for (int bit = 0; bit < bits; bit++) {       int len = 1 << bit;       for (int i = 0; i + 2 * len <= n; i++) {         dp[bit + 1][i] = dp[bit][i] + dp[bit][i + len] +                          (sum(i, i + len) + sum(i + len, i + 2 * len)) / 10;       }     }     int q;     scanf( %d , &q);     for (int qq = 0; qq < q; qq++) {       int l, r;       scanf( %d %d , &l, &r);       --l;       int bit = __builtin_ctz(r - l);       printf( %d n , dp[bit][l]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 5, MOD = 1e9 + 7;   long long n;   long long par[MAXN];   long long cnt1[MAXN];   long long cnt2[MAXN];   long long dp1[MAXN];   long long dp2[MAXN];   long long color[MAXN];   bool subtree[MAXN];   vector<long long> G[MAXN];   void dfs_up1(long long v = 0) {     for (long long i = 0; i < G[v].size(); i++) {       dfs_up1(G[v][i]);       subtree[v] |= subtree[G[v][i]];     }     subtree[v] |= color[v];   }   void dfs_up2(long long v = 0) {     for (long long i = 0; i < G[v].size(); i++) dfs_up2(G[v][i]);     if (!subtree[v]) {       dp1[v] = 0;       dp2[v] = 1;       return;     }     if (color[v]) {       dp1[v] = 1;       for (long long i = 0; i < G[v].size(); i++)         if (subtree[G[v][i]]) {           if (color[G[v][i]]) dp1[v] = (dp1[v] * dp1[G[v][i]]) % MOD;           if (!color[G[v][i]])             dp1[v] = (dp1[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;         }       dp2[v] = 0;       return;     }     long long bu = 1, num = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) {           num++;           bu = (bu * dp1[G[v][i]]) % MOD;         }         if (!color[G[v][i]]) bu = (bu * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;       }     dp1[v] = num * bu % MOD;     bu = 1;     num = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) bu = (bu * dp1[G[v][i]]) % MOD;         if (!color[G[v][i]]) {           cnt1[num] =               ((num ? cnt1[num - 1] : 1) * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;           num++;         }       }     long long ind = num - 1;     for (long long i = G[v].size() - 1; ~i; i--)       if (subtree[G[v][i]]) {         if (!color[G[v][i]]) {           cnt2[ind] = ((ind != num - 1 ? cnt2[ind + 1] : 1) *                        (dp1[G[v][i]] + dp2[G[v][i]])) %                       MOD;           ind--;         }       }     ind = 0;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (!color[G[v][i]]) {           dp1[v] = (dp1[v] + bu * (ind ? cnt1[ind - 1] : 1) % MOD *                                  (ind + 1 != num ? cnt2[ind + 1] : 1) % MOD *                                  dp1[G[v][i]]) %                    MOD;           ind++;         }       }     dp2[v] = 1;     for (long long i = 0; i < G[v].size(); i++)       if (subtree[G[v][i]]) {         if (color[G[v][i]]) dp2[v] = (dp2[v] * dp1[G[v][i]]) % MOD;         if (!color[G[v][i]])           dp2[v] = (dp2[v] * (dp1[G[v][i]] + dp2[G[v][i]])) % MOD;       }   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i < n; i++) {       scanf( %lld , &par[i]);       G[par[i]].push_back(i);     }     for (long long i = 0; i < n; i++) scanf( %lld , &color[i]);     dfs_up1();     dfs_up2();     printf( %lld n , dp1[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long s, x, a, ans = 1;   void setup() {     cin >> s >> x;     a = s - x;     if (a & 1) {       cout << 0;       exit(0);     }     a >>= 1;   }   void xuly() {     long long k = a;     while (x) {       if (x & 1) {         if (a & 1) {           cout << 0;           return;         }         ans <<= 1;       }       x >>= 1;       a >>= 1;     }     if (k == 0) ans -= 2;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     setup();     xuly();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int n = a.size();     int f = 0, s = 0;     for (int i = 0; i < n; ++i)       if (a[i] != b[i]) {         if (a[i] ==  4 )           f++;         else           s++;       }     int ans = min(f, s);     ans += (f - ans) + (s - ans);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 5;   int n, par[N], mx1[N], mx2[N], ans[N];   int main() {     scanf( %d , &n);     par[1] = mx1[1] = mx2[1] = ans[1] = 0;     for (int i = 2; i <= n + 1; i++) {       scanf( %d , &par[i]);       int v = i, val;       ans[i] = mx1[i] = mx2[i] = 0;       while (v > 0) {         val = max(mx1[v], mx2[v] + 1);         if (val <= ans[v]) break;         ans[v] = val;         if (mx1[par[v]] < val)           mx1[par[v]] = val;         else if (mx2[par[v]] < val)           mx2[par[v]] = val;         v = par[v];       }       printf( %d  , max(mx1[1], mx2[1]));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct rec {     int w, h;   };   vector<rec> v;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int w, h;       scanf( %d %d , &w, &h);       v.push_back({w, h});     }     int last = -0x3f3f3f3f;     for (int i = n; i > 0; i--) {       int prev = max(v[i - 1].w, v[i - 1].h);       int mini = min(v[i].h, v[i].w);       int maxi = max(v[i].h, v[i].w);       if (mini >= last && mini <= prev) {         last = mini;       } else if (maxi >= last && maxi <= prev) {         last = maxi;       } else {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100001], v[100001], posa[100001], posv[100001], x, y;   int inx[100001];   inline void kspxa(int s, int t) {     if (s < t) {       int i = s, j = t, k = (i + j) >> 1;       int l = a[i];       a[i] = a[k];       a[k] = l;       l = posa[i];       posa[i] = posa[k];       posa[k] = l;       k = a[i];       l = posa[i];       while (i != j) {         while (i < j && a[j] > k) --j;         if (i < j) a[i] = a[j], posa[i++] = posa[j];         while (i < j && a[i] < k) ++i;         if (i < j) a[j] = a[i], posa[j--] = posa[i];       }       a[i] = k;       posa[i] = l;       kspxa(s, i - 1);       kspxa(i + 1, t);     }   }   inline void kspxv(int s, int t) {     if (s < t) {       int i = s, j = t, k = (i + j) >> 1;       int l = v[i];       v[i] = v[k];       v[k] = l;       l = posv[i];       posv[i] = posv[k];       posv[k] = l;       k = v[i];       l = posv[i];       while (i != j) {         while (i < j && v[j] > k) --j;         if (i < j) v[i] = v[j], posv[i++] = posv[j];         while (i < j && v[i] < k) ++i;         if (i < j) v[j] = v[i], posv[j--] = posv[i];       }       v[i] = k;       posv[i] = l;       kspxv(s, i - 1);       kspxv(i + 1, t);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &x, &y);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), posa[i] = i;     for (int i = 1; i <= m; i++) scanf( %d , &v[i]), posv[i] = i;     kspxa(1, n);     kspxv(1, m);     int left = 1, ans = 0;     memset(inx, 0, sizeof(inx));     for (int i = 1; i <= n; i++) {       if (left > m) break;       while (left <= m && v[left] < a[i] - x) ++left;       if (left > m) break;       if (v[left] >= a[i] - x && v[left] <= a[i] + y)         inx[posa[i]] = posv[left], ++left, ++ans;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       if (inx[i]) printf( %d %d n , i, inx[i]);   }
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &a) {     return out <<  (  << a.first <<  ,  << a.second <<  ) ;   }   template <class A>   ostream &operator<<(ostream &out, const vector<A> &a) {     for (const A &it : a) out << it <<    ;     return out;   }   template <class A, class B>   istream &operator>>(istream &in, pair<A, B> &a) {     return in >> a.first >> a.second;   }   template <class A>   istream &operator>>(istream &in, vector<A> &a) {     for (A &i : a) in >> i;     return in;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, x, y;     cin >> n >> x >> y;     string s;     cin >> s;     reverse((s).begin(), (s).end());     long long cnt = 0;     for (long long i = 0; i < x; i++) {       if ((i == x || i == y)) {         cnt += s[i] ==  0 ;       } else         cnt += s[i] ==  1 ;     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   long long a[2005];   vector<long long> Z;   vector<long long> F;   int main() {     long long n, i, S = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       S += a[i];     }     sort(a, a + n);     reverse(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] % 2 == 0)         Z.push_back(a[i]);       else         F.push_back(a[i]);     }     i = 0;     long long j = 0, k = 1, sum1 = 0, sum2 = 0;     while (1) {       if (k == 0) {         if (i >= Z.size()) break;         sum1 += Z[i];         i++;         k = 1;       } else {         if (j >= F.size()) break;         sum1 += F[j];         j++;         k = 0;       }     }     i = 0, j = 0, k = 0;     while (1) {       if (k == 0) {         if (i >= Z.size()) break;         sum2 += Z[i];         i++;         k = 1;       } else {         if (j >= F.size()) break;         sum2 += F[j];         j++;         k = 0;       }     }     long long maxi = max(sum1, sum2);     cout << S - maxi;     return 0;   }
#include <bits/stdc++.h>   long long t[105], s[105];   long long a[105];   int getNumber(long long add) {     if (add == 0)       return 1;     else {       int res = -1;       for (int i = 2; i <= 101; i++) {         long long last = i * (i - 1) * (i - 2) / 6,                   next = i * (i - 1) * (i + 1) / 6;         if ((next - last) == add) {           res = i;           break;         }       }       return res;     }   }   int main() {     int n;     scanf( %d%lld%lld , &n, &t[0], &s[0]);     for (int i = 1; i <= n; i++) {       if (i <= n - 3)         printf( + %d n , n - i);       else {         if (i == n || i == n - 2)           printf( + 1 n );         else           printf( + 2 n );       }       fflush(stdout);       scanf( %lld%lld , &t[i], &s[i]);     }     long long add = t[n] - t[n - 1];     a[1] = getNumber(add) - 1;     long long add0 = s[n] - s[n - 1], add1 = s[n - 2] - s[n - 3];     a[3] = add0 - add1 - 1;     a[2] = add1 / (a[3] + 1);     add = s[n - 1] - s[n - 2];     a[4] = (add - (a[3] + 1) * (a[1] + 1)) / (a[3] + 1) - 1;     for (int i = 5; i <= n; i++) {       long long add = s[n - i + 2] - s[n - i + 1];       a[i] = (add - a[i - 3] * a[i - 4] - a[i - 3] * (a[i - 1] + 1)) /                  (a[i - 1] + 1) -              1;     }     a[n]++;     printf( !  );     for (int i = 1; i <= n; i++) printf( %lld  , a[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long ans[100100 << 1];   long long ksm(long long p, long long q) {     long long res = 1;     while (q) {       if (q & 1) res = res * p % 1000000007;       p = p * p % 1000000007;       q >>= 1;     }     return res;   }   signed main() {     cin >> n;     ans[0] = 1;     for (long long i = 1; i <= (n << 1); i++) {       ans[i] = ans[i - 1] * i % 1000000007;     }     cout << (ans[n << 1] * ksm(ans[n] * ans[n] % 1000000007, 1000000007 - 2)) %                     1000000007 -                 n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2;   bool eq(int a1, int b1, int a2, int b2) {     if ((b1 - a1) & 1) {       while (a1 < b1) {         if (s1[a1] != s2[a2]) return 0;         ++a1;         ++a2;       }       return 1;     }     int m1 = (a1 + b1) / 2;     int m2 = (a2 + b2) / 2;     return (eq(a1, m1, a2, m2) && eq(m1, b1, m2, b2)) ||            (eq(a1, m1, m2, b2) && eq(m1, b1, a2, m2));   }   bool func() {     if (s1.length() != s2.length()) return 0;     if (eq(0, s1.length(), 0, s2.length())) {       return 1;     }   }   int main() {     cin >> s1 >> s2;     if (func())       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, k;     cin >> n >> m >> k;     vector<int> dp1(m, 0);     vector<int> pref_max(m, 0);     vector<int> suf_max(m, 0);     vector<vector<int> > a(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         a[i].push_back(x);       }     }     for (int i = 0; i < n; i++) {       vector<vector<int> > sa1(m);       vector<vector<int> > sa2(m);       for (int j = 0; j < m; j++) {         sa1[j].push_back(0);         sa2[j].push_back(0);         for (int ii = 0; ii < k; ii++) {           if (j + ii < m) {             sa1[j].push_back(sa1[j][sa1[j].size() - 1] + a[i][j + ii]);             if (i < n - 1) {               sa2[j].push_back(sa2[j][sa2[j].size() - 1] + a[i + 1][j + ii]);             } else {               sa2[j].push_back(0);             }           } else {             sa1[j].push_back(sa1[j][sa1[j].size() - 1]);             sa2[j].push_back(sa2[j][sa2[j].size() - 1]);           }         }       }       vector<int> dp2(m, -1e9);       for (int j = 0; j < m; j++) {         if (j - k >= 0) {           dp2[j] = pref_max[j - k];         }         if (j + k < m) {           dp2[j] = max(dp2[j], suf_max[j + k]);         }         for (int ii = max(0, j - k + 1); ii < min(m, j + k); ii++) {           if (ii < j) {             dp2[j] = max(dp2[j], dp1[ii] - sa1[j][k - (j - ii)]);           } else {             dp2[j] = max(dp2[j], dp1[ii] - sa1[ii][k - (ii - j)]);           }         }         if (i == 0) {           dp2[j] = sa1[j][k] + sa2[j][k];         } else {           dp2[j] += sa1[j][k] + sa2[j][k];         }       }       dp1 = dp2;       pref_max[0] = dp1[0];       for (int j = 1; j < m; j++) {         pref_max[j] = max(pref_max[j - 1], dp1[j]);       }       suf_max[m - 1] = dp1[m - 1];       for (int j = m - 2; j >= 0; j--) {         suf_max[j] = max(suf_max[j + 1], dp1[j]);       }     }     cout << pref_max[m - 1];   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     solve();     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s = s +  x ;     int dol = 0;     int cent = 0;     int td = 0;     int tc = 0;     for (int i = 0; i < s.length(); ++i) {       if (s[i] >=  a  && s[i] <=  z ) {         dol += td;         cent += tc;         td = 0;         tc = 0;         continue;       }       if (s[i] >=  0  && s[i] <=  9 ) td = td * 10 + (int)(s[i] -  0 );       if (s[i] ==  . ) {         if (s[i + 3] >=  0  && s[i + 3] <=  9 )           continue;         else           for (int j = 0; j < 2; ++j) {             ++i;             tc = tc * 10 + (int)(s[i] -  0 );           }       }     }     dol = dol + cent / 100;     cent = cent % 100;     int storecent = cent;     int dig = 0;     string sd;     string sc;     if (dol == 0 && cent > 0) {       sd =  .  + sd;       sd =  0  + sd;     }     while (dol > 0) {       if (dig == 0) sd =  .  + sd;       sd = (char)((dol % 10) +  0 ) + sd;       dol /= 10;       dig = (dig + 1) % 3;     }     while (cent > 0) {       sc = (char)((cent % 10) +  0 ) + sc;       cent /= 10;     }     if (sc.length() == 1) sc =  0  + sc;     for (int i = 0; i < sd.length() - 1; ++i) cout << sd[i];     if (storecent != 0) {       cout <<  . ;       cout << sc[0] << sc[1];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   bool v[N];   int n, m, x, y, k, q[N], t, d[N], A[N], c;   vector<int> a[N];   void D(int x) {     q[++t] = x, d[x] = t;     for (int i = 0; i < a[x].size(); i++)       if (!d[a[x][i]])         D(a[x][i]);       else if (d[x] - d[a[x][i]] + 1 >= k) {         cout << 2 <<   n  << d[x] - d[a[x][i]] + 1 <<   n ;         for (int j = d[a[x][i]]; j <= d[x]; j++) cout << q[j] <<    ;         exit(0);       }     if (!v[x]) {       A[++c] = x;       for (int i = 0; i < a[x].size(); i++) v[a[x][i]] = true;     }     t--;   }   int main() {     cin >> n >> m;     while (m-- && cin >> x >> y) a[x].push_back(y), a[y].push_back(x);     k = sqrt(n - 1) + 1, D(1);     cout << 1 <<   n ;     for (int i = 1; i <= k; i++) cout << A[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t, cur = 1, pre, s;     cin >> n >> pre;     s = n;     n--;     for (int i = 0; i < (int)(n); ++i) {       cin >> t;       if (t == pre)         cur++;       else if (t != pre && cur > 1) {         s += (cur * (cur - 1) / 2);         cur = 1;       }       pre = t;     }     if (cur > 1) s += (cur * (cur - 1) / 2);     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     string s;     cin >> s;     int n = s.size();     int ps[n + 5];     ps[0] = s[0] -  0 ;     for (int i = 1; i < n; i++) ps[i] = ps[i - 1] + s[i] -  0 ;     long long ans = 0;     for (int i = 0; i < n; i++) {       int it1 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k) - ps;       if (it1 == n) continue;       int it2 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k + 1) - 1 - ps;       ans += it2 - it1 + 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int x;   long long int k;   long long int res;   long long int curr;   long long int exponentiation(long long int base, long long int power) {     long long int ans = 1;     while (power > 0) {       if (power % 2) ans = (ans * base) % mod;       base = (base * base) % mod;       power /= 2;     }     return ans % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> x >> k;     if (x == 0) {       res = 0;     } else if (k == 0) {       res = (2 * x) % mod;     } else {       curr = (2 * x - 1 - x + mod) % mod;       res =           (x + ((((curr + x) % mod) * exponentiation(2, k)) % mod - curr) + mod) %           mod;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long N;     cin >> N;     long long frend[N + 1][N + 1];     long long i, j, k;     for (i = 1; i <= N; i++) {       for (j = 1; j <= N; j++) {         cin >> frend[i][j];       }     }     long long alex[N + 1];     long long liking[N + 1];     long long c = N + 9;     for (i = 1; i <= N; i++) {       cin >> alex[i];       liking[alex[i]] = c--;     }     for (i = 1; i <= N; i++) {       for (j = 1; j <= N; j++) {         if (frend[i][j] == i) continue;         long long mx = 0;         for (k = 1; k <= frend[i][j]; k++) {           if (k == i) continue;           mx = max(mx, liking[k]);         }         if (mx == liking[frend[i][j]]) {           cout << frend[i][j] <<    ;           break;         }       }     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int count_inversions(vector<int> v) {     int t = 0;     for (int i = 0; i < (int)v.size(); ++i)       for (int j = i + 1; j < (int)v.size(); ++j)         if (v[i] > v[j]) t++;     return t;   }   int main() {     int n;     scanf( %d , &n);     vector<int> v(n);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     int inversions = count_inversions(v);     cout << (inversions / 2) * 4 + (inversions % 2) << endl;   }
#include <bits/stdc++.h>   long long mod;   long long solve(int dep, long long idx, long long left, long long right,                   long long l, long long r, long long u, long long v) {     if (right < l) return 0;     if (left > r) return 0;     if (left >= l && right <= r) {       long long delta = (1LL << dep);       long long begin = idx, end = idx + (right - left) * delta;       if (end < u) return 0;       if (begin > v) return 0;       if (begin < u) begin = begin + (u - begin) / delta * delta;       if (begin < u) begin += delta;       if (end > v) end = end - (end - v) / delta * delta;       if (end > v) end -= delta;       if (begin > end) return 0;       long long total = (end - begin) / delta + 1;       return ((total % mod) * ((begin + end) % mod)) % mod;     }     long long delta = (1LL << dep);     long long mid = (left + right) / 2;     return (solve(dep + 1, idx, left, mid, l, r, u, v) +             solve(dep + 1, idx + delta, mid + 1, right, l, r, u, v)) %            mod;   }   int main() {     long long n;     int m;     while (scanf( %I64d%d%I64d , &n, &m, &mod) == 3) {       mod *= 2;       for (int i = 0; i < m; i++) {         long long l, r, u, v;         scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v);         printf( %I64d n , solve(0, 1, 1, n, l, r, u, v) / 2);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct _ {     ios_base::Init i;     _() {       cin.sync_with_stdio(0);       cin.tie(0);     }   } _;   const int MAXN = -1;   int n, m;   int main() {     int a, b;     cin >> a >> b;     int n = a + b + 1;     for (int i = n - a; i <= n; ++i) cout << i <<    ;     for (int i = n - a - 1; i >= 1; --i) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, s = 0;     scanf( %I64d%I64d , &a, &b);     while (b != 0) {       s = s + a / b;       c = b;       b = a % b;       a = c;     }     printf( %I64d n , s);     return 0;   }