malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(1919810);   int T, n, K, zr;   inline char qry(int la, int ra, int lb, int rb) {     cout <<  ?   << ra - la + 1 <<     << rb - lb + 1 << endl;     for (int i = la; i <= ra; i++) cout << i << (i == ra ?   n  :    );     for (int i = lb; i <= rb; i++) cout << i << (i == rb ?   n  :    );     fflush(stdout);     char c[15];     return scanf( %s , c), *c;   }   inline char blck1() {     for (int i = 2; i <= n; i++)       if (qry(1, 1, i, i) ==  S ) return 1;     return 0;   }   inline char rdck1() {     for (int i = 1, x = rnd() % (n - 1) + 2; i <= 30;          i++, x = rnd() % (n - 1) + 2)       if (qry(1, 1, x, x) ==  S ) return 1;     return 0;   }   inline void work(int l, int r) {     int md = (l + r) >> 1;     if (l == r) return printf( ! %d n , l), void();     if (qry(1, md - l + 1, l, md) ==  E )       return work(md + 1, r);     else       return work(l, md);   }   inline void solve() {     cin >> n >> K;     if ((n <= 30 && blck1()) || (n > 30 && rdck1())) return puts( ! 1 ), void();     for (int i = 1; i <= n; i <<= 1)       if (qry(1, min(i, n - i), i + 1, min(i << 1, n)) !=  E )         return work(i + 1, min(i << 1, n));   }   int main() {     for (cin >> T; T--;) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename float_t>   struct _complex_ {     float_t x, y;     _complex_<float_t>(float_t _x = 0, float_t _y = 0) : x(_x), y(_y) {}     float_t real() const { return x; }     void real(float_t _x) { x = _x; }     float_t imag() const { return y; }     void imag(float_t _y) { y = _y; }     _complex_<float_t> &operator+=(const _complex_<float_t> &other) {       x += other.x;       y += other.y;       return *this;     }     _complex_<float_t> &operator-=(const _complex_<float_t> &other) {       x -= other.x;       y -= other.y;       return *this;     }     _complex_<float_t> operator+(const _complex_<float_t> &other) const {       return _complex_<float_t>(*this) += other;     }     _complex_<float_t> operator-(const _complex_<float_t> &other) const {       return _complex_<float_t>(*this) -= other;     }     _complex_<float_t> operator*(const _complex_<float_t> &other) const {       return {x * other.x - y * other.y, x * other.y + other.x * y};     }     _complex_<float_t> operator*(float_t mult) const {       return {x * mult, y * mult};     }   };   template <typename float_t>   _complex_<float_t> conj(const _complex_<float_t> &c) {     return {c.x, -c.y};   }   template <typename float_t>   _complex_<float_t> polar(float_t magnitude, float_t angle) {     return {magnitude * cos(angle), magnitude * sin(angle)};   }   template <typename float_t>   ostream &operator<<(ostream &stream, const _complex_<float_t> &c) {     return stream <<  (  << c.x <<  ,   << c.y <<  ) ;   }   const int mod = 1e9 + 7;   const long long inf = 9223372036854775807;   struct query {     int y, pos, type;     query(int a, int b, int c) { y = a, pos = b, type = c; }   };   bool query_sort(const query &a, const query &b) {     if ((a.y ^ b.y)) {       return (a.y < b.y);     }     return (a.pos ^ b.pos) ? (a.pos < b.pos) : (a.type < b.type);   }   int n, k;   int x_coor[300 * 100001], y_coor[300 * 100001], sorted_x[100001];   long long ans[100001];   map<int, int> pos;   signed main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> x_coor[i] >> y_coor[i];       sorted_x[i] = x_coor[i];     }     sort(sorted_x, sorted_x + n);     int oniichan = 0;     sorted_x[n] = mod;     for (int i = 0; i < n; ++i) {       if (sorted_x[i] ^ sorted_x[i + 1]) {         pos[sorted_x[i]] = oniichan + 1;         oniichan += min(sorted_x[i] + k, sorted_x[i + 1]) - sorted_x[i];       }     }     vector<query> q;     for (int i = 0; i < n; ++i) {       q.push_back(query(y_coor[i], pos[x_coor[i]], 1));       q.push_back(query(y_coor[i] + k, pos[x_coor[i]], -1));     }     sort((q).begin(), (q).end(), query_sort);     memset(x_coor, 0, sizeof(x_coor));     memset(y_coor, 0, sizeof(y_coor));     for (query &i : q) {       for (int j = i.pos; j < i.pos + k; ++j) {         ans[y_coor[j]] += i.y - x_coor[j];         y_coor[j] += i.type;         x_coor[j] = i.y;       }     }     for (int i = 1; i < n + 1; ++i) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   const int maxn = 4050;   const int maxsec = 86400;   vector<pair<int, int> > input;   int dp[maxn][maxn];   int main() {     int k, n;     scanf( %d , &n);     ;     scanf( %d , &k);     ;     int i, j;     int x, y;     for (i = 0; i < n; ++i) {       scanf( %d , &x);       ;       scanf( %d , &y);       ;       input.push_back(make_pair(x - 1, y));     }     if (k >= n) {       printf( %d n , maxsec);       ;       return 0;     }     sort(input.begin(), input.end());     int m = input.size();     dp[0][0] = input[0].first + input[0].second;     for (j = 1; j <= k; ++j) dp[0][j] = 0;     for (i = 1; i < m; ++i) {       dp[i][0] = max(input[i].first, dp[i - 1][0]) + input[i].second;       for (j = 1; j <= k; ++j) {         dp[i][j] = min(dp[i - 1][j - 1],                        max(dp[i - 1][j], input[i].first) + input[i].second);       }     }     int ans = input[k].first;     int wakeup;     for (i = 0; i < m; ++i)       for (j = 0; j <= k; ++j) {         if (i + k - j + 1 < m)           wakeup = input[i + k - j + 1].first;         else           wakeup = maxsec;         ans = max(ans, wakeup - dp[i][j]);       }     printf( %d n , ans);     ;     return 0;   }
#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(0);     int n, m, k, a, ans = 0;     std::cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       std::cin >> a;       if (a == 1) {         m--;         if (m == -1) {           m++;           ans++;         }       }       if (a == 2) {         if (k > 0)           k--;         else {           m--;           if (m == -1) {             m++;             ans++;           }         }       }     }     std::cout << ans++;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int row[5001] = {0};   int rowt[5001] = {0};   int col[5001] = {0};   int colt[5001] = {0};   int main() {     int n, m, k;     cin >> n >> m >> k;     int q, t, a;     for (int i = 1; i < k + 1; i++) {       cin >> q >> t >> a;       t--;       if (q == 1) {         row[t] = a;         rowt[t] = i;       }       if (q == 2) {         col[t] = a;         colt[t] = i;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (colt[j] > rowt[i])           cout << col[j] <<    ;         else           cout << row[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int Array[n];     for (int i = (int)0; i < (int)n; ++i) cin >> Array[i];     stable_sort(Array, Array + n);     int Sum = accumulate(Array, Array + n, 0, plus<int>());     int Middle = Sum / n;     vector<int> a(n, Middle);     int NewSum = Middle * n;     int Diff = n - (Sum - NewSum);     int Ans = 0;     for (int i = 0; i < n; ++i) {       if (i >= Diff) {         Ans += abs(Array[i] - (a[i] + 1));       } else {         Ans += abs(Array[i] - a[i]);       }     }     cout << Ans / 2;     return 0;   }
#include <bits/stdc++.h>   const double pi = 3.1415926535897;   using namespace std;   int main() {     string s;     cin >> s;     int counter = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  a ) counter++;     }     if (s.length() / 2 < counter)       cout << s.length();     else       cout << (counter - 1) * 2 + 1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   array<int, N> a;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     long long power = 1;     while (abs(power) < 1e15) {       map<long long, int> m;       m[0] = 1;       long long sum = 0ll;       for (int i = 0; i < n; i++) {         sum += a[i];         ans += m[sum - power];         m[sum]++;       }       power *= k;       if (power == 1) break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(int n, int k) {     int i;     for (i = 1; i <= 2 * k; ++i)       if (i & 1)         printf( %d %d  , 2 * i - 1, 2 * i);       else         printf( %d %d  , 2 * i, 2 * i - 1);     for (i = 4 * k + 1; i <= 2 * n; ++i) printf( %d  , i);     putchar(  n );   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     solve(n, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 8;   const int dxs[] = {2, 1, -1, -2, -2, -1, 1, 2};   const int dys[] = {-1, -2, -2, -1, 1, 2, 2, 1};   char s0[8], s1[8];   bool flds[N][N];   inline void readpos(char s[], int &x, int &y) {     x = s[0] -  a ;     y = s[1] -  1 ;   }   inline void setknight(int x, int y) {     for (int di = 0; di < 8; di++) {       int vx = x + dxs[di], vy = y + dys[di];       if (vx >= 0 && vx < N && vy >= 0 && vy < N) flds[vy][vx] = true;     }   }   int main() {     scanf( %s%s , s0, s1);     int rx, ry, kx, ky;     readpos(s0, rx, ry);     readpos(s1, kx, ky);     flds[ry][rx] = flds[ky][kx] = true;     for (int x = 0; x < N; x++) flds[ry][x] = true;     for (int y = 0; y < N; y++) flds[y][rx] = true;     setknight(kx, ky);     setknight(rx, ry);     int cnt = 0;     for (int y = 0; y < N; y++)       for (int x = 0; x < N; x++)         if (!flds[y][x]) cnt++;     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     if ((x == n / 2 || x == n / 2 + 1) && (y == n / 2 || y == n / 2 + 1))       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }
#include <bits/stdc++.h>   const int MAXINT = 2147483640;   const long long MAXLL = 9223372036854775800LL;   const long long MAXN = 1000000;   const double pi = 3.1415926535897932384626433832795;   using namespace std;   double s, v1, v2;   long long n, kol;   long long check(double xx) {     long long sum = 0;     double anstime = 0, vk, s1, s2, tin, s3;     while (1) {       s3 = s - v1 * anstime;       vk = (s3 - (xx - anstime) * v1) / (v2 - v1);       anstime += vk;       sum += kol;       if (sum >= n) break;       s2 = vk * v2 + (anstime - vk) * v1;       s1 = anstime * v1;       tin = (s2 - s1) / (v1 + v2);       anstime += tin;       if (anstime > xx) return 0;     }     if (xx - anstime >= 0)       return 1;     else       return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     srand(time(0));     double time, kolend, s1, t1, s2, l, r, c;     cin >> n >> s >> v1 >> v2 >> kol;     l = 0;     r = s / v1 + 1;     while (r - l > 1e-6) {       c = (l + r) / 2;       if (check(c))         r = c;       else         l = c;     }     cout << fixed << setprecision(7) << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, ans;     scanf( %lld , &n);     if (n % 2 == 0) {       ans = n / 2;     }     if (n % 2 == 1) {       ans = (n - 1) / 2 - n;     }     printf( %lld n , ans);     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d, a[1000];   int main() {     cin >> n >> d;     for (int i = 0; i < n; i++) {       int s;       cin >> s;       a[s]++;     }     int maxn = 0;     for (int i = 1; i <= 100; i++) {       int l = 0;       for (int j = i; j <= i + d; j++) {         l += a[j];       }       if (l > maxn) {         maxn = l;       }     }     cout << n - maxn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s1[105], s2[105];   int a[105], b[105];   int tt[305];   int main() {     int n, T;     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) tt[b[i]] = i;     memset(s1, 0, sizeof s1);     memset(s2, 0, sizeof s2);     int boardl = min(T / 2, 100);     int boardr = min(T - boardl, 100);     for (int i = 1; i <= boardl; i++)       for (int j = 1; j <= n; j++) {         int nowm = 0;         for (int k = 1; k <= tt[a[j]]; k++) nowm = max(nowm, s1[k]);         s1[tt[a[j]]] = nowm + 1;       }     for (int i = 1; i <= boardr; i++)       for (int j = n; j; j--) {         int nowm = 0;         for (int k = n; k >= tt[a[j]]; k--) nowm = max(nowm, s2[k]);         s2[tt[a[j]]] = nowm + 1;       }     int ans = 0;     for (int i = 1; i <= n; i++) {       int ans1 = 0, ans2 = 0;       if (tt[b[i]] != tt[b[i - 1]]) {         for (int j = 1; j <= tt[b[i]]; j++) ans1 = max(ans1, s1[j]);         for (int j = tt[b[i]]; j <= n; j++) ans2 = max(ans2, s2[j]);         ans = max(             ans, ans1 + ans2 + (T - boardl - boardr) * (tt[b[i]] - tt[b[i - 1]]));       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 8;   int a[N], b[N];   int n, m;   long long x, k, y;   bool chk(int l, int r, long long &res) {     if (l > r) return true;     bool canDel = false;     int mx = *max_element(a + l, a + r + 1);     int len = r - l + 1;     if (l - 1 >= 0 && a[l - 1] > mx) canDel = true;     if (r + 1 < n && a[r + 1] > mx) canDel = true;     if (len < k && !canDel) return false;     int need = len % k;     res += need * y;     len -= need;     if (y * k >= x) {       res += len / k * x;     } else if (canDel) {       res += len * y;     } else {       res += (len - k) * y + x;     }     return true;   }   int main() {     cin >> n >> m >> x >> k >> y;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     long long res = 0;     int lst = -1, posa = 0, posb = 0;     while (posb < m) {       while (posa < n && a[posa] != b[posb]) posa++;       if (posa == n) {         cout <<  -1 ;         return 0;       }       if (!chk(lst + 1, posa - 1, res)) {         cout <<  -1 ;         return 0;       }       lst = posa;       posb++;     }     if (!chk(lst + 1, n - 1, res)) {       cout <<  -1 ;       return 0;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   int x, k;   int NumsBetween(int a, int b) { return (b / x - (a - 1) / x); }   int main() {     int n;     std::cin >> n >> x >> k;     std::vector<int> array(n, 0);     for (int i = 0; i < n; ++i) {       std::cin >> array[i];     }     std::sort(array.begin(), array.end());     long long answ = 0;     int pointer = 0;     int start = 0;     int finish = 0;     while (pointer < n) {       for (; start < n; start += 1) {         if (NumsBetween(array[pointer], array[start]) >= k) break;       }       for (; finish < n; finish += 1) {         if (NumsBetween(array[pointer], array[finish]) > k) break;       }       answ += finish - start;       pointer += 1;       if (start != n && pointer != n && array[pointer] > array[start])         start = pointer;       if (finish != n && start != n && array[start] > array[finish])         finish = start;     }     std::cout << answ << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 100000;   vector<int> divisors[MX + 10];   int n, last[MX + 10], pos, X;   int main() {     for (int j = 1; j <= MX; j++)       for (int i = j; i <= MX; i += j) divisors[i].push_back(j);     cin >> n;     for (int j = 1; j <= n; j++) {       cin >> X >> pos;       pos = j - pos;       int sz = divisors[X].size(), ret = 0, div;       for (int i = 0; i < sz; i++) {         div = divisors[X][i];         if (last[div] < pos) ret++;         last[div] = j;       }       cout << ret << endl;     }   }
#include <bits/stdc++.h>   struct node {     int h, typ;     bool operator<(node b) const {       if (typ == b.typ) return h > b.h;       return typ < b.typ;     }   } a[10010];   int n, x, y, sum, L, R, ans, dp[10010];   int main() {     scanf( %d%d%d , &n, &x, &y);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].h), sum += a[i].h;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].typ);     L = sum - y, R = sum - x;     std::sort(a + 1, a + n + 1);     memset(dp, 128, sizeof(dp));     dp[0] = 0;     for (int i = 1; i <= n; i++)       for (int j = sum; j >= a[i].h; j--) {         int res = dp[j - a[i].h];         if (L <= j && R >= j) res += a[i].typ;         dp[j] = std::max(dp[j], res);       }     for (int i = 0; i <= sum; i++) ans = std::max(ans, dp[i]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long data[n + 1];     long long mx = LLONG_MIN;     for (int i = 1; i <= n; i++) {       cin >> data[i];       mx = max(mx, data[i]);     }     vector<int> graph[n + 1];     for (int i = 0; i < n - 1; i++) {       int s, t;       cin >> s >> t;       graph[s].push_back(t);       graph[t].push_back(s);     }     int mxi = 0;     long long mxcnt = 0;     for (int i = 1; i <= n; i++) {       if (data[i] == mx) {         mxi = i;         mxcnt++;       }     }     long long res = mx;     if (mxcnt == 1) {       int level[n + 1];       fill_n(level, n + 1, -1);       deque<int> queue;       queue.push_back(mxi);       level[mxi] = 0;       while (!queue.empty()) {         int cur = queue.front();         res = max(res, data[cur] + level[cur]);         queue.pop_front();         for (int next : graph[cur]) {           if (level[next] < 0) {             level[next] = min(2, level[cur] + 1);             queue.push_back(next);           }         }       }     } else {       bool level1 = false;       for (int i = 1; !level1 && i <= n; i++) {         long long cnt = data[i] == mx ? 1 : 0;         for (int next : graph[i]) {           if (data[next] == mx) cnt++;         }         level1 |= cnt == mxcnt;       }       res = level1 ? mx + 1 : mx + 2;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long tree[3 * 100005];   bool lazy[3 * 100005];   void update(long long node, long long b, long long e, long long i, long long j,               long long v) {     if (i > e || j < b) {       return;     }     if (b >= i && e <= j) {       lazy[node] = true;       { tree[node] = tree[node] | v; }       return;     }     if (lazy[node]) {       tree[node * 2] |= tree[node];       tree[node * 2 + 1] |= tree[node];       lazy[node * 2] = 1;       lazy[node * 2 + 1] = 1;       lazy[node] = 0;     }     update(node * 2, b, (b + e) / 2, i, j, v);     update(node * 2 + 1, (b + e) / 2 + 1, e, i, j, v);     tree[node] = tree[node * 2] & tree[node * 2 + 1];   }   long long query(long long node, long long b, long long e, long long i,                   long long j) {     if (i > e || j < b) {       return (1LL << 33) - 1;     }     if (b >= i && e <= j) {       return tree[node];     }     if (lazy[node]) {       tree[node * 2] |= tree[node];       tree[node * 2 + 1] |= tree[node];       lazy[node * 2] = 1;       lazy[node * 2 + 1] = 1;       lazy[node] = 0;     }     return query(node * 2, b, (b + e) / 2, i, j) &            query(node * 2 + 1, (b + e) / 2 + 1, e, i, j);   }   int main() {     long long n, m;     cin >> n >> m;     pair<long long, long long> p[m + 1];     long long a[m + 1];     memset(tree, 0, sizeof tree);     memset(lazy, 0, sizeof lazy);     for (long long i = 1; i <= m; i++) {       long long x, y, z;       cin >> x >> y >> z;       update(1, 1, n, x, y, z);       p[i].first = x;       p[i].second = y;       a[i] = z;     }     int f = 1;     for (long long i = 1; i <= m; i++) {       long long x = query(1, 1, n, p[i].first, p[i].second);       if (x != a[i]) {         f = 0;       }     }     if (f == 1) {       cout <<  YES n ;       for (long long i = 1; i <= n; i++) {         cout << query(1, 1, n, i, i) <<    ;       }       cout << endl;     } else {       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long mod = 1e9 + 7;   long long sod(long long n) {     long long sum = 0;     while (n > 0) {       sum += n % 10;       n /= 10;     }     return sum;   }   long long dig(long long n) {     long long cnt = 0;     while (n > 0) {       n /= 10;       cnt++;     }     return cnt;   }   long long divs(long long n) {     long long cnt = 0;     for (long long x = 1; x * x <= n; x++) {       if (n % x == 0) {         cnt++;         if (n / x != x) cnt++;       }     }     return cnt;   }   long long isprime(long long n) {     if (n < 2) return false;     for (long long x = 2; x * x <= n; x++)       if (n % x == 0) return false;     return true;   }   long long power(long long x, unsigned long long y, long long p = mod) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   const long long inf = 1e18;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s;       cin >> s;       long long ans = 0;       long long found = 0;       for (long long x = 0; x < n; x++) {         long long pos = x + 1;         long long bck = n - x;         long long cnt = 0;         if (s[x] ==  1 ) {           cnt = 2 * pos;           ans = max(ans, cnt);           long long cnt2 = 2 * bck;           ans = max(ans, cnt2);         }       }       if (ans == 0) ans = n;       cout << ans <<   n ;     }     return 0;   }