malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int gi() {     int res = 0, w = 1;     char ch = getchar();     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (isdigit(ch)) res = res * 10 + ch -  0 , ch = getchar();     return res * w;   }   const int MAX_N = 1e6 + 5;   const int V = 1e6 + 1;   int mn[MAX_N << 2], tag[MAX_N << 2], cnt[MAX_N << 2];   void pushup(int o) {     mn[o] = min(mn[(o << 1)], mn[(o << 1 | 1)]), cnt[o] = 0;     if (mn[(o << 1)] == mn[o]) cnt[o] += cnt[(o << 1)];     if (mn[(o << 1 | 1)] == mn[o]) cnt[o] += cnt[(o << 1 | 1)];   }   void puttag(int o, int v) { tag[o] += v, mn[o] += v; }   void pushdown(int o) {     if (!tag[o]) return;     puttag((o << 1), tag[o]), puttag((o << 1 | 1), tag[o]);     tag[o] = 0;   }   void modify(int o, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) return puttag(o, v);     pushdown(o);     int mid = (l + r) >> 1;     if (ql <= mid) modify((o << 1), l, mid, ql, qr, v);     if (qr > mid) modify((o << 1 | 1), mid + 1, r, ql, qr, v);     pushup(o);   }   void mdy(int o, int l, int r, int pos, int v) {     if (l == r) return (void)(cnt[o] += v);     pushdown(o);     int mid = (l + r) >> 1;     if (pos <= mid)       mdy((o << 1), l, mid, pos, v);     else       mdy((o << 1 | 1), mid + 1, r, pos, v);     pushup(o);   }   int query(int o, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return mn[o] == 1 ? cnt[o] : 0;     pushdown(o);     int mid = (l + r) >> 1, res = 0;     if (ql <= mid) res = query((o << 1), l, mid, ql, qr);     if (qr > mid) res += query((o << 1 | 1), mid + 1, r, ql, qr);     return res;   }   void upd(int l, int r, int v) {     if (l == r) return (void)puts( xgzc ak ioi );     if (l > r) swap(l, r);     modify(1, 0, V, l, r - 1, v);   }   int N, Q, a[MAX_N];   int main() {     N = gi(), Q = gi();     for (int i = 1; i <= N; i++) a[i] = gi();     a[0] = V, a[N + 1] = 0;     for (int i = 0; i <= N; i++) upd(a[i], a[i + 1], 1), mdy(1, 0, V, a[i], 1);     while (Q--) {       int p = gi(), v = gi();       upd(a[p - 1], a[p], -1), upd(a[p], a[p + 1], -1), mdy(1, 0, V, a[p], -1);       a[p] = v;       upd(a[p - 1], a[p], 1), upd(a[p], a[p + 1], 1), mdy(1, 0, V, a[p], 1);       printf( %d n , query(1, 0, V, 1, V - 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bef[1000100], af[1000100];   long long calc(long long n) { return (n * (n + 1)) / 2; }   int main() {     int k;     string s;     cin >> k >> s;     memset(bef, 0, sizeof bef);     memset(af, 0, sizeof af);     long long last(1000010), cur(1), i(0);     vector<int> ones;     long long incase(0);     while (i < s.size()) {       while (s[i] ==  0 ) {         ++i;         ++cur;       }       incase += calc(cur - 1);       if (i < s.size()) {         bef[i] = cur;         cur = 1;         ones.push_back(i);       }       ++i;     }     if (!k) {       cout << incase;       return 0;     }     i = s.size() - 1;     cur = 1;     while (i >= 0) {       while (s[i] ==  0 ) {         --i;         ++cur;       }       if (i >= 0) {         af[i] = cur;         cur = 1;       }       --i;     }     long long ans(0);     for (int j = 0; j + k - 1 < ones.size(); ++j) {       ans += bef[ones[j]] * af[ones[j + k - 1]];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b = 0, c = 0, n, t;     cin >> t;     for (int o = 1; o <= t; o++) {       b = 0;       c = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a;         if (a != 1) {           c = 1;         } else {           if (c == 0) {             b = b + 1;           }         }       }       if (n == 1) {         cout <<  First ;       } else {         if (c == 0) {           if (n % 2 == 0) {             cout <<  Second ;           } else {             cout <<  First ;           }         } else {           if (b % 2 == 0) {             cout <<  First ;           } else {             cout <<  Second ;           }         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > G[500005];   int sz[500005];   vector<int> *vec[500005];   int cnt[(1 << 23) + 5];   int lazy[500005];   int len[500005];   int res[500005];   void get_ready(int u, int par, int mask, int hh) {     sz[u] = 1;     len[u] = hh;     lazy[u] = mask;     for (auto v : G[u])       if (v.first != par)         get_ready(v.first, u, mask ^ v.second, hh + 1), sz[u] += sz[v.first];   }   void DFS(int u, int par, int keep, int mask) {     int node = -1, mx = 0, xr = 0;     for (auto x : G[u]) {       int v = x.first;       if (par != v and sz[v] > mx) {         mx = sz[v], node = v, xr = x.second;       }     }     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) DFS(v, u, 0, x.second);     }     if (node != -1) {       DFS(node, u, 1, xr);       vec[u] = vec[node];       res[u] = max(res[u], res[node]);     } else       vec[u] = new vector<int>;     for (int i = 1; i <= (1 << 22); i <<= 1) {       res[u] = max(res[u], cnt[lazy[u] ^ i] - len[u]);     }     res[u] = max(res[u], cnt[lazy[u]] - len[u]);     cnt[lazy[u]] = max(cnt[lazy[u]], len[u]);     vec[u]->push_back(u);     for (auto x : G[u]) {       int v = x.first;       if (v != par and v != node) {         res[u] = max(res[u], res[v]);         for (auto vv : *vec[v]) {           for (int i = 1; i <= (1 << 22); i <<= 1) {             res[u] = max(res[u], len[vv] + cnt[lazy[vv] ^ i] - 2 * len[u]);           }           res[u] = max(res[u], len[vv] + cnt[lazy[vv]] - 2 * len[u]);         }         for (auto vv : *vec[v]) {           int temp = lazy[vv];           cnt[temp] = max(cnt[temp], len[vv]);           vec[u]->push_back(vv);         }         vec[v]->clear();       }     }     if (!keep) {       for (auto v : *vec[u]) cnt[lazy[v]] = -1000000000;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     for (int i = 0; i < (1 << 23) + 5; i++) cnt[i] = -1000000000;     int N;     cin >> N;     for (int i = 2; i <= N; i++) {       string ch;       int p;       cin >> p >> ch;       G[p].push_back({i, 1 << (ch[0] -  a )});       G[i].push_back({p, 1 << (ch[0] -  a )});     }     get_ready(1, -1, 0, 0);     DFS(1, -1, 1, 0);     for (int i = 1; i <= N; i++) cout << res[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, i, j, k, t;     scanf( %lld , &n);     long long int prev = 0, ans = 0, count = 0, diff = 0, sum = 0, powe = 0;     long long int a[n];     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     if (n == 1) {       cout << 0 << endl;       return 0;     }     prev = a[1] - a[0];     ans = prev;     count = 2;     for (i = 2; i < n; i++) {       count = (count * 2) % 1000000007;       powe = (count - 1) % 1000000007;       diff = (a[i] - a[i - 1]) % 1000000007;       sum = ((2 * prev) % 1000000007 + (diff * powe) % 1000000007) % 1000000007;       ans = ((ans) % 1000000007 + (sum) % 1000000007) % 1000000007;       prev = sum % 1000000007;     }     cout << ans % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long sum[500000 + 10];   int data[500000 + 10];   int main() {     int n, l, r, ql, qr;     scanf( %d%d%d%d%d , &n, &l, &r, &ql, &qr);     for (int i = 1; i <= n; ++i) {       scanf( %d , &data[i]);       sum[i] += (sum[i - 1] + data[i] * r);     }     long long ans = 100000000000000;     long long tem = 0;     for (int i = 0; i <= n; ++i) {       tem += data[i] * l;       if (0 == i)         ans = min(ans, sum[n] + (n - 1) * qr);       else if (n == i)         ans = min(ans, tem + (n - 1) * ql);       else if (i == (n - i)) {         ans = min(ans, tem + sum[n] - sum[i]);       } else if (i < (n - i))         ans = min(ans, tem + sum[n] - sum[i] + (n - i - i - 1) * qr);       else         ans = min(ans, tem + sum[n] - sum[i] + (2 * i - n - 1) * ql);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, x;   char s[3];   int main() {     cin >> n;     while (n--) {       cin >> s;       if (s[0] ==  a ) {         cin >> x;         v.insert(lower_bound(v.begin(), v.end(), x), x);       }       if (s[0] ==  d ) {         cin >> x;         v.erase(lower_bound(v.begin(), v.end(), x));       }       if (s[0] ==  s ) {         long long ans = 0;         for (int i = 2; i < v.size(); i += 5) {           ans += v[i];         }         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     int d;     for (int i = 0; i < n; i++) {       cin >> d;       sum += d;     }     int count = 5;     for (int i = 1; i <= 5; i++) {       if ((sum + i) % (n + 1) == 1) {         count--;       }     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long arr1[1000001];   template <typename T>   T myMax(T x, T y) {     return (x > y) ? x : y;   }   template <typename T>   T myMin(T x, T y) {     return (x < y) ? x : y;   }   template <typename T>   T sum(T x, T y) {     return (x + y);   }   template <typename T>   T Mean(T x, T y) {     return (x + ((y - x) / 2));   }   void seive() {     for (long long i = 0; i <= 1000000; i++) {       arr1[i] = 1;     }     for (long long i = 2; i * i <= 1000000; i++) {       if (arr1[i] == 1) {         arr1[i] = 1;         for (long long j = i * i; j <= 1000000; j = j + i) {           arr1[j] = 0;         }       }     }   }   long long find_occurances(string s) {     string s1 =   ;     long long c = 0;     for (long long i = 0; i < 3; i++) {       s1 = s1 + s[i];     }     if (s1 ==  abc ) {       c++;     }     long long n = s.size();     long long l = 0;     long long r = 2;     while (r < n - 1) {       s1.erase(s1.begin());       l++;       r++;       s1 += s[r];       if (s1 ==  abc ) {         c++;       }     }     return c;   }   bool check_power_of_2(long long x) {     if ((x & (x - 1)) == 0) {       return true;     }     return false;   }   bool cmp(pair<long long, pair<long long, long long>> x,            pair<long long, pair<long long, long long>> y) {     if (x.first == y.first) {       return x.second.second < y.second.second;     }     return x.first < y.first;   }   bool cmp1(pair<long long, long long> p, pair<long long, long long> q) {     return p.first < q.second;   }   bool check(vector<long long>& v) {     if (v[0] == 1) {       bool flag1 = true;       for (long long i = 1; i < v.size(); i++) {         if (v[i] != v[i - 1]) {           flag1 = false;           break;         }       }       return flag1;     } else {       return false;     }   }   bool check_prime(long long x) {     if (x == 2) {       return true;     }     if (x == 3) {       return true;     }     if ((x % 2) == 0) {       return false;     }     if ((x % 3) == 0) {       return false;     }     for (long long i = 5; i * i <= x; i = i + 6) {       if ((x % i) == 0) {         return false;       }       if ((x % (i + 2)) == 0) {         return false;       }     }     return true;   }   bool check_array(vector<long long>& v) {     for (long long i = 1; i < v.size(); i++) {       if (v[i] == v[i - 1]) return false;     }     return true;   }   bool is_vowel(char x) {     if ((x ==  a ) || (x ==  e ) || (x ==  o ) || (x ==  i ) || (x ==  u )) {       return true;     }     return false;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       long long sum = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];       }       if ((sum % n) == 0) {         cout << 0 <<   n ;       } else {         cout << 1 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ini;   struct TrieNode {     long long value;     TrieNode *arr[2];   };   TrieNode *newNode() {     TrieNode *temp = new TrieNode;     temp->value = 0;     temp->arr[0] = temp->arr[1] = NULL;     return temp;   }   void insert(TrieNode *root, long long pre_xor) {     TrieNode *temp = root;     for (int i = 41 - 1; i >= 0; i--) {       bool val = pre_xor & (1LL << i);       if (temp->arr[val] == NULL) temp->arr[val] = newNode();       temp = temp->arr[val];     }     temp->value = pre_xor;   }   long long query(TrieNode *root, long long pre_xor) {     TrieNode *temp = root;     for (int i = 41 - 1; i >= 0; i--) {       bool val = pre_xor & (1LL << i);       if (temp->arr[1 - val] != NULL)         temp = temp->arr[1 - val];       else if (temp->arr[val] != NULL)         temp = temp->arr[val];     }     return pre_xor ^ (temp->value);   }   long long maxSubarrayXOR(long long arr[], long long n) {     TrieNode *root = newNode();     insert(root, 0);     long long result = ini, pre_xor = 0;     for (int i = 0; i < n; i++) {       pre_xor = pre_xor ^ arr[i];       insert(root, pre_xor);       result = max(result, query(root, pre_xor ^ ini));     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long arr[100000], n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i], ini ^= arr[i];     cout << maxSubarrayXOR(arr, n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long number;       cin >> number;       if (number == 2) {         cout << 0 << endl;       } else if (number == 1) {         cout << 0 << endl;       } else {         if (number % 2 == 0) {           cout << number / 2 - 1 << endl;         } else {           cout << number / 2 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, u[6], v[6], x;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) {       scanf( %d , &x);       u[x]++;     }     for (int i = (1); i <= (n); i++) {       scanf( %d , &x);       v[x]++;     }     int dif = 0;     for (int i = (1); i <= (5); i++)       if ((u[i] + v[i]) & 1) {         printf( -1 n );         return 0;       } else         dif += max(0, (u[i] - v[i]) / 2);     printf( %d n , dif);     return 0;   }
#include <bits/stdc++.h>   long long int min(long long int x, long long int y) { return (x < y) ? x : y; }   long long int max(long long int x, long long int y) { return (x > y) ? x : y; }   long long int fastexpo(long long int base, long long int power) {     long long int res = 1;     while (power) {       if (power % 2 == 0) {         base *= base;         power /= 2;       } else {         res *= base;         power--;       }     }     return res;   }   long long int modexpo(long long int base, long long int power,                         long long int mod) {     long long int res = 1;     while (power) {       if (power % 2 == 0) {         base = (base * base) % mod;         power /= 2;       } else {         res = (base * res) % mod;         power--;       }     }     return res;   }   const long long int SN = 1e7;   bool prime[SN + 1];   void SEIVE(int n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     prime[0] = false;     prime[1] = false;   }   using namespace std;   int x[26], par[200010];   int find(int n) {     if (par[n] == n)       return n;     else       return par[n] = find(par[n]);   }   void solve() {     int n;     cin >> n;     for (long long int i = 0; i < n + 1; i++) par[i] = i;     for (long long int i = 1; i < n + 1; i++) {       string s;       cin >> s;       for (long long int j = 0; j < s.size(); j++) {         if (!x[s[j] -  a ])           x[s[j] -  a ] = i;         else           par[find(i)] = par[x[s[j] -  a ]];       }     }     int ans = 0;     for (long long int i = 1; i < n + 1; i++) {       if (par[i] == i) ans++;     }     cout << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, x, y, c1 = 0, c2 = 0, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x > 0)         c1++;       else         c2++;     }     m = min(c1, c2);     if (m <= 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     { solve(); }     return 0;   }
#include <bits/stdc++.h>   static const int MOD = 1000000007;   using ll = long long;   using u32 = unsigned;   using u64 = unsigned long long;   using namespace std;   template <class T>   constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;   char buf[200001];   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       int a = 1, b = 0;       for (int i = 0; i < n; ++i) {         if (s[i] <=  2  && t[i] <=  2 ) {         } else if (s[i] <=  2 )           b = 0;         else if (t[i] <=  2 )           a = 0;         else {           swap(a, b);         }       }       puts(b ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, r;     cin >> k >> r;     int count = 1;     int aux = k;     while (true) {       if ((k % 10 == 0) || (abs(k - r) % 10 == 0)) {         break;       } else {         k += aux;         count++;       }     }     cout << count << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, d;     cin >> n >> d;     vector<long long> delta(n);     vector<long long> rs(n);     for (int i = 0; i < n; ++i) cin >> delta[i];     rs[0] = delta[0];     for (int i = 1; i < n; ++i) rs[i] = rs[i - 1] + delta[i];     vector<long long> maxTotDeposit(n);     long long mxSoFar = LLONG_MIN;     for (int i = n - 1; i >= 0; --i) {       mxSoFar = max(mxSoFar, rs[i]);       maxTotDeposit[i] = d - mxSoFar;       if (mxSoFar > d) {         cout << -1;         return 0;       }     }     long long dep = 0;     int ans = 0;     for (int i = 0; i < n; ++i) {       if (!delta[i] && rs[i] + maxTotDeposit[i] < 0) {         cout << -1;         return 0;       }       if (!delta[i] && rs[i] + dep < 0) {         ++ans;         dep = maxTotDeposit[i];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   const int N = 1e5 + 10;   int buc[N], L, R, a[N];   long long ans;   void update(int c, int d) { ans += d * buc[c] * (long long)(buc[c] - 1) / 2; }   long long cal(int l, int r) {     while (L < l) update(a[L], -1), buc[a[L]]--, update(a[L], 1), L++;     while (L > l) L--, update(a[L], -1), buc[a[L]]++, update(a[L], 1);     while (R < r) R++, update(a[R], -1), buc[a[R]]++, update(a[R], 1);     while (R > r) update(a[R], -1), buc[a[R]]--, update(a[R], 1), R--;     return ans;   }   long long dp[22][N];   int cur;   void solve(int lb, int rb, int l, int r) {     if (lb > rb || l > r) return;     int mid = l + r >> 1;     int d = 0;     long long res = 1e18;     for (int i = lb; i <= min(rb, mid - 1); ++i) {       long long tmp = cal(i + 1, mid);       if (res > dp[cur - 1][i] + tmp) res = dp[cur - 1][i] + tmp, d = i;     }     dp[cur][mid] = res;     solve(lb, d, l, mid - 1), solve(d, rb, mid + 1, r);   }   int main() {     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     int n, m;     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]);     buc[a[1]]++, L = R = 1;     for (cur = 1; cur <= m; ++cur) solve(0, n - 1, 1, n);     printf( %lld , dp[m][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int arr[t];     for (int i = 0; i < t; i++) {       int y;       cin >> y;       y = y + i;       arr[i] = y;     }     sort(arr, arr + t);     for (int i = 0; i < t; i++) {       arr[i] -= i;     }     int check = 1;     for (int i = 0; i < t - 1; i++) {       if (arr[i] > arr[i + 1]) {         check = 0;         break;       }     }     if (check == 0)       cout <<  :(  n ;     else {       for (int i = 0; i < t; i++) {         cout << arr[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int N = 1e5 + 15, M = 105, T = 1e7 + 5;   long long maxi[N], l[N], r[N];   pair<long long, long long> f[N];   pair<long long, int> bsd(pair<long long, int> a, pair<long long, int> b) {     if (a.first > b.first || a.first == b.first && a.second < b.second)       return a;     else       return b;   }   int get(long long n, long long target, long long j) {     while (j <= n && target > r[j]) ++j;     return j;   }   int main() {     long long j = 1, g = 1, n, i, p, t, L, t0, x;     cin >> L >> n >> p >> t;     for (i = 1; i <= n; i++) cin >> l[i] >> r[i];     for (i = 1; i <= n; i++) {       maxi[i] = max(maxi[i], maxi[i - 1]);       f[i] = bsd(f[i], make_pair(maxi[i] + (r[i] - l[i]) / p,                                  l[i] + ((r[i] - l[i]) / p) * p));       t0 = f[i].second + t;       j = get(n, t0, j);       if (j > n) continue;       if (l[j] >= t0) {         maxi[j] = max(maxi[j], f[i].first);         continue;       }       f[j] = bsd(f[j], make_pair(f[i].first + (r[j] - t0) / p,                                  t0 + ((r[j] - t0) / p) * p));       maxi[j + 1] = max(maxi[j + 1], f[i].first);     }     long long ret = 0;     for (i = 1; i <= n; ++i) ret = max(ret, f[i].first);     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005, T = 100000;   int n, m, a[N], l[N], r[N];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i];     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = m; i > 0; --i) {       l[a[i] + T + i] = l[a[i] + T + i + 1] + 1;       r[a[i] + T - i] = r[a[i] + T - i - 1] + 1;     }     long long ans = 0;     for (int i = 1; i <= n; i++)       ans += min(n, i + (m + 1) - r[i + T]) - max(1, i - (m + 1) + l[i + T]) + 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, e, x, l[7], r[7];   double p, c, res, f[7][7][3];   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]);     for (i = 1; i <= 10000; i++) {       memset(f, 0, sizeof(f));       f[0][0][0] = 1;       for (j = 0; j < n; j++) {         p = 1. / (r[j] - l[j] + 1.);         for (k = 0; k <= j; k++)           for (e = 0; e < 2; e++)             if (f[j][k][e]) {               x = min(r[j] + 1, i) - l[j];               if (x > 0) f[j + 1][k][e] += f[j][k][e] * x * p;               if (i >= l[j] && i <= r[j]) f[j + 1][k + 1][e] += f[j][k][e] * p;               x = r[j] - max(l[j] - 1, i);               if (x > 0) f[j + 1][k][e + 1] += f[j][k][e] * x * p;             }       }       for (c = 0, k = 1; k <= j; k++)         for (e = 0; e < 2; e++)           if ((k > 1 && e == 0) || e == 1) c += f[n][k][e];       res += c * i;     }     printf( %.15lf n , res);     return 0;   }
#include <bits/stdc++.h>   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   int main() {     int n, a;     scanf( %d , &n);     for (int i = 1; i <= n / 2; i++) {       if (gcd(i, n - i) == 1) a = i;     }     printf( %d %d , a, n - a);   }