malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, root;   int val[100000], maxl[100000], maxr[100000];   vector<int> fo[100000];   void dfs(int vr) {     if (fo[vr].size() == 0) {       maxl[vr] = maxr[vr] = val[vr];       return;     }     dfs(fo[vr][0]);     dfs(fo[vr][1]);     maxl[vr] = maxl[fo[vr][0]];     maxr[vr] = maxr[fo[vr][1]];   }   map<int, int> rev1;   map<int, int> revq, vals;   double sum[100000], pl[100000];   void dfs1(int vr, int par = -1) {     if (par == -1) {       pl[vr] = 0;       sum[vr] = 0;     } else {       pl[vr] = pl[par] + 1;       if (fo[par][0] == vr)         sum[vr] = sum[par] + maxl[fo[par][1]];       else         sum[vr] = sum[par] + maxr[fo[par][0]];     }     if (!fo[vr].empty()) {       dfs1(fo[vr][0], vr);       dfs1(fo[vr][1], vr);     }   }   vector<int> ID, IDX;   void dfs2(int vr, int f, int t) {     if (f > t) return;     if (fo[vr].size() == 0) {       for (int i = f; i <= t; ++i) IDX[i] = vr;       return;     }     int DEL = (int)(lower_bound(ID.begin() + f, ID.begin() + t + 1, val[vr]) -                     ID.begin());     dfs2(fo[vr][0], f, DEL - 1);     dfs2(fo[vr][1], DEL, t);   }   int main() {     int i, j, k, l;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       int _p, _v;       scanf( %d%d , &_p, &_v);       --_p;       if (_p < 0)         root = i;       else         fo[_p].push_back(i);       val[i] = _v;     }     for (i = 0; i < n; ++i) {       if (!fo[i].empty())         if (val[fo[i][0]] > val[i]) swap(fo[i][0], fo[i][1]);       rev1[val[i]] = i;     }     dfs(root);     dfs1(root);     int Q;     scanf( %d , &Q);     ID.resize(Q);     IDX.resize(Q);     for (i = 0; i < Q; ++i) {       scanf( %d , &ID[i]);       revq[i] = ID[i];     }     sort(ID.begin(), ID.end());     for (i = 0; i < ID.size(); ++i) vals[ID[i]] = i;     dfs2(root, 0, Q - 1);     for (i = 0; i < Q; ++i)       printf( %.12lf n , sum[IDX[vals[revq[i]]]] / pl[IDX[vals[revq[i]]]]);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline void umax(long long &a, long long b) { a = max(a, b); }   inline void umin(long long &a, long long b) { a = min(a, b); }   inline pair<long long, long long> rv(pair<long long, long long> a) {     return make_pair(a.second, a.first);   }   const long long N = 2e5 + 10;   const long long INF = 1e16 + 10;   const pair<long long, long long> NINF = make_pair(INF, INF);   const long double EPS = 1e-6;   const long long II = 1e9;   const long long MOD = 1e9 + 9;   long long dp[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     string second;     cin >> second;     queue<pair<long long, long long> > buf;     for (long long i = 0; i < (min(k, n)); i++)       if (second[i] ==  1 ) buf.push(make_pair(i + 1, i + k));     for (long long i = 0; i < (n + 1); i++) dp[i] = INF;     dp[0] = 1;     for (long long i = 0; i < n; i++) {       if (i + k < n && second[i + k] ==  1 )         buf.push(make_pair(i + k + 1, i + k * 2));       if (buf.size()) {         auto beg = buf.front();         long long pr = beg.second - k * 2 - 1;         long long ll = (pr >= 0 ? dp[pr] : 0LL);         umin(dp[i], ll + beg.first);         if (beg.second == i) buf.pop();       }       if (i) umin(dp[i], dp[i - 1] + i + 1);     }     cout << dp[n - 1];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, t;     cin >> n >> t;     string s;     cin >> s;     char temp;     while (t--) {       for (int i = 0; i < n - 1; i++) {         if (s[i] != s[i + 1] && s[i] ==  B ) {           temp = s[i + 1];           s[i + 1] = s[i];           s[i] = temp;           i++;         }       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> g(n);       for (int i = 0; i < n; i++) cin >> g[i];       auto flip = [&](int i, int j) {         if (g[i][j] ==  0 )           g[i][j] =  1 ;         else           g[i][j] =  0 ;       };       vector<array<int, 6> > v;       for (int i = 0; i + 2 < n; i++) {         for (int j = 0; j < m; j++) {           if (g[i][j] ==  1 ) {             if (j == m - 1) {               v.push_back({i, j, i + 1, j, i + 1, j - 1});               flip(i + 1, j);               flip(i + 1, j - 1);               flip(i, j);             } else {               v.push_back({i, j, i + 1, j, i + 1, j + 1});               flip(i + 1, j);               flip(i + 1, j + 1);               flip(i, j);             }           }         }       }       for (int j = 0; j + 2 < m; j++) {         if (g[n - 2][j] ==  1 ) {           v.push_back({n - 2, j, n - 2, j + 1, n - 1, j + 1});           flip(n - 2, j);           flip(n - 2, j + 1);           flip(n - 1, j + 1);         }         if (g[n - 1][j] ==  1 ) {           v.push_back({n - 1, j, n - 2, j + 1, n - 1, j + 1});           flip(n - 1, j);           flip(n - 2, j + 1);           flip(n - 1, j + 1);         }       }       vector<vector<int> > r(2, vector<int>(2, 0));       if (g[n - 2][m - 2] ==  1 ) {         r[0][1] ^= 1;         r[1][0] ^= 1;         r[1][1] ^= 1;       }       if (g[n - 2][m - 1] ==  1 ) {         r[0][0] ^= 1;         r[1][0] ^= 1;         r[1][1] ^= 1;       }       if (g[n - 1][m - 2] ==  1 ) {         r[0][0] ^= 1;         r[0][1] ^= 1;         r[1][1] ^= 1;       }       if (g[n - 1][m - 1] ==  1 ) {         r[0][0] ^= 1;         r[0][1] ^= 1;         r[1][0] ^= 1;       }       if (r[0][0]) v.push_back({n - 2, m - 1, n - 1, m - 2, n - 1, m - 1});       if (r[0][1]) v.push_back({n - 2, m - 2, n - 1, m - 2, n - 1, m - 1});       if (r[1][0]) v.push_back({n - 2, m - 2, n - 2, m - 1, n - 1, m - 1});       if (r[1][1]) v.push_back({n - 2, m - 2, n - 2, m - 1, n - 1, m - 2});       cout << v.size() <<   n ;       for (auto z : v)         cout << z[0] + 1 <<     << z[1] + 1 <<     << z[2] + 1 <<     << z[3] + 1              <<     << z[4] + 1 <<     << z[5] + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long maxn = 3e6;   const long long mod = 1e9 + 7;   const long double PI = acos((long double)-1);   long long pw(long long a, long long b, long long md = mod) {     long long res = 1;     while (b) {       if (b & 1) {         res = (a * res) % md;       }       a = (a * a) % md;       b >>= 1;     }     return (res);   }   int n;   long long l[maxn], r[maxn];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> r[i];     long long p = 1, q = 0, sum = 0, sm = 0;     for (int i = 0; i < n; i++) {       if (i) {         long long a = max(0LL, min(r[i], r[i - 1]) - max(l[i], l[i - 1]) + 1);         long long b = (r[i] - l[i] + 1) * (r[i - 1] - l[i - 1] + 1) % mod;         p = ((b - a + mod) % mod * pw(b, mod - 2)) % mod;       }       sum = (sum + p) % mod;       sm = (sm + pw(p, 2) + (2LL * (p - 1) * (q - 1)) % mod + mod) % mod;       q = p;     }     long long ans = (sum * (sum + 1) - sm + mod * 100LL) % mod;     for (int i = 2; i < n; i++) {       long long a = max(0LL, min({r[i], r[i - 1], r[i - 2]}) -                                  max({l[i], l[i - 1], l[i - 2]}) + 1);       long long b = max(0LL, r[i - 2] - l[i - 2] + 1);       b = (b * max(0LL, r[i - 1] - l[i - 1] + 1)) % mod;       b = (b * max(0LL, r[i] - l[i] + 1)) % mod;       p = (a * pw(b, mod - 2)) % mod;       ans = (ans + 2 * p) % mod;     }     cout << ans <<   n ;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> dx = {-1, 0, 0, 1};   vector<int> dy = {0, -1, 1, 0};   const int Mod = (int)((int)1e9 + 7);   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     for (int i = 1; i < n; i++) {       while (a[i] + a[0] <= k) {         a[i] += a[0];         ans++;       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     cin >> q;     for (int i = 1; i <= q; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int game[2];     int m, c;     m = c = 0;     for (int i = 0; i < n; i++) {       cin >> game[0] >> game[1];       if (game[0] > game[1]) {         m++;       } else if (game[0] < game[1]) {         c++;       }     }     if (m > c) {       cout <<  Mishka  << endl;     } else if (m < c) {       cout <<  Chris  << endl;     } else {       cout <<  Friendship is magic!^^  << endl;     }   };
#include <bits/stdc++.h>   using namespace std;   int n;   int b[3100];   int a[3100];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);       int bb = b[i] - b[i - 1], l;       if (bb > 0) {       youginzi:         l = 1;         while (bb) {           while (a[l] == 9) l++;           a[l]++;           --bb;         }       } else if (bb < 0) {         while (bb) {           if (bb > 0) goto youginzi;           l = 0;           while (a[++l] == 0)             ;           do {             bb += a[l] - 1;             a[l] = 0;             ++a[++l];           } while (a[l] >= 10);         }       } else {         l = 0;         while (a[++l] == 0)           ;         do {           bb += a[l] - 1;           a[l] = 0;           ++a[++l];         } while (a[l] >= 10);         goto youginzi;       }       int len = 3005;       while (a[len] == 0) --len;       for (int j = len; j >= 1; --j) printf( %d , a[j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   int n, m, i, j, t, a[30005];   long long s0, s1;   int main() {     read(t);     while (t--) {       read(n);       for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]);       a[n + 1] = 0;       for (((i)) = ((n + 1)); ((i)) >= (1); ((i))--) a[i] = a[i] - a[i - 1];       s0 = a[1];       s1 = a[n + 1];       for ((i) = (2); (i) <= (n); (i)++)         if (a[i] > 0)           s1 += a[i];         else           s0 += a[i];       if (s1 <= 0 && s0 >= 0)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       long k;       scanf( %ld , &k);       int d;       scanf( %d , &d);       long arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       if (d == 1) {         cout << 1 << endl;       } else {         set<long> con;         unordered_map<long, int> cnt;         for (int i = 0; i < d; i++) {           con.insert(arr[i]);           cnt[arr[i]]++;         }         long ans = con.size();         long final = con.size();         if (final == 1) {           cout << 1 << endl;         } else {           for (int i = 0; i < n - d; i++) {             cnt[arr[i]]--;             if (cnt[arr[i]] == 0) {               ans--;             }             cnt[arr[i + d]]++;             if (cnt[arr[i + d]] == 1) {               ans++;             }             final = min(final, ans);           }           cout << final << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long a, b, n, m;       scanf( %lld%lld%lld%lld , &a, &b, &n, &m);       if (a < m || b < m) {         printf( No n );         continue;       }       if ((a + b) < (m + n)) {         printf( No n );         continue;       }       if (a <= b) {         a -= m;       } else {         b -= m;       }       if (a + b >= n) {         printf( Yes n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   char scn[N][2];   int l, x, mem;   string s;   int main() {     l = 1;     x = 25;     cin >> s;     for (int i = 1; i <= 10000; i++) {       scn[i][1] =  . ;     }     mem = 0;     l = 1;     for (int i = 0; i < s.size(); i++) {       while (mem != s[i]) {         l++;         scn[l][1] =  X ;         l++;         mem--;         if (mem < 0) {           mem = 256 + mem;         }       }       scn[l][1] =  X ;       l++;     }     for (int i = 1; i <= l; i++) {       cout << scn[i][1] <<  .  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int n, r;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d , &n, &r);       r--;       int sum = 0;       for (int i = 0; i < n - 1; i++) {         int a;         scanf( %d , &a);         a--;         sum = (sum + a) % n;       }       int res = (r - sum + n) % n;       printf( %d n , res + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, n, m, s;   int a[1000], b[1000];   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> l;       a[l]++;     }     for (i = 1; i <= 110; i++) {       s = 0;       for (j = i; j <= i + m; j++) s = s + a[j];       k = max(k, s);     }     cout << n - k;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     long long int brstr = 0;     brstr += (n - 3) * (n - 4);     brstr += 3 * (n - 3);     cout << brstr + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> seive() {     long long n = 2;     vector<long long> pr(200000, -1);     for (int i = n; i < 200000; i++) {       if (pr[i] == -1)         pr[i] = 1;       else         continue;       for (int j = 2 * i; j < 200000; j += i) pr[j] = 0;     }     return pr;   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   bool isprime(long long n) {     bool flag = true;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = false;         break;       }     }     return flag;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     vector<int> le, ri;     int l = 0, r = s.size() - 1;     while (l < r) {       while (l < s.size() && s[l] ==  ) ) l++;       while (r >= 0 && s[r] ==  ( ) r--;       if (l < s.size() && r >= 0 && l < r) {         le.push_back(l + 1);         ri.push_back(r + 1);         l++;         r--;       }     }     if (le.empty()) {       cout <<  0 n ;       return 0;     }     cout <<  1 n ;     cout << 2 * le.size() <<   n ;     for (auto x : le) cout << x <<    ;     reverse(ri.begin(), ri.end());     for (auto x : ri) cout << x <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 5, M = 2e4 + 5;   int a[105], b[300];   int dp[105][M];   int main() {     int t;     cin >> t;     while (t--) {       memset(dp, 0, sizeof(dp));       int n, k, l;       scanf( %d %d %d , &n, &k, &l);       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 0; i <= k; i++) b[i] = i;       for (int i = 1; i < k; i++) b[k + i] = k - i;       for (int i = 0; i < 2 * k; i++) dp[0][i] = 1;       for (int i = 1; i <= n; i++)         for (int j = 0; j < 2 * k * n; j++) {           dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - 1]);           if (l < b[j % (2 * k)] + a[i]) dp[i][j] = 0;         }       int flag = 0;       for (int i = 0; i < 2 * k * n; i++)         if (dp[n][i]) {           flag = 1;           break;         }       if (flag)         printf( Yes n );       else         printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[24], n, Z[24];   bool DP[24][(1 << 23) + 5];   vector<int> X;   map<int, int> Memo;   int main() {   std:     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       Memo[a[i]] = i + 1;     }     Z[0] = 1;     DP[0][0] = 1;     for (int i = 1; i < n; i++) {       int b = 1 << i;       for (int j = 1; j < b; j++) {         if (j & (1 << (i - 1))) {           int cnt = 0, ch = 0;           for (int k = 0; k < i; k++) {             if (j & 1 << k) {               int P = a[i] - a[k];               if (Memo[P] != 0) {                 if (j & 1 << (Memo[P] - 1)) ch = 1;               }               cnt++;             }           }           if (ch == 1) {             int mmask = j & (~(1 << (i - 1)));             if (DP[i - 1][mmask] == 1) ch = 2;             for (int k = 0; k < i - 1; k++) {               if (!(mmask & 1 << k)) {                 int mask = 1 << k;                 mask = mask | mmask;                 if (DP[i - 1][mask] == 1) ch = 2;               }             }           }           if (ch == 2) {             DP[i][j] = 1;             if (cnt < Z[i] || Z[i] == 0) Z[i] = cnt;           }         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (Z[i] == 0) {         cout <<  -1 n ;         return 0;       }       if (ans < Z[i]) ans = Z[i];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int v = 3 - n % 3, ans = 0;     for (int i = v;; i += 3) {       if (1LL * i * (i + 1) / 2 > (n + i) / 3) break;       ++ans;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int mod = 1e9 + 7, maxn = 1e6, maxm = 6;   int n, a[maxn], b[maxn], c[maxn], g[maxn], pw2[maxn], pw10[maxm];   long long ans;   int main() {     scanf( %d , &n);     while (n--) {       int x;       scanf( %d , &x);       ++a[x];       (b[x] += x) %= mod;       c[x] = (1ll * x * x + c[x]) % mod;     }     pw2[0] = pw10[0] = 1;     for (int i = 1; i < maxm; ++i) {       pw2[i] = pw2[i - 1] << 1;       pw10[i] = pw10[i - 1] * 10;     }     for (int i = maxm; i < maxn; ++i) {       pw2[i] = (pw2[i - 1] << 1) % mod;     }     for (int j = 0; j < maxm; ++j) {       for (int i = maxn - 1; ~i; --i) {         if (i / pw10[j] % 10 < 9) {           (a[i] += a[i + pw10[j]]) %= mod;           (b[i] += b[i + pw10[j]]) %= mod;           (c[i] += c[i + pw10[j]]) %= mod;         }       }     }     for (int i = 0; i < maxn; ++i) {       if (a[i] >= 1) {         g[i] = (1ll * c[i] * pw2[a[i] - 1] + g[i]) % mod;         if (a[i] >= 2) {           g[i] = ((1ll * b[i] * b[i] - c[i]) % mod * pw2[a[i] - 2] + g[i]) % mod;         }       }     }     for (int j = 0; j < maxm; ++j) {       for (int i = 0; i < maxn; ++i) {         if (i / pw10[j] % 10 < 9) {           (g[i] -= g[i + pw10[j]]) %= mod;         }       }     }     for (int i = 0; i < maxn; ++i) {       ans ^= 1ll * (g[i] + mod) % mod * i;     }     printf( %lld n , ans);     return 0;   }
/* -> Written by <-      -----------     |K_A_Z_A_M_A|     |___________|     |    ___    |     |   (^_^)   |     |  /( | )  |     |____|_|____|       H O A N G   */      #include <bits/stdc++.h>      #define Task             running    #define F               first   #define S               second   #define pb              push_back   #define bit(x, i)       ((x >> (i)) & 1)   #define inf             1e9 + 7   #define INF             1e18 + 7   #define ll              long long   #define pii             pair <int, int>   #define debug(x)        cerr << #x <<   is   << x <<   n ;      using namespace std;      const int MOD = 1e9 + 7;   const int maxn = 1e5 + 5;   const int base = 3e5 + 1;      int n;   pair <int, int> a[200005];      int CalDis(int r1, int c1, int r2, int c2) {       if (r1 - c1 == r2 - c2) {           if ((r1 + c1) % 2 == 0) return r2 - r1;           return 0;       }       int newr = r2 - c2 + c1;       int newc = c1;       int x = newr - r1;       if ((newr + newc) % 2) return x / 2;       return (x + 1) / 2;   }      void Solve() {       cin >> n;       for (int i = 1; i <= n; ++ i) {           cin >> a[i].F;       }       for (int i = 1; i <= n; ++ i) {           cin >> a[i].S;       }       sort(a + 1, a + 1 + n);       int r1 = 1, c1 = 1;       ll res = 0;       for (int i = 1; i <= n; ++ i) {           int r2 = a[i].F;           int c2 = a[i].S;           res += CalDis(r1, c1, r2, c2);           c1 = c2;           r1 = r2;       }       cout << res <<   n ;   }      int main(){       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       if (fopen(Task .inp ,  r )){           freopen(Task .inp ,  r , stdin);           freopen(Task .out ,  w , stdout);       }   //    Prepare();       int test_case = 1;       cin >> test_case;       while (test_case --){           Solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int min(long long int a, long long int b) { return a < b ? a : b; }   int getMedian(int ai[100001], int n) {     map<int, int> m;     for (int i = 0; i < n; i++) {       if (m.find(ai[i]) != m.end()) {         m[ai[i]] = m[ai[i]] + 1;       } else         m[ai[i]] = 1;     }     int temp = (m.size() - 1) / 2, k = 0, median;     for (map<int, int>::iterator it = m.begin(); k <= temp; ++it, ++k) {       median = it->first;     }     return median;   }   int main() {     int n, ai[100001];     bool isPossible;     scanf(  n%d , &n);     for (int i = 0; i < n; i++) scanf(  n%d , &ai[i]);     int median = getMedian(ai, n);     bool isDiffSet = false;     int globalDiff, diff;     isPossible = true;     for (int i = 0; i < n; i++) {       diff = ai[i] - median < 0 ? median - ai[i] : ai[i] - median;       if (!diff) continue;       if (isDiffSet) {         if (diff != globalDiff) {           isPossible = false;           break;         }       } else {         globalDiff = diff;         isDiffSet = true;       }     }     printf( %s n , isPossible ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int v, e;     cin >> v >> e;     vector<set<int> > g(v);     int a, b;     for (int i = 0; i < e; i++) {       cin >> a >> b;       g[a - 1].insert(b - 1);       g[b - 1].insert(a - 1);     }     int ans = 0;     while (1) {       vector<int> ve;       for (int i = 0; i < v; i++) {         if (g[i].size() == 1) {           ve.push_back(i);         }       }       for (int i = 0; i < ve.size(); i++) {         set<int>::iterator it = g[ve[i]].begin();         g[ve[i]].clear();         g[*it].erase(ve[i]);       }       if (ve.size())         ans++;       else         break;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int A[100010];   int B[100010];   int C[100010];   int main() {     int n;     scanf( %d , &n);     int m, k;     scanf( %d%d , &m, &k);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , A + i, B + i, C + i);     }     long long sum = 0;     for (int i = 0; i < k; i++) {       int take;       scanf( %d , &take);       for (int t = 0; t < m; t++) {         if (take >= A[t] && take <= B[t]) sum += (C[t] + take - A[t]);       }     }     printf( %I64d n , sum);     return 0;   }