malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2001;   const int inf = 1000000000;   int d[maxn], a[maxn], n, k;   bool check(int x) {     int ans = inf;     for (int i = 1; i <= n; i++) {       d[i] = i - 1;       for (int j = 1; j < i; j++)         if (abs(a[i] - a[j]) <= (i - j) * 1ll * x)           d[i] = min(d[i], d[j] + i - j - 1);       ans = min(ans, d[i] + n - i);     }     if (ans <= k) return true;     return false;   }   int main() {     cin >> n >> k;     int l = -1, r = 0, mid;     for (int i = 1; i <= n; i++) {       cin >> a[i];       r = max(r, (i == 1 ? r : abs(a[i] - a[i - 1])));     }     while (r - l > 1) {       mid = (l + 0ll + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int INF = 1e9;   const int maxn = 1e6 + 10;   const double eps = 1e-8;   int add(int x, int y) {     x += y;     return x >= mod ? x - mod : x;   }   int sub(int x, int y) {     x -= y;     return x < 0 ? x + mod : x;   }   int mul(int x, int y) { return 1LL * x * y % mod; }   int dep[maxn], tot, ans;   vector<pair<int, int> > g[maxn];   queue<pair<int, int> > q;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     bool ok = false;     for (int i = 1; i <= n; i++) {       vector<int> fac;       int x;       cin >> x;       for (int d = 2; d * d <= x; d++)         if (x % d == 0) {           int cnt = 0;           while (x % d == 0) cnt++, x /= d;           if (cnt & 1) fac.push_back(d);         }       if (x > 1) fac.push_back(x);       if (fac.size() == 2) {         int p = fac[0], q = fac[1];         g[p].push_back(pair<int, int>{q, ++tot}),             g[q].push_back(pair<int, int>{p, tot});       } else if (fac.size() == 1) {         int p = fac[0];         g[p].push_back(pair<int, int>{1, ++tot}),             g[1].push_back(pair<int, int>{p, tot});       } else         ok = true;     }     if (ok) {       cout << 1 << endl;       return 0;     }     ans = INF;     fill(dep + 1, dep + 1000000 + 1, INF);     for (int i = 1; i <= 1000; i++) {       vector<int> save;       dep[i] = 0, q.push(pair<int, int>{i, 0});       while (!q.empty()) {         pair<int, int> x = q.front();         q.pop();         int u = x.first, pre = x.second;         save.push_back(u);         for (auto e : g[u]) {           int v = e.first, id = e.second;           if (id == pre) continue;           if (dep[v] == INF) {             dep[v] = dep[u] + 1;             q.push(pair<int, int>{v, id});           } else             ans = min(ans, dep[u] + dep[v] + 1);         }       }       for (auto x : save) dep[x] = INF;     }     if (ans == INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   int n;   int t[maxn], c[maxn];   long long d[maxn][maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> t[i] >> c[i];     for (int i = 0; i < n + 1; i++) d[0][i] = 1ll << 62;     d[0][0] = 0;     for (int i = 1; i < n + 1; i++) {       d[i][0] = 0;       for (int j = 1; j < n + 1; j++) {         d[i][j] = d[i - 1][j];         int tmp = max(0, j - t[i - 1] - 1);         if (d[i - 1][tmp] + c[i - 1] < d[i][j])           d[i][j] = d[i - 1][tmp] + c[i - 1];       }     }     cout << d[n][n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[500000], r[500000];   long long a[500000];   int L, R;   int n, q;   int main() {     scanf( %d%d , &n, &q);     a[0] = 0;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = n; i >= 1; i--) a[i] = abs(a[i] - a[i - 1]);     stack<int> S;     for (int i = 2; i <= n; i++) {       while (!S.empty() && a[i] >= a[S.top()]) {         r[S.top()] = i - 1;         S.pop();       }       if (!S.empty())         l[i] = S.top() + 1;       else         l[i] = 2;       S.push(i);     }     while (!S.empty()) {       r[S.top()] = n;       S.pop();     }     while (q--) {       scanf( %d%d , &L, &R);       L++;       long long ans = 0;       for (int i = L; i <= R; i++) {         ans += (long long)(i - max(L, l[i]) + 1) *                (long long)(min(R, r[i]) - i + 1) * a[i];       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<int> val[33];   long long sum[33];   int n = 0;   int calc() {     long long allsum = 0;     int res = 0;     for (int i = 0; i < 30; i++) {       if (val[i].empty()) continue;       if (allsum * 2 < *(val[i].begin())) res++;       allsum += sum[i];     }     return res;   }   int main() {     int q;     scanf( %d , &q);     while (q--) {       char s[2];       int x;       scanf( %s%d , s, &x);       int mn = 0;       for (int i = 0; i < 30; i++)         if (x >> i & 1) mn = i;       if (s[0] ==  - ) {         n--;         sum[mn] -= x;         val[mn].erase(val[mn].find(x));       } else {         sum[mn] += x;         val[mn].insert(x);         n++;       }       printf( %d n , n - calc());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   const int sz = 1 << 20;   char a[sz + 5], b[sz + 5], *p1 = a, *p2 = a, *t = b, p[105];   inline char gc() {     return getchar();     if (p1 == p2) p2 = (p1 = a) + fread(a, 1, sz, stdin);     return *p1++;   }   template <class T>   inline T read() {     T ret = 0;     char c = gc();     int f = 1;     for (; c <  0  || c >  9 ; c = gc())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = gc()) ret = ret * 10 + (c -  0 );     return ret * f;   }   template <class T>   inline void read(T& ret) {     ret = read<T>();   }   inline void flush() { fwrite(b, 1, t - b, stdout), t = b; }   inline void pc(char x) {     *t++ = x;     if (t - b == sz) flush();   }   template <class T>   inline void print(T x, char c =   n ) {     if (x < 0) x = -x, pc( - );     if (x == 0) pc( 0 );     int t = 0;     for (; x; x /= 10) p[++t] = x % 10 +  0 ;     for (; t; --t) pc(p[t]);     pc(c);   }   struct F {     ~F() { flush(); }   } f;   }  // namespace IO   using IO::print;   using IO::read;   const int mo = 1e9 + 7;   inline int add(int a, int b) { return a + b < mo ? a + b : a + b - mo; }   inline int dec(int a, int b) { return a < b ? a + mo - b : a - b; }   inline int mul(int a, int b) { return 1LL * a * b % mo; }   const int N = 1e3 + 10;   int k;   int c[N], s[N];   int C[N][N];   int f[N];   int main() {     for (int i = 0; i <= 1000; i++) C[i][0] = C[0][i] = 1;     C[0][0] = 0;     for (int i = 1; i <= 1000; i++)       for (int j = 1; j <= 1000; j++) C[i][j] = add(C[i - 1][j], C[i][j - 1]);     read(k);     for (int i = 1; i <= k; read(c[i]), s[i] = add(s[i - 1], c[i]), i++)       ;     f[1] = 1;     for (int i = 2; i <= k; i++) f[i] = mul(f[i - 1], C[s[i - 1]][c[i] - 1]);     print(f[k]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[2000005], num[2000005], ans;   long long ksm(long long x, long long y) {     long long ans = 1, t = x;     while (y) {       if (y & 1) ans = ans * t % 1000000007;       t = t * t % 1000000007;       y >>= 1;     }     return ans;   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       if (a[i] != -1) num[a[i]]++;     }     for (long long i = 1; i <= n; i++) {       if (a[i] == -1) ans = (ans + ksm(2, num[i]) - 1 + 1000000007) % 1000000007;     }     printf( %lld , (ksm(2, n - 1) - 1 - ans + 1000000007) % 1000000007);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010, M = N * 2, mod = 1e9 + 7;   const double PI = acos(-1.0), eps = 1e-6;   int T, n, m, k, c1, c2;   int a[N * 10], b[N], tot, cnt[N], s[N * 10], ans;   map<int, int> mp;   vector<int> v;   string g[N * 10];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> g[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (i - 1 >= 0 && g[i - 1][j] ==  X  && j - 1 >= 0 && g[i][j - 1] ==  X )           a[j + 1] = 1;     for (int i = 1; i <= m; i++) s[i] = s[i - 1] + a[i];     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       if (s[r] - s[l] > 0)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   inline void cmin(int &a, int b) {     if (b < a) a = b;   }   int a[1000005], f[1 << 21];   int main() {     int n, i, now, ans, l, j, k;     char s[22];     for (scanf( %d , &n), i = 0; i < n; i++) {       scanf( %s , s);       for (a[i] = j = 0; s[j]; j++) a[i] = (a[i] << 1) + s[j] -  0 ;     }     memset(f, 1, sizeof f);     for (f[0] = 0, ans = l = strlen(s), i = 1; i < n; i++) {       for (k = 0; (a[i - 1] & (1 << l - k) - 1) != (a[i] >> k); k++)         ;       ans += k;       for (now = 1 << 25, j = 0; j <= l; j++)         cmin(now, f[(1 << l - j) - 1 + (a[i] >> j)] + j);       for (now -= k, j = 0; j <= l; j++)         cmin(f[(1 << j) - 1 + (a[i - 1] & (1 << j) - 1)], now);     }     for (now = i = 0; i < 1 << 21; i++) cmin(now, f[i]);     printf( %d n , ans + now);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, bool> mapa;   long long _abs(long long a) {     if (a >= 0)       return a;     else       return -a;   }   int main() {     long long b1, q, l, m;     cin >> b1 >> q >> l >> m;     for (int i = 0; i < m; i++) {       long long a;       cin >> a;       mapa[a] = 1;     }     if (b1 == 0LL) {       if (!mapa.count(0))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     }     if (q == 0LL) {       if (_abs(b1) > l)         cout <<  0 n ;       else if (!mapa.count(0))         cout <<  inf n ;       else if (!mapa.count(b1))         cout <<  1 n ;       else         cout <<  0 n ;       return 0;     } else if (q == 1LL) {       if (_abs(b1) <= l && !mapa.count(b1))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     } else if (q == -1LL) {       if (_abs(b1) > l)         cout <<  0 n ;       else if (!mapa.count(b1) || !mapa.count(-b1))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     }     long long val = b1;     int cont = 0;     while (_abs(val) <= l) {       if (!mapa.count(val)) cont++;       val *= q;     }     cout << cont <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, p;   int tot, head[100010], next1[100010 << 1], to[100010 << 1];   int deep[100010], cnt[100010];   void add(int x, int y) {     to[++tot] = y;     next1[tot] = head[x];     head[x] = tot;   }   void dfs(int x, int f) {     deep[x] = deep[f] + 1;     cnt[deep[x]]++;     for (int i = head[x]; i; i = next1[i]) {       int y = to[i];       if (y == f) continue;       dfs(y, x);     }   }   int main() {     scanf( %d%d%d , &n, &k, &p);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     sort(deep + 1, deep + n + 1);     int l = 2, r = 2, ans = 1, tmp = 0;     while (1) {       if (l >= n || r >= n) break;       r++;       if (deep[r] != deep[r - 1]) tmp += (r - l);       while (tmp > p || r - l + 1 > k) {         tmp -= (deep[r] - deep[l]);         l++;       }       ans = max(ans, (r - l + 1));     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int k, b, n;     cin >> k >> b >> n;     map<int, int> freq;     freq[0]++;     int cont_zeros = 0;     int cur_mod = 0;     long long total_zeros = 0;     long long total_mod = 0;     for (int i = 0; i < n; ++i) {       int u;       cin >> u;       if (u == 0) {         cont_zeros++;         total_zeros += cont_zeros;       } else {         cont_zeros = 0;       }       cur_mod = (cur_mod + u) % (k - 1);       int tt = (k - 1 + cur_mod - b) % (k - 1);       total_mod += freq[tt];       freq[cur_mod]++;     }     if (b == 0) {       cout << total_zeros <<   n ;     } else if (b == k - 1) {       cout << total_mod - total_zeros <<   n ;     } else {       cout << total_mod <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int N = 1E5 + 5;   long long n, l, r, ql, qr;   long long arr[N], pre[N];   int main() {     fast();     cin >> n >> l >> r >> ql >> qr;     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i <= n; ++i) {       pre[i] = arr[i] + pre[i - 1];     }     long long mini =         min(pre[n] * l + (ql * (n - 1)), pre[n] * r + (qr * (n - 1)));     for (int i = 1; i <= n; ++i) {       long long x = (pre[i] * l) + ((pre[n] - pre[i]) * r);       int takenL = i, takenR = n - i;       if (takenL < takenR) {         x += (takenR - takenL - 1) * qr;       } else if (takenR < takenL)         x += (takenL - takenR - 1) * ql;       mini = min(mini, x);     }     cout << mini <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     bool w, l;     int a[26];     node() {       w = false;       l = false;       memset(a, -1, sizeof a);     }   };   node a[100030];   long long cnt;   char second[100010];   void insert(long long n) {     int curr = 0;     int i = 0;     while (curr < n) {       if (a[i].a[second[curr] -  a ] == -1) {         a[i].a[second[curr] -  a ] = ++cnt;       }       i = a[i].a[second[curr] -  a ];       curr++;     }   }   void dfs(long long curr) {     if (curr == -1) {       return;     }     int cnt = 0;     for (int i = 0; i < 26; i++) {       if (a[curr].a[i] != -1) {         cnt++;         dfs(a[curr].a[i]);         if (a[a[curr].a[i]].w == false) {           a[curr].w = true;         }         if (a[a[curr].a[i]].l == false) {           a[curr].l = true;         }       }     }     if (cnt == 0) {       a[curr].w = false;       a[curr].l = true;     }   }   int main() {     long long n, k;     cnt = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %s , second);       insert(strlen(second));     }     dfs(0);     if (a[0].w == true && a[0].l == true) {       cout <<  First  << endl;     } else if (a[0].w == false) {       cout <<  Second  << endl;     } else if (a[0].w == true && a[0].l == false) {       if (k % 2 == 1) {         cout <<  First  << endl;       } else {         cout <<  Second  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   struct point {     int x, y;   } s[N], t[N];   vector<int> q[2];   int cntx, cnty, vis[N], n, now, dis[N], S, ax[N], ay[N];   set<pair<int, int> > a[N];   set<pair<int, int> >::iterator it;   int lowbit(int x) { return x & (-x); }   void upd(int x, pair<int, int> y) {     while (x <= cntx) {       a[x].insert(y);       x += lowbit(x);     }   }   void get(int x, int y, int id) {     while (x) {       it = a[x].begin();       for (pair<int, int> i : a[x]) {         if (i.first > y) break;         it++;         if (vis[i.second]) continue;         q[now].push_back(i.second);         vis[i.second] = id;       }       a[x].erase(a[x].begin(), it);       x -= lowbit(x);     }   }   void bfs(int d) {     if (!q[now].size()) return;     if (vis[n]) return;     now ^= 1;     q[now].clear();     for (int x : q[now ^ 1]) get(t[x].x, t[x].y, x);     for (int x : q[now]) dis[x] = d;     bfs(d + 1);   }   int main() {     scanf( %d , &n);     memset(dis, 0x3f, sizeof(dis));     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &s[i].x, &s[i].y, &t[i].x, &t[i].y);       if (s[i].x == 0 && s[i].y == 0) {         q[0].push_back(i);         dis[i] = 1, vis[i] = -1;       }       ax[++cntx] = s[i].x, ax[++cntx] = t[i].x;       ay[++cnty] = s[i].y, ay[++cnty] = t[i].y;     }     sort(ax + 1, ax + cntx + 1);     sort(ay + 1, ay + cnty + 1);     cntx = unique(ax + 1, ax + cntx + 1) - ax - 1;     cnty = unique(ay + 1, ay + cnty + 1) - ay - 1;     for (int i = 1; i <= n; i++) {       s[i].x = lower_bound(ax + 1, ax + cntx + 1, s[i].x) - ax;       s[i].y = lower_bound(ay + 1, ay + cnty + 1, s[i].y) - ay;       upd(s[i].x, make_pair(s[i].y, i));       t[i].x = lower_bound(ax + 1, ax + cntx + 1, t[i].x) - ax;       t[i].y = lower_bound(ay + 1, ay + cnty + 1, t[i].y) - ay;     }     now = 0;     bfs(2);     if (!vis[n])       puts( -1 );     else {       printf( %d n , dis[n]);       int x = n, cnt = 0, ans[N];       while (x != -1) {         ans[++cnt] = x;         x = vis[x];       }       for (int i = cnt; i >= 1; i--) printf( %d  , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const long long M = 1000000007;   const long double PI = acos((long double)-1.0);   template <typename T>   struct SegmentTree {     T data[N << 2];     T calc(const T &x, const T &y) const { return max(x, y); }     void push_up(int rt) { data[rt] = calc(data[rt << 1], data[rt << 1 | 1]); }     void build(int l, int r, int rt) {       data[rt] = 0;       if (l == r) {         return;       }       int m = (l + r) >> 1;       build(l, m, rt << 1);       build(m + 1, r, rt << 1 | 1);     }     void update(int p, T val, int l, int r, int rt) {       if (l == r) {         data[rt] = val;         return;       }       int m = (l + r) >> 1;       if (p <= m) {         update(p, val, l, m, rt << 1);       } else {         update(p, val, m + 1, r, rt << 1 | 1);       }       push_up(rt);     }     T query(int L, int R, int l, int r, int rt) {       if (L > R) {         return 0;       }       if (L <= l && r <= R) {         return data[rt];       }       int m = (l + r) >> 1;       T ret = 0;       if (L <= m) {         ret = calc(ret, query(L, R, l, m, rt << 1));       }       if (m < R) {         ret = calc(ret, query(L, R, m + 1, r, rt << 1 | 1));       }       return ret;     }   };   SegmentTree<long long> st;   int n;   struct Node {     long long v;     int id;   } a[N];   bool cmp(const Node &a, const Node &b) {     return a.v < b.v || (a.v == b.v && a.id > b.id);   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         long long r, h;         scanf( %I64d%I64d , &r, &h);         a[i].v = r * r * h;         a[i].id = i;       }       sort(a + 1, a + n + 1, cmp);       st.build(1, n, 1);       long long ans = a[0].v;       for (int i = 1; i <= n; i++) {         long long val = st.query(1, a[i].id - 1, 1, n, 1);         st.update(a[i].id, val + a[i].v, 1, n, 1);         ans = max(ans, val + a[i].v);       }       printf( %.10f n , double(PI * ans));     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1ll;   long long lim = 0, Ans = 0;   struct Plan {     long long pos;     long long c, p;   } a[N];   struct Tree {     long long c, p;     Tree() { c = p = 0; };   } t[N << 2ll];   struct Acht {     long long a, b;     Acht() { a = b = 0; };   };   bool ctrl(Plan u, Plan v) { return u.pos < v.pos; }   inline void pushup(long long u) {     t[u].c = t[u << 1ll].c + t[u << 1ll | 1ll].c;     t[u].p = t[u << 1ll].p + t[u << 1ll | 1ll].p;   }   void update(long long u, long long l, long long r, long long pos) {     if (l == r && l == a[pos].p) {       t[u].c += a[pos].c;       t[u].p += a[pos].c * a[pos].p;       return;     }     long long mid = (l + r) >> 1ll;     if (a[pos].p <= mid)       update(u << 1ll, l, mid, pos);     else       update(u << 1ll | 1ll, mid + 1ll, r, pos);     pushup(u);   }   Acht query(long long u, long long l, long long r, long long rnk) {     if (l == r) {       Acht res;       if (rnk == t[u].c)         res.a = l;       else         res.a = l - 1ll, res.b = l * rnk;       return res;     }     if (t[u].c == rnk) {       Acht res;       res.a = r;       return res;     }     long long mid = (l + r) >> 1ll;     if (t[u << 1ll].c >= rnk) return query(u << 1ll, l, mid, rnk);     return query(u << 1ll | 1ll, mid + 1ll, r, rnk - t[u << 1ll].c);   }   long long query(long long u, long long l, long long r, long long a,                   long long b) {     if (a <= l && r <= b) return t[u].p;     long long mid = (l + r) >> 1ll;     long long res = 0;     if (a <= mid) res += query(u << 1ll, l, mid, a, b);     if (b > mid) res += query(u << 1ll | 1ll, mid + 1ll, r, a, b);     return res;   }   signed main() {     long long n, k, m;     scanf( %lld%lld%lld , &n, &k, &m);     for (long long i = 1ll; i <= m; ++i) {       long long y = i << 1ll, x = y - 1ll;       scanf( %lld%lld%lld%lld , &a[x].pos, &a[y].pos, &a[x].c, &a[x].p);       a[y].pos++, a[y].c = -a[x].c, a[y].p = a[x].p;       lim = max(lim, a[x].p);     }     sort(a + 1ll, a + (m << 1ll | 1ll), ctrl);     update(1ll, 1ll, lim, 1ll);     for (long long i = 2; i <= (m << 1ll); ++i) {       long long itv = a[i].pos - a[i - 1ll].pos;       if (t[1ll].c <= k)         Ans += t[1ll].p * itv;       else {         Acht tmp = query(1ll, 1ll, lim, k);         long long res = tmp.b;         if (tmp.a) res += query(1ll, 1ll, lim, 1ll, tmp.a);         Ans += res * itv;       }       update(1ll, 1ll, lim, i);     }     printf( %lld , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct s {     int x;     int y;     int str;     s(int a, int b, int st) {       x = a;       y = b;       str = st;     }   };   bool func(s x, s y) { return x.str > y.str; }   int main() {     int n;     cin >> n;     vector
 v;     for (int i = 2; i <= 2 * n; i++) {       for (int j = 1; j < i; j++) {         int d;         cin >> d;         v.push_back(s(i, j, d));       }     }     sort(v.begin(), v.end(), func);     map<int, int> m;     for (int i = 0; i < v.size(); i++) {       if (m.find(v[i].x) != m.end() || m.find(v[i].y) != m.end()) {         continue;       }       m[v[i].x] = v[i].y;       m[v[i].y] = v[i].x;     }     for (int i = 1; i <= 2 * n; i++) {       cout << m[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T read1() {     T t = 0;     bool vis = 0;     char k;     do (k = getchar()) ==  -  && (vis = 1);     while ( 0  > k || k >  9 );     while ( 0  <= k && k <=  9 )       t = (t << 3) + (t << 1) + (k ^  0 ), k = getchar();     return vis ? -t : t;   }   vector<long long> x[500005];   vector<pair<int, int> > G[500005];   int s, k;   long long dfs(int n, int f) {     long long t = 0;     for (int i = 0; i < G[n].size(); ++i)       if (G[n][i].first ^ f) {         long long o = dfs(G[n][i].first, n);         t += o;         x[n].back() += G[n][i].second - o;       }     sort(x[n].begin(), x[n].end());     reverse(x[n].begin(), x[n].end());     int j = 0;     while (j + 1 < k && j < x[n].size() && x[n][j] > 0) t += x[n][j++];     x[f].push_back(t);     if (j < x[n].size() && x[n][j] > 0) t += x[n][j];     return t;   }   int main() {     for (int T = read1<int>(); T--;) {       s = read1<int>(), k = read1<int>();       for (int i = 0; i <= s; ++i) G[i].clear(), x[i].clear();       for (int i = 1; i < s; ++i) {         int u = read1<int>(), v = read1<int>(), t = read1<int>();         G[u].push_back(make_pair(v, t));         G[v].push_back(make_pair(u, t));       }       printf( %lld n , dfs(1, 0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, ans;     while (cin >> a >> b) {       if (a == 0 && b == 0)         cout <<  NO  << endl;       else {         ans = abs(a - b);         if (ans <= 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int number_of_ones = 0;     string binary_string;     cin >> n >> binary_string;     for (int i = 0; i < n; i++) {       if (binary_string[i] ==  1 ) number_of_ones++;       if (binary_string[i] ==  0 ) {         cout << number_of_ones;         number_of_ones = 0;       }     }     cout << number_of_ones << endl;     return 0;   }