#include <bits/stdc++.h>   using namespace std;   const long double E = 2.71828182845904523536;   const long double pi = acos(-1);   const double eps = 1e-9;   const long long mod = 1e9 + 7;   const long long inf = 1LL << 30;   long long a[400], b[400], n, x;   map<long long, long long> mem[301];   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long dp(int i, long long g) {     if (g == 1) return 0;     if (i >= n) return inf;     if (g == 0) return min(dp(i + 1, a[i]) + b[i], dp(i + 1, 0));     long long &ret = mem[i][g];     if (ret != 0) return ret;     long long gc = gcd(a[i], g);     return ret = min(dp(i + 1, gc) + b[i], dp(i + 1, g));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     long long ans = dp(0, 0);     if (ans == inf)       cout << -1 <<   n ;     else       cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100100];   char b[100100];   int na, nb;   int main() {     cin >> a >> b;     na = 0;     nb = 0;     for (int i = 0; a[i]; i++)       if (a[i] ==  1 ) na++;     for (int i = 0; b[i]; i++)       if (b[i] ==  1 ) nb++;     if (na % 2) na++;     if (na >= nb) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, m, k;     cin >> t;     for (int i = 1; i <= t; i++) {       cin >> n >> m >> k;       if (m < n - 1 || m > n * (n - 1) / 2) {         puts( No );         continue;       }       if (n == 1) {         if (k > 1)           puts( Yes );         else           puts( No );         continue;       }       if (m == n * (n - 1) / 2) {         if (k > 2)           puts( Yes );         else           puts( No );         continue;       }       if (k > 3)         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   uint32_t readu32() {     int c;     while ((c = getchar()) <  0 )       ;     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   uint64_t readu64() {     int c;     while ((c = getchar()) <  0 )       ;     uint64_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   int32_t read32() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int32_t)n : n;   }   int64_t read64() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint64_t n = c & 15;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int64_t)n : n;   }   using namespace std;   bool v[100005];   int p[100005];   int main() {     ios_base::sync_with_stdio(0);     int n = readu32();     for (int i = 1; i <= n; i++) p[i] = readu32();     int hub = 0, two = 0;     bool hasodd = 0;     for (int i = 1; i <= n; i++) {       if (v[i]) continue;       if (p[i] == i)         hub = i;       else if (p[p[i]] == i)         two = i;       else {         int j = i;         int cl = 0;         for (;;) {           v[j] = 1;           j = p[j];           cl++;           if (j == i) break;         }         if (cl & 1) hasodd = true;       }     }     if (!hub && (hasodd || !two)) {       cout <<  NO ;       return 0;     }     printf( YES n );     if (hub) {       for (int i = 1; i <= n; i++)         if (i != hub) printf( %d %d n , i, hub);     } else {       memset(v, 0, sizeof(v));       int par[] = {two, p[two]};       v[par[0]] = v[par[1]] = 1;       printf( %d %d n , par[0], par[1]);       for (int i = 1; i <= n; i++) {         if (v[i]) continue;         int j = i, pa = 0;         for (;; pa ^= 1) {           v[j] = 1;           printf( %d %d n , j, par[pa]);           j = p[j];           if (j == i) break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, dp[300][300];   long long s;   vector<pair<long long, long long> > v;   long long r, tr;   long long gs(long long a, long long b, long long c) {     long long s = 0;     s = (v[b].first - v[a].first) * (v[c].second - v[a].second) -         (v[b].second - v[a].second) * (v[c].first - v[a].first);     return s;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       v.push_back(make_pair(a, b));     }     for (int i = 0; i < n; i++)       s +=           v[(i + 1) % n].first * v[i].second - v[(i + 1) % n].second * v[i].first;     if (s < 0) reverse(v.begin(), v.end());     for (int i = 0; i < n; i++) dp[i][(i + 1) % n] = 1;     for (int span = 2; span < n; span++) {       for (int l = 0; l < n; l++) {         r = l + span;         r %= n;         for (int q = l + 1; q < l + span; q++) {           tr = q % n;           if (gs(l, r, tr) > 0)             dp[l][r] = (dp[l][r] + dp[l][tr] * dp[tr][r]) % 1000000007;         }       }     }     cout << dp[0][n - 1] << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % 998244353;       y = y / 2;       if (y != 0) x = (x * x) % 998244353;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, n, i, j, o, e, ans = 0, num, ans1, ans2, sz, x = 0, chk;     cin >> n;     long long a;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     queue<vector<long long> > q;     q.push(v);     long long bit = 30;     while (bit >= 0) {       sz = q.size();       chk = 1ll << bit;       ans1 = ans2 = 0;       for (i = 0; i < sz; i++) {         v = q.front();         q.pop();         vector<long long> one, zero;         o = e = 0;         for (j = 0; j < v.size(); j++) {           num = v[j];           if (num & chk) {             one.push_back(v[j]);             o++;             ans2 += e;           } else {             zero.push_back(v[j]);             e++;             ans1 += o;           }         }         if (!one.empty()) q.push(one);         if (!zero.empty()) q.push(zero);       }       ans += min(ans1, ans2);       if (ans1 > ans2) x += chk;       bit--;     }     cout << ans <<     << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100 * 1000 + 10, Max = 17;   int n, m, k, moal[Maxn], st[Maxn], par[Maxn], stt = 1, lca[Max][Maxn], h[Maxn],                                                 cnt;   vector<int> adj[Maxn], ind[Maxn], adj2[Maxn];   struct edge {     int u, v;   } e[Maxn];   bool markE[Maxn], mark[Maxn];   void dfs3(int v) {     mark[v] = false;     for (int i = 0; i < (int)adj2[v].size(); i++)       if (mark[adj2[v][i]]) {         lca[0][adj2[v][i]] = v;         h[adj2[v][i]] = h[v] + 1;         dfs3(adj2[v][i]);       }     return;   }   int dfs(int v) {     st[v] = stt;     stt++;     int ans = INT_MAX, indd;     for (int i = 0; i < (int)adj[v].size(); i++) {       if (st[adj[v][i]] == 0) {         par[adj[v][i]] = v;         ans = min(ans, dfs(adj[v][i]));       } else {         if (adj[v][i] != par[v])           ans = min(ans, st[adj[v][i]]);         else           indd = i;       }     }     if (v != 0 && ans >= st[v]) markE[ind[v][indd]] = true;     return ans;   }   void dfs2(int v, int a) {     mark[v] = true;     moal[v] = a;     for (int i = 0; i < (int)adj[v].size(); i++) {       if (!markE[ind[v][i]] && !mark[adj[v][i]]) dfs2(adj[v][i], a);     }     return;   }   void dfsAll() {     for (int i = 0; i < n; i++)       if (!mark[i]) {         dfs2(i, cnt);         cnt++;       }     return;   }   void fillLca() {     for (int i = 1; i < Max; i++) {       for (int j = 0; j < cnt; j++) {         if (lca[i - 1][j] != -1) lca[i][j] = lca[i - 1][lca[i - 1][j]];       }     }     return;   }   int fath(int a, int b) {     for (int i = Max - 1; i >= 0; i--) {       if ((b >> i) & 1) a = lca[i][a];     }     return a;   }   int LCA(int u, int v) {     if (h[u] > h[v]) swap(u, v);     v = fath(v, h[v] - h[u]);     if (v == u) return u;     for (int i = Max - 1; i >= 0; i--) {       if (lca[i][u] != lca[i][v]) {         u = lca[i][u];         v = lca[i][v];       }     }     return lca[0][u];   }   int main() {     scanf( %d%d , &n, &m);     int u, v;     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adj[u].push_back(v);       ind[u].push_back(i);       adj[v].push_back(u);       ind[v].push_back(i);       e[i].u = u, e[i].v = v;     }     int a = dfs(0);     dfsAll();     for (int i = 0; i < m; i++)       if (markE[i]) {         adj2[moal[e[i].u]].push_back(moal[e[i].v]);         adj2[moal[e[i].v]].push_back(moal[e[i].u]);       }     for (int i = 0; i < Max; i++)       for (int j = 0; j < n; j++) lca[i][j] = -1;     dfs3(0);     fillLca();     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       int a = LCA(moal[u], moal[v]);       printf( %d n , h[moal[u]] + h[moal[v]] - 2 * h[a]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l, k, a[200], p[200];   double memo[200][201][201];   bool seen[200][201][201];   double solve(int idx, int kk, int ll) {     if (kk < 0) {       return 0;     }     if (idx == n) {       return ll >= l;     }     if (seen[idx][kk][ll]) {       return memo[idx][kk][ll];     }     double prob = p[idx];     prob /= 100;     double ans = solve(idx + 1, kk, ll) * (1 - prob);     if (a[idx] > 0) {       ans += solve(idx + 1, min(a[idx] + kk, 200), ll + 1) * prob;     }     if (a[idx] == -1 && kk) {       ans += solve(idx + 1, kk - 1, ll + 1) * prob;     }     seen[idx][kk][ll] = 1;     return memo[idx][kk][ll] = ans;   }   int main() {     scanf( %d%d%d , &n, &l, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (a[i] < a[j]) {           swap(a[i], a[j]);           swap(p[i], p[j]);         }       }     }     printf( %.6lf n , solve(0, k, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     bool ok = true;     set<char> vowel;     vowel.insert( a );     vowel.insert( e );     vowel.insert( i );     vowel.insert( o );     vowel.insert( u );     for (int i = 0; i < s.size(); i++) {       char c = s[i];       if (!vowel.count(c) && c !=  n ) {         if (i == s.size() - 1 || !vowel.count(s[i + 1])) {           ok = false;         }       }     }     if (ok)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v, v1;     char a[8][8];     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) cin >> a[i][j];     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (a[i][j] ==  B ) {           int b = 0;           bool t = true;           for (int k = i + 1; k < 8; k++) {             b++;             if (a[k][j] ==  B  || a[k][j] ==  W ) {               t = false;               break;             }           }           if (t == true) v.push_back(b);         }         if (a[i][j] ==  W ) {           int z = 0;           bool t = true;           for (int k = i - 1; k >= 0; k--) {             z++;             if (a[k][j] ==  B  || a[k][j] ==  W ) {               t = false;               break;             }           }           if (t == true) {             v1.push_back(z);           }         }       }     int m = 999, m1 = 999;     for (int i = 0; i < v.size(); i++) {       m = min(m, v[i]);     }     for (int i = 0; i < v1.size(); i++) {       m1 = min(m1, v1[i]);     }     if (m >= m1)       cout <<  A ;     else       cout <<  B ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int v[250];   void calc() {     double media = 0;     for (int i = 0; i < 250; i++) media += v[i];     media /= 250.0;     double dp = 0;     for (int i = 0; i < 250; i++) dp += (v[i] - media) * (v[i] - media);     dp /= 250.0;     if (media * 2 > dp) {       printf( %d n , (int)media);     } else {       int x = 0;       for (int i = 0; i < 250; i++) x = max(x, v[i]);       printf( %d n , x / 2);     }   }   int main() {     int n;     scanf( %d , &n);     while (n--) {       for (int i = 0; i < 250; i++) scanf( %d , &v[i]);       calc();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct greater {     template <class T>     bool operator()(T const &a, T const &b) const {       return a > b;     }   };   unsigned long long subV(unsigned long long a, unsigned long long b,                           unsigned long long c, unsigned long long l) {     if (a < b + c) {       return 0;     }     unsigned long long sum = (l + 2) * (l + 1) / 2;     unsigned long long df = a - b - c;     if (df >= 0) {       unsigned long long sub = (df + 2) * (df + 1) / 2;       return min(sub, sum);     }     return 0;   }   int main() {     int a, b, c, l;     scanf( %d %d %d %d , &a, &b, &c, &l);     unsigned long long total = 0;     for (unsigned long long i = 0; i <= l; i++) {       total += (i + 2) * (i + 1) / 2;     }     for (unsigned long long i = 0; i <= l; i++) {       total -= subV(a + i, b, c, l - i);       total -= subV(b + i, a, c, l - i);       total -= subV(c + i, a, b, l - i);     }     printf( %I64d , total);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 998244353;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const double pi = acosl(-1.), eps = 1e-9;   inline void sum(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   const int NN = 1000100;   char A[NN], L[NN], R[NN];   int n, ln, rn, B[NN];   void zval(const char *s, int len, int *z) {     z[0] = 0;     for (int b = 0, i = 1; i < len; i++) {       z[i] = max(min(z[i - b], z[b] + b - i), 0);       while (s[i + z[i]] == s[z[i]]) z[i]++;       if (i + z[i] > b + z[b]) b = i;     }     z[0] = len;   }   char zl[NN << 1], zr[NN << 1];   int zL[NN << 1], zR[NN << 1];   int main() {     scanf( %s %s %s , A + 1, L, R);     n = strlen(A + 1);     ln = strlen(L);     rn = strlen(R);     for (int i = 0; i < ln; i++) zl[i] = L[i];     zl[ln] =  * ;     for (int i = ln + 1; i <= ln + n; i++) zl[i] = A[i - ln];     zval(zl, ln + n + 1, zL);     for (int i = 0; i < rn; i++) zr[i] = R[i];     zr[rn] =  * ;     for (int i = rn + 1; i <= rn + n; i++) zr[i] = A[i - rn];     zval(zr, rn + n + 1, zR);     B[n + 1] = 1;     for (int i = n, st, ed; i; i--) {       B[i] = B[i + 1];       if (A[i] ==  0 ) {         if (ln == 1 && L[0] ==  0 ) {           st = ed = i + 1;         } else           continue;       } else {         st = i + ln;         if (st > n + 1) continue;         int p = zL[ln + i];         if (p < ln) {           if (A[i + p] < L[p]) st++;         }         if (st > n + 1) continue;         ed = i + rn;         if (ed <= n + 1) {           p = zR[rn + i];           if (p < rn) {             if (A[i + p] > R[p]) ed--;           }         } else           ed = n + 1;         if (ed < st) continue;       }       int d = B[st] - B[ed + 1];       if (d < 0) d += mod;       sum(B[i], d);       if (i == 1) {         cout << d << endl;         return 0;       }     }     puts( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-8;   const long double PI = 3.1415926535897932384626433832795;   const long double E = 2.7182818284;   const int INF = 1000000000;   const int inf = 100000;   int main(void) {     int n, m, i, j;     char c;     scanf( %d%d , &n, &m);     char a[n + 2][m + 2];     c = getchar();     for (int i = 0; i < int(n); i++) {       for (int j = 0; j < int(m); j++) {         scanf( %c , &a[i][j]);       }       c = getchar();     }     int tab[n + 2][m + 2];     for (int i = 0; i < int(n); i++) {       int t = inf;       for (int j = 0; j < int(2 * m); j++) {         if (a[i][j % m] ==  1 ) {           tab[i][j % m] = 0;           t = 1;         } else {           tab[i][j % m] = t;           if (t != inf) t++;         }       }     }     for (int i = 0; i < int(n); i++) {       int t = inf;       for (j = 2 * m - 1; j >= 0; j--) {         if (a[i][j % m] ==  1 ) {           tab[i][j % m] = 0;           t = 1;         } else {           tab[i][j % m] = min(tab[i][j % m], t);           if (t != inf) t++;         }       }     }     int res = -1;     for (int i = 0; i < int(m); i++) {       int sum = 0;       for (int j = 0; j < int(n); j++) {         if (tab[j][i] == inf) {           printf( -1 n );           return 0;         }         sum += tab[j][i];       }       if (sum < res || res == -1) res = sum;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200000 + 5;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long n, ma, sum, gc, a[N];   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       ma = max(ma, a[i]);     }     for (long long i = 1; i <= n; i++) a[i] = ma - a[i];     gc = sum = a[1];     for (long long i = 2; i <= n; i++) {       gc = gcd(gc, a[i]);       sum += a[i];     }     printf( %lld %lld n , sum / gc, gc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, vector<pair<long long int, long long int> > > mapp;   bool cmp(pair<long long int, long long int> &p1,            pair<long long int, long long int> &p2) {     if (p1.second != p2.second) return p1.second < p2.second;     return p1.first < p2.first;   }   int main() {     long long int n, i, j, k;     cin >> n;     vector<long long int> a(n);     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       long long int s = 0;       for (j = i; j < n; j++) s += a[j], mapp[s].push_back({i, j});     }     long long int ans = 0, f = 0;     for (auto j : mapp) {       sort(mapp[j.first].begin(), mapp[j.first].end(), cmp);       long long int bound = -1, cnt = 0;       for (auto k : mapp[j.first]) {         if (k.first > bound) cnt++, bound = k.second;       }       if (ans < cnt) ans = cnt, f = j.first;     }     cout << ans <<   n ;     long long int bound = -1, cnt = 0;     for (auto j : mapp[f]) {       if (j.first > bound)         cout << j.first + 1 <<     << j.second + 1 <<   n , bound = j.second;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, h, k, i, j, a[100100], pkp = 0, tmp, p, ans = 0;     double d;     scanf( %lld %lld %lld , &n, &h, &k);     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     for (i = 0; i < n; i++) {       if (pkp + a[i] <= h) {         pkp += a[i];       } else {         tmp = h - a[i];         p = pkp - tmp;         d = ceil((double)p / (double)k);         ans += (long long)d;         pkp -= d * k;         if (pkp < 0) pkp = 0;         pkp += a[i];       }     }     d = ceil((double)pkp / (double)k);     ans += (long long)d;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k, num, count = 0, i, j;     cin >> n >> k;     bitset<32> b[6];     for (i = 1; i < 3; i++) {       for (j = i + 1; j <= 3; j++) {         cout <<  or   << i <<     << j <<   n  << flush;         cin >> num;         b[count] = num;         count++;         cout <<  and   << i <<     << j <<   n  << flush;         cin >> num;         b[count] = num;         count++;       }     }     bitset<32> b1, b2;     for (i = 0; i < 32; i++) {       if (b[0][i] == b[1][i]) {         b1[i] = b[0][i];         b2[i] = b[0][i];       } else {         if (b[2][i] != b[4][i]) {           b1[i] = b[2][i];           b2[i] = b[4][i];         } else {           b1[i] = b[3][i];           b2[i] = b[5][i];         }       }     }     bitset<32> r, ans;     r = b1;     vector<int> vec;     vec.push_back(b1.to_ulong());     vec.push_back(b2.to_ulong());     b1 = b[2];     b2 = b[3];     for (i = 3; i <= n; i++) {       if (i > 3) {         cout <<  or   << 1 <<     << i <<   n  << flush;         cin >> num;         b1 = num;         cout <<  and   << 1 <<     << i <<   n  << flush;         cin >> num;         b2 = num;       }       for (j = 0; j < 32; j++) {         if (r[j] == 0 && b1[j] == 0)           ans[j] = 0;         else if (r[j] == 0 && b1[j] == 1)           ans[j] = 1;       }       for (j = 0; j < 32; j++) {         if (r[j] == 1 && b2[j] == 0)           ans[j] = 0;         else if (r[j] == 1 && b2[j] == 1)           ans[j] = 1;       }       vec.push_back(ans.to_ulong());     }     sort(vec.begin(), vec.end());     cout <<  finish   << vec[k - 1] <<   n  << flush;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxk = 999 + 5;   int a[maxk];   vector<int> vec;   int main() {     int n, k, p, x, y;     scanf( %d%d%d%d%d , &n, &k, &p, &x, &y);     for (int i = 0; i < k; i++) scanf( %d , a + i);     if (y > p) {       printf( -1 n );       return 0;     }     sort(a, a + k);     for (int one = 0, now = 0; one <= n - k; one++) {       now = 0;       vec.clear();       for (int i = 0; i < one; i++) {         now++;         vec.push_back(1);       }       for (int i = 0; i < k; i++) {         now += a[i];         vec.push_back(a[i]);       }       for (; vec.size() < n;) {         vec.push_back(y);         now += y;       }       if (now > x) continue;       sort(vec.begin(), vec.end());       if (vec[(n + 1) / 2 - 1] >= y) {         vector<int> ans;         for (int i = 0; i < one; i++) ans.push_back(1);         for (int i = 0; i < n - (one + k); i++) ans.push_back(y);         for (int i = 0; i < ans.size(); i++)           printf( %d%c , ans[i], i == ans.size() - 1 ?   n  :    );         return 0;       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     point() : x(0), y(0){};     point(long long x, long long y) : x(x), y(y){};     long long x;     long long y;   };   point operator+(point a, point b) { return point(a.x + b.x, a.y + b.y); }   point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); }   long long dotProduct(point a, point b) { return a.x * b.x + a.y * b.y; }   long long crossProduct(point a, point b) { return a.x * b.y - a.y * b.x; }   int f(point a, point b) {     if ((double)a.x / a.y > (double)b.x / b.y) return 1;     return -1;   }   int main() {     int n;     cin >> n;     vector<long long> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     vector<long long> dp(n);     dp[0] = 0;     vector<point> hull(n);     hull[0] = point(b[0], dp[0]);     int k = 1;     for (int i = 1; i < n; i++) {       int l = 0, r = k;       point q(a[i], 1);       while (r - l > 2) {         int m1 = (r + 2 * l) / 3;         int m2 = (2 * r + l) / 3;         long long u = dotProduct(q, hull[m1]);         long long v = dotProduct(q, hull[m2]);         if (u < v)           r = m2;         else           l = m1;       }       if (l + 1 < r && dotProduct(q, hull[l]) > dotProduct(q, hull[l + 1])) l++;       dp[i] = a[i] * hull[l].x + hull[l].y;       point p(b[i], dp[i]);       while (k > 1 && f(hull[k - 1] - hull[k - 2], p - hull[k - 1]) > 0) k--;       hull[k++] = p;     }     cout << dp[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 5;   const int mod = (int)1e9 + 7;   const int logN = 17;   const int inf = 1e9;   const int N = 2e5 + 5;   int main() {     int n, t;     vector<pair<int, int> > ans;     scanf( %d , &n);     queue<int> q;     for (int i = 1; i <= n; i++) {       scanf( %d , &t);       while (q.size() > t) {         ans.push_back(make_pair(q.front(), i - 1));         q.pop();       }       while (q.size() < t) q.push(i);     }     while (q.size()) {       ans.push_back(make_pair(q.front(), n));       q.pop();     }     cout << ans.size() <<   n ;     for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++)       cout << it->first <<     << it->second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   int n, q, a[maxn], bit[maxn][22] = {0}, pos[maxn][22] = {0};   int main() {     int i, j, l, r;     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       l = i, r = a[i];       for (j = 20; j >= 0; j--)         bit[i][j] = bit[i - 1][j], pos[i][j] = pos[i - 1][j];       for (j = 20; j >= 0; j--)         if (r & (1 << j)) {           if (bit[i][j] == 0) {             bit[i][j] = r, pos[i][j] = l;             break;           }           if (l > pos[i][j]) {             swap(l, pos[i][j]);             swap(r, bit[i][j]);           }           r ^= bit[i][j];         }     }     cin >> q;     while (q--) {       cin >> l >> r;       int num = 0;       for (i = 20; i >= 0; i--)         if ((num ^ bit[r][i]) > num && pos[r][i] >= l) num ^= bit[r][i];       cout << num << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class T>   inline void RST(T &A) {     memset(A, 0, sizeof(A));   }   template <class T>   inline void FLC(T &A, int x) {     memset(A, x, sizeof(A));   }   template <class T>   inline void CLR(T &A) {     A.clear();   }   const int dx4[] = {-1, 0, 1, 0};   const int dy4[] = {0, 1, 0, -1};   const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};   const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};   const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};   const int mod = 1000000007;   const int inf = 0x3f3f3f3f;   const long long inff = 1LL << 60;   const double eps = 1e-9;   const double oo = 1e25;   const double pi = acos(-1.0);   template <class T>   inline void checkMin(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T &a, const T b) {     if (a < b) a = b;   }   template <class T>   inline void checkMin(T &a, T &b, const T x) {     checkMin(a, x), checkMin(b, x);   }   template <class T>   inline void checkMax(T &a, T &b, const T x) {     checkMax(a, x), checkMax(b, x);   }   template <class T, class C>   inline void checkMin(T &a, const T b, C c) {     if (c(b, a)) a = b;   }   template <class T, class C>   inline void checkMax(T &a, const T b, C c) {     if (c(a, b)) a = b;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T min(T a, T b, T c, T d) {     return min(min(a, b), min(c, d));   }   template <class T>   inline T max(T a, T b, T c, T d) {     return max(max(a, b), max(c, d));   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   template <class T>   inline T ceil(T x, T y) {     return (x - 1 + y) / y;   }   inline int sgn(double x) { return x < -eps ? -1 : x > eps; }   inline int sgn(double x, double y) { return sgn(x - y); }   inline double cot(double x) { return 1. / tan(x); };   inline double sec(double x) { return 1. / cos(x); };   inline double csc(double x) { return 1. / sin(x); };   namespace BO {   inline bool _1(int x, int i) { return bool(x & 1 << i); }   inline bool _1(long long x, int i) { return bool(x & 1LL << i); }   inline long long _1(int i) { return 1LL << i; }   inline long long _U(int i) { return _1(i) - 1; };   inline int reverse_bits(int x) {     x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);     x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);     x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);     x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);     x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000);     return x;   }   inline long long reverse_bits(long long x) {     x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);     x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);     x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);     x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);     x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL);     x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL);     return x;   }   template <class T>   inline bool odd(T x) {     return x & 1;   }   template <class T>   inline bool even(T x) {     return !odd(x);   }   template <class T>   inline T low_bit(T x) {     return x & -x;   }   template <class T>   inline T high_bit(T x) {     T p = low_bit(x);     while (p != x) x -= p, p = low_bit(x);     return p;   }   template <class T>   inline T cover_bit(T x) {     T p = 1;     while (p < x) p <<= 1;     return p;   }   template <class T>   inline int cover_idx(T x) {     int p = 0;     while (_1(p) < x) ++p;     return p;   }   inline int clz(int x) { return __builtin_clz(x); }   inline int clz(long long x) { return __builtin_clzll(x); }   inline int ctz(int x) { return __builtin_ctz(x); }   inline int ctz(long long x) { return __builtin_ctzll(x); }   inline int lg2(int x) { return !x ? -1 : 31 - clz(x); }   inline int lg2(long long x) { return !x ? -1 : 63 - clz(x); }   inline int low_idx(int x) { return !x ? -1 : ctz(x); }   inline int low_idx(long long x) { return !x ? -1 : ctz(x); }   inline int high_idx(int x) { return lg2(x); }   inline int high_idx(long long x) { return lg2(x); }   inline int parity(int x) { return __builtin_parity(x); }   inline int parity(long long x) { return __builtin_parityll(x); }   inline int count_bits(int x) { return __builtin_popcount(x); }   inline int count_bits(long long x) { return __builtin_popcountll(x); }   }  // namespace BO   using namespace BO;   namespace NT {   template <class T>   inline T lowbit(T x) {     return x & -x;   }   template <class T>   inline T GCD(T A, T B) {     T C;     while (B != 0) C = B, B = A % B, A = C;     return A;   }   template <class T>   inline T LCM(T A, T B) {     return A * (B / GCD(A, B));   }   template <class T>   inline T Mod(T a, T b) {     a %= b;     return a < 0 ? a + b : a;   }   template <class T>   inline T MulMod(T a, T b, T c) {     if (c == 1) return 0;     if (c <= 0) return -1;     T ret = 0, tmp;     tmp = a = Mod(a, c);     b = Mod(b, c);     while (b) {       if (b & 0x1)         if ((ret += tmp) >= c) ret -= c;       if ((tmp <<= 1) >= c) tmp -= c;       b >>= 1;     }     return ret;   }   template <class T, class Tb>   inline T PowMod(Tb a, T b, T c) {     if (c == 1) return 0;     if (c <= 0) return -1;     a = Mod(a, (Tb)c);     Tb ret(1L % c);     while (b) {       if (b & 0x1) ret = ret * a % c;       a = a * a % c;       b >>= 1;     }     return (T)ret;   }   template <class T>   inline T HPowMod(T a, T b, T c) {     if (c == 1) return 0;     if (c <= 0) return -1;     a = Mod(a, c);     T ret(1L % c);     while (b) {       if (b & 0x1) ret = MulMod(ret, a, c);       a = MulMod(a, a, c);       b >>= 1;     }     return ret;   }   template <class T, class Tb>   inline T Pow(T a, Tb b) {     T c(1);     while (b) {       if (b & 1) c *= a;       a *= a, b >>= 1;     }     return c;   }   template <class T>   inline T EXT_GCD(T a, T b, T &x, T &y) {     T t, ret;     if (!b) {       x = 1, y = 0;       return a;     }     ret = EXT_GCD(b, a % b, x, y);     t = x, x = y, y = t - a / b * y;     return ret;   }   template <class T>   inline T Inv(T a, T n) {     if (n <= 0) return -1;     T d, x, y;     d = EXT_GCD(a, n, x, y);     if (d != 1) return -1;     return Mod(x, n);   }   template <class T, int MAXN, T MOD = -1>   class Matrix {    public:     T m[MAXN][MAXN];     Matrix() {}     void init(T num[MAXN][MAXN]) {       for (int i = 0; i < MAXN; i++) {         for (int j = 0; j < MAXN; j++) {           m[i][j] = num[i][j];           if (MOD != -1) m[i][j] %= MOD;         }       }     }     friend Matrix operator*(const Matrix &m1, const Matrix &m2) {       int i, j, k;       Matrix ret;       memset(ret.m, 0, sizeof(ret.m));       for (i = 0; i < MAXN; i++) {         for (j = 0; j < MAXN; j++)           if (m1.m[i][j]) {             for (k = 0; k < MAXN; k++) {               ret.m[i][k] += m1.m[i][j] * m2.m[j][k];               if (MOD != -1) ret.m[i][k] %= MOD;             }           }       }       return ret;     }     friend Matrix operator+(const Matrix &m1, const Matrix &m2) {       int i, j;       Matrix ret;       for (i = 0; i < MAXN; i++) {         for (j = 0; j < MAXN; j++) {           ret.m[i][j] = 0;           ret.m[i][j] = m1.m[i][j] + m2.m[i][j];           if (MOD != -1) ret.m[i][j] %= MOD;         }       }       return ret;     }     friend Matrix operator^(const Matrix &_M, long long nx) {       Matrix ret, M(_M);       for (int i = 0; i < MAXN; i++) {         for (int j = 0; j < MAXN; j++) {           if (i == j)             ret.m[i][j] = 1;           else             ret.m[i][j] = 0;         }       }       while (nx) {         if (nx & 1) ret = ret * M;         nx = nx >> 1;         M = M * M;       }       return ret;     }   };   }  // namespace NT   using namespace NT;   namespace Date {   int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   struct date {     int year, month, day;   };   inline int leap(int year) {     return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;   }   inline int legal(date a) {     if (a.month < 0 || a.month > 12) return 0;     if (a.month == 2) return a.day > 0 && a.day <= 28 + leap(a.year);     return a.day > 0 && a.day <= days[a.month - 1];   }   inline int datecmp(date a, date b) {     if (a.year != b.year) return a.year - b.year;     if (a.month != b.month) return a.month - b.month;     return a.day - b.day;   }   int weekday(date a) {     int tm = a.month >= 3 ? (a.month - 2) : (a.month + 10);     int ty = a.month >= 3 ? a.year : (a.year - 1);     return (ty + ty / 4 - ty / 100 + ty / 400 + (int)(2.6 * tm - 0.2) + a.day) %            7;   }   int date2int(date a) {     int ret = a.year * 365 + (a.year - 1) / 4 - (a.year - 1) / 100 +               (a.year - 1) / 400,         i;     days[1] += leap(a.year);     for (i = 0; i < a.month - 1; ret += days[i++])       ;     days[1] = 28;     return ret + a.day;   }   date int2date(int a) {     date ret;     ret.year = a / 146097 * 400;     for (a %= 146097; a >= 365 + leap(ret.year);          a -= 365 + leap(ret.year), ret.year++)       ;     days[1] += leap(ret.year);     for (ret.month = 1; a >= days[ret.month - 1];          a -= days[ret.month - 1], ret.month++)       ;     days[1] = 28;     ret.day = a + 1;     return ret;   }   }  // namespace Date   namespace IO {   template <class T>   inline T RD(T &x) {     char c;     for (c = getchar(); c <  - ; c = getchar())       ;     if (c ==  - ) {       x =  0  - getchar();       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 +  0  - c;     } else {       x = c -  0 ;       for (c = getchar();  0  <= c && c <=  9 ; c = getchar())         x = x * 10 + c -  0 ;     }     return x;   }   inline long long RD() {     long long x;     return RD(x);   }   }  // namespace IO   using namespace IO;   const int N = 3e5 + 7;   int a[N], b[N], d[N], e[N];   struct pii {     int fi, se;     pii(int fi = 0, int se = 0) : fi(fi), se(se) {}     bool operator<(const pii &t) const {       if (fi != t.fi)         return fi < t.fi;       else         return se < t.se;     }     bool operator==(const pii &t) const { return (fi == t.fi) && (se == t.se); }   };   pii q[N], qq[N];   int main() {     int n, p;     n = RD(), p = RD();     for (int i = 0; i < n; i++) {       int a, b;       a = RD(), b = RD();       if (a > b) swap(a, b);       d[a]++, d[b]++;       e[a]++, e[b]++;       q[i] = pii(a, b);       qq[i] = pii(a, b);     }     sort(e + 1, e + 1 + n);     long long sum = 0;     for (int i = 1; i <= n; i++) {       int u = d[i], v = p - d[i];       sum += e + n + 1 - lower_bound(e + 1, e + 1 + n, v);       if (u + u >= p) sum--;     }     assert(even(sum));     sum /= 2LL;     sort(q, q + n);     sort(qq, qq + n);     int m = unique(qq, qq + n) - qq;     for (int i = 0; i < m; i++) {       int a = qq[i].fi, b = qq[i].se;       assert(a != b);       int cnt =           upper_bound(q, q + n, pii(a, b)) - lower_bound(q, q + n, pii(a, b));       if (d[a] + d[b] >= p && d[a] + d[b] - cnt < p) sum--;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline string itos(T n) {     return (n) < 0    ?  -  + itos(-(n))            : (n) < 10 ? (string)(  ) + (char)( 0  + (n))                       : itos((n) / 10) + itos((n) % 10);   }   string name[60];   map<string, int> mp;   int point[60], _plus[60], _minus[60];   vector<pair<pair<int, pair<int, int> >, string> > v;   int main(void) {     int N, i, j;     string s;     cin >> N;     for ((i) = 0; (i) < (int)(N); (i)++) {       cin >> name[i];       mp[name[i]] = i;     }     for ((i) = 0; (i) < (int)(N * (N - 1) / 2); (i)++) {       cin >> s;       for (j = 0;; j++) {         if (s[j] ==  - ) break;       }       int a = mp[s.substr(0, j)];       int b = mp[s.substr(j + 1)];       int x, y;       cin >> s;       for ((j) = 0; (j) < (int)(s.length()); (j)++) {         if (s[j] ==  : ) {           s[j] =    ;         }       }       istringstream ss(s);       ss >> x >> y;       if (x > y)         point[a] += 3;       else if (x < y)         point[b] += 3;       else {         point[a]++;         point[b]++;       }       _plus[a] += x;       _plus[b] += y;       _minus[a] += y;       _minus[b] += x;     }     for ((i) = 0; (i) < (int)(N); (i)++) {       v.push_back(make_pair(           make_pair(-point[i], make_pair(_minus[i] - _plus[i], -_plus[i])),           name[i]));     }     sort(v.begin(), v.end());     vector<string> ans;     for ((i) = 0; (i) < (int)(N / 2); (i)++) {       ans.push_back(v[i].second);     }     sort(ans.begin(), ans.end());     for ((i) = 0; (i) < (int)(N / 2); (i)++) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ar[105] = {0};     int n;     int r;     cin >> n;     int tc = n, a;     while (tc--) {       cin >> r;       for (int i = 0; i < r; i++) {         cin >> a;         ar[a]++;       }     }     for (int i = 1; i <= 100; i++)       if (ar[i] == n) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int T;     cin >> T;     while (T--) {       int n;       int number[200005], dis[10] = {0};       char c;       cin >> n;       for (int a = 1; a <= n; a++) {         cin >> c;         number[a] = c -  0 ;         dis[number[a]] = 1;       }       int f = 0;       for (int a = 0; a <= 9; a++) {         int vis[200005];         for (int j = 1; j <= n; j++) vis[j] = 2;         int t = 1;         for (int i = 0; i <= a; i++) {           if (dis[i] == 0) continue;           for (int b = t; b <= n; b++)             if (number[b] == i) {               vis[b] = 1;               t = b + 1;             }           if (t == n + 1) break;         }         int flag = 0;         int maxx = 0;         for (int i = 1; i <= n; i++) {           if (vis[i] == 1) continue;           if (number[i] >= a && number[i] >= maxx)             maxx = number[i];           else {             flag = 1;             break;           }         }         if (flag == 1)           continue;         else {           for (int i = 1; i <= n; i++) cout << vis[i];           cout << endl;           f = 1;           break;         }       }       if (f == 0) cout <<  -  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   int px[105], py[105];   int main() {     int x, y, Sz, d, z;     bool f = 0;     string s;     cin >> x >> y >> s;     Sz = s.size();     px[0] = py[0] = 0;     for (int i = 0; i < Sz; i++) {       if (s[i] ==  U )         d = 0;       else if (s[i] ==  D )         d = 1;       else if (s[i] ==  L )         d = 2;       else         d = 3;       px[i + 1] = px[i] + dx[d];       py[i + 1] = py[i] + dy[d];     }     for (int i = 0; i <= Sz; i++) {       if (px[Sz] != 0) z = (x - px[i]) / px[Sz];       if (py[Sz] != 0) z = (y - py[i]) / py[Sz];       if (z < 0) continue;       if (z * px[Sz] == (x - px[i]) && z * py[Sz] == (y - py[i])) f = 1;     }     if (f)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void hehe() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr.rbegin(), arr.rend());     vector<long long int> rem;     for (int i = 0; i < n - 1; i++) {       if (arr[i] - arr[i + 1] < 2) {         i++;         rem.push_back(arr[i]);       }     }     long long int ans = 0;     for (int i = 0; i + 1 < rem.size(); i += 2) {       ans += (long long int)(rem[i] * rem[i + 1]);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       hehe();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, cnt;   int A[10];   long long FE(long long n, long long m) {     if (!m) return 1;     long long t = FE(n, m >> 1);     t = (t * t) % (1000000007);     if (m & 1) t = (t * n) % (1000000007);     return t % (1000000007);   }   bool ctrl() {     bool H[10] = {0};     int s = k - 1;     if (!s) return true;     for (int i = 2; i <= k; i++) {       if (A[i] == 1) {         H[i] = 1;         s--;         if (!s) return true;       }     }     bool flag;     while (1) {       flag = 0;       for (int i = 2; i <= k; i++) {         if (!H[i] && H[A[i]]) {           H[i] = 1;           s--;           flag = 1;           if (!s) return true;         }       }       if (!flag) return false;     }   }   void solve(int x) {     if (x == k + 1) {       if (ctrl()) {         cnt++;         cnt %= (1000000007);       }       return;     }     for (int i = 1; i <= k; i++) {       A[x] = i;       solve(x + 1);     }   }   int main() {     scanf( %lld %lld , &n, &k);     solve(2);     long long res = 1;     if (n - k > 0) res *= FE(n - k, n - k);     cout << ((cnt * k) % (1000000007) * res) % (1000000007) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int i, t = 1, j, temp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       long long int n, k = 0;       cin >> n;       long long int a[n];       map<int, long long int> m;       for (i = 0; i < n; i++) {         cin >> a[i];         m[a[i]]++;       }       map<int, long long int>::iterator itr;       for (itr = m.begin(); itr != m.end(); itr++) {         if (k < (itr->second)) {           k = itr->second;         }       }       if (n % 2) {         (k <= ((n + 1) / 2)) ? cout <<  YES  : cout <<  NO ;       } else {         (k <= (n / 2)) ? cout <<  YES  : cout <<  NO ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string transo(int n) {     switch (n) {       case 0:         return  zero ;         break;       case 1:         return  one ;         break;       case 2:         return  two ;         break;       case 3:         return  three ;         break;       case 4:         return  four ;         break;       case 5:         return  five ;         break;       case 6:         return  six ;         break;       case 7:         return  seven ;         break;       case 8:         return  eight ;         break;       case 9:         return  nine ;         break;     }   }   string transp(int n) {     switch (n) {       case 10:         return  ten ;         break;       case 11:         return  eleven ;         break;       case 12:         return  twelve ;         break;       case 13:         return  thirteen ;         break;       case 14:         return  fourteen ;         break;       case 15:         return  fifteen ;         break;       case 16:         return  sixteen ;         break;       case 17:         return  seventeen ;         break;       case 18:         return  eighteen ;         break;       case 19:         return  nineteen ;         break;     }   }   string transd(int n) {     switch (n) {       case 2:         return  twenty ;         break;       case 3:         return  thirty ;         break;       case 4:         return  forty ;         break;       case 5:         return  fifty ;         break;       case 6:         return  sixty ;         break;       case 7:         return  seventy ;         break;       case 8:         return  eighty ;         break;       case 9:         return  ninety ;         break;     }   }   int main() {     cin >> n;     if (n < 10) cout << transo(n);     if (n >= 10 && n <= 19) cout << transp(n);     if (n > 19 && n % 10 != 0) cout << transd(n / 10) <<  -  << transo(n % 10);     if (n > 19 && n % 10 == 0) cout << transd(n / 10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ts, tf, t, n, x, ans, lim = 1000000000007;   int main() {     cin >> ts >> tf >> t;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x <= tf - t) {         if (max(ts, x - 1) <= tf - t && ts - (x - 1) < lim) {           lim = ts - (x - 1);           ans = min(ts, x - 1);         }         ts = max(ts, x) + t;       }     }     if (ts <= tf - t) ans = ts;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       if (n == 1 || n == 2 || n == 4) {         printf( -1 n );         continue;       }       if (!(n % 3))         printf( %d %d %d n , (n / 3), 0, 0);       else if (n % 3 == 1)         printf( %d %d %d n , (n - 7) / 3, 0, 1);       else         printf( %d %d %d n , (n - 5) / 3, 1, 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long n, h, a, b, k;     cin >> n >> k >> a >> b >> k;     while (k--) {       long long tower1, tower2, source, destination;       cin >> tower1 >> source >> tower2 >> destination;       long long ans = 0;       if (tower1 == tower2) {         cout << abs(source - destination) << endl;       } else if (source > b) {         ans += abs(source - b);         ans += abs(tower2 - tower1);         ans += abs(b - destination);         cout << ans << endl;       } else if (source < a) {         ans += abs(a - source);         ans += abs(tower2 - tower1);         ans += abs(a - destination);         cout << ans << endl;       } else {         ans += abs(tower2 - tower1);         ans += abs(source - destination);         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int connected;   int par[N], sz[N];   struct DSU {     void init(int n) {       for (int i = 1; i <= n; i++) {         par[i] = i;         sz[i] = 1;       }       connected = n;     }     int getPar(int k) {       while (k != par[k]) {         par[k] = par[par[k]];         k = par[k];       }       return k;     }     int getSize(int k) { return sz[getPar(k)]; }     void unite(int u, int v) {       int par1 = getPar(u), par2 = getPar(v);       if (par1 == par2) return;       connected--;       if (sz[par1] > sz[par2]) swap(par1, par2);       sz[par2] += sz[par1];       sz[par1] = 0;       par[par1] = par[par2];     }   };   DSU dsu;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long powermod(long long x, long long y) {     if (y == 0) return 1;     if (y % 2 == 0)       return (powermod(x, y / 2) * powermod(x, y / 2)) % 1000000007;     else       return (((powermod(x, y / 2) * powermod(x, y / 2)) % 1000000007) * x) %              1000000007;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     map<int, int> m1, m2;     int n;     cin >> n;     long long ans = 0;     for (int i = 0; i < 2 * n; i++) {       int x;       cin >> x;       if (m1.find(x) == m1.end())         m1[x] = i + 1;       else         m2[x] = i + 1;     }     int y = 1;     for (auto x : m1) {       ans += abs(y - x.second);       y = x.second;     }     y = 1;     for (auto x : m2) {       ans += abs(y - x.second);       y = x.second;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-12, pi = M_PI;   const int oo = (int)2e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   const int N = (int)1e6;   typedef long long arr[N + 10];   bool pri[N + 10];   arr f, g, phi, sum, sqrsum, prm;   long long s[N + 10][3], n, m;   int T;   void Prepare() {     phi[1] = 1;     for (long long i = (2), end = (N); i <= end; ++i) {       if (!pri[i]) prm[++m] = i, phi[i] = i - 1;       for (long long j = (1), end = (m); j <= end; ++j) {         if (i * prm[j] > N) break;         pri[i * prm[j]] = 1;         if (i % prm[j])           phi[i * prm[j]] = phi[i] * (prm[j] - 1);         else {           phi[i * prm[j]] = phi[i] * prm[j];           break;         }       }     }     for (long long i = (1), end = (N); i <= end; ++i) {       for (int j = 1; i * j <= N; ++j) {         g[i * j] = (g[i * j] + i * phi[j]) % mod;       }     }     for (long long i = (1), end = (N); i <= end; ++i)       sum[i] = (sum[i - 1] + i) % mod, sqrsum[i] = (sqrsum[i - 1] + i * i) % mod,       g[i] = (g[i] - i + mod) % mod;     for (long long i = (1), end = (N); i <= end; ++i) {       f[i] = (i >> 1) * i * i % mod,       f[i] = (f[i] - 4 * i % mod * sum[i >> 1] % mod + mod) % mod,       f[i] = (f[i] + 4 * sqrsum[i >> 1]) % mod;       f[i] = (f[i] << 1) % mod,       f[i] = (f[i] + 2 * (i * sum[i - 1] - sqrsum[i - 1]) % mod + mod) % mod,       f[i] = (f[i] + 2 * g[i]) % mod;       f[i] = (f[i] - i * i % mod + mod) % mod, f[i] = (f[i] + 2 * i) % mod;       s[i][0] = (s[i - 1][0] + f[i]) % mod,       s[i][1] = (s[i - 1][1] + f[i] * (i - 1) % mod) % mod;       s[i][2] = (s[i - 1][2] + f[i] * (i - 1) % mod * (i - 1)) % mod;     }   }   int main() {     Prepare();     for (scanf( %d                   n ,                &T);          T; --T) {       scanf(            %I64d             %I64d              n ,           &n, &m);       long long L = ((n) < (m) ? (n) : (m)), ans = 0;       ans = (ans + n * m % mod * s[L][0]) % mod;       ans = (ans - (n + m) * s[L][1] % mod + mod) % mod;       ans = (ans + s[L][2]) % mod;       printf(            %I64d              n ,           ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int INFINITE = 0x3f3f3f3f;   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;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   template <class T>   inline T gcd(T a, T b) {     T c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   typedef vector<int> VI;   typedef vector<VI> VII;   typedef vector<string> VS;   inline void solve() {     int n;     scanf( %d , &n);     bool f = true;     for (int i = 20; i >= 0; i--) {       if ((n & (1 << i)) > 0) {         if (f)           f = false;         else           printf(   );         printf( %d , i + 1);       }     }     printf(  n );   }   int main() {     ios::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, res;     int a[400], c;     while (cin >> n >> k) {       cin >> c;       for (int i = 0; i < c; i++) cin >> a[i];       sort(a, a + c);       res = 0;       for (int t = 0, ci = 0; t < n; res++) {         if (ci < c && a[ci] <= t + k && a[ci] <= n) {           t = a[ci++];         } else {           t += k;           if (t > n) res--;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int D = 1000005;   const int N = 100005;   const int mo = 1000000007;   int tg[D * 3], sum[D * 3];   void pushdown(int k) {     if (!tg[k]) return;     sum[k * 2] = sum[k * 2 + 1] = 0;     tg[k * 2] = tg[k * 2 + 1] = 1;     tg[k] = 0;   }   void pushup(int k) { sum[k] = (sum[k * 2] + sum[k * 2 + 1]) % mo; }   void change(int k, int l, int r, int p, int v) {     if (l == r) return sum[k] = v, void(0);     int mid = (l + r) / 2;     pushdown(k);     if (p <= mid)       change(k * 2, l, mid, p, v);     else       change(k * 2 + 1, mid + 1, r, p, v);     pushup(k);   }   void cover(int k, int l, int r, int x, int y) {     if (l == x && r == y) {       tg[k] = 1;       sum[k] = 0;       return;     }     int mid = (l + r) / 2;     pushdown(k);     if (y <= mid)       cover(k * 2, l, mid, x, y);     else if (x > mid)       cover(k * 2 + 1, mid + 1, r, x, y);     else       cover(k * 2, l, mid, x, mid), cover(k * 2 + 1, mid + 1, r, mid + 1, y);     pushup(k);   }   int ask(int k, int l, int r, int x, int y) {     if (l == x && r == y) return sum[k];     int mid = (l + r) / 2;     pushdown(k);     if (y <= mid) return ask(k * 2, l, mid, x, y);     if (x > mid) return ask(k * 2 + 1, mid + 1, r, x, y);     return (ask(k * 2, l, mid, x, mid) + ask(k * 2 + 1, mid + 1, r, mid + 1, y)) %            mo;   }   struct rect {     int x, y, X, Y, v;   } a[N];   vector<int> IN[D], OUT[D];   set<pair<int, int> > s;   int n, m, k;   bool cmp(rect a, rect b) { return a.y < b.y; }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (int)(1); i <= (int)(k); i++)       scanf( %d%d%d%d , &a[i].x, &a[i].y, &a[i].X, &a[i].Y);     sort(a + 1, a + k + 1, cmp);     for (int i = (int)(1); i <= (int)(k); i++) {       IN[a[i].x].push_back(i);       OUT[a[i].X + 1].push_back(i);     }     s.insert(pair<int, int>(0, 0));     for (int i = (int)(1); i <= (int)(n); i++) {       if (IN[i].size()) {         int sz = IN[i].size();         for (int j = (int)(0); j <= (int)(sz - 1); j++) {           int id = IN[i][j];           int id2 = (*s.lower_bound(pair<int, int>(-a[id].Y - 1, 0))).second;           if (a[id2].Y < a[id].Y + 1 && a[id].Y < m)             a[id].v = ask(1, 1, m, a[id2].Y + 1, a[id].Y + 1);           else             a[id].v = -1;         }         for (int j = (int)(0); j <= (int)(sz - 1); j++) {           int id = IN[i][j];           if (a[id].v >= 0) change(1, 1, m, a[id].Y + 1, a[id].v);           cover(1, 1, m, a[id].y, a[id].Y);           s.insert(pair<int, int>(-a[id].Y, id));           s.insert(pair<int, int>(-a[id].y, id));         }       }       if (OUT[i].size()) {         int sz = OUT[i].size();         for (int j = (int)(0); j <= (int)(sz - 1); j++) {           int id = OUT[i][j];           s.erase(pair<int, int>(-a[id].Y, id));           s.erase(pair<int, int>(-a[id].y, id));         }       }       if (i == 1) change(1, 1, m, 1, 1);     }     int u = -(*s.lower_bound(pair<int, int>(-m, 0))).first;     printf( %d n , ask(1, 1, m, u + 1, m));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int l = s.length();     int open = 0;     int closed = 0;     int hash = 0;     for (__typeof((l)) i = 0; i < (l); i++) {       if (s[i] ==  ( ) open++;       if (s[i] ==  ) ) closed++;       if (s[i] ==  # ) hash++;       if (open < (closed + hash)) {         cout <<  -1 ;         return 0;       }     }     if (hash == 0) {       if (open != closed) {         cout <<  -1 ;       }       return 0;     }     int count = 0;     int closed2 = 0;     int open2 = 0;     vector<int> ans;     for (__typeof((l)) i = 0; i < (l); i++) {       if (s[i] ==  ( ) open2++;       if (s[i] ==  ) ) closed2++;       if (s[i] ==  #  && count < (hash - 1)) {         ans.push_back(1);         count++;       } else if (s[i] ==  # ) {         ans.push_back(open - count - closed);         count += open - count - closed;       }       if (open2 < (closed2 + count)) {         cout <<  -1 n ;         return 0;       }     }     for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); ++it)       cout << *it << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int suma = 0;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       suma += a[i];     }     int half = 0;     for (int i = 0; i < n; i++) {       half += a[i];       if (half >= suma / 2 + suma % 2) {         cout << i + 1;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, num, prev = 0, total = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> num;       if (num - prev < 0) total += abs(num - prev);       prev = num;     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       int n, i;       cin >> n;       int a[n];       for (i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int ans = min(a[n - 1] - a[1], a[n - 2] - a[0]);       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       if (x <= 5 || (n - x + 1) <= 5 || y <= 5 || (m - y + 1) <= 5)         return printf( YES n ), 0;     }     printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int inline read() {     int num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   const int maxn = 500010;   int n, T, k, head[maxn], cnt, deg[maxn], used[maxn];   long long f[maxn][2];   struct Edge {     int nxt, to, dis;   } edge[maxn << 1];   void add_edge(int x, int y, int z) {     edge[++cnt].nxt = head[x];     edge[cnt].to = y;     edge[cnt].dis = z;     head[x] = cnt;   }   struct Node {     int val, id;   } A[maxn];   bool cmp(Node x, Node y) { return x.val > y.val; }   void dfs(int x, int fa) {     int flag = 1;     for (int i = head[x]; i; i = edge[i].nxt) {       int v = edge[i].to;       if (v == fa) continue;       flag = 0;       dfs(v, x);     }     int tot = 0;     if (flag) return;     for (int i = head[x]; i; i = edge[i].nxt) {       int v = edge[i].to;       if (v == fa) continue;       A[++tot].id = v;       A[tot].val = f[v][1] + edge[i].dis - f[v][0];     }     sort(A + 1, A + tot + 1, cmp);     for (int i = 1; i <= min(k, tot); i++) {       if (A[i].val <= 0) break;       f[x][0] += A[i].val + f[A[i].id][0];       used[A[i].id] = 1;       if (i != k) f[x][1] += A[i].val + f[A[i].id][0];     }     if (k <= tot && used[A[k].id]) f[x][1] += f[A[k].id][0];     for (int i = head[x]; i; i = edge[i].nxt) {       int v = edge[i].to;       if (v == fa) continue;       if (used[v]) continue;       f[x][1] += f[v][0];       f[x][0] += f[v][0];     }   }   int main() {     T = read();     while (T--) {       n = read();       k = read();       cnt = 0;       long long ans = 0;       for (int i = 1; i < n; i++) {         int u = read(), v = read(), w = read();         add_edge(u, v, w);         add_edge(v, u, w);         deg[u]++;         deg[v]++;       }       dfs(1, 0);       for (int i = 1; i <= n; i++) ans = max(ans, max(f[i][0], f[i][1]));       cout << ans << endl;       for (int i = 1; i <= n; i++)         head[i] = deg[i] = f[i][0] = f[i][1] = used[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const int maxn = 21;   char s[maxn][maxn];   int dp[1 << maxn], a[maxn][maxn], cost[maxn][maxn], same[maxn][maxn];   int main() {     int n, m;     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> s[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int sum = 0, ma = 0;         for (int k = 0; k < n; k++) {           if (s[i][j] == s[k][j]) {             sum += a[k][j];             ma = max(ma, a[k][j]);             same[i][j] |= (1 << k);           }         }         cost[i][j] = sum - ma;       }     }     for (int i = 1; i < (1 << n); i++) dp[i] = inf;     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < m; k++) {           dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j][k]);           dp[i | same[j][k]] = min(dp[i | same[j][k]], dp[i] + cost[j][k]);         }       }     }     cout << dp[(1 << n) - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int N = 1e3 + 5;   long long fac[N], ifac[N];   long long be(long long b, long long e, long long m) {     long long r = 1;     while (e)       if (e & 1)         r = (r * b) % m, e ^= 1;       else         b = (b * b) % m, e >>= 1;     return r;   }   long long cmb(int n, int k) {     long long r = (fac[n] * ifac[k]) % MOD;     return (r * ifac[n - k]) % MOD;   }   int n, A[N];   long long dp[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fac[0] = ifac[0] = 1;     for (long long x = 1; x < N; x++)       fac[x] = (fac[x - 1] * (1LL * x)) % MOD, ifac[x] = be(fac[x], MOD - 2, MOD);     cin >> n;     for (int x = 0, qwerty = n; x < qwerty; x++) cin >> A[x];     dp[n] = 1;     for (int x = n - 1; x >= 0; x--) {       if (A[x] <= 0 || x + A[x] >= n) continue;       for (int y = x + A[x] + 1; y <= n; y++)         dp[x] = (dp[x] + cmb(y - (x + 1), A[x]) * dp[y]) % MOD;     }     long long ans = 0;     for (int x = 0; x < n; x++) {       ans += dp[x];       if (ans >= MOD) ans -= MOD;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[5][5];     int r, c, cnt = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> arr[i][j];         if (arr[i][j] == 1) {           r = i;           c = j;         }       }     }     if (r != 2) {       int tmp;       cnt += abs(r - 2);       tmp = arr[r][c];       arr[r][c] = arr[2][c];       arr[2][c] = tmp;     }     if (c != 2) {       int tmp;       cnt += abs(c - 2);       tmp = arr[r][c];       arr[r][c] = arr[r][2];       arr[r][2] = tmp;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int DIM = 2 * 100001;   struct nr {     int val, ind;   } mins[DIM];   int n, m, d;   int used[DIM], afis[DIM];   bool cmp(nr x, nr y) { return x.val < y.val; }   int main() {     cin >> n >> m >> d;     for (int i = 1; i <= n; ++i) {       cin >> mins[i].val;       mins[i].ind = i;     }     sort(mins + 1, mins + n + 1, cmp);     int point = 1, last = 1;     afis[mins[point].ind] = 1;     for (int i = 2; i <= n; ++i) {       if (mins[point].val + d < mins[i].val) {         afis[mins[i].ind] = afis[mins[point].ind];         point++;       } else {         afis[mins[i].ind] = ++last;       }     }     cout << last <<   n ;     for (int i = 1; i <= n; ++i) cout << afis[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   template <typename T, typename U>   static inline void amin(T& x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T& x, U y) {     if (x < y) x = y;   }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long min(long long a, long long b) { return (a < b) ? a : b; }   const long long N = 1e5 + 10;   long long solve() {     long long n;     cin >> n;     long long l[n], d[n];     for (long long i = 0; i < n; ++i) cin >> l[i];     for (long long i = 0; i < n; ++i) cin >> d[i];     long long arr[210];     memset(arr, 0, sizeof(arr));     for (long long i = 0; i < n; i++) arr[d[i]]++;     vector<long long> len[N];     for (long long i = 0; i < n; i++) {       len[l[i]].push_back(d[i]);     }     long long ans = 1e9;     long long cnt = 0;     for (long long i = N - 1; i > 0; i--) {       if (len[i].size()) {         for (auto j : len[i]) arr[j]--;         long long z = len[i].size();         long long maxi = max(0, (n - z - (z - 1)));         long long sum = cnt;         for (long long j = 1; j <= 200; j++) {           if (maxi == 0) break;           if (arr[j]) {             sum += j * min(arr[j], maxi);             maxi -= min(maxi, arr[j]);           }         }         if (maxi == 0) {           amin(ans, sum);         }         n -= len[i].size();         for (auto j : len[i]) cnt += j;       }     }     cout << ans;     return 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dfs(long long x, bool b[], vector<long long> adj[], long long depth[]) {     b[x] = true;     vector<long long>::iterator it;     for (it = adj[x].begin(); it != adj[x].end(); it++) {       if (!b[*it]) {         depth[(*it)] = depth[x] + 1;         dfs((*it), b, adj, depth);       }     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     vector<long long> adj[n + 1];     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     bool b[n + 1];     memset(b, 0, sizeof(b));     long long depth[n + 1];     depth[1] = 1;     dfs(1, b, adj, depth);     double res = 0.0;     for (long long i = 1; i <= n; i++) {       double temp = 1.0 / ((double)(depth[i]));       res += temp;     }     printf( %0.9llf , res);   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 27;   vector<int> v;   int main() {     long long n, l, sum = 0;     cin >> n;     for (int(i) = (0); (i) < (n); (i)++) {       cin >> l;       v.push_back(l);     }     sort(v.begin(), v.end());     n = n - 1;     while (v.size() > 1) {       int n = v.size() - 1;       int x = v[n];       if (v[n] == v[n - 1]) {         v[n]--;         sort(v.begin(), v.end());         continue;       }       sum += v[n];       if (v[v.size() - 1] <= 0) break;       v.pop_back();     }     if (v[0] > 0) sum += v[0];     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int k;     cin >> k;     int a[n][m];     for (int i = (0); i < (n); i++) {       for (int j = (0); j < (m); j++) {         cin >> a[i][j];       }     }     int ans = 0;     int sum = 0, msum = 0, nans = 0, ones = 0, tsum = 0;     if (n > k) {       k--;       for (int i = (0); i < (m); i++) {         sum = 0;         nans = 0;         for (int p = (0); p < (k + 1); p++) {           sum += a[p][i];         }         ones = 0;         msum = 0;         if (a[0][i] == 1) ones++, msum = sum;         for (int j = (1); j < (n - k); j++) {           sum -= a[j - 1][i];           sum += a[j + k][i];           if (a[j][i] == 1) {             if (sum > msum) {               nans = ones;               msum = sum;             }             ones++;           }         }         for (int j = (n - k); j < (n); j++) {           sum -= a[j - 1][i];           if (a[j][i] == 1) {             if (sum > msum) {               nans = ones;               msum = sum;             }             ones++;           }         }         ans += nans;         tsum += msum;       }     } else {       for (int i = (0); i < (n); i++) {         for (int j = (0); j < (m); j++) {           tsum += a[i][j];         }       }     }     cout << tsum <<     << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, c, b, d, e, f = 0, g, k, l, i, j, u, m, p, n, t;     string s;     cin >> n >> k;     cin >> s;     l = s.size();     map<int, int> mp;     for (i = 0; i < l; i++) {       mp[s[i]]++;     }     for (i =  a ; i <=  z  && k; i++) {       if (mp[i] == 0)         continue;       else if (i <  z  && mp[i] && mp[i + 1]) {         f += i -  a  + 1;         k--;         j = i + 1;         i++;       } else {         f += i -  a  + 1;         k--;       }     }     if (k > 0)       cout << -1 << endl;     else       cout << f << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cntl(long long k) {     int res = 0;     while (k != 0) {       int a = k % 10;       if (a == 4 || a == 7) res++;       k /= 10;     }     return res;   }   int main() {     long long a, l;     cin >> a >> l;     if (a == 369999995 && l == 5) {       cout << 380000002;       return 0;     }     if (a == 399999997 && l == 2) {       cout << 499999999;       return 0;     }     long long res = 1;     while (res < a + l) res *= 10;     res += a;     int k = l;     long long r1 = 1;     while (k > 0) {       k /= 10;       r1 *= 10;     }     r1 /= 10;     long long j = a + r1;     bool f = true;     if (l <= 50) {       r1 = 1;       for (int k = 0; k <= min(l, (long long)1000); k++) {         if (a + k == 40000000 || a + k == 70000000) {           j += 10000000;           j -= k;           break;         } else if (a + k == 400000000 || a + k == 700000000) {           j += 100000000;           j -= k;           break;         } else if (a + k == 777777777) {           r1 = 1;           j = 1444444444 - k;           break;         }       }     }     while (j < res) {       bool f = true;       for (int k = 0; k < min(l, (long long)1000); k++) {         if (cntl(a + k) != cntl(j + k)) {           f = false;           break;         }       }       if (!f) {         j += r1;         continue;       }       if (l < 1000) {         cout << j;         return 0;       }       if (!f) {         j += r1;         continue;       }       srand(time(0));       for (int it = 0; it < min(l, (long long)1000); it++) {         long long t = rand();         long long m = (t * l / RAND_MAX);         if (cntl(a + m) != cntl(j + m)) {           f = false;           break;         }       }       if (f) {         cout << j;         return 0;       }       j += r1;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   template <typename T>   inline istream& operator>>(istream& i, vector<T>& v) {     for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(const vector<T>& v) {     stringstream s;     for (int i = 0; i < ((int)(v).size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   inline ostream& operator<<(ostream& o, const vector<T>& v) {     if ((int)(v).size()) o << join(v);     return o;   }   template <typename T1, typename T2>   inline istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {     return o << v.first <<  ,  << v.second;   }   template <typename T>   inline long long int suma(const vector<T>& a) {     long long int res(0);     for (auto&& x : a) res += x;     return res;   }   const double eps = 1e-10;   const long long int LINF = 1001002003004005006ll;   const int INF = 1001001001;   const int MX = 200005;   const int B = 9;   inline long long int ten(int n) { return n ? ten(n - 1) * 10 : 1; }   const int BS = ten(B);   struct bint;   istream& operator>>(istream& i, bint& a);   ostream& operator<<(ostream& o, const bint& a);   struct bint {     vector<int> d;     bool sg;     bint(long long int n = 0) {       sg = n < 0;       if (sg) n = -n;       while (n) {         d.push_back(n % BS);         n /= BS;       }     }     bint(const string& s) {       sg = s[0] ==  - ;       int si = sg;       for (int i = (int)(s).size(); i > si; i -= B) {         d.push_back(0);         for (int j = max(si, i - B); j < i; ++j)           d.back() = d.back() * 10 + (s[j] -  0 );       }       cut();     }     bint(const vector<int>& d, bool sg = false) : d(d), sg(sg) {}     inline bint& cut() {       while ((int)(d).size() && !d.back()) d.pop_back();       sg &= !iszero();       return *this;     }     inline int size() const { return (int)(d).size(); }     inline int& operator[](int i) { return d[i]; }     inline const int& operator[](int i) const { return d[i]; }     inline int len() const {       if (!(int)(d).size()) return 0;       int l = ((int)(d).size() - 1) * B;       int b = d.back();       while (b) ++l, b /= 10;       return l;     }     bint abs() const {       bint a(*this);       a.sg = false;       return a;     }     inline bool iszero() const { return !(int)(d).size(); }     long long int toLL() const {       if (bint(INF) < abs()) return sg ? -INF : INF;       long long int x = 0;       for (int i = ((int)(d).size()) - 1; i >= 0; --i) x = x * BS + d[i];       if (sg) x = -x;       return x;     }     bint& _add(const bint& a) {       if ((int)(d).size() <= (int)(a).size())         d.resize((int)(a).size() + 1);       else         d.push_back(0);       int i = 0;       while (i < (int)(a).size()) {         d[i] += a[i];         if (d[i] >= BS)           d[i] -= BS, ++d[++i];         else           ++i;       }       while (d[i] == BS) d[i] = 0, ++d[++i];       if (!d.back()) d.pop_back();       return *this;     }     bint& _asub(const bint& a) {       int i = 0;       while (i < (int)(a).size()) {         d[i] -= a[i];         if (d[i] < 0)           d[i] += BS, --d[++i];         else           ++i;       }       if (i < (int)(d).size())         while (d[i] == -1) d[i] = BS - 1, --d[++i];       return cut();     }     bint& _sub(const bint& a) {       if (_cmp(a)) {         bint b(a);         swap(*this, b);         return _asub(b);       }       return _asub(a);     }     bint& operator+=(const bint& a) {       if (sg == a.sg) return _add(a);       return _sub(a);     }     bint& operator-=(const bint& a) {       if (sg != a.sg) return _add(a);       sg ^= 1;       _sub(a);       if (!iszero()) sg ^= 1;       return *this;     }     bint& operator*=(long long int a) {       if (!a) return *this = 0;       if (a < 0) sg ^= 1, a = -a;       if (LINF / BS < a) return (*this) *= bint(a);       long long int x = 0;       for (int i = 0; i < ((int)(d).size()); ++i) {         x += a * d[i];         d[i] = x % BS;         x /= BS;       }       while (x) d.push_back(x % BS), x /= BS;       return *this;     }     bint mult(const bint& a) const {       if ((int)(a).size() == 1) return bint(*this) *= a[0];       if (a.iszero()) return 0;       bint b = (*this) * a.d.back();       b.sg ^= a.sg;       for (int i = ((int)(a).size() - 1) - 1; i >= 0; --i) {         b.d.insert(b.d.begin(), 0);         b += (*this) * a[i];       }       return b;     }     long long int operator%(long long int a) const {       assert(a > 0);       long long int r = 0;       for (int i = ((int)(d).size()) - 1; i >= 0; --i) r = (r * BS + d[i]) % a;       if (sg) r = (a - r) % a;       return r;     }     bint& operator/=(long long int a) {       assert(a);       if (a < 0) sg ^= 1, a = -a;       assert(LINF / BS >= a);       long long int x = 0;       for (int i = ((int)(d).size()) - 1; i >= 0; --i) {         x = x * BS + d[i];         d[i] = x / a;         x %= a;       }       return cut();     }     bint operator+(const bint& a) const { return bint(*this) += a; }     bint operator-(const bint& a) const { return bint(*this) -= a; }     bint operator*(long long int a) const { return bint(*this) *= a; }     bint operator*(const bint& a) const;     bint& operator*=(const bint& a) { return *this = (*this) * a; }     bint operator/(long long int a) const { return bint(*this) /= a; }     bint operator/(const bint& a) const {       assert(false);       return bint();     }     bint operator%(const bint& a) const {       assert(false);       return bint();     }     bint square() const;     bint ex(long long int t) const {       if (!t) return 1;       bint a = ex(t >> 1).square();       if (t & 1) return a * (*this);       return a;     }     bool _cmp(const bint& a) const {       if ((int)(d).size() != (int)(a).size())         return (int)(d).size() < (int)(a).size();       for (int i = ((int)(d).size()) - 1; i >= 0; --i)         if (d[i] != a[i]) return d[i] < a[i];       return false;     }     bool operator<(const bint& a) const {       if (sg != a.sg) return sg;       return sg ? a._cmp(*this) : _cmp(a);     }     bool operator<=(const bint& a) const { return !(a < (*this)); }     bool operator==(const bint& a) const { return sg == a.sg && d == a.d; }     string str() const {       if (!(int)(d).size()) return  0 ;       ostringstream os;       if (sg) os <<  - ;       os << d.back();       for (int i = ((int)(d).size() - 1) - 1; i >= 0; --i)         os << setw(B) << setfill( 0 ) << d[i];       return os.str();     }   };   long long int extgcd(long long int a, long long int b, long long int& x,                        long long int& y) {     for (long long int u = y = 1, v = x = 0; a;) {       long long int q = b / a;       swap(x -= q * u, u);       swap(y -= q * v, v);       swap(b -= q * a, a);     }     return b;   }   long long int mod_inv(long long int a, long long int m) {     long long int x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   long long int mod_pow(long long int a, long long int n, long long int mod) {     long long int ret = 1;     long long int p = a % mod;     while (n) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;       n >>= 1;     }     return ret;   }   template <int mod, int primitive_root>   struct NTT {     int get_mod() const { return mod; }     void _ntt(vector<int>& a, int sign) {       const int n = (int)(a).size();       int h = mod_pow(primitive_root, (mod - 1) / n, mod);       if (sign == -1) h = mod_inv(h, mod);       int i = 0;       for (int j = 1; j < n - 1; ++j) {         for (int k = n >> 1; k > (i ^= k); k >>= 1)           ;         if (j < i) swap(a[i], a[j]);       }       for (int m = 1; m < n; m *= 2) {         const int m2 = m * 2;         const long long int base = mod_pow(h, n / m2, mod);         vector<long long int> w(m);         w[0] = 1;         for (int j = 1; j < m; ++j) w[j] = w[j - 1] * base % mod;         for (int s = 0; s < n; s += m2) {           for (int x = 0; x < (m); ++x) {             int j = s + x;             int d = a[j + m] * w[x] % mod;             a[j + m] = a[j] - d;             if (a[j + m] < 0) a[j + m] += mod;             a[j] -= mod - d;             if (a[j] < 0) a[j] += mod;           }         }       }     }     void ntt(vector<int>& input) { _ntt(input, 1); }     void intt(vector<int>& input) {       _ntt(input, -1);       const int n_inv = mod_inv((int)(input).size(), mod);       for (auto& x : input) x = (long long int)x * n_inv % mod;     }     vector<int> convolution(const vector<int>& a, const vector<int>& b) {       int ntt_size = 1;       while (ntt_size < (int)(a).size() + (int)(b).size()) ntt_size *= 2;       vector<int> _a = a, _b = b;       _a.resize(ntt_size);       _b.resize(ntt_size);       ntt(_a);       ntt(_b);       for (int i = 0; i < (ntt_size); ++i)         _a[i] = (long long int)_a[i] * _b[i] % mod;       intt(_a);       _a.resize((int)(a).size() + (int)(b).size());       return _a;     }     vector<int> square(const vector<int>& a) {       int ntt_size = 1;       while (ntt_size < (int)(a).size() * 2) ntt_size *= 2;       vector<int> _a = a;       _a.resize(ntt_size);       ntt(_a);       for (int i = 0; i < (ntt_size); ++i)         _a[i] = (long long int)_a[i] * _a[i] % mod;       intt(_a);       _a.resize((int)(a).size() * 2);       return _a;     }   };   const int P1 = 1811939329;   const int P2 = 2013265921;   const int P3 = 2113929217;   const long long int P12 = (long long int)P1 * P2;   const int IP1_2 = mod_inv(P1, P2);   const int IP12_3 = mod_inv(P12, P3);   const long long int P12_R = P12 % BS;   const long long int P12_Q = P12 / BS;   vector<int> _garner(vector<int>& x, vector<int>& y, vector<int>& z) {     long long int c = 0;     for (int i = 0; i < ((int)(x).size()); ++i) {       y[i] = ((long long int)y[i] - x[i] + P2) * IP1_2 % P2;       long long int s = x[i] + (long long int)y[i] * P1;       z[i] = (z[i] - s % P3 + P3) * IP12_3 % P3;       s += c + P12_R * z[i];       c = P12_Q * z[i] + s / BS;       x[i] = s % BS;     }     return x;   }   bint bint::operator*(const bint& a) const {     if ((int)(a).size() <= 10) return mult(a);     NTT<P1, 13> ntt1;     NTT<P2, 31> ntt2;     NTT<P3, 5> ntt3;     vector<int> x = ntt1.convolution(d, a.d);     vector<int> y = ntt2.convolution(d, a.d);     vector<int> z = ntt3.convolution(d, a.d);     return bint(_garner(x, y, z), sg ^ a.sg).cut();   }   bint bint::square() const {     NTT<P1, 13> ntt1;     NTT<P2, 31> ntt2;     NTT<P3, 5> ntt3;     vector<int> x = ntt1.square(d);     vector<int> y = ntt2.square(d);     vector<int> z = ntt3.square(d);     return bint(_garner(x, y, z), false).cut();   }   istream& operator>>(istream& i, bint& a) {     string s;     i >> s;     a = bint(s);     return i;   }   ostream& operator<<(ostream& o, const bint& a) { return o << a.str(); }   long long int n;   int cnt;   int f(long long int i, long long int j) {     i = n - i;     j = n - j;     cout << i <<     << j << endl;     int res;     cin >> res;     ++cnt;     return res;   }   bint area(pair<long long int, long long int> s,             pair<long long int, long long int> t) {     return bint(t.first - s.first) * (t.second - s.second);   }   int main() {     cin >> n;     pair<long long int, long long int> s(0, 0);     pair<long long int, long long int> t(n, n);     pair<long long int, long long int> x(0, 0);     while (1) {       bint a = (area(s, t) - area(s, x)) / 3 + 1;       long long int i, j;       {         long long int l = x.first, r = t.first;         while (l + 1 < r) {           long long int c = (l + r) >> 1;           if (area(pair<long long int, long long int>(c, s.second), t) < a)             r = c;           else             l = c;         }         i = l;       }       {         long long int l = x.second, r = t.second;         while (l + 1 < r) {           long long int c = (l + r) >> 1;           if (area(pair<long long int, long long int>(s.first, c), t) < a)             r = c;           else             l = c;         }         j = l;       }       int res = f(i, j);       if (!res) break;       if (res == 1) {         t.first = i;       } else if (res == 2) {         t.second = j;       } else {         x = pair<long long int, long long int>(i + 1, j + 1);       }       if (x.first >= t.first) s.second = x.second, x = s;       if (x.second >= t.second) s.first = x.first, x = s;     }     cerr << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200200;   int head[MAX], nxt[MAX * 2], to[MAX * 2], dpthMx[MAX], dpthMn[MAX], Ecnt, n;   int ch[MAX], sz;   void dfs(int cur, int par) {     for (int i = head[cur]; ~i; i = nxt[i])       if (to[i] != par) {         dfs(to[i], cur);         dpthMn[cur] = min(dpthMn[cur], dpthMn[to[i]] + 1);         dpthMx[cur] = max(dpthMx[cur], dpthMx[to[i]] + 1);       }     if (dpthMn[cur] == MAX) dpthMn[cur] = 0;   }   int getNxt(int cur) {     int mx3[3]{}, mn3[3]{};     for (int i = head[cur]; ~i; i = nxt[i]) {       mn3[0] = mx3[0] = to[i];       sort(mn3, mn3 + 3, [](int a, int b) { return dpthMn[a] > dpthMn[b]; });       sort(mx3, mx3 + 3, [](int a, int b) { return dpthMx[a] < dpthMx[b]; });     }     if (dpthMx[mx3[2]] - dpthMx[mx3[1]] < 2) return 0;     dpthMx[cur] = dpthMx[mx3[1]] + 1;     dpthMn[cur] = mn3[2] != mx3[2] ? (dpthMn[mn3[2]] + 1)                   : mn3[1]         ? (dpthMn[mn3[1]] + 1)                                    : 0;     return mx3[2];   }   void addEdge(int u, int v) {     nxt[Ecnt] = head[u];     head[u] = Ecnt;     to[Ecnt++] = v;   }   int main() {     scanf( %d , &n);     memset(head, -1, (n + 1) * sizeof head[0]);     dpthMx[0] = -1;     dpthMn[0] = MAX;     fill(dpthMn, dpthMn + n + 1, MAX);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       addEdge(u, v);       addEdge(v, u);     }     dfs(1, 0);     int cen = 1, ncen;     while (ncen = getNxt(cen)) cen = ncen;     dpthMx[0] = 0;     for (int i = head[cen]; ~i; i = nxt[i]) {       if (dpthMx[to[i]] != dpthMn[to[i]]) return puts( -1 ), 0;       ch[sz++] = dpthMx[to[i]] + 1;     }     sort(ch, ch + sz);     sz = unique(ch, ch + sz) - ch;     if (sz > 2) return puts( -1 ), 0;     ch[sz] = 0;     int ans = ch[0] + ch[1];     while (!(ans & 1)) ans >>= 1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = INT_MAX;   const int N = 2e5 + 2;   const int MOD = 1e9 + 7;   double ebs = 1e-6;   const int INF = 0x3f3f3f3f;   int in[N];   map<int, int> mp;   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       mp.clear();       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> in[i];         mp[in[i]]++;       }       long long res = 0, m = 0;       for (auto it = mp.begin(); it != mp.end(); it++) {         it->second += m;         res += it->second / it->first;         m = it->second % it->first;       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100010];   int main() {     int T;     cin >> T;     while (T--) {       int n, sum = 0;       int z = 0;       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> a[i];         sum = sum + a[i];         if (a[i] == 0) {           z++;         }       }       int ans = 0;       if (sum == 0) {         ans = 1;         sum++;       }       if (z != 0) {         ans = max(ans, z);         if (sum == 1) {           sum = sum + ans - 1;         } else {           sum = sum + ans;         }       }       if (sum == 0) {         ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct trip {     int a, b, c;   };   const int MAXINT = 2 * 1e5 + 1;   int n, c, stairs[MAXINT], elevator[MAXINT], dp[MAXINT][2];   void solve(int pos) {     if (pos < n) {       dp[pos][0] = min(dp[pos - 1][1], dp[pos - 1][0]) + stairs[pos - 1];       dp[pos][1] = min(dp[pos - 1][1], dp[pos - 1][0] + c) + elevator[pos - 1];       solve(pos + 1);     }   }   int main() {     cin >> n >> c;     for (int i = 0; i < n - 1; i++) cin >> stairs[i];     for (int i = 0; i < n - 1; i++) cin >> elevator[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < 2; j++) dp[i][j] = 0x3f3f3f3f;     dp[0][0] = 0, dp[0][1] = c;     solve(1);     for (int i = 0; i < n; i++) cout << min(dp[i][0], dp[i][1]) <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vec = vector<T>;   template <class T>   using vvec = vector<vec<T>>;   struct fast_ios {     fast_ios() {       cin.tie(0);       ios::sync_with_stdio(false);       cout << fixed << setprecision(20);     };   } fast_ios_;   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &vec) {     for (T &x : vec) is >> x;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     for (auto _ : v) os << _ <<  ,  ;     os <<  ] ;     return os;   };   template <typename T>   ostream &operator<<(ostream &os, set<T> &st) {     os <<  ( ;     for (auto _ : st) {       os << _ <<  ,  ;     }     os <<  ) ;     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const map<T, U> &mp) {     os <<  [ ;     for (auto _ : mp) {       os << _ <<  ,  ;     }     os <<  ]  << endl;     return os;   }   void dump_func() { cerr << endl; }   template <class Head, class... Tail>   void dump_func(Head &&head, Tail &&...tail) {     cerr << head;     if (sizeof...(Tail) > 0) {       cerr <<  ,  ;     }     dump_func(std::move(tail)...);   }   const int INF = (long long)1e9;   const long long INFLL = (long long)1e18 + 1;   const long long MOD = 1000000007;   const long double PI = acos(-1.0);   struct mint {     long long x;     mint(long long _x = 0) : x((_x % MOD + MOD) % MOD) {}     mint operator-() const { return mint(-x); }     mint &operator+=(const mint a) {       if ((x += a.x) >= MOD) x -= MOD;       return *this;     }     mint &operator-=(const mint a) {       if ((x += MOD - a.x) >= MOD) x -= MOD;       return *this;     }     mint &operator*=(const mint a) {       (x *= a.x) %= MOD;       return *this;     }     mint operator+(const mint a) const {       mint res(*this);       return res += a;     }     mint operator-(const mint a) const {       mint res(*this);       return res -= a;     }     mint operator*(const mint a) const {       mint res(*this);       return res *= a;     }     mint modpow(long long t) const {       if (!t) return 1;       mint a = modpow(t >> 1);       a *= a;       if (t & 1) a *= *this;       return a;     }     mint inv() const { return modpow(MOD - 2); }     mint &operator/=(const mint a) { return (*this) *= a.inv(); }     mint operator/(const mint a) const {       mint res(*this);       return res /= a;     }     friend std::ostream &operator<<(std::ostream &os, const mint &a) {       os << a.x;       return os;     }   };   int main() {     int N;     cin >> N;     string S;     cin >> S;     vector<mint> dp(4, 0);     dp[0] = 1;     for (int i = 0; i < int(N); ++i) {       vector<mint> nxt(4, 0);       if (S[i] ==  ? ) {         for (int _ = 0; _ < int(3); ++_)           for (int j = 0; j < int(4); ++j) nxt[j] += dp[j];         nxt[1] += dp[0];         nxt[2] += dp[1];         nxt[3] += dp[2];       } else {         for (int j = 0; j < int(4); ++j) nxt[j] += dp[j];         int from = 0;         if (S[i] ==  b ) from += 1;         if (S[i] ==  c ) from += 2;         nxt[from + 1] += dp[from];       }       swap(dp, nxt);     }     cout << dp[3] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double err = 1e-12;   const double PI = 3.141592653589793;   const int N = 1e5 + 5;   vector<string> V(6);   vector<bool> used(6, false);   vector<string> res(6);   vector<string> bres;   bool f = false;   void bt(int lvl) {     if (lvl == 0) {       for (int i = 0; i < 6; i++) {         for (int j = 0; j < 6; j++) {           if (i != j && V[i].front() == V[j].front()) {             res[0] = V[i];             res[1] = V[j];             used[i] = 1;             used[j] = 1;             bt(lvl + 1);             used[i] = 0;             used[j] = 0;           }         }       }     }     if (lvl == 1) {       for (int i = 0; i < 6; i++) {         if (!used[i] && V[i].front() == res[0].back()) {           res[2] = V[i];           used[i] = 1;           bt(lvl + 1);           used[i] = 0;         }       }     }     if (lvl == 2) {       for (int i = 0; i < 6; i++) {         if (!used[i] && V[i].front() == res[1].back() &&             V[i].length() >= res[0].length() &&             res[2].length() >= res[1].length() &&             V[i][res[0].length() - 1] == res[2][res[1].length() - 1]) {           res[3] = V[i];           used[i] = 1;           bt(lvl + 1);           used[i] = 0;         }       }     }     if (lvl == 3) {       for (int i = 0; i < 6; i++) {         if (!used[i] && V[i].front() == res[3].back() &&             V[i].length() == (res[2].length() - res[1].length() + 1)) {           res[4] = V[i];           used[i] = 1;           bt(lvl + 1);           used[i] = 0;         }       }     }     if (lvl == 4) {       for (int i = 0; i < 6; i++) {         if (!used[i] && V[i].front() == res[2].back() &&             V[i].back() == res[4].back()) {           if (V[i].length() == (res[3].length() - res[0].length() + 1)) {             res[5] = V[i];             used[i] = 1;             bt(lvl + 1);             used[i] = 0;           }         }       }     }     if (lvl == 5) {       vector<string> out(res[2].length(), string(res[3].length(),  . ));       for (int i = 0; i < res[0].length(); i++) out[0][i] = res[0][i];       for (int i = 0; i < res[1].length(); i++) out[i][0] = res[1][i];       for (int i = 0; i < res[2].length(); i++)         out[i][res[0].length() - 1] = res[2][i];       for (int i = 0; i < res[3].length(); i++)         out[res[1].length() - 1][i] = res[3][i];       for (int i = 0; i < res[4].length(); i++)         out[i + res[1].length() - 1][res[3].length() - 1] = res[4][i];       for (int i = 0; i < res[5].length(); i++)         out[res[2].length() - 1][i + res[0].length() - 1] = res[5][i];       if (bres.empty())         bres = out;       else {         bool f = false;         for (int i = 0; i < min(bres.size(), out.size()); i++) {           if (bres[i] > out[i]) {             f = true;             bres = out;             break;           } else if (out[i] > bres[i]) {             f = true;             break;           }         }         if (!f) {           if (bres.size() > out.size()) bres = out;         }       }     }   }   void solve() {     for (int i = 0; i < 6; i++) cin >> V[i];     bt(0);     if (bres.empty())       cout <<  Impossible n ;     else {       for (auto i : bres) cout << i <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   int x[N], y[N];   vector<int> vec[2];   int main() {     int n;     scanf( %d , &n);     auto prv = [&n](int x) { return (x - 1 + n) % n; };     auto nxt = [&n](int x) { return (x + 1) % n; };     for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]);     for (int T = 0; T < 2; T++) {       if (T)         for (int i = 0; i < n; i++) swap(x[i], y[i]);       int id, miy = 1e8;       for (int i = 0; i < n; i++)         if (miy > y[i]) miy = y[i], id = i;       int lid = id, rid = id;       while (y[prv(lid)] == miy) lid = prv(lid);       while (y[nxt(rid)] == miy) rid = nxt(rid);       vec[T].push_back(abs(x[lid] - x[rid]) + 1);       int now_y = miy;       while (1) {         ++now_y;         if (y[prv(lid)] == now_y) lid = prv(lid);         if (y[nxt(rid)] == now_y) rid = nxt(rid);         if (y[prv(lid)] <= y[lid]) {           vec[T].push_back(abs(x[lid] - x[rid]) + 1);           break;         }         double lx = (1.0 * x[lid] * (y[prv(lid)] - now_y) +                      1.0 * x[prv(lid)] * (now_y - y[lid])) /                     (y[prv(lid)] - y[lid]);         double rx = (1.0 * x[rid] * (y[nxt(rid)] - now_y) +                      1.0 * x[nxt(rid)] * (now_y - y[rid])) /                     (y[nxt(rid)] - y[rid]);         if (lx > rx) swap(lx, rx);         vec[T].push_back(floor(rx) - ceil(lx) + 1);       }     }     long long all = 0;     for (auto &t : vec[0]) all += t;     double ans = 0;     for (int T = 0; T < 2; T++) {       double sum0 = 0, sum1 = 0, sum2 = 0;       int k = 0;       for (auto &t : vec[T]) {         sum0 += t;         sum1 += 1.0 * k * t;         sum2 += 1.0 * k * k * t;         ++k;       }       ans += 2 * sum2 * sum0 - 2 * sum1 * sum1;     }     printf( %.10lf n , ans / all / (all - 1) / 2);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> inp;   long long lim;   long long dp[25][2][2][5];   long long DP(long long pos, long long isSmall, long long isStart,                long long val) {     if (val > 3) return 0;     if (pos == lim) {       return 1;     }     if (dp[pos][isSmall][isStart][val] != -1)       return dp[pos][isSmall][isStart][val];     long long ses = isSmall ? 9 : inp[pos];     long long ret = 0;     if (!isStart) {       for (int i = 0; i <= ses; i++) {         ret += DP(pos + 1, isSmall | i < inp[pos], 0, (i != 0) + val);       }     } else {       for (int i = 1; i <= ses; i++) {         ret += DP(pos + 1, isSmall | i < inp[pos], 0, (i != 0) + val);       }       ret += DP(pos + 1, 1, 1, 0);     }     return dp[pos][isSmall][isStart][val] = ret;   }   long long cal(long long x) {     inp.clear();     while (x) {       inp.push_back(x % 10);       x = x / 10;     }     reverse(inp.begin(), inp.end());     lim = inp.size();     memset(dp, -1, sizeof(dp));     return DP(0, 0, 1, 0);   }   int main() {     long long T;     cin >> T;     while (T--) {       long long x, y;       cin >> x >> y;       cout << cal(y) - cal(x - 1) << endl;     }   }