#include <bits/stdc++.h>   #define ff first   #define ss second   #define endl   n    using namespace std;   const long long INF = (long long) 1e18;   const int mod = (int) 1e9+7;   const int MAXN = (int) 3.5e4+5;      typedef long long ll;   typedef unsigned long long ull;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   ll n, lst[MAXN], nx[MAXN], pr[MAXN], a[MAXN];   set<ll> idx[MAXN];   ll dp[105][MAXN];   ll t[101][4*MAXN], lazy[101][4*MAXN];   int x;   void push(int v){       if(lazy[x][v] == 0)           return;       lazy[x][2*v] += lazy[x][v];       lazy[x][2*v + 1] += lazy[x][v];       t[x][2*v] += lazy[x][v];       t[x][2*v + 1] += lazy[x][v];       lazy[x][v] = 0;   }      void upd(int v, int tl, int tr, int l, int r, ll val){       if(l > r)           return;       if(tl == l && tr == r){           t[x][v] += val;           lazy[x][v] += val;       }else{           push(v);           int tm = (tl + tr) / 2;           upd(2*v, tl, tm, l, min(tm, r), val);           upd(2*v+1, tm + 1, tr, max(tm + 1, l), r, val);           t[x][v] = max(t[x][2*v], t[x][2*v + 1]);       }   }      ll que(int v, int tl, int tr, int l, int r){       if(l > r)           return -INF;       if(tl == l && tr == r)           return t[x][v];       else {           push(v);           int tm = (tl + tr) / 2;           return max(que(2*v, tl, tm, l, min(tm, r)), que(2*v+1, tm + 1, tr, max(tm + 1, l), r));       }   }   int main(){       ios_base::sync_with_stdio(false);       cin.tie(nullptr);cout.tie(nullptr);          #ifdef Local           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt , r ,stdin);           freopen( C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt , w ,stdout);       #endif       ll k;       cin>>n>>k;       ll top = 0;       for(ll i = 1; i <= n; i++){           cin>>a[i];           if(lst[a[i]] != 0)               top += i - lst[a[i]];           pr[i] = lst[a[i]];           lst[a[i]] = i;       }       memset(lst, 0x7f, sizeof(lst));          for(int i = n; i >= 1; i--){           nx[i] = min(n + 1, lst[a[i]]);           lst[a[i]] = i;       }          memset(dp, 0xf7, sizeof(dp));       dp[0][0] = 0;       ll mx = 0;       for(int i = 1; i < k; i++){           x = i - 1;           ll cev = 0;           for(ll j = 1; j <= n; j++){               if(j != 1)                   if(pr[j - 1] != 0)                       upd(1, 0, n, pr[j - 1] + 1, j - 1, j - 1 - pr[j - 1]);               dp[i][j] = que(1, 0, n, 0, j - 1) + cev;               upd(1, 0, n, j, j, dp[i - 1][j] - cev);               //cerr<<dp[i][j]<<   ;               mx = max(mx, dp[i][j]);                  if(pr[j] != 0)                   cev -= j - pr[j];               if(nx[j] != n + 1)                   cev += nx[j] - j;           }       }          cout<<top - mx<<endl;             #ifdef Local           cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<<   milliseconds  ;       #endif   }


#include <bits/stdc++.h>   using namespace std;   void sort(int temp[2000], int start, int end) {     int flag;     for (int i = start; i < end - 1; i++) {       for (int j = start; j < end - i - 1; j++) {         if (temp[j] < temp[j + 1]) {           flag = temp[j];           temp[j] = temp[j + 1];           temp[j + 1] = flag;         }       }     }   }   int main() {     int n, k, arr[2000], count = 0;     cin >> n;     cin >> k;     cout <<   n ;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, 0, n);     for (int i = 0; i < n; i += k) count = count + (2 * (arr[i] - 1));     cout <<   n  << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int m, n, t, ans;   pair<int, int> a[N];   vector<pair<int, int>> v;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       ans = 0;       v.clear();       for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i;       sort(a + 1, a + n + 1);       for (int i = 1; i < n; i++) {         v.push_back(make_pair(a[i].second, a[i + 1].second));         ans += a[i].first + a[i + 1].first;       }       v.push_back(make_pair(a[n].second, a[1].second));       ans += a[n].first + a[1].first;       if (v.size() > m || n == 2) {         puts( -1 );         continue;       }       for (int i = v.size() + 1; i <= m; i++) {         v.push_back(make_pair(a[1].second, a[2].second));         ans += a[1].first + a[2].first;       }       printf( %d n , ans);       for (int i = 0; i < v.size(); i++)         printf( %d %d n , v[i].first, v[i].second);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       cout << (a ^ b) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string A, B;   bool is_divisor(const string &a, const string &b) {     int sa = a.size(), sb = b.size();     for (int i = 0; i < sb; i += sa) {       if (b.substr(i, sa) != a) return false;     }     return true;   }   int process(const string &a, const string &b) {     int sz = a.size();     vector<int> divi;     for (int i = 1; i < sqrt(sz) + 1; ++i) {       if (sz % i == 0) {         divi.push_back(i);         if (i * i != sz) divi.push_back(sz / i);       }     }     set<string> s;     for (int i = 0; i < divi.size(); ++i)       if (is_divisor(a.substr(0, divi[i]), a)) s.insert(a.substr(0, divi[i]));     sz = b.size();     divi.clear();     for (int i = 1; i < sqrt(sz) + 1; ++i) {       if (sz % i == 0) {         divi.push_back(i);         if (i * i != sz) divi.push_back(sz / i);       }     }     int ans = 0;     set<string> ss;     for (int i = 0; i < divi.size(); ++i)       if (is_divisor(b.substr(0, divi[i]), b)) ss.insert(b.substr(0, divi[i]));     for (string a : s)       if (ss.find(a) != ss.end()) ++ans;     return ans;   }   int main() {     char a[100001];     scanf(  %s , a);     A = string(a);     scanf(  %s , a);     B = string(a);     cout << process(A, B) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     scanf( %lld , &n);     printf( 1  );     if ((n - 1) % 3 == 1)       printf( 2 %lld , n - 3);     else       printf( 1 %lld , n - 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> mmap;   map<string, string>::iterator it;   int main() {     int t;     cin >> t;     while (t--) {       string a;       string b;       cin >> a >> b;       if (mmap[b] !=   ) {         for (it = mmap.begin(); it != mmap.end(); it++) {           if (it->first == b) {             mmap.erase(it);             break;           }         }       }       int flag = 0;       for (it = mmap.begin(); it != mmap.end(); it++) {         if (it->second == a) {           it->second = b;           flag = 1;           break;         }       }       if (!flag) mmap[a] = b;     }     int flag = 0;     for (it = mmap.begin(); it != mmap.end(); it++)       if (it->second ==   ) flag++;     cout << mmap.size() - flag << endl;     for (it = mmap.begin(); it != mmap.end(); it++)       if (it->second !=   ) cout << it->first <<     << it->second << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100010];   long long int weight[100010], add[100010], sub[100010];   int n;   void dfs(int mom, int u) {     for (vector<int>::iterator v = g[u].begin(); v != g[u].end(); v++)       if (*v != mom) {         dfs(u, *v);         add[u] = max(add[*v], add[u]);         sub[u] = max(sub[u], sub[*v]);       }     weight[u] += add[u] - sub[u];     if (weight[u] < 0)       add[u] -= weight[u];     else       sub[u] += weight[u];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       g[u].push_back(v), g[v].push_back(u);     }     for (int i = 1; i <= n; i++) scanf( %I64d , weight + i);     dfs(-1, 1);     printf( %I64d n , add[1] + sub[1]);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long llinf = (long long)3e18;   const int N = (int)1e5 + 111;   const long double PI = (long double)acos(-1);   int main() {     int n, cur, num, ans = 0;     scanf( %d , &n);     vector<int> a(n);     vector<char> us(n, 0);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a.begin(), a.end());     for (int i = 0; i < n; i++)       if (us[i] == 0) {         cur = i;         num = 0;         while (cur < n) {           if (us[cur] == 1 || a[cur] < num)             cur++;           else {             num++;             us[cur] = 1;           }         }         ans++;       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   int x[10];   int cp, dp;   using namespace std;   void print() {     for (int i = 0; i < 10; ++i) {       cout << x[i];       if (i == 9)         cout <<   n ;       else         cout <<    ;     }   }   int pp(char a, int &dp) {     if (a ==  < ) {       dp = -1;       return -2;     } else if (a ==  > ) {       dp = 1;       return -2;     } else       return a -  0 ;   }   void work(int l, int r, string ch1) {     cp = l;     dp = 1;     int temp;     bool ins = true;     while (cp >= l && cp <= r) {       temp = pp(ch1[cp], dp);       if (temp >= 0) {         x[temp]++;         ch1[cp]--;         cp += dp;       } else {         if (temp == -1) cp += dp;         if (temp == -2) {           int cpt = cp;           cp += dp;           if (cp < l || cp > r) break;           int temp1 = pp(ch1[cp], dp);           while (temp1 == -1) {             cp += dp;             temp1 = pp(ch1[cp], dp);           }           if (cp < l || cp > r) break;           if (temp1 == -2) ch1[cpt] =  0  - 1;           if (temp1 >= 0) x[temp1]++, ch1[cp]--, cp += dp;         }       }     }     print();   }   int main() {     int n, q;     string ch;     cin >> n >> q;     cin >> ch;     for (int i = 0; i < q; ++i) {       int l, r;       cin >> l >> r;       l--, r--;       memset(x, 0, sizeof(x));       if (l == r) {         int pk = ch[l];         if (pk ==  <  || pk ==  > )           print();         else           x[pk -  0 ]++, print();       } else         work(l, r, ch);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Swap(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   int Max(int a, int b) {     if (a > b) return a;     return b;   }   int Scan() {     int res = 0;     char ch;     ch = getchar();     if (ch >=  0  && ch <=  9 ) res = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + (ch -  0 );     return res;   }   int main() {     int T = Scan();     int X = 0, Y = 0;     while (T--) {       char c;       cin >> c;       int a = Scan();       int b = Scan();       if (a < b) Swap(a, b);       if (c ==  + )         X = Max(X, a), Y = Max(Y, b);       else if (a >= X && b >= Y)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     cout << s[0];     for (int i = 1; i < s.size() - 1; i += 2) {       cout << s[i];     }     cout << s.back();     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t_;     cin >> t_;     while (t_--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int pre[1000010];   int GetN(int n) {     if (pre[n] > 0) return pre[n];     if (n < 10) {       pre[n] = n;       return n;     }     int temp = n;     int product = 1;     while (n > 0) {       int rem = n % 10;       product *= rem == 0 ? 1 : rem;       n = n / 10;     }     return pre[temp] = GetN(product);   }   int dp[1000010][10];   void Precal() {     for (int i = 1; i < 1000010; i++) {       int res = GetN(i);       dp[i][res] = 1;       for (int k = 1; k <= 9; k++) {         dp[i][k] = dp[i][k] + dp[i - 1][k];         if (dp[i][0] == 1) {           cout << i <<     << k;           int v;           cin >> v;           exit(0);         }       }     }   }   int main() {     Precal();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int l, r, k;       cin >> l >> r >> k;       cout << dp[r][k] - dp[l - 1][k] << endl;       ;     }     int v;     cin >> v;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(3e5) + 228, mod = int(1e9) + 7;   const long long inf = (long long)(1e16);   int n;   pair<int, int> p[N];   pair<long long, long long> t[2 * N], dp[N];   pair<long long, long long> merg(pair<long long, long long> a,                                   pair<long long, long long> b) {     if (a.first > b.first) return b;     if (a.first < b.first) return a;     a.second += b.second;     if (a.second >= mod) a.second -= mod;     return a;   }   void upd(int v, pair<long long, long long> a) {     v += n - 1;     t[v] = merg(t[v], a);     while (v > 1) {       v >>= 1;       t[v] = merg(t[v + v], t[v + v + 1]);     }   }   pair<long long, long long> get(int l, int r) {     l += n - 1;     r += n - 1;     pair<long long, long long> res = make_pair(inf, 0);     while (l <= r) {       if (l & 1) res = merg(res, t[l]);       if (!(r & 1)) res = merg(res, t[r]);       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p[i].first, &p[i].second);     }     for (int i = 1; i <= 2 * n; i++) {       t[i] = make_pair(inf, 0);     }     sort(p + 1, p + n + 1);     for (int i = 1; i <= n; i++) {       int l = 0, r = i;       while (r - l > 1) {         int mid = (l + r) >> 1;         if (p[mid].first <= p[i].second)           l = mid;         else           r = mid;       }       if (l == 0) {         dp[i] = make_pair(p[i].second, 1);       } else {         dp[i] = get(1, l);         dp[i].first += p[i].second;       }       upd(i, make_pair(dp[i].first - p[i].first, dp[i].second));     }     int mx = 0;     pair<long long, long long> ans = make_pair(inf, 0);     for (int i = n; i > 0; i--) {       if (mx < p[i].first) ans = merg(ans, dp[i]);       mx = max(mx, p[i].second);     }     printf( %lld , ans.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       while (a[i] % 2 == 0) a[i] /= 2;       while (a[i] % 3 == 0) a[i] /= 3;     }     int flag = 1;     int val = a[0];     for (int i = 1; i < n; i++) {       if (a[i] != val) flag = 0;     }     if (flag)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mx = INT_MIN, n, a[10];   char x;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 7; j++) {         cin >> x;         a[j] += x - 48;       }     }     for (int i = 1; i <= 7; i++)       if (mx < a[i]) mx = a[i];     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a, b;     int t = n / 2;     if (n % 2 == 1) {       cout << t <<     << t + 1;     } else if (n % 4 == 2) {       cout << t - 2 <<     << t + 2;     } else if (n % 4 == 0) {       cout << t - 1 <<     << t + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long c[n], s[n];     for (int i = 0; i < n; i++) {       cin >> c[i] >> s[i];     }     long long dp[m + 1];     dp[m] = 0;     for (int i = m - 1; i >= 0; i--) {       dp[i] = m - i;       for (int j = 0; j < n; j++) {         long long l = c[j] - s[j];         l = max(0LL, l);         long long r = c[j] + s[j];         r = min(r, m);         if (i + 1 >= l && i + 1 <= r) {           dp[i] = min(dp[i], dp[i + 1]);           break;         }         if (i < l) {           long long gap = l - i - 1;           long long rr = r + gap;           rr = min(m, rr);           dp[i] = min(dp[i], gap + dp[rr]);         }       }     }     cout << dp[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[] = {1, 2, 4, 3};   int b[] = {1, 3, 4, 2};   int c[] = {1, 4, 1, 4};   int d[] = {1, 1, 1, 1};   int main() {     string s;     cin >> s;     int n = s.length();     int rem = 0;     for (int i = 0; i < n; i++) {       rem = (rem * 10 + s[i] -  0 ) % 4;     }     int ans = a[rem] + b[rem] + c[rem] + d[rem];     ans %= 5;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1), eps = 1e-6, INF = 1e16;   bool isEqual(long double x, long double y) { return fabs(x - y) < eps; }   int sgn(long double sc) {     if (isEqual(sc, 0)) return 0;     if (sc < eps) return -1;     return 1;   }   struct pnt {     long double x, y;     pnt() {}     pnt(long double _x, long double _y) {       x = _x;       y = _y;     }     pnt(pnt A, pnt B) {       x = B.x - A.x;       y = B.y - A.y;     }     pnt operator+(pnt p) { return pnt(x + p.x, y + p.y); }     pnt operator-(pnt p) { return pnt(x - p.x, y - p.y); }     void operator+=(pnt p) { x += p.x, y += p.y; }     void operator-=(pnt p) { x -= p.x, y -= p.y; }     pnt operator*(long double sc) { return pnt(x * sc, y * sc); }     pnt operator/(long double sc) { return pnt(x / sc, y / sc); }     long double operator*(pnt p) { return x * p.x + y * p.y; }     long double operator^(pnt p) { return x * p.y - p.x * y; }     bool operator==(pnt p) { return isEqual(x, p.x) && isEqual(y, p.y); }     bool operator!=(pnt p) { return !isEqual(x, p.x) || !isEqual(y, p.y); }     void normalize() {       long double sq = sqrt(x * x + y * y);       x /= sq;       y /= sq;       return;     }     long double dist2(pnt p) {       return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);     }     long double dist(pnt p) { return sqrt(dist2(p)); }     bool isParallel(pnt p) { return isEqual(pnt(x, y) ^ p, 0); }   };   struct line {     long double a, b, c;     line() {}     line(long double _a, long double _b, long double _c) {       a = _a, b = _b, c = _c;     }     line(pnt p1, pnt p2) {       a = p1.y - p2.y;       b = p2.x - p1.x;       c = -(a * p1.x + b * p1.y);     }     pnt getPerpendicularVector() { return pnt(a, b); }     pnt getParallelVector() { return pnt(-b, a); }     line getPerpendicularLine() { return line(-b, a, c); }     bool isParallel(line l) {       return getParallelVector().isParallel(l.getParallelVector());     }     pnt intersect(line l) {       if (isParallel(l)) {         return pnt(INF, INF);       }       long double q = a * l.b - b * l.a;       return pnt((b * l.c - c * l.b) / q, (c * l.a - a * l.c) / q);     }     long double dist(pnt p) {       return fabs(a * p.x + b * p.y + c) / sqrt(a * a + b * b);     }     pnt basePerp(pnt p) {       return intersect(line(p, p + getPerpendicularVector()));     }     bool isOnLine(pnt p) { return isEqual(a * p.x + b * p.y + c, 0); }   };   int main() {     int n, d;     cin >> n >> d;     pnt A(0, d), B(d, 0), C(n, n - d), D(n - d, n);     pnt BA(B, A), BC(B, C), CD(C, D), DA(D, A), AC(A, C), DC(D, C);     line BAl(B, A), BCl(B, C), CDl(C, D), DAl(D, A), ACl(A, C);     int m, x, y;     cin >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       pnt kuz(x, y), Bkuz(B, kuz), Dkuz(D, kuz);       if ((((BA ^ Bkuz) < 0 && (BC ^ Bkuz) > 0) &&            (((DA ^ Dkuz) > 0) && ((DC ^ Dkuz) < 0))) ||           BAl.isOnLine(kuz) || BCl.isOnLine(kuz) || CDl.isOnLine(kuz) ||           DAl.isOnLine(kuz)) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   long long ans;   int son[100010][2], fa[100010], cnt[100010], val[100010];   int is[100010];   long long sumVal[100010], sumCnt[100010], sum[100010], all[100010],       lazy[100010];   void up(int p) {     sumCnt[p] = sumCnt[son[p][0]] + sumCnt[son[p][1]] + cnt[p];     sumVal[p] = sumVal[son[p][0]] + sumVal[son[p][1]] + val[p];     sum[p] = sum[son[p][0]] + sum[son[p][1]] + 1LL * cnt[p] * val[p];   }   void func(int p, long long v) {     if (!p) return;     all[p] += v * cnt[p];     lazy[p] += v;   }   void down(int p) {     if (lazy[p]) {       func(son[p][0], lazy[p]);       func(son[p][1], lazy[p]);       lazy[p] = 0;     }   }   void Rotate(int x) {     int y = fa[x], z = fa[y];     int o = son[y][0] == x;     down(y), down(x);     son[y][!o] = son[x][o], fa[son[x][o]] = y;     son[x][o] = y, fa[y] = x;     fa[x] = z;     if (is[y])       is[y] = 0, is[x] = 1;     else       son[z][son[z][1] == y] = x;     up(y);   }   void Splay(int x) {     int y, z;     down(x);     while (!is[x]) {       y = fa[x], z = fa[y];       if (is[y])         Rotate(x);       else if ((son[y][0] == x) ^ (son[z][0] == y))         Rotate(x), Rotate(x);       else         Rotate(y), Rotate(x);     }     up(x);   }   int Access(int x) {     int y = 0;     for (; x; x = fa[x]) {       Splay(x);       is[son[x][1]] = 1;       if (son[x][1]) {         cnt[x] += sumCnt[son[x][1]];       }       son[x][1] = y;       if (y) {         cnt[x] -= sumCnt[y];       }       is[y] = 0;       y = x;       up(x);     }     return y;   }   int vv[100010], nxt[100010], h[100010], e;   void add(int u, int v) { vv[e] = v, nxt[e] = h[u], h[u] = e++; }   void dfs(int u, int f) {     fa[u] = f, is[u] = 1, cnt[u] = 1;     son[u][0] = son[u][1] = 0;     all[u] = 1;     for (int i = h[u]; i + 1; i = nxt[i]) {       int v = vv[i];       dfs(v, u);       all[u] += 1LL * cnt[v] * cnt[u] * 2;       cnt[u] += cnt[v];     }     ans += all[u] * val[u];     up(u);   }   void change(int x, long long v) {     Splay(x);     ans += (v - val[x]) * all[x];     val[x] = v;     up(x);   }   int getFa(int x) {     Splay(x);     if (!son[x][0]) return fa[x];     int y = son[x][0];     while (son[y][1]) y = son[y][1];     return y;   }   void gao(int u, int v) {     Access(u);     Splay(v);     if (!fa[v]) swap(u, v);     int f = getFa(v);     if (f == u) return;     Access(f), Splay(f);     cnt[f] -= sumCnt[v], up(f);     fa[v] = 0;     ans -= 2 * sum[f] * sumCnt[v];     func(f, -2 * sumCnt[v]);     Access(u), Splay(u);     ans += 2 * sum[u] * sumCnt[v];     func(u, 2 * sumCnt[v]);     cnt[u] += sumCnt[v], up(u);     fa[v] = u;   }   int main() {     int n;     int u;     scanf( %d , &n);     memset(h, -1, sizeof(h)), e = 0;     for (int i = 2; i <= n; ++i) {       scanf( %d , &u);       add(u, i);     }     for (int i = 1; i <= n; ++i) scanf( %d , val + i);     dfs(1, 0);     int m, v;     scanf( %d , &m);     char c[3];     double mu = 1.0 * n * n;     printf( %.10lf n , ans / mu);     while (m--) {       scanf( %s%d%d , c, &u, &v);       if (c[0] ==  P )         gao(v, u);       else         change(u, v);       printf( %.10lf n , ans / mu);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, day, dep[1000010], arr[1000010], cost[1000010], cel, from,       coss;   long long mini[1000010], wylot[1000010], dolot[1000010], sum, inf = 1e7;   vector<pair<long long, int> > tab;   int ptr;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     inf *= inf;     for (int a = 1; a <= m; a++) {       cin >> day >> dep[a] >> arr[a] >> cost[a];       tab.push_back(make_pair(day, a));     }     sort(tab.begin(), tab.end());     ptr = 0;     for (int a = 1; a <= n; a++) mini[a] = inf;     sum = n * inf;     dolot[0] = n * inf;     for (int a = 1; a <= 1e6; a++) {       while (ptr < tab.size() && tab[ptr].first <= a) {         cel = arr[tab[ptr].second];         from = dep[tab[ptr].second];         coss = cost[tab[ptr].second];         if (cel != 0) {           ptr++;           continue;         }         if (coss < mini[from]) {           sum -= mini[from];           mini[from] = coss;           sum += coss;         }         ptr++;       }       dolot[a] = sum;     }     reverse(tab.begin(), tab.end());     ptr = 0;     for (int a = 1; a <= n; a++) mini[a] = inf;     sum = n * inf;     wylot[(int)1e6 + 1] = n * inf;     for (int a = 1e6; a >= 0; a--) {       while (ptr < tab.size() && tab[ptr].first >= a) {         cel = arr[tab[ptr].second];         from = dep[tab[ptr].second];         coss = cost[tab[ptr].second];         if (cel == 0) {           ptr++;           continue;         }         if (coss < mini[cel]) {           sum -= mini[cel];           mini[cel] = coss;           sum += coss;         }         ptr++;       }       wylot[a] = sum;     }     long long ans = inf;     for (int a = 1; a <= 1e6 - k; a++) {       if (dolot[a - 1] < n * inf && wylot[a + k] < n * inf)         ans = min(ans, dolot[a - 1] + wylot[a + k]);     }     if (ans == inf)       cout << -1;     else       cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[3][11];   int sum[11];   int x, len, i;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++)       for (int j = 0; j < 6; j++) {         scanf( %d , &x);         a[i][x]++;         sum[x]++;       }     for (i = 1; i < 1000; i++) {       if (i < 10) {         if (sum[i])           continue;         else           break;       } else if (i < 100) {         int flag = 0;         for (int j = 0; j < 3; j++)           for (int k = 0; k < 3; k++) {             if (k == j) continue;             if (a[j][i % 10] && a[k][i / 10]) flag = 1;           }         if (flag == 0) break;       } else {         int flag = 0;         for (int j = 0; j < 3; j++) {           for (int k = 0; k < 3; k++) {             if (k == j) continue;             for (int l = 0; l < 3; l++) {               if (l == k || l == j) continue;               if (a[j][i % 10] && a[k][i / 10 % 10] && a[l][i / 100]) flag = 1;             }           }         }         if (flag == 0) break;       }     }     cout << i - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, mem[100004][28];   char x, y;   string s;   map<pair<int, int>, int> m;   int dp(int i = 0, int j = 27) {     if (i == (int)s.size()) return 0;     int& ret = mem[i][j];     if (~ret) return ret;     if (m[{(int)(s[i] -  a ), j}] != 1) {       return ret = max(dp(i + 1, (int)(s[i] -  a )) + 1, dp(i + 1, j));     } else       return ret = dp(i + 1, j);   }   int main() {     cin >> s;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       m[{(int)(x -  a ), (int)(y -  a )}] = 1;       m[{(int)(y -  a ), (int)(x -  a )}] = 1;     }     memset(mem, -1, sizeof mem);     cout << (int)s.size() - dp();     return 0;   }


#include <bits/stdc++.h>   void answer(unsigned long long v) { std::cout << v <<   n ; }   void solve(unsigned n, unsigned k) {     const auto s = n * (n - 1ull) / 2;     if (k > n / 2) return answer(s);     const auto m = n - 2 * k;     const auto d = m * (m - 1ull) / 2;     answer(s - d);   }   int main() {     unsigned n, k;     std::cin >> n >> k;     solve(n, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b) return gcd(b, a % b);     return gcd(a, b % a);   }   int main() {     long long n, x, y;     cin >> n >> x >> y;     long long d = gcd(x, y);     long long xd = x / d;     long long yd = y / d;     long long nok = x / d * y;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       long long l = 0;       long long r = (a / (x + y) + 2) * nok;       while ((r - l) > 1) {         long long m = (r + l) / 2;         long long hits = m / yd + m / xd;         if (hits >= a)           r = m;         else           l = m;       }       if (((r % yd) == 0) && ((r % xd) == 0))         cout <<  Both n ;       else if (r % yd == 0)         cout <<  Vanya n ;       else         cout <<  Vova n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int ans, tot, head[N], ver[N], Next[N], val[N], n, m, deg[N];   queue<int> q[2];   bool vis[N];   inline void add(int x, int y) {     ver[++tot] = y;     Next[tot] = head[x];     head[x] = tot;     deg[y]++;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++;       y++;       add(y, x);     }     for (int i = 1; i <= n; i++)       if (!deg[i]) q[val[i]].push(i);     while ((!q[0].empty()) || (!q[1].empty())) {       while (!q[0].empty()) {         int x = q[0].front();         q[0].pop();         vis[x] = true;         for (int i = head[x]; i; i = Next[i]) {           int y = ver[i];           if (vis[y]) continue;           if (!(--deg[y])) q[val[y]].push(y);         }       }       if (!q[1].empty()) {         ans++;         while (!q[1].empty()) {           int x = q[1].front();           q[1].pop();           vis[x] = true;           for (int i = head[x]; i; i = Next[i]) {             int y = ver[i];             if (vis[y]) continue;             if (!(--deg[y])) q[val[y]].push(y);           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 7050;   int dp[2][maxn];   vector<int> g[2];   int state[2][maxn];   void dfs(int player, int cur, int n) {     if (state[player][cur] == 1) return;     state[player][cur] = 1;     for (int i = 0; i < g[player].size(); i++) {       int v = (cur + g[player][i]) % n;       if (v == 0) {         dp[player][cur] = 1;         return;       }     }     int cnt = 0;     for (int i = 0; i < g[player].size(); i++) {       int v = (cur + g[player][i]) % n;       dfs(player ^ 1, v, n);       if (dp[player ^ 1][v] == (-1)) {         dp[player][cur] = 1;         return;       }       if (dp[player ^ 1][v] == 1) {         cnt++;       }     }     if (cnt == g[player].size()) dp[player][cur] = (-1);     return;   }   void WORK(int n) {     for (int i = 0; i <= n; i++) dp[0][i] = dp[1][i] = 2;     for (int k = 1; k <= 5; k++) {       memset(state, 0, sizeof(state));       for (int i = n - 1; i >= 0; i--) {         dfs(0, i % n, n);         dfs(1, i % n, n);       }     }   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < 2; i++) {         g[i].clear();         int cnt;         scanf( %d , &cnt);         while (cnt--) {           int x;           scanf( %d , &x);           g[i].push_back(x);         }       }       WORK(n);       for (int i = 0; i < 2; i++) {         for (int j = 1; j < n; j++) {           if (dp[i][j] == 1)             printf( Win  );           else if (dp[i][j] == (-1))             printf( Lose  );           else             printf( Loop  );         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void out(T x) {     cout << x << endl;     exit(0);   }   const int maxn = 1e6 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     int m;     cin >> n >> m;     int need = (n + 4 - 1) / 4;     string a =  5 ;     int tota = 5;     while ((int)a.size() < need) {       a +=  5 ;       tota += 5;     }     string b =  5 ;     int totb = 5;     while ((int)b.size() < need) {       b +=  4 ;       totb += 4;     }     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     cout << a <<   n ;     cout << b <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt;   map<int, int> g[200005];   set<int> s, ns;   void dfs(int x) {     vector<int> v;     v.clear();     ns.clear();     for (set<int>::iterator it = s.begin(); it != s.end(); it++)       if (!g[x][*it])         v.push_back(*it);       else         ns.insert(*it);     s = ns;     for (int i : v) dfs(i);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, u, v; i <= m; ++i)       scanf( %d%d , &u, &v), g[u][v] = 1, g[v][u] = 1;     for (int i = 1; i <= n; ++i) s.insert(i);     for (; s.size();) {       ++cnt;       int t = *s.begin();       s.erase(t);       dfs(t);     }     printf( %d n , cnt - 1);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t, a, b, c, d, k;     cin >> t;     while (t--) {       cin >> a >> b >> c >> d >> k;       int x = a / c;       int y = b / d;       if (a % c) x++;       if (b % d) y++;       if (x + y <= k) {         cout << x <<     << k - x << endl;       } else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, a[300000], b[300000];   long long s;   map<long, long> x, y;   map<pair<long, long>, long> t;   int main() {     cin >> n;     for (long i = 0; i < n; i++) {       cin >> a[i] >> b[i];       x[a[i]]++;       y[b[i]]++;       pair<long, long> p;       p.first = a[i];       p.second = b[i];       t[p]++;     }     for (long i = 0; i < n; i++) {       pair<long, long> p;       p.first = a[i];       p.second = b[i];       s += (x[a[i]] + y[b[i]] - 1 - t[p]);     }     s /= 2;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     scanf( %lld , &n);     scanf( %lld , &k);     long long a[k + 5], mn = -1, ans1, ans2, flag = 0;     for (long long i = 1; i <= k; i++) {       scanf( %lld , &a[i]);       if (a[i] > n) {         continue;       }       flag = 1;       long long r = n % a[i];       if (mn == -1) {         mn = r;         ans1 = i;         ans2 = n / a[i];         continue;       }       if (mn > r) {         mn = r;         ans1 = i;         ans2 = n / a[i];       }     }     if (flag == 0) {       cout <<  1 0 n ;       return 0;     }     cout << ans1 <<     << ans2 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   vector<int> adj[N];   int n, st[N], sz[N], flat[N], tim = 1;   int dfs(int u) {     int s = 1;     st[u] = tim;     flat[tim] = u;     for (int v : adj[u]) {       tim++;       s += dfs(v);     }     return sz[u] = s;   }   int main(int argc, char const *argv[]) {     int q;     cin >> n >> q;     for (int i = 2; i <= n; ++i) {       int p;       cin >> p;       adj[p].push_back(i);     }     for (int i = 1; i <= n; ++i) {       sort(adj[i].begin(), adj[i].end());     }     dfs(1);     while (q--) {       int u, k;       cin >> u >> k;       if (k > sz[u])         cout << -1 <<   n ;       else         cout << flat[st[u] + k - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     cin >> n >> d;     int in[n];     vector<pair<int, int>> c;     in[0] = in[n - 1] = 0;     for (int i = 1; i < n - 1; i++) cin >> in[i];     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       c.push_back({x, y});     }     long long dis[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         dis[i][j] =             d * (abs(c[i].first - c[j].first) + abs(c[i].second - c[j].second));         if (i != 0 && i != n - 1 && i != j) dis[i][j] -= in[i];       }     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (dis[i][k] + dis[k][j] < dis[i][j])             dis[i][j] = dis[i][k] + dis[k][j];         }       }     }     cout << dis[0][n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int r, c, w;   char a[1005][1005];   int rows[1005], columns[1005];   int main() {     scanf( %d%d , &r, &c);     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) {           w++;           rows[i]++;           columns[j]++;         }       }     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++) {         if (rows[i] + columns[j] - (a[i][j] ==  * ) == w) {           printf( YES n%d %d , i, j);           return 0;         }       }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   vector<int> id;   int a[N];   int tr[N];   int find(int u) {     return lower_bound(id.begin(), id.end(), u) - id.begin() + 1;   }   int lowbit(int x) { return x & -x; }   void add(int x, int c) {     for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;   }   int sum(int x) {     int res = 0;     for (int i = x; i; i -= lowbit(i)) res += tr[i];     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       id.clear();       memset(tr, 0, sizeof tr);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         id.push_back(a[i]);       }       sort(id.begin(), id.end());       id.erase(unique(id.begin(), id.end()), id.end());       int tot = id.size();       long long res = 0;       for (int i = 0; i < n; i++) {         int id = find(a[i]);         int q1 = sum(tot) - sum(id);         int q2 = sum(id - 1);         add(id, 1);         res += (long long)min(q1, q2);       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[110];   int n, k;   double p[110];   double dp[110][110];   int was[110][110];   double dist(pair<int, int> a, pair<int, int> b) {     double x = a.first - b.first;     double y = a.second - b.second;     return sqrt(x * x + y * y);   }   double rec(int pos, int kol) {     if (pos == n) {       if (kol >= k) return 1;       return 0;     }     if (was[pos][kol]) return dp[pos][kol];     was[pos][kol] = 1;     double res = p[pos] * rec(pos + 1, kol + 1);     res += (1 - p[pos]) * rec(pos + 1, kol);     return dp[pos][kol] = res;   }   int main() {     scanf( %d , &n);     int x, y, e;     scanf( %d%d , &k, &e);     scanf( %d%d , &x, &y);     e = 1000 - e;     for (int i = (0); i < (n); ++i) scanf( %d%d , &a[i].first, &a[i].second);     double l = 0, r = 1e40;     double best = -1;     for (int i = (0); i < (1000); ++i) {       double m = (l + r) / 2;       for (int i = (0); i < (n); ++i) {         double d = dist(make_pair(x, y), a[i]);         if (d <= m)           p[i] = 1;         else {           double k = d * d / m / m;           p[i] = exp(1.0 - k);         }       }       memset(was, 0, sizeof(was));       double prob = rec(0, 0);       if (prob * 1000 >= e) {         best = m;         r = m;       } else         l = m;     }     printf( %.10lf n , best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m;   struct st {     int go;     long long int a;     long long int b;     st() {       go = -1;       a = 0;       b = 0;     }     st(int a_, long long int b_, long long int c_) {       go = a_;       a = b_;       b = c_;     }   };   vector<st> v[300002];   vector<st> g[300002];   int lim;   st p[300002];   inline void trans(int b, int pr = -1) {     if (pr == -1) {       lim = n;     }     for (int j = 0; j < v[b].size(); j++) {       if (v[b][j].go == pr) continue;       if (g[b].size() == 2) {         swap(g[b], g[lim]);         lim++;         g[b].push_back({lim - 1, 0, 0});       }       g[b].push_back(v[b][j]);     }     for (int j = 0; j < v[b].size(); j++) {       if (v[b][j].go == pr) continue;       trans(v[b][j].go, b);     }   }   bool used[300002];   int dp[300002];   pair<int, int> cent(int b, int whole, int pr = -1) {     pair<int, int> ret = make_pair(INT_MAX, -1);     dp[b] = 1;     int deg = 0;     for (int i = 0; i < g[b].size(); i++) {       int go = g[b][i].go;       if (go == pr) continue;       if (used[go]) continue;       ret = min(ret, cent(go, whole, b));       dp[b] += dp[go];       deg = max(deg, dp[go]);     }     deg = max(deg, whole - dp[b]);     ret = min(ret, make_pair(deg, b));     return ret;   }   struct line {     long long int a;     long long int b;     line(long long int A = 0, long long int B = 0) {       a = A;       b = B;     }     long long int at(long long int x) { return a * x + b; }   };   inline bool enu(int b, vector<line> &lis, int pr = -1,                   line propagate = line()) {     bool leaf = true;     for (int i = 0; i < g[b].size(); i++) {       int go = g[b][i].go;       if (go == pr) continue;       if (used[go]) continue;       leaf = false;       propagate.a += g[b][i].a;       propagate.b += g[b][i].b;       enu(go, lis, b, propagate);       propagate.a -= g[b][i].a;       propagate.b -= g[b][i].b;     }     if (leaf) lis.emplace_back(propagate);     return true;   }   vector<line> all;   bool cmp(line a, line b) {     if (a.a == b.a) {       return a.b < b.b;     }     return a.a < b.a;   }   vector<line> v2;   void clean(vector<line> &v1) {     v2.clear();     sort(v1.begin(), v1.end(), cmp);     for (int i = 0; i < v1.size(); i++) {       while (v2.size()) {         if (v2.back().a == v1[i].a) {           v2.pop_back();           continue;         }         if (v2.size() > 1) {           auto a = v2[v2.size() - 2];           auto b = v2[v2.size() - 1];           auto c = v1[i];           if ((c.b - a.b) * (a.a - b.a) <= (b.b - a.b) * (a.a - c.a)) {             v2.pop_back();             continue;           }         }         break;       }       v2.push_back(v1[i]);     }     v1 = v2;   }   inline void init(int b) {     cent(b, -1);     b = cent(b, dp[b]).second;     used[b] = true;     vector<vector<line> > vv;     for (int i = 0; i < g[b].size(); i++) {       if (used[g[b][i].go]) continue;       vv.push_back(vector<line>());       if (!enu(g[b][i].go, vv.back(), b, line(g[b][i].a, g[b][i].b)))         vv.pop_back();     }     while (1) {       if (vv.size() == 0) break;       if (vv.size() == 1) {         for (auto el : vv[0]) {           all.push_back(el);         }         vv.clear();         break;       }       for (int i = 0; i < vv.size(); i++) {         clean(vv[i]);       }       for (int i1 = 0; i1 < vv.size(); i1++) {         for (int j1 = i1 + 1; j1 < vv.size(); j1++) {           int i = 0;           int j = 0;           while (i < vv[i1].size() && j < vv[j1].size()) {             all.push_back(                 line(vv[i1][i].a + vv[j1][j].a, vv[i1][i].b + vv[j1][j].b));             if (i == vv[i1].size() - 1 && j == vv[j1].size() - 1) break;             if (i == vv[i1].size() - 1) {               j++;               continue;             }             if (j == vv[j1].size() - 1) {               i++;               continue;             }             if (vv[i1][i].a == vv[i1][i + 1].a) {               i++;               continue;             }             if (vv[j1][j].a == vv[j1][j + 1].a) {               j++;               continue;             }             if ((vv[i1][i + 1].b - vv[i1][i].b) *                     (vv[j1][j].a - vv[j1][j + 1].a) <=                 (vv[i1][i].a - vv[i1][i + 1].a) *                     (vv[j1][j + 1].b - vv[j1][j].b)) {               i++;             } else {               j++;             }           }         }       }       break;     }     for (int i = 0; i < g[b].size(); i++) {       if (used[g[b][i].go] == false) {         init(g[b][i].go);       }     }   }   int main() {     cin >> n >> m;     for (int i = 1; i < n; i++) {       int a, b;       long long int c, d;       scanf( %d%d%lld%lld , &a, &b, &c, &d);       a--;       b--;       v[a].push_back(st(b, c, d));       v[b].push_back(st(a, c, d));     }     trans(0);     n = lim;     for (int i = 0; i < n; i++) p[i].go = -1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < g[i].size(); j++) {         p[g[i][j].go] = g[i][j];         p[g[i][j].go].go = i;       }     }     for (int i = 0; i < n; i++) {       if (p[i].go == -1) continue;       g[i].push_back(p[i]);     }     init(0);     int idx = 0;     all.push_back(line());     clean(all);     for (int t = 0; t <= m - 1; t++) {       if (t) {         printf(   );       }       long long int mx = 0;       int pos = -1;       while (idx + 1 < all.size() && all[idx].at(t) <= all[idx + 1].at(t)) {         idx++;       }       printf( %lld , all[idx].at(t));     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300500;   int T[N], L[N], C[N];   int m;   int len = 0;   const int inf = 100500;   int A[N];   int fs = -1, pos = -1;   void apply() {     for (int i = 0; i < m; i++) {       if (i == m - 1) {         pos = len;         fs = m - 1;         goto end;       }       if (T[i] == 1) {         A[len++] = L[i];         if (len >= inf) {           fs = i + 1;           pos = len;           goto end;         }       } else {         assert(L[i] <= len);         for (int q = 0; q < C[i]; q++) {           for (int j = 0; j < L[i]; j++) {             A[len++] = A[j];           }           if (len >= inf) {             for (int u = m - 1; u >= i; u--)               T[u + 1] = T[u], L[u + 1] = L[u], C[u + 1] = C[u];             ++m;             C[i + 1] = C[i] - q - 1;             C[i] = q + 1;             fs = i + 1;             pos = len;             goto end;           }         }       }     }   end:;   }   inline int blen(int o) {     if (T[o] == 1)       return 1;     else       return L[o] * C[o];   }   int main() {     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &T[i]);       if (T[i] == 1)         scanf( %d , &L[i]);       else         scanf( %d %d , &L[i], &C[i]);     }     T[m] = 0;     L[m] = -42;     m++;     apply();     int n;     scanf( %d , &n);     int curg = fs;     long long l = pos, r = pos + blen(fs);     for (int i = 0; i < n; i++) {       long long x;       scanf( %I64d , &x);       --x;       int ans = -1;       if (x < len)         ans = A[(int)x];       else {         while (r <= x && curg < m - 1) l = r, r += blen(++curg);         assert(l <= x && x < r);         if (T[curg] == 1)           ans = L[curg];         else           ans = A[(x - l) % L[curg]];       }       printf( %d%c , ans,    n [i + 1 == n]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     string s1, s2, s3;     cin >> t;     map<string, int> mp;     mp[ polycarp ] = 1;     while (t--) {       cin >> s1 >> s2 >> s3;       transform(s1.begin(), s1.end(), s1.begin(), ::tolower);       transform(s3.begin(), s3.end(), s3.begin(), ::tolower);       mp[s1] = mp[s3] + 1;     }     map<string, int>::iterator it;     int ans = 0;     for (it = mp.begin(); it != mp.end(); ++it)       if (it->second > ans) ans = it->second;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int vp, vd, t, f, c, ans = 0;     double tempt;     double curs = 0;     cin >> vp >> vd >> t >> f >> c;     curs = vp * t;     if (vp >= vd) {       cout << 0 << endl;       return 0;     }     while (curs < c) {       tempt = curs / (vd - vp);       curs += tempt * vp;       if (curs >= c)         break;       else         curs += (tempt + f) * vp;       ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   bool check(string s) {     string tmp = s;     reverse(tmp.begin(), tmp.end());     return tmp != s;   }   void solve() {     string s;     cin >> s;     int ans = 0;     for (int i = 0; i < ((int)(s).size()); ++i) {       string cur =   ;       for (int j = i; j < ((int)(s).size()); ++j) {         cur += s[j];         if (check(cur)) {           ans = max(ans, j - i + 1);         }       }     }     cout << ans <<   n ;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     ios::sync_with_stdio(false);     int tests = 1;     for (int it = 1; it <= tests; ++it) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       int arr[2 * n];       for (int j = 0; j < 2 * n; j++) {         cin >> arr[j];       }       sort(arr, arr + 2 * n);       vector<int> left, right;       for (int j = 0; j < 2 * n; j++) {         if (j == 2 * n - 1) {           if (n % 2 == 0) {             if (j % 2 != 0)               left.push_back(arr[j]);             else               right.push_back(arr[j]);           } else {             if (j % 2 == 0)               left.push_back(arr[j]);             else               right.push_back(arr[j]);           }         } else {           if (j % 2 == 0)             left.push_back(arr[j]);           else             right.push_back(arr[j]);         }       }       cout << abs(left[left.size() / 2] - right[right.size() / 2]) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     sort(a, a + n);     if (n % 2)       printf( %d n , a[n / 2]);     else       printf( %d n , a[n / 2 - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n, x, y, f1, f2, f3, f4;     cin >> q;     for (int i = 0; i < q; ++i) {       cin >> n;       int minx = -100000, miny = -100000, maxx = 100000, maxy = 100000;       for (int o = 0; o < n; ++o) {         cin >> x >> y >> f1 >> f2 >> f3 >> f4;         if (f1 == 0 && minx < x) {           minx = x;         }         if (f2 == 0 && maxy > y) {           maxy = y;         }         if (f3 == 0 && maxx > x) {           maxx = x;         }         if (f4 == 0 && miny < y) {           miny = y;         }       }       if (minx > maxx || miny > maxy) {         cout << 0 << endl;       } else {         cout << 1 <<     << minx <<     << miny << endl;       }     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       int tmp = b + 1;       long long len = -1;       while (tmp != 0) {         tmp /= 10;         len++;       }       long long ans = a * len;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<7000> bit;   int main() {     int n, count = 0;     cin >> n;     while (n--) {       int int1, int2;       string stars;       cin >> int1 >> int2;       if (n >= 1) cin >> stars;       int a = int1 / 10, b = int1 % 10, c = int2 % 10, d = int2 / 10;       int i1 = 1000 * a + 100 * b + 10 * c + d,           i2 = 1000 * d + 100 * a + 10 * b + c,           i3 = 1000 * c + 100 * d + 10 * a + b,           i4 = 1000 * b + 100 * c + 10 * d + a;       if (!bit[i1] && !bit[i2] && !bit[i3] && !bit[i4]) {         count++;         bit.set(i1);         bit.set(i2);         bit.set(i3);         bit.set(i4);       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)3e5, maxM = (int)2e3, intMax = INT_MAX,             maxValue = (int)1e4, intInf = (int)1e9, mod = (int)1e9 + 7, www = 97;   const long long llmax = LLONG_MAX, INF = (long long)1e9 + 1;   long long nod(long long a, long long b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   int nod(int a, int b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   long long nok(long long a, long long b) { return a * b / nod(a, b); }   int nok(int a, int b) { return a * b / nod(a, b); }   long long modPlus(long long a, long long b) {     return ((a % mod) + (b % mod)) % mod;   }   int modPlus(int a, int b) { return ((a % mod) + (b % mod)) % mod; }   long long binPow(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   double binPow(double a, long long b) {     double res = 1;     while (b) {       if (b % 2 == 1) {         res *= a;         while (res >= mod) res -= mod;       }       a *= a;       while (a >= mod) a -= mod;       b >>= 1;     }     return res;   }   long long mulmod(long long a, long long b) {     long long res = 0;     a = a % mod;     while (b > 0) {       if (b % 2 == 1) res = (res + a) % mod;       a = (a * 2) % mod;       b /= 2;     }     return res % mod;   }   pair<int, int> max(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first) return a;     if (a.first < b.first) return b;     if (a.second > b.second) return a;     return b;   }   pair<int, int> min(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return a;     if (a.first != b.first) return b;     if (a.second < b.second) return a;     return b;   }   int n, k, Q[4][maxN];   vector<tuple<int, int, int> > res;   int main() {     scanf( %d%d , &n, &k);     int x = -1, y = -1;     int count = 0;     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &Q[i][j]);         if (i && i < 3) {           if (Q[i][j])             count++;           else {             x = j;             y = i - 1;           }         }         if ((i == 1 || i == 3) && Q[i - 1][j] == Q[i][j]) {           x = j;           if (i == 1)             y = 0;           else             y = 1;         }       }     }     if (x == -1) {       printf( %d n , -1);       fflush(stdout);       return 0;     }     while (count) {       if (y) {         if (Q[1 + y][x]) {           res.emplace_back(Q[1 + y][x], 4, x + 1);           Q[1 + y][x] = 0;           count--;         } else if (x) {           if (Q[1 + y][x - 1] && Q[1 + y][x - 1] != Q[2 + y][x - 1]) {             res.emplace_back(Q[1 + y][x - 1], 3, x + 1);             Q[1 + y][x] = Q[1 + y][x - 1];             Q[1 + y][x - 1] = 0;           }           x--;         } else {           if (Q[1][0] && Q[1][0] != Q[0][0]) {             res.emplace_back(Q[1][x], 3, 1);             Q[2][0] = Q[1][0];             Q[1][0] = 0;           }           y = !y;         }       } else {         if (Q[1 + y][x]) {           res.emplace_back(Q[1 + y][x], 1, x + 1);           Q[1 + y][x] = 0;           count--;         } else if (x < n - 1) {           if (Q[1 + y][x + 1] && Q[1 + y][x + 1] != Q[0][x + 1]) {             res.emplace_back(Q[1 + y][x + 1], 2, x + 1);             Q[1 + y][x] = Q[1 + y][x + 1];             Q[1 + y][x + 1] = 0;           }           x++;         } else {           if (Q[2][n - 1] && Q[2][n - 1] != Q[3][n - 1]) {             res.emplace_back(Q[2][n - 1], 2, n);             Q[1][n - 1] = Q[2][n - 1];             Q[2][n - 1] = 0;           }           y = !y;         }       }     }     printf( %d n , (int)res.size());     fflush(stdout);     int a, b, c;     for (auto i : res) {       tie(a, b, c) = i;       printf( %d %d %d n , a, b, c);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     unsigned long long int n;     scanf( %llu , &n);     printf( %llu , (n / 2) + 1);   }


#include <bits/stdc++.h>   using namespace std;   int cx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0},       cy[] = {0, -1, 1, 0, -1, 1, 1, -1, 0};   int ingrid(int ii, int jj, int R, int C) {     if (ii < 0 || jj < 0 || ii >= R || jj >= C) return 0;     return 1;   }   int main() {     long long n;     cin >> n;     long long maxx = -1, minn = (1LL << 60);     for (int i = 1; i <= sqrt(n); i++) {       long long a = i;       if (n % a == 0) {         long long c = n / a;         for (int i = a; i <= sqrt(c); i++) {           if (c % i == 0) {             long long b = c / i;             long long c = i;             long long temp = (a + 1) * (b + 2) * (c + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);             temp = (b + 1) * (a + 2) * (c + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);             temp = (c + 1) * (a + 2) * (b + 2);             minn = min(minn, temp);             maxx = max(maxx, temp);           }         }       }     }     cout << minn - n <<     << maxx - n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   const int INF = ~0U >> 1;   int N, idx[MAXN];   map<int, int> mp, o_cnt, ls;   map<int, vector<int> > rs;   int main() {     scanf( %d , &N);     int a;     for (int i = 1; i <= N; ++i) {       scanf( %d , &a);       mp[a] = i;     }     int o = INF;     for (int i = 1; i <= N; ++i) {       scanf( %d , &a);       a = idx[i] = mp[a];       if (i <= a) {         o_cnt[ls[i] = a - i] += 1;       } else {         rs[i - a].push_back(i);       }       o = min(o, abs(a - i));     }     printf( %d n , o);     for (int i = 1; i < N; ++i) {       if ((o_cnt[ls[i]] -= 1) == 0) {         o_cnt.erase(o_cnt.find(ls[i]));       }       ls.erase(ls.find(i));       rs[N + i - idx[i]].push_back(i);       if (rs.count(i)) {         for (vector<int>::iterator it = rs[i].begin(); it != rs[i].end(); ++it) {           o_cnt[ls[*it] = -i] += 1;         }         rs.erase(rs.find(i));       }       o = o_cnt.size() ? o_cnt.begin()->first + i : INF;       o = min(o, rs.size() ? rs.begin()->first - i : INF);       printf( %d n , o);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, l;     cin >> n >> m >> k >> l;     if (m > n || n - k < l) return cout << -1, 0;     long long ans = k / m;     k %= m;     while (k > 0) {       k -= m;       ans++;     }     l += k;     ans += (l + m - 1) / m;     if (ans * m > n) return cout << -1, 0;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:16777216 )   const string debug_line =  yolo ;   const long long linf = 1e15 + 5;   const int BLOCK = 330;   struct answerType {     int val;     vector<int> edges;       public:     answerType() {       val = INT_MAX;       edges.clear();     };     answerType(int _val, vector<int> _edges) {       val = _val;       edges = _edges;     };     void reset() {       val = 0;       edges.clear();     }   };   struct solve {     bool visited[1010];     int component[1010];     int arr[1010];     bool isbridge[30010];     vector<pair<pair<int, int>, int> > Adj[1010];     queue<int> Q[1010];     int comp2[1010];     vector<int> tree[1010];     int P[1010][36];     int level1[1010];     vector<pair<pair<pair<int, int>, int>, int> > edges;     int s;     int t;     int ignoreEdge;     int n;     int m;     answerType answer;     int comcount;     int countPairNodes;     map<pair<int, int>, int> mp1;     vector<int> edgeList[30010];     int dfs_timer;     solve() {       s = -1;       t = -1;       ignoreEdge = -1;       edges.clear();       n = -1;       m = -1;       countPairNodes = 0;       comcount = 0;       dfs_timer = 0;     };     solve(int _s, int _t, int _ignoreEdge,           vector<pair<pair<pair<int, int>, int>, int> > _edges, int _n, int _m) {       s = _s;       t = _t;       n = _n;       m = _m;       countPairNodes = 0;       comcount = 0;       ignoreEdge = _ignoreEdge;       edges = _edges;       dfs_timer = 0;       for (int(i) = (0); (i) < (n + 1); ++(i)) {         Adj[i].clear();         visited[i] = false;       }       for (int(i) = (0); (i) < (m + 1); ++(i)) {         isbridge[i] = false;       }       for (auto &(t1) : (edges)) {         if (t1.second != ignoreEdge) {           Adj[t1.first.first.first].push_back(make_pair(               make_pair(t1.first.first.second, t1.first.second), t1.second));           Adj[t1.first.first.second].push_back(make_pair(               make_pair(t1.first.first.first, t1.first.second), t1.second));         }       }       answer.val = INT_MAX;       answer.edges.clear();     };       public:     int DFS(int u, int p, int edge) {       visited[u] = true;       component[u] = comcount;       arr[u] = dfs_timer++;       int dbe = arr[u];       for (auto &(t1) : (Adj[u])) {         if (!visited[t1.first.first] && t1.first.first != p) {           dbe = min(dbe, DFS(t1.first.first, u, t1.second));         } else if (edge != t1.second) {           dbe = min(dbe, arr[t1.first.first]);         }       }       if (dbe == arr[u] && edge != -1) {         isbridge[edge] = true;       }       return dbe;     };     void DFS1(int u) {       int curcmp = comcount;       Q[curcmp].push(u);       visited[u] = true;       while (!Q[curcmp].empty()) {         int v = Q[curcmp].front();         comp2[v] = curcmp;         Q[curcmp].pop();         for (auto &(t1) : (Adj[v])) {           if (visited[t1.first.first]) {             continue;           } else if (isbridge[t1.second]) {             comcount++;             tree[curcmp].push_back(comcount);             tree[comcount].push_back(curcmp);             DFS1(t1.first.first);           } else {             Q[curcmp].push(t1.first.first);             visited[t1.first.first] = true;           }         }       }     };     void DFS2(int u, int p) {       visited[u] = true;       P[u][0] = p;       level1[u] = level1[p] + 1;       for (int(i) = (1); (i) < (35); ++(i)) {         P[u][i] = P[P[u][i - 1]][i - 1];       }       for (auto &(t1) : (tree[u])) {         if (!visited[t1]) {           DFS2(t1, u);         }       }     };     int LCA(int u, int v) {       if (level1[u] < level1[v]) {         swap(u, v);       }       for (int(i) = (34); (i) > (-1); --(i)) {         if (level1[P[u][i]] >= level1[v]) {           u = P[u][i];         }       }       if (u == v) {         return u;       }       for (int(i) = (34); (i) > (-1); --(i)) {         if (P[u][i] != P[v][i]) {           u = P[u][i];           v = P[v][i];         }       }       return P[u][0];     };     void fillListNodes(vector<pair<int, int> > &listNodes, int s, int t) {       int lca = LCA(s, t);       if (lca == s) {         int currNode = t;         while (currNode != lca) {           listNodes.push_back(make_pair(currNode, P[currNode][0]));           currNode = P[currNode][0];         }       } else if (lca == t) {         int currNode = s;         while (currNode != lca) {           listNodes.push_back(make_pair(currNode, P[currNode][0]));           currNode = P[currNode][0];         }       } else {         int currNode = s;         while (currNode != lca) {           listNodes.push_back(make_pair(currNode, P[currNode][0]));           currNode = P[currNode][0];         }         currNode = t;         while (currNode != lca) {           listNodes.push_back(make_pair(currNode, P[currNode][0]));           currNode = P[currNode][0];         }       }     };     void findAnswer() {       memset(visited, 0, sizeof(visited));       for (int(i) = (1); (i) < (n + 1); ++(i)) {         if (!visited[i]) {           DFS(i, 0, -1);           comcount++;         }       }       memset(visited, 0, sizeof(visited));       for (int(i) = (1); (i) < (n + 1); ++(i)) {         if (!visited[i]) {           DFS1(i);         }       }       memset(visited, 0, sizeof(visited));       for (int(i) = (1); (i) < (n + 1); ++(i)) {         if (!visited[i]) {           level1[i] = 0;           DFS2(i, i);         }       }       for (int(i) = (1); (i) < (n + 1); ++(i)) {       }       for (auto &(t1) : (edges)) {         if (isbridge[t1.second]) {           if (level1[comp2[t1.first.first.first]] <               level1[comp2[t1.first.first.second]]) {             swap(t1.first.first.first, t1.first.first.second);           }           if (mp1.count(make_pair(comp2[t1.first.first.first],                                   comp2[t1.first.first.second])) == 0) {             mp1[make_pair(comp2[t1.first.first.first],                           comp2[t1.first.first.second])] = countPairNodes++;           }           assert(level1[comp2[t1.first.first.first]] -                      level1[comp2[t1.first.first.second]] ==                  1);           edgeList[mp1[make_pair(comp2[t1.first.first.first],                                  comp2[t1.first.first.second])]]               .push_back(t1.second);         }       }       if (component[s] != component[t]) {         if (ignoreEdge == -1) {           answer.val = 0;           answer.edges.clear();         } else {           answer.val = edges[ignoreEdge].first.second;           answer.edges = {ignoreEdge + 1};         }         return;       } else {         int s1 = s;         int t1 = t;         s1 = comp2[s1];         t1 = comp2[t1];         if (s1 == t1) {           answer.val = INT_MAX;           answer.edges.clear();           return;         }         int lca = LCA(s1, t1);         vector<pair<int, int> > listNodes;         fillListNodes(listNodes, s1, t1);         answerType temp;         bool poss = false;         for (auto &(t1) : (listNodes)) {           if (edgeList[mp1[t1]].size() == 1) {             answerType currentAnswer;             if (ignoreEdge == -1) {               poss = true;               currentAnswer.val = edges[edgeList[mp1[t1]][0]].first.second;               currentAnswer.edges = {edgeList[mp1[t1]][0] + 1};             } else {               poss = true;               currentAnswer.val = edges[edgeList[mp1[t1]][0]].first.second +                                   edges[ignoreEdge].first.second;               currentAnswer.edges = {edgeList[mp1[t1]][0] + 1, ignoreEdge + 1};             }             if (currentAnswer.val < answer.val) {               answer = currentAnswer;             }           }         }         if (!poss) {           answer.val = INT_MAX;           answer.edges.clear();         }       }     };   };   vector<pair<pair<pair<int, int>, int>, int> > edges;   vector<pair<pair<int, int>, int> > Adj[1010];   bool visited[1010];   vector<int> answerPath;   answerType answer;   vector<int> path;   void DFSPath(int u, int p, int end1) {     visited[u] = true;     if (u == end1) {       answerPath = path;     }     for (auto &(t1) : (Adj[u])) {       if (!visited[t1.first.first] && t1.first.first != p) {         path.push_back(t1.second);         DFSPath(t1.first.first, u, end1);         path.pop_back();       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int s, t;     scanf( %d%d , &s, &t);     for (int(i) = (0); (i) < (m); ++(i)) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       edges.push_back(make_pair(make_pair(make_pair(a, b), c), i));       Adj[a].push_back(make_pair(make_pair(b, c), i));       Adj[b].push_back(make_pair(make_pair(a, c), i));     }     solve tryAll = solve(s, t, -1, edges, n, m);     tryAll.findAnswer();     if (tryAll.answer.val < answer.val) {       answer = tryAll.answer;     }     DFSPath(s, 0, t);     for (auto &(t1) : (answerPath)) {       solve tryAll = solve(s, t, t1, edges, n, m);       tryAll.findAnswer();       if (tryAll.answer.val < answer.val) {         answer = tryAll.answer;       }     }     if (answer.val == INT_MAX) {       printf( -1 n );     } else {       printf( %d n , answer.val);       printf( %d n , (int)answer.edges.size());       for (auto &(t1) : (answer.edges)) {         printf( %d  , t1);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300 * 1000 + 9;   const int LOGN = 19;   const int M = 21;   const long long INF64 = 1e18;   int n, m, q;   vector<pair<int, int> > g[N];   int p[LOGN][N];   int tin[N], tout[N], T;   long long h[N];   set<pair<int, int> > badEdges;   long long d[M + M][N];   bool u[N];   void dfs(int v, int pr) {     tin[v] = T++;     p[0][v] = pr;     u[v] = true;     for (int i = 1; i < LOGN; ++i) p[i][v] = p[i - 1][p[i - 1][v]];     for (auto e : g[v]) {       int to = e.first, len = e.second;       if (!u[to]) {         h[to] = h[v] + len;         dfs(to, v);         if (v < to)           badEdges.erase(make_pair(v, to));         else           badEdges.erase(make_pair(to, v));       }     }     tout[v] = T;   }   bool isAncestor(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   int getLCA(int a, int b) {     if (isAncestor(a, b)) return a;     if (isAncestor(b, a)) return b;     for (int i = LOGN - 1; i >= 0; --i)       if (!isAncestor(p[i][a], b)) a = p[i][a];     return p[0][a];   }   void dij(int st, long long d[N]) {     set<pair<long long, int> > q;     for (int i = 0; i < n; ++i) d[i] = INF64;     d[st] = 0;     q.insert(make_pair(d[st], st));     while (!q.empty()) {       int v = q.begin()->second;       q.erase(q.begin());       for (auto e : g[v]) {         int to = e.first, len = e.second;         if (d[to] > d[v] + len) {           q.erase(make_pair(d[to], to));           d[to] = d[v] + len;           q.insert(make_pair(d[to], to));         }       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       --u, --v;       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));     }     for (int v = 0; v < n; ++v)       for (auto e : g[v])         if (v < e.first) badEdges.insert(make_pair(v, e.first));     dfs(0, 0);     int cpos = 0;     for (auto e : badEdges) dij(e.first, d[cpos++]);     scanf( %d , &q);     for (int tc = 0; tc < q; ++tc) {       int u, v;       scanf( %d %d , &u, &v);       --u, --v;       int lca = getLCA(u, v);       long long ans = h[u] + h[v] - 2 * h[lca];       for (int i = 0; i < badEdges.size(); ++i) ans = min(ans, d[i][u] + d[i][v]);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     int n;     scanf( %d , &n);     if ((n * n) % 2 == 1) {       printf( %d n , ((n * n) / 2) + 1);     } else {       printf( %d n , (n * n) / 2);     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         if ((i + j) % 2 == 0) {           printf( C );         } else {           printf( . );         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<20> a;   vector<int> w;   int sol = 0;   void verific(int &l, int &r, int &x) {     int sum = 0, i, minim = INT_MAX, maxim = INT_MIN;     for (i = 0; i < w.size(); ++i) {       if (a[i]) {         sum += w[i];         minim = min(minim, w[i]);         maxim = max(maxim, w[i]);       }     }     if (sum >= l and sum <= r and maxim - minim >= x) ++sol;   }   int main() {     int n, i, val, l, r, x;     cin >> n >> l >> r >> x;     for (i = 1; i <= n; ++i) {       cin >> val;       w.push_back(val);     }     for (i = 1; i <= 1 << n; ++i) {       a = i;       if (i & (i - 1) == 0) continue;       verific(l, r, x);     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     cin >> s;     int arr[10] = {0};     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  L ) {         int i = 0;         for (; i < 10; i++) {           if (arr[i] == 0) break;         }         arr[i] = 1;       } else if (s[i] ==  R ) {         int i = 9;         for (; i >= 0; i--) {           if (arr[i] == 0) break;         }         arr[i] = 1;       } else {         int t = s[i] - 48;         arr[t] = 0;       }     }     for (int i = 0; i < 10; i++) cout << arr[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int ok(double x, double a[]) {     double z1 = 0, z2 = 0;     for (int i = 0; i < n; i++) {       if (x - a[i] > 0) {         z1 += x - a[i];       }       if (x - a[i] < 0) {         double ans = 1 - (k * (double)1) / 100;         z2 += (a[i] - x) * ans;       }     }     if (z1 <= z2) {       return 1;     }     return 0;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     double a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     double ans = 0, low = 0, high = 10000;     int z = 0;     while (low < high) {       z++;       double mid = (low + high) / 2;       if (ok(mid, a) == 1) {         low = mid;         ans = mid;       } else {         high = mid;       }       if (z == 999) {         break;       }     }     cout << setprecision(12) << ans;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   bool FLAG = 0;   using namespace std;   const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222;   const long long INF = (long long)1e18;   long long dx[] = {0, -1, 0, 1, 0};   long long dy[] = {0, 0, 1, 0, -1};   long long b[N];   inline void solve() {     long long n;     cin >> n;     long long k = 1;     vector<long long> v;     while (n != 0) {       if (n < k) {         v.push_back(n);         n = 0;         break;       }       n -= k;       v.push_back(k);       k += k;     }     sort(v.begin(), v.end());     cout << (long long)(v.size()) - 1 << endl;     for (long long i = 1; i < (long long)(v.size()); ++i) {       cout << v[i] - v[i - 1] <<    ;     }     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200005];   int t1[200005], t2[200005];   bool vis[200005];   int n, x, a, b;   void dfs1(int step, int t) {     t1[step] = t;     vis[step] = true;     for (int i = 0; i < v[step].size(); i++) {       if (!vis[v[step][i]]) dfs1(v[step][i], t + 1);     }   }   void dfs2(int step, int t) {     t2[step] = t;     vis[step] = true;     for (int i = 0; i < v[step].size(); i++) {       if (!vis[v[step][i]]) dfs2(v[step][i], t + 1);     }   }   int main() {     cin >> n >> x;     for (int i = 1; i <= n - 1; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     memset(vis, false, sizeof(vis));     dfs1(1, 0);     memset(vis, false, sizeof(vis));     dfs2(x, 0);     int maxl = 0;     for (int i = 1; i <= n; i++) {       if (t1[i] > t2[i]) maxl = max(maxl, 2 * t1[i]);     }     cout << maxl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n, k, temp;       cin >> n >> k;       set<int> s;       for (int i = 0; i < n; i++) {         cin >> temp;         s.insert(temp);       }       set<int>::reverse_iterator it;       int count = 0;       for (it = s.rbegin(); it != s.rend(); it++) {         if ((*it - k * count) <= 0) break;         count++;       }       cout << count <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #define int long long   using namespace std;      long long gcd(long long a, long long b)   {       if(!b)           return a;       return gcd(b, a % b);   }      long long lcm(long long a, long long b)   {       long long z = gcd(a, b);       a /= z;       if(a > 1e18 / b)           return -1;       return a * b;   }   const int MOD = 1e9 + 7;   int inv(int x)   {       int y = MOD - 2, r = 1;       while(y)       {           if(y&1)               r=1LL*r*x%MOD;           y>>=1;           x=1LL*x*x%MOD;       }       return r;   }   int32_t main()   {       long long n;       int t;       cin >> t;       while(t--)       {          cin >> n;           long long q = 1, ans = 0;              for(int i = 1; i <= 1000; ++i)           {                  long long p = lcm(q, i);                  if(p == -1)                   break;               else                   q = p;               long long mul = (i + 1) / gcd(q, (i + 1));               long long divI = n / q, t3 = divI / mul;               long long pqr = divI - t3;               long long qq = (1LL * pqr * (i + 1)) % MOD;               ans = (ans + qq) % MOD;           }           cout << ans <<   n ;          }   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1000005, Mod = 1e9 + 7;   const int Mod1 = 1e9 + 7, Mod2 = 1e9 + 9;   char A[Nmax], B[Nmax];   int hash1[Nmax], hash2[Nmax];   int inv_hash1[Nmax], inv_hash2[Nmax];   int main() {     ios::sync_with_stdio(false);     int N, M;     cin >> N >> M;     cin >> (B + 1);     int K = strlen(B + 1);     for (int i = 1; i <= K; ++i) {       hash1[i] = (27LL * hash1[i - 1] + B[i] -  a  + 1) % Mod1;       hash2[i] = (27LL * hash2[i - 1] + B[i] -  a  + 1) % Mod2;     }     for (int i = K, pw1 = 1, pw2 = 1; i > 0; --i) {       inv_hash1[i] = (inv_hash1[i + 1] + 1LL * (B[i] -  a  + 1) * pw1) % Mod1;       inv_hash2[i] = (inv_hash2[i + 1] + 1LL * (B[i] -  a  + 1) * pw2) % Mod2;       pw1 = 27LL * pw1 % Mod1;       pw2 = 27LL * pw2 % Mod2;     }     set<int> insertions;     bool goodSol = true;     while (M-- > 0) {       int left;       cin >> left;       int right = left + K - 1;       auto it = insertions.upper_bound(left);       if (it != insertions.begin()) {         --it;         int p = *it;         if (p + K - 1 >= left) {           int p1 = p + K - left, p2 = K - p1 + 1;           if (hash1[p1] != inv_hash1[p2] || hash2[p1] != inv_hash2[p2]) {             goodSol = false;             break;           }         }       }       it = insertions.lower_bound(left);       if (it != insertions.end()) {         int p = *it;         if (p <= right) {           int p1 = right - p + 1, p2 = K - p1 + 1;           if (hash1[p1] != inv_hash1[p2] || hash2[p1] != inv_hash2[p2]) {             goodSol = false;             break;           }         }       }       insertions.insert(left);     }     if (goodSol == false)       cout <<  0 n ;     else {       int ans = 1;       for (int i = 1; i <= N; ++i) {         auto it = insertions.upper_bound(i);         if (it != insertions.begin()) {           --it;           int p = *it;           if (p + K - 1 < i) ans = 26LL * ans % Mod;         } else {           ans = 26LL * ans % Mod;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     long long ans = 0;     unordered_map<int, int> m;     for (int r = 0, l = 0; r < n; r++) {       m[v[r]]++;       while (m[v[r]] >= k) {         m[v[l++]]--;       }       ans += l;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void yash() {     int arr[4], count = 1;     for (int i = 0; i < 4; i++) {       cin >> arr[i];     }     sort(arr, arr + 4);     for (int i = 0; i < 3; i++) {       if (arr[i] != arr[i + 1]) {         count++;       }     }     cout << 4 - count <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     yash();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, x;     cin >> n >> m;     x = m - n;     if (x >= 2 && n % 2 == 0)       cout << n <<     << n + 1 <<     << n + 2 << endl;     else if (x >= 3 && n % 2 != 0)       cout << n + 1 <<     << n + 2 <<     << n + 3 << endl;     else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000 + 5;   int n, m;   int l[N][N], r[N][N], cnt[N], fen[N];   char s[N][N];   vector<int> del[N];   void up(int x, int k) {     cnt[x] += k;     for (; x; x -= x & -x) fen[x] += k;   }   int get(int x) {     int res = 0;     for (; x < N; x += x & -x) res += fen[x];     return res;   }   long long start(int x, int y) {     memset(fen, 0, sizeof(fen));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; i++) del[i].clear();     long long ans = 0;     int go = x;     while (x <= n and y >= 1) {       for (auto u : del[x]) up(u, -1);       if (s[x][y] ==  . ) {         for (int i = go; i < x; i++)           if (cnt[i]) up(i, -1);         go = x + 1;         x++;         y--;         continue;       }       up(x, +1);       if (x + l[x][y] <= n) del[x + l[x][y]].push_back(x);       int len = min(r[x][y], x - go + 1);       ans += get(x - len + 1);       x++;       y--;     }     return ans;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; j++) {         l[i][j] = s[i][j] ==  z  ? l[i][j - 1] + 1 : 0;       }       for (int j = m; j >= 1; j--) {         r[i][j] = s[i][j] ==  z  ? r[i][j + 1] + 1 : 0;       }     }     long long ans = 0;     for (int i = 1; i <= m; i++) {       ans += start(1, i);     }     for (int i = 2; i <= n; i++) {       ans += start(i, m);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111111], b[111111];   vector<int> v;   long long t[555][555];   int main() {     int n;     cin >> n;     int r, c;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> t[i][j];         if (t[i][j] == 0) {           r = i;           c = j;         }       }     }     if (n == 1) {       cout <<  1  << endl;       return 0;     }     long long sum = 0;     if (r == 0) {       for (int i = 0; i < n; i++) sum += t[1][i];     } else {       for (int i = 0; i < n; i++) sum += t[0][i];     }     long long lel = 0;     for (int i = 0; i < n; i++) {       lel += t[r][i];     }     if (lel >= sum) {       cout <<  -1 ;       return 0;     }     t[r][c] = sum - lel;     for (int i = 0; i < n; i++) {       long long cur = 0;       for (int j = 0; j < n; j++) {         cur += t[i][j];       }       if (cur != sum) {         cout <<  -1 ;         return 0;       }     }     for (int i = 0; i < n; i++) {       long long cur = 0;       for (int j = 0; j < n; j++) {         cur += t[j][i];       }       if (cur != sum) {         cout <<  -1 ;         return 0;       }     }     long long cur = 0;     for (int i = 0; i < n; i++) {       cur += t[i][i];     }     if (cur != sum) {       cout <<  -1 ;       return 0;     }     cur = 0;     for (int i = 0; i < n; i++) {       cur += t[i][n - 1 - i];     }     if (cur != sum) {       cout <<  -1 ;       return 0;     }     cout << t[r][c];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;   long long c[maxn][maxn], pw[2][maxn], f[maxn][maxn];   inline int add(long long a, long long b) {     a += b;     return a >= mod ? a - mod : a;   }   inline int mul(long long a, long long b) { return a * b % mod; }   inline long long kpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   void init(int n, int m) {     for (int i = 0; i <= n; ++i) c[i][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= i; ++j)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     for (int i = 0; i <= n; ++i) {       pw[0][i] = kpow(m - 1, i);       pw[1][i] = kpow(m, i);     }   }   int main() {     int n, m;     cin >> n >> m;     init(n, m);     f[0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= n; ++j) {         for (int k = 1; k <= j; ++k)           f[i][j] =               add(f[i][j],                   mul(mul(mul(f[i - 1][j - k], c[n - j + k][k]), pw[1][j - k]),                       pw[0][n - j]));         f[i][j] =             add(f[i][j], mul(f[i - 1][j], mul((pw[1][j] - pw[0][j] + mod) % mod,                                               kpow(m - 1, n - j))));       }     cout << f[n][n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INT_INF = 1e9;   const long long LL_INF = 1e18;   int getInt(char c) { return c -  0 ; }   int getDistance(int index, int y, int z, vector<vector<int>>& last) {     int p = last[index][y];     if (p == -1) return INT_INF;     int q = last[p][z];     if (q == -1) return INT_INF;     return index - q + 1;   }   int main() {     int tt;     cin >> tt;     while (tt--) {       string s;       cin >> s;       int n = (int)s.size();       vector<vector<int>> last(n, vector<int>(3, -1));       last[0][getInt(s[0]) - 1] = 0;       int ans = INT_INF;       for (int i = 1; i < n; i++) {         int u = getInt(s[i]) - 1;         for (int j = 0; j < 3; j++) {           if (u == j)             last[i][u] = i;           else             last[i][j] = last[i - 1][j];         }         if (u == 0) {           ans = min(ans, getDistance(i, 1, 2, last));           ans = min(ans, getDistance(i, 2, 1, last));         } else if (u == 1) {           ans = min(ans, getDistance(i, 0, 2, last));           ans = min(ans, getDistance(i, 2, 0, last));         } else {           ans = min(ans, getDistance(i, 0, 1, last));           ans = min(ans, getDistance(i, 1, 0, last));         }       }       cout << (ans == INT_INF ? 0 : ans) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, tmp, ans = 0, mx = -1;     cin >> n;     for (int i = 0; i < n && cin >> tmp; ++i) mx = max(tmp, mx);     cout << (mx > 25 ? mx - 25 : 0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 212345, LG = 21, mod = 1000000007;   const double eps = 1e-3, pi = acos(-1.0);   int in[N];   vector<int> adj[N];   map<pair<int, int>, int> mp;   set<pair<int, int>> s;   int main() {     int n, m;     scanf( %d , &n), scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d , &u), scanf( %d , &v);       adj[u].push_back(v);       mp[{u, v}] = i;       in[v]++;     }     for (int i = 1; i <= n; ++i) s.insert({in[i], i});     int ans = -1;     while (s.size() > 1) {       int t = s.begin()->second;       s.erase(s.begin());       if (in[t] != 0) {         ans = -1;         break;       }       if (s.begin()->first == 0) {         ans = -1;         break;       }       for (int i = 0; i < adj[t].size(); ++i) {         int u = adj[t][i];         s.erase({in[u], u});         in[u]--;         s.insert({in[u], u});       }       ans = max(ans, mp[{t, s.begin()->second}]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int A = 100000, MD = 998244353;   int kk[A + 1];   int pp[A + 1][6][6], aa[6][6], tt[6][6];   int uu_[6], vv_[6], *uu = uu_, *vv = vv_;   int kp[A + 1];   bool sq[A + 1];   void init(int *aa, int a0, int a1, int a2, int a3, int a4, int a5) {     aa[0] = a0, aa[1] = a1, aa[2] = a2, aa[3] = a3, aa[4] = a4, aa[5] = a5;   }   void init(int aa[][6], int x) {     int x2 = x * 2 % MD;     int xx = (long long)x * x % MD;     init(aa[0], 2, 1, x2, x2, xx, xx);     init(aa[1], 0, 2, 0, x2, 0, xx);     init(aa[2], 0, 0, 2, 1, x, x);     init(aa[3], 0, 0, 0, 2, 0, x);     init(aa[4], 0, 0, 0, 0, 2, 1);     init(aa[5], 0, 0, 0, 0, 0, 2);   }   void mult(int aa[][6], int *uu, int *vv) {     for (int i = 0; i < 6; i++) {       long long v = 0;       for (int j = 0; j < 6; j++) v += (long long)aa[i][j] * uu[j];       vv[i] = v % MD;     }   }   void mult(int aa[][6], int bb[][6], int cc[][6]) {     for (int i = 0; i < 6; i++)       for (int j = 0; j < 6; j++) {         long long c = 0;         for (int k = 0; k < 6; k++) c += (long long)aa[i][k] * bb[k][j];         cc[i][j] = c % MD;       }   }   void power(int aa[][6], int pp[][6], int tt[][6], int k) {     if (k == 0) {       for (int i = 0; i < 6; i++) {         for (int j = 0; j < 6; j++) pp[i][j] = 0;         pp[i][i] = 1;       }       return;     }     if (k & 1) {       power(aa, pp, tt, k >> 1);       mult(pp, pp, tt);       mult(tt, aa, pp);     } else {       power(aa, tt, pp, k >> 1);       mult(tt, tt, pp);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m;     cin >> m;     while (m--) {       int a, k;       cin >> a >> k;       kk[a] = k;       init(aa, a);       power(aa, pp[a], tt, k);     }     long long ans = 0;     for (int a = 1; a <= A; a++) {       if (sq[a]) continue;       if (a > 1 && kp[a] == 0) {         for (int b = a; b <= A; b += a) kp[b]++;         if (a <= A / a)           for (int s = a * a, t = s; t <= A; t += s) sq[t] = true;       }       fill(uu, uu + 6, 0);       uu[5] = 1;       for (int b = a; b <= A; b += a)         if (kk[b] > 0) {           mult(pp[b], uu, vv);           swap(uu, vv);         }       int z = uu[0] - uu[1];       ans += kp[a] % 2 == 0 ? z : -z;     }     ans %= MD;     if (ans < 0) ans += MD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, K, p;   char s[11];   int calc(int x, int y) {     printf( 1 %d %d n , x, y);     fflush(stdout);     scanf( %s , s + 1);     return s[1] ==  T ;   }   int find(int l, int r) {     while (l < r) {       int mid = (l + r) >> 1;       if (calc(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     scanf( %d%d , &n, &K);     p = find(1, n);     int l = 1, r = p;     while (l < r) {       int mid = (l + r + 1) >> 1;       if (calc(mid - 1, mid)) return printf( 2 %d %d n , p, find(l, mid - 1)), 0;       l = mid;     }     l = p;     r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (calc(mid + 1, mid)) return printf( 2 %d %d n , p, find(mid + 1, r)), 0;       r = mid;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 100;   int n, k;   char str[N];   bool f[N];   int main() {     scanf( %s , str + 1), n = strlen(str + 1);     while (1 << k < n) ++k;     if (1 << k > n) --k;     memset(f, 1, sizeof(f));     for (int i = 1; i <= n - (1 << k) + 1; ++i) {       char ch =  z ;       for (int s = 0; s < 1 << k; ++s)         if (f[s])           for (int t = 0; t < k; ++t) f[s | (1 << t)] = 1;       for (int s = 0; s < 1 << k; ++s)         if (f[s]) ch = min(str[i + s], ch);       for (int s = 0; s < 1 << k; ++s)         if (str[i + s] != ch) f[s] = 0;       putchar(ch);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     cin >> l >> r;     while (l <= r) {       int arr[9] = {0};       int x = l;       bool diff = 1;       while (x) {         int num = x % 10;         x /= 10;         if (arr[num]) {           diff = 0;           l++;           break;         }         arr[num]++;       }       if (diff) {         cout << l << endl;         return 0;       }     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s, str;   long long mns, all, pls, nom, maxi, mini, n, sum, otn;   vector<char> v;   vector<long long> ans;   int main() {     getline(cin, s);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  - ) mns++;       if (s[i] ==  ? ) all++;       if (s[i] ==  = ) nom = i;     }     pls = all - mns;     string str;     str = s.substr(nom + 2, s.size() - nom - 2);     n = atoll(str.c_str());     maxi = n * pls - mns;     mini = pls - mns * n;     if (n < mini || n > maxi) {       cout <<  Impossible ;       return 0;     }     cout <<  Possible n ;     v.push_back( + );     for (int i = 0; i < s.size(); i++)       if (s[i] ==  + )         v.push_back( + );       else if (s[i] ==  - )         v.push_back( - );     for (int i = 0; i < v.size(); i++)       if (v[i] ==  + )         ans.push_back(n);       else         ans.push_back(1);     sum = maxi;     for (int i = 0; i < ans.size(); i++)       if (sum > n)         if (v[i] ==  + ) {           otn = min(n - 1, sum - n);           ans[i] -= otn;           sum -= otn;         } else {           otn = min(n - 1, sum - n);           ans[i] += otn;           sum -= otn;         }     cout << ans[0] <<    ;     for (int i = 1; i < v.size(); i++) cout << v[i] <<     << ans[i] <<    ;     cout <<  =   << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};     long a, b;     cin >> a;     cin >> b;     int count = 0;     int i;     long x;     do {       x = a;       while (x >= 10) {         i = x % 10;         count += m[i];         x /= 10;       }       count += m[x];       a++;     } while (a <= b);     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll cnt_inv[30][2];   void rec(vector<int>& a, int b) {     if (b < 0 || a.empty()) return;     vector<int> s, us;     for (int& i : a) {       int val = i & (1 << b);       if (val)         cnt_inv[b][1] += us.size(), s.push_back(i);       else         cnt_inv[b][0] += s.size(), us.push_back(i);     }     rec(s, b - 1);     rec(us, b - 1);   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); i++) cin >> a[i];     memset(cnt_inv, 0, sizeof cnt_inv);     rec(a, 29);     ll inv = 0, x = 0;     for (int b = 29; b >= 0; b--) {       inv += min(cnt_inv[b][0], cnt_inv[b][1]);       int val = 1;       if (cnt_inv[b][0] <= cnt_inv[b][1]) val = 0;       x += (val << b);     }     cout << inv <<     << x <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   namespace LYYY {   int read() {     int s = 0;     char c = getchar();     int f = 1;     while (c < 48 || c > 57) {       if (c == 45) f = -1;       c = getchar();     }     while (c >= 48 && c <= 57) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     return s * f;   }   long long readl() {     long long s = 0;     char c = getchar();     int f = 1;     while (c < 48 || c > 57) {       if (c == 45) f = -1;       c = getchar();     }     while (c >= 48 && c <= 57) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     return s * f;   }   void write(int x) {     if (x >= 10) write(x / 10);     putchar(x % 10 + 48);   }   void W(int x) {     if (x < 0) x = -x, putchar(45);     write(x);   }   void writel(long long x) {     if (x >= 10) write(x / 10);     putchar(x % 10 + 48);   }   void Wl(long long x) {     if (x < 0) x = -x, putchar(45);     write(x);   }   }  // namespace LYYY   using namespace LYYY;   const int mod = 1000 * 1000 * 1000 + 7;   int mul(int x, long long k) {     long long ans = 1, mid = x;     while (k) {       if (k & 1) ans = ans * mid % mod;       mid = mid * mid % mod;       k >>= 1;     }     return ans;   }   int Get(long long n, int x) {     if (n < x) return 1;     return (long long)mul(x, n / x) * Get(n / x, x) % mod;   }   int main() {     int x = read();     long long n = readl(), ans = 1;     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) {         ans = ans * Get(n, i) % mod;         while (x % i == 0) x /= i;       }     if (x > 1) ans = ans * Get(n, x) % mod;     writel(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[111];   int main() {     int n;     scanf( %d , &n);     arr[0] = 0;     for (int i = (1); i < (n + 1); ++i) scanf( %d , &arr[i]);     int ans = 0;     if (n % 2 == 0 || n == 1) {       printf( -1 n );       return 0;     }     for (int i = n; i >= 1; i -= 2) {       int tmp = max(arr[i], arr[i - 1]);       ans += tmp;       arr[i] = arr[i - 1] = 0;       arr[(i - 1) / 2] = max(0, arr[(i - 1) / 2] - tmp);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct msg {     long long lstl = 0;     long long lstr = 0;     long long num = 0;   };   int32_t main() {     long long n, k;     cin >> n >> k;     long long a[n];     msg ms[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       if (a[i] == 0) {         ms[i].lstl = max(i - k, 0LL);         ms[i].lstr = min(i + k, n - 1);         ms[i].num = 1 + ms[i].lstr - ms[i].lstl;       } else {         ms[i].lstl = max(i - k, 0LL);         ms[i].lstr = min(i + k, n - 1);         long long nmr, nml;         if (ms[i].lstl <= ms[a[i] - 1].lstr) {           if (ms[a[i] - 1].lstr < i) {             nml = k - (ms[a[i] - 1].lstr - ms[i].lstl + 1);           } else {             nml = 0;           }         } else {           nml = i - ms[i].lstl;         }         if (ms[a[i] - 1].lstr < i) {           nmr = ms[i].lstr - i + 1;         } else if (ms[a[i] - 1].lstr == i) {           nmr = ms[i].lstr - i;         } else {           nmr = ms[i].lstr - ms[a[i] - 1].lstr;         }         ms[i].num = nmr + nml + ms[a[i] - 1].num;       }     }     for (long long i = 0; i < n; i++) {       cout << ms[i].num <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 11);   const int maxs = 27;   string s[maxn];   vector<int> NextIn[maxn][maxs];   int NextOut[maxn][maxs], First[maxn][maxs], a[maxn];   pair<int, int> dp[maxn][maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(First, 63, sizeof First);     memset(NextOut, 63, sizeof NextOut);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];       int m = s[i].size();       for (int ch = 0; ch < maxs; ch++) NextIn[i][ch].resize(m);       for (int j = m - 1; j >= 0; j--)         for (int ch = 0; ch < maxs; ch++) {           if (j + 1 < m && s[i][j + 1] == ch +  a )             NextIn[i][ch][j] = j + 1;           else if (j + 1 < m)             NextIn[i][ch][j] = NextIn[i][ch][j + 1];           else             NextIn[i][ch][j] = 1e9;         }       for (int j = m - 1; j >= 0; j--) First[i][s[i][j] -  a ] = j;     }     int m;     cin >> m;     for (int i = 0; i < m; i++) cin >> a[i], a[i]--;     for (int i = m - 1; i >= 0; i--)       for (int ch = 0; ch < maxs; ch++) {         if (i + 1 < m && First[a[i + 1]][ch] < 1e7)           NextOut[i][ch] = i + 1;         else           NextOut[i][ch] = NextOut[i + 1][ch];       }     string t;     cin >> t;     int k = t.size();     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++) dp[i][j] = {1e9, 1e9};     dp[0][0] = {0, -1};     for (int i = 1; i <= k; i++)       for (int j = 0; j <= k; j++) {         int ch = t[i - 1] -  a ;         dp[i][j] = dp[i - 1][j];         if (!j) continue;         auto tmp = dp[i - 1][j - 1];         if (tmp.first >= m) continue;         int ind = a[tmp.first];         if (tmp.second == -1 && First[ind][ch] < 1e7)           dp[i][j] = min(dp[i][j], make_pair(tmp.first, First[ind][ch]));         else if (tmp.second != -1 && NextIn[ind][ch][tmp.second] < 1e7)           dp[i][j] =               min(dp[i][j], make_pair(tmp.first, NextIn[ind][ch][tmp.second]));         if (NextOut[tmp.first][ch] < m) {           int pt = NextOut[tmp.first][ch];           dp[i][j] = min(dp[i][j], make_pair(pt, First[a[pt]][ch]));         }       }     int ans = 0;     while (ans + 1 <= k && dp[k][ans + 1].first < m) ans++;     cout << ans << endl;   }