malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, a, b, c, d, mn, mx;     cin >> a >> b >> c >> d;     mn = min(b, d);     b -= mn;     d -= mn;     if (d > b) {       for (i = 0; i < 1000; i++) {         if (d % a == 0) {           cout << d + mn;           return 0;         }         d += c;       }     } else if (d < b) {       for (i = 0; i < 1000; i++) {         if (b % c == 0) {           cout << b + mn;           return 0;         }         b += a;       }     } else if (d == b) {       cout << d + mn;       return 0;     }     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct T {     double x, y;   };   T ball;   double g1, g2, r, h;   double ll, rr, eps = 1e-8;   int main() {     scanf( %lf%lf%lf%lf%lf%lf , &g1, &g2, &h, &ball.x, &ball.y, &r);     ll = 0;     rr = ball.x;     while (rr - ll > eps) {       double m = (ll + rr) / 2;       double xl = m - (ball.x - m);       double a, b, c;       a = ball.y - (h - r);       b = m - xl;       c = -a * m - b * (h - r);       double yl = -c / b;       if (yl < g1)         rr = m;       else if (yl > g2)         ll = m;       else {         if ((b * g2 + c) / sqrt(a * a + b * b) < r)           ll = m;         else if (yl - r < g1)           rr = m;         else {           printf( %.10lf , m);           return 0;         }       }     }     printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 301000, MMax = 200;   int N, A[NMax];   map<int, int> S;   long long sum[NMax];   vector<int> R;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , A + i);       S[A[i]] = max(S[A[i]], i);       if (A[i] >= 0)         sum[i] = sum[i - 1] + A[i];       else         sum[i] = sum[i - 1];     }     long long maxx = -(~0uLL >> 1);     pair<int, int> ans;     for (int i = 1; i <= N; i++) {       int t = S[A[i]];       if (t > i) {         long long first = sum[t] - sum[i - 1];         if (A[i] < 0) first += (long long)A[i] * 2;         if (first > maxx) {           maxx = first;           ans = make_pair(i, t);         }       }     }     printf( %I64d  , maxx);     for (int i = 1; i < ans.first; i++) R.push_back(i);     for (int i = ans.first + 1; i < ans.second; i++)       if (A[i] < 0) R.push_back(i);     for (int i = ans.second + 1; i <= N; i++) R.push_back(i);     printf( %d n , (int)R.size());     for (int i = 0; i < R.size(); i++) printf( %d  , R[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long toInt(string s) {     long v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   inline T sqr(T x) {     return x * x;   }   long long pw(long long x, long long y) {     long long ans = 1;     for (long long i = 0; i < y; i++) {       ans = ans * x;     }     return ans;   }   long long factorial(long long x) {     long long ans = 1;     for (int i = 1; i < x + 1; i++) {       ans = ans * i;     }     return ans;   }   long long combination(long long x, long long y) {     return factorial(x) / factorial(y) / factorial(x - y);   }   long long permutation(long long x, long long y) {     return factorial(x) / factorial(x - y);   }   string flip(string s) {     string ss;     for (int i = 0; i < s.size(); i++) {       ss = toString(s[i]) + ss;     }     return ss;   }   long long mod(long long a, long long b) {     if (a % b == 0) {       return 0;     } else {       return a % b;     }   }   int main() {     long long n;     cin >> n;     vector<long long> v(n);     long long a, b;     for (long long i = 0; i < n - 1; i++) {       cin >> a >> b;       v[a - 1]++;       v[b - 1]++;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (v[i] >= 2) {         ans += combination(v[i], 2);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 998244353, M = 16;   int n, m, a[35], x[10], y[10];   int f[31][M][M][M][M][2][2];   bool v[31][M][M][M][M][2][2];   int F(int bit, int JW1, int JW2, int JW3, int JW4, int fl1, int fl2) {     if (bit == 30) return !JW1 && !JW2 && !JW3 && !JW4 && fl1 && fl2;     if (v[bit][JW1][JW2][JW3][JW4][fl1][fl2])       return f[bit][JW1][JW2][JW3][JW4][fl1][fl2];     v[bit][JW1][JW2][JW3][JW4][fl1][fl2] = 1;     int &ans = f[bit][JW1][JW2][JW3][JW4][fl1][fl2];     for (int sta = (int)(0); sta <= (int)((1 << n) - 1); sta++) {       int NJW1 = JW1, NJW2 = JW2, NJW3 = JW3, NJW4 = JW4;       for (int i = (int)(1); i <= (int)(n); i++)         if (sta & (1 << (i - 1))) {           if (x[i] <= 0) NJW1 -= x[i];           if (y[i] <= 0) NJW2 -= y[i];           if (x[i] >= 0) NJW3 += x[i];           if (y[i] >= 0) NJW4 += y[i];         }       if (((NJW1 ^ NJW3) & 1) || ((NJW2 ^ NJW4) & 1)) continue;       int nfl1 = ((NJW3 & 1) == a[bit] ? fl1 : (NJW3 & 1) < a[bit]);       int nfl2 = ((NJW4 & 1) == a[bit] ? fl2 : (NJW4 & 1) < a[bit]);       NJW1 /= 2;       NJW2 /= 2;       NJW3 /= 2;       NJW4 /= 2;       ans = (ans + F(bit + 1, NJW1, NJW2, NJW3, NJW4, nfl1, nfl2)) % mo;     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (int)(0); i <= (int)(29); i++) a[i] = (m >> i) & 1;     bool fl1 = 0, fl2 = 0, fl3 = 0, fl4 = 0;     for (int i = (int)(1); i <= (int)(n); i++) {       scanf( %d%d , &x[i], &y[i]);       fl1 |= (x[i] < 0);       fl2 |= (x[i] > 0);       fl3 |= (y[i] < 0);       fl4 |= (y[i] > 0);     }     if (!fl1 || !fl2 || !fl3 || !fl4) return puts( 0 ), 0;     printf( %d n , (F(0, 0, 0, 0, 0, 1, 1) + mo - 1) % mo);   }
#include <bits/stdc++.h>   using namespace std;   int deg[200040], erased[200500], depth[200040];   void dfs(int x, int d, vector<vector<int>>& adj, int pa) {     for (auto u : adj[x])       if (u != pa) dfs(u, d + 1, adj, x);     depth[x] = d;   }   int main() {     int n;     cin >> n;     vector<vector<int>> adj(n + 1);     int root;     for (int i = 1; i <= n; i++) {       int p;       cin >> p;       if (p == 0) {         root = i;         continue;       }       adj[p].push_back(i);       adj[i].push_back(p);       deg[i]++;       deg[p]++;     }     dfs(root, 0, adj, 0);     set<pair<int, int>> S;     for (int i = 1; i <= n; i++) {       if (deg[i] % 2 == 0) S.insert({-depth[i], i});     }     vector<int> res;     while (!S.empty()) {       int x = (*S.begin()).second;       S.erase({-depth[x], x});       erased[x] = 1;       for (auto u : adj[x]) {         if (erased[u]) continue;         deg[u]--;         if (deg[u] % 2 == 0) {           S.insert({-depth[u], u});         } else           S.erase({-depth[u], u});       }       res.push_back(x);     }     if (res.size() != n) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (auto u : res) {       cout << u << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1005];   int main() {     int i, t, mini = 1000000, s, val, tfin;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (t = 1; t <= 105; t++) {       s = 0;       for (i = 1; i <= n; i++) {         val = abs(t + 1 - a[i]);         val = min(val, abs(t - a[i]));         val = min(val, abs(t - 1 - a[i]));         s += val;       }       if (mini > s) {         mini = s;         tfin = t;       }     }     cout << tfin <<     << mini;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long md = 1000000007;   long long bexp(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long r = bexp(a, b / 2);     r = r * r;     if (b % 2 == 0)       return r;     else       return r * a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case--) {       long long n, i, j, m, k;       cin >> n;       long long a[n];       for (i = 0; i < n; i++) {         cin >> a[i];       }       long long pr = -1;       long long ans = 0;       for (i = 0; i < n; i++) {         if (a[i] != 0) {           if (pr == -1) {             pr = i;           } else {             ans += i - pr - 1;             pr = i;           }         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int P = 998244353;   int n, m, a[N], pre[N], rec[N], f[N];   inline void add(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) x += P;   }   struct BL {     int bel[N], tag[450], w[N], size, cnt, sum[450][N], ans[450];     void init() {       sum[1][0] = ans[1] = 1;       size = sqrt(n);       for (int i = 1; i <= n; ++i) bel[i] = (i - 1) / size + 1;       cnt = bel[n];       for (int i = 1; i <= cnt; ++i) tag[i] = m;     }     void update(int pos, int x) {       int px = bel[pos];       sub(sum[px][w[pos]], f[pos - 1]);       if (w[pos] <= tag[px]) sub(ans[px], f[pos - 1]);       w[pos] = x;       add(sum[px][x], f[pos - 1]);       if (x <= tag[px]) add(ans[px], f[pos - 1]);     }     void ins(int x, int y, int d) {       if (x > y) return;       if (bel[x] + 1 >= bel[y]) {         for (int i = x; i <= y; ++i) update(i, w[i] + d);         return;       }       for (int i = x; i <= bel[x] * size; ++i) update(i, w[i] + d);       for (int i = (bel[y] - 1) * size + 1; i <= y; ++i) update(i, w[i] + d);       for (int i = bel[x] + 1; i <= bel[y] - 1; ++i) {         if (d > 0) sub(ans[i], sum[i][tag[i]]);         tag[i] -= d;         if (d < 0) add(ans[i], sum[i][tag[i]]);       }     }     int qry(int x) {       int res = 0;       for (int i = x; bel[i] == bel[x]; --i)         if (w[i] <= tag[bel[x]]) add(res, f[i - 1]);       for (int i = bel[x] - 1; i >= 1; --i) add(res, ans[i]);       return res;     }   } bl;   int main() {     scanf( %d%d , &n, &m);     bl.init();     f[0] = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       pre[i] = rec[a[i]], rec[a[i]] = i;       bl.ins(pre[pre[i]] + 1, pre[i], -1), bl.ins(pre[i] + 1, i, 1);       f[i] = bl.qry(i);       add(bl.sum[bl.bel[i + 1]][0], f[i]);       add(bl.ans[bl.bel[i + 1]], f[i]);     }     printf( %d n , f[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b <= 0 ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <class T>   T large(T a, T b) {     return a > b ? a : b;   }   template <class T>   T small(T a, T b) {     return a < b ? a : b;   }   template <class T>   T dif(T a, T b) {     return a - b < 0 ? b - a : a - b;   }   template <class T>   string toStr(const T &x) {     stringstream s;     s << x;     return s.str();   }   template <class T>   int toInt(const T &x) {     stringstream s;     s << x;     int r;     s >> r;     return r;   }   void in() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     map<int, vector<pair<int, string> > > m1;     map<int, string> m2;     int n, m, a, b, i;     string s;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> s >> a >> b;       m1[a].push_back(make_pair(b, s));     }     for (i = 0; i < m1.size(); i++) {       sort(m1[i].rbegin(), m1[i].rend());     }     for (auto it : m1) {       for (i = 0; i < it.second.size(); i++) {         if (it.second[1].first == it.second[2].first) {           cout <<  ?  << endl;           break;         } else {           if (i < 1)             cout << it.second[i].second <<     << it.second[i + 1].second << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 1e6;   const int INF = 0x7fffffff;   const int mod = 1e9 + 7;   const double eps = 1e-7;   const double Pi = acos(-1.0);   inline int read_int() {     char c;     int ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   inline long long read_ll() {     char c;     long long ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   int n, res = 1;   string s;   int main() {     cin >> n >> s;     for (int i = 1; i < n; i++) {       res += (s[i] != s[i - 1]);     }     cout << ((res + 2) < (n) ? (res + 2) : (n)) << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main(){    int t;    cin >> t;    while(t--){     int n;     cin >> n;     vector <int> a(n);     int k = INT_MAX,z = -1;     for(int i=0;i<n;i++){      cin >> a[i];      k = min(k,a[i]);      if(k==a[i]){       z = i;      }     }     cout << n-1 << endl;     for(int i=0;i<n;i++){      if(i!=z){       cout << i+1 <<     << z+1 <<     << max(1,k+abs(z-i)) <<     << k << endl;      }     }     //cout << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     map<int, vector<int> > vec;     for (int i = 0; i < a; i++) {       int g;       cin >> g;       vec[g % c].push_back(g);     }     for (int i = 0; i < c; i++) {       if (vec[i].size() >= b) {         cout <<  Yes  << endl;         for (int j = 0; j < b; j++) {           cout << vec[i][j];           if (j != b - 1) {             cout <<    ;           } else {             cout << endl;           }         }         return 0;       }     }     cout <<  No  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-4;   const long double PI = acos((long double)-1.0);   const long long int MOD = 1e9 + 7;   long long int powmod(long long int a, long long int b, long long int mod) {     long long int res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   const int debug = 1;   template <typename T>   void DBG(vector<T> v) {     if (debug) {       for (T t : v) cout << t <<     ;       cout << endl;     }   }   template <typename T>   void DBG(T t) {     if (debug) cout << t << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(10);     cout << fixed;     string s;     cin >> s;     vector<int> counts(26, 0);     for (char c : s) {       counts[c -  a ]++;     }     vector<char> result(s.size(),  . );     for (int prime = 2; prime <= s.size(); prime++) {       bool is_prime = true;       for (int divisor = 2; divisor * divisor <= prime; divisor++) {         if (prime % divisor == 0) {           is_prime = false;           break;         }       }       if (is_prime) {         set<char> se;         for (int i = prime; i <= s.size(); i += prime) {           for (int divisor = 2; divisor * divisor <= i; divisor++) {             if (i % divisor == 0) se.insert(result[divisor - 1]);           }         }         se.erase( . );         if (se.size() > 1) {           cout <<  NO  << endl;           return 0;         }         char c;         if (se.size() == 1) {           char c = *se.begin();         } else {           int m = 0;           for (int k = 0; k < (26); ++k) {             if (counts[m] < counts[k]) m = k;           }           c =  a  + m;         }         for (int i = prime; i <= s.size(); i += prime) {           if (result[i - 1] ==  . ) {             if (!counts[c -  a ]) {               cout <<  NO  << endl;               return 0;             }             counts[c -  a ]--;             result[i - 1] = c;           }         }       }     }     for (int i = 0; i < (26); ++i) {       if (counts[i]) result[0] =  a  + i;     }     DBG( YES );     DBG(string(result.begin(), result.end()));   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   void debugi(vector<int>& vec) {     int n = (int)vec.size();     for (int i = 0; i < n; i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   void debugl(vector<ll>& vec) {     int n = (int)vec.size();     for (int i = 0; i < n; i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   void debugmap(map<int, int>& mp) {     for (auto x : mp) {       cout << x.first <<     << x.second <<   ,  ;     }     cout << endl;   }   void debugset(set<int>& st) {     for (auto x : st) {       cout << x <<    ;     }     cout << endl;   }   void debugparri(vector<pair<int, int>>& arr) {     for (int i = 0; i < (int)arr.size(); i++) {       cout <<  [  << arr[i].first <<   :   << arr[i].second <<  ]             <<    ;     }     cout << endl;   }   void debugpi(pair<int, int>& pi) {     cout << pi.first <<     << pi.second << endl;   }   void debugq(queue<int> q) {     while (!q.empty()) {       cout << q.front() <<    ;       q.pop();     }     cout << endl;   }   ll mod = 1000000007;   bool check(int n, int i, int j) {     if ((0 <= i & i < n) && (0 <= j & j < n)) {       return true;     }     return false;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int tt = 0; tt < t; tt++) {       int n;       cin >> n;       vector<int> arr(n);       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       vector<int> pre(n), suf(n);       int s = 0;       for (int i = 0; i < n; i++) {         if (arr[i] != i + 1) {           s += 1;         }         pre[i] = s;       }       s = 0;       for (int i = n - 1; i >= 0; i--) {         if (arr[i] != i + 1) {           s += 1;         }         suf[i] = s;       }       int cnt = 0;       for (int i = 0; i < n; i++) {         if (pre[i] != 0 && suf[i] != 0 && arr[i] == i + 1) {           cnt += 1;         }       }       if (cnt == 0) {         if (s == 0) {           cout << 0 << endl;           continue;         } else {           cout << 1 << endl;           continue;         }       }       cout << 2 << endl;       continue;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 200;   long long c[N][N], dp[N][N * N + N], g[N][N];   long long modp(long long a, long long b) {     if (b == 0) return 1;     long long u = modp(a, b / 2);     u = (u * u) % mod;     if (b & 1) return (a * u) % mod;     return u;   }   int32_t main() {     long long n, m, o;     cin >> n >> m >> o;     for (long long i = 0; i < N; i++) c[i][0] = dp[i][0] = 1;     for (long long i = 1; i < N; i++)       for (long long j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     for (long long i = 1; i <= n; i++)       for (long long j = 0; j <= n; j++) g[i][j] = modp(c[n][j], (m + n - i) / n);     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n * i; j++)         for (long long k = max(j - n, 0LL); k <= j; k++) {           dp[i][j] = (dp[i][j] + dp[i - 1][k] * g[i][j - k]) % mod;         }     cout << dp[n][o] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     if (abs(a) + abs(b) <= n) {       if ((n - abs(a) - abs(b)) % 2 == 0)         cout <<  Yes ;       else         cout <<  No ;     } else {       cout <<  No ;     }   }
#include <bits/stdc++.h>   using namespace std;   int l[100000], r[100000], u[100000], d[100000];   int dp[2], dp2[2];   int main() {     int i;     int n, m, q;     char c;     scanf( %d %d %d , &n, &m, &q);     for (i = 0; i < n; i++) scanf(  %c , &c), l[i] = (c ==  B );     for (i = 0; i < n; i++) scanf(  %c , &c), r[i] = (c ==  B );     for (i = 0; i < m; i++) scanf(  %c , &c), u[i] = (c ==  B );     for (i = 0; i < m; i++) scanf(  %c , &c), d[i] = (c ==  B );     for (i = 0; i < n; i++) dp[!l[i]]++;     dp[!u[0]]++, dp[!d[0]]++;     for (i = 1; i < m; i++) {       dp2[0] = min(dp[0], dp[1] + n) + u[i] + d[i];       dp2[1] = min(dp[1], dp[0] + n) + !u[i] + !d[i];       swap(dp, dp2);     }     for (i = 0; i < n; i++) dp[!r[i]]++;     int ans = min(dp[0], dp[1]);     dp[0] = dp[1] = 0;     for (i = 0; i < m; i++) dp[!u[i]]++;     dp[!l[0]]++, dp[!r[0]]++;     for (i = 1; i < n; i++) {       dp2[0] = min(dp[0], dp[1] + m) + l[i] + r[i];       dp2[1] = min(dp[1], dp[0] + m) + !l[i] + !r[i];       swap(dp, dp2);     }     for (i = 0; i < m; i++) dp[!d[i]]++;     ans = min(ans, min(dp[0], dp[1]));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, now;   int a[3005], b[3005];   int vis[3005], f[3005], c[3005];   int ok[3005];   int findcir(int *a, int n) {     int ret = 0;     for (int i = 1; i <= n; i++) b[a[i]] = i;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int j;       ret++;       for (j = i; !vis[j]; j = b[j]) {         f[j] = ret;         vis[j] = 1;         c[ret]++;       }     }     return ret;   }   void Swap(int x) {     if (!x) return;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (f[i] == f[j]) {           printf( %d %d  , i, j);           x--;           if (!x) return;           swap(a[i], a[j]);           findcir(a, n);         }   }   void move(int x) {     if (!x) return;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (f[i] != f[j]) {           printf( %d %d  , i, j);           x--;           if (!x) return;           swap(a[i], a[j]);           findcir(a, n);         }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     now = findcir(a, n);     now = n - now;     scanf( %d , &m);     printf( %d n , abs(now - m));     if (now > m) {       Swap(now - m);     } else       move(m - now);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   set<long long> s;   set<int> si;   set<long long>::iterator it;   vector<long long> v;   vector<int> vi;   int n, m, q, k;   int a[200005];   int main() {     int i, j, t;     int w, h;     ;     scanf( %d%d , &w, &h);     ;     int u1, d1, u2, d2;     ;     scanf( %d%d , &u1, &d1);     ;     ;     scanf( %d%d , &u2, &d2);     ;     for (i = h; i >= 0; i--) {       w = w + i;       if (d1 == i) w -= u1;       if (d2 == i) w -= u2;       w = max(0, w);     }     printf( %d n , w);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, x;   vector<int> a;   long long int tarkib(long long int r, long long int n) {     long long int a = 1;     for (long long int i = n; i > (n - r); i--) a = a * i;     for (long long int i = 2; i < r + 1; i++) a = a / i;     return a;   }   int main() {     long long int r;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     long long int i;     for (i = 3; i < n; i++) {       if (a[i] > a[i - 1]) break;     }     i--;     i--;     if (a[0] == a[1]) {       if (a[1] == a[2]) {         r = 3;         i += 2;       } else {         r = 1;       }     } else {       if (a[1] == a[2]) {         i++;         r = 2;       } else {         r = 1;       }     }     cout << tarkib(r, i);     return 0;   }