malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #include<cmath>   using namespace std;      int main(){       long long t;       cin>>t;       while(t--){           int a,b,n;           long long ans=0;           cin>>a>>b>>n;           int ar[a+1],br[b+1],arr[2][n];           memset(ar,0,sizeof(ar));           memset(br,0,sizeof(br));           for(int i=0;i<n;i++){               cin>>arr[0][i];               ar[arr[0][i]]++;           }           for(int i=0;i<n;i++){               cin>>arr[1][i];               br[arr[1][i]]++;           }           for(int i=0;i<n-1;i++){               ans+=n-i-1 -ar[arr[0][i]]+1 -br[arr[1][i]]+1;               ar[arr[0][i]]--;               br[arr[1][i]]--;           }           cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ex[3];   char st[210];   int main() {     scanf( %d , &n);     scanf( %s , st + 1);     for (int i = 1; i <= (n); i++) {       if (st[i] ==  R ) ex[0]++;       if (st[i] ==  G ) ex[1]++;       if (st[i] ==  B ) ex[2]++;     }     if ((ex[0] > 0) + (ex[1] > 0) + (ex[2] > 0) == 3)       printf( BGR n );     else if ((ex[0] > 0) + (ex[1] > 0) + (ex[2] > 0) == 1) {       if (ex[0]) printf( R n );       if (ex[1]) printf( G n );       if (ex[2]) printf( B n );     } else {       if (ex[0] == 0) {         if (ex[1] == 1 && ex[2] == 1) printf( R n );         if (ex[1] > 1 && ex[2] > 1) printf( BGR n );         if (ex[1] == 1 && ex[2] > 1) printf( GR n );         if (ex[1] > 1 && ex[2] == 1) printf( BR n );       }       if (ex[1] == 0) {         if (ex[0] == 1 && ex[2] == 1) printf( G n );         if (ex[0] > 1 && ex[2] > 1) printf( BGR n );         if (ex[0] == 1 && ex[2] > 1) printf( GR n );         if (ex[0] > 1 && ex[2] == 1) printf( BG n );       }       if (ex[2] == 0) {         if (ex[1] == 1 && ex[0] == 1) printf( B n );         if (ex[1] > 1 && ex[0] > 1) printf( BGR n );         if (ex[1] == 1 && ex[0] > 1) printf( BG n );         if (ex[1] > 1 && ex[0] == 1) printf( BR n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100 * 3;   const int INF = 1E9;   const int base = 1E9 + 7;   void no() {     cout <<  no n ;     exit(0);   }   int a[maxn];   pair<int, int> b[maxn];   char ans[3030][3030];   int n, m;   void validate() {     vector<int> draws;     n = m;     for (int i = 0; i < n; i++)       if (a[i] & 1) draws.push_back(i);     memset(ans, 0, sizeof(ans));     for (int i = 0; i < draws.size(); i += 2) {       int x, y;       x = draws[i], y = draws[i + 1];       a[x]--, a[y]--;       ans[x][y] = ans[y][x] =  D ;     }     for (int i = 0; i < n; i++) b[i] = make_pair(a[i], i);     for (int i = 0; i < n; i++) ans[i][i] =  X ;     for (int i = 0; i < n; i++) {       sort(b + i, b + n);       reverse(b + i, b + n);       int g = b[i].second;       for (int j = n - 1; j > i; j--)         if (ans[g][b[j].second] == 0) {           char w =  W , l =  L ;           if (b[i].first > 0) {             ans[g][b[j].second] = w, ans[b[j].second][g] = l;             b[i].first -= 2;           } else {             ans[g][b[j].second] = l, ans[b[j].second][g] = w;             b[j].first -= 2;           }         }       if (b[i].first != 0) no();     }     puts( yes );     for (int i = 0; i < n; i++) puts(ans[i]);   }   int solve() {     cin >> m >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int sum = 0;     for (int i = 0; i < n; i++) sum += a[i];     if (sum > m * (m - 1)) no();     if (sum + (m - n) * a[n - 1] < m * (m - 1)) no();     while (sum < m * (m - 1))       for (int i = n; sum < m * (m - 1) && i < m; i++) a[i]++, sum++;     validate();   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   const long long mod = 1e9 + 7;   long long num[N];   long long a[N];   long long b[N];   long long ans[N];   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long T = 1;     cin >> T;     while (T--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) cin >> num[i];       a[1] = num[1] - 1, b[1] = 1;       for (long long i = 2; i <= n; i++) {         a[i] = min(a[i - 1], num[i] - b[i - 1]);         b[i] = num[i] - a[i];       }       bool flag = true;       long long ma = *min_element(a + 1, a + 1 + n);       long long mb = *min_element(b + 1, b + n + 1);       if (ma + mb < 0) flag = false;       cout << (flag ?  YES n  :  NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     scanf( %lld %lld %lld %lld , &a, &b, &c, &d);     printf( %lld %lld %lld n , b, c, c);   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long a[300005], m[300005], t[300005], ans, sum, n, x, qwq;   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i], &m[i]);       x = m[i];       while (x) {         x >>= 1ll;         t[i]++;       }       sum += a[i];     }     if (sum < 0)       for (long long i = 1; i <= n; i++) a[i] *= -1ll;     for (long long i = 0; i <= 62; i++) {       qwq = 0ll;       for (long long j = 1; j <= n; j++)         if (m[j] & (1ll << i) && t[j] - 1ll == i) qwq += a[j];       if (qwq > 0) {         for (long long j = 1; j <= n; j++)           if (m[j] & (1ll << i)) a[j] *= -1ll;         ans += (1ll << i);       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long ans[maxn << 2];   int main() {     long long n, k, m;     scanf( %lld%lld , &n, &k);     m = (n * 6 - 1) * k;     printf( %lld n , m);     for (int i = 1; i <= n; i++) {       long long tmp = 6 * (i - 1);       printf( %lld %lld %lld %lld n , (tmp + 1LL) * k, (tmp + 2LL) * k,              (tmp + 3LL) * k, (tmp + 5LL) * k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int x) {     if (x == 1) return false;     for (long long i = 2; i <= sqrt(x); i += 1)       if (x % i == 0) return false;     return true;   }   void print(int a[], int n) {     for (long long i = 0; i < n; i += 1) cout << a[i] <<    ;   }   void iarr(int *a, int n) {     for (long long i = 0; i < n; i += 1) cin >> a[i];   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007;       a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;       b >>= 1;     }     return res;   }   long long numFactors(long long x) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(x); i += 1) {       if (x % i == 0) {         if (x / i == i)           cnt += 1;         else           cnt += 2;       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed;     cout.precision(10);     ;     int n;     cin >> n;     int a[n];     iarr(a, n);     long long cnt = 0;     while (true) {       int ind = -1, mx = a[0];       for (long long i = 1; i < n; i += 1) {         if (a[i] >= mx) {           ind = i;           mx = a[i];         }       }       if (ind != -1) {         a[ind]--;         a[0]++;         cnt++;       } else if (ind == -1) {         break;       }     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int power(unsigned long long int a, unsigned long long int b,                                unsigned long long int p) {     unsigned long long int res = 1;     a = a % p;     while (b > 0) {       if (b & 1) {         res = (res * a) % p;         b--;       }       a = (a * a) % p;       b >>= 1;     }     return res;   }   unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long int n, p, k;     cin >> n >> p >> k;     vector<unsigned long long int> v(n);     for (auto &i : v) cin >> i;     map<unsigned long long int, unsigned long long int> cnt;     for (unsigned long long int i = 0; i < n; i++) {       unsigned long long int cur = (power(v[i], 4, p) - (k * v[i]) % p + p) % p;       cnt[cur]++;     }     unsigned long long int ans = 0;     for (auto i : cnt) ans += (i.second * (i.second - 1)) / 2;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const unsigned gen_seed =       std::chrono::system_clock::now().time_since_epoch().count();   std::mt19937_64 gen(gen_seed);   const int A = 500;   long long d[A + 1][A + 1];   long long fac[A + 1];   long long ifac[A + 1];   long long cfac[A + 1][A + 1];   long long cfac2[A + 1][A + 1];   long long gcd(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long invmod(long long a, long long modulo) {     long long x, y;     gcd(a, modulo, x, y);     return (x % modulo + modulo) % modulo;   }   int main() {     fac[0] = 1;     for (long long i = 1; i <= A; i++) fac[i] = (fac[i - 1] * i) % mod;     for (int i = 0; i < A + 1; i++) ifac[i] = invmod(fac[i], mod);     d[0][0] = 1;     for (int i = 0; i < A + 1; i++)       for (int j = 0; j < i + 1; j++) cfac[i][j] = fac[i] * ifac[i - j] % mod;     for (int i = 0; i < A + 1; i++)       for (int j = 0; j < i + 1; j++) cfac2[i][j] = cfac[i][j] * (j + 1) % mod;     for (int b = 0; b < A + 1; b++)       for (int a = 0; a < A + 1; a++) {         if (a == 0) {           if (b > 0) d[0][b] = (d[0][b - 1] * b) % mod;           continue;         }         for (int tb = 0; tb < b + 1; tb++) {           d[a][b] += d[a - 1][b - tb] * cfac[b][tb] % mod;         }         if (a > 1) {           long long cand = 0;           for (int tb = 0; tb < b + 1; tb++) {             cand += d[a - 2][b - tb] * cfac2[b][tb] % mod;           }           d[a][b] += cand * (a - 1);         }         d[a][b] %= mod;       }     int n;     scanf( %d , &n);     int a = 0;     int b = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x == 1)         a++;       else         b++;     }     cout << d[a][b];   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 20, LMAX = 400000, INF = ~0u >> 1;   int K, L = 1, f1[2 * LMAX], f2[LMAX], f3[LMAX];   long long A, B;   int gcd(int x, int y) {     if (!y) return x;     return gcd(y, x % y);   }   int main() {     int i, j;     scanf( %I64d %I64d %d , &B, &A, &K);     for (i = 2, L = 2; i <= K; i += 1) L = i * L / gcd(L, i);     f1[0] = f2[0] = f3[0] = 0;     if (B - A <= (long long)2 * L) {       for (i = 1; A + i - 1 != B; i += 1) {         f1[i] = f1[i - 1] + 1;         for (j = 2; j <= K; j += 1) {           if (i >= (A + i) % j) f1[i] = min(f1[i], f1[i - (A + i) % j] + 1);         }       }       printf( %d n , f1[i - 1]);     } else {       for (i = 1; i <= L && (A + i - 1) % L; i += 1) {         f1[i] = f1[i - 1] + 1;         for (j = 2; j <= K; j += 1) {           if ((long long)i >= (A + i) % j)             f1[i] = min(f1[i], f1[i - (A + i) % j] + 1);         }       }       for (i = 1; i <= L; i += 1) {         f2[i] = f2[i - 1] + 1;         for (j = 2; j <= K; j += 1) {           if (i >= i % j) f2[i] = min(f2[i], f2[i - i % j] + 1);         }       }       for (i = 1; i <= L && (i - 1) != B % L; i += 1) {         f3[i] = f3[i - 1] + 1;         for (j = 2; j <= K; j += 1) {           if (i >= i % j) f3[i] = min(f3[i], f3[i - i % j] + 1);         }       }       printf( %I64d n , f1[(A + L - 1) / L * L - A] +                             (long long)f2[L] * (B / L - (A + L - 1) / L) +                             f3[i - 1]);     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, ans = 0, t;     cin >> t;     while (t--) {       cin >> n >> k;       ans = 0;       while (n > 0) {         if (n % k == 0) {           n /= k;           ans++;         } else {           ans += n % k;           n -= n % k;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   long long p(long long n, long long k) {     long long d = 1;     while (n) {       if (n & 1) d = (d * k) % 1000000007;       k = (k * k) % 1000000007;       n >>= 1;     }     return d;   }   int main() {     long long n, l;     scanf( %I64d , &n);     l = p(n, 2);     printf( %I64d , ((l + l * l) / 2) % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using VV = vector<vector<T>>;   template <class T>   inline bool SMIN(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool SMAX(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   const string yes =  YES , no =  NO ;   int X, Y, Z, T1, T2, T3;   string solve() {     long long s = abs(X - Y) * T1;     long long e = abs(Z - X) * T2 + abs(X - Y) * T2 + 3LL * T3;     return !(s < e) ? yes : no;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> X >> Y >> Z >> T1 >> T2 >> T3;     cout << solve() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, i, j, mas[50077], fix[50077], dom, a[50077];   int main() {     cin >> n;     for (k = 1; k <= n; k++) cin >> a[k];     for (k = 1; k <= n; k++) {       dom = a[k];       for (j = 1; j <= n; j++) mas[a[j]] = 0;       for (i = k; i <= n; i++) {         mas[a[i]]++;         if (mas[a[i]] > mas[dom])           dom = a[i];         else if (a[i] < dom && mas[a[i]] == mas[dom])           dom = a[i];         fix[dom]++;       }     }     for (k = 1; k <= n; k++) cout << fix[k] <<    ;   }
#include <bits/stdc++.h>   const double pi = (double)(2.0 * acos(0.0));   const int inf = 1 << 30;   const double eps = 1E-9;   const double e = exp(1.0);   const int sz = 100000 + 5;   const int mod = 1000000000 + 7;   using namespace std;   int main() {     double x, y, z, res, v;     string st =   ;     scanf( %lf %lf %lf , &x, &y, &z);     if (x < 1.0 + eps && y < 1.0 + eps && z < 1.0 + eps) {       res = 1e18;       v = z * log(y) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  x^y^z ;       v = y * log(z) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  x^z^y ;       v = log(y) + log(z) + log(log(1.0 / x));       if (res > v + eps) res = v, st =  (x^y)^z ;       v = z * log(x) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  y^x^z ;       v = x * log(z) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  y^z^x ;       v = log(x) + log(z) + log(log(1.0 / y));       if (res > v + eps) res = v, st =  (y^x)^z ;       v = y * log(x) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  z^x^y ;       v = x * log(y) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  z^y^x ;       v = log(x) + log(y) + log(log(1.0 / z));       if (res > v + eps) res = v, st =  (z^x)^y ;       cout << st << endl;     } else {       res = -1e18;       if (x > 1.0 + eps) {         v = z * log(y) + log(log(x));         if (res + eps < v) res = v, st =  x^y^z ;         v = y * log(z) + log(log(x));         if (res + eps < v) res = v, st =  x^z^y ;         v = log(y) + log(z) + log(log(x));         if (res + eps < v) res = v, st =  (x^y)^z ;       }       if (y > 1.0 + eps) {         v = z * log(x) + log(log(y));         if (res + eps < v) res = v, st =  y^x^z ;         v = x * log(z) + log(log(y));         if (res + eps < v) res = v, st =  y^z^x ;         v = log(x) + log(z) + log(log(y));         if (res + eps < v) res = v, st =  (y^x)^z ;       }       if (z > 1.0 + eps) {         v = y * log(x) + log(log(z));         if (res + eps < v) res = v, st =  z^x^y ;         v = x * log(y) + log(log(z));         if (res + eps < v) res = v, st =  z^y^x ;         v = log(x) + log(y) + log(log(z));         if (res + eps < v) res = v, st =  (z^x)^y ;       }       cout << st << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = 0;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 )         ans += 10;       else if (s[i] ==  A )         ans += 1;       else         ans += s[i] -  0 ;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005], b[100005], difs, f, s;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (int i = 0; i < n; i++)       if (a[i] != b[i]) difs++;     if (difs > 2) {       cout <<  NO ;       return 0;     } else {       cout <<  YES ;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   const int maxn = 3e5 + 5;   const int maaxn = 1e7 + 2;   const int minn = 22;   const long long mod = 1e9 + 7;   const long double pi = 3.141592653589793238462643383279;   long long binpow(long long a, long long p) {     if (p == 0) return 0;     if (p % 2 == 1) return (a + binpow(a, p - 1)) % mod;     long long b = binpow(a, p / 2);     return (b + b) % mod;   }   int a[maxn];   vector<int> dv[maxn];   vector<int> hop[maaxn];   int cnt[maaxn];   bool sh(int &c, int &b) { return a[c] < a[b]; }   void solve() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 2; j * j <= a[i]; j++) {         if (a[i] % j == 0) {           dv[i].push_back(j);           cnt[j]++;           hop[j].push_back(i);           if (j * j != a[i])             dv[i].push_back(a[i] / j), cnt[a[i] / j]++,                 hop[a[i] / j].push_back(i);         }       }     }     for (int i = 2; i < maaxn; i++) {       if (cnt[i] >= k) {         for (int j = 0; j < k; j++) {           cout << (hop[i][j] + 1) <<    ;         }         cout << endl;         return;       }     }     int ma = 0;     int p = 0;     for (int i = 2; i < maaxn; i++) {       if (hop[i].size() > ma) {         ma = hop[i].size();         p = i;       }     }     vector<int> answ;     unordered_set<int> tv;     for (int i = 0; i < hop[p].size(); i++) tv.insert(hop[p][i]);     for (int i = 0; i < n; i++) {       if (tv.count(i) == 0) answ.push_back(i);     }     sort(answ.begin(), answ.end(), sh);     for (int i = 0; i < k; i++) cout << answ[i] + 1 <<    ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     cin >> t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int p = 1e9 + 7;   struct Matrix {     int n, m;     long long a[105][105];     Matrix(int x, int y) {       n = x, m = y;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) a[i][j] = 0;       }     }     void init() {       for (int i = 1; i <= min(n, m); i++) a[i][i] = 1;     }     void print() {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) cout << a[i][j] <<    ;         cout << endl;       }       cout << endl;     }   };   Matrix operator*(Matrix a, Matrix b) {     Matrix c = Matrix(a.n, b.m);     for (int i = 1; i <= a.n; i++) {       for (int j = 1; j <= b.m; j++) {         for (int k = 1; k <= a.m; k++) {           c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j] % p) % p;         }       }     }     return c;   }   Matrix qpow(Matrix a, long long b) {     Matrix res = Matrix(a.n, a.m);     res.init();     while (b) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long n, m, k;   int main() {     cin >> n >> m >> k;     Matrix f = Matrix(m, m);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= m; j++) f.a[i][j] = 1;     }     string s;     int x, y, z;     while (k--) {       cin >> s;       if (s[0] <=  Z  && s[0] >=  A )         x = s[0] -  A  + 27;       else         x = s[0] -  a  + 1;       if (s[1] <=  Z  && s[1] >=  A )         y = s[1] -  A  + 27;       else         y = s[1] -  a  + 1;       f.a[x][y] &= 0;     }     Matrix ans = Matrix(1, m);     for (int i = 1; i <= m; i++) ans.a[1][i] = 1;     f = qpow(f, n - 1);     ans = ans * f;     long long res = 0;     for (int i = 1; i <= m; i++) res += ans.a[1][i], res %= p;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, a[5001];     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (a[a[a[i]]] == i) {         printf( YES );         return 0;       }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   #define pb push_back   using namespace std;   typedef long long ll;      void solve()   {       int n;       cin >> n;       int adad[n];       map<int, int> cnt;       for (int i = 0; i < n; i++)       {           cin >> adad[i];           cnt[adad[i]]++;       }       int mini;       mini = *min_element(adad, adad + n);       cout << n - cnt[mini] << endl;   }      int main()   {       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       int t;       cin >> t;       while (t--)       {           solve();       }   }
#include <bits/stdc++.h>   using namespace std;   set<int> marc[100010];   int input(void) {     int x;     scanf( %d , &x);     return x;   }   int main() {     int n = input();     for (int i = 0; i < (n); i++) {       int x = input(), k = input();       if (x == 0) {         marc[k].insert(0);       } else {         if (marc[k].find(x - 1) != marc[k].end()) {           marc[k].insert(x);         } else {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Time {     long long deno, num;     inline long long gcd(long long a, long long b) {       return !b ? a : gcd(b, a % b);     }     inline void simplify() {       long long g = gcd(abs(deno), abs(num));       deno /= g;       num /= g;       if (deno < 0) {         deno *= -1;         num *= -1;       }     }     Time() {}     Time(long long n, long long d) : num(n), deno(d) { simplify(); }     inline bool operator<(const Time &t) const {       return num * t.deno < t.num * deno;     }     inline bool operator!=(const Time &t) const {       return num * t.deno != t.num * deno;     }   };   pair<Time, Time> s[100010];   pair<Time, int> ds[100010];   int d[100010];   struct BIT {     int f[100010];     BIT() { fill(f, f + 100010, 0); }     inline int lowbit(int x) { return (x & -x); }     inline void add(int p, int v) {       for (++p; p < 100010; p += lowbit(p)) f[p] += v;     }     inline int sum(int p) {       int ret = 0;       for (++p; p; p -= lowbit(p)) ret += f[p];       return ret;     }     inline int sum(int l, int r) { return sum(r) - sum(l - 1); }   } bit;   int n, w;   long long v, x;   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       cin >> x >> v;       s[i] = make_pair(Time(-x, v - w), Time(-x, v + w));     }     for (int i = 0; i < n; i++) s[i].second.num *= -1;     sort(s, s + n);     for (int i = 0; i < n; i++) s[i].second.num *= -1;     for (int i = 0; i < n; i++) ds[i] = make_pair(s[i].second, i);     sort(ds, ds + n);     for (int i = 0, rk = -1; i < n; i++) {       if (!i || ds[i].first != ds[i - 1].first) rk++;       d[ds[i].second] = rk;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ans += bit.sum(d[i], 100010 - 1);       bit.add(d[i], 1);     }     cout << ans << endl;     return 0;   }