#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     int t[m], l[m], r[m];     int a[n + 1];     fill_n(a, n + 1, -1);     a[0] = 1e5;     for (int i = 0; i < m; i++) {       cin >> t[i] >> l[i] >> r[i];       if (t[i] == 1) {         for (int j = l[i] + 1; j <= r[i]; j++) {           a[j] = 1;         }       }     }     for (int i = 0; i < m; i++) {       if (t[i] == 0) {         bool ok = false;         for (int j = l[i] + 1; j <= r[i]; j++) {           ok |= (a[j] == -1);         }         if (ok == false) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     for (int i = 1; i <= n; i++) {       a[i] += a[i - 1];       cout << a[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   const int MAX = 1e3 + 11;   using namespace std;   char A[MAX];   int W[33];   int main() {     scanf( %s , (A));     int(K);     scanf( %d , &K);     for (int i = 0; i < (26); ++i) scanf( %d , &(W[i]));     int mx = 0, N = int(strlen(A));     int v = *max_element(W, W + 26);     for (int i = 0; i < (K + 1); ++i) {       int s = 0, pos = i;       for (int j = 0; j < (N); ++j) {         s += W[A[j] -  a ] * (j + 1 + i);       }       for (int k = 0; k < (pos); ++k) {         s += (k + 1) * v;       }       for (int k = (pos + N); k < (K + N); ++k) {         s += (k + 1) * v;       }       mx = max(mx, s);     }     printf( %d , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   template <class T>   void R(T &x) {     cin >> x;   }   void R(int &x) { scanf( %d , &x); }   void R(long long &x) { scanf( %lld , &x); }   void R(double &x) { scanf( %lf , &x); }   void R(char &x) { scanf(  %c , &x); }   void R(char *x) { scanf( %s , x); }   long long _pow(long long a, long long b) {     long long res = 1ll;     while (b) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return res;   }   int main() {     int n, k;     char t[10005], s[10005];     while (~scanf( %d , &(n))) {       R(k);       R(t);       int len = strlen(t);       int i, j, flag = 0;       for (i = 1; i < len; i++) {         for (j = i; j < len; j++) {           if (t[j] != t[j - i]) break;         }         if (j == len) break;       }       j = len;       for (int o = 1; o < k; o++) {         for (int x = len - i; x < len; x++) t[j++] = t[x];       }       t[j] =   0 ;       puts(t);     }     return 0;   }


#include<set>   #include<map>   #include<stack>   #include<cmath>   #include<queue>   #include<cstdio>   #include<vector>   #include<climits>   #include<cstdlib>   #include<cstring>   #include<iostream>   #include<algorithm>   #define LL long long   using namespace std;   LL read(){    bool f=0;LL x=0;char c=getchar();    while(c< 0 || 9 <c){if(c== - )f=1;c=getchar();}    while( 0 <=c&&c<= 9 ) x=(x<<3)+(x<<1)+(c^48),c=getchar();    return !f?x:-x;   }   typedef pair<long double,long double> pii;   #define mp make_pair   #define fi first   #define se second   #define lch (u<<1)   #define rch (u<<1|1)   const long double eps=1e-10;   const int MAXN=200000;   const int INF=0x3f3f3f3f;   LL a[MAXN+5];   vector<pair<int,LL> > Tu[5*MAXN+5];   bool K(pii p,pii a,pii b){if(p.fi==a.fi) return 1;return (p.se-a.se)/(p.fi-a.fi)>=(p.se-b.se)/(p.fi-b.fi);}   void Build(int u,int L,int R){    if(L==R){     Tu[u].push_back(mp(L,a[L]));     return ;    }    int Mid=(L+R)>>1;    Build(lch,L,Mid),Build(rch,Mid+1,R);    Tu[u]=Tu[lch];    int lst=Tu[u].size()-1;    for(int i=0;i<Tu[rch].size();i++){     while(lst&&K(Tu[u][lst-1],Tu[u][lst],Tu[rch][i])) Tu[u].pop_back(),lst--;     Tu[u].push_back(Tu[rch][i]),lst++;    }    return ;   }   pair<long double,int> P[MAXN+5];   int Query(int u,int L,int R,int qL,int qR,int pos){    if(qL<=L&&R<=qR){     int siz=Tu[u].size();     int le=0,ri=siz;     while(le+1<ri){      int mid=(le+ri)>>1;      if(K(mp(pos,a[pos]),Tu[u][mid-1],Tu[u][mid])) le=mid;      else ri=mid;     }     return Tu[u][le].first;    }    int Mid=(L+R)>>1,ret=-1;    if(qL<=Mid)     ret=Query(lch,L,Mid,qL,qR,pos);    if(Mid+1<=qR){     int tmp=Query(rch,Mid+1,R,qL,qR,pos);     if(ret==-1||K(mp(pos,a[pos]),mp(ret,a[ret]),mp(tmp,a[tmp])))      ret=tmp;    }    return ret;   }   int n,m;   void Get(int L,int R,int ad){    if(L>=R) return ;    int p=Query(1,0,n,L,R,L);    P[p]=mp(1.0*(a[p]-a[L])/(p-L)-eps,R-L-1+ad);    //printf( %f %d %d %d n ,(double)P[p].first,p,L,R-L-1+ad);    Get(L,p-1,1),Get(p,R,ad);    return ;   }   int ans[MAXN+5];   long double k[MAXN+5];   int main(){    n=read(),m=read();    for(int i=1;i<=n;i++)     a[i]=a[i-1]+read();    Build(1,0,n);    Get(0,n,0);    sort(P+1,P+n+1);    for(int i=n;i>=1;i--)     ans[i]=max(P[i].second,ans[i+1]);    for(int i=1;i<=m;i++){     k[i]=read();     int t=upper_bound(P+1,P+n+1,mp(k[i],0))-P;     printf( %d ,ans[t]),putchar(i==m?  n :   );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans, Max, an, x;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (Max < x) {         Max = x;         ans = 0;         an = 0;       }       if (x == Max)         an++;       else         an = 0;       ans = max(ans, an);     }     printf( %d , ans);   }


#include <bits/stdc++.h>   int main() {     unsigned short n;     unsigned short ac1;     unsigned short i;     unsigned short w;     unsigned short ac2;     unsigned short gw;     if (scanf( %hu , &n) != 1) return -1;     if (n < 1 || n > 100) return -1;     ac1 = 0;     for (i = 0; i < n; i++) {       if (scanf( %hu , &w) != 1) return -1;       if (w != 100 && w != 200) return -1;       if (w == 100) ac1++;     }     ac2 = n - ac1;     gw = 50 * (ac1 + 2 * ac2);     if (!(gw % 200) || (!(gw % 100) && ac1))       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxN = 1005;   long long x[maxN], y[maxN];   long long det(int i, int j, int k) {     return (x[j] - x[i]) * (y[k] - y[i]) - (x[k] - x[i]) * (y[j] - y[i]);   }   long long askArea(int i, int j, int k) {     cout << 1 <<     << i <<     << j <<     << k << endl;     long long resp;     cin >> resp;     return resp;   }   int askVec(int i, int j, int k) {     cout << 2 <<     << i <<     << j <<     << k << endl;     int res;     cin >> res;     return res;   }   int n;   int main() {     cin >> n;     int who = n;     vector<int> up, down;     for (int i = 2; i < n; i++) {       if (askVec(1, i, who) < 0) {         up.emplace_back(i);       } else {         down.emplace_back(i);       }     }     vector<pair<long long, int> > get_vals;     for (int v : up) {       get_vals.emplace_back(askArea(1, v, who), v);     }     sort(get_vals.begin(), get_vals.end());     reverse(get_vals.begin(), get_vals.end());     deque<int> ans_up;     if (!get_vals.empty()) ans_up.push_back(get_vals[0].second);     for (int i = 1; i < get_vals.size(); i++) {       int p = get_vals[i].second;       if (askVec(1, p, ans_up.front()) < 0)         ans_up.push_front(p);       else         ans_up.push_back(p);     }     vector<int> perm;     for (int v : ans_up) perm.push_back(v);     perm.push_back(who);     get_vals.clear();     deque<int> ans_down;     for (int v : down) {       get_vals.emplace_back(askArea(1, v, who), v);     }     sort(get_vals.begin(), get_vals.end());     reverse(get_vals.begin(), get_vals.end());     if (!get_vals.empty()) ans_down.push_back(get_vals[0].second);     for (int i = 1; i < get_vals.size(); i++) {       int p = get_vals[i].second;       if (askVec(1, p, ans_down.front()) < 0)         ans_down.push_front(p);       else         ans_down.push_back(p);     }     for (int v : ans_down) perm.push_back(v);     reverse(perm.begin(), perm.end());     cout << 0 <<    ;     cout << 1 <<    ;     for (int v : perm) cout << v <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const long long xx = 2e7;   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   long long isprime(long long n) {     if (n == 2) return 1;     if (n % 2 == 0) return 0;     for (long long i = 3; i * i <= n; i += 2) {       if (n % i == 0) return 0;     }     return 1;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     if (isprime(n)) {       cout << 1 <<   n ;     } else if (n % 2 == 0 || isprime(n - 2)) {       cout << 2 <<   n ;     } else       cout << 3 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 2e5 + 10, N = 260, M = 5e6 + 10;   constexpr int MAX_INF = 0x3f3f3f3f;   int mp[maxn];   int main() {     int T;     cin >> T;     while (T--) {       int n, m;       scanf( %d%d , &n, &m);       int root = 0;       memset(mp, 0, sizeof(mp));       while (m--) {         int a, b, c;         scanf( %d%d%d , &a, &b, &c);         mp[b] = 1;       }       for (int i = 1; i <= n; i++) {         if (!mp[i]) {           root = i;           break;         }       }       for (int i = 1; i <= n; i++) {         if (i == root) continue;         printf( %d %d n , i, root);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, hp = 0, row[100], col[100];   char cake[101][101];   int main() {     for (int i = 0; i < 100; ++i) {       row[i] = 0, col[i] = 0;     }     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> cake[i][j];         if (cake[i][j] ==  C ) {           ++row[j];           ++col[i];         }       }     }     for (int i = 0; i < n; i++) {       hp += (row[i] * (row[i] - 1)) / 2;       hp += (col[i] * (col[i] - 1)) / 2;     }     cout << hp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100001], b[100001];   void solve(int first) {     vector<int> ans(1, first);     for (int i = 1; i < n; i++) {       int pre = ans.back();       for (int j = 0; j <= 3; j++) {         if ((pre & j) == b[i] && (pre | j) == a[i]) {           ans.push_back(j);           break;         }       }     }     if (ans.size() != n) return;     cout <<  YES n ;     for (int x : ans) cout << x <<    ;     exit(0);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) cin >> b[i];     for (int i = 0; i <= 3; i++) solve(i);     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[111];   int b[111];   int main() {     cin >> n >> m;     int s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s ^= a[i];     }     int tmp = 0;     for (int i = 0; i < m; i++) {       cin >> b[i];       tmp ^= b[i];     }     if (tmp != s) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i == 0 && j == 0) {           cout << (tmp ^ a[0] ^ b[0]) <<    ;         } else if (i == 0) {           cout << b[j] <<    ;         } else if (j == 0) {           cout << a[i] <<    ;         } else {           cout << 0 <<    ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp;     cin >> n;     string s;     cin >> s;     temp = n;     for (int i = n - 2; i >= 0; i--) {       if (s.substr(i, 2) ==  10  || s.substr(i, 2) ==  01 ) {         temp -= 2;         s.erase(i, 2);         i++;       }     }     cout << temp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<int, bool> a;     for (int i = 0, j; i < n; i++) {       cin >> j;       a[j] = 1;     }     int k = 0;     vector<int> l;     for (int i = 1; m - i >= 0; i++)       if (!a[i]) {         l.push_back(i);         m -= i;       }     cout << l.size() << endl;     for (int i = 0; i < l.size(); i++) cout << l[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, q, t = 1;   int lson[N * 2], rson[N * 2], vm[2][N * 2], ovl[N * 2];   set<pair<int, int> > sm[2][N * 2];   map<int, int> op[N * 2];   void build(int pos, int x, int y) {     vm[1][pos] = m + 1;     if (x == y) return;     int mid = (x + y) >> 1;     lson[pos] = ++t;     rson[pos] = ++t;     build(lson[pos], x, mid);     build(rson[pos], mid + 1, y);   }   inline int MAX(int knd, int pos) {     if (sm[knd][pos].empty()) return 0;     set<pair<int, int> >::iterator it = sm[knd][pos].end();     it--;     return it->first;   }   inline int MIN(int knd, int pos) {     if (sm[knd][pos].empty()) return m + 1;     return sm[knd][pos].begin()->first;   }   void update(int pos) {     vm[0][pos] = MAX(0, pos);     if (lson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][lson[pos]]);     if (rson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][rson[pos]]);     vm[1][pos] = MIN(1, pos);     if (lson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][lson[pos]]);     if (rson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][rson[pos]]);     ovl[pos] = (MIN(1, pos) <= vm[0][pos]) | (MAX(0, pos) >= vm[1][pos]);     ovl[pos] |= ovl[lson[pos]] | ovl[rson[pos]];   }   void modify(int knd, int pos, int l, int r, int x, int y, pair<int, int> v) {     if (l >= x && r <= y) {       if (knd == 0) {         if (sm[knd][pos].find(v) != sm[knd][pos].end())           sm[knd][pos].erase(v);         else           sm[knd][pos].insert(v);       } else {         if (sm[knd][pos].find(v) != sm[knd][pos].end())           sm[knd][pos].erase(v);         else           sm[knd][pos].insert(v);       }       update(pos);       return;     }     if (l > y || r < x) return;     int mid = (l + r) >> 1;     modify(knd, lson[pos], l, mid, x, y, v);     modify(knd, rson[pos], mid + 1, r, x, y, v);     update(pos);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     build(1, 1, n);     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (op[x][y] == 0) {         op[x][y] = i;         if (x % 2 == 0)           modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, i));         else           modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, i));       } else {         if (x % 2 == 0)           modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, op[x][y]));         else           modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, op[x][y]));         op[x][y] = 0;       }       if (ovl[1])         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2 && y1 == y2) {       cout <<  10 ;       return;     }     if (x1 == x2) {       cout << 2 * (abs(y2 - y1) + 1) + 4;       return;     }     if (y1 == y2) {       cout << 2 * (abs(x2 - x1) + 1) + 4;       return;     }     cout << 2 * (abs(x2 - x1) + abs(y2 - y1) + 2);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const int N = 1 << 7, M = 1 << 14;   int a[M], b[M], c[M];   bool val[N], vis[N];   vector<int> g[N];   int n, m;   bool dfs(int u, bool x) {     val[u] = x;     vis[u] = true;     for (int e : g[u]) {       int v = a[e] ^ b[e] ^ u;       bool new_x = c[e] ^ 1 ^ x;       if (!vis[v]) {         if (!dfs(v, new_x)) return false;       } else if (new_x != val[v])         return false;     }     return true;   }   bool solve(bool init) {     fill(vis, vis + n, false);     fill(val, val + n, false);     for (auto u = (0); u < (n); ++u)       if (!vis[u] && !dfs(u, init)) return false;     return true;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (auto e = (0); e < (m); ++e) {       cin >> a[e] >> b[e] >> c[e], --a[e], --b[e];       g[a[e]].push_back(e);       g[b[e]].push_back(e);     }     if (solve(0) || solve(1)) {       int cnt = 0;       for (auto u = (0); u < (n); ++u) cnt += val[u];       cout << cnt <<   n ;       for (auto e = (0); e < (m); ++e) assert(c[e] ^ val[a[e]] ^ val[b[e]]);       for (auto u = (0); u < (n); ++u)         if (val[u]) cout << u + 1 <<    ;     } else       cout <<  Impossible ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int M = 400005;   inline int read() {     int 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 f * x;   }   int n, m, q, num;   int hd[N], nxt[M], to[M], tot;   inline void add(int x, int y) {     to[++tot] = y;     nxt[tot] = hd[x];     hd[x] = tot;   }   int dfn[N], low[N], dfn_cnt;   int st[N], tp;   bool vis[N];   vector<int> G[N];   void tarjan(int x) {     vis[x] = 1;     st[++tp] = x;     dfn[x] = low[x] = ++dfn_cnt;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (!dfn[y]) {         tarjan(y);         low[x] = min(low[x], low[y]);         if (low[y] == dfn[x]) {           ++num;           while (st[tp + 1] != y) {             G[num].push_back(st[tp]);             G[st[tp]].push_back(num);             vis[st[tp--]] = 0;           }           G[num].push_back(x);           G[x].push_back(num);         }       } else if (vis[y])         low[x] = min(low[x], dfn[y]);     }   }   multiset<int> s[N];   int siz[N], fa[N], dep[N], son[N];   void dfs_son(int x, int f) {     fa[x] = f;     siz[x] = 1;     dep[x] = dep[f] + 1;     for (int i = 0; i < G[x].size(); i++) {       int y = G[x][i];       if (y == f) continue;       dfs_son(y, x);       siz[x] += siz[y];       if (siz[y] > siz[son[x]]) son[x] = y;     }   }   int rev[N], top[N];   void dfs_chain(int x, int tp) {     top[x] = tp;     dfn[x] = ++dfn_cnt;     rev[dfn_cnt] = x;     if (son[x]) dfs_chain(son[x], tp);     for (int i = 0; i < G[x].size(); i++) {       int y = G[x][i];       if (y == fa[x] || y == son[x]) continue;       dfs_chain(y, y);     }   }   int val[N << 2];   int w[N];   void build(int l, int r, int p) {     if (l == r) {       val[p] = w[rev[l]];       return;     }     build(l, ((l + r) >> 1), (p << 1));     build(((l + r) >> 1) + 1, r, (p << 1 | 1));     val[p] = min(val[(p << 1)], val[(p << 1 | 1)]);   }   void modify(int l, int r, int t, int v, int p) {     if (l == r) {       val[p] = v;       return;     }     if (t <= ((l + r) >> 1))       modify(l, ((l + r) >> 1), t, v, (p << 1));     else       modify(((l + r) >> 1) + 1, r, t, v, (p << 1 | 1));     val[p] = min(val[(p << 1)], val[(p << 1 | 1)]);   }   int query(int l, int r, int L, int R, int p) {     if (L <= l && r <= R) return val[p];     int ans = 0x3f3f3f3f;     if (L <= ((l + r) >> 1))       ans = min(ans, query(l, ((l + r) >> 1), L, R, (p << 1)));     if (R > ((l + r) >> 1))       ans = min(ans, query(((l + r) >> 1) + 1, r, L, R, (p << 1 | 1)));     return ans;   }   int get_min(int x, int y) {     int ans = 0x3f3f3f3f;     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       ans = min(ans, query(1, num, dfn[top[x]], dfn[x], 1));       x = fa[top[x]];     }     if (dfn[x] > dfn[y]) swap(x, y);     ans = min(ans, query(1, num, dfn[x], dfn[y], 1));     if (x > n) ans = min(ans, w[fa[x]]);     return ans;   }   int main() {     n = read();     m = read();     q = read();     for (int i = 1; i <= n; i++) w[i] = read();     num = n;     for (int i = 1, x, y; i <= m; i++) {       x = read();       y = read();       add(x, y), add(y, x);     }     tarjan(1);     dfn_cnt = 0;     dfs_son(1, 0);     dfs_chain(1, 1);     for (int i = 1; i <= n; i++)       if (fa[i]) s[fa[i]].insert(w[i]);     for (int i = n + 1; i <= num; i++) w[i] = *s[i].begin();     memset(val, 0x3f, sizeof(val));     build(1, num, 1);     char op;     int x, y;     while (q--) {       cin >> op;       x = read();       y = read();       if (op ==  C ) {         modify(1, num, dfn[x], y, 1);         if (fa[x]) {           s[fa[x]].erase(s[fa[x]].lower_bound(w[x]));           s[fa[x]].insert(y);           if (w[fa[x]] != *s[fa[x]].begin()) {             w[fa[x]] = *s[fa[x]].begin();             modify(1, num, dfn[fa[x]], w[fa[x]], 1);           }         }         w[x] = y;       } else         printf( %d n , get_min(x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int(i) = 0; (i) < (sz(t)); ++(i)) s << t[i] <<    ;     return s;   }   int r, n;   long long MOD = 1000003;   long long qp(long long a, long long b) {     long long x = 1;     while (b) {       if (b & 1) x = x * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return x;   }   int main() {     cin >> r >> n;     long long ans = 0, cur = 1;     for (int a = n, b = 1; b <= r; a++, b++) {       cur = cur * a % MOD * qp(b, MOD - 2) % MOD;       ans = (ans + cur) % MOD;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string name, a;     vector<pair<int, string> > s;     vector<pair<int, string> > v(n);     for (int i = 0; i < (int)n; i++) cin >> v[i].second >> v[i].first;     sort(v.begin(), v.end());     int h = 1e9;     for (int i = 0; i < (int)n; i++) {       if (v[i].first > (int)s.size()) {         cout << -1 << endl;         return 0;       }       if (i && v[i - 1].first != v[i].first) h--;       s.insert(s.begin() + v[i].first, make_pair(h, v[i].second));     }     for (int i = 0; i < (int)s.size(); i++)       cout << s[i].second <<     << s[i].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int ans = 0;       if (n < k) {         cout << n << endl;         continue;       }       while (n != 0) {         if (n % k == 0) {           n = n / k;           ans++;         } else {           long long x = n % k;           n -= x;           ans += x;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111;   const double INF = 1e200;   double dp[N][10 * N];   struct problem {     int a, p;     bool operator<(const problem &o) const { return a > o.a; }   } p[N];   int n;   double C, T;   double solve(double x) {     x /= 0.9;     auto t = (sqrt(C * x) - 1) / C;     t = max(t, 0.0);     return x / (1 + C * t) + t;   }   int main() {     int tc;     cin >> tc;     while (tc--) {       cin >> n >> C >> T;       for (int i = 0; i < n; i++) cin >> p[i].a >> p[i].p;       sort(p, p + n);       fill(dp[0], dp[N], INF);       dp[0][0] = 0;       int sum = 0;       for (int i = n - 1; i >= 0; i--) {         for (int k = n - 1 - i; k >= 0; k--) {           for (int s = sum; s >= 0; s--)             if (dp[k][s] < INF) {               dp[k + 1][s + p[i].p] =                   min(dp[k + 1][s + p[i].p], dp[k][s] / 0.9 + p[i].a);             }         }         sum += p[i].p;       }       int ans = 0;       for (int s = sum; s > 0; s--) {         for (int k = 0; k <= n; k++) {           if (dp[k][s] < INF) {             auto cost = k * 10 + solve(dp[k][s]);             if (cost <= T) {               ans = max(ans, s);             }           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101], ans = 0;     cin >> n;     bool flag = false;     for (int i = 1; i <= n; i += 1) {       cin >> a[i];       if (a[i] == 100) flag = true;       ans += a[i];     }     if (ans % 200 == 100)       cout <<  NO  << endl;     else {       if (ans % 400 == 0)         cout <<  YES  << endl;       else if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10 * 100 * 1000 + 10;   vector<int> vec[N];   int bit[N];   int n, c;   void addbit(int i, int p) {     for (i++; i <= c; i += (i & -i)) bit[i] += p;   }   int get(int i) {     int x = 0;     for (i++; i > 0; i -= (i & -i)) x += bit[i];     return x;   }   void add(int l, int r) {     addbit(l, 1);     addbit(r, -1);   }   int main() {     cin >> n >> c;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       for (int j = 0; j < t; j++) {         int a;         cin >> a;         vec[i].push_back(a - 1);       }     }     for (int i = 0; i < n - 1; i++) {       int j = 0, k = 0;       while (j < (int)vec[i].size() && k < (int)vec[i + 1].size() &&              vec[i][j] == vec[i + 1][k])         j++, k++;       if (j == (int)vec[i].size())         add(0, c);       else if (k == (int)vec[i + 1].size()) {         cout <<  -1 n ;         return 0;       } else {         int a = vec[i][j], b = vec[i + 1][k];         int li = (c - a) % c, ri = (c - b) % c;         if (li < ri)           add(li, ri);         else           add(li, c), add(0, ri);       }     }     for (int i = 0; i < c; i++)       if (get(i) >= n - 1) {         cout << i << endl;         return 0;       }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %i , &n);     int a = n / 3, b = n - a;     for (i = 1; i <= b; i++) printf( 1 %i n , i);     for (i = 1; i <= a; i++) printf( 4 %i n , i * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s, ret;   bool dfs(int idx, int four, int seven, bool flag) {     if (idx == n) return true;     if (flag) {       for (int i = 0; i < four; i++) ret[idx + i] =  4 ;       for (int i = four; i < four + seven; i++) ret[idx + i] =  7 ;       return true;     }     if (four > 0 && s[idx] <=  4  &&         dfs(idx + 1, four - 1, seven, s[idx] <  4 )) {       ret[idx] =  4 ;       return true;     }     if (seven > 0 && s[idx] <=  7  &&         dfs(idx + 1, four, seven - 1, s[idx] <  7 )) {       ret[idx] =  7 ;       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s;     n = s.length();     ret.resize(n);     if (n % 2 == 1 || !dfs(0, n / 2, n / 2, false)) {       int half = (n + 2) / 2;       for (int i = 0; i < half; i++) cout <<  4 ;       for (int i = 0; i < half; i++) cout <<  7 ;       cout <<   n ;     } else       cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void Routine() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   template <class T, class U>   istream &operator>>(istream &in, pair<T, U> &p) {     in >> p.fi >> p.se;     return in;   }   template <class T, class U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     out << p.first <<     << p.second;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &i : v) {       in >> i;     }     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &v) {     for (auto &i : v) {       out << i <<   n ;     }     return out;   }   const long long mod = 1e9 + 7;   int main() {     Routine();     long long q, l1, l2, r1, r2, i;     cin >> q;     for (i = 0; i < q; i++) {       cin >> l1 >> r1 >> l2 >> r2;       if (l1 != r2) {         cout << l1 <<     << r2 <<   n ;       } else {         cout << r1 <<     << l2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   using namespace std::chrono;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     string s;     cin >> s;     long long int a[26];     for (int i = 0; i < 26; i++) cin >> a[i];     long long int maxx = -1, len = 0, minn;     vector<long long int> dp(n + 1, 0), dp2(n + 1, 1e12);     for (int i = 0; i < n; i++) {       minn = 1e12;       for (int j = i; j >= 0; j--) {         len = i - j + 1;         minn = min(minn, a[s[j] -  a ]);         if (minn < len) break;         long long int x = j - 1 >= 0 ? dp[j - 1] : 1;         dp[i] = (dp[i] + x) % mod;         maxx = max(maxx, len);         x = j - 1 >= 0 ? dp2[j - 1] : 0;         dp2[i] = min(dp2[i], x + 1);       }     }     cout << dp[n - 1] % mod << endl << maxx << endl << dp2[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Wall {     int l, r, t;     void init(int _l, int _r, int _t) { l = _l, r = _r, t = _t; }     void input() { scanf( %d%d%d , &l, &r, &t); }     static bool by_l(const Wall &a, const Wall &b) { return a.l < b.l; }     bool operator<(const Wall &a) const { return t > a.t; }   } w[500010], wc[500010];   struct Table {     int a[500010 * 2], top;     Table() { top = 0; }     void insert(int x) { a[top++] = x; }     void sort() {       std::sort(a, a + top);       top = unique(a, a + top) - a;     }     int search(int x) { return lower_bound(a, a + top, x) - a; }   } table;   struct Tri {     int x, p;     void init(int _x, int _p) { x = _x, p = _p; }     bool operator<(const Tri &a) const { return x < a.x; }   } tri[500010];   int q[500010];   int main() {     int n, m;     cin >> m >> n;     for (int i = 0; i < n; ++i) {       w[i].input();     }     for (int i = 0; i < m; ++i) {       scanf( %d , q + i);     }     sort(w, w + n, Wall::by_l);     for (int i = 0; i < n; ++i) {       table.insert(w[i].l), table.insert(w[i].r);     }     table.sort();     priority_queue<Wall> que;     int nc = 0;     for (int i = 0, j = 0; i < table.top - 1; ++i) {       while (j < n && w[j].l <= table.a[i]) {         que.push(w[j++]);       }       while (!que.empty()) {         Wall wall = que.top();         if (wall.r > table.a[i]) {           wc[nc++].init(table.a[i], table.a[i + 1], wall.t);           break;         }         que.pop();       }     }     int ntri = 0;     for (int i = 0; i < nc; ++i) {       tri[ntri++].init(wc[i].t - wc[i].r, 1);       tri[ntri++].init(wc[i].t - wc[i].l, -1);     }     sort(tri, tri + ntri);     int sgm = 0, cnt = 0;     for (int i = 0, j = 0; i < m; ++i) {       while (j < ntri && tri[j].x <= q[i]) {         cnt += tri[j].p;         sgm += tri[j].x * tri[j].p;         ++j;       }       printf( %d n , q[i] * cnt - sgm);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[200001];     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     long long buy = a[n - 1];     int pre = a[n - 1];     for (i = n - 2; i >= 0; i--) {       if (a[i] >= pre - 1) {         if (pre - 1 == 0)           break;         else           buy += pre - 1;         pre--;       } else {         buy += a[i];         pre = a[i];       }     }     printf( %lld n , buy);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     set<string> s;     s.insert( don t even );     s.insert( worse );     s.insert( terrible );     s.insert( no way );     s.insert( go die in a hole );     s.insert( are you serious );     int c = 0;     while (true) {       cout << c++ << endl;       string t;       getline(cin, t);       if (t !=  no ) {         if (s.count(t) == 0) {           cout <<  normal  << endl;           return 0;         } else {           cout <<  grumpy  << endl;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int max = a[0];     int pos = 0;     for (int i = 0; i < n; i++) {       if (max < a[i]) {         max = a[i];         pos = i;       }     }     bool k = true;     for (int i = pos; i > 0; i--) {       if (a[i - 1] >= a[i]) {         k = false;       }     }     for (int i = pos; i < n - 1; i++) {       if (a[i] <= a[i + 1]) {         k = false;       }     }     if (k == true)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> sum;   vector<vector<bool>> used;   int n, m;   int g = 0;   int k = 0;   vector<pair<int, int>> p = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   void dfs(int first, int second, const int &r1, const int &r2, const int &l1,            const int &l2) {     if (first <= r1 || first > r2 || second <= l1 || second > l2 ||         used[first][second])       return;     used[first][second] = true;     k++;     for (int i = 0; i < 4; i++)       dfs(first + p[i].first, second + p[i].second, r1, r2, l1, l2);   }   bool f(int r) {     r = r * 2 + 1;     k = 0;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= m; j++) used[i][j] = false;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (i >= r && j >= r &&             sum[i][j] - sum[i - r][j] - sum[i][j - r] + sum[i - r][j - r] ==                 r * r) {           dfs(i, j, i - r, i, j - r, j);         }     if (k == g)       return true;     else       return false;   }   int main() {     cin >> n >> m;     sum.resize(n + 1, vector<int>(m + 1, 0));     used.resize(n + 1, vector<bool>(m + 1, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         char c;         cin >> c;         sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j];         if (c ==  X ) sum[i + 1][j + 1]++;       }     g = sum.back().back();     int l = 0, r = min(n / 2 + 2, m / 2 + 2);     while (l + 1 < r) {       int c = (l + r) / 2;       if (f(c))         l = c;       else         r = c;     }     cout << l <<   n ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i >= l + 1 && j >= l + 1 && i + l <= n && j + l <= m &&             sum[i + l][j + l] - sum[i - l - 1][j + l] - sum[i + l][j - l - 1] +                     sum[i - l - 1][j - l - 1] ==                 (2 * l + 1) * (2 * l + 1))           cout <<  X ;         else           cout <<  . ;       }       cout <<   n ;     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       int sum = 0, odd = 0, even = 0;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         if (x % 2 == 0) {           even++;         } else {           odd++;         }         sum += x;       }       if (sum % 2 == 1) {         cout <<  YES n ;       } else {         if (odd < n && odd > 0) {           cout <<  YES n ;         } else {           cout <<  NO n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1E9;   const long long LINF = (long long)1E18;   int INP, AM;   char BUF[(1 << 10) + 1], *inp = BUF;   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const char IN[] =  input.txt ;   const char OUT[] =  output.txt ;   int ntest = 0, test;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       freopen(IN,  r , stdin);     }     init();     if (ntest == 0) {       puts( ntest = ? );       return 0;     }     for (test = 1; test <= ntest; test++) {       run();     }     return 0;   }   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double EPS = 1E-9;   const long long MODULO = 1000000007LL;   inline void init() { ntest = 1; }   double s;   void run() {     cin >> s;     double a, b, c;     cin >> a >> b >> c;     if (a == 0 && b == 0 && c == 0) {       cout <<  0 0 0 ;       return;     }     double sum = a + b + c;     printf( %.20lf %.20lf %.20lf , a / sum * s, b / sum * s, c / sum * s);   }


#include <bits/stdc++.h>   #include <iomanip>      // std::setprecision      #define ll long long   const long modulo=1000000007;      using namespace std;            int ctoi(char c) {return c- 0 ;}            int compare(pair <int,pair<int,int>> one, pair <int,pair<int,int>> two){    if(one.first<two.first) return 1;    return 0;   }      ll power(ll a, ll b){   ll res=1;   while(b!=0){      if(b%2==1){    res*=a;    //res%=modulo;   }   a*=a;   //a%=modulo;   b/=2;   }   return res;   }      int dp[501][501][21]={0};   int n,m,k;   int dn[501][501];   int rightt[501][501];      int explore(int q,int i,int j){      if(q==0){ return 0;   }      if(dp[i][j][q]!=0){    //cout<< 1 ;    return dp[i][j][q];   }    int ans = dp[i][j][k];   ans=INT_MAX;       if(j<m-1) ans=min(ans,explore(q-2,i,j+1) + 2*dn[i][j]);    if(j>0)ans=min(ans,explore(q-2,i,j-1) +2*dn[i][j-1]);    if(i<n-1)ans=min(ans,explore(q-2,i+1,j) +2*rightt[i][j]);    if(i>0)ans=min(ans,explore(q-2,i-1,j) +2*rightt[i-1][j]);          //ans=min(min(explore(d,r,n-2,i,j-1,dn,right) +2*dn[i][y0], explore(d,r,n-2,i,j+1,dn,right) +2*dn[i][y]),min(explore(d,r,n-2,i-1,j,dn,right)+2*right[x0][j], explore(d,r,n-2,i+1,j,dn,right)+2*right[x][j]));    dp[i][j][q]=ans;    return ans;            }         void solve()   {      cin>>n>>m>>k;            if(k%2!=0){      for(int i=0;i<n;i++){    for(int j=0;j<m;j++){          cout<< -1 <<   ;    }    cout<<endl;   }   return;   }      for(int i=0;i<n;i++){    for(int j=0;j<m-1;j++){     cin>>dn[i][j];    }      }      for(int i=0;i<n-1;i++){    for(int j=0;j<m;j++){     cin>>rightt[i][j];    }      }      int ans[501][501];      for(int i=0;i<n;i++){    for(int j=0;j<m;j++){     ans[i][j]=explore(k,i,j);     cout<<ans[i][j]<<   ;    }    cout<<endl;   }            }                        int main() {        #ifndef ONLINE_JUDGE        freopen( input.txt ,  r , stdin);        freopen( output.txt ,  w , stdout);     #endif    ios_base::sync_with_stdio(false);        cin.tie(NULL);            ll t=1;//cin>>t;   while(t--){      solve();      }         return 0;   }            //rememberhere


#include <bits/stdc++.h>   using namespace std;   long long ar[1005][1005], br[1005][1005], fr[555];   string s[555];   string s1, s2;   int main() {     long long i, j, k, m, n, r, c;     while (cin >> r >> c) {       getchar();       s[0] =   ;       for (i = 1; i <= r; i++) {         getline(cin, s[i]);       }       n = r;       if (n & 1) {         cout << n << endl;         continue;       }       while (n > 0) {         i = 1;         j = n;         while (s[i] == s[j]) {           i++, j--;           if (i > j) break;         }         if (i > j)           n /= 2;         else {           cout << n << endl;           return 0;         }         if (n & 1) {           cout << n << endl;           return 0;         }       }       cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[27][200010];   int main() {     string s;     int q, i, j, l, r, c;     cin >> s >> q;     memset(cnt, 0, sizeof(cnt));     for (i = 0; i < s.length(); i++) {       c = s[i] -  a ;       cnt[c][i + 1]++;       for (j = 0; j < 26; j++) cnt[j][i + 1] += cnt[j][i];     }     for (; q > 0; q--) {       scanf( %d%d , &l, &r);       if (l == r)         cout <<  Yes  << endl;       else {         if (s[l - 1] != s[r - 1])           cout <<  Yes  << endl;         else {           int sum = 0;           for (i = 0; i < 26; i++) {             if (cnt[i][r] - cnt[i][l - 1] >= 1) sum++;             if (sum == 3) break;           }           if (sum == 3)             cout <<  Yes  << endl;           else             cout <<  No  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool palindrom = true;     for (int i = 0; i < ceil(s.length() / 2.0); i++) {       if (s[i] != s[s.length() - 1 - i]) palindrom = false;     }     if (!palindrom) {       cout << s.length() <<   n ;       return 0;     }     char elso = s[0];     bool mind_ugyanaz = true;     for (auto c : s) {       if (c != elso) mind_ugyanaz = false;     }     if (mind_ugyanaz)       cout <<  0 n ;     else       cout << s.length() - 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, dfn[100010], siz[100010], tim, idfn[100010], a[100010], Q;   vector<int> v[100010];   inline int add(int a, int b) {     if ((a += b) >= m) a -= m;     return a;   }   void dfs(int np, int fath) {     dfn[np] = ++tim;     idfn[tim] = np;     siz[np] = 1;     for (auto &x : v[np]) {       if (x == fath) continue;       dfs(x, np);       siz[np] += siz[x];     }   }   bitset<1000> bas, prm;   inline void shift(bitset<1000> &bt, int v) {     if (!v) return;     bt = ((bt << v) | (bt >> (m - v))) & bas;   }   class sgt {    public:     bitset<1000> dat[400010];     int lzy[400010];     void pushnow(int p, int v) {       lzy[p] = add(lzy[p], v);       shift(dat[p], v);     }     void pushdown(int p) {       if (lzy[p]) {         pushnow((p << 1), lzy[p]);         pushnow(((p << 1) | 1), lzy[p]);         lzy[p] = 0;       }     }     void pushup(int p) { dat[p] = dat[(p << 1)] | dat[((p << 1) | 1)]; }     void build(int p, int l, int r) {       for (int i = l; i <= r; i++) dat[p].set(a[idfn[i]]);       if (l == r) return;       int mid = (l + r) >> 1;       build((p << 1), l, mid);       build(((p << 1) | 1), mid + 1, r);     }     void modify(int p, int l, int r, int ml, int mr, int v) {       if (ml <= l && r <= mr) {         pushnow(p, v);         return;       }       pushdown(p);       int mid = (l + r) >> 1;       if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);       if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);       pushup(p);     }     void query(int p, int l, int r, int ql, int qr, bitset<1000> &q) {       if (ql <= l && r <= qr) {         q |= dat[p];         return;       }       pushdown(p);       int mid = (l + r) >> 1;       if (ql <= mid) query((p << 1), l, mid, ql, qr, q);       if (qr > mid) query(((p << 1) | 1), mid + 1, r, ql, qr, q);       return;     }   } T;   vector<int> prime;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) bas.set(i);     for (int i = 2; i < m; i++) prm.set(i);     for (int i = 2; i < m; i++) {       if (prm[i]) prime.push_back(i);       for (int j = 0; j < prime.size() && i * prime[j] < m; j++) {         prm[i * prime[j]] = 0;         if ((i % prime[j]) == 0) break;       }     }     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] %= m;     for (int i = 1, ti, tj; i < n; i++) {       scanf( %d%d , &ti, &tj);       v[ti].push_back(tj);       v[tj].push_back(ti);     }     dfs(1, 0);     T.build(1, 1, n);     scanf( %d , &Q);     bitset<1000> ans;     while (Q--) {       int opt, x, y;       scanf( %d%d , &opt, &x);       if (opt == 1) {         scanf( %d , &y);         y %= m;         T.modify(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, y);       } else {         ans.reset();         T.query(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, ans);         printf( %d n , (ans & prm).count());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ppp {     int x1, x2, y1, y2;     void make_pair(int x1_, int x2_, int y1_, int y2_) {       x1 = x1_;       x2 = x2_;       y1 = y1_;       y2 = y2_;     }   } a[120];   long long ans;   int n, m, i, j, k, x, y, l, r, P[220], tot, Pn, u, d;   char c[1010][1010];   int Find(int x) { return lower_bound(P + 1, P + Pn + 1, x) - P; }   int main() {     scanf( %d%d%*d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , c[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (c[i][j] ==  * ) {           k = j;           while (c[i][k] ==  * ) k++;           k--;           l = i;           while (c[l][j] ==  * ) l++;           l--;           for (x = i; x <= l; ++x)             for (y = j; y <= k; ++y) c[x][y] =  . ;           a[++tot].make_pair(i, l, j, k);           P[++Pn] = i;           P[++Pn] = l;         }     P[++Pn] = 0;     P[++Pn] = n + 1;     sort(P + 1, P + Pn + 1);     Pn = unique(P + 1, P + Pn + 1) - P - 1;     for (i = 1; i <= tot; ++i) a[i].x1 = Find(a[i].x1), a[i].x2 = Find(a[i].x2);     for (u = 2; u < Pn; ++u) {       for (d = u; d < Pn; ++d) {         long long tmp = 0;         vector<pair<int, int> > Q;         for (i = 1; i <= tot; ++i) {           if (a[i].x2 < u || a[i].x1 > d) continue;           if (a[i].x1 >= u && a[i].x2 <= d)             Q.push_back(make_pair(a[i].y1, -1)),                 Q.push_back(make_pair(a[i].y2, 1));           else             Q.push_back(make_pair(a[i].y1, -100)),                 Q.push_back(make_pair(a[i].y2, 100));         }         sort(Q.begin(), Q.end());         int num = Q.size(), C, suml, sumr, cc;         Q.push_back(make_pair(m + 1, 0));         for (int C = 1; C <= 3; ++C) {           suml = sumr = 0;           cc = 0;           for (l = 0, r = 0; r < num; ++r) {             sumr += Q[r].second;             cc += max(0, Q[r].second);             if (!sumr) {               while (suml || cc > C) {                 suml -= Q[l].second;                 cc -= max(0, Q[l].second);                 l++;               }               if (!suml && cc == C)                 tmp += (Q[r + 1].first - Q[r].first) *                        (Q[l].first - (!l ? 0 : Q[l - 1].first));             }           }         }         ans += tmp * (P[u] - P[u - 1]) * (P[d + 1] - P[d]);       }     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   int n, k, s, e, m, ans, temp, tp, tv;   bool m11, m22, first, b[100005], move;   char a[100005];   int dist() {     if (m - s < e - m)       return e - m;     else       return m - s;   }   int main() {     scanf( %d %d , &n, &k);     scanf( %s , a);     for (e = 0; e < n; e++) {       if (a[e] ==  0 ) temp++;       if (a[e] ==  0  && !first) s = e, first = true;       if (temp >= k + 1) break;     }     m = s;     ans = dist();     while (e < n) {       tv = dist();       tp = m;       move = false;       if (ans > dist()) {         ans = dist();       }       while (m <= e) {         m++;         if (a[m] ==  0 ) {           if (tv > dist()) {             tv = dist();             tp = m;             if (ans > dist()) {               ans = dist();             }           } else {             m = tp;             break;           }         }       }       while (e < n) {         e++;         if (e < n && a[e] ==  0 ) {           while (true) {             s++;             if (a[s] ==  0 ) {               if (m < s) {                 m = s;               }               move = true;               break;             }           }         }         if (move) break;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> temp[102][102];   int ans[102][102];   int main() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         temp[i][j].first = i;         temp[i][j].second = j;       }     }     while (q--) {       int t;       cin >> t;       if (t == 1) {         int r;         cin >> r;         pair<int, int> p;         p = temp[r][1];         for (int j = 1; j < m; j++) {           temp[r][j] = temp[r][j + 1];         }         temp[r][m] = p;       } else if (t == 2) {         int c;         cin >> c;         pair<int, int> p;         p = temp[1][c];         for (int j = 1; j < n; j++) {           temp[j][c] = temp[j + 1][c];         }         temp[n][c] = p;       } else {         int r, c, x;         cin >> r >> c >> x;         int indx1 = temp[r][c].first;         int indx2 = temp[r][c].second;         ans[indx1][indx2] = x;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   using namespace std;   long long powmod(long long a, long long b, long long mod) {     if (b == 0 || a == 1) {       if (mod == 1)         return 0;       else         return 1;     }     if (b % 2 == 0) {       long long k = powmod(a, b / 2, mod);       return (k * k) % mod;     } else {       long long k = powmod(a, b / 2, mod);       return ((k * k) % mod * a) % mod;     }   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b)       return gcd(a % b, b);     else       return gcd(b % a, a);   }   long long prime(long long p) {     for (long long i = 2; i * i <= p; i++) {       if (p % i == 0 && i < p) return i;     }     return 1;   }   long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); }   void solve(long long ppppppppp = 1) {     long long a, b;     cin >> a >> b;     if (a + b == 2) {       cout << 0;       return;     }     if (a == 1) {       for (long long i = 0; i < b; i++) cout << i + 2 <<    ;       return;     }     if (b == 1) {       for (long long i = 0; i < a; i++) cout << i + 2 <<    ;       return;     }     for (long long i = 0; i < a; i++) {       for (long long j = 0; j < b; j++) cout << (i + 1) * (a + j + 1) <<    ;       cout <<   n ;     }     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tututu;     tututu = 1;     for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   pair<pair<int, int>, int> queries[N];   long long arr[N], acc[N], in[N];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       in[i] = x;     }     for (int i = 0; i < m; ++i) {       scanf( %d %d %d , &queries[i].first.first, &queries[i].first.second,             &queries[i].second);       --queries[i].first.first;       --queries[i].first.second;     }     for (int i = 0; i < k; ++i) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       acc[a] += 1;       acc[b + 1] -= 1;     }     for (int i = 1; i < m; ++i) {       acc[i] += acc[i - 1];     }     for (int i = 0; i < m; ++i) {       int a = queries[i].first.first;       int b = queries[i].first.second;       long long x = queries[i].second * acc[i];       arr[a] += x;       arr[b + 1] -= x;     }     for (int i = 1; i < n; ++i) {       arr[i] += arr[i - 1];     }     for (int i = 0; i < n - 1; ++i) {       cout << arr[i] + in[i] <<    ;     }     cout << arr[n - 1] + in[n - 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long R = 1, n, q, arr[N];   vector<long long> a[N];   long long h[N], p[N][20];   long long cnt = 0, st[N], en[N], pos[2 * N];   long long it[8 * N], lz[8 * N];   void dfs(long long u) {     st[u] = ++cnt;     pos[cnt] = arr[u];     for (long long i = 1; i < 17; ++i) p[u][i] = p[p[u][i - 1]][i - 1];     for (long long i = 0; i < a[u].size(); ++i) {       long long v = a[u][i];       if (v == p[u][0]) continue;       h[v] = h[u] + 1;       p[v][0] = u;       dfs(v);     }     en[u] = ++cnt;     pos[cnt] = arr[u];   }   long long par(long long u, long long d) {     for (long long i = 0; i < 17; ++i)       if ((d >> i & 1)) u = p[u][i];     return u;   }   long long lca(long long u, long long v) {     if (h[u] != h[v]) {       if (h[u] < h[v]) swap(u, v);       u = par(u, h[u] - h[v]);     }     if (u == v) return u;     for (long long i = 16; i >= 0; --i)       if (p[u][i] != p[v][i]) {         u = p[u][i];         v = p[v][i];       }     return p[u][0];   }   void build_IT(long long i, long long l, long long r) {     if (l == r) {       it[i] = pos[l];       return;     }     long long m = (l + r) / 2;     build_IT(i * 2, l, m);     build_IT(i * 2 + 1, m + 1, r);     it[i] = it[i * 2] + it[i * 2 + 1];   }   void true_val(long long i, long long l, long long r) {     if (lz[i] == 0) return;     it[i] += (r - l + 1) * lz[i];     if (l != r) {       lz[i * 2] += lz[i];       lz[i * 2 + 1] += lz[i];     }     lz[i] = 0;   }   void update(long long i, long long l, long long r, long long a, long long b,               long long val) {     true_val(i, l, r);     if (l > b || r < a || l > r) return;     if (a <= l && r <= b) {       it[i] += (r - l + 1) * val;       if (l != r) {         lz[i * 2] += val;         lz[i * 2 + 1] += val;       }       return;     }     long long m = (l + r) / 2;     update(i * 2, l, m, a, b, val);     update(i * 2 + 1, m + 1, r, a, b, val);     it[i] = it[i * 2] + it[i * 2 + 1];   }   long long get(long long i, long long l, long long r, long long a, long long b) {     true_val(i, l, r);     if (l > b || r < a || l > r) return 0;     if (a <= l && r <= b) return it[i];     long long m = (l + r) / 2;     return get(i * 2, l, m, a, b) + get(i * 2 + 1, m + 1, r, a, b);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     scanf( %lld%lld , &n, &q);     for (long long i = 1; i <= n; ++i) scanf( %lld , &arr[i]);     for (long long i = 1; i < n; ++i) {       long long x, y;       scanf( %lld%lld , &x, &y);       a[x].push_back(y);       a[y].push_back(x);     }     dfs(1);     n *= 2;     build_IT(1, 1, n);     while (q--) {       long long t;       scanf( %lld , &t);       if (t == 1) {         scanf( %lld , &R);         continue;       }       if (t == 3) {         long long u, ans = 0;         scanf( %lld , &u);         if (lca(R, u) != u)           ans = get(1, 1, n, st[u], en[u]);         else if (R == u)           ans = it[1];         else {           long long z = par(R, h[R] - h[u] - 1);           ans = it[1] - get(1, 1, n, st[z], en[z]);         }         printf( %lld n , ans / 2);         continue;       }       long long u, v, val;       scanf( %lld%lld%lld , &u, &v, &val);       long long x = lca(u, v);       if (lca(x, R) != x)         update(1, 1, n, st[x], en[x], val);       else {         long long a = lca(u, R), b = lca(v, R);         long long w = (a == x ? b : a);         update(1, 1, n, 1, n, val);         if (w != R) {           long long z = par(R, h[R] - h[w] - 1);           update(1, 1, n, st[z], en[z], -val);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int dig[15];   int qpow(int digit) {     int a = 2, b = digit, ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b >>= 1;     }     return ans;   }   int getDigit(int x) {     int ans = 0;     while (x) {       x /= 10;       ans++;     }     return ans;   }   void getHead(int x, int len) {     int index = len;     while (x) {       dig[index--] = x % 10;       x /= 10;     }   }   int main() {     int n;     while (~scanf( %d , &n)) {       int len = getDigit(n);       int ans = 0;       for (int i = 1; i <= len - 1; i++) ans += qpow(i);       if (ans == 1) ans -= 1;       getHead(n, len);       for (int i = 1; i <= len; i++) {         if (dig[i] > 7) {           ans += qpow(len - i + 1);           break;         } else if (dig[i] == 7) {           ans += qpow(len - i);           if (i == len) ans += 1;         } else if (dig[i] > 4) {           ans += qpow(len - i);           break;         } else if (dig[i] == 4) {           if (i == len) ans += 1;           continue;         } else           break;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   int n, m, k, ct[200010], cnt;   vector<pair<int, int> > e[200010];   vector<int> mp[200010];   char bf[100000], *p1 = bf, *p2 = bf;   inline int read() {     int x = 0;     char ch =         (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)              ? -1              : *p1++);     for (; ch <  0  || ch >  9 ;          ch =              (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)                   ? -1                   : *p1++))       ;     for (; ch <=  9  && ch >=  0 ;          x = x * 10 + ch - 48,          ch =              (p1 == p2 && (p2 = (p1 = bf) + fread(bf, 1, 100000, stdin), p2 == p1)                   ? -1                   : *p1++))       ;     return x;   }   int ans, O = 1;   int hah, val[10][200010];   void dfs(int x, int f) {     if (x == k + 1) {       if (f == hah) ++ans;       return;     }     if (mp[x].size() == 0) {       dfs(x + 1, f);       return;     }     for (auto i = (1); i <= (x); ++i) {       int flag = 1;       dfs(x + 1, f + val[x][i]);     }   }   int hsh[200010];   inline void solve() {     n = read(), m = read(), k = read();     for (auto i = (1); i <= (n); ++i) hsh[i] = rand(), hah += hsh[i];     for (auto i = (1); i <= (m); ++i) {       int u = read(), v = read(), w = read();       e[u].push_back({w, v});     }     for (auto i = (1); i <= (n); ++i) sort(e[i].begin(), e[i].end());     for (auto i = (1); i <= (n); ++i) mp[e[i].size()].push_back(i);     for (auto i = (1); i <= (k); ++i)       for (auto j = (1); j <= (i); ++j) {         val[i][j] = 0;         for (auto v : mp[i]) val[i][j] += hsh[e[v][j - 1].second];       }     for (auto i = (1); i <= (k); ++i)       if (mp[i].size() == 0) O *= i;     dfs(1, 0);     printf( %d n , ans * O);   }   int main() {     int T = 1;     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   long long MOD;   inline void Inc(long long &x, long long y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(long long &x, long long y) {     x -= y;     if (x < 0) x += MOD;   }   inline long long Add(long long x, long long y) {     Inc(x, y);     return x;   }   inline long long Sub(long long x, long long y) {     Dec(x, y);     return x;   }   inline long long Mul(long long x, long long y) { return x * y % MOD; }   }  // namespace ModCalculator   using namespace ModCalculator;   int n, d;   long long C[N][N], dp[N][N], sum[N], ans;   void init() {     read(n);     read(d);     read(MOD);     for (int i = 0; i <= n; ++i) {       C[i][0] = 1;       for (int j = 1; j <= i; ++j) {         C[i][j] = Add(C[i - 1][j], C[i - 1][j - 1]);       }     }   }   void solve() {     dp[1][0] = sum[1] = 1;     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= d; ++j) {         for (int k = 1; k < i; ++k) {           Inc(dp[i][j], Mul(C[i - 2][k - 1], Mul(sum[k], dp[i - k][j - 1])));         }         if (j < d) Inc(sum[i], dp[i][j]);       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= d; ++j) {         for (int k = 0; k + j <= d; ++k) {           if (k == 1) continue;           Inc(ans, Mul(dp[i][j], dp[n - i + 1][k]));         }       }     }     printf( %lld n , Mul(ans, 2LL * n * (n - 1)));   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int A, B, C, D, E, H, W, M, K, L, R, N, X, Y, Z, num = 0, sum = 0,                                                                flag = 0;     string S, T;     cin >> Z;     while (Z--) {       cin >> N >> M;       vector<long long int> P(N, 0);       vector<long long int> Q(M, 0);       for (long long int i = 0; i < N; i++) cin >> P[i];       for (long long int i = 0; i < M; i++) cin >> Q[i];       sort(P.begin(), P.end());       sort(Q.begin(), Q.end());       num = -1;       for (long long int i = 0; i < N; i++)         for (long long int j = 0; j < M; j++)           if (P[i] == Q[j]) num = P[i];       if (num == -1)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         cout << 1 <<     << num << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     while (cin >> n) {       long flag = 0, count = 0, a[100005] = {0}, i;       for (i = 0; i < n; i++) cin >> a[i];       for (i = n - 1; i > 0; i--) {         if (a[i - 1] > a[i])           break;         else           count++;       }       cout << n - count - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   int main() {     cin >> a >> b;     long long v = (a * (a + 1) / 2) % 1000000007;     long long rs = b * (b - 1) / 2;     rs %= 1000000007;     long long res = 0;     for (long long i = 1; i <= a; ++i)       res = (res + rs * (i * b % 1000000007 + 1) % 1000000007) % 1000000007;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t, x, n;     cin >> t;     while (t--) {       cin >> n;       vector<int> v(109, 0);       while (n--) {         cin >> x;         v[x] += 1;       }       int sum = 0;       for (int i = 0; i < v.size(); i++) {         if (v[i] == 0) {           sum += i;           break;         }       }       for (int i = 0; i < v.size(); i++) {         if (v[i] <= 1) {           sum += i;           break;         }       }       cout << sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 6010;   const int mod = 1000000007;   int n;   long long k[MAXN], k2[MAXN];   int main() {     string asd;     string asd2;     cin >> asd;     cin >> asd2;     n = ((int)(asd2.size()));     long long res = 0;     for (int i = 0; i < ((int)(asd.size())); i++) {       for (int j = 0; j < ((int)(asd2.size())); j++) {         if (asd2[j] == asd[i]) {           k2[j] = (k2[j] + k[j - 1] + 1) % mod;         }         k2[j + 1] = (k2[j + 1] + k2[j]) % mod;       }       res = (res + k2[n]) % mod;       for (int j = 0; j < ((int)(asd2.size())); j++) k[j] = k2[j];       memset(k2, 0, sizeof k2);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   int Case, n, a[N], la[N], fn[N];   int f[N][N];   int main() {     scanf( %d , &Case);     while (Case--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) fn[i] = 0;       for (int i = 1; i <= n; ++i) {         scanf( %d , a + i);         if (a[i] == a[i - 1]) {           --i;           --n;         } else {           la[i] = fn[a[i]];           fn[a[i]] = i;         }       }       for (int i = n; i; --i) {         for (int j = i + 1; j <= n; ++j) {           f[i][j] = f[i][j - 1];           for (int k = la[j]; k >= i; k = la[k]) {             f[i][j] = max(f[i][j], f[i][k] + f[k][j - 1] + 1);           }         }       }       printf( %d n , n - 1 - f[1][n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n >> ws;       string str;       cin >> str;       int flag = 0, i;       for (i = 0; i < str.size() - 1; i++) {         if (str[i] > str[i + 1]) {           flag = 1;           break;         }       }       if (flag == 0) {         cout << str << endl;         continue;       }       string clean_str;       for (i = 0; i < str.size(); i++) {         if (str[i] ==  1 ) break;         clean_str.push_back( 0 );       }       clean_str.push_back( 0 );       for (i = str.size() - 1; i >= 0; i--) {         if (str[i] ==  0 ) break;         clean_str.push_back( 1 );       }       cout << clean_str << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 4e5 + 5;   int ans[nax];   int b[nax];   int n;   bool solve(int bb) {     vector<int> a;     int val = (1 << (bb));     int val2 = val * 2;     int val3 = val * 3;     int val4 = val * 4;     for (int i = 1; i <= n; i++) {       a.push_back(b[i] & ((1 << (bb + 1)) - 1));     }     sort(a.begin(), a.end());     int hi2 = n - 1;     int hi1 = n - 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       hi1 = min(hi1, n - 1);       while (hi1 >= i && a[i] + a[hi1] >= val) hi1--;       if (a[i] + a[hi1] < val) hi1++;       hi1 = max(hi1, i + 1);       while (hi2 >= 0 && a[i] + a[hi2] >= val2) hi2--;       ans += max(0, hi2 - hi1 + 1);     }     hi2 = n - 1;     hi1 = n - 1;     for (int i = 0; i < n; i++) {       hi1 = min(hi1, n - 1);       while (hi1 >= i && a[i] + a[hi1] >= val3) hi1--;       if (a[i] + a[hi1] < val3) hi1++;       hi1 = max(hi1, i + 1);       while (hi2 >= 0 && a[i] + a[hi2] >= val4) hi2--;       ans += max(0, hi2 - hi1 + 1);     }     return ans % 2;   }   void brut() {     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) ans ^= (b[i] + b[j]);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int ans = 0;     for (int i = 0; i <= 27; i++) {       if (solve(i)) ans += (1 << i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long ind = 0, xtr = 0;     sort(a, a + n);     while (ind < n) {       for (long long i = ind; i < n; i++) {         if (a[i] > 2 * k) {           ind = i;           break;         } else if (i == n - 1 and a[i] <= 2 * k) {           ind = n;           break;         }         k = max(k, a[i]);       }       if (ind != n) {         if (ind > 0) k = max(k, a[ind - 1]);         k = 2 * k;         xtr++;       }     }     cout << xtr << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long MAXN = 1123456;   const long long N = 2e6;   const long long inf = 3e18;   const long long mod = 998244353;   const long long MOD = mod * (mod - 2);   mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());   template <typename T>   void vout(T s) {     cout << s << endl;     exit(0);   }   void main_solve() {     long long n;     cin >> n;     vector<long long> a(n + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     vector<bool> f(n + 1);     vector<long long> c, ans;     long long s = 1;     while (1) {       c.push_back(s);       if (f[s]) break;       f[s] = 1;       s = s - a[s];     }     reverse(c.begin(), c.end());     ans.push_back(c[0]);     for (int i = 1; i < (int)c.size(); i++)       if (c[i] != c[0]) {         ans.push_back(c[i]);       } else         break;     cout << (int)ans.size() <<   n ;     for (auto i : ans) cout << i <<    ;     cout <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       main_solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char field[8][8];     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> field[i][j];       }     }     int minDist = 10;     for (int j = 0; j < 8; j++) {       for (int i = 0; i < 8; i++) {         if (field[i][j] ==  B ) {           break;         }         if (field[i][j] ==  W ) {           if (minDist > i) minDist = i;         }       }     }     int blackMinDist = -1;     for (int j = 0; j < 8; j++) {       for (int i = 7; i >= 0; i--) {         if (field[i][j] ==  W ) {           break;         }         if (field[i][j] ==  B ) {           if (blackMinDist < i) blackMinDist = i;         }       }     }     blackMinDist = 7 - blackMinDist;     if (blackMinDist >= minDist) {       cout <<  A ;       return 0;     }     cout <<  B ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e15;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n, k;     cin >> n >> k;     vector<int> first(n);     for (int i = 0; i < n; i++) cin >> first[i];     vector<long long> pr(n + 1);     for (int i = 0; i < n; i++) pr[i + 1] = pr[i] + first[i];     map<long long, int> how;     for (int i = 0; i < n; i++) {       how[pr[i + 1]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (k == 1) {         ans += how[k + pr[i]];       } else {         if (k == -1) {           ans += how[k + pr[i]];           ans += how[-k + pr[i]];         } else {           for (long long p = 1; p <= MAX; p *= k) {             ans += how[p + pr[i]];           }         }       }       how[pr[i + 1]]--;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<pair<int, bool> > adj[maxn];   vector<pair<pair<int, int>, bool> > edge;   int dp[maxn], dis[maxn], par[maxn];   bool mark[maxn], in_path[maxn];   int n, m, ans = 0;   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, w;       cin >> a >> b >> w;       adj[a - 1].push_back(make_pair(b - 1, 1 - w));       adj[b - 1].push_back(make_pair(a - 1, 1 - w));       edge.push_back(make_pair(make_pair(a - 1, b - 1), 1 - w));       if (w) ans++;     }   }   void bfs() {     queue<int> q;     q.push(0);     mark[0] = true;     dis[0] = 0;     dp[0] = 0;     while (!q.empty()) {       int v = q.front();       q.pop();       for (auto u : adj[v]) {         if (!mark[u.first]) {           q.push(u.first);           mark[u.first] = true;           dis[u.first] = dis[v] + 1;           par[u.first] = v;           dp[u.first] = dp[v] + u.second;         } else if ((dp[u.first] > dp[v] + u.second) &&                    (dis[u.first] == dis[v] + 1)) {           par[u.first] = v;           dp[u.first] = dp[v] + u.second;         }       }     }   }   void check() {     for (int i = 0; i < n; i++) cout <<  par   << par[i] << endl;   }   void pp(int v) {     if (par[v] == v) return;     in_path[v] = true;     pp(par[v]);   }   void output() {     cout << ans - dis[n - 1] + 2 * dp[n - 1] << endl;     in_path[0] = true;     in_path[n - 1] = true;     pp(n - 1);     for (int i = 0; i < m; i++) {       int a = edge[i].first.first, b = edge[i].first.second, w = edge[i].second;       if (!in_path[a] || !in_path[b])         if (!w) cout << a + 1 <<     << b + 1 <<     << w << endl;       if (in_path[a] && in_path[b])         if (w) cout << a + 1 <<     << b + 1 <<     << w << endl;     }     return;   }   int main() {     input();     bfs();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   template <typename T, typename... Args>   void read(T &first, Args &...args) {     read(first);     read(args...);   }   template <typename T>   void write(T arg) {     T x = arg;     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   template <typename T, typename... Ts>   void write(T arg, Ts... args) {     write(arg);     if (sizeof...(args) != 0) {       putchar(   );       write(args...);     }   }   const long long MOD = 998244353;   const int MAXN = 5e5 + 50;   long long n, k, fac[MAXN], inv[MAXN];   long long qpow(long long a, long long p) {     long long sum = 1;     while (p) {       if (p & 1) {         sum = sum * a % MOD;       }       a = a * a % MOD;       p >>= 1;     }     return sum;   }   long long get_inv(long long k) { return qpow(k, MOD - 2); }   void pre() {     fac[0] = 1;     for (register int i = 1; i <= n; ++i) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = get_inv(fac[i]);     }   }   long long C(long long n, long long m) {     if (m > n) {       return 0;     } else {       return fac[n] * get_inv(fac[n - m] * fac[m] % MOD) % MOD;     }   }   int main() {     read(n, k);     pre();     long long ans = 0;     for (register int i = 1; i <= n; ++i) {       long long p = n / i - 1;       ans = (ans + C(p, k - 1)) % MOD;     }     write(ans), putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int cnt;   int getdeal(long long c) {     int ret = 0;     while (c) {       ret += c % 10;       c /= 10;     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     long long temp = 0;     while (temp * 10 + 9 <= n) {       temp = temp * 10 + 9;     }     cout << getdeal(temp) + getdeal(n - temp);   }


#include <bits/stdc++.h>   using namespace std;   int mod = 998244353;   const int M = 1e6 + 10;   const int N = 1e5 + 10;   inline long long read() {     long long b = 1, sum = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) b = -1;       c = getchar();     }     while (isdigit(c)) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return b * sum;   }   int a[N], in[N], d[N];   int n, m, k, T;   int vis[N];   vector<int> e[N];   vector<pair<int, int> > ans;   void dfs(int x, int _fa, int need) {     int i, j;     if (x == 1) {       for (i = 0; i < e[x].size(); i++) {         int y = e[x][i];         ans.push_back({y, i + 1});         dfs(y, x, i);       }       return;     }     int cha = need - in[x] + 1, sum = 0;     if (in[x] == 1) {       ans.push_back({x, need});     } else if (cha >= 0) {       ans.push_back({x, cha});       for (i = 0; i < e[x].size(); i++) {         int y = e[x][i];         if (y == _fa) continue;         ans.push_back({y, cha + sum + 1});         dfs(y, x, cha + sum);         sum++;       }     } else {       int now = need + 1, sum = 0;       for (i = 0; sum < -cha && i < e[x].size(); i++) {         int y = e[x][i];         if (y == _fa) continue;         ans.push_back({y, now + 1});         dfs(y, x, now);         now++;         sum++;       }       ans.push_back({x, 0});       sum = 0;       for (; i < e[x].size(); i++) {         int y = e[x][i];         if (y == _fa) continue;         ans.push_back({y, sum + 1});         dfs(y, x, sum);         sum++;       }     }     ans.push_back({_fa, need + 1});   }   int main() {     int i, j;     n = read();     for (i = 1; i <= n - 1; i++) {       int x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);       in[x]++;       in[y]++;     }     ans.push_back({1, 0});     dfs(1, 0, 0);     printf( %d n , ans.size());     for (i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 3e5 + 100;   int t, T, n, k;   int A[maxn];   int B[maxn];   int main() {     ios::sync_with_stdio(false);     cin >> T;     while (T--) {       cin >> n;       int sum = 0;       for (int i = 1; i <= n; i++) {         cin >> A[i];         sum += A[i];         B[i] = A[i];       }       if (sum % n) {         cout << -1 << endl;         continue;       }       sum /= n;       int cnt = 0;       for (int i = 2; i <= n; i++) {         int d = (A[i] + i - 1) / i * i - A[i];         if (d <= A[1]) {           A[i] += d;           A[1] -= d;           cnt++;         }         int x = A[i] / i * i;         A[1] += x;         A[i] -= x;       }       int ok = 1;       for (int i = n; i > 1; i--) {         if (A[i] > sum) ok = 0;         A[1] -= (sum - A[i]);         if (A[1] < 0) ok = 0;         if (!ok) break;       }       if (!ok) {         cout << -1 << endl;         continue;       }       if (ok) {         cout << 2 * (n - 1) + cnt << endl;         for (int i = 2; i <= n; i++) {           int d = (B[i] + i - 1) / i * i - B[i];           if (d <= B[1]) {             B[i] += d;             B[1] -= d;             cout << 1 <<     << i <<     << d << endl;           }           int x = B[i] / i * i;           B[1] += x;           B[i] -= x;           cout << i <<     << 1 <<     << x / i << endl;         }         for (int i = n; i > 1; i--) {           int x = sum - B[i];           B[1] -= x;           B[i] += x;           cout << 1 <<     << i <<     << x << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, v, k1 = 0, k2 = 0;     int how_many1 = 0;     vector<int> molt[99 + 1];     scanf( %d , &n);     short b[n << 1];     for (int i = 0; i < (n << 1); i++) {       scanf( %d , &v);       molt[v].push_back(i);     }     for (int v = 10; v <= 99; v++)       if (molt[v].size() >= 2) {         k1++;         k2++;         how_many1++;         b[molt[v][0]] = 1;         b[molt[v][1]] = 2;       }     for (int v = 10; v <= 99; v++)       if (molt[v].size() == 1) {         if (k1 <= k2) {           k1++;           how_many1++;           b[molt[v][0]] = 1;         } else {           k2++;           b[molt[v][0]] = 2;         }       }     for (int v = 10; v <= 99; v++) {       for (int i = 2; i < molt[v].size(); i++) {         if (how_many1 < n) {           b[molt[v][i]] = 1;           how_many1++;         } else {           b[molt[v][i]] = 2;         }       }     }     printf( %d n , k1 * k2);     for (int i = 0; i < 2 * n; i++) printf( %d  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[105][3];   vector<int> vec[105];   bool vis[105];   void dfs(int i) {     vis[i] = true;     for (int j = 0; j < vec[i].size(); j++) {       if (!vis[vec[i][j]]) dfs(vec[i][j]);     }     return;   }   int main() {     int n, i, cnt = 0, j;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d%d , &arr[i][0], &arr[i][1]);     }     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++) {         if (i != j) {           if (arr[i][0] == arr[j][0] || arr[i][1] == arr[j][1]) {             vec[i].push_back(j);             vec[j].push_back(i);           }         }       }     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         cnt++;         dfs(i);       }     }     cout << cnt - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kMaxN = 1 + 50;   char A[kMaxN][kMaxN], B[kMaxN][kMaxN];   int N, M;   int type;   void ReadInput() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %s , A[i] + 1);     }     for (int i = 1; i <= N; i++) {       scanf( %s , B[i] + 1);     }     if (N % 2 == 0) {       type = 0;     } else {       type = 1;     }   }   bool Perfect(char mat[kMaxN][kMaxN]) {     if (type == 0) {       for (int i = 1; i <= N; i++) {         for (int j = 1; j <= M; j++) {           if (i % 2 == 1 && mat[i][j] !=  U ) {             return false;           }           if (i % 2 == 0 && mat[i][j] !=  D ) {             return false;           }         }       }       return true;     } else {       for (int i = 1; i <= N; i++) {         for (int j = 1; j <= M; j++) {           if (j % 2 == 1 && mat[i][j] !=  L ) {             return false;           }           if (j % 2 == 0 && mat[i][j] !=  R ) {             return false;           }         }       }       return true;     }   }   vector<pair<int, int> > Normalize(char mat[kMaxN][kMaxN]) {     vector<pair<int, int> > moves;     bool now = 0;     while (!Perfect(mat)) {       if (now == 0) {         for (int i = 1; i < N; i++) {           for (int j = 1; j < M; j++) {             if (mat[i][j] ==  U  && mat[i][j + 1] ==  U  &&                 mat[i + 1][j] ==  D  && mat[i + 1][j + 1] ==  D ) {               mat[i][j] = mat[i + 1][j] =  L ;               mat[i][j + 1] = mat[i + 1][j + 1] =  R ;               moves.push_back(make_pair(i, j));             }           }         }       } else {         for (int i = 1; i < N; i++) {           for (int j = 1; j < M; j++) {             if (mat[i][j] ==  L  && mat[i + 1][j] ==  L  &&                 mat[i][j + 1] ==  R  && mat[i + 1][j + 1] ==  R ) {               mat[i][j] = mat[i][j + 1] =  U ;               mat[i + 1][j] = mat[i + 1][j + 1] =  D ;               moves.push_back(make_pair(i, j));             }           }         }       }       now ^= 1;     }     return moves;   }   int main() {     ReadInput();     vector<pair<int, int> > first = Normalize(A);     vector<pair<int, int> > second = Normalize(B);     reverse(second.begin(), second.end());     printf( %d n , (int)first.size() + (int)second.size());     for (auto p : first) {       printf( %d %d n , p.first, p.second);     }     for (auto p : second) {       printf( %d %d n , p.first, p.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MX = 1e5 + 6;   long long l, r;   int main() {     cin >> l >> r;     puts( YES );     for (long long i = l; i <= r; i += 2) cout << i <<     << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, a, b;       cin >> n >> m >> a >> b;       if (n * a != m * b) {         cout <<  NO  << endl;         continue;       }       int index = 0;       cout <<  YES  << endl;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           cout << ((index + j) % m < a ? 1 : 0);         }         index -= a;         if (index < 0) index += m;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct dot {     string f, s;   };   bool cmp(dot x, dot y) {}   int main() {     int i, j, k, n;     int p[100010];     dot A[100010];     cin >> n;     for (int(i) = int(1); i <= int(n); i++) {       cin >> A[i].f >> A[i].s;     }     string las =   ;     for (int(i) = int(1); i <= int(n); i++) {       cin >> p[i];     }     bool OK = true;     las = min(A[p[1]].f, A[p[1]].s);     for (int(i) = int(2); i <= int(n); i++) {       if (min(A[p[i]].f, A[p[i]].s) > las)         las = min(A[p[i]].f, A[p[i]].s);       else if (max(A[p[i]].f, A[p[i]].s) > las) {         las = max(A[p[i]].f, A[p[i]].s);       } else {         OK = false;         break;       }     }     if (OK)       cout <<  YES n ;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long num[30];   int main() {     int n, m;     long long k;     string temp;     scanf( %d%I64d , &n, &k);     long long cnt = 0;     cin >> temp;     for (int i = 0; i < n; i++) {       num[temp[i] -  A  + 1]++;     }     for (int i = 0; i < 26 && k != 0; i++) {       m = 1;       for (int j = 2; j <= 26; j++) {         if (num[m] < num[j]) m = j;       }       if (num[m] <= k) {         cnt += num[m] * num[m];         k -= num[m];         num[m] = 0;       } else {         cnt += k * k;         break;       }     }     printf( %I64d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int c[1000010];   int mp[1000];   int in[1000010];   int fir[1000010];   int ans[1000010];   vector<int> v[1000010];   int calc(int nod) {     if (c[nod] == 5) return fir[nod] = in[nod];     if (c[nod] == 4) return fir[nod] = 1 - calc(v[nod][0]);     int q1 = calc(v[nod][0]);     int q2 = calc(v[nod][1]);     if (c[nod] == 3) return fir[nod] = q1 ^ q2;     if (c[nod] == 2) return fir[nod] = q1 | q2;     if (c[nod] == 1) return fir[nod] = q1 & q2;   }   void dfs(int nod, int ch) {     if (c[nod] == 5) {       ans[nod] = ch;       return;     }     if (c[nod] == 4) {       dfs(v[nod][0], ch);       return;     }     if (ch == 0) {       dfs(v[nod][0], 0);       dfs(v[nod][1], 0);       return;     }     int q1 = fir[v[nod][0]];     int q2 = fir[v[nod][1]];     if (c[nod] == 3) {       if ((q1 ^ (!q2)) == fir[nod]) {         dfs(v[nod][1], 0);       } else {         dfs(v[nod][1], 1);       }       if ((q2 ^ (!q1)) == fir[nod]) {         dfs(v[nod][0], 0);       } else {         dfs(v[nod][0], 1);       }     }     if (c[nod] == 2) {       if ((q1 | (!q2)) == fir[nod]) {         dfs(v[nod][1], 0);       } else {         dfs(v[nod][1], 1);       }       if ((q2 | (!q1)) == fir[nod]) {         dfs(v[nod][0], 0);       } else {         dfs(v[nod][0], 1);       }     }     if (c[nod] == 1) {       if ((q1 & (!q2)) == fir[nod]) {         dfs(v[nod][1], 0);       } else {         dfs(v[nod][1], 1);       }       if ((q2 & (!q1)) == fir[nod]) {         dfs(v[nod][0], 0);       } else {         dfs(v[nod][0], 1);       }     }   }   int main() {     memset(ans, -1, sizeof ans);     mp[ A ] = 1;     mp[ O ] = 2;     mp[ X ] = 3;     mp[ N ] = 4;     mp[ I ] = 5;     cin >> n;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       if (s ==  IN ) {         int a;         cin >> a;         c[i] = 5;         in[i] = a;       } else if (s ==  NOT ) {         int a;         cin >> a;         c[i] = mp[ N ];         v[i].push_back(a);       } else {         int a, b;         cin >> a >> b;         v[i].push_back(a);         v[i].push_back(b);         c[i] = mp[s[0]];       }     }     calc(1);     dfs(1, 1);     string s1 =   ;     for (int i = 1; i <= n; i++) {       if (ans[i] != -1) {         if (ans[i])           ans[i] = 1 - fir[1];         else           ans[i] = fir[1];         s1 += char( 0  + ans[i]);       }     }     cout << s1 << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   char a[1000005], b[1000005], s[1000005];   int k, T, tmp[27], vis[27], p, n, tt[27], vv[27];   bool check(int x, int cas) {     memcpy(tt, tmp, sizeof(tt));     memcpy(vv, vis, sizeof(vv));     if (cas == 1) {       for (int i = x; i <= n; i++) {         if (tt[s[i] -  a ] != -1) {           if (tt[s[i] -  a ] > a[i]) return 1;           if (tt[s[i] -  a ] < a[i]) return 0;           continue;         }         for (int j = a[i] + 1; j <= k +  a  - 1; j++)           if (!vv[j -  a ]) return 1;         if (!vv[a[i] -  a ])           vv[a[i] -  a ] = 1, tt[s[i] -  a ] = a[i];         else           return 0;       }       return 1;     } else {       for (int i = x; i <= n; i++) {         if (tt[s[i] -  a ] != -1) {           if (tt[s[i] -  a ] > b[i]) return 0;           if (tt[s[i] -  a ] < b[i]) return 1;           continue;         }         for (int j =  a ; j < b[i]; j++)           if (!vv[j -  a ]) return 1;         if (!vv[b[i] -  a ])           vv[b[i] -  a ] = 1, tt[s[i] -  a ] = b[i];         else           return 0;       }       return 1;     }   }   void solve() {     scanf( %d%s%s%s , &k, s + 1, a + 1, b + 1);     n = strlen(s + 1);     memset(tmp, -1, sizeof(tmp));     p = n + 1;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++)       if (a[i] == b[i]) {         if (tmp[s[i] -  a ] == a[i]) continue;         if (tmp[s[i] -  a ] == -1 && !vis[a[i] -  a ])           tmp[s[i] -  a ] = a[i], vis[a[i] -  a ] = 1;         else {           puts( NO );           return;         }       } else {         p = i;         break;       }     int flag = 0;     for (int i = p; i <= n; i++) {       if (!flag && a[i] > b[i]) {         puts( NO );         return;       }       if (tmp[s[i] -  a ] != -1) {         if ((((flag & 2) == 0) && tmp[s[i] -  a ] < a[i]) ||             (((flag & 4) == 0) && tmp[s[i] -  a ] > b[i])) {           puts( NO );           return;         }         if ((flag & 2) == 0 && tmp[s[i] -  a ] > a[i]) flag |= 2;         if ((flag & 4) == 0 && tmp[s[i] -  a ] < b[i]) flag |= 4;       } else if ((flag & 6) == 0) {         bool used = 0;         for (int j = a[i] + 1; j < b[i]; j++)           if (!vis[j -  a ]) {             tmp[s[i] -  a ] = j;             vis[j -  a ] = 1;             flag |= 6;             used = 1;             break;           }         if (!used) {           if (!used && !vis[b[i] -  a ]) {             vis[b[i] -  a ] = 1, tmp[s[i] -  a ] = b[i];             if (!check(i + 1, 2))               vis[b[i] -  a ] = 0, tmp[s[i] -  a ] = -1;             else               flag |= 2, used = 1;           }           if (!used && !vis[a[i] -  a ]) {             vis[a[i] -  a ] = 1, tmp[s[i] -  a ] = a[i];             if (check(i + 1, 1)) flag |= 4, used = 1;           }           if (!used) {             puts( NO );             return;           }         }       } else if ((flag & 2) == 0) {         bool used = 0;         for (int j = a[i] + 1; j <= k +  a  - 1; j++)           if (!vis[j -  a ]) {             tmp[s[i] -  a ] = j;             vis[j -  a ] = 1;             flag |= 2;             used = 1;             break;           }         if (!used) {           if (!vis[a[i] -  a ])             vis[a[i] -  a ] = 1, tmp[s[i] -  a ] = a[i];           else {             puts( NO );             return;           }         }       } else if ((flag & 4) == 0) {         bool used = 0;         for (int j =  a ; j < b[i]; j++)           if (!vis[j -  a ]) {             tmp[s[i] -  a ] = j;             vis[j -  a ] = 1;             flag |= 4;             used = 1;             break;           }         if (!used) {           if (!vis[b[i] -  a ])             vis[b[i] -  a ] = 1, tmp[s[i] -  a ] = b[i];           else {             puts( NO );             return;           }         }       }       flag |= 1;       if (flag == 7) break;     }     puts( YES );     int now = 0;     while (vis[now]) now++;     for (int i = 0; i < k; i++)       if (tmp[i] == -1) {         tmp[i] =  a  + now;         vis[now] = 1;         while (vis[now]) now++;       }     for (int i = 0; i < k; i++) printf( %c , tmp[i]);     puts(  );   }   int main() {     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using std::string;   int main() {     int n, k;     cin >> n >> k;     if (n * (n - 1) / 2 > k) {       int i = 0, j = 0;       while (n--) {         cout << i <<     << j++ << endl;       }     } else       cout <<  no solution ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans = 1;   long long C(long long m, long long n) {     long long p = 1;     for (long long i = 1; i <= n; i++) p *= i;     for (long long i = 1; i <= m; i++) p /= i;     for (long long i = 1; i <= n - m; i++) p /= i;     return p;   }   signed main() {     cin >> n;     for (long long i = 1; i <= n / 2 - 1; i++) ans *= i;     ans *= ans;     ans *= C(n / 2, n);     ans /= 2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T[100010], first[100010], canKill[100010], ans = 0;   char flag;   int X, M, N, fle = 0, A[100010];   int main() {     scanf( %d %d , &N, &M);     memset(T, 0, sizeof(T));     memset(first, 0, sizeof(first));     memset(canKill, 0, sizeof(canKill));     ans = 0;     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       if (A[i] > 0)         T[A[i]]++;       else {         first[-1 * A[i]]++;         fle++;       }     }     for (int i = 1; i <= N; i++) {       if (fle - first[i] + T[i] == M) {         canKill[i] = 1;         ans++;       }     }     for (int i = 1; i <= N; i++) {       if (A[i] > 0) {         if (canKill[A[i]] == 1) {           if (ans == 1)             printf( Truth n );           else             printf( Not defined n );         } else {           printf( Lie n );         }       } else {         A[i] = A[i] * -1;         if (canKill[A[i]] == 0) {           printf( Truth n );         } else {           if (ans == 1)             printf( Lie n );           else             printf( Not defined n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> v(2000000);     for (long long i = 0; i < 2000000; i++) v[i] = 0;     for (long long i = 0; i < n; i++) {       long long t1;       cin >> t1;       v[t1]++;     }     long long t = 0;     long long l = 1;     long long r = 1000000;     while (n > 0) {       t++;       l++;       r--;       if (v[l]) n--;       if (v[r]) n--;     }     cout << t;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n = 0;     cin >> n;     string s;     vector<vector<int> > v(5, vector<int>(0));     for (int i = 0; i < n; i++) {       cin >> s;       vector<int> cnt(5, 0);       int sum = 0;       for (int j = 0; j < s.size(); j++) {         cnt[s[j] -  a ]++;         sum++;       }       for (int j = 0; j < 5; j++) {         v[j].push_back(cnt[j] - (sum - cnt[j]));       }     }     long long ans = -1;     for (int i = 0; i < 5; i++) {       sort(v[i].rbegin(), v[i].rend());       long long sum = 0;       long long cnt = 0;       for (int j = 0; j < v[i].size(); j++) {         sum += v[i][j];         if (sum > 0) {           cnt++;         }       }       ans = max(ans, cnt);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char x = getchar();     long long ans = 0, flag = 1;     while (!isdigit(x))       if (x ==  - )         flag = -1, x = getchar();       else         x = getchar();     while (isdigit(x)) ans = ans * 10 + x -  0 , x = getchar();     return ans * flag;   }   long long n, a[200005], ans, las;   map<long long, long long> mp;   signed main() {     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) a[i] += a[i - 1];     mp[0] = 0;     las = 0;     for (long long i = 1; i <= n; i++) {       if (mp.find(a[i]) != mp.end()) {         if (mp[a[i]] >= las) {           ans -= (mp[a[i]] - las + 1) * ((n - i + 1));           las = mp[a[i]] + 1;         }       }       mp[a[i]] = i;     }     cout << ans + n * (n + 1) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   ;   int n;   long long mod = 1000 * 1000 * 1000 + 7;   const int maxn = 1000005;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long d[maxn];   long long cnt[maxn];   long long pow2[maxn];   long long coef[maxn];   long long bad[maxn];   int main() {     pow2[0] = 1;     for (int i = 1; i < maxn; ++i) {       pow2[i] = pow2[i - 1] * 2;       pow2[i] %= mod;     }     cin >> n;     vector<int> v;     v.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &v[i]);       cnt[v[i]]++;     }     for (int i = 2; i < maxn; ++i) {       for (int j = i; j < maxn; j += i) {         d[i] += cnt[j];         if (i != j) bad[j] += i;         bad[j] %= mod;       }     }     long long ans = 0;     for (int i = maxn - 1; i >= 2; --i) {       if (d[i] == 0) continue;       coef[i] = (1LL * ((d[i] * pow2[d[i] - 1]) % mod)) % mod;       for (int j = i * 2; j < maxn; j += i) coef[i] -= coef[j];       ans += i * coef[i];       ans %= mod;       ans += mod;       ans %= mod;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   vector<int> ed[200001];   int an[200001];   int b[200001];   set<int> o[2000001];   void dfs(int x, int g, int p) {     int i;     if (x == 1) {       an[x] = b[1];       o[x].insert(0);     } else {       o[x].insert(g);       an[x] = g;       if (o[p].size()) {         set<int>::iterator f = o[p].begin();         for (i = 0; i < o[p].size(); i++) {           int y = gcd(b[x], *f);           an[x] = max(an[x], y);           if (y != 1) o[x].insert(y);           f++;         }       }     }     g = gcd(g, b[x]);     for (i = 0; i < ed[x].size(); i++) {       if (ed[x][i] != p) {         dfs(ed[x][i], g, x);       }     }   }   int main() {     int n;     cin >> n;     int i;     for (i = 1; i <= n; i++) cin >> b[i];     for (i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       ed[x].push_back(y);       ed[y].push_back(x);     }     dfs(1, 0, 0);     for (i = 1; i <= n; i++) cout << an[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     char arr[200];     int i, j, jp, g, t, cl, jm, a, m, n;     scanf( %d%d , &cl, &jm);     scanf( %c , &arr[0]);     for (i = 1; i <= cl; i++) scanf( %c , &arr[i]);     for (i = 1; i <= cl; i++) {       if (arr[i] ==  G ) {         g = i;       }       if (arr[i] ==  T ) {         t = i;       }     }     if (g > t) {       m = t;       n = g;       a = g - t;     } else {       m = g;       n = t;       a = t - g;     }     for (i = m; i < n; i = i + jm) {       if (arr[i] ==  # ) {         printf( NO n );         return 0;       }     }     if ((a % jm) == 0)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double eps = 1e-9;   const int INF = 1e9 + 7;   const int MAXN = int(2e5 + 7);   int n, k, b, ans;   long long cur = 1, t;   int main() {     cin >> k >> b >> n >> t;     while (cur <= t) {       cur = cur * k + b;       n--;     }     cout << max(0, ++n);     return 0;   }