malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   int n, Q, cc = 1, tp, h[N], s[N];   struct E {     int v, nxt;   } e[N << 1];   inline void add(int u, int v) {     e[cc] = (E){v, h[u]};     h[u] = cc++;   }   struct st {     int n, c[N << 1];     inline void upd(int x, int v) {       for (; x <= n; x += x & -x) c[x] += v;     }     inline int qry(int x) {       int r = 0;       for (; x; x -= x & -x) r += c[x];       return r;     }   } C;   struct tr {     int ch[2], f, r, sz, c, tg;   } t[N];   inline int isrt(int x) { return t[t[x].f].ch[0] != x && t[t[x].f].ch[1] != x; }   inline int wh(int x) { return t[t[x].f].ch[1] == x; }   inline void up(int x) { t[x].sz = t[t[x].ch[0]].sz + t[t[x].ch[1]].sz + 1; }   inline void rot(int x) {     int y = t[x].f, z = t[y].f, c = wh(x);     t[x].f = z;     if (!isrt(y)) t[z].ch[wh(y)] = x;     t[t[x].ch[c ^ 1]].f = y;     t[y].ch[c] = t[x].ch[c ^ 1];     t[y].f = x;     t[x].ch[c ^ 1] = y;     up(y);     up(x);   }   inline void rev(int x) {     swap(t[x].ch[0], t[x].ch[1]);     t[x].r ^= 1;   }   inline void cov(int x, int v) { t[x].c = t[x].tg = v; }   inline void dn(int x) {     if (t[x].r) rev(t[x].ch[0]), rev(t[x].ch[1]), t[x].r ^= 1;     if (t[x].tg) cov(t[x].ch[0], t[x].tg), cov(t[x].ch[1], t[x].tg), t[x].tg = 0;   }   inline void splay(int x) {     for (int i = s[tp = 1] = x; !isrt(i); i = t[i].f) s[++tp] = t[i].f;     while (tp) dn(s[tp--]);     for (int y; !isrt(x); rot(x))       if (!isrt(y = t[x].f)) wh(x) ^ wh(y) ? rot(x) : rot(y);   }   inline void access(int x, int c) {     for (int y = 0; x; x = t[y = x].f) {       splay(x);       t[x].ch[1] = 0;       up(x);       C.upd(t[x].c, -t[x].sz);       cov(x, c);       C.upd(t[x].c, t[x].sz);       t[x].ch[1] = y;       up(x);     }   }   inline int qry(int x) {     splay(x);     return C.qry(t[x].c) - t[t[x].ch[0]].sz;   }   void dfs(int x, int p) {     t[x].c = x;     t[x].sz = 1;     t[x].f = p;     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].v != p) dfs(e[i].v, x), t[x].c = max(t[x].c, t[e[i].v].c);     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].v != p && t[x].c == t[e[i].v].c)         t[x].ch[1] = e[i].v, t[x].sz += t[e[i].v].sz;     C.upd(t[x].c, 1);   }   int main() {     scanf( %d%d , &n, &Q);     C.n = n + Q + 1;     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     dfs(n, 0);     int c = n;     while (Q--) {       char o[10];       scanf( %s , o);       int x, y;       if (o[0] ==  u ) {         scanf( %d , &x);         access(x, c);         splay(x);         rev(x);         dn(x);         C.upd(t[x].c, -1);         t[x].ch[1] = 0;         cov(x, ++c);         t[x].sz = 1;         C.upd(t[x].c, 1);       } else if (o[0] ==  w )         scanf( %d , &x), printf( %d n , qry(x));       else {         scanf( %d%d , &x, &y);         printf( %d n , qry(x) < qry(y) ? x : y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, mod = 1e9 + 7, inf = 1e18;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k, x, s = 0, flag = 0, ans = 0;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       s += x;       if (s / k) flag = 0;       ans += s / k;       s %= k;       if (flag) ans++, s = 0, flag = 0;       if (s) flag = 1;     }     if (s) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[3000000], a[3000000];   vector<long long int> v;   int main() {     long long int n, ans = 0;     cin >> n;     for (long long int i = 0; i < n; i++) cin >> arr[i];     a[0] = 1;     for (long long int i = 0; i < n; i++) {       v.clear();       for (long long int j = 1; j * j <= arr[i]; j++) {         if (arr[i] % j == 0) {           v.push_back(j);           if (j != arr[i] / j) v.push_back(arr[i] / j);         }       }       sort(v.begin(), v.end());       for (long long int j = v.size() - 1; j >= 0; j--) {         a[v[j]] = (a[v[j]] % 1000000007 + a[v[j] - 1] % 1000000007) % 1000000007;       }     }     for (int i = 1; i <= 1800000; i++) {       ans = (ans % 1000000007 + a[i] % 1000000007) % 1000000007;       ans = (ans % 1000000007 + 1000000007) % 1000000007;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 2 * 1e5 + 5;   long long int vis[mxn];   vector<vector<long long int>> ad(mxn);   long long int leaf, ans = 0;   void dfs(long long int n, long long int d) {     vis[n] = 1;     for (auto child : ad[n])       if (!vis[child]) dfs(child, d + 1);     if (d > ans) {       ans = d;       leaf = n;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k, n, m;       cin >> n >> k;       vector<long long int> par(k + 1);       for (j = 1; j <= k; j++) par[j] = j;       vector<vector<long long int>> adj(n + 1);       for (i = 1; i <= k; i++) {         adj[n].emplace_back(i);         ad[n].emplace_back(i);         ad[i].emplace_back(n);       }       for (j = 0; i < n; i++, j++) {         adj[par[j % k + 1]].emplace_back(i);         ad[par[j % k + 1]].emplace_back(i);         ad[i].emplace_back(par[j % k + 1]);         par[j % k + 1] = i;       }       dfs(1, 0);       ans = 0;       memset(vis, 0, sizeof vis);       dfs(leaf, 0);       cout << ans <<   n ;       for (i = 1; i <= n; i++) {         for (auto j : adj[i]) cout << i <<     << j <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A[100005];     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     int mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += A[i];       if (A[i] > mx) mx = A[i];     }     sum -= mx;     if (sum <= mx) {       cout << mx - sum + 1 << endl;     } else {       cout << 0;     }     return 0;   }
#include <bits/stdc++.h>   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   using namespace std;   long long po(long long n, long long exp) {     long long prod = 1;     for (long long i = 0; i < exp; i++) prod = (prod * n);     return prod;   }   double dis(long long x1, long long y1, long long x2, long long y2) {     return sqrt(((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));   }   signed main() {     ios_base::sync_with_stdio(false);     long long TESTS = 1;     while (TESTS--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       long long p = 1, ans = 0;       a[n] = 1e11;       for (long long i = 0; i < n; i++) {         if (a[i] == a[i + 1]) {           p++;         } else {           ans += (p * p + p) / 2;           p = 1;         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k, s;   vector<long long int> v, ans;   void build(const int &last, const int &i, const int &k,              const bool &increasing) {     if (!k)       return;     else if (last != v[i] and int(v.size()) - i == k)       ans.push_back(v[i]), build(v[i], i + 1, k - 1, increasing);     else if (last == v[i])       build(last, i + 1, k, increasing ^ 1);     else       ans.push_back(last + (increasing ? 1 : -1)),           build(last + (increasing ? 1 : -1), i, k - 1, increasing);   }   int main() {     scanf( %lld %lld %lld , &n, &k, &s);     if (k * (n - 1) < s or k > s) return printf( %s n ,  NO ), 0;     for (int i = 0; i < k and s > n - 1; ++i, s -= (n - 1))       v.push_back((i & 1) ? 1 : n);     if (int(v.size()) & 1)       v.push_back(n - s);     else       v.push_back(1 + s);     build(1, 0, k, 1);     printf( %s n ,  YES );     for (int i = 0; i < int(ans.size()); ++i)       printf( %lld%c , ans[i], (i == int(ans.size()) - 1) ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<vector<char>> arr(n + 2, vector<char>(m + 2));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> arr[i][j];       }     }     for (int i = 0; i < n + 2; i++) {       arr[i][0] = arr[i][m + 1] =  . ;     }     for (int i = 0; i < m + 2; i++) {       arr[0][i] = arr[n + 1][i] =  . ;     }     n += 2, m += 2;     int l = 0, r = n + m + 1;     vector<vector<int>> dist(n, vector<int>(m));     queue<pair<int, int>> q;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] ==  . ) {           q.emplace(i, j);           dist[i][j] = 0;         } else {           dist[i][j] = INF;         }       }     }     while (!q.empty()) {       int i = q.front().first, j = q.front().second;       q.pop();       vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                                   {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};       for (auto &add : t) {         int ni = i + add.first, nj = j + add.second;         if (ni >= 0 && ni < n && nj >= 0 && nj < m && dist[ni][nj] == INF) {           dist[ni][nj] = dist[i][j] + 1;           q.emplace(ni, nj);         }       }     }     while (r - l > 1) {       int t = (l + r) / 2;       vector<vector<int>> dist_start(n, vector<int>(m));       deque<pair<int, int>> q;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (arr[i][j] ==  X  && dist[i][j] > t) {             q.emplace_back(i, j);             dist_start[i][j] = 0;           } else {             dist_start[i][j] = INF;           }         }       }       while (!q.empty()) {         int i = q.front().first, j = q.front().second;         q.pop_front();         vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                                     {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};         for (auto &add : t) {           int ni = i + add.first, nj = j + add.second;           if (ni >= 0 && ni < n && nj >= 0 && nj < m &&               dist_start[ni][nj] == INF) {             dist_start[ni][nj] = dist_start[i][j] + 1;             q.emplace_back(ni, nj);           }         }       }       bool flag = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (arr[i][j] ==  X  && dist_start[i][j] > t) {             flag = false;           }         }       }       if (flag) {         l = t;       } else {         r = t;       }     }     cout << l <<   n ;     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         if (arr[i][j] ==  X  && dist[i][j] > l) {           cout <<  X ;         } else {           cout <<  . ;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct yts {     int v[300010], ne[2 * 300010], x[2 * 300010], y[2 * 300010];     bool val[2 * 300010];     int num;     void put(int s, int t) {       num++;       x[num] = s;       y[num] = t;       ne[num] = v[s];       v[s] = num;     }   } e1, e2;   int q[300010];   bool vis[300010];   char dir[300010];   int S, n, m, undir;   char ty(int x) { return (x & 1) ?  -  :  + ; }   void bfs(int type) {     int h = 0, w = 1;     q[1] = S;     vis[S] = 1;     while (h != w) {       int x = q[++h];       for (int i = e2.v[x]; i; i = e2.ne[i]) {         if (!dir[i >> 1]) {           if (type == 1)             e2.val[i] = 1, e2.val[i ^ 1] = 0, dir[i >> 1] = ty(i);           else             e2.val[i] = 0, e2.val[i ^ 1] = 1, dir[i >> 1] = ty(i ^ 1);         }       }       for (int i = e2.v[x]; i; i = e2.ne[i])         if (e2.val[i]) {           int y = e2.y[i];           if (!vis[y]) vis[y] = 1, q[++w] = y;         }       for (int i = e1.v[x]; i; i = e1.ne[i]) {         int y = e1.y[i];         if (!vis[y]) vis[y] = 1, q[++w] = y;       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans += vis[i];     printf( %d n , ans);     for (int i = 1; i <= undir; i++) putchar(dir[i] ? dir[i] :  + );     puts(  );     memset(vis, 0, sizeof(vis));     memset(dir, 0, sizeof(dir));     memset(e2.val, 0, sizeof(e2.val));   }   int main() {     scanf( %d%d%d , &n, &m, &S);     e2.num = 1;     for (int i = 1; i <= m; i++) {       int x, y, ty;       scanf( %d%d%d , &ty, &x, &y);       if (ty == 1)         e1.put(x, y);       else {         undir++;         e2.put(x, y);         e2.put(y, x);       }     }     bfs(1);     bfs(2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 0x3f3f3f3f3f3f3f3fll;   const int LGN = 25;   const int MOD = 1e9 + 7;   const int N = 3e5 + 5;   int n, a[N], m, l[N], r[N];   int mem[N * LGN], cnt;   int* alloc(int x) {     int* p = mem + cnt;     cnt += x;     return p;   }   struct {     int* a;     int ans;   } st[4 * N];   void build(int p = 1, int L = 1, int R = n) {     if (R < L) return;     if (L == R) {       st[p].a = alloc(1);       st[p].a[0] = ::a[L];       st[p].ans = oo;       return;     }     int m = (L + R) >> 1;     build(2 * p, L, m), build(2 * p + 1, m + 1, R);     st[p].a = alloc(R - L + 1);     int* lf = st[2 * p].a;     int* ri = st[2 * p + 1].a;     merge(lf, lf + (m - L + 1), ri, ri + (R - m), st[p].a);     st[p].ans = oo;     for (long long i = 1, __R = R - L; i <= __R; i++)       st[p].ans = min(st[p].ans, st[p].a[i] - st[p].a[i - 1]);   }   int query(int l, int r, int p = 1, int L = 1, int R = n);   void update(int i, int v, int& d, int p = 1, int L = 1, int R = n) {     if (R < L || i < L || R < i) return;     if (L == R) {       st[p].ans = min(st[p].ans, abs(st[p].a[0] - v));       d = min(d, st[p].ans);       return;     }     int j = upper_bound(st[p].a, st[p].a + (R - L + 1), v) - st[p].a;     if ((j == 0 || d <= v - st[p].a[j - 1]) &&         (j == R - L + 1 || d <= st[p].a[j] - v)) {       d = min(d, query(L, i, p, L, R));       return;     }     int m = (L + R) >> 1;     if (i <= m)       update(i, v, d, 2 * p, L, m);     else {       update(i, v, d, 2 * p + 1, m + 1, R);       update(m, v, d, 2 * p, L, m);     }     st[p].ans = min(st[p].ans, min(st[2 * p].ans, st[2 * p + 1].ans));   }   int query(int l, int r, int p, int L, int R) {     if (R < L || r < L || R < l) return oo;     if (l <= L && R <= r) return st[p].ans;     int m = (L + R) >> 1;     return min(query(l, r, 2 * p, L, m), query(l, r, 2 * p + 1, m + 1, R));   }   int main() {     std::ios::sync_with_stdio(false);     scanf( %d , &(n));     for (long long i = 1, __R = n; i <= __R; i++) scanf( %d , &(a[i]));     build();     scanf( %d , &(m));     static int idx[N];     for (long long i = 1, __R = m; i <= __R; i++)       scanf( %d%d , &(l[i]), &(r[i])), idx[i] = i;     sort(idx + 1, idx + m + 1, [](int i, int j) { return r[i] < r[j]; });     int curr = 1;     static int ans[N];     for (long long j = 1, __R = m; j <= __R; j++) {       int i = idx[j];       while (curr < r[i]) {         curr++;         int d = oo;         update(curr - 1, a[curr], d);       }       ans[i] = query(l[i], r[i]);     }     for (long long i = 1, __R = m; i <= __R; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10004;   int v[MAXN];   int solve(int x, int y) {     if (x == y) return 0;     int mid = (x + y) >> 1;     int left = 0, right = 0;     for (int i = x; i < mid + 1; ++i) left = max(left, v[i]);     for (int i = mid + 1; i < y + 1; ++i) right = max(right, v[i]);     return abs(right - left) + solve(x, mid) + solve(mid + 1, y);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     while (cin >> n) {       memset(v, 0, sizeof v);       int m = (1 << (n + 1)) - 1;       for (int i = 0; i < m - 1; ++i) {         int x;         cin >> x;         int u = i + 2;         int p = (u) >> 1;         v[u] = v[p] + x;       }       cout << solve(1 << n, m) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, j = 1, a, b, c, d, maxi = -1;     cin >> n;     cin >> a >> b >> c >> d;     maxi = a + b + c + d;     for (int i = 2; i <= n; i++) {       cin >> a >> b >> c >> d;       if (a + b + c + d > maxi) {         j++;       }     }     cout << j << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long p = 998244353;   const long long N = 3e5;   long long fact[N + 1];   int32_t main() {     clock_t clk = clock();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = 1;     for (long long i = 1; i <= N; i++) {       fact[i] = (fact[i - 1] * i) % p;     }     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (auto &it : a) cin >> it.first >> it.second;     map<long long, vector<long long> > byA;     map<long long, vector<long long> > byB;     long long ans = 0;     long long temp;     for (pair<long long, long long> pa : a) {       byA[pa.first].push_back(pa.second);     }     temp = 1;     for (auto pa : byA) {       temp = (temp * fact[pa.second.size()]) % p;     }     ans = (ans + temp) % p;     for (pair<long long, long long> pa : a) {       byB[pa.second].push_back(pa.first);     }     temp = 1;     for (auto pa : byB) {       temp = (temp * fact[pa.second.size()]) % p;     }     ans = (ans + temp) % p;     bool isPossible = 1;     for (auto it = byA.begin(); it != byA.end(); it++) {       sort(it->second.begin(), it->second.end());       if (it == byA.begin()) continue;       auto it2 = it;       --it2;       long long v1 = it2->second.back();       long long v2 = it->second[0];       if (v2 < v1) {         isPossible = 0;         break;       }     }     temp = 0;     if (isPossible) {       temp = 1;       for (auto pa : byA) {         long long m = pa.second.size();         vector<long long> isLand;         long long c = 1;         long long flag = pa.second[0];         for (long long i = 1; i < m; i++) {           if (flag == pa.second[i])             c++;           else {             isLand.push_back(c);             c = 1;             flag = pa.second[i];           }         }         if (c) isLand.push_back(c);         long long temp3 = 1;         for (long long x : isLand) {           temp3 = (temp3 * fact[x]) % p;         }         temp = (temp * temp3) % p;       }       ans = (ans + p - temp) % p;     }     long long total = fact[n];     total = (total + p - ans) % p;     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct tree {     queue<int> a;   };   tree num[100005];   long long apple[100005];   int beg = 1;   void dfs(int nn, int beg) {     if (num[nn].a.empty()) return;     while (!num[nn].a.empty()) {       int n1 = num[nn].a.front();       num[nn].a.pop();       apple[beg + 1]++;       dfs(n1, beg + 1);     }   }   int main() {     int number;     cin >> number;     int num1;     memset(apple, 0, sizeof(apple));     apple[1] = 1;     for (int i = 2; i <= number; i++) {       cin >> num1;       num[num1].a.push(i);     }     long long ans = 0;     dfs(1, beg);     for (int i = 1; i <= number; i++) {       if (apple[i] % 2 != 0) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2e5 + 10;   int n, k, a, b, q, i;   int tip, d, p, lll;   pair<int, int> arb[4 * Nmax];   void update(int nod, int st, int dr, int val, int poz) {     if (st >= dr) {       arb[nod].first = min(b, arb[nod].first + val);       arb[nod].second = min(a, arb[nod].second + val);       return;     }     int mij = (st + dr) >> 1;     if (poz <= mij)       update((nod << 1), st, mij, val, poz);     else       update(((nod << 1) | 1), mij + 1, dr, val, poz);     arb[nod].first = arb[(nod << 1)].first + arb[((nod << 1) | 1)].first;     arb[nod].second = arb[(nod << 1)].second + arb[((nod << 1) | 1)].second;   }   int query(int nod, int st, int dr, int a, int b, int r) {     if (a <= st && dr <= b)       if (r == 0)         return arb[nod].first;       else         return arb[nod].second;     int mij = (st + dr) >> 1;     int val1 = (a <= mij) ? query((nod << 1), st, mij, a, b, r) : 0;     int val2 = (mij < b) ? query(((nod << 1) | 1), mij + 1, dr, a, b, r) : 0;     return val1 + val2;   }   int main() {     scanf( %d %d , &n, &k);     scanf( %d %d , &a, &b);     scanf( %d , &q);     for (i = 1; i <= q; ++i) {       scanf( %d , &tip);       if (tip == 1) {         scanf( %d %d , &d, &p);         update(1, 1, n, p, d);       } else {         scanf( %d , &lll);         int v = 0;         if (lll > 1) v += query(1, 1, n, 1, lll - 1, 0);         if (lll + k <= n) v += query(1, 1, n, lll + k, n, 1);         printf( %d n , v);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string l;     cin >> l;     sort(l.begin(), l.end());     int a = 0, ans = 0;     char p = l[0];     for (;;) {       if (l[0] == p) {         a++;         l.erase(l.begin());       } else {         ans = max(ans, a);         if (l.size() > 0) {           p = l[0];           a = 0;         } else           break;       }     }     if (ans > k)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   const int mx = 500010;   int n, m, k, a[1010], c[1010], ans, sum;   int jud[mx];   set<int> s[mx];   set<int>::iterator it;   vector<int> vc[mx];   void dfs(int y, int pre) {     vector<int> v;     if (pre == -1) {       int t = 1;       for (it = s[y].begin(); it != s[y].end(); it++) {         jud[*it] = t++;         sum = max(sum, t - 1);       }     } else {       for (it = s[y].begin(); it != s[y].end(); it++) {         if (jud[(*it)]) v.push_back(jud[(*it)]);       }       int vn = v.size();       sort(v.begin(), v.end());       int f = 0, t = 1;       for (it = s[y].begin(); it != s[y].end(); it++) {         if (!jud[(*it)]) {           while (f < vn && v[f] == t) {             f++;             t++;           }           jud[(*it)] = t++;         }         sum = max(sum, t - 1);       }     }     int nm = vc[y].size();     for (int i = 0; i < nm; i++) {       int vyi = vc[y][i];       if (vyi != pre) dfs(vyi, y);     }   }   int dxy[8] = {1, 0, -1, 0, 0, 1, 0, -1};   int main() {     ios::sync_with_stdio(false);     int t, i, j, l, q, x, y, ss;     int cas = 1, flag;     cin >> n >> m;     {       l = max(n, m);       for (i = 0; i <= l; i++) {         vc[i].clear();         jud[i] = 0;       }       sum = 1;       for (i = 1; i <= n; i++) {         cin >> ss;         for (j = 0; j < ss; j++) {           cin >> x;           s[i].insert(x);         }       }       for (i = 0; i < n - 1; i++) {         cin >> x >> y;         vc[x].push_back(y);         vc[y].push_back(x);       }       dfs(1, -1);       cout << sum << endl;       for (i = 1; i <= m; i++) {         if (jud[i])           cout << jud[i];         else           cout <<  1 ;         if (i != m)           cout <<    ;         else           cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w[101], i, j, S, Sum, k, C, a, t;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &k);       for (j = 1; j <= k; j++) {         scanf( %d , &a);         Sum += a;         t = j * 2 - k;         if (t == 1)           w[C++] = -a;         else if (t <= 0)           S += a;       }     }     sort(w, w + C);     for (i = 0; i < C; i += 2) S -= w[i];     printf( %d %d n , S, Sum - S);   }