malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100005, MAX_K = 105;   int N, M, K, S;   int good_type[MAX_N];   int distances[MAX_N][MAX_K];   vector<int> adj[MAX_N];   int dist[MAX_N];   void RunBFS(int type) {     queue<int> q;     for (int i = 0; i < N; ++i) {       if (good_type[i] == type) {         distances[i][type] = 0;         q.push(i);       }     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (const int& v : adj[u]) {         if (distances[v][type] == -1) {           distances[v][type] = distances[u][type] + 1;           q.push(v);         }       }     }   }   int main() {     scanf( %d %d %d %d , &N, &M, &K, &S);     for (int i = 0; i < N; ++i) {       scanf( %d , &good_type[i]);       --good_type[i];     }     for (int i = 0; i < M; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     memset(distances, -1, sizeof distances);     for (int i = 0; i < K; ++i) {       RunBFS(i);     }     for (int i = 0; i < N; ++i) {       sort(distances[i], distances[i] + K);       long long sum = 0;       for (int j = 0; j < S; ++j) sum += distances[i][j];       printf( %lld  , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 7;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   map<long long, long long> mp;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long i = 1;     vector<long long> v;     long long n, a, b, m;     cin >> m >> a >> b;     long long k = gcd(a, b);     long long z = m / k;     long long val1 = m * z - (k * z * (z + 1) / 2) + z + m + 1;     long long val2 = 0;     long long start = 0;     long long cnt = 0;     long long ans = 0;     long long currmx = 0;     while (start <= (a + b)) {       if (mp[start]) break;       mp[start] = 1;       currmx = max(currmx, start);       if (start <= m) {         ans += min(currmx - start, m - start + 1);       }       if (start >= b)         start -= b;       else         start += a;     }     cout << val1 - ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long linf = 1LL << 62;   const int iinf = 1000000009;   const double dinf = 1e17;   const int Mod = 1e9 + 9;   const int maxn = 1000005;   int n;   long long a, b[maxn];   long long dp[3][maxn];   void solve() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a, b[i] = __builtin_popcountll(a);     long long suf = 0;     dp[0][n + 1] = 1;     long long res = 0;     for (int i = n; i >= 1; i--) {       long long sum = 0, mx = 0, ret = 0;       for (int j = i; j <= min(n, i + 64); j++) {         sum += b[j];         mx = max(b[j], mx);         if (mx > sum - mx && sum % 2 == 0) ret--;       }       suf += b[i];       if (suf & 1)         ret += dp[1][i + 1];       else         ret += dp[0][i + 1];       res += ret;       dp[0][i] = dp[0][i + 1];       dp[1][i] = dp[1][i + 1];       if (suf & 1)         dp[1][i]++;       else         dp[0][i]++;     }     cout << res << endl;   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int x[1000][1000];   int r[1000][1000][4];   void upd1(int j) {     int i = 0;     for (int k = 0; k < n; ++k) {       if (x[k][j] == 0) {         i = k + 1;         r[k][j][0] = -1;       } else         r[k][j][0] = i;     }     i = n - 1;     for (int k = n - 1; k > -1; --k) {       if (x[k][j] == 0) {         i = k - 1;         r[k][j][1] = -1;       } else         r[k][j][1] = i;     }   }   void upd2(int i) {     int j = 0;     for (int k = 0; k < m; ++k) {       if (x[i][k] == 0) {         j = k + 1;         r[i][k][2] = -1;       } else         r[i][k][2] = j;     }     j = m - 1;     for (int k = m - 1; k > -1; --k) {       if (x[i][k] == 0) {         j = k - 1;         r[i][k][3] = -1;       } else         r[i][k][3] = j;     }   }   int main() {     cin.sync_with_stdio(false);     cin >> n >> m >> q;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> x[i][j];     for (int j = 0; j < m; ++j) upd1(j);     for (int i = 0; i < n; ++i) upd2(i);     for (int k = 0; k < q; ++k) {       int op;       int i, j;       cin >> op;       cin >> i >> j;       i--;       j--;       if (op == 1) {         x[i][j] = 1 - x[i][j];         upd1(j);         upd2(i);       } else {         int res = 0;         if (x[i][j] != 0) {           int up = 0;           int down = n - 1;           for (int k = j; k <= r[i][j][3]; ++k) {             up = max(up, r[i][k][0]);             down = min(down, r[i][k][1]);             res = max(res, (down - up + 1) * (k - j + 1));           }           up = 0;           down = n - 1;           for (int k = j; k >= r[i][j][2]; --k) {             up = max(up, r[i][k][0]);             down = min(down, r[i][k][1]);             res = max(res, (down - up + 1) * (j - k + 1));           }           int left = 0;           int right = m - 1;           for (int k = i; k <= r[i][j][1]; ++k) {             left = max(left, r[k][j][2]);             right = min(right, r[k][j][3]);             res = max(res, (right - left + 1) * (k - i + 1));           }           left = 0;           right = m - 1;           for (int k = i; k >= r[i][j][0]; --k) {             left = max(left, r[k][j][2]);             right = min(right, r[k][j][3]);             res = max(res, (right - left + 1) * (i - k + 1));           }         }         cout << res << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int a[n];       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n - i - 1; j++) {           if (a[j + 1] < a[j]) {             int t = a[j];             a[j] = a[j + 1];             a[j + 1] = t;           }         }       }       int ans = INT_MAX;       for (int i = 0; i < n - 1; i++) {         if (a[i + 1] - a[i] < ans) {           ans = a[i + 1] - a[i];           if (ans == 0) break;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXD = 500;   const int MAXS = 5000;   bool vis[MAXD][MAXS + 1];   int dig[MAXD][MAXS + 1], from[MAXD][MAXS + 1];   struct Data {     int last, c, prev_r;     int r, sum;     bool operator<(const Data &other) const { return last < other.last; }   };   queue<Data> mst;   int main() {     int d, s;     ios::sync_with_stdio(false);     cin >> d >> s;     mst.push({0, 0, 0, 0, 0});     int last = 0;     while (!mst.empty()) {       auto it = mst.front();       int r = it.r, sum = it.sum;       int prev_r = it.prev_r, c = it.c;       mst.pop();       if (vis[r][sum]) {         continue;       }       vis[r][sum] = 1;       dig[r][sum] = c;       from[r][sum] = prev_r;       for (c = 0; c < 10; c++) {         int cur = (r * 10 + c) % d;         if (sum + c <= s && vis[cur][sum + c] == 0) {           mst.push({++last, c, r, cur, sum + c});         }       }     }     if (vis[0][s]) {       vector<int> sol;       int r = 0;       while (s > 0) {         int cur = dig[r][s];         sol.push_back(cur);         r = from[r][s];         s -= cur;       }       reverse(sol.begin(), sol.end());       for (auto it : sol) {         cout << it;       }       return 0;     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   const int M = 2e5 + 10;   const int N = 5e2 + 10;   inline long long read() {     long long b = 1, sum = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) b = -1;       c = getchar();     }     while (isdigit(c)) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return b * sum;   }   int hs, gs;   int n, m, k, T;   int h, g, a[1 << 22];   long long sum;   vector<int> ans;   void change(int x) {     int l = 2 * x, r = 2 * x + 1;     if (a[l] == 0 && a[r] == 0) {       a[x] = 0;     } else {       if (a[l] > a[r]) {         a[x] = a[l];         change(l);       } else {         a[x] = a[r];         change(r);       }     }   }   int pull(int x) {     int l = 2 * x, r = 2 * x + 1;     if (a[l] == 0 && a[r] == 0) {       return x;     } else {       if (a[l] > a[r]) {         return pull(l);       } else {         return pull(r);       }     }   }   void solv(int x) {     if (a[x] == 0) return;     int l = 2 * x, r = 2 * x + 1;     while (pull(x) >= gs) {       ans.push_back(x);       sum -= a[x];       change(x);     }     solv(l);     solv(r);   }   int main() {     int i, j;     T = read();     while (T--) {       sum = 0;       h = read(), g = read();       hs = (1 << h);       gs = (1 << g);       n = hs - gs;       for (i = 1; i <= hs - 1; i++) {         a[i] = read();         a[i + n] = a[i + 2 * n] = 0;         sum += a[i];       }       ans.clear();       solv(1);       printf( %lld n , sum);       for (i = 0; i < ans.size(); i++) {         printf( %d  , ans[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int v[1100];   int pd[1100][1 << 8];   int qtd1, qtd2;   int vis[1100][1 << 8];   int inv[1100];   vector<int> pos[10];   bool check(int mask) {     for (int i = 0; i < 8; ++i) {       if (mask & (1 << i)) continue;       if (qtd1) return false;     }     return true;   }   int f(int x, int mask) {     if (x >= n) {       if (check(mask))         return 0;       else         return -0x3F3F3F3F;     }     int &p = pd[x][mask];     if (vis[x][mask] < qtd2) {       vis[x][mask] = qtd2;       p = f(x + 1, mask);       if (!(mask & (1 << v[x]))) {         int fim, qtd;         qtd = pos[v[x]].size() - inv[x];         if (qtd1 && qtd >= qtd1) {           fim = pos[v[x]][inv[x] + qtd1 - 1] + 1;           p = max(p, f(fim, mask | (1 << v[x])) + qtd1);         }         qtd = pos[v[x]].size() - inv[x];         if (qtd >= qtd2) {           fim = pos[v[x]][inv[x] + qtd2 - 1] + 1;           p = max(p, f(fim, mask | (1 << v[x])) + qtd2);         }       }     }     return p;   }   int main() {     int ans = 1;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &v[i]);       v[i]--;       inv[i] = (int)pos[v[i]].size();       pos[v[i]].push_back(i);     }     for (int i = 0; i < n; ++i) {       qtd1 = i, qtd2 = i + 1;       ans = max(ans, f(0, 0));     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   bool a[100000 << 1];   int b[100000 << 1], c[100000 << 1], h[100000], n, m, i, x, y;   int go(int k) {     int i, t, x = -1;     for (i = h[k]; ~i; i = b[i])       if (!a[i]) {         a[i] = 1, a[i >= m ? i - m : i + m] = 1;         t = go(c[i]);         if (~t)           printf( %d %d %d n , k + 1, c[i] + 1, t + 1);         else if (~x)           printf( %d %d %d n , x + 1, k + 1, c[i] + 1), x = -1;         else           x = c[i];       }     return ~x ? x : -1;   }   int main() {     scanf( %d%d , &n, &m);     if (m & 1) {       puts( No solution );       return 0;     }     for (i = 0; i < m * 2; i++) c[i] = -1;     for (i = 0; i < n; i++) h[i] = -1;     for (i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       --x, --y;       b[i] = h[x];       c[i] = y;       h[x] = i;       b[i + m] = h[y];       c[i + m] = x;       h[y] = i + m;     }     go(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... second>   void dbs(string str, T t, second... s) {     int idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  ,  ;     dbs(str.substr(idx + 1), s...);   }   template <class second, class T>   ostream& operator<<(ostream& os, const pair<second, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   const int N = 2020;   long long first[N][N];   long long G[N][N];   string s;   long long g(int n, int k);   long long f(int n, int k) {     if (k < 0) return 0;     if (n == 0) return k == 0;     long long& ans = first[n][k];     if (ans != -1) return ans;     ans = 0;     int ch = s[int(s.size()) - n] -  a ;     ans = ch * f(n - 1, k) + (25 - ch) * f(n - 1, k - n) + g(n - 1, k) + (k == 0);     int nk = k;     for (int i = 1; i <= n - 1; ++i) {       int ch = s[int(s.size()) - n + i] -  a ;       nk = k - (i + 1) * (n - i);       if (nk < 0) {         for (int i = n - 1; i >= 1; --i) {           int ch = s[int(s.size()) - n + i] -  a ;           nk = k - (i + 1) * (n - i);           if (nk < 0) break;           ans += (25 - ch) * f(n - i - 1, nk);           ans %= inf;         }         break;       }       ans += (25 - ch) * f(n - i - 1, nk);       ans %= inf;     }     ans %= inf;     return ans;   }   long long g(int n, int k) {     if (k < 0) return 0;     if (n == 0) return 0;     long long& ans = G[n][k];     if (ans != -1) return ans;     int ch = s[int(s.size()) - n] -  a ;     ans = ch * f(n - 1, k) + g(n - 1, k);     ans %= inf;     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     memset(first, -1, sizeof first);     memset(G, -1, sizeof G);     cin >> s;     cout << f(n, k) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, g[505][505], f[505][505], tot[505], ans[505][505];   int main() {     scanf( %d%d , &n, &m);     memset(g, 0x3f, sizeof(g));     memset(f, 0x3f, sizeof(f));     for (int i = 1; i <= n; i++) f[i][i] = 0;     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       g[u][v] = g[v][u] = f[u][v] = f[v][u] = min(g[u][v], w);     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           f[i][j] = f[j][i] = min(f[i][j], f[i][k] + f[k][j]);     for (int i = 1; i <= n; i++) {       memset(tot, 0, sizeof(tot));       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           if (f[i][k] + g[k][j] == f[i][j]) tot[j]++;       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           if (f[i][k] + f[k][j] == f[i][j]) ans[i][j] += tot[k];     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         if (i == j) continue;         if (f[i][j] >= 0x3f3f3f3f - 100) ans[i][j] = 0;         printf( %d  , ans[i][j]);       }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &a) {     a = 0;     int c = getchar(), b = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) b = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) a = (a << 3) + (a << 1) + c - 48, c = getchar();     a *= b;   }   inline int Rem() {     int a = 0, c = getchar(), b = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) b = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) a = (a << 3) + (a << 1) + c - 48, c = getchar();     return a *= b;   }   inline void write(long long x) {     if (x > 9) write(x / 10);     putchar( 0  + x % 10);   }   inline void W(long long x) {     if (x < 0) {       putchar( - ), x = -x;     }     write(x);   }   const int N = 2e5 + 5, M = 1e6 + 5;   int n, m, a[N], pos[N], block;   long long ans, rec[N], cnt[M];   struct node {     int l, r, id;   } q[N];   inline bool cmp(node a, node b) {     return (pos[a.l] == pos[b.l]) ? (pos[a.l] & 1 ? a.r < b.r : a.r > b.r)                                   : a.l < b.l;   }   inline void add(int x) {     cnt[x]++;     ans += ((cnt[x] * cnt[x]) - ((cnt[x] - 1) * (cnt[x] - 1))) * x;   }   inline void del(int x) {     ans -= ((cnt[x] * cnt[x]) - ((cnt[x] - 1) * (cnt[x] - 1))) * x;     cnt[x]--;   }   int main() {     read(n);     read(m);     block = sqrt(n);     for (register int i = 1; i <= n; i++) read(a[i]), pos[i] = i / block;     for (register int i = 1; i <= m; i++) {       read(q[i].l);       read(q[i].r);       q[i].id = i;     }     sort(q + 1, q + 1 + m, cmp);     for (register int i = 1, ql, qr, l = 1, r = 0; i <= m; i++) {       ql = q[i].l, qr = q[i].r;       while (ql < l) add(a[--l]);       while (ql > l) del(a[l++]);       while (qr < r) del(a[r--]);       while (qr > r) add(a[++r]);       rec[q[i].id] = ans;     }     for (register int i = 1; i <= m; i++) W(rec[i]), putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10, pi = 3.1415926535898;   const int mod = 998244353, maxn = 2e5 + 10;   int T, n, m, k, x, y, a[maxn], p, b;   long long fac[maxn] = {1, 1}, inv[maxn] = {1, 1}, inv_fac[maxn] = {1, 1};   char st[maxn];   void init() {     for (int i = 2; i < maxn; ++i) {       fac[i] = fac[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       inv_fac[i] = inv_fac[i - 1] * inv[i] % mod;     }   }   long long C(long long n, long long m) {     if (m < 0 || n < 0 || n < m) return 0;     return fac[n] * inv_fac[n - m] % mod * inv_fac[m] % mod;   }   int main(int argc, char const *argv[]) {     init();     scanf( %d %d , &n, &m);     if (n == 2) {       printf( 0 n );       return 0;     }     long long ans = 0, cnt = 0;     for (int i = n - 2; i <= m - 1; ++i) {       cnt += C(i, n - 2);     }     cnt %= mod;     for (int i = 2; i <= n - 1; ++i) {       long long cc = cnt;       cc = cc * C(n - 3, i - 2) % mod * (n - 2) % mod;       ans += cc;     }     cout << ans % mod << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, str;     int n, cont = 0, ca = 0, cb = 0;     cin >> a >> b;     n = a.size();     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) cont++;     }     if (cont % 2 == 0) {       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) {           if (ca > cb)             cb++, str += b[i];           else             ca++, str += a[i];         } else           str += a[i];       }       cout << str << endl;     } else       printf( impossible n );   }
#include <bits/stdc++.h>   using namespace std;   inline void input(long long &x) {     long long y = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) y = -1;       c = getchar();     }     x = 0;     while (c >=  0  && c <=  9 ) {       x = x * 10 + (c -  0 );       c = getchar();     }     x = x * y;   }   const long long inf = 1e18;   long long f, t, temp, a1, cnt, p1, a2, now, p2, resf, rest;   long long ans = inf;   signed main() {     input(f);     input(t);     input(temp);     input(a1);     input(cnt);     input(p1);     input(a2);     input(now);     input(p2);     if (cnt > now) {       swap(a1, a2);       swap(p1, p2);       swap(cnt, now);     }     for (register long long i = 0; (i - 1) * a1 <= f; ++i) {       resf = f - min(i * a1, f);       rest = t - min(i * a1, f) * cnt;       if (!resf) {         if (rest < 0) break;         ans = min(ans, i * p1);         break;       }       if (temp * resf > rest && now * resf > rest) continue;       if (temp * resf <= rest)         ans = min(ans, i * p1);       else {         long long x, pk;         if ((rest - temp * resf) % (now - temp) == 0)           x = (rest - temp * resf) / (now - temp) + 0;         else           x = (rest - temp * resf) / (now - temp) + 1;         if (x % a2 == 0)           pk = (x / a2) + 0;         else           pk = (x / a2) + 1;         ans = min(ans, pk * p2 + i * p1);       }     }     ans = max(ans, 0ll);     if (ans < inf)       printf( %lld n , ans);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 10;   int n, cnt = 0;   string a, b;   void check(string a, string b) {     int p = 0;     for (; p < ((int)(a).size()) && a[p] == b[p]; ++p)       ;     if (a.substr(0, p) == b.substr(0, p) && a.substr(p) == b.substr(p + 1)) ++cnt;   }   int main() {     cin >> n >> a >> b;     int p = 0;     for (; a[p] == b[p]; ++p)       ;     if (a.substr(0, p) == b.substr(0, p) && a.substr(p + 1) == b.substr(p + 1))       puts( 2 ), exit(0);     check(b.substr(p + 1), a.substr(p));     check(a.substr(p + 1), b.substr(p));     cout << cnt << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>      using namespace std;   typedef long long ll;   ll a[200009],n,p;   bool vis[200009][2];   pair <ll,ll> g[200009];   int main()   {       ios::sync_with_stdio(0);       int t;       cin>>t;       while(t--)       {           cin>>n>>p;           ll ans=0;           for(int i=1;i<=n;i++)           {               cin>>a[i];               vis[i][0]=vis[i][1]=0;               g[i]=make_pair(a[i],i);           }           vis[1][0]=vis[n][1]=1;         sort(g+1,g+n+1);         for(int i=1;i<=n;i++)         {             int w=g[i].second;             if(a[w]>p)break;             int l,r;             l=r=w;             while(!vis[l][0]&&(a[l-1]%a[w]==0))l--;             while(!vis[r][1]&&(a[r+1]%a[w]==0))r++;             ans+=(r-l)*a[w];             if(l!=r){vis[l][1]=vis[r][0]=1;}             for(int h=l+1;h<r;h++)vis[h][0]=vis[h][1]=1;               }           for(int i=1;i<=n;i++)if(!vis[i][1])ans+=p;        cout<<ans<<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {     fin >> pr.first >> pr.second;     return fin;   }   template <class T0, class T1, class T2>   inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {     fin >> get<0>(t) >> get<1>(t) >> get<2>(t);     return fin;   }   template <class T>   inline istream& operator>>(istream& fin, vector<T>& a) {     for (auto& u : a) fin >> u;     return fin;   }   template <class T, size_t n>   inline istream& operator>>(istream& fin, array<T, n>& a) {     for (auto& u : a) fin >> u;     return fin;   }   int f542() {     size_t n, time;     cin >> n >> time;     typedef struct {       size_t buf, val;     } value_t;     const auto comp = [](const value_t& a, const value_t& b) {       return a.buf < b.buf || (a.buf == b.buf && a.val < b.val);     };     priority_queue<value_t, vector<value_t>, decltype(comp)> heap(comp);     for (size_t i = 0; i < n; ++i) {       size_t val, lag;       cin >> lag >> val;       if (lag < time + 1) heap.push({time - lag, val});     }     size_t val = 0;     while (!heap.empty()) {       const auto top = heap.top();       heap.pop();       if (top.buf == 0 || heap.empty())         val = max(val, top.val);       else {         const auto next = heap.top();         if (top.buf != next.buf)           heap.push({next.buf, top.val});         else {           heap.pop();           heap.push({top.buf - 1, top.val + next.val});         }       }     }     return val;   }   int main(const int argc, char* argv[]) {     cout << f542();     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, r;     cin >> n >> r;     vector<double> a(1 << n);     double sum = 0, div = (double)(1 << n);     for (int i = 0; i < (1 << n); i++) {       int x;       cin >> x;       a[i] = (double)x;       sum += a[i];     }     double ans = sum / div;     cout << setprecision(7) << fixed << ans <<   n ;     while (r--) {       int z, g;       cin >> z >> g;       double gg = (double)g;       sum += (gg - a[z]);       a[z] = gg;       ans = sum / div;       cout << setprecision(7) << fixed << ans <<   n ;     }     return 0;   }