malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 16;   int from[MAXN], to[MAXN], p[MAXN], q[MAXN];   bool w[MAXN][MAXN];   long long dp[1 << MAXN];   int main() {     int n, m, a, b;     long long y;     cin >> n >> y >> m;     fill(from, from + n, 0);     fill(to, to + n, 0);     fill(w[0], w[m], false);     for (int i = 0; i < m; ++i) {       cin >> a >> b;       --a;       --b;       w[a][b] = true;     }     for (int k = 0; k < n; ++k) {       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           w[i][j] |= w[i][k] && w[k][j];         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (w[i][j]) {           from[j] |= 1 << i;           to[i] |= 1 << j;         }       }     }     fill(dp, dp + (1 << n), 0);     dp[0] = 1;     for (int i = 1; i < (1 << n); ++i) {       for (int j = 0; j < n; ++j) {         if ((i & (1 << j)) != 0 && (i & from[j]) == 0) {           dp[i] += dp[i ^ (1 << j)];         }       }     }     y -= 2001;     m = (1 << n) - 1;     if (y >= dp[m]) {       cout <<  The times have changed  << endl;       return 0;     }     fill(p, p + n, -1);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (p[j] != -1) {           continue;         }         p[j] = i;         {           fill(dp, dp + (1 << n), 0);           dp[0] = 1;           for (int i = 1; i < (1 << n); ++i) {             int k = n - __builtin_popcount(i);             if (p[k] != -1) {               int j = p[k];               if ((i & (1 << j)) != 0 && (i & from[j]) == 0) {                 dp[i] += dp[i ^ (1 << j)];               }             } else {               for (int j = 0; j < n; ++j) {                 if ((i & (1 << j)) != 0 && (i & from[j]) == 0) {                   dp[i] += dp[i ^ (1 << j)];                 }               }             }           }         }         if (y < dp[m]) {           q[i] = j;           break;         } else {           p[j] = -1;           y -= dp[m];         }       }     }     for (int i = 0; i < n; ++i) {       printf( %d%c , q[i] + 1, i == n - 1 ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 50005;   int n, m;   int p[N], a[N];   struct LCT {     int fa[N], ch[N][2], siz[N], sv[N];     long long sv2[N], sav[N], san[N], sa[N];     int nroot(int u) { return ch[fa[u]][0] == u || ch[fa[u]][1] == u; }     void pushup(int u) {       siz[u] = siz[ch[u][0]] + siz[ch[u][1]] + sv[u];       san[u] = san[ch[u][0]] + san[ch[u][1]] + 1ll * a[u] * sv[u];       sa[u] =           sa[ch[u][0]] + sa[ch[u][1]] + sav[u] +           (1ll * sv[u] * sv[u] - sv2[u] + 2ll * siz[ch[u][1]] * sv[u]) * a[u] +           2 * san[ch[u][0]] * (siz[ch[u][1]] + sv[u]);     }     void rot(int u) {       int v = fa[u], t = fa[v], d = (u == ch[v][1]);       if (nroot(v)) ch[t][v == ch[t][1]] = u;       fa[u] = t;       fa[ch[u][d ^ 1]] = v;       ch[v][d] = ch[u][d ^ 1];       fa[v] = u;       ch[u][d ^ 1] = v;       pushup(v);       pushup(u);     }     void splay(int u) {       while (nroot(u)) {         int v = fa[u];         if (nroot(v)) rot(u == ch[v][1] ^ v == ch[fa[v]][1] ? u : v);         rot(u);       }     }     int access(int u) {       int v = 0;       for (; u; v = u, u = fa[u]) {         splay(u);         sv[u] += siz[ch[u][1]] - siz[v];         sv2[u] += 1ll * siz[ch[u][1]] * siz[ch[u][1]] - 1ll * siz[v] * siz[v];         sav[u] += sa[ch[u][1]] - sa[v];         ch[u][1] = v;         pushup(u);       }       return v;     }     int lca(int u, int v) {       access(u);       return access(v);     }     void makeroot(int u) {       access(u);       splay(u);     }     void Link(int u, int v) {       makeroot(u);       makeroot(v);       fa[u] = v;       sv[v] += siz[u];       sv2[v] += 1ll * siz[u] * siz[u];       sav[v] += sa[u];       pushup(v);     }     void Cut(int u, int v) {       access(u);       splay(v);       ch[v][1] = fa[u] = 0;       pushup(v);     }   } lt;   void query() {     lt.splay(1);     printf( %.12lf n , 1.0 * lt.sa[1] / n / n);   }   int main() {     int x, y;     char ty;     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , p + i);     for (int i = 1; i <= n; i++)       scanf( %d , a + i), lt.siz[i] = lt.sv[i] = 1, lt.san[i] = lt.sa[i] = a[i];     for (int i = 2; i <= n; i++) lt.Link(i, p[i]);     scanf( %d , &m);     query();     while (m--) {       do ty = getchar();       while (ty !=  P  && ty !=  V );       scanf( %d%d , &x, &y);       if (ty ==  P ) {         if (lt.lca(x, y) == x) swap(x, y);         lt.Cut(x, p[x]);         lt.Link(x, p[x] = y);       } else         lt.makeroot(x), a[x] = y, lt.pushup(x);       query();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[6];   int sum = 0;   int x, y, z;   int x1, adjf, z1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     scanf( %d%d%d , &x, &y, &z);     scanf( %d%d%d , &x1, &adjf, &z1);     for (auto i = 0; i != 6; i++) scanf( %d , &a[i]);     if (y < 0) {       sum += a[0];     }     if (y > adjf) {       sum += a[1];     }     if (z < 0) {       sum += a[2];     }     if (z > z1) {       sum += a[3];     }     if (x < 0) {       sum += a[4];     }     if (x > x1) {       sum += a[5];     }     printf( %d , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long mx, p1, p2, val, sum, res, res1;   long long m[200007][27];   int main() {     ios_base::sync_with_stdio();     cin.tie();     cout.tie();     ;     cin >> n >> k;     res = 1000000007.0;     for (int i = 1; i <= n; i++) {       cin >> val;       mx = max(val, mx);       m[val][0]++;       if (m[val][0] >= k) res = 0;     }     mx /= 2;     for (long long i = mx; i >= 0; i--) {       if (i == 0) {         sum = m[0][0];         for (int j = 0; j <= 19; j++) {           m[0][j + 1] += m[1][j];           sum += m[i][j + 1];         }       } else {         p1 = 2 * i;         p2 = 2 * i + 1;         sum = m[i][0];         for (int j = 0; j <= 19; j++) {           m[i][j + 1] += m[p1][j] + m[p2][j];           sum += m[i][j + 1];         }       }       if (sum >= k) {         sum = 0;         res1 = 0;         for (long long j = 0; j <= 19; j++) {           res1 += m[i][j] * j;           sum += m[i][j];           if (sum >= k) {             res = min(res, (res1 - (sum - k) * j));             break;           }         }       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100003;   int n, L, R, phi;   long long mod;   long long fac[N], inv[N];   int d[N][33];   int tot, p[N];   long long fpow(long long x, int y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   void init() {     fac[0] = inv[0] = 1;     for (int i = 1; i <= n; i++) {       int tmp = i;       for (int j = 1; j <= tot; j++) {         d[i][j] = d[i - 1][j];         while (tmp % p[j] == 0) tmp /= p[j], d[i][j]++;       }       fac[i] = fac[i - 1] * tmp % mod;       inv[i] = fpow(fac[i], phi - 1);     }   }   long long C(int n, int m) {     if (n < m) return 0;     long long res = fac[n] * inv[m] % mod * inv[n - m] % mod;     for (int i = 1; i <= tot; i++)       res = res * fpow(p[i], d[n][i] - d[m][i] - d[n - m][i]) % mod;     return res;   }   int main() {     scanf( %d%I64d%d%d , &n, &mod, &L, &R);     int tmp = mod;     phi = mod;     for (int i = 2; i * i <= tmp; i++)       if (tmp % i == 0) {         p[++tot] = i;         phi = phi / i * (i - 1);         while (tmp % i == 0) tmp /= i;       }     if (tmp != 1) p[++tot] = tmp, phi = phi / tmp * (tmp - 1);     init();     long long ans = 0;     for (int i = 0; i <= n; i++) {       long long res = (C(i, (i + L + 1) / 2) - C(i, (i + R) / 2 + 1) + mod) % mod;       ans = (ans + res * C(n, i) % mod) % mod;     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mapa[35];   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       for (int j = 30; j >= 0; j--)         if ((1 << j) & x) {           mapa[j]++;           break;         }     }     while (q--) {       int x;       scanf( %d , &x);       long long pos = 0, res = 0;       for (int i = 30; i >= 0; i--) {         long long b = (1 << i);         if (b > x) continue;         long long aux = min(mapa[i], (long long)x / b);         res += aux;         x -= b * aux;       }       if (x > 0)         printf( -1 n );       else         printf( %lld n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 2010;   long long a[mn], b[mn];   int main() {     int n, k;     long long p;     scanf( %d %d %lld , &n, &k, &p);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= k; i++) scanf( %lld , &b[i]);     sort(a + 1, a + n + 1);     sort(b + 1, b + k + 1);     long long ans = 4e18;     for (int st = 0; st + n <= k; st++) {       long long tans = 0;       for (int i = 1; i <= n; i++) {         long long temp = 0;         long long now = b[st + i];         if (a[i] <= p && now <= p) {           if (a[i] <= now)             temp += p - a[i];           else             temp += a[i] - now + p - now;         } else if (a[i] <= p && p < now)           temp += now - a[i] + now - p;         else if (now <= p && p < a[i])           temp += a[i] - now + p - now;         else if (p < a[i] && p < now) {           if (now <= a[i])             temp += a[i] - p;           else             temp += now - a[i] + now - p;         }         tans = max(tans, temp);       }       ans = min(ans, tans);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, b, r;     cin >> n >> m;     b = 3;     r = 1;     while (n > 0) {       if (n % 2 != 0) r = (r * b) % m;       b = (b * b) % m;       n = n / 2;     }     cout << (r - 1 + m) % m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   unordered_map<int, int> Par[N];   map<pair<int, int>, int> ans;   vector<int> G[N];   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   inline int find(int x, int c) {     if (Par[c].find(x) == Par[c].end()) return x;     return Par[c][x] = find(Par[c][x], c);   }   inline void merge(int x, int y, int c) {     x = find(x, c);     y = find(y, c);     if (x == y) return;     Par[c][x] = y;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       G[a].push_back(c);       G[b].push_back(c);       merge(a, b, c);     }     for (int i = 1; i <= n; i++) {       sort(G[i].begin(), G[i].end());       G[i].resize(unique(G[i].begin(), G[i].end()) - G[i].begin());     }     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (G[a].size() > G[b].size()) swap(a, b);       if (G[a].size() == G[b].size() and a > b) swap(a, b);       if (ans.count({a, b})) {         cout << ans[{a, b}] <<   n ;         continue;       }       int res = 0;       for (auto u : G[a])         if (find(b, u) == find(a, u)) res++;       ans[{a, b}] = res;       cout << res <<   n ;     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   long long maxi = LLONG_MAX;   long long mini = LLONG_MIN;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long a[] = {1, 1, 3};   void fn(long long n, long long x) {     if (n <= 1) {       for (long long i = 0; i < n; i++) {         cout << x <<    ;       }       return;     }     long long t = (n) / 2;     if (n == 3) {       for (long long i = 0; i < 3; i++) {         cout << x * a[i] <<    ;       }       return;     } else {       if (n % 2 == 1) cout << x <<    ;       for (long long i = 0; i < t; i++) {         cout << x <<    ;       }     }     x *= 2;     fn(t, x);   }   int main() {     fast();     long long n;     cin >> n;     fn(n, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 105000;   int n;   int a[MAXN];   bool can(int x) {     if (x == 0) return true;     if (n - x < x) return false;     int r = n;     for (int i = x; i >= 1; i--) {       if (r <= x) return false;       while (a[r] < 2 * a[i]) {         r--;         if (r <= x) return false;       }       r--;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int l = 0, r = n;     while (l < r) {       int m = (l + r + 1) / 2;       if (can(m))         l = m;       else         r = m - 1;     }     printf( %d , n - l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100020;   const int logn = 18;   const int MOd = 1e9 + 7;   int a, b;   int ar[maxn];   int main() {     scanf( %d %d , &a, &b);     for (int i = 1; i <= a; i++) scanf( %d , &ar[i]);     double ans = 0.0;     for (int i = 1, j, k, t; i <= b; i++) {       scanf( %d %d %d , &j, &k, &t);       ans = max(ans, ((double)(ar[j] + ar[k]) / t));     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   char mat[105][105];   void solve() {     int n, m, horizontal;     cin >> n >> m >> horizontal;     int vertical = n * m / 2 - horizontal;     int oxe = 0, nte = 0;     char cc =  e ;     if (n % 2 != m % 2) {       if (n % 2 == 0) {         for (int i = 0; i < n; i += 2) {           mat[i][m - 1] = mat[i + 1][m - 1] = cc++;           if (cc >  z ) cc =  e ;         }         vertical -= n / 2;         m--;         nte = 1;       } else {         for (int j = 0; j < m; j += 2) {           mat[n - 1][j] = mat[n - 1][j + 1] = cc++;           if (cc >  z ) cc =  e ;         }         horizontal -= m / 2;         n--;         oxe = 1;       }     }     assert(n % 2 == 0 && m % 2 == 0);     int puth = n * m / 2;     int putv = 0;     char mofio[] = { a ,  b };     int cur = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j += 2) {         mat[i][j] = mat[i][j + 1] = mofio[cur];         cur ^= 1;       }       if (m % 4 == 0) cur ^= 1;     }     mofio[0] =  c , mofio[1] =  d ;     cur = 0;     for (int i = 0; i < n; i += 2) {       for (int j = 0; j < m; j += 2) {         if (puth == horizontal && putv == vertical) {           cout <<  YES n ;           for (int ii = 0; ii < n + oxe; ii++) {             for (int jj = 0; jj < m + nte; jj++) {               cout << mat[ii][jj];             }             cout <<   n ;           }           return;         }         mat[i][j] = mat[i + 1][j] = mofio[cur];         mat[i][j + 1] = mat[i + 1][j + 1] = mofio[cur ^ 1];         puth -= 2;         putv += 2;       }       cur ^= 1;     }     if (puth == horizontal && putv == vertical) {       cout <<  YES n ;       for (int ii = 0; ii < n + oxe; ii++) {         for (int jj = 0; jj < m + nte; jj++) {           cout << mat[ii][jj];         }         cout <<   n ;       }       return;     }     cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   int main() {     int N, ele = -1;     cin >> N;     vector<int> A(N);     int i;     for (i = 0; i < N; ++i) cin >> A[i];     sort(A.begin(), A.end());     int ans = 0, ctr = 0, x;     for (i = 0; i < N; i += x) {       x = upper_bound(A.begin(), A.end(), A[i]) -           lower_bound(A.begin(), A.end(), A[i]);       ans = ans + min(ctr, x);       ctr = max(ctr, x);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, c;     cin >> a >> b >> c;     if (b >= a && c >= a)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   inline int clamp(int v) {     if (v > n)       return v - n;     else if (v < 1) {       if (v == 0)         return n;       else         return n + v;     } else       return v;   }   void validate() {     n = 6;     assert(clamp(0) == 6);     assert(clamp(1) == 1);     assert(clamp(-1) == 5);     assert(clamp(6) == 6);     assert(clamp(7) == 1);     assert(clamp(3 + 5 % n) == 2);     assert(clamp(3 + 6 % n) == 3);     assert(clamp(3 + 7 % n) == 4);     assert(clamp(3 + 8 % n) == 5);     assert(clamp(3 + 9 % n) == 6);     assert(clamp(3 + 10 % n) == 1);     assert(clamp(3 + 11 % n) == 2);   }   int main() {     validate();     cin >> n >> q;     int startOdd = 1;     int startEven = 2;     for (int i = 0; i < q; i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int count;         scanf( %d , &count);         startOdd = clamp(startOdd + (count % n));         startEven = clamp(startEven + (count % n));       } else {         startOdd = (startOdd % 2 == 0) ? startOdd - 1 : startOdd + 1;         startEven = (startEven % 2 == 0) ? startEven - 1 : startEven + 1;       }     }     int evenOffset = startEven - 2;     int oddOffset = startOdd - 1;     int positions[1000000 + 1];     for (int i = 1; i <= n; i++) {       int pos = (i % 2 == 1) ? clamp(i + oddOffset) : clamp(i + evenOffset);       positions[pos] = i;     }     for (int i = 1; i <= n; i++) {       cout << positions[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, l, mx;   int a[100001];   int p[100001], miu[100001], len;   vector<int> b[100001];   vector<int> c[100001];   bool bz[100001];   int f[100001];   long long ans, s;   bool cmp(int a, int b) { return a > b; }   int gcd(int x, int y) {     int r = x % y;     while (r) x = y, y = r, r = x % y;     return y;   }   void init() {     int i, j, k, l;     miu[1] = 1;     for (i = 2; i <= 100000; i++) {       if (!bz[i]) p[++len] = i, miu[i] = -1;       for (j = 1; j <= len; j++)         if (1ll * i * p[j] <= 100000) {           bz[i * p[j]] = 1;           if (!(i % p[j])) break;           miu[i * p[j]] = -miu[i];         } else           break;     }   }   void add(int t, int s) {     int i, l = b[t].size();     for (i = 0; i <= l - 1; i++) f[b[t][i]] += s;   }   int get(int t) {     int i, k, l = b[t].size(), ans = 0;     for (i = 0; i <= l - 1; i++) k = b[t][i], ans += miu[k] * f[k];     return ans;   }   void work(int S) {     static int d[100001];     int i, j, k, l, len = c[S].size(), t = 0, A;     if (!len) return;     for (i = 0; i <= len - 1; i++) {       A = c[S][i];       while (t && get(A)) {         while (gcd(d[t], A) > 1) add(d[t], -1), --t;         s = 1ll * d[t] * A * S;         ans = (ans > s ? ans : s);         add(d[t], -1), --t;       }       d[++t] = A, add(A, 1);     }     while (t) add(d[t], -1), --t;   }   int main() {     init();     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]), mx = (mx > a[i] ? mx : a[i]);     sort(a + 1, a + n + 1, cmp);     l = 0;     for (i = 1; i <= n; i++)       if (a[i] != a[i - 1])         a[++l] = a[i];       else         ans = (ans > a[i] ? ans : a[i]);     n = l;     for (i = 1; i <= mx; i++) {       s = floor(sqrt(i));       for (j = 1; j <= s; j++)         if (!(i % j)) {           b[i].push_back(j);           if (j * j < i) b[i].push_back(i / j);         }     }     for (i = 1; i <= n; i++) {       l = b[a[i]].size();       for (j = 0; j <= l - 1; j++) k = b[a[i]][j], c[k].push_back(a[i] / k);     }     for (i = 1; i <= 100000; i++) work(i);     printf( %lld n , ans);     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch[1005];   int dp[1005][3 * 1005];   int n, k;   int func(int idx, int diff) {     if (idx == n) {       return (abs(diff) == k);     }     if (abs(diff) == k) {       return 0;     }     int &re = dp[idx][diff + 1005];     if (re != -1) return re;     re = 0;     if (ch[idx] ==  W )       re = func(idx + 1, diff + 1);     else if (ch[idx] ==  L )       re = func(idx + 1, diff - 1);     else if (ch[idx] ==  D )       re = func(idx + 1, diff);     else {       re =           func(idx + 1, diff - 1) | func(idx + 1, diff) | func(idx + 1, diff + 1);     }     return re;   }   void path(int idx, int diff) {     if (idx == n) return;     if (ch[idx] ==  W ) {       printf( W );       path(idx + 1, diff + 1);     } else if (ch[idx] ==  L ) {       printf( L );       path(idx + 1, diff - 1);     } else if (ch[idx] ==  D ) {       printf( D );       path(idx + 1, diff);     } else {       if (func(idx + 1, diff + 1)) {         printf( W );         path(idx + 1, diff + 1);       } else if (func(idx + 1, diff)) {         printf( D );         path(idx + 1, diff);       } else {         printf( L );         path(idx + 1, diff - 1);       }     }   }   int main() {     scanf( %d%d%s , &n, &k, ch);     memset(dp, -1, sizeof dp);     if (func(0, 0)) {       path(0, 0);     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int pos[4] = {0};       int n = s.size(), ans = s.size() + 1;       for (int i = 0; i < n; i++) {         pos[s[i] -  0 ] = i + 1;         int x = min(pos[1], min(pos[2], pos[3]));         if (x == 0) continue;         ans = min(ans, i - x + 2);       }       if (s.size() + 1 == ans)         cout <<  0  << endl;       else         cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 150;   int ej[M][M];   const int inf = 1e9;   int n;   int bfs(int src, int sink) {     vector<int> vis(n, 0);     vector<int> dis(n, 0);     queue<int> que;     vis[src] = 1;     que.push(src);     while (que.size() > 0) {       int u = que.front();       que.pop();       for (int v = 0; v < n; v++) {         if (vis[v] == 0 && ej[u][v] == 1) {           vis[v] = 1;           dis[v] = dis[u] + 1;           que.push(v);           if (v == sink) return dis[v];         }       }     }     return -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (x) v.push_back(x);     }     n = v.size();     for (long long k = 0; k < 62; k++) {       int cnt = 0;       for (int i = 0; i < n; i++) {         if (v[i] & (1LL << k)) {           cnt++;         }       }       if (cnt >= 3) {         cout << 3 << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if ((v[i] & v[j]) > 0) ej[i][j] = 1;       }     }     int ans = inf;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (ej[i][j] == 0) continue;         ej[i][j] = 0;         ej[j][i] = 0;         int cur = bfs(i, j);         if (cur != -1) {           ans = min(ans, cur + 1);         }         ej[i][j] = 1;         ej[j][i] = 1;       }     }     if (ans == inf) ans = -1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long arr[n + 5];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     long long mn = arr[0];     long long mx = arr[n - 1];     long long cnt1 = 0, cnt2 = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == mn)         cnt1++;       else if (arr[i] == mx)         cnt2++;     }     cout << mx - mn <<    ;     if (mn == mx)       cout << n * 1LL * (n - 1) / 2;     else       cout << (long long)(cnt1 * cnt2);     return 0;   }