malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const long long linf = 1ll << 60;   const double dinf = 1e60;   template <typename T>   inline void scf(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void scf(T1 &x, T2 &y) {     scf(x);     return scf(y);   }   template <typename T1, typename T2, typename T3>   void scf(T1 &x, T2 &y, T3 &z) {     scf(x);     scf(y);     return scf(z);   }   template <typename T1, typename T2, typename T3, typename T4>   void scf(T1 &x, T2 &y, T3 &z, T4 &w) {     scf(x);     scf(y);     scf(z);     return scf(w);   }   inline char mygetchar() {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   template <typename T>   void chkmax(T &x, const T &y) {     if (y > x) x = y;     return;   }   template <typename T>   void chkmin(T &x, const T &y) {     if (y < x) x = y;     return;   }   void TZL();   void RANK1();   int main() {     TZL();     RANK1();     return 0;   }   void TZL() {     long long k;     int n;     vector<long long> a;     a.clear();     scf(n, k);     for (int i = 0, _end_ = (n); i < _end_; ++i) {       long long x;       scf(x);       a.push_back(x);     }     sort(a.begin(), a.end());     long long ans = 0;     for (int i = 1; i < n; ++i) {       long long x = a[i] - a[0];       if (x % k != 0) {         puts( -1 );         return;       }       ans += x / k;       ;     }     cout << ans << endl;   }   void RANK1() {}
#include <bits/stdc++.h>   using namespace std;   namespace solve {   long long int a[200007], sum[200007], dpDown[200007], dpUp[200007];   vector<int> graph[200007];   void rec(int u, int p) {     sum[u] = a[u];     for (int v : graph[u]) {       if (v == p) continue;       rec(v, u);       dpDown[u] += dpDown[v] + sum[v];       sum[u] += sum[v];     }   }   void dfs(int u, int p) {     for (int v : graph[u]) {       if (v == p) continue;       dpUp[v] = dpDown[u] - dpDown[v] - sum[v] + (sum[1] - sum[v]) + dpUp[u];       dfs(v, u);     }   }   void takeInput() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     rec(1, -1);     dfs(1, -1);     long long int res = 0;     for (int i = 1; i <= n; i++) {       res = max(res, dpDown[i] + dpUp[i]);     }     cout << res << endl;   }   }  // namespace solve   int main() {     solve::takeInput();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   string board[30];   int mask[42][30];   int dp[42][1 << 20];   int func(int i, int j, int c, bool first) {     if (dp[i][j] != 10000) return dp[i][j];     int next;     int ans = -(1 << 29);     if (i == 2 * (N - 1)) {       ans = 0;     } else {       for ((next) = 0; (next) < (int)(26); (next)++) {         int i2 = i + 1;         int j2 = (mask[i + 1][next] & (j | (j << 1)));         if (j2 != 0) ans = max(ans, -func(i2, j2, next, !first));       }     }     if (first) {       if (c == 0)         ans++;       else if (c == 1)         ans--;     } else {       if (c == 0)         ans--;       else if (c == 1)         ans++;     }     return dp[i][j] = ans;   }   string calc() {     int i, j, k;     for ((i) = 0; (i) < (int)(2 * N); (i)++)       for ((j) = 0; (j) < (int)(26); (j)++)         for ((k) = 0; (k) < (int)(N); (k)++) {           int x = k;           int y = i - x;           if (y >= 0 && y < N && board[x][y] -  a  == j) mask[i][j] |= (1 << k);         }     for ((i) = 0; (i) < (int)(2 * N); (i)++)       for ((j) = 0; (j) < (int)((1 << N)); (j)++) dp[i][j] = 10000;     int ans = func(0, 1, board[0][0] -  a , false);     if (ans < 0) return  FIRST ;     if (ans > 0) return  SECOND ;     return  DRAW ;   }   void solve(istream &in, ostream &out) {     in >> N;     for (int i = 0; i < N; i++) in >> board[i];     out << calc() << endl;   }   int main() {     solve(cin, cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long in() {     long long re = 0, f = 1;     char x = getchar();     while (x <  0  || x >  9 ) {       if (x ==  - ) f = -1;       x = getchar();     }     while (x >=  0  && x <=  9 ) re = re * 10 + x - 48, x = getchar();     return re * f;   }   void out(long long x) {     if (x < 0) putchar( - ), x = -x;     if (!x) {       putchar( 0 );       return;     }     char z[21], ct = 0;     while (x) {       z[++ct] = x % 10 + 48, x /= 10;     }     while (ct) {       putchar(z[ct]);       --ct;     }   }   const long long mod1 = 1e9 + 7;   const long long mod2 = 998244353;   const long long base1 = 3001;   const long long base2 = 2333;   long long upd(long long a, long long b) { return a < 0 ? a + b : a; }   struct ull {     long long x, y;     ull operator-(const ull &b) const {       return (ull){upd(x - b.x, mod1), upd(y - b.y, mod2)};     }     ull operator+(const long long &b) const {       return (ull){(x + b) % mod1, (y + b) % mod2};     }     ull operator+(const ull &b) const {       return (ull){(x + b.x) % mod1, (y + b.y) % mod2};     }     ull operator*(const ull &b) const {       return (ull){(x * b.x) % mod1, (y * b.y) % mod2};     }     bool operator==(const ull &b) const { return x == b.x && y == b.y; }     bool operator!=(const ull &b) const { return x != b.x || y != b.y; }   } base;   ull hs[1000010], pw[1000010];   ull geths(int l, int r) {     int len = r - l + 1;     ull re = hs[r] - hs[l - 1] * pw[len];     return re;   }   long long ls[200010], lt[200010];   char cs[200010], ct[200010];   long long S[500000], T[500000];   int n, m;   int main() {     n = in();     m = in();     for (int i = 1; i <= n; ++i) {       scanf( %d-%c , &ls[i], &cs[i]);       if (cs[i] == cs[i - 1]) {         ls[i - 1] += ls[i];         --i;         --n;       }     }     for (int i = 1; i <= m; ++i) {       scanf( %d-%c , &lt[i], &ct[i]);       if (ct[i] == ct[i - 1]) {         lt[i - 1] += lt[i];         --i;         --m;       }     }     if (m == 1) {       char c = ct[1];       long long ans = 0;       for (int i = 1; i <= n; ++i)         if (cs[i] == c) ans = ans + max(0ll, ls[i] - lt[1] + 1);       cout << ans <<   n ;       return 0;     }     base = (ull){base1, base2};     int cnt1 = lt[1], cnt2 = lt[m], ch = ct[m];     for (int i = 1; i <= n; ++i) S[i * 2 - 1] = ls[i], S[i * 2] = cs[i];     T[1] = ct[1];     for (int i = 2; i < m; ++i) T[i * 2 - 2] = lt[i], T[i * 2 - 1] = ct[i];     int tlen = m * 2 - 3;     ull hT = (ull){0, 0};     for (int i = 1; i <= tlen; ++i) hT = hT * base + (long long)T[i];     pw[0].x = pw[0].y = 1;     for (int ed = max(tlen, n * 2), i = 1; i <= ed; ++i) pw[i] = pw[i - 1] * base;     for (int i = 1; i <= n * 2; ++i) hs[i] = hs[i - 1] * base + (long long)S[i];     long long ans = 0;     for (int i = 2; i + tlen + 1 <= n * 2; i += 2) {       int l = i, r = i + tlen - 1;       ull hS = geths(l, r);       if (hS == hT) {         if (S[l - 1] < cnt1) continue;         if (S[r + 1] < cnt2) continue;         if (S[r + 2] != ch) continue;         ++ans;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 1;   vector<int> g[maxn];   int n, m, k, num[maxn], pre[maxn], maxx = 0, flag = 0;   void dfs(int u, int fa, int deep) {     num[u] = deep;     pre[u] = fa;     for (int to : g[u]) {       if (flag) return;       if (to == fa) continue;       if (num[to] > 0) {         if (num[u] - num[to] + 1 >= k + 1) {           printf( %d n , num[u] - num[to] + 1);           while (u != to) {             printf( %d  , u);             u = pre[u];           }           printf( %d , to);           flag = 1;           return;         }         continue;       }       dfs(to, u, deep + 1);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 0, 1);   }
#include <bits/stdc++.h>   using namespace std;   int m, n, l, r, mid, t;   int a[200002], b[200002], ida[200002], idb[200002], to[200002];   long long ans[200002] = {};   template <class T>   void read(T &x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();     x = f ? -x : x;     return;   }   inline bool cmpa(int x, int y) { return a[x] > a[y] ? 1 : 0; }   inline bool cmpb(int x, int y) { return b[x] > b[y] ? 1 : 0; }   inline void add(int l, int r, long long d) {     --l, r -= (l / n) * n, l %= n, ++l;     if (r <= n)       ans[l] += d, ans[r] -= d;     else       ans[l] += d, ans[1] += d, ans[(r - 1) % n + 1] -= d;   }   int main() {     read(m), read(n);     for (int i = 1; i <= n; ++i) read(a[i]), ida[i] = i;     for (int i = 1; i <= n; ++i) read(b[i]), idb[i] = i;     sort(ida + 1, ida + n + 1, cmpa), sort(idb + 1, idb + n + 1, cmpb);     for (int i = 1; i <= n; ++i) {       t = l = 1, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (a[ida[i]] < b[idb[mid]] - m / 2)           l = mid + 1;         else           r = mid - 1;       }       add(t + n - i + 1, l + n - i + 1, m + a[ida[i]]), t = l, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (a[ida[i]] < b[idb[mid]])           l = mid + 1;         else           r = mid - 1;       }       add(t + n - i + 1, l + n - i + 1, -a[ida[i]]), t = l, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (a[ida[i]] <= b[idb[mid]] + m / 2)           l = mid + 1;         else           r = mid - 1;       }       add(t + n - i + 1, l + n - i + 1, a[ida[i]]),           add(l + n - i + 1, 2 * n - i + 2, m - a[ida[i]]), t = l = 1, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (b[idb[i]] < a[ida[mid]] - m / 2)           l = mid + 1;         else           r = mid - 1;       }       add(n - l + i + 2, n - t + i + 2, b[idb[i]]), t = l, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (b[idb[i]] <= a[ida[mid]])           l = mid + 1;         else           r = mid - 1;       }       add(n - l + i + 2, n - t + i + 2, -b[idb[i]]), t = l, r = n;       while (l <= r) {         mid = ((l + r) >> 1);         if (b[idb[i]] <= a[ida[mid]] + m / 2)           l = mid + 1;         else           r = mid - 1;       }       add(n - l + i + 2, n - t + i + 2, b[idb[i]]),           add(i + 1, n - l + i + 2, -b[idb[i]]);     }     t = 1;     for (int i = 2; i <= n; ++i)       if ((ans[i] += ans[i - 1]) < ans[t]) t = i;     for (int i = 1; i <= n; ++i) to[ida[i]] = idb[(i + t - 2) % n + 1];     printf( %lld n , ans[t]);     for (int i = 1; i <= n; ++i) printf( %d  , to[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<long long>;   using vpi = vector<pair<long long, long long>>;   using vvi = vector<vi>;   using tp = tuple<long long, long long, long long>;   using pi = pair<long long, long long>;   void __READ__() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     };     return _in;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.first >> _p.second;     return _in;   }   const long long nax = 1e5 + 7;   const long long mod = 1e9 + 7;   const long long inf = numeric_limits<long long>::max() - (long long)9e6;   void test() {     long long n;     cin >> n;     vi v(n);     cin >> v;     long long ans = inf;     map<long long, long long> m;     long long rsum = 0;     for (long long x : v) {       rsum += x;       m[rsum]++;       ans = min(ans, n - m[rsum]);     }     cout << ans;   }   signed main() {     __READ__();     long long T = 1;     for (long long tt = 1; tt <= T; tt++) {       test();       cout <<   n ;     }     return 0;   }
#include<cstdio>   #include<cstring>   #include<algorithm>   #include<iostream>   #include<string>   #include<vector>   #include<stack>   #include<bitset>   #include<cstdlib>   #include<cmath>   #include<set>   #include<list>   #include<deque>   #include<map>   #include<queue>      #define rep(i, a, n) for (ll  i=a;i<=n;i++)   #define per(i, a, n) for (ll  i=a;i>=n;i--)   #define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)   #pragma GCC optimize(3)//O3   #pragma GCC optimize(2)//O2   //#define endl   n    #define Mod(x) x % mod   #define toNum(x) x - 0    #define fi first   #define se second   #define mm(a, b) memset(a,b, sizeof(a));   #define dbg(x) cout << #x <<  =  << x << endl;   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef pair<ll, ll> PII;   const ll maxn = 3e6 + 10;   const ll mod = 1e9 + 7;   const ll N = 1e6 + 10;   const ll INF = 0x3f3f3f3f;   #define cf ll  t;cin>>t;while (t--) solve();   int n, m, sum, cnk, maxx, minn = INF, u, l, r, pre, op, p, k, z, ok, x, y, temp, q, sum1, sum2, A, B, cnt, ans, b, ask, t, nums, len;   char s[110];      void solve() {       cin >> n >> k >> s + 1;       sum = 0;       for (int i = 1, j = n; j > i; i++, j--) {           if (s[i] == s[j]) {               sum++;           } else break;       }       if(!(n & 1) && k == n / 2) puts( NO );       else if (k <= sum) puts( YES );       else puts( NO );   }      int main() {       IOS;       cf;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000;   int te, A, B, C, num[maxn + 5], AB, AC, BC, ABC, sum[8];   long long ans;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   inline bool check(int i, int j, int k) { return (i & 1) && (j & 2) && (k & 4); }   inline long long C3(long long x) { return x * (x - 1) * (x - 2) / 6; }   inline long long C2(long long x) { return x * (x - 1) / 2; }   int main() {     for (int i = 1; i <= maxn; i++)       for (int j = i; j <= maxn; j += i) num[j]++;     for (scanf( %d , &te); te; printf( %lld n , ans), ans = 0, te--) {       scanf( %d%d%d , &A, &B, &C);       AB = gcd(A, B);       AC = gcd(A, C);       BC = gcd(B, C);       ABC = gcd(AB, C);       sum[1] = num[A] - num[AB] - num[AC] + num[ABC];       sum[2] = num[B] - num[AB] - num[BC] + num[ABC];       sum[3] = num[AB] - num[ABC];       sum[4] = num[C] - num[AC] - num[BC] + num[ABC];       sum[5] = num[AC] - num[ABC];       sum[6] = num[BC] - num[ABC];       sum[7] = num[ABC];       for (int i = 1; i < 8; i++)         for (int j = i; j < 8; j++)           for (int k = j; k < 8; k++)             if (check(i, j, k) || check(i, k, j) || check(j, i, k) ||                 check(j, k, i) || check(k, i, j) || check(k, j, i))               if (i == j && j == k)                 ans += C3(sum[i] + 2);               else if (i == j)                 ans += C2(sum[i] + 1) * sum[k];               else if (j == k)                 ans += C2(sum[j] + 1) * sum[i];               else                 ans += (long long)sum[i] * sum[j] * sum[k];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 15, OO = 1e6 + 3;   int n, q, t1, t2;   int inv[N], y[15], de[15];   long long MOD(long long a, long long b) {     a %= b;     if (a < 0) a += b;     return a;   }   void rangeInv(long long m) {     inv[1] = 1;     for (long long i = 2; i < m; ++i) inv[i] = (m - (m / i) * inv[m % i] % m) % m;   }   int f(int x) {     printf( ? %d n , x);     fflush(stdout);     scanf( %d , &x);     return x;   }   int F(int x) {     int ret = 0;     for (int i = 0; i < 11; ++i) {       int l = 1;       for (int j = 0; j < 11; ++j) {         if (j == i) continue;         l = MOD(1ll * l * (x - j), OO);       }       int li = de[i];       l = (1ll * li * l) % OO;       ret += (1ll * l * y[i]) % OO;       if (ret >= OO) ret -= OO;     }     return ret;   }   int main() {     rangeInv(OO);     for (int i = 0; i < 11; ++i) {       y[i] = f(i);       de[i] = 1;       for (int j = 0; j < 11; ++j) {         if (j == i) continue;         de[i] = MOD(de[i] * (i - j), OO);       }       de[i] = inv[de[i]];     }     for (int i = 0; i <= OO; ++i) {       if (F(i) == 0) {         printf( ! %d n , i);         fflush(stdout);         return 0;       }     }     printf( ! -1 n );     fflush(stdout);   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     vector<long long> apr(n + 1), arr(n);     long long now = 1, next = 2;     for (long long i = 0; i < n - 1; i++, next++) {       long long a = 0, b = 0;       cout <<  ?   << now <<     << next <<   n ;       cout.flush();       cin >> a;       cout <<  ?   << next <<     << now <<   n ;       cout.flush();       cin >> b;       if (a > b) {         arr[now - 1] = a;         apr[a] = 1;         now = next;       } else {         arr[next - 1] = b;         apr[b] = 1;       }     }     for (long long i = 1; i <= n; i++) {       if (apr[i] == false) {         arr[now - 1] = i;         break;       }     }     cout <<  !  ;     for (long long i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;     cout.flush();   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 101;   int a[MAX_N];   int n;   vector<vector<int>> ans;   pair<int, int> pop(multiset<pair<int, int>, std::greater<pair<int, int>>> &s) {     pair<int, int> x = *s.begin();     s.erase(s.begin());     return x;   }   bool check(int d) {     ans.clear();     multiset<pair<int, int>, std::greater<pair<int, int>>> s;     int sum = 0;     for (int i = 0; i < n; i++) {       if (a[i] < d) return false;       s.insert({a[i] - d, i});       sum += a[i] - d;     }     if (sum % 2 == 1) {       if (n < 3) return false;       pair<int, int> x = pop(s), y = pop(s), z = pop(s);       if (z.first == 0) return false;       ans.push_back({x.second, y.second, z.second});       s.insert({x.first - 1, x.second});       s.insert({y.first - 1, y.second});       s.insert({z.first - 1, z.second});       sum -= 3;     }     while (sum > 0) {       if (n < 2) return false;       pair<int, int> x = pop(s), y = pop(s);       if (y.first == 0) return false;       ans.push_back({x.second, y.second});       s.insert({x.first - 1, x.second});       s.insert({y.first - 1, y.second});       sum -= 2;     }     return true;   }   void dummy() {     ans.clear();     multiset<pair<int, int>, std::greater<pair<int, int>>> s;     for (int i = 0; i < n; i++) {       s.insert({a[i], i});     }     while ((*s.begin()).first > 0) {       pair<int, int> x = pop(s), y = pop(s);       s.insert({(x.first > 1 ? x.first - 1 : 0), x.second});       s.insert({(y.first > 1 ? y.first - 1 : 0), y.second});       ans.push_back({x.second, y.second});     }   }   int main() {     cin >> n;     int r = MAX_N;     for (int i = 0; i < n; i++) {       cin >> a[i];       r = min(r, a[i]);     }     r++;     int l = 0;     while (l < r) {       int m = l + (r - l) / 2;       if (check(m)) {         l = m + 1;       } else {         r = m;       }     }     if (l == 0 || !check(l - 1)) {       l = 1;       dummy();     }     cout << l - 1 << endl << ans.size() << endl;     for (auto p : ans) {       for (int i = 0; i < n; i++) {         bool ok = 0;         for (int x : p) {           ok |= x == i;         }         cout << (ok ?  1  :  0 );       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T mabs(const T &a) {     return a < 0 ? -a : a;   }   const int mod = 1e9 + 7;   const int Row = 14, Mask = 4782969;   int D[2][2][Mask];   int setbit[Mask][3];   int getbit[Mask][3];   int p3[20] = {1};   inline int setBit(int mask, int pos, int val) {     return (mask / p3[pos + 1] * 3 + val) * p3[pos] + mask % p3[pos];   }   inline int getBit(int mask, int pos) { return mask / p3[pos] % 3; }   inline int up(int i, int mask) {     if (i == 0) return 3;     return getbit[mask][i - 1];   }   inline int left(int i, int j, int mask) {     if (j == 0) return 3;     return getbit[mask][i];   }   inline void addTo(int &a, int val) {     a += val;     if (a >= mod) a -= mod;   }   inline int &next(int flag, int flag2, int i, int n, int mask) {     if (i == n - 1) return D[flag ^ 1][0][mask];     return D[flag][flag2 ^ 1][mask];   }   void run() {     char str[] = { AHIMOTUVWXY };     char A[100100];     scanf( %s , A);     bool ok = 1;     int n = strlen(A);     for (int i = (0), ei = (n / 2); i < ei; i++)       if (A[i] != A[n - 1 - i]) ok = 0;     for (int i = (0), ei = (n); i < ei; i++)       if (strchr(str, A[i]) == 0) ok = 0;     puts(ok ?  YES  :  NO );   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char cc[8][9];   int win;   void dfs(int t, int i, int j) {     int x, y;     if (win) {       return;     }     if (i < 0 || i >= 8 || j < 0 || j >= 8) {       return;     }     if (i - t >= 0 && cc[i - t][j] ==  S ) {       return;     }     if (i + 1 - t >= 0 && i + 1 - t < 8 && cc[i + 1 - t][j] ==  S ) {       return;     }     if (t >= 8) {       win = 1;       return;     }     for (x = -1; x <= 1; x++) {       for (y = -1; y <= 1; y++) {         dfs(t + 1, i + x, j + y);       }     }   }   int main() {     int i;     for (i = 0; i < 8; i++) {       scanf( %s , cc[i]);     }     dfs(0, 7, 0);     printf(win ?  WIN n  :  LOSE n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l1, l2, r1, r2, k, temp, ans, st, en;     cin >> l1 >> l2 >> r1 >> r2 >> k;     if (l1 <= r1) {       st = r1;     } else       st = l1;     if (l2 <= r2)       en = l2;     else       en = r2;     if (k >= st && k <= en)       ans = (en - st);     else       ans = (en - st + 1);     if (ans < 0)       cout << 0 << endl;     else       cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int n, fa[100005], p[100005], size[100005], tsize[100005], q, d[100005];   long long ans = 0, sum[100005];   void dfs(int x, int f) {     p[x] = f, fa[x] = x, size[x] = tsize[x] = 1, d[x] = d[f] + 1,     ans += 1ll * (n - 2) * (n - 1);     for (int y : g[x]) {       if (y == f) continue;       dfs(y, x), tsize[x] += tsize[y], sum[x] += 1ll * tsize[y] * (tsize[y] - 1);     }     ans -= 1ll * (n - tsize[x]) * (n - tsize[x] - 1) + sum[x];   }   int gf(int x) { return x == fa[x] ? x : fa[x] = gf(fa[x]); }   void Add(int x, long long dlt) {     ans += dlt * size[x] *            (1ll * (n - size[x]) * (n - size[x] - 1) - sum[x] -             1ll * (n - tsize[x]) * (n - tsize[x] - 1));     ans += dlt * size[x] * (size[x] - 1) * (n - size[x]) * 2;     ans += dlt * size[x] * (size[x] - 1) * (size[x] - 2);   }   void Merge(int x, int y) {     x = gf(x), y = gf(y);     if (x == y) return;     Add(x, -1), Add(y, -1), fa[x] = y, size[y] += size[x],                             sum[y] += sum[x] - 1ll * (tsize[x] - 1) * tsize[x],                             Add(y, 1);   }   int main() {     cin >> n;     for (int i = 1, x, y; i < n; i++)       cin >> x >> y, g[x].push_back(y), g[y].push_back(x);     dfs(1, 0), cout << ans <<   n , cin >> q;     while (q--) {       int x, y;       cin >> x >> y, x = gf(x), y = gf(y);       while (x ^ y) {         if (d[gf(p[x])] < d[gf(p[y])]) swap(x, y);         Merge(x, p[x]), x = gf(p[x]), y = gf(y);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int n, ans, a[15][15];   inline void maxx(int& a, int b) { a = (a > b ? a : b); }   inline void minx(int& a, int b) { a = (a < b ? a : b); }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) minx(a[i][j], a[i][k] + a[k][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) maxx(ans, a[i][j]);     printf( %d n , ans);     return 0;   }