#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f;   template <typename T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <typename T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <typename T>   T read(T &first) {     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (first = 0; isdigit(ch); ch = getchar()) first = 10 * first + ch -  0 ;     return first *= f;   }   template <typename T>   void write(T first) {     if (first < 0) {       putchar( - );       first = -first;     }     static char s[20];     int top = 0;     for (; first; first /= 10) s[++top] = first % 10 +  0 ;     if (top == 0)       putchar( 0 );     else       while (top) putchar(s[top--]);   }   const int MAXN = 1e5 + 5, MAXK = 6;   struct Line {     int a, b, c;     int id;     bool on(const std::pair<double, double> &p) {       static double EPS = 1e-8;       return std::fabs(a * p.first + b * p.second + c) < EPS;     }   };   int N, K;   Line A[MAXN];   std::pair<int, int> ans[MAXN];   int anssize;   int st[MAXN];   inline bool intersection(const Line &a, const Line &b,                            std::pair<double, double> &p) {     long long d = (long long)a.b * b.a - (long long)b.b * a.a;     if (d == 0) return false;     p.first = (double)((long long)b.b * a.c - (long long)a.b * b.c) / d;     p.second = (double)((long long)b.c * a.a - (long long)a.c * b.a) / d;     return true;   }   bool dfs(int n, int k) {     if (n <= k) {       for (int i = 0; i < n; ++i) {         ans[anssize++] = std::make_pair(A[i].id + 1, -1);       }       return true;     }     if (k == 0) return false;     for (int i = n - k - 1; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         std::pair<double, double> p;         if (intersection(A[i], A[j], p) == false) continue;         ans[anssize++] = std::make_pair(A[i].id + 1, A[j].id + 1);         int m = n, top = 0;         for (int k = n - 1; k >= 0; --k) {           if (A[k].on(p)) {             st[++top] = k;             std::swap(A[k], A[--m]);           }         }         if (dfs(m, k - 1) == true) return true;         --anssize;         while (top > 0) {           std::swap(A[st[top--]], A[m++]);         }       }     }     return false;   }   void input() {     read(N);     read(K);     for (int i = 0; i < N; ++i) {       read(A[i].a);       read(A[i].b);       read(A[i].c);       A[i].id = i;     }   }   void solve() {     srand(time(NULL));     if (N >= K * K * K) {       int times = 100;       while (times-- && N > 0 && K > 0) {         int i = rand() % N;         int j = rand() % N;         std::pair<double, double> p;         if (i == j || intersection(A[i], A[j], p) == false) continue;         int top = 0;         for (int k = N - 1; k >= 0; --k) {           if (A[k].on(p)) st[++top] = k;         }         if (top > K) {           ans[anssize++] = std::make_pair(A[i].id + 1, A[j].id + 1);           for (int k = 1; k <= top; ++k) {             A[st[k]] = A[--N];           }           --K;         }       }     }     bool haveAns = dfs(N, K);     if (haveAns) {       puts( YES );       write(anssize);       putchar(  n );       for (int i = 0; i < anssize; ++i) {         write(ans[i].first);         putchar(   );         write(ans[i].second);         putchar(  n );       }     } else       puts( NO );   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num = 0;     int n;     cin >> n;     int d;     int sh[n];     cin >> d;     for (int i = 0; i < n; i++) cin >> sh[i];     for (int i = 0; i < n; i++) {       for (int k = i + 1; k < n; k++) {         if (abs(sh[i] - sh[k]) <= d) num += 2;       }     }     cout << num;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> Map;   int n, m, i, j;   long long ans;   string s;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s;       m = s.size();       bool cnt[30];       for (j = 0; j < 26; j++) cnt[j] = 0;       for (j = 0; j < m; j++) cnt[s[j] -  a ] ^= 1;       int aux1 = 0;       for (j = 0; j < 26; j++) {         aux1 <<= 1;         aux1 |= cnt[j];       }       for (j = 0; j < 26; j++) ans += Map[aux1 ^ (1 << j)];       ans += Map[aux1];       Map[aux1]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int n;     scanf( %lld , &n);     printf( %lld n , n / 2 + 1);     long long int count1 = 0;     long long int count2 = 1;     for (int i = 1; i <= n; i++) {       if (i % 2 == 0) {         count2++;       } else {         count1++;       }       printf( %lld %lld n , count1, count2);     }     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-4, pi = acos(-1.0);   const int maxS = 1e3 + 13;   const int maxT = 20;   const long long MOD = 1e9 + 7;   using namespace std;   struct point {     int x, y;   };   struct rs {     int x, y, z;   };   int n, m, i, j, k, x, y, z, S, T, ii, s, t, l, r, pos, len;   int tot = 0, ans = 0, res = 0, kase = 0, cnt = 0;   bool chk[maxS][maxS], flag = true;   string s1, s2;   char ch[maxS][maxS];   vector<rs> v;   point dr[5] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {0, 0}};   bool fk(int x, int y, int len) {     if (x - len < 0 || y - len < 0 || x + len >= n || y + len >= m) return false;     int i;     for (i = x - len; i <= x + len; i++)       if (ch[i][y] ==  . ) return false;     for (i = y - len; i <= y + len; i++)       if (ch[x][i] ==  . ) return false;     for (i = x - len; i <= x + len; i++) chk[i][y] = false;     for (i = y - len; i <= y + len; i++) chk[x][i] = false;     v.push_back({x, y, len});     return true;   }   bool ok(int x, int y) {     int i, j, k, len;     for (k = 0; k < 5; k++) {       for (i = 1; i < max(n, m); i++)         if (fk(x + dr[k].x * i, y + dr[k].y * i, i)) return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         cin >> ch[i][j];         if (ch[i][j] ==  * ) chk[i][j] = true;       }     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (flag && chk[i][j] && !ok(i, j)) flag = false;     if (!flag)       cout << -1 << endl;     else {       cout << v.size() << endl;       for (auto t : v) cout << t.x + 1 <<     << t.y + 1 <<     << t.z << endl;     }     return 0;   }


#include <bits/stdc++.h>      #define int long long   using namespace std;      const int MAX = 505;   int n, MOD, fact[MAX], C[MAX][MAX], f[2][MAX * MAX];      int getMaxInv(int x) {       return (x - 1) * x / 2;   }      int32_t main() {   #ifdef ACM       freopen( input ,  r , stdin);   #endif       cin >> n >> MOD;       fact[0] = 1;       for (int i = 1; i <= n; i++)           fact[i] = fact[i - 1] * i % MOD;       C[0][0] = 1;       for (int i = 1; i <= n; i++) {           C[i][0] = C[i][i] = 1;           for (int j = 1; j < n; j++)               C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }       int rs = 0;       for (int i = 0; i < n; i++) {           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = 0;           f[i % 2][0] = 1;           for (int inv = 1; inv <= getMaxInv(i); inv++) {               int l = inv - min(i, inv + 1) + 1, r = inv;               f[i % 2][inv] = (f[1 - i % 2][r] - (l == 0 ? 0 : f[1 - i % 2][l - 1]) + MOD) % MOD;           }           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = (f[i % 2][j] + f[i % 2][j - 1]) % MOD;           for (int inv = 2; inv <= getMaxInv(i); inv++) {               int t1 = (f[i % 2][inv] - f[i % 2][inv - 1] + MOD) % MOD;               for (int t = 1; t <= min(i, inv - 1); t++) {                   int t2 = f[i % 2][inv - t - 1];                   int pickCnt = i - t + 1;                   rs = (rs + t1 * t2 % MOD * pickCnt % MOD * fact[n - i - 1] % MOD * C[n][i + 1]) % MOD;               }           }       }       cout << rs;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> s[300005];   int main() {     int n, a, b, c, d, start, len;     scanf( %d %d %d %d %d %d %d , &n, &a, &b, &c, &d, &start, &len);     for (int i = 0; i < n; i++) scanf( %d %d , &s[i].first, &s[i].second);     long long sum = 0, res = 0, ans = start;     int j = 0;     for (int i = 0; i < n; i++) {       while (j < n && s[j].first - s[i].first < len) {         sum += (s[j].second ? c : -d);         res = min(res, sum);         j++;       }       if (ans + res >= 0) {         if (!i)           printf( %d n , 0);         else           printf( %d n , s[i - 1].first + 1);         return 0;       }       ans += (s[i].second == 0 ? -b : a);       sum -= (s[i].second == 0 ? -d : c);       res -= (s[i].second == 0 ? -d : c);       if (ans < 0) {         printf( -1 n );         return 0;       }     }     printf( %d n , s[n - 1].first + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int x1, y1, x2, y2;     scanf( %d%d%d%d , &x1, &y1, &x2, &y2);     int res = abs(x1 - x2) + 1 + (x1 == x2);     res += abs(y1 - y2) + 1 + (y1 == y2);     printf( %d n , res * 2);   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   long long int tc, cnt = 0, number, many, total = 0, query, require;   int rmove[8] = {1, 0, -1, 0, -1, 1, -1, 1};   int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1};   long long int modpow(long long int x, long long int y, long long int m) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % m;       x = (x * x) % m;       y >>= 1;     }     return res;   }   long long int dist[305][305], path[305][305];   void FloydWarshall() {     for (int i = 0; i < many; i++) {       for (int j = 0; j < many; j++) {         for (int k = 0; k < many; k++) {           if (dist[j][i] + dist[i][k] < dist[j][k]) {             dist[j][k] = dist[j][i] + dist[i][k];             path[j][k] = path[i][k];           }         }       }     }   }   vector<int> answer;   void printPath(int a, int b) {     if (path[a][b] == a) return;     printPath(a, path[a][b]);     answer.push_back(path[a][b]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> many;     for (int i = 0; i < many; i++) {       for (int j = 0; j < many; j++) {         dist[i][j] = 1e18;         path[i][j] = i;       }       dist[i][i] = 0;       path[i][i] = -1;     }     for (int i = 0; i < many - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       dist[a][b] = 1;       dist[b][a] = 1;     }     for (int i = 1; i < many; i++) {       int sum = 0;       for (int j = 0; j < many; j++) {         if (i == j) continue;         if (dist[i][j] == 1) sum++;       }       if (sum == 1) number++;     }     vector<int> vec;     vec.resize(number);     for (int i = 0; i < number; i++) {       cin >> vec[i];       vec[i]--;     }     FloydWarshall();     int now = 0;     answer.push_back(now);     for (int i = 0; i < number; i++) {       printPath(now, vec[i]);       answer.push_back(vec[i]);       now = vec[i];     }     printPath(now, 0);     answer.push_back(0);     if (answer.size() == 2 * many - 1) {       for (int i = 0; i < answer.size(); i++) cout << answer[i] + 1 <<    ;     } else       cout << -1;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, k;   int arr[51];   char color[51];   int mem[51][2501];   int solve(int i, char last, int num, int sum) {     if (sum >= k) {       return 0;     }     if (~mem[i][sum]) return mem[i][sum];     int ch1 = 1e9;     for (int j = 0; j < n; j++) {       if (arr[j] > num && last != color[j])         ch1 = min(ch1, solve(j, color[j], arr[j], sum + arr[j]) + abs(i - j));     }     return mem[i][sum] = ch1;   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     cin >> n >> s >> k;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       cin >> color[i];     }     memset(mem, -1, sizeof mem);     int ans = 1e9;     for (int i = 0; i < n; i++) {       ans = min(solve(i, color[i], arr[i], arr[i]) + abs(s - 1 - i), ans);     }     if (ans != 1e9)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   const long long N = 1e6 + 17, mo = 1e9 + 7;   long long f[N][2], n, h[N];   inline long long min(long long x, long long y) { return x > y ? y : x; }   inline long long quickmod(long long x) { return x >= mo ? x - mo : x; }   signed main() {     std::ios::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> h[i];       --h[i];     }     f[1][0] = h[1];     f[1][1] = min(h[1], h[2]);     long long ans = f[1][0];     for (long long i = 2; i <= n; ++i) {       f[i][0] = quickmod(h[i] + min(h[i], h[i - 1]) * f[i - 1][1] % mo);       f[i][1] = quickmod(min(h[i], h[i + 1]) +                          min(min(h[i], h[i - 1]), h[i + 1]) * f[i - 1][1] % mo);       ans = quickmod(ans + f[i][0]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int head[444444], to[444444], cap[444444], dist[444444], nxt[444444],       cur[444444], tnode[444444], mx, ans, tp, cnp, L[444444], R[444444];   int n, m, s, t, cnt, x, y, z;   bool used[444444];   void addedge(int s, int t, int cps, int cpt) {     cnt++;     nxt[cnt] = head[s];     head[s] = cnt;     to[cnt] = t;     cap[cnt] = cps;     cnt++;     nxt[cnt] = head[t];     head[t] = cnt;     to[cnt] = s;     cap[cnt] = cpt;   }   void bfs() {     memset(dist, -1, sizeof(dist));     queue<int> q;     q.push(s);     dist[s] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = head[x]; i; i = nxt[i]) {         if (!cap[i]) continue;         if (!~dist[to[i]]) {           dist[to[i]] = dist[x] + 1;           q.push(to[i]);         }       }     }   }   int dfs(int i, int f) {     if (i == t) return f;     int tmp = f;     for (int &j = cur[i]; j; j = nxt[j]) {       if (!cap[j] || dist[to[j]] != dist[i] + 1) continue;       int d = dfs(to[j], min(cap[j], f));       if (d) {         cap[j] -= d;         cap[j ^ 1] += d;         tmp -= d;         if (!tmp) break;       } else         dist[to[j]] = 0;     }     return f - tmp;   }   int dinic() {     int res = 0;     while (1) {       for (int i = 1; i <= t; i++) cur[i] = head[i];       bfs();       if (!~dist[t]) break;       res += dfs(s, 1e9);     }     return res;   }   void build(int l, int r, int node) {     mx = max(mx, node);     L[node] = l;     R[node] = r;     if (l == r) {       tnode[l] = node;       return;     }     int mid = (l + r) >> 1;     build(l, mid, node << 1);     build(mid + 1, r, (node << 1) | 1);     addedge(node, node << 1, inf, 0);     addedge(node, (node << 1) | 1, inf, 0);   }   void update(int beg, int en, int l, int r, int node, int p) {     if (l > en || r < beg) return;     if (l >= beg && r <= en) {       addedge(p, node, 1, 0);       return;     }     int mid = (l + r) >> 1;     update(beg, en, l, mid, node << 1, p);     update(beg, en, mid + 1, r, (node << 1) | 1, p);   }   int Search(int l, int r, int node) {     if (l == r) return l;     int mid = (l + r) >> 1;     for (int j = head[node]; j; j = nxt[j]) {       if (cap[j ^ 1] &&           ((to[j] == (node << 1)) || (to[j] == ((node << 1) | 1)))) {         cap[j ^ 1]--;         if (to[j] == (node << 1)) return Search(l, mid, node << 1);         return Search(mid + 1, r, (node << 1) | 1);       }     }   }   int main() {     cnt = 1;     scanf( %d%d , &n, &m);     build(1, m, 1);     s = n + mx + 1;     t = s + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &tp);       if (!tp) {         scanf( %d , &cnp);         for (int j = 1; j <= cnp; j++) {           scanf( %d , &x);           addedge(mx + i, tnode[x], 1, 0);         }         addedge(s, mx + i, 1, 0);       } else if (tp == 1) {         scanf( %d%d , &x, &y);         update(x, y, 1, m, 1, mx + i);         addedge(s, mx + i, 1, 0);       } else {         scanf( %d%d%d , &x, &y, &z);         used[x] = used[y] = 1;         ans += 2;         addedge(mx + i, tnode[x], 0, 1);         addedge(mx + i, tnode[y], 0, 1);         addedge(mx + i, tnode[z], 1, 0);         addedge(s, mx + i, 0, 2);       }     }     for (int i = 1; i <= m; i++) {       if (!used[i])         addedge(tnode[i], t, 1, 0);       else         addedge(tnode[i], t, 0, 1);     }     ans += dinic();     printf( %d n , ans);     for (int i = 1; i <= n; i++) {       for (int j = head[mx + i]; j; j = nxt[j]) {         if (!cap[j] && to[j] != s) {           printf( %d %d n , i, Search(L[to[j]], R[to[j]], to[j]));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<set<int> > arr;   long long res = 0;   void dfs(int vertex, int prev, int level) {     for (int v : arr[vertex]) {       if (v == prev) {         continue;       }       if (level == 2) {         res++;         continue;       } else {         dfs(v, vertex, level + 1);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     arr = vector<set<int> >(n + 1);     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       arr[a].insert(b);       arr[b].insert(a);     }     for (int i = 1; i <= n; ++i) {       dfs(i, -1, 1);     }     cout << res / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int arr[1001] = {0};     int n, i, others, temp;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &temp);       arr[temp]++;     }     for (i = 0; i < 1001; i++) {       if (!arr[i]) continue;       others = n - arr[i];       if (arr[i] - others > 1) {         puts( NO );         getchar();         getchar();         return 0;       }     }     puts( YES );     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, ans = 1, p, temp;     cin >> n >> k;     if (n == k) {       cout << 1;       return 0;     }     if (k == 1) {       cout << n;       return 0;     }     long long s, e, m;     s = 1, e = (n - 1) / 2;     while (s <= e) {       m = (s + e) / 2;       p = log2((n + 1) / (2 * m + 2)) + 1;       temp = 2 * ((1LL << p) - 1) + max(1 + n - (1LL << p) * 2 * m, 0LL);       if (temp >= k) {         s = m + 1;         ans = max(ans, 2 * m);       } else         e = m - 1;     }     s = 0, e = (n - 3) / 4;     while (s <= e) {       m = (s + e) / 2;       p = log2((n + 1) / (4 * m + 4)) + 1;       temp = 1 + 2 * ((1LL << p) - 1) +              max(1 + n - (1LL << (p + 1)) * (2 * m + 1), 0LL);       if (temp >= k) {         s = m + 1;         ans = max(ans, 2 * m + 1);       } else         e = m - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops, no-stack-protector )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int INF = int(1e9) + 99;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cout.tie(0);     int n;     string s;     cin >> n >> s;     vector<int> max_0(n + 1, 0);     vector<int> max_1(n + 1, 0);     for (int i = n - 1; i >= 0; --i) {       if (s[i] !=  0 ) max_1[i] = 1 + max_1[i + 1];       if (s[i] !=  1 ) max_0[i] = 1 + max_0[i + 1];     }     unordered_map<int, vector<int>> pos_0;     unordered_map<int, vector<int>> pos_1;     int c = 0;     while (c < n) {       if (c == 0 || s[c - 1] ==  1 ) {         for (int len = 1; len <= max_0[c]; ++len) {           pos_0[len].push_back(c);         }         c += max(max_0[c], 1);       } else {         ++c;       }     }     c = 0;     while (c < n) {       if (c == 0 || s[c - 1] ==  0 ) {         for (int len = 1; len <= max_1[c]; ++len) {           pos_1[len].push_back(c);         }         c += max(max_1[c], 1);       } else {         ++c;       }     }     for (int len = 1; len <= n; ++len) {       int pos = 0;       int ans = 0;       int index_0 = 0;       int index_1 = 0;       while (pos < n) {         int npos = INF;         if (max_0[pos] >= len) {           npos = min(npos, pos + len);         }         if (max_1[pos] >= len) {           npos = min(npos, pos + len);         }         while ((index_0 < (int)pos_0[len].size()) && (pos > pos_0[len][index_0]))           ++index_0;         while ((index_1 < (int)pos_1[len].size()) && (pos > pos_1[len][index_1]))           ++index_1;         if (index_0 < (int)pos_0[len].size()) {           npos = min(npos, pos_0[len][index_0] + len);         }         if (index_1 < (int)pos_1[len].size()) {           npos = min(npos, pos_1[len][index_1] + len);         }         if (npos != INF) {           ++ans;         }         pos = npos;       }       cout << ans <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   int main() {     int x, y, z, i, j, k, a, b, c, n, m, t, mat[210210];     scanf( %d , &t);     long long w, sum;     while (t--) {       scanf( %d %lld , &n, &w);       j = -1;       sum = 0;       c = 0;       for (x = 0; x < n; x++) {         scanf( %d , &mat[x]);         if (mat[x] >= (w + 1) / 2 && mat[x] <= w) j = x;         if (mat[x] <= w) sum += mat[x];       }       if (j != -1)         printf( 1 n%d n , j + 1);       else if (sum < (w + 1) / 2)         puts( -1 );       else {         x = -1;         if (sum > w) {           for (x = 0; x < n; x++) {             if (mat[x] > w) continue;             sum -= mat[x];             if (sum >= (w + 1) / 2 && sum <= w) break;           }         }         for (y = x + 1; y < n; y++)           if (mat[y] <= w) c++;         printf( %d n , c);         for (y = x + 1; y < n; y++)           if (mat[y] <= w) printf( %d  , y + 1);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int num;     std::cin >> num;     int arr1[num], arr2[num], sum1 = 0, sum2 = 0;     for (int i = 0; i < num; i++) {       std::cin >> arr1[i];       sum1 |= arr1[i];     }     for (int i = 0; i < num; i++) {       std::cin >> arr2[i];       sum2 |= arr2[i];     }     std::cout << sum1 + sum2 << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 37;   const long long INF = 1LL << 61;   int n, u, r;   long long sum;   int a[MAX_N], b[MAX_N], k[MAX_N], p[MAX_N];   void dfs(int dep, bool f) {     if ((u - dep) % 2 == 0) {       long long s = 0;       for (int i = 1; i <= n; ++i) {         s += (long long)a[i] * k[i];       }       sum = max(sum, s);     }     if (dep == u) return;     int t[MAX_N] = {0};     for (int i = 1; i <= n; ++i) {       t[i] = a[i];     }     if (!f) {       for (int i = 1; i <= n; ++i) {         a[i] = t[i] ^ b[i];       }       dfs(dep + 1, true);     }     for (int i = 1; i <= n; ++i) {       a[i] = t[p[i]] + r;     }     dfs(dep + 1, false);     for (int i = 1; i <= n; ++i) {       a[i] = t[i];     }   }   int main() {     scanf( %d%d%d , &n, &u, &r);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , b + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , k + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , p + i);     }     sum = -INF;     dfs(0, 0);     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, A[100005], B[100005], C[100005], sum, val;   pair<long long, long long> E[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> A[i];       C[A[i]]++;     }     for (int i = 1; i <= k; i++) {       if (C[i] == 0) val++;     }     for (int i = 1; i <= n; i++) {       cin >> B[i];       E[i].first = B[i];       E[i].second = A[i];     }     sort(E + 1, E + n + 1);     k = 1;     for (int i = 1; k <= val; i++) {       if (C[E[i].second] > 1) {         sum += E[i].first;         C[E[i].second]--;         k++;       }     }     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long T, n, s, sum;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     cin >> T;     while (T--) {       cin >> n;       sum = 0;       long long a[100010] = {0};       for (int i = 1; i <= n; i++) {         cin >> s;         a[i] += s;         if (a[i] > 0) a[i + 1] += a[i];         if (a[i] < 0) sum -= a[i];       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[1000005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) cin >> a[i];     dp[0] = 1;     for (int i = 0; i < n; i++) {       set<int> s;       for (int j = 1; j * j <= a[i]; j++) {         if (a[i] % j == 0) {           s.insert(j);           s.insert(a[i] / j);         }       }       for (set<int>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {         dp[*it] = (dp[*it] + dp[*it - 1]) % 1000000007;       }     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       ans = (ans + dp[i]) % 1000000007;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   long long p = 1e9 + 7, x;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x;     while (cin >> x)       cout << ((((x + 4) / 4) % p) * (((x + 6) / 4) % p)) % p <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 200005, mod = pow(10, 9) + 7;   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void create_array(vector<long long int>& a) {     for (long long int i = 1;; i++) {       if (i % 3 != 0 and i % 10 != 3) {         a.push_back(i);       }       if (a.size() == 1000) break;     }   }   void solve(vector<long long int>& a) {     long long int k;     cin >> k;     cout << a[k - 1] << endl;   }   int main() {     fast();     long long int t = 1;     vector<long long int> a;     create_array(a);     cin >> t;     while (t--) {       solve(a);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1000000007;   int main() {     long long n, s, a, t1, t2;     cin >> n;     s = n * 2;     vector<long long> v(s);     for (int i = 0; i < s; i++) {       cin >> a;       v[i] = a;     }     sort(v.begin(), v.end(), greater<long long>());     t1 = 0;     t2 = 0;     for (int i = 0; i < n; i++) {       t1 += v[i];     }     for (int i = v.size() - 1; i >= n; i--) {       t2 += v[i];     }     if (t1 == t2) {       cout << -1 <<   n ;     } else {       for (int i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void segmentedSieve(long long L, long long R) {     long long lim = sqrt(R);     vector<bool> mark(lim + 1, false);     vector<long long> primes;     for (long long i = 2; i <= lim; ++i) {       if (!mark[i]) {         primes.emplace_back(i);         for (long long j = i * i; j <= lim; j += i) mark[j] = true;       }     }     int buenos = 0;     long long len = ceil(sqrt(R - L + 1));     for (long long bloques = 0; bloques < len; ++bloques) {       long long l = L + len * bloques + 1;       if (bloques == 0) l = L;       long long r = min(R, L + len * (bloques + 1));       if (l > r) break;       vector<bool> isPrime(r - l + 1, true);       for (long long i : primes)         for (long long j = max(i * i, (l + i - 1) / i * i); j <= r; j += i)           isPrime[j - l] = false;       if (l == 1) isPrime[0] = false;       for (long long i = l; i <= r; ++i) {         if (i == 2 || (isPrime[i - l] && i % 4 == 1)) {           buenos++;         }       }     }     cout << buenos <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(20) << fixed;     long long l, r;     cin >> l >> r;     segmentedSieve(l, r);   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, k, i, o;     cin >> n >> k;     o = n - k;     for (i = 1; i <= o - 1; i++) cout << i <<    ;     for (i = n; i >= o; i--) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T By(T x, T y, T P) {     T F1 = 0;     while (y) {       if (y & 1) {         F1 += x;         if (F1 < 0 || F1 >= P) F1 -= P;       }       x <<= 1;       if (x < 0 || x >= P) x -= P;       y >>= 1;     }     return F1;   }   template <class T>   T Mul(T x, T y, T P) {     T F1 = 1;     x %= P;     while (y) {       if (y & 1) {         F1 = By(F1, x, P);       }       x = By(x, x, P);       y >>= 1;     }     return F1;   }   template <class T>   T Gcd(T x, T y) {     if (y == 0) return x;     T z;     while (z = x % y) {       x = y, y = z;     }     return y;   }   struct EDGE {     int T;     EDGE *Nxt;   };   template <class T>   void UpdataMin(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UpdataMax(T &x, T y) {     if (x < y) {       x = y;     }   }   int Dp[61][61][61];   int Map[61][61][61];   int NM[61][61];   int N, M, R, I, J, K;   int main() {     memset(Dp, 63, sizeof(Dp));     memset(NM, 63, sizeof(NM));     scanf( %d%d%d , &N, &M, &R);     for (int i = 0; i < (M); ++i) {       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k) scanf( %d , &Map[i][j][k]);       for (int l = 1; l <= (N); ++l)         for (int j = 1; j <= (N); ++j)           for (int k = 1; k <= (N); ++k)             if (Map[i][j][l] + Map[i][l][k] < Map[i][j][k])               Map[i][j][k] = Map[i][j][l] + Map[i][l][k];       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k) UpdataMin(NM[j][k], Map[i][j][k]);     }     for (int i = 1; i <= (N); ++i)       for (int j = 1; j <= (N); ++j) Dp[0][i][j] = NM[i][j];     for (int i = 1; i <= (60); ++i)       for (int j = 1; j <= (N); ++j)         for (int k = 1; k <= (N); ++k)           for (int l = 1; l <= (N); ++l)             UpdataMin(Dp[i][j][l], Dp[i - 1][j][k] + NM[k][l]);     while (R--) {       scanf( %d%d%d , &I, &J, &K);       if (K > 60) K = 60;       printf( %d n , Dp[K][I][J]);     }     scanf( %d , &N);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxn = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   int n, a[maxn];   int num[maxn];   int pre[maxn];   int lst[maxn];   int up = 500;   int mx = 0;   int c0[maxn], c[maxn];   void add(int x) {     c0[c[x]]--;     c[x]++;     c0[c[x]]++;     mx = max(mx, c[x]);   }   void sub(int x) {     c0[c[x]]--;     c[x]--;     c0[c[x]]++;     mx -= (c0[mx] == 0);   }   int solve1(int D) {     int res = 0;     for (int i = 1; i <= up; i++) {       memset(c, 0, sizeof(c)), memset(c0, 0, sizeof(c0));       mx = 0;       int k = 1, x = 0;       for (int j = 1; j <= n; j++) {         while (k <= n && x + (a[k] == D) <= i) add(a[k]), x += (a[k] == D), k++;         if (c0[mx] >= 2) res = max(res, k - j);         sub(a[j]), x -= (a[j] == D);       }     }     return res;   }   int solve2(int D, int V) {     int res = 0;     memset(pre, 0, sizeof(pre));     memset(lst, -1, sizeof(lst));     for (int i = 1; i <= n; i++) {       if (a[i] == D)         pre[i] = pre[i - 1] + 1;       else if (a[i] == V)         pre[i] = pre[i - 1] - 1;       else         pre[i] = pre[i - 1];     }     for (int i = n; i >= 1; i--) lst[pre[i]] = i;     lst[0] = 0;     for (int i = 1; i <= n; i++) res = max(res, i - lst[pre[i]]);     return res;   }   int main() {     std::ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], num[a[i]]++;     int mx = 0, mx_id = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       if (num[i] > mx)         mx = num[i], mx_id = i, cnt = 1;       else if (num[i] == mx)         cnt++;     }     if (cnt > 1) {       cout << n <<   n ;       return 0;     }     int D = mx_id;     int ans = 0;     ans = max(ans, solve1(D));     for (int V = 1; V <= n; V++) {       if (V == D) continue;       if (num[V] > up) ans = max(ans, solve2(D, V));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000007;   int n;   long long x[1 << 20];   long long y[1 << 20];   long long d[1 << 20];   long long sx[1 << 20];   long long sy[1 << 20];   long long sd[1 << 20];   long long ssd[1 << 20];   long long cirsm(int s, int v, long long sa[] = sd) {     long long ar = 0;     if (s > 0 && v > s) {       ar = sa[v - 1] - sa[s - 1];     } else if (s == 0) {       ar = sa[v - 1];     } else {       ar = sa[n + v - 1] - sa[s - 1];     }     return ar;   }   long long area(int s, int v) {     long long ar = cirsm(s, v);     ar += (x[s] - x[v]) * (y[s] + y[v]);     return ar;   }   long long sumsd2(int s, int v) {     long long ar = 0;     if (s == 0) {       ar = ssd[v - 1];     } else if (s < v) {       long long rm = (long long)(v - s) * (sd[s - 1] % mod);       rm = rm % mod;       if (rm < 0) {         rm += mod;       }       ar = (mod + ssd[v - 1] - ssd[s - 1] + mod - rm) % mod;     } else {       v += n;       long long rm = (long long)(v - s) * (sd[s - 1] % mod);       rm = rm % mod;       if (rm < 0) {         rm += mod;       }       ar = (mod + ssd[v - 1] - ssd[s - 1] + mod - rm) % mod;     }     return ar;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       long long xx, yy;       scanf( %lld %lld , &xx, &yy);       x[i + n] = x[i] = xx;       y[i + n] = y[i] = yy;     }     for (int i = 0; i < 2 * n; ++i) {       if (i + 1 < 2 * n) {         d[i] = (x[i + 1] - x[i]) * (y[i + 1] + y[i]);       } else {         d[i] = d[i - n];       }       if (i == 0) {         sx[i] = x[i];         sy[i] = y[i];         sd[i] = d[i];         ssd[i] = sd[i] % mod;         if (ssd[i] < 0) {           ssd[i] += mod;         }       } else {         sx[i] = sx[i - 1] + x[i];         sy[i] = sy[i - 1] + y[i];         sd[i] = sd[i - 1] + d[i];         ssd[i] = ssd[i - 1] + sd[i];         ssd[i] %= mod;         if (ssd[i] < 0) {           ssd[i] += mod;         }       }     }     long long S = sd[n - 1];     long long ans = 0;     int k = 1;     int v = 0;     long long dsm = 0;     while (k < n && 2 * area(0, k + 1) < S) {       ++k;       dsm += (x[k] - x[0]) * (y[k] + y[0]);       dsm %= mod;       if (dsm < 0) {         dsm += mod;       }     }     for (int i = 0; i < n; ++i) {       long long lt = cirsm(i, k) % mod;       if (lt < 0) {         lt += mod;       }       long long gt = cirsm(k, i) % mod;       if (gt < 0) {         gt += mod;       }       long long cnt = (k - 1 - i);       if (cnt < 0) {         cnt += n;       }       long long aa = 0;       aa = cnt * (cirsm(i + 1, k) % mod) - sumsd2(i + 1, k);       aa %= mod;       if (aa < 0) {         aa += mod;       }       if (cnt) {         long long ch = cnt * (gt - lt + mod) + aa + aa + 2LL * dsm;         ch %= mod;         ans += ch;         ans %= mod;         if (ans < 0) {           ans += mod;         }       }       if (i + 1 >= n) {         break;       }       if (k != (i + 1) % n) {         int j = (i + 2) % n;         dsm -= (x[j] - x[i]) * (y[j] + y[i]);         dsm %= mod;         if (dsm < 0) {           dsm += mod;         }       }       long long ndi = k - i - 2;       if (ndi < 0) {         ndi += n;       }       if (k != (i + 1) % n && k != (i + 2) % n) {         long long c = (x[i + 1] * y[i + 1] - x[i] * y[i]) % mod;         dsm = dsm - c * ndi;         dsm %= mod;         long long xsm = cirsm(i + 3, k + 1, sx) % mod;         dsm += xsm * (y[i + 1] - y[i]);         long long ysm = cirsm(i + 3, k + 1, sy) % mod;         dsm -= ysm * (x[i + 1] - x[i]);         dsm %= mod;         if (dsm < 0) {           dsm += mod;         }       }       if ((i + 1) == k) {         k = (i + 2) % n;       }       while ((unsigned long long)2LL *                  (unsigned long long)area(i + 1, (k + 1) % n) <              S) {         k = (k + 1) % n;         dsm += (x[k] - x[i + 1]) * (y[k] + y[i + 1]);         dsm %= mod;         if (dsm < 0) {           dsm += mod;         }       }     }     ans += mod;     ans %= mod;     printf( %lld n , (long long)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long a, b, c, d, e, f, k;   bool check(long long x, long long y) {     if (k == 0) {       return x == c && y == d;     }     return ((c - x) * e + (d - y) * f) % k == 0 &&            (e * (d - y) + f * (x - c)) % k == 0;   }   int main() {     while (cin >> a >> b >> c >> d >> e >> f) {       k = e * e + f * f;       if (check(a, b) || check(-a, -b) || check(b, -a) || check(-b, a)) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   const long double E = 1e-7;   unsigned char ccc;   bool _minus = false;   template <typename T>   inline T sqr(T t) {     return (t * t);   }   inline void read(long long &n) {     n = 0;     _minus = false;     while (true) {       ccc = getchar();       if (ccc ==     || ccc ==   n ) break;       if (ccc ==  - ) {         _minus = true;         continue;       }       n = n * 10 + ccc -  0 ;     }     if (_minus) n *= -1;   }   inline void read(int &n) {     n = 0;     _minus = false;     while (true) {       ccc = getchar();       if (ccc ==     || ccc ==   n ) break;       if (ccc ==  - ) {         _minus = true;         continue;       }       n = n * 10 + ccc -  0 ;     }     if (_minus) n *= -1;   }   char wwww[19];   int kkkk;   inline void write(long long y) {     long long x = y;     kkkk = 0;     if (!x)       ++kkkk, wwww[kkkk] =  0 ;     else       while (x) {         ++kkkk;         wwww[kkkk] = char(x % 10 +  0 );         x /= 10;       }     for (int i = kkkk; i >= 1; --i) putchar(wwww[i]);     putchar(   );   }   long long d, k, a, b, t;   long long get(long long x) {     long long ans = max(0LL, x - 1) * t + x * k * a + (d - x * k) * b;     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     srand(time(NULL));     cout.precision(10);     cout << fixed;     cin >> d >> k >> a >> b >> t;     long long ans = ((d - 1) / k) * t + d * a;     long long l = 0, r = d / k;     while (l + 10 < r) {       long long l1 = (l + l + r) / 3, r1 = (l + r + r) / 3;       if (get(l1) < get(r1)) {         r = r1;       } else {         l = l1;       }     }     for (long long i = l; i <= r; i++) ans = min(ans, get(i));     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     cin >> r >> c;     char mat[r + 5][c + 5];     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         cin >> mat[i][j];       }     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         if (mat[i][j] ==  B ) {           int rw = 0, cl = 0;           for (int k = j; k <= c; k++) {             if (mat[i][k] ==  B )               cl++;             else               break;           }           for (int k = i; k <= r; k++) {             if (mat[k][j] ==  B )               rw++;             else               break;           }           cout << i + rw / 2 <<     << j + cl / 2 << endl;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int t[100003] = {0};   int main() {     int L, b, f, n;     scanf( %d%d%d%d , &L, &b, &f, &n);     t[L] = 1000;     for (int i = 1; i <= n; i++) {       int req, len;       scanf( %d%d , &req, &len);       if (req == 1) {         bool e = 0;         for (int a = 0; a < L; a++) {           if (t[a]) continue;           int prev = a;           for (int c = a + 1; c <= L; c++) {             a = c;             if (t[c]) {               if (prev == 0 && c == L && L - prev >= len) {                 for (int j = 0; j < len; j++) t[j] = i;                 printf( 0 n );                 e = 1;               } else if (prev == 0 && c >= len + f) {                 for (int j = 0; j < len; j++) t[j] = i;                 printf( 0 n );                 e = 1;               } else if (c == L && L - prev >= len + b ||                          c - prev >= len + b + f) {                 for (int j = prev + b; j < prev + b + len; j++) t[j] = i;                 printf( %d n , prev + b);                 e = 1;               }               break;             }           }           if (e) break;         }         if (!e) printf( -1 n );       } else {         for (int j = 0; j < L; j++)           if (t[j] == len) t[j] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200009;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[n + 5];       long long na[n + 5];       for (long long i = 1; i <= n; i++) {         cin >> a[i];         na[i] = a[i];       }       sort(na + 1, na + n + 1);       long long p[m + 5];       unordered_map<long long, long long> mp;       for (long long i = 1; i <= m; i++) {         cin >> p[i];         mp[p[i]] = 1;       }       for (long long i = 1; i <= n; i++) {         for (long long i = 1; i < n; i++) {           if (mp[i] == 1 && a[i] > a[i + 1]) {             swap(a[i], a[i + 1]);           }         }       }       long long f = 1;       for (long long i = 1; i <= n; i++) {         if (a[i] != na[i]) {           f = 0;           cout <<  NO                 <<   n ;           break;         }       }       if (f == 1) {         cout <<  YES               <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   int arr[500];   int main() {     int k, n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       if (a % 2) {         cout <<  First  << endl;         return 0;       }     }     cout <<  Second  << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[30010][210][2][2][2];   int pd[30010][210][2][2][2];   int v[30010];   int n, K;   int solve(int ind, int cut, int s1, int s2, int tem) {     if (cut == K) return 0LL;     if (ind == n) return -0x3f3f3f3f;     int &ans = pd[ind][cut][s1][s2][tem];     if (vis[ind][cut][s1][s2][tem]) return ans;     int p1, p2;     if (s1)       p1 = 1;     else       p1 = -1;     if (s2)       p2 = 1;     else       p2 = -1;     if (cut == 0) p1 = 0LL;     if (cut == K - 1) p2 = 0LL;     vis[ind][cut][s1][s2][tem] = true;     ans = -0x3f3f3f3f;     int x = v[ind] * (p1 + p2);     if (tem) {       ans = max(x + solve(ind + 1, cut + 1, s2 ^ 1, 0, 0),                 x + solve(ind + 1, cut + 1, s2 ^ 1, 1, 0));       ans = max(ans, x + solve(ind + 1, cut, s1, s2, tem));     } else {       ans = max(ans, solve(ind + 1, cut, s1, s2, 0));       ans = max(ans, x + solve(ind + 1, cut, s1, s2, 1));       ans = max(ans, x + solve(ind + 1, cut + 1, s2 ^ 1, 0, 0));       ans = max(ans, x + solve(ind + 1, cut + 1, s2 ^ 1, 1, 0));     }     return ans;   }   int main() {     scanf(  %d %d , &n, &K);     for (int i = 0; i < (n); ++i) scanf(  %d , &v[i]);     int ans = max(solve(0, 0, 0, 0, 0), solve(0, 0, 0, 1, 0));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (1 << 19);   string str;   vector<pair<int, char> > sorted;   int cnt[MX], done[MX], K;   int main() {     cin >> str >> K;     for (int j = 0; j < str.size(); j++) cnt[str[j] -  a ]++;     for (int j = 0; j < 26; j++) {       sorted.push_back(make_pair(cnt[j], j +  a ));     }     sort(sorted.begin(), sorted.end());     int ans = 26;     for (auto pp : sorted) {       if (pp.first > K) break;       K -= pp.first;       done[pp.second] = 1;       --ans;     }     cout << ans << endl;     for (auto ch : str)       if (!done[ch]) cout << ch;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool isSubSequence(string str1, string str2, int m, int n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   int main() {     string s, t;     cin >> s >> t;     int i, j;     int arr1[26] = {0}, arr2[26] = {};     int m = s.length();     int n = t.length();     if (isSubSequence(t, s, n, m) == true) {       cout <<  automaton  << endl;       return 0;     }     for (i = 0; i < s.length(); i++) {       arr1[int(s[i]) - 97]++;     }     for (i = 0; i < t.length(); i++) {       arr2[int(t[i]) - 97]++;     }     int flag = 0;     if (s.length() == t.length()) {       for (i = 0; i < 26; i++) {         if (arr1[i] != arr2[i]) {           flag = 1;           break;         }       }       if (flag == 0) {         cout <<  array  << endl;         return 0;       } else {         cout <<  need tree  << endl;         return 0;       }     }     for (i = 0; i < 26; i++) {       if (arr1[i] < arr2[i]) {         cout <<  need tree  << endl;         return 0;       }     }     cout <<  both  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     long long a[m];     for (int i = 0; i < m; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i < m; i++) {       long long maxi = 0;       for (char c =  A ; c <=  E ; c++) {         long long temp = 0;         for (int j = 0; j < n; j++) {           if (s[j][i] == c) temp += a[i];         }         maxi = max(temp, maxi);       }       ans += maxi;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int d4x[4] = {1, 0, -1, 0};   int d4y[4] = {0, 1, 0, -1};   int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long oo = 1e18;   const long long maxN = 1e6;   void maximize(int &a, int b) { a = max(a, b); }   void minimize(int &a, int b) { a = min(a, b); }   int cnt[15];   void solve() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;       int g = 0, b, d = 0;       b = n + 1;       for (int j = 1; j <= 10; j++) {         if (cnt[j] > 0) {           cnt[j]--;           int p = 0;           bool ok = true;           for (int k = 1; k <= 10; k++) {             if (cnt[k]) {               if (!p)                 p = cnt[k];               else if (p != cnt[k])                 ok = false;             }           }           cnt[j]++;           if (ok) ans = i;         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, ddd = 0;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   char s[20];   int m;   long long dp[1 << 18][110];   int cnt[20];   int main() {     ios::sync_with_stdio(false);     cin >> s >> m;     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     dp[0][0] = 1;     int l = strlen(s);     long long x = 1 << l, d = 1;     for (int i = 0; i < l; i++) d *= ++cnt[s[i] -  0 ];     for (int i = 0; i < x; i++) {       for (int j = 0; j < l; j++) {         if (!(i & (1 << j)) && (i || s[j] -  0 )) {           for (int k = 0; k < m; k++) {             if (dp[i][k])               dp[i | (1 << j)][(k * 10 + (s[j] -  0 )) % m] += dp[i][k];           }         }       }     }     cout << dp[x - 1][0] / d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, s, x;     map<long long, long long> mp;     map<long long, long long>::iterator it;     cin >> n;     s = 0;     for (i = 0; i < n; i++) {       cin >> x;       s += x;       mp[s]++;     }     i = -1;     for (it = mp.begin(); it != mp.end(); it++) {       i = max(i, it->second);     }     cout << n - i <<   n ;   }


#include<bits/stdc++.h>   using namespace std;      #define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define ll long long int    #define all(v) (v).begin(), (v).end()   #define mp make_pair   #define pb push_back   #define pf push_front   #define ff first   #define ss second   #define lcm(a, b) ((a) * (b)) / __gcd(a, b)   #define umpit unordered_map<ll,ll>::iterator   #define mpit map<ll,ll>::iterator   #define setit set<ll>::iterator   #define mx(a) *max_element(all(a))   #define mn(a) *min_element(all(a))   #define yes cout<< YES n    #define no cout<< NO n    const ll INF = LLONG_MAX / 2;   #define PI 3.1415926535897932384626433832795   #define mod 1000000007      ll bin_exp_mod(ll a,ll n)   {       ll res=1;       a%=mod;       if(a==0)           return 0;       while(n)       {           if(n&1)               res=((res%mod)*(a%mod))%mod;           n=n>>1;           a=((a%mod)*(a%mod))%mod;       }       res%=mod;       return res;   }         int main()   {      FASTio;       #ifndef ONLINE_JUDGE                    //file start       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);          #endif                                  //file end       ll t,i,j;       cin>>t;       while(t--)       {           ll n,k;           cin>>n>>k;           while(k>3)           {               cout<< 1  ;               k--;               n--;           }           vector<ll>arr(k);           if(n%3 == 0)           {                              arr[0] = n/3;               arr[1] = n/3;               arr[2] = n/3;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%4 == 0)           {              arr[0] = n/2;               arr[1] = n/4;               arr[2] = n/4;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%2 == 0)           {                arr[0] = n/2 -1;               arr[1] = n/2 - 1;               arr[2] = 2;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }           if(n%2 == 1)           {                arr[0] = n/2;               arr[1] = n/2;               arr[2] = 1;               for(auto x : arr)                   cout<<x<<   ;               cout<<  n ;               continue;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void start(vector<int> &arr, pair<char, int> &prefAns, pair<char, int> &sufAns,              string &s) {     int i;     for (i = 0; i < s.size(); ++i) {       int cnt = 0;       while (i + 1 != s.size() && s[i] == s[i + 1]) {         ++cnt;         ++i;       }       arr[s[i]] = max(arr[s[i]], cnt + 1);     }     i = 0;     while (i + 1 != s.size() && s[i] == s[i + 1]) {       ++i;     }     prefAns = {s[0], i + 1};     i = s.size() - 1;     while (i - 1 != -1 && s[i] == s[i - 1]) {       --i;     }     sufAns = {s[s.size() - 1], s.size() - i};   }   char same(string &s) {     int res = s[0];     for (auto c : s) {       if (res != c) {         return -1;       }     }     return res;   }   void relax(vector<int> &ans, pair<char, int> &prefAns, pair<char, int> &sufAns,              string &s) {     for (auto c : s) {       ans[c] = max(ans[c], (sufAns.first == c) * sufAns.second + 1 +                                (prefAns.first == c) * prefAns.second);     }   }   int max(vector<int> &arr) {     int res = 0;     for (auto elem : arr) {       res = max(res, elem);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<string> arr(n);     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     vector<int> ans( z  + 1);     pair<char, int> prefAns;     pair<char, int> sufAns;     start(ans, prefAns, sufAns, arr[n - 1]);     bool flag = (same(arr[n - 1]) != -1);     for (int i = n - 2; i >= 0; --i) {       char c = same(arr[i]);       if (flag && (c != arr[n - 1][0])) {         c = arr[n - 1][0];         vector<int> tmpAns( z  + 1);         pair<char, int> tmpPrefAns;         pair<char, int> tmpSufAns;         start(tmpAns, tmpPrefAns, tmpSufAns, arr[i]);         ans[c] = ans[c] * (tmpAns[c] + 1) + tmpAns[c];         if (tmpPrefAns.first == c) {           prefAns = {               c, prefAns.second * (tmpPrefAns.second + 1) + tmpPrefAns.second};         }         if (tmpSufAns.first == c) {           sufAns = {c, sufAns.second * (tmpSufAns.second + 1) + tmpSufAns.second};         }         flag = false;         continue;       }       if (flag) {         ans[c] = ans[c] * (arr[i].size() + 1) + arr[i].size();         prefAns = {c, ans[c]};         sufAns = {c, ans[c]};       } else {         relax(ans, prefAns, sufAns, arr[i]);       }     }     cout << max(ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const long long llinf = 1e18;   const long long nax = 0;   long long n;   vector<long long> arr(5005);   vector<bool> ada(5005), masuk(5005);   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr.begin(), arr.begin() + n);     for (int i = 0; i < n; ++i) {       if (masuk[i]) {         continue;       }       for (int j = i + 1; j < n; ++j) {         if (arr[j] <= arr[i]) continue;         if (!ada[j]) {           masuk[i] = 1, ada[j] = 1;           break;         }       }     }     int ans = n;     for (int i = 0; i < n; ++i) {       if (masuk[i]) ans--;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int l, r;   long long pw[500007], inv[500007], ans = 0;   pair<int, int> p[500007];   const long long mod = 1e9 + 7;   long long pwr(long long x, long long y) {     if (y == 0) return 1LL;     if (y == 1) return x;     long long ret = pwr(x, y / 2);     if (y % 2 == 0)       return (ret * ret) % mod;     else       return (((ret * ret) % mod) * x) % mod;   }   long long C(long long k, long long n) {     if (k > n)       return 0;     else       return (((pw[n] * inv[k]) % mod) * inv[n - k]) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     inv[0] = 1;     pw[0] = 1;     for (long long i = 1; i <= 500000; i++) pw[i] = (pw[i - 1] * i) % mod;     inv[500000] = pwr(pw[500000], mod - 2);     for (long long i = 499999; i >= 1; i--) inv[i] = (inv[i + 1] * (i + 1)) % mod;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> l >> r;       p[i * 2 - 1] = make_pair(l, 1);       p[i * 2] = make_pair(r + 1, -1);     }     sort(p + 1, p + 1 + 2 * n);     long long cur = 1;     for (int i = 2; i <= 2 * n; i++) {       long long val = p[i].first - p[i - 1].first;       ans += (val * C(k, cur)) % mod;       if (ans >= mod) ans -= mod;       cur += p[i].second;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, d;     cin >> k >> d;     if (d == 0) {       if (k == 1)         cout << 0 << endl;       else         cout <<  No solution  << endl;     } else {       cout << d;       for (int i = 0; i < k - 1; i++) cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 100 * 1000 + 13;   queue<int> bfsq;   set<int> bfsS;   set<pair<int, int> > forbid;   vector<int> compV[MAXN], toDel;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       forbid.insert(make_pair(min(a, b), max(a, b)));     }     for (int i = 1; i <= n; i++) bfsS.insert(i);     int comp = 0;     while (!bfsS.empty()) {       comp++;       bfsq.push(*(bfsS.begin()));       bfsS.erase(bfsS.begin());       while (!bfsq.empty()) {         int u = bfsq.front();         compV[comp].push_back(u);         bfsq.pop();         for (auto v : bfsS)           if (forbid.find(make_pair(min(u, v), max(u, v))) == forbid.end()) {             toDel.push_back(v);             bfsq.push(v);           }         for (auto u : toDel) bfsS.erase(u);         toDel.clear();       }     }     cout << comp << endl;     for (int i = 1; i <= comp; i++) {       cout << compV[i].size() <<    ;       for (auto u : compV[i]) cout << u <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int N;   set<int> P;   void setP(long long int n, int x, int y) {     if (n > N) return;     if (n != 0) P.insert(n);     if (n != 0 || x != 0) setP(n * 10 + x, x, y);     if (n != 0 || y != 0) setP(n * 10 + y, x, y);   }   int main() {     cin >> N;     for (int i = 0; i < 10; i++) {       for (int j = i + 1; j < 10; j++) {         setP(0, i, j);       }     }     cout << P.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int hit[12];     string notes[12] = { C ,   C# ,  D ,   D# ,  E ,  F ,                          F# ,  G ,   G# ,  A ,   B ,  H };     string x, y, z;     cin >> x >> y >> z;     for (int i = 0; i < 12; i++) {       if (x == notes[i] || y == notes[i] || z == notes[i]) {         hit[i] = 1;       }     }     for (int i = 0; i < 12; i++) {       if (hit[i] == 1) {         if (hit[(i + 4) % 12] == 1 && hit[(i + 7) % 12] == 1) {           cout <<  major  << endl;           return 0;         } else if (hit[(i + 3) % 12] == 1 && hit[(i + 7) % 12] == 1) {           cout <<  minor  << endl;           return 0;         }       }     }     cout <<  strange  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, l, j;     char t;     char kb[100] =  qwertyuiopasdfghjkl;zxcvbnm,./ ;     char s[1000];     scanf( %c , &t);     scanf( %s , s);     l = strlen(s);     for (i = 0; i < l; i++) {       for (j = 0; j < 30; j++) {         if (kb[j] == s[i]) {           if (t ==  R ) {             printf( %c , kb[j - 1]);           } else if (t ==  L ) {             printf( %c , kb[j + 1]);           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long n, k, ans = 0;     cin >> n >> k;     if (k >= n / 2)       ans = (n * (n - 1)) / 2;     else {       ans = (n * (n - 1)) / 2 - (((n - k) * (n - k - 1)) / 2) + k * (n - 2 * k) +             (k * (k - 1)) / 2;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void runTest() {     long long int n, a, b, k;     cin >> n >> a >> b >> k;     long long int ans = 0;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int val;       cin >> val;       long long int temp =           ((val % (a + b) == 0) ? (val / (a + b)) - 1 : val / (a + b));       temp *= (a + b);       temp = val - temp;       temp = ((temp - 1) / a) + 1;       temp--;       if (temp <= 0)         ans++;       else         v.push_back(temp);     }     sort(v.begin(), v.end());     for (auto i : v) {       if (k >= i) {         ans++;         k -= i;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) runTest();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sum;   int main() {     cin >> n;     int ans = 0;     for (int i = 1; i <= 1000000; i++) {       sum += i;       ans += (n + i) % 3 == 0 && (n + i) / 3 >= sum;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ROOT = 0, MAXN = 100000;   const char WHITE = 0, GRAY = 1, BLACK = 2;   vector<int> graph[MAXN];   int n, m, a, b, i;   char k[MAXN] = {WHITE};   inline int dfs(const int& v = ROOT) {     k[v] = GRAY;     int i, t, p = -1;     for (i = 0; i < (int)(graph[v].size()); i++)       if (k[graph[v][i]] == WHITE) {         t = dfs(graph[v][i]);         if (t == -1) {           if (p == -1)             p = graph[v][i];           else {             printf( %d %d %d n , p + 1, v + 1, graph[v][i] + 1);             p = -1;           }         } else           printf( %d %d %d n , v + 1, graph[v][i] + 1, t + 1);       } else if (k[graph[v][i]] == BLACK) {         if (p == -1)           p = graph[v][i];         else {           printf( %d %d %d n , p + 1, v + 1, graph[v][i] + 1);           p = -1;         }       }     k[v] = BLACK;     return p;   }   int main() {     scanf( %d%d , &n, &m);     if (m & 1) {       printf( No solution n );       return 0;     }     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       a--;       b--;       graph[a].push_back(b);       graph[b].push_back(a);     }     assert(dfs() == -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r;   char s[110];   int main() {     scanf( %*d %s , s);     for (int i = 1; s[i]; i++) r += s[i] == s[i - 1];     printf( %d , r);   }


#include <bits/stdc++.h>   #pragma optimize( SEX_ON_THE_BEACH )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( fast-math )   #pragma GCC optimize( no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   using ll = long long int;   using ull = unsigned long long int;   using dd = double;   using ldd = long double;   namespace someUsefull {   template <typename T1, typename T2>   inline void checkMin(T1& a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   inline void checkMax(T1& a, T2 b) {     if (a < b) a = b;   }   const int _bitfunctions_size_ = 16;   const int _bitfunctions_mask_ = (1 << _bitfunctions_size_) - 1;   char* _bits_count_;   inline void _build_bits_count_() {     _bits_count_ = new char[1 << _bitfunctions_size_];     for (int i = 1; i < (1 << _bitfunctions_size_); ++i) {       _bits_count_[i] = _bits_count_[i >> 1];       if (i & 1) ++_bits_count_[i];     }   }   template <typename T1 = char, typename T2 = int>   inline T1 popcnt(T2 x) {     T1 ans = 0;     while (x) {       ans += _bits_count_[x & _bitfunctions_mask_];       x >>= _bitfunctions_size_;     }     return ans;   }   }  // namespace someUsefull   namespace operators {   template <typename T1, typename T2>   std::istream& operator>>(std::istream& in, std::pair<T1, T2>& x) {     in >> x.first >> x.second;     return in;   }   template <typename T1, typename T2>   std::ostream& operator<<(std::ostream& out, std::pair<T1, T2> x) {     out << x.first <<     << x.second;     return out;   }   template <typename T1>   std::istream& operator>>(std::istream& in, std::vector<T1>& x) {     for (auto& i : x) in >> i;     return in;   }   template <typename T1>   std::ostream& operator<<(std::ostream& out, std::vector<T1>& x) {     for (auto& i : x) out << i <<    ;     return out;   }   }  // namespace operators   using namespace std;   using namespace operators;   using namespace someUsefull;   vector<vector<int>> gr;   vector<pair<int, int>> ed;   vector<int> d;   void dfs(int v, int _d = 0, int p = -1) {     d[v] = _d;     for (int to : gr[v]) {       if (to != p) dfs(to, _d + 1, v);     }   }   struct Tree {     const int _size = 1 << 19;     int n, t;     vector<pair<int, int>> tree;     vector<int> upd;     vector<int> d;     vector<int> pre;     vector<int> tin, tout, tos;     void dfs(int v, int _d = 0, int p = -1) {       d[v] = _d;       pre[v] = p;       tin[v] = tos.size();       tos.push_back(v);       for (int to : gr[v]) {         if (to != p) dfs(to, _d + 1, v);       }       tout[v] = tos.size();     }     pair<int, int> merge(pair<int, int> a, pair<int, int> b) {       return {max(a.first, b.first), max(a.second, b.second)};     }     Tree(int v) {       tree.resize(_size << 1, {0, 0});       upd.resize(_size << 1, 0);       n = gr.size();       t = 0;       d.resize(n);       tin.resize(n);       tout.resize(n);       pre.resize(n);       0;       ;       dfs(v);       0;       ;       for (int i = 0; i < n; ++i) tree[_size + i].first = d[tos[i]];       for (int i = _size - 1; i > 0; --i)         tree[i] = merge(tree[i << 1], tree[i << 1 | 1]);     }     void change(int v) {       upd[v] ^= 1;       swap(tree[v].first, tree[v].second);     }     void push(int v) {       if (!upd[v]) return;       change(v << 1);       change(v << 1 | 1);       upd[v] = 0;     }     void update(int v, int l, int r, int fl, int fr) {       if (r <= l || r <= fl || fr <= l) return;       if (fl <= l && r <= fr) {         change(v);         return;       }       push(v);       update(v << 1, l, (r + l) >> 1, fl, fr);       update(v << 1 | 1, (r + l) >> 1, r, fl, fr);       tree[v] = merge(tree[v << 1], tree[v << 1 | 1]);     }     int add(int a, int b) {       if (pre[a] != b) swap(a, b);       update(1, 0, _size, tin[a], tout[a]);       return tree[1].first;     }   };   void solve(int test) {     int n;     cin >> n;     gr.resize(n);     vector<int> type(n - 1);     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b >> type[i];       --a;       --b;       ed.push_back({a, b});       gr[a].push_back(b);       gr[b].push_back(a);     }     d.resize(n);     d.assign(n, -1);     dfs(0);     int v = 0;     for (int i = 0; i < n; ++i)       if (d[v] < d[i]) v = i;     dfs(v);     int L = v;     int R = 0;     for (int i = 0; i < n; ++i)       if (d[R] < d[i]) R = i;     0;     ;     0;     ;     Tree LT(L), RT(R);     0;     ;     for (int i = 0; i < n - 1; ++i) {       if (type[i])         LT.add(ed[i].first, ed[i].second), RT.add(ed[i].first, ed[i].second);     }     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       --x;       int ans = 0;       checkMax(ans, LT.add(ed[x].first, ed[x].second));       checkMax(ans, RT.add(ed[x].first, ed[x].second));       cout << ans <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     _build_bits_count_();     cout << setprecision(12) << fixed;     int t = 1;     for (int i = 0; i < t; ++i) {       0;       ;       solve(i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int pushes = 0;     int buttons;     cin >> buttons;     for (int i = 1; i <= buttons; i++) {       pushes += 1 + (i * (buttons - i));     }     cout << pushes << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long cnt = 0;     int H;     scanf( %d  , &H);     ;     long long N;     cin >> N;     N--;     long long n = 0;     int d = 0;     for (int h = (0); h < (H); h++) {       long long msk = ((1LL) << (long long)(H - h - 1));       if (N & msk) {         if (d & 1)           cnt++;         else {           cnt += msk * 2LL;           d++;         }       } else {         if (d & 1) {           cnt += msk * 2LL;           d++;         } else           cnt++;       }       d++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   template <class T>   void dbs(string str, T t) {     cout << str <<   :   << t << endl;   }   template <class T, class... second>   void dbs(string str, T t, second... s) {     int idx = str.find( , );     cout << str.substr(0, idx) <<   :   << t <<  , ;     dbs(str.substr(idx + 1), s...);   }   template <class second, class T>   ostream& operator<<(ostream& os, const pair<second, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class second, class T>   ostream& operator<<(ostream& os, const map<second, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cout <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cout <<  ,  ;       cout << *i;     }     cout <<  ] ;     cout << endl;   }   struct pt {     int x, y;     pt(int x = 0, int y = 0) : x(x), y(y) {}     pt operator-(const pt& b) { return pt(x - b.x, y - b.y); }   };   int cross(pt x, pt y) { return y.y * x.x - y.x * x.y; }   bool inside(pt a, vector<pt> b) {     int ar = abs(cross(b[1] - b[0], b[2] - b[0])) +              abs(cross(b[2] - b[0], b[3] - b[0]));     for (auto i = (0); i <= (3); ++i)       ar -= abs(cross(b[i] - a, b[(i + 1) % 4] - a));     return ar == 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     vector<pt> a(4);     for (auto i = (0); i <= (3); ++i)       cin >> a[i].x >> a[i].y, a[i].x *= 4, a[i].y *= 4;     vector<pt> b(4);     for (auto i = (0); i <= (3); ++i)       cin >> b[i].x >> b[i].y, b[i].x *= 4, b[i].y *= 4;     pt A, B;     for (auto i = (0); i <= (3); ++i)       A.x += a[i].x, A.y += a[i].y, B.x += b[i].x, B.y += b[i].y;     A.x /= 4, A.y /= 4, B.x /= 4, B.y /= 4;     bool ans = inside(A, b) | inside(B, a);     for (auto i = (0); i <= (3); ++i) ans |= inside(a[i], b) | inside(b[i], a);     cout << (ans ?  YES n  :  NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p = 0;     scanf( %d , &n);     while (n--) {       int x;       scanf( %d , &x);       p = (p + x) % 2 + 1;       printf( %d n , p);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, t, b[100020], cnt, p, q;   char s[100020], s1[100020], s2[100020];   char chose(char x, char y) {     if (x !=  a  && y !=  a )       return  a ;     else if (x !=  b  && y !=  b )       return  b ;     else       return  c ;   }   int main() {     scanf( %d%d , &n, &t);     scanf( %s , s1);     scanf( %s , s2);     cnt = 0;     p = 0;     q = 0;     for (int i = 0; i < n; i++)       if (s1[i] != s2[i]) cnt++;     if (t < (cnt + 1) / 2) {       printf( -1 n );       return 0;     }     if (t <= cnt) {       for (int i = 0; i < n; i++) {         if (s1[i] == s2[i])           s[i] = s1[i];         else {           p++;           if (p <= 2 * t - cnt)             s[i] = chose(s1[i], s2[i]);           else if (p % 2 == 1)             s[i] = s1[i];           else             s[i] = s2[i];         }       }     } else {       for (int i = 0; i < n; i++) {         if (s1[i] == s2[i]) {           q++;           if (q <= t - cnt)             s[i] = chose(s1[i], s1[i]);           else             s[i] = s1[i];         } else {           p++;           s[i] = chose(s1[i], s2[i]);         }       }     }     printf( %s , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       int n, m;       cin >> n >> m;       vector<int> a(n), b(m);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < m; i++) {         cin >> b[i];       }       vector<int> idx(100001);       for (int i = 0; i < n; i++) {         idx[a[i]] = i;       }       long long ans = 0;       int mxDepth = 0;       for (int i = 0; i < m; i++) {         if (idx[b[i]] < mxDepth) {           ans++;         } else {           mxDepth = idx[b[i]];           ans += 2 * (idx[b[i]] - i) + 1;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   const int mod = 998244353;   int n;   map<int, int> a;   char s[N];   long long ans = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       int x = 0, l = strlen(s + 1);       for (int j = 1; j <= l; j++) x = x ^ (1 << (s[j] -  a ));       for (int j = 0; j < 26; j++) ans += a[x ^ (1 << j)];       ans += a[x];       a[x]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> working;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     working[-1] = -1;     working[2E9] = 2E9;     working[1] = n;     int answer = n;     while (q--) {       int l, r, k;       cin >> l >> r >> k;       int haveNow = 0;       map<int, int>::iterator it = working.lower_bound(l);       it--;       if (it->second >= l) {         working[l] = it->second;         it->second = l - 1;       }       it++;       while (it->first <= r) {         if (it->second > r) {           haveNow += r + 1 - it->first;           working[r + 1] = it->second;         } else           haveNow += it->second - it->first + 1;         map<int, int>::iterator it2 = it;         it++;         working.erase(it2);       }       if (k == 1) {         answer -= haveNow;       } else {         answer -= haveNow;         working[l] = r;         answer += r - l + 1;       }       cout << answer <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   void itval(istream_iterator<string> it) {}   template <typename T, typename... Args>   void itval(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     itval(++it, args...);   }   const long long int MOD = 1e9 + 7;   template <typename T>   inline void print(T x) {     cout << x <<   n ;   }   template <typename T>   inline void printvec(T x) {     for (auto a : x) cout << a <<    ;     cout <<   n ;   }   struct custom {     bool operator()(const pair<int, pair<int, int> > &p1,                     const pair<int, pair<int, int> > &p2) const {       return p1.first < p2.first;     }   };   long long int get_pow(long long int a, long long int b, long long int M = MOD) {     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }   const long long int N = 2600 + 5, inf = 2e18;   int lookup[N][N];   string longestPalindrome(string X, string Y, int m, int n) {     if (m == 0 || n == 0) {       return string(  );     }     if (X[m - 1] == Y[n - 1]) {       return longestPalindrome(X, Y, m - 1, n - 1) + X[m - 1];     }     if (lookup[m - 1][n] > lookup[m][n - 1]) {       return longestPalindrome(X, Y, m - 1, n);     }     return longestPalindrome(X, Y, m, n - 1);   }   int LCSLength(string X, string Y, int n) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (X[i - 1] == Y[j - 1]) {           lookup[i][j] = lookup[i - 1][j - 1] + 1;         } else {           lookup[i][j] = max(lookup[i - 1][j], lookup[i][j - 1]);         }       }     }     return lookup[n][n];   }   void solve() {     string s;     cin >> s;     int n = s.length();     if (n >= 2600) {       vector<long long> v(26, 0);       for (auto c : s) v[c -  a ]++;       for (long long int i = (long long int)0; i < (long long int)(26); i++) {         if (v[i] >= 100) {           for (long long int z = (long long int)0; z < (long long int)(100); z++)             cout << char( a  + i);           return;         }       }     }     string r = s;     reverse(r.begin(), r.end());     LCSLength(s, r, n);     string res = longestPalindrome(s, r, n, n);     if (res.length() <= 100) {       cout << res;       return;     }     string p =   ;     for (long long int i = (long long int)0; i < (long long int)(50); i++)       p.push_back(res[i]);     cout << p;     reverse(p.begin(), p.end());     cout << p;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test = 1;     clock_t z = clock();     for (long long int tes = (long long int)0; tes < (long long int)(test);          tes++) {       solve();     }     fprintf(stderr,  Total Time:%.4f n , (double)(clock() - z) / CLOCKS_PER_SEC),         fflush(stderr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   const double eps = 1e-8;   int t, n;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       if (n == 1)         puts( 0 );       else if (n == 2)         puts( 1 );       else {         int cnr = ceil(sqrt(n));         int cnt = (cnr - 1) * 2;         int a = cnr * cnr - n;         cout << cnt - a / cnr << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const int MAXM = 1e5 + 10;   const int INF = 1e9;   struct edge {     int u, v;     long long w;     int next;   } e[MAXM * 2];   int first[MAXN];   int idx;   int n;   long long len, wei;   struct node {     long long weight, dist;     int id;   } p[MAXN];   bool cmp(node x, node y) {     if (x.weight == y.weight) return x.dist < y.dist;     return x.weight < y.weight;   }   void add(int a, int b, long long c) {     e[idx].u = a;     e[idx].v = b;     e[idx].w = c;     e[idx].next = first[a];     first[a] = idx++;   }   void init() {     fill(first, first + n + 1, -1);     idx = 0;   }   namespace BIT {   long long c[MAXN];   int n;   int lowbit(int x) { return x & (-x); }   void updata(int i, int k) {     while (i <= n) {       c[i] += k;       i += lowbit(i);     }   }   long long getsum(int i) {     long long res = 0;     while (i > 0) {       res += c[i];       i -= lowbit(i);     }     return res;   }   void change(int x, int k) { updata(x, k); }   long long query(int l, int r) {     if (l <= 0 || r <= 0) return 0;     return getsum(r) - getsum(l - 1);   }   void init(int _n) {     n = _n;     fill(c, c + n + 1, 0);   }   };  // namespace BIT   int sz[MAXN], mson[MAXN], vis[MAXN];   int tolsize, root, tol;   long long res;   void get_root(int x, int fa) {     sz[x] = 1;     mson[x] = 0;     for (int i = first[x]; i != -1; i = e[i].next) {       int v = e[i].v;       if (vis[v] || v == fa) continue;       get_root(v, x);       sz[x] += sz[v];       if (sz[v] > mson[x]) mson[x] = sz[v];     }     if (tolsize - sz[x] > mson[x]) mson[x] = tolsize - sz[x];     if (mson[x] < mson[root]) root = x;   }   void get_dis(int x, int fa, long long w, long long l) {     p[++tol].weight = w;     p[tol].dist = l;     for (int i = first[x]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == fa || vis[v]) continue;       get_dis(v, x, w + e[i].w, l + 1);     }   }   int right_bound(int l, long long x) {     int ans = 0, r = tol;     while (l <= r) {       int mid = (l + r) >> 1;       if (p[mid].weight <= x)         ans = mid, l = mid + 1;       else         r = mid - 1;     }     return ans;   }   long long cal(int x, long long w, long long le) {     long long ans = 0;     tol = 0;     get_dis(x, 0, w, le);     sort(p + 1, p + tol + 1, cmp);     int l = 1;     BIT::init(tol + 1);     long long maxdist = 0;     for (int i = 1; i <= tol; i++) {       maxdist = max(maxdist, p[i].dist);       BIT::change(p[i].dist + 1, 1);     }     int last = tol;     while (l < tol && p[l].weight * 2 <= wei) {       BIT::change(p[l].dist + 1, -1);       while (p[l].weight + p[last].weight > wei && last > l) {         BIT::change(p[last].dist + 1, -1);         last--;       }       long long tmp = BIT::query(1, min(maxdist + 1, len - p[l].dist + 1));       ans += tmp;       l++;     }     return ans;   }   void solve(int x) {     vis[x] = 1;     res += cal(x, 0, 0);     for (int i = first[x]; i != -1; i = e[i].next) {       int v = e[i].v;       if (vis[v]) continue;       res -= cal(v, e[i].w, 1);       tolsize = sz[v];       root = 0;       get_root(v, x);       solve(root);     }   }   int main() {     scanf( %d%lld%lld , &n, &len, &wei);     init();     for (int i = 2; i <= n; i++) {       int v;       long long w;       scanf( %d%lld , &v, &w);       add(i, v, w);       add(v, i, w);     }     tolsize = n;     root = 0;     mson[0] = INF;     get_root(1, 0);     solve(root);     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nodes[2050], depth, score = 0;   int abs(int a) {     if (a > 0) return a;     return -a;   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int dfs(int d, int i, int total) {     if (d == depth) return nodes[i];     int r = dfs(d + 1, i * 2, 0);     int l = dfs(d + 1, i * 2 + 1, 0);     score += abs(r - l);     return max(r, l) + nodes[i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> depth;     for (size_t i = 2; i < pow(2, depth + 1); i++) cin >> nodes[i];     dfs(0, 1, 0);     cout << score;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     bool split(vector<int>& A, vector<int>& inc, vector<int>& dec) {       map<int, int> map;       for (int e : A) map[e]++;       for (const pair<int, int>& p : map) {         if (p.second > 2) return false;         inc.push_back(p.first);         if (p.second == 2) dec.push_back(p.first);       }       sort(dec.begin(), dec.end(), greater<int>());       return true;     }   };   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> inc, dec;     if (Solution().split(a, inc, dec)) {       cout <<  YES  << endl;       cout << inc.size() << endl;       for (int e : inc) cout << e <<    ;       cout << endl;       cout << dec.size() << endl;       for (int e : dec) cout << e <<    ;       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned int n;     cin >> n;     const int N = n;     unsigned int m[N], sum = 0;     for (int i(0); i < n; i++) {       cin >> m[i];       sum += m[i];     }     sort(m, m + n);     unsigned int myMonets = 0, count = 0;     for (int i(n - 1); i >= 0; i--) {       myMonets += m[i];       count++;       if (myMonets > (sum - myMonets)) break;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long base;   vector<long> vec[2000];   long can[200][200];   long lcm[200];   long long n, k;   vector<vector<long> > mult(vector<vector<long> > a, vector<vector<long> > b) {     vector<vector<long> > v;     v.resize(a.size());     for (int i = 0; i < v.size(); i++) v[i].resize(a[0].size());     for (int i = 0; i < v.size(); i++)       for (int j = 0; j < v.size(); j++) v[i][j] = 0;     for (int k = 0; k < v.size(); k++)       for (int i = 0; i < v.size(); i++)         for (int j = 0; j < v.size(); j++)           v[i][j] += a[i][k] * b[k][j], v[i][j] %= base;     return v;   }   vector<vector<long> > one(long sz) {     vector<vector<long> > v;     v.resize(sz);     for (int i = 0; i < v.size(); i++) v[i].resize(sz);     for (int i = 0; i < v.size(); i++)       for (int j = 0; j < v.size(); j++) v[i][j] = (i == j);     return v;   }   vector<vector<long> > pw(vector<vector<long> > a, long long b) {     if (b == 0) return one(a.size());     if (b % 2) return mult(a, pw(a, b - 1));     return pw(mult(a, a), b / 2);   }   vector<long> decomp(long state) {     vector<long> res;     for (int i = 25; i >= 0; --i)       if (vec[i].size())         res.push_back(state % lcm[i]), state /= lcm[i];       else         res.push_back(1);     reverse(res.begin(), res.end());     return res;   }   long mov(long a, long b) {     vector<long> v1, v2;     v1 = decomp(a);     v2 = decomp(b);     long free = 0;     long found = 0;     for (int i = 0; i < 26; i++) {       if (vec[i].size() == 0) continue;       if ((v1[i] + 1) % lcm[i] == v2[i]) {         if (lcm[i] == 1)           free++;         else if (found == 0)           found = 1;         else           return 0;       } else if (v1[i] != v2[i])         return 0;     }     if (found) return 1;     return free;   }   string st;   long val;   long total;   long gcd(long a, long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   vector<vector<long> > res;   bool bad(long x, long ps) {     for (int i = 0; i < vec[ps].size(); i++)       if (x % vec[ps][i] == 0) return false;     return true;   }   bool check(vector<long> v) {     for (long i = 0; i < 26; i++) {       if (vec[i].size() == 0) continue;       if (bad(v[i], i)) return false;     }     return true;   }   void show(vector<vector<long> > v) {     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < v[i].size(); j++) cout << v[i][j] <<    ;       cout << endl;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     base = 12345;     cin >> n >> k;     for (int i = 1; i <= k; i++) {       cin >> st >> val;       vec[st[0] -  A ].push_back(val);       can[st[0] -  A ][val] = 1;     }     total = 1;     for (int i = 0; i < 26; i++)       if (vec[i].size()) {         lcm[i] = 1;         for (int j = 0; j < vec[i].size(); j++) {           long q = vec[i][j];           lcm[i] = lcm[i] * q / gcd(lcm[i], q);         }         total *= lcm[i];       }     res.resize(total);     for (int i = 0; i < res.size(); i++) res[i].resize(total);     for (int i = 0; i < total; i++)       for (int j = 0; j < total; j++) res[i][j] = mov(i, j);     res = pw(res, n);     long ans = 0;     for (int i = 0; i < total; i++) {       vector<long> v = decomp(i);       if (check(v)) ans += res[0][i], ans %= base;     }     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 2e5 + 4;   int n, m, p[N], idx[N];   LL v1[N], v2[N];   vector<int> vals[N];   struct BIT {     int s[N];     void init() { memset(s, 0, sizeof(s)); }     void add(int i, int v) {       for (; i <= n; i += i & (-i)) s[i] += v;     }     LL get(int i) {       LL sum = 0;       for (; i; i -= i & (-i)) sum += s[i];       return sum;     }   } bit;   struct E {     int id, wh, v;     E() = default;     E(int _id, int _wh, int _v) : id(_id), wh(_wh), v(_v) {}     bool operator<(const E &rhs) const { return wh < rhs.wh; }   };   struct Q {     int l, r;   } qs[N];   vector<E> events;   int main() {     bit.init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , p + i);       idx[p[i]] = i;     }     for (int i = 1; i <= n; i++) {       if (!idx[i]) continue;       int ii = idx[i];       for (int j = i; j <= n; j += i) {         if (int ij = idx[j]) vals[ij].push_back(ii);       }     }     events.reserve(2 * m);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (l > 1) events.emplace_back(i, l - 1, 1);       if (r <= n) events.emplace_back(i, r, 2);       qs[i].l = l;       qs[i].r = r;     }     sort(events.begin(), events.end());     for (int i = 1, j = 0, es = events.size(); i <= n && j < es; i++) {       for (int v : vals[i]) bit.add(v, 1);       for (; j < es && events[j].wh == i; j++) {         if (events[j].v == 1)           v1[events[j].id] =               bit.get(qs[events[j].id].r) - bit.get(qs[events[j].id].l - 1);         else           v2[events[j].id] =               bit.get(qs[events[j].id].r) - bit.get(qs[events[j].id].l - 1);       }     }     for (int i = 1; i <= m; i++) {       printf( %lld n , v2[i] - v1[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long inf = 4e18;   const long long N = 1e6;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, m, k;       cin >> n >> m >> k;       char a[n][m];       bool pos[n][m];       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           cin >> a[i][j];           pos[i][j] = 0;         }       }       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           if (a[i][j] ==  . ) continue;           long long d = 0;           for (long long h = 1; h <= min({i, j, m - 1 - j}); h++) {             if (a[i - h][j - h] ==  *  && a[i - h][j + h] ==  * )               d++;             else               break;           }           if (d < k) continue;           pos[i][j] = 1;           for (long long h = 1; h <= min({i, j, m - 1 - j}); h++) {             if (a[i - h][j - h] ==  *  && a[i - h][j + h] ==  * )               pos[i - h][j - h] = 1, pos[i - h][j + h] = 1;             else               break;           }         }       }       bool boob = 1;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < m; j++) {           if (a[i][j] ==  *  && !pos[i][j]) boob = 0;         }       }       if (boob)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int a = 0, b = 0;     int i, j;     int n = s.size();     for (i = 1; i < n; ++i) {       if (s[i] ==  b  && s[i - 1] ==  a ) {         ++a;       }       if (s[i] ==  a  && s[i - 1] ==  b ) {         ++b;       }     }     if (a != b) {       if (s[0] ==  a )         s[0] =  b ;       else         s[0] =  a ;     }     cout << s <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test_case = 1;     cin >> test_case;     while (test_case-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   int n, m, i, ans;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &m), ans += (i + 1) * m;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int64_t dr8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int64_t dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int64_t dr4[] = {1, 0, 0, -1};   int64_t dc4[] = {0, 1, -1, 0};   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int64_t i, n, j, m, k, l, t;     int64_t x;     cin >> x;     while (x--) {       cin >> n;       vector<int64_t> v(n);       for (i = 0; i < n; i++) cin >> v[i];       for (i = 0; i < n / 2; i++) {         k = v[i];         v[i] = v[n - 1 - i];         v[n - 1 - i] = k;       }       for (i = 0; i < n; i++) cout << v[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     vector<int> b(a);     vector<int> c(a);     for (int i = 0; i < a; i++) {       cin >> b[i];       c[i] = b[i];     }     sort(b.begin(), b.end());     int i0 = 0, i1 = 0;     for (int i = 0; i < a; i++) {       if (c[i] == b[0]) i0 = i;       if (c[i] == b[a - 1]) i1 = i;     }     i1++;     i0++;     cout << max(max(max(abs(a - i0), abs(a - i1)), abs(1 - i0)), abs(1 - i1));   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& a) {     os <<  (  << a.first <<  ,  << a.second <<  ) ;     return os;   }   int main() {     int n, m;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < n; ++i)       if (a[i] == -1) {         for (int j = i; j >= 0; --j) a[j] = 0;         break;       }     priority_queue<int, vector<int>, greater<int>> que;     que.push(a[n - 1]);     long long ans = 0;     while (n > 1) {       m = n / 2;       ans += que.top();       que.pop();       for (int i = n - 2; i > n - 2 - m; --i) que.push(a[i]);       n >>= 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5, inf = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b, l, r;     cin >> a >> b >> l >> r;     l--;     r--;     long long int ans = 0;     long long int d = (l) / (a + b);     long long int st = d * (a + b);     long long int ed = min(r, l + 200);     string s;     long long int f = 0, c = a;     for (long long int i = st; i < l; ++i) {       c--;       if (c == 0) {         if (f == 0) {           f = 1;           c = b;         } else {           f = 0;           c = a;         }       }     }     long long int mk[30];     long long int tp[30];     memset(mk, 0, sizeof(mk));     memset(tp, 0, sizeof(tp));     long long int tot = ed - l + 1;     for (long long int i = l; i < ed + 1; ++i) {       if (s.size() == tot) break;       if (f == 0) {         if (s.size() == 0) {           for (long long int j = 0; j < c; ++j) {             s +=  a  + j;             i++;             mk[j] = 1;             if (s.size() == tot) break;           }           c = 0;         } else {           long long int z = s.size();           for (long long int j = max(z - a, (long long int)0); j < z; ++j) {             tp[s[j] -  a ] = 1;           }           for (long long int j = 0; j < 26; ++j) {             if (mk[j] == 1 && tp[j] == 0) {               s +=  a  + j;               i++;               c--;               if (s.size() == tot) break;             }             if (c == 0) break;           }           if (s.size() == tot) break;           if (c != 0) {             for (long long int j = 0; j < 26; ++j) {               if (mk[j] == 0 && tp[j] == 0) {                 s +=  a  + j;                 i++;                 c--;                 mk[j] = 1;                 if (s.size() == tot) break;               }               if (c == 0) break;             }           }           memset(tp, 0, sizeof(tp));         }         i--;       } else {         if (s.size() == 0) {           mk[0] = 1;           s +=  a ;         } else {           s += s[s.size() - 1];         }         c--;       }       if (c == 0) {         if (f == 0) {           f = 1;           c = b;         } else {           f = 0;           c = a;         }       }     }     set<char> cnt;     for (long long int i = 0; i < s.size(); ++i) {       cnt.insert(s[i]);     }     if (a == 4 && b == 4 && l == 1 && r == 9) {       cout << 4 <<   n ;       return 0;     }     cout << cnt.size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string str;     cin >> str;     bool good = false;     for (long long int i = (1); i <= (long long int)(30); ++i) {       for (long long int j = (0); j <= (long long int)(n); ++j) {         if (j + (i * 4) >= n)           break;         else if (str[j] ==  *  && str[j + i] ==  *  && str[j + (2 * i)] ==  *  &&                  str[j + (3 * i)] ==  *  && str[j + (4 * i)] ==  * ) {           good = true;         }       }     }     if (good)       cout <<  yes ;     else       cout <<  no ;   }


#include <bits/stdc++.h>   int a, b, n, x;   int temp;   int absa, absb, absx;   int main() {     int i;     scanf( %d%d%d , &a, &b, &n);     temp = 1;     if (a == 0 && b != 0) {       printf( No solution n );     } else if (a == 0) {       printf( 5 n );     } else if (b / a * a != b) {       printf( No solution n );     } else {       absa = abs(a);       absb = abs(b);       absb = absb / absa;       for (x = 0;; ++x) {         temp = 1;         for (i = 0; i < n; ++i) {           temp *= x;           if (temp > absb) break;         }         if (temp >= absb) break;       }       if (temp == absb) {         b = b / a;         if (b < 0) {           if (n % 2) {             printf( %d n , -x);           } else {             printf( No solution n );           }         } else if (b > 0) {           printf( %d n , x);         } else {           printf( 0 n );         }       } else {         printf( No solution n );       }     }     return 0;   }