malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000000, inv2 = (MOD + 1) / 2;   long double eps = 1e-6;   int dx[4] = {-1, 1, 0, 0};   int dy[4] = {0, 0, -1, 1};   long double pi = acos(-1.0L);   struct node {     int x, y, z, op, id;   } a[1000000 + 10], c[1000000 + 10];   bool cmp(node a, node b) {     if (a.z != b.z) return a.z < b.z;     return a.op < b.op;   }   int f[1000000 + 10], used[1000000 + 10], n, m, k;   int read() {     int v = 0, f = 1;     char c = getchar();     while (c < 48 || 57 < c) {       if (c ==  -- ) f = -1;       c = getchar();     }     while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();     return v * f;   }   long long readll() {     long long v = 0, f = 1;     char c = getchar();     while (c < 48 || 57 < c) {       if (c ==  - ) f = -1;       c = getchar();     }     while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();     return v * f;   }   int dsu(int k) {     if (f[k] != k) f[k] = dsu(f[k]);     return f[k];   }   pair<int, long long> calc(int mid) {     for (int i = (int)1; i <= (int)m; i++) {       c[i] = a[i];       if (c[i].op) c[i].z += mid;     }     sort(c + 1, c + m + 1, cmp);     for (int i = (int)1; i <= (int)m; i++) used[i] = 0;     for (int i = (int)1; i <= (int)n; i++) f[i] = i;     int s = 0, num = n;     long long ans = 0;     for (int i = (int)1; i <= (int)m; i++) {       int x = dsu(c[i].x), y = dsu(c[i].y);       if (x != y && s + c[i].op <= k) {         f[x] = y;         ans += c[i].z;         used[c[i].id] = 1;         s += c[i].op;         num--;       }     }     if (num != 1) ans = 2e10;     return make_pair(s, ans);   }   void solve() {     pair<int, long long> t = calc(-2e5);     if (t.second == 2e10 || t.first < k) {       printf( -1 n );       return;     }     t = calc(2e5);     if (t.second < 2e10 && t.first > k) {       printf( -1 n );       return;     }     int l = -1e5, r = 1e5;     int ans = -1e5;     while (l <= r) {       int mid = (l + r) >> 1;       if (calc(mid).first >= k)         l = mid + 1, ans = mid;       else         r = mid - 1;     }     if (calc(ans).first > k) ans++, calc(ans);     int res = 0;     for (int i = (int)1; i <= (int)m; i++)       if (used[i]) res++;     printf( %d n , res);     for (int i = (int)1; i <= (int)m; i++)       if (used[i]) printf( %d  , i);   }   int main() {     n = read(), m = read(), k = read();     for (int i = (int)1; i <= (int)m; i++) {       a[i].x = read(), a[i].y = read(), a[i].z = read();       if (a[i].x == 1 || a[i].y == 1) a[i].op = 1;       a[i].id = i;     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<pair<int, int> > > mp;     int res[200], mini = INT_MAX;     for (int i = 0; i < n; i++) {       pair<int, int> p;       scanf( %d%d , &p.first, &p.second);       mp[p.first].push_back({p.second, i});     }     int cur = 0;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     for (auto m : mp) {       while (!pq.empty() && cur < m.first) {         auto j = pq.top();         pq.pop();         res[j.second] = cur++;       }       if (pq.empty()) {         cur = m.first;       }       for (auto i : m.second) {         pq.push(i);       }     }     while (!pq.empty()) {       auto j = pq.top();       pq.pop();       res[j.second] = cur++;     }     for (int i = 0; i < n; i++) {       cout << res[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535897932384626433832795;   double eps = 1e-14;   char ch[1 << 20];   inline string gs() {     scanf( %s , ch);     return string(ch);   }   inline int gi() {     int x;     scanf( %d , &x);     return x;   }   void error() {     int ttt = 0;     cout << 7 / ttt;   }   long long gcd(long long a, long long b) { return (!a) ? b : gcd(b % a, a); }   const long long mod = 1000 * 1000 * 1000 + 7;   inline long long MUL(long long a, long long b) { return a * b % mod; }   inline long long ADD(long long a, long long b) {     return (a + b >= mod) ? a + b - mod : a + b;   }   inline long long SUB(long long a, long long b) {     return (a - b < 0) ? a + mod - b : a - b;   }   const int BLOCK = 10000;   int nP[20000], B[BLOCK];   int P[20000], C;   int go(int n1, int n) {     C = 0;     for (int i = 2; i * i <= n; ++i)       if (!nP[i]) {         P[C++] = i;         for (int j = i + i; j * j <= n; j += i) nP[j] = 1;       }     int res = 0;     for (int k = 0, mxk = n / BLOCK; k <= mxk; ++k) {       memset(B, 0, sizeof(B));       int beg = k * BLOCK;       for (int i = 0; i < C; ++i)         for (int j = max((beg + P[i] - 1) / P[i], 2) * P[i] - beg; j < BLOCK;              j += P[i])           B[j] = 1;       if (!k) B[0] = B[1] = 1;       int x = beg;       for (int i = 0; i < BLOCK && beg + i <= n; ++i) {         if (!B[i] && x >= n1 && ((x & 3) == 1 || x == 2)) ++res;         ++x;       }     }     return res;   }   int main() {     int a, b;     scanf( %d%d , &a, &b);     int r = go(a, b);     printf( %d n , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double EPS = 1e-9;   const int INF = 1 << 29;   int const NN = 1e6 + 6;   string s;   string t[NN];   pair<pair<int, int>, int> p[NN];   int tot = 0;   int mxI[NN];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       cin >> t[i];       int len = t[i].length();       int k;       scanf( %d , &k);       for (int j = 0; j < k; ++j) {         int x;         scanf( %d , &x);         --x;         int y = x + len - 1;         p[tot++] = make_pair(make_pair(x, y), i);       }     }     sort(p, p + tot);     int mnIdx = NN, mxIdx = -1;     int mx = -1;     for (int i = 0; i < tot; ++i) {       if (p[i].first.second > mx) {         mxI[i] = i;         mx = p[i].first.second;       } else         mxI[i] = mxI[i - 1];       mnIdx = min(mnIdx, p[i].first.first);       mxIdx = max(mxIdx, p[i].first.second);     }     for (int i = 0; i <= mxIdx; ++i) s +=  a ;     for (int i = 0; i < mnIdx; ++i) s[i] =  a ;     for (int i = mnIdx; i <= mxIdx; ++i) {       int lo = 0, hi = tot - 1, mid;       while (lo <= hi) {         mid = (lo + hi) >> 1;         if (p[mid].first.first > i)           hi = mid - 1;         else           lo = mid + 1;       }       if (p[mid].first.first > i) --mid;       if (mid < 0) {         s[i] =  a ;         continue;       }       int idx = mxI[mid];       int xx = p[idx].first.first;       int yy = p[idx].first.second;       int indexx = p[idx].second;       if (i > yy || i < xx) {         s[i] =  a ;         continue;       }       s[i] = t[indexx][i - xx];     }     cout << s;     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n, k;     string s;     cin >> q;     while (q--) {       cin >> n >> k >> s;       string rgb =  RGB ;       int cnt = 0, ans = k;       for (int i = 0; i <= n - k; i++) {         for (int j = 0; j < 3; j++) {           cnt = 0;           for (int m = 0; m < k; m++)             if (s[i + m] != rgb[(j + m) % 3]) cnt++;           if (cnt < ans) ans = cnt;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, ans, a, b;   int main() {     scanf( %d%d , &n, &k);     while (n--) {       scanf( %d%d , &a, &b);       x += b - a + 1;     }     x = (k - (x % k)) % k;     printf( %d , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     long long ans = (n * (n - 1)) / 2;     long long l = 0, r = n - 1;     while (s[l] == s[0]) l++;     while (s[r] == s[n - 1]) r--;     r = n - 1 - r;     long long num = 0;     for (long long i = 1; i < n; i++) {       if (s[i] != s[i - 1]) {         num++;       }     }     cout << ans - (2 * n) + l + r + num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int digit[32];   long long dp[32][32][2];   long long dfs(int p, int k, bool tag) {     int i;     long long ret = 0;     if (p == -1) return 1;     if (~dp[p][k][tag]) return dp[p][k][tag];     if (!k)       ret = (ret + dfs(p - 1, k, tag && !digit[p])) % 1000000007;     else {       ret = (ret + (dfs(p - 1, k, tag && !digit[p]) << (k - 1)) % 1000000007) %             1000000007;       if (!tag || digit[p])         ret = (ret + (dfs(p - 1, k, tag) << (k - 1)) % 1000000007) % 1000000007;     }     if (!tag || digit[p])       ret = (ret + dfs(p - 1, k + 1, tag && digit[p])) % 1000000007;     return dp[p][k][tag] = ret;   }   int main() {     int k, p;     while (cin >> k) {       memset(dp, -1, sizeof(dp));       for (p = 0; k; k >>= 1) digit[p++] = (k & 1);       cout << dfs(p - 1, 0, true) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXVAL = 1000000;   const int MAXCNT = 200000;   const int MOD = 1000000007;   int n, want, nq;   int cnt[MAXVAL + 1];   int dv[MAXVAL + 1];   int tot[MAXVAL + 1];   int fac[MAXCNT + 1];   int inv[MAXCNT + 1];   int ifac[MAXCNT + 1];   int ans;   int C(int n, int k) {     if (k > n) return 0;     return (long long)fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;   }   void inc(int x, int y) {     if (x == 1) {       ans -= (long long)tot[y] * C(cnt[y], want) % MOD;       if (ans < 0) ans += MOD;       ++cnt[y];       ans += (long long)tot[y] * C(cnt[y], want) % MOD;       if (ans >= MOD) ans -= MOD;     } else {       int t = 0, z = dv[x];       while (dv[x] == z) x /= dv[x], ++t;       for (int i = (0); i <= (t); ++i) {         inc(x, y);         y *= z;       }     }   }   void run() {     memset(dv, -1, sizeof(dv));     for (int i = (2); i <= (MAXVAL); ++i)       if (dv[i] == -1)         for (int j = i; j <= MAXVAL; j += i) dv[j] = i;     tot[1] = 1;     for (int i = (2); i <= (MAXVAL); ++i) {       int j = i / dv[i];       tot[i] = tot[j] * (dv[i] - (dv[j] != dv[i] ? 1 : 0));     }     fac[0] = 1;     for (int i = (1); i <= (MAXCNT); ++i)       fac[i] = (long long)fac[i - 1] * i % MOD;     inv[1] = 1;     for (int i = (2); i <= (MAXCNT); ++i)       inv[i] = (MOD - (long long)(MOD / i) * inv[MOD % i] % MOD) % MOD;     ifac[0] = 1;     for (int i = (1); i <= (MAXCNT); ++i)       ifac[i] = (long long)ifac[i - 1] * inv[i] % MOD;     scanf( %d%d%d , &n, &want, &nq);     ans = 0;     for (int i = (0); i < (n); ++i) {       int x;       scanf( %d , &x);       inc(x, 1);     }     for (int i = (0); i < (nq); ++i) {       int x;       scanf( %d , &x);       inc(x, 1);       printf( %d n , ans);     }   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int N = 1000005;   const double PI = 4 * atan(1);   const long long MAX = 9223372036854775807;   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }   bool isprime(long long u) {     for (long long i = 2; i <= (int)sqrt(u); i++) {       if (u % i == 0) return 0;     }     return 1;   }   long long mod(long long to_mod, long long MOD) {     to_mod %= MOD;     while (to_mod < 0) to_mod += MOD;     return to_mod % MOD;   }   long long moduloMultiplication(long long a, long long b) {     long long res = 0;     while (b) {       if (b & 1) res = (res + a);       a = (2 * a);       b >>= 1;     }     return res;   }   long long power(long long x, long long y, long long p) {     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;   }   long long q, y, k, z, w, t, l, r, x, n, m;   long long a[N];   stack<long long> ss;   int main() {     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] = a[i] % 2;     }     for (int i = 0; i < n;) {       if (i == n - 1) {         if (!ss.empty() && a[i] == ss.top()) {           ss.pop();         } else {           ss.push(a[i]);         }         i++;       } else {         if (!ss.empty() && a[i] == ss.top()) {           ss.pop();           i++;         } else if (a[i] == a[i + 1]) {           i += 2;         } else {           ss.push(a[i]);           i++;         }       }     }     if (ss.size() >= 2)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   const int N = 3e5 + 5;   int T, n, i, x, d, v, o;   inline int mx(int x, int y) { return x > y ? x : y; }   inline int mn(int x, int y) { return x < y ? x : y; }   int main() {     for (scanf( %d , &T); T--;) {       d = 0, v = 1e9, o = 1;       scanf( %d , &n);       for (i = 1; i <= n; ++i) {         scanf( %d , &x);         if (!o) continue;         x -= d;         if (x < 0) {           o = 0;           continue;         }         d += mx(x - v, 0);         v = mn(v, x);       }       if (o)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long INF = 1e18;   struct P {     int id;     long long dis;     friend bool operator<(P a, P b) { return a.dis > b.dis; }   };   int n, m, q, x[N], y[N], t[N], l[2][N], id[N], c;   long long d[2][N], ans[N], pre[N];   vector<long long> add[N], del[N];   vector<int> g[N];   void dij(int p, int s) {     memset(d[p], 0x3f, sizeof(d[p])), d[p][s] = 0;     if (p) memset(pre, 0, sizeof(pre));     priority_queue<P> q;     q.push((P){s, 0ll});     while (!q.empty()) {       int u = q.top().id;       long long nd = q.top().dis;       q.pop();       if (nd != d[p][u]) continue;       for (auto e : g[u]) {         int v = x[e] + y[e] - u;         long long w = t[e];         if (d[p][u] + w < d[p][v])           q.push((P){v, d[p][v] = d[p][u] + w}), pre[v] = e;       }     }   }   void it(int p, int s) {     priority_queue<P> q;     for (int i = 1; i <= n; i++)       if (l[p][i] || i == 1) q.push((P){i, l[p][i]});     while (!q.empty()) {       int u = q.top().id;       q.pop();       for (auto e : g[u])         if (!id[e]) {           int v = x[e] + y[e] - u;           long long w = t[e];           if (d[p][u] + w == d[p][v] && l[p][u] < l[p][v])             q.push((P){v, l[p][v] = l[p][u]});         }     }   }   void solve(int i) {     if (l[0][x[i]] >= l[1][y[i]]) return;     long long val = d[0][x[i]] + t[i] + d[1][y[i]];     add[l[0][x[i]]].push_back(val), del[l[1][y[i]]].push_back(val);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &x[i], &y[i], &t[i]);       g[x[i]].push_back(i), g[y[i]].push_back(i);     }     dij(0, 1), dij(1, n), memset(l[0], 0x3f, sizeof(l[0]));     for (int u = 1; u != n;) {       int e = pre[u], v = x[e] + y[e] - u;       u = v, l[0][u] = l[1][u] = id[e] = ++c, l[1][u] = -l[1][u];     }     l[0][1] = 0, it(0, 1), it(1, n);     for (int i = 1; i <= n; i++) l[1][i] = -l[1][i];     for (int i = 1; i <= m; i++)       if (!id[i]) solve(i), swap(x[i], y[i]), solve(i);     multiset<long long> s;     s.insert(INF);     for (int i = 0; i < c; i++) {       for (auto v : add[i]) s.insert(v);       for (auto v : del[i]) s.erase(v);       ans[i + 1] = *s.begin();     }     while (q--) {       int e;       long long len;       scanf( %d%lld , &e, &len);       long long res = len + min(d[0][x[e]] + d[1][y[e]], d[0][y[e]] + d[1][x[e]]);       if (len <= t[e] || !id[e])         res = min(res, d[0][n]);       else if (id[e])         res = min(res, ans[id[e]]);       printf( %lld n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int max(long long int x, long long int y) {     if (x >= y) return x;     return y;   }   long long int min(long long int x, long long int y) {     if (x > y) return y;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, i, j = 0, k = 0;       cin >> n;       long long int a[n];       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 1 && k == 0) {           j++;         } else           k = 1;       }       if ((j % 2 == 0 && k == 1) || (j % 2 == 1 && k == 0))         cout <<  First n ;       else         cout <<  Second n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int l = -INF, r = INF, a = 0;     while (n--) {       int a_, d;       cin >> a_ >> d;       if (d == 1)         l = max(l, 1900 - a);       else         r = min(r, 1899 - a);       a += a_;     }     if (r != INF && l <= r)       cout << r + a <<   n ;     else if (r == INF)       cout <<  Infinity n ;     else       cout <<  Impossible n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = 3.1415926536;   int dX[] = {1, -1, 0, 0};   int dY[] = {0, 0, 1, -1};   int main() {     int a, b, c, x, y, z, extra = 0, need = 0;     cin >> a >> b >> c >> x >> y >> z;     if (a > x)       extra += ((a - x) / 2) * 2;     else       need += x - a;     if (b > y)       extra += ((b - y) / 2) * 2;     else       need += y - b;     if (c > z)       extra += ((c - z) / 2) * 2;     else       need += z - c;     if (extra / 2 >= need)       cout <<  Yes n ;     else       cout <<  No n ;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); }   double dcmp(double a, double b) {     return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1;   }   const int MAX_SIZE = 3e5 + 5;   const int MOD = 1e9 + 7;   int r = 0;   long long segtree[MAX_SIZE * 4];   void update(long long L, long long R, long long t, long long val,               long long idx) {     if (L == R && R == t) {       segtree[idx] += val;       segtree[idx] %= MOD;       return;     }     if (L > t || R < t) return;     update(L, (L + R) / 2, t, val, idx * 2);     update((L + R) / 2 + 1, R, t, val, idx * 2 + 1);     segtree[idx] = (segtree[idx * 2] + segtree[idx * 2 + 1]) % MOD;   }   long long query(long long L, long long R, long long tl, long long tr,                   long long idx) {     if (L >= tl && R <= tr) {       return segtree[idx] % MOD;     }     if (L > tr || R < tl) return 0;     return (query(L, (L + R) / 2, tl, tr, idx * 2) +             query((L + R) / 2 + 1, R, tl, tr, idx * 2 + 1)) %            MOD;   }   map<long long, long long> rnk;   int main() {     set<long long> tmp;     long long n, m, a, b;     vector<pair<long long, long long> > data;     cin >> n >> m;     tmp.insert(0);     tmp.insert(n);     for (long long i = 0; i < m; i++) {       cin >> a >> b;       data.push_back({b, a});       tmp.insert(a);       tmp.insert(b);       tmp.insert(b - 1);     }     for (long long x : tmp) {       rnk[x] = ++r;     }     sort(data.begin(), data.end());     update(0, MAX_SIZE - 1, 1, 1, 1);     for (int i = 0; i < m; i++) {       swap(data[i].second, data[i].first);       int x =           query(0, MAX_SIZE - 1, rnk[data[i].first], rnk[data[i].second - 1], 1);       update(0, MAX_SIZE - 1, rnk[data[i].second], x, 1);     }     cout << query(0, MAX_SIZE - 1, rnk[n], rnk[n], 1) % MOD;   }
#include <bits/stdc++.h>   using namespace std;   int mp[505][505], f[505];   void push(int n) {     for (int i = 1; i <= n; i++) cout << f[i] <<    ;     cout << endl;   }   int main() {     int n, m, i, j, Q, sum, x, y;     while (scanf( %d%d%d , &n, &m, &Q) != EOF) {       memset(f, 0, sizeof(f));       for (i = 1; i <= n; i++)         for (j = 1; j <= m; j++) scanf( %d , &mp[i][j]);       int ans = 0, maxn = 0, sum = 0;       for (i = 1; i <= n; i++) {         sum = 0;         maxn = 0;         for (j = 1; j <= m; j++) {           if (mp[i][j] == 1)             sum++;           else {             maxn = max(maxn, sum);             sum = 0;           }         }         f[i] = max(maxn, sum);       }       while (Q--) {         scanf( %d%d , &x, &y);         if (mp[x][y] == 0)           mp[x][y] = 1;         else           mp[x][y] = 0;         maxn = 0, sum = 0;         for (j = 1; j <= m; j++) {           if (mp[x][j] == 1)             sum++;           else {             maxn = max(maxn, sum);             sum = 0;           }         }         maxn = max(maxn, sum);         f[x] = maxn;         for (i = 1; i <= n; i++) maxn = max(maxn, f[i]);         ans = maxn;         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:500000000 )   using namespace std;   int A[222];   bool used[222];   int main() {     int n, k, i;     cin >> n >> k;     for (i = 0; i < 2 * n + 1; i++) cin >> A[i];     int N = 2 * n + 1;     memset(used, false, sizeof(used));     while (k) {       for (i = 1; i < N && k > 0; i++)         if ((i & 1) && !used[i] && A[i] - 1 > A[i - 1] && A[i] - 1 > A[i + 1])           used[i] = true, A[i]--, k--;     }     printf( %d , A[0]);     for (i = 1; i < N; i++) printf(  %d , A[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mo(long long a) { return a % (long long)(1e9 + 7); }   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y >>= 1;       x = (x * x) % p;     }     return res % p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n);       for (long long i = 0; i < a.size(); i++) cin >> a[i];       ;       vector<long long> sp;       long long i = 0;       while (i < n && a[i] == 0) i++;       for (; i < n; i++) {         while (i < n && a[i]) i++;         long long cnt = 0;         while (i < n && a[i] == 0) {           cnt++;           i++;         }         sp.push_back(cnt);       }       if (a[n - 1] == 0) sp.pop_back();       long long ans = 0;       for (long long e : sp) ans += e;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast_IO_file() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast_IO_file();     string s1, s2;     getline(cin, s1);     getline(cin, s2);     map<char, long long int> m1;     map<char, long long int> m2;     for (long long int i = 0; i < s1.size(); i++) {       if (s1[i] ==    )         continue;       else         m1[s1[i]]++;     }     for (long long int i = 0; i < s2.size(); i++) {       if (s2[i] ==    )         continue;       else         m2[s2[i]]++;     }     long long int count = 0;     for (long long int i = 0; i < s2.size(); i++) {       if (s2[i] ==    )         continue;       else {         if (m1[s2[i]] < m2[s2[i]]) {           count = 1;           break;         }       }     }     if (count == 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool flag = false;     int n, boro;     cin >> n;     int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     for (int i = 0; i < 1; i++) {       boro = max(a[i], b[i]);     }     for (int i = 1; i < n; i++) {       if (max(a[i], b[i]) <= boro) {         boro = max(a[i], b[i]);       } else if (min(a[i], b[i]) <= boro) {         boro = min(a[i], b[i]);       } else {         flag = true;         break;       }     }     if (flag == false)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }