malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double PI = 3.141592653589793238462643383279;   const double EPS = 1e-9;   const long long MOD = 1000000007;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   int n;   int a[100];   vector<pair<vector<int>, int> > v1, v2;   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)n; i++) scanf( %d , a + i);     for (int i = 0; i < (int)(1 << 15); i++) {       {         int pre = __builtin_popcount((a[0] ^ i) & ((1 << 15) - 1));         vector<int> tmp;         for (int k = 1; k < n; k++) {           int now = __builtin_popcount((a[k] ^ i) & ((1 << 15) - 1));           tmp.push_back(pre - now);           pre = now;         }         v1.push_back(pair<vector<int>, int>(tmp, i));         if (i == 3) {         }       }       {         int pre = __builtin_popcount((a[0] >> 15) ^ i);         vector<int> tmp2;         for (int k = 1; k < n; k++) {           int now = __builtin_popcount((a[k] >> 15) ^ i);           tmp2.push_back(now - pre);           pre = now;         }         v2.push_back(pair<vector<int>, int>(tmp2, i * (1 << 15)));       }     }     sort(v1.begin(), v1.end(),          [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) {            for (int i = 0; i < (int)n - 1; i++) {              if (l.first[i] < r.first[i]) return true;              if (l.first[i] > r.first[i]) return false;            }            return l.second < r.second;          });     sort(v2.begin(), v2.end(),          [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) {            for (int i = 0; i < (int)n - 1; i++) {              if (l.first[i] < r.first[i]) return true;              if (l.first[i] > r.first[i]) return false;            }            return l.second < r.second;          });     int pos = 0;     for (pair<vector<int>, int>& p : v1) {       while (pos < (int)v2.size()) {         pair<vector<int>, int>& q = v2[pos];         bool ok = true;         bool con = false;         for (int i = 0; i < (int)n - 1; i++) {           if (q.first[i] < p.first[i]) {             pos++;             ok = false;             con = true;             break;           }           if (q.first[i] > p.first[i]) {             ok = false;             break;           }         }         if (ok) {           printf( %d n , p.second + q.second);           return 0;         }         if (!con) break;       }     }     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, l, m, n, d, x = 0;     cin >> k;     cin >> l;     cin >> m;     cin >> n;     cin >> d;     int arr[] = {k, l, m, n};     for (int i = 1; i <= d; i++) {       for (int j = 0; j < 4; j++) {         if (i % arr[j] == 0) {           x++;           break;         }       }     }     cout << x;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, input;     int count = 1;     int s = 3;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &input);       if (input == 10) {         if (s == 1) {           count++;         }         s = 0;       } else if (input == 1) {         if (s == 0) {           count++;         }         s = 1;       }     }     printf( %d , count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     T = 1;     while (T--) {       string t, s, s1, s2;       cin >> t;       s = t;       int i, j, x, l, a = 0;       for (i = 0; i < t.length(); i++) {         if (t[i] ==  a ) a = i;       }       for (i = 0; i < t.length(); i++) {         if (t[i] ==  a ) {           t.erase(i, 1);           i--;         }       }       l = t.length();       s1 = t.substr(0, l / 2);       s2 = t.substr(l / 2, l - l / 2);       if (s1 == s2) {         for (i = 0, j = 0; j < s1.length();) {           if (s[i] !=  a ) {             i++;             j++;           } else             i++;         }         while (s[i] ==  a ) {           i++;         }         if (i > a) {           s1 = s.substr(0, i);           cout << s1 << endl;         } else           cout <<  :( n ;       } else {         cout <<  :( n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p, x, y;     cin >> p >> x >> y;     for (int i = x; i >= y; i -= 50) {       int t = ((i / 50) % 475);       set<int> tr;       for (int j = 0; j < 25; j++) {         t = (t * 96 + 42) % 475;         tr.insert(26 + t);       }       if (tr.find(p) != tr.end()) {         cout <<  0 n  <<   n ;         return 0;       }     }     for (int i = x;; i += 50) {       int t = ((i / 50) % 475);       set<int> tr;       for (int j = 0; j < 25; j++) {         t = (t * 96 + 42) % 475;         tr.insert(26 + t);       }       if (tr.find(p) != tr.end()) {         (i - x) % 100 == 0 ? cout << (i - x) / 100                            : cout << (i - x) / 100 + 1 <<   n ;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i = 2, c = 0, v = 1;     cin >> n;     int x = 5;     while (n - x > 0) {       n = n - x;       x = x * 2;       v = v * 2;     }     while (n - v >= 1) {       n = n - v;       c++;     }     if (c + 1 == 1) {       cout <<  Sheldon ;     }     if (c + 1 == 2) {       cout <<  Leonard ;     }     if (c + 1 == 3) {       cout <<  Penny ;     }     if (c + 1 == 4) {       cout <<  Rajesh ;     }     if (c + 1 == 5) {       cout <<  Howard ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 520;   long long A[N];   long long dp[N];   long long maxl[N];   long long n, m;   long long get(long long x, long long y) {     if (x == 0) return N - 1;     return (x - 1) * m + y;   }   int main() {     cin >> n >> m;     A[N - 1] = 0;     for (long long i = 1; i <= n * m; i++) cin >> A[i];     for (long long i = 1; i <= m; i++)       for (long long j = 1; j <= n; j++) {         if (j == 1) {           long long a = get(j, i);           dp[a] = 1;           maxl[j] = max(maxl[j], 1ll);           continue;         }         long long a = get(j, i);         long long b = get(j - 1, i);         long long xia = A[a];         long long shang = A[b];         if (xia >= shang) {           dp[a] = dp[b] + 1;           maxl[j] = max(maxl[j], dp[a]);         } else {           dp[a] = 1;           maxl[j] = max(maxl[j], dp[a]);         }       }     long long t;     cin >> t;     while (t--) {       long long l, r;       cin >> l >> r;       if (r - maxl[r] + 1 <= l) {         cout <<  Yes  << endl;         continue;       }       cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   ifstream F( p.in );   const int M = 1000000007;   const int K = 110;   const int N = 100100;   int dp[K][N], b[N], c[N][K];   int n, m;   void add(int &x, int y) { x = ((x + y) % M + M) % M; }   int main() {     ios::sync_with_stdio(0);     for (int n = 0; n < N; ++n) {       c[n][0] = 1;       for (int k = 1; k <= min(n, K - 1); ++k)         c[n][k] = (c[n - 1][k - 1] + c[n - 1][k]) % M;     }     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> b[i];     for (int tt = 1, l, r, k; tt <= m; ++tt) {       cin >> l >> r >> k;       add(dp[k][l], 1);       for (int i = 0; i <= k; ++i)         add(dp[i][r + i + 1], -c[r - l + k + 1][k - i]);     }     for (int k = 100; k >= 0; --k)       for (int i = 1; i <= n; ++i) {         if (k > 0) add(dp[k - 1][i], dp[k][i]);         add(dp[k][i + 1], dp[k][i]);       }     for (int i = 1; i <= n; ++i) cout << (dp[0][i] + b[i]) % M <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100100], b[100100];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     sort(a, a + n);     sort(b, b + m, greater<int>());     n = min(n, m);     for (int i = 0; i < n and a[i] < b[i]; i++) {       ans += b[i] - a[i];     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long c2(long long n) { return n * (n - 1) / 2; }   void solve(long long x, long long y) {     if (x == 0) return;     if (y + 1 >= x) {       cout <<  ( ;       solve(x - 1, y - x + 1);       cout <<  ) ;       return;     } else {       cout <<  () ;       solve(x - 1, y);     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin >> n >> k;     if (c2(n) < k) {       cout <<  Impossible ;       return 0;     }     solve(n, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150100;   long long n, m, l, r;   long long P;   vector<int> p;   long long sum;   long long _dfs(long long d, long long x, long long y) {     if (d == p.size()) {       long long n = abs(y / x);       sum += n * (n + 1) / 2 * x;       return y / x;     }     return (_dfs(d + 1, x, y) + _dfs(d + 1, -x * p[d], y));   }   int gcdnumber(long long a, long long y) {     p.clear();     for (long long i = 2; i * i <= a; i++) {       if (a % i == 0) {         p.push_back(i);         while (a % i == 0) a /= i;       }     }     sum = 0;     if (a != 1) p.push_back(a);     return _dfs(0, 1, y);   }   long long calc(long long radiu, int add) {     long long y = radiu;     long long ret = 0;     for (long long i = 1; i <= radiu; i++) {       while (y && i * i + y * y > radiu * radiu - add) y--;       if (y >= m) y = m;       if (i <= n && y > 0) {         long long tmp = gcdnumber(i, y);         ret += (n - i + 1) * (tmp * (m + 1) - sum);         ret %= P;       }     }     return ret;   }   int main() {     cin >> n >> m;     cin >> l >> r >> P;     long long ans = 0;     if (l == 1) ans = n * (m + 1) + m * (n + 1);     ans %= P;     ans += (calc(r, 0) - calc(l, 1)) * 2;     while (ans < 0) ans += P;     ans %= P;     cout << ans << endl;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double lf;   typedef unsigned long long ull;   typedef pair<ll,int>P;   const int inf = 0x7f7f7f7f;   const ll INF = 1e16;   const int N = 2e5+10;   const ull base = 131;   const ll mod =  1e9+7;   const double PI = acos(-1.0);   const double eps = 1e-4;      inline int read(){int x=0,f=1;char ch=getchar();while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();}return x*f;}   inline string readstring(){string str;char s=getchar();while(s==   ||s==  n ||s==  r ){s=getchar();}while(s!=   &&s!=  n &&s!=  r ){str+=s;s=getchar();}return str;}   int random(int n){return (int)(rand()*rand())%n;}   void writestring(string s){int n = s.size();for(int i = 0;i < n;i++){printf( %c ,s[i]);}}         int a[N];   int b[N],c[N];      void solve(){       int n = read();       memset(b,0,sizeof b);       memset(c,0,sizeof c);       set<int>st1,st2;       for(int i = 1;i <= n;i++){           st1.insert(i);           st2.insert(i);       }       for(int i = 1;i <= n;i++){           a[i] = read();       }       b[1] = c[1] = a[1];       st1.erase(a[1]);       st2.erase(a[1]);       for(int i = 2;i <= n;i++){           if(a[i] != a[i-1]){               b[i] = c[i] = a[i];               st1.erase(a[i]);               st2.erase(a[i]);           }       }             for(int i = 1;i <= n;i++){           if(b[i] == 0){               int x = *st1.begin();               b[i] = x;               //cout<<x<<endl;               st1.erase(x);           }              if(c[i] == 0){               auto it = st2.upper_bound(c[i-1]);               it--;               c[i] = *it;               st2.erase(c[i]);           }          }             for(int i = 1;i <= n;i++){           printf( %d  ,b[i]);       }       puts(  );       for(int i = 1;i <= n;i++){           printf( %d  ,c[i]);       }       puts(  );      }   int main(){       int t = read();       while(t--){           solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mm;   int mv[100000] = {0};   int bfs(int n, int m) {     queue<int> mq;     mq.push(n);     mv[n] = 0;     while (!mq.empty()) {       int r = mq.front();       if (r == m) return mv[r];       mq.pop();       int x, y;       x = r - 1;       y = r * 2;       if (x > 0 && x < 10001 && mv[x] == 0) {         mv[x] = mv[r] + 1;         mq.push(x);       }       if (y > 0 && y < 10001 && mv[y] == 0) {         mv[y] = mv[r] + 1;         mq.push(y);       }     }   }   int main() {     int n, m;     cin >> n >> m;     int k = bfs(n, m);     cout << k << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   using dd = long double;   namespace {   static bool constexpr dbg = 0;   ll constexpr N = -999;   ll n, k;   bool ok(string const &s1, string const &s2) {     do {       if (dbg) {         bool b = (s1.size() == s2.size() + 1);         if (!b)           cerr <<  s1.size() == s2.size() + 1                 <<  : failed! n ;       }     } while (0);     if (s1.size() != s2.size()) return s1.size() > s2.size();     for (int i = 0; i < n; ++i)       if (s1[i] != s2[i]) return s1[i] > s2[i];     return true;   }   string solve() {     string s;     cin >> n >> k >> s;     cout << n <<   n ;     auto sub = s.substr(0, k);     while (sub.size() < n) sub.push_back(sub[sub.size() - k]);     if (ok(sub, s)) return sub;     int i = k - 1;     for (; i >= 0; --i)       if (s[i] !=  9 ) break;     ++s[i];     for (++i; i < k; ++i) s[i] =  0 ;     for (int j = k; j < n; ++j) s[j] = s[j - k];     return s;   }   }  // namespace   int main() {     if (!dbg) {       std::ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     cout << fixed << setprecision(20);     cout << solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, sum;   vector<long long> my, temp;   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> x;       my.push_back(x);       temp.push_back(x);     }     for (long long i = 0; i < n; i++) my.push_back(temp[i]);     long long maxi = 0;     for (long long i = 0; i < my.size(); i++) {       if (my[i] == 1) {         sum++;         maxi = max(maxi, sum);       } else         sum = 0;     }     cout << maxi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 4)       cout <<  No solution  << endl;     else {       double alpha = 2 * M_PI / n;       cout << fixed << setprecision(6);       double x = 0, y = 0;       for (int i = 1; i <= n - 2; i++) {         cout << x <<     << y << endl;         double l = 500;         l += 0.01 * i;         x += l * cos(alpha * i), y += l * sin(alpha * i);       }       cout << x <<     << y << endl;       x -= y / sin(alpha * (n - 1)) * cos(alpha * (n - 1)), y = 0;       cout << x <<     << y << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> ans;     if (k == 1) {       printf( %d n , n);       return 0;     }     for (int i = 2; i * i <= n; i++) {       while (n % i == 0) {         n /= i;         ans.push_back(i);         if (((int)ans.size()) == k - 1) break;       }       if (((int)ans.size()) == k - 1) break;     }     if (n == 1 || ((int)ans.size()) != k - 1) {       puts( -1 );       return 0;     }     ans.push_back(n);     for (int x : ans) printf( %d  , x);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Debug(vector<int> v) {     for (int i : v) {       cerr << i <<    ;     }   }   void Debug(int a[]) {     for (int i = 0; i < 5; i++) {       cerr << a[i] <<    ;     }   }   void Debug(int a) { cerr << a; }   void Debug(string a) { cerr << a; }   void Debug(long long a) { cerr << a; }   void Debug(unsigned long long a) { cerr << a; }   void Debug(float a) { cerr << a; }   void Debug(double a) { cerr << a; }   void Debug(char a) { cerr << a; }   int32_t main() {     int64_t l;     cin >> l;     int64_t a, b;     cin >> a >> b;     int64_t speed = a + b;     double time = (double)l / speed;     cout << time * a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long MAX = 1e17;   bool b[1000];   int main() {     ios_base::sync_with_stdio(0);     ;     int m, t, r, ans = 0;     cin >> m >> t >> r;     int w[m];     for (int i = 0; i < m; i++) cin >> w[i];     if (r > t) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < m; i++) w[i] += t + 10;     for (int i = 0; i < m; i++) {       int k = r;       for (int j = w[i] - t; j < w[i]; j++)         if (b[j]) k--;       if (k <= 0) continue;       for (int j = w[i] - 1; j > w[i] - t - 1; j--) {         if (!b[j]) {           b[j] = 1;           k--;           ans++;         }         if (k == 0) break;         if (j == w[i] - t) {           cout << -1 << endl;           return 0;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   vector<int> e[N];   int s[N], seg[N << 2], num[N << 2], chg[N << 2], dfn[N][2], dfsns[N],       sgn[N] = {-1}, stamp;   void dfs(int now, int pre) {     dfn[now][0] = ++stamp;     dfsns[stamp] = now;     sgn[dfn[now][0]] = sgn[dfn[pre][0]] == 1 ? -1 : 1;     for (int i = 0; i < e[now].size(); i++)       if (e[now][i] != pre) dfs(e[now][i], now);     dfn[now][1] = stamp;   }   void pushup(int rt) { seg[rt] = seg[rt << 1] + seg[rt << 1 | 1]; }   void pushdown(int rt, int l, int r) {     if (chg[rt]) {       seg[rt << 1] += num[rt << 1] * chg[rt];       seg[rt << 1 | 1] += num[rt << 1 | 1] * chg[rt];       chg[rt << 1] += chg[rt];       chg[rt << 1 | 1] += chg[rt];       chg[rt] = 0;     }   }   void build(int l, int r, int rt) {     if (l == r) {       seg[rt] = s[dfsns[l]];       num[rt] = sgn[l];       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     num[rt] = num[rt << 1] + num[rt << 1 | 1];     pushup(rt);   }   void update(int l, int r, int rt, int L, int R, int v) {     if (L <= l && r <= R) {       seg[rt] += num[rt] * v;       chg[rt] += v;       return;     }     int m = l + r >> 1;     pushdown(rt, l, r);     if (L <= m) update(l, m, rt << 1, L, R, v);     if (m < R) update(m + 1, r, rt << 1 | 1, L, R, v);     pushup(rt);   }   int query(int l, int r, int rt, int p) {     if (l == r) return seg[rt];     int m = l + r >> 1;     pushdown(rt, l, r);     if (p <= m)       return query(l, m, rt << 1, p);     else       return query(m + 1, r, rt << 1 | 1, p);   }   int main() {     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i < n; i++) {       int tmp1, tmp2;       cin >> tmp1 >> tmp2;       e[tmp1].push_back(tmp2);       e[tmp2].push_back(tmp1);     }     dfs(1, 0);     build(1, n, 1);     for (int i = 0; i < k; i++) {       int op, tmp1, tmp2;       cin >> op;       if (op == 1) {         cin >> tmp1 >> tmp2;         update(1, n, 1, dfn[tmp1][0], dfn[tmp1][1], sgn[dfn[tmp1][0]] * tmp2);       } else {         cin >> tmp1;         cout << query(1, n, 1, dfn[tmp1][0]) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, i, j, k, sum = 0;     scanf( %d%d%d , &n, &a, &b);     int arr[n];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     for (i = 0, j = n - 1; i <= j; i++, j--) {       if (i != j && arr[i] != arr[j] && arr[i] != 2 && arr[j] != 2) {         printf( -1 n );         return 0;       } else if (arr[i] == 2 && arr[j] == 2) {         if (i != j)           sum += (2 * min(a, b));         else           sum += min(a, b);       } else if (arr[i] == 2 || arr[j] == 2) {         if (arr[i] == 2 && arr[j] == 1)           sum += b;         else if (arr[i] == 2 && arr[j] == 0)           sum += a;         else if (arr[j] == 2 && arr[i] == 1)           sum += b;         else if (arr[j] == 2 && arr[i] == 0)           sum += a;       }     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   const long double eps = 0.00000001;   const long long MOD = 1e9 + 7;   const double PI = 3.141592653589793238463;   using namespace std;   long long ans;   int was[1010][1010];   int main() {     fflush(stdin);     cout << fixed, cout.precision(18);     ios_base::sync_with_stdio(false);     int i, j, n, m;     cin >> n >> m;     string second[n];     for (i = 0; i < n; ++i) cin >> second[i];     vector<pair<pair<int, int>, int>> ve;     for (i = 1; i < n - 1; ++i) {       for (j = 1; j < m - 1; ++j) {         if (second[i][j] ==  . ) continue;         int max_len = min(min(i, n - i - 1), min(j, m - j - 1));         if (max_len == 0) continue;         int x = i, y = j;         for (int len = 1; len <= max_len; ++len) {           if (second[i + len][j] ==  *  && second[i - len][j] ==  *  &&               second[i][j - len] ==  *  && second[i][j + len] ==  * ) {             was[i][j] = 1;             was[i + len][j] = was[i - len][j] = was[i][j - len] =                 was[i][j + len] = 1;             if (len == max_len) ve.push_back({{i + 1, j + 1}, len});             continue;           }           if (len - 1 > 0) ve.push_back({{i + 1, j + 1}, len - 1});           break;         }       }     }     bool b = true;     for (i = 0; i < n; ++i)       for (j = 0; j < m; ++j)         if (second[i][j] ==  *  && !was[i][j]) b = false;     if (!b) return cout << -1, 0;     cout << ve.size() << endl;     for (i = 0; i < ve.size(); ++i) {       printf( %d %d %d n , ve[i].first.first, ve[i].first.second, ve[i].second);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int n, k, a[maxn], b[maxn];   void work(long long g);   long long as, ct;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     long long l = 0, r = 1e12, mid, ot;     while (l < r) {       work(mid = l + r >> 1);       if (ct >= k)         r = mid, ot = mid;       else         l = mid + 1;     }     work(ot), printf( %lld n , as + 2 * k * ot);     return 0;   }   void work(long long g) {     priority_queue<pair<long long, int> > q;     as = ct = 0;     long long tp;     for (int i = 1; i <= n; i++) {       q.push({g - a[i], 1});       if ((tp = b[i] - q.top().first - g) <= 0) {         as += tp, ct += q.top().second, q.pop(), q.push({b[i] - g, 0});       }     }   }