malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int const N = 400010;   int const M = 1001000;   int n, m;   struct edges {     int u, next;   } e[M];   int p[N], idx;   void addedge(int u, int v) { e[idx].u = v, e[idx].next = p[u], p[u] = idx++; }   void init() {     idx = 0;     memset(p, (0xff), sizeof p);   }   int key[N];   int sz[N];   int dep[N];   void dfs(int u, int d, int pre = -1) {     sz[u] = 1;     dep[u] = d;     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dfs(v, d + 1, u);         sz[u] += sz[v];       }     }     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         if (sz[v] + sz[v] > n) key[u] = v;       }     }     if (pre != -1 && sz[u] + sz[u] < n) key[u] = pre;   }   int dp[N];   int dpu[N];   void dfs1(int u, int pre = -1) {     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dfs1(v, u);         dp[u] = max(dp[u], dp[v]);       }     }     if (sz[u] + sz[u] <= n) dp[u] = sz[u];   }   void dfs2(int u, int pre = -1) {     int m1 = dpu[u], m2 = 0;     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dp[u] = max(dp[u], dp[v]);         if (dp[v] >= m1) {           m2 = m1;           m1 = dp[v];         } else if (dp[v] >= m2) {           m2 = dp[v];         }       }     }     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         int rem = n - sz[v];         if (rem + rem <= n)           dpu[v] = rem;         else {           if (dp[v] == m1)             dpu[v] = max(dpu[v], m2);           else             dpu[v] = max(dpu[v], m1);         }         dfs2(v, u);       }     }   }   int main() {     scanf( %d , &n);     init();     for (int i = 0; i < (n - 1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       addedge(a, b);       addedge(b, a);     }     dfs(1, 0);     dfs1(1);     dfs2(1);     for (int i = 1; i <= (n); ++i) {       if (key[i] == 0)         printf( 1  );       else {         bool ok = 0;         int u = key[i];         if (dep[u] > dep[i]) {           int rem = sz[u] - dp[u];           if (rem + rem <= n) ok = 1;         } else {           int t = dpu[i];           int rem = n - sz[i];           if ((rem - t) * 2 <= n) ok = 1;         }         if (ok)           printf( 1  );         else           printf( 0  );       }     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       long long n, k;       cin >> n >> k;       if (n < k * k) {         cout <<  NO  <<   n ;       } else if (n % 2 != k % 2) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char save[550][550];   int n, m;   bool vis[550][550];   int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};   int ans;   bool iscan(int x, int y) {     if (x < 1 || x > n || y < 1 || y > m) return false;     return true;   }   struct Rec {     char k;     int x, y;   } rec[1100000];   void dfs(int x, int y) {     int xx, yy;     for (int i = 0; i < 4; i++) {       xx = x + dir[i][0], yy = y + dir[i][1];       if (iscan(xx, yy)) {         if (save[xx][yy] !=  . ) continue;         if (vis[xx][yy]) continue;         vis[xx][yy] = true;         ans++;         rec[ans].k =  B , rec[ans].x = xx, rec[ans].y = yy;         dfs(xx, yy);         ans++;         rec[ans].k =  D , rec[ans].x = xx, rec[ans].y = yy;         ans++;         rec[ans].k =  R , rec[ans].x = xx, rec[ans].y = yy;       }     }   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 1; i <= n; i++) scanf( %s , save[i] + 1);       memset(vis, false, sizeof(vis));       ans = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           if (save[i][j] ==  .  && !vis[i][j]) {             vis[i][j] = true;             ans++;             rec[ans].k =  B , rec[ans].x = i, rec[ans].y = j;             dfs(i, j);           }         }       printf( %d n , ans);       for (int i = 1; i <= ans; i++)         printf( %c %d %d n , rec[i].k, rec[i].x, rec[i].y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, i, j, t;     char c;     string s;     cin >> k;     for (i = 1; i < k; i++) {       for (j = 1; j < k; j++) {         if (j > 1) {           cout <<    ;         }         t = i * j;         s =   ;         while (t > 0) {           c = t % k +  0 ;           s = c + s;           t /= k;         }         cout << s;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 2000;   int x[mxn];   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int(i) = (0); (i) < (n); (i)++) cin >> x[i];     sort(x, x + n);     cout << x[n - a] - x[n - a - 1];   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const double EPS = 1e-9;   const int maxn = (int)1e5 + 9;   int n, q, t[maxn], k[maxn], d[maxn];   int x[150];   int ans[maxn];   void Solve() {     while (cin >> n >> q) {       for (int i = (1); i <= (q); i++) cin >> t[i] >> k[i] >> d[i];       memset(ans, (-1), sizeof(ans));       for (int i = (1); i <= (q); i++) {         int f = 0, nt = 0;         for (int j = (1); j <= (n); j++) {           if (x[j] <= t[i]) {             nt++;           }           if (nt == k[i]) {             f = 1;             break;           }         }         if (f) {           int pp = 0, nt = 0;           for (int j = (1); j <= (n); j++) {             if (x[j] <= t[i]) {               x[j] = t[i] + d[i];               nt++;               pp += j;             }             if (nt == k[i]) break;           }           ans[i] = pp;         }       }       for (int i = (1); i <= (q); i++) {         cout << (ans[i]) << endl;         ;       }     }   }   int main() {     iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dfs(const vector<vector<array<int, 3>>>& edges, vector<int>& ans,           vector<int>& s, vector<char>& used, int v) {     used[v] = true;     int sum = 0;     for (auto& w : edges[v]) {       if (!used[w[0]]) {         int d = dfs(edges, ans, s, used, w[0]);         ans[w[1]] = -d * w[2];         sum += d;       }     }     return sum - s[v];   }   int main() {     std::ios::sync_with_stdio(false);     int n, m;     cin >> n;     vector<int> s(n);     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     cin >> m;     if (n == 1) {       cout << (s[0] == 0 ?  Possible  :  Impossible );       return 0;     }     vector<vector<array<int, 3>>> edges(n);     vector<int> ans(m);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       edges[x].push_back({y, i, 1});       edges[y].push_back({x, i, -1});     }     vector<char> used(n);     if (dfs(edges, ans, s, used, 0) == 0) {       cout <<  Possible n ;       for (int i : ans) {         cout << i << endl;       }     } else {       cout <<  Impossible ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); }   int main() {     int n, num[35][35], sumh[35], suml[35];     cin >> n;     memset(sumh, 0, sizeof(sumh));     memset(suml, 0, sizeof(suml));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> num[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         sumh[i] += num[i][j];         suml[i] += num[j][i];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (suml[j] > sumh[i]) {           ans++;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, sx, sy, dx, dy;   string s[1022];   bool vis[1002][1002][5][5];   bool f(int i, int j, int dir, int steps) {     if (i < 0 || j < 0 || i == n || j == m || steps > 2 || s[i][j] ==  *  ||         (dir != -1 && vis[i][j][dir][steps]))       return false;     if (dir != -1) vis[i][j][dir][steps] = 1;     if (i == dx && j == dy && steps <= 2) return true;     if (dir == -1) {       return f(i + 1, j, 2, steps) || f(i - 1, j, 0, steps) ||              f(i, j + 1, 1, steps) || f(i, j - 1, 3, steps);     } else {       if (dir == 0)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps + 1);       if (dir == 1)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps + 1) ||                f(i, j + 1, 1, steps) || f(i, j - 1, 3, steps + 1);       if (dir == 2)         return f(i + 1, j, 2, steps) || f(i - 1, j, 0, steps + 1) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps + 1);       if (dir == 3)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps);     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < s[i].size(); j++) {         if (s[i][j] ==  S ) {           sx = i;           sy = j;         }         if (s[i][j] ==  T ) {           dx = i;           dy = j;         }       }     }     memset(vis, 0, sizeof(vis));     if (f(sx, sy, -1, 0))       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   inline int readint() {     int a;     cin >> a;     return a;   }   int toInt(string &s) {     const static int Mod = 998244353;     const static long long bas = 29;     int res = 0;     for (int i = 0, n = s.length(); i < n; ++i)       res = (res * bas + s[i] -  a  + 1) % Mod;     return res;   }   const int MaxN = 100005;   vector<int> v[MaxN];   map<int, int> *dp[MaxN];   int siz[MaxN], son[MaxN];   void build(int x) {     siz[x] = 1, son[x] = x;     for (auto y : v[x]) {       dp[y] = dp[x] + 1, build(y);       if (siz[y] >= siz[son[x]]) son[x] = y;       siz[x] += siz[y];     }   }   int val[MaxN];   void calc(int x, bool f) {     if (f)       dp[x][0][val[x]]++;     else {       dp[x][0][val[x]]--;       if (dp[x][0][val[x]] == 0) dp[x][0].erase(val[x]);     }     for (auto y : v[x]) calc(y, f);   }   vector<pair<int, int> > query[MaxN];   int ans[MaxN];   void dfs(int x, bool f) {     for (auto y : v[x])       if (y != son[x]) dfs(y, false);     if (son[x] != x) dfs(son[x], true);     for (auto y : v[x])       if (y != son[x]) calc(y, true);     dp[x][0][val[x]]++;     for (auto t : query[x]) {       int dep = t.first;       int id = t.second;       ans[id] = dp[x][dep].size();     }     if (not f) calc(x, false);   }   map<int, int> cnt[MaxN];   bool root[MaxN];   int main() {     int n = readint();     string s;     int fa;     for (int i = 1; i <= n; ++i) {       cin >> s >> fa;       if (!fa)         root[i] = true;       else         v[fa].push_back(i);       val[i] = toInt(s);     }     for (int i = 1; i <= n; ++i)       if (root[i]) dp[i] = cnt, build(i);     int T = readint();     pair<int, int> p;     for (int i = 1, a, b; i <= T; ++i) {       a = readint();       b = readint();       if (dp[a] + b >= cnt + MaxN) continue;       p.first = b;       p.second = i;       query[a].push_back(p);     }     for (int i = 1; i <= n; ++i)       if (root[i]) dfs(i, false);     for (int i = 1; i <= T; ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m, count, x;     while (scanf( %d %d , &n, &m) == 2) {       x = 0;       count = 0;       while (n != 0) {         count++;         if (count % m == 0) x = 1;         n = (n - 1) + x;         x = 0;       }       printf( %d n , count);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   #pragma GCC optimize( O3 )   using namespace std;   const long long N = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long INF = 1e18;   const long long inf = -1e18;   const long long M = 1e6;   int n, x, y, a[5 * N];   bool us[1000010];   int used[1000010];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> x >> y;     for (int i = 1; i <= n; i++) {       cin >> a[i];       used[a[i]]++;     }     long long ans = INF;     for (int i = 2; i <= 1000000; i++) {       if (us[i] == 0) {         long long s = used[i];         for (int j = i + i; j <= 1000000; j += i) {           us[j] = 1;           s += used[j];         }         if ((n - s) * min(x, y) >= ans) continue;         long long cnt = 0;         for (int j = 1; j <= n; j++) {           if (a[j] % i != 0) {             long long t = a[j] % i;             cnt += min(1ll * x, 1ll * (i - t) * y);           }         }         ans = min(ans, 1ll * cnt);       }     }     cout << ans;     cin.get(), cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void doit(long long int a[], long long int i, long long int sz) {     long long int x;     x = i + sz - 1;     a[i] = x;     for (i++; i <= x; i++) a[i] = i - 1;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, a, b, x, y, i, z;     cin >> n >> a >> b;     long long int arr[n + 1];     i = 0;     while (i * a <= n) {       x = n - i * a;       if (x % b == 0) break;       i++;     }     if (i * a > n) {       cout << -1 <<   n ;       return 0;     }     y = x / b;     x = i;     for (i = 0; i < x; i++) doit(arr, i * a + 1, a);     for (i = 0; i < y; i++) doit(arr, x * a + i * b + 1, b);     for (i = 1; i <= n; i++) cout << arr[i] <<    ;     cout <<   n ;   }
#include <bits/stdc++.h>   int a[101], b[101];   int main() {     int n, i, q, x, y, k, t, s, ls;     for (scanf( %d , &n), i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[a[i]] = i;     }     for (scanf( %d , &q), i = 0; i < q; i++) {       scanf( %d%d%d , &k, &x, &y);       if (k == 1) {         for (s = 0, ls = 101, t = x; t <= y; t++) {           if (b[t] < ls) s++;           ls = b[t];         }         printf( %d n , s);       } else if (k == 2) {         b[a[x]] = y;         b[a[y]] = x;         t = a[x];         a[x] = a[y];         a[y] = t;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1E6 + 5, K = 1E6 + 5, INF = 1E9 + 7;   int n, k, c, v, ans = 0, dsu[K];   char s[N];   vector<int> adj[N];   struct node {     int l, r, xo;     node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {}     int get() { return min(l, r); }     inline void operator+=(node oth) {       l = min(INF, l + oth.l);       r = min(INF, r + oth.r);     }   } val[K];   pair<int, int> trace(int u) {     if (dsu[u] < 0) {       return {u, 0};     } else {       pair<int, int> tmp = trace(dsu[u]);       dsu[u] = tmp.first;       val[u].xo ^= tmp.second;       return {dsu[u], val[u].xo};     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k >> (s + 1);     for (int i = 1; i <= k; i++) {       dsu[i] = -1;       val[i] = node(1, 0, 0);       cin >> c;       while (c--) {         cin >> v;         adj[v].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       int typ = (s[i] -  0 ) ^ 1;       if (ans != -1) {         if (adj[i].size() == 1) {           pair<int, int> u = trace(adj[i][0]);           ans -= val[u.first].get();           val[u.first] += node((u.second == typ) * INF, (u.second != typ) * INF);           ans += val[u.first].get();         } else if (adj[i].size() == 2) {           pair<int, int> u = trace(adj[i][0]);           pair<int, int> v = trace(adj[i][1]);           if (u.first != v.first) {             ans -= val[u.first].get() + val[v.first].get();             if (dsu[u.first] > dsu[v.first]) {               swap(u, v);             }             if (u.second ^ v.second ^ typ) {               swap(val[v.first].l, val[v.first].r);               val[v.first].xo = 1;             }             dsu[u.first] += dsu[v.first];             dsu[v.first] = u.first;             val[u.first] += val[v.first];             ans += val[u.first].get();           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int q, n, i, j, k, t;     long long int a[3];     cin >> t;     long long int area[5];     while (t--) {       long long int a, b, x, y;       cin >> a >> b >> x >> y;       area[1] = (b - y - 1) * a;       area[2] = (y)*a;       area[3] = (a - x - 1) * b;       area[4] = (x)*b;       long long int ans = -1;       for (i = 1; i <= 4; i++) {         ans = max(ans, area[i]);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int rem = 10;   set<char> st;   int main() {     string s;     cin >> s;     long long ans = 1;     int zeroes = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] >=  0  && s[i] <=  9 ) continue;       if (s[i] ==  ? ) {         if (i == 0)           ans *= 9;         else           zeroes += 1;       } else {         if (st.count(s[i])) continue;         st.insert(s[i]);         if (i == 0)           ans *= 9;         else           ans *= rem;         rem--;       }     }     cout << ans;     while (zeroes) {       cout <<  0 ;       zeroes--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   const int MACX = (int)1e9 + 7;   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   long long n, a[N], b[N], c[N];   multiset<long long> ms, ms2;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ms.insert(a[i]);     }     for (int i = 1; i < n; i++) {       cin >> b[i];       ms.erase(ms.find(b[i]));       ms2.insert(b[i]);     }     for (int i = 1; i < n - 1; i++) {       cin >> c[i];       ms2.erase(ms2.find(c[i]));     }     cout << *ms.begin() <<     << *ms2.begin();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   const int B = 165;   int nxt[41005][10], cnt;   bool vis[20][41005];   unordered_map<bitset<B>, int> id;   bitset<B> rid[41005];   long long dp[20][10][41005];   void init() {     bitset<B> bs;     bs.reset();     bs[0] = 1;     id[bs] = ++cnt;     rid[cnt] = bs;     vis[0][1] = 1;     for (int(i) = 1; (i) <= (int)(19); (i)++) {       for (int u = 1; u <= cnt; u++)         if (vis[i - 1][u]) {           for (int(j) = 0; (j) < (int)(10); (j)++) {             if (nxt[u][j] == 0) {               if (j == 0)                 nxt[u][j] = u;               else {                 bs.reset();                 bs |= rid[u] >> j;                 bs |= rid[u] << j;                 for (int k = 1; k < j; k++)                   if (rid[u][k]) bs[j - k] = 1;                 if (id.count(bs))                   nxt[u][j] = id[bs];                 else {                   id[bs] = ++cnt;                   rid[cnt] = bs;                   nxt[u][j] = cnt;                 }               }             }             vis[i][nxt[u][j]] = 1;           }         }     }     for (int(i) = 1; (i) <= (int)(cnt); (i)++) {       int j = 0;       for (; j < 10; j++)         if (rid[i][j] == 1) break;       for (; j < 10; j++) dp[0][j][i] = 1;     }     for (int(i) = 1; (i) <= (int)(19); (i)++) {       for (int(k) = 1; (k) <= (int)(cnt); (k)++)         if (vis[19 - i][k]) {           for (int(j) = 0; (j) < (int)(10); (j)++)             for (int(l) = 0; (l) < (int)(10); (l)++) {               dp[i][l][k] += dp[i - 1][l][nxt[k][j]];             }         }     }   }   long long cal(long long x, int k) {     if (x == 0) return 1;     vector<int> bs;     while (x) {       bs.push_back(x % 10);       x /= 10;     }     long long ans = 0;     int u = 1;     for (int i = (int)bs.size() - 1; ~i; i--) {       for (int j = 0; j < bs[i] + (i == 0); j++) ans += dp[i][k][nxt[u][j]];       u = nxt[u][bs[i]];     }     return ans;   }   void fmain(int ID) {     init();     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       long long l, r;       scanf( %lld%lld%d , &l, &r, &k);       printf( %lld n , cal(r, k) - cal(l - 1, k));     }   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, d, b;   long long a[500005], c[500005];   long long x, xx;   void read(long long &x) {     x = 0;     long long k = 1;     char c = getchar();     while ((c !=  - ) && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) k = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     x = x * k;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   void init() { freopen( f.in ,  r , stdin); }   long long sum(long long x, long long y) {     if (x < 1) x = 1;     if (y > n) y = n;     return c[y] - c[x - 1];   }   int main() {     read(n), read(d), read(b);     for (long long i = 1; i <= n; i++) {       read(a[i]);       c[i] = c[i - 1] + a[i];     }     for (long long i = 1; i <= n / 2; i++) {       if (sum(1, i + i * d) >= (x + 1) * b) x++;       if (sum(n - i - i * d + 1, n) >= (xx + 1) * b) xx++;     }     write(max(n / 2 - x, n / 2 - xx));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<int, int> a[N];   int n;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;     sort(a, a + n);     int ans = 0;     int mxb = -1;     for (int i = 0; i < n; ++i) {       if (a[i].second < mxb)         ++ans;       else         mxb = a[i].second;     }     cout << ans <<   n ;     return 0;   }