#include <bits/stdc++.h>   using namespace std;   int a[1001][1001];   vector<pair<pair<int, int>, char> > start;   int row[1001][1001], col[1001][1001];   pair<char, int> dir[100001];   vector<char> ans;   void init() {     for (int i = 0; i < 1001; i++) {       for (int j = 0; j < 1001; j++) a[i][j] = -1;     }   }   int main() {     int i, j, n, m, x, y, k, len, f;     string str;     cin >> n >> m;     init();     for (i = 1; i <= n; i++) {       cin >> str;       str =     + str;       for (j = 1; j <= m; j++) {         if (str[j] ==  # )           a[i][j] = -1;         else if (str[j] ==  . )           a[i][j] = 0;         else {           start.push_back(make_pair(make_pair(i, j), str[j]));           a[i][j] = 0;         }       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) row[i][j] = row[i][j - 1] + a[i][j];     }     for (j = 1; j <= m; j++) {       for (i = 1; i <= n; i++) col[j][i] = col[j][i - 1] + a[i][j];     }     cin >> k;     for (i = 1; i <= k; i++) cin >> dir[i].first >> dir[i].second;     for (i = 0; i < start.size(); i++) {       x = start[i].first.first;       y = start[i].first.second;       f = 0;       for (j = 1; j <= k; j++) {         len = dir[j].second;         if (dir[j].first ==  N ) {           if (x - len < 1) {             f = 1;             break;           } else if (col[y][x] - col[y][x - len - 1] != 0) {             f = 1;             break;           } else             x = x - len;         } else if (dir[j].first ==  S ) {           if (x + len > n) {             f = 1;             break;           } else if (col[y][x + len] - col[y][x - 1] != 0) {             f = 1;             break;           } else             x = x + len;         } else if (dir[j].first ==  E ) {           if (y + len > m) {             f = 1;             break;           } else if (row[x][y + len] - row[x][y - 1] != 0) {             f = 1;             break;           } else             y = y + len;         } else {           if (y - len < 1) {             f = 1;             break;           } else if (row[x][y] - row[x][y - len - 1] != 0) {             f = 1;             break;           } else             y = y - len;         }       }       if (!f) ans.push_back(start[i].second);     }     if (!ans.size()) {       cout <<  no solution ;       return 0;     }     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++) cout << ans[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<char> s(n + 1), t(n + 1);     scanf( %s , &s[0]);     scanf( %s , &t[0]);     long long ans = 0;     long long cnt_a = 0;     long long cnt_b = 0;     bool found_diff = false;     bool big_num = false;     for (int i = 0; i < n; ++i) {       if (found_diff && !big_num) {         cnt_a = cnt_a * 2 + (s[i] ==  a  ? 1 : 0);         cnt_b = cnt_b * 2 + (t[i] ==  b  ? 1 : 0);       }       if (s[i] != t[i]) {         found_diff = true;       }       if (found_diff) {         ans += min(cnt_a + cnt_b + 2, (long long)k);         if (cnt_a + cnt_b + 2 >= k) {           big_num = true;         }       } else {         ++ans;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[101];   int dp[101][1 << 17];   int M[61];   vector<int> prime;   bool isprime(int num) {     int i;     for (i = 2; i < num; ++i) {       if (num % i == 0) return 0;     }     return 1;   }   void pre() {     int i, j;     for (i = 2; i < 60; ++i) {       if (isprime(i)) prime.push_back(i);     }     memset(M, 0, sizeof(M));     for (i = 2; i <= 60; ++i) {       for (j = 0; j < prime.size(); ++j) {         if (i % prime[j] == 0) M[i] = M[i] + (1 << j);       }     }   }   vector<int> ans;   int f(int pos, int mask) {     int i;     if (pos == n)       return 0;     else if (dp[pos][mask] != -1)       return dp[pos][mask];     else {       int tmp = INT_MAX;       for (i = 1; i <= 2 * a[pos]; ++i) {         if ((mask & M[i]) == 0)           tmp = min(tmp, abs(a[pos] - i) + f(pos + 1, mask | M[i]));       }       return dp[pos][mask] = tmp;     }   }   void rec(int pos, int mask) {     int i;     if (pos == n)       return;     else {       for (i = 1; i <= 2 * a[pos]; ++i) {         if ((mask & M[i]) != 0) continue;         if (f(pos, mask) == (abs(a[pos] - i) + f(pos + 1, mask | M[i]))) {           ans.push_back(i);           rec(pos + 1, mask | M[i]);           return;         }       }     }   }   int main() {     int i;     pre();     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     memset(dp, -1, sizeof(dp));     rec(0, 0);     for (i = 0; i < n; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ask(long long l, long long r) {     printf( %lld %lld n , l, r);     fflush(stdout);     char x[4];     scanf(  %s , x);     return x[0] ==  Y ;   }   long long n, k;   int main() {     cin >> n >> k;     long long l = 1, r = n;     srand(time(0));     while (1) {       if (r - l + 1 <= 50) {         long long q = l + rand() % (r - l + 1);         if (ask(q, q)) return 0;         l = max(1LL, l - k);         r = min(n, r + k);       } else {         long long md = l + ((r - l) >> 1);         if (ask(l, md)) {           l = max(1LL, l - k);           r = min(n, md + k);         } else {           l = max(1LL, md + 1 - k);           r = min(n, r + k);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (int i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1, T;     T = t;     while (t--) {       int n;       cin >> n;       vector<pair<int, int> > kb(n);       vector<pair<pair<long double, int>, int> > v;       vector<pair<long double, int> > minus, plus;       vector<pair<long long, long long> > lines;       long long K = 0, B = 0;       for (int i = 0; i < n; i++) {         cin >> kb[i].first >> kb[i].second;         if (kb[i].first == 0 && kb[i].second == 0)           continue;         else if (kb[i].first == 0) {           if (kb[i].second > 0)             B += kb[i].second;           else             continue;         } else if (kb[i].second == 0) {           if (kb[i].first > 0)             v.push_back(make_pair(make_pair(0, 1), i));           else             v.push_back(make_pair(make_pair(0, -1), i));         } else {           if (kb[i].first > 0)             v.push_back(                 make_pair(make_pair((-1.0 * kb[i].second) / kb[i].first, 1), i));           else             v.push_back(                 make_pair(make_pair((-1.0 * kb[i].second) / kb[i].first, -1), i));         }       }       n = (int)v.size();       int ans = 0;       sort(v.begin(), v.end());       for (int i = 0; i < n; i++) {         if (v[i].first.second == -1) {           K += kb[v[i].second].first;           B += kb[v[i].second].second;         }       }       lines.push_back(make_pair(K, B));       for (int i = 0; i < n; i++) {         long double x = v[i].first.first;         while (i < n && v[i].first.first == x) {           if (v[i].first.second == 1) {             K += kb[v[i].second].first;             B += kb[v[i].second].second;           } else {             K -= kb[v[i].second].first;             B -= kb[v[i].second].second;           }           i++;         }         i--;         lines.push_back(make_pair(K, B));       }       for (int i = 0; i < (int)lines.size() - 1; i++) {         if (lines[i].first != lines[i + 1].first) ans++;       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool used[15];   int main() {     int n, m, a[15], b[15];     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int j = 1; j <= m; j++) cin >> b[j];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i] == b[j] && used[j] == 0) {           used[j] = 1;           cout << a[i] <<    ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, long long>> v[63];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     long long sum = 0;     for (int i = 0; i < n; i++) {       int val;       long long mask;       cin >> val >> mask;       sum += val;       int j = 62;       while (!(mask & (1LL << j))) j--;       v[j].push_back(make_pair(val, mask));     }     if (sum > 0)       for (int j = 0; j < 63; j++)         for (auto& p : v[j]) p.first *= -1;     long long s = 0;     for (int j = 0; j < 63; j++) {       sum = 0;       for (auto& p : v[j]) {         p.second &= s;         int b = 0;         for (int k = 0; k < j; k++)           if (p.second & (1LL << k)) b++;         sum += (b % 2 ? -p.first : p.first);       }       if (sum < 0) s |= (1LL << j);     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);   long long int gcd(long long int a, long long int b);   int prime(int n);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x;       cin >> n >> m;       vector<vector<long long int> > v(n, vector<long long int>(26, 0));       long long int b[26] = {0};       string a;       cin >> a;       for (int i = 0; i < n; i++) {         if (i > 0)           for (int j = 0; j < 26; j++) {             v[i][j] = v[i - 1][j];           }         v[i][a[i] -  a ]++;       }       for (int i = 0; i < m; i++) {         cin >> x;         for (int i = 0; i < 26; i++) {           b[i] += v[x - 1][i];         }       }       for (int i = 0; i < 26; i++) {         b[i] += v[n - 1][i];       }       for (int i = 0; i < 26; i++) cout << b[i] <<    ;       cout << endl;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int prime(int n) {     int flag = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }


#include<bits/stdc++.h>   using namespace std;   template<typename AA>inline void CMax(AA &u,AA v){if(v>u)u=v;}   template<typename AA>inline void CMin(AA &u,AA v){if(v<u)u=v;}   #define Put(a) cout<<(a)<<endl   #define For(a,b,c) for(int a=(b);a<=(c);++a)   #define Fov(a,b,c) for(int a=(b);a>=(c);--a)   #define Foe(a,b,c) for(int a=(b);a<(c);++a)   #define Clear(a,b) memset(a,b,sizeof(a))   const double eps=1E-8;const int Inf=0x3f3f3f3f,oo=0x7fffffff,Mod=998244353;   typedef long long lon;const lon Lnf=0x3f3f3f3f3f3f3f3f;   template<typename AA>void read(AA &x)   {int s=0;char c;while(c=getchar(),(c< 0 ||c> 9 )&&c!= - );c== - ?(s=1,x=0):(x=c- 0 );   while(c=getchar(),c>= 0 &&c<= 9 ) x=x*10+c- 0 ;if(s) x=-x;}   template<typename AA, typename...Args>void read(AA &t,Args &...args)   {read(t);read(args...);}template<typename AA>void print(AA k){int num=0;   static char stk[23];if(k<0){putchar( - );k=-k;}while(k>0)stk[++num]=k%10+48,k/=10;   if(!num)putchar( 0 );else while(num)putchar(stk[num--]);putchar(  n );}   inline int Log2(int x) {if(!x)return 0;else return 31-__builtin_clz(x);}   char getc(){char ch;do{ch=getchar();}while(ch==   ||ch==  n );return ch;}   lon Pow(lon d,lon m){lon f=1;while(m){if(m&1)f=f*d%Mod;d=d*d%Mod;m>>=1;}return f;}   //#include<ext/rope> using namespace __gnu_cxx;   //#include<bits/extc++.h>#include<ext/pb_ds/assoc_container.hpp>   //using namespace __gnu_pbds;   //#pragma GCC optimize(3)   int N,M,S,Q,K,T=1;      int u,v;   char s[300030];      int n;   int nd[300030];   int ansp;char ansc;      void init() {    int cnt[26]={};    For(a,1,n) {     if(cnt[s[a]- a ]==0) nd[a]=nd[a-1]+K-1;     else nd[a]=nd[a-1]-1;        cnt[s[a]- a ]=(cnt[s[a]- a ]+1)%K;        if(a<n&&s[a+1]< z ) {      Fov(b,25,0) {       if( a +b==s[a+1]) break;          if(cnt[b]==0) {        nd[a+1]=nd[a]+K-1;       }       else {        nd[a+1]=nd[a]-1;       }          if(n-a-1>=nd[a+1]&&(n-a-1-nd[a+1])%K==0) ansp=a+1,ansc= a +b;         }     }       }   }         signed main()   {    //freopen( 1.in , r ,stdin);       read(T);    while(T--) {     read(N,K);     scanf( %s ,s+1); n=strlen(s+1);     ansp=1;ansc=s[1]+1;     if(N%K) {puts( -1 );continue;}        init();          //printf( %d %c n ,ansp,ansc);        if(nd[n]==0) {printf( %s n ,s+1);continue;}     if(ansp==1&&ansc> z ) {puts( -1 );continue;}                int cnt[26]={};     s[ansp]=ansc;     For(a,1,ansp) {      cnt[s[a]- a ]=(cnt[s[a]- a ]+1)%K;     }     For(a,0,25) if(cnt[a]!=0) cnt[a]=K-cnt[a];        int now=n;     Fov(a,25,0) {      while(cnt[a]--) s[now--]= a +a;     }     while(now>ansp) s[now--]= a ;        printf( %s n ,s+1);    }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mm = 2;   long long n, m0[mm][mm], m1[mm][mm] = {{0, 1}, {2, 1}}, mz[mm][mm], tmp[mm][mm],                            pwk, dv = 1e9 + 7;   void cop(long long x[mm][mm], long long y[mm][mm]) {     long long i, j;     for (i = 0; i < mm; i++) {       for (j = 0; j < mm; j++) {         y[i][j] = x[i][j];       }     }   }   void mul(long long x[mm][mm], long long y[mm][mm], long long z[mm][mm]) {     long long i, j, r;     for (i = 0; i < mm; i++) {       for (j = 0; j < mm; j++) {         tmp[i][j] = 0;         for (r = 0; r < mm; r++) {           tmp[i][j] = (tmp[i][j] + x[i][r] * y[r][j]) % dv;         }       }     }     cop(tmp, z);   }   long long pw(long long x, long long y) {     if (!y) {       return 1;     }     pwk = pw(x, y / 2);     pwk = pwk * pwk % dv;     if (y % 2) {       pwk = pwk * x % dv;     }     return pwk;   }   void mpw(long long x) {     if (!x) {       cop(m0, mz);       return;     }     mpw(x / 2);     mul(mz, mz, mz);     if (x % 2) {       mul(mz, m1, mz);     }   }   int main() {     long long i, k, dn = 2;     for (i = 0; i < mm; i++) {       m0[i][i] = 1;     }     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &k);       mpw(k);       cop(mz, m1);       dn = pw(dn, k) % dv;     }     printf( %lld/%lld n , mz[0][0] * pw(2, dv - 2) % dv, dn * pw(2, dv - 2) % dv);   }


/**    * Author: lukasdeimos   */      #include<bits/stdc++.h>      #define endl   n       #define ff first   #define ss second      using ll = long long;   using namespace std;      void solve() {    int n,k;    cin >> n >> k;       cout << (n-k+k/2) << endl;    for(int i = k+1; i <= n; i++) cout << i <<    ;    for(int i = (k+1)/2; i < k; i++) cout << i <<    ;    cout << endl;      }      int main() {    ios::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);        ll tt;    tt = 1;     cin >> tt;    for(auto test_case = 1; test_case <= tt; test_case++) {    // cout <<  Case   << test_case <<  :  ;     solve();    }           return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nCr(int n, int r) {     if (r > n - r) r = n - r;     long long ans = 1;     int i;     for (i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long a, b, c, d, e, g, h, n, t, f, k, l, m,         f1 = 0, flag = 0, flag1 = 0, co = 0, co1 = 0, co2 = 0, arr1[100001] = {0},         arr[100001] = {0}, sum = 0, sum1 = 0, ma = 0, mi = 1000000000000000001;     long long co3 = 0, co4 = 0, co5 = 0, co6 = 0, co7 = 0, co8 = 0;     double pi = 2 * acos(0.0);     string str, str1, str2, str3;     char ch;     vector<long long> v;     vector<long long> v1;     vector<string> vs;     vector<string> vs1;     map<int, int> mp;     set<long long> s;     set<long long> s1;     set<long long>::iterator it;     queue<long long> q;     int x[] = {1, 1, 1, 0, 0, -1, -1, -1};     int y[] = {0, 1, -1, 1, -1, 1, -1, 0};     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> c;       mp[c] = 1;     }     for (int i = 1;; i++) {       if (mp[i] == 1)         continue;       else {         b -= i;         if (b < 0) break;         v.push_back(i);       }     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   int n, MOD;   pair<int, int> s[MAXN];   int main() {     scanf( %d , &n);     int m = 0;     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d , &a);       s[++m] = make_pair(a, i);     }     for (int i = 1; i <= n; i++) {       int a, b;       scanf( %d , &a);       s[++m] = make_pair(a, i);     }     sort(s + 1, s + m + 1);     scanf( %d , &MOD);     long long res = 1;     for (int i = 1, j = 1; i <= m; i = j) {       while (j <= m && s[i].first == s[j].first) j++;       int l = j - i;       int t = 0;       for (int k = i + 1; k < j; k++)         if (s[k] == s[k - 1]) t++;       for (int k = 1; k <= l; k++) {         int tk = k;         while (t > 0 && tk % 2 == 0) tk /= 2, t--;         res = (res * tk) % MOD;       }     }     printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  * ) {         for (int j = 1; j < n; j++) {           int t = i;           int k = 0;           while (k < 6 && t < n && s[t] ==  * ) {             t = t + j;             k++;           }           if (k == 5) {             cout <<  yes ;             return 0;           }         }       }     }     cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int aaa = 0;   int n, pown = 1, a[250005], indx, indy, p[250005], lvl[250005], timer,          in[250005], out[250005], pw[4 * 250005], st, en, lc, oo, c[6], ans, q,          typ;   vector<int> v[250005], gg;   pair<int, pair<int, int> > tt[2 * 250005], l[2 * 250005][19], r[2 * 250005][19],       t[4 * 250005];   inline void dfs(int x, int par) {     gg.push_back(x);     p[x] = par;     timer++;     in[x] = timer;     for (int i = 0; i < v[x].size(); i++) {       if (v[x][i] == par) continue;       lvl[v[x][i]] = lvl[x] + 1;       dfs(v[x][i], x);     }     gg.push_back(x);     timer++;     out[x] = timer;   }   inline int lca(int x, int y) {     if (lvl[x] > lvl[y]) swap(x, y);     if (in[x] <= in[y] && out[x] >= out[y]) return x;     int t1 = in[x];     if (t1 > in[y]) t1 = in[y];     int t2 = out[x];     if (t2 < out[y]) t2 = out[y];     int sz = pw[t2 - t1];     pair<int, pair<int, int> > ret = l[t1][sz];     if (ret > r[t2][sz]) ret = r[t2][sz];     return p[gg[ret.second.first - 1]];   }   pair<int, pair<int, int> > doit() {     for (st = 1; st <= 4; st++) {       for (en = st + 1; en <= 4; en++) {         lc = lca(c[st], c[en]);         oo = 1;         for (int i = 1; i <= 4; i++) {           if (!((in[c[i]] <= in[c[st]] && out[c[st]] <= out[c[i]]) ||                 (in[c[i]] <= in[c[en]] && out[c[en]] <= out[c[i]]))) {             oo = 0;             break;           }           if (!(in[lc] <= in[c[i]] && out[c[i]] <= out[lc])) {             oo = 0;             break;           }         }         if (oo) {           break;         }       }       if (oo) break;     }     if (oo)       return make_pair(1, make_pair(c[st], c[en]));     else       return make_pair(0, make_pair(0, 0));   }   void upd(int x) {     if (!x) return;     t[x].first = 0;     if (t[2 * x].first && t[2 * x + 1].first) {       c[1] = t[2 * x].second.first;       c[2] = t[2 * x].second.second;       c[3] = t[2 * x + 1].second.first;       c[4] = t[2 * x + 1].second.second;       t[x] = doit();     }     upd(x / 2);   }   void cnt(int x, int L, int R) {     if (t[x].first) {       if (!c[1]) {         c[1] = t[x].second.first;         c[2] = t[x].second.second;         ans += R - L + 1;         return;       }       c[3] = t[x].second.first;       c[4] = t[x].second.second;       pair<int, pair<int, int> > ret = doit();       if (ret.first) {         c[1] = ret.second.first;         c[2] = ret.second.second;         ans += R - L + 1;         return;       }     }     if (!t[2 * x].first) {       if (L == R) return;       cnt(2 * x, L, (L + R) / 2);     } else {       if (!c[1]) {         c[1] = t[2 * x].second.first;         c[2] = t[2 * x].second.second;         ans += (L + R) / 2 - L + 1;         if (L == R) return;         cnt(2 * x + 1, (L + R) / 2 + 1, R);       } else {         c[3] = t[2 * x].second.first;         c[4] = t[2 * x].second.second;         pair<int, pair<int, int> > ret = doit();         if (ret.first) {           c[1] = ret.second.first;           c[2] = ret.second.second;           ans += (L + R) / 2 - L + 1;           if (L == R) return;           cnt(2 * x + 1, (L + R) / 2 + 1, R);         } else {           if (L == R) return;           cnt(2 * x, L, (L + R) / 2);         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     while (pown <= n) {       pown *= 2;     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i]++;     }     for (int i = 2; i <= n; i++) {       int x;       cin >> x;       v[x].push_back(i);     }     cin >> q;     dfs(1, 1);     for (int i = 0; i < gg.size(); i++) {       tt[i + 1] = make_pair(lvl[gg[i]], make_pair(i + 1, i + 1));     }     for (int i = 2 * n; i >= 1; i--) {       l[i][0] = tt[i];       if (tt[i + 1].first < tt[i].first && i != 2 * n) l[i][0] = tt[i + 1];       if (i != 2 * n) l[i][0].second.second = i + 1;       r[l[i][0].second.second][0] = l[i][0];       for (int j = 1; j <= 18; j++) {         l[i][j] = l[i][j - 1];         if (l[i][j].first > l[l[i][j - 1].second.second][j - 1].first) {           l[i][j].first = l[l[i][j - 1].second.second][j - 1].first;           l[i][j].second.first = l[l[i][j - 1].second.second][j - 1].second.first;         }         l[i][j].second.second = l[l[i][j - 1].second.second][j - 1].second.second;         r[l[i][j].second.second][j] = l[i][j];       }     }     pw[1] = 0;     int pp = 2, txx = 1;     for (int i = 1; i < 19; i++) {       for (int j = pp; j < 2 * pp; j++) {         pw[j] = txx;       }       pp *= 2;       txx++;     }     for (int i = 1; i <= n; i++) {       t[pown + a[i] - 1].first = 1;       t[pown + a[i] - 1].second.first = i;       t[pown + a[i] - 1].second.second = i;       upd((pown + a[i] - 1) / 2);     }     while (q--) {       cin >> typ;       if (typ == 1) {         cin >> indx >> indy;         t[pown + a[indx] - 1].first = 1;         t[pown + a[indx] - 1].second.first = indy;         t[pown + a[indx] - 1].second.second = indy;         upd((pown + a[indx] - 1) / 2);         t[pown + a[indy] - 1].first = 1;         t[pown + a[indy] - 1].second.first = indx;         t[pown + a[indy] - 1].second.second = indx;         upd((pown + a[indy] - 1) / 2);         swap(a[indx], a[indy]);       } else {         ans = 0;         for (int i = 1; i <= 4; i++) c[i] = 0;         cnt(1, 1, pown);         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }   struct key {     string name;     int t, p, g;   };   int main() {     int n, s, mt = 0, mg = 0, mp = 0;     string x;     cin >> n;     vector<key> vec(n);     for (int i = 0; i < n; i++) {       cin >> s >> vec[i].name;       vec[i].t = vec[i].p = vec[i].g = 0;       for (int j = 0; j < s; j++) {         cin >> x;         if (x[0] == x[1] && x[1] == x[3] && x[3] == x[4] && x[4] == x[6] &&             x[6] == x[7])           vec[i].t++;         else if (x[1] < x[0] && x[3] < x[1] && x[4] < x[3] && x[6] < x[4] &&                  x[7] < x[6])           vec[i].p++;         else           vec[i].g++;       }       mt = max(mt, vec[i].t);       mg = max(mg, vec[i].g);       mp = max(mp, vec[i].p);     }     int f = 0;     cout <<  If you want to call a taxi, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].t == mt) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     f = 0;     cout <<  .  << endl <<  If you want to order a pizza, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].p == mp) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     f = 0;     cout <<  .  << endl          <<  If you want to go to a cafe with a wonderful girl, you should call: ;     for (int i = 0; i < n; i++)       if (vec[i].g == mg) {         if (f) cout <<  , ;         cout <<     << vec[i].name;         f = 1;       }     cout <<  . ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a, Q;   vector<vector<int>> Q2;   int n;   void help(int x) {     int p1, p2, p3, s1, s2, s3, s4;     vector<int> A, B, C, D;     p3 = find(a.begin(), a.end(), x) - a.begin();     p1 = find(a.begin(), a.end(), x + 1) - a.begin() - 1;     p2 = p3;     while (a[p2] != x + 1) --p2;     while (a[p2 + 1] == a[p2] + 1) ++p2;     for (int i = 1; i <= p1; ++i) A.push_back(a[i]);     for (int i = p1 + 1; i <= p2; ++i) B.push_back(a[i]);     for (int i = p2 + 1; i <= p3; ++i) C.push_back(a[i]);     for (int i = p3 + 1; i <= n; ++i) D.push_back(a[i]);     int sz = (!A.empty()) + (!B.empty()) + (!C.empty()) + (!D.empty());     if (sz) {       Q.push_back(sz);       vector<int> temp;       if (!A.empty()) temp.push_back(A.size());       if (!B.empty()) temp.push_back(B.size());       if (!C.empty()) temp.push_back(C.size());       if (!D.empty()) temp.push_back(D.size());       Q2.push_back(temp);     }     vector<int> b{0};     for (auto it : D) b.push_back(it);     for (auto it : C) b.push_back(it);     for (auto it : B) b.push_back(it);     for (auto it : A) b.push_back(it);     a = b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     a = vector<int>(n + 1);     for (int i = 1; i <= n; ++i) cin >> a[i];     while (1) {       int no = 0;       for (int j = 1; j < n; ++j) {         if (find(a.begin(), a.end(), j + 1) < find(a.begin(), a.end(), j)) {           no = j;           break;         }       }       if (!no) break;       help(no);     }     cout << Q.size() <<   n ;     for (int i = 0; i < Q.size(); ++i, cout <<   n ) {       cout << Q[i] <<    ;       for (auto it : Q2[i]) cout << it <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};   int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   };   long long getDigit(long long i) {     int res = 0;     while (i) {       i = i / 10ll;       res++;     }     return res;   }   void solve() {     long long n;     cin >> n;     long long sum = 0;     long long i = 1;     long long tdigit = 0;     long long last = 0;     while (true) {       long long digit = getDigit(i);       tdigit += digit;       sum += tdigit;       if (sum >= n) {         break;       }       last = sum;       i++;     }     long long st = 1;     while (true) {       long long temp = st;       string str = to_string(temp);       for (int i = 0; i < str.size(); i++) {         last++;         if (last == n) {           cout << str[i] << endl;           ;           return;         }       }       st++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     cout.tie(nullptr);     cin.tie(nullptr);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[25][25];   int cost[25][25];   const int maxc = 1 << 20;   int dp[maxc];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , str + i);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) scanf( %d , &cost[i][j]);     }     int total = (1 << n) - 1;     memset(dp, -1, sizeof(dp));     dp[0] = 0;     for (int i = 0; i < total; i++) {       if (dp[i] == -1) continue;       int j = 0;       while (((i >> j) & 1) == 1) j++;       for (int k = 0; k < m; k++) {         int cnt = 0, sumc = 0, maxc = 0, tmp = 0;         for (int z = 0; z < n; z++) {           if (str[z][k] == str[j][k]) {             cnt++;             sumc += cost[z][k];             maxc = max(maxc, cost[z][k]);             tmp |= (1 << z);           }         }         if (cnt == 1) {           if (dp[i | (1 << j)] == -1)             dp[i | (1 << j)] = dp[i];           else             dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i]);         } else {           if (dp[i | (1 << j)] == -1)             dp[i | (1 << j)] = dp[i] + cost[j][k];           else             dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost[j][k]);           if (dp[i | tmp] == -1)             dp[i | tmp] = dp[i] + sumc - maxc;           else             dp[i | tmp] = min(dp[i | tmp], dp[i] + sumc - maxc);         }       }     }     printf( %d n , dp[total]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2505;   int n, a[N][N];   struct node {     int x, y, v;     node() {}     node(int _x, int _y, int _v) : x(_x), y(_y), v(_v) {}     bool operator<(const node k) const { return v < k.v; }   };   vector<node> p;   bitset<N> r[N], c[N], t;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (a[i][j] != a[j][i]) {           puts( NOT MAGIC );           return 0;         }         if (i == j && a[i][j]) {           puts( NOT MAGIC );           return 0;         }         p.push_back(node(i, j, a[i][j]));       }     }     sort(p.begin(), p.end());     for (int i = 0, j; i < p.size(); i = j) {       j = i;       while (j < p.size() && p[j].v == p[i].v) j++;       for (int k = i; k < j; k++) {         int x = p[k].x, y = p[k].y;         t = r[x] & c[y];         if (t.count()) {           puts( NOT MAGIC );           return 0;         }       }       for (int k = i; k < j; k++) {         int x = p[k].x, y = p[k].y;         r[x][y] = c[y][x] = 1;       }     }     puts( MAGIC );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long int i = 0, j = 0, ans = 0, curr = v[0];     while (i < n && j < n) {       ans = max((j - i + 1), ans);       if (v[j + 1] <= curr + 5)         j++;       else {         i++;         j++;       }       curr = v[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void inc(T& a, const T& b) {     if (a < b) a = b;   }   template <class T>   void dec(T& a, const T& b) {     if (a > b) a = b;   }   const int N = 100010;   int n;   int a[N];   struct node {     int lf, len;     bool operator<(const node& rhs) const {       if (len != rhs.len) return len < rhs.len;       return lf < rhs.lf;     }   } c[N * 10];   int cn;   map<int, vector<int> > g;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       if (g.find(a[i]) == g.end()) g[a[i]] = vector<int>();       g[a[i]].push_back(i);     }     for (map<int, vector<int> >::iterator it = (g).begin(); it != (g).end();          ++it) {       vector<int>& t = it->second;       int sz = t.size();       for (int i = 0; i < sz; i++) {         for (int j = i + 1; j < sz; j++) {           if (t[j] - t[i] + t[j] > n) break;           c[cn].lf = t[i];           c[cn].len = t[j] - t[i];           cn++;         }       }     }     sort(c, c + cn);     int p = 0;     for (int i = 0; i < cn; i++) {       int& lf = c[i].lf;       int rt = lf + c[i].len;       if (lf < p) continue;       bool flag = true;       for (int j = 1; j < c[i].len; j++) {         if (a[lf + j] != a[rt + j]) {           flag = false;           break;         }       }       if (flag) {         p = rt;       }     }     printf( %d n , n - p);     for (int i = p; i < n; ++i) {       printf( %d , a[i]);       putchar(i + 1 < n ? 32 : 10);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug;   const int inf = 1e9 + 5;   const int nax = 3005;   vector<int> w[nax];   int d[nax][nax];   int main(int argc, char *argv[]) {     debug = argc > 1;     int n, m;     scanf( %d%d , &n, &m);     for (int _ = 0; _ <= (m)-1; ++_) {       int a, b;       scanf( %d%d , &a, &b);       w[a].push_back(b);       w[b].push_back(a);     }     for (int i = 1; i <= (n); ++i) {       for (int j = 1; j <= (n); ++j) d[i][j] = inf;       d[i][i] = 0;       queue<int> q;       q.push(i);       while (!q.empty()) {         int a = q.front();         q.pop();         for (int b : w[a])           if (d[i][b] == inf) {             d[i][b] = d[i][a] + 1;             q.push(b);           }       }     }     int a[2], b[2], lim[2];     for (int r = 0; r <= (2) - 1; ++r) scanf( %d%d%d , &a[r], &b[r], &lim[r]);     int res = inf;     for (int i = 1; i <= (n); ++i)       for (int j = 1; j <= (n); ++j)         for (int _ = 0; _ <= (2) - 1; ++_) {           int dist[2];           for (int r = 0; r <= (2) - 1; ++r)             dist[r] = d[a[r]][i] + d[i][j] + d[j][b[r]];           if (dist[0] <= lim[0] && dist[1] <= lim[1])             res = min(res, dist[0] + dist[1] - d[i][j]);           swap(a[0], b[0]);         }     int dist[2];     for (int r = 0; r <= (2) - 1; ++r) dist[r] = d[a[r]][b[r]];     if (dist[0] <= lim[0] && dist[1] <= lim[1]) res = min(res, dist[0] + dist[1]);     printf( %d n , res == inf ? -1 : m - res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     double n;     cin >> n;     vector<double> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     double sum = 0;     for (int i = 0; i < n; i++) sum += v[i] / 100.0;     double res = (sum / n) * 100.0;     cout << fixed << setprecision(12) << res << endl;     cin.ignore();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   long long T, ans, res;   long long Ans[N], p[N], a, b, c;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void solve(long long dep, long long a, long long x, long long b,                     long long y) {     if (x == 0 || y == 0) return;     if (x == y) {       p[dep] = x, ans = dep;       for (long long i = 0; i <= dep; i++) Ans[i] = p[i];       res++;     }     long long c = y % b;     p[dep] = c;     if (c % a != x % a) return;     solve(dep + 1, a, (x - c) / a, b, (y - c) / b);   }   signed main() {     a = read(), b = read(), c = read();     if (a == 1 && b == 1 && c == 1) {       printf( inf n );       return 0;     }     if (a == b && b != c) {       printf( 0 n );       return 0;     }     res = 0;     solve(0, a, b, b, c);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, pos, ans;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> s;       ans = pos = 0;       s +=  R ;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  R ) {           ans = max(ans, (i + 1) - pos);           pos = (i + 1);         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <typename T>   inline void Add(T &x, T y) {     x += y;     if (x >= mod) x -= mod;   }   template <typename T>   inline void Mul(T &x, T y) {     (x *= y) %= mod;   }   inline int read() {     int x = 0;     char ch = getchar();     bool f = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = 1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 3) + (x << 1) + (ch ^ 48);     return f ? -x : x;   }   struct matrix {     long long a[2][2];     matrix() { memset(a, 0, sizeof(a)); }     inline bool isI() {       return a[0][0] == 1 && a[1][1] == 1 && a[0][1] == 0 && a[1][0] == 0;     }     friend inline matrix operator*(const matrix &A, const matrix &B) {       matrix C;       for (int i = (0), end_i = (1); i <= end_i; i++)         for (int j = (0), end_i = (1); j <= end_i; j++)           for (int k = (0), end_i = (1); k <= end_i; k++)             Add(C.a[i][j], A.a[i][k] * B.a[k][j] % mod);       return C;     }     friend inline matrix operator+(const matrix &A, const matrix &B) {       matrix C;       for (int i = (0), end_i = (1); i <= end_i; i++)         for (int j = (0), end_i = (1); j <= end_i; j++)           C.a[i][j] = (A.a[i][j] + B.a[i][j]) % mod;       return C;     }   } I, F;   inline matrix Pow(matrix A, long long n) {     matrix B = I;     for (; n; n >>= 1, A = A * A)       if (n & 1) B = B * A;     return B;   }   int n;   matrix sum[200010 << 2], tag[200010 << 2];   inline void pushdown(int u) {     if (tag[u].isI()) return;     sum[u << 1] = sum[u << 1] * tag[u];     sum[u << 1 | 1] = sum[u << 1 | 1] * tag[u];     tag[u << 1] = tag[u << 1] * tag[u];     tag[u << 1 | 1] = tag[u << 1 | 1] * tag[u];     tag[u] = I;   }   inline void pushup(int u) { sum[u] = sum[u << 1] + sum[u << 1 | 1]; }   void add(int L, int R, const matrix &C, int u = 1, int l = 1, int r = n) {     if (L <= l && r <= R) {       tag[u] = tag[u] * C, sum[u] = sum[u] * C;       return;     }     int mid = l + r >> 1;     pushdown(u);     if (L <= mid) add(L, R, C, u << 1, l, mid);     if (mid < R) add(L, R, C, u << 1 | 1, mid + 1, r);     pushup(u);   }   matrix ask(int L, int R, int u = 1, int l = 1, int r = n) {     if (L <= l && r <= R) return sum[u];     pushdown(u);     int mid = l + r >> 1;     matrix ans;     if (L <= mid) ans = ans + ask(L, R, u << 1, l, mid);     if (mid < R) ans = ans + ask(L, R, u << 1 | 1, mid + 1, r);     return ans;   }   int m;   int main() {     I.a[0][0] = I.a[1][1] = 1;     F.a[0][0] = 1, F.a[0][1] = 1;     F.a[1][0] = 1;     F.a[1][1] = 0;     n = read();     m = read();     for (int i = (1), end_i = (n << 2); i <= end_i; i++) tag[i] = I, sum[i] = I;     int opt, l, r, x;     matrix B;     for (int i = (1), end_i = (n); i <= end_i; i++)       B = Pow(F, read() - 1), add(i, i, B);     for (int _ = (1), end_i = (m); _ <= end_i; _++) {       opt = read(), l = read(), r = read();       if (opt == 1)         add(l, r, Pow(F, read()));       else         printf( %d n , ask(l, r).a[0][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   char s[33];   int num[33];   char mp[3][14];   int main() {     while (scanf( %s , s + 1) != EOF) {       memset(num, 0, sizeof(num));       int id;       for (int i = 1; i <= 27; i++) {         num[s[i] -  A ]++;         if (num[s[i] -  A ] == 2) {           id = s[i] -  A ;         }       }       int st = -1, ed = -1;       for (int i = 1; i <= 27; i++) {         int x = s[i] -  A ;         if (x == id) {           if (st == -1)             st = i;           else             ed = i;         }       }       if (ed - st == 1) {         printf( Impossible n );         continue;       }       int len = ed - st - 1;       int L = st - 1, R = len / 2, cnt = 1;       if (L + R + 1 <= 13) {         for (int i = 13 - R - 1 - L + 1; i <= 13 - R - 1; i++) {           mp[1][i] = s[cnt++];         }         mp[1][13 - R] = s[cnt++];         for (int i = 13 - R + 1; i <= 13; i++) mp[1][i] = s[cnt++];         int now = 13;         for (int i = len - R; i >= 1; i--) mp[2][now--] = s[cnt++];         cnt++;         for (int i = now; i >= 1; i--) mp[2][i] = s[cnt++];         now = 1;         for (int i = cnt; i <= 27; i++) mp[1][now++] = s[i];       } else {         int lef = L + R + 1 - 13;         for (int i = lef; i >= 1; i--) {           mp[2][i] = s[cnt++];         }         for (int i = 1; i <= L - lef; i++) mp[1][i] = s[cnt++];         mp[1][L - lef + 1] = s[cnt++];         int now = L - lef + 2;         for (int i = 1; i <= R; i++) mp[1][now++] = s[cnt++];         now = 13;         for (int i = len - R; i >= 1; i--) mp[2][now--] = s[cnt++];         cnt++;         for (int i = cnt; i <= 27; i++) mp[2][now--] = s[i];       }       for (int i = 1; i <= 2; i++) {         for (int j = 1; j <= 13; j++) printf( %c , mp[i][j]);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265359;   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T sqr(T x) {     return x * x;   }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   const int maxn = 2e5 + 5;   const int inf = 1e9;   int nxt[maxn];   int len[maxn];   int dp[maxn];   int ff[maxn];   int main() {     srand(time(NULL));     int n;     scanf( %d , &n);     vector<int> cc;     cc.push_back(0);     vector<int> a;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       x++;       a.push_back(x);       cc.push_back(x);     }     int k;     scanf( %d , &k);     vector<int> b;     for (int i = 0; i < k; i++) {       int x;       scanf( %d , &x);       x++;       b.push_back(x);       cc.push_back(x);     }     sort(cc.begin(), cc.end());     cc.resize(unique(cc.begin(), cc.end()) - cc.begin());     for (int &x : a) {       if (x != 0) {         x = lower_bound(cc.begin(), cc.end(), x) - cc.begin();       }     }     multiset<int> bs;     for (int &x : b) {       x = lower_bound(cc.begin(), cc.end(), x) - cc.begin();       bs.insert(x);     }     sort(b.begin(), b.end());     int p = 0;     for (int i = 0; i < maxn; i++) {       while (p < k && i == b[p]) {         p++;       }       nxt[i] = p < k ? b[p] : -1;     }     fill(len, len + maxn, inf);     len[0] = 0;     for (int i = 0; i < n; i++) {       if (a[i] != 0) {         int lo = -1, hi = maxn;         while (hi - lo > 1) {           int mid = (lo + hi) >> 1;           if (len[mid] < a[i]) {             lo = mid;           } else {             hi = mid;           }         }         dp[i] = lo + 1;         ff[i] = a[i];         if (len[lo + 1] > a[i]) {           len[lo + 1] = a[i];         }       } else {         for (int j = n - 1; j >= 0; j--) {           if (len[j] == inf) {             continue;           }           int x = nxt[len[j]];           if (x != -1) {             if (dp[i] < j + 1) {               dp[i] = j + 1;               ff[i] = x;             }           }           if (x != -1 && len[j + 1] > x) {             len[j + 1] = x;           }         }       }     }     int clen = *max_element(dp, dp + n);     int ub = 1e9;     int pos = n;     p = k - 1;     vector<vector<int>> d(maxn);     for (int i = 0; i < n; i++) {       if (a[i]) {         d[dp[i]].push_back(i);       }     }     for (int i = clen; i >= 1; i--) {       bool found = false;       for (int x : d[i]) {         if (x < pos && a[x] < ub) {           ub = a[x];           pos = x;           found = true;           break;         }       }       if (found) {         continue;       }       for (int j = pos - 1; j >= 0; j--) {         if (a[j] == 0 && dp[j] >= i) {           while (p >= 0 && b[p] >= ub) {             p--;           }           assert(p >= 0);           a[j] = b[p];           bs.erase(bs.find(a[j]));           ub = a[j];           pos = j;           p--;           break;         }       }     }     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         assert(bs.size());         a[i] = *bs.begin();         bs.erase(bs.begin());       }     }     for (int i = 0; i < n; i++) {       if (i) {         printf(   );       }       printf( %d , cc[a[i]] - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long int, long long int> v1,             pair<long long int, long long int> v2) {     if (v1.first == v2.first) {       return v1.second > v2.second;     }     return v1.first > v2.first;   }   int main() {     long long int n, i, j, k, flag;     string s;     cin >> s;     map<long long int, long long int> mp;     for (i = 1; i <= 26; i++) {       mp[i] = 0;     }     for (i = 0; i < s.length(); i++) {       k = (s[i] -  a ) + 1;       mp[k] = 1;       for (j = 1; j <= k; j++) {         if (mp[j] == 0) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[100001][11], x[100001], cnt[11], u, v;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= k && scanf( %d%d , &u, &v); i++) x[u]++, cnt[v]++;     for (int i = 1; i <= n; i++) {       int y = 0;       for (int j = 1; j <= m; j++)         if (a[i][j]) y += cnt[j];       printf( %d  , y - x[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     string s;     cin >> s;     vector<string> v(10);     for (int i = 0; i < 10; i++) {       cin >> v[i];     }     string res =   ;     for (int i = 0; i <= 70; i += 10) {       string find = s.substr(i, 10);       for (int j = 0; j < 10; j++) {         if (v[j] == find) {           res.push_back(j +  0 );           break;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 555;   long long saveori[maxn];   long long savepos[maxn];   long long tree[maxn << 2];   void update(long long nowid, long long l, long long r, long long pos,               long long v) {     if (l == r) {       tree[nowid] = v;       return;     }     if (pos <= ((l + r) >> 1)) update((nowid << 1), l, ((l + r) >> 1), pos, v);     if (((l + r) >> 1) < pos)       update(((nowid << 1) | 1), ((l + r) >> 1) + 1, r, pos, v);     tree[nowid] = tree[(nowid << 1)] + tree[((nowid << 1) | 1)];   }   long long query(long long nowid, long long l, long long r, long long ql,                   long long qr) {     if (ql <= l && r <= qr) return tree[nowid];     long long res = 0;     if (ql <= ((l + r) >> 1))       res += query((nowid << 1), l, ((l + r) >> 1), ql, qr);     if (((l + r) >> 1) < qr)       res += query(((nowid << 1) | 1), ((l + r) >> 1) + 1, r, ql, qr);     return res;   }   long long tree1[maxn << 2];   void update1(long long nowid, long long l, long long r, long long pos,                long long v) {     if (l == r) {       tree1[nowid] = v;       return;     }     if (pos <= ((l + r) >> 1)) update1((nowid << 1), l, ((l + r) >> 1), pos, v);     if (((l + r) >> 1) < pos)       update1(((nowid << 1) | 1), ((l + r) >> 1) + 1, r, pos, v);     tree1[nowid] = tree1[(nowid << 1)] + tree1[((nowid << 1) | 1)];   }   long long query1(long long nowid, long long l, long long r, long long ql,                    long long qr) {     if (ql <= l && r <= qr) return tree1[nowid];     long long res = 0;     if (ql <= ((l + r) >> 1))       res += query1((nowid << 1), l, ((l + r) >> 1), ql, qr);     if (((l + r) >> 1) < qr)       res += query1(((nowid << 1) | 1), ((l + r) >> 1) + 1, r, ql, qr);     return res;   }   long long n;   long long getpos(long long k) {     long long cnt = (k + 1) / 2;     long long l = 1, r = n;     long long pos = 0;     while (l <= r) {       long long now = query(1, 1, n, 1, ((l + r) >> 1));       now = ((l + r) >> 1) - now;       if (cnt <= now) {         pos = ((l + r) >> 1);         r = ((l + r) >> 1) - 1;       } else         l = ((l + r) >> 1) + 1;     }     return pos;   }   inline long long cal1(long long a1, long long n) { return n * (n - 1) / 2; }   void solve() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &saveori[i]);       savepos[saveori[i]] = i;     }     vector<long long> ans;     ans.push_back(0);     long long l = savepos[1];     long long r = savepos[1];     for (long long i = 2; i <= n; i++) {       update(1, 1, n, savepos[i], 1);       update1(1, 1, n, savepos[i], savepos[i]);     }     long long last = 0;     for (long long i = 2; i <= n; i++) {       update(1, 1, n, savepos[i], 0);       update1(1, 1, n, savepos[i], 0);       l = min(l, savepos[i]);       r = max(r, savepos[i]);       long long pos = getpos(i);       long long cnt = query(1, 1, n, l, pos);       long long sum = query1(1, 1, n, l, pos) - cnt * l - cal1(0, cnt);       cnt = query(1, 1, n, pos + 1, r);       sum += (cnt * n - query1(1, 1, n, pos, r)) - cal1(0, cnt) - (n - r) * cnt;       last += i - (savepos[i] - query(1, 1, n, 1, savepos[i]));       ans.push_back(last + sum);     }     for (long long aa : ans) printf( %lld n , aa);   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int a, b, c;     cin >> a >> b >> c;     if (min(a, b) != max(a, b))       cout << (2 * min(a, b) + 1 + 2 * c);     else       cout << (a + b + 2 * c);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sc1() {     int x;     scanf( %d , &x);     return x;   }   long long sc2() {     long long x;     scanf( %lld , &x);     return x;   }   int bs;   int n, q;   int arr[100007];   int cnt[100007];   int ans = 0;   int answer[100007];   struct A {     int l, r, id;   } node[100007];   bool cmp(A a, A b) {     int x = a.l / bs;     int y = b.l / bs;     if (x != y) return x < y;     return a.r < b.r;   }   void add(int x) {     if (x <= n) {       if (cnt[x] == x) ans--;       cnt[x]++;       if (cnt[x] == x) ans++;     }   }   void rmv(int x) {     if (x <= n) {       if (cnt[x] == x) ans--;       cnt[x]--;       if (cnt[x] == x) ans++;     }   }   int main() {     n = sc1(), q = sc1();     bs = sqrt(n);     for (int i = 0; i < n; i++) arr[i] = sc1();     for (int i = 0; i < q; i++) {       int a = sc1(), b = sc1();       node[i].l = --a;       node[i].r = --b;       node[i].id = i;     }     sort(node, node + q, cmp);     int mo_left = 0, mo_right = -1;     for (int i = 0; i < q; i++) {       int left = node[i].l;       int right = node[i].r;       while (mo_right < right) {         mo_right++;         add(arr[mo_right]);       }       while (mo_right > right) {         rmv(arr[mo_right]);         mo_right--;       }       while (mo_left < left) {         rmv(arr[mo_left]);         mo_left++;       }       while (mo_left > left) {         mo_left--;         add(arr[mo_left]);       }       answer[node[i].id] = ans;     }     for (int i = 0; i < q; i++) {       cout << answer[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());   const double PI = 2 * acos(0.0);   const string DIGITS =  0123456789 ;   const string ALPH =  abcdefghijklmnopqrstuvwxyz ;   istream &operator>>(istream &in, pair<int, int> &a) {     in >> a.first >> a.second;     return in;   }   ostream &operator<<(ostream &out, pair<int, int> &a) {     out << a.first <<     << a.second;     return out;   }   istream &operator>>(istream &in, pair<double, double> &a) {     in >> a.first >> a.second;     return in;   }   ostream &operator<<(ostream &out, pair<double, double> &a) {     out << a.first <<     << a.second;     return out;   }   template <class T0, class T1>   inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {     return out <<  {  << a.first <<  ,   << a.second <<  } ;   }   template <class T0, class T1, class T2>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  } ;   }   template <class T0, class T1, class T2, class T3>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  ,   << get<3>(a) <<  } ;   }   template <class T>   inline ostream &operator<<(ostream &out, vector<T> &a) {     out <<  [ ;     for (int i = 0; i < int(a.size()); ++i)       out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()];     return out;   }   void print(int n, int k, vector<tuple<int, int, int, int> > kek) {     ofstream cout( output.txt );     cout << n <<     << k <<   n ;     for (auto p : kek) {       int r, x, y, z;       tie(r, x, y, z) = p;       cout << x <<     << y <<     << z <<     << r <<   n ;     }     cout.close();     exit(0);   }   void smain();   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(12) << fixed;     smain();   }   const int M1 = 1000000093, p1 = 27162;   const int M2 = 1000000087, p2 = 241;   const double pi = atan2(1, 0) * 2, EPS = 1e-9;   const int pw = 10, N = 2e5 + 10, oo = 1e9 + 100, B = 1000, M = 998244353;   const int NN = 1e4;   const int RND = 37542135;   template <class KEY, class VAL, int N>   struct HashTable {     pair<KEY, VAL> hmap[NN];     HashTable(KEY a, KEY b) {       for (int i = 0; i < int(NN); ++i) hmap[i] = {a, b};     }     int has1(KEY v) { return (v ^ RND) % NN; }     int h1(KEY v, int i) { return (has1(v) + i) % NN; }     int find(KEY v) {       int pos, i = 0;       do {         pos = h1(v, i);         if (hmap[pos].first == v) return pos;         i++;       } while (hmap[pos].first != -1 && i != NN);       assert(i != NN);       return pos;     }     VAL get(KEY key) {       int pos = find(key);       return hmap[pos].second;     }     void set(KEY key, VAL val) {       int lol = find(key);       hmap[lol] = {key, val};     }   };   vector<int> vertices1[N];   vector<int> vertices2[N];   vector<int> bvertices[N];   int used[N], used2[N], TIMER = 1;   long long trans(long long a, long long b) { return (a << 18) | b; }   void dfs(int v, int col) {     used[v] = col;     for (int u : vertices2[v]) {       if (!used[u]) dfs(u, col);     }   }   void dfs2(int v) {     used2[v] = TIMER;     for (int u : bvertices[v]) {       if (used2[u] != TIMER) dfs2(u);     }   }   void smain() {     int n, m;     cin >> n >> m;     vector<tuple<int, int, int> > quer(m);     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       quer[i] = make_tuple(a, b, c);     }     int last = 0;     vector<int> vertex;     vertex.reserve(4 * B);     vector<pair<int, int> > edges;     edges.reserve(B);     for (int i = 0; i <= n; ++i) bvertices[i].reserve(B / 10);     for (int i = 0; i < m; i += B) {       vertex.clear();       HashTable<long long, int, NN> abused(-1, 0);       for (int i = 0; i <= n; ++i) {         bvertices[i].clear();         vertices2[i].clear();         vertices2[i].reserve(((int)((vertices1[i]).size())));       }       for (int j = i; j < min(m, i + B); ++j) {         int a, b, c;         tie(a, b, c) = quer[j];         if (a == 1) {           if (b > c) swap(b, c);           abused.set(trans(b, c), 1);           vertex.push_back(b);           vertex.push_back(c);           b++, c++;           if (b == n + 1) b = 1;           if (c == n + 1) c = 1;           if (b > c) swap(b, c);           vertex.push_back(b);           vertex.push_back(c);           abused.set(trans(b, c), 1);         } else {           vertex.push_back(b);           vertex.push_back(c);           b++, c++;           if (b == n + 1) b = 1;           if (c == n + 1) c = 1;           vertex.push_back(b);           vertex.push_back(c);         }       }       for (int v = 1; v <= n; ++v)         for (int &u : vertices1[v])           if (!abused.get(trans(min(v, u), max(v, u)))) {             vertices2[v].push_back(u);           }       int col = 1;       fill(used, used + N, 0);       for (auto &v : vertex)         if (!used[v]) dfs(v, col++);       edges.clear();       for (int v = 1; v <= n; ++v)         for (int &u : vertices1[v])           if (abused.get(trans(v, u))) {             if (used[u] != used[v]) {               bvertices[used[v]].push_back(used[u]);               bvertices[used[u]].push_back(used[v]);             }             edges.push_back(make_pair(min(v, u), (max(v, u))));           }       for (int j = i; j < min(m, i + B); ++j) {         int a, b, c;         tie(a, b, c) = quer[j];         if (last) b++, c++;         if (b == n + 1) b = 1;         if (c == n + 1) c = 1;         if (b > c) swap(b, c);         if (a == 1) {           if (find(edges.begin(), edges.end(), make_pair(b, (c))) !=               edges.end()) {             edges.erase(find(edges.begin(), edges.end(), make_pair(b, (c))));             if (used[b] != used[c]) {               bvertices[used[b]].erase(find(bvertices[used[b]].begin(),                                             bvertices[used[b]].end(), used[c]));               bvertices[used[c]].erase(find(bvertices[used[c]].begin(),                                             bvertices[used[c]].end(), used[b]));             }           } else {             edges.push_back(make_pair(b, (c)));             if (used[b] != used[c]) {               bvertices[used[b]].push_back(used[c]);               bvertices[used[c]].push_back(used[b]);             }           }         } else {           if (used[b] == used[c]) {             cout <<  1 ;             last = 1;           } else {             dfs2(used[b]);             if (used2[used[c]] == TIMER) {               cout <<  1 ;               last = 1;             } else {               cout <<  0 ;               last = 0;             }             TIMER++;           }         }       }       for (int i = 1; i <= n; ++i) vertices1[i] = vertices2[i];       for (auto &p : edges) {         vertices1[p.first].push_back(p.second);         vertices1[p.second].push_back(p.first);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<vector<int> > graph, trees, chains;   vector<int> head, sub, mxs, mp, idx;   int dfs(int ind = 0) {     sub[ind] = 1;     mxs[ind] = 0;     for (auto u : graph[ind]) {       sub[ind] += dfs(u);       mxs[ind] = max(mxs[ind], sub[u]);     }     return sub[ind];   }   void HLD(int ind = 0, int chain = 0) {     pair<int, int> mx = {INT_MIN, INT_MIN};     if (chains[chain].empty()) head[chain] = ind;     chains[chain].push_back(ind);     mp[ind] = chain;     idx[ind] = chains[chain].size() - 1;     for (auto u : graph[ind]) {       mx = max(mx, make_pair(sub[u], u));     }     if (mx.first >= 0) {       HLD(mx.second, chain);       for (auto u : graph[ind]) {         if (u == mx.second) continue;         chains.push_back(vector<int>());         head.push_back(0);         HLD(u, chains.size() - 1);       }     }   }   int x;   void build(int n = 0, int l = 0, int r = chains[x].size() - 1) {     if (l == r) {       trees[x][n] = mxs[chains[x][l]];       return;     }     int md = (l + r) >> 1;     build(2 * n + 1, l, md);     build(2 * n + 2, md + 1, r);     trees[x][n] = min(trees[x][2 * n + 1], trees[x][2 * n + 2]);   }   int K, ind;   pair<bool, int> qry(int n = 0, int l = 0, int r = chains[x].size() - 1) {     if (l == r) {       return {K >= trees[x][n], chains[x][l]};     }     int md = (l + r) >> 1;     if (ind <= md && trees[x][2 * n + 1] <= K) {       return qry(2 * n + 1, l, md);     } else if (ind <= r && trees[x][2 * n + 2] <= K)       return qry(2 * n + 2, md + 1, r);     else       return {false, -1};   }   void s(int &x) {     register int c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   int main() {     int N, Q, u, v;     s(N), s(Q);     graph.resize(N);     mxs.resize(N);     sub.resize(N);     mp.resize(N);     idx.resize(N);     for (int i = 1; i < N; i++) {       v = i;       s(u);       u--;       graph[u].push_back(v);     }     dfs();     chains.push_back(vector<int>());     head.push_back(0);     HLD();     trees.resize(chains.size());     for (x = 0; x < (int)chains.size(); x++) {       trees[x].resize(4 * chains[x].size());       build();     }     while (Q--) {       s(v);       v--;       x = mp[v];       K = sub[v] / 2;       printf( %d n , qry().second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     if ((int)str.size() == 1) {       cout << 1 << endl;       return 0;     }     str +=  8 ;     int cnt = 1, ans = 0;     for (int i = 1; i < (int)str.size(); i++) {       if (str[i] == str[i - 1])         cnt++;       else {         ans += ceil(cnt * 1.0 / 5.0);         cnt = 1;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   int ar[100000];   using namespace std;   int main() {     int n;     cin >> n;     int c = 0, ans = 0;     int r;     for (int i = 0; i < 2 * n; i++) {       cin >> r;       if (ar[r]) {         ar[r] = 0;         c--;       } else {         c++;         ar[r] = 1;       }       if (ans < c) ans = c;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[600000], *p1, *p2;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 600000, stdin), p1 == p2)                ? EOF                : *p1++;   }   long long rd() {     long long x = 0;     char ch = nc();     while (ch <  0  || ch >  9 ) ch = nc();     while (ch >=  0  && ch <=  9 ) x = (x << 3) + (x << 1) + ch -  0 , ch = nc();     return x;   }   const long long MAX_N = 5e5 + 25;   long long n, m, q;   long long cnt[MAX_N];   long long ans[MAX_N];   set<pair<long long, long long> > city;   set<pair<long long, long long> >::iterator it;   long long Fen[MAX_N];   long long num;   long long Min;   set<pair<long long, long long> > Q;   void add(long long tmp) {     tmp++;     for (; tmp < MAX_N; tmp += tmp & -tmp) Fen[tmp]++;   }   long long get(long long tmp) {     long long res = 0;     long long id = 0;     for (long long i = 20; ~i; i--)       if (id + (1 << i) < MAX_N && ((id >> i) & 1) == 0)         if (res + Fen[id + (1 << i)] < tmp) {           res += Fen[id + (1 << i)];           id += (1 << i);         }     return id;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     n = rd();     m = rd();     q = rd();     for (long long i = 0; i < n; i++) {       long long tmp;       tmp = rd();       tmp--;       cnt[tmp]++;     }     for (long long i = 0; i < q; i++) {       long long t;       t = rd();       t -= n;       Q.insert({t, i});     }     for (long long i = 0; i < m; i++) city.insert({cnt[i], i});     num = 1;     it = city.begin();     add(it->second);     Min = it->first;     city.erase(it);     while (city.size() && city.begin()->first == Min) {       num++;       it = city.begin();       add(it->second);       city.erase(it);     }     long long Y = 0;     while (num != m) {       while (Q.size() && Q.begin()->first <= Y + num) {         it = Q.begin();         ans[it->second] = get(it->first - Y);         Q.erase(it);       }       if (!Q.size()) break;       Y += num;       Min++;       while (city.size() && city.begin()->first == Min) {         num++;         it = city.begin();         add(it->second);         city.erase(it);       }     }     while (Q.size()) {       it = Q.begin();       ans[it->second] = (((it->first - Y) % m - 1) + m) % m;       Q.erase(it);     }     for (long long i = 0; i < q; i++) printf( %lld  , ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %  PRId64, &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <typename T, typename... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <typename T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   template <typename T>   void _W(const vector<T> &x) {     for (auto i = x.cbegin(); i != x.cend(); i++) {       if (i != x.cbegin()) putchar(   );       _W(*i);     }   }   void W() {}   template <typename T, typename... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   const int N = 1e5 + 10;   struct E {     int to, flow;     long double ang;   };   bool operator<(const E &a, const E &b) { return a.ang < b.ang; }   int n, m;   long long x[N], y[N];   vector<E> e[N];   vector<int> sf[N];   inline long double get_ang(int a, int b) {     map<pair<int, int>, long double> memo;     auto k = make_pair(a, b);     if (memo.count(k))       return memo[k];     else       return memo[k] = atan2l(y[b] - y[a], x[b] - x[a]);   }   double cross(int a, int b) { return x[a] * y[b] - x[b] * y[a]; }   bool vis[N];   int dfs(int p) {     vis[p] = 1;     int s = 1;     for (auto &i : e[p])       if (!vis[i.to]) {         int f = dfs(i.to);         i.flow = -f;         for (auto &j : e[i.to])           if (j.to == p) j.flow = f;         s += f;       }     return s;   }   int main() {     R(n, m);     for (int i = 0; i < int(m); i++) {       int a, b;       R(a, b);       e[a].push_back({b, 0, 0});       e[b].push_back({a, 0, 0});     }     for (int i = (1); i <= int(n); i++) R(x[i], y[i]);     int w = 1;     for (int i = (1); i <= int(n); i++)       if (x[i] < x[w]) w = i;     x[0] = x[w] - 1;     e[0].push_back({w, 0, 0});     e[w].push_back({0, 0, 0});     dfs(0);     for (int i = (0); i <= int(n); i++) {       for (auto &j : e[i]) j.ang = get_ang(i, j.to);       sort(begin(e[i]), end(e[i]));       sf[i].push_back(0);       for (auto &j : e[i]) sf[i].push_back(sf[i].back() + j.flow);       ;     }     int q;     R(q);     while (q--) {       static int np, p[N];       R(np);       for (int i = 0; i < int(np); i++) R(p[i]);       p[np] = p[0];       double area = 0;       for (int i = 0; i < int(np); i++) area += cross(p[i], p[i + 1]);       if (area < 0) reverse(p, p + np + 1);       p[np + 1] = p[1];       int ans = 0;       for (int ii = 0; ii < int(np); ii++) {         int i = p[ii], j = p[ii + 1], k = p[ii + 2];         auto aji = get_ang(j, i);         auto ajk = get_ang(j, k);         int ti = lower_bound(begin(e[j]), end(e[j]), E{0, 0, aji}) - e[j].begin();         int tk = lower_bound(begin(e[j]), end(e[j]), E{0, 0, ajk}) - e[j].begin();         assert(ti < ((int)(e[j]).size()) && e[j][ti].to == i);         assert(tk < ((int)(e[j]).size()) && e[j][tk].to == k);         ;         if (ti < tk) {           ans += sf[j][tk] - sf[j][ti + 1];         } else {           ans += sf[j].back() - sf[j][ti + 1];           ans += sf[j][tk];         }       }       W(ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 20;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k % 2 == n % 2 && (k * k) <= n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long f(long long a, long long b) {     if (b == 0) return 0;     return a / b + f(b, a % b);   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> a >> b;     cout << f(a, b) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 50;   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     sort(a.begin(), a.end());     for (long long i = 0, j = n - 1; i < j; i++, j--) {       ans += (a[i] + a[j]) * (a[i] + a[j]);     }     cout << ans;   }


#include <bits/stdc++.h>   const int maxn = 1000010;   const int P = 1000000007;   int k, w;   int f[maxn], g[maxn];   int pow(int x, int y) {     int e = 1;     while (y) {       if (y & 1) e = (long long)e * x % P;       x = (long long)x * x % P;       y >>= 1;     }     return e;   }   int main() {     int i, d, t, s = 0;     scanf( %d%d , &k, &w);     for (f[0] = g[0] = 1, i = 1; i <= k; ++i)       f[i] = (long long)f[i - 1] * i % P, g[i] = pow(f[i], P - 2);     for (t = 1; t <= k; ++t) {       d = (long long)f[k] * g[k - t] % P * g[k - t] % P;       if (t <= w - 1)         s = ((long long)d * t % P * f[k] % P * pow(k, w - t - 1) + s) % P;       else         s = ((long long)d * w % P * f[k - t + w - 1] + s) % P;     }     for (t = 1; t < k; ++t) {       d = (long long)f[k] * g[k - t] % P * g[k - t - 1] % P;       if (t + 1 <= w - 1)         s = ((long long)d * t % P * f[k] % P * pow(k, w - t - 2) + s) % P;       else         s = ((long long)d * (w - 1) % P * f[k - t + w - 2] + s) % P;     }     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void bruteforce() {}   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   long long modInverse(long long n) { return power(n, 1000000007 - 2); }   long long primes[1000100];   int main() {     ios::sync_with_stdio(0);     long long tc = 1;     cin >> tc;     for (long long i = 2; i < 1000100; i++) {       if (!primes[i]) {         for (long long j = i * i; j < 1000100; j += i) primes[j] = i;       }     }     for (int tci = 1; tci < tc + 1; tci++) {       long long x, p, k;       cin >> x >> p >> k;       if (p == 1) {         cout << x + k << endl;         continue;       }       set<long long> s;       long long pp = primes[p];       while (primes[p]) {         s.insert(pp);         p /= pp;         pp = primes[p];       }       s.insert(p);       vector<long long> v;       for (auto ss : s) v.push_back(ss);       long long d = v.size();       long long l = x + 1, r = 1e8;       long long ans = 0;       while (l <= r) {         long long mid = (l + r) / 2;         long long u = mid - x;         for (int i = 1; i < (1ll << d); i++) {           long long num = 1;           for (int j = 0; j < d; j++) {             if (i & (1ll << j)) {               num *= v[j];             }           }           long long o = __builtin_popcount(i);           if (o % 2 == 0)             u += (mid / num) - (x / num);           else             u -= (mid / num) - (x / num);         }         if (u >= k)           r = mid - 1;         else if (u < k)           l = mid + 1;         if (u == k) ans = mid;       }       if (ans == 0) cout << x <<  00  << p <<  00  << k << endl;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, l, k;     cin >> t;     while (t--) {       cin >> n >> k >> l;       int s = 0, f = 2 * k - 1, dep, flg = 1;       for (i = 1; i <= n; i++) {         cin >> dep;         if (!flg) continue;         if (l < dep) {           cout <<  NO  << endl;           flg = 0;         }         if (!flg) continue;         int s1 = k - 1 - (l - dep), f1 = k - 1 + (l - dep);         if (s1 < 0) s1 = 0;         if (f1 > 2 * k - 1) f1 = 2 * k - 1;         if (s1 == 0 && f1 == 2 * k - 1) {           s = 0;           f = 2 * k - 1;           continue;         }         if (s == 0 && f == 2 * k - 1) {           s = s1;           f = f1;           continue;         }         s = max(s + 1, s1);         f = f1;         if (s > f) {           cout <<  NO  << endl;           flg = 0;         }       }       if (flg) cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0, cnt5 = 0, cnt6 = 0;     char x[10];     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , x);       if (x[0] ==  p ) {         cnt1++;       } else if (x[0] ==  g ) {         cnt2++;       } else if (x[0] ==  b ) {         cnt3++;       } else if (x[0] ==  o ) {         cnt4++;       } else if (x[0] ==  r ) {         cnt5++;       } else if (x[0] ==  y ) {         cnt6++;       }     }     printf( %d n , 6 - n);     if (cnt1 == 0) {       printf( Power n );     }     if (cnt2 == 0) {       printf( Time n );     }     if (cnt3 == 0) {       printf( Space n );     }     if (cnt4 == 0) {       printf( Soul n );     }     if (cnt5 == 0) {       printf( Reality n );     }     if (cnt6 == 0) {       printf( Mind n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<long long, long long>;   using vi = vector<long long>;   using vvi = vector<vi>;   const signed INF_ = 1001001001;   const long long INF = 1001001001001001001LL;   const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},                   DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto i = begin(v); i != end(v); i++)       os << *i << (i == end(v) - 1 ?    :    );     return os;   }   template <class T>   istream &operator>>(istream &is, vector<T> &v) {     for (auto i = begin(v); i != end(v); i++) is >> *i;     return is;   }   template <class T, class U>   istream &operator>>(istream &is, pair<T, U> &p) {     is >> p.first >> p.second;     return is;   }   template <class T, class U>   bool chmax(T &a, const U &b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   bool chmin(T &a, const U &b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   void psum(T &c) {     partial_sum(begin(c), end(c), begin(c));   }   template <class T>   using heap = priority_queue<T, deque<T>, greater<T>>;   struct before_main_function {     before_main_function() {       cin.tie(nullptr);       ios::sync_with_stdio(false);       cout << setprecision(15) << fixed;     }   } before_main_function;   signed main() {     vi a(6);     cin >> a;     long long n;     cin >> n;     vi b(n);     cin >> b;     vector<pii> c;     c.reserve(n * 6);     for (long long i = 0, ilen = (long long)(n); i < ilen; ++i) {       for (long long j = 0, jlen = (long long)(6); j < jlen; ++j) {         c.emplace_back(b[i] - a[j], i);       }     }     sort(begin(c), end(c));     map<long long, long long> cnt;     long long l = 0;     long long ans = INF;     for (long long r = 0, rlen = (long long)(((long long)c.size())); r < rlen;          ++r) {       cnt[c[r].second] += 1;       while (((long long)cnt.size()) == n) {         chmin(ans, c[r].first - c[l].first);         if (cnt[c[l].second] == 1) {           cnt.erase(c[l].second);         } else {           cnt[c[l].second] -= 1;         }         l += 1;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void getmax(int &a, const int b) {     if (b > a) a = b;   }   struct Segment {     int l, r;     Segment() {}     Segment(const int _l, const int _r) : l(_l), r(_r) {}     bool operator<(const Segment &s) const {       return l != s.l ? l < s.l : r > s.r;     }   };   vector<Segment> SEG[100][100];   int N;   void RemoveCovering(vector<Segment> &s) {     sort(s.begin(), s.end());     vector<Segment> ans;     for (int i = 0, j; i < (int)s.size();) {       ans.push_back(s[i]);       for (j = i + 1; j < (int)s.size() && s[j].r <= s[i].r; j++)         ;       i = j;     }     s.clear(), ans.swap(s);   }   void Insert(vector<Segment> &ans, const vector<Segment> &ls,               const vector<Segment> &rs) {     for (const Segment &s : ls) ans.push_back(s);     for (const Segment &s : rs) ans.push_back(s);     if (ls.empty() || rs.empty()) return;     for (int i = 0, j = 0; i < (int)ls.size(); i++) {       while (j + 1 < (int)rs.size() && rs[j + 1].l <= ls[i].r) j++;       if (rs[j].l <= ls[i].r && rs[j].r >= ls[i].l)         ans.push_back(Segment(ls[i].l, rs[j].r));     }   }   int M;   int DP[101][301];   vector<int> VALS;   int Id(const int v) {     return lower_bound(VALS.begin(), VALS.end(), v) - VALS.begin();   }   int main() {     while (scanf( %d , &N) == 1) {       if (true) {         vector<Segment> tmp;         for (int i = 0; i < N; i++) {           static Segment s;           scanf( %d%d , &s.l, &s.r);           tmp.push_back(s);         }         sort(tmp.begin(), tmp.end());         for (int i = 0; i < N; i++)           for (int j = i; j < N; j++) SEG[i][j].clear();         VALS.clear();         for (int i = 0; i < N; i++) {           const int a = tmp[i].l, l = tmp[i].r;           SEG[i][i].push_back(Segment(a - l, a));           SEG[i][i].push_back(Segment(a, a + l));           VALS.push_back(a - l), VALS.push_back(a), VALS.push_back(a + l);         }         tmp.clear(), vector<Segment>().swap(tmp);       }       if (true) {         auto &s = VALS;         sort(s.begin(), s.end()),             s.resize(unique(s.begin(), s.end()) - s.begin());         M = s.size();       }       for (int gap = 1; gap < N; gap++) {         for (int i = 0; i + gap < N; i++) {           const int j = i + gap;           for (int k = i; k < j; k++) {             Insert(SEG[i][j], SEG[i][k], SEG[k + 1][j]);             Insert(SEG[i][j], SEG[k + 1][j], SEG[i][k]);           }           RemoveCovering(SEG[i][j]);         }       }       for (int i = 0; i <= M; i++) DP[0][i] = 0;       for (int i = 1; i <= N; i++) {         for (int j = 0; j <= M; j++) DP[i][j] = DP[i - 1][j];         for (int j = 1; j <= i; j++)           for (const auto &s : SEG[j - 1][i - 1]) {             const int l = Id(s.l) + 1;             for (int k = Id(s.r) + 1; k <= M; k++)               getmax(DP[i][k], DP[j - 1][l - 1] + (s.r - s.l));           }       }       const int ans = DP[N][M];       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 55;   int n, m;   int f[N][N], g[N][N], h[N][N], F[N][N], inv[N];   inline long long qpow(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1, a = a * a % mod)       if (b & 1) res = res * a % mod;     return res;   }   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void dec(int &x, int y) {     x -= y;     if (x < 0) x += mod;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n + 1; i++) inv[i] = qpow(i, mod - 2);     f[0][1] = 1;     h[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = n + 1; j >= 1; j--)         F[i - 1][j] = (F[i - 1][j + 1] + f[i - 1][j]) % mod;       for (int j = n + 1; j >= 1; j--)         for (int k = 0; k < i; k++)           add(g[i][j], 1ll * F[k][j] * F[i - k - 1][j] % mod);       for (int j = 1; j <= n + 1; j++) dec(g[i][j], g[i][j + 1]);       for (int j = 1; j <= n + 1; j++)         for (int x = n; x >= 0; x--)           for (int y = n + 1; y >= 0; y--) {             int res = 0, c = 1;             for (int k = 0; k * i <= x && k * j <= y; k++) {               add(res, 1ll * h[x - k * i][y - k * j] * c % mod);               c = 1ll * c * (g[i][j] + k) % mod * inv[k + 1] % mod;             }             h[x][y] = res;           }       for (int j = 1; j <= n + 1; j++) f[i][j] = h[i][j - 1];     }     printf( %d , f[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, i, a;     unsigned long long s1 = 0, s2 = 0, s3 = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       s1 += (unsigned long long)a;     }     for (i = 0; i < n - 1; i++) {       cin >> a;       s2 += (unsigned long long)a;     }     for (i = 0; i < n - 2; i++) {       cin >> a;       s3 += (unsigned long long)a;     }     cout << s1 - s2 <<   n  << s2 - s3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10, maxk = 52;   const int MOD = (int)1e9 + 7;   inline void add(long long &a, long long b) { a = (a + b) % MOD; }   long long fac[maxn];   struct P {     int to, w;   };   vector<P> v[maxn], v2[maxn];   bool vis[maxn];   int n, fa[maxn], in[maxn], out[maxn], tick;   int sz[maxn];   int id[maxn], cnt1, cnt2, pt1[maxk], pt2[maxk];   void dfs(int x, int f) {     vis[x] = 1;     fa[x] = f;     sz[x] = 1;     in[x] = tick++;     if (x <= n)       pt1[cnt1] = x, id[x] = cnt1++;     else       pt2[cnt2] = x, id[x] = cnt2++;     v2[x].clear();     for (auto i : v[x])       if (!vis[i.to]) v2[x].push_back(i), dfs(i.to, x), sz[x] += sz[i.to];     out[x] = tick++;   }   inline bool isfa(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; }   long long dp0[2][1 << 17];   long long *solve0(int t) {     memset(dp0, 0, sizeof(dp0));     dp0[1][0] = 1;     int *pt = (!t ? pt1 : pt2);     int cnt = (!t ? cnt1 : cnt2), ma = cnt1 + cnt2 - cnt;     for (int i = 0; i < cnt; i++) {       fill(dp0[i % 2], dp0[i % 2] + (1 << 17), 0);       for (int j = 0; j < (1 << ma); j++) {         add(dp0[i % 2][j], dp0[(i + 1) % 2][j]);         for (auto k : v[pt[i]])           if (j & (1 << id[k.to]))             add(dp0[i % 2][j], dp0[(i + 1) % 2][j ^ (1 << id[k.to])] * k.w);       }     }     static long long ret[maxk];     memset(ret, 0, sizeof(ret));     for (int j = 0; j < (1 << ma); j++)       add(ret[__builtin_popcount(j)], dp0[(cnt - 1) % 2][j]);     return ret;   }   bool mark[maxn];   long long dp[maxn][maxk][2], dp2[maxk][2], tmp[maxk][2];   void DP(int x) {     if (v2[x].empty()) {       dp[x][0][0] = 1;       dp[x][0][1] = 0;       return;     }     for (auto i : v2[x]) DP(i.to);     fill(dp2[0], dp2[sz[x] / 2] + 2, 0);     for (int i = 0, sum = 3; i < (int)v2[x].size(); i++) {       int xi = v2[x][i].to, w = v2[x][i].w, sz2 = sz[xi];       if (!i) {         for (int j = 0; 2 * j <= sz2; j++) {           dp2[j][0] = (dp[xi][j][0] + dp[xi][j][1]) % MOD;           if (!mark[x] && !mark[xi]) dp2[j + 1][1] = dp[xi][j][0] * w % MOD;         }         sum += sz2;         continue;       }       for (int j = 0; 2 * j <= sum; j++)         for (int k = 0; k < 2; k++) tmp[j][k] = dp2[j][k];       fill(dp2[0], dp2[(sum + sz2) / 2] + 2, 0);       for (int j = 0; 2 * j <= sum; j++)         for (int j2 = 0; 2 * j2 <= sz2; j2++) {           add(dp2[j + j2][0], tmp[j][0] * (dp[xi][j2][0] + dp[xi][j2][1]));           add(dp2[j + j2][1], tmp[j][1] * (dp[xi][j2][0] + dp[xi][j2][1]));           if (mark[x] || mark[xi]) continue;           add(dp2[j + j2 + 1][1], (tmp[j][0] * dp[xi][j2][0] % MOD) * w);         }       sum += sz2;     }     for (int i = 0; 2 * i <= sz[x]; i++)       for (int j = 0; j < 2; j++) dp[x][i][j] = dp2[i][j];   }   struct E {     int x, y, w;   };   vector<E> edge;   long long *solve1() {     edge.clear();     for (int i = 0; i < cnt1; i++)       for (auto j : v[pt1[i]])         if (j.to != fa[pt1[i]] && fa[j.to] != pt1[i] && isfa(j.to, pt1[i]))           edge.push_back((E){pt1[i], j.to, j.w});     for (int i = 0; i < cnt2; i++)       for (auto j : v[pt2[i]])         if (j.to != fa[pt2[i]] && fa[j.to] != pt2[i] && isfa(j.to, pt2[i]))           edge.push_back((E){pt2[i], j.to, j.w});     static long long ret[maxk];     memset(ret, 0, sizeof(ret));     int size = edge.size();     for (int i = 0; i < (1 << size); i++) {       for (int j = 0; j < cnt1; j++) mark[pt1[j]] = 0;       for (int j = 0; j < cnt2; j++) mark[pt2[j]] = 0;       bool ok = 1;       long long mul = 1LL;       int num = 0;       for (int j = 0; j < size; j++)         if (i & (1 << j)) {           num++;           if (mark[edge[j].x] || mark[edge[j].y]) {             ok = 0;             break;           }           mark[edge[j].x] = mark[edge[j].y] = 1;           mul = mul * edge[j].w % MOD;         }       if (!ok) continue;       int root = pt1[0];       for (; root != fa[root]; root = fa[root])         ;       DP(root);       for (int j = 0; 2 * j <= sz[root]; j++)         add(ret[num + j], (dp[root][j][0] + dp[root][j][1]) * mul);     }     return ret;   }   long long ans[maxk], tmp2[maxk];   int main() {     int k;     scanf( %d%d , &n, &k);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % MOD;     while (k--) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       v[x].push_back((P){n + y, w - 1});       v[n + y].push_back((P){x, w - 1});     }     ans[0] = 1;     for (int i = 1; i <= n; i++)       if (!vis[i] && !v[i].empty()) {         cnt1 = cnt2 = 0;         dfs(i, i);         long long *ret;         if (cnt2 <= 17)           ret = solve0(0);         else if (cnt1 <= 17)           ret = solve0(1);         else           ret = solve1();         for (int j = 0; j < maxk; j++) tmp2[j] = ans[j], ans[j] = 0;         for (int j = 0; j < maxk; j++)           for (int j2 = 0; j + j2 < maxk; j2++)             add(ans[j + j2], tmp2[j] * ret[j2]);       }     long long ANS = 0LL;     for (int i = 0; i < maxk; i++) add(ANS, fac[n - i] * ans[i]);     printf( %I64d n , ANS);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], b[N];   void add(int l, int r, int val) {     if (l > r) return;     b[l] += val;     b[r + 1] -= val;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 1; i < m; i++)       if (a[i - 1] != a[i]) {         int x1 = min(a[i - 1], a[i]);         int x2 = max(a[i - 1], a[i]);         add(1, x1 - 1, x2 - x1);         add(x1, x1, x2 - 1);         add(x1 + 1, x2 - 1, x2 - x1 - 1);         add(x2, x2, x1);         add(x2 + 1, n, x2 - x1);       }     for (int i = 1; i <= n; i++) b[i] += b[i - 1];     for (int i = 1; i <= n; i++) {       if (i > 1) cout <<    ;       cout << b[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   struct node {     int next, to;   } e[maxn * 2];   int head[maxn * 2];   int a[maxn];   set<int> G[maxn];   int ans[maxn];   int cnt;   int gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   void init() {     memset(head, 0, sizeof(head));     cnt = 0;   }   void add(int u, int t) {     e[++cnt].next = head[u];     e[cnt].to = t;     head[u] = cnt;   }   void dfs(int u, int fa) {     for (int i = head[u]; i != 0; i = e[i].next) {       int v = e[i].to;       if (v == fa) continue;       ans[v] = gcd(ans[u], a[v]);       G[v].insert(ans[u]);       for (set<int>::iterator it = G[u].begin(); it != G[u].end(); it++) {         G[v].insert(gcd(*it, a[v]));       }       dfs(v, u);     }   }   int main() {     int n;     init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     ans[1] = a[1];     G[1].insert(0);     dfs(1, 0);     for (int i = 1; i <= n; i++) {       set<int>::iterator it = G[i].end();       it--;       ans[i] = max(ans[i], *it);     }     for (int i = 1; i <= n; i++) {       if (i == 1)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   int powmod(long long a, int b, int c) {     long long r = 1 % c;     while (b) {       if (b & 0x1) r = r * a % c;       a = a * a % c;       b >>= 1;     }     return r;   }   int phi(int n) {     int ret = n, i;     for (i = 2; i * i <= n; ++i)       if (n % i == 0) {         ret -= ret / i;         while (n % i == 0) n /= i;       }     if (n != 1) ret -= ret / n;     return ret;   }   int eval(char s[]) {     int i, r = 0;     for (i = 0; s[i]; ++i) r = r * 10 + s[i] -  0 ;     return r;   }   char B[1000005], N[1000005];   int C;   void gao() {     long long b = 0, c;     int i;     for (i = 0; B[i]; ++i) b = b * 10 + B[i] -  0 , b %= C;     if (strlen(N) == 1 && N[0] ==  1 ) {       --b;       if (b < 0) b += C;       if (b == 0) b = C;       cout << b << endl;       return;     }     if (strlen(N) <= 9) {       c = eval(N);       --c;     } else {       c = phi(C);       long long t = 0;       for (i = 0; N[i]; ++i) t = t * 10 + N[i] -  0 , t %= c;       --t;       if (t < 0) t += c;       c += t;     }     long long ret = powmod(b, c, C);     ret = ret * (b - 1) % C;     if (ret < 0) ret += C;     if (ret == 0) ret = C;     cout << ret << endl;   }   int main() {     while (3 == scanf( %s%s%d , B, N, &C)) gao();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (!(n & 1))       cout << -1 << endl;     else {       for (int i = 0; i < n; i++) cout << i <<    ;       cout << endl;       for (int i = 0; i < n; i++) cout << i <<    ;       cout << endl;       for (int i = 0; i < n; i++) cout << 2 * i % n <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   vector<vector<pair<int, long long>>> G;   set<pair<long long, int>> s;   vector<long long> dis;   vector<int> par;   void dijkstra(int x) {     int n = G.size();     dis.resize(n);     par.resize(n);     for (int i = 0; i < n; ++i) {       dis[i] = INF;       par[i] = -1;     }     dis[x] = 0;     for (int i = 0; i < n; ++i) s.insert(make_pair(dis[i], i));     while (!s.empty()) {       auto curr = s.begin();       int v = curr->second, val = curr->first;       s.erase(s.begin());       for (auto u : G[v]) {         if (dis[u.first] > dis[v] + u.second) {           s.erase(make_pair(dis[u.first], u.first));           dis[u.first] = dis[v] + u.second;           par[u.first] = v;           s.insert(make_pair(dis[u.first], u.first));         }       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     G.resize(n);     for (int i = 0; i < m; ++i) {       int x, y;       long long z;       scanf( %d%d%lld , &x, &y, &z);       x--, y--;       G[x].push_back(make_pair(y, z));       G[y].push_back(make_pair(x, z));     }     dijkstra(0);     if (dis[n - 1] == INF)       printf( -1 n );     else {       stack<int> ans;       ans.push(n - 1);       int curr = n - 1;       while (curr != 0) {         curr = par[curr];         ans.push(curr);       }       while (!ans.empty()) {         int x = ans.top() + 1;         ans.pop();         printf( %d  , x);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double bili = acos(-1.0) / 4;   const double pi = acos(-1.0);   bool IN() {     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     return bool(ch -  0 );   }   int n, ptot, yuan;   bool a[2005][2005], vis[2005][2005];   int sum[2005][2005];   pair<int, int> Q[4000005];   int l, r, ans1;   int dx[4] = {-1, 1, 0, 0};   int dy[4] = {0, 0, -1, 1};   double C[100005];   bool edge(int x, int y) {     for (int i = 0; i < 4; i++) {       int zx = x + dx[i], zy = y + dy[i];       if (zx <= 0 || zx > n || zy <= 0 || zy > n || a[zx][zy] == 0) return 1;     }     return 0;   }   void bfs(int x, int y) {     Q[l = r = 1] = make_pair(x, y);     int bian = 0;     for (; l <= r; l++) {       pair<int, int> u = Q[l];       if (edge(u.first, u.second)) bian++;       for (int j = 0; j < 4; j++) {         pair<int, int> v = make_pair(u.first + dx[j], u.second + dy[j]);         if (v.first > 0 && v.first <= n && v.second > 0 && v.second <= n &&             !vis[v.first][v.second]) {           if (a[v.first][v.second] == 0) continue;           Q[++r] = v;           vis[v.first][v.second] = 1;         }       }     }     int mxy = -211, mxx = 0, miy = 21100, mix = 0, d = 0;     for (int i = (int)1; i <= (int)r; i++) {       if (Q[i].second > mxy) {         mxx = Q[i].first;         mxy = Q[i].second;       }       if (Q[i].second < miy) {         mix = Q[i].first;         miy = Q[i].second;       }     }     if (r > 101) {       sort(Q + 1, Q + r + 1);       for (int i = 1; i <= 8; i++)         for (int j = r - 7; j <= r; j++) {           d = max(d, ((Q[i].first - Q[j].first) * (Q[i].first - Q[j].first) +                       (Q[i].second - Q[j].second) * (Q[i].second - Q[j].second)));         }       ++ans1;       double z = 1.0 * d / r;       if (z < 1.55) yuan++;     }   }   int main() {     scanf( %d , &n);     for (int i = (int)1; i <= (int)n; i++)       for (int j = (int)1; j <= (int)n; j++) a[i][j] = IN();     for (int i = (int)1; i <= (int)n; i++)       for (int j = (int)1; j <= (int)n; j++)         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];     for (int i = (int)1; i <= (int)n; i++) {       for (int j = (int)1; j <= (int)n; j++) {         int u = ((((i) < (j) ? (i) : (j))) <                          (((n - i + 1) < (n - j + 1) ? (n - i + 1) : (n - j + 1)))                      ? (((i) < (j) ? (i) : (j)))                      : (((n - i + 1) < (n - j + 1) ? (n - i + 1) : (n - j + 1))));         u = ((u) < (4) ? (u) : (4));         int sm = sum[i + u - 1][j + u - 1] - sum[i - u + 1 - 1][j + u - 1] -                  sum[i + u - 1][j - u + 1 - 1] +                  sum[i - u + 1 - 1][j - u + 1 - 1],             total = (2 * u) * (2 * u);         double lv = 1. * sm / total;         if (lv > 0.5)           a[i][j] = 1;         else           a[i][j] = 0;       }     }     for (int i = (int)1; i <= (int)n; i++)       for (int j = (int)1; j <= (int)n; j++) {         if (vis[i][j]) continue;         bfs(i, j);       }     sort(C + 1, C + ans1 + 1);     printf( %d %d n , yuan, ans1 - yuan);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100009];   int dp[100009];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     int ans = 1;     dp[0] = 1;     for (int i = 0; i < n; i++) {       dp[i] = 1;       if (arr[i] >= arr[i - 1]) dp[i] = dp[i - 1] + 1;       ans = max(ans, dp[i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int T;   double pi = acos(-1.0);   vector<long long> v;   long long factorial(long long x) {     long long total = 1;     for (int i = 2; i <= x; i++) total *= i;     return total;   }   bool isprime(long long x) {     vector<bool> prime(x + 1, 1);     prime[0] = prime[1] = 0;     for (long long i = 2; i * i <= x; i++)       if (prime[i])         for (long long j = i * i; j <= x; j += i) prime[j] = 0;     return prime[x];   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long temp = 1;   long long fastpow(long long base, long long exponent) {     if (exponent == 0) return 1;     if (exponent == 1) return (temp * base);     if (exponent % 2 == 0)       return fastpow(base * base, exponent / 2);     else {       temp *= base;       fastpow(base * base, exponent / 2);     }   }   void fill(long long f) {     v.clear();     long long x;     for (long long i = 0; i < f; i++) {       cin >> x;       v.push_back(x);     }   }   void printv() {     int size = v.size() - 1;     for (int i = 0; i <= size; i++) {       cout << v[i] <<    ;     }     cout << endl;   }   bool is = 0;   long long f(long long n) {     long long num = n;     long long Max = 0, Min = 9;     while (n) {       long long dig = n % 10;       if (dig == 0) {         is = 1;         return num;       }       Max = max(Max, dig);       Min = min(Min, dig);       n /= 10;     }     return Max * Min + num;   }   void solve() {     int n, m;     cin >> n >> m;     int cn = 0;     for (int a = 0; a <= 1000; a++)       for (int b = 0; b <= 1000; b++)         if (a * a + b == n && b * b + a == m) {           cn++;         }     cout << cn << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     { solve(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O2 )   const int lim = 2e5 + 5;   long long n, k, x, y, t, ans, p[lim];   map<long long, long long> f;   long long inv(long long x) { return (~x) & ((1LL << k) - 1); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     f[0] += 1;     ans += n * (n + 1);     for (int i = 1; i <= n; i++) {       cin >> x;       p[i] = p[i - 1] ^ x;       f[p[i]]++;     }     for (auto u : f) {       if (f.find(inv(u.first)) == f.end()) {         t = f[u.first] / 2;         y = f[u.first] - t;         ans -= t * (t - 1) + y * (y - 1);       } else {         t = (f[u.first] + f[inv(u.first)]) / 2;         y = f[u.first] + f[inv(u.first)] - t;         ans -= t * (t - 1) / 2 + y * (y - 1) / 2;       }     }     ans /= 2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int matrix[n][n], sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> matrix[i][j];       }     }     int j = 0;     for (int i = 0; i < n; i++) {       sum += matrix[i][i];     }     for (int i = n - 1; i >= 0; i--) {       sum += matrix[i][j];       j++;     }     int ind = (n - 1) / 2;     for (auto it : matrix) sum += it[ind];     for (int i = 0; i < n; i++) sum += matrix[ind][i];     cout << sum - (3 * matrix[ind][ind]);     return 0;   }