#include <bits/stdc++.h>   const int MOD = int(1e9) + 7;   inline int add(int a, int b) {     return (a + b >= MOD) ? (a + b - MOD) : (a + b);   }   inline void inc(int &a, int b) { a = add(a, b); }   inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); }   inline void dec(int &a, int b) { a = sub(a, b); }   inline int mul(int a, int b) { return (a * 1ll * b) % MOD; }   using namespace std;   const int N = 100000;   vector<pair<int, int> > vet;   vector<int> aux;   vector<vector<int> > cycles[N + 1];   int P[N];   bool vis[N];   void dfs(int u) {     vis[u] = true;     aux.push_back(u);     u = P[u];     if (!vis[u]) dfs(u);   }   void debug() {     for (int i = 0; i <= N; i++)       if (!cycles[i].empty()) {         printf( %d:  , i);         for (__typeof((cycles[i]).begin()) it = (cycles[i]).begin();              it != (cycles[i]).end(); ++it) {           printf( ( );           for (__typeof((*it).begin()) it2 = (*it).begin(); it2 != (*it).end();                ++it2)             printf( %d  , *it2);           printf( )  );         }         puts(  );       }   }   bool solve(int testNumber) {     int n;     if (scanf( %d , &n) == EOF) return false;     for (int i = 0; i < n; i++) {       scanf( %d , &P[i]);       P[i]--;     }     for (int i = 0; i <= N; i++) cycles[i].clear();     vet.clear();     for (int i = 0; i < N; i++) vis[i] = false;     for (int i = 0; i < n; i++)       if (!vis[i]) {         aux.clear();         dfs(i);         cycles[((int)(aux).size())].push_back(aux);       }     for (int i = 0; i <= N; i++)       for (int j = 1; j < ((int)(cycles[i]).size()); j++)         for (int k = 0; k < i; k++)           vet.push_back(make_pair((cycles[i][0][k]), (cycles[i][j][k])));     for (int i = 0; i <= N; i++)       if (!cycles[i].empty())         for (int j = 1; j * j <= i; j++)           if (i % j == 0) {             if (j != i && !cycles[j].empty()) {               for (int k = 0; k < i; k++)                 vet.push_back(                     make_pair((cycles[j][0][k % j]), (cycles[i][0][k])));               break;             }             int x = i / j;             if (x != i && !cycles[x].empty()) {               for (int k = 0; k < i; k++)                 vet.push_back(                     make_pair((cycles[x][0][k % x]), (cycles[i][0][k])));               break;             }           }     if (cycles[1].empty() && !cycles[2].empty())       vet.push_back(make_pair((cycles[2][0][0]), (cycles[2][0][1])));     if (((int)(vet).size()) < n - 1)       puts( NO );     else {       puts( YES );       for (__typeof((vet).begin()) it = (vet).begin(); it != (vet).end(); ++it)         printf( %d %d n , it->first + 1, it->second + 1);     }     return true;   }   int main() {     for (int i = 1; solve(i); i++)       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, l, a[1000009], b[1000009], f[1000009], ans, cn, t, x, y, z,       mx, mn, s;   char c[1000009], d[1000009], ch;   map<int, int> mp, mm;   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       ans = 1;       mp.clear();       mm.clear();       for (i = 1; i <= n; i++) {         scanf( %d , &f[i]);         mm[f[i]] = 1;       }       for (i = 1; i <= m; i++) {         scanf( %d , &b[i]);         if (mm[b[i]] == 0) {           ans = 0;         }       }       if (ans == 0) {         printf( Impossible n );       } else {         ans = 1;         mp.clear();         mm.clear();         for (i = 1; i <= m; i++) {           mp[b[i]] = 1;         }         for (i = 1; i <= n; i++) {           if (mp[f[i]] == 1) {             mm[f[i]]++;             if (mm[f[i]] == 2) {               ans = 0;               break;             }           }         }         if (ans == 0) {           printf( Ambiguity n );         } else {           printf( Possible n );           mp.clear();           for (i = 1; i <= n; i++) {             mp[f[i]] = i;           }           for (i = 1; i <= m; i++) {             a[i] = mp[b[i]];             if (i > 1) {               printf(   );             }             printf( %d , a[i]);           }           printf(  n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9 + 5;   const int MOD = (int)1e9 + 7;   const long double Pi = 3.141592653589793238;   const int N = (int)2e5 + 5;   long long qqaGJJ[N], ss[2][N], vRI[2][N], n, uVyh = 0;   int main() {     cin >> n;     for (int i = (int)(1); i <= (int)(n); i++) cin >> qqaGJJ[i];     reverse(qqaGJJ + 1, qqaGJJ + n + 1);     for (int i = (int)(1); i <= (int)(n); i++) {       if (i == 1) {         ss[0][i] = ss[1][0] = 0;         vRI[0][i] = vRI[1][i] = 0;       } else {         for (int k = (int)(0); k <= (int)(1); k++) {           ss[k][i] = ss[k][i - 1] +                      abs(qqaGJJ[i] - qqaGJJ[i - 1]) * (((i + k) % 2) ? 1 : -1);           vRI[k][i] = min(vRI[k][i - 1], ss[k][i]);         }       }     }     uVyh = ss[1][2];     for (int i = (int)(2); i <= (int)(n); i++) {       uVyh = max(uVyh, ss[(i + 1) % 2][i] - vRI[(i + 1) % 2][i - 1]);     }     cout << uVyh;   }


# include <bits/stdc++.h>   # define int long long   using namespace std;   const int N=505;   const int mo=998244353;   int a[2*N][N],b[N][N];   bool f[2*N];   int Pow(int x,int n) {       int ans=1;       while (n) {           if (n&1) ans=ans*x%mo;           x=x*x%mo;           n>>=1;       }       return ans;   }   vector<int>an;   signed main() {       int t; scanf( %lld ,&t);       while (t--) {           an.clear();           long long ans=1ll;           int n; scanf( %lld ,&n);           for (int i=1;i<=2*n;i++)               for (int j=1;j<=n;j++)                   scanf( %lld ,&a[i][j]);           int tot=0;           for (int i=1;i<=2*n;i++) f[i]=false;                 while (true) {               for (int i=1;i<=n;i++)                   for (int j=1;j<=n;j++)                       b[i][j]=0;               for (int i=1;i<=2*n;i++) if (!f[i]) {                       for (int j=1;j<=n;j++)                           b[j][a[i][j]]++;                   }                        bool cc; int uniq;               for (int i=1;i<=2*n;i++) if (!f[i]) {                       cc=false;                       for (int j=1;j<=n;j++) if (b[j][a[i][j]]==1) {                               cc=true; uniq=i; break;                           }                       if (cc) break;                   }                  if (cc)               {                   an.push_back(uniq);               }               else {                   for (int i=1;i<=2*n;i++) if (!f[i]) {                           uniq=i; break;                       }                   an.push_back(uniq);                   ans=ans*2ll%mo;               }               for (int i=1;i<=2*n;i++) if (!f[i]) {                       bool flag=true;                       for (int j=1;j<=n;j++) if (a[i][j]==a[uniq][j]) {                               flag=false; break;                           }                       if (!flag) f[i]=true;                   }               if (an.size()==n) break;           }           printf( %lld n ,ans);           for (int i=0;i<an.size();i++) printf( %lld  ,an[i]);           puts(  );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     std::vector<std::vector<long long>> f(151, std::vector<long long>(151, 0));     f[0][0] = 1;     f[1][0] = 1;     f[1][1] = 1;     for (long long i = 2; i <= 150; ++i) {       for (long long j = 0; j <= i; ++j) {         f[i][j] = ((f[i - 2][j]) + ((j != 0) ? (f[i - 1][j - 1]) : 0));         f[i][j] %= 2;       }     }     long long n;     cin >> n;     cout << n <<   n ;     for (long long i = 0; i <= n; ++i) {       cout << f[n][i] <<    ;     }     cout <<   n ;     cout << n - 1 <<   n ;     for (long long i = 0; i <= n - 1; ++i) {       cout << f[n - 1][i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, sum = 1e6;     cin >> n;     long a[n];     for (long i = 0; i < n; cin >> a[i++])       ;     long opt;     for (long i = 1; i <= 1000; ++i) {       long s = 0;       for (long j = 0; j < n; ++j) {         if (i != a[j]) s += abs(i - a[j]) - 1;       }       if (s < sum) {         sum = s;         opt = i;       }     }     cout << opt <<     << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:247474112 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   long long mod = 1e9 + 7;   void time() {}   const long long N = 3100300;   const long long maxn = 1e5 + 5;   const long long despacito = 1e9 + 7;   long long n, m;   long long a[N], p[N], cnt[N], z[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> p[i];     }     for (long long i = 1; i <= n; i++) {       cnt[a[i]]++;     }     for (long long a = 1; a <= N; a++) {       if (!cnt[a]) continue;       for (long long b = a; b < N; b += a) {         if (b / a != a) {           z[b] += (long long)(cnt[a] * cnt[b / a]);         } else           z[b] += (long long)(cnt[a] * (cnt[a] - 1));       }     }     for (long long i = 1; i <= N; ++i) {       z[i] += z[i - 1];     }     for (long long i = 1; i <= m; ++i) {       long long ans = (long long)(n) * (n - 1) - z[p[i] - 1];       cout << ans <<   n ;     }     time();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   char a[maxn], b[maxn];   int pre[maxn], suf[maxn];   int main() {     scanf( %s%s , a + 1, b + 1);     int n = strlen(a + 1);     int m = strlen(b + 1);     int pos = 0;     for (int i = 1; b[i]; i++, pos++) {       while (pos <= n && a[pos] != b[i]) pos++;       pre[i] = pos;     }     pos = n + 1;     for (int i = m; b[i]; i--, pos--) {       while (pos > 0 && b[i] != a[pos]) {         pos--;       }       suf[i] = pos;     }     suf[m + 1] = n + 1;     int ans1, ans2, l = 0, r = m;     while (l <= r) {       int mid = l + r >> 1, i;       for (i = 0; i + mid <= m; ++i)         if (pre[i] < suf[i + mid + 1]) break;       if (i + mid <= m) {         ans1 = i, ans2 = i + mid + 1, r = mid - 1;       } else         l = mid + 1;     }     if (ans2 - ans1 > m)       putchar( - );     else {       for (int i = 1; i <= ans1; ++i) putchar(b[i]);       for (int i = ans2; b[i]; ++i) putchar(b[i]);     }     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s;       int cnt[26];       fill(cnt, cnt + 26, 0);       set<int> st;       int u = s.size();       for (int j = 0; j < u; j++) {         int y = s[j] -  a ;         cnt[y]++;         st.insert(y);       }       u /= 2;       vector<int> ans;       vector<int> v;       for (auto itr = st.begin(); itr != st.end(); itr++) {         v.push_back(*itr);       }       if (v.size() == 1) {         cout << s << endl;         continue;       }       if (v.size() == 2) {         if (v[0] - v[1] == -1)           cout <<  No answer  << endl;         else {           cout << s << endl;         }         continue;       }       if (v.size() == 3) {         if (v[0] == v[1] - 1 && v[1] == v[2] - 1)           cout <<  No answer  << endl;         else if (v[0] == v[1] - 1) {           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         } else if (v[1] == v[2] - 1) {           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         } else {           for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a );           for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a );           for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a );           cout << endl;         }         continue;       }       for (int j = 1; j < v.size(); j += 2) {         for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a );       }       for (int j = 0; j < v.size(); j += 2) {         for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a );       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   constexpr int SQRT = 1000;   struct query {     int x, y, pos;     short sqrt;     bool operator<(const query &b) const {       if (sqrt == b.sqrt) {         return ((sqrt & 1) ^ y < b.y);       }       return sqrt < b.sqrt;     }   };   query que[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> que[i].x >> que[i].y;       que[i].pos = i + 1, que[i].sqrt = que[i].x / SQRT;     }     sort(que, que + n);     for (int i = 0; i < n; i++) {       cout << que[i].pos <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const int mod = 1e9 + 7;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0)       if (b & 1) {         res = (long long)(res * 1ll * a);         --b;       } else {         a = (long long)(a * 1ll * a);         b >>= 1;       }     return (long long)res;   }   vector<vector<int>> g;   vector<bool> used;   vector<long double> ver;   void dfs(int v, int prev) {     used[v] = true;     double cnt = 0, sum = 0;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to == prev) continue;       dfs(to, v);       sum += ver[to];       cnt++;     }     if (cnt == 0)       ver[v] = 0;     else       ver[v] = 1 + sum / cnt;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       if (n % 4 == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct S {     int l, r, x;   };   vector<S> tree[8000];   int mk[1000100], step, ans;   int n;   pair<int, int> expand(int v) {     int inc = 0;     if (v > 1) {       while ((1 << inc) < v) ++inc;     }     int bef = (v - 1) + inc;     pair<int, int> at = make_pair(bef + 1, bef + 1);     if (!(v & (v - 1))) at.second = (bef + 2);     return at;   }   void answer(int lvl, int v) {     pair<int, int> at = make_pair(v, v);     while (lvl <= n) {       pair<int, int> next =           make_pair(expand(at.first).first, expand(at.second).second);       for (int i = 0; i < tree[lvl].size(); ++i) {         int l = tree[lvl][i].l, r = tree[lvl][i].r, x = tree[lvl][i].x;         if (at.first > r || at.second < l) continue;         if (mk[x] != step) ++ans, mk[x] = step;       }       at = next;       ++lvl;     }   }   void process() {     int m;     scanf( %d%d , &n, &m);     step = 0;     for (int i = 0; i < m; ++i) {       int type, t, l, r, c, v, x;       scanf( %d , &type);       if (type == 1)         scanf( %d %d %d %d , &t, &l, &r, &x), tree[t].push_back((S){l, r, x});       else         scanf( %d %d , &t, &v), ans = 0, ++step, answer(t, v),                                 printf( %d n , ans);     }   }   int main() { process(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 75010;   struct edge {     int y, next;   } s[N];   struct loop {     vector<int> V;     int S;   } P[N];   struct node {     int x, y, d;     bool operator<(const node q) const { return x < q.x; }   };   vector<node> A;   vector<int> F[32768];   int first[N], len = 0, d[N], op[N], low[N], dfn[N], T = 0;   int sta[N], top = 0, totl;   int n, num, D;   map<long long, int> mp;   map<long long, int>::iterator it;   long long sum[20], tot = 0;   void ins(int x, int y) {     s[++len] = (edge){y, first[x]};     first[x] = len;   }   void Tarjan(int x) {     dfn[x] = ++T;     low[x] = T;     sta[++top] = x;     for (int i = first[x]; i != 0; i = s[i].next) {       if (!dfn[s[i].y]) {         Tarjan(s[i].y);         low[x] = min(low[x], low[s[i].y]);       } else         low[x] = min(low[x], dfn[s[i].y]);     }     if (low[x] == dfn[x]) {       bool tf = true;       totl++;       while (1) {         int now = sta[top];         top--;         P[totl].V.push_back(now);         if (P[totl].S & (1 << (d[now] - 1))) tf = false;         P[totl].S |= (1 << (d[now] - 1));         if (now == x) break;       }       if (first[x] == 0 || P[totl].V.size() == 1 && s[first[x]].y != x || !tf)         return;       if (!F[P[totl].S].size()) F[P[totl].S].push_back(totl);     }   }   int main() {     scanf( %d , &n);     D = (1 << n) - 1;     int size = 0, x, y;     mp.clear();     for (int i = 1; i <= n; i++) {       scanf( %d , &size);       while (size--) {         num++;         scanf( %d , &op[num]);         mp[1ll * op[num]] = num;         d[num] = i;         sum[i] += op[num];       }       tot += sum[i];     }     if (tot % n != 0) {       printf( No n );       return 0;     }     tot /= n;     for (int i = 1; i <= num; i++)       if (mp[tot - sum[d[i]] + op[i]]) ins(i, mp[tot - sum[d[i]] + op[i]]);     for (int i = 1; i <= num; i++)       if (!dfn[i]) Tarjan(i);     for (int i = 1; i <= D; i++)       for (int j = i & (i - 1); j; j = (j - 1) & i) {         if (F[j].size() && F[i ^ j].size()) {           F[i] = F[i ^ j];           for (int k = 0; k < F[j].size(); k++) F[i].push_back(F[j][k]);           break;         }       }     if (!F[D].size())       printf( No n );     else {       printf( Yes n );       for (int i = 0; i < F[D].size(); i++) {         x = F[D][i];         for (int j = 0; j < P[x].V.size() - 1; j++)           A.push_back((node){d[P[x].V[j]], op[P[x].V[j]], d[P[x].V[j + 1]]});         A.push_back((node){d[P[x].V[P[x].V.size() - 1]],                            op[P[x].V[P[x].V.size() - 1]], d[P[x].V[0]]});       }       sort(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) printf( %d %d n , A[i].y, A[i].d);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int mas[n];     for (int i = 0; i < n; i++) {       cin >> mas[i];     }     int d = 0;     int t = 0;     for (int i = 0; i < n; i++) {       if (mas[i] - d == 1) {         t++;         d = mas[i];       }     }     if (!d) {       cout <<  0 ;       return 0;     }     cout << t << endl;     d = 0;     for (int i = 0; i < n; i++) {       if (mas[i] - d == 1) {         d = mas[i];         cout << 2000 + i + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s = to_string(n);     int m = s.size();     vector<int> v;     for (int i = 9 * m; i >= 0; i--) {       int j = n - i;       int sum = 0;       for (sum = 0; j > 0; j /= 10) sum += j % 10;       if (sum == i) v.push_back(n - i);     }     cout << v.size() << endl;     for (auto i : v) cout << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     const long long MOD = 1000003;     int n;     cin >> n;     long long g = 1;     for (int i = 1; i < n; i++) {       g = (g * 3) % MOD;     }     cout << g;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 1303;   long long solve() {     long long n;     string s;     cin >> s;     map<char, string> mp;     mp[ > ] =  1000 ;     mp[ < ] =  1001 ;     mp[ + ] =  1010 ;     mp[ - ] =  1011 ;     mp[ . ] =  1100 ;     mp[ , ] =  1101 ;     mp[ [ ] =  1110 ;     mp[ ] ] =  1111 ;     n = s.size();     string tmp =   ;     for (long long i = 0; i < n; ++i) tmp += mp[s[i]];     reverse((tmp).begin(), (tmp).end());     long long ans = 0;     long long p = 1;     for (auto x : tmp)       ans = (ans + ((x -  0 ) % 1000003 * (p % 1000003)) % 1000003) % 1000003,       p <<= 1, p %= 1000003;     cout << ans;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve(), cout << endl;     cerr << (float)clock() / CLOCKS_PER_SEC <<   secs n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char s[100005] = {0};     int i, j;     int panjang;     int banyak[27] = {0};     gets(s);     scanf( %d , &n);     panjang = strlen(s);     if (panjang <= n) {       printf( 0 n );       return 0;     }     for (i = 0; i < panjang; i++) {       ++banyak[s[i] -  a ];     }     int hasil = 0;     for (i = 0; i < 26; i++)       if (banyak[i] > 0) ++hasil;     int min = 100005;     int indeks;     while (1) {       min = 100005;       for (i = 0; i < 26; i++) {         if (banyak[i] > 0 && banyak[i] < min) {           min = banyak[i];           indeks = i;         }       }       if (banyak[indeks] > n) break;       --hasil;       n -= banyak[indeks];       banyak[indeks] = 0;     }     printf( %d n , hasil);     for (i = 0; i < panjang; i++) {       if (banyak[s[i] -  a ] > 0) printf( %c , s[i]);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     string x;     cin >> x;     int H = 0;     for (char &c : x)       if (c ==  H ) H++;     int result = n;     for (int i = 0; i < n; i++) {       int now = 0;       for (int j = 0; j < H; j++) {         if (x[(i + j) % n] !=  H ) now++;       }       result = min(result, now);     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, abc = 864197532, N = 1000001, logN = 17;   vector<int> a;   vector<int> d, lp;   struct Seg {     int l, r, m;     long long int val = 0;     Seg* ch[2];     Seg(int _l, int _r) : l(_l), r(_r), m(l + r >> 1) {       if (r - l > 1) {         ch[0] = new Seg(l, m);         ch[1] = new Seg(m, r);         pull();       } else {         val = a[l];       }     }     void pull() { val = ch[0]->val + ch[1]->val; }     void set(int p) {       if (r - l == 1)         val = d[val];       else         ch[p >= m]->set(p), pull();     }     long long int query(int a, int b) {       if (a <= l && r <= b) return val;       long long int ans = 0;       if (a < m) ans += ch[0]->query(a, b);       if (m < b) ans += ch[1]->query(a, b);       return ans;     }   };   void build() {     d.assign(N, 1);     lp.assign(N, 0);     for (int i = 2; i < N; ++i)       if (lp[i] == 0) {         for (int j = i; j < N; j += i) lp[j] = i;       }     for (int i = 2; i < N; ++i) {       int p = lp[i], tmp = i, cnt = 0;       while (tmp % p == 0) tmp /= p, cnt++;       d[i] = d[tmp] * (cnt + 1);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     build();     int n, q, t, l, r;     cin >> n >> q;     a.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     Seg root(0, n);     set<int> s;     for (int i = 0; i < n; ++i)       if (a[i] > 2) s.insert(i);     vector<int> eras;     while (q--) {       cin >> t >> l >> r, l--;       if (t == 1) {         for (auto it = s.lower_bound(l); it != s.end() && *it < r; ++it) {           int p = *it;           root.set(p);           a[p] = d[a[p]];           if (a[p] <= 2) eras.push_back(p);         }         while (eras.size()) {           s.erase(eras.back());           eras.pop_back();         }       } else {         cout << root.query(l, r) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T &x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T &x, L y) {     return y < x ? (x = y, 1) : 0;   }   const int maxn = 1e5 + 17, S = 1e9 + 1, maxfen = S * 2;   map<int, vector<pair<int, int>>> xs, ys;   int n;   unordered_map<int, int> iman;   struct eve {     int x, y, v;   };   vector<eve> event;   void make(vector<pair<int, int>> &vec) {     vector<pair<int, int>> ans;     sort(vec.begin(), vec.end());     int mxr = vec[0].second;     ans.push_back({vec[0].first, -1});     for (int i = 1; i < vec.size(); i++) {       if (mxr < vec[i].first)         ans.back().second = mxr + 1, ans.push_back({vec[i].first, -1});       smax(mxr, vec[i].second);     }     ans.back().second = mxr + 1;     vec = ans;   }   void majid(long long p, int v) {     for (p += S; p < maxfen; p += p & -p) iman[p] += v;   }   int hamid(int p) {     int ans = 0;     for (p += S; p; p ^= p & -p) ans += iman[p];     return ans;   }   int hamid(int l, int r) { return hamid(r - 1) - hamid(l - 1); }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int x1, y1, x2, y2, i = 0; i < n; i++) {       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2)         xs[x1].push_back(minmax(y1, y2));       else         ys[y1].push_back(minmax(x1, x2));     }     long long ans = 0;     for (auto &v : ys) {       make(v.second);       for (auto x : v.second) {         ans += x.second - x.first;         event.push_back({v.first, x.first, 1});         event.push_back({v.first, x.second, -1});       }     }     sort(event.begin(), event.end(), [](eve &a, eve &b) { return a.y < b.y; });     int ptr = 0;     for (auto &v : xs) {       make(v.second);       while (ptr < event.size() && event[ptr].y <= v.first)         majid(event[ptr].x, event[ptr].v), ptr++;       for (auto x : v.second) {         ans += x.second - x.first;         ans -= hamid(x.first, x.second);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const float pi = acos(-1.0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       cout << 0 <<     << 0 <<     << n;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   const int mlen = 303;   int p[6];   char s[6][mlen];   char res[mlen][mlen];   vector<vector<string> > x;   void draw(int sx, int sy, const char *s, int dx, int dy) {     while (*s) res[sy][sx] = *s++, sx += dx, sy += dy;   }   int main() {     for (int i = 0; i < (int)(6); i++) gets(s[i]), p[i] = i;     do {       int H = strlen(s[p[0]]) - 1;       int W = strlen(s[p[1]]) - 1;       int h = strlen(s[p[2]]) - 1;       int w = strlen(s[p[3]]) - 1;       int bad = 0;       bad |= (strlen(s[p[0]]) != strlen(s[p[2]]) + strlen(s[p[4]]) - 1);       bad |= (strlen(s[p[1]]) != strlen(s[p[3]]) + strlen(s[p[5]]) - 1);       bad |= (s[p[0]][0] != s[p[3]][w]);       bad |= (s[p[0]][h] != s[p[1]][w]);       bad |= (s[p[0]][H] != s[p[5]][0]);       bad |= (s[p[2]][0] != s[p[3]][0]);       bad |= (s[p[2]][h] != s[p[1]][0]);       bad |= (s[p[4]][0] != s[p[1]][W]);       bad |= (s[p[4]][H - h] != s[p[5]][W - w]);       if (bad) continue;       memset(res,  . , sizeof(res));       draw(0, 0, s[p[2]], 0, 1);       draw(w, 0, s[p[0]], 0, 1);       draw(W, h, s[p[4]], 0, 1);       draw(0, 0, s[p[3]], 1, 0);       draw(0, h, s[p[1]], 1, 0);       draw(w, H, s[p[5]], 1, 0);       vector<string> R;       for (int i = 0; i < (int)(H + 1); i++)         res[i][W + 1] = 0, R.push_back(res[i]);       x.push_back(R);     } while (next_permutation(p, p + 6));     sort((x).begin(), (x).end());     if (!x.size())       puts( Impossible );     else {       for (int i = 0; i < (int)(x[0].size()); i++) {         for (int j = 0; j < (int)(x[0][0].size()); j++) printf( %c , x[0][i][j]);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 75005;   const long long maxm = (1 << 15) + 5;   long long k, n[16], s[16], a[16][5005], co[maxn], col[maxn], idx, b[maxn],       yhp[16], num;   long long st[maxn], cnt[16], vis[maxm], lst[maxm], from[maxm], sel[maxn];   long long head[maxn], ecnt, d[maxn];   struct edge {     long long to, next;   } e[maxn << 1];   map<long long, long long> id, ans;   long long sum[maxn];   vector<long long> to, nxt;   void adde(long long u, long long v) {     e[++ecnt].to = v;     d[v]++;     e[ecnt].next = head[u];     head[u] = ecnt;   }   long long read() {     long long res = 0, f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (!isdigit(ch));     do {       res = res * 10 + ch -  0 ;       ch = getchar();     } while (isdigit(ch));     return res * f;   }   void topsort() {     queue<long long> q;     for (long long i = (1); i <= (s[k]); ++i)       if (!d[i]) q.push(i);     while (!q.empty()) {       long long u = q.front();       q.pop();       for (long long i = head[u]; i; i = e[i].next) {         long long v = e[i].to;         d[v]--;         if (!d[v]) q.push(v);       }     }   }   void dfs(long long u) {     col[u] = idx;     st[idx] |= (1 << (yhp[co[u]] - 1));     cnt[yhp[co[u]]]++;     for (long long i = head[u]; i; i = e[i].next) {       long long v = e[i].to;       if (!d[v] || col[v]) continue;       dfs(v);     }   }   signed main() {     k = read();     for (long long i = (1); i <= (k); ++i) {       n[i] = read();       s[i] = s[i - 1] + n[i];       for (long long j = (1); j <= (n[i]); ++j)         a[i][j] = read(), id[a[i][j]] = s[i - 1] + j, co[id[a[i][j]]] = i,         b[id[a[i][j]]] = a[i][j], sum[i] += a[i][j];       sum[0] += sum[i];     }     if (sum[0] % k != 0) {       puts( No );       return 0;     }     sum[0] /= k;     for (long long i = (1); i <= (k); ++i)       if (sum[i] == sum[0])         yhp[i] = yhp[i - 1];       else         yhp[i] = ++num;     for (long long i = (1); i <= (k); ++i)       for (long long j = (1); j <= (n[i]); ++j) {         if (sum[i] == sum[0]) continue;         long long x = (sum[0] - (sum[i] - a[i][j]));         if (id[x] == 0 || (co[id[a[i][j]]] == co[id[x]] && id[a[i][j]] != id[x]))           continue;         adde(id[a[i][j]], id[x]);       }     topsort();     for (long long i = (1); i <= (s[k]); ++i) {       if (d[i] && !col[i]) {         ++idx;         memset(cnt, 0, sizeof(cnt));         dfs(i);         for (long long j = (1); j <= (k); ++j)           if (cnt[j] > 1) st[idx] = 0;       }     }     vis[0] = 1;     to.push_back(0);     long long S = (1 << num) - 1;     for (long long i = (1); i <= (idx); ++i) {       if (!st[i]) continue;       nxt.clear();       for (long long x : to) {         if (x & st[i]) continue;         if (vis[x | st[i]]) continue;         vis[x | st[i]] = 1;         lst[x | st[i]] = x;         from[x | st[i]] = i;         nxt.push_back(x | st[i]);       }       for (long long x : nxt) to.push_back(x);     }     if (!vis[S]) {       puts( No );       return 0;     }     puts( Yes );     long long tmp = S;     while (tmp) sel[from[tmp]] = 1, tmp = lst[tmp];     for (long long u = (1); u <= (s[k]); ++u)       if (sel[col[u]])         for (long long i = head[u]; i; i = e[i].next) {           long long v = e[i].to;           if (d[v]) ans[b[v]] = co[u];         }     for (long long i = (1); i <= (k); ++i) {       if (sum[i] == sum[0])         printf( %lld %lld n , a[i][1], i);       else         for (long long j = (1); j <= (n[i]); ++j)           if (ans[a[i][j]]) printf( %lld %lld n , a[i][j], ans[a[i][j]]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000009;   long long poww(long long base, long long power) {     long long ret = 1;     for (long long i = 0; i < power; i++) {       ret *= base;       ret %= mod;     }     return ret;   }   int main() {     long long ans;     long long n, m;     while (~scanf( %I64d%I64d , &n, &m)) {       ans = 1;       long long sum = poww(2, m);       for (long long i = 1; i <= n; i++) {         ans *= (sum - i);         ans %= mod;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int dist[200002];   vector<pair<int, int>> v[200002];   vector<int> nes[200002];   char s[200002];   vector<string> ans;   void dfs(int d) {     if (ans.size() >= k) return;     if (d > n) {       ans.push_back(s);       return;     }     for (auto i : nes[d]) {       s[i] =  1 ;       dfs(d + 1);       s[i] =  0 ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       v[a].push_back({b, i});       v[b].push_back({a, i});     }     queue<int> q;     q.push(1);     dist[1] = 1;     while (q.size()) {       int x = q.front();       q.pop();       for (auto i : v[x]) {         if (dist[i.first]) continue;         dist[i.first] = dist[x] + 1;         q.push(i.first);       }     }     for (int i = 2; i <= n; ++i) {       for (auto j : v[i]) {         if (dist[j.first] + 1 == dist[i]) nes[i].push_back(j.second);       }     }     fill(s, s + m,  0 );     dfs(2);     cout << ans.size() <<   n ;     for (auto i : ans) cout << i <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       long long int n, m, c = 0;       cin >> n >> m;       vector<set<long long int>> v(n + 1);       long long int x, y;       for (int i = 0; i < m; i++) {         cin >> x >> y;         v[x].insert(y);         v[y].insert(x);       }       while (1) {         vector<long long int> q;         for (int i = 1; i <= n; i++)           if (v[i].size() == 1) q.push_back(i);         for (int i = 0; i < q.size(); i++) {           auto it = v[q[i]].begin();           v[q[i]].clear();           v[*it].erase(q[i]);         }         if (q.size() > 0)           c++;         else           break;       }       cout << c;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long geti() {     long long ret = 0;     char ch = getchar(), k = 1;     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) k = 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return k ? ret : -ret;   }   const int N = 1000010;   const int mo = 1000000007;   int n, t, mx;   long long f[N], g[N], mi2[N], ans = 0;   int main() {     n = geti();     for (int i = 1; i <= n; i += 1) {       t = geti();       mx = max(mx, t);       for (int j = 1; j * j <= t; j += 1) {         if (t % j != 0) continue;         f[j] += 1;         if (j != t / j) f[t / j] += 1;       }     }     mi2[0] = 1;     for (int i = 1; i <= mx; i += 1) mi2[i] = mi2[i - 1] * 2 % mo;     for (int i = mx; i > 1; i -= 1) {       g[i] = f[i] * mi2[f[i] - 1] % mo;       for (int j = 2 * i; j <= mx; j += i) {         g[i] -= g[j];         g[i] %= mo;       }       ans += i * g[i] % mo;       ans %= mo;     }     cout << (ans + mo) % mo;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 5;   int b[maxn];   int g[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= m; i++) scanf( %d , &g[i]);     long long sum = 0;     sort(b + 1, b + n + 1);     sort(g + 1, g + m + 1);     if (b[n] > g[1])       printf( -1 n );     else {       int cur = m;       for (int i = n; i >= 1; i--) {         sum += (long long)b[i] * m;         int k = m;         if (cur == m) {           while (k > 0 && cur >= 2 && g[cur] > b[i]) {             k--;             sum += g[cur] - b[i];             cur--;           }         } else {           while (k > 0 && cur >= 1 && g[cur] > b[i]) {             k--;             sum += g[cur] - b[i];             cur--;           }         }         while (cur >= 1 && g[cur] == b[i]) cur--;       }       if (cur >= 1)         printf( -1 n );       else         printf( %I64d n , sum);     }     return 0;   }


//Be Name Khoda      #include<bits/stdc++.h>      using namespace std;      typedef long long ll;      #define pb push_back   #define pp pop_back   #define all(x) x.begin(), x.end()      const ll mxn = 3e5 + 5;   ll t, n = 0, k, q;   ll cnt[mxn];   vector<ll> v, v2;      void input() {          for(int i = 0; i <= n; i++) {           cnt[i] = 0;       }          v.clear(), v2.clear();          cin >> n;          for(int i = 0; i < n; i++) {           cin >> q;            v.pb(q);           cnt[q]++;       }      }         void solve() {          ll l = 0, r = n - 1;          if(cnt[1] > 0) {           v2.pb(1);       }          for(int i = 2; i < n; i++) {           if(cnt[1] == 0 || cnt[i] == 0 || cnt[i - 1] > 1) {               break;           }           if(v[l] == i - 1) {               v2.pb(1);               l++;           }           else if(v[r] == i - 1) {               v2.pb(1);               r--;           }           else {               break;           }       }          while(v2.size() < n - 1) {           v2.pb(0);       }          bool check = 1;          for(int i = 1; i <= n; i++) {           if(cnt[i] != 1) {               check = 0;               break;           }       }          if(n > 1) {           if(!check) {               v2.pb(0);           }           else {               v2.pb(1);           }       }          for(int i = v2.size() - 1; i > -1; i--) {           cout << v2[i];       }       cout << endl;      }      int main() {          ios::sync_with_stdio(false);          cin >> t;          while(t--) {           input(), solve();       }              return 0;          }


#include <bits/stdc++.h>   using namespace std;   int I, len[500005], las[500005];   string second, ans[500005];   char fi[500005], se[500005];   string get(int raod, char c, int ind) {     len[I] = raod + len[ind];     raod = min(raod, 10);     string ret =   ;     for (int i = 0; i < raod; i++) ret += c;     ret = ret + ans[ind];     if (ret.size() <= 10) return ret;     string ne;     for (int i = 0; i < 5; i++) ne += ret[i];     ne +=  ... ;     for (int i = (int)ret.size() - 2; i < ret.size(); i++) ne += ret[i];     return ne;   }   int main() {     ios::sync_with_stdio(false);     cin >> second;     int n = (int)second.size();     ans[n - 1] += second[n - 1];     len[n - 1] = 1;     las[n - 1] = n;     fi[n - 1] = second[n - 1];     se[n - 1] =  % ;     fi[n] =  % ;     se[n] =  % ;     for (int i = (int)second.size() - 2; i >= 0; i--) {       I = i;       int raod;       if (second[i] == second[i + 1]) {         las[i] = las[i + 1];       } else {         las[i] = i + 1;       }       int ind = las[i];       if (fi[ind] ==  % ) {         raod = (ind - i) % 2;         ans[i] = get(raod, second[i], ind);         if (raod) {           fi[i] = second[i];         } else           fi[i] =  % ;         se[i] =  % ;         continue;       }       if (fi[ind] == second[i]) {         if (se[ind] ==  % ) {           raod = (ind - i) % 2;           ans[i] = get(raod, second[i], ind);           fi[i] = second[i];           se[i] =  % ;           continue;         } else {           if (se[ind] > second[i]) {             ans[i] = get(ind - i, second[i], ind);             fi[i] = second[i];             se[i] = se[ind];           } else {             raod = (ind - i) % 2;             ans[i] = get(raod, second[i], ind);             fi[i] = second[i];             se[i] = se[i];           }         }       } else {         if (fi[ind] > second[i]) {           ans[i] = get(ind - i, second[i], ind);           fi[i] = second[i];           se[i] = fi[ind];         } else {           raod = (ind - i) % 2;           ans[i] = get(raod, second[i], ind);           if (raod) {             fi[i] = second[i];             se[i] = fi[ind];           } else {             fi[i] = fi[ind];             se[i] = se[ind];           }         }       }     }     for (int i = 0; i < n; i++) cout << len[i] <<     << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = 100 * 1000 + 5;   const long long INF = 10LL * 1000 * 1000 * 1000 * 1000;   long long a[N];   pair<long long, long long> next(long long x, long long c) {     pair<long long, long long> res = {-1, -1};     for (long long d = 1; d * d <= c; d++)       if (c % d == 0 && (d + c / d) % 2 == 0) {         long long x2 = (d + c / d) / 2;         long long x1 = c / d - x2;         if (x1 > x && x2 > x1 && x1 * x1 - x * x <= INF &&             (res.second == -1 || x2 < res.second))           res = {x1, x2};       }     return res;   }   int main() {     int n = in();     long long x = 0;     for (int i = 0; i < n / 2; i++) {       long long c = in();       a[2 * i + 1] = c;       pair<long long, long long> nx = next(x, c);       if (nx.first == -1) return (cout <<  No n ), 0;       a[2 * i] = nx.first * nx.first - x * x;       x = nx.second;     }     cout <<  Yes n ;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, p[100000], la[100000], lb[100000];   int party[100000];   bool pass, assigned[100000];   map<int, int> m;   inline int deg(int i) { return (la[i] != -1) + (lb[i] != -1); }   int dfs(int i) {     if (deg(i) == 0) {       return 1;     }     if (~la[i]) {       int t = la[i];       la[t] = la[i] = lb[i] = -1;       if (!assigned[i] && (assigned[i] = assigned[t] = 1))         party[i] = party[t] = 0;       if (t == i) pass = 1;       return 1 + dfs(t);     } else {       int t = lb[i];       lb[t] = la[i] = lb[i] = -1;       if (!assigned[i] && (assigned[i] = assigned[t] = 1))         party[i] = party[t] = 1;       if (t == i) pass = 1;       return 1 + dfs(t);     }   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; ++i) scanf( %d , p + i), m[p[i]] = i;     auto fd = [](int x) {       auto it = m.find(x);       return it == m.end() ? -1 : it->second;     };     for (int i = 0; i < n; ++i) {       la[i] = fd(a - p[i]);       lb[i] = fd(b - p[i]);       if (deg(i) == 0) {         puts( NO );         return 0;       }     }     for (int i = 0; i < n; ++i) {       if (deg(i) == 1) {         pass = 0;         if (dfs(i) & 1 && !pass) {           puts( NO );           return 0;         }       }     }     for (int i = 0; i < n; ++i) {       if (deg(i) == 2) {         dfs(i);       }     }     puts( YES );     for (int i = 0; i < n; ++i) printf( %d  , party[i]);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n;   long long deg[N], ans[N];   vector<pair<long long, long long> > g[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) {       long long x1, x2, y1, y2, z1, z2;       cin >> x1 >> y1 >> z1;       cin >> x2 >> y2 >> z2;       bool x = x1 ^ x2;       x = !x;       bool y = y1 ^ y2;       y = !y;       bool z = z1 ^ z2;       z = !z;       if (x || y || z)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct second {     int l, r, x, id;     bool operator<(const second a) const {       if (r < a.r) return 1;       if (r > a.r) return 0;       return id < a.id;     }   } s[10005];   int cmp(const second a, const second b) {     if (a.l != b.l) return a.l < b.l;     return a.r < b.r;   }   set<second> st;   int a[10005];   int dp1[10005], dp2[10005];   bool ans[10005];   int main(void) {     int n, q;     scanf( %d%d , &n, &q);     int i;     for (i = 0; i < q; i++) {       scanf( %d%d%d , &s[i].l, &s[i].r, &s[i].x);       s[i].id = i;     }     sort(s, s + q, cmp);     int j = 0;     dp1[0] = dp2[0] = 1;     for (i = 1; i <= n; i++) {       bool modi = false;       while (j < q && s[j].l <= i) {         st.insert(s[j]);         int x = s[j].x;         for (int l = n; l >= x; l--) {           dp1[l] += dp1[l - x];           dp1[l] %= 19950527;           dp2[l] += dp2[l - x];         }         modi = true;         j++;       }       while (!st.empty()) {         auto it = st.begin();         if (it->r < i) {           int x = it->x;           for (int l = x; l <= n; l++) {             dp1[l] -= dp1[l - x];             dp1[l] %= 19950527;             dp2[l] -= dp2[l - x];           }           st.erase(it);           modi = true;         } else {           break;         }       }       if (!modi) continue;       for (int l = 1; l <= n; l++)         if (dp1[l] || dp2[l]) ans[l] = true;     }     int cnt = 0;     for (i = 1; i <= n; i++)       if (ans[i]) cnt++;     printf( %d n , cnt);     for (i = 1; i <= n; i++)       if (ans[i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   #pragma optimize( Ofast )   using namespace std;   unsigned int start = clock();   using ll = unsigned long long;   struct obj {     int fi, se;     obj() { fi = se = 0; }   };   void gettime(string s) {     cout << endl << s << (clock() - start) / 1000000.0 << endl;   }   void insert() {}   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> pref(n, 0);     for (int i = 1; i < n - 1; i++) {       pref[i] = pref[i - 1] + (a[i - 1] < a[i] && a[i] > a[i + 1] ? 1 : 0);     }     pref[n - 1] = pref[n - 2];     int l = 0;     int ans = pref[k - 2];     for (int i = k - 1; i < n; i++) {       if (ans < pref[i - 1] - pref[i - k + 1]) {         ans = pref[i - 1] - pref[i - k + 1];         l = i - k + 1;       }     }     cout << ans + 1 <<     << l + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int q = 1;     cin >> q;     while (q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= M;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % M;       a = a * a % M;     }     return res % M;   }   const long long N = 1e5;   int main() {     int n;     cin >> n;     map<string, int> m;     int c = 0;     set<string> st[21], st1[21];     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (m.count(s))         ;       else         m[s] = c++;       int nn;       cin >> nn;       for (int j = 0; j < nn; ++j) {         string ss;         cin >> ss;         st[m[s]].insert(ss);       }     }     for (int i = 0; i < c; ++i) {       for (set<string>::iterator it = st[i].begin(); it != st[i].end(); ++it) {         bool flag = 0;         for (set<string>::iterator it1 = st[i].begin(); it1 != st[i].end();              ++it1) {           if (*it != *it1) {             string s1 = *it, s2 = *it1;             if (s1.size() <= s2.size()) {               int k = s2.size() - s1.size();               int j = 0;               for (; k < s2.size(); ++k) {                 if (s2[k] == s1[j])                   j++;                 else                   break;               }               if (j == s1.size()) flag = 1;             }           }         }         if (flag == 0) st1[i].insert(*it);       }     }     cout << c << endl;     for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << st1[it->second].size() <<    ;       for (set<string>::iterator it1 = st1[it->second].begin();            it1 != st1[it->second].end(); ++it1)         cout << *it1 <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   struct Point {     int x, y;     Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}     Point(std::istream &in) {       in >> x >> y;       x *= 2;       y *= 2;     }   };   bool operator<(const Point &a, const Point &b) {     return (a.x < b.x) || (a.x == b.x && a.y < b.y);   }   bool cmp_sum(const Point &a, const Point &b) { return (a.x + a.y < b.x + b.y); }   bool cmp_diff(const Point &a, const Point &b) {     return (a.x - a.y < b.x - b.y);   }   int n, k;   vector<Point> gnome, metro;   vector<int> sorted_x, sorted_y;   vector<int> tree;   int curk;   void upd_val(int x, int val, const vector<int> &coords) {     x = lower_bound(coords.begin(), coords.end(), x) - coords.begin();     x += curk;     tree[x] = min(tree[x], val);     x /= 2;     while (x != 1) {       tree[x] = min(tree[x * 2], tree[x * 2 + 1]);       x /= 2;     }   }   int get_min_val(int l, int r, const vector<int> &coords) {     l = lower_bound(coords.begin(), coords.end(), l) - coords.begin();     r = lower_bound(coords.begin(), coords.end(), r) - coords.begin();     l += curk;     r += curk;     int res = INF;     while (l < r) {       res = min(res, min(tree[l], tree[r]));       l = (l + 1) / 2;       r = (r - 1) / 2;     }     if (l == r) {       res = min(res, tree[l]);     }     return res;   }   void shrink(vector<int> &coord) {     sort(coord.begin(), coord.end());     coord.resize(unique(coord.begin(), coord.end()) - coord.begin());   }   template <typename T>   std::vector<int> argsort(const std::vector<T> &vals, bool reverse = false) {     vector<int> result(vals.size());     for (int i = 0; i < int(vals.size()); ++i) {       result[i] = i;     }     sort(result.begin(), result.end(),          [&](int a, int b) -> bool { return (vals[a] < vals[b]); });     if (reverse) {       std::reverse(result.begin(), result.end());     }     return result;   }   void get_min_dist(const std::vector<Point> &gnome, std::vector<Point> metro,                     std::vector<int> &result) {     sorted_x.clear();     sorted_y.clear();     for (auto &x : gnome) {       sorted_x.push_back(x.x);       sorted_y.push_back(x.y);     }     for (auto &x : metro) {       sorted_x.push_back(x.x);       sorted_y.push_back(x.y);     }     shrink(sorted_x);     shrink(sorted_y);     int nn = gnome.size();     result.assign(nn, INF);     auto indices = argsort(gnome);     sort(metro.begin(), metro.end());     curk = 2;     while (int(sorted_y.size()) > curk) curk *= 2;     {       tree.assign(2 * curk, INF);       int l = 0, r = 0;       while (l < nn) {         int ind = indices[l];         while (r < k && metro[r].x <= gnome[ind].x) {           upd_val(metro[r].y, -metro[r].x - metro[r].y, sorted_y);           ++r;         }         result[ind] = min(result[ind],                           get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) +                               gnome[ind].x + gnome[ind].y);         ++l;       }     }     {       tree.assign(2 * curk, INF);       int l = 0, r = 0;       while (l < nn) {         int ind = indices[l];         while (r < k && metro[r].x <= gnome[ind].x) {           upd_val(metro[r].y, -metro[r].x + metro[r].y, sorted_y);           ++r;         }         result[ind] = min(result[ind],                           get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) +                               gnome[ind].x - gnome[ind].y);         ++l;       }     }     reverse(metro.begin(), metro.end());     reverse(indices.begin(), indices.end());     {       tree.assign(2 * curk, INF);       int l = 0, r = 0;       while (l < nn) {         int ind = indices[l];         while (r < k && metro[r].x >= gnome[ind].x) {           upd_val(metro[r].y, metro[r].x - metro[r].y, sorted_y);           ++r;         }         result[ind] = min(result[ind],                           get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) -                               gnome[ind].x + gnome[ind].y);         ++l;       }     }     {       tree.assign(2 * curk, INF);       int l = 0, r = 0;       while (l < nn) {         int ind = indices[l];         while (r < k && metro[r].x >= gnome[ind].x) {           upd_val(metro[r].y, metro[r].x + metro[r].y, sorted_y);           ++r;         }         result[ind] = min(result[ind],                           get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) -                               gnome[ind].x - gnome[ind].y);         ++l;       }     }   }   int find_dist(pair<pair<int, int>, pair<int, int> > rect, const Point &pnt) {     int sum = pnt.x + pnt.y;     int diff = pnt.x - pnt.y;     int sum_dist =         max(0, -min(rect.first.second, sum) + max(rect.first.first, sum));     int diff_dist =         max(0, -min(rect.second.second, diff) + max(rect.second.first, diff));     return max(sum_dist, diff_dist);   }   void get_all_min_dist(vector<pair<pair<int, int>, pair<int, int> > > rect,                         vector<Point> metro, vector<int> &dist) {     dist.assign(n, INF);     vector<Point> ok_points;     for (int i = 0; i < n; ++i) {       const auto &cr = rect[i];       int a, b, c, d;       tie(a, b) = cr.first;       tie(c, d) = cr.second;       ok_points.emplace_back((a + c) / 2, (a - c) / 2);       ok_points.emplace_back((a + d) / 2, (a - d) / 2);       ok_points.emplace_back((b + c) / 2, (b - c) / 2);       ok_points.emplace_back((b + d) / 2, (b - d) / 2);     }     vector<int> tmp;     get_min_dist(ok_points, metro, tmp);     for (int i = 0; i < n * 4; ++i) {       dist[i / 4] = min(dist[i / 4], tmp[i]);     }     vector<int> sorted_sum;     vector<int> sorted_diff;     for (auto &pnt : rect) {       sorted_sum.push_back(pnt.first.first);       sorted_sum.push_back(pnt.first.second);       sorted_diff.push_back(pnt.second.first);       sorted_diff.push_back(pnt.second.second);     }     for (auto &pnt : metro) {       sorted_sum.push_back(pnt.x + pnt.y);       sorted_diff.push_back(pnt.x - pnt.y);     }     shrink(sorted_sum);     shrink(sorted_diff);     sort(metro.begin(), metro.end(), cmp_sum);     curk = 2;     while (curk < int(sorted_diff.size())) curk *= 2;     vector<pair<pair<int, int>, pair<int, int> > > segment;     for (int i = 0; i < n; ++i) {       segment.emplace_back(make_pair(rect[i].first.first, i), rect[i].second);       if (rect[i].first.first != rect[i].first.second) {         segment.emplace_back(make_pair(rect[i].first.second, i), rect[i].second);       }     }     sort(segment.begin(), segment.end());     {       tree.assign(curk * 2, INF);       int nn = segment.size();       int l = 0, r = 0;       while (l < nn) {         while (r < k && metro[r].x + metro[r].y <= segment[l].first.first) {           upd_val(metro[r].x - metro[r].y, -metro[r].y - metro[r].x, sorted_diff);           ++r;         }         int ind = segment[l].first.second;         dist[ind] =             min(dist[ind], get_min_val(segment[l].second.first,                                        segment[l].second.second, sorted_diff) +                                segment[l].first.first);         ++l;       }     }     reverse(metro.begin(), metro.end());     reverse(segment.begin(), segment.end());     {       tree.assign(curk * 2, INF);       int nn = segment.size();       int l = 0, r = 0;       while (l < nn) {         while (r < k && metro[r].x + metro[r].y >= segment[l].first.first) {           upd_val(metro[r].x - metro[r].y, metro[r].x + metro[r].y, sorted_diff);           ++r;         }         int ind = segment[l].first.second;         dist[ind] =             min(dist[ind], get_min_val(segment[l].second.first,                                        segment[l].second.second, sorted_diff) -                                segment[l].first.first);         ++l;       }     }     sort(metro.begin(), metro.end(), cmp_diff);     segment.clear();     for (int i = 0; i < n; ++i) {       segment.emplace_back(make_pair(rect[i].second.first, i), rect[i].first);       if (rect[i].second.first != rect[i].second.second) {         segment.emplace_back(make_pair(rect[i].second.second, i), rect[i].first);       }     }     sort(segment.begin(), segment.end());     curk = 2;     while (curk < int(sorted_sum.size())) curk *= 2;     {       tree.assign(curk * 2, INF);       int nn = segment.size();       int l = 0, r = 0;       while (l < nn) {         while (r < k && metro[r].x - metro[r].y <= segment[l].first.first) {           upd_val(metro[r].x + metro[r].y, metro[r].y - metro[r].x, sorted_sum);           ++r;         }         int ind = segment[l].first.second;         dist[ind] =             min(dist[ind], get_min_val(segment[l].second.first,                                        segment[l].second.second, sorted_sum) +                                segment[l].first.first);         ++l;       }     }     reverse(metro.begin(), metro.end());     reverse(segment.begin(), segment.end());     {       tree.assign(curk * 2, INF);       int nn = segment.size();       int l = 0, r = 0;       while (l < nn) {         while (r < k && metro[r].x - metro[r].y >= segment[l].first.first) {           upd_val(metro[r].x + metro[r].y, metro[r].x - metro[r].y, sorted_sum);           ++r;         }         int ind = segment[l].first.second;         dist[ind] =             min(dist[ind], get_min_val(segment[l].second.first,                                        segment[l].second.second, sorted_sum) -                                segment[l].first.first);         ++l;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; ++i) {       gnome.emplace_back(std::cin);     }     for (int i = 0; i < k; ++i) {       metro.emplace_back(std::cin);     }     int min_x = INF, max_x = -INF;     int min_y = INF, max_y = -INF;     for (const auto &pnt : gnome) {       min_x = min(min_x, pnt.x + pnt.y);       max_x = max(max_x, pnt.x + pnt.y);       min_y = min(min_y, pnt.x - pnt.y);       max_y = max(max_y, pnt.x - pnt.y);     }     int result = (max(max_x - min_x, max_y - min_y) + 1) / 2;     if (n > 1 && k) {       vector<int> dist;       get_min_dist(gnome, metro, dist);       auto indices = argsort(dist, true);       vector<pair<pair<int, int>, pair<int, int> > > all_rect;       vector<int> add_dist;       min_x = INF, max_x = -INF;       min_y = INF, max_y = -INF;       for (int i = 0; i < n; ++i) {         const auto &pnt = gnome[indices[i]];         min_x = min(min_x, pnt.x + pnt.y);         max_x = max(max_x, pnt.x + pnt.y);         min_y = min(min_y, pnt.x - pnt.y);         max_y = max(max_y, pnt.x - pnt.y);         int dist = (max(max_x - min_x, max_y - min_y) + 1) / 2;         add_dist.push_back(dist);         all_rect.emplace_back(make_pair(max_x - dist, min_x + dist),                               make_pair(max_y - dist, min_y + dist));       }       result = min(result, dist[indices[0]]);       vector<int> new_dist;       get_all_min_dist(all_rect, metro, new_dist);       for (int i = 0; i < n - 1; ++i) {         int t1 = add_dist[i];         int t2 = new_dist[i];         int t3 = dist[indices[i + 1]];         int x = (max(0, min(2 * t2, t3 + t2 - t1)) + 1) / 2;         result = min(result, max(t1 + x, t3 + t2 - x));       }     }     result = (result + 1) / 2;     cout << result <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   constexpr ll INF = (1LL << 30) - 1LL;   constexpr ll LINF = (1LL << 60) - 1LL;   constexpr ll MOD = 1e9 + 7;   template <typename T>   void chmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   struct Median {     priority_queue<T> smq;     priority_queue<T, vector<T>, greater<T>> lgq;     void push(T x) {       if (smq.empty()) {         smq.push(x);         return;       }       T t = smq.top();       if (smq.size() > lgq.size()) {         if (t <= x) {           lgq.push(x);         } else {           lgq.push(t);           smq.pop();           smq.push(x);         }       } else {         if (t >= x) {           smq.push(x);         } else {           lgq.push(x);           smq.push(lgq.top());           lgq.pop();         }       }     }     inline T get() { return smq.top(); }   };   template <typename T>   struct BinaryIndexedTree {     vector<T> node;     int n;     BinaryIndexedTree(int n) : n(n) { node.assign(++n, 0); }     void add(int k, T x) {       for (++k; k < n; k += k & -k) {         node[k] += x;       }     }     T sum(int k) {       if (k < 0) {         return 0;       }       T res = 0;       for (++k; k > 0; k -= k & -k) {         res += node[k];       }       return res;     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> p(n), pos(n + 1);     for (int i = 0; i < n; i++) {       cin >> p[i];       pos[p[i]] = i;     }     BinaryIndexedTree<ll> bit(n + 1), bit2(n + 1);     for (int i = 0; i < n; i++) {       bit2.add(i, 1);     }     ll res = 0;     Median<ll> med;     for (int k = 1; k <= n; k++) {       res += bit.sum(n - 1) - bit.sum(pos[k]);       res -= min(bit.sum(pos[k] - 1), bit.sum(n - 1) - bit.sum(pos[k]));       bit.add(pos[k], 1);       bit2.add(pos[k], -1);       int t;       if (k % 2 > 0) {         med.push(pos[k]);       }       if (k > 1) {         t = med.get();         if (t < pos[k]) {           res += bit2.sum(pos[k]) - bit2.sum(t - 1);         } else {           res += bit2.sum(t) - bit2.sum(pos[k] - 1);         }         if (k % 2 == 0) {           med.push(pos[k]);         }       }       cout << res;       if (k < n) {         cout <<    ;       } else {         cout << endl;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   void solve() {     long long n, k;     cin >> n >> k;     if (n == 1 && k == 10) {       cout <<  -1             <<   n ;       return;     }     if (k == 10) {       cout << 1;       for (int i = 1; i <= n - 1; i++) {         cout << 0;       }     } else {       for (int i = 1; i <= n; i++) {         cout << k;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, a;     cin >> n;     vector<int> c(3 * 1e5, 0);     for (int i = 1; i <= n / 2; i++) {       cin >> a;       if (a >= i) c[1e5 + a - i]++;     }     if (n % 2) {       cin >> a;       if (a >= n / 2 + 1) c[1e5 + a - (n / 2) - 1]++;     }     for (int i = n / 2; i > 0; i--) {       cin >> a;       if (a >= i) c[1e5 + a - i]++;     }     int ans = 0;     for (int i = 0; i < 3 * 1e5; i++) ans = max(ans, c[i]);     cout << n - ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int sumo[maxn], sume[maxn];   int main() {     int n;     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int t;       cin >> t;       if (i % 2)         sumo[i] = sumo[i - 1] + t;       else         sumo[i] = sumo[i - 1];       if (i % 2 == 0)         sume[i] = sume[i - 1] + t;       else         sume[i] = sume[i - 1];     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int cnto = sumo[i - 1] + (sume[n] - sume[i]);       int cnte = sume[i - 1] + (sumo[n] - sumo[i]);       if (cnto == cnte) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int BIG = 1e9 + 239;   const int M = 2010;   int n, m, kol[M], id[M][M];   vector<int> v[M];   bitset<M> a[M];   string s;   bool used[M], need[M];   vector<pair<int, int> > ans;   inline void upd(int s, int f) {     used[s] = false;     for (int i = 0; i < n; i++)       if (used[i]) {         if (id[s][i] == -1) continue;         int bk = (int)v[i].back();         id[bk][i] = id[s][i];         v[i][id[s][i]] = bk;         v[i].pop_back();         id[s][i] = -1;       }     for (int i = 0; i < m; i++)       if (a[s][i]) kol[i]--;     bool ch = false;     for (int i = 0; i < m; i++)       if (kol[i] < 2 && a[f][i] == 1) a[f][i] = 0, ch = true;     if (ch) {       for (int i = 0; i < n; i++) need[i] = true;       for (int i : v[f]) need[i] = false;       for (int i = 0; i < n; i++)         if (need[i] && used[i] && i != f && ((a[f] & a[i]) == a[f])) {           id[i][f] = (int)v[f].size();           v[f].push_back(i);         }     }   }   inline void solve() {     ans.clear();     cin >> n >> m;     for (int i = 0; i < n; i++) v[i].clear();     for (int i = 0; i < n; i++) a[i] = 0;     for (int i = 0; i < m; i++) kol[i] = 0;     for (int i = 0; i < m; i++) {       cin >> s;       for (int x = 0; x < n; x++) {         a[x][i] = (s[x] -  0 );         if (s[x] ==  1 ) kol[i]++;       }     }     for (int i = 0; i < m; i++)       if (kol[i] < 2)         for (int x = 0; x < n; x++) a[x][i] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) id[i][j] = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j)           if ((a[i] & a[j]) == a[i]) {             id[j][i] = (int)v[i].size();             v[i].push_back(j);           }     for (int i = 0; i < n; i++) used[i] = true;     for (int iter = 0; iter < n - 1; iter++) {       int s = -1;       for (int i = 0; i < n; i++)         if (used[i] && !v[i].empty()) {           s = i;           break;         }       if (s == -1) {         cout <<  NO n ;         return;       }       int f = v[s].back();       ans.push_back(make_pair(s, f));       upd(s, f);     }     cout <<  YES n ;     for (pair<int, int> t : ans)       cout << (t.first + 1) <<     << (t.second + 1) <<   n ;   }   int main() {     cin.sync_with_stdio(0);     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout <<  INTERCAL n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[1000000];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int sol = x[n - 1] - x[0];     int p = n / 2 - 1;     for (int i = 0; i <= p; i++) sol = min(sol, x[n - 1 - (p - i)] - x[i]);     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, inF = 1e6 + 10;   int n, k, u, v, c, maxi, a[N], sz[N];   bool ok;   vector<int> nei[N];   int get_sz(int v, int par = -1) {     for (int u : nei[v])       if (u != par) sz[v] += get_sz(u, v);     return ++sz[v];   }   int dfs(int v, int par = -1) {     int dp = (a[v] < c ? -inF : 1);     int mx1 = 0, mx2 = 0;     for (int u : nei[v])       if (u != par) {         int DP = dfs(u, v);         if (DP == sz[u])           dp += DP;         else {           mx2 = max(mx2, DP);           if (mx2 > mx1) swap(mx1, mx2);         }       }     ok |= (dp + mx1 + mx2) >= k;     if (a[v] < c) return 0;     return dp + mx1;   }   bool check() {     ok = false;     dfs(min_element(a, a + n) - a);     return ok;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       nei[--u].push_back(--v);       nei[v].push_back(u);     }     get_sz(min_element(a, a + n) - a);     int l = 0, r = inF;     while (r - l > 1) {       c = (l + r) >> 1;       if (check())         l = c;       else         r = c;     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 8;   int a[N], fa[N][20];   vector<int> E[N];   long long res;   void dfs(int x, int f) {     fa[x][0] = f;     long long temp = a[f];     for (int i = 1; i < 20; i++) {       fa[x][i] = fa[fa[x][i - 1]][i - 1];       temp = min(temp, (i + 1ll) * a[fa[x][i]]);     }     if (f != x) res += temp + a[x];     for (int &e : E[x])       if (e != f) dfs(e, x);   }   int main() {     ios::sync_with_stdio(false);     int n, rt = 0;     a[0] = INT_MAX;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], rt = a[rt] < a[i] ? rt : i;     for (int i = 1, u, v; i < n; i++)       cin >> u >> v, E[u].push_back(v), E[v].push_back(u);     dfs(rt, rt);     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 5;   const long long LINF = LLONG_MAX;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (360 % (180 - n) == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long int k, col = 0;     cin >> n >> m >> k;     vector<int> desk;     for (int i = 1; i < n + 1; ++i) {       desk.push_back(m * i);     }     for (int i = 1; i < desk.size() + 1; ++i) {       if (k <= desk[i - 1] * 2) {         cout << i <<    ;         if (k % 2 == 0) {           if (i > 1)             cout << (k - desk[i - 2] * 2) / 2 <<   R ;           else             cout << k / 2 <<   R ;         } else {           if (i > 1)             cout << ((k + 1) - desk[i - 2] * 2) / 2 <<   L ;           else             cout << (k + 1) / 2 <<   L ;         }         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   using namespace std;   int main() {     int q;     long long int a, b, c;     long long int ans = 0;     cin >> q;     while (q--) {       cin >> a >> b >> c;       ans = (a + b + c) / 2;       cout << ans <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }   void solve() {     int r1, r2, c1, c2, d1, d2;     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     int a;     bool ans = false;     for (a = 1; a <= 9; ++a) {       int b = r1 - a;       int c = c1 - a;       int d = d1 - a;       if (a > 0 && a < 10 && b > 0 && b < 10 && c > 0 && c < 10 && d > 0 &&           d < 10) {         if (a != b && b != c && c != d && b != d && a != d && a != c) {           if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 &&               a + d == d1 && b + c == d2) {             cout << a <<     << b <<   n ;             cout << c <<     << d <<   n ;             ans = true;           }         }       }     }     if (!ans) cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     while (cin >> s) {       int ans = 1e6;       for (int i =  a ; i <=  z ; i++) {         int t = 0, k = 0;         for (int j = 0; j < s.length(); j++) {           if (s[j] == i)             t = 0;           else             t++;           k = max(k, t);         }         ans = min(ans, k);       }       cout << ans + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> E[65600];   vector<pair<int, int> > V;   int main() {     int n;     scanf( %d , &n);     queue<int> Q;     int degree[65600 + 10], Xsum[65600 + 10];     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       degree[i] = a;       Xsum[i] = b;       if (degree[i] == 1) Q.push(i);     }     while (!Q.empty()) {       int u = Q.front();       Q.pop();       if (degree[u] == 0) continue;       int othernode = Xsum[u];       V.push_back(make_pair(u, othernode));       degree[othernode]--;       degree[u]--;       Xsum[othernode] = Xsum[othernode] ^ u;       if (degree[othernode] == 1) Q.push(othernode);     }     printf( %d n , V.size());     for (int i = 0; i < V.size(); i++) printf( %d %d n , V[i].first, V[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using dl = double;   const int N = 2e5 + 10;   ll aarray[200000 + 10];   ll magic[101][101];   vector<ll> primes;   bool prime[1000001];   int main() {     ios_base::sync_with_stdio(false);     string str, ptr, ans =    ;     ll a, b, c, d, e, f, x = INT_MAX, y, k, t, A = 0, mod, B = 0, L, j, i, l, r,                          m, n, C = 0, sum = 0, sum1 = 0;     vector<ll> v, v1;     queue<ll> qu;     cin >> str;     cin >> n;     ll cnt = 0, fla = 0;     for (i = 1; i <= n; i++) {       cin >> ptr;       if (ptr.size() >= str.size()) {         if (ptr.substr(0, str.size()) == str) {           if (ptr < ans || ans ==    ) ans = ptr;         }       }     }     if (ans ==    )       cout << str << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int t = 1;     while (t--) {       long long int k, b, n;       cin >> k >> b >> n;       long long int s = 0;       long long int a[n];       map<long long int, vector<long long int> > mp;       mp[0].push_back(-1);       for (long long int i = 0; i < n; i++) {         cin >> a[i];         s = s + a[i];         s = s % (k - 1);         mp[s].push_back(i);       }       long long int an = 0;       if (b == k - 1 || b == 0) {         map<long long int, long long int> mp;         mp[0]++;         long long int an = 0, z = 0, ts = 0;         for (long long int i = 0; i < n; i++) {           ts = (ts + a[i]) % (k - 1);           if (a[i] == 0)             z++;           else             z = 0;           long long int tmp = (ts + (k - 1) - b) % (k - 1);           if (b == 0)             an += z;           else             an = an + mp[tmp] - z;           mp[ts]++;         }         cout << an;       } else {         for (auto x : mp) {           long long int y = x.first;           y = (y + b) % (k - 1);           for (long long int i = 0; i < x.second.size(); i++) {             long long int l =                 lower_bound(mp[y].begin(), mp[y].end(), x.second[i]) -                 mp[y].begin();             an = an + max(0ll, (long long int)(mp[y].size() - l));           }         }         cout << an;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_set<long long int> s;   void fun(long long int l, long long int r, long long int n) {     if (n > r)       return;     else if (n <= r and n >= l) {       s.insert(n);     }     fun(l, r, n * 2);     fun(l, r, n * 3);   }   void solve() {     long long int l, r;     cin >> l >> r;     fun(l, r, 1);     cout << s.size() << endl;   }   signed main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long dc(long long x, long long y) {     long long r;     while (y) {       r = x % y;       x = y;       y = r;     }     return x;   }   int main() {     cin >> n >> m >> k;     if (2 * n * m % k != 0)       cout <<  NO ;     else {       int ok = 0;       cout <<  YES  <<   n ;       if (k % 2 == 0) {         k = k / 2;         ok = 1;       }       long long d = dc(n, k);       k = k / d;       long long x = n / d;       d = dc(m, k);       k = k / d;       long long y = m / d;       if (ok) {         cout << 0 <<     << 0 <<   n ;         cout << x <<     << 0 <<   n ;         cout << 0 <<     << y <<   n ;       } else {         cout << 0 <<     << 0 <<   n ;         if (x < n)           x *= 2;         else if (y < m)           y *= 2;         cout << x <<     << 0 <<   n ;         cout << 0 <<     << y <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, k;     cin >> q;     long long l, r, d, x;     for (k = 0; k < q; ++k) {       cin >> l >> r >> d;       if (d < l || d > r)         x = d;       else {         if (r % d == 0)           x = r + d;         else           x = r + (d - (r % d));       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T solve(T n, T k) {     vector<T> arr(n);     for (T i = 0; i < n; i++) {       cin >> arr[i];     }     T sum = 0;     sort(arr.begin(), arr.end(), greater<int>());     for (int i = 2 * k; i < n; i++) {       sum += arr[i];     }     for (T i = 0; i < k; ++i) {       sum += (arr[i + k] / arr[i]);     }     return sum;   }   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       cout << solve(n, k) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10, M = 1e6 + 100, MOD = 1e9 + 7, ML = 25;   int a[M], ne[M];   map<int, bool> mp[M];   vector<int> ve[M], adj[M];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       adj[i].push_back(INF);       sort(adj[i].begin(), adj[i].end());       ne[i] = i + 1;     }     ne[n] = -1;     int l = 0, r = 0, cnt = 0, link = 1;     while (link != -1) {       int la = r;       a[r++] = link;       link = ne[link];       while (l < r) {         int v = a[l++];         ve[cnt].push_back(v);         int u = link, la = -1;         while (u != -1) {           int z = *lower_bound(adj[v].begin(), adj[v].end(), u);           if (z != u) {             if (u == link) link = ne[link];             if (la != -1) ne[la] = ne[u];             a[r++] = u;           } else             la = u;           u = ne[u];         }       }       cnt++;     }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) {       printf( %d  , ve[i].size());       for (int u : ve[i]) printf( %d  , u);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long n, long long pos) { return (n & (1 << pos)); }   bool Set(long long n, long long pos) { return (n | (1 << pos)); }   long double LOG(long double b, long double e) { return log(b) / log(e); }   vector<int> v1[200005], v2[200005], comps[200005], vv;   vector<pair<int, int> > v;   int st[200005], en[200005], cnt = 1, level[200005], par[200005];   bitset<200005> b1, yes;   void solve() {     int n, a, b, cc;     cin >> n >> a >> b;     bool ok = 0;     cc = b * 10;     while (1) {       if (cc >= n) {         ok = 1;         break;       }       if (a) {         n /= 2;         n += 10;         --a;       }       if (cc >= n) {         ok = 1;         break;       }       if (a == 0) break;     }     ok ? cout <<  YES n  : cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int q;   vector<pair<int, int> > v;   vector<pair<int, int> > V;   vector<int> amount;   int root = 0;   int en = 100002 - 1;   struct MaximumFlow {     static const long long int InfCapacity = LLONG_MAX;     struct Edge {       int to;       long long int capacity;       int rev;     };     vector<vector<Edge> > g;     void init(int n) { g.assign(n, vector<Edge>()); }     void add(int i, int j, long long int capacity) {       Edge e, f;       e.to = j, f.to = i;       e.capacity = capacity, f.capacity = 0;       g[i].push_back(e);       g[j].push_back(f);       g[i].back().rev = (int)g[j].size() - 1;       g[j].back().rev = (int)g[i].size() - 1;     }     void addB(int i, int j, long long int capacity) {       Edge e, f;       e.to = j, f.to = i;       e.capacity = capacity, f.capacity = capacity;       g[i].push_back(e);       g[j].push_back(f);       g[i].back().rev = (int)g[j].size() - 1;       g[j].back().rev = (int)g[i].size() - 1;     }     long long int maximumFlow(int s, int t) {       int n = g.size();       vector<int> level(n);       long long int total = 0;       bool update;       do {         update = false;         fill(level.begin(), level.end(), -1);         level[s] = 0;         queue<int> q;         q.push(s);         for (int d = n; !q.empty() && level[q.front()] < d;) {           int u = q.front();           q.pop();           if (u == t) d = level[u];           for (auto e = g[u].begin(); e != g[u].end(); e++)             if (e->capacity > 0 && level[e->to] == -1)               q.push(e->to), level[e->to] = level[u] + 1;         }         vector<int> iter(n);         for (int i = 0; i < n; i++) iter[i] = (int)g[i].size() - 1;         while (1) {           long long int f = augment(level, iter, s, t, InfCapacity);           if (f == 0) break;           total += f;           update = true;         }       } while (update);       return total;     }     long long int augment(vector<int> &level, vector<int> &iter, int u, int t,                           long long int f) {       if (u == t || f == 0) return f;       int lv = level[u];       if (lv == -1) return 0;       level[u] = -1;       for (; iter[u] >= 0; --iter[u]) {         Edge &e = g[u][iter[u]];         if (level[e.to] <= lv) continue;         long long int l = augment(level, iter, e.to, t, min(f, e.capacity));         if (l == 0) continue;         e.capacity -= l;         g[e.to][e.rev].capacity += l;         level[u] = lv;         return l;       }       return 0;     }   };   MaximumFlow f;   void add_edge(int a, int b, int c) { f.add(a, b, c); }   int b;   int lab[10002];   int linkk[10002];   int main() {     cin >> n >> b >> q;     while (q--) {       int c, d;       scanf( %d%d , &c, &d);       v.push_back(make_pair(c, d));     }     v.push_back(make_pair(b, n));     sort(v.begin(), v.end());     int pr = 1;     int cnt = 0;     for (int i = 0; i < v.size(); i++) {       int res = v[i].second - cnt;       if (res < 0) {         puts( unfair );         return 0;       }       V.push_back(make_pair(pr, v[i].first));       amount.push_back(res);       cnt = v[i].second;       pr = v[i].first + 1;     }     int C = 11451;     for (int i = 0; i < V.size(); i++) {       linkk[i] = C;       C++;     }     f.init(100002);     for (int i = 0; i < 5; i++) {       add_edge(root, i + 1, n / 5);     }     for (int i = 1; i <= b; i++) {       lab[i] = 5 + i;       add_edge((i % 5) + 1, lab[i], 1);       add_edge(lab[i],                linkk[lower_bound(V.begin(), V.end(), make_pair(i, INT_MAX)) -                      V.begin() - 1],                1);     }     for (int i = 0; i < V.size(); i++) {       add_edge(linkk[i], en, amount[i]);     }     int ans = f.maximumFlow(root, en);     if (ans == n) {       puts( fair );     } else {       puts( unfair );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> visited;   vector<vector<int> > adj;   void dfs(int node, long long &s0, long long &s1, int mod) {     if (mod == 0)       s0++;     else       s1++;     visited[node] = true;     for (int i = 0; i < adj[node].size(); i++) {       if (!visited[adj[node][i]]) {         dfs(adj[node][i], s0, s1, (mod + 1) % 2);       }     }   }   int main() {     int t = 1;     while (t--) {       int n;       cin >> n;       adj = vector<vector<int> >(n + 1);       visited = vector<bool>(n + 1, false);       for (int i = 0; i < n - 1; i++) {         int a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       long long s0 = 0, s1 = 0;       dfs(1, s0, s1, 0);       cout << s0 * s1 - n + 1 <<   n ;     }     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,popcnt,tune=native )   using namespace std;   const int MN = 3333, inf = 1000000005, mod = 1000000007;   const long long INF = 1000000000000000005LL;   bitset<MN> Z[MN];   int dist[MN][MN], X[MN], Y[MN];   inline int d2(int a, int b) {     return (X[a] - X[b]) * (X[a] - X[b]) + (Y[a] - Y[b]) * (Y[a] - Y[b]);   }   int n;   bool dasie(int x) {     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) Z[i][j] = (i != j && dist[i][j] >= x);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         if (Z[i][j] == 0) continue;         if ((Z[i] & Z[j]).count()) return true;       }     return false;   }   int bs() {     int zd = 0, zg = 1e9 + 5;     while (zd != zg) {       int mid = (zd + zg + 1) >> 1;       if (dasie(mid))         zd = mid;       else         zg = mid - 1;     }     return zd;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &X[i], &Y[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) dist[i][j] = d2(i, j);     int ans = bs();     double odp = ans;     odp = sqrt(odp) / 2.0;     printf( %.9lf , odp);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, a = INT_MIN, b = INT_MIN;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) {       cin >> v[i];     }     if (n == 1) {       for (int i = 0; i < 3; i++) {         cout << 1 <<     << 1 <<   n ;         cout << (-1) * v[0] <<   n ;         v[0] = 0;       }       return 0;     }     cout << 1 <<     << n - 1 <<   n ;     for (int i = 0; i < n - 1; i++) {       if (v[i] < 0) {         int a = v[i] % (n - 1);         cout << (abs(v[i]) + a * (n)) <<    ;         v[i] = (a * (n));         continue;       }       cout << v[i] * (n - 1) <<    ;       v[i] = v[i] * (n);     }     cout <<   n ;     cout << n <<     << n <<   n ;     cout << (-1) * v[n - 1] <<   n ;     v[n - 1] = 0;     cout << 1 <<     << n <<   n ;     for (int i = 0; i < n; i++) {       cout << (-1) * v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   string to_string(pair<T1, T2> p);   template <typename T1, typename T2, typename T3>   string to_string(tuple<T1, T2, T3> tup);   template <typename T1, typename T2, typename T3, typename T4>   string to_string(tuple<T1, T2, T3, T4> tup);   string to_string(const string& v) { return  {  + v +  } ; }   string to_string(const char* v) { return to_string((string)v); }   string to_string(const bool& v) { return (v ?  True  :  False ); }   string to_string(vector<bool> v) {     string ret =  [ ;     int n = (int)v.size();     for (int i = 0; i < n - 1; i++) {       ret +=  [  + to_string(i) +  ](  + to_string(v[i]) +  ),  ;     }     ret +=  [  + to_string(n - 1) +  ](  + to_string(v[n - 1]) +  )] ;     return ret;   }   template <size_t N>   string to_string(bitset<N> b) {     string ret =   ;     for (int i = 0; i < N; i++) {       ret += (char)(b[i] +  0 );     }     return ret;   }   template <typename T>   string to_string(T v) {     bool ok = true;     string ret =  [ ;     int cnt = 0;     for (auto x : v) {       if (!ok) {         ret +=  ,  ;       }       ok = false;       ret +=  [  + to_string(cnt++) +  ](  + to_string(x) +  ) ;     }     return ret +  ] ;   }   template <typename T1, typename T2>   string to_string(pair<T1, T2> p) {     return  {  + to_string(p.first) +  ,   + to_string(p.second) +  } ;   }   template <typename T1, typename T2, typename T3>   string to_string(tuple<T1, T2, T3> tup) {     return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   +            to_string(get<2>(tup)) +  } ;   }   template <typename T1, typename T2, typename T3, typename T4>   string to_string(tuple<T1, T2, T3, T4> tup) {     return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   +            to_string(get<2>(tup)) +  ,   + to_string(get<3>(tup)) +  } ;   }   void DEBUG() { cerr <<   n ; }   template <typename start, typename... end>   void DEBUG(start first, end... other) {     cerr <<   |   << to_string(first);     DEBUG(other...);   }   void solve() {     int n, k;     cin >> n >> k;     if (n / 2 > k || (n == 1 && k != 0)) {       cout << -1;       return;     }     if (n == 1 && k == 0) {       cout << 1;       return;     }     int x = k - n / 2 + 1;     cout << x <<     << 2 * x <<    ;     for (long long i = 0; i < n - 2; i++) cout << 2 * x + 1 + i <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return a > val ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int MAXN = 654321;   const int NOTFOUND = -1;   struct HashMap {     int cur, head[MAXN], next[MAXN];     long long l[MAXN];     int x[MAXN];     HashMap() {       cur = 0;       fill_n(head, MAXN, 0);       fill_n(next, MAXN, 0);     }     int find(long long key) {       for (int i = head[key % MAXN]; i; i = next[i]) {         if (l[i] == key) {           return x[i];         }       }       return NOTFOUND;     }     void insert(long long key, int val) {       if (find(key) != NOTFOUND) return;       l[++cur] = key;       x[cur] = val;       next[cur] = head[key % MAXN];       head[key % MAXN] = cur;     }   } hs;   const int maxn = 1000 + 10;   const int maxd = 7000 + 10;   int n;   long long k;   long long a[maxn];   vector<long long> dvs;   pair<int, long long> f[maxn][maxd];   int r[maxn][maxd];   void solve() {     cin >> n >> k;     for (int i = 1; (long long)i * i <= k; i++) {       if (k % i == 0) {         dvs.push_back(i);         if (i < k / i) {           dvs.push_back(k / i);         }       }     }     sort((dvs).begin(), (dvs).end());     for (int i = (0); i < (int((dvs).size())); i++) {       hs.insert(dvs[i], i);     }     for (int i = (0); i < (n); i++) cin >> a[i];     if (k == 1) {       cout << 1 <<   n ;       int best = 0;       for (int i = (1); i < (n); i++)         if (a[best] > a[i]) best = i;       cout << best + 1 <<   n ;       return;     }     for (int i = (0); i < (n + 1); i++)       for (int j = (1); j < (int((dvs).size())); j++) f[i][j] = make_pair(INF, 0);     for (int pos = (n)-1; pos >= (0); pos--)       for (int i = (1); i < (int((dvs).size())); i++) {         f[pos][i] = f[pos + 1][i];         int nxt = hs.find(dvs[i] / gcd(dvs[i], a[pos]));         if (chkmin(f[pos][i], make_pair(f[pos + 1][nxt].first + 1,                                         f[pos + 1][nxt].second + a[pos]))) {           r[pos][i] = 1;         }       }     int ans = f[0][int((dvs).size()) - 1].first;     if (ans > n) {       cout << -1 <<   n ;       return;     }     cout << ans <<   n ;     int cur = 0;     k = int((dvs).size()) - 1;     while (cur < n) {       if (r[cur][k]) {         cout << cur + 1 <<    ;         k = hs.find(dvs[k] / gcd(dvs[k], a[cur]));       }       cur++;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     vector<vector<int> > gr(n + 1, a);     int any;     int th;     for (int i = 1; i <= n; i++) {       cin >> th;       if (th != 0) {         gr[i].push_back(th);         gr[th].push_back(i);       }     }     vector<int> chet(n + 1, 0);     for (int i = 1; i <= n; i++) {       if (gr[i].size() % 2 == 0) {         chet[i] = 1;         any = i;       }     }     if (n % 2 == 0) {       cout <<  NO ;     } else {       cout <<  YES n ;       queue<int> q;       q.push(any);       vector<int> dist(n + 1, 0);       vector<int> bfu(n + 1, 0);       vector<int> pred(n + 1, 0);       vector<vector<int> > next(n + 1, a);       bfu[any] = 1;       pred[any] = -1;       while (q.size() != 0) {         int v = q.front();         q.pop();         for (int i = 0; i < gr[v].size(); i++) {           if (bfu[gr[v][i]] == 0) {             pred[gr[v][i]] = v;             q.push(gr[v][i]);             bfu[gr[v][i]] = 1;             next[v].push_back(gr[v][i]);             dist[gr[v][i]] = dist[v] + 1;           }         }       }       vector<int> ans;       int maxd = dist[max_element(dist.begin(), dist.end()) - dist.begin()];       vector<int> ansu(n + 1, 0);       set<int> sss;       vector<set<int> > ch(maxd + 1, sss);       for (int i = 1; i <= n; i++) {         if (chet[i] == 1) {           ch[dist[i]].insert(i);         }       }       for (int i = ch.size() - 1; i >= 0; i--) {         for (auto j : ch[i]) {           queue<int> qq;           qq.push(j);           if (i != 0) {             if (ch[i - 1].find(pred[j]) != ch[i - 1].end()) {               ch[i - 1].erase(pred[j]);             } else {               ch[i - 1].insert(pred[j]);             }           }           while (qq.size() != 0) {             int v = qq.front();             qq.pop();             if (ansu[v] == 0) {               cout << v <<   n ;               ansu[v] = 1;               for (int jj = 0; jj < next[v].size(); jj++) {                 qq.push(next[v][jj]);               }             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> ans;   map<string, int> lo;   string s[100], V[55];   long long int n, m, k, done[100], fyes = -1;   void give() {     string T =  abcdef ;     do {       ans.push_back(T);     } while (next_permutation(T.begin(), T.end()));     for (int i = 0; i < ans.size(); i++) lo[ans[i]] = i;   }   int main() {     give();     cin >> n >> k;     for (int i = 0; i < (n - k + 1); i++) {       cin >> s[i];       if (s[i] ==  YES  && fyes == -1) fyes = i;     }     if (fyes != -1) {       for (int i = fyes, j = 0; j < k; i++, j++) V[i] = ans[j];       for (int i = fyes + 1; i < n - k + 1; i++) {         if (s[i] ==  YES ) {           V[i + k - 1] = ans[lo[V[i]] + k - 1];         } else {           V[i + k - 1] = V[i];         }       }       for (int i = 0; i < fyes; i++) V[i] = V[fyes];     } else {       for (int i = 0; i < n; i++) V[i] =  fuchka ;     }     for (int i = 0; i < n; i++) {       V[i][0] = V[i][0] +  A  -  a ;       cout << V[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[1 << 23];   vector<pair<int, int> > p[23];   int a[100];   int main() {     int n, res = 1000;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; j < i; j++)         for (int k = j; k < i; k++)           if (a[j] + a[k] == a[i]) p[i].push_back(make_pair(j, k));     }     memset(dp, 125, sizeof(dp));     dp[1] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j < (1 << (i - 1)); j++) {         int jj = j | (1 << (i - 1));         for (int k = 0; k < p[i].size(); k++) {           int a = p[i][k].first, b = p[i][k].second;           if (!(jj & (1 << a)) || !(jj & (1 << b))) continue;           int msk = jj | (1 << i);           dp[msk] = min(dp[msk], dp[jj] + 1);           for (int del = 0; del < i; del++)             if (msk & (1 << del))               dp[msk ^ (1 << del)] = min(dp[msk ^ (1 << del)], dp[jj]);         }       }     }     for (int i = 0; i < 1 << n; i++)       if ((i & (1 << (n - 1)))) res = min(res, dp[i]);     cout << (res == 1000 ? -1 : res) << endl;     return 0;   }