#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 10;   int n, d[N], par[N];   pair<int, int> tr[N * 4];   pair<long long, int> a[N], b[N];   void add(int val, int p, int b = 0, int e = n, int ind = 1) {     tr[ind] = max(tr[ind], make_pair(val, p));     if (b + 1 == e) return;     int mid = (b + e) / 2;     if (p < mid)       add(val, p, b, mid, ind * 2);     else       add(val, p, mid, e, ind * 2 + 1);     return;   }   pair<int, int> get(int l, int r, int b = 0, int e = n, int ind = 1) {     if (l <= b && e <= r) return tr[ind];     int mid = (b + e) / 2;     pair<int, int> ret = make_pair(0, 0);     if (l < mid) ret = get(l, r, b, mid, ind * 2);     if (r > mid) ret = max(get(l, r, mid, e, ind * 2 + 1), ret);     return ret;   }   void pp(int v) {     if (d[v] == 1) {       cout << v + 1 <<    ;       return;     }     pp(par[v]);     cout << v + 1 <<    ;     return;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       b[i].first = a[i].first;       b[i].second = i;     }     sort(b, b + n);     for (int i = 0; i < n; i++) a[b[i].second].second = i;     d[0] = 1;     add(1, a[0].second);     for (int i = 1; i < n; i++) {       int l = upper_bound(b, b + n, make_pair(a[i].first - k, n)) - b;       int r = lower_bound(b, b + n, make_pair(a[i].first + k, 0)) - b;       if (l) {         pair<int, int> temp = get(0, l);         d[i] = temp.first + 1;         par[i] = b[temp.second].second;       }       if (r < n) {         pair<int, int> temp = get(r, n);         if (temp.first >= d[i]) {           d[i] = temp.first + 1;           par[i] = b[temp.second].second;         }       }       add(d[i], a[i].second);     }     long long maxx = 0, maxind;     for (int i = 0; i < n; i++) {       if (d[i] > maxx) {         maxx = d[i];         maxind = i;       }     }     cout << maxx << endl;     pp(maxind);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:267386880 )   using namespace std;   int n;   char g[72][72];   struct pos {     int data[3];   };   const int MAXQ = 400000;   bool used[72][72][72];   pos prv[72][72][72];   pos q[MAXQ];   int head, tail;   pair<int, int> getDiff(pos &a, pos &b) {     int diffA(-1);     for (int i(0); i <= ((long long)(3) - 1); ++i) {       bool ok(true);       for (int j(0); j <= ((long long)(3) - 1); ++j)         if (b.data[j] == a.data[i]) ok = false;       if (ok) {         diffA = a.data[i];         break;       }     }     int sm1(accumulate(a.data, a.data + 3, 0));     int sm2(accumulate(b.data, b.data + 3, 0));     int diffB = -(sm1 - sm2 - diffA);     return make_pair(diffA, diffB);   }   void printAns() {     pos tmp = {{0, 1, 2}};     pos &now = tmp;     pos &from = prv[0][1][2];     vector<pair<int, int> > ans;     while (from.data[0] != -1) {       pair<int, int> rs(getDiff(from, now));       ans.push_back(rs);       now = from;       from = prv[now.data[0]][now.data[1]][now.data[2]];     }     reverse((ans).begin(), (ans).end());     printf( %d n , ((int)ans.size()));     for (int i(0); i <= ((long long)(((int)ans.size())) - 1); ++i)       printf( %d %d n , ans[i].first + 1, ans[i].second + 1);     exit(0);   }   void addPos(int a, int b, int c, pos from) {     pos p = {{a, b, c}};     sort(p.data, p.data + 3);     if (used[p.data[0]][p.data[1]][p.data[2]]) return;     used[p.data[0]][p.data[1]][p.data[2]] = true;     prv[p.data[0]][p.data[1]][p.data[2]] = from;     q[tail++] = p;     if (tail == MAXQ) tail = 0;     if (p.data[0] == 0 && p.data[1] == 1 && p.data[2] == 2) printAns();   }   bool can(int from, int to, int a, int b) { return g[a][b] == g[from][to]; }   void process() {     pos &cur = q[head++];     if (head == MAXQ) head = 0;     for (int i(0); i <= ((long long)(3) - 1); ++i) {       int from(cur.data[i]);       int a(cur.data[(i + 1) % 3]), b(cur.data[(i + 2) % 3]);       for (int to(0); to <= ((long long)(n)-1); ++to) {         if (to == a || to == b || to == from) continue;         if (can(from, to, a, b)) addPos(to, a, b, cur);       }     }   }   void solve() {     scanf( %d , &n);     int a, b, c;     scanf( %d%d%d n , &a, &b, &c);     for (int i(0); i <= ((long long)(n)-1); ++i) gets(g[i]);     pos fict = {{-1, -1, -1}};     addPos(--a, --b, --c, fict);     while (head != tail) process();     printf( -1 n );   }   void bruteforce() {}   int main() {     solve();     bruteforce();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, q;       cin >> n >> q;       string s;       cin >> s;       int pref[n + 1];       memset(pref, 0, sizeof(pref));       set<int> arr[2 * n + 5];       for (int i = 0; i < 2 * n + 5; i++) {         set<int> ss;         arr[i] = ss;       }       for (int i = 1; i <= n; i++) {         if (s[i - 1] ==  + ) {           if (i % 2 == 1) {             pref[i] = pref[i - 1] + 1;           } else {             pref[i] = pref[i - 1] - 1;           }         } else {           if (i % 2 == 1) {             pref[i] = pref[i - 1] - 1;           } else {             pref[i] = pref[i - 1] + 1;           }         }         arr[pref[i] + n].insert(i);       }       for (int i = 0; i < q; i++) {         int l, r;         cin >> l >> r;         int val = pref[r] - pref[l - 1];         if (val == 0) {           cout << 0 << endl;         } else {           if (abs(val) % 2 == 1) {             if (val < 0) {               val--;             } else {               val++;             }             int half = pref[l - 1] + val / 2;             half += n;             auto it = arr[half].lower_bound(l);             int res = *it;             cout << 1 << endl;             cout << res << endl;           } else {             int diff = pref[r] - pref[r - 1];             val -= diff;             if (val < 0) {               val--;             } else {               val++;             }             int half = pref[l - 1] + val / 2;             half += n;             auto it = arr[half].lower_bound(l);             int res = *it;             cout << 2 << endl;             cout << res <<     << r << endl;           }         }       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int Max = 1e6 + 5;   int lst[Max];   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long sum = 0;       while (n > 0) {         if (n % k == 0) {           n /= k;           sum++;         } else {           sum += n % k;           n -= n % k;         }       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split_string(string);   bool isDiverse(string &s) {     int len = s.length();     sort(s.begin(), s.end());     for (int i = 0; i < len - 1; i++) {       if (s[i] == s[i + 1]) {         return false;       } else if (s[i + 1] != s[i] + 1) {         return false;       }     }     return true;   }   int main() {     ios::sync_with_stdio(false);     int N;     string s;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> s;       if (isDiverse(s)) {         cout <<  Yes n ;       } else {         cout <<  No n ;       }     }   }   vector<string> split_string(string input_string) {     vector<string> splits;     stringstream ss(input_string);     string item;     while (getline(ss, item,    )) {       splits.push_back(item);     }     return splits;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 405;   const int oo = 10005;   int N, M, T, K, Q;   vector<pair<int, int> > G[MAXN];   int dp[MAXN][MAXN][MAXN];   int par[MAXN];   int indPar[MAXN];   void DFS(int u, int p) {     par[u] = p;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i].first;       if (v != p) {         indPar[v] = G[u][i].second;         DFS(v, u);       }     }     return;   }   int solve(int i, int cnt, int curK) {     if (curK == 0) return 0;     if (G[i].size() == 1 && i != 1) return (curK == 1) ? 0 : oo;     if (cnt >= G[i].size()) return (curK == 1) ? 0 : oo;     if (dp[i][cnt][curK] != -1) return dp[i][cnt][curK];     int res = oo;     int v = G[i][cnt].first;     if (v == par[i]) return dp[i][cnt][curK] = solve(i, cnt + 1, curK);     res = min(res, solve(i, cnt + 1, curK) + 1);     for (int k = 1; k < curK; k++)       res = min(res, solve(v, 0, k) + solve(i, cnt + 1, curK - k));     return dp[i][cnt][curK] = res;   }   void TRACE(int i, int cnt, int curK) {     if (curK == 0) return;     if (G[i].size() == 1 && i != 1) return;     if (cnt >= G[i].size()) return;     int res = solve(i, cnt, curK);     int v = G[i][cnt].first;     if (v == par[i]) {       TRACE(i, cnt + 1, curK);       return;     }     if (res == solve(i, cnt + 1, curK) + 1) {       cout << G[i][cnt].second <<    ;       TRACE(i, cnt + 1, curK);       return;     }     for (int k = 1; k < curK; k++)       if (res == solve(v, 0, k) + solve(i, cnt + 1, curK - k)) {         TRACE(v, 0, k);         TRACE(i, cnt + 1, curK - k);         return;       }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( 440D                 .inp ,                r )) {       freopen(            440D             .inp ,            r , stdin);       freopen(            440D             .out ,            w , stdout);     }     cin >> N >> K;     int u, v;     for (int i = 1; i <= N - 1; i++) {       cin >> u >> v;       G[u].push_back({v, i});       G[v].push_back({u, i});     }     DFS(1, 0);     memset(dp, -1, sizeof(dp));     int ANS = solve(1, 0, K);     int Root = 1;     for (int i = 2; i <= N; i++) {       if (ANS > solve(i, 0, K) + 1) {         ANS = solve(i, 0, K) + 1;         Root = i;       }     }     if (Root == 1) {       cout << solve(1, 0, K) <<   n ;       TRACE(1, 0, K);       return 0;     }     cout << solve(Root, 0, K) + 1 <<   n ;     cout << indPar[Root] <<   n ;     TRACE(Root, 0, K);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n;     string s = to_string(n);     k = s.size() - 1;     if (k > 0) {       long long a = rint(pow(10, k));       long long z = rint(n / a);       long long m = (z + 1) * a;       cout << m - n;     } else       cout << 1;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   ll gcd(ll a, ll b){    return b?gcd(b,a%b):a;   }   ll a[200005],b[200005],c,d;   int main(){    ll n,m;    scanf( %lld%lld ,&n,&m);    ll d=0;    cin>>a[1];    for(ll i=2;i<=n;i++){      //从a[2]-a[1]开始      scanf( %lld ,&a[i]);     d=gcd(d,a[i]-a[i-1]);  //gcd(0,a)=a    }    for(ll i=1;i<=m;i++){     scanf( %lld ,&b[i]);     ll dd=abs(gcd(d,a[1]+b[i]));     printf( %lld  ,dd);    }    return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   const int maxn = 30010;   int a[maxn] = {};   int used[maxn] = {};   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     vector<int> ans1, ans2;     if (n == 2) {       ans1.push_back(a[0]);       ans2.push_back(a[1]);       goto ooo;     }     if (n == 3) {       ans1.push_back(a[0]);       ans1.push_back(a[1]);       ans2.push_back(a[2]);       goto ooo;     }     if (n == 4) {       ans1.push_back(a[0]);       ans1.push_back(a[1]);       ans2.push_back(a[2]);       ans2.push_back(a[3]);       goto ooo;     }     for (int i = 0; i < 5; ++i)       for (int j = i + 1; j < 5; ++j)         for (int k = j + 1; k < 5; ++k) {           if (a[j] - a[i] == a[k] - a[j]) {             memset(used, 0, sizeof(used));             used[i] = 1;             used[j] = 1;             used[k] = 1;             int d = a[j] - a[i];             int cur = a[k] + d;             int cused = 3;             int lused = k;             for (int t = k + 1; t < n; ++t) {               if (a[t] == cur) {                 used[t] = 1;                 lused = t;                 cused++;                 cur += d;               }             }             int pppp = 2;             while (pppp--) {               if (pppp == 0) used[lused] = 0;               bool ok = true;               int p1 = -1;               int p2 = -1;               int curd = 0;               for (int t = 0; t < n; ++t) {                 if (used[t]) continue;                 int ccc = a[i];                 if (curd == 0) {                   if (p2 == -1) {                     p2 = p1;                     p1 = t;                     if (p2 != -1) {                       curd = a[p1] - a[p2];                     }                   }                 } else {                   if (a[t] - a[p1] != curd) {                     ok = false;                     break;                   } else {                     p1 = t;                   }                 }               }               if (ok) {                 if (cused == n) used[0] = 0;                 for (int t = 0; t < n; ++t) {                   if (used[t])                     ans1.push_back(a[t]);                   else                     ans2.push_back(a[t]);                 }                 goto ooo;               }             }           }         }     printf( No solution );     return 0;   ooo:     for (int i = 0; i < ans1.size(); ++i) printf( %d  , ans1[i]);     printf(  n );     for (int i = 0; i < ans2.size(); ++i) printf( %d  , ans2[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( O2 )   constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};   constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   constexpr long long INF = 1999999999999999997;   constexpr int inf = INT_MAX;   constexpr int MAXSIZE = int(1e6) + 5;   constexpr auto PI = 3.14159265358979323846L;   constexpr auto oo = numeric_limits<int>::max() / 2 - 2;   constexpr auto eps = 1e-6;   constexpr auto mod = 1000000007;   constexpr auto MOD = 1000000007;   constexpr auto MOD9 = 1000000009;   constexpr auto maxn = 100006;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int n, m, k;   int fre;   char a[502][502];   int x = -1, y = -1;   bool visited[502][502];   int l;   void dfs(int x, int y) {     if (l == 0) return;     if (x + 1 < n && a[x + 1][y] ==  .  && !visited[x + 1][y] && l > 0) {       visited[x + 1][y] = 1;       l--;       dfs(x + 1, y);     }     if (l == 0) return;     if (y + 1 < m && a[x][y + 1] ==  .  && !visited[x][y + 1] && l > 0) {       visited[x][y + 1] = 1;       l--;       dfs(x, y + 1);     }     if (l == 0) return;     if (x - 1 >= 0 && a[x - 1][y] ==  .  && !visited[x - 1][y] && l > 0) {       visited[x - 1][y] = 1;       l--;       dfs(x - 1, y);     }     if (l == 0) return;     if (y - 1 < n && a[x][y - 1] ==  .  && !visited[x][y - 1] && l > 0) {       visited[x][y - 1] = 1;       l--;       dfs(x, y - 1);     }     if (l == 0) return;   }   int main() {     fastio();     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  . ) {           fre++;           if (x == -1) {             x = i, y = j;           }         }       }     }     l = fre - k;     int c = k;     dfs(x, y);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  .  && !visited[i][j] && c > 0) {           a[i][j] =  X ;           c--;         }         cout << a[i][j];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>      #define fi first   #define se second   #define db double   #define U unsigned   #define P std::pair<int,int>   #define LL long long   #define pb push_back   #define MP std::make_pair   #define all(x) x.begin(),x.end()   #define CLR(i,a) memset(i,a,sizeof(i))   #define FOR(i,a,b) for(int i = a;i <= b;++i)   #define ROF(i,a,b) for(int i = a;i >= b;--i)   #define DEBUG(x) std::cerr << #x <<  =  << x << std::endl      const int MAXN = 500+5;   int n,k;   int mn[26];   std::string f[MAXN],str;      inline std::string ctos(char x){       return std::string(1,x);   }      inline void Solve(){       std::cin >> n >> k >> str;str =  0 +str;       mn[0] = 0;FOR(i,1,k-2) mn[i] = i-1;mn[k-1] = 0;       f[0].clear();FOR(i,1,n) f[i] =  { ;       FOR(i,0,n-1){           f[i+1] = std::min(f[i+1],f[i]+ctos( a +mn[str[i+1]- a ]));           if(i) f[i+1] = std::min(f[i+1],f[i].substr(0,i-1)+ctos(str[i+1])+f[i].back());           if(i != n-1) f[i+2] = std::min(f[i+2],f[i]+ctos( a +mn[str[i+2]- a ])+ctos(str[i+1]));           if(i && i != n-1) f[i+2] = std::min(f[i+2],f[i].substr(0,i-1)+ctos(str[i+2])+f[i].back()+ctos(str[i+1]));       }       std::cout << f[n] << std::endl;   }      int main(){       std::ios::sync_with_stdio(false);       int T;std::cin >> T;       while(T--) Solve();       return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   using namespace std;   template <typename T>   inline void Cin(T& first) {     char c;     T sign = 1;     first = 0;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ;     first *= sign;   }   template <typename T>   inline void Out(T first) {     if (first > 9) Out(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void Cout(T first, char c) {     if (first < 0) putchar( - );     first = abs(first);     Out(first);     putchar(c);   }   template <typename T, typename... Args>   inline void Cin(T& a, Args&... args) {     Cin(a);     Cin(args...);   }   template <typename T, typename... Args>   inline void Cout(T a, char c, Args... args) {     Cout(a, c);     Cout(args...);   }   const int mod = int(1e9) + 7;   const int N = 2050;   int f[N][N], a[N], n, k, nState;   void Enter() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];   }   void add(int& first, int second) {     if ((first += second) >= mod) first -= mod;   }   void Solve() {     nState = 1 << k, f[0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int bit = 0; bit <= nState; ++bit) {         if (!f[i - 1][bit]) continue;         if (a[i] == 2 || a[i] == 0) {           if (bit + 2 >= nState)             add(f[i][nState], f[i - 1][bit]);           else             add(f[i][bit + 2], f[i - 1][bit]);         }         if (a[i] == 4 || a[i] == 0) {           if ((bit >> 1) & 1)             add(f[i][4], f[i - 1][bit]);           else {             if (bit + 4 >= nState)               add(f[i][nState], f[i - 1][bit]);             else               add(f[i][bit + 4], f[i - 1][bit]);           }         }       }     }     cout << f[n][nState];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( test                 .inp ,                r )) {       freopen(            test             .inp ,            r , stdin);       freopen(            test             .out ,            w , stdout);     }     Enter(), Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   int a[32][101111], n, m, d[32][111111], b[111111], t[400111];   pair<pair<int, int>, int> p[111111];   int bit(int mask, int i) { return (mask & (1 << i)) > 0; }   void build(int v, int tl, int tr) {     if (tl == tr)       t[v] = b[tl];     else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       t[v] = (t[v * 2] & t[v * 2 + 1]);     }   }   int get(int v, int tl, int tr, int l, int r) {     if (l > r) return (1 << 30) - 1;     if (l == tl && r == tr) return t[v];     int tm = (tl + tr) / 2;     return get(v * 2, tl, tm, l, min(r, tm)) &            get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);   }   int main() {     scanf( %d%d , &n, &m);     int len = (int)sqrt(n + .0) + 1;     for (int cs = 0; cs < m; ++cs) {       int l, r, q;       scanf( %d%d%d , &l, &r, &q);       p[cs] = make_pair(make_pair(l, r), q);       for (int j = 0; j < 30; ++j) {         int w = bit(q, j);         if (w == 0) continue;         a[j][l]++;         a[j][r + 1]--;       }     }     for (int i = 0; i < 30; ++i) {       int second = 0;       for (int j = 1; j <= n; ++j) {         second += a[i][j];         a[i][j] = a[i][j - 1] + second;       }     }     for (int i = 1; i <= n; ++i) {       int ans = 0;       for (int j = 0; j < 30; ++j) ans += (1 << j) * (a[j][i] - a[j][i - 1] > 0);       b[i] = ans;     }     build(1, 1, n);     for (int i = 0; i < m; ++i) {       int l = p[i].first.first, r = p[i].first.second, q = p[i].second;       if (get(1, 1, n, l, r) != q) {         puts( NO );         return 0;       }     }     puts( YES );     for (int i = 1; i <= n; ++i) printf( %d  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   map<int, int> memo;   int solve(int mask) {     if (!mask) return 0;     if (memo.find(mask) != memo.end()) return memo[mask];     map<int, bool> canreach;     for (int i = 0; i < 32; i++) {       int aux = ((1 << i) - 1) & mask;       int ns = aux | ((mask - aux) >> (i + 1));       if (ns == mask) continue;       canreach[solve(ns)] = true;     }     int mex = 0;     for (int i = 0; i < 100; i++)       if (!canreach[i]) {         mex = i;         break;       }     return memo[mask] = mex;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> mps;     for (int j = 0; j < n; j++) {       int val, aux;       cin >> val;       aux = val;       for (int i = 2; i * i <= val; i++) {         int cnt = 0;         while (aux % i == 0) {           aux /= i;           cnt++;         }         if (cnt) mps[i] |= (1 << (cnt - 1));       }       if (aux != 1) mps[aux] |= 1;     }     int grundy = 0;     for (auto u : mps) grundy ^= solve(u.second);     cout << (grundy ?  Mojtaba  :  Arpa ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   int a[1000005];   vector<int> x;   void solve() {     int sum = 0, ans;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     int l = 1, r = 1e7;     while (l <= r) {       int mid = (l + r) >> 1;       if (mid * n >= sum) {         r = mid - 1;         ans = mid;       } else {         l = mid + 1;       }     }     x.push_back(ans);   }   int main() {     cin >> t;     while (t--) solve();     for (int i = 0; i < x.size(); i++) {       cout << x[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) {       long long a, b, n;       cin >> a >> b >> n;       if (a < b) swap(a, b);       int ans = 0;       while (a <= n) {         b += a;         if (a < b) swap(a, b);         ans++;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, jump[100005];     bool visited[100005];     string s;     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) cin >> jump[i];     int pos = 0;     fill(visited, visited + n, false);     while (!visited[pos]) {       visited[pos] = true;       if (s[pos] ==  > )         pos += jump[pos];       else if (s[pos] ==  < )         pos -= jump[pos];       if (pos < 0 || pos >= n) {         cout <<  FINITE  << endl;         return 0;       }     }     cout <<  INFINITE  << endl;   }


#include <bits/stdc++.h>   using namespace std;   double PI = 3.141592653589793238462643383279;   const double EPS = 1e-9;   const long long MOD = 1000000007;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   namespace LCA {   vector<vector<int>> G;   int root;   int MAX_LOG_N;   vector<vector<int>> parent;   vector<int> depth;   void dfs(int v, int p, int d) {     parent[0][v] = p;     depth[v] = d;     for (int i = 0; i < (int)G[v].size(); i++) {       if (G[v][i] != p) dfs(G[v][i], v, d + 1);     }   }   void init(int V, vector<vector<int>> _G, int root) {     {       int tmp = 1;       MAX_LOG_N = 1;       while (tmp <= V) {         tmp *= 2;         MAX_LOG_N++;       }     }     parent.resize(MAX_LOG_N, vector<int>(V));     depth.resize(V);     G = _G;     dfs(root, -1, 0);     for (int k = 0; k + 1 < MAX_LOG_N; k++) {       for (int v = 0; v < V; v++) {         if (parent[k][v] < 0)           parent[k + 1][v] = -1;         else           parent[k + 1][v] = parent[k][parent[k][v]];       }     }   }   int get_kth_parent(int v, int k) {     for (int i = MAX_LOG_N - 1; i >= 0; i--) {       if ((1 << i) > k) continue;       v = parent[i][v];       k -= (1 << i);     }     return v;   }   int lca(int u, int v) {     if (depth[u] > depth[v]) swap(u, v);     for (int k = 0; k < MAX_LOG_N; k++) {       if ((depth[v] - depth[u]) >> k & 1) {         v = parent[k][v];       }     }     if (u == v) return u;     for (int k = MAX_LOG_N - 1; k >= 0; k--) {       if (parent[k][u] != parent[k][v]) {         u = parent[k][u];         v = parent[k][v];       }     }     return parent[0][u];   }   }  // namespace LCA   int n;   vector<vector<int>> e;   vector<pair<int, int>> e2[200000];   int ord[200000];   int v[200000], s[200000], u[200000];   int rv[200000], ru[200000];   long long dist[200000];   int infe[200000];   void dfs(int v, int p, int& pos) {     ord[v] = pos++;     for (int to : e[v]) {       if (to == p) continue;       dfs(to, v, pos);     }   }   int main() {     scanf( %d , &n);     e.resize(n);     for (int i = 0; i < (int)n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       e[x].push_back(y);       e[y].push_back(x);     }     int tmp = 0;     dfs(0, -1, tmp);     LCA::init(n, e, 0);     int q;     scanf( %d , &q);     memset(rv, -1, sizeof(rv));     memset(ru, -1, sizeof(ru));     for (int i = 0; i < (int)q; i++) {       int k, m;       scanf( %d%d , &k, &m);       vector<int> vers(k + m);       for (int j = 0; j < (int)k; j++) {         scanf( %d%d , v + j, s + j);         v[j]--;         vers[j] = v[j];         rv[v[j]] = j;       }       for (int j = 0; j < (int)m; j++) {         scanf( %d , u + j);         u[j]--;         vers[j + k] = u[j];         ru[u[j]] = j;       }       sort(vers.begin(), vers.end(),            [&](const int& l, const int& r) { return ord[l] < ord[r]; });       for (int j = 1; j < k + m; j++) {         int com = LCA::lca(vers[j - 1], vers[j]);         vers.push_back(com);       }       sort(vers.begin(), vers.end());       vers.erase(unique(vers.begin(), vers.end()), vers.end());       int N = vers.size();       sort(vers.begin(), vers.end(),            [&](const int& l, const int& r) { return ord[l] < ord[r]; });       vector<int> sta;       sta.push_back(vers[0]);       for (int j = 1; j < N; j++) {         while (true) {           if (LCA::lca(sta.back(), vers[j]) == sta.back()) break;           sta.pop_back();         }         e2[sta.back()].push_back(pair<int, int>(             vers[j], LCA::depth[vers[j]] - LCA::depth[sta.back()]));         e2[vers[j]].push_back(pair<int, int>(             sta.back(), LCA::depth[vers[j]] - LCA::depth[sta.back()]));         sta.push_back(vers[j]);       }       priority_queue<pair<pair<long long, long long>, int>,                      vector<pair<pair<long long, long long>, int>>,                      greater<pair<pair<long long, long long>, int>>>           que;       for (int ve : vers) {         dist[ve] = linf;         infe[ve] = -1;         if (rv[ve] != -1) {           dist[ve] = 0;           infe[ve] = rv[ve];           que.push(pair<pair<long long, long long>, int>(               pair<long long, long long>(                   (dist[ve] + s[infe[ve]] - 1) / s[infe[ve]], infe[ve]),               ve));         }       }       while (!que.empty()) {         pair<pair<long long, long long>, int> q = que.top();         que.pop();         for (pair<int, int> E : e2[q.second]) {           int to = E.first, cost = E.second;           if (infe[to] == -1) {             dist[to] = dist[q.second] + cost;             infe[to] = infe[q.second];             que.push(pair<pair<long long, long long>, int>(                 pair<long long, long long>(                     (dist[to] + s[infe[to]] - 1) / s[infe[to]], infe[to]),                 to));             continue;           }           long long ti = (dist[to] + s[infe[to]] - 1) / s[infe[to]];           if (pair<long long, long long>(ti, infe[to]) >               pair<long long, long long>(                   (dist[q.second] + cost + s[infe[q.second]] - 1) /                       s[infe[q.second]],                   infe[q.second])) {             dist[to] = dist[q.second] + cost;             infe[to] = infe[q.second];             que.push(pair<pair<long long, long long>, int>(                 pair<long long, long long>(                     (dist[to] + s[infe[to]] - 1) / s[infe[to]], infe[to]),                 to));           }         }       }       vector<int> out(m);       for (int ve : vers) {         if (ru[ve] == -1) continue;         out[ru[ve]] = infe[ve] + 1;       }       for (int o : out) printf( %d  , o);       puts(  );       for (int ve : vers) e2[ve].clear();       for (int j = 0; j < (int)k; j++) {         rv[v[j]] = -1;       }       for (int j = 0; j < (int)m; j++) {         ru[u[j]] = -1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int h, q, v, e;   string s;   map<int, int> xx;   inline double dfs(int x, int mx) {     if (xx[x] <= mx) return mx;     return 0.5 * (dfs(x << 1, max(mx, xx[x] - xx[x << 1])) +                   dfs(x << 1 | 1, max(mx, xx[x] - xx[x << 1 | 1])));   }   int main() {     scanf( %d%d , &h, &q);     while (q--) {       cin >> s;       if (s[0] ==  a ) {         scanf( %d%d , &v, &e);         while (v) xx[v] += e, v >>= 1;       } else         printf( %.8lf n , dfs(1, 0));     }   }


#include <bits/stdc++.h>   using namespace std;   int a[200000];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int odd = 0, even = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] & 1)           odd++;         else           even++;       }       if (odd == 0 or (even == 0 and n % 2 == 0)) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, m, a, b, s = 0, e1, e2, o1, o2;     long long t;     cin >> t;     while (t--) {       e1 = e2 = o1 = o2 = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a;         if (a & 1)           o1++;         else           e1++;       }       cin >> m;       for (int i = 0; i < m; i++) {         cin >> b;         if (b & 1)           o2++;         else           e2++;       }       cout << o1 * o2 + e1 * e2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400050;   int n, x;   long long w;   vector<long long> val[4];   int Abs(int a) { return a < 0 ? -a : a; }   int main() {     scanf( %d , &n);     long long sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d%I64d , &x, &w);       if (x == 11)         val[0].push_back(w), sum += w;       else if (x == 1)         val[1].push_back(w), sum += w;       else if (x == 10)         val[2].push_back(w), sum += w;       else         val[3].push_back(w);     }     int len = val[3].size();     int cnt = n - len;     int num = min(val[1].size(), val[2].size());     num += val[0].size();     for (int i = 0; i < 4; i++) sort(val[i].begin(), val[i].end());     long long ans = sum;     int now1 = 0, now2 = 0;     if (num * 2 < cnt) {       ans = 0;       int no = Abs(val[1].size() - val[2].size());       if (val[2].size() < val[1].size()) {         for (int i = 0; i < no; i++) {           if (num * 2 >= cnt) break;           sum -= val[1][i];           cnt--;           now1++;           if (num * 2 >= cnt) ans = max(ans, sum);         }       } else {         for (int i = 0; i < no; i++) {           if (num * 2 >= cnt) break;           sum -= val[2][i];           cnt--;           now2++;           if (num * 2 >= cnt) ans = max(ans, sum);         }       }       if (num * 2 >= cnt) ans = max(ans, sum);     }     if (num * 2 > cnt) {       ans = sum;       int pos = 1;       while (num * 2 >= cnt) {         if (pos > len) break;         if (num * 2 >= (cnt + 1)) {           sum += val[3][len - pos];           ans = max(ans, sum);           cnt++;         } else           break;         pos++;       }       if (num * 2 >= cnt) ans = max(ans, sum);       int no = Abs(val[2].size() - val[1].size());       if (val[2].size() > val[1].size()) {         for (int i = now2; i < no; i++) {           if (pos + i - now2 > len) break;           sum -= val[2][i];           sum += val[3][len - i + now2 - pos];           if (num * 2 >= cnt) ans = max(ans, sum);         }       } else {         for (int i = now1; i < no; i++) {           if (pos + i - now1 > len) break;           sum -= val[1][i];           sum += val[3][len - i + now1 - pos];           if (num * 2 >= cnt) ans = max(ans, sum);         }       }     } else if (num * 2 == cnt) {       int no = Abs(val[2].size() - val[1].size());       if (val[2].size() > val[1].size()) {         for (int i = now2; i < no; i++) {           if (i - now2 >= len) break;           sum -= val[2][i];           sum += val[3][len - i + now2 - 1];           if (num * 2 >= cnt) ans = max(ans, sum);         }       } else {         for (int i = now1; i < no; i++) {           if (i - now1 >= len) break;           sum -= val[1][i];           sum += val[3][len - i + now1 - 1];           if (num * 2 >= cnt) ans = max(ans, sum);         }       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     cin >> r;     cin >> c;     vector<vector<bool> > a(r);     for (int i = 0; i < r; i++) a[i].resize(c);     char t_c;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         cin >> t_c;         if (t_c ==  . )           a[i][j] = true;         else           a[i][j] = false;       }     }     vector<vector<bool> > b(r);     vector<vector<bool> > d(r);     b = a;     d = a;     b[0][0] = true;     d[r - 1][c - 1] = true;     for (int i = 1; i <= r + c - 2; i++) {       for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {         b[j][i - j] = false;         if (a[j][i - j] == true) {           if (j != 0)             if (b[j - 1][i - j] == true) b[j][i - j] = true;           if (i - j != 0)             if (b[j][i - j - 1] == true) b[j][i - j] = true;         }       }     }     for (int i = r + c - 3; i >= 0; i--) {       for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {         d[j][i - j] = false;         if (a[j][i - j] == true) {           if (j != r - 1)             if (d[j + 1][i - j] == true) d[j][i - j] = true;           if (i - j != c - 1)             if (d[j][i - j + 1] == true) d[j][i - j] = true;         }       }     }     bool weak = false;     for (int i = 1; i <= r + c - 3; i++) {       int cnt1 = 0;       for (int j = max(0, i - c + 1); j <= min(r - 1, i); j++) {         if (b[j][i - j] && d[j][i - j]) cnt1++;       }       if (cnt1 < 2) weak = true;     }     if (!d[0][0])       cout <<  0 ;     else if (weak)       cout <<  1 ;     else       cout <<  2 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 5;   const long long MOD = 1000000007;   long long pow2[MAXN];   char x[MAXN];   int main() {     scanf( %s , x);     int n = strlen(x);     pow2[0] = 1;     for (int i = 1; i < n; i++) pow2[i] = (pow2[i - 1] * 2) % MOD;     long long d = pow2[n - 1], ans = 0;     for (int i = 0; i < n; i++)       if (x[i] ==  1 ) ans = (ans + pow2[n - i - 1] * d) % MOD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000000 + 20;   int pos[MAX_N], mark[MAX_N];   int inter[MAX_N];   set<int> D;   long long ans;   int n, k;   void add(int x) {     for (; x <= n; x += x & (-x)) ++inter[x];   }   int get(int x) {     if (x < 1) return 0;     int res = 0;     for (; x > 0; x -= x & (-x)) res += inter[x];     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       pos[x] = i + 1;     }     for (int i = 0; i < k; ++i) {       int x;       cin >> x;       mark[x] = 1;     }     D.insert(0);     D.insert(n + 1);     for (int i = 1; i <= n; ++i) {       if (mark[i])         D.insert(pos[i]);       else {         int l, r;         set<int>::iterator it = D.lower_bound(pos[i]);         r = *it - 1;         --it;         l = *it + 1;         ans += r - l + 1 - get(r) + get(l - 1);         add(pos[i]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18 + 9;   const long long MAX_SIZE = 1e7 + 1;   long long _t = 1, _T, csn;   long long max(long long a, long long b) {     if (a < b) return b;     return a;   }   long long min(long long a, long long b) {     if (a > b) return b;     return a;   }   long long mmi(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long nxor(long long n) {     if (n % 4 == 0) return n;     if (n % 4 == 1) return 1;     if (n % 4 == 2) return n + 1;     return 0;   }   long long sum(long long n) { return ((n * (n + 1)) / 2); }   long long modsum(long long n, long long m) {     long long ans = n % m;     ans *= (n + 1) % m;     ans %= m;     ans *= mmi(2, m);     return ans % m;   }   long long leap(long long y) {     if (y % 400 == 0)       return 1;     else if (y % 100 == 0)       return 0;     else if (y % 4 == 0)       return 1;     else       return 0;   }   void solve();   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     bool multicases = 0;     if (multicases) cin >> _t;     _T = _t;     while (_t--) solve();     return 0;   }   void solve() {     csn = _T - _t;     long long n;     cin >> n;     ;     map<string, long long> m;     string s, ts;     vector<vector<pair<long long, string>>> ans;     for (long long i = 0; i < n; i += 1) {       cin >> s;       vector<pair<long long, string>> tv;       for (long long j = 0; j < 9; j += 1) {         for (long long k = 1; k < 9 - j + 1; k += 1) {           ts = s.substr(j, k);           m[ts]++;           tv.emplace_back(make_pair(k, ts));         }       }       sort(tv.begin(), tv.end());       for (long long j = 1; j < tv.size(); j += 1)         if (tv[j].second == tv[j - 1].second) m[tv[j].second]--;       ans.emplace_back(tv);     }     for (long long i = 0; i < n; i += 1) {       for (long long j = 0; j < ans[i].size(); j += 1)         if (m[ans[i][j].second] == 1) {           cout << ans[i][j].second <<   n ;           ;           break;         }     }     return;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   const int L = 20;   int par[N][L];   int up[N][L];   int h[N];   int to[N];   int s[N], t[N];   pair<int, int> edge[N];   vector<pair<int, int> > al[N];   int find(int v) {     if (to[v] == v) return v;     return to[v] = find(to[v]);   }   int unite(int u, int v) {     u = find(u), v = find(v);     to[u] = v;     return (u != v);   }   void dfs(int v, int p = -1) {     h[v] = (p + 1 ? h[p] + 1 : 0);     par[v][0] = p;     for (int i = 1; i < L; i++) {       if (par[v][i - 1] + 1) {         par[v][i] = par[par[v][i - 1]][i - 1];         up[v][i] = max(up[v][i - 1], up[par[v][i - 1]][i - 1]);       }     }     for (int i = 0; i < al[v].size(); i++) {       int u = al[v][i].first;       if (u == p) continue;       up[u][0] = al[v][i].second;       dfs(u, v);     }     return;   }   pair<int, int> go_up(int v, int x) {     int mx = 0;     for (int b = 0; b < L; b++)       if (x >> b & 1) mx = max(mx, up[v][b]), v = par[v][b];     return {v, mx};   }   int lca(int u, int v) {     if (h[u] < h[v]) swap(u, v);     u = go_up(u, h[u] - h[v]).first;     if (u == v) return v;     for (int b = L - 1; ~b; --b)       if (par[v][b] != par[u][b]) v = par[v][b], u = par[u][b];     return par[v][0];   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) to[i] = i;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       --u, --v;       s[i] = u, t[i] = v;       edge[i] = {w, i};     }     sort(edge, edge + m);     long long ans = 0;     int p = 0;     for (int i = 0; i < m; i++) {       long long w = edge[i].first, id = edge[i].second;       int u = s[id], v = t[id];       if (unite(u, v)) {         ans += w, p++;         al[u].push_back({v, w});         al[v].push_back({u, w});       }     }     dfs(0);     int q;     cin >> q;     while (q--) {       int u, v;       cin >> u >> v;       --u, --v;       int pu = find(u), pv = find(v);       if ((p == n - 2 && pu == pv) || p < n - 2) {         cout << -1 <<   n ;         continue;       }       if (p == n - 2) {         cout << ans <<   n ;         continue;       }       int lc = lca(u, v);       cout << ans - max(go_up(u, h[u] - h[lc]).second,                         go_up(v, h[v] - h[lc]).second)            <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1999999999;   const double pi = acos(-1.0);   const double eps = 1e-10;   char gc() {     char c;     while (isspace(c = getchar()))       ;     return c;   }   int gs(char* s) {     gets(s);     int l = strlen(s);     while (l && isspace(s[l - 1])) s[--l] = 0;     return l;   }   int n;   double p[101];   double isok(double a) {     double tmn = 1e20, tmx = -1e20;     for (int i = 0; i <= n; i++) {       if (i * 2 > n) tmx = max(tmx, (p[i] - a) / (i - n / 2.));       if (i * 2 < n) tmn = min(tmn, (a - p[i]) / (n / 2. - i));     }     return tmn < tmx;   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; i++) scanf( %lf , &p[i]);     double low = -0.001, mid, high = 1.001;     if ((n % 2) == 0) low = p[n / 2];     for (int i = 0; i < 60; i++) {       mid = (low + high) / 2;       if (isok(mid))         low = mid;       else         high = mid;     }     printf( %.10f n , (low + high) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<vector<string> > tab(9);     int emp[3][3];     memset(emp, 0, sizeof emp);     for (int i = 0; i < 9; i++) {       tab[i].resize(3);       for (int j = 0; j < 3; j++) {         string a;         cin >> a;         for (int k = 0; k < a.size(); k++) {           if (a[k] ==  . ) emp[i / 3][j]++;         }         tab[i][j] = a;       }     }     int n, m;     cin >> n >> m;     n--;     m--;     char ne;     int ln = n, lm = (m + 1) % 3;     if (tab[ln][lm][m % 3] ==  x )       ne =  o ;     else       ne =  x ;     n = n % 3;     m = m % 3;     if (emp[n][m] == 0) {       for (int i = 0; i < 9; i++) {         for (int j = 0; j < 3; j++) {           string a = tab[i][j];           for (int k = 0; k < 3; k++) {             if (a[k] ==  . ) tab[i][j][k] =  ! ;           }         }       }     } else {       for (int i = n * 3; i < (n + 1) * 3; i++) {         string a = tab[i][m];         for (int j = 0; j < 3; j++) {           if (a[j] ==  . ) tab[i][m][j] =  ! ;         }       }     }     for (int i = 0; i < 9; i++) {       if (i != 0 && i % 3 == 0) cout << endl;       for (int j = 0; j < 3; j++) {         cout << tab[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 10;   const long long INF = 8e18;   const long long MOD = 1e9 + 7;   inline long long poww(long long a, long long b) {     a %= MOD;     long long ans = 1;     while (b > 0) {       if (b & 1) ans = ans * a % MOD;       b >>= 1;       a = a * a % MOD;     }     return ans;   }   long long fact[MAXN], inv[MAXN], n, k, ans, F[MAXN];   inline long long C(int k, int n) {     return fact[n] * inv[k] % MOD * inv[n - k] % MOD;   }   inline void mkey(long long& a) {     if (a >= MOD) a -= MOD;     if (a < 0) a += MOD;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     fact[0] = inv[0] = 1;     for (int i = 1; i < MAXN; i++)       fact[i] = fact[i - 1] * i % MOD, inv[i] = poww(fact[i], MOD - 2);     F[0] = 1;     for (int i = 1; i <= n; i++) {       F[i] = i * F[i - 1] % MOD;       if (i > k) mkey(F[i] -= C(k, i - 1) * fact[k] % MOD * F[i - k - 1] % MOD);     }     for (int i = 1; i <= n; i++)       mkey(ans += C(i - 1, n - 1) * F[i - 1] % MOD * fact[n - i] % MOD);     cout << (fact[n] - ans + MOD) % MOD <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105], c[105];   int findz(int n) { return a[n] == n ? a[n] : a[n] = findz(a[n]); }   void un(int x, int y) { a[findz(x)] = findz(y); }   int main() {     int n, l, f;     cin >> n >> l;     int count = 0;     int wei = 0;     memset(c, 0, sizeof(c));     for (int i = 1; i <= l; i++) a[i] = i;     for (int i = 0; i < n; i++) {       int z;       cin >> z;       if (z >= 1) {         cin >> f;         c[f]++;       } else         count++;       for (int j = 1; j < z; j++) {         int b;         cin >> b;         c[b]++;         un(f, b);       }     }     set<int> s;     for (int i = 1; i <= l; i++) {       s.insert(findz(i));       if (c[i] == 0) wei++;     }     if (s.size() - wei == 0) {       cout << count;     } else {       cout << count + s.size() - wei - 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n) { return (n % 1000000007); }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n;     vector<long long> v(n);     map<long long, long long> has, cnt;     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     cin >> m;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       has[v[x - 1]]++;     }     long long sz = has.size();     while (v.size() < n + 5 * m) {       for (long long i = n - 2; i >= 0; i--) v.push_back(v[i]);       for (long long i = 1; i < n; i++) v.push_back(v[i]);     }     set<long long> possible;     long long cur = 0;     long long match = 0;     for (long long i = 0; i < m; i++) {       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--;       cnt[v[i]]++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++;       cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0));       if (i == 0) cur -= v[i];       if (match == sz) possible.insert(cur);     }     for (long long i = m; i < n + 5 * m; i++) {       if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match--;       cnt[v[i - m]]--;       if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--;       cnt[v[i]]++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++;       cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0));       cur -= abs(v[i - m + 1] - (i - m >= 0 ? v[i - m] : 0));       if (match == sz) possible.insert(cur);     }     if (possible.size() > 1)       cout << -1 <<   n ;     else if (possible.size() == 0)       cout << -1 <<   n ;     else       cout << *possible.begin() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int invertir(int n) {     int r = 0;     while (n > 0) {       r = r * 10 + (n % 10);       n = n / 10;     }     return r;   }   int main() {     int a, b;     cin >> a >> b;     cout << (a + invertir(b));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int m;   const long long mod = 1e9 + 7;   struct Mat {     long long mat[111][111];   } st, ed;   long long stt[111][111];   void init() {     memset(stt, 0, sizeof(stt));     stt[0][0] = stt[0][m - 1] = 1;     for (int i = 1; i < m; ++i) stt[i][i - 1] = 1;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) st.mat[i][j] = stt[i][j];   }   Mat mul(Mat a, Mat b) {     Mat ret;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) {         ret.mat[i][j] = 0;         for (int k = 0; k < m; ++k)           (ret.mat[i][j] += a.mat[i][k] * b.mat[k][j] % mod) %= mod;       }     return ret;   }   Mat pow(Mat a, long long b) {     Mat ret;     memset(ret.mat, 0, sizeof(ret.mat));     for (int i = 0; i < m; ++i) ret.mat[i][i] = 1;     while (b) {       if (b & 1) ret = mul(ret, a);       a = mul(a, a);       b >>= 1;     }     return ret;   }   int main() {     cin >> n >> m;     if (n < m) return 0 * puts( 1 );     init();     ed = pow(st, n - m + 1);     long long ans = 0;     for (int i = 0; i < m; ++i) (ans += ed.mat[0][i]) %= mod;     cout << ans << (  n );   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long a_na_b_mod_c(long long a, long long b, long long c) {     if (b == 0) return 1;     long long t = a_na_b_mod_c(a, (b / 2), c) % c;     if (b % 2 == 0)       return (t * t) % c;     else       return (((t * t) % c) * (a % c)) % c;   }   long long ip(long long a) { return a_na_b_mod_c(a, mod - 2, mod); }   vector<long long> f(1, 1), fi;   long long nCk(long long n, long long k) {     return (((f[n] * fi[k]) % mod) * fi[n - k]) % mod;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long long k;     cin >> n >> k;     if (!k) {       cout <<  0 n ;       return 0;     }     for (int i = 1; i < n + 79; i++) f.push_back((f.back() * i) % mod);     fi.resize(n + 79);     for (int i = 0; i < n + 79; i++) fi[i] = ip(f[i]);     vector<int> h(n);     for (int i = 0; i < n; i++) {       cin >> h[i];     }     h.push_back(h[0]);     long long eq = 0;     for (int i = 1; i <= n; i++) {       if (h[i] == h[i - 1]) eq++;     }     long long dif = n - eq;     if (!dif) {       cout <<  0 n ;       return 0;     }     long long all = 0;     long long i2 = ip(2);     long long p2 = a_na_b_mod_c(2, dif, mod);     long long kp2 = 1;     for (long long z = 0; z < dif; z++) {       long long non_zero = dif - z;       long long good = p2;       long long zero = non_zero % 2 == 1 ? 0 : nCk(non_zero, non_zero >> 1);       good = ((good - zero + mod) * i2) % mod;       all += (((good * nCk(dif, z)) % mod) * kp2) % mod;       all %= mod;       p2 = (p2 * i2) % mod;       kp2 = (kp2 * (k - 2)) % mod;     }     cout << (all * a_na_b_mod_c(k, eq, mod)) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     s.insert(0);     int a;     for (int i = 1; i <= n; i++) {       cin >> a;       if (s.find(a) != s.end()) {         s.erase(a);       }       s.insert(i);     }     cout << s.size();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100050;   struct node {     int sa, ea, sb, eb;   } a[N];   int t[N << 1], rt1[N << 1], rt2[N << 1], lc[N * 80], rc[N * 80], tot, n, m1, m2;   bool cnt[N * 80], addv[N * 80];   inline bool cmp1(const node &a, const node &b) { return a.ea < b.ea; }   inline bool cmp2(const node &a, const node &b) { return a.sa < b.sa; }   int add(int pre, int L, int R, int x, int y) {     if (addv[pre]) return pre;     int o = ++tot;     cnt[o] = 1;     if (x <= L && y >= R) {       addv[o] = 1;       lc[o] = lc[pre];       rc[o] = rc[pre];     } else {       int M = L + R >> 1;       addv[o] = 0;       if (x <= M)         lc[o] = add(lc[pre], L, M, x, y);       else         lc[o] = lc[pre];       if (y > M)         rc[o] = add(rc[pre], M + 1, R, x, y);       else         rc[o] = rc[pre];     }     return o;   }   bool ask(int o, int L, int R, int x, int y) {     if (addv[o]) return 0;     if (x <= L && y >= R) return !cnt[o];     int M = L + R >> 1;     return (x > M || ask(lc[o], L, M, x, y)) &&            (y <= M || ask(rc[o], M + 1, R, x, y));   }   inline bool check() {     int i, k = 1;     memset(rt1, 0, sizeof(rt1));     memset(rt2, 0, sizeof(rt2));     tot = 0;     sort(a + 1, a + n + 1, cmp1);     for (i = 1; i <= (m1); ++i) {       rt1[i] = rt1[i - 1];       for (; k <= n && a[k].ea == i; ++k)         rt1[i] = add(rt1[i], 1, m2, a[k].sb, a[k].eb);     }     sort(a + 1, a + n + 1, cmp2);     k = n;     for (i = m1; i >= (1); --i) {       rt2[i] = rt2[i + 1];       for (; k && a[k].sa == i; --k)         rt2[i] = add(rt2[i], 1, m2, a[k].sb, a[k].eb);     }     for (i = 1; i <= (n); ++i)       if (!ask(rt1[a[i].sa - 1], 1, m2, a[i].sb, a[i].eb) ||           !ask(rt2[a[i].ea + 1], 1, m2, a[i].sb, a[i].eb)) {         puts( NO );         return 0;       }     return 1;   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= (n); ++i) {       scanf( %d%d%d%d , &a[i].sa, &a[i].ea, &a[i].sb, &a[i].eb);       t[(i << 1) - 1] = a[i].sa;       t[i << 1] = a[i].ea;     }     sort(t + 1, t + (n << 1) + 1);     m1 = unique(t + 1, t + (n << 1) + 1) - t - 1;     for (i = 1; i <= (n); ++i) {       a[i].sa = lower_bound(t + 1, t + m1 + 1, a[i].sa) - t;       a[i].ea = lower_bound(t + 1, t + m1 + 1, a[i].ea) - t;     }     for (i = 1; i <= (n); ++i) {       t[(i << 1) - 1] = a[i].sb;       t[i << 1] = a[i].eb;     }     sort(t + 1, t + (n << 1) + 1);     m2 = unique(t + 1, t + (n << 1) + 1) - t - 1;     for (i = 1; i <= (n); ++i) {       a[i].sb = lower_bound(t + 1, t + m2 + 1, a[i].sb) - t;       a[i].eb = lower_bound(t + 1, t + m2 + 1, a[i].eb) - t;     }     if (!check()) return 0;     for (i = 1; i <= (n); ++i) {       swap(a[i].sa, a[i].sb);       swap(a[i].ea, a[i].eb);     }     swap(m1, m2);     if (check()) puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }   long long oo = 1e18;   long long const M = 1e9 + 7, N = 3e5 + 9;   int n, m, d;   string s =   ;   int ans = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> d;     vector<int> v;     set<int> s;     map<int, int> mb;     int x;     for (int i = 0; i < n; i++) {       cin >> x;       s.insert(x);       v.push_back(x);     }     int day = 1, cofe = 0;     while (s.size()) {       if (s.lower_bound(cofe) != s.end()) {         cofe = *s.lower_bound(cofe);         s.erase(s.lower_bound(cofe));         mb[cofe] = day;         cofe += d + 1;       } else {         cofe = 0;         day++;       }     }     cout << day << endl;     for (int i = 0; i < n; i++) {       cout << mb[v[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int maxn = 1005;   int c[10], n, s;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1, x; i <= n; i++) scanf( %d , &x), c[x]++;     int ans = INF, I, K, J, t;     for (int i = s / n; i >= 0; i--)       for (int j = (s - c[3] * i) / (n - c[3]); j >= i; j--) {         int k = (s - c[3] * i - c[4] * j) / c[5];         if (k * c[5] - j * c[4] >= ans) break;         if (i * c[3] + j * c[4] + k * c[5] == s &&             ans > (t = abs(i * c[3] - j * c[4]) + abs(j * c[4] - k * c[5])))           ans = t, I = i, J = j, K = k;       }     if (ans != INF)       printf( %d %d %d n , I, J, K);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > data;   vector<bool> parallel;   vector<int> father;   vector<int> spec;   vector<int> opt;   vector<long long> ans;   void dfs(int vertex) {     if (parallel[vertex]) {       int tot = 0;       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs(to);         tot += opt[to];       }       opt[vertex] = tot;     } else {       if (spec[vertex] != -1) {         opt[vertex] = 1;         return;       }       int mn = 1e9;       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs(to);         mn = min(mn, opt[to]);       }       opt[vertex] = mn;     }   }   void dfs2(int vertex, long long need) {     if (parallel[vertex]) {       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         dfs2(to, need);       }     } else {       if (spec[vertex] != -1) {         ans[spec[vertex]] = need;         return;       }       for (int i = 0; i < data[vertex].size(); ++i) {         int to = data[vertex][i];         if (opt[to] == opt[vertex]) {           dfs2(to, need);           return;         }       }     }   }   void solve() {     int first;     cin >> first;     data = {{}}, father = {-1}, spec = {-1}, parallel = {false};     int cur = 0, u = 0;     while (true) {       char ch =    ;       while (ch ==    ) cin >> ch;       if (ch ==  ( ) {         data.push_back({});         father.push_back(cur), parallel.push_back(false), spec.push_back(-1);         int index = data.size() - 1;         data[cur].push_back(index);         cur = index;       }       if (ch ==  * ) {         data.push_back({});         father.push_back(cur), parallel.push_back(false), spec.push_back(u++);         int index = data.size() - 1;         data[cur].push_back(index);       }       if (ch ==  P ) parallel[cur] = true;       if (ch ==  ) ) {         cur = father[cur];       }       if (cur == 0) break;     }     ans.assign(u, 0);     opt.assign(data.size(), -1);     dfs(1);     long long need = (long long)first * opt[1];     dfs2(1, need);     cout <<  REVOLTING  ;     for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; ++i) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long int c[2020][2020];   int main() {     long long int n, k, sum = 0;     cin >> n >> k;     for (int i = 0; i < ((int)(n)); i++) {       c[i][i] = -1;     }     if (k >= 3) {       long long int tmp;       for (int i = 0; i < ((int)(n - 1)); i++) {         for (int j = (int)(i + 1); j < ((int)(n)); j++) {           scanf( %I64d , &tmp);           sum += tmp;         }       }     } else {       for (int i = 0; i < ((int)(n - 1)); i++) {         for (int j = (int)(i + 1); j < ((int)(n)); j++) {           cin >> c[i][j];           c[j][i] = c[i][j];           if (c[i][j] > -1) {             sum += c[i][j];           }         }       }     }     if (k != 2) {       double ress = (double)(sum * 2) / (double)n;       cout << (long long int)(floor(ress)) << endl;     } else {       long long int res = 0;       for (int i = 0; i < ((int)(n)); i++) {         vector<long long int> pl;         for (int j = 0; j < ((int)(n)); j++) {           if (c[i][j] > -1) pl.push_back(c[i][j]);         }         for (int j = 0; j < ((int)(((long long int)(pl).size()))); j++) {           res += pl[j] * (((long long int)(pl).size()) - 1);         }       }       double ress = (double)(res) / (double)(n * (n - 1) / 2);       cout << (int)(floor(ress)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i, t;     vector<int> a;     for (i = 0; i < n; i++) {       cin >> t;       a.push_back(t);     }     for (i = 0; i < n - 1; i++) {       if (a[i] % 2 != 0) {         a[i] %= 2;         a[i + 1]--;         if (a[i + 1] < 0) {           cout <<  NO ;           return 0;         }       }     }     if (a[i] & 1) {       cout <<  NO ;       return 0;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Q = 1e9 + 7;   long long poww(long long a, long long b) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > Q) x %= Q;       }       y = (y * y);       if (y > Q) y %= Q;       b /= 2;     }     return x;   }   long long C[52][52];   void binomialCoeff() {     long long i, j;     for (i = 0; i <= 50; i++) {       for (j = 0; j <= 50; j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }   }   int main() {     long long n, m, k;     cin >> n >> m >> k;     long long ans = 0;     if (m == 1) {       ans = 1;     } else if (k == 1 || k > n) {       ans = poww(m, n);     } else if (n == k) {       ans = poww(m, (k + 1) / 2);       ans %= Q;     } else if (k % 2 != 0) {       ans = m * m;       ans %= Q;     } else {       ans = m;       ans %= Q;     }     ans %= Q;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> ar(n + 1, 1e10);     vector<long long> cur(n + 1, 1);     for (long long i = 1; i <= n; i++) {       cin >> ar[i];       if (ar[i] == ar[i - 1]) cur[i] = cur[i - 1] + 1;     }     long long ans = 0;     for (long long i = 1; i <= n; i++) ans += cur[i];     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     string s;     for (int i = 1; i <= n; i++) {       string str;       ostringstream temp;       temp << i;       s += temp.str();     }     cout << s[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char i = getchar();     long long f = 1, res = 0;     while (i <  0  || i >  9 ) {       if (i ==  - ) f = -1;       i = getchar();     }     while (i >=  0  && i <=  9 ) {       res = res * 10 + i -  0 ;       i = getchar();     }     return res * f;   }   const int N = 1e5 + 50;   long long h[N], a[N], n, m, k, p;   struct bamboo {     long long time, id;     bool operator<(const bamboo& A) const { return time > A.time; }     bamboo(long long T, long long ID) : time(T), id(ID) {}   };   priority_queue<bamboo> q;   long long cnt[N];   bool pd(long long mid) {     while (!q.empty()) {       q.pop();     }     memset(cnt, 0, sizeof(cnt));     for (register int i = 1; i <= n; ++i) {       if (mid - a[i] * m < h[i]) {         q.push(bamboo(mid / a[i], i));       }     }     for (register int i = 1; i <= m; ++i) {       if (q.empty()) {         break;       }       for (register int j = 1; j <= k; ++j) {         if (q.empty()) {           break;         }         bamboo now = q.top();         q.pop();         if (now.time < i) {           return false;         }         cnt[now.id]++;         if (mid + cnt[now.id] * p - a[now.id] * m < h[now.id]) {           q.push(bamboo((mid + cnt[now.id] * p) / a[now.id], now.id));         }       }     }     return q.empty();   }   int main() {     n = read();     m = read();     k = read();     p = read();     long long l = 0, r = -10, ans = -1, mid;     for (register int i = 1; i <= n; ++i) {       h[i] = read();       a[i] = read();       r = max(r, h[i] + a[i] * m);     }     while (l <= r) {       mid = (l + r) >> 1;       if (pd(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tostr(const T& t) {     ostringstream os;     os << t;     return os.str();   }   int adj[110][110];   int adj2[110][110];   int N, M;   set<int> emp[110];   bool are_connected2(int a, int b) {     set<int>::iterator it;     for (it = emp[a].begin(); it != emp[a].end(); ++it) {       int x = *it;       if (emp[b].count(x)) return true;     }     return false;   }   void floyd() {     for (int k = (int)(0); k <= (int)(N - 1); ++k)       for (int i = (int)(0); i <= (int)(N - 1); ++i)         for (int j = (int)(0); j <= (int)(N - 1); ++j) {           if (adj[i][k] == 9999999 || adj[k][j] == 9999999) continue;           adj[i][j] = 1;         }   }   bool are_connected(vector<int>& comp1, vector<int>& comp2) {     for (int i = (int)(0); i <= (int)(comp1.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp2.size() - 1); ++j) {         if (adj[comp1[i]][comp2[j]] != 9999999) return true;       }     }     return false;   }   vector<vector<int> > find_scc() {     floyd();     vector<int> colors = vector<int>(N, -1);     int cur_color = -1;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (adj[i][j] != 9999999 && adj[j][i] != 9999999) {           if (colors[i] != -1)             colors[j] = colors[i];           else {             ++cur_color;             colors[i] = colors[j] = cur_color;           }         }       }     }     for (int i = (int)(0); i <= (int)(colors.size() - 1); ++i)       if (colors[i] == -1) colors[i] = ++cur_color;     int ncolors = cur_color + 1;     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj2[i][j] = 9999999;     vector<vector<int> > comp_list = vector<vector<int> >(ncolors);     for (int i = (int)(0); i <= (int)(ncolors - 1); ++i) {       for (int j = (int)(0); j <= (int)(N - 1); ++j) {         if (colors[j] == i) comp_list[i].push_back(j);       }     }     for (int i = (int)(0); i <= (int)(comp_list.size() - 1); ++i) {       for (int j = (int)(0); j <= (int)(comp_list.size() - 1); ++j) {         if (are_connected(comp_list[i], comp_list[j])) {           adj2[i][j] = 1;         }       }     }     return comp_list;   }   int main() {     cin >> N >> M;     bool nonZero = false;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       int k;       cin >> k;       for (int j = (int)(0); j <= (int)(k - 1); ++j) {         int a;         cin >> a;         --a;         emp[i].insert(a);         if (a != 0) nonZero = true;       }     }     if (!nonZero) {       cout << N << endl;       return 0;     }     for (int i = (int)(0); i <= (int)(N - 1); ++i)       for (int j = (int)(0); j <= (int)(N - 1); ++j) adj[i][j] = 9999999;     for (int i = (int)(0); i <= (int)(N - 1); ++i) {       for (int j = (int)(i + 1); j <= (int)(N - 1); ++j) {         if (are_connected2(i, j)) {           adj[i][j] = 1;           adj[j][i] = 1;         }       }     }     vector<vector<int> > scc = find_scc();     int ans = (int)scc.size() - 1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   }   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> items;     for (int i = 0; i < n; i++) {       int item;       cin >> item;       items.push_back(item);     }     sort(items.rbegin(), items.rend());     set<long long> st;     long long cnt = 0;     for (int i = n - 1; i >= 0; i--) {       while (items[i]) {         if (st.count(items[i]) == 0) {           cnt += items[i];           st.insert(items[i]);           break;         }         items[i]--;       }     }     cout << cnt << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(10);     cout.tie(nullptr);     cin.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     int pause;     cin >> pause;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007, BIG = 0x3f3f3f3f;   int n;   vector<int> a;   vector<int> Process() {     vector<int> ans = {0};     int x = 0;     for (int i = 0; i < n; i++) {       if (a[i] < 0 && ++x > 2) {         x = 1;         ans.push_back(0);       }       ans.back()++;     }     return ans;   }   void Output() {     const vector<int> ans = Process();     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (cin >> n) {       a.resize(n);       for (int i = 0; i < n; i++) cin >> a[i];       Output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int i, t;     char str[25];     while (~scanf( %s , str)) {       int len = strlen(str);       t = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  4  || str[i] ==  7 ) {           t++;         }       }       if (t == 4 || t == 7)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n, a[200001], mp[200001], x, y;   vector<int> to[200001], t2[200001];   int fa[200001], d[200001], sz[200001], son[200001];   int top[200001], dfn[200001], cnt;   int f[200001], v[200001], p[200001], g[200001];   int st[200001], tp, s, sum, ans;   bool in[200001];   inline int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; }   inline int sub(int x, int y) { return x < y ? x + mod - y : x - y; }   inline int power(int a, int n) {     int tp = 1;     while (n) {       if (n & 1) tp = 1ll * tp * a % mod;       a = 1ll * a * a % mod, n >>= 1;     }     return tp;   }   inline bool cmp(int i, int j) { return dfn[i] < dfn[j]; }   inline void dfs1(int i) {     sz[i] = 1;     dfn[i] = ++cnt;     for (int j : to[i]) {       if (j == fa[i]) continue;       fa[j] = i, d[j] = d[i] + 1;       dfs1(j);       sz[i] += sz[j];       if (sz[son[i]] < sz[j]) son[i] = j;     }   }   inline void dfs2(int i) {     if (son[i]) top[son[i]] = top[i], dfs2(son[i]);     for (int j : to[i])       if (j != fa[i] && j != son[i]) top[j] = j, dfs2(j);   }   inline int lca(int x, int y) {     while (top[x] != top[y]) {       if (d[top[x]] < d[top[y]]) swap(x, y);       x = fa[top[x]];     }     return d[x] < d[y] ? x : y;   }   inline int dfs(int i) {     g[i] = 0;     if (in[i]) g[i] = v[i];     int ans = 0;     for (int j : t2[i]) {       ans = add(ans, dfs(j)), g[i] = add(g[i], g[j]);       ans = (ans + 1ll * (d[j] - d[i]) * g[j] % mod * sub(sum, g[j])) % mod;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , a + i), mp[a[i]] = i;     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       to[x].push_back(y), to[y].push_back(x);     }     dfs1(1), top[1] = 1, dfs2(1);     f[1] = 1;     for (int i = 2; i <= n; i++) {       if (f[i]) continue;       f[i] = i - 1;       for (int j = 2 * i; j <= n; j += i) {         if ((j / i) % i)           f[j] = f[i] * f[j / i];         else           f[j] = i * f[j / i];       }     }     for (int i = 1; i <= n; i++) v[i] = f[a[i]];     for (int i = 1; i <= n; i++) f[i] = 1ll * i * power(f[i], mod - 2) % mod;     for (int i = 1; i <= n; i++)       for (int j = 2 * i; j <= n; j += i) f[j] = sub(f[j], f[i]);     for (int t = 1; t <= n; t++) {       sum = s = 0;       for (int i = t; i <= n; i += t)         p[++s] = mp[i], sum = add(sum, v[mp[i]]), in[mp[i]] = 1;       sort(p + 1, p + s + 1, cmp);       st[tp = 1] = p[1], t2[p[1]].clear();       for (int i = 2; i <= s; i++) {         int x = lca(p[i], st[tp]), lt = 0;         while (d[st[tp]] > d[x]) {           if (lt) t2[st[tp]].push_back(lt);           lt = st[tp--];         }         if (st[tp] != x) st[++tp] = x, t2[x].clear();         if (lt) t2[x].push_back(lt);         st[++tp] = p[i], t2[p[i]].clear();       }       while (tp > 1) t2[st[tp - 1]].push_back(st[tp]), tp--;       ans = (ans + 1ll * dfs(st[1]) * f[t]) % mod;       for (int i = 1; i <= s; i++) in[p[i]] = 0;     }     cout << 2ll * ans * power(1ll * n * (n - 1) % mod, mod - 2) % mod;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n;     string str;     string ans =   ;     while (cin >> n) {       cin >> str;       int now = 0;       int vis[26];       ans =   ;       while (now < str.length()) {         char tmp = str[now];         int diff = 0;         memset(vis, 0, sizeof vis);         int flag = 0;         for (int i = now + 1; i < str.length(); i++) {           if (str[i] != tmp) {             flag = 1;             ans.push_back(tmp);             ans.push_back(str[i]);             now = i + 1;             break;           }           if (!vis[str[i] -  a ]) {             diff++;             if (diff > 2) {               flag = 1;               now = now + 1;               break;             }           }         }         if (flag == 0) {           break;         }       }       cout << str.length() - ans.length() << endl;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       n = 4 * n;       for (long long i = 0; i < (n / 4); i++) {         cout << n - (2 * i) <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100020, mo = 1e9 + 7;   int n, second[N], x, y, cnt, dfn[N], vis[N];   int dot[N], size;   int l[N], r[N];   long long ans = 1;   set<pair<int, int> > L[N], R[N];   struct Dot {     int x, y;   } s[N];   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = 10 * x + c -  0 ;       c = getchar();     }     x *= f;   }   inline int LS() {     sort(second + 1, second + n + 1);     int l = 0;     for (int i = 1; i <= n; i++)       if (i == 1 || second[i] != second[i - 1]) second[++l] = second[i];     return l;   }   inline void dfs(int u) {     if (u > n || u < 1) return;     vis[u] = cnt;     dot[++size] = u;     set<pair<int, int> >::iterator it = L[s[u].x].find(pair<int, int>(s[u].y, u));     it++;     if (!vis[(*it).second]) dfs((*it).second);     it--;     it--;     if (!vis[(*it).second]) dfs((*it).second);     it = R[s[u].y].find(pair<int, int>(s[u].x, u));     it++;     if (!vis[(*it).second]) dfs((*it).second);     it--;     it--;     if (!vis[(*it).second]) dfs((*it).second);   }   inline int power(long long a, int n) {     long long ans = 1;     while (n) {       if (n & 1) ans = (ans * a % mo);       a = (a * a % mo);       n >>= 1;     }     return ans;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(s[i].x), read(s[i].y);     for (int i = 1; i <= n; i++) second[i] = s[i].x;     int X = LS();     for (int i = 1; i <= n; i++)       s[i].x = lower_bound(second + 1, second + X + 1, s[i].x) - second;     for (int i = 1; i <= n; i++) second[i] = s[i].y;     int Y = LS();     for (int i = 1; i <= n; i++)       s[i].y = lower_bound(second + 1, second + Y + 1, s[i].y) - second;     vis[n + 1] = 1e9;     for (int i = 1; i <= n; i++)       L[i].insert(pair<int, int>(0, n + 1)),           L[i].insert(pair<int, int>(n + 1, n + 1));     for (int i = 1; i <= n; i++)       R[i].insert(pair<int, int>(0, n + 1)),           R[i].insert(pair<int, int>(n + 1, n + 1));     for (int i = 1; i <= n; i++) {       L[s[i].x].insert(pair<int, int>(s[i].y, i));       R[s[i].y].insert(pair<int, int>(s[i].x, i));     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         size = 0;         cnt++;         dfs(i);         int num = 0;         bool flag = 0;         for (int j = 1; j <= size; j++) {           if (l[s[dot[j]].x] || r[s[dot[j]].y]) flag = 1;           num += (!l[s[dot[j]].x]) + (!r[s[dot[j]].y]);           l[s[dot[j]].x] = 1;           r[s[dot[j]].y] = 1;         }         int x = power(2, num);         if (size < num) x--;         if (x < 0) x += mo;         ans = ans * x % mo;       }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool notprime[1000010];   int sumprime[1000010];   void fun() {     for (int i = 2; i <= 1000000; i++) {       if (notprime[i] == 0) {         for (int j = i * 2; j <= 1000000; j += i) {           notprime[j] = 1;         }       }     }   }   void sum() {     sumprime[1] = 0;     for (int i = 2; i <= 1000000; i++) {       sumprime[i] = sumprime[i - 1] + (!notprime[i]);     }   }   int main() {     int n, x;     scanf( %d , &n);     fun();     sum();     while (n--) {       scanf( %d , &x);       int sum = sumprime[x] - sumprime[(int)sqrt(x)] + 1;       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j;   string s[103];   bool ktra1() {     if (n % 3 == 0) {       static int chk[1000];       fill_n(chk, 1000, 0);       for (int i = 1; i <= n / 3; ++i) {         for (int j = 1; j <= m; ++j) {           chk[s[i][j]]++;         }       }       if (chk[s[1][1]] != m * n / 3) return false;       for (int i = n / 3 + 1; i <= 2 * n / 3; ++i) {         for (int j = 1; j <= m; ++j) {           chk[s[i][j]]++;         }       }       if (chk[s[n / 3 + 1][1]] != m * n / 3) return false;       for (int i = 2 * n / 3 + 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           chk[s[i][j]]++;         }       }       if (chk[s[n][1]] != m * n / 3) return false;     } else       return false;     return true;   }   bool ktra2() {     if (m % 3 == 0) {       static int chk[1000];       fill_n(chk, 1000, 0);       for (int j = 1; j <= m / 3; ++j) {         for (int i = 1; i <= n; ++i) {           chk[s[i][j]]++;         }       }       if (chk[s[1][1]] != m * n / 3) return false;       for (int j = m / 3 + 1; j <= 2 * m / 3; ++j) {         for (int i = 1; i <= n; ++i) {           chk[s[i][j]]++;         }       }       if (chk[s[1][m / 3 + 1]] != m * n / 3) return false;       for (int j = 2 * m / 3 + 1; j <= m; ++j) {         for (int i = 1; i <= n; ++i) {           chk[s[i][j]]++;         }       }       if (chk[s[1][m]] != m * n / 3) return false;     } else       return false;     return true;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> s[i], s[i] =     + s[i];     if (ktra1() || ktra2())       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   int main() {     {       long long n, m, k, p, s, k1, p1;       cin >> n >> m >> s;       if (s == 1) {         cout << n * m;         return 0;       }       k = (n - 1) % s + 1;       k1 = n / s;       if (n % s != 0) k1++;       k = k1 * k;       p = (m - 1) % s + 1;       p1 = m / s;       if (m % s != 0) p1++;       p = p1 * p;       cout << p * k;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, idx;     long double at;     bool operator<(const point &other) const { return at < other.at; }   };   point p[123123];   int main() {     int n;     scanf( %d n , &n);     for (auto(i) = (0); (i) < (n); (i)++) {       int a, b;       scanf( %d %d n , &a, &b);       p[i].x = a;       p[i].y = b;       p[i].idx = i;       p[i].at = atan2(b, a);     }     sort(p, p + n);     long double kek = 123123;     int good1, good2;     for (auto(i) = (1); (i) < (n); (i)++) {       if (kek - p[i].at + p[i - 1].at > 1e-21) {         kek = p[i].at - p[i - 1].at;         good1 = p[i - 1].idx;         good2 = p[i].idx;       }     }     p[0].at += 2 * 3.1415926535897932384;     if (kek - p[0].at + p[n - 1].at > 1e-21) {       good1 = p[0].idx;       good2 = p[n - 1].idx;     }     printf( %d %d n , good1 + 1, good2 + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool primeFactor(int n) {     if (n == 2 || n == 3) return true;     int sum = 1, two = 0, cnt;     while (!(n % 2)) {       return false;     }     for (int i = 3; i <= sqrt(n); i += 2) {       while (!(n % i)) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     ;     int n, i, j, k, m, x, y, z;     int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,                    43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};     cin >> n;     if (n == 3) {       cout << 1 << endl << 3 << endl;       exit(0);     } else if (n == 5) {       cout << 2 << endl << 2 <<     << 3 << endl;       exit(0);     }     m = n - 4;     for (i = m; i >= 0; i -= 2) {       if (primeFactor(i)) {         z = i;         break;       }     }     int zz = z;     y = n - z;     for (i = y; i >= 0; i--) {       if (n - zz - i > 1 && primeFactor(i)) {         z = i;         if (binary_search(prime, prime + 25, n - zz - z)) {           y = i;           x = n - zz - z;           break;         }       }     }     cout << 3 << endl;     cout << x <<     << y <<     << zz << endl;     return 0;   }


#include <bits/stdc++.h>   const uint64_t MAX_NUM = 1000000000000000001ul;   uint64_t get_iteration_simple(const int n, const uint64_t k,                                 std::vector<uint64_t>& a) {     int iterations = 0;     while (true) {       ++iterations;       for (int i = 1; i < n; ++i) {         a[i] += a[i - 1];         if (a[i] >= k) {           return iterations;         }       }     }   }   bool is_there_more_than_k_with_coeffs(       const int n, const uint64_t k, std::vector<uint64_t>& a,       std::vector<std::vector<uint64_t>>& coeffs) {     for (int i = 0; i < n; ++i) {       uint64_t result = 0;       for (int j = 0; j <= i; ++j) {         if (static_cast<double>(a[j]) * static_cast<double>(coeffs[i][j]) >             MAX_NUM) {           return true;         }         result += coeffs[i][j] * a[j];         if (result >= k) {           return true;         }       }     }     return false;   }   std::tuple<std::vector<std::vector<uint64_t>>, bool> generate_mixed_coeffs(       const int n, const uint64_t k,       std::vector<std::vector<uint64_t>>& first_coeffs,       std::vector<std::vector<uint64_t>>& second_coeffs) {     bool is_there_overflow = false;     std::vector<std::vector<uint64_t>> new_coeffs(n);     for (int i = 0; i < n; ++i) {       new_coeffs[i].resize(i + 1, 0);       for (int j = 0; j <= i; ++j) {         new_coeffs[i][j] = 0;         for (int k = j; k <= i; ++k) {           if (static_cast<double>(second_coeffs[i][k]) *                   static_cast<double>(first_coeffs[k][j]) >               MAX_NUM) {             is_there_overflow = true;           }           new_coeffs[i][j] += second_coeffs[i][k] * first_coeffs[k][j];         }       }     }     return std::make_tuple(new_coeffs, is_there_overflow);   }   uint64_t get_iteration_binsearch(const int n, const uint64_t k,                                    std::vector<uint64_t>& a) {     uint64_t left = 0;     uint64_t right = 1;     std::vector<std::vector<std::vector<uint64_t>>> level_coeffs(100);     level_coeffs[0].resize(n);     std::vector<std::vector<uint64_t>> current_coeffs(n);     for (int i = 0; i < n; ++i) {       level_coeffs[0][i].resize(i + 1, 0);       current_coeffs[i].resize(i + 1, 0);       for (int j = 0; j <= i; ++j) {         level_coeffs[0][i][j] = 1;         current_coeffs[i][j] = (i == j ? 1 : 0);       }     }     int diff_two_power = 0;     while (true) {       if (is_there_more_than_k_with_coeffs(n, k, a,                                            level_coeffs[diff_two_power])) {         break;       } else {         right *= 2;         bool is_there_overflow;         std::tie(level_coeffs[diff_two_power + 1], is_there_overflow) =             generate_mixed_coeffs(n, k, level_coeffs[diff_two_power],                                   level_coeffs[diff_two_power]);         ++diff_two_power;         if (is_there_overflow) {           break;         }       }     }     while (right - left > 1) {       uint64_t middle = left + (1ull << (diff_two_power - 1));       std::vector<std::vector<uint64_t>> middle_coeffs;       bool is_there_overflow;       std::tie(middle_coeffs, is_there_overflow) = generate_mixed_coeffs(           n, k, current_coeffs, level_coeffs[diff_two_power - 1]);       if (is_there_overflow ||           is_there_more_than_k_with_coeffs(n, k, a, middle_coeffs)) {         right = middle;       } else {         left = middle;         current_coeffs = std::move(middle_coeffs);       }       --diff_two_power;     }     return left + 1;   }   bool is_there_more_than_k(const int n, const uint64_t k,                             const std::vector<uint64_t>& a) {     for (int i = 0; i < n; ++i) {       if (a[i] >= k) {         return true;       }     }     return false;   }   int main() {     int n;     uint64_t k;     std::cin >> n >> k;     bool still_zero = true;     std::vector<uint64_t> a(n);     int new_n = 0;     for (int i = 0; i < n; ++i) {       uint64_t number;       std::cin >> number;       if (number != 0 || !still_zero) {         a[new_n++] = number;       }       if (number != 0) {         still_zero = false;       }     }     const int simple_algo_bound = 60;     uint64_t result;     if (is_there_more_than_k(new_n, k, a)) {       result = 0;     } else if (new_n >= simple_algo_bound) {       result = get_iteration_simple(new_n, k, a);     } else {       result = get_iteration_binsearch(new_n, k, a);     }     std::cout << result << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 7;   const int inf = 0x3f3f3f3f;   int t, n;   int a[maxn];   char s[maxn];   int main() {     cin >> t;     while (t--) {       scanf( %s , s + 1);       n = strlen(s + 1);       int ou = 0, sum = 0, zero = 0;       int mark = -1;       for (int i = 1; i <= n; i++) {         int num = s[i] -  0 ;         if (num == 0) {           zero = 1;           mark = i;         }         sum += num;       }       if (sum % 3 != 0 || zero == 0) {         printf( cyan n );         continue;       }       if (sum == 0) {         printf( red n );         continue;       }       for (int i = 1; i <= n; i++) {         int num = s[i] -  0 ;         if (num % 2 == 0 && i != mark) {           ou = 1;           break;         }       }       if (ou == 1) {         printf( red n );         continue;       } else {         printf( cyan n );         continue;       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   char _;   inline long long powmod(long long x, long long n, long long _mod) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % _mod;       x = (x * x) % _mod;       n >>= 1;     }     return res;   }   int n;   int a[2000006];   int b[2000006];   int seen[2000006];   vector<int> factors(int x) {     vector<int> ret;     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) {         ret.push_back(i);         while (x % i == 0) x /= i;       }     }     if (x > 1) ret.push_back(x);     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n + 1; ++i) cin >> a[i];     int cur = 1;     while (cur <= n) {       vector<int> f = factors(a[cur]);       bool ok = true;       for (int i = 0; i < int((f).size()); ++i) {         if (seen[f[i]]) {           ok = false;           break;         }       }       if (!ok) break;       b[cur] = a[cur];       cur++;       for (int i = 0; i < int((f).size()); ++i) seen[f[i]] = 1;     }     if (cur <= n) {       for (int i = a[cur] + 1;; i++) {         vector<int> f = factors(i);         bool ok = true;         for (int j = 0; j < int((f).size()); ++j) {           if (seen[f[j]]) {             ok = false;             break;           }         }         if (ok) {           b[cur] = i;           for (int j = 0; j < int((f).size()); ++j) {             seen[f[j]] = 1;           }           cur++;           break;         }       }     }     if (cur <= n) {       vector<int> v;       for (int i = 2;; i++) {         if (cur + int((v).size()) > 1e5 + 5) break;         if (seen[i]) continue;         vector<int> f = factors(i);         bool ok = true;         for (int j = 0; j < int((f).size()); ++j)           if (seen[f[j]]) {             ok = false;             break;           }         if (ok) {           v.push_back(i);           for (int j = 0; j < int((f).size()); ++j) seen[f[j]] = 1;         }       }       int i = 0;       while (cur <= n) {         b[cur++] = v[i++];       }     }     for (int i = 1; i < n + 1; ++i) cout << b[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, p, ans, v;   void wczytaj(int x) {     string slowo;     cin >> slowo;     if (x != n) wczytaj(x + 1);     if (slowo.size() > 4) {       ans += v * p;       ans += p / 2;       v *= 2;       ++v;     } else {       ans += v * p;       v *= 2;     }   }   int main() {     cin >> n >> p;     wczytaj(1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       int a;       int f[51] = {0};       for (int i = 0; i < 2 * n; i++) {         cin >> a;         if (f[a] == 0) {           f[a]++;           cout << a <<    ;         }       }       std::cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 32;   int n, arr[nmax];   vector<int> output, current;   bool been[2 * nmax][2 * nmax * nmax][nmax];   void dfs(int people, int sum, int position) {     if (position > n) {       if (people * (people - 1) / 2 == sum) {         if (output.size() == 0)           output = current;         else if (output.size() > current.size())           output = current;       }       return;     }     if (been[people][sum][position]) return;     been[people][sum][position] = 1;     int take_now = 1;     for (; take_now * arr[position] + sum >=            (people + take_now) * (people + take_now - 1) / 2;          take_now++) {       current.push_back(arr[position]);       dfs(people + take_now, take_now * arr[position] + sum, position + 1);     }     for (int i = 1; i < take_now; i++) {       current.pop_back();     }   }   pair<int, int> work[2 * nmax];   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int out[2 * nmax][2 * nmax];   int main() {     scanf( %i , &n);     for (int i = 1; i <= n; i++) scanf( %i , &arr[i]);     sort(arr + 1, arr + n + 1);     dfs(0, 0, 1);     if (output.size() == 0) {       printf( =( );       return 0;     }     printf( %i n , output.size());     for (int i = 1; i <= output.size(); i++) work[i] = {i, output[i - 1]};     for (int steps = output.size(); steps >= 1; steps--) {       sort(work + 1, work + steps + 1, cmp);       assert(work[steps].second < steps);       int who = work[steps].first;       for (int j = 1; j <= work[steps].second; j++) out[who][work[j].first] = 1;       for (int j = work[steps].second + 1; j < steps; j++) {         assert(work[j].second);         work[j].second--;         out[work[j].first][who] = 1;       }     }     for (int i = 1; i <= output.size(); i++) {       for (int j = 1; j <= output.size(); j++) printf( %i , out[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int manx = 1e5 + 100;   const int INF = 0x3f3f3f3f;   int main() {     int n, a[200], b[200], cnt = 0, numb1 = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i]) cnt++;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       if (b[i]) {         if (a[i])           cnt--;         else           numb1++;       }     }     if (!cnt)       printf( -1 n );     else       printf( %d n , numb1 / cnt + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     int k;     cin >> n >> k;     long l = 1, r = n;     while (l < r) {       long m = l + (r - l) / 2;       long s = 0, v = m;       while (v != 0) {         s += v;         v /= k;       }       if (s >= n)         r = m;       else         l = m + 1;     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename P, typename Q>   ostream& operator<<(ostream& os, pair<P, Q> p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long long int k;     while (cin >> n >> k) {       deque<int> q;       for (int i = 0; i < n; ++i) {         int a;         cin >> a;         q.push_back(a);       }       int x = n;       while (true) {         int a = q.front();         q.pop_front();         int b = q.front();         q.pop_front();         int cnt = 1;         int c = max(a, b);         q.push_back(min(a, b));         while (cnt < min<long long int>(n, k)) {           if (c < q.front()) {             break;           }           ++cnt;           q.push_back(q.front());           q.pop_front();         }         if (min<long long int>(n, k) == cnt) {           x = c;           break;         }         q.push_front(c);       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, M = 500010;   int h[N], e[M * 2], nex[M * 2], idx, n, m, nodea, nodeb, sz;   int col[N];   void add(int x, int y) {     e[idx] = y;     nex[idx] = h[x];     h[x] = idx++;   }   bool dfs1(int u) {     col[u] = 1;     sz++;     for (int i = h[u]; ~i; i = nex[i]) {       int v = e[i];       if (v == nodea) continue;       if (v == nodeb || col[v] == 2) return false;       if (col[v] == 0) {         if (!dfs1(v)) return false;       }     }     return true;   }   bool dfs2(int u) {     col[u] = -1;     sz++;     for (int i = h[u]; ~i; i = nex[i]) {       int v = e[i];       if (v == nodeb) continue;       if (v == nodea || col[v] == 1 || col[v] == 2) return false;       if (col[v] == 0) {         if (!dfs2(v)) return false;       }     }     return true;   }   void modify(int u) {     col[u] = 2;     for (int i = h[u]; ~i; i = nex[i]) {       int v = e[i];       if (col[v] == 2 || v == nodea || v == nodeb)         continue;       else         modify(v);     }   }   int main() {     int T;     cin >> T;     while (T--) {       scanf( %d%d%d%d , &n, &m, &nodea, &nodeb);       for (int i = 0; i <= n; ++i) h[i] = -1, col[i] = 0;       idx = 0;       for (int i = 1; i <= m; ++i) {         int x, y;         scanf( %d%d , &x, &y);         add(x, y);         add(y, x);       }       int cnta = 0, cntb = 0;       for (int i = h[nodea]; ~i; i = nex[i]) {         int v = e[i];         sz = 0;         if (col[v] == 0 && v != nodeb) {           if (dfs1(v))             cnta += sz;           else             modify(v);         }       }       for (int i = h[nodeb]; ~i; i = nex[i]) {         int v = e[i];         sz = 0;         if (col[v] == 0 && v != nodea) {           if (dfs2(v))             cntb += sz;           else             modify(v);         }       }       cout << 1ll * cnta * cntb << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d[100005], sd[100005][3], f[2 * 100005];   int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }   void link(int a, int b) {     int x = Find(a), y = Find(b);     if (x != y) f[x] = y;   }   int main(void) {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> d[i];     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       for (int j = 0; j < x; ++j) {         int dr;         cin >> dr;         dr--;         sd[dr][++sd[dr][0]] = i;       }     }     for (int i = 0; i < 2 * m; ++i) f[i] = i;     for (int i = 0; i < n; ++i) {       if (d[i])         link(sd[i][1], sd[i][2]), link(sd[i][1] + m, sd[i][2] + m);       else         link(sd[i][1], sd[i][2] + m), link(sd[i][1] + m, sd[i][2]);     }     for (int i = 0; i < m; ++i)       if (Find(i) == Find(i + m)) {         cout <<  NO ;         return 0;       }     cout <<  YES ;   }