#include <bits/stdc++.h>   using namespace std;   vector<long long> v[200010];   vector<long long> traversal;   long long cnt;   long long color[200010];   long long start[200010];   long long enddd[200010];   void dfs(long long curr) {     start[curr] = cnt;     traversal.push_back(curr);     cnt++;     for (int i = 0; i < v[curr].size(); i++) {       dfs(v[curr][i]);     }     enddd[curr] = cnt;   }   long long tree[800010];   long long lazy[800010];   void build_tree(int node, int a, int b) {     if (a > b) return;     if (a == b) {       tree[node] = color[traversal[a]];       return;     }     build_tree(node * 2, a, (a + b) / 2);     build_tree(node * 2 + 1, 1 + (a + b) / 2, b);     tree[node] = tree[node * 2] + tree[node * 2 + 1];   }   void update_tree(int node, int a, int b, int i, int j, int value) {     if (lazy[node] != 0) {       tree[node] = (b - a + 1 - tree[node]);       if (a != b) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];         lazy[node * 2] %= 2;         lazy[node * 2 + 1] %= 2;       }       lazy[node] = 0;     }     if (a > b || a > j || b < i) return;     if (a >= i && b <= j) {       tree[node] = (b - a + 1 - tree[node]);       if (a != b) {         lazy[node * 2] += value;         lazy[node * 2 + 1] += value;         lazy[node * 2] %= 2;         lazy[node * 2 + 1] %= 2;       }       return;     }     update_tree(node * 2, a, (a + b) / 2, i, j, value);     update_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j, value);     tree[node] = tree[node * 2] + tree[node * 2 + 1];   }   int query_tree(int node, int a, int b, int i, int j) {     if (a > b || a > j || b < i) return 0;     if (lazy[node] != 0) {       tree[node] = (b - a + 1 - tree[node]);       if (a != b) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];         lazy[node * 2] %= 2;         lazy[node * 2 + 1] %= 2;       }       lazy[node] = 0;     }     if (a >= i && b <= j) return tree[node];     int q1 = query_tree(node * 2, a, (a + b) / 2, i, j);     int q2 = query_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j);     int res = q1 + q2;     return res;   }   char str[4];   int main() {     long long n, temp;     cin >> n;     cnt = 0;     for (int i = 2; i <= n; i++) {       cin >> temp;       v[temp].push_back(i);     }     for (int i = 1; i <= n; i++) {       cin >> color[i];     }     dfs(1);     build_tree(1, 0, cnt - 1);     long long q;     cin >> q;     long long vertex;     while (q--) {       scanf( %s , str);       cin >> vertex;       if (str[0] ==  p ) {         update_tree(1, 0, cnt - 1, start[vertex], enddd[vertex] - 1, 1);       } else {         cout << query_tree(1, 0, cnt - 1, start[vertex], enddd[vertex] - 1)              << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> M;   long long posSum[300001];   int A[300001];   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) cin >> A[i];     posSum[0] = 0;     for (int i = 1; i <= N; i++) {       if (A[i] < 0)         posSum[i] = posSum[i - 1];       else         posSum[i] = posSum[i - 1] + A[i];     }     int a = 1;     int b = N;     long long best = -1000000000000000LL;     long long cur;     for (int i = 1; i <= N; i++) {       if (M.find(A[i]) != M.end()) {         if (A[i] < 0)           cur = 2LL * A[i] + posSum[i] - posSum[M[A[i]]];         else           cur = posSum[i] - posSum[M[A[i]] - 1];         if (best < cur) {           best = cur;           a = M[A[i]];           b = i;         }       } else         M[A[i]] = i;     }     int cnt = 0;     for (int i = 1; i <= N; i++) {       if ((i < a) || (i > b) || ((i > a) && (i < b) && (A[i] < 0))) cnt++;     }     cout << best <<     << cnt <<   n ;     for (int i = 1; i <= N; i++)       if ((i < a) || (i > b) || ((i > a) && (i < b) && (A[i] < 0)))         cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long A = 100000000000000LL, N = 10000, M = 1000001;   long long i, j, n, m, a, t[M * 4];   void modi(long long v, long long l, long long r, long long g, long long h) {     if (l == r) {       t[v] = h % 1000000007;       return;     }     long long mid = (l + r) / 2;     if (g <= mid)       modi(v * 2, l, mid, g, h);     else       modi(v * 2 + 1, mid + 1, r, g, h);     t[v] = (t[v * 2] + t[v * 2 + 1]) % 1000000007;   }   long long get(long long v, long long l, long long r, long long _l,                 long long _r) {     if (l > r || _l > _r) return 0;     if (l == _l && r == _r) return t[v];     long long mid = (l + r) / 2;     return get(v * 2, l, mid, _l, min(mid, _r)) +            get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r);   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       modi(1, 1, M, a, get(1, 1, M, 1, a) * a + a);     }     cout << get(1, 1, M, 1, M);   }


#include <bits/stdc++.h>   using namespace std;   int p[300002], pi;   bool tag[300002];   int main() {     int n, x;     long long cnt;     while (scanf( %d , &n) != EOF) {       memset(tag, false, sizeof(tag));       pi = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &x);         if (x < 1 || x > n || tag[x])           p[pi++] = x;         else           tag[x] = true;       }       sort(p, p + pi);       cnt = 0;       for (int i = 0, j = 1; i < pi; i++, j++) {         while (tag[j]) j++;         cnt += (long long)abs(p[i] - j);       }       printf( %I64d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[514][514];   int n, m;   int ID[514][514];   int RID[20005];   int idt[20005];   int g[20005];   int FIND(int x) { return g[x] == x ? x : (g[x] = FIND(g[x])); }   void UNION(int x, int y) {     x = FIND(x);     y = FIND(y);     g[x] = y;   }   int edge(int x, int y) {     if (FIND(x) == FIND(y)) return 1;     UNION(x, y);     return 0;   }   long long P[2][514][514];   int MOD = 1e9 + 7;   int nid = 0, Pid[2] = {};   void bridge(int x, int y) {     x = FIND(x);     y = FIND(y);     if (x == y) return;     P[idt[x]][RID[x]][RID[x]]++;     P[idt[x]][RID[x]][RID[y]]--;     P[idt[x]][RID[y]][RID[x]]--;     P[idt[x]][RID[y]][RID[y]]++;   }   long long inv(long long x, long long y, long long p, long long q, long long r,                 long long s) {     if (y == 0) return (p % MOD + MOD) % MOD;     return inv(y, x % y, r, s, p - r * (x / y), q - s * (x / y));   }   long long det(long long F[514][514], int D) {     long long ans = 1;     for (int i = 0; i < D; i++) {       int r = i;       while (r < D && F[r][i] == 0) ++r;       if (r >= D) return 0;       if (r != i) ans = ans * (MOD - 1) % MOD;       for (int j = i; j < D; j++) swap(F[r][j], F[i][j]);       ans = ans * F[i][i] % MOD;       long long t = inv(F[i][i], MOD, 1, 0, 0, 1);       for (int j = i; j < D; j++) F[i][j] = (F[i][j] * t) % MOD;       for (int r = i + 1; r < D; r++)         if (F[r][i] != 0) {           long long s = F[r][i];           for (int j = i; j < D; j++) {             F[r][j] = (F[r][j] - s * F[i][j]) % MOD;             if (F[r][j] < 0) F[r][j] += MOD;           }         }     }     return ans;   }   int main(void) {     scanf( %d%d%d , &n, &m, &MOD);     assert(1 <= n && n <= 100);     assert(1 <= m && m <= 100);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     for (int i = 0; i < n; i++) assert(strlen(a[i]) == m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         assert(a[i][j] ==  /  || a[i][j] ==      || a[i][j] ==  * );     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) {         ID[i][j] = ++nid;         g[nid] = nid;         idt[nid] = (i % 2) ^ (j % 2);       }     int fail = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] ==  / ) {           fail |= edge(ID[i + 1][j], ID[i][j + 1]);         } else if (a[i][j] ==     ) {           fail |= edge(ID[i][j], ID[i + 1][j + 1]);         }       }     if (fail) {       puts( 0 );       return 0;     }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++)         if (FIND(ID[i][j]) == ID[i][j]) {           RID[ID[i][j]] = Pid[idt[ID[i][j]]]++;         }     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           bridge(ID[i][j], ID[i + 1][j + 1]);           bridge(ID[i + 1][j], ID[i][j + 1]);           ++cnt;         }       }     }     assert(cnt <= 200);     for (int z = 0; z < 2; z++)       for (int i = 0; i < Pid[z]; i++)         for (int j = 0; j < Pid[z]; j++) P[z][i][j] = (P[z][i][j] + MOD) % MOD;     long long ans = det(P[0], Pid[0] - 1) + det(P[1], Pid[1] - 1);     printf( %d n , (int)(ans % MOD));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const N = 222;   int const M = 1e9 + 7;   int n;   ll f[N][N];   struct point {     ll x, y;     point(ll _x = 0, ll _y = 0) : x(_x), y(_y) {}     ll operator*(const point &rhs) const { return x * rhs.y - y * rhs.x; }     point operator-(const point &rhs) const {       return point(x - rhs.x, y - rhs.y);     }   } p[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %I64d%I64d , &p[i].x, &p[i].y);     ll area = 0;     for (int i = 1; i + 1 < n; ++i) area += (p[i] - p[0]) * (p[i + 1] - p[0]);     if (area < 0) reverse(p, p + n);     for (int i = 0; i < n; ++i) f[i][i] = f[i][(i + 1) % n] = 1;     for (int step = 2; step < n; ++step)       for (int i = 0; i < n; ++i) {         int j = (i + step) % n;         for (int t = 1; t <= step - 1; ++t) {           int k = (i + t) % n;           if ((p[k] - p[i]) * (p[j] - p[i]) > 0) {             f[i][j] = (f[i][j] + f[i][k] * f[k][j]) % M;           }         }       }     printf( %I64d n , f[0][n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void think() {     long long n, m;     cin >> n >> m;     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     long long ans = 0;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       ans += min(v[x - 1], v[y - 1]);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long testcase = 1;     while (testcase--) {       think();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long k = (n + 1) / 2;       k = k - 1;       long long ans = 0;       for (long long i = 1; i <= k; ++i) {         ans += 8 * i * i;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e4 + 5;   int n, q;   bool possible[MAXN];   vector<int> seg[4 * MAXN];   void update(int u, int l, int r, int tl, int tr, int x) {     if (l > tr || r < tl)       return;     else if (l <= tl && tr <= r) {       seg[u].push_back(x);     } else {       int tm = (tl + tr) / 2;       update(u << 1, l, r, tl, tm, x);       update(u << 1 | 1, l, r, tm + 1, tr, x);     }   }   void query(int u, int tl, int tr, bitset<MAXN> parsums) {     bitset<MAXN> sums = parsums;     for (int v : seg[u]) {       sums |= sums << v;     }     for (int i = 1; i <= n; ++i) {       possible[i] |= sums[i];     }     if (tl != tr) {       int tm = (tl + tr) / 2;       query(2 * u, tl, tm, sums);       query(2 * u + 1, tm + 1, tr, sums);     }   }   int main() {     cin >> n >> q;     while (q--) {       int l, r, x;       cin >> l >> r >> x;       update(1, l, r, 1, n, x);     }     query(1, 1, n, bitset<MAXN>(1));     int cnt = 0;     for (int i = 0; i <= n; ++i) {       if (possible[i]) {         ++cnt;       }     }     cout << cnt <<   n ;     for (int i = 0; i <= n; ++i) {       if (possible[i]) {         cout << i <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int f[100010], g[100010];   int _Max(int x, int y) { return x > y ? x : y; }   void upd(int x, int ans, int k) {     if (f[x] < ans)       f[x] = ans, g[x] = k;     else if (f[x] == ans && k < g[x])       g[x] = k;   }   int main() {     int n, L, p, t, i, j, l = 1, r = 0, x, y, s = 0, ans = 0;     scanf( %d%d%d%d , &L, &n, &p, &t);     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       while (r < i - 1 && g[r + 1] + t <= y) r++;       while (l < i && g[l] + t <= x) s = _Max(s, f[l++]);       f[i] = -1;       upd(i, s + (y - x) / p, x + (y - x) / p * p);       for (j = l; j <= r; j++)         upd(i, f[j] + (y - g[j] - t) / p, g[j] + t + (y - g[j] - t) / p * p);       ans = _Max(ans, f[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   template <class T>   double sqrt(T x) {     return sqrt((double)x);   }   template <class T>   T sqr(T x) {     return x * x;   }   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1000000007;   void wa() {     cout << 5;     exit(0);   }   void tl() {     while (1)       ;   }   void pe() {     cout <<  abc abc n 453534 wff sf sd n ;     exit(0);   }   void re() { exit(1); }   void ml() { int *b = new int[1000]; }   int main() {     double TIME_START = clock();     int n;     cin >> n;     unsigned long long ans = 1, lay;     if (n >= 2) {       lay = 12;       for (int x = 2; x <= n; x++) {         ans += lay;         lay += 12;       }     }     cout << ans;     fprintf(stderr,   n n%.15lf n n ,             (double)(clock() - TIME_START) / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 998244353;   const long long inf = 4e18;   const long long N = 3e5;   long long fac[N + 1];   long long power(long long x, long long y) {     if (y < 0) return power(x, M - 2) * power(x, y + 1) % M;     y %= (M - 1);     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x % M;       y = y >> 1;       x = x * x % M;     }     return res;   }   void factorial() {     fac[0] = 1;     for (long long i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % M;   }   long long nCr(long long n, long long r) {     if (r > n || r < 0) return 0;     if (r == 0) return 1;     return (fac[n] * power(fac[r], M - 2) % M * power(fac[n - r], M - 2) % M) % M;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     factorial();     long long n, k;     cin >> n >> k;     vector<pair<long long, long long> > v;     vector<long long> right;     for (long long i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       v.emplace_back(l, r);       right.emplace_back(r);     }     sort(v.begin(), v.end());     sort(right.begin(), right.end());     long long o = 0;     for (long long i = 0; i < n; i++) {       long long j =           upper_bound(v.begin(), v.end(), make_pair(right[i], inf)) - v.begin();       o = (o + nCr(j - i - 1, k - 1)) % M;     }     cout << o <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<long long int> cost(n);     for (long long int i = 0; i < n; i++) {       cin >> cost[i];     }     sort(cost.begin(), cost.end());     long long int m;     cin >> m;     vector<long long int> coup(m);     for (long long int i = 0; i < m; i++) {       cin >> coup[i];     }     long long int temp_sum = 0;     for (long long int i = 0; i < n; i++) {       temp_sum += cost[i];     }     for (long long int i = 0; i < m; i++) {       cout << temp_sum - cost.at(n - coup[i]) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool chk[5000050];   int ara[5000050], sum[5000050];   void sieve() {     int i, j, k, x, y, z;     for (i = 2; i <= 5000000; i++)       if (!chk[i]) {         for (j = i; j <= 5000000; j += i) {           x = 0;           k = j;           while (k % i == 0) {             x++;             k /= i;           }           chk[j] = true;           ara[j] += x;         }       }     sum[2] = ara[2];     for (i = 3; i <= 5000000; i++) sum[i] = sum[i - 1] + ara[i];   }   int main() {     sieve();     int i, t, n, m, k, ans;     scanf( %d , &t);     for (i = 0; i < t; i++) {       scanf( %d %d , &m, &n);       ans = sum[m] - sum[n];       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   string S;   int N;   int Z[MAXN];   int len[MAXN];   void Zalg() {     int L = 0, R = 0;     for (int i = 1; i < N; i++) {       if (i > R) {         L = R = i;         while (R < N && S[R] == S[R - L]) R++;         Z[i] = R - L;         R--;       } else {         int j = i - L;         if (Z[j] < R - i + 1)           Z[i] = Z[j];         else {           L = i;           while (R < N && S[R] == S[R - L]) R++;           Z[i] = R - L;           R--;         }       }     }   }   int main() {     cin >> S;     N = S.size();     Z[0] = N;     Zalg();     memcpy(len, Z, sizeof(len));     sort(len, len + N);     int total = 0;     for (int i = 1; i <= N; i++)       if (Z[N - i] == i) total++;     cout << total <<   n ;     int idx = 0;     for (int i = 1; i <= N; i++) {       if (Z[N - i] != i) continue;       while (idx < N && len[idx] < i) idx++;       cout << i <<     << N - idx <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   inline void print(int x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x >= 10) print(x / 10);     putchar((x % 10) | 48);   }   int n, m;   int ans[200010];   pair<int, int> edg[200010];   int len[200010];   bool tre[200010];   namespace tree {   vector<pair<int, int> > vec[200010];   int maxn[800010], ano[800010], tag[800010];   int siz[200010], son[200010], fa[200010], dfn[200010], top[200010], val[200010],       dep[200010];   int id;   void add(int u, int v, int w) {     vec[u].push_back(make_pair(v, w));     vec[v].push_back(make_pair(u, w));   }   void pushup(int p) {     maxn[p] = max(maxn[p << 1], maxn[p << 1 | 1]);     ano[p] = min(ano[p << 1], ano[p << 1 | 1]);   }   void pushdown(int p) {     if (tag[p] != -1) {       if (tag[p] < ano[p << 1]) {         ano[p << 1] = tag[p];       }       if (tag[p] < ano[p << 1 | 1]) {         ano[p << 1 | 1] = tag[p];       }       tag[p << 1] = (tag[p << 1] == -1 ? tag[p] : min(tag[p << 1], tag[p]));       tag[p << 1 | 1] =           (tag[p << 1 | 1] == -1 ? tag[p] : min(tag[p << 1 | 1], tag[p]));       tag[p] = -1;     }   }   void update(int p, int l, int r, int L, int R, int k) {     if (l >= L && r <= R) {       if (k < ano[p]) {         ano[p] = k;       }       tag[p] = (tag[p] == -1 ? k : min(tag[p], k));       return;     }     pushdown(p);     int mid = l + r >> 1;     if (L <= mid) update(p << 1, l, mid, L, R, k);     if (R > mid) update(p << 1 | 1, mid + 1, r, L, R, k);     pushup(p);   }   int qano(int p, int l, int r, int L, int R) {     if (l >= L && r <= R) {       return ano[p];     }     pushdown(p);     pushup(p);     int mid = l + r >> 1;     int res = 0x3f3f3f3f;     if (L <= mid) res = min(res, qano(p << 1, l, mid, L, R));     if (R > mid) res = min(res, qano(p << 1 | 1, mid + 1, r, L, R));     return res;   }   void build(int p, int l, int r) {     tag[p] = -1;     if (l == r) {       maxn[p] = val[l];       ano[p] = 0x3f3f3f3f;       return;     }     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     pushup(p);   }   int query(int p, int l, int r, int L, int R) {     if (l >= L && r <= R) return maxn[p];     int mid = l + r >> 1;     int res = 0;     if (L <= mid) res = max(res, query(p << 1, l, mid, L, R));     if (R > mid) res = max(res, query(p << 1 | 1, mid + 1, r, L, R));     return res;   }   int Query(int u, int v) {     int res = 0;     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       res = max(res, query(1, 1, id, dfn[top[u]], dfn[u]));       u = fa[top[u]];     }     if (u == v) return res;     if (dep[u] > dep[v]) swap(u, v);     res = max(res, query(1, 1, id, dfn[u] + 1, dfn[v]));     return res;   }   void dfs1(int x, int f) {     fa[x] = f, dep[x] = dep[f] + 1, siz[x] = 1;     for (auto i : vec[x]) {       int v = i.first;       if (v == f) continue;       dfs1(v, x);       siz[x] += siz[v];       if (siz[v] > siz[son[x]]) son[x] = v;     }   }   void dfs2(int x, int topf, int va) {     dfn[x] = ++id;     val[id] = va;     top[x] = topf;     if (!son[x]) return;     for (auto i : vec[x]) {       int v = i.first;       if (v == son[x]) {         dfs2(v, topf, i.second);       }     }     for (auto i : vec[x]) {       int v = i.first;       if (v == fa[x] || v == son[x]) continue;       dfs2(v, v, i.second);     }   }   void UPD(int x, int y, int k) {     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       update(1, 1, id, dfn[top[x]], dfn[x], k);       x = fa[top[x]];     }     if (x == y) return;     if (dep[x] > dep[y]) swap(x, y);     update(1, 1, id, dfn[x] + 1, dfn[y], k);   }   int another(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     return qano(1, 1, id, dfn[x], dfn[x]);   }   void solve() {     memset(ano, 0x3f, sizeof(ano));     dfs1(1, 0);     dfs2(1, 1, 0);     build(1, 1, id);   }   }  // namespace tree   namespace MST {   int cnt;   int fa[200010];   struct edge {     int u, v, w, id;   } e[200010];   void add(int u, int v, int w, int id) { e[++cnt] = edge{u, v, w, id}; }   bool cmp(edge x, edge y) { return x.w < y.w; }   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   void kruskal() {     int t = 1;     for (int i = 1; i <= m; ++i) {       int fx = find(e[i].u);       int fy = find(e[i].v);       if (fx == fy) {         continue;       }       ++t;       tree::add(e[i].u, e[i].v, e[i].w);       tre[e[i].id] = 1;       fa[fx] = fy;       if (t == n) break;     }   }   void solve() {     for (int i = 1; i <= n; ++i) fa[i] = i;     sort(e + 1, e + m + 1, cmp);     kruskal();   }   }  // namespace MST   int main() {     n = read(), m = read();     for (int i = 1; i <= m; ++i) {       int u = read(), v = read(), w = read();       edg[i].first = u, edg[i].second = v, len[i] = w;       MST::add(u, v, w, i);     }     MST::solve();     tree::solve();     for (int i = 1; i <= m; ++i) {       if (!tre[i]) {         tree::UPD(edg[i].first, edg[i].second, len[i]);       }     }     for (int i = 1; i <= m; ++i) {       if (ans[i] == -1) continue;       if (tre[i]) {         ans[i] = tree::another(edg[i].first, edg[i].second) - 1;         if (ans[i] > 0x3f3f3f15) ans[i] = -1;         continue;       }       int maxn = tree::Query(edg[i].first, edg[i].second);       ans[i] = maxn - 1;     }     for (int i = 1; i <= m; ++i) print(ans[i]), putchar(   );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[4];   int y[4];   int ii[4] = {1, -1, 0, 0};   int jj[4] = {0, 0, -1, 1};   int main() {     ios_base::sync_with_stdio(0);     int x1, x2, x3, y1, y2, y3;     for (int i = 1; i <= 3; i++) {       cin >> x[i] >> y[i];     }     set<pair<int, int>> s;     long long xx = 0, yy = 0;     long long d = 1e9;     for (int j = 0; j <= 1000; j++) {       for (int i = 0; i <= 1000; i++) {         if (abs(x[1] - i) + abs(y[1] - j) + abs(x[2] - i) + abs(y[2] - j) +                 abs(x[3] - i) + abs(y[3] - j) <             d) {           xx = i;           yy = j;           d = abs(x[1] - i) + abs(y[1] - j) + abs(x[2] - i) + abs(y[2] - j) +               abs(x[3] - i) + abs(y[3] - j);         }       }     }     for (int t = 1; t <= 3; t++) {       int i, j;       i = xx;       j = yy;       s.insert({x[t], y[t]});       while (i != x[t] || j != y[t]) {         s.insert({i, j});         for (int e = 0; e < 4; e++) {           if (abs(i - x[t]) > abs(i + ii[e] - x[t]) ||               abs(j - y[t]) > abs(j + jj[e] - y[t])) {             i += ii[e];             j += jj[e];             break;           }         }       }     }     cout << s.size() <<   n ;     for (auto p : s) {       cout << p.first <<     << p.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int Candidates[100];   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) {       int MaxVotesNum = -1;       int idx = -1;       for (int j = 0; j < N; j++) {         int Temp;         cin >> Temp;         if (MaxVotesNum < Temp) {           MaxVotesNum = Temp;           idx = j;         }       }       Candidates[idx]++;     }     cout << (max_element(Candidates, Candidates + 100) - Candidates) + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};   void solve() {     int d, x;     int a, b;     cin >> a >> b;     int ans = 0;     for (int i = a; i <= b; i++) {       x = i;       while (x) {         d = x % 10;         x = x / 10;         ans += arr[d];       }     }     cout << ans << endl;   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int lss[2000][2000] = {};   int main() {     string s;     cin >> s;     int n = s.length();     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       lss[i][i] = 1;       int temp = s[i];       int zero = 0;       if (s[i] ==  0 ) {         zero++;       }       for (int j = i + 1; j < n; j++) {         if (s[j] ==  1 ) {           lss[i][j] = lss[i][j - 1] + 1;         } else {           zero++;           lss[i][j] = max(zero, lss[i][j - 1]);         }       }     }     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         continue;       }       int temp1 = 0;       int zero = 0;       for (int j = 0; j <= i; j++) {         if (j != i && s[j] ==  1 ) {           temp1 = temp1 + 1;         } else {           zero++;           temp1 = max(zero, temp1);         }       }       int temp2 = 0;       zero = 0;       for (int j = i; j < n; j++) {         if (j != i && s[j] ==  1 ) {           temp2 = temp2 + 1;         } else {           zero++;           temp2 = max(zero, temp2);         }       }       if (temp1 == lss[0][i] && temp2 == lss[i][n - 1]) {         s[i] =  0 ;       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const bool OJ = true;   const long long inf = 1LL << 60;   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (long long i = 0; i < (((long long)((v).size()))); i++) os << v[i] <<    ;     return os;   }   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (long long i = 0; i < (((long long)((v).size()))); i++) is >> v[i];     return is;   }   template <class A, class B>   istream& operator>>(istream& is, tuple<A, B>& p) {     is >> get<0>(p) >> get<1>(p);     return is;   }   long long dp[100005][30];   string s;   long long k;   vector<tuple<char, char>> f;   bool ok(char x, char y) {     return !binary_search((f).begin(), (f).end(), make_tuple(x, y));   }   long long solve(long long i, char prev) {     if (i == ((long long)((s).size()))) return 0;     long long& d = dp[i][prev - 26];     if (d != -1) return d;     long long ans = inf;     if (ok(prev, s[i])) {       ans = min(ans, solve(i + 1, s[i]));     }     ans = min(ans, 1 + solve(i + 1, prev));     return d = ans;   }   void run() {     cin >> s;     cin >> k;     f = vector<tuple<char, char>>();     for (long long i = 0; i < (k); i++) {       string tmp;       cin >> tmp;       char x = tmp[0];       char y = tmp[1];       f.emplace_back(x, y);       f.emplace_back(y, x);     }     sort((f).begin(), (f).end());     memset(dp, -1, sizeof(dp));     cout << solve(0,  a  + 28) << endl;   }   int main(int argc, char* argv[]) {     run();     return 0;   }


#include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C& container, const E& element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T& a, T b) {     if (b > a) a = b;   }   using namespace std;   int n;   string s;   bool Check(int i) {     if (i == 0) return true;     vector<bool> d(10, false);     while (i != 0) {       int dig = i % 10;       if (d[dig]) return false;       d[dig] = true;       i = i / 10;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     int l, r;     cin >> l >> r;     for (int i = (l), _b = (r); i <= _b; i++) {       if (Check(i)) {         cout << i;         return 0;       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& x) {       clog << x <<    ;       return *this;     }   } dbg;   auto ____ = []() {     std::ios::sync_with_stdio(false);     cin.tie(nullptr);     return nullptr;   }();   int main(int argc, char* argv[]) {     int n, K;     cin >> n >> K;     vector<pair<int, int> > edges(n - 1);     vector<vector<pair<int, int> > > g(n);     for (int i = 0; i < (n - 1); ++i) {       int x, y;       cin >> x >> y;       --x, --y;       edges[i].first = x, edges[i].second = y;       g[x].push_back(make_pair(y, i));       g[y].push_back(make_pair(x, i));     }     vector<pair<int, int> > deg(n);     for (int i = 0; i < (n); ++i) deg[i] = make_pair((int)(g[i]).size(), i);     sort(deg.begin(), deg.end(), greater<pair<int, int> >());     int R = deg[K].first;     vector<int> edge_color(n - 1, -1);     stack<pair<int, int> > S;     S.push(make_pair(0, -1));     while (!S.empty()) {       auto p = S.top();       S.pop();       int x = p.first, c = p.second;       int d = 0;       for (auto y : g[x]) {         d %= R;         if (edge_color[y.second] == -1) {           if (R == 1)             d = 0;           else if (d == c) {             d++;             d %= R;           }           edge_color[y.second] = d;           S.push(make_pair(y.first, d));           ++d;         }       }     }     cout << R <<   n ;     for (auto c : edge_color) {       cout << c + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       int res[100];       memset(res, 0, sizeof(res));       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           int r;           cin >> r;           if (i < j) continue;           switch (r) {             case 1:               ++res[i];               break;             case 2:               ++res[j];               break;             case 3:               ++res[i];               ++res[j];             default:               break;           }         }       }       int count = 0;       for (int i = 0; i < n; ++i) {         if (res[i] == 0) {           res[count++] = i + 1;         }       }       cout << count << endl;       if (count > 0) {         for (int i = 0; i < count; ++i) {           cout << res[i] <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T mdINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   template <class T>   bool ISLEFT(T a, T b, T c) {     if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -          (b.first.first - c.first.first) * (a.second.second - b.second.second)) <         0.0)       return 1;     else       return 0;   }   int main() {     int n;     scanf( %d , &n);     string a[n + 2];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = n - 1; i >= 1; i--) {       string s;       int l = a[i + 1].size();       int l1 = a[i].size();       int first = 0;       s +=  # ;       bool fl = 0;       for (int j = 1; j <= min(l - 1, l1 - 1); j++) {         if (a[i][j] < a[i + 1][j]) fl = 1;         if (a[i][j] > a[i + 1][j]) {           break;         }         s += a[i][j];       }       if (fl)         a[i] = a[i];       else         a[i] = s;     }     for (int i = 1; i <= n; i++) cout << a[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void pre() {}   void solve() {}   bool vis[200009];   int ans[200009];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int n;     cin >> n;     int a, b;     cin >> a >> b;     priority_queue<pair<int, int> > q;     q.push(make_pair(0, 0));     memset(ans, -1, sizeof(ans));     ans[0] = 0;     while (!q.empty()) {       pair<int, int> z = q.top();       q.pop();       if (vis[z.second]) continue;       vis[z.second] = 1;       if (z.second + a < a + b && !vis[z.second + a] &&           (ans[z.second + a] == -1 ||            ans[z.second + a] > max(z.second + a, ans[z.second]))) {         ans[z.second + a] = max(z.second + a, ans[z.second]);         q.push(make_pair(-ans[z.second + a], z.second + a));       }       if (z.second - b >= 0 && !vis[z.second - b] &&           (ans[z.second - b] == -1 || ans[z.second - b] > ans[z.second])) {         ans[z.second - b] = ans[z.second];         q.push(make_pair(-ans[z.second - b], z.second - b));       }     }     long long fns = 0;     int m = min(a + b - 2, n);     for (int i = 0; i < (a + b - 1); ++i) {       if (ans[i] == -1) {         continue;       }       fns += max(0, m + 1 - ans[i]);     }     if (n > a + b - 2) {       m = n;       for (int i = 0; i < (a); ++i) {         if (ans[i] == -1) continue;         int l = (m) / a;         if (m % a >= i) l++;         int d = -a;         int st = m - i + 1;         fns += 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2;       }       m = a + b - 2;       for (int i = 0; i < (a); ++i) {         if (ans[i] == -1) continue;         int l = (m) / a;         if (m % a >= i) l++;         int d = -a;         int st = m - i + 1;         fns -= 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2;       }     }     cout << fns;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<string, int> m;   string s;   string pr[109];   int darab[109][26];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cout <<  ?   << 1 <<     << n << endl;     for (int i = 1; i <= (n * (n + 1)) / 2; i++) {       cin >> s;       sort(s.begin(), s.end());       m[s]++;     }     if (n == 1) {       cout <<  !   << s << endl;       return 0;     }     cout <<  ?   << 2 <<     << n << endl;     for (int i = 1; i <= (n * (n - 1)) / 2; i++) {       cin >> s;       sort(s.begin(), s.end());       m[s]--;     }     auto it = m.begin();     while (it != m.end()) {       if (it->second > 0) {         pr[(it->first).size()] = (it->first);       }       it++;     }     for (int i = n; i >= 1; i--) {       for (int j = 0; j < i; j++) {         darab[i][pr[i][j] -  a ]++;       }     }     string ans =   ;     for (int i = 1; i <= n; i++) {       int kul = 0;       for (int j = 0; j < 26; j++) {         if (darab[i][j] != darab[i - 1][j]) {           kul = j;           break;         }       }       ans += ((char)( a  + kul));     }     cout <<  !   << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long a, b;     cin >> a >> b;     long long m = b / 2 + 1;     if (m > a)       return b % m;     else       return b % a;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, mr;   vector<string> v;   string s, s2, tmp, res;   vector<pair<int, int> > e;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s;       v.push_back(s);     }     sort(v.begin(), v.end());     for (int i = 0; i < m; i++) {       cin >> s >> s2;       int a;       for (a = 0; a < n; a++)         if (v[a] == s) break;       int b;       for (b = 0; b < n; b++)         if (v[b] == s2) break;       e.push_back(make_pair(a, b));     }     int mx = (int)pow(2.0, n);     for (int x = mx - 1; x > 0; x--) {       bool f = true;       for (int i = 0; i < e.size(); i++) {         int e1 = n - e[i].first - 1, e2 = n - e[i].second - 1;         if ((x >> e1 & 1) && (x >> e2 & 1)) f = false;       }       if (f) {         int amx = mx;         int r = 0;         for (int o = 0; o < n; o++) {           if (x & (mx >> 1)) r++;           mx /= 2;         }         mx = amx;         tmp =   ;         for (int o = 0; o < n; o++) {           if (x & (mx >> 1)) tmp += v[o] +   n ;           mx /= 2;         }         mx = amx;         if (r > mr) res = tmp, mr = r;       }     }     cout << mr << endl;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 9e18 + 2e17;   const int inf = 2e9;   const int N = 1e5 + 22;   const double eps = 1e-10;   bool cmp(pair<int, int> A, pair<int, int> B) {     if (A.first != B.first) return A.first < B.first;     return A.second > B.second;   }   void _solve() {     int n, m;     cin >> n >> m;     pair<int, int> sr[n];     for (int i = (int)0; i < (int)n; i++) cin >> sr[i].first >> sr[i].second;     sort(sr, sr + n, cmp);     int c = 0;     for (int i = 0; i < n;) {       int x = sr[i].first;       while (i < n && x == sr[i].first) i++;       c++;     }     vector<vector<int> > row_sum(c);     vector<int> tot_sum;     int p = 0;     for (int i = 0; i < n;) {       int x = sr[i].first, sum = 0;       while (i < n && x == sr[i].first) {         sum += sr[i].second;         i++;         if (sum <= 0) continue;         row_sum[p].push_back(sum);       }       if (!row_sum[p].empty()) p++;     }     pair<int, int> row_sz[p];     for (int i = (int)0; i < (int)p; i++) row_sz[i] = {row_sum[i].size(), i};     sort(row_sz, row_sz + p);     for (int y = 0, i = 0; y < p;) {       int x = row_sz[y].first;       while (i < x) {         int sum = 0;         for (int j = (int)y; j < (int)p; j++) sum += row_sum[row_sz[j].second][i];         tot_sum.push_back(sum);         i++;       }       while (x == row_sz[y].first) y++;     }     int ans = 0;     for (int i = (int)0; i < (int)tot_sum.size(); i++) ans = max(ans, tot_sum[i]);     cout << ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     _solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt;   vector<int> a[150004];   int num[150004], sl[150004];   int d[150004];   void DFS(int u) {     num[u] = cnt;     for (int i = 0; i < a[u].size(); i++)       if (num[a[u][i]] == 0) DFS(a[u][i]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       d[u]++, d[v]++;       a[u].push_back(v);       a[v].push_back(u);     }     for (int u = 1; u <= n; u++)       if (num[u] == 0) {         cnt++;         DFS(u);       }     for (int i = 1; i <= n; i++) sl[num[i]]++;     for (int i = 1; i <= n; i++)       if (d[i] != sl[num[i]] - 1) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool arng(pair<long long, long long> p, pair<long long, long long> q) {     if (p.first > q.first) return true;     if (p.first == q.first) {       return (p.second < q.second);     }     return false;   }   void solve() {     long long n, m;     cin >> n;     long long ac[n];     pair<long long, long long> a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       ac[i] = a[i].first;       a[i].second = i;     }     sort(a, a + n, arng);     cin >> m;     while (m--) {       long long k, pos;       cin >> k >> pos;       long long s = 0;       long long posa[k];       for (long long i = 0; i < k; i++) {         posa[i] = a[i].second;       }       sort(posa, posa + k);       cout << ac[posa[pos - 1]] << endl;     }     return;   }   int32_t main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n + 1];       for (int i = 1; i <= n; i++) cin >> arr[i];       sort(arr + 1, arr + n + 1);       int dp[n + 1][405];       for (int i = 0; i <= n; i++)         for (int j = 0; j < 405; j++) dp[i][j] = 1000000;       for (int j = 0; j < 405; j++) dp[0][j] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j < 405; j++) {           dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + abs(j - arr[i]));         }       }       cout << dp[n][404] << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6 + 5;   using namespace std;   int n, k, a[N], cnt[N], Min = N;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       Min = min(Min, a[i]);       cnt[a[i]]++;     }     for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1];     for (int i = Min; i > k; i--) {       bool ck = 0;       int j;       for (j = i; j < N; j += i) {         if (cnt[j - 1] - cnt[j - i + k]) {           ck = 1;           break;         }       }       if (j - i + k < N && cnt[N - 1] - cnt[j - i + k]) ck = 1;       if (!ck) return cout << i, 0;     }     cout << min(Min, k) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     int ans = 1e9;     for (long long i = 0; i < n; i++) {       int j = max(n - i - 1, i);       int k;       if (i - j < 0)         k = min(a[n - 1], a[i]);       else         k = min(a[0], a[j]);       int cans = k / j;       ans = min(ans, cans);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); };     int n, cnt = 0;     cin >> n;     while (n) {       if (n >= 100) {         cnt += n / 100;         n %= 100;       }       if (n >= 20) {         cnt += n / 20;         n %= 20;       }       if (n >= 10) {         cnt += n / 10;         n %= 10;       }       if (n >= 5) {         cnt += n / 5;         n %= 5;       }       if (n >= 1) {         cnt += n;         n = 0;       }     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   string blank =   ;   const int N = 2e5 + 10;   vector<double> arr(N);   int n;   vector<double> can(double mid) {     vector<double> ans;     vector<double>::iterator i = arr.begin();     ans.push_back(min(arr[n - 1], *i + mid));     i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2));     if (i == arr.begin() + n) i = arr.begin() + n - 1;     ans.push_back(min(arr[n - 1], *i + mid));     i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2));     if (i == arr.begin() + n) i = arr.begin() + n - 1;     ans.push_back(min(arr[n - 1], *i + mid));     if (ans[2] + mid < arr[n - 1]) ans.clear();     return ans;   }   void solve() {     cin >> n;     for (long long i = (0); i < (n); i++) cin >> arr[i];     sort(arr.begin(), arr.begin() + n);     double l = 0, r = arr[n - 1] - arr[0], mid;     int rep = 100;     vector<double> ans;     while (rep--) {       mid = l + ((r - l) / 2.0);       vector<double> res = can(mid);       if (!res.empty())         r = mid, ans = res;       else         l = mid;     }     cout << fixed << setprecision(6) << l <<   n ;     for (long long i = (0); i < (3); i++)       cout << fixed << setprecision(6) << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const long long INF = 2e18;   void print(int a[], int n) {     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;   jump:     while (tc--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       string t =   ;       for (int i = 0; i < (n); i++) {         if (k == 0) {           for (int j = i; j < n; j++) t += s[j];           break;         }         int f =  z  - s[i];         int b = s[i] -  a ;         if (f > b) {           int x = s[i] + min(f, k);           t += (char)x;           k -= min(f, k);         } else {           int x = s[i] - min(b, k);           t += (char)x;           k -= min(b, k);         }       }       if (k > 0)         cout << -1;       else         cout << t;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 10e18;   map<long long, long long> mp;   int main() {     int t;     cin >> t;     long long int type, u, v, w;     while (t--) {       scanf( %lld , &type);       if (type == 1) {         scanf( %lld%lld%lld , &u, &v, &w);         while (u != v) {           if (u > v)             mp[u] += w, u /= 2;           else             mp[v] += w, v /= 2;         }       } else {         scanf( %lld%lld , &u, &v);         long long ans = 0;         while (u != v) {           if (u > v)             ans += mp[u], u /= 2;           else             ans += mp[v], v /= 2;         }         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct triplet {     int first, second, third;   } per[1005];   pair<int, int> pr[1005 / 2][1005], s[1005 / 2];   int n, a[1005], dp[1005], k, l, ind[1005 / 2][1005], indice, minim = 1 << 30,                                                                pas;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n + 2; i++) dp[i] = 1 << 30;     pas = 1;     per[1] = {1, 2, 3};     dp[1] = 0;     while (pas + 2 <= n) {       ++k;       for (int i = 1; i <= pas; i++) {         if (dp[pas + 1] > dp[i] + max(a[per[i].first], a[per[i].third])) {           dp[pas + 1] = dp[i] + max(a[per[i].first], a[per[i].third]);           pr[k][pas + 1] = {per[i].first, per[i].third};           ind[k][pas + 1] = i;         }         if (dp[pas + 2] > dp[i] + max(a[per[i].first], a[per[i].second])) {           dp[pas + 2] = dp[i] + max(a[per[i].first], a[per[i].second]);           pr[k][pas + 2] = {per[i].first, per[i].second};           ind[k][pas + 2] = i;         }         dp[i] = dp[i] + max(a[per[i].second], a[per[i].third]);         pr[k][i] = {per[i].second, per[i].third};         ind[k][i] = i;         per[i] = {i, pas + 3, pas + 4};       }       per[pas + 1] = {pas + 1, pas + 3, pas + 4};       per[pas + 2] = {pas + 2, pas + 3, pas + 4};       pas += 2;     }     l = 1;     for (int i = 1; i <= pas; i++)       if (dp[i] + max(a[per[i].first], a[per[i].second]) < minim) {         minim = dp[i] + max(a[per[i].first], a[per[i].second]);         s[l] = {per[i].first, per[i].second};         indice = i;       }     for (int i = k; i >= 1; i--) {       s[++l] = pr[i][indice];       indice = ind[i][indice];     }     cout << minim <<   n ;     for (int i = l; i > 1; i--) cout << s[i].first <<     << s[i].second <<   n ;     if (n % 2 == 0)       cout << s[1].first <<     << s[1].second;     else       cout << s[1].first;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   const int MD = 1000 * 1000 * 1000 + 7;   vector<int> g[maxn];   long long dp[maxn][2], mult[maxn][2], ans, cnt[maxn];   bool visited[maxn];   int binPow(int a, int b) {     if (!b) return 1;     if (b & 1) {       return (1LL * binPow(a, b - 1) * a) % MD;     } else {       int half = binPow(a, b / 2);       return (1LL * half * half) % MD;     }   }   long long inv(int a) { return binPow(a, MD - 2); }   void dfs(int v) {     cnt[v] = 1;     visited[v] = true;     mult[v][0] = mult[v][1] = 1;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (visited[to]) continue;       dfs(to);       cnt[v] += cnt[to];       mult[v][0] *= dp[to][0];       mult[v][0] %= MD;       mult[v][1] *= dp[to][1];       mult[v][1] %= MD;     }     if (cnt[v] == 1) {       dp[v][0] = dp[v][1] = 1;     } else {       dp[v][0] = (mult[v][0] + mult[v][1]) % MD;       dp[v][1] = (mult[v][0] + mult[v][1]) % MD;     }   }   void set_root(int v, int to) {     cnt[v] -= cnt[to];     cnt[to] += cnt[v];     mult[v][0] *= inv(dp[to][0]);     mult[v][0] %= MD;     mult[v][1] *= inv(dp[to][1]);     mult[v][1] %= MD;     if (cnt[v] > 1) {       dp[v][0] = (mult[v][0] + mult[v][1]) % MD;       dp[v][1] = (mult[v][0] + mult[v][1]) % MD;     } else {       dp[v][0] = dp[v][1] = 1;     }     mult[to][0] *= dp[v][0];     mult[to][0] %= MD;     mult[to][1] *= dp[v][1];     mult[to][1] %= MD;     dp[to][0] = (mult[to][0] + mult[to][1]) % MD;     dp[to][1] = (mult[to][0] + mult[to][1]) % MD;   }   void calc(int v, int parent) {     ans += dp[v][0];     if (ans >= MD) ans -= MD;     for (auto to : g[v]) {       if (to == parent) continue;       set_root(v, to);       calc(to, v);       set_root(to, v);     }   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     ans = 0;     memset(visited, false, sizeof(visited));     dfs(1);     calc(1, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int m = 1e9;     for (int i = 0; i < n; i++)       if (s[i] ==  R  && s[i + 1] ==  L ) m = min(m, (a[i + 1] - a[i]) / 2);     if (m == 1e9)       cout << -1 << endl;     else       cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string f0 =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   string fi1 =  What are you doing while sending   ;   string fi2 =   ? Are you busy? Will you send   ;   string fi3 =   ? ;   string ff =        What are you doing while sending  What are you doing at the end of the          world? Are you busy? Will you save us? ? Are you busy? Will you send           What are you doing at the end of the world? Are you busy? Will you save          us? ? ;   string answer;   long long l0, li1, li2, li3;   long long q, n, k, maxn = 53;   long long len[54];   void prep() {     l0 = f0.size();     li1 = fi1.size();     li2 = fi2.size();     li3 = fi3.size();     len[0] = l0;     for (int i = 1; i <= maxn; i++) {       len[i] = 2 * len[i - 1] + li1 + li2 + li3;     }   }   char ans(long long n, long long k) {     if (n > maxn)       return k <= (n - maxn) * li1 ? fi1[(k - 1) % li1]                                    : ans(maxn, k - (n - maxn) * li1);     if (k > len[n]) return  . ;     if (n == 0) return f0[k - 1];     if (k <= li1) return fi1[k - 1];     if (k <= li1 + len[n - 1]) return ans(n - 1, k - li1);     if (k <= li1 + len[n - 1] + li2) return fi2[k - li1 - len[n - 1] - 1];     if (k <= li1 + len[n - 1] + li2 + len[n - 1])       return ans(n - 1, k - li1 - len[n - 1] - li2);     return fi3[k - li1 - len[n - 1] - li2 - len[n - 1] - 1];   }   int main() {     prep();     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> n >> k;       answer += ans(n, k);     }     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O3 )   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a1, a2, k1, k2, n;     cin >> a1 >> a2 >> k1 >> k2 >> n;     if (k1 > k2) {       swap(a1, a2);       swap(k1, k2);     }     if (n <= a1 * (k1 - 1) + a2 * (k2 - 1)) {       cout <<  0  ;     } else {       cout << n - (a1 * (k1 - 1) + a2 * (k2 - 1)) <<    ;     }     long long int ans = n / k1;     n = n % k1;     if (ans > a1) {       n += (ans - a1) * k1;       ans = a1;     }     ans += n / k2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, a, b, c, d;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       long long l = 0, r = (c + d - 1) / d;       while (l < r) {         long long mid = l + r + 1 >> 1;         long long sum1 = (mid + 1) * mid / 2 * d * b - (mid + 1) * a;         if (mid == (c + d - 1) / d) sum1 -= (mid * d - c) * b;         long long sum2 = (mid - 1) * mid / 2 * d * b - mid * a;         if (sum1 >= sum2)           r = mid - 1;         else           l = mid;       }       if (l == (c + d - 1) / d)         cout <<  -1 n ;       else {         long long sum = (l + 1) * l / 2 * d * b - (l + 1) * a;         cout << -sum <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void show() {}   template <typename T, typename... V>   void show(T t, V... v) {     cerr << t;     if (sizeof...(v)) cerr <<  ,  ;     show(v...);   }   template <class X>   bool mini(X& a, const X& b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class X>   bool maxi(X& a, const X& b) {     if (a < b) {       a = b;       return true;     }     return false;   }   typedef const int& ci;   int n;   int dp[1 << 24];   void enter() {     cin >> n;     for (int i = 1, _b = (n) + 1; i < _b; ++i) {       char a, b, c;       cin >> a >> b >> c;       ++dp[(1 << a -  a ) | (1 << b -  a ) | (1 << c -  a )];     }   }   void solve() {     int MASK = (1 << 24);     for (int i = 0; i < 24; ++i)       for (int mask = 0; mask < MASK; ++mask)         if (mask >> i & 1) dp[mask] += dp[mask ^ (1 << i)];     int res = 0;     for (int mask = 0; mask < MASK; ++mask)       if (dp[mask] != n) res ^= (n - dp[mask]) * (n - dp[mask]);     cout << res;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     enter();     solve();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms ;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> adj[101];   set<pair<long long int, long long int>> color[101];   long long int visited[101];   long long int x;   void bfs(long long int a, long long int b, long long int c) {     queue<long long int> q;     q.push(a);     while (!q.empty()) {       long long int p = q.front();       q.pop();       if (p == b) {         x = 1;         visited[p] = 1;       }       if (visited[p]) continue;       visited[p] = 1;       for (long long int i = 0; i < adj[p].size(); i++) {         if (color[c].find({p, adj[p][i]}) != color[c].end()) {           q.push(adj[p][i]);         }       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, j, k, l, m, n, p, t, a, b, c, q;     cin >> n >> m;     set<pair<long long int, long long int>> s;     for (i = 0; i < m; i++) {       cin >> a >> b >> c;       if (s.find({a, b}) == s.end()) {         s.insert({a, b});         adj[a].push_back(b);         adj[b].push_back(a);       }       color[c].insert({a, b});       color[c].insert({b, a});     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> a >> b;       p = 0;       for (j = 1; j <= m; j++) {         x = 0;         bfs(a, b, j);         p += x;         memset(visited, 0, sizeof(visited));       }       cout << p <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, g;   int a[100010];   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   bool used[100010];   int main() {     scanf( %d%d , &n, &k);     g = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] %= k;       g = gcd(g, a[i]);       g = gcd(g, k - a[i]);     }     int cnt = 0;     for (int i = 0; i < k; i += g) {       if (used[i] == 1) break;       used[i] = 1;       cnt++;     }     printf( %d n , cnt);     for (int i = 0; i < k; i++)       if (used[i] == 1) printf( %d  , i);   }


#include <bits/stdc++.h>   using namespace std;   int a[109];   int main() {     int n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> a[i];       int p = 0;       sort(a, a + n);       for (int i = 0; i < n; i++) {         int flag = 0;         while (a[i]) {           if (a[i] % 10 == 4 || a[i] % 10 == 7) flag++;           a[i] /= 10;         }         if (flag <= m) p++;       }       cout << p << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     for (int i = 0; i < a; i++) {       int c = 0;       int j;       cin >> j;       int f = j % 10;       if (j > 1) f = (f - 1) * 10;       if (j > 1000) {         f = f + 10;       } else if (j > 100) {         f = f + 6;       } else if (j > 10) {         f = f + 3;       } else if (j > 1 && j < 10) {         f = f + 1;       }       cout << f << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   #define size(v) (int)v.size()   #define all(v) (v).begin(),(v).end()   using lint = long long;   using fint = long double;   const int INF = 1e9 + 9;   const int MOD = 998244353;      int n, a[200000];      int solve(){       int ret = 0;          // pp...p cc...c       lint psum = 0, sum = accumulate(a,a+n,0ll);       for(int i=0;i<n;++i){           psum += a[i];           if(psum > sum - psum)               ret++;       }          // cc...c pcpc...pc pp...p       //      i         ^ (lower bonud)       auto f = [&](vector<int> a,lint base){           vector<lint> pa, ev, od;           for(int i=0;i<size(a);++i) pa.push_back(a[i]);           for(int i=0;i<size(a)-1;i+=2) ev.push_back(a[i]);           for(int i=1;i<size(a)-1;i+=2) od.push_back(a[i]);           for(int i=1;i<size(pa);++i) pa[i] += pa[i-1];           for(int i=1;i<size(ev);++i) ev[i] += ev[i-1];           for(int i=1;i<size(od);++i) od[i] += od[i-1];           for(int i=0;i<size(a)-1;++i){               vector<lint> &oe = (i&1 ? od : ev);               lint dff = base + pa[size(a)-1] - pa[i] - pa[i];               int cnt = lower_bound(all(oe), oe[i/2] + (dff+1)/2) - lower_bound(all(oe), oe[i/2]);               if(dff > 0) ret = (ret + cnt) % MOD;           }       };          // Case1: cc...c pcpc...pc pp...p       if(1 < n) f(vector<int>(a,a+n), 0);       // Case2: cc...c pcpc...pc pp...p(c)       if(2 < n) f(vector<int>(a,a+n-1), -a[n-1]);       // Case3: (p)ccc...c pcpc...pc pp...p       if(2 < n) f(vector<int>(a+1,a+n), a[0]);       // Case4: (p)ccc...c pcpc...pc pp...p(c)       if(3 < n) f(vector<int>(a+1,a+n-1), a[0]-a[n-1]);          return ret;      }      int main(){       int tc; scanf( %d ,&tc);       while(tc--){           scanf( %d ,&n);           for(int i=0;i<n;++i)               scanf( %d ,a+i);           printf( %d n ,solve());       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   long long A[N];   map<long long, long long> MP;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &A[i]);     MP.insert({A[1] - 1, 0});     for (int i = 2; i <= n; i++) {       long long B = -1;       while (MP.rbegin()->first >= A[i]) {         long long a = MP.rbegin()->first;         long long b = MP.rbegin()->second;         MP[a % A[i]] = max(MP[a % A[i]], b + a / A[i] * A[i] * (i - 1));         B = max(B, b + (a / A[i] - 1) * A[i] * (i - 1));         MP.erase(a);       }       if (B >= 0) MP[A[i] - 1] = max(MP[A[i] - 1], B);     }     long long MX = 0;     for (auto X : MP) MX = max(MX, X.first * n + X.second);     return !printf( %lld n , MX);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long a[n + 2];     a[0] = 0;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1])         sum += (a[i] - a[i - 1]) * (n - a[i] + 1);       else if (a[i] < a[i - 1])         sum += a[i] * (a[i - 1] - a[i]);     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int num[maxn];   int F[1010];   int fnd(int t) {     if (F[t] == t) return t;     return F[t] = fnd(F[t]);   }   void join(int a, int b) {     int t1 = fnd(a);     int t2 = fnd(b);     if (t1 != t2) F[t1] = t2;   }   int main() {     int n, m, k;     int cap[maxn];     cin >> n >> m >> k;     memset(num, 0, sizeof(num));     memset(F, 0, sizeof(F));     for (int i = 1; i <= n; ++i) F[i] = i;     for (int i = 1; i <= k; ++i) cin >> cap[i];     for (int i = 1, a, b; i <= m; ++i) {       cin >> a >> b;       join(a, b);     }     for (int i = 1; i <= n; ++i) num[fnd(i)]++;     int maxn = 0, lef = n;     int ans = 0;     for (int i = 1; i <= k; ++i) {       num[cap[i]] = num[fnd(cap[i])];       maxn = max(maxn, num[cap[i]]);       lef -= num[cap[i]];       ans += (num[cap[i]] - 1) * (num[cap[i]]) / 2;     }     ans += (lef + maxn) * (lef + maxn - 1) / 2;     ans -= maxn * (maxn - 1) / 2 + m;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000005;   int n, a[maxN], p[230], b[230];   bool bo[1 << 22];   void Init() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);   }   void Work() {     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= 20; ++j) {         while (p[j] <= n && (p[j] < i || ((a[p[j]] >> (j - 1)) & 1) == 0)) ++p[j];         b[j] = p[j];       }       sort(b + 1, b + 1 + 20);       int x = a[i];       if (!bo[x]) {         ++ans;         bo[x] = 1;       }       for (int j = 1; j <= 20; ++j) {         x |= a[b[j]];         if (!bo[x]) {           ++ans;           bo[x] = 1;         }       }     }     cout << ans << endl;   }   int main() {     Init();     Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     while (T-- > 0) {       long long n, k;       cin >> n >> k;       int m;       for (m = 2; m <= n; m++) {         if (n % m == 0) break;       }       long long ans = n + m + (k - 1) * 2;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   struct point;   struct vec;   struct line;   struct circle;   struct triangle;   double to_rad(double theta);   double to_deg(double theta);   double dist(point p, point q);   point middle(point p, point q);   point translate(point p, vec u);   double norm_sq(vec u);   double dot(vec u, vec v);   double cross(vec u, vec v);   bool are_parallel(line l, line d);   bool are_same(line l, line d);   double dist_to_line(point p, point a, point b);   bool ccw(point p, point q, point r);   bool collinear(point p, point q, point r);   double angle(point a, point o, point b);   point rotate(point p, double theta, point q);   point intersection(line l, line d);   point projection(point p, point a, point b);   double dist_to_segment(point p, point a, point b);   point reflection(point p, point a, point b);   line perpendicular(point p, point a, point b);   line bisector(point a, point o, point b);   circle find_circle(point p, point q, double r);   circle in_circle(triangle t);   circle circum_circle(triangle t);   double perimeter(vector<point> P);   double area(vector<point> P);   bool is_convex(vector<point> P);   bool is_in(point p, vector<point> P);   vector<point> cut(vector<point> P, point a, point b);   bool ch_cmp(point a, point b);   vector<point> convex_hull(vector<point> P);   struct point {     double x, y;     point(double nx = 0, double ny = 0) { x = nx, y = ny; }     bool operator==(point p) {       return fabs(x - p.x) <= (1e-9) && fabs(y - p.y) <= (1e-9);     }     bool operator!=(point p) {       return fabs(x - p.x) > (1e-9) || fabs(y - p.y) > (1e-9);     }     bool operator<(point p) {       if (fabs(x - p.x) > (1e-9)) return x < p.x - (1e-9);       return y < p.y - (1e-9);     }     friend istream &operator>>(istream &is, point &p) { return is >> p.x >> p.y; }     friend ostream &operator<<(ostream &os, point &p) {       return os << p.x <<     << p.y;     }   };   struct vec {     double x, y;     vec(double nx = 0, double ny = 0) { x = nx, y = ny; }     vec(point p, point q) { x = q.x - p.x, y = q.y - p.y; }     vec operator+(vec u) { return vec(x + u.x, y + u.y); }     vec operator-(vec u) { return vec(x - u.x, y - u.y); }     vec operator*(double k) { return vec(k * x, k * y); }     friend istream &operator>>(istream &is, vec &u) { return is >> u.x >> u.y; }     friend ostream &operator<<(ostream &os, vec &u) {       return os << u.x <<     << u.y;     }   };   struct line {     double a, b, c;     line(double na = 0, double nb = 0, double nc = 0) { a = na, b = nb, c = nc; }     line(point p, point q) {       double dx = q.x - p.x;       double dy = q.y - p.y;       if (fabs(dx) <= (1e-9)) {         a = 1, b = 0, c = -p.x;         return;       }       a = -dy / dx;       b = 1.0;       c = dy / dx * p.x - p.y;     }     line(point p, double m) {       a = -m;       b = 1.0;       c = -(a * p.x + p.y);     }     pair<point, point> to_points() {       point p, q;       if (fabs(b) <= (1e-9))         p.x = -c / a, q.x = p.x, p.y = 0, q.y = 1;       else         p.x = 0, q.x = 1, p.y = -(a * p.x + c), q.y = -(a * q.x + c);       return make_pair(p, q);     }   };   struct circle {     double x, y, r;     circle(point c = point(0, 0), double nr = 0) { x = c.x, y = c.y, r = nr; }     int is_in(point p) {       double dx = p.x - x, dy = p.y - y;       double d = dx * dx + dy * dy, R = r * r;       return (d < R - (1e-9)) ? 0 : (fabs(d - R) <= (1e-9)) ? 1 : 2;     }     double perimeter(double theta = 360) {       theta = to_rad(theta);       return theta * r;     }     double area(double theta = 360) {       theta = to_rad(theta);       return theta * r * r / 2;     }   };   struct triangle {     point A, B, C;     double a, b, c;     triangle(double na = 0, double nb = 0, double nc = 0) {       a = na, b = nb, c = nc;     }     triangle(point nA, point nB, point nC) {       A = nA, B = nB, C = nC;       c = dist(A, B), a = dist(B, C), b = dist(C, A);     }     bool is_triangle() {       return a + b > c + (1e-9) && b + c > a + (1e-9) && c + a > b + (1e-9);     }     double perimeter() { return a + b + c; }     double area() {       double s = perimeter() / 2;       return sqrt(s * (s - a) * (s - b) * (s - c));     }   };   double to_rad(double theta) { return theta * acos(-1.0) / 180; }   double to_deg(double theta) { return theta * 180 / acos(-1.0); }   double dist(point p, point q) { return hypot(p.x - q.x, p.y - q.y); }   point middle(point p, point q) {     return point((p.x + q.x) / 2, (p.y + q.y) / 2);   }   point translate(point p, vec u) { return point(p.x + u.x, p.y + u.y); }   double norm_sq(vec u) { return u.x * u.x + u.y * u.y; }   double dot(vec u, vec v) { return u.x * v.x + u.y * v.y; }   double cross(vec u, vec v) { return u.x * v.y - u.y * v.x; }   bool are_parallel(line l, line d) {     return fabs(l.a - d.a) <= (1e-9) && fabs(l.b - l.b) <= (1e-9);   }   bool are_same(line l, line d) {     return are_parallel(l, d) && fabs(l.c - d.c) <= (1e-9);   }   double dist_to_line(point p, point a, point b) {     return dist(p, projection(p, a, b));   }   bool ccw(point p, point q, point r) {     return cross(vec(p, q), vec(p, r)) > 0 + (1e-9);   }   bool collinear(point p, point q, point r) {     return fabs(cross(vec(p, q), vec(p, r))) <= (1e-9);   }   double angle(point a, point o, point b) {     vec oa = vec(o, a), ob = vec(o, b);     return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob)));   }   point rotate(point p, double theta, point q = point(0, 0)) {     vec oq = vec(point(0, 0), q);     p = translate(p, oq * -1);     theta = to_rad(theta);     double x = p.x * cos(theta) - p.y * sin(theta);     double y = p.x * sin(theta) + p.y * cos(theta);     p = point(x, y);     p = translate(p, oq);     return p;   }   point intersection(line l, line d) {     point p;     p.x = (d.b * l.c - l.b * d.c) / (d.a * l.b - l.a * d.b);     if (fabs(l.b) > (1e-9))       p.y = -(l.a * p.x + l.c);     else       p.y = -(d.a * p.x + d.c);     return p;   }   point projection(point p, point a, point b) {     vec ap = vec(a, p), ab = vec(a, b);     double u = dot(ap, ab) / norm_sq(ab);     return translate(a, ab * u);   }   double dist_to_segment(point p, point a, point b) {     vec ap = vec(a, p), ab = vec(a, b);     double u = dot(ap, ab) / norm_sq(ab);     if (u < 0 - (1e-9)) return dist(p, a);     if (u > 1 + (1e-9)) return dist(p, b);     return dist_to_line(p, a, b);   }   point reflection(point p, point a, point b) {     point c = projection(p, a, b);     vec pc = vec(p, c);     return translate(p, pc * 2);   }   line perpendicular(point p, point a, point b) {     if (!collinear(p, a, b)) return line(p, projection(p, a, b));     line l = line(a, b);     if (fabs(l.b) <= (1e-9)) return line(p, point(p.x + 1, p.y));     if (fabs(l.a) <= (1e-9)) return line(p, point(p.x, p.y + 1));     return line(p, 1 / l.a);   }   line bisector(point a, point o, point b) {     double ratio = dist(o, a) / dist(o, b);     ratio /= ratio + 1;     vec ab = vec(a, b);     point c = translate(a, ab * ratio);     return line(o, c);   }   circle find_circle(point p, point q, double r) {     point m = middle(p, q);     vec mp = vec(m, p);     double mc = r * r - norm_sq(mp);     if (mc < 0 - (1e-9)) return circle();     mc = sqrt(mc);     double u = mc / dist(m, p);     point c = translate(m, mp * u);     c = rotate(c, 90, m);     return circle(c, r);   }   circle in_circle(triangle t) {     double r = 2 * t.area() / t.perimeter();     if (fabs(r) <= (1e-9)) return circle();     line l = bisector(t.B, t.A, t.C);     line d = bisector(t.C, t.B, t.A);     point c = intersection(l, d);     return circle(c, r);   }   circle circum_circle(triangle t) {     double r = (t.a * t.b * t.c) / (4 * t.area());     if (fabs(r) <= (1e-9)) return circle();     line l = perpendicular(middle(t.A, t.B), t.A, t.B);     line d = perpendicular(middle(t.A, t.C), t.A, t.C);     point c = intersection(l, d);     return circle(c, r);   }   point pivot;   double perimeter(vector<point> P) {     int n = P.size();     double ret = 0;     for (int i = 0; i < n - 1; i++) ret += dist(P[i], P[i + 1]);     return ret;   }   double area(vector<point> P) {     int n = P.size();     double ret = 0;     double x1, x2, y1, y2;     for (int i = 0; i < n - 1; i++) {       x1 = P[i].x, x2 = P[i + 1].x;       y1 = P[i].y, y2 = P[i + 1].y;       ret += x1 * y2 - x2 * y1;     }     ret /= 2, ret = fabs(ret);     return ret;   }   bool is_convex(vector<point> P) {     int n = P.size();     if (n <= 3) return false;     bool turn = ccw(P[0], P[1], P[2]);     for (int i = 1; i < n - 1; i++)       if (ccw(P[i], P[i + 1], P[i + 2 != n ? i + 2 : 1]) != turn) return false;     return true;   }   bool is_in(point p, vector<point> P) {     int n = P.size();     double sum = 0;     for (int i = 0; i < n - 1; i++)       if (ccw(P[i], p, P[i + 1]))         sum += angle(P[i], p, P[i + 1]);       else         sum -= angle(P[i], p, P[i + 1]);     sum = fabs(sum);     return fabs(sum - 2 * acos(-1.0)) <= (1e-9);   }   vector<point> cut(vector<point> P, point a, point b) {     int n = P.size();     vector<point> ret;     for (int i = 0; i < n; i++) {       double left1 = cross(vec(a, b), vec(a, P[i]));       double left2 = (i != n - 1) ? cross(vec(a, b), vec(a, P[i + 1])) : 0;       if (left1 >= -(1e-9)) ret.push_back(P[i]);       if (left1 * left2 < -(1e-9))         ret.push_back(intersection(line(a, b), line(P[i], P[i + 1])));     }     if (!ret.empty() && ret.front() != ret.back()) ret.push_back(ret.front());     return ret;   }   bool ch_cmp(point a, point b) {     if (collinear(pivot, a, b)) return dist(pivot, a) < dist(pivot, b) - (1e-9);     double dx1 = a.x - pivot.x, dy1 = a.y - pivot.y;     double dx2 = b.x - pivot.x, dy2 = b.y - pivot.y;     return atan2(dy1, dx1) < atan2(dy2, dx2) - (1e-9);   }   vector<point> convex_hull(vector<point> P) {     int n = P.size();     if (n <= 3) {       if (n != 0 && P[0] != P[n - 1]) P.push_back(P[0]);       return P;     }     int idx = 0;     for (int i = 1; i < n; i++)       if (P[idx].y > P[i].y + (1e-9) ||           (fabs(P[idx].y - P[i].y) <= (1e-9) && P[idx].x < P[i].x - (1e-9)))         idx = i;     swap(P[0], P[idx]);     pivot = P[0];     sort(P.begin() + 1, P.end(), ch_cmp);     vector<point> ch;     ch.push_back(P[n - 1]), ch.push_back(P[0]), ch.push_back(P[1]);     int i = 2;     while (i < n) {       int j = ch.size() - 1;       if (ccw(ch[j - 1], ch[j], P[i]))         ch.push_back(P[i]), i++;       else         ch.pop_back();     }     return ch;   }   void print(vector<point> P) {     int n = P.size();     cout << endl;     for (int i = 0; i < n; i++) cout << P[i] << endl;     cout << endl;   }   int main() {     read_file();     int x;     while (cin >> x) {       point p = point(0, 0);       vector<point> P;       P.push_back(p);       vec u(1, 0);       point q = translate(p, u * x);       P.push_back(q);       for (int i = 0; i < 5; i++) {         cin >> x;         u = vec(p, q);         u = u * (1 / dist(p, q));         p = q;         q = translate(q, u * x);         q = rotate(q, 60, p);         P.push_back(q);       }       P.push_back(point(0, 0));       double a = area(P);       triangle t = triangle(1, 1, 1);       double b = t.area();       int ans = a / b + 1e-6;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   long long n, m, aa, b, i, j, k, mx[1005][1005], mx2[1005][1005], a[1005][1005],       l, r, qx[1005][2], vis[1005][1005], c[1005][1005];   vector<pair<long long, pair<int, int> > > s;   vector<pair<pair<int, int>, long long> > ans;   int main() {     ios::sync_with_stdio(false);     ;     cin >> n >> m >> aa >> b;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         cin >> a[i][j];         c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + a[i][j];       }     }     for (i = 1; i <= n; i++) {       k = 1;       l = r = 0;       for (j = 1; j <= m; j++) {         while (k <= m && j + b > k) {           while (l < r && qx[r - 1][0] >= a[i][k]) r--;           qx[r][0] = a[i][k];           qx[r][1] = k;           r++;           k++;         }         while (l < r && qx[l][1] < j) l++;         mx[i][j] = qx[l][0];       }     }     for (i = 1; i <= m; i++) {       k = 1;       l = r = 0;       for (j = 1; j <= n; j++) {         while (k <= n && j + aa > k) {           while (l < r && qx[r - 1][0] >= mx[k][i]) r--;           qx[r][0] = mx[k][i];           qx[r][1] = k;           r++;           k++;         }         while (l < r && qx[l][1] < j) l++;         mx2[j][i] = qx[l][0];       }     }     for (i = 1; i + aa - 1 <= n; i++) {       for (j = 1; j + b - 1 <= m; j++) {         s.push_back(make_pair(c[i + aa - 1][j + b - 1] - c[i + aa - 1][j - 1] -                                   c[i - 1][j + b - 1] + c[i - 1][j - 1] -                                   mx2[i][j] * aa * b,                               make_pair(i, j)));       }     }     stable_sort((s).begin(), (s).end());     int pos = 0;     while (pos < s.size()) {       pair<long long, pair<int, int> > cur = s[pos];       pos++;       i = cur.second.first, j = cur.second.second;       if (vis[i][j]) continue;       for (int xx = max(i - aa + 1, 1ll); xx <= i + aa - 1 && xx <= n; xx++) {         for (int yy = max(j - b + 1, 1ll); yy <= j + b - 1 && yy <= m; yy++) {           vis[xx][yy] = 1;         }       }       ans.push_back(make_pair(make_pair(i, j), cur.first));     }     writell((long long)ans.size());     writeln();     for (i = 0; i < ans.size(); i++)       printf( %d %d %I64d n , ans[i].first.first, ans[i].first.second,              ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 3;   const long long linf = (long long)inf * inf + 2;   int N, K;   struct TrieNode {     TrieNode *children[26];     bool canWin, canLose;     TrieNode() {       canWin = canLose = false;       for (int i = 0; i < 26; ++i) children[i] = nullptr;     }   };   TrieNode *root;   struct Trie {     Trie() { root = new TrieNode(); }     void insert(string &key, int idx = 0, TrieNode *pCrawl = root) {       if (idx == (int)key.length()) return;       int charId = key[idx] -  a ;       if (pCrawl->children[charId] == nullptr)         pCrawl->children[charId] = new TrieNode();       insert(key, idx + 1, pCrawl->children[charId]);     }     void precompute(TrieNode *pCrawl = root) {       bool hasChildren = false;       for (int i = 0; i < 26; ++i)         if (pCrawl->children[i] != nullptr) {           hasChildren = true;           precompute(pCrawl->children[i]);           if (!pCrawl->children[i]->canWin) pCrawl->canWin = true;           if (!pCrawl->children[i]->canLose) pCrawl->canLose = true;         }       if (!hasChildren) pCrawl->canLose = true;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> K;     Trie myTrie = Trie();     string str;     for (int i = 0; i < N; ++i) {       cin >> str;       myTrie.insert(str);     }     myTrie.precompute();     bool canForceWin = root->canWin, canForceLose = root->canLose;     if (canForceWin && canForceLose)       cout <<  First n ;     else if (canForceWin)       cout << (K % 2 ?  First n  :  Second n );     else       cout <<  Second n ;     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000007;   using namespace std;   int main() {     long long ax, ay, bx, by, tx, ty;     scanf( %I64d , &(ax));     scanf( %I64d , &(ay));     scanf( %I64d , &(bx));     scanf( %I64d , &(by));     scanf( %I64d , &(tx));     scanf( %I64d , &(ty));     long long n;     scanf( %I64d , &(n));     vector<pair<long long, long long>> bot(n);     vector<double> toT(n);     vector<pair<double, int>> toA(n), toB(n);     double sum = 0;     for (int(i) = 0; (i) < n; (i)++) {       scanf( %I64d , &(bot[i].first));       scanf( %I64d , &(bot[i].second));       toT[i] = sqrt((double)((bot[i].first - tx) * (bot[i].first - tx) +                              (bot[i].second - ty) * (bot[i].second - ty)));       sum += 2 * toT[i];       toA[i].first = sqrt((double)((bot[i].first - ax) * (bot[i].first - ax) +                                    (bot[i].second - ay) * (bot[i].second - ay)));       toA[i].first -= toT[i];       toA[i].second = i;       toB[i].first = sqrt((double)((bot[i].first - bx) * (bot[i].first - bx) +                                    (bot[i].second - by) * (bot[i].second - by)));       toB[i].first -= toT[i];       toB[i].second = i;     }     sort((toA).begin(), (toA).end());     sort((toB).begin(), (toB).end());     double ans = 1e18;     for (int i = 0; i < n; i++) {       int j = toA[i].second;       int k = toB[0].second;       double tmp = sum + toA[i].first;       ans = min(ans, tmp);       tmp = sum + toB[i].first;       ans = min(ans, tmp);       if (j != k)         tmp = sum + toA[i].first + toB[0].first;       else         tmp = sum + toA[i].first + toB[1].first;       j = toB[i].second;       ans = min(ans, tmp);       k = toA[0].second;       if (j != k)         tmp = sum + toA[0].first + toB[i].first;       else         tmp = sum + toA[1].first + toB[i].first;       ans = min(ans, tmp);     }     printf( %.10f , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   const long long M = 1e4;   const long long mod = 1e9 + 7;   const long long inf = 1e9;   long long read() {     long long s = 0;     register bool neg = 0;     register char c = getchar();     for (; c <  0  || c >  9 ; c = getchar()) neg |= (c ==  - );     for (; c >=  0  && c <=  9 ; s = s * 10 + (c ^ 48), c = getchar())       ;     s = (neg ? -s : s);     return s;   }   long long a, s[N + 5], r[N + 5];   long double val[N + 5];   vector<long long> p[63], q[63];   bool cmp(long long p1, long long p2) { return val[p1] < val[p2]; }   signed main() {     a = read();     for (long long i = (1); i <= (a); ++i) {       s[i] = read();       long long j = 0, x = s[i];       for (; x; ++j)         if (x & (1ll << j)) {           if ((x ^ (1ll << j))) q[j].push_back(i);           x ^= (1ll << j);         }       --j;       p[j].push_back(i);     }     long long L = 0;     for (long long i = (61); i >= (0); --i) {       if (!((long long)((p[i]).size()))) continue;       if (((long long)((p[i]).size())) > ((long long)((q[i]).size())) + 1) {         puts( No );         return 0;       }       sort(q[i].begin(), q[i].end(), cmp);       r[p[i][0]] = L;       val[p[i][0]] = val[L] - 1e18;       L = p[i][0];       for (long long j = (1); j <= (((long long)((p[i]).size())) - 1); ++j) {         long long k = p[i][j], t = q[i][j - 1];         val[k] = (val[t] + val[r[t]]) / 2;         r[k] = r[t];         r[t] = k;       }     }     puts( Yes );     for (long long i = L; i; i = r[i]) printf( %lld  , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   const int MAX = 1e6 + 1;   int n, f[MAX], dep[MAX];   int u[MAX], pr[MAX];   int stk[2][N], q[N << 1];   bool mk[MAX], cmp[N];   vector<int> a, adj[MAX], dv[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       a.push_back(0);       cin >> a[i];     }     fill(f, f + MAX, 0);     fill(u, u + MAX, -1);     fill(cmp, cmp + N, 1);     for (int i = 0; i < n; i++) {       int p1 = -1, p2 = -1;       int x = a[i], y, z = 1;       if (x == 1) {         f[1]++;         dv[1].push_back(1);         continue;       }       for (int j = 2; j < a[i]; j++) {         if (j * j > a[i]) break;         if (x % j == 0) {           y = 0;           if (p1 == -1)             p1 = j;           else             p2 = j;           while (x % j == 0) {             x /= j;             y ^= 1;           }           if (y)             z *= j;           else {             if (p2 == j)               p2 = -1;             else               p1 = -1;           }         }       }       if (x != 1) {         if (p1 == -1)           p1 = x;         else           p2 = x;         z *= x;       }       a[i] = z;       u[z] = i;       stk[0][i] = max(p1, 0);       stk[1][i] = max(p2, 0);       for (int j = 0; j < 2; j++) cmp[i] &= (stk[j][i] != 0);       if (cmp[i])         for (int j = 0; j < 2; j++) dv[stk[j][i]].push_back(stk[j ^ 1][i]);       else {         dv[1].push_back(z);         dv[z].push_back(1);       }       f[z]++;     }     if (f[1]) {       cout << 1 <<   n ;       return 0;     }     int mx = -1;     for (int x = 0; x < MAX; x++) mx = max(mx, f[x]);     if (mx > 1) {       cout << 2 <<   n ;       return 0;     }     fill(mk, mk + MAX, 0);     for (int x = 0; x < MAX; x++) {       for (auto& y : dv[x])         if (!mk[y]) {           mk[y] = 1;           adj[x].push_back(y);         }       for (auto& y : dv[x]) mk[y] = 0;     }     fill(pr, pr + MAX, 0);     for (int x = 0; x < MAX; x++)       for (auto& y : adj[x]) pr[y]++;     int l, r, mn = MAX;     mx = -1;     for (int x = 0; x < MAX; x++)       if (pr[x]) mx = max(mx, x);     mx = sqrt(mx) + 1;     fill(q, q + (N << 1), 0);     for (int x = 0; x < MAX; x++)       if (pr[x]) {         if (x > mx) continue;         fill(mk, mk + MAX, 0);         fill(dep, dep + MAX, 0);         l = 0;         r = 0;         dep[x] = 0;         mk[x] = 1;         q[r++] = x;         q[r++] = x;         while (l != r) {           int y = q[l++];           int z = q[l++];           for (auto& w : adj[y]) {             if (w == z) continue;             if (mk[w]) {               mn = min(mn, dep[w] + 1 + dep[y]);               continue;             }             dep[w] = 1 + dep[y];             mk[w] = 1;             q[r++] = w;             q[r++] = y;           }         }       }     if (mn == MAX) mn = -1;     cout << mn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   set<string> name;   map<string, int> id;   string pos[N];   string s, st, o;   int n, a[N], cnt;   void add(string x) {     if (name.find(x) != name.end()) return;     name.insert(x);     cnt++;     id[x] = cnt;     pos[cnt] = x;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> st;     add(st);     cin >> n;     getline(cin, st);     for (int i = 1; i <= n; ++i) {       getline(cin, st);       stringstream ss(st);       string tmp;       vector<string> v;       while (ss >> tmp) {         v.emplace_back(tmp);       }       add(v[0]);       if (v[1] ==  posted ) {         v[3].pop_back();         v[3].pop_back();         add(v[3]);         int u = id[v[0]], vv = id[v[3]];         if (u == 1 || vv == 1) {           a[u] += 15, a[vv] += 15;         }       }       if (v[1] ==  commented ) {         v[3].pop_back();         v[3].pop_back();         add(v[3]);         int u = id[v[0]], vv = id[v[3]];         if (u == 1 || vv == 1) {           a[u] += 10, a[vv] += 10;         }       }       if (v[1] ==  likes ) {         v[2].pop_back();         v[2].pop_back();         add(v[2]);         int u = id[v[0]], vv = id[v[2]];         if (u == 1 || vv == 1) {           a[u] += 5, a[vv] += 5;         }       }     }     sort(pos + 2, pos + cnt + 1, [](string x, string y) {       return a[id[x]] != a[id[y]] ? a[id[x]] > a[id[y]] : x < y;     });     for (int i = 2; i <= cnt; ++i) cout << pos[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3002;   int dfn[N], low[N], c;   bool ipt[N];   pair<int, int> edge[N];   vector<pair<int, int> > p[N];   void tarjan(int x, int pre) {     dfn[x] = low[x] = ++c;     for (__typeof(p[x].begin()) it = p[x].begin(); it != p[x].end(); ++it) {       if (pre == (*it).second) continue;       int y = (*it).first;       if (dfn[y]) {         low[x] = min(low[x], dfn[y]);       } else {         tarjan(y, (*it).second);         low[x] = min(low[x], low[y]);         if (dfn[x] < low[y]) ipt[(*it).second] = 1;       }     }   }   int n, m, k, f[N];   void init() {     for (int i = 1; i <= n; ++i) f[i] = i;   }   int finds(int x) { return x == f[x] ? x : f[x] = finds(f[x]); }   void unions(int x, int y) {     x = finds(x);     y = finds(y);     f[x] = y;   }   bool vis[N];   int dfs(int x, int y, int deep) {     if (x == y) return deep;     vis[x] = true;     for (__typeof(p[x].begin()) e = p[x].begin(); e != p[x].end(); ++e)       if (!vis[e->first]) {         int g = dfs(e->first, y, deep + 1);         if (g != -1) return g;       }     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int x, y;     for (int i = 0; i < m; ++i) {       cin >> edge[i].first >> edge[i].second;       x = edge[i].first;       y = edge[i].second;       p[x].push_back(make_pair(y, i));       p[y].push_back(make_pair(x, i));     }     init();     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, -1);     for (int i = 0; i < m; ++i)       if (!ipt[i]) {         unions(edge[i].first, edge[i].second);       }     for (int i = 0; i <= n; ++i) p[i].clear();     for (int i = 0; i < m; ++i)       if (ipt[i]) {         p[finds(f[edge[i].first])].push_back(             make_pair(finds(f[edge[i].second]), -1));         p[finds(f[edge[i].second])].push_back(             make_pair(finds(f[edge[i].first]), -1));       }     cin >> m;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       for (int i = 0; i <= n; ++i) vis[i] = false;       cout << dfs(finds(f[x]), finds(f[y]), 0) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dir;   int n, m, k;   int go(int pos) {     if (pos == 1) {       dir = 1;       return pos + 1;     }     if (pos == n) {       dir = 0;       return pos - 1;     }     if (dir) return pos + 1;     return pos - 1;   }   int main() {     cin >> n >> m >> k;     string napr, isstop;     cin >> napr >> napr;     cin >> isstop;     if (napr ==  head )       dir = 0;     else       dir = 1;     for (int i = 0; i < isstop.size(); i++) {       if (isstop[i] ==  1 ) {         k = go(k);         if (dir == 0) {           if (k == n)             m = 1;           else             m = n;         } else {           if (k == 1)             m = n;           else             m = 1;         }       } else {         if (dir == 0) {           if (m < k) {             m--;             m = max(1, m);           } else {             m++;             m = min(m, n);           }         } else {           if (m > k) {             m++;             m = min(m, n);           } else {             m--;             m = max(1, m);           }         }         k = go(k);       }       if (m == k) {         cout <<  Controller   << i + 1;         return 0;       }     }     cout <<  Stowaway ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool palindrome(string s) {     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] != s[n - i - 1]) return 0;     }     return 1;   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     sort(s.begin(), s.end());     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       int x, y, n, cnt = 0, chk = 0, tmp, pos = -1, pos2 = -1, res;       map<pair<int, int>, int> mp, Tmp, Imp;       map<int, string> mp2;       string s =   , s2 =   , s3 =   ;       scanf( %d , &n);       cin >> s;       x = 0, y = 0;       Tmp[{x, y}]++;       mp[{x, y}]++;       for (int j = 0; j < s.size(); j++) {         s2 =   , s3 =   ;         if (s[j] ==  U ) {           y++;         } else if (s[j] ==  D ) {           y--;         } else if (s[j] ==  R ) {           x++;         } else if (s[j] ==  L ) {           x--;         }         if (j == 0) {           int tx = x, ty = y;         }         tmp = mp[{x, y}];         mp[{x, y}]++;         if (j == 0) {           Imp[{x, y}] = j;         }         if (mp[{x, y}] != tmp && tmp != 0) {           int dist;           if (x == 0 && y == 0 && pos == -1 && pos2 == -1) {             dist = abs((j + 1) - (Imp[{x, y}] + 1));           } else {             dist = abs((j + 1) - (Imp[{x, y}] + 2));           }           chk++;           if (chk == 1 || dist < res) {             res = dist;             if (x == 0 && y == 0 && pos == -1 && pos2 == -1) {               pos2 = Imp[{x, y}] + 1;               pos = j + 1;             } else {               pos2 = Imp[{x, y}] + 2;               pos = j + 1;             }           }         }         if (j != 0) {           Imp[{x, y}] = j;         }       }       if (chk == 0) {         printf( -1 n );       } else {         printf( %d %d n , min(pos, pos2), max(pos, pos2));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long arr[200005];   pair<long long, long long> pt[200005];   int main() {     long long n, x, y, newX, newY, cnt = 0, ansX, ansY, val = 0;     map<pair<long long, long long>, long long> mp1;     cin >> n >> x >> y;     for (int i = 0; i < n; i++) {       cin >> pt[i].first >> pt[i].second;     }     newX = x + 1, newY = y;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x - 1, newY = y;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x, newY = y + 1;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x, newY = y - 1;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     for (auto it = mp1.begin(); it != mp1.end(); it++) {       if (it->second > val) {         val = it->second;         ansX = it->first.first;         ansY = it->first.second;       }     }     cout << val << endl;     cout << ansX <<     << ansY << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<string> rs;     if (n == 1) {       rs.push_back( a );       rs.push_back( a );       rs.push_back( b );       rs.push_back( b );     } else if (n == 2) {       rs.push_back( aa );       rs.push_back( bb );       rs.push_back( aa );       rs.push_back( bb );     } else if (n == 3) {       rs.push_back( aac );       rs.push_back( bbc );       rs.push_back( add );       rs.push_back( abb );     } else if (n == 4) {       rs.push_back( aabb );       rs.push_back( cddc );       rs.push_back( ceec );       rs.push_back( aabb );     } else if (n % 2 == 0) {       int b = 0;       int c = 5;       int d = 10;       string pal1 =   ;       string pal2 =  z ;       string pal3 =  z ;       for (int i = 0; i < n / 2; i++) {         b = (b + 1) % 24;         c = (c + 1) % 24;         d = (d + 1) % 24;         pal1 += string(2, char( a  + b));         if (i == n / 2 - 1) continue;         pal2 += string(2, char( a  + c));         pal3 += string(2, char( a  + d));       }       pal2 +=  z ;       pal3 +=  z ;       rs.push_back(pal1);       rs.push_back(pal2);       rs.push_back(pal3);       rs.push_back(pal1);     } else if (n % 2 != 0) {       int b = 0;       int c = 5;       int d = 10;       string pal1 =   ;       string pal2 =   ;       string pal3 =  z ;       for (int i = 0; i < n / 2; i++) {         b = (b + 1) % 24;         c = (c + 1) % 24;         d = (d + 1) % 24;         pal1 += string(2, char( a  + b));         pal2 += string(2, char( a  + c));         pal3 += string(2, char( a  + d));       }       string pal4 =  z  + pal1;       pal1 +=  z ;       pal2 +=  z ;       rs.push_back(pal1);       rs.push_back(pal2);       rs.push_back(pal3);       rs.push_back(pal4);     }     for (int i = int(0); i < int(4); i++) {       cout << rs[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-6;   int H[1005];   int main() {     int n, m, h;     int l, r, x;     int i, j;     scanf( %d%d%d , &n, &h, &m);     for (i = 1; i <= n; i++) H[i] = h;     for (i = 0; i < m; i++) {       scanf( %d%d%d , &l, &r, &x);       for (j = l; j <= r; j++) H[j] = min(H[j], x);     }     int ans = 0;     for (i = 1; i <= n; i++) ans += H[i] * H[i];     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[500006];   long long dp[500006];   long long vis[500006];   vector<long long> v[500006];   long long on;   long long n, d, che;   void dfs(long long root, long long parent) {     vis[root] = 1;     dp[root] = 1;     for (auto it : v[root]) {       if (!vis[it]) {         dfs(it, root);         if (a[it] == che && it < on) {           continue;         }         if (it != parent && che <= a[it] && a[it] <= che + d) {           (dp[root] *= (1 + dp[it])) %= 1000000007;         }       }     }   }   void solve() {     cin >> d >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 0; i < n - 1; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       on = i;       for (long long j = 1; j <= n; j++) vis[j] = dp[j] = 0;       che = a[i];       dfs(i, -1);       (ans += dp[i]) %= 1000000007;     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }