malteklaes/cpp-code-code_search_net-style huggingface dataset:
//...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE...    #include <bits/stdc++.h>   using namespace std;   #define FAST_FURIER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define pb push_back   #define mk make_pair   #define rep(i,a,N) for(ll i=a;i<N;i++)   #define rrep(i,a,N) for(ll i=a;i>N;i--)   typedef long long ll;   #define M 1000000007   bool comp(int x,int y)   {       return x > y;   }           /*..............................code starts here........................*/   // C is first won in M           int main() {       FAST_FURIER;       int tt=1;       cin >> tt;       ll m,d,k;      //ll a,b,c;       while(tt--)       {           cin >> d >> k;           ll x = 0,y = 0;           int f = 0;           while(true){               ll d1 = pow(x+k,2)+pow(y,2), d2 = pow(x,2)+pow(y+k,2);               f = abs(f-1);               if(d1 < d2 and d1 <= d*d){                   x += k;               }               else if(d2 <= d1 and d2 <= d*d) y += k;               else break;           }           if(f) cout <<  Utkarsh ;           else cout <<  Ashish ;           cout << endl;          }   }               // Author : shivam_123       // g++ -std=c++17
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, e[200000], mix, l, r, o, d[200000];   vector<long long> v[100000], v1;   set<long long> st;   map<long long, long long> mp, mp1;   string s;   pair<int, int> p[100000], p1[100000];   char ch[10];   deque<char> dq;   int main() {     cin >> a;     for (int i = 0; i < a / 4; i++)       if ((a - 2 * (i + 1)) % 2 == 0) c++;     if (a % 4 == 0) {       cout << c - 1;     } else       cout << c;   }
#include <bits/stdc++.h>   using namespace std;   char s[5000005];   int len[1000005];   int idx[1000005];   int sum[1000005];   int sz = 0;   int dp[1000005][20];   int p[1000005];   int main() {     int n, r, c;     scanf( %d%d%d , &n, &r, &c);     gets(s);     gets(s);     int cnt = 0, slen = 0;     for (int i = 0; s[i]; i++, slen++) {       if (s[i] ==     && cnt != 0) {         len[sz] = cnt;         idx[sz++] = i - cnt;         cnt = 0;       } else         cnt++;     }     if (cnt > 0) {       len[sz] = cnt;       idx[sz++] = slen - cnt;       cnt = 0;     }     sum[0] = len[0];     for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + 1 + len[i];     for (int i = n - 1; i >= 0; i--) {       int id = upper_bound(sum, sum + n, (i > 0 ? sum[i - 1] + 1 : 0) + c) - sum;       if (id > n) id = n;       dp[i][0] = id - i;     }     for (int j = 2, t = 1; j <= r; j *= 2, t++) {       for (int i = n - 1; i >= 0; i--)         dp[i][t] = dp[i][t - 1] + dp[i + dp[i][t - 1]][t - 1];     }     int maid = -1, ma = 0;     for (int i = 0; i < n; i++) {       int idx = i, rr = r, cur = 0;       for (int j = 20; j >= 0; j--) {         if (rr >= (1 << j)) {           rr -= (1 << j);           cur += dp[idx][j];           idx += dp[idx][j];         }       }       if (cur > ma) maid = i, ma = cur;     }     int cn = 1, cs = dp[maid][0];     for (int i = maid; i < maid + ma; i++) {       s[idx[i] + len[i]] = 0;       if (cn < cs) {         printf( %s  , s + idx[i]);         cn++;       } else {         printf( %s n , s + idx[i]);         cs = dp[i + 1][0];         cn = 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char change(char curranswer) {     if (curranswer ==  z )       curranswer =  A ;     else if (curranswer ==  Z )       curranswer =  0 ;     else if (curranswer ==  9 )       ;     else       curranswer++;     return curranswer;   }   int main() {     long long i, j, t;     cin >> t;     while (t--) {       long long r, c, k;       long long rice = 0;       char a[100][100];       cin >> r >> c >> k;       for (i = 0; i < r; i++) {         for (j = 0; j < c; j++) {           cin >> a[i][j];           if (a[i][j] ==  R ) rice++;         }       }       long long ans = rice / k;       long long maxx = rice - k * ans;       long long minn = k - maxx;       char curranswer =  a ;       long long currcount = 0;       bool flag = true;       for (i = 0; i < r; i++) {         for (flag ? (j = 0) : (j = c - 1); flag ? (j < c) : j >= 0;              flag ? j++ : j--) {           bool local = false;           if (a[i][j] ==  R ) local = true;           a[i][j] = curranswer;           if (local) {             currcount++;             if (maxx > 0) {               if (currcount == ans + 1) {                 maxx--;                 currcount = 0;                 curranswer = change(curranswer);               }             } else if (minn > 0) {               if (currcount == ans) {                 minn--;                 currcount = 0;                 if (minn) curranswer = change(curranswer);               }             }           }         }         flag = !flag;       }       for (i = 0; i < r; i++) {         for (j = 0; j < c; j++) cout << a[i][j];         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m) {     long long r = 1;     while (m > 0) {       if (m % 2) r = (r * n) % 1000000009;       n = (n * n) % 1000000009;       m = m / 2;     }     return r % 1000000009;   }   long long lx = 0, ly = 0;   bool check(long long x, long long y) {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long a, b;     cin >> a >> b;     string s;     cin >> s;     long long p = 0, q = 0;     if (a == 0 && b == 0) {       cout <<  Yes ;       return 0;     }     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  U ) {         ly++;       } else if (s[i] ==  D )         ly--;       else if (s[i] ==  L )         lx--;       else         lx++;       if (lx == a && ly == b) {         cout <<  Yes ;         return 0;       }     }     if (lx == 0 && ly == 0) {       cout <<  No ;       return 0;     }     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  U ) {         q++;       } else if (s[i] ==  D )         q--;       else if (s[i] ==  L )         p--;       else         p++;       long long x = a - p, y = b - q, X = lx, Y = ly;       if (lx == 0) {         if (ly > 0 && y > 0 && x == 0 && y % ly == 0) {           cout <<  Yes ;           return 0;         } else if (ly < 0 && y < 0 && x == 0) {           ly = -1 * ly, y = -1 * y;           if (y % ly == 0) {             cout <<  Yes ;             return 0;           }         }       } else if (ly == 0) {         if (lx > 0 && x > 0 && y == 0 && x % lx == 0) {           cout <<  Yes ;           return 0;         } else if (lx < 0 && x < 0 && y == 0) {           lx = -1 * lx, x = -1 * x;           if (x % lx == 0) {             cout <<  Yes ;             return 0;           }         }       } else {         if (lx > 0 && x > 0) {           if (ly > 0 && y > 0) {             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           } else if (ly < 0 && y < 0) {             ly = -1 * ly, y = -1 * y;             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           }         } else if (lx < 0 && x < 0) {           lx = -1 * lx, x = -1 * x;           if (ly > 0 && y > 0) {             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           } else if (ly < 0 && y < 0) {             ly = -1 * ly, y = -1 * y;             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           }         }       }       lx = X, ly = Y;     }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(3e5), mod = int(1e9) + 7;   int n;   int a[N], c[N];   long long t[N];   long long x[N], pref[N];   long double p[N];   long long suf[N];   void upd(int v, int val) {     v += n - 1;     t[v] += val;     c[v]++;     while (v > 1) {       v >>= 1;       t[v] = t[v + v] + t[v + v + 1];       c[v] = c[v + v] + c[v + v + 1];     }   }   long long get(int l, int r) {     l += n - 1;     r += n - 1;     long long res = 0;     while (l <= r) {       if (l & 1) res += t[l];       if (!(r & 1)) res += t[r];       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     return res;   }   int cnt(int l, int r) {     l += n - 1;     r += n - 1;     int res = 0;     while (l <= r) {       if (l & 1) res += c[l];       if (!(r & 1)) res += c[r];       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     long long all = 1ll * n * (n + 1) / 2;     long double res = 0;     for (int i = 1; i <= n; i++) {       long long cur = get(1, a[i] - 1);       long double p = (cur + 0.0) * (n - i + 1) / all;       res += p * 0.5;       cur = get(a[i] + 1, n);       p = (cur + 0.0) * (n - i + 1) / all;       res += cnt(a[i] + 1, n);       res -= p * 0.5;       upd(a[i], i);     }     printf( %.12lf , double(res));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     long long ans = 0;     while (true) {       long long x = max(a, b);       long long y = min(a, b);       if (x == 0 || y == 0) break;       long long n = x / y;       ans += n;       x -= n * y;       a = x;       b = y;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x, test;     cin >> test;     while (test--) {       int n, c0, c1, h;       string s;       cin >> n >> c0 >> c1 >> h >> s;       int cnt0 = 0, cnt1 = 0;       for (auto &z : s) {         cnt0 += z ==  0 ;         cnt1 += z ==  1 ;       }       int cost = (cnt0 * c0) + (cnt1 * c1);       int cost0 = (c0 * n) + (cnt1 * h);       int cost1 = (c1 * n) + (cnt0 * h);       cout << min({cost, cost0, cost1}) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 123;   int main() {     int n, v;     cin >> n >> v;     vector<int> a;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     int sum = 0;     for (int i = 0; i < a.size() - 1; i++) {       sum += a[i];     }     if (sum <= v) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string vow =  aeiou ;   long long month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const long long dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const long long dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const long long dx4[] = {-1, 0, 1, 0};   const long long dy4[] = {0, 1, 0, -1};   const long long dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};   const long long dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const long double pie = 3.1415926535897932384626;   const long long special_prime = 982451653l;   const long long mod = 1e9 + 7;   const long long inf = 2e18;   template <class T>   istream &operator>>(istream &in, vector<T> &a) {     for (auto &i : a) cin >> i;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &a) {     for (auto &i : a) cout << i <<    ;     return out;   }   template <class T, class U>   ostream &operator<<(ostream &out, const map<T, U> &a) {     for (auto &i : a) cout <<  (  << i.first <<  ,   << i.second <<  ) n ;     return out;   }   template <class T, class U>   ostream &operator<<(ostream &out, const unordered_map<T, U> &a) {     for (auto &i : a) cout <<  (  << i.first <<  ,   << i.second <<  ) n ;     return out;   }   long long GCD(long long a, long long b) {     if (!b) return a;     return GCD(b, a % b);   }   long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }   bool comp(long long a, long long b) { return a > b; }   void sieve(vector<long long> &prime) {     prime[0] = false;     prime[1] = false;     for (long long p = 2; p * p <= 99999; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= 99999; i += p) prime[i] = false;       }     }   }   void solve() {     long long n, g, b;     cin >> n >> g >> b;     long long d = n / 2 + n % 2;     if (d % g)       cout << max(n, (d / g) * (g + b) + d % g) <<   n ;     else       cout << max((d / g) * (g + b) - b, n) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     cout << setprecision(15) << fixed;     for (long long i = 1; i <= t; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   const int N = (int)1e6 + 6;   int f[30][N];   int pref[30][N];   int lp[N];   void precalc() {     pref[0][0] = f[0][0] = 1;     for (int i = 1; i < 30; i++) {       f[i][0] = 2;       pref[i][0] = f[i][0] + pref[i - 1][0];       pref[i][0] -= pref[i][0] >= mod ? mod : 0;     }     for (int level = 1; level < N; level++) {       pref[0][level] = f[0][level] = 1;       for (int pw = 1; pw < 30; pw++) {         f[pw][level] = pref[pw][level - 1];         pref[pw][level] = f[pw][level] + pref[pw - 1][level];         pref[pw][level] -= pref[pw][level] >= mod ? mod : 0;       }     }     for (int i = 2; i < N; i++) {       if (lp[i]) continue;       for (int j = i; j < N; j += i) {         lp[j] = lp[j] ? lp[j] : i;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     precalc();     int T;     scanf( %d , &T);     while (T--) {       int r, n;       scanf( %d%d , &r, &n);       if (n == 1) {         printf( 1 n );         continue;       }       long long ans = 1;       while (n > 1) {         int p = lp[n];         int pw = 0;         while (lp[n] == p) {           n /= p;           ++pw;         }         ans = ans * f[pw][r] % mod;       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }   const int MAXN = 3e5 + 10;   const int INF = 0x3f3f3f3f;   const int MOD = 1e7 + 9;   int a[MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = (1); i < (n + 1); ++i) {       scanf( %d , &a[i]);     }     int ans1 = 0;     int t1 = 1;     for (int i = (n); i > (0); --i) {       if (a[t1] != a[i]) {         ans1 = i - t1;         break;       } else {         t1++;         i++;       }     }     int ans2 = 0;     int t2 = n;     for (int i = (1); i < (n + 1); ++i) {       if (a[t2] != a[i]) {         ans2 = t2 - i;         break;       } else {         t2--;         i--;       }     }     printf( %d n , max(ans1, ans2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   const int M = 998244353;   int n, a[N], i, s;   long long f[N], c[N], x, y, z, ans[N], tp;   long long qpow(long long a, long long b) {     long long s = a, ans = 1;     while (b) {       if (b & 1) ans = ans * s % M;       s = s * s % M;       b >>= 1;     }     return ans;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       s += a[i];     }     long long is = qpow(s, M - 2), in = qpow(n - 1, M - 2);     c[1] = 1 - n;     f[0] = f[1] = 1;     for (i = 1; i < s; ++i) {       x = i * is % M, y = (s - i) * is % M * in % M;       z = qpow(y, M - 2);       f[i + 1] = (f[i] * (x + y) - f[i - 1] * x) % M * z % M;       c[i + 1] = (c[i] * (x + y) - 1 - c[i - 1] * x) % M * z % M;     }     ans[0] = -c[s] * qpow(f[s], M - 2) % M;     for (i = 1; i < s; ++i) ans[i] = (f[i] * ans[0] + c[i]) % M;     for (i = 1; i <= n; ++i) tp += ans[a[i]];     tp -= ans[0] * (n - 1);     cout << (tp % M * qpow(n, M - 2) % M + M) % M;   }
#include <bits/stdc++.h>   using namespace std;   long long w[2], b[2], q[2], mod = 998244353, fac[100001];   long long modpow(long long b, long long p) {     long long ret = 1;     while (p > 0) {       if (p & 1) ret = ret * b % mod;       b = b * b % mod;       p >>= 1;     }     return ret;   }   long long choose(long long n, long long m) {     long long denom = modpow(fac[m], mod - 2) * modpow(fac[n - m], mod - 2) % mod;     return (fac[n] * denom % mod);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, qq = 0;     bool bw = true, wb = true, both = true;     string s;     fac[0] = 1;     for (int i = 1; i < 100001; i++) fac[i] = fac[i - 1] * i % mod;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < 2; j++) {         if (s[j] ==  W ) w[j]++;         if (s[j] ==  B ) b[j]++;         if (s[j] ==  ? ) q[j]++;       }       if (s ==  ?? ) qq++;       if (s ==  WW  || s ==  BB ) bw = wb = both = false;       if (s ==  W?  || s ==  ?B  || s ==  WB ) bw = false;       if (s ==  B?  || s ==  ?W  || s ==  BW ) wb = false;     }     if (n == 1) {       if (s ==  WW  | s ==  BB )         cout << 0;       else if (s ==  ?? )         cout << 2;       else         cout << 1;       return 0;     }     long long ans = 0;     for (int i = 0; i < q[0] + 1; i++) {       if (w[0] + i < b[1] || w[0] + i > b[1] + q[1]) continue;       ans = (ans + choose(q[0], i) * choose(q[1], w[0] + i - b[1])) % mod;     }     if (both) {       ans -= modpow(2, qq);       if (bw) ans++;       if (wb) ans++;     }     ans = ((ans % mod) + mod) % mod;     cout << ans;   }
#include <bits/stdc++.h>   using std::abs;   using std::bitset;   using std::cerr;   using std::cin;   using std::copy;   using std::cout;   using std::endl;   using std::fill;   using std::fixed;   using std::greater;   using std::lower_bound;   using std::map;   using std::max;   using std::min;   using std::next_permutation;   using std::pair;   using std::priority_queue;   using std::queue;   using std::reverse;   using std::rotate;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::unique;   using std::unordered_map;   using std::unordered_set;   using std::upper_bound;   using std::vector;   int const INF = (int)1e9;   long long const INFL = (long long)1e18;   long double const PI = 3.1415926535897932384626433832795028;   bool isPrime(int x) {     for (int a = 2; a * a <= x; ++a) {       if (x % a == 0) {         return false;       }     }     return true;   }   int const N = 100100;   int len[N];   int g[N], next[N];   int find(int v) {     if (next[v] != v) {       int root = find(next[v]);       len[v] += len[next[v]];       next[v] = root;     }     return next[v];   }   int v[N], res[N];   bool did[N];   int calc(int a, int b) {     int ret = 0;     find(a);     b -= len[a];     a = next[a];     while (b > 0 && !did[a]) {       ++ret;       did[a] = true;       next[a] = find(g[a]);       len[a] = 1 + len[g[a]];       b -= len[a];       a = find(g[a]);     }     return ret;   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       next[i] = i;       len[i] = 0;       cin >> g[i];       --g[i];     }     for (int i = 1; i <= m; ++i) {       cin >> v[i];     }     for (int i = 1; i <= m; ++i) {       int b;       cin >> b;       int a = (v[i] + res[i - 1] - 1) % n;       res[i] = calc(a, b);     }     for (int i = 1; i <= m; ++i) {       cout << res[i] <<   n ;     }   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   bool vis[305][305];   string s[305];   int len[305][305];   int d[305];   int hs[305][305];   int n;   const int mod = 9e8 + 7;   int qpow(int x, int y) {     long long ret = 1;     long long now = x;     while (y) {       if (y & 1) ret = ret * now % mod;       now = now * now % mod;       y >>= 1;     }     return ret;   }   void init() {     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) {       d[i] = 0;       len[i][0] = s[i].size();       for (int j = 0; j < s[i].size(); j++) {         d[i] = (d[i] * 233LL + s[i][j] -  a  + 1) % mod;       }     }     for (int i = 1; i <= n; i++) {       hs[i][0] = d[i];       for (int j = 1; j + i <= n; j++) {         len[i][j] = len[i + j][0] + len[i][j - 1];         hs[i][j] = (1LL * hs[i][j - 1] * 2333LL + d[i + j]) % mod;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> s[i];     init();     int ans = 0;     for (int i = 1; i <= n; i++) {       int ls = 0;       for (int j = 0; i + j <= n; j++) {         ls += len[i + j][0];         int nx = i + j + 1;         int cnt = 1;         while (nx + j <= n) {           if (hs[i][j] == hs[nx][j] && len[i][j] == len[nx][j]) {             cnt++;             nx += j + 1;           } else {             nx++;           }         }         if (cnt > 1) ans = max(ans, (ls - 1) * cnt);       }     }     ans = n - 1 - ans;     for (int i = 1; i <= n; i++) ans += len[i][0];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[100005];   int p[100005];   int h[100005];   int happy[100005];   int sad[100005];   bool vis[100005];   bool ok;   void init(int n) {     for (int i = 1; i < n + 1; i++) {       v[i].clear();       vis[i] = false;     }     ok = true;   }   void dfs(int node) {     vis[node] = true;     long long int happyChild = 0;     long long int sadChild = p[node];     for (int child : v[node]) {       if (vis[child]) continue;       dfs(child);       happyChild += happy[child];       sadChild += sad[child];     }     long long int gg = (long long int)h[node] - (happyChild - sadChild);     if (gg >= 0 && gg % 2 == 0 && gg / 2 <= sadChild) {       long long int x = gg / 2;       happy[node] = x + happyChild;       sad[node] = sadChild - x;     } else {       ok = false;       return;     }   }   int main() {     int t, n, m, a, b;     scanf( %d , &t);     while (t--) {       scanf( %d %d , &n, &m);       init(n);       for (int i = 1; i < n + 1; i++) scanf( %d , &p[i]);       for (int i = 1; i < n + 1; i++) scanf( %d , &h[i]);       for (int i = 0; i < n - 1; i++) {         scanf( %d %d , &a, &b);         v[a].push_back(b);         v[b].push_back(a);       }       dfs(1);       if (ok)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long j, k, a, b, s, ss, l, m, n, t, d;   long long e, i, c[221];   vector<long long> p[111], q[111], r, v;   char w;   map<long long, long long> y, z;   long long too(long long i, long long j) {     long long l = 0, d = 0;     for (k = 0; k < q[i].size(); k++) {       l += q[i][k];       r.push_back(l);     }     l = 0;     for (k = 0; k < q[j].size(); k++) {       l += q[j][k];       r.push_back(l);     }     l = r.size();     sort(r.begin(), r.end());     for (k = 0; k < l; k++) c[k] = 0;     for (k = 0; k < l; k++) {       long long x, a = 0, b = 0, e = 0;       x = r[k];       while (x > q[i][e] && e < q[i].size()) {         a += p[i][e] * q[i][e];         x -= q[i][e];         e++;       }       if (e < q[i].size()) a += p[i][e] * x;       x = r[k];       e = 0;       while (x > q[j][e] && e < q[j].size()) {         b += p[j][e] * q[j][e];         x -= q[j][e];         e++;       }       if (e < q[j].size()) b += p[j][e] * x;       if (a > b) c[k] = 1;       if (a < b) c[k] = 2;     }     e = 0;     while (c[e] == 0) e++;     for (k = e + 1; k < l; k++) {       if (c[k] == 0) c[k] = c[k - 1];     }     for (k = e + 1; k < l; k++)       if (c[k] != c[k - 1]) d++;     return d;   }   int main() {     cin >> n >> s;     for (i = 0; i < n; i++) {       cin >> k;       for (j = 0; j < k; j++) {         cin >> a >> b;         p[i].push_back(a);         q[i].push_back(b);       }     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         ss += too(i, j);         r = v;       }     }     cout << ss;     return 0;   }