malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const double eps = 1e-6;   int n, k, q, m;   int a[N], b[N], used[N];   double MinAns = 100.0, MaxAns = 0.0;   double max(double x, double y) { return x - eps >= y ? x : y; }   double min(double x, double y) { return x + eps <= y ? x : y; }   void init() {     scanf( %d %d , &n, &k);     m = n / k;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);   }   void work() {     int x, sum, cnt;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       sum = 0;       for (int j = 1; j <= m; j++) {         scanf( %d , &x);         used[x] = 1;         sum += a[x];       }       MinAns = min(MinAns, 1.0 * sum / m);       MaxAns = max(MaxAns, 1.0 * sum / m);     }     cnt = 0;     for (int i = 1; i <= n; i++)       if (!used[i]) b[++cnt] = a[i];     sort(b + 1, b + 1 + cnt);     if (cnt >= m && n - cnt < k * m) {       sum = 0;       for (int i = 1; i <= m; i++) sum += b[i];       MinAns = min(MinAns, 1.0 * sum / m);       sum = 0;       for (int i = cnt; i > cnt - m; i--) sum += b[i];       MaxAns = max(MaxAns, 1.0 * sum / m);     }     printf( %.10lf %.10lf n , MinAns, MaxAns);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   int i, n, k, a, s, j;   int main() {     for (std::cin >> n >> k; i < k; i++)       std::cin >> a, a % 2 ? a++, j++ : 0, s += a;     std::cout << (s > 8 * n || s == 8 * n && k == 4 * n && j < n ?  NO  :  YES );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, i;     cin >> n;     string s;     cin >> s;     int k = 1;     for (i = 0; i < n; i++) {       if (s[i] ==  1  && k == 1) {         sum++;       } else if (s[i] ==  0  && k == 1) {         sum++;         k = 0;       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     short negative = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) negative = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     x *= negative;   }   inline void write(long long x) {     static long long sta[35];     long long top = 0;     do {       sta[top++] = x % 10, x /= 10;     } while (x);     while (top) putchar(sta[--top] + 48);     puts(  );   }   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   vector<long long> v;   int n;   void w(string s) {     v.push_back(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==     || s[i] ==  - ) v.push_back(i + 1);     }     v.push_back(s.size());   }   bool check(int mid) {     int len = 0, g = 1;     for (int i = 1; i < v.size(); i++) {       if (v[i] - v[i - 1] > mid) return 0;       if (len + (v[i] - v[i - 1]) <= mid)         len += (v[i] - v[i - 1]);       else {         g++;         len = v[i] - v[i - 1];       }     }     return g <= n;   }   int main() {     read(n);     char s[1000010];     gets(s);     w(s);     int l = 1, r = 1e6, res = 1e5;     while (l <= r) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid - 1;       else {         l = mid + 1;       }     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, a, b, signo, dist, centro;   vector<pair<long long int, long long int> > distancias;   vector<long long int> izq, der;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     a = 1;     b = 2;     for (int i = (3); i <= (n); i++) {       cout <<  2   << a <<     << b <<     << i << endl;       cin >> signo;       if (signo > 0) b = i;     }     for (int i = (1); i <= (n); i++) {       if (i == a || i == b) continue;       cout <<  1   << a <<     << b <<     << i << endl;       cin >> dist;       distancias.push_back({-dist, i});     }     sort(distancias.begin(), distancias.end());     centro = 0;     for (auto d : distancias) {       if (centro == 0) {         centro = d.second;         continue;       }       cout <<  2   << a <<     << centro <<     << d.second << endl;       cin >> signo;       if (signo > 0)         izq.push_back(d.second);       else         der.push_back(d.second);     }     reverse(der.begin(), der.end());     cout <<  0   << a <<    ;     for (auto n : der) cout << n <<    ;     cout << centro <<    ;     for (auto n : izq) cout << n <<    ;     cout << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char x =   0 ;     int fh = 1, sum = 0;     for (x = getchar(); x <  0  || x >  9 ; x = getchar())       if (x ==  - ) fh = -1;     for (; x >=  0  && x <=  9 ; x = getchar()) sum = sum * 10 + x -  0 ;     return fh * sum;   }   const int N = 1e5 + 9;   int fa[N], ch[N][2], sz[N];   long long A[N], B[N], val[N];   int n, a, rt, cnt;   inline long long pd(int x) { return ch[fa[x]][1] == x; }   inline void pushup(int x) {     int ls = ch[x][0], rs = ch[x][1];     sz[x] = sz[ls] + sz[rs] + 1;   }   inline void modify(int x, long long a, long long b) {     val[x] += a * (sz[ch[x][0]] + 1) + b;     A[x] += a, B[x] += b;   }   inline void pushdown(int x) {     if (A[x] || B[x]) {       if (ch[x][0]) modify(ch[x][0], A[x], B[x]);       if (ch[x][1]) modify(ch[x][1], A[x], B[x] + A[x] * (sz[ch[x][0]] + 1));       A[x] = B[x] = 0;     }   }   inline void rotate(int x) {     int y = fa[x], z = fa[y], kx = pd(x), ky = pd(y);     if (z) ch[z][ky] = x;     fa[x] = z, fa[y] = x, fa[ch[x][kx ^ 1]] = y;     ch[y][kx] = ch[x][kx ^ 1];     ch[x][kx ^ 1] = y;     pushup(y), pushup(x);     if (z) pushup(z);   }   inline void splay(int x) {     static int sta[N], tp;     sta[tp = 1] = x;     for (int y = x; fa[y]; y = fa[y]) sta[++tp] = fa[y];     while (tp) pushdown(sta[tp--]);     for (; fa[x]; rotate(x))       if (fa[fa[x]]) rotate((pd(x) ^ pd(fa[x])) ? x : fa[x]);     pushup(rt = x);   }   inline long long getv(int k) {     int x = rt;     while (1) {       if (sz[ch[x][0]] + 1 == k) {         splay(x);         return val[x];       }       if (sz[ch[x][0]] >= k)         x = ch[x][0];       else         k -= sz[ch[x][0]] + 1, x = ch[x][1];     }   }   inline long long getmx(int x) {     if (!x) return -1e18;     pushdown(x);     return std::max(val[x], std::max(getmx(ch[x][0]), getmx(ch[x][1])));   }   int main() {     n = read();     sz[1] = rt = cnt = 1;     for (register int i = 1, endi = n; i <= endi; ++i) {       int a = read();       int lp = 0, rp = i - 2, ans = i - 1;       while (lp <= rp) {         int mid = (lp + rp) >> 1;         if (getv(mid + 1) + (mid + 1LL) * a > getv(mid + 2))           rp = (ans = mid) - 1;         else           lp = mid + 1;       }       getv(ans + 1);       fa[++cnt] = rt, val[cnt] = val[rt], ch[cnt][1] = ch[rt][1];       fa[ch[rt][1]] = cnt;       ch[rt][1] = cnt;       modify(cnt, a, 1LL * a * ans);     }     printf( %lld n , getmx(rt));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k, a;     scanf( %d , &n);     vector<int> nums;     unordered_map<int, int> hashmap, sizes, parent, inp;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       nums.push_back(a);     }     sort(nums.begin(), nums.end());     int smin = -1, smin_pos = 0, res = 1;     for (int i = 0; i < n; i++) {       a = nums[i];       if (smin == -1) {         smin = a;         smin_pos = i;       } else {         if (a - smin <= 5) {           continue;         } else {           res = max(res, i - smin_pos);           while (a - nums[smin_pos] > 5 && smin_pos < i) smin_pos++;           smin = nums[smin_pos];         }       }     }     if (nums[n - 1] - smin <= 5) {       res = max(res, n - smin_pos);     }     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   int main() {     char str[100][100] = { January ,    February ,  March ,     April ,                            May ,        June ,      July ,      August ,                            September ,  October ,   November ,  December };     char month[100];     scanf(  %[^ n] , month);     int n;     scanf( %d , &n);     int index;     int i;     for (i = 0; i < 12; i++) {       if (strcmp(str[i], month) == 0) {         index = i;         break;       }     }     index = ((index) % 12 + n % 12) % 12;     printf( %s n , str[index]);   }
#include <bits/stdc++.h>   inline int read() {     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     int k = 0, kk = 1;     if (c ==  - ) c = getchar(), kk = -1;     while (c >=  0  && c <=  9 ) k = k * 10 + c -  0 , c = getchar();     return kk * k;   }   using namespace std;   void write(int x) {     if (x < 0) x = -x, putchar( - );     if (x / 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(int x) {     write(x);     puts(  );   }   int n, m, k, x[1000000], y[1000000], l[1000000], r[1000000], f[1000000];   struct lsg {     int x, y, d, bj;   } a[1000000], ff[1000000];   bool cmp1(lsg x, lsg y) { return x.d < y.d; }   bool cmp2(lsg x, lsg y) { return x.x < y.x; }   bool cmp3(lsg x, lsg y) { return x.y > y.y; }   bool pd(int kkk) {     int d = 0, dd = 0, ddd = 0;     memset(a, 0, sizeof(a));     for (int i = 1; i <= k; i++) {       a[++d].d = x[i] - kkk;       a[d].x = y[i] - kkk;       a[d].y = y[i] + kkk;       a[d].bj = i;       a[++d].d = x[i] + kkk + 1;       a[d].bj = -i;     }     a[++d].d = 1;     a[++d].d = n;     sort(a + 1, a + 1 + d, cmp1);     a[d + 1].d = -1e9;     for (int i = 1; i <= d; i++) {       if (a[i].bj > 0) {         ff[++dd].x = a[i].x;         ff[dd].y = a[i].y;         ff[dd].bj = a[i].bj;       } else if (a[i].bj < 0) {         int kk = 0;         for (int j = 1; j <= dd; j++)           if (ff[j].bj != -a[i].bj) ff[++kk] = ff[j];         dd = kk;       }       if (a[i].d != a[i + 1].d && a[i].d >= 1 && a[i].d <= n) {         sort(ff + 1, ff + 1 + dd, cmp2);         l[++ddd] = 1;         r[ddd] = m;         f[ddd] = a[i].d;         for (int j = 1; j <= dd; j++) {           if (l[ddd] >= ff[j].x) l[ddd] = max(l[ddd], ff[j].y + 1);         }         sort(ff + 1, ff + 1 + dd, cmp3);         for (int j = 1; j <= dd; j++) {           if (r[ddd] <= ff[j].y) r[ddd] = min(r[ddd], ff[j].x - 1);         }       }     }     int ll = 1, rr = ddd, lll = m, rrr = 1;     f[ddd + 1] = n;     f[ddd + 2] = n + 1;     while (l[ll] > r[ll] && ll <= rr) ll++;     while (l[rr] > r[rr] && ll <= rr) rr--;     if (f[rr + 1] - 1 - f[ll] > kkk * 2) return 0;     for (int i = ll; i <= rr; i++) lll = min(lll, l[i]), rrr = max(rrr, r[i]);     if (rrr - lll > kkk * 2) return 0;     return 1;   }   signed main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= k; i++) x[i] = read(), y[i] = read();     int l = 0, r = max(n, m);     while (l < r) {       int m = (l + r) / 2;       if (pd(m))         r = m;       else         l = m + 1;     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<int> Q[200];   int main() {     int n, k;     cin >> n >> k;     unsigned long long pr[200000];     for (int i = 0; i < n; i++) {       cin >> pr[i];     }     string str;     vector<unsigned long> vec[200];     unsigned long long sum = 0;     cin >> str;     for (int i = 0; i < n; i++) {       Q[str[i]].push(pr[i]);       if (str[i] != str[i - 1] && i > 0) {         int j = 0;         while (!Q[str[i - 1]].empty()) {           if (j <= k - 1) sum += Q[str[i - 1]].top();           Q[str[i - 1]].pop();           j++;         }       }     }     for (int i = 97; i <= 122; i++) {       int j = 0;       while (!Q[i].empty()) {         if (j > k - 1) break;         sum += Q[i].top();         Q[i].pop();         j++;       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   int N, K, D[MAX], S[MAX];   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < (int)N; i++) scanf( %d , &D[i]);     for (int i = 0; i < (int)N; i++) scanf( %d , &S[i]);     int res = 0;     int lho = S[0];     int pos = 0;     int fuel = 0;     while (pos != N) {       if (lho < S[pos]) lho = S[pos];       fuel += S[pos];       int rem = max(0, D[pos] - fuel);       int add = (rem + lho - 1) / lho;       res += add * K;       fuel += add * lho;       fuel -= D[pos];       res += D[pos];       pos++;     }     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const int MAX = 5e3 + 10;   const int MOD = 998244353;   long long fat[MAX], ifat[MAX];   long long choose(int a, int b) {     if (a < b) return 0;     return fat[a] * ifat[b] % MOD * ifat[a - b] % MOD;   }   long long fexp(long long a, long long e) {     long long ans = 1;     while (e) {       if (e & 1) ans = ans * a % MOD;       a = a * a % MOD;       e /= 2;     }     return ans;   }   void compute() {     fat[0] = 1;     ifat[0] = 1;     for (int i = 1; i < MAX; i++) {       fat[i] = i * fat[i - 1] % MOD;       ifat[i] = fexp(fat[i], MOD - 2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     compute();     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0 || count(s.begin(), s.end(),  1 ) < k) {       cout << 1 <<   n ;       return 0;     }     long long ans = 1;     for (int l = 0; l < n; l++) {       int cnt = 0, r = l;       while (r < n && cnt + (s[r] ==  1 ) <= k) cnt += s[r++] ==  1 ;       long long add = 0;       if (s[l] ==  0  && cnt > 0) add = choose((r - l) - 1, cnt - 1);       if (s[l] ==  1  && ((r - l) - cnt) > 0) add = choose((r - l) - 1, cnt);       ans = (ans + add) % MOD;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int get() {     int f = 0, v = 0;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) break;     if (ch ==  - )       f = 1;     else       v = ch -  0 ;     while (isdigit(ch = getchar())) v = v * 10 + ch -  0 ;     if (f)       return -v;     else       return v;   }   const int maxn = 1003;   long long a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];   int n, m, k;   int main() {     n = get(), m = get();     k = get();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         a[i][j] = a[i - 1][j] + a[i][j - 1] + get() - a[i - 1][j - 1],         b[i][j] = b[i - 1][j + 1] + a[i][j] -                   (i > k && j + k <= m ? a[i - k][j + k] : 0),         c[i][j] =             c[i - 1][j - 1] + a[i][j] - (i > k && j > k ? a[i - k][j - k] : 0);       b[i][0] = b[i - 1][1] - (i > k ? a[i - k][k] : 0);     }     long long v = -1, t;     int x, y;     for (int i = k; i <= n - k + 1; i++)       for (int j = k; j <= m - k + 1; j++)         if ((t = b[i + k - 1][j] + b[i - 1][j - k] - c[i + k - 1][j - 1] -                  c[i - 1][j + k - 1]) > v)           v = t, x = i, y = j;     printf( %d %d n , x, y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1153][1153];   int n, m;   unsigned long long int b[1153][1153];   bool pos(int minval) {     memset(b, 0, sizeof(b));     int i, j, k;     for (i = 0; i < n; i++) {       int ccnt = 0;       for (j = 0; j < 1024; j += 63) {         unsigned long long int blk = 0;         for (k = j; k < j + 63; k++) {           blk <<= 1;           if (a[i][k] >= minval) {             blk |= 1;           }         }         b[i][j] = blk;       }       for (j = 0; j < i; j++) {         ccnt = 0;         for (k = 0; k < 1024; k += 63) {           unsigned long long int ret = (b[i][k] & b[j][k]);           if (ret != 0) {             if ((ret & (ret - 1)) == 0)               ccnt++;             else               return true;           }         }         if (ccnt >= 2) return true;       }     }     return false;   }   int main() {     int i, j;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf( %d , &a[i][j]);       }     }     int lb = 0, ub = 1000000004, mid, ans;     while (lb <= ub) {       mid = (lb + ub) / 2;       if (pos(mid)) {         lb = mid + 1;         ans = mid;       } else         ub = mid - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   int n, q;   int len[N];   vector<pair<int, int>> g[N];   double prob[N];   double sum;   int dfs(int v, int p) {     int size = 1;     for (auto e : g[v]) {       int to = e.first;       int ind = e.second;       int w = len[ind];       if (to == p) continue;       int A = dfs(to, v);       size += A;       int B = n - A;       double prob_nom = (long long)A * B * (B - 1) / 2;       prob_nom += (long long)B * A * (A - 1) / 2;       double prob_denom = (long long)n * (n - 1) * (n - 2) / 6;       prob[ind] = prob_nom / prob_denom;       sum += w * prob[ind];     }     return size;   }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       u--;       v--;       len[i] = w;       g[u].push_back(make_pair(v, i));       g[v].push_back(make_pair(u, i));     }     dfs(0, -1);     0;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int r, w;       scanf( %d%d , &r, &w);       r--;       double delta = w - len[r];       sum += delta * prob[r];       len[r] = w;       printf( %.10lf n , 2 * sum);     }   }   int main() {     solve();     0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ts;     cin >> ts;     while (ts--) {       int n;       cin >> n;       vector<int> v(n);       vector<int> pos[2];       for (int i = 0; i < n; i++) {         cin >> v[i];         pos[v[i]].push_back(i);       }       int x = 0;       if (pos[0].size() >= n / 2) {         x = 0;       } else         x = 1;       if (x) {         if (pos[x].size() % 2 != 0) {           int k = pos[x].size() - 1;           if (k < n / 2) {             vector<int> vv;             for (int i = 0; i < k; i++) vv.push_back(pos[x][i]);             int f = lower_bound(pos[0].begin(), pos[0].end(), vv[vv.size() - 1]) -                     pos[0].begin();             int d =                 lower_bound(pos[0].begin(), pos[0].end(), vv[0]) - pos[0].begin();             if (pos[0].size() - f >= 2) {               vv.push_back(pos[0][f]);               vv.push_back(pos[0][f + 1]);               cout << vv.size() <<   n ;               for (int i = 0; i < vv.size(); i++) cout << v[vv[i]] <<    ;               cout << endl;             } else if (d >= 1) {               vv.push_back(pos[0][d]);               vv.push_back(pos[0][d - 1]);               cout << vv.size() <<   n ;               for (int i = vv.size() - 1; i >= 0; i--) {                 cout << v[vv[i]] <<    ;               }               cout << endl;             }           } else {             cout << k <<   n ;             for (int i = 0; i < k; i++) {               cout << 1 <<    ;             }             cout <<   n ;           }         } else {           cout << pos[x].size() <<   n ;           for (int i = 0; i < pos[x].size(); i++) cout <<  1  ;           cout << endl;         }       } else {         cout << pos[x].size() <<   n ;         for (int i = 0; i < pos[x].size(); i++) cout <<  0  ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200007], b[200007];   bool check[200007];   int main() {     string s;     getline(cin, s);     int res = 0;     for (auto i = (0); i <= ((int)s.size() - 1); ++i) {       int tmp = s[i];       int ans = 0;       for (auto i = (1); i <= (8); ++i) {         ans = 2 * ans + tmp % 2;         tmp /= 2;       }       printf( %d n , (res - ans + 256) % 256);       res = ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 20;   int pos[maxn];   int n, m;   long long k, ans[maxn];   int val[maxn];   struct query {     int l, r, id;   } Q[maxn];   long long now = 0;   long long M[maxn];   bool cmp(query a, query b) {     if (pos[a.l] == pos[b.l]) return a.r < b.r;     return pos[a.l] < pos[b.l];   }   void add(int x) {     now += M[val[x] ^ k];     M[val[x]]++;   }   void del(int x) {     M[val[x]]--;     now -= M[val[x] ^ k];   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       long long temp;       scanf( %I64d , &temp);       val[i] = val[i - 1] ^ temp;     }     int block = sqrt(n);     for (int i = 1; i <= n; i++) pos[i] = i / block;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &Q[i].l, &Q[i].r);       Q[i].id = i;     }     sort(Q + 1, Q + m + 1, cmp);     M[0] = 1;     for (int i = 1, L = 1, R = 0; i <= m; i++) {       for (; R < Q[i].r; R++) add(R + 1);       for (; R > Q[i].r; R--) del(R);       for (; L < Q[i].l; L++) del(L - 1);       for (; L > Q[i].l; L--) add(L - 2);       ans[Q[i].id] = now;     }     for (int i = 1; i <= m; i++) printf( %I64d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mod = 998244353;   int n;   long long a[N];   long long p[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     long long m = 1;     p[0] = 1;     p[1] = 3;     for (int i = 2; i < n; i++) {       m = (m << 1) % mod;       p[i] = m * (i + 2) % mod;     }     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + p[n - i - 1] * a[i]) % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   const int P = 1000000007;   int m, n, mi[N], l[N], r[N];   char a[N], ans[N];   bool Check(int t, int x) {     if (++t < x) return 0;     return ((r[t] - r[t - x] * mi[x]) * mi[t - x] == l[t] - l[t - x]);   }   bool Dfs(int k, bool has) {     if (k == n) {       puts(ans);       return true;     }     for (ans[k] = (has ? a[k] :  a ); ans[k] <=  z ; ++ans[k]) {       l[k + 1] = l[k] + ans[k] * mi[k];       r[k + 1] = r[k] * P + ans[k];       if (!Check(k, m) && !Check(k, m + 1) && Dfs(k + 1, has && (a[k] == ans[k])))         return true;     }     return false;   }   int main() {     scanf( %d%s , &m, a);     int i;     for (i = (n = strlen(a)) - 1; i >= 0 && a[i] ==  z ; --i) a[i] =  a ;     if (i < 0) {       puts( Impossible );       return 0;     }     ++a[i];     mi[0] = 1;     for (int i = 1; i <= n; ++i) mi[i] = mi[i - 1] * P;     if (!Dfs(0, 1)) puts( Impossible );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int S = (int)1e6;   int dp[S];   string txt, pat;   vector<int> ans;   void kmp() {     int i = 0, j = -1, n = ((int)(txt.size())), m = ((int)(pat.size()));     dp[0] = -1;     while (i < m) {       while (j >= 0 and pat[i] != pat[j]) j = dp[j];       i++, j++;       dp[i] = j;     }   }   int main() {     ios::sync_with_stdio(0);   a:     string s, s2;     cin >> s >> s2;     int ones = 0, zeros = 0, ones2 = 0, zeros2 = 0, ones3 = 0, zeros3 = 0;     for (char c : s) (c ==  0 ) ? zeros++ : ones++;     pat = s2;     kmp();     string res = s2, r = s2.substr(dp[((int)(s2.size()))],                                    ((int)(s2.size())) - dp[((int)(s2.size()))]);     for (char c : res) (c ==  0 ) ? zeros2++ : ones2++;     for (char c : r) (c ==  0 ) ? zeros3++ : ones3++;     if (zeros2 > zeros or ones2 > ones)       cout << s <<   n ;     else {       while (1) {         if (zeros2 + zeros3 > zeros or ones2 + ones3 > ones) break;         res += r;         zeros2 += zeros3;         ones2 += ones3;       }       for (int i = 0; i < zeros - zeros2; i++) res +=  0 ;       for (int i = 0; i < ones - ones2; i++) res +=  1 ;       cout << res <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1100100;   long long N, l, r;   long long L[MAX], R[MAX], d, sol;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int I = 0; I < N; I++) {       cin >> L[I] >> R[I];       l += L[I];       r += R[I];     }     d = abs(l - r);     for (int I = 0; I < N; I++) {       l += +R[I] - L[I];       r += -R[I] + L[I];       if (abs(l - r) > d) {         d = abs(l - r);         sol = I + 1;       }       l -= +R[I] - L[I];       r -= -R[I] + L[I];     }     cout << sol << endl;   }