#include <bits/stdc++.h>   using namespace std;   inline pair<long long int, long long int> compute_pos(       pair<long long int, long long int> prev, char ch) {     int flag = 1;     pair<long long int, long long int> dest;     dest = prev;     if (ch ==  U ) dest.second += flag;     if (ch ==  D ) dest.second -= flag;     if (ch ==  R ) dest.first += flag;     if (ch ==  L ) dest.first -= flag;     return dest;   }   int main() {     string str;     pair<long long int, long long int> dest;     ios_base::sync_with_stdio(false);     cin >> dest.first >> dest.second;     cin >> str;     long long int R_num = 0, L_num = 0, U_num = 0, D_num = 0, i;     for (i = 0; i < str.length(); i++)       if (str[i] ==  U )         U_num++;       else if (str[i] ==  D )         D_num++;       else if (str[i] ==  L )         L_num++;       else         R_num++;     long long int initial_moves, initial_moves_1 = 0, initial_moves_2 = 0,                                  R_net = R_num - L_num, U_net = U_num - D_num;     if (R_net != 0) initial_moves_1 = dest.first / R_net;     if (U_net != 0) initial_moves_2 = dest.second / U_net;     int s_bit_1 = 1, s_bit_2 = 1;     s_bit_1 = dest.first > 0 ? 1 : -1;     s_bit_2 = dest.second > 0 ? 1 : -1;     while (initial_moves_1 * R_net * s_bit_1 + R_num >= s_bit_1 * dest.first &&            initial_moves_1 > 0)       initial_moves_1--;     while (initial_moves_2 * U_net * s_bit_2 + U_num >= s_bit_2 * dest.second &&            initial_moves_2 > 0)       initial_moves_2--;     initial_moves =         initial_moves_2 < initial_moves_1 ? initial_moves_1 : initial_moves_2;     pair<long long int, long long int> position;     position.first = 0;     position.second = 0;     initial_moves = initial_moves > 0 ? initial_moves : 0;     position.first = R_net * initial_moves;     position.second = U_net * initial_moves;     int flag = 0;     {       if (position == dest)         flag = 1;       else if (R_net == 0 && U_net == 0) {         for (i = 0; i < str.length(); i++) {           position = compute_pos(position, str[i]);           if (dest == position) {             flag = 1;             break;           }         }       } else {         while (true) {           for (i = 0; i < str.length(); i++) {             if (position == dest) {               flag = 1;               break;             }             position = compute_pos(position, str[i]);           }           if (position == dest) {             flag = 1;             break;           }           if (position.first - dest.first > L_num) break;           if (position.second - dest.second > D_num) break;           if (dest.first - position.first > R_num) break;           if (dest.second - position.second > U_num) break;         }       }     }     if (flag == 1)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[101], t, m, c, b, i, j, k, l;   string s;   int main() {     cin >> t >> m;     for (k = 0; k < t; k++) {       cin >> s;       if (s[0] ==  a ) {         cin >> c;         for (i = 0, j = -1; i < m; i++)           if (i - j == c && !d[i])             break;           else if (d[i])             j = i;         if (i - j == c && i < m) {           cout << ++b << endl;           for (l = j + 1; l <= i; l++) d[l] = b;         } else           cout <<  NULL  << endl;       } else if (s[0] ==  e ) {         cin >> c;         for (i = 0, j = 0; i < m; i++)           if (d[i] == c && c != 0) d[i] = 0, j = 1;         if (!j) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;       } else if (s[0] ==  d )         for (i = 0, j = 0; i < m; i++)           if (d[i]) l = d[j], d[j] = d[i], d[i] = l, j++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch, s[22][22];   int n, m, N, sg[22][22][22][22], op[22][22];   bool ok, bo[100000];   void read(int &x) {     for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) ok = 1;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     if (ok) x = -x;   }   int calc(int a, int b, int c, int d) {     if (a > b || c > d) return 0;     if (sg[a][b][c][d] != -1) return sg[a][b][c][d];     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           calc(a, b, c, j - 1), calc(a, b, j + 1, d);         else if (op[i][j] == 2)           calc(a, i - 1, c, d), calc(i + 1, b, c, d);         else if (op[i][j] == 3)           calc(a, i - 1, c, j - 1), calc(a, i - 1, j + 1, d),               calc(i + 1, b, c, j - 1), calc(i + 1, b, j + 1, d);     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 1;         else if (op[i][j] == 2)           bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 1;         else if (op[i][j] == 3)           bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^              calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 1;     for (int i = 0;; i++)       if (!bo[i]) {         sg[a][b][c][d] = i;         break;       }     for (int i = a; i <= b; i++)       for (int j = c; j <= d; j++)         if (op[i][j] == 1)           bo[calc(a, b, c, j - 1) ^ calc(a, b, j + 1, d)] = 0;         else if (op[i][j] == 2)           bo[calc(a, i - 1, c, d) ^ calc(i + 1, b, c, d)] = 0;         else if (op[i][j] == 3)           bo[calc(a, i - 1, c, j - 1) ^ calc(a, i - 1, j + 1, d) ^              calc(i + 1, b, c, j - 1) ^ calc(i + 1, b, j + 1, d)] = 0;     return sg[a][b][c][d];   }   int solve(int p) {     memset(op, 0, sizeof(op));     memset(sg, -1, sizeof(sg));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (((i + j) & 1) == p) {           op[(i - j + m + 1) >> 1][(i + j) >> 1] = s[i][j] ==  L    ? 1                                                    : s[i][j] ==  R  ? 2                                                                     : 3;         }     int t = calc(1, N, 1, N);     return t;   }   int main() {     read(n), read(m), N = (n + m) >> 1;     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     puts(solve(0) ^ solve(1) ?  WIN  :  LOSE );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[100010];   int l[100010], r[100010];   int tree[100010 << 2];   int lazy[100010 << 2];   vector<int> v[100010];   void build(int l, int r, int rt) {     if (l == r) {       tree[rt] = num[l];       lazy[rt] = 0;       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);   }   void update(int L, int R, int l, int r, int rt, int w) {     if (L <= l && r <= R) {       tree[rt] += w;       lazy[rt] += w;       return;     }     if (lazy[rt]) {       tree[rt << 1] += lazy[rt];       tree[rt << 1 | 1] += lazy[rt];       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }     int m = l + r >> 1;     if (L <= m) update(L, R, l, m, rt << 1, w);     if (R > m) update(L, R, m + 1, r, rt << 1 | 1, w);     tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);   }   int query(int x, int l, int r, int rt) {     if (l == r) return tree[rt];     int m = l + r >> 1;     if (lazy[rt]) {       tree[rt << 1] += lazy[rt];       tree[rt << 1 | 1] += lazy[rt];       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }     int ans = -0x3f3f3f3f;     if (x <= m)       ans = query(x, l, m, rt << 1);     else       ans = query(x, m + 1, r, rt << 1 | 1);     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> num[i];     build(1, n, 1);     for (int i = 1; i <= m; ++i) {       cin >> l[i] >> r[i];       v[l[i]].emplace_back(i);       v[r[i] + 1].emplace_back(-i);     }     long long ans = -0x3f3f3f3f;     int mark;     for (int i = 1; i <= n; ++i) {       int sz = v[i].size();       for (int j = 0; j < sz; j++) {         int t = v[i][j];         if (t > 0)           update(l[t], r[t], 1, n, 1, -1);         else           update(l[-t], r[-t], 1, n, 1, 1);       }       long long maxx = tree[1];       long long now = query(i, 1, n, 1);       if (maxx - now > ans) {         ans = maxx - now;         mark = i;       }     }     cout << ans << endl;     long long number = 0;     for (int i = 1; i <= m; ++i) {       if (l[i] <= mark && r[i] >= mark) {         number++;       }     }     cout << number << endl;     for (int i = 1; i <= m; ++i) {       if (l[i] <= mark && r[i] >= mark) {         cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast();     long long int t;     t = 1;     while (t--) {       int n;       cin >> n;       long long arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n, greater<int>());       int a = ceil((float)n / 2);       int b = n - a;       int answer = 0;       int curr = a;       vector<long long> arr2;       vector<long long> arr3;       for (int i = 1; i < a; i++) {         for (int j = curr; j < n; j++) {           if (arr[j] < arr[i]) {             curr = j + 1;             answer++;             arr2.push_back(arr[j]);             break;           } else             arr3.push_back(arr[j]);         }       }       cout << answer << endl;       for (int i = 0; i < arr3.size(); i++) arr2.push_back(arr3[i]);       if (arr2.size() != b) {         for (int i = 0; i < (b - arr2.size()); i++)           arr2.push_back(arr[n - 1 - i]);       }       for (int i = 0; i < n; i++) {         if (i % 2)           cout << arr2[i / 2] <<    ;         else           cout << arr[i / 2] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int cnt(vector<vector<pair<int, int>>>& graph, int cur, int parent, int val) {     int ans = 1;     for (auto p : graph[cur]) {       if (p.first == parent) continue;       if (p.second == val) ans += cnt(graph, p.first, cur, val);     }     return ans;   }   void fill(vector<vector<pair<int, int>>>& graph,             vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec,             int cur, int parent, int val, int num) {     if (val == 0) {       visited[cur].first = true;       cnt_vec[cur].first = num;     } else {       visited[cur].second = true;       cnt_vec[cur].second = num;     }     for (auto p : graph[cur]) {       if (p.first == parent) continue;       if (p.second == val) fill(graph, visited, cnt_vec, p.first, cur, val, num);     }   }   int process(vector<vector<pair<int, int>>>& graph,               vector<pair<bool, bool>>& visited, vector<pair<int, int>>& cnt_vec,               int start, int val) {     int n = graph.size(), ans;     ans = cnt(graph, start, -1, val);     fill(graph, visited, cnt_vec, start, -1, val, ans);     return ans;   }   int main() {     int n, i, a, b, val, tmp;     long long ans = 0;     cin >> n;     vector<vector<pair<int, int>>> graph(n + 1);     for (i = 0; i < n - 1; ++i) {       cin >> a >> b >> val;       graph[a].push_back({b, val});       graph[b].push_back({a, val});     }     vector<pair<int, int>> cnt_vec(n + 1, {0, 0});     vector<pair<bool, bool>> visited(n + 1, {false, false});     vector<int> components;     for (i = 1; i <= n; ++i) {       if (!visited[i].first) {         tmp = process(graph, visited, cnt_vec, i, 0);         if (tmp > 1) components.push_back(tmp);       }       if (!visited[i].second) {         tmp = process(graph, visited, cnt_vec, i, 1);         if (tmp > 1) components.push_back(tmp);       }     }     for (auto num : components) ans += 1LL * num * (num - 1);     for (i = 1; i <= n; ++i)       ans += 1LL * (cnt_vec[i].first - 1) * (cnt_vec[i].second - 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   void pr_init() {}   void solve() {     string str[2];     cin >> str[0] >> str[1];     long long ss = (long long)str[0].size();     long long dp[2][ss + 1];     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < ss; j++) {         if (str[i][j] ==  X )           dp[i][j] = 0;         else           dp[i][j] = 1;       }     }     dp[0][ss] = dp[1][ss] = 0;     long long ways = 0;     for (long long j = 0; j < ss; j++) {       if (dp[0][j] == 1 && dp[1][j] == 1) {         if (dp[0][j + 1] == 1)           ways++, dp[0][j + 1] = 0;         else if (dp[1][j + 1] == 1)           ways++, dp[1][j + 1] = 0;         continue;       } else if (dp[0][j] == 1) {         if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1)           ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0;         continue;       } else if (dp[1][j] == 1) {         if (dp[0][j + 1] == 1 && dp[1][j + 1] == 1)           ways++, dp[0][j + 1] = 0, dp[1][j + 1] = 0;         continue;       }     }     cout << ways << endl;   }   int32_t main() {     pr_init();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   inline t read(t &x) {     char c = getchar();     bool f = 0;     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0)       putchar( - ), write(-x);     else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int N = 55;   int n, a[N], cnt;   signed main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) cnt += a[i] == a[1];     if (cnt > n / 2)       puts( Bob );     else       puts( Alice );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5, Lim = 18;   int tr[maxn * 19][2], nowxor, cnt = 1, siz[maxn * 19], n, m;   template <typename T>   inline void read(T &x) {     char c;     int f = 1;     while (!isdigit(c = getchar())) (c ==  - ) && (f = -1);     x = c ^ 48;     while (isdigit(c = getchar())) x = x * 10 + (c ^ 48);     x *= f;   }   void insert(int x, int u = 1, int now = Lim) {     if (now == -1) return siz[u] = 1, void();     int s = x >> now & 1;     if (!tr[u][s]) tr[u][s] = ++cnt;     insert(x, tr[u][s], now - 1);     siz[u] = siz[tr[u][0]] + siz[tr[u][1]];   }   inline int query(int x = nowxor) {     int u = 1, res = 0;     for (int i = Lim; i >= 0; --i) {       int s = x >> i & 1;       if (siz[tr[u][s]] == ((1 << i)))         u = tr[u][s ^ 1], res |= (1 << i);       else         u = tr[u][s];       if (!u) return res;     }     return res;   }   int main() {     int x;     read(n);     read(m);     for (int i = 1; i <= n; ++i) read(x), insert(x);     while (m--) {       read(x);       nowxor ^= x;       printf( %d n , query());     }     return 0;     int yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;     yy = 0;   }


#include <bits/stdc++.h>   long long vx[200010], vy[200010];   std::map<long long, long long> mp, gg;   int main() {     int n;     long long a, b;     scanf( %d%lld%lld , &n, &a, &b);     long long ans = 0;     for (int k = 1; k <= n; k++) {       long long t;       scanf( %lld%lld%lld , &t, &vx[k], &vy[k]);       long long c = a * vx[k] - vy[k];       long long d = (long long)2000000000 * vx[k] + vy[k];       ans -= gg[d];       gg[d]++;       ans += mp[c];       mp[c]++;     }     printf( %lld n , 2 * ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mmmm = 1111;   int n;   char s[mmmm];   int a[mmmm], f[mmmm];   void qwe() {     a[0] = 1989;     f[0] = 1;     for (int i = 1; i <= 9; i++) {       f[i] = f[i - 1] * 10;       a[i] = a[i - 1] + f[i];     }   }   int main() {     qwe();     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %s , s);         int l = strlen(s) - 4;         int c = 0;         for (int i = 4; i < l + 4; i++) {           c = c * 10 + s[i] -  0 ;         }         int asd = a[l - 1];         int zxc = a[l];         int t1 = asd / f[l] * f[l] + c;         int t2 = zxc / f[l] * f[l] + c;         if (t1 >= asd && t1 < zxc) {           printf( %d n , t1);         } else {           printf( %d n , t2);         }       }     }     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238463;   using namespace std;   inline long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   inline long long sub(long long a, long long b) {     a -= b;     if (a < 0) a += 1000000007;     return a;   }   inline long long mul(long long a, long long b) {     return (long long)((long long)a * b % 1000000007);   }   long long fast_power(long long base, long long power) {     long long result = 1;     while (power > 0) {       if (power % 2 == 1) {         result = (result * base);       }       base = (base * base);       power = power / 2;     }     return result;   }   long long min(long long a, long long b) { return a > b ? b : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   void SieveOfEratosthenes(long long n, unordered_set<long long> &s) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p]) s.insert(p);   }   void dfs(long long s, vector<bool> &vis, vector<vector<long long>> &adlist) {     if (vis[s]) return;     vis[s] = true;     for (auto x : adlist[s]) {       if (vis[x] == false) {         cout << s <<     << x <<   n ;       }       dfs(x, vis, adlist);     }   }   void bfs(long long x, vector<bool> &vis, vector<vector<long long>> &adlist) {     queue<long long> q;     vis[x] = true;     q.push(x);     while (!q.empty()) {       long long s = q.front();       q.pop();       for (auto u : adlist[s]) {         if (vis[u]) continue;         vis[u] = true;         q.push(u);       }     }   }   bool bpchk(vector<vector<long long>> &adj, vector<long long> &color) {     color[1] = 1;     queue<long long> q;     q.push(1);     while (!q.empty()) {       long long u = q.front();       q.pop();       for (auto x : adj[u]) {         if (color[x] == -1) {           color[x] = color[u] ^ 1;           q.push(x);         }       }     }     for (long long i = 1; i < adj.size(); i++) {       for (auto x : adj[i]) {         if (color[x] == color[i]) return false;       }     }     return true;   }   int main() {     string s;     cin >> s;     bool flag = true;     long long zc = 0, oc = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) {         zc += 1;       } else {         oc += 1;       }       if (zc < oc) {         flag = false;         break;       }     }     zc = 0, oc = 0;     for (long long i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  0 ) {         zc += 1;       } else {         oc += 1;       }       if (zc < oc) {         flag = false;         break;       }     }     if (flag == false) {       cout << -1 <<   n ;     } else {       long long vecsz = 0;       long long ctr = 1;       long long i = 0;       vector<long long> s2;       while (i < s.size()) {         if (i == 0) {           ctr = 1;           s2.push_back(ctr);         } else {           if (s[i] == s[i - 1] && s[i] ==  0 ) {             ctr += 1;             s2.push_back(ctr);           } else if (s[i] == s[i - 1] && s[i] ==  1 ) {             ctr -= 1;             s2.push_back(ctr);           } else {             s2.push_back(ctr);           }         }         vecsz = max(vecsz, ctr);         i += 1;       }       cout << vecsz <<   n ;       vector<vector<long long>> v(vecsz + 1, vector<long long>());       for (long long i = 0; i < s2.size(); i++) {         v[s2[i]].push_back(i + 1);       }       for (long long i = 1; i < v.size(); i++) {         cout << v[i].size() <<    ;         for (long long j = 0; j < v[i].size(); j++) {           cout << v[i][j] <<    ;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000000 + 7;   const int N = 10000001;   long long dp[N];   int main() {     dp[1] = 0;     dp[2] = 3;     for (int i = 3; i < N; i++) dp[i] = (dp[i - 2] * 3 + dp[i - 1] * 2) % mod;     int n;     while (scanf( %d , &n) != EOF) printf( %lld n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 1e4 + 5;   int n, b, q;   int a[maxn], c[maxn];   inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); }   inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); }   int main() {     scanf( %d%d%d , &n, &b, &q);     memset(a, -1, sizeof(a));     for (int i = (0); i < (q); ++i) {       int x, k;       scanf( %d%d , &x, &k);       if (~a[x] && a[x] != k) {         puts( unfair );         return 0;       }       a[x] = k;     }     if (~a[b] && a[b] != n) {       puts( unfair );       return 0;     }     a[b] = n;     a[0] = 0;     for (int msk = (0); msk < (1 << 5); ++msk) {       int x, g = 0, lst = 0;       for (int i = (1); i <= (b); ++i)         if (~a[i]) {           int sub = 0, nin = 0;           if (a[i] < a[lst]) {             puts( unfair );             return 0;           }           for (int j = (0); j < (5); ++j) {             if (msk >> j & 1)               sub += calc(j, lst + 1, i);             else               nin += calc(j, lst + 1, i);           }           g += min(a[i] - a[lst], sub);           if (a[i] - a[lst] > i - lst) {             puts( unfair );             return 0;           }           lst = i;         }       x = __builtin_popcount(msk) * n / 5;       if (x > g) {         puts( unfair );         return 0;       }     }     puts( fair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e7;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     int n, ans = INT_MAX, count = 0;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       count += (v[i] == 1);     }     if (count > 0) {       cout << n - count << endl;     } else {       vector<vector<int>> dp(n, vector<int>(n));       for (int i = 0; i < n; i++) dp[i][i] = v[i];       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++) dp[i][j] = gcd(v[j], dp[i][j - 1]);       for (int i = 0; i < n; i++)         for (int j = i; j < n; j++)           if (dp[i][j] == 1) ans = min(ans, j - i);       if (ans == INT_MAX)         cout << -1 << endl;       else         cout << ans + n - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[200000];   int cost[200001];   int sub() {     int n, p, k;     cin >> n >> p >> k;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     sort(A, A + n);     for (int i = 0; i < n; i++) {       if (i < k - 1) {         cost[i + 1] = cost[i] + A[i];       } else {         cost[i + 1] = cost[i - k + 1] + A[i];       }     }     int ans = 0;     for (int i = 0; i <= n; i++) {       if (cost[i] <= p) {         ans = i;       }     }     cout << ans << endl;     return 0;   }   int main() {     int t;     cin >> t;     while (t--) {       sub();     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const long long INF = 1e18 + 1LL;   const double Pi = acos(-1.0);   const int N = 5e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9;   vector<int> G[N];   long long dp[N][10], fs[N][10];   long long ans = 0;   int n, k, a, b;   void dfs(int u, int f) {     dp[u][0] = 1;     for (int i = 0; i < G[u].size(); ++i) {       int to = G[u][i];       if (to == f) continue;       dfs(to, u);       for (int j = 0; j <= k; ++j) {         for (int h = 0; h <= k; ++h) {           if (!dp[u][j] || !dp[to][h]) continue;           long long tmp = j + h + 1;           if (tmp % k)             tmp = tmp / k + 1;           else             tmp = tmp / k;           ans += tmp * dp[to][h] * dp[u][j] + fs[u][j] * dp[to][h] +                  fs[to][h] * dp[u][j];         }       }       for (int j = 1; j <= k; ++j)         dp[u][j] += dp[to][j - 1], fs[u][j] += fs[to][j - 1];       dp[u][1] += dp[to][k];       fs[u][1] += fs[to][k] + dp[to][k];     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     reverse(s.begin(), s.end());     reverse(t.begin(), t.end());     int i = 0;     while (i < s.length() && i < t.length() && s[i] == t[i]) {       i++;     }     cout << s.length() + t.length() - 2 * i;   }


#include <bits/stdc++.h>   int main() {     int n, s;     scanf( %d%d , &n, &s);     s *= 100;     int max = 0;     bool tr = false;     for (int i = 1; i <= n; i++) {       int d, c;       scanf( %d%d , &d, &c);       int money = d * 100 + c;       if (money <= s) {         tr = true;         int sweet = (s - money) % 100;         if (max < sweet) max = sweet;       }     }     if (tr == false)       printf( -1 n );     else       printf( %d n , max);   }


#include <bits/stdc++.h>   using namespace std;   int n, k, m;   int times[45];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> m;     for (int i = 0; i < k; i++) cin >> times[i];     int s = 0;     for (int i = 0; i < k; i++) s += times[i];     sort(begin(times), begin(times) + k);     int currBest = 0;     for (int numSolves = 0; numSolves < n + 1; numSolves++) {       if (s * numSolves > m) break;       int score = 0;       score += numSolves * (k + 1);       int timeLeft = m - s * numSolves;       int numUnsolved = n - numSolves;       int i = 0;       while (timeLeft >= times[i] && i < k) {         score += min(timeLeft / times[i], numUnsolved);         timeLeft -= times[i] * min(timeLeft / times[i], numUnsolved);         i++;       }       currBest = max(score, currBest);     }     cout << currBest <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   void bugp(const pair<T, V> &x) {     cerr <<  {  << x.first <<  ,   << x.second <<  }  << endl;   }   template <typename T, typename U, typename V>   void bugpp(const pair<T, pair<U, V> > &x) {     cerr <<  {  << x.first <<  , {  << x.second.first <<  ,   << x.second.second          <<  }}  << endl;   }   template <typename T>   bool maximize(T &x, const T &y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   template <typename T>   bool minimize(T &x, const T &y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   const int N = 100001;   int n, arr[N], dp[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int total_sum = 0;     map<int, int> cnt;     for (int i = 1, _n = (n); i <= _n; ++i) {       cin >> arr[i];       total_sum += arr[i];       if (!(total_sum & 1)) dp[i] = cnt[total_sum - total_sum / 2];       ++cnt[total_sum];     }     long long ans = 0;     int sum = 0;     for (int i = (n), _b = (3); i >= _b; --i) {       sum += arr[i];       if (3 * sum == total_sum) ans += dp[i - 1];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const long long OO = 0x3f3f3f3f3f3f3f3fLL;   const int maxn = 200000;   int d, V, n;   pair<int, int> a[maxn + 5];   long long dp[maxn + 5];   int Min[maxn + 5];   int main() {     memset(Min, -1, sizeof Min);     scanf( %d%d%d , &d, &V, &n);     for (int i = (0), _end_ = (n); i < _end_; ++i)       scanf( %d%d , &a[i].first, &a[i].second);     a[n++] = make_pair(0, 0);     a[n++] = make_pair(d, 0);     sort(a, a + n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i)       if (a[i].first + V < a[i + 1].first) {         printf( -1 n );         return 0;       }     long long ans = 0;     int lst = 0, cur = 0;     for (int i = (1), _end_ = (n); i < _end_; ++i) {       cur = a[i - 1].first;       while (a[lst].first + V < a[i].first) {         ans += (long long)(a[lst].first + V - cur) * a[lst].second;         cur = a[lst].first + V;         int best = -1;         for (int j = lst + 1; j <= n; j += j & -j)           if (best == -1 || (Min[j] != -1 && a[Min[j]].second < a[best].second))             best = Min[j];         lst = best;       }       ans += (long long)(a[i].first - cur) * a[lst].second;       cur = a[i].first;       if (a[i].second < a[lst].second) lst = i;       for (int j = i; j > 0; j -= j & -j)         if (Min[j] == -1 || a[Min[j]].second > a[i].second) Min[j] = i;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n % 2)       printf( black n );     else       printf( white n1 2 n );   }


#include <bits/stdc++.h>   using namespace std;   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline long long read() {     bool sign = 0;     char ch = nc();     long long x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return 0;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return x;   }   };  // namespace fastIO   using namespace fastIO;   vector<long long> e[2000010];   long long dep[2000010], fa[2000010], son[2000010], top[2000010], id[2000010],       now = 0, f[2000010];   void dfs1(long long x, long long pre) {     dep[x] = 1;     for (auto i : e[x]) {       if (i == pre) continue;       dfs1(i, x);       fa[i] = x;       if (dep[i] > dep[son[x]]) son[x] = i;       dep[x] = max(dep[x], dep[i] + 1);     }   }   void dfs2(long long x, long long tp) {     id[x] = ++now;     top[x] = tp;     if (son[x]) dfs2(son[x], son[x]);     for (auto i : e[x]) {       if (i == son[x] || i == fa[x]) continue;       dfs2(i, tp);     }   }   long long maxx[1000010], maxi[1000010];   void merge(long long p, long long x, long long y) {     for (long long i = 1; i <= dep[y]; i++) {       f[id[x] + i - 1] += f[id[y] + i - 1];       if (f[id[x] + i - 1] > maxx[p] ||           (f[id[x] + i - 1] == maxx[p] && i < maxi[p]))         maxx[p] = f[id[x] + i - 1], maxi[p] = i;     }   }   void dfs3(long long x, long long pre) {     if (son[x]) dfs3(son[x], x);     if (son[x])       maxx[x] = maxx[son[x]], maxi[x] = maxi[son[x]] + 1;     else       maxx[x] = 1, maxi[x] = 0;     for (auto i : e[x]) {       if (i == fa[x] || i == son[x]) continue;       dfs3(i, x);       merge(x, son[x], i);     }     f[id[x]] = 1;     if (maxx[x] == 1) maxi[x] = 0;   }   signed main() {     long long n = read();     for (long long i = 1; i < n; i++) {       long long x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     dfs1(1, 1);     dfs2(1, 1);     dfs3(1, 1);     for (long long i = 1; i <= n; i++) cout << maxi[i] <<   n ;     return 0;   }


#include <iostream>   #include <string.h>   #include <bits/stdc++.h>   using namespace std;   int main() {       int t;       cin >> t;       while(t--) {           int x;           cin >> x;           bool isPossible = false;           for (int i = 0; i < 11; i++) {               if (111*i <= x && (x - 111*i)%11 == 0) {                   isPossible = true;               }           }           if(isPossible) cout <<  YES  << endl;           else cout <<  NO  << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int a[maxn], ra[maxn];   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         ra[a[i]] = i;       }       int t;       long long cnt = 0;       for (int i = 0; i < m; i++) {         scanf( %d , &t);         int j = ra[t];         if ((j + 1) % k == 0)           cnt += (j + 1) / k;         else           cnt += ((j + 1) / k + 1);         if (j != 0) {           swap(a[j], a[j - 1]);           swap(ra[t], ra[a[j]]);         }       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   unsigned long long n, k, x;   unsigned long long a[300000];   unsigned long long dpL[300000];   unsigned long long dpR[300000];   int main() {     int i, j;     cin >> n >> k >> x;     unsigned long long s = 0, MAX = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 1; i++) {       dpL[i + 1] = dpL[i] | a[i];     }     for (i = n - 1; i > 0; i--) {       dpR[i - 1] = dpR[i] | a[i];     }     unsigned long long ans1 = a[0], ans2 = a[n - 1];     for (i = 0; i < k; i++) {       ans1 = ans1 * x;       ans2 = ans2 * x;     }     unsigned long long ans = max(ans1 | dpR[0], ans2 | dpL[n - 1]);     for (i = 1; i < n - 1; i++) {       unsigned long long ANS = a[i];       for (j = 0; j < k; j++) {         ANS *= x;       }       ans = max(ans, ANS | dpL[i] | dpR[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int64_t n, m;     cin >> n >> m;     pair<char, int64_t> a[n][m];     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         cin >> a[i][j].first;         a[i][j].second = 0;       }     }     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         int64_t c = 0;         for (int64_t k = 0; k < n; ++k) c += a[k][j].first == a[i][j].first;         if (c > 1) a[i][j].second = 1;         c = 0;         for (int64_t k = 0; k < m; ++k) c += a[i][j].first == a[i][k].first;         if (c > 1) a[i][j].second = 1;       }     }     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         if (a[i][j].second == 0) cout << a[i][j].first;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int l, s, cnt, last, b[100005];   char a[100005];   int main() {     int i, j;     scanf( %s , a);     l = strlen(a);     for (i = 0; i < strlen(a); i++) {       if (a[i] ==  ( )         s++;       else if (a[i] ==  ) )         s--;       else if (a[i] ==  # ) {         s--;         cnt++;       }       if (s < 0) {         puts( -1 );         return 0;       }     }     for (i = 0; i < cnt; i++) {       b[i] = 1;     }     b[cnt - 1] += s;     s = 0;     for (i = 0, j = 0; i < strlen(a); i++) {       if (a[i] ==  ( )         s++;       else if (a[i] ==  ) )         s--;       else if (a[i] ==  # )         s -= b[j++];       if (s < 0) {         puts( -1 );         return 0;       }     }     for (i = 0; i < cnt; i++) {       printf( %d  , b[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, first, last, ans, flag;     cin >> n;     if (n <= 2) {       cout << 0 << endl;       return 0;     }     ans = flag = 0;     first = 1;     last = n;     for (int i = 1; i < n; i++) {       ans += (first + last) % (n + 1);       if (!flag) {         first++;         swap((first), last);       } else {         first--;         swap((first), last);       }       flag = 1 - flag;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int MAX = 1e5 + 55;   const int inf = 1e9 + 77;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-7;   int main() {     long long n;     scanf( %I64d , &n);     long long div = 3;     while (n % div == 0) div *= 3;     n /= div;     ++n;     printf( %I64d , n);     return 0;   }


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


#include <bits/stdc++.h>   #define ll long long      using namespace std;      void solve(){       ll n, i;       cin >> n;       ll u, r, d, l;       ll u1=0, r1=0, d1=0, l1=0;       cin >> u >> r >> d >> l;       if(u==n) r1++,l1++;       if(d==n) r1++,l1++;       if(r==n) u1++,d1++;       if(l==n) u1++,d1++;          if(u==n-1){           if(r1<r) r1++;           else l1++;       }       if(d==n-1){           if(r1<r) r1++;           else l1++;       }       if(r==n-1){           if(u1<u) u1++;           else d1++;       }       if(l==n-1){           if(u1<u) u1++;           else d1++;       }       if(u>=u1 and r>=r1 and l>=l1 and d>=d1) cout <<  YES n ;       else cout <<  NO n ;   }   int main(){       ios_base::sync_with_stdio(false); cin.tie(NULL);       ll t;       cin >> t;       while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int x;     cin >> x;     cin.ignore();     string input;     getline(cin, input);     int len = input.length();     int cnt[3] = {0};     for (int i = 0; i < len; i++) {       if (input[i] ==  0 )         cnt[0]++;       else if (input[i] ==  1 )         cnt[1]++;       else if (input[i] ==  2 )         cnt[2]++;     }     int max = len / 3;     cnt[0] = max - cnt[0];     cnt[1] = max - cnt[1];     cnt[2] = max - cnt[2];     if (cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0) {       std::cout << input <<   n ;     } else {       for (int i = 0; i < len && cnt[0] > 0; i++) {         if (input[i] ==  1  && cnt[1] < 0) {           input[i] =  0 ;           cnt[1]++;           cnt[0]--;         } else if (input[i] ==  2  && cnt[2] < 0) {           input[i] =  0 ;           cnt[2]++;           cnt[0]--;         }       }       for (int i = len - 1; cnt[2] > 0; i--) {         if (input[i] ==  1  && cnt[1] < 0) {           input[i] =  2 ;           cnt[1]++;           cnt[2]--;         } else if (input[i] ==  0  && cnt[0] < 0) {           input[i] =  2 ;           cnt[0]++;           cnt[2]--;         }       }       for (int i = 0; i < len && cnt[1] > 0 && cnt[2] < 0; i++) {         if (input[i] ==  2 ) {           input[i] =  1 ;           cnt[1]--;           cnt[2]++;         }       }       for (int i = len - 1; i >= 0 && cnt[1] > 0 && cnt[0] < 0; i--) {         if (input[i] ==  0 ) {           input[i] =  1 ;           cnt[1]--;           cnt[2]++;         }       }       std::cout << input <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[120], b[120], c[120], d[120];   map<int, int> mp;   vector<int> ans;   int main() {     memset(b, -1, sizeof(b));     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d %d , &x, &y);       b[x] = y;       mp[x] = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       ans.clear();       memcpy(c, a, sizeof(c));       memcpy(d, b, sizeof(d));       for (int q = 1; q <= m; q++) {         int choose = -1, hp = 2000000000;         for (int j = 1; j <= n; j++) {           if (d[j] == -1) continue;           int tmp = d[j], ok = 1;           if (j <= i) {             for (int k = j; k <= i; k++) {               tmp += c[k];               if (tmp < 0) {                 ok = 0;                 break;               }             }           } else {             for (int k = j; k >= i; k--) {               tmp += c[k];               if (tmp < 0) {                 ok = 0;                 break;               }             }           }           if (!ok) continue;           if (tmp < hp) {             choose = j;             hp = tmp;           }         }         if (choose == -1) break;         for (int j = min(i, choose); j <= max(i, choose); j++) c[j] = 0;         d[choose] = -1;         ans.push_back(choose);       }       if (ans.size() == m) {         printf( %d n , i);         for (int j = 0; j < ans.size(); j++) printf( %d  , mp[ans[j]]);         return 0;       }     }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 5;   long double x[maxN], y[maxN], r[maxN], val[maxN];   long double f(long double xx, long double yy) {     for (int i = 0; i < 3; ++i) {       val[i] = sqrt((x[i] - xx) * (x[i] - xx) + (y[i] - yy) * (y[i] - yy)) / r[i];     }     val[3] = val[0];     long double answer = 0;     for (int i = 0; i < 3; ++i)       answer += (val[i] - val[i + 1]) * (val[i] - val[i + 1]);     return answer;   }   int main() {     for (int i = 0; i < 3; ++i) cin >> x[i] >> y[i] >> r[i];     long double pX = (x[0] + x[1] + x[2]) / 3., pY = (y[0] + y[1] + y[2]) / 3.;     long double qq = 1.;     while (qq > 1e-5) {       if (f(pX - qq, pY) < f(pX, pY))         pX -= qq;       else if (f(pX + qq, pY) < f(pX, pY))         pX += qq;       else if (f(pX, pY - qq) < f(pX, pY))         pY -= qq;       else if (f(pX, pY + qq) < f(pX, pY))         pY += qq;       else         qq *= 0.777777777;     }     if (f(pX, pY) > 1e-5) return 0;     cout << fixed << setprecision(15) << pX <<     << pY << endl;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-9;   const double PI = acos(-1.0);   const long long int mod = 1e9 + 7;   const int MAXN = 2e3 + 5;   using namespace std;   vector<vector<int>> adj(MAXN);   int mxd;   void dfs(int u, int d) {     mxd = max(mxd, d);     for (int v : adj[u]) dfs(v, d + 1);   }   void cp() {     int n;     cin >> n;     vector<int> roots;     for (int i = 0; i < n; i++) {       int p;       cin >> p;       if (p == -1)         roots.push_back(i);       else         adj[p - 1].push_back(i);     }     for (int u : roots) dfs(u, 1);     cout << mxd <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int power(long long int x, long long int y) {     long long int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   bool prime_check(long long int n) {     long long int i, j;     if (n == 1) {       return false;     }     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long int fact(long long int n) {     long long int prod = 1;     for (long long int i = 1; i <= n; i++) {       prod = (prod * i) % 1000000007;     }     return prod;   }   bool vowl(char c) {     return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, i;       cin >> n;       int a[n + 3];       multiset<int, greater<int>> ms;       for (i = 0; i < n; i++) {         cin >> a[i];         ms.insert(a[i]);       }       bool flag = 0;       int x = *ms.begin();       --x;       ms.erase(ms.begin());       while (!ms.empty()) {         int first = *ms.begin();         --first;         ms.erase(ms.begin());         if (x) ms.insert(x);         x = first;         flag = 1 - flag;       }       if (!flag)         cout <<  T               <<   n ;       else         cout <<  HL               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char nchar() {     static const int bufl = 1 << 20;     static char buf[bufl], *a = NULL, *b = NULL;     return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF                                                                           : *a++;   }   inline int read() {     int x = 0, f = 1;     char c = nchar();     for (; !isdigit(c); c = nchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = nchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int maxn = 1e5 + 1;   int n, m;   namespace sgt {   struct D {     double s, j;     D(double s = 0, double j = 0) : s(s), j(j) {}     inline void set() {       int x = read(), y = read();       double d = (double)x / y;       d = (1 - d) / d;       s = (j = d) + 1;     }     inline friend D operator+(D a, D b) {       return D(a.s + a.j * (b.s - 1), a.j * b.j);     }   } t[maxn << 1];   inline int ID(int l, int r) { return l + r | l != r; }   void build(int l, int r) {     int x = ID(l, r);     if (l == r) {       t[x].set();       return;     }     int mid = l + r >> 1;     build(l, mid), build(mid + 1, r);     t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)];   }   void reset(int l, int r, int p) {     int x = ID(l, r);     if (l == r) {       t[x].set();       return;     }     int mid = l + r >> 1;     p <= mid ? reset(l, mid, p) : reset(mid + 1, r, p);     t[x] = t[ID(l, mid)] + t[ID(mid + 1, r)];   }   void reset(int p) { reset(1, n, p); }   D query(int L, int R, int l, int r) {     if (L == l && R == r) return t[ID(L, R)];     int mid = L + R >> 1;     if (r <= mid) return query(L, mid, l, r);     if (l > mid) return query(mid + 1, R, l, r);     return query(L, mid, l, mid) + query(mid + 1, R, mid + 1, r);   }   double query(int l, int r) {     D d = query(1, n, l, r);     return 1. / d.s;   }   }  // namespace sgt   int main() {     n = read(), m = read();     sgt::build(1, n);     while (m--) {       int o = read();       if (o == 1)         sgt::reset(read());       else {         int l = read(), r = read();         double ans = sgt::query(l, r);         printf( %.12lf n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 9223372036854775807LL;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroint-loops )   long long int power(long long int a, long long int b, long long int m) {     long long int res = 1;     while (b) {       if (b & 1) res = ((res % m) * (a % m)) % m;       a = ((a % m) * (a % m)) % m;       b >>= 1;     }     return res;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   void solve() {     long long int a, b, c, d, x, y;     cin >> a >> b >> c >> d >> x >> y;     if (abs(c - a) % x == 0 and abs(d - b) % y == 0) {       long long int xx = abs(c - a) / x;       long long int yy = abs(d - b) / y;       if ((xx & 1 and yy & 1) or (xx & 1 ^ 1 and yy & 1 ^ 1))         cout <<  YES ;       else         cout <<  NO ;     } else       cout <<  NO ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int x = a[0], j = 0;     vector<int> pol(n, 0);     pol[0] = 1;     for (int i = 1; i < n; i++) {       if (a[i] == x)         pol[j]++;       else {         j++;         pol[j]++;         x = a[i];       }     }     bool same = 1;     for (int i = 1; i <= j; i++)       if (pol[i] != pol[i - 1]) same = false;     if (same)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int visited[200001];   int colour[200001];   vector<int> adj_list[200001];   int* graph[1000001];   int* finalcolour[1000001];   int size[1000001];   int check;   int count1 = 0;   int k[9];   int l[9];   int dp[9][1001];   int A[9][11];   int c[9][10];   bool pairCompare(const pair<int, int>& firstElem,                    const pair<int, int>& secondElem) {     return firstElem.first > secondElem.first;   }   int solve(int cards, int coins) {     int i;     if (cards <= 0) return 0;     if (dp[cards][coins] != -1) return dp[cards][coins];     int ret = A[cards][l[cards]] + solve(cards - 1, coins);     int use = 0;     int coins_left = coins;     for (i = l[cards] + 1; i <= k[cards]; i++) {       coins_left = coins_left - c[cards][i - 1];       if (coins_left >= 0)         ret = max(ret, A[cards][i] + solve(cards - 1, coins_left));       else         break;     }     dp[cards][coins] = ret;     return ret;   }   long long powe(long long a, long long b, long long k) {     if (b == 0) return 1;     long long temp = powe(a, b / 2, k);     temp *= temp;     if (temp >= k) temp %= k;     if (b % 2 == 1) temp *= a;     if (temp >= k) temp %= k;     return temp;   }   void dfs(int x) {     int i;     visited[x] = 1;     for (i = 0; i < adj_list[x].size(); i++) {       if (visited[adj_list[x][i]] == 0) {         printf( %d  , x);         if (colour[x] == -1) {           colour[x] = 1;         } else {           colour[x] = -1;         }         dfs(adj_list[x][i]);         if (colour[adj_list[x][i]] == -1) {           printf( %d %d  , x, adj_list[x][i]);           colour[adj_list[x][i]] = 1;           if (colour[x] == -1) {             colour[x] = 1;           } else {             colour[x] = -1;           }         }       }     }     printf( %d  , x);     if (colour[x] == -1) {       colour[x] = 1;     } else {       colour[x] = -1;     }   }   int main() {     int n, i, count = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &colour[i]);       visited[i] = 0;       if (colour[i] == 1) count++;     }     for (i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj_list[x].push_back(y);       adj_list[y].push_back(x);     }     if (count == n) {       printf( 1 n );       return 0;     }     if (colour[1] == -1)       colour[1] = 1;     else       colour[1] = -1;     dfs(1);     if (colour[1] == -1) {       printf( %d 1 %d  , adj_list[1][0], adj_list[1][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 4e18, mod = 1e9 + 7;   vector<pair<pair<long long, long long>, pair<long long, long long>>> v;   int segt[4 * 6000000 + 5], lazy[4 * 6000000 + 5];   void push(int v, int l, int r) {     segt[v] += lazy[v];     if (l != r) {       lazy[2 * v] += lazy[v];       lazy[2 * v + 1] += lazy[v];     }     lazy[v] = 0;   }   void update_range(int v, int l, int r, int qs, int qe, int x) {     push(v, l, r);     if (l > qe || r < qs) return;     if (qs <= l && r <= qe) {       lazy[v] += x;       push(v, l, r);       return;     }     int m = (l + r) / 2;     update_range(2 * v, l, m, qs, qe, x);     update_range(2 * v + 1, m + 1, r, qs, qe, x);     segt[v] = max(segt[2 * v], segt[2 * v + 1]);   }   int query(int v, int l, int r, int qs, int qe) {     push(v, l, r);     if (l > qe || r < qs) return 0;     if (qs <= l && r <= qe) return segt[v];     int m = (l + r) / 2;     int val1 = query(2 * v, l, m, qs, qe);     int val2 = query(2 * v + 1, m + 1, r, qs, qe);     return max(val1, val2);   }   void solve() {     int n, r;     cin >> n >> r;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       int X = x + y, Y = y - x;       int lx, ly, ux, uy;       lx = X - r, ux = X + r, ly = Y - r, uy = Y + r;       lx += 3000000;       ux += 3000000;       ly += 3000000;       uy += 3000000;       v.push_back({{ly, 0}, {lx, ux}});       v.push_back({{uy, 1}, {lx, ux}});     }     sort(v.begin(), v.end());     int res = 0;     for (auto it : v) {       if (it.first.second == 0)         update_range(1, 0, 6000000, it.second.first, it.second.second, 1);       else         update_range(1, 0, 6000000, it.second.first, it.second.second, -1);       int val = query(1, 0, 6000000, 0, 6000000);       res = max(res, val);     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   bool m[1001][1001];   bool ff[1001][1001];   int n, num;   int ans;   int main() {     cin >> n >> num;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= i + num; j++)         if (!m[i][(j - 1) % n + 1]) {           m[i][(j - 1) % n + 1] = true;           m[(j - 1) % n + 1][i] = true;           ff[i][(j - 1) % n + 1] = true;         } else {           cout << -1 << endl;           return 0;         }     if (n == 1) {       cout << -1 << endl;       return 0;     }     cout << num * n << endl;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (ff[i][j]) printf( %d %d n , i, j);   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int a[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t, i, j, n, m, l, r;     cin >> n;     for (i = 0; i < n; i++) {       cin >> l;       a[l] = 1;     }     l = r = 0;     if (a[1] == 1) l++;     if (a[(int)1e6] == 1) l++;     for (i = 2, j = 1e6 - 1; i < j && l < n; i++, j--, r++) {       if (a[i] == 1) l++;       if (a[j] == 1) l++;     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int AbsDifference(int a, int b) {     if (a >= b) return a - b;     return b - a;   }   long long AbsDifference(long long a, long long b) {     if (a >= b) return a - b;     return b - a;   }   const int mod = 1000000007;   const int mod2 = 1000000009;   const int inf = 1 << 30;   const long long infLL = 1ll << 62;   const int impossible = -1;   struct stoyan_point {     int x, y;     int id;   };   struct stoyan_pointLL {     long long x, y;     int id;   };   struct stoyan_segment {     stoyan_point first, second;     int lenght;     bool type;     int id;   };   struct stoyan_segmentLL {     stoyan_pointLL first, second;     long long lenght;     bool type;     int id;   };   string translate(int number, int lenght, int k) {     string ans;     while (number) {       ans += char(( 1 ) + number & 1);       number >>= 1;     }     reverse(ans.begin(), ans.end());     return ans;   }   vector<int> find_divisors(long long number) {     vector<int> ans;     int sq = sqrt(number), j;     for (j = 1; j <= sq; j++) {       if (number % j == 0) {         ans.push_back(j);         if (j * j != number) ans.push_back(number / j);       }     }     sort(ans.begin(), ans.end());     return ans;   }   int cnt_divisors(long long number) {     int ans = 0;     int sq = sqrt(number), j;     for (j = 1; j <= sq; j++) {       if (number % j == 0) {         ans++;         if (j * j != number) ans++;       }     }     return ans;   }   int n;   string s;   int x, y;   int where_last = 0;   int AnswerProblem;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     cin >> s;     for (int i = 0; i < int(s.size()); i++) {       if (s[i] ==  R )         x++;       else         y++;       if (y > x) {         if (where_last == -1) {           AnswerProblem++;         }         where_last = 1;       }       if (y < x) {         if (where_last == 1) {           AnswerProblem++;         }         where_last = -1;       }     }     cout << AnswerProblem << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[101];   int n, ans;   int check(int k) {     int cnt = 0, sum = 0;     for (int i = 0; i < n; i++) {       sum += c[i] -  0 ;       if (sum > k) return 0;       if (sum == k) sum = 0, cnt++;     }     return (sum == 0 && cnt > 1) ? 1 : 0;   }   int main() {     scanf( %d , &n);     scanf( %s , c);     for (int i = 0; i <= 1000; i++) {       if (check(i)) {         printf( YES );         return 0;       }     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long w, m, k;   int main() {     scanf( %I64d%I64d%I64d , &w, &m, &k);     w /= k;     if (!w) {       puts( 0 );       return 0;     }     long long cnt = 0;     long long tmp = m;     while (tmp) {       cnt++;       tmp /= 10;     }     tmp = 1;     for (int i = 0; i < cnt; i++) tmp *= 10;     long long x = m - 1, y = tmp - 1;     while (w) {       if (w < cnt) break;       if (w >= (y - x) * cnt) {         w -= (y - x) * cnt;         x = y;         y = y * 10 + 9;         cnt++;       } else {         x += w / cnt;         w = 0;         break;       }     }     cout << x - m + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = (1e19);   int n, m;   int a[105];   bool cmp(int a, int b) { return a > b; }   bool check(int d) {     int i = 1, k = 0, ans = 0;     while (a[i] - k > 0 && i <= n) {       ans += (a[i] - k);       if (i % d == 0) {         k++;       }       if (ans >= m) {         return true;       }       i++;     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ans += a[i];     }     if (ans < m) {       printf( -1 );     } else {       sort(a + 1, a + 1 + n, cmp);       int l = 1, r = n, p;       while (l <= r) {         int mid = (l + r) / 2;         if (check(mid)) {           r = mid - 1;           p = mid;         } else {           l = mid + 1;         }       }       printf( %d n , p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     map<long long, long long> mp;     long long ans = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (mp[a[i]]) {         mp[a[i]] = 0;         mp[i + 1] = 1;       } else {         mp[i + 1] = 1;         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int MAXN = 1005;   vector<int> child[200000];   int ceng[200000];   void dfs(int v, int ii) {     ceng[ii]++;     for (int i = 0; i < child[v].size(); i++) {       dfs(child[v][i], ii + 1);     }   }   int main() {     int n;     scanf( %d , &n);     int temp;     for (int i = 2; i <= n; i++) {       scanf( %d , &temp);       child[temp].push_back(i);     }     int ans = 0;     dfs(1, 1);     for (int i = 1; i <= n; i++) {       if (ceng[i] % (2) == 0) ceng[i] = 0;       if (ceng[i]) ceng[i] = 1;       ans += ceng[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 309, mod = 1e9 + 7;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c - 48, c = getchar();     }     return x * f;   }   void pls(long long &x, long long y) {     x += y;     x = (x >= mod ? x - mod : x);   }   long long n, a[N], s[N];   namespace Solution_1 {   long long s[N], f[2][N][N];   void solve() {     long long d = 0;     for (register long long i = (1); i <= (n); i++) {       if (a[i] == a[i - 1])         s[i] = s[i - 1] + 1;       else         s[i] = 0;     }     f[0][0][0] = 1;     for (register long long i = (1); i <= (n); i++) {       if (a[i] != a[i - 1]) {         for (register long long j = (0); j <= (i); j++)           for (register long long k = (1); k <= (s[i - 1]); k++)             pls(f[d ^ 1][j][0], f[d ^ 1][j][k]), f[d ^ 1][j][k] = 0;       }       for (register long long j = (0); j <= (i); j++) {         long long upk = min(s[i], j);         for (register long long k = (0); k <= (upk); k++) {           if (j && k)             pls(f[d][j][k], f[d ^ 1][j - 1][k - 1] * (2 * s[i] - k + 1) % mod);           pls(f[d][j][k], f[d ^ 1][j][k] * (i - 2 * s[i] + 2 * k - j) % mod);           pls(f[d][j][k], f[d ^ 1][j + 1][k] * (j - k + 1) % mod);         }       }       memset(f[d ^ 1], 0, sizeof(f[d ^ 1]));       if (i != n) d ^= 1;     }     printf( %lld n , f[d][0][0]);   }   }  // namespace Solution_1   signed main() {     n = read();     for (register long long i = (1); i <= (n); i++) {       a[i] = read();       for (long long j = 2; j * j <= a[i]; j++)         while (a[i] % (j * j) == 0) a[i] /= j * j;     }     sort(a + 1, a + n + 1);     Solution_1::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int poww(int a, int b) {     for (int i = 0; i < b; i++) a *= a;     return a;   }   int main() {     int n, t;     cin >> n;     if (n < 10) {       cout << n << endl;       return 0;     }     long long i = 2;     long long sum = 9;     long long x = 10, v[] = {999999999, 99999999, 9999999, 999999, 99999, 9999,                              999,       99,       9,       0,      0};     reverse(v, v + 11);     for (int i = 10; i > 1; i--) {       if (n - v[i] > 0) {         sum += (n - v[i]) * i;         n -= (n - v[i]);       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 3;   int sz, mn, o, rt, s[N], s2[N], fa[N], ch[N][2], lf[N], cnt;   bool vis[N];   void findrt(int u) {     if (vis[u]) {       s[u] = 0;       return;     }     int mx;     if (ch[u][0]) {       int x = ch[u][0], y = ch[u][1];       findrt(x), findrt(y);       s[u] = s[x] + s[y] + 1, mx = max(s2[u] = sz - s[u], max(s[x], s[y]));     } else       s[u] = 1, mx = s2[u] = sz - s[u];     if (mx < mn) mn = mx, o = u;   }   void lk(int f, int c, int x) { ch[fa[x] = f][c] = x; }   void solve(int u, int f, int c, int nd) {     vis[u] = true;     char str[5];     int x = ch[u][0], y = ch[u][1];     if (x) {       printf( %d %d %d n , lf[x], lf[y], nd);       fflush(stdout), scanf( %s , str);     }     if (!x || str[0] ==  X ) {       if (!fa[u] || vis[fa[u]]) {         if (!fa[u])           rt = ++cnt;         else           lk(fa[u], c, ++cnt);         lk(cnt, 0, u), lk(cnt, 1, nd), lf[cnt] = lf[nd] = nd;         return;       }       sz = mn = s2[u], findrt(f ? ch[f][c] : rt), solve(o, f, c, nd);     } else {       int t = str[0] ==  Y , x = ch[u][t];       if (vis[x]) {         lk(++cnt, 0, x), lk(cnt, 1, nd), lk(u, t, cnt), lf[cnt] = lf[nd] = nd;         return;       }       sz = mn = s[x], findrt(x), solve(o, u, t, nd);     }   }   int main() {     srand(time(0));     int n;     scanf( %d , &n);     cnt = n;     lk(rt = ++cnt, 0, 1), lk(rt, 1, 2), lf[1] = lf[rt] = 1, lf[2] = 2;     for (int i = 3; i <= n; ++i) {       memset(vis, 0, sizeof(vis));       sz = mn = 2 * (i - 1) - 1, findrt(rt), solve(o, 0, 0, i);     }     puts( -1 );     for (int i = 1; i <= cnt; ++i) printf( %d  , fa[i] ? fa[i] : -1);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long tot = 0;       long long cont = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  -  && cont == 0) {           tot += i + 1;         } else if (s[i] ==  + ) {           cont++;         } else if (s[i] ==  - ) {           cont--;         }       }       tot += s.size();       cout << tot <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, g, b;     cin >> t;     while (t--) {       cin >> n >> g >> b;       long long val = (n + 1) / 2;       long long total = val / g;       long long sum = total * g;       if (val % g) {         total++;       }       total--;       sum += (b * total);       sum += (val % g);       if (sum <= n)         cout << n << endl;       else         cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   using ll = long long;   using ld = long double;   const int MOD = 1e9 + 7, inf = 1e9, N = 2e5 + 1;   const ll INF = 1e18;   ld tic, tac;   void solve() {     string str, ans =   ;     cin >> str;     int cr = 0, cs = 0, cp = 0;     for (int i = 0; i < (str.size()); ++i) {       if (str[i] ==  R )         cr++;       else if (str[i] ==  P )         cp++;       else         cs++;     }     char ch;     if (cr >= cp && cr >= cs)       ch =  P ;     else if (cp >= cs && cp >= cr)       ch =  S ;     else       ch =  R ;     cout << string(str.size(), ch) <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535;   double cot(double x) { return cos(x) / sin(x); }   int main() {     double r, n;     cin >> n >> r;     cout << fixed << setprecision(9)          << n * r * r * sin(PI / n) / (1 + 2 * cos(PI / n));     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.14159265358979323846;   using namespace std;   int main() {     std::map<int, long long> pairs;     std::set<long long> positive;     int n;     std::cin >> n;     std::vector<int> nums(n);     for (int i = 0; i < n; ++i) {       std::cin >> nums[i];       if (nums[i] > 0) {         positive.insert(nums[i]);       }       pairs[nums[i]]++;     }     long long result = 0;     if (pairs[0]) {       result += pairs[0] * (pairs[0] - 1) / 2;     }     for (std::set<long long>::iterator itr = positive.begin();          itr != positive.end(); ++itr) {       result += pairs[*itr] * pairs[-(*itr)];     }     std::cout << result << std::endl;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4244 4267 4018 4996 4800)   using namespace std;   istream& in = std::cin;   ostream& out = std::cout;   int n, m, total;   int xstart = -1, ystart;   vector<vector<char>> p;   int res = -1;   bool ones(int x1, int y1, int x2, int y2) {     for (int i = x1; i <= x2; ++i)       for (int j = y1; j <= y2; ++j)         if (!p[i][j]) return false;     return true;   }   int count(int w, int h) {     int x = ::xstart, y = ::ystart;     int res = 0;     while (x < n && y < m && p[x][y]) {       if (x + h < n && p[x + h][y] && (y + w == m || !p[x][y + w])) {         if (ones(x, y, x, y + w - 1))           res += w;         else           return -1;         ++x;       } else if (y + w < m && p[x][y + w] && (x + h == n || !p[x + h][y])) {         if (ones(x, y, x + h - 1, y))           res += h;         else           return -1;         ++y;       } else         break;     }     if (x < n && y < m && p[x][y]) {       if (ones(x, y, x + h - 1, y + w - 1))         res += w * h;       else         return -1;     }     return res;   }   void trysolve() {     int w = 0, h = 0;     int i;     for (i = ystart; i < m && p[xstart][i]; ++i, ++w)       ;     int prev = -1;     for (i = xstart; i < n && p[i][ystart]; ++i) {       if (ystart + w < m && p[i][ystart + w] && prev == -1) {         prev = i;       }     }     h = prev == -1 ? 1 : i - prev;     if (count(w, h) == total && (res == -1 || w * h < res)) res = w * h;   }   template <class T>   vector<T> transpose(vector<T> const& t) {     vector<T> u(t[0].size(), T(t.size()));     for (unsigned i = 0; i < t.size(); ++i)       for (unsigned j = 0; j < t[i].size(); ++j) u[j][i] = t[i][j];     return u;   }   int main() {     std::ios_base::sync_with_stdio(false);     in >> n >> m;     string s;     p.resize(n, vector<char>(m));     for (auto& row : p) {       in >> s;       for (int i = 0; i < s.size(); ++i) row[i] = s[i] ==  X  ? 1 : 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (p[i][j]) {           ++total;           if (xstart == -1) {             xstart = i;             ystart = j;           }         }       }     }     trysolve();     p = transpose(p);     swap(xstart, ystart);     swap(n, m);     trysolve();     out << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   #define pii pair<int, int>   int32_t mod = 1e9 + 7;      void solveCase()   {       int n = 0, m = 0;       cin >> n >> m;          vector<vector<int>> mp(m, vector<int>(26, 0));       for (int i = 0; i < n; i++)       {           string s;           cin >> s;           for (int i = 0; i < m; i++)               mp[i][s[i] -  a ]++;       }       for (int i = 0; i < n - 1; i++)       {           string s;           cin >> s;           for (int i = 0; i < m; i++)               mp[i][s[i] -  a ]--;       }          for (int i = 0; i < m; i++)           for (int x = 0; x < 26; x++)               if (mp[i][x])                   cout << char( a  + x);       cout <<   n ;   }      int32_t main()   {       ios::sync_with_stdio(false), cin.tie(NULL);       int t = 0;       cin >> t;       while (t--)           solveCase();   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n;     std::cin >> n;     long long int ans[n];     for (long long int i = 0; i < n; i++) {       std::cin >> ans[i];     }     long long int count[n];     memset(count, 0, sizeof(count));     for (long long int i = 0; i < n; i++) {       count[i] += (ans[i] * 15);       for (long long int j = 0; j < ans[i]; j++) {         long long int x;         std::cin >> x;         count[i] += (x * 5);       }     }     long long int min = (*(std::min_element(count, count + n)));     std::cout << min <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int sz[N];   struct Edge {     long long from, to, val, nex;   } edge[N];   int h[N], idx;   void add(long long u, long long v, long long w) {     Edge E = {u, v, w, h[u]};     edge[idx] = E;     h[u] = idx++;   }   void init() {     memset(h, -1, sizeof(h));     idx = 0;   }   long long ans;   void dfs1(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = edge[i].nex) {       int v = edge[i].to;       if (v == fa) continue;       dfs1(v, u);       sz[u] += sz[v];       if (sz[v] & 1) {         ans += edge[i].val;       }     }   }   int n;   long long ans2;   void dfs2(int u, int fa) {     sz[u] = 1;     for (int i = h[u]; ~i; i = edge[i].nex) {       int v = edge[i].to;       if (v == fa) continue;       dfs2(v, u);       sz[u] += sz[v];       ans2 += min(sz[v], n - sz[v]) * edge[i].val;     }   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       n = n * 2;       init();       ans = ans2 = 0;       for (int i = 1; i < n; i++) {         long long u, v, w;         cin >> u >> v >> w;         add(u, v, w);         add(v, u, w);       }       dfs1(1, -1);       printf( %lld  , ans);       dfs2(1, -1);       printf( %lld  , ans2);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10100;   int i, j, k, n, m, ch, c;   int s[N], t[N];   long long ans, f[N];   void R(int &x) {     x = 0;     ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();   }   void W(long long x) {     if (x >= 10) W(x / 10);     putchar(x % 10 +  0 );   }   long long min(long long x, long long y) {     if (x < y) return x;     return y;   }   int main() {     R(n);     R(c);     for (i = 1; i <= n; i++) R(s[i]);     for (i = 1; i <= n; i++) R(t[i]);     memset(f, 60, sizeof f);     f[0] = 0;     for (i = 1; i <= n; i++)       for (j = i - 1; j >= 0; j--) {         f[j + 1] = min(f[j + 1], f[j] + t[i]);         f[j] = (long long)c * j + f[j] + s[i];       }     ans = 1000000000000000000ll;     for (i = 0; i <= n; i++) ans = min(ans, f[i]);     W(ans);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int color[100005];   vector<int> DSK[100005];   int num = 0, block_size;   int S[100005], E[100005], c[100005];   struct query {     int l, r, k, id;   } Q[100005];   void DFS(int u, int pre) {     S[u] = ++num;     c[num] = color[u];     for (int i = 0; i < DSK[u].size(); i++) {       int w = DSK[u][i];       if (w != pre) DFS(w, u);     }     E[u] = num;   }   int cnt[100005], ans[100005], res[100005];   void add(int i) {     cnt[c[i]]++;     ans[cnt[c[i]]]++;   }   void del(int i) {     ans[cnt[c[i]]]--;     cnt[c[i]]--;   }   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 <= n; i++) cin >> color[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       DSK[u].push_back(v);       DSK[v].push_back(u);     }     DFS(1, -1);     for (int i = 1; i <= m; i++) {       int v, k;       cin >> v >> k;       Q[i] = {S[v], E[v], k, i};     }     block_size = sqrt(n);     sort(Q + 1, Q + 1 + m, [](const query &a, const query &b) {       if (a.l / block_size == b.l / block_size) return a.r < b.r;       return a.l / block_size < b.l / block_size;     });     int curL = 1, curR = 0;     for (int i = 1; i <= m; i++) {       int L = Q[i].l, R = Q[i].r;       while (curL > L) {         add(curL - 1);         curL--;       }       while (curR < R) {         add(curR + 1);         curR++;       }       while (curL < L) {         del(curL);         curL++;       }       while (curR > R) {         del(curR);         curR--;       }       res[Q[i].id] = ans[Q[i].k];     }     for (int i = 1; i <= m; i++) cout << res[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, count, flag, j, x;     cin >> n;     long long int h[n], a[n], c[n], maxc, no2, task[n], temp, tasknumber[n][n],         flaggy;     flaggy = 0;     for (i = 0; i < n; i++) {       cin >> h[i];     }     for (i = 0; i < n; i++) {       c[i] = 0;       task[i] = i + 1;     }     for (i = (n - 1); i >= 0; i--) {       for (j = 0; j < i; j++) {         if (h[j] > h[j + 1]) {           temp = h[j + 1];           h[j + 1] = h[j];           h[j] = temp;           temp = task[j + 1];           task[j + 1] = task[j];           task[j] = temp;         }       }     }     a[0] = h[0];     count = 1;     c[0] = 1;     maxc = 1;     no2 = 0;     tasknumber[0][0] = task[0];     for (i = 1; i < n; i++) {       flag = 0;       for (j = 0; j < count; j++) {         if (h[i] == a[j]) {           flag = 1;           c[j] = c[j] + 1;           tasknumber[j][(c[j] - 1)] = task[i];           if (c[j] > maxc) {             maxc = c[j];           }           if (c[j] == 2) {             no2 = no2 + 1;           }           break;         }       }       if (flag == 1) {       } else {         count++;         a[count - 1] = h[i];         c[count - 1] = 1;         tasknumber[count - 1][0] = task[i];       }     }     if (maxc >= 3) {       cout <<  YES  << endl;       for (x = 0; x < 3; x++) {         for (i = 0; i < count; i++) {           if (c[i] == 1) {             cout << tasknumber[i][0] <<    ;           } else if (c[i] == 2) {             cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;           } else if (c[i] == 3) {             if (x == 0) {               cout << tasknumber[i][0] <<     << tasknumber[i][1] <<                        << tasknumber[i][2] <<    ;             }             if (x == 1) {               cout << tasknumber[i][0] <<     << tasknumber[i][2] <<                        << tasknumber[i][1] <<    ;             }             if (x == 2) {               cout << tasknumber[i][1] <<     << tasknumber[i][0] <<                        << tasknumber[i][2] <<    ;             }           } else if (c[i] >= 3) {             if (x == 0) {               cout << tasknumber[i][0] <<     << tasknumber[i][1] <<                        << tasknumber[i][2] <<    ;               for (j = 3; j < c[i]; j++) {                 cout << tasknumber[i][j] <<    ;               }             }             if (x == 1) {               cout << tasknumber[i][0] <<     << tasknumber[i][2] <<                        << tasknumber[i][1] <<    ;               for (j = 3; j < c[i]; j++) {                 cout << tasknumber[i][j] <<    ;               }             }             if (x == 2) {               cout << tasknumber[i][1] <<     << tasknumber[i][0] <<                        << tasknumber[i][2] <<    ;               for (j = 3; j < c[i]; j++) {                 cout << tasknumber[i][j] <<    ;               }             }           }         }         cout << endl;       }     } else if (maxc == 2) {       if (no2 >= 2) {         cout <<  YES  << endl;         for (x = 0; x < 3; x++) {           flaggy = 0;           for (i = 0; i < count; i++) {             if (c[i] == 1) {               cout << tasknumber[i][0] <<    ;             } else if (c[i] == 2) {               flaggy = flaggy + 1;               if (x == 0) {                 if (flaggy == 1) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 }                 if (flaggy == 2) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 } else if (flaggy >= 3) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 }               }               if (x == 1) {                 if (flaggy == 1) {                   cout << tasknumber[i][1] <<     << tasknumber[i][0] <<    ;                 }                 if (flaggy == 2) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 } else if (flaggy >= 3) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 }               }               if (x == 2) {                 if (flaggy == 1) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 }                 if (flaggy == 2) {                   cout << tasknumber[i][1] <<     << tasknumber[i][0] <<    ;                 } else if (flaggy >= 3) {                   cout << tasknumber[i][0] <<     << tasknumber[i][1] <<    ;                 }               }             }           }           if (x == 2) {             break;           }           cout << endl;         }       } else {         cout <<  NO ;       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6;   const int M = 10010;   const int K = 510;   const int LIT = 2500;   const int INF = 1 << 30;   int n, m[N][N], tot, need;   vector<int> v, vis;   int row[N], col[N], dia1, dia2;   int cr[N], cc[N], cd1, cd2;   void init() {     memset(m, 0, sizeof(m));     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     dia1 = dia2 = 0;     memset(cr, 0, sizeof(cr));     memset(cc, 0, sizeof(cc));     cd1 = cd2 = 0;     tot = n * n;     need = 0;     v = vector<int>(n * n);     vis = vector<int>(n * n);     for (int i = 0; i < tot; i++) cin >> v[i];     sort(v.begin(), v.end());     for (int i = 0; i < tot; i++) need += v[i];     need /= n;   }   void insert(int x, int y, int p, int ord) {     m[x][y] = v[p];     vis[p] = (ord > 0) ? 1 : 0;     int tmp = v[p] * ord;     row[x] += tmp;     cr[x] += ord;     col[y] += tmp;     cc[x] += ord;     if (x == y) dia1 += tmp, cd1 += ord;     if (x + y == n + 1) dia2 += tmp, cd2 += ord;   }   void out(int sum) {     printf( %d n , sum);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) printf( %d  , m[i][j]);       printf(  n );     }   }   bool check() {     int sum = dia1;     for (int i = 1; i <= n; i++)       if (sum != row[i]) return 0;     for (int i = 1; i <= n; i++)       if (sum != col[i]) return 0;     if (dia1 != dia2) return 0;     out(sum);     return 1;   }   bool dfs1(int x, int y) {     if (x > n) return check();     int xx = x, yy = y + 1;     if (yy > n) xx++, yy = 1;     for (int i = 0; i < tot; i++) {       if (vis[i]) continue;       insert(x, y, i, 1);       if (dfs1(xx, yy)) return 1;       insert(x, y, i, -1);     }     return 0;   }   const int nxt[][2] = {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {3, 1}, {1, 4},                         {4, 1}, {2, 2}, {3, 3}, {4, 4}, {2, 3}, {2, 4},                         {3, 2}, {3, 4}, {4, 2}, {4, 3}};   const int bnd = 16;   pair<long long, long long> getmax2() {     pair<long long, long long> ret = make_pair(-INF, -INF);     for (int i = 0; i < tot; i++) {       if (vis[i]) continue;       if (ret.first < v[i]) {         swap(ret.first, ret.second);         ret.first = v[i];       } else if (ret.second < v[i])         ret.second = v[i];     }     return ret;   }   bool validate() {     pair<long long, long long> now = getmax2();     for (int i = 1; i <= n; i++) {       if (cr[i] == 3) {         bool f = 0;         for (int j = 0; j < tot; j++)           if (!vis[j] && row[i] + v[j] == need) f = 1;         if (!f) return 0;       }       if (cc[i] == 3) {         bool f = 0;         for (int j = 0; j < tot; j++)           if (!vis[j] && col[i] + v[j] == need) f = 1;         if (!f) return 0;       }     }     if (cd1 == 3) {       bool f = 0;       for (int i = 0; i < tot; i++)         if (!vis[i] && dia1 + v[i] == need) f = 1;       if (!f) return 0;     }     if (cd2 == 3) {       bool f = 0;       for (int i = 0; i < tot; i++)         if (!vis[i] && dia2 + v[i] == need) f = 1;       if (!f) return 0;     }     return 1;   }   bool dfs(int p) {     if (p > bnd) return check();     int x = nxt[p][0], y = nxt[p][1];     for (int i = 0; i < tot; i++) {       if (vis[i]) continue;       insert(x, y, i, 1);       if (validate() && dfs(p + 1)) return 1;       insert(x, y, i, -1);     }     return 0;   }   void solve() {     if (n <= 3)       dfs1(1, 1);     else       dfs(0);   }   int main() {     while (cin >> n) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     cout << s << (reverse(s.begin(), s.end()), s) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   long long Pow(long long x, long long k, long long _p) {     long long ans = 1;     for (; k; k >>= 1, x = x * x % _p)       if (k & 1) (ans *= x) %= _p;     return ans;   }   const int N = 100005, _p = 998244353;   const int _M = N, _N = N;   template <class V>   struct FT {     vector<V> aa, bb;     V w[2][_M * 2 + 5], rev[_M * 2 + 5], tmp;     void FFT(vector<V> &A, int m, int op) {       int N = 1 << m;       V w0 = Pow(3, (_p - 1) / N, _p);       w[0][0] = w[1][0] = 1;       for (int i = (1); i < (N); i++)         w[0][i] = w[1][N - i] = (long long)w[0][i - 1] * w0 % _p;       for (int i = (1); i < (N); i++)         rev[i] = (rev[i >> 1] >> 1) | (i & 1) << m - 1;       for (int i = (0); i < (N); i++)         if (i < rev[i]) swap(A[i], A[rev[i]]);       for (int i = 1; i < N; i <<= 1)         for (int j = 0, t = N / (i << 1); j < N; j += i << 1)           for (int k = j, l = 0; k < j + i; k++, l += t) {             V x = A[k], y = (long long)w[op][l] * A[k + i] % _p;             A[k] = (x + y) % _p, A[k + i] = (x - y + _p) % _p;           }       if (op) {         tmp = Pow(N, _p - 2, _p);         for (int i = (0); i < (N); i++) A[i] = 1ll * A[i] * tmp % _p;       }     }     vector<V> multiply(vector<V> A, vector<V> B, vector<V> *C = NULL,                        int op = 0) {       int lena = A.size(), lenb = B.size(), len = 1, L = 0;       aa = A, bb = B;       while (len < lena + lenb - 1) len <<= 1, ++L;       aa.resize(len), bb.resize(len);       if (op) reverse((bb).begin(), (bb).end());       FFT(aa, L, 0), FFT(bb, L, 0);       if (!C) C = &A;       (*C).resize(len);       for (int i = (0); i < (len); i++) (*C)[i] = (long long)aa[i] * bb[i] % _p;       FFT(*C, L, 1);       if (op) reverse((*C).begin(), (*C).end());       (*C).resize(lena + lenb - 1);       return *C;     }   };   int n, k, x, y, siz[N];   vector<int> V[N], P[N];   long long ans = 0, s = 0, fac[N], inv[N], dp[N];   FT<int> T;   vector<int> solve(int l, int r, const vector<int> &a) {     if (l == r) return vector<int>{1, a[l]};     int mid = l + r >> 1;     return T.multiply(solve(l, mid, a), solve(mid + 1, r, a));   }   void dfs(int x, int p) {     siz[x] = 1;     for (auto y : V[x]) {       if (y == p) continue;       dfs(y, x), siz[x] += siz[y], P[x].push_back(siz[y]);     }     if (P[x].empty())       P[x].push_back(1);     else       P[x] = solve(0, (int)P[x].size() - 1, P[x]);     for (int i = (0); i < (min(k, (int)P[x].size() - 1) + 1); i++)       dp[x] += inv[k - i] % _p * P[x][i] % _p;     dp[x] %= _p, (dp[x] *= fac[k]) %= _p;   }   void dfs(int x, int p, long long s1, long long s2) {     ans += dp[x] * (s1 - s2) % _p, ans %= _p;     P[x].push_back(0);     unordered_map<int, int> M;     for (int i = ((int)P[x].size()) - 1; i >= (1); i--)       P[x][i] += (long long)P[x][i - 1] * (n - siz[x]) % _p, P[x][i] %= _p;     for (auto y : V[x]) {       if (y == p || M.find(siz[y]) != M.end()) continue;       long long ret = 0;       vector<int> tmp = P[x];       for (int i = (0); i < ((int)tmp.size() - 1); i++)         tmp[i + 1] -= (long long)tmp[i] * siz[y] % _p, tmp[i + 1] %= _p;       for (int i = (0); i < (min(k, (int)tmp.size() - 1) + 1); i++)         ret += tmp[i] * fac[k] % _p * inv[k - i] % _p, ret %= _p;       M[siz[y]] = ret;     }     for (auto y : V[x]) {       if (y == p) continue;       dfs(y, x, (s1 + M[siz[y]]) % _p, (s2 + dp[x]) % _p);     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     scanf( %d%d , &n, &k);     for (int i = (1); i < (n); i++)       scanf( %d%d , &x, &y), V[x].push_back(y), V[y].push_back(x);     fac[0] = inv[0] = inv[1] = 1;     for (int i = (2); i < (N); i++) inv[i] = (_p - _p / i) * inv[_p % i] % _p;     for (int i = (1); i < (N); i++)       inv[i] = inv[i - 1] * inv[i] % _p, fac[i] = fac[i - 1] * i % _p;     if (k == 1) {       cout << (long long)n * (n - 1) / 2 % _p << endl;       return 0;     }     dfs(1, 0), dfs(1, 0, 0, 0);     for (int i = (1); i < (n + 1); i++)       ans += dp[i] * s % _p, s += dp[i], ans %= _p, s %= _p;     cout << (ans + _p) % _p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool can(int x, int y, int a, int b) {     cout <<  ?   << x <<     << y <<     << a <<     << b << endl;     string ans;     cin >> ans;     if (ans ==  BAD ) exit(0);     return ans ==  YES ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int x = 1, y = 1;     string ord1(n - 1,    ), ord2(n - 1,    );     int i = 0;     while (i < n - 1) {       if (can(x + 1, y, n, n)) {         ++x;         ord1[i] =  D ;       } else {         ord1[i] =  R ;         ++y;       }       ++i;     }     x = n;     y = n;     i = 0;     while (i < n - 1) {       if (can(1, 1, x, y - 1)) {         ord2[i] =  R ;         --y;       } else {         --x;         ord2[i] =  D ;       }       ++i;     }     reverse(ord2.begin(), ord2.end());     cout <<  !   << ord1 << ord2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 507;   int n, m;   int E[Maxn][Maxn];   vector<int> V[Maxn];   int ans[Maxn];   bool mark[Maxn];   void dfs(int v) {     mark[v] = true;     for (int i = 0; i < V[v].size(); i++) {       int u = V[v][i];       if (!mark[u])         ans[u] = 2 - ans[v], dfs(u);       else if (ans[u] == ans[v]) {         cout <<  No  << endl;         exit(0);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       E[u][v] = E[v][u] = 1;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (!E[i][j] and i != j) V[i].push_back(j);     for (int i = 1; i <= n; i++) {       if (!V[i].size())         ans[i] = 1, mark[i] = true;       else if (!mark[i])         ans[i] = 2, dfs(i);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++) {         if (E[i][j] and abs(ans[i] - ans[j]) == 2) return cout <<  No  << endl, 0;       }     cout <<  Yes  << endl;     for (int i = 1; i <= n; i++) cout << (char)(ans[i] +  a );     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       string s;       cin >> n >> m >> s;       vector<int> pref(n);       for (int i = 0; i < m; ++i) {         int p;         cin >> p;         ++pref[p - 1];       }       for (int i = n - 1; i > 0; --i) {         pref[i - 1] += pref[i];       }       vector<int> ans(26);       for (int i = 0; i < n; ++i) {         ans[s[i] -  a ] += pref[i];         ++ans[s[i] -  a ];       }       for (int i = 0; i < 26; ++i) {         cout << ans[i] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 4;   int main() {     vector<pair<long long, char> > ans;     long long n, st[MAX_N],         pr[MAX_N] = {             0,         };     long long sum = 0;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &st[i]);       pr[i] = st[i];       sum += (1ll * st[i]);     }     long long k, last[MAX_N];     scanf( %lld , &k);     for (int i = 0; i < k; i++) {       scanf( %lld , &last[i]);       sum = sum - last[i];     }     if (sum != 0) {       cout <<  NO ;       return 0;     }     int left = n - 1, left_last = k - 1, prev;     while (left >= 0 && left_last >= 0) {       if (st[left] != last[left_last]) {         if (last[left_last] < st[left]) {           cout <<  NO ;           return 0;         }         prev = left;         while (left >= 0 && st[left] < last[left_last]) {           left--;           st[left] = st[left] + st[left + 1];         }         if (left < 0 || st[left] != last[left_last]) {           cout <<  NO ;           return 0;         }         long long max_ = pr[left], find_ = left;         for (int i = left + 1; i < prev; i++)           if (max_ < pr[i]) {             max_ = pr[i];             find_ = i;           } else if (max_ == pr[i]) {             if (i < prev)               if (pr[i] > pr[i + 1]) {                 max_ = pr[i];                 find_ = i;               }           }         if (max_ < pr[prev]) {           find_ = prev;           max_ = pr[prev];         }         if (find_ == prev)           ;         else if (find_ == left && pr[find_ + 1] == pr[find_]) {           cout <<  NO ;           return 0;         }         if (find_ != left && max_ == pr[find_ - 1]) {           if (find_ < prev && pr[find_] > pr[find_ + 1])             ;           else {             cout <<  NO ;             return 0;           }         }         int kol1 = prev - find_;         int kol2 = find_ - left;         if (find_ != left && pr[find_ - 1] < pr[find_]) {           ans.push_back(make_pair(find_ + 1,  L ));           kol2--;           find_--;         }         while (kol1 > 0) {           ans.push_back(make_pair(find_ + 1,  R ));           kol1--;         }         while (kol2 > 0) {           ans.push_back(make_pair(find_ + 1,  L ));           find_--;           kol2--;         }       }       left--;       left_last--;     }     cout <<  YES  << endl;     for (auto it : ans) {       printf( %lld %c n , it.first, it.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }   int N;   int a[2010], b[2010], c[2010];   vector<pair<long long, long long> > v;   long long func(void) {     int i, j;     int ans = 0;     i = 0;     while (i < v.size()) {       for (j = i; j < v.size(); j++)         if (v[j] != v[i]) break;       int d = j - i;       ans += d * (d - 1) / 2;       i = j;     }     return ans;   }   int main(void) {     int i, j;     cin >> N;     for ((i) = 0; (i) < (int)(N); (i)++) scanf( %d%d%d , &a[i], &b[i], &c[i]);     long long ans = 0;     int zero = 0;     for ((i) = 0; (i) < (int)(N); (i)++)       if (c[i] == 0) zero++;     if (zero == 2) ans += N - 2;     for ((i) = 0; (i) < (int)(N); (i)++)       if (c[i] != 0) {         v.clear();         long long px = a[i] * a[i] + b[i] * b[i];         long long qx = a[i] * c[i];         long long py = a[i] * a[i] + b[i] * b[i];         long long qy = b[i] * c[i];         for ((j) = 0; (j) < (int)(i); (j)++)           if (c[j] != 0) {             long long px2 = a[j] * a[j] + b[j] * b[j];             long long qx2 = a[j] * c[j];             long long py2 = a[j] * a[j] + b[j] * b[j];             long long qy2 = b[j] * c[j];             long long rx = px * px2;             long long sx = qx * px2 - px * qx2;             long long ry = py * py2;             long long sy = qy * py2 - py * qy2;             long long g =                 gcd(((sx) > 0 ? (sx) : -(sx)), ((sy) > 0 ? (sy) : -(sy)));             sx /= g;             sy /= g;             if (sx < 0 || (sx == 0 && sy < 0)) {               sx = -sx;               sy = -sy;             }             v.push_back(make_pair(sx, sy));           }         sort(v.begin(), v.end());         long long tmp = func();         ans += tmp;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test, n, i, j, a, b;     cin >> test;     for (i = 0; i < test; i++) {       cin >> n;       for (a = 2; a < n; a++) {         for (b = n - 1; b > a; b--) {           if (n % a == n % b) {             break;           }         }         if (n % a == n % b) {           cout << a <<     << b << endl;           break;         }       }     }     return 0;   }


#include <iostream>   #include <vector>   #include <cstring>   #include <algorithm>   #include <cassert>   #include <deque>   #include <map>   #include <queue>   #include <climits>   #include <set>   #include <stack>   #include <cmath>   #include <array>   #include <unordered_map>   #include <unordered_set>      using namespace std;      #define ll long long   #define MAX 100000   #define MAX1 10000   #define MAX2 100000   #define inf 1000000000   #define eps 1e-12   #define MOD 1000000007      int main() {          ios_base::sync_with_stdio(0);       cin.tie(0);   #ifndef ONLINE_JUDGE       freopen( in.txt ,  r , stdin);       freopen( out.txt ,  w , stdout);   #endif          int t;       cin >> t;       while (t-- > 00) {           int n;           cin >> n;           int a[n + 5], i;           bool is = true;           for (i = 1; i <= n; ++i) {               cin >> a[i];               is &= a[i] == i;           }           if (is) {               cout << 0 <<   n ;               continue;           }           cout << (a[1] == 1 or a[n] == n ? 1 : (a[1] == n and a[n] == 1) ? 3 : 2) <<   n ;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 5;   struct stu {     int id, sc;   } a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int i, j;     for (i = 1; i <= n; i++) {       a[i].id = i;       a[i].sc = 0;       int x;       for (j = 0; j < 4; j++) {         cin >> x;         a[i].sc += x;       }     }     for (i = 1; i < n; i++) {       for (j = i + 1; j <= n; j++) {         if (a[i].sc < a[j].sc || (a[i].sc == a[j].sc && a[i].id > a[j].id)) {           swap(a[i], a[j]);         }       }       if (a[i].id == 1) break;     }     cout << i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     int l[n];     for (int i = 0; i < n; ++i) {       l[i] = n;     }     for (int i = 0; i < n; ++i) {       for (int j = 1; j <= min(n - i - 1, i); ++j) {         if (s[i - j] == s[i] && s[i] == s[i + j]) {           l[i - j] = min(l[i - j], i + j);           break;         }       }     }     set<pair<int, int> > h;     for (int i = 0; i < n; ++i) {       h.insert({l[i], i});     }     long long sum = 0;     for (int i = 0; i < n; ++i) {       sum += n - ((*h.begin()).first);       h.erase({l[i], i});     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }   long long POWER(long long x, long long y, long long m) {     if (y == 0) return 1;     if (y % 2 == 0) {       long long temp = POWER(x, y / 2, m);       temp *= temp;       temp %= m;       return temp;     }     long long temp = POWER(x, y - 1, m);     temp *= x;     temp %= m;     return temp;   }   long long POWER(long long x, long long y) {     if (y == 0) return 1;     if (y % 2 == 0) {       long long temp = POWER(x, y / 2);       temp *= temp;       return temp;     }     long long temp = POWER(x, y - 1);     temp *= x;     return temp;   }   long long a[100010];   int main() {     ifstream fin( ali );     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long id = 0;     for (long long i = 1; i <= n; i++) {       if ((i * (i + 1)) / 2 >= k) {         id = i;         break;       }     }     if ((id * (id + 1) / 2) == k) {       cout << a[id] <<   n ;       return 0;     }     id--;     id = (id * (id + 1)) / 2;     for (int i = 1; i <= n; i++) {       id++;       if (id == k) {         cout << a[i] <<   n ;         return 0;       }     }     main();   }