malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, c, a, b;   int main() {     scanf( %d , &n);     while (n--) {       scanf( %d%d , &a, &b);       if (a != b)         if (a > b)           m++;         else           c++;     }     if (m != c)       if (m > c)         printf( Mishka );       else         printf( Chris );     else       printf( Friendship is magic!^^ );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     stringstream ss;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       switch (s[i]) {         case  > :           ss << 1000;           break;         case  < :           ss << 1001;           break;         case  + :           ss << 1010;           break;         case  - :           ss << 1011;           break;         case  . :           ss << 1100;           break;         case  , :           ss << 1101;           break;         case  [ :           ss << 1110;           break;         case  ] :           ss << 1111;           break;         default:           break;       }     }     string ans = ss.str();     int os = 1;     long long jawab = 0;     for (int i = ans.length() - 1; i >= 0; i--) {       if (ans[i] ==  1 ) jawab = (jawab + os) % 1000003;       os = (os * 2) % 1000003;     }     cout << jawab << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-9;   const int MOD = 1000000007;   const int INF = 1000000000;   const long long LINF = 1000000000000000000LL;   int main() {     int r, h, ret, m, x;     scanf( %d %d , &r, &h);     r *= 2, h *= 2, ret = h / r * 2, m = h % r, x = m + r / 2;     if (m >= r / 2) ret += 2, x -= r;     if ((0.5 * r * (sqrt(3.0) + 1.0) - 1.0 * x - 1.0 * r) < EPS) ret++;     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct ask {     int l, r, cur;   } tmp;   long long pre[maxn], suf[maxn], s[maxn], d[maxn], h[maxn], ans[maxn];   vector<ask> V, W;   int n, m, a, b;   long long solve(int l, int r, vector<ask> &V) {     if (l == r) return 0;     int mid = (l + r) >> 1;     long long best;     vector<ask> Vl, Vr, Vt;     pre[mid] = 0;     for (int i = (mid + 1); i <= int(r); i++)       pre[i] = max(pre[i - 1], s[i] - s[mid] + 2 * h[i]);     suf[mid + 1] = 0;     for (int i = (mid); i >= (l); i--)       suf[i] = max(suf[i + 1], s[mid] - s[i] + 2 * h[i]);     for (auto x : V)       if (x.r <= mid)         Vl.push_back(x);       else if (mid + 1 <= x.l)         Vr.push_back(x);       else if (l != x.l || r != x.r) {         ans[x.cur] = max(ans[x.cur], suf[x.l] + pre[x.r]);         Vl.push_back((ask){x.l, mid, x.cur});         Vr.push_back((ask){mid + 1, x.r, x.cur});       }     best = pre[r] + suf[l];     best = max(best, solve(l, mid, Vl));     best = max(best, solve(mid + 1, r, Vr));     for (auto x : V)       if (l == x.l && r == x.r) ans[x.cur] = max(ans[x.cur], best);     return best;   }   void solve2() {     pre[0] = 0;     for (int i = (1); i <= int(n); i++)       pre[i] = max(pre[i - 1], s[i] - s[1] + 2 * h[i]);     suf[n + 1] = 0;     for (int i = (n); i >= (1); i--)       suf[i] = max(suf[i + 1], s[n + 1] - s[i] + 2 * h[i]);     for (auto x : W) ans[x.cur] = max(ans[x.cur], pre[x.l] + suf[x.r]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= int(n); i++)       scanf( %I64d , &d[i]), s[i + 1] = s[i] + d[i];     for (int i = (1); i <= int(n); i++) scanf( %I64d , &h[i]);     for (int i = (1); i <= int(m); i++) {       scanf( %d%d , &a, &b);       if (a <= b) {         if (3 <= a) V.push_back((ask){1, a - 1, i});         if (b <= n - 2) V.push_back((ask){b + 1, n, i});         if (2 <= a && b <= n - 1) W.push_back((ask){a - 1, b + 1, i});       } else         V.push_back((ask){b + 1, a - 1, i});     }     solve(1, n, V);     solve2();     for (int i = (1); i <= int(m); i++) printf( %I64d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   #define int long long   #define ld long double   #define vc vector   #define s second   #define f first         //#include  prettyprint.hpp       using namespace std;         typedef pair <int, int> pii;   int n, m;   int t(int a){       return a+n;   }   int mod=998244353;   vc< vc <int> > anz, suf, pref;      bool g (int a, int b){       if (a<0 || b<0) return false;       if (a >n || b >=m) return false;       return true;   }      int h (int a, int b){       if (a<0 || a>n) return 1;       return 0;   }      int an(int a ,int b){       return g(a, b)? anz[a][b] : h(a, b);   }      int su(int a ,int b){       return g(a, b)? suf[a][b] : h(a, b);   }      int pre(int a ,int b){       return g(a, b)? pref[a][b] : h(a, b);   }   int plu (int & a, int b){       return a =(a+b)%mod;   }      int mult (int a, int b){       return a*b % mod;   }      int calc_inst(int i, int j){       int s1 = mult(mult(an(i, j), an(n-i+1, j-1)), su(n-i, m-j));          int s2 = mult(mult(an(i, j), an(i+1, m-j-1)), pre(i, m-j+1));          return plu(s1, s2);      }   int do_calc(){       anz = suf = pref = vc <vc <int> > (n+1, vc <int > (m+1));          vc <vc <int > > b (n+1, vc <int> (m)), c (n+1, vc <int> (m));          anz[0][0] = 1;             for (int i=1; i<=n; i++){          anz[i][0] = anz[i-1][0];           for (int j=1; j<m; j++){               anz[i][j] = (anz[i][j-1]+anz[i-1][j])%mod;           }       }       for (int i=1; i<=n; i++){           for (int j=1; j<m; j++){               b[i][j] = anz[i][j]*anz[n-i+1][j-1] % mod;               suf[i][j] = (suf[i-1][j]+b[i][j])%mod;           }          }             for (int i=1; i<n; i++){           for (int k=m-1; k>=2; k--){               c[i][k] = anz[n-i][k]*anz[n-i+1][m-k-1]%mod;               pref[i][k]=(pref[i][k+1]+c[i][k])%mod;           }          }                int ret = 0;       for (int i=1; i<=n; i++){           for (int j=1; j<m; j++){               plu(ret, calc_inst(i, j));           }       }       return ret;      }      void do_test(){             cin >> n >> m;       int res= do_calc();       //a1 = very_balanced();      // cout << res <<   n ;       //swap(n, m);     //  a2 = very_balanced();      // res1=do_calc();       //assert(a1 == a2);   //a1 = (n-1)*(m-1);          res = 2*res%mod;         // cout <<  res1   << res1 <<     << res2 <<   a   << a1 <<      << a2 <<     << endl;          cout << res <<   n ;          //cout << a << endl;      }   signed main(){       ios_base::sync_with_stdio(false);             do_test();   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());   int a[105], vis[105];   vector<int> v[105];   int main() {     int n;     cin >> n;     for (int i = 1; i <= 2 * n; ++i) cin >> a[i];     int ans = 0;     for (int i = 1; i <= 2 * n; ++i) {       if (vis[a[i]]) continue;       vis[a[i]] = 1;       for (int j = i + 1; a[j] != a[i]; ++j)         if (!vis[a[j]]) ++ans;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   const double PI = acos(-1.0);   const int maxn = 1e6;   const int INF = 0x3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   using namespace std;   struct node {     int a, b, color;   } edge[maxn];   int n, m, ans;   int vis[maxn];   vector<int> v[maxn];   void dfs(int x, int fa) {     if (vis[x]) {       if (x == fa) ans = 2;       return;     }     vis[x] = 1;     for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], fa);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[i].a = a;       edge[i].b = b;       edge[i].color = 1;       v[a].push_back(b);     }     ans = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) vis[j] = 0;       dfs(i, i);     }     cout << ans << endl;     if (ans == 1) {       for (int i = 0; i < m; i++) cout << 1 <<    ;       cout << endl;     } else {       for (int i = 1; i <= m; i++) {         if (edge[i].a < edge[i].b) edge[i].color = 2;       }       for (int i = 1; i <= m; i++) cout << edge[i].color <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > q1, q2;   int x[200005];   int main() {     int n, z, ans = 0;     cin >> n >> z;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int l1 = n >> 1;     for (int i = 0; i < l1; i++) q1.push(x[i]);     for (int i = l1; i < n; i++) q2.push(x[i]);     while (!q2.empty()) {       if (!q1.empty() && q2.top() - q1.top() >= z) {         ans++;         q1.pop();         q2.pop();       } else {         q1.push(q2.top());         q2.pop();       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int a[100000];   int base = int(1e9 + 7);   int lucky[2000];   long long co[2000];   long long f[2000][2000];   long long unlucky;   long long frac[100001];   long long c[100001];   int size = 1100;   int r1, r2;   int getBit(int, int);   void create();   int find(int);   long long inpow(long long, long long);   void calCombination();   void dp();   int main() {     cin >> n >> k;     create();     for (int i = 0; i < n; i++) {       fscanf(stdin,  %d , &a[i]);       int pos = find(a[i]);       if (pos != -1) {         co[pos]++;       } else         unlucky++;     }     calCombination();     dp();     long long res = 0;     f[m - 1][0] = 1;     for (int j = 0; j <= k; j++) {       res = (res + f[m - 1][j] * c[k - j]) % base;     }     cout << res << endl;     return 0;   }   int getBit(int x, int i) { return ((x & (1 << i)) != 0); }   void create() {     m = 0;     for (int ndig = 1; ndig <= 9; ndig++)       for (int i = 0; i < (1 << ndig); i++) {         int cur = 0;         for (int j = ndig - 1; j >= 0; j--)           if (getBit(i, j) == 0)             cur = cur * 10 + 4;           else             cur = cur * 10 + 7;         lucky[m++] = cur;       }   }   int find(int x) {     int lo, hi;     lo = 0;     hi = m - 1;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (x == lucky[mid]) return mid;       if (x < lucky[mid])         hi = mid - 1;       else         lo = mid + 1;     }     return -1;   }   long long inpow(long long x, long long p) {     if (p == 1) return x % base;     if (p % 2 == 0) {       long long t = inpow(x, p / 2);       return (t * t) % base;     } else       return (x * inpow(x, p - 1)) % base;   }   void calCombination() {     frac[0] = 1;     for (int i = 1; i <= unlucky; i++) frac[i] = (frac[i - 1] * i) % base;     c[0] = 1;     c[1] = unlucky;     for (long long i = 2; i <= unlucky; i++) {       c[i] =           frac[unlucky] * inpow((frac[i] * frac[unlucky - i]) % base, base - 2);       c[i] = c[i] % base;     }   }   void dp() {     for (int i = 0; i < m; i++) f[i][0] = 1;     f[0][1] = co[0];     for (int i = 1; i < m; i++)       for (int j = 1; j <= (i + 1); j++)         f[i][j] = (f[i - 1][j - 1] * co[i] + f[i - 1][j]) % base;   }
#include <bits/stdc++.h>   using namespace std;   long long a[101];   long long vis[101];   long long judge(vector<long long> A) {     if (A.empty()) return 0;     for (long long i = 0; i < A.size(); i++) {       if (A[i] != i) return i;     }     return A.size();   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       memset(vis, 0, sizeof vis);       vector<long long> A, B;       vis[1] = 1;       A.push_back(a[1]);       for (long long i = 2; i <= n; i++) {         if (a[i] != a[i - 1]) {           vis[i] = 1;           A.push_back(a[i]);         }       }       for (long long i = 1; i <= n; i++) {         if (!vis[i]) {           B.push_back(a[i]);         }       }       B.erase(unique(B.begin(), B.end()), B.end());       cout << judge(A) + judge(B) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 10;   int n, m;   int px[] = {0, 1, -1, 0};   int py[] = {1, 0, 0, -1};   bool dig[10];   char a[N][N];   bool inside(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }   bool alone(int x, int y) {     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  . ) return false;     }     return true;   }   void go(int x, int y) {     a[x][y] =  * ;     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  X ) go(x2, y2);       if (isdigit(a[x2][y2])) dig[a[x2][y2] -  0 ] = 1;     }   }   char getColor(int x, int y) {     memset(dig, 0, sizeof(dig));     go(x, y);     int i;     for (i = 0; i < 10; i++)       if (dig[i] == 0) return  0  + i;     assert(false);   }   void fill(int x, int y, char c) {     a[x][y] = c;     int k, x2, y2;     for (k = 0; k < 4; k++) {       x2 = x + px[k];       y2 = y + py[k];       if (!inside(x2, y2)) continue;       if (a[x2][y2] ==  * ) fill(x2, y2, c);     }   }   void print() {     int i;     for (i = 0; i < n; i++) printf( %s n , a[i]);     printf(  n n );   }   int main() {     scanf( %d%d , &n, &m);     int i, j, k, t;     for (i = 0; i < n; i++) scanf( %s , a[i]);     int x[3], y[3];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (a[i][j] !=  . ) continue;         x[0] = i;         y[0] = j;         for (k = 0; k < 2; k++) {           x[1] = x[0] + px[k];           y[1] = y[0] + py[k];           if (!inside(x[1], y[1])) continue;           if (a[x[1]][y[1]] ==  . ) break;         }         if (k == 2) {           printf( -1 n );           return 0;         }         a[x[0]][y[0]] =  X ;         a[x[1]][y[1]] =  X ;         for (t = 0; t < 2; t++) {           for (k = 0; k < 4; k++) {             x[2] = x[t] + px[k];             y[2] = y[t] + py[k];             if (!inside(x[2], y[2])) continue;             if (a[x[2]][y[2]] !=  . ) continue;             if (alone(x[2], y[2])) a[x[2]][y[2]] =  X ;           }         }         fill(x[0], y[0], getColor(x[0], y[0]));       }     for (i = 0; i < n; i++) printf( %s n , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000009];   int pre[10000009];   vector<long long> alr;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     long long ans = 0, ans1 = 0;     int taken = 0;     for (int i = 0; i < n; i++) {       pre[a[i]]++;     }     for (int i = 0; i < n; i++) {       if (pre[a[i]] % 2 == 1) {         if (pre[a[i] - 1] > 0)           pre[a[i]]--, pre[a[i] - 1]++;         else           pre[a[i]]--;       }     }     int x = 0, y = 0, l = 0, r = 2;     while (l < n && r < n) {       if (pre[a[l]] >= 2 && pre[a[r]] >= 2) {         if (a[l] == a[r] && pre[a[r]] < 4) {           r++;           continue;         }         pre[a[l]] -= 2;         pre[a[r]] -= 2;         ans += a[l] * a[r];       } else if (pre[a[r]] < 2 && pre[a[l]] >= 2)         r++;       else if (pre[a[r]] >= 2 && pre[a[l]] < 2)         l++;       else if (pre[a[r]] < 2 && pre[a[l]] < 2)         l++, r++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   template <class T>   inline void relaxMin(T &a, T b) {     a = min(a, b);   }   template <class T>   inline void relaxMax(T &a, T b) {     a = max(a, b);   }   string str(int i) {     char s[100];     sprintf(s,  %d , i);     return string(s);   }   inline int sign(int x) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }   inline int myAbs(int a) { return a > 0 ? a : -a; }   const int mlen = (int)2e5 + 10;   int n;   char s[mlen];   int main() {     gets(s);     n = strlen(s);     int i = 0;     while (i < n && s[i] <= 32) i++;     while (i < n) {       char ch = s[i];       int l;       if (ch ==  , )         l = 1;       else if (ch ==  . )         l = 3;       else         l = n;       while (l > 0 && i < n && isdigit(ch) == isdigit(s[i])) putchar(s[i++]), l--;       while (i < n && s[i] <= 32) i++;       if (i < n && (ch ==  ,  || s[i] ==  .  || (isdigit(ch) && isdigit(s[i]))))         putchar(   );     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ex[100];   int att[100];   int de[100];   int jo[100];   int n, m, n1, n2;   int ae() {     int ina = 0;     int inb = 0;     pair<int, bool> mi[200];     for (int i = 0; i < n1; i++) mi[i].first = att[i], mi[i].second = 0;     for (int i = n1; i < n1 + m; i++) {       mi[i].first = jo[i - n1], mi[i].second = 1;     }     sort(mi, mi + m + n1);     int v = 0;     int y = 0;     for (int i = 0; i < n1 + m; i++) {       if (mi[i].second == 0)         v++;       else if (v) {         v--;         y++;       }     }     int v1 = 0;     int vt = 0;     for (int i = 0; i < y; i++) {       vt = jo[m - i - 1] - att[i];       if (vt > 0) v1 += vt;     }     return v1;   }   bool di() {     int in1 = 0;     int in2 = 0;     while (true) {       if (in2 == n2) return true;       if (in1 == m) return false;       while (jo[in1++] <= de[in2]) {         if (in1 == m) return false;       }       in1--;       ex[in1] = 1;       in1++, in2++;     }   }   bool di2() {     int in1 = 0;     int in2 = 0;     while (true) {       if (in2 == n1) return true;       if (in1 == m) return false;       while (ex[in1++] == 1)         ;       in1--;       if (in1 == m) return 0;       while (jo[in1++] < att[in2]) {         if (in1 == m) return false;       }       in1--;       in1++, in2++;     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       int t;       cin >> s >> t;       if (s[0] ==  A ) {         att[n1++] = t;       } else {         de[n2++] = t;       }     }     for (int i = 0; i < m; i++) cin >> jo[i];     sort(jo, jo + m);     sort(de, de + n2);     sort(att, att + n1);     int m1 = 0;     if (di() && di2()) {       for (int i = 0; i < m; i++)         if (!(ex[i] == 1)) m1 += jo[i];       for (int i = 0; i < n1; i++) m1 -= att[i];     }     cout << max(m1, ae());     return 0;   }
#include <bits/stdc++.h>   int a[100];   int main() {     int n;     scanf( %d%d%d , &a[0], &a[1], &n);     for (int i = 2; i <= n; i++) {       a[i] = a[i - 1] + a[i - 2];     }     printf( %d n , a[n]);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 100;   class Node {    public:     int l, r;     bool operator<(const Node &a) const { return r < a.r; }   };   Node n[maxn];   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d%d , &n[i].l, &n[i].r);     sort(n, n + N);     int ans = 1, ps = 0;     for (int i = 1; i < N; i++)       if (n[i].l > n[ps].r) {         ans++;         ps = i;       }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[210][210], n, m, s[110];   bool dop(int x, int y) { return (x >= 0 && y >= 0 && x < 2 * n && y < 2 * m); }   void dfs(int x, int y, int cur) {     s[cur]++;     a[x][y] = cur;     if (dop(x + 2, y) && a[x + 1][y] != -1 && a[x + 2][y] != cur) {       dfs(x + 2, y, cur);     }     if (dop(x - 2, y) && a[x - 1][y] != -1 && a[x - 2][y] != cur) {       dfs(x - 2, y, cur);     }     if (dop(x, y + 2) && a[x][y + 1] != -1 && a[x][y + 2] != cur) {       dfs(x, y + 2, cur);     }     if (dop(x, y - 2) && a[x][y - 1] != -1 && a[x][y - 2] != cur) {       dfs(x, y - 2, cur);     }   }   void qsort(int first, int last) {     int i = first, j = last, x = s[(i + j) / 2];     do {       while (s[i] < x) {         i++;       }       while (s[j] > x) {         j--;       }       if (i <= j) {         if (i != j) {           swap(s[i], s[j]);         }         i++;         j--;       }     } while (i <= j);     if (i < last) {       qsort(i, last);     }     if (j > first) {       qsort(first, j);     }   }   int main() {     int x1, x2, y1, y2, t, i, j;     cin >> n >> m >> t;     for (i = 0; i < n * 2; i++) {       for (j = 0; j < m * 2; j++) {         a[i][j] = 0;       }     }     for (i = 0; i < t; i++) {       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2) {         if (y1 > y2) {           swap(y1, y2);         }         for (j = y1 * 2; j < y2 * 2; j++) {           a[x1 * 2][j] = -1;         }       } else {         if (x1 > x2) {           swap(x1, x2);         }         for (j = x1 * 2; j < x2 * 2; j++) {           a[j][y1 * 2] = -1;         }       }     }     for (i = 0; i < 100; i++) {       s[i] = 0;     }     int curcol = 1;     for (i = 1; i < 2 * n; i += 2) {       for (j = 1; j < 2 * m; j += 2) {         if (a[i][j] == 0) {           dfs(i, j, curcol);           curcol++;         }       }     }     qsort(1, curcol - 1);     for (i = 1; i < curcol; i++) {       cout << s[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400005;   int N;   long long T;   long long A[MAXN];   long long pre[MAXN];   map<long long, int> mp;   int BIT[MAXN];   void add(int idx) {     for (; idx < MAXN; idx += idx & -idx) BIT[idx]++;   }   int get(int idx) {     int ret = 0;     for (; idx > 0; idx -= idx & -idx) ret += BIT[idx];     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin >> N >> T;     mp[-T] = 1;     mp[0] = 1;     for (int i = 1; i <= N; i++) {       cin >> A[i];       pre[i] = pre[i - 1] + A[i];       mp[pre[i] - T] = 1;       mp[pre[i]] = 1;     }     int ind = 0;     for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++)       it->second = ++ind;     long long ans = 0;     add(mp[0]);     for (int i = 1; i <= N; i++) {       ans += i - get(mp[pre[i] - T]);       add(mp[pre[i]]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, n, r;     cin >> t;     while (t--) {       cin >> n >> r;       vector<long long> v(n);       set<long long> s;       for (int i = 0; i < n; i++) {         cin >> v[i];         s.insert(v[i]);       }       vector<long long> a;       for (auto i : s) {         a.push_back(i);       }       int co = 0;       long long cur = 0;       for (int i = a.size() - 1; i >= 0; i--) {         if (a[i] - cur > 0) {           a[i] = 0;           co++;           cur += r;         } else           break;       }       cout << co << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000];   bool b[100000];   int c[3][100000 / 3];   int main() {     int n;     while (cin >> n) {       memset(a, 0, sizeof(a));       memset(b, true, sizeof(b));       bool flag = true;       int sum1 = 0;       int sum2, sum3;       sum2 = sum3 = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 5 || a[i] == 7) flag = false;         if (a[i] == 1) sum1++;         if (a[i] == 2 || a[i] == 3) sum2++;         if (a[i] == 4 || a[i] == 6) sum3++;       }       if (sum1 != n / 3 || sum2 != n / 3 || sum3 != n / 3) flag = false;       if (!flag)         cout <<  -1  << endl;       else {         sort(a, a + n);         for (int i = 0; i < n / 3; i++) {           c[0][i] = a[i];           c[1][i] = a[i + n / 3];           c[2][i] = a[i + 2 * n / 3];           if (c[1][i] == 3 && c[2][i] == 4) flag = false;         }         if (flag) {           for (int i = 0; i < n / 3; i++)             cout << c[0][i] <<     << c[1][i] <<      << c[2][i] << endl;         } else           cout <<  -1  << endl;       }     }     return 0;   }