malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int fa[101000][20], h[101000], lev[101000], ans[101000];   int dp[101000];   struct EDGE {     int to, nxt;   } box[2 * 101000];   int top, K;   void add(int u, int v) {     box[top].to = v;     box[top].nxt = h[u];     h[u] = top++;   }   void DFS(int u, int pre, int t) {     lev[u] = lev[pre] + 1;     fa[u][0] = pre;     if (!t)       for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];     for (int p = h[u]; p != -1; p = box[p].nxt) {       int v = box[p].to;       if (pre == v) continue;       DFS(v, u, t);       if (t) {         dp[u] += dp[v];         ans[p / 2] = dp[v];       }     }   }   int lca(int u, int v) {     if (lev[u] < lev[v]) swap(u, v);     int c = lev[u] - lev[v];     for (int i = 19; i >= 0; i--) {       if (c & (1 << i)) {         u = fa[u][i];         c -= (1 << i);       }     }     if (u == v) return u;     for (int i = 19; i >= 0; i--) {       if (fa[u][i] != fa[v][i]) {         u = fa[u][i];         v = fa[v][i];       }     }     return fa[u][0];   }   int main() {     int n, k;     int a, b;     scanf( %d , &n);     memset(h, -1, sizeof(h));     for (int i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       add(a, b);       add(b, a);     }     DFS(1, 1, 0);     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d%d , &a, &b);       int c = lca(a, b);       dp[a]++;       dp[b]++;       dp[c] -= 2;     }     DFS(1, 1, 1);     for (int i = 0; i < n - 1; i++) {       printf( %d%c , ans[i], i == n - 2 ?   n  :    );     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long extgcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long x1, y1;     long long d = extgcd(b, a % b, x1, y1);     x = y1;     y = x1 - y1 * (a / b);     return d;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   long long divide(long long a, long long b) {     return (a % 1000000007) * powm(b, 1000000007 - 2) % 1000000007;   }   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long add(long long a, long long b) {     return (a % 1000000007 + b % 1000000007) % 1000000007;   }   long long Totfun(long long n) {     long long z = n;     if (n % 2 == 0) {       while (n % 2 == 0) {         n /= 2;       }       z /= 2;     }     for (long long i = 3; i <= sqrt(n); i += 2) {       if (isPrime(i) && n % i == 0) {         while (n % i == 0) {           n /= i;         }         z -= z / i;       }     }     if (n > 1) {       z -= z / n;     }     return z;   }   long long fact[100001];   long long nCr(long long n, long long r) {     if (r > n || r < 0) return 0;     long long z = fact[n];     z = mul(z, powm(fact[n - r], 1000000007 - 2));     z = mul(z, powm(fact[r], 1000000007 - 2));     return z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, a = 0, b = 0, c = 0, z = 1;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < n; i++) {       if (s[i] ==  a )         a = add(a, z);       else if (s[i] ==  b )         b = add(b, a);       else if (s[i] ==  c )         c = add(c, b);       else {         c = add(3 * c, b);         b = add(3 * b, a);         a = add(3 * a, z);         z = mul(z, 3);       }     }     cout << c <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, ar[100001], max_s[100001], max_e[100001], pre_s[100001],       pre_e[100001], ans = INT_MIN;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> ar[i];     for (int i = 1; i < n; i++) pre_s[i] = pre_s[i - 1] + ar[i - 1];     for (int i = n - 2; i >= 0; i--) pre_e[i] = pre_e[i + 1] + ar[i + 1];     max_e[n - 1] = abs(ar[n - 1]);     max_s[0] = abs(ar[0]);     for (int i = n - 2; i >= 0; i--)       max_e[i] = max(ar[i] + max_e[i + 1], -(ar[i] + pre_e[i]));     for (int i = 1; i < n; i++)       max_s[i] = max(ar[i] + max_s[i - 1], -(ar[i] + pre_s[i]));     ans = max(ans, max_e[0]);     ans = max(ans, max_s[n - 1]);     for (int i = 0; i < n - 1; i++) ans = max(ans, max_s[i] + max_e[i + 1]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996);   long long int n, h[1000007], d[1000007][2], mod = 1e9 + 7;   void solve() {     long long int i, j;     cin >> n;     for (i = 0; i < n; i++) {       cin >> h[i];       h[i] -= 1;     }     h[n] = 0;     d[0][0] = max((long long int)0, h[0] - h[1]);     d[0][1] = min(h[0], h[1]);     for (i = 1; i < n; i++) {       long long int k = min(h[i - 1], h[i]);       d[i][0] = d[i - 1][1] * max((long long int)0, k - h[i + 1]);       d[i][0] %= mod;       d[i][0] = (d[i][0] + max((long long int)0, h[i] - h[i + 1])) % mod;       d[i][1] = d[i - 1][1] * min(h[i + 1], k);       d[i][1] %= mod;       d[i][1] = (d[i][1] + min(h[i], h[i + 1])) % mod;     }     long long int ans = 0;     for (i = 0; i < n; i++) {       ans = (ans + d[i][0] + d[i][1]) % mod;     }     cout << ans;   }   int main() {   #pragma comment(linker,  /STACK:1073741824      solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int setBit(int n, int pos) { return n | (1 << pos); }   int resetBit(int n, int pos) { return n & ~(1 << pos); }   bool checkBit(int n, int pos) { return n & (1 << pos); }   inline long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     while (e > 0) {       if (e % 2) ret = (ret * p) % M;       p = (p * p) % M;       e /= 2;     }     return ret;   }   inline long long power(long long x, long long y) {     long long ans = 1;     while (y > 0) {       if (y % 2) ans *= x;       x *= x;       y /= 2;     }     return ans;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   int n, k, a, b, c, d;   int vis[1003];   int main() {     cin >> n >> k >> a >> b >> c >> d;     if (k < n + 1 || n == 4) {       cout << -1;       return 0;     }     vis[a] = vis[b] = vis[c] = vis[d] = 1;     printf( %d %d  , a, c);     for (int i = 1; i <= n; i++) {       if (vis[i] == 0) {         printf( %d  , i);       }     }     printf( %d %d n , d, b);     printf( %d %d  , c, a);     for (int i = 1; i <= n; i++) {       if (vis[i] == 0) {         printf( %d  , i);       }     }     printf( %d %d , b, d);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx )   using namespace std;   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , aa + i);     }     for (int i = 2; i <= n; ++i) {       scanf( %d , fa + i);       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];     }     for (int i = 1; i <= q; ++i) {       int x;       scanf( %d , &x);       int y = siz[x];       x = fp[x];       int pp = i + 1, gg = y >> 3, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j ^ gg; ++j, jj += 8, diao += 8, aa += 8) {         if (jj[0] < pp) ans += diao[0], jj[0] = i + aa[0], ++cnt;         if (jj[1] < pp) ans += diao[1], jj[1] = i + aa[1], ++cnt;         if (jj[2] < pp) ans += diao[2], jj[2] = i + aa[2], ++cnt;         if (jj[3] < pp) ans += diao[3], jj[3] = i + aa[3], ++cnt;         if (jj[4] < pp) ans += diao[4], jj[4] = i + aa[4], ++cnt;         if (jj[5] < pp) ans += diao[5], jj[5] = i + aa[5], ++cnt;         if (jj[6] < pp) ans += diao[6], jj[6] = i + aa[6], ++cnt;         if (jj[7] < pp) ans += diao[7], jj[7] = i + aa[7], ++cnt;       }       gg <<= 3;       for (int j = gg; j < y; ++j) {         if (jj[j - gg] < pp)           ans += diao[j - gg], jj[j - gg] = i + aa[j - gg], ++cnt;         ;       }       ans = ans - cnt * dd[x];       printf( %d %d n , ans, cnt);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     for (int i = 1; i <= 1000000000; i++) {       if (i % 2 == 1) {         if (a >= i) {           a -= i;         } else {           cout <<  Vladik ;           return 0;         }       } else {         if (b >= i) {           b -= i;         } else {           cout <<  Valera ;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int f[4005][4005];   int a[4005];   int main() {     int i, j, k, n, m = 0;     memset(f, 0, sizeof(f));     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       k = 0;       for (j = 0; j < i; j++) {         f[i][j] = f[j][k] + 1;         if (a[j] == a[i]) {           k = j;         }         m = max(m, f[i][j]);       }     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline long long mnz(long long& a, long long b) { return a = (a > b ? b : a); }   inline long long mxz(long long& a, long long b) { return a = (a < b ? b : a); }   inline string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   double const eps = 1e-6;   long long const Base = 1e9 + 7, oo = 1e17, MAXN = 1e6;   long long A[MAXN + 5];   vector<long long> dske[MAXN + 5];   bitset<MAXN + 5> bi;   long long Solves() {     long long n, m, k, cnt = 0, ans = 0, x = -1, y = -1, q, c, sum = 0, v, t = -1;     cin >> n;     for (long long i = 1; i <= n; i++) dske[i].clear(), bi[i] = 0;     for (long long i = 1; i <= n; i++) {       cin >> k;       c = 0;       while (k--) {         cin >> x;         if (!bi[x] and !c) c = x;       }       if (c)         bi[c] = 1;       else         y = i;     }     if (y == -1) return cout <<  OPTIMAL  << endl, 0;     vector<long long> vec;     for (long long i = 1; i <= n; i++)       if (!bi[i]) vec.push_back(i);     map<long long, long long> mm;     for (long long i = 0; i < dske[y].size(); i++) mm[dske[y][i]] = 1;     for (long long i = 0; i < vec.size(); i++) {       if (!mm[vec[i]]) {         cout <<  IMPROVE  << endl;         cout << y <<     << vec[i] << endl;         return 0;       }     }     assert(0);     return 0;   }   int main() {     if (fopen( locin.txt ,  r )) freopen( locin.txt ,  r , stdin);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long test = 1;     cin >> test;     for (long long T = 1; T <= test; T++) {       Solves();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<string> res;     for (int i = 0; i < t; ++i) {       long long int a, b;       cin >> a >> b;       if (a > b) swap(a, b);       if ((a + b) % 3 == 0 && 2 * a >= b)         res.push_back( YES );       else         res.push_back( NO );     }     for (int i = 0; i < t; ++i) {       cout << res[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10;   map<char, int> d, t;   string s;   string know[MAXN];   int pd[MAXN];   int n, m, ans, q, x;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] !=  * ) x++;     }     if (x == s.size()) {       cout <<  0  << endl;       return 0;     }     for (int i = 0; i < s.size(); i++) d[s[i]]++;     cin >> m;     for (int i = 1; i <= m; i++) cin >> know[i];     for (int i = 1; i <= m; i++) {       int cnt = 0, z = 0;       memset(pd, 0, sizeof(pd));       for (int j = 0; j < know[i].size(); j++) {         if (s[j] !=  *  && s[j] != know[i][j]) {           z = 1;           break;         }       }       if (z) {         q++;         continue;       }       for (int j = 0; j < know[i].size(); j++) {         if (d[know[i][j]] && s[j] ==  * ) {           z = 1;           break;         }       }       if (z) {         q++;         continue;       }       for (int j = 0; j < know[i].size(); j++) {         if (!pd[know[i][j] -  a ] && !d[know[i][j]]) {           pd[know[i][j] -  a ] = 1;           t[know[i][j]]++;           z = 1;         }       }       if (!z) q++;     }     for (int i = 0; i <= 25; i++) {       char k =  a  + i;       if (!d[k] && t[k] == m - q && t[k]) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     int c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m, b = 0;     cin >> n >> m;     vector<vector<int> > arr(n, vector<int>(4, 0));     for (int i = 0; i < n; i++) {       if (b < m) {         b++;         arr[i][0] = b;       }       if (b < m) {         b++;         arr[i][3] = b;       }     }     for (int i = 0; i < n; i++) {       if (b < m) {         b++;         arr[i][1] = b;       }       if (b < m) {         b++;         arr[i][2] = b;       }     }     for (int i = 0; i < n; i++) {       if (arr[i][1] != 0) cout << arr[i][1] <<    ;       if (arr[i][0] != 0) cout << arr[i][0] <<    ;       if (arr[i][2] != 0) cout << arr[i][2] <<    ;       if (arr[i][3] != 0) cout << arr[i][3] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1001], b[1001], c[1001], d[1001];   int ans[2][1001];   int main() {     int n, m, c0, d0;     cin >> n >> m >> c0 >> d0;     for (int i = 0; i < m; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];     ans[0][0] = 0;     for (int i = 1; i <= n; ++i) {       ans[0][i] = ans[0][i - 1];       if (i >= c0) ans[0][i] = max(ans[0][i - 1], ans[0][i - c0] + d0);     }     for (int j = 0; j < m; ++j) {       ans[1][0] = ans[0][0];       for (int i = 1; i <= n; ++i) {         ans[1][i] = max(ans[1][i - 1], ans[0][i]);         for (int t = 0; t <= a[j] / b[j] && t * c[j] <= i; ++t)           ans[1][i] = max(ans[1][i], ans[0][i - t * c[j]] + t * d[j]);       }       for (int i = 0; i <= n; ++i) {         ans[0][i] = ans[1][i];       }     }     cout << ans[0][n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ld = long double;   using ll = long long;   using ull = unsigned long long;   const int INF = 1 << 30;   const ll LINF = 1LL << 60;   const int SZ = 1 << 13;   char buff[SZ], *pos = buff + SZ - 1;   inline ll read() {     ll x = 0;     int f = 1,         c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos);     for (; !isdigit(c);          c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))       if (c ==  - ) f = -f;     for (; isdigit(c);          c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))       x = (x << 3) + (x << 1) + (c ^ 48);     return x * f;   }   const int N = 5005;   int n;   int T;   int t[N];   ld p[N], pw[N];   ld dp[2][N];   int main() {     cout << fixed << setprecision(9);     n = read(), T = read();     for (int i = 1; i <= n; ++i)       p[i] = read() / 100.0, t[i] = read(), pw[i] = pow(1 - p[i], t[i] - 1);     ld ans = 0;     dp[0][0] = 1;     int pp = 0, qq = 1;     for (int i = 1; i <= n; ++i) {       ld sum = 0;       for (int j = 1; j <= T; ++j) {         sum = sum * (1 - p[i]) + dp[pp][j - 1];         if (j >= t[i]) sum -= dp[pp][j - t[i]] * pw[i];         dp[qq][j] = sum * p[i];         if (j >= t[i]) dp[qq][j] += dp[pp][j - t[i]] * pw[i];         ans += dp[qq][j];       }       swap(pp, qq);       memset(dp[qq], 0, sizeof dp[qq]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200002;   vector<vector<pair<int, int> > > ans;   vector<vector<int> > cs, twoCs, threeCs;   int n, p[N];   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     bool mark[N] = {};     for (int i = 1; i <= n; i++)       if (!mark[i] && p[i] != i) {         vector<int> newC;         int v = i;         while (!mark[v]) {           mark[v] = 1;           newC.push_back(v);           v = p[v];         }         cs.push_back(newC);       }     for (int i = 0; i < cs.size(); i++)       while (cs[i].size() >= 4) {         vector<pair<int, int> > move;         for (int j = max(0, (int)cs[i].size() - 5); j + 1 < cs[i].size(); j++)           move.push_back(make_pair(cs[i][j], cs[i][j + 1]));         move.push_back(             make_pair(cs[i].back(), cs[i][max((int)cs[i].size() - 5, 0)]));         ans.push_back(move);         for (int j = 0; j < 4; j++) cs[i].pop_back();       }     for (int i = 0; i < cs.size(); i++)       if (cs[i].size() == 2)         twoCs.push_back(cs[i]);       else if (cs[i].size() == 3)         threeCs.push_back(cs[i]);     while (threeCs.size()) {       vector<pair<int, int> > move;       vector<int> &tt = threeCs.back();       move.push_back(make_pair(tt[0], tt[1]));       move.push_back(make_pair(tt[1], tt[2]));       move.push_back(make_pair(tt[2], tt[0]));       threeCs.pop_back();       if (twoCs.size()) {         tt = twoCs.back();         move.push_back(make_pair(tt[0], tt[1]));         move.push_back(make_pair(tt[1], tt[0]));         twoCs.pop_back();       } else if (threeCs.size()) {         tt = threeCs.back();         move.push_back(make_pair(tt[0], tt[1]));         move.push_back(make_pair(tt[1], tt[0]));         vector<int> newC;         newC.push_back(tt[0]);         newC.push_back(tt[2]);         twoCs.push_back(newC);         threeCs.pop_back();       }       ans.push_back(move);     }     while (twoCs.size()) {       vector<pair<int, int> > move;       vector<int> &tt = twoCs.back();       move.push_back(make_pair(tt[0], tt[1]));       move.push_back(make_pair(tt[1], tt[0]));       twoCs.pop_back();       if (twoCs.size()) {         tt = twoCs.back();         move.push_back(make_pair(tt[0], tt[1]));         move.push_back(make_pair(tt[1], tt[0]));         twoCs.pop_back();       }       ans.push_back(move);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].size() << endl;       for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j].first <<    ;       cout << endl;       for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j].second <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   const int N = 550;   using namespace std;   int n;   int m;   int k;   long long d[N][N][2];   long long cost[N][N];   vector<pair<int, long long> > R[N][N];   vector<pair<int, long long> > D[N][N];   vector<pair<int, long long> > nv;   void normal(vector<pair<int, long long> > &v) {     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = 1; i < v.size(); i++) {       v[i].second += v[i - 1].second;     }   }   void upd(long long &x, long long y) { x = min(x, y); }   bool good(vector<pair<int, int> > &g, int i, int t) {     int cur = g[i].first + g[i].second;     if (cur >= t && (cur - t) % 4 == i) {       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     scanf( %d%d%d , &n, &m, &k);     vector<pair<int, int> > g;     for (int i = 1, x, y, d, t, e; i <= k; i++) {       scanf( %d%d%d%d%d , &x, &y, &d, &t, &e);       g.clear();       g.push_back({x, y});       g.push_back({x + d, y - d});       g.push_back({x + d, y});       g.push_back({x, y + d});       for (int i = 0; i < 4; i++) {         if (good(g, i, t)) {           cost[g[i].first][g[i].second] += e;         }       }       if (good(g, 0, t) && good(g, 3, t)) {         R[g[3].first][g[3].second].push_back({g[0].second, e});       }       if (good(g, 0, t) && good(g, 2, t)) {         D[g[2].first][g[2].second].push_back({g[0].first, e});       }       if (good(g, 1, t) && good(g, 2, t)) {         R[g[2].first][g[2].second].push_back({g[1].second, e});       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         normal(R[i][j]);         normal(D[i][j]);       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         d[i][j][0] = 1e18;         d[i][j][1] = 1e18;       }     }     d[0][0][0] = 0;     d[0][0][1] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         long long cnt = d[i][j][1];         for (int h = j + 1; h < m; h++) {           while (!R[i][h].empty() && R[i][h].back().first < j) {             R[i][h].pop_back();           }           if (!R[i][h].empty()) {             cnt -= R[i][h].back().second;           }           cnt += cost[i][h];           upd(d[i][h][0], cnt);         }         cnt = d[i][j][0];         for (int h = i + 1; h < n; h++) {           while (!D[h][j].empty() && D[h][j].back().first < i) {             D[h][j].pop_back();           }           if (!D[h][j].empty()) {             cnt -= D[h][j].back().second;           }           cnt += cost[h][j];           upd(d[h][j][1], cnt);         }       }     }     printf( %lld n , min(d[n - 1][m - 1][0], d[n - 1][m - 1][1]) + cost[0][0]);   }
#include <bits/stdc++.h>   using namespace std;   long long n, _C;   long long lo, hi;   set<long long> S;   vector<long long> vec;   int actual;   long long offset;   void ask(long long x) {     S.insert(x);     vec.emplace_back(x);     if (actual) cout <<  ?   << x <<   n ;     if (actual)       cin >> x;     else       x = abs(vec[(int)vec.size() - 2] - vec.back()) >= _C;     if ((int)vec.size() > 1) {       long long d = abs(vec[(int)vec.size() - 2] - vec.back());       if (x)         hi = min(hi, d);       else         lo = max(lo, d + 1);     }   }   long long solve() {     vec.clear();     S.clear();     lo = 1;     hi = n;     long long cur = offset;     ask(cur);     while (lo < hi) {       long long mid = (lo + hi) / 2;       int p1 = (lo & 1);       int p2 = (hi & 1);       if ((lo & 1) == (hi & 1)) mid--;       if ((int)S.size() & 1)         ask(vec.back() - mid);       else         ask(vec.back() + mid);     }     if (actual) cout <<  =   << lo <<   n ;     return *S.begin();   }   int main() {     ios_base::sync_with_stdio(0);     int itest;     cin >> itest;     while (itest--) {       cin >> n;       offset = 0;       _C = n;       actual = 0;       offset = 1 - solve();       actual = 1;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n;     cin >> t;     while (t--) {       long long x;       double sum = 0;       cin >> n >> x;       vector<long long> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];         sum += v[i];       }       sort(v.begin(), v.end());       int ans = sum / n >= x ? n : 0;       double subSum = 0;       for (int i = 0; i < n and !ans; i++) {         subSum += v[i];         if ((sum - subSum) / (n - (i + 1)) >= x) {           ans = n - (i + 1);           break;         }       }       cout << ans <<   n ;     }     return 0;   }