malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, temp, prev, A[100005];     bool f = false;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     for (int i = 0; i < k; i++) {       cin >> temp;     }     if (k == 1) {       if (n == 1) {         cout <<  Yes ;         f = true;       } else {         int prevMax;         for (int i = 0; i < n; i++) {           if (A[i] == 0) {             A[i] = temp;           }           if (i != 0) {             if (A[i] <= prevMax) {               cout <<  Yes ;               f = true;               break;             }             prevMax = A[i];           } else {             prevMax = A[0];           }         }       }     } else {       cout <<  Yes ;       f = true;     }     if (!f) {       cout <<  No ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, pair<int, int> > ins;   void operator+=(pair<int, int> &i, pair<int, int> &j) {     i.first += j.first, i.second += j.second;   }   int main() {     ins[ U ] = pair<int, int>(0, 1), ins[ D ] = pair<int, int>(0, -1),     ins[ L ] = pair<int, int>(-1, 0), ins[ R ] = pair<int, int>(1, 0);     int n, m, w = 0;     pair<int, int> p;     char s[205];     scanf( %d %s , &n, s), m = strlen(s);     for (int i = 0; i < m - 1; ++i) {       p = ins[s[i]];       for (int j = i + 1; j < m; ++j) {         p += ins[s[j]];         if (p == pair<int, int>(0, 0)) w++;       }     }     printf( %d n , w);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     vector<long long> pref(n + 1, 0);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       pref[i + 1] = pref[i] + a[i];     }     map<long long, int> m;     m[0] = 0;     long long ans = 0;     int prev = -1;     for (int i = 1; i <= n; i++) {       if (m.find(pref[i]) != m.end()) {         if (m[pref[i]] >= prev - 1) {           ans++;           prev = i;         }       }       m[pref[i]] = i;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100007];   pair<int, int> b[100007];   pair<int, int> p, r;   double t, q, x, y, w;   int fl = 1;   int main() {     int n;     int d1, d2, res = 0;     scanf( %d , &n);     ;     scanf( %d , &d1);     ;     scanf( %d , &d2);     ;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i].first);       ;       scanf( %d , &a[i].second);       ;       scanf( %d , &b[i].first);       ;       scanf( %d , &b[i].second);       ;     }     for (int i = 1; i < n; ++i) {       p.first = b[i + 1].first - a[i + 1].first;       p.second = b[i + 1].second - a[i + 1].second;       r.first = b[i].first - a[i].first;       r.second = b[i].second - a[i].second;       t = 2.0 * r.first * (p.first - r.first);       t += 2.0 * r.second * (p.second - r.second);       q = 2.0 * (r.first - p.first) * (r.first - p.first);       q += 2.0 * (r.second - p.second) * (r.second - p.second);       t = t / q;       t = -t;       x = r.first * r.first + r.second * r.second;       y = p.first * p.first + p.second * p.second;       if (t <= 0.0 || t >= 1.0) {         if (y <= 1.0 * d1 * d1 && fl == 1) {           res += 1;           fl = 0;         } else if (y > 1.0 * d2 * d2 && fl == 0)           fl = 1;       } else {         w = (t * (p.first - r.first) + r.first) *             (t * (p.first - r.first) + r.first);         w += (t * (p.second - r.second) + r.second) *              (t * (p.second - r.second) + r.second);         if (w < x) {           if (w <= 1.0 * d1 * d1 && fl == 1) {             res += 1;             fl = 0;           }           if (y > 1.0 * d2 * d2 && fl == 0) fl = 1;         } else {           if (w > 1.0 * d2 * d2 && fl == 0) fl = 1;           if (y <= 1.0 * d1 * d1 && fl == 1) {             res += 1;             fl = 0;           }         }       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400000 + 5;   int n, m, tr[N << 2][3], q;   set<int> ssp[N][2];   void modify(int x, int who, int v, int l = 1, int r = n, int k = 1) {     if (l == r) {       if (ssp[l][who].count(v))         ssp[l][who].erase(v);       else         ssp[l][who].insert(v);       tr[k][0] = ssp[l][0].empty() ? 0x3f3f3f3f : *ssp[l][0].begin();       tr[k][1] = ssp[l][1].empty() ? 0 : *ssp[l][1].rbegin();       tr[k][2] = tr[k][1] >= tr[k][0];       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       modify(x, who, v, l, mid, k << 1);     else       modify(x, who, v, mid + 1, r, k << 1 | 1);     tr[k][1] = max(tr[k << 1][1], tr[k << 1 | 1][1]);     tr[k][0] = min(tr[k << 1][0], tr[k << 1 | 1][0]);     tr[k][2] =         (tr[k << 1 | 1][1] >= tr[k << 1][0]) | tr[k << 1][2] | tr[k << 1 | 1][2];   }   void build(int l = 1, int r = n, int k = 1) {     tr[k][0] = 0x3f3f3f3f, tr[k][1] = tr[k][2] = 0;     if (l == r) return;     int mid = (l + r) >> 1;     build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     n <<= 1, m <<= 1, build();     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       if (x & 1) {         modify(x, 0, y);       } else {         --x, --y;         modify(x, 1, y);       }       printf( %s n , !tr[1][2] ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     unsigned long long k, res = 0;     cin >> n >> k;     unsigned long long *arr = new unsigned long long[n + 1];     arr[0] = 1;     for (int i = 1; i <= n; i++) arr[i] = arr[i - 1] * 2;     bool left = true;     while (n > 1) {       if (k > arr[n - 1]) {         if (left) {           res += arr[n];         } else {           res++;           left = true;         }         k -= arr[n - 1];       } else {         if (left) {           res++;         } else {           res += arr[n];         }         left = false;       }       n--;     }     if (k == 1 && left)       res += 2;     else if (k == 2 && left)       res += 3;     else if (k == 1)       res += 3;     else       res += 2;     cout << res - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     multiset<long long int> s;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       s.insert(x);     }     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       while (s.size()) {         long long int x = *(s.begin());         if (x >= i) break;         s.erase(s.begin());       }       if (!s.size()) break;       ans++;       s.erase(s.begin());     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2 )   const int P = 998244353;   int n, k, ans;   int dp[2][510][510];   int cnt[510], pre[510];   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   inline int exp_mod(int a, int n) {     int b = a, res = 1;     while (n) {       if (n & 1) res = 1ll * res * b % P;       b = 1ll * b * b % P;       n >>= 1;     }     return res;   }   int main() {     read(n);     read(k);     if (n == 1) {       printf( 0 n );       return 0;     }     dp[0][0][0] = 1;     for (int i = 0; i <= n; i++) {       int now = i & 1, nxt = now ^ 1;       for (int j = 0; j <= n; j++) {         for (int x = 0; x <= n; x++) {           dp[nxt][j][x] = 0;         }       }       for (int j = 0; j <= i; j++) {         for (int x = 0; x <= n; x++) {           dp[nxt][j + 1][max(x, j + 1)] =               (1ll * dp[nxt][j + 1][max(x, j + 1)] + dp[now][j][x]) % P;           dp[nxt][1][max(x, 1)] =               (1ll * dp[nxt][1][max(x, 1)] + dp[now][j][x]) % P;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cnt[i] = (1ll * cnt[i] + dp[n & 1][j][i]) % P;       }     }     for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + cnt[i]) % P;     for (int i = 1; i <= n; i++)       ans = (ans + 1ll * cnt[i] * 1ll * pre[min(n, (k - 1) / i)]) % P;     printf( %d n , 1ll * ans * exp_mod(2, P - 2) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 22) + 20;   bool vis[2][N];   int a[N], n, m, ex[N];   int get_not(int x) { return (1 << n) - 1 - x; }   void dfs(int type, int msk) {     vis[type][msk] = true;     if (type == 1) {       if (!vis[0][get_not(msk)]) dfs(0, get_not(msk));       for (int i = 0; i < n; i++)         if ((!(msk & (1 << i))) && (!vis[1][msk ^ (1 << i)]))           dfs(1, msk ^ (1 << i));     } else if (!vis[1][msk] && ex[msk])       dfs(1, msk);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i], ex[a[i]] = 1;     int ans = 0;     for (int i = 0; i < m; i++) {       if (!vis[0][a[i]]) dfs(0, a[i]), ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     n++;     for (int i = 1; i < n - 2; i++) {       for (int j = i; j < n - 1; j++) {         int k = (int)(i ^ j);         if (k < n && k > j) {           if (!(i ^ j ^ k)) {             double p = (i + j + k) / 2;             double s = sqrt(p * (p - i) * (p - j) * (p - k));             if (s > 0) {               sum++;             }           }         }       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b, long long p) {     long long s = 0;     while (b) {       if (b & 1) s = (s + a) % p;       a = (a + a) % p;       b >>= 1;     }     return s;   }   long long ksm(long long a, long long b, long long p) {     long long s = 1;     while (b) {       if (b & 1) s = mul(s, a, p);       a = mul(a, a, p);       b >>= 1;     }     return s;   }   int main() {     long long n;     cin >> n;     while (n--) {       long long a;       cin >> a;       long long n = to_string(a).length();       for (long long m = 0;; m++) {         long long b = ((1 << n + m) - a % (1 << n + m)) % (1 << n + m);         if ((a + b) % 5 == 0) b += 1 << n + m;         if (b < pow(10, m)) {           long long x = (a + b) >> n + m, d = -1;           for (long long i = 0; i < 5; i++)             if ((1 << i) % 5 == x % 5) {               d = i;               break;             }           for (long long i = 2, p = 5; i <= n + m; i++) {             long long phi = p / 5 * 4;             p *= 5;             for (long long k = 0; k < 5; k++)               if (ksm(2, d + k * phi, p) == x % p) {                 d += k * phi;                 break;               }           }           cout << d + n + m <<   n ;           break;         }         a *= 10;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int n, m, _m, cnt, d[maxn], fa[maxn];   bool vis[maxn];   struct Edge {     int x, y;   } Es[maxn];   long long ans;   int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   void merge(int x, int y) {     x = getfa(x);     y = getfa(y);     if (x != y) fa[x] = y;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (x != y) {         Es[++_m].x = x, Es[_m].y = y;         d[x]++;         d[y]++;         vis[x] = vis[y] = true;         merge(x, y);       } else         cnt++, vis[x] = true;     }     int rt = 0;     for (int i = 1; i <= n; i++)       if (vis[i]) rt = i;     if (!rt) return printf( 0 n ), 0;     for (int i = 1; i <= n; i++)       if (vis[i] && getfa(rt) != getfa(i)) return printf( 0 n ), 0;     for (int i = 1; i <= _m; i++) ans += (d[Es[i].x] - 1) + (d[Es[i].y] - 1);     ans = ans / 2 + (long long)_m * cnt + (long long)cnt * (cnt - 1) / 2;     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b;     cin >> n >> a >> b;     long long ma, mi;     ma = max(a, b);     mi = min(a, b);     long long seated = 0;     for (long long i = (long long)(0); i < (long long)(n); i++) {       char t;       cin >> t;       while (t ==  .  and i < n) {         if (ma != 0) {           ma--;           seated++;         }         a = ma;         ma = mi;         mi = a;         i++;         if (i < n) cin >> t;       }       a = ma;       ma = max(mi, ma);       mi = min(mi, a);     }     cout << seated << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   int num[222222];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> num[i];     int sum = 1;     int ans = 1;     for (int i = 1; i < n; i++) {       if (num[i] <= num[i - 1] * 2) {         sum++;       } else {         ans = max(ans, sum);         sum = 1;       }     }     ans = max(ans, sum);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     double df, de;     void init(double _df, double _de) {       df = _df;       de = _de;     }   } V[100];   int nf, ne, ns, rf, re, rs, df, de;   int n, top, place[13];   double ans = 0, dp[21][21], lf, le, ls;   bool cmp(const point &a, const point &b) { return a.df > b.df; }   double cross(double l1, double r1, double l2, double r2) {     if (l2 >= r1 || l1 >= r2) return 0;     return min(r1, r2) - max(l1, l2);   }   void init_V() {     top = 0;     for (int i = 0; i < n; i++)       if (place[i] < 2) {         double t1 = lf * df, t2 = le * de;         for (int j = 0; j < n; j++)           if (place[j]) {             t1 += df * place[j] *                   cross(j - ls / 2, j + ls / 2, i - lf / 2, i + lf / 2);             t2 += de * place[j] *                   cross(j - ls / 2, j + ls / 2, i - le / 2, i + le / 2);           }         for (int j = 1; j + place[i] <= 2; j++) V[top++].init(t1, t2);       }     sort(V, V + top, cmp);   }   void init_dp() {     memset(dp, 0, sizeof(dp));     for (int i = 0; i <= nf; i++)       for (int j = 0; j <= ne; j++) {         if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + V[i + j - 1].df);         if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + V[i + j - 1].de);       }     ans = max(ans, dp[nf][ne]);   }   void dfs(int p, int left) {     if ((n - p) * 2 < left) return;     if (p == n) {       init_V();       init_dp();       return;     }     for (int i = 0; i <= 2 && left >= i; i++) {       place[p] = i;       dfs(p + 1, left - i);     }   }   int main() {     cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de;     n = (nf + ne + ns) / 3 * 2 + 1;     lf = 2 * sqrt(rf * rf - 1.0);     le = 2 * sqrt(re * re - 1.0);     ls = 2 * sqrt(rs * rs - 1.0);     dfs(0, ns);     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10003;   int32_t main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     if (n == 1) {       cout <<  0 ;       return 0;     }     n--;     long long ans = 0;     ans += min(a, b);     n--;     if (min(a, b) > c) {       ans += n * c;       cout << ans;       return 0;     }     ans += n * min(a, b);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> vec1, vec2, vec3;     int n, sz;     cin >> n;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       if (x == 1)         vec1.push_back(i);       else if (x == 2)         vec2.push_back(i);       else         vec3.push_back(i);     }     sz = min(min(vec1.size(), vec2.size()), vec3.size());     cout << sz << endl;     for (int i = 0; i < sz; ++i)       cout << vec1[i] <<     << vec2[i] <<     << vec3[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[100000], r, arr1[100000], z;   bool boo[100000];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> r;       arr[i] = r;     }     for (int i = 0; i < n; i++) arr1[i] = arr[i];     reverse(arr1, arr1 + n);     z = arr1[0];     boo[0] = 1;     for (int i = 0; i < n; i++) {       if (arr1[i] > z) boo[i] = 1;       if (arr1[i] >= z)         z = arr1[i];       else         arr1[i] = z;     }     reverse(arr1, arr1 + n);     reverse(boo, boo + n);     for (int i = 0; i < n; i++) {       int k = arr1[i] - arr[i];       if (boo[i] == 1)         cout << 0 << endl;       else         cout << k + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[222222];     scanf( %d n , &n);     pair<int, int> p;     vector<pair<int, int> > v, v1;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       p.first = x;       p.second = 0;       v.push_back(p);     }     reverse(v.begin(), v.end());     int maxi = v[0].first, pos = 0;     ;     for (int i = 0; i < v.size(); i++) {       if (pos != i) {         if (maxi >= v[i].first) v[i].second = maxi - v[i].first + 1;         if (maxi < v[i].first) {           maxi = v[i].first;           pos = i;         }       }     }     reverse(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) printf( %d  , v[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     s += s;     int ans = -1;     int len = 1;     for (int i = 1; i < 2 * n; i++) {       if (s[i] != s[i - 1])         len++;       else {         if (len <= n) ans = max(len, ans);         len = 1;       }     }     if (len <= n) ans = max(len, ans);     if (len > n) ans = n;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int curr = 1;     for (int i = 0; i < n; i++) {       if (arr[i] >= curr) {         curr++;       }     }     cout << curr;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long dp[255][255];   long long p[255], q[255], C[255][255];   int N;   long long K;   void init() {     cin >> N >> K;     p[0] = q[0] = C[0][0] = 1;     for (int i = 1; i <= 250; i++) {       p[i] = p[i - 1] * K % MOD;       q[i] = q[i - 1] * (K - 1) % MOD;       C[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }     }   }   void solve() {     dp[0][0] = 1;     for (int r = 1; r <= N; r++) {       for (int c = 1; c <= N; c++) {         for (int a = 0; a <= c; a++) {           if (a == c) {             dp[r][c] = (dp[r][c] + ((p[c] + MOD - q[c]) * q[N - c] % MOD *                                     dp[r - 1][c] % MOD)) %                        MOD;           } else {             dp[r][c] = (dp[r][c] + (C[N - a][c - a] * p[a] % MOD * q[N - c] %                                     MOD * dp[r - 1][a] % MOD)) %                        MOD;           }         }       }     }     cout << dp[N][N] <<   n ;   }   int main() {     init();     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 10;   int n, tot;   int a[N], vis[N], twom[N], threem[N];   vector<int> x, y;   stack<int> one, two, three;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = n; i >= 1; --i) {       if (a[i] == 1) {         one.push(i);       } else if (a[i] == 2) {         if (!one.size()) {           cout << -1 << endl;           return 0;         } else {           twom[i] = one.top();           one.pop();         }         two.push(i);       } else if (a[i] == 3) {         if (three.size()) {           threem[i] = three.top();           three.pop();         } else if (two.size()) {           threem[i] = two.top();         } else if (one.size()) {           threem[i] = one.top();           one.pop();         } else {           cout << -1 << endl;           return 0;         }         three.push(i);       }     }     int currow = 1;     for (int i = 1; i <= n; ++i) {       if (a[i] == 0 || vis[i] == 1) continue;       int curcol = i;       while (curcol) {         vis[curcol] = 1;         if (a[curcol] == 1) {           x.push_back(currow);           y.push_back(curcol);           curcol = 0;           ++currow;         } else if (a[curcol] == 2) {           x.push_back(currow);           y.push_back(curcol);           curcol = twom[curcol];         } else if (a[curcol] == 3) {           x.push_back(currow);           y.push_back(curcol);           curcol = threem[curcol];           x.push_back(currow);           y.push_back(curcol);           ++currow;         }       }     }     cout << x.size() << endl;     for (int i = 0; i <= (int)x.size() - 1; ++i) printf( %d %d n , x[i], y[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<pair<long long, int> > v;   int main() {     long long a, b, d;     cin >> a;     cin >> b;     d = a * b / gcd(a, b);     if (a < b) {       for (int i = 0; i * a <= d; i++) {         v.push_back(make_pair(i * a, 1));       }       for (int i = 0; i * b <= d; i++) {         v.push_back(make_pair(i * b, 0));       }     } else {       for (int i = 0; i * a <= d; i++) {         v.push_back(make_pair(i * a, 0));       }       for (int i = 0; i * b <= d; i++) {         v.push_back(make_pair(i * b, 1));       }     }     sort(v.begin(), v.end());     long long s1, s2;     s1 = 0;     s2 = 0;     for (int i = 0; i < (int)v.size() - 1; i++) {       if (v[i + 1].second == 0) {         s1 += v[i + 1].first - v[i].first;       } else         s2 += v[i + 1].first - v[i].first;     }     if (a > b) {       if (s1 > s2) printf( Dasha n );       if (s1 < s2) printf( Masha n );     } else {       if (s1 < s2) printf( Dasha n );       if (s1 > s2) printf( Masha n );     }     if (s1 == s2) printf( Equal n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp;   long long ar[200005];   long long br[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> ar[i];       }       long long prv = 1;       mp[0] = 0;       long long ans = 0;       for (int i = 1; i <= n; i++) {         br[i] = br[i - 1] + ar[i];         if (mp.count(br[i])) {           prv = max(prv, mp[br[i]] + 2);         }         ans += i - prv + 1;         mp[br[i]] = i;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n + 1);     vector<int> b(n + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a.begin() + 1, a.end());     for (int i = 1; i <= n / 2; i++) b[2 * i] = a[i];     for (int i = n / 2 + 1; i <= n; i++) b[(i - n / 2) * 2 - 1] = a[i];     int ans = 0;     for (int i = 2; i < n; i++) ans += (b[i] < b[i - 1]) * (b[i] < b[i + 1]);     cout << ans << endl;     for (auto i = b.begin() + 1; i != b.end(); i++) cout << *i <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << (n * n) / 4 << endl;     for (int i = 1; i <= n / 2; i++) cout << n <<     << i << endl;     for (int i = 1; i <= n / 2; i++)       for (int j = n / 2 + 1; j < n; j++) cout << i <<     << j << endl;   }