#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 1e6 + 5;   struct Node {     long long cnt;     char c;     inline bool operator==(Node &b) { return cnt == b.cnt && c == b.c; }     inline bool operator!=(Node &b) { return cnt != b.cnt || c != b.c; }   } p1[MAXN], p2[MAXN], up1[MAXN], up2[MAXN], cpy[MAXN];   int nxt[MAXN];   int N, M, l1, l2;   char s[MAXN];   bool pos[MAXN];   inline void Unique1() {     l1 = 0;     long long now = 0;     for (int i = 1; i <= N; i++)       if (p1[i].c != p1[i - 1].c) {         up1[l1].cnt = now;         up1[++l1].c = p1[i].c;         now = p1[i].cnt;       } else         now += p1[i].cnt;     up1[l1].cnt = now;     N = l1;     memcpy(p1, up1, sizeof(p1));   }   inline void Unique2() {     l2 = 0;     long long now = 0;     for (int i = 1; i <= M; i++)       if (p2[i].c != p2[i - 1].c) {         up2[l2].cnt = now;         up2[++l2].c = p2[i].c;         now = p2[i].cnt;       } else         now += p2[i].cnt;     up2[l2].cnt = now;     M = l2;     memcpy(p2, up2, sizeof(p2));   }   namespace Subtask1 {   inline void Main() {     long long ans = 0;     for (int i = 1; i <= N; i++)       if (p1[i].c == p2[1].c) {         if (p1[i].cnt >= p2[1].cnt) ans += p1[i].cnt - p2[1].cnt + 1;       }     printf( %I64d n , ans);   }   }  // namespace Subtask1   namespace Subtask2 {   inline void Main() {     long long ans = 0;     for (int i = 1; i < N; i++)       if (p1[i].c == p2[1].c && p1[i + 1].c == p2[2].c) {         if (p1[i].cnt >= p2[i].cnt && p1[i + 1].cnt >= p2[2].cnt) ans++;       }     printf( %I64d n , ans);   }   }  // namespace Subtask2   int main() {     N = read();     M = read();     for (int i = 1; i <= N; i++) {       scanf( %s , s);       int len = strlen(s), ret = 0;       bool flg = false;       char c;       for (int j = 0; j < len; j++) {         if (s[j] ==  - ) {           flg = true;           continue;         }         if (!flg)           ret = ret * 10 + s[j] -  0 ;         else           c = s[j];       }       p1[i] = {ret, c};     }     Unique1();     for (int i = 1; i <= M; i++) {       scanf( %s , s);       int len = strlen(s), ret = 0;       bool flg = false;       char c;       for (int j = 0; j < len; j++) {         if (s[j] ==  - ) {           flg = true;           continue;         }         if (!flg)           ret = ret * 10 + s[j] -  0 ;         else           c = s[j];       }       p2[i] = {ret, c};     }     Unique2();     if (M == 1) return Subtask1::Main(), 0;     if (M == 2) return Subtask2::Main(), 0;     int p = 0;     for (int i = 2; i < M; i++) cpy[++p] = p2[i];     int j = 0;     for (int i = 2; i <= p; i++) {       while (j && cpy[i] != cpy[j + 1]) j = nxt[j];       if (cpy[i] == cpy[j + 1]) j++;       nxt[i] = j;     }     for (int i = 1; i <= N; i++) {       while (j && p1[i] != cpy[j + 1]) j = nxt[j];       if (p1[i] == cpy[j + 1]) j++;       if (j == p) pos[i] = true, j = nxt[j];     }     long long ans = 0;     for (int i = p + 1; i < N; i++)       if (pos[i]) {         if (p1[i + 1].c == p2[M].c && p1[i + 1].cnt >= p2[M].cnt &&             p1[i - p].c == p2[1].c && p1[i - p].cnt >= p2[1].cnt)           ans++;       }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, k;   const int MOD = 1000000007;   int dp[5005][5005], sum[5005];   int main() {     scanf( %d%d%d%d , &n, &b, &a, &k);     for (int i = b; i <= n; i++) sum[i] = 1;     dp[0][b] = 1;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         if (j == a) continue;         if (j > a)           dp[i][j] =               ((sum[n] - sum[(a + j) / 2] + MOD) % MOD - dp[i - 1][j] + MOD) %               MOD;         else           dp[i][j] = (sum[(a - 1 + j) / 2] - dp[i - 1][j] + MOD) % MOD;       }       sum[0] = 0;       for (int j = 1; j <= n; j++) sum[j] = (sum[j - 1] + dp[i][j]) % MOD;     }     printf( %d n , sum[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out <<  {  << p.first <<  ,   << p.second <<  } ;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& arr) {     for (auto& i : arr) {       in >> i;     }     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> arr) {     for (int64_t i = 0; i < (int64_t)arr.size() - 1; ++i) out << arr[i] <<    ;     if (arr.size()) out << arr.back();     out <<   n ;     return out;   }   int64_t get(int64_t n, int64_t k) {     if (n >= 0) {       return -n / k;     } else {       return abs(n) / k + (n % k != 0) * 1;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int64_t p, k;     cin >> p >> k;     if (p < k) {       cout << 1 <<   n ;       cout << p <<   n ;       return 0;     }     vector<int64_t> ans(500000);     ans[0] = -p / k;     for (int64_t i = 1; i < 500000; ++i) {       ans[i] = get(ans[i - 1], k);     }     if (ans.back() != 0) {       cout << -1 <<   n ;       return 0;     }     while (ans.back() == 0) ans.pop_back();     vector<int64_t> ans2(ans.size() + 1);     ans2[0] = ans[0] * k + p;     for (int64_t i = 1; i < ans.size(); ++i) {       ans2[i] = ans[i] * k + ans[i - 1];     }     ans2[ans.size()] = ans.back();     cout << ans2.size() <<   n ;     cout << ans2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, a[N], ans;   bool vis[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int now = 1, dir = 0, tot = 0;     while (tot < n) {       if (dir == 0) {         for (int i = now; i <= n; i++)           if (!vis[i] && tot >= a[i]) {             vis[i] = 1;             tot++;           }         now = n;         dir = 1;         if (tot < n) ans++;       } else {         for (int i = now; i >= 1; i--)           if (!vis[i] && tot >= a[i]) {             vis[i] = 1;             tot++;           }         now = 1;         dir = 0;         if (tot < n) ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxn = 5e3 + 100;   long long dp[25][mxn];   long long arr[mxn];   long long n, k;   bool Check(long long id, long long lo, long long hi, long long rtk) {     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (dp[id][mid] > rtk)         hi = mid - 1;       else if (dp[id][mid] < rtk)         lo = mid + 1;       else         return true;     }     return false;   }   int main() {     scanf( %lld%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &arr[i]);     sort(arr + 1, arr + n + 1);     for (int i = 1; i <= n; i++) dp[1][i] = arr[i];     for (int i = 2; i <= k; i++) {       for (long long j = 1; j <= n; j++) dp[i][j] = arr[j] * i;     }     long long q;     scanf( %lld , &q);     while (q--) {       long long tk;       scanf( %lld , &tk);       long long mn = 1e9;       long long ans = 0;       for (int i = 1; i <= k; i++) {         for (int j = 1; j <= n; j++) {           long long tmp = dp[i][j];           if (tmp > tk) break;           long long ans = i;           long long rem = k - i;           if (tmp == tk)             mn = min(ans, mn);           else {             for (int jj = 1; jj <= rem; jj++) {               if (Check(jj, j + 1, n, tk - tmp)) {                 mn = min(ans + jj, mn);                 break;               }             }           }         }       }       if (mn == 1e9) mn = -1;       printf( %lld n , mn);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s[100010][200], ans = 0x3f3f3f3f, vis[200], sub, cunt;   char a[100010];   bool check(int l, int r) {     int cnt = 0;     for (int i = 65; i <= 122; i++)       if (s[r][i] - s[l - 1][i]) cnt++;     return (cnt == cunt);   }   int find(int pos) {     int l = pos, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (check(pos, mid))         r = mid;       else         l = mid + 1;     }     if (check(pos, r))       return r;     else       return 0x3f3f3f3f;   }   int main() {     scanf( %d%s , &n, a + 1);     for (int i = 1; i <= n; i++) {       for (int j = 65; j <= 122; j++) s[i][j] = s[i - 1][j];       s[i][a[i]]++;       if (!vis[a[i]]) cunt++, vis[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       ans = min(ans, find(i) - i + 1);       if (--vis[a[i]] == 0) sub++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   char op[3];   long long res;   void Gao(vector<long long> a) {     if (a.size() == 1) {       if (res == -1)         res = a[0];       else         res = min(res, a[0]);       return;     }     vector<long long> tmp;     for (int i = 0; i < a.size(); i++)       for (int j = i + 1; j < a.size(); j++) {         tmp.clear();         for (int k = 0; k < a.size(); k++)           if (k != i && k != j) tmp.push_back(a[k]);         if (op[4 - a.size()] ==  + )           tmp.push_back(a[i] + a[j]);         else           tmp.push_back(a[i] * a[j]);         Gao(tmp);       }   }   int main() {     a.resize(4);     for (int i = 0; i < 4; i++) cin >> a[i];     for (int i = 0; i < 3; i++) scanf(  %c , &op[i]);     res = -1;     Gao(a);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], n, sum = 0, tp = 0, ans = -(1 << 30);   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) scanf( %d , &a[i]), sum += a[i];     for (register int i = 1; i <= n; ++i)       if (tp + a[i] < 0)         tp = 0;       else         ans = max(ans, tp + a[i]), tp += a[i];     ans = max(0, ans);     printf( %d n , max(ans * 2 - sum, sum));   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int MaxN = 100005, NA = -1, MaxC = 0x3F3F3F3F;   int a[MaxN];   int b[MaxN], c[MaxN];   bool f[MaxN];   int d, e, g, m, n;   int main(void) {     int i;     while (scanf(  %d %d , &n, &m) != EOF) {       memset(b, 0, sizeof(b));       memset(c, 0, sizeof(c));       d = e = 0;       for (i = 1; i <= n; i++) {         scanf(  %d , &a[i]);         if (a[i] > 0)           d++, b[abs(a[i])]++;         else           e++, c[abs(a[i])]++;       }       memset(f, 0, sizeof(f));       g = 0;       for (i = 1; i <= n; i++)         if (b[i] + e - c[i] == m) g++, f[i] = true;       assert(g > 0);       for (i = 1; i <= n; i++)         if (a[i] > 0) {           if (!f[abs(a[i])])             printf( Lie n );           else if (g > 1)             printf( Not defined n );           else             printf( Truth n );         } else {           if (!f[abs(a[i])])             printf( Truth n );           else if (g > 1)             printf( Not defined n );           else             printf( Lie n );         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double eps = 1e-10;   const long long M = 1e9 + 7;   const long long N = 1e5 + 5;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c, s[5];       cin >> a >> b >> c;       long long minx = INF;       for (long long i = 1; i <= 11000; i++) {         for (long long j = i; j <= 11000; j += i) {           for (long long k = j; k <= 11000; k += j) {             long long tmp = abs(a - i) + abs(b - j) + abs(c - k);             if (tmp < minx) {               minx = tmp;               s[1] = i;               s[2] = j;               s[3] = k;             }           }         }       }       cout << minx << endl;       cout << s[1] <<     << s[2] <<     << s[3] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int K = 12;   int n, k, q;   int arr[K][N];   int who[N][K];   int nrr[N * K][K];   int siz;   vector<int> lol[N];   int when[1 << K];   int parent[N * K];   bitset<1 << K> bit[N + K];   int idx[N * K];   int main() {     scanf( %d %d %d , &n, &k, &q);     for (int i = 0; i < k; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , &arr[i][j]);       }     }     for (int i = 0; i < n; ++i) {       vector<int> tmp;       for (int j = 0; j < k; ++j) {         tmp.emplace_back(arr[j][i]);       }       sort(tmp.begin(), tmp.end());       for (int j = 0; j < k; ++j) {         for (int x = 0; x < k; ++x) {           nrr[siz][x] = (arr[x][i] > tmp[j]);         }         who[i][j] = siz;         ++siz;       }       lol[i].swap(tmp);     }     memset(when, -1, sizeof(when));     for (int i = 0; i < siz; ++i) {       int mask = 0;       for (int j = 0; j < k; ++j) {         if (nrr[i][j]) {           mask |= 1 << j;         }       }       parent[i] = when[mask];       if (when[mask] == -1) {         when[mask] = i;       }     }     int cnt = 0;     for (int i = 0; i < siz; ++i) {       if (parent[i] == -1) {         idx[i] = cnt++;       }     }     for (int i = 0; i < siz; ++i) {       if (parent[i] != -1) {         continue;       }       parent[i] = i;       for (int j = 0; j < k; ++j) {         if (nrr[i][j]) {           bit[j].set(idx[i]);         }       }     }     int who = k;     while (q--) {       int type, x, y;       scanf( %d %d %d , &type, &x, &y);       if (type == 1) {         bit[who] = bit[x - 1] | bit[y - 1];         ++who;       } else if (type == 2) {         bit[who] = bit[x - 1] & bit[y - 1];         ++who;       } else {         int ans = lol[y - 1][k - 1];         ;         for (int j = 0; j < k; ++j) {           int idx = ::idx[parent[::who[y - 1][j]]];           if (!bit[x - 1].test(idx)) {             ans = min(ans, lol[y - 1][j]);           }         }         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int suma(long long int n) {     long long int temp = n;     long long int sum1 = 0;     while (temp != 0) {       sum1 += (temp % 10);       temp = temp / 10;     }     return sum1;   }   int main() {     fastio();     long long int q;     cin >> q;     while (q--) {       long long int n;       cin >> n;       unordered_map<long long int, long long int> mp, count;       std::vector<long long int> arr(n);       for (long long int i = 0; i < n; i++) {         cin >> arr[i];         mp[arr[i]]++;       }       priority_queue<long long int> pq;       for (auto it = mp.begin(); it != mp.end(); it++) pq.push(it->second);       long long int sum = 0;       while (!pq.empty()) {         if (count[pq.top()] == 0) {           count[pq.top()]++;           sum += pq.top();           pq.pop();         } else {           long long int temp = pq.top();           pq.pop();           if (temp > 1) pq.push(temp - 1);         }       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int m;     int sum = 0;     int a[100005];     int rec[100005] = {0};     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       int ss = a[i];       if (rec[ss] == 0) {         rec[ss]++;         sum++;         if (sum == n) {           cout << 1;           for (int j = 1; j <= n; j++) {             rec[j]--;             if (rec[j] == 0) {               sum--;             }           }         } else {           cout << 0;         }       } else {         rec[ss]++;         cout << 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pow(int a, int k) {     if (k == 0) return 1;     int r = pow(a, k / 2);     if (k % 2 == 0) return r * r;     return r * r * a;   }   int main() {     int n, ans = 1;     scanf( %d , &n);     for (int i = 1; (pow(2, i) - 1) * pow(2, i - 1) <= n; i++) {       int v = (pow(2, i) - 1) * pow(2, i - 1);       if (n % v == 0) ans = v;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int max_n = 1e5 + 5;   template <class Q>   void getint(Q &res, char ch = getchar()) {     while (!isdigit(ch) && ch !=  - ) ch = getchar();     bool flag = true;     if ( -  == ch) flag = false, ch = getchar();     for (res = 0; isdigit(ch); ch = getchar()) res = res * 10 + ch - 48;     if (!flag) res = -res;   }   void putint(int x) {     int i = 0, a[10];     bool flag = true;     if (x < 0) {       flag = false;       x = -x;     } else if (x == 0) {       a[i++] = 0;     }     while (x > 0) {       a[i++] = x % 10;       x /= 10;     }     if (flag == false) putchar( - );     for (int j = i - 1; j >= 0; --j) putchar(a[i] + 48);   }   int mmax(int a, int b) { return a > b ? a : b; }   int mmin(int a, int b) { return a < b ? a : b; }   int gcd(int a, int b) {     while (b) {       b ^= a ^= b ^= a %= b;     }     return a;   }   int n;   char s[1005], t[1005];   int a[10], b[10];   int main() {     std::cin >> n;     std::cin >> s >> t;     for (int i = 0; i < n; ++i) {       a[t[i] -  0 ]++;       b[t[i] -  0 ]++;     }     int ans1 = 0, ans2 = 0;     for (int i = 0; i < n; ++i) {       int f = 0;       for (int j = s[i] -  0 ; j <= 9; ++j) {         if (a[j] > 0) {           a[j]--;           f = 1;           break;         }       }       if (f == 0) ans1++;       for (int j = s[i] -  0  + 1; j <= 9; ++j) {         if (b[j] > 0) {           b[j]--;           ans2++;           break;         }       }     }     std::cout << ans1 << std::endl << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int sz, n;     cin >> sz >> n;     int sx, sy, tx, ty;     cin >> sx >> sy >> tx >> ty;     vector<vector<pair<int, int>>> g(n + 2);     g[n].emplace_back(n + 1, abs(tx - sx) + abs(ty - sy));     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       g[n].emplace_back(i, min(abs(x[i] - sx), abs(y[i] - sy)));       g[i].emplace_back(n + 1, abs(tx - x[i]) + abs(ty - y[i]));     }     vector<int> order(n);     iota(order.begin(), order.end(), 0);     for (int rot = 0; rot < 2; rot++) {       sort(order.begin(), order.end(), [&](int i, int j) { return x[i] < x[j]; });       for (int z = 0; z < n - 1; z++) {         int i = order[z];         int j = order[z + 1];         g[i].emplace_back(j, x[j] - x[i]);         g[j].emplace_back(i, x[j] - x[i]);       }       swap(x, y);     }     priority_queue<pair<int, int>> q;     vector<int> dist(n + 2, (int)2e9);     dist[n] = 0;     q.emplace(0, n);     while (!q.empty()) {       auto pr = q.top();       q.pop();       int expected = -pr.first;       int v = pr.second;       if (dist[v] != expected) {         continue;       }       for (const auto& pr : g[v]) {         int to = pr.first;         int cost = pr.second;         if (dist[v] + cost < dist[to]) {           dist[to] = dist[v] + cost;           q.emplace(-dist[to], to);         }       }     }     cout << dist[n + 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int DBG = 0, INF = int(1e9);   int main() {     ios_base::sync_with_stdio(0);     cout.setf(ios::fixed);     int n;     cin >> n;     vector<int> a(n);     for (auto& x : a) cin >> x;     int mx = *max_element(a.begin(), a.end());     for (int q = 0; q < mx; ++q) {       for (int i = 0; i < n; ++i) {         if (a[i] > 0) {           cout <<  P ;           --a[i];         }         if (i < n - 1) cout <<  R ;       }       for (int i = 0; i < n - 1; ++i) cout <<  L ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[8000];   char s[8000];   int main() {     scanf( %s , s);     int n = strlen(s), m = n;     if (s[0] ==  *  || s[0] ==  / ) {       puts( 0 );       return 0;     }     f[m] = 1;     for (int i = 0; i < n; i++)       if (!isdigit(s[i]))         if (s[i + 1] ==  *  || s[i + 1] ==  /  || i == n - 1) {           puts( 0 );           return 0;         } else           m--;       else if (!isdigit(s[i + 1]))         for (int j = m + n; j > m; j--) f[j - 1] = (f[j - 1] + f[j]) % 1000003;     printf( %d n , f[m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str1, str2, ans1, ans2;     cin >> str1 >> str2;     ans1 = str1;     ans2 = str2;     cout << ans1 <<     << ans2 << endl;     cin >> n;     while (n--) {       cin >> str1 >> str2;       if (str1 == ans1) {         ans1 = str2;       } else         ans2 = str2;       cout << ans1 <<     << ans2 << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     vector<long long> ans(n);     set<pair<long long, long long>> demid;     for (int i = 0; i < k; i++) {       long long s, m;       cin >> s >> m;       demid.insert({s + m, i});     }     for (int i = 0; i < n - k; i++) {       long long s, m;       pair<long long, long long> now;       cin >> s >> m;       now = *demid.begin();       demid.erase(demid.begin());       ans[now.second] = now.first;       demid.insert({max(s, now.first) + m, i + k});     }     while (demid.size()) {       pair<long long, long long> now;       now = *demid.begin();       demid.erase(demid.begin());       ans[now.second] = now.first;     }     for (int i = 0; i < n; i++) {       cout << ans[i] << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   long long a[N], f[N], g[N], r1, r2, r3, d;   int n;   long long nkb() { return min(r1, r2); }   long long cnkb(int i) { return min(r2, r1 * a[i] + nkb()); }   long long clear_go(int i) {     return min(r1 * a[i] + r3, cnkb(i) + d + d + nkb());   }   void Solve() {     cin >> n >> r1 >> r2 >> r3 >> d;     r1 = min(r1, r3);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) f[i] = 1e18;     f[0] = 0;     f[1] = clear_go(1);     for (int i = 2; i <= n; ++i) {       f[i] = f[i - 1] + clear_go(i) + d;       if (i > 1) {         f[i] = min(f[i], f[i - 2] + cnkb(i - 1) + d + cnkb(i) + d + nkb() + d +                              nkb() + d * (i != 2));       }     }     g[n + 1] = 0;     g[n] = clear_go(n);     for (int i = n - 1; i >= 1; --i) {       g[i] = g[i + 1] + 2ll * d + min(cnkb(i) + nkb(), clear_go(i));     }     long long ans = min(g[1], f[n]);     for (int i = 1; i < n; ++i) {       ans = min(ans, f[i] + d + g[i + 1]);     }     cout << ans <<   n ;   }   int main() {     int test = 1;     while (test--) Solve();   }


#include <bits/stdc++.h>   using namespace std;   int gcd(long long a, long long b) {     if (b == 0) {       return a;     } else {       return gcd(b, a % b);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long i, j, k, n, m, t = 1;     cin >> t;     while (t--) {       string s;       cin >> s;       n = s.size();       map<char, long long> make_pair;       long long mx = INT_MIN;       for (i = 0; i < n; i++) {         make_pair[s[i]]++;       }       for (char c =  0 ; c <=  9 ; c++) {         if (make_pair[c] > mx) {           mx = make_pair[c];         }       }       for (char c1 =  0 ; c1 <  9 ; c1++) {         for (char c2 = c1 + 1; c2 <=  9 ; c2++) {           k = 0;           char prev =  $ ;           for (i = 0; i < n; i++) {             if (s[i] == c1) {               if (prev == c2) {                 prev = c1;                 k++;               } else if (prev ==  $ ) {                 prev = c1;                 k++;               }             } else if (s[i] == c2) {               if (prev == c1) {                 prev = c2;                 k++;               } else if (prev ==  $ ) {                 prev = c2;                 k++;               }             }           }           if (k > mx && k % 2 == 0) {             mx = k;           } else if ((k - 1) > mx && (k - 1) % 2 == 0) {             mx = k - 1;           }         }       }       cout << s.size() - mx << endl;     }     return 0;   }


#include <bits/stdc++.h>   struct point {     int x, y;     inline point operator+(const point &a) const { return {x + a.x, y + a.y}; }     inline point operator-(const point &a) const { return {x - a.x, y - a.y}; }     inline int operator^(const point &a) const { return x * a.x + y * a.y; }     inline int operator*(const point &a) const { return x * a.y - y * a.x; }     inline bool operator<(const point &a) const {       return x == a.x ? y > a.y : x < a.x;     }   };   void input(point *arr, int n) {     for (int i = 0; i < n; i++) scanf( %d%d , &arr[i].x, &arr[i].y);   }   void convex_hull(point *vec, int n, point *res, int &tp) {     tp = 0;     std::sort(vec, vec + n);     for (int i = 0; i < n; i++) {       while (tp >= 2 && (res[tp - 1] - vec[i]) * (res[tp - 2] - vec[i]) >= 0)         tp--;       res[tp++] = vec[i];     }     int orig = tp--;     for (int i = n - 1; i >= 0; i--) {       while (tp > orig && (res[tp - 1] - vec[i]) * (res[tp - 2] - vec[i]) >= 0)         tp--;       res[tp++] = vec[i];     }     tp--;   }   point edge[40005];   int ecnt;   void get_edge(point *arr, int l, int r) {     edge[ecnt++] = {l, r};     if (r - l + 1 <= 2) return;     double mx = -1e18;     int pos = -1;     for (int i = l + 1; i < r; i++) {       double d = (double)((arr[i] - arr[l]) ^ (arr[i] - arr[r]));       d /= (arr[l] - arr[i]) * (arr[l] - arr[r]);       if (d > mx) {         mx = d;         pos = i;       }     }     get_edge(arr, l, pos);     get_edge(arr, pos, r);   }   bool solve(point *A, int n, point *b, int m) {     static point a[40005];     convex_hull(A, n, a, n);     ecnt = 0;     get_edge(a, 0, n - 1);     for (int j = 0; j < ecnt; j++) {       int l = edge[j].x, r = edge[j].y;       double lp = -1e18, rp = 1e18;       for (int i = 0; i < n && lp < rp; i++) {         if (i == l || i == r) continue;         int x = (a[i] - a[l]) ^ (a[i] - a[r]);         int y = (a[l] - a[i]) * (a[l] - a[r]);         if (!y) continue;         double t = (double)x / y;         if (y < 0)           rp = std::min(rp, t);         else           lp = std::max(lp, t);       }       for (int i = 0; i < m && lp < rp; i++) {         int x = (b[i] - a[l]) ^ (b[i] - a[r]);         int y = (a[l] - b[i]) * (a[l] - a[r]);         if (!y) {           if (x > 0) continue;           if (x <= 0) {             lp = 1e18;             break;           }         }         double t = (double)x / y;         if (y > 0)           rp = std::min(rp, t);         else           lp = std::max(lp, t);       }       if (lp < rp) return true;     }     return false;   }   point a[40005], b[40005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     input(a, n);     input(b, m);     if (n == 1 || m == 1) {       puts( YES );       return 0;     }     puts(solve(a, n, b, m) || solve(b, m, a, n) ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e6 + 10;   const int mod = 998244353;   long long a[maxn], b[maxn], n, m, sum1, sum2, res1, res2;   long long dp[3030][3030];   inline long long qm(long long a, long long b, long long res = 1) {     for (a %= mod; b; b >>= 1, a = a * a % mod)       if (b & 1) res = res * a % mod;     return res;   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %I64d , &b[i]);       if (a[i] == 1)         sum1 += b[i];       else         sum2 += b[i];     }     dp[1][1] = sum1 * qm(sum1 + sum2, mod - 2) % mod;     dp[1][0] = sum2 * qm(sum1 + sum2, mod - 2) % mod;     for (int i = 1; i < m; i++) {       for (int j = 0; j <= i; j++) {         int tmp = i - j;         dp[i + 1][j + 1] =             (dp[i + 1][j + 1] +              dp[i][j] * (sum1 + j) % mod * qm(sum1 + sum2 + j - tmp, mod - 2)) %             mod;         dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * max(0LL, sum2 - tmp) % mod *                                            qm(sum1 + sum2 + j - tmp, mod - 2)) %                        mod;       }     }     for (int i = 0; i <= m; i++) {       res1 = (res1 + dp[m][i] * (sum1 + i) % mod) % mod;       res2 = (res2 + dp[m][i] * max(0LL, sum2 - m + i) % mod) % mod;     }     for (int i = 1; i <= n; i++) {       if (a[i]) {         printf( %I64d n , res1 * b[i] % mod * qm(sum1, mod - 2) % mod);       } else {         printf( %I64d n , res2 * b[i] % mod * qm(sum2, mod - 2) % mod);       }     }   }


#include <bits/stdc++.h>   inline int mymin(int x, int y) { return x < y ? x : y; }   bool isprime[22000];   inline void init_prime() {     memset(isprime, true, sizeof(isprime));     for (int i = 2; i <= (int)sqrt(20000 * 1.0); ++i)       if (isprime[i])         for (int j = 2; i * j <= 20000; ++j) isprime[i * j] = false;   }   struct edge {     int to, c, next;   } e[22000];   int n, id[220], a[220], head[220], h[220], q[220], cnt, tot, num[55],       path[55][220];   bool f[220];   inline void print() { printf( Impossible n ); }   inline void ins(int u, int v, int c) {     e[++cnt].to = v;     e[cnt].c = c;     e[cnt].next = head[u];     head[u] = cnt;     e[++cnt].to = u;     e[cnt].c = 0;     e[cnt].next = head[v];     head[v] = cnt;   }   int dfs(int u, int in) {     if (u == n + 1 || !in) return in;     int out = 0;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to, c = e[i].c;       if (h[v] == h[u] + 1 && c) {         int flow = dfs(v, mymin(in - out, c));         if (!flow)           h[v] = 0;         else           out += flow;         e[i].c -= flow;         e[i ^ 1].c += flow;         if (in == out) return out;       }     }     return out;   }   inline bool bfs() {     int op = 0, cl = 0;     memset(h, 0, sizeof(h));     h[q[++cl] = 0] = 1;     while (op < cl) {       int u = q[++op];       if (u == n + 1) break;       for (int i = head[u]; i; i = e[i].next) {         int v = e[i].to, c = e[i].c;         if (!h[v] && c) h[q[++cl] = v] = h[u] + 1;       }     }     return h[n + 1];   }   inline int Dinic() {     int rec = 0;     while (bfs()) rec += dfs(0, n);     return rec;   }   int dfs_path(int x) {     path[tot][++num[tot]] = x;     int y;     for (int i = head[x]; i; i = e[i].next) {       if (e[i].c) continue;       y = e[i].to;       if (f[y]) continue;       f[y] = true;       path[tot][++num[tot]] = y;       break;     }     for (int i = head[y]; i; i = e[i].next) {       if (e[i ^ 1].c) continue;       x = e[i].to;       if (f[x]) continue;       f[x] = true;       dfs_path(x);     }   }   int main() {     scanf( %d , &n);     if (n & 1) {       print();       return 0;     }     int cnt1 = 0, cnt2 = n >> 1;     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       if (x & 1) {         a[++cnt1] = x;         id[cnt1] = i;       } else {         a[++cnt2] = x;         id[cnt2] = i;       }       if (cnt1 > n >> 1 || cnt2 > n) {         print();         return 0;       }     }     init_prime();     memset(head, 0, sizeof(head));     cnt = 1;     for (int i = 1; i <= (n >> 1); ++i) {       ins(0, id[i], 2);       for (int j = (n >> 1) + 1; j <= n; ++j)         if (isprime[a[i] + a[j]]) ins(id[i], id[j], 1);     }     for (int i = (n >> 1) + 1; i <= n; ++i) ins(id[i], n + 1, 2);     int maxflow = Dinic();     if (maxflow != n) {       print();       return 0;     }     memset(f, false, sizeof(f));     f[0] = f[n + 1] = true;     tot = 0;     for (int i = 1; i <= (n >> 1); ++i)       if (!f[id[i]]) {         f[id[i]] = true;         ++tot;         num[tot] = 0;         dfs_path(id[i]);       }     printf( %d n , tot);     for (int i = 1; i <= tot; ++i) {       printf( %d , num[i]);       for (int j = 1; j <= num[i]; ++j) printf(  %d , path[i][j]);       if (i != tot) printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   const T& max(const T& a, const T& b, const T& c) {     return max(a, max(b, c));   }   template <class T>   const T& min(const T& a, const T& b, const T& c) {     return min(a, min(b, c));   }   struct sp {     bool operator()(const pair<string, int>& a, const pair<string, int>& b) {       if (a.second != b.second) {         return (a.second > b.second);       }       return (a.first < b.first);     }   };   long long stoi(string& str) {     istringstream second(str);     long long i;     second >> i;     return i;   }   string itos(long long i) {     stringstream second;     second << i;     return second.str();   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long poww(long long a, long long b) {     long long res = 1;     for (int i = 1; i <= b; i++) res *= a;     return res;   }   long long sumOfDigs(string s) {     long long sum = 0;     for (int i = 0; i < s.length(); i++) sum += s[i] -  0 ;     return sum;   }   long long mod = 1000000007;   using namespace std;   long long a[100001];   int fn(int x) {     if (x == 0)       return 0;     else if (x & 1) {       return (fn(x >> 1) + 1);     } else       return fn(x >> 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     int x;     for (int i = 1; i <= n; i++) {       cin >> x;       a[fn(x)]++;     }     long long s = 0;     for (int i = 0; i < 100001; i++) {       if (a[i] > 1) {         s += (a[i] * (a[i] - 1)) / 2;       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ms = 1001000;   bool hole[ms];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     long long n, m, k;     cin >> n;     if (n == 1 || n == 2) {       cout << 0;       return 0;     }     cout << (n + 1) / 2 - 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, x, ans, num, n, fa[2001];     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %d , &fa[i]);       }       ans = 1;       for (i = 1; i <= n; i++) {         num = 1;         x = i;         while (fa[x] != -1) {           num++;           x = fa[x];         }         if (num > ans) ans = num;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const double eps = 1e-12;   int n, k, h;   struct lemming {     int w, v, id;     bool operator<(const lemming &rhs) const {       if (w != rhs.w) return w < rhs.w;       return v < rhs.v;     }   } a[maxn];   vector<int> ans;   int dcmp(double x) {     if (fabs(x) < eps) return x;     return x > 0 ? 1 : -1;   }   bool ok(double t) {     vector<int> v;     for (int i = 1, j = 1; i <= n; i++) {       if (dcmp(t - (double)h * j / a[i].v) < 0) continue;       v.emplace_back(a[i].id);       j++;       if (j > k) break;     }     if (v.size() < k) return 0;     ans = v;     return 1;   }   int main() {     scanf( %d %d %d , &n, &k, &h);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].w), a[i].id = i;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v);     sort(a + 1, a + 1 + n);     double l = 0, r = 1e9;     for (int i = 0; i < 150; i++) {       double mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid;     }     for (auto i : ans) printf( %d  , i);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   char a[N];   int chk[N];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     cin >> a;     if (n == 1) {       cout <<  Yes  << endl;       return 0;     }     for (int i = 0; i < n; i++) chk[a[i]]++;     bool flg = 1;     for (int i = 0; i < 256; i++) {       if (chk[i] != 1 && chk[i] != 0) flg = 0;     }     if (flg)       cout <<  No  << endl;     else       cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   const double eps = 1e-8;   void read(int &k) {     k = 0;     char x = getchar();     while (x <  0  || x >  9 ) x = getchar();     while (x >=  0  && x <=  9 ) {       k = k * 10 - 48 + x;       x = getchar();     }   }   long long mul[40][40], tmp[40][40], now[40], nxt[40];   int L, R, no[10][10];   long long powe(long long a, long long b) {     long long ret = 1;     for (; b; b >>= 1, a = a * a % MOD)       if (b & 1) ret = ret * a % MOD;     return ret;   }   long long solve1(int x) {     if (x == 0) return 0;     memset(mul, 0, sizeof mul);     for (int i = 0; i < 5; i++)       for (int j = 0; j < 5; j++)         if (!no[i][j])           for (int k = 1; k < 5; k++)             if (!no[j][k])               if ((i != 4 || j != 1 || k != 3) && (i != 3 || j != 1 || k != 4))                 mul[i * 6 + j][j * 6 + k] = 1;     for (int i = 0; i < 5; i++)       for (int j = 0; j < 5; j++) mul[i * 6 + j][35] = 1;     mul[35][35] = 1;     memset(now, 0, sizeof now);     now[0] = 1;     for (; x; x >>= 1) {       if (x & 1) {         memset(nxt, 0, sizeof nxt);         for (int k = 0; k < 36; k++)           if (now[k])             for (int j = 0; j < 36; j++)               nxt[j] = (nxt[j] + now[k] * mul[k][j]) % MOD;         memcpy(now, nxt, sizeof now);       }       memset(tmp, 0, sizeof tmp);       for (int i = 0; i < 36; i++)         for (int k = 0; k < 36; k++)           if (mul[i][k])             for (int j = 0; j < 36; j++)               tmp[i][j] = (tmp[i][j] + mul[i][k] * mul[k][j]) % MOD;       memcpy(mul, tmp, sizeof mul);     }     long long ret = 0;     for (int i = 0; i < 36; i++) ret = (ret + now[i]) % MOD;     return (ret + MOD - 1) % MOD;   }   long long solve2(int x) {     long long ret = 0;     x--;     int y = x;     for (int T = 1; T <= 4; T++) {       x = y;       memset(mul, 0, sizeof mul);       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++)           if (!no[i][j])             for (int k = 1; k < 5; k++)               if (!no[j][k])                 if ((i != 4 || j != 1 || k != 3) && (i != 3 || j != 1 || k != 4))                   mul[i * 6 + j][j * 6 + k] = 1;       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++) mul[i * 6 + j][35] = 1;       mul[35][35] = 1;       memset(now, 0, sizeof now);       now[T] = 1;       for (; x; x >>= 1) {         if (x & 1) {           memset(nxt, 0, sizeof nxt);           for (int k = 0; k < 36; k++)             if (now[k])               for (int j = 0; j < 36; j++)                 nxt[j] = (nxt[j] + now[k] * mul[k][j]) % MOD;           memcpy(now, nxt, sizeof now);         }         memset(tmp, 0, sizeof tmp);         for (int i = 0; i < 36; i++)           for (int k = 0; k < 36; k++)             if (mul[i][k])               for (int j = 0; j < 36; j++)                 tmp[i][j] = (tmp[i][j] + mul[i][k] * mul[k][j]) % MOD;         memcpy(mul, tmp, sizeof mul);       }       for (int i = 0; i < 36; i++) ret = (ret + now[i]) % MOD;     }     return (ret + MOD) % MOD;   }   long long calc(int x) {     if (x == 0) return 0;     return (solve1(x) + solve2((x + 1) / 2)) % MOD * powe(2, MOD - 2) % MOD;   }   int main() {     cin >> L >> R;     no[1][1] = no[2][2] = no[3][3] = no[4][4] = no[1][2] = no[3][4] = no[2][1] =         no[4][3] = 1;     cout << (calc(R) - calc(L - 1) + MOD) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   int n, v[MAX];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0, x; i < n; i++) cin >> x, v[x % n] = i;     for (int i = 0, x; i < n; i++) cin >> x, cout << v[x % n] + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000000 + 7;   const int N = 200000 + 10;   const int NUMHASH = 3;   const long long hashNum[3] = {M, M + 2, M + 14};   struct re {     int x, y;   };   int n, q;   string s;   int cnt[26][N], f[26][N], g[26][N];   long long h[NUMHASH][26][N], p[NUMHASH][N];   int countLetter(int x, int y, int c) { return cnt[c][x] - cnt[c][y + 1]; }   int getHash(int x, int l, int c, int k) {     return (h[k][c][x + l - 1] - (h[k][c][x - 1] * p[k][l] % hashNum[k]) +             hashNum[k]) %            hashNum[k];   }   bool equalHash(int x, int i, int y, int j, int l) {     for (int k = (0); (k <= (NUMHASH - 1)); ++k) {       if (getHash(x, l, i, k) != getHash(y, l, j, k)) return false;     }     return true;   }   bool iso(int x, int y, int l) {     for (int i = (0); (i <= (25)); ++i) {       int pos = f[i][x];       if (pos < l) {         int j = s[y - 1 + pos] -  a ;         if (f[j][y] != pos) return false;         if (countLetter(x, x + l - 1, i) != countLetter(y, y + l - 1, j))           return false;         if (!equalHash(x, i, y, j, l)) return false;       }     }     return true;   }   int main() {     cin >> n >> q;     cin >> s;     for (int i = (n); (i >= (1)); --i) {       for (int j = (0); (j <= (25)); ++j)         cnt[j][i] = cnt[j][i + 1], f[j][i] = f[j][i + 1] + 1;       int j = s[i - 1] -  a ;       cnt[j][i] = cnt[j][i + 1] + 1;       f[j][i] = 0;       g[j][i] = 1;     }     for (int k = (0); (k <= (NUMHASH - 1)); ++k) {       p[k][0] = 1;       for (int i = (1); (i <= (n)); ++i) p[k][i] = (p[k][i - 1] * 2) % hashNum[k];       for (int j = (0); (j <= (25)); ++j) {         for (int i = (1); (i <= (n)); ++i)           h[k][j][i] = (h[k][j][i - 1] * 2 + g[j][i]) % hashNum[k];       }     }     while (q--) {       int x, y, len;       cin >> x >> y >> len;       if (iso(x, y, len))         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, ans = -1;     cin >> n;     pair<int, int> g[n];     for (i = 0; i < n; i++) {       cin >> g[i].first >> g[i].second;     }     sort(g, g + n);     for (i = 0; i < n; i++) {       if (ans <= g[i].second)         ans = g[i].second;       else         ans = g[i].first;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> p[300100];   int per[300300];   long long sz[300300];   long long mx[300300];   int res[300300];   long long dfs(int x) {     sz[x]++;     for (int i = 0; i < p[x].size(); i++) {       long long t = dfs(p[x][i]);       sz[x] += t;       mx[x] = max(mx[x], t);     }     return sz[x];   }   bool ch(int x, int y) {     if (mx[y] * 2 > sz[x]) return 0;     if ((sz[x] - sz[y]) * 2 > sz[x]) return 0;     return 1;   }   void f(int x) {     int st = x, maxx = 0;     if (ch(x, x)) res[x] = x;     for (int i = 0; i < p[x].size(); i++) {       f(p[x][i]);       if (maxx < sz[p[x][i]]) {         maxx = sz[p[x][i]];         st = res[p[x][i]];       }     }     while (1) {       if (ch(x, st)) {         res[x] = st;         break;       }       st = per[st];     }   }   int main() {     int n, q, z;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       scanf( %d , &z);       per[i] = z;       p[z].push_back(i);     }     dfs(1);     f(1);     for (int i = 0; i < q; i++) {       scanf( %d , &z);       printf( %d n , res[z]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int a[N], gcd[N], is_max[N], cnt[N];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i + n] = a[i];     }     for (int i = 1; i <= n; ++i) {       if (n % i == 0) {         for (int j = i; j <= n; j += i) {           gcd[j] = i;         }       }     }     long long ans = 0ll;     for (int i = 1; i <= n; ++i) {       if (n % i == 0) {         for (int j = 0; j < i; ++j) {           int m = 0;           for (int q = j; q < n; q += i) {             m = max(m, a[q]);           }           for (int q = j; q < n * 2; q += i) {             is_max[q] = a[q] == m;           }         }         for (int j = 1; j < n * 2; ++j) {           if (is_max[j]) {             is_max[j] += is_max[j - 1];           }         }         cnt[0] = 0;         for (int j = 1; j < n; ++j) {           cnt[j] = cnt[j - 1] + (gcd[j] == i);         }         for (int j = n; j < n * 2; ++j) {           ans += cnt[min(is_max[j], n - 1)];         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, ans = 0, f[30][30], h, t, l;   char st[20];   int main() {     scanf( %d n , &n);     memset(f, 0, sizeof(f));     while (n--) {       gets(st);       l = strlen(st);       h = (int)st[0] - 97;       t = (int)st[l - 1] - 97;       for (i = 0; i < 26; i++)         if (f[i][h] && (f[i][t] < f[i][h] + l)) {           f[i][t] = f[i][h] + l;           if (t == i && ans < f[i][t]) ans = f[i][t];         }       if (f[h][t] < l) {         f[h][t] = l;         if (t == h) ans = max(ans, l);       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   long long fpow(long long a, int b, int mod) {     long long res = 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long d[N];   long long cnt[26];   long long fac[N];   char s[N];   int len;   long long num[N];   long long calc(int x) {     long long tot = 0;     for (int i = 0; i < x; i++) tot += cnt[i];     return tot;   }   long long dfs(int d) {     if (d == len + 1) return 0;     long long tot = calc(s[d] -  a ) * fac[len - d] % mod;     if (cnt[s[d] -  a ]) {       cnt[s[d] -  a ]--;       long long u = dfs(d + 1);       cnt[s[d] -  a ]++;       tot = (tot + cnt[s[d] -  a ] * u % mod) % mod;     }     return tot;   }   int main() {     fac[0] = 1;     for (long long i = 1; i < N; i++) {       fac[i] = (fac[i - 1] * i) % mod;     }     scanf( %s , s + 1);     len = strlen(s + 1);     for (int i = 1; i <= len; i++) cnt[s[i] -  a ]++;     long long ans = dfs(1);     scanf( %s , s + 1);     ans = (dfs(1) - ans + mod) % mod;     for (int i = 0; i < 26; i++) {       if (cnt[i] >= 1) ans = ans * fpow(fac[cnt[i]], mod - 2, mod) % mod;     }     cout << ans - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int p = 0;     int aa = a;     while (aa > 0) {       p = max(p, aa % 10);       aa = aa / 10;     }     int bb = b;     while (bb > 0) {       p = max(p, bb % 10);       bb = bb / 10;     }     p++;     int carry = 0;     int num = 0;     while (a > 0 or b > 0 or carry > 0) {       carry = ((a % 10) + (b % 10) + carry) / p;       a = a / 10;       b = b / 10;       num++;     }     cout << num << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long k, d, t, cnt = 0;   bool f(double T) {     long long interval = ((long long)ceil(k / (d * 1.0))) * d;     long long no_of_interval = T / interval;     double t_on = no_of_interval * k, t_off = (interval - k) * no_of_interval;     double rem = T - no_of_interval * interval;     if (rem <= (double)k)       t_on += rem;     else {       t_on += k;       t_off += rem - k;     }     return t_on + t_off / 2 >= t;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k >> d >> t;     double s = t, e = 2 * t, mid;     while (cnt++ <= 10000) {       mid = (s + e) / 2;       if (f(mid))         e = mid;       else         s = mid;     }     cout << setprecision(20) << mid;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, rock = 0, peper = 0, sec = 0, de = 0;       cin >> n;       cin >> rock >> peper >> sec;       string s, ans;       cin >> s;       for (long long int i = 0; i < n; i++) {         if (s[i] ==  R  && peper > 0) {           ans = ans +  P ;           peper--;           de++;           continue;         } else if (s[i] ==  P  && sec > 0) {           sec--;           ans = ans +  S ;           de++;           continue;         } else if (s[i] ==  S  && rock > 0) {           rock--;           ans = ans +  R ;           de++;           continue;         } else {           ans = ans +  1 ;         }       }       for (long long int i = 0; i < n; i++) {         if (ans[i] ==  1 ) {           if (rock > 0) {             ans[i] =  R ;             rock--;           } else if (peper > 0) {             ans[i] =  P ;             peper--;           } else if (sec > 0) {             sec--;             ans[i] =  S ;           }         }       }       if (n % 2 == 0)         n = n / 2;       else         n = (n + 1) / 2;       if (de >= n) {         cout <<  YES               <<   n ;         cout << ans <<   n ;       } else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {     return a.second < b.second;   }   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {     a.first += b.first;     a.second += b.second;     return a;   }   pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }   const double pi = acos(-1.0);   int main(void) {     double w, h, a;     scanf( %lf %lf %lf , &w, &h, &a);     if (a > 90.0) a = 180.0 - a;     a = a / 180.0 * pi;     double d = sqrt(w * w + h * h) * 0.5;     double sol;     if ((d * d + d * d - min(w, h) * min(w, h)) / (2 * d * d) <= cos(a)) {       double A = 1 + cos(a);       double B = sin(a);       double x = (A * w - B * h) / (A * A - B * B);       double y = (A * h - B * w) / (A * A - B * B);       sol = w * h - (x * x + y * y) * sin(a) * cos(a);     } else {       double s = min(w, h);       double z = s / sin(a);       sol = z * z * sin(a);     }     printf( %.12lf n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 250000;   int n, k, C[30], c[30];   vector<string> S;   bool anda, Z, term;   bool trythis(string X) {     bool ans = true;     for (int i = (0); i < (int)(k); i++) {       int cnt = 0;       for (int j = (0); j < (int)(n); j++)         if (S[i][j] != X[j]) cnt++;       if (!(cnt == 2 || (!cnt && Z))) ans = false;     }     return ans;   }   void proba(string X, int a, int b) {     swap(X[a], X[b]);     if (trythis(X)) {       cout << X << endl;       term = true;     }     swap(X[a], X[b]);   }   int main() {     while (cin >> k >> n) {       for (int i = (0); i < (int)(30); i++) C[i] = 0;       anda = true;       term = false;       S.resize(k);       for (int i = (0); i < (int)(k); i++) cin >> S[i];       for (int j = (0); j < (int)(n); j++) C[S[0][j] -  a ]++;       for (int i = (0); i < (int)(k); i++) {         for (int j = (0); j < (int)(30); j++) c[j] = 0;         for (int j = (0); j < (int)(n); j++) c[S[i][j] -  a ]++;         for (int j = (0); j < (int)(30); j++)           if (C[j] != c[j]) anda = false;       }       if (!anda) {         cout << -1 << endl;         continue;       }       for (int i = (0); i < (int)(30); i++)         if (C[i] > 1) Z = true;       for (int i = (0); i < (int)(k); i++)         for (int ii = (i + 1); ii < (int)(k); ii++) {           int cnt = 0;           for (int j = (0); j < (int)(n); j++)             if (S[i][j] != S[ii][j]) cnt++;           switch (cnt) {             case 0:               break;             case 2: {               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               int t1 = P[0], t2 = P[1];               for (int c = (0); c < (int)(n); c++) {                 if (S[i][c] == S[i][t1]) {                   proba(S[i], c, t2);                   if (term) return 0;                 }                 if (S[i][c] == S[i][t2]) {                   proba(S[i], c, t1);                   if (term) return 0;                 }               }               proba(S[i], t1, t2);               if (term) return 0;               proba(S[ii], t1, t2);               if (term) return 0;               cout << -1 << endl;               return 0;             }             case 3: {               string X = S[i];               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               for (int a = (0); a < (int)(3); a++)                 for (int b = (a + 1); b < (int)(3); b++) {                   proba(X, P[a], P[b]);                   if (term) return 0;                 }               cout << -1 << endl;               term = true;               return 0;             }             case 4: {               string X = S[i];               vector<int> P;               for (int j = (0); j < (int)(n); j++)                 if (S[i][j] != S[ii][j]) P.push_back(j);               for (int a = (0); a < (int)(4); a++)                 for (int b = (a + 1); b < (int)(4); b++) {                   proba(X, P[a], P[b]);                   if (term) return 0;                 }               cout << -1 << endl;               term = true;               return 0;             }             default: {               cout << -1 << endl;               term = true;               return 0;             }           }         }       if (!term) proba(S[0], 0, 1);     }     return 0;   }


#include <bits/stdc++.h>   int fac[100100];   int n, m, i, x, j, l, r, p, ans, st, dr, mn, mx, M;   void init() {     int i, j;     for (i = 2; i <= 100000; i++)       if (!fac[i]) {         fac[i] = i;         if (i > 316) continue;         for (j = i * i; j <= 100000; j += i)           if (!fac[j]) fac[j] = i;       }   }   int solve(int x, int y) {     int v[20];     int N;     int i, j, lim, ind, nr, rez = 0;     if (y == 0) return 0;     v[0] = 0;     N = 0;     for (i = x; i > 1; i /= fac[i])       if (N == 0 || v[N - 1] != fac[i]) v[N++] = fac[i];     lim = 1 << N;     for (i = 0; i < lim; i++) {       ind = 0;       nr = 1;       for (j = 0; j < N; j++)         if (i & (1 << j)) {           ind++;           nr = nr * v[j];         }       int ax = y / nr;       if (ind % 2 == 1)         rez = (long long)((long long)((long long)rez - (long long)(M + 1) * ax +                                       (long long)nr * ax * ((long long)ax + 1) /                                           2) %                               p +                           (long long)p) %               p;       else         rez = (long long)((long long)((long long)rez + (long long)(M + 1) * ax -                                       (long long)nr * ax * ((long long)ax + 1) /                                           2) %                               p +                           (long long)p) %               p;     }     rez = (long long)((long long)rez * ((long long)n - x + 1)) % p;     return ((int)rez);   }   int main() {     scanf( %d%d%d%d%d , &n, &M, &l, &r, &p);     init();     for (x = 1; x <= n; x++) {       for (st = 0, dr = 100001; st < dr;) {         m = (st + dr) / 2;         if ((long long)x * x + (long long)m * m >= (long long)l * l)           dr = m;         else           st = m + 1;       }       mn = st;       for (st = 0, dr = 100001; st < dr;) {         m = (st + dr) / 2 + 1;         if ((long long)x * x + (long long)m * m <= (long long)r * r)           st = m;         else           dr = m - 1;       }       if (mn < 1) mn = 1;       mx = st;       if (mx > M) mx = M;       if (mn > mx) continue;       ans = (long long)((long long)((long long)ans + solve(x, mx) -                                     solve(x, mn - 1)) %                             p +                         p) %             p;     }     ans = (long long)ans * 2 % p;     if (l <= 1)       ans = (long long)((long long)ans + n * ((long long)M + 1) +                         ((long long)n + 1) * M) %             p;     printf( %d , ans);     return 0;   }


#include  bits/stdc++.h       using namespace std;   using ll = long long;   using pii = pair<int,int>;      vector<tuple<int,int,int>> edges;      void add(int x, int y, int z) {     edges.push_back({x,y,z});   }      int solve(int l, int r) {     if (l > 1) {       int k = solve(1,r-l+1);       add(k,k+1,l-1);       return k+1;     }     if ((r&(-r)) == r) // r is a power of 2      {       int k = __builtin_ctz(r); // Count Trailing Zeros       add(1,2,1);       for (int i = 3; i <= k+2; i++) {         add(1,i,1);         for (int j = 2; j < i; j++)           add(j,i,1<<(j-2));       }       return k+2;     }     int k =0;     while(1<<(k+1) <= r-1) k++;     solve(1,1<<k);     add(1,k+3,1);     for (int i = 0; i <= k; i++){       if ((r-1)>>i&1)         add(i+2,k+3,1+((r-1)>>(i+1)<<(i+1)));     }     return k+3;   }      int main()   {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int l,r;     cin >> l >> r;     cout <<  YES n ;     int n = solve(l,r);     cout << n <<     << edges.size() <<   n ;     for (auto [x,y,z] : edges) cout << x <<     << y <<     << z <<   n ;   }      // DAG   // Good if all paths from 1 to n are between L and R   // All possible distances should be represented, once each   //   // How many different distances can I have? n nodes an give 2^n-1 paths. Always   // possible?   //   // Seems like we can do binary magic to solve   //


#include <bits/stdc++.h>   using namespace std;   bitset<501> bt[1010];   int c[505];   int ans[250001], tot;   int main() {     tot = 0;     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     bt[0].set(0);     int maxn = 0;     for (int i = 1; i <= n; i++) {       int lim = maxn;       for (int j = lim; j >= 0; j--) {         if (j + c[i] > k) continue;         bt[j + c[i]] |= bt[j];         bt[j + c[i]] |= bt[j] << c[i];       }       maxn = maxn + c[i];     }     for (int i = 0; i <= 500; i++) {       if (bt[k].test(i)) {         ans[tot++] = i;       }     }     printf( %d n , tot);     for (int i = 0; i < tot; i++) {       printf( %d , ans[i]);       if (i == tot - 1)         printf(  n );       else         printf(   );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout << (n / 2) - 1 << endl;     } else {       cout << n / 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long a[200011];   string s;   int main() {     long long n, k, i, x, res = 0, j;     cin >> n >> k;     for (i = 0; i < n; i++) cin >> a[i];     cin >> s;     char C =  A ;     for (i = 0; i < n; i++) {       x = k;       if (s[i] == C) v.push_back(a[i]);       if (s[i] != C || i == n - 1) {         if (i == n - 1 && s[i] != C) res += a[i];         C = s[i];         sort(v.begin(), v.end());         if (v.size()) {           for (j = v.size() - 1; j >= 0; j--) {             if (x > 0) {               res += v[j];               x--;             }           }           v.erase(v.begin(), v.end());         }         v.push_back(a[i]);       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 13;   int n, m;   int a[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       long long n;       long long x, y;       scanf( %lld , &n);       if (n == 1) {         printf( 1 1 n );         continue;       }       long long p = sqrt(n);       if (p * p != n) p++;       if (p * p - n < p) {         x = p;         y = p * p - n + 1;       } else {         y = p;         x = n - (p - 1) * (p - 1);       }       printf( %lld %lld n , x, y);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = ((int)2e6) + 5;   int energy[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, u;     cin >> n >> u;     for (int i = 0; i < n; i++) cin >> energy[i];     int curr = 2;     double eff = -1;     for (int i = 1; i < n - 1; i++) {       int ei = energy[i - 1];       int ej = energy[i];       while (energy[curr] - ei > u) {         curr--;       }       while (curr < n && energy[curr] - ei <= u) {         eff = max(eff, (energy[curr] - ej) / (energy[curr] - ei + 0.0));         curr++;       }       if (curr == n) curr--;     }     if (eff < 1e-7) {       cout << -1;     } else {       cout << fixed << setprecision(9) << eff;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() { return getchar(); }   template <class T>   int read(T &ans) {     ans = 0;     char ch = gc();     T f = 1;     while (!isdigit(ch)) {       if (ch == EOF) return -1;       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) ans = ans * 10 + ch -  0 , ch = gc();     ans *= f;     return 1;   }   template <class T1, class T2>   int read(T1 &a, T2 &b) {     return read(a) != EOF && read(b) != EOF ? 2 : EOF;   }   template <class T1, class T2, class T3>   int read(T1 &a, T2 &b, T3 &c) {     return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;   }   const int Maxn = 1100;   const int inf = 0x3f3f3f3f;   int a[Maxn], b[Maxn], c[Maxn], tims;   long long n, L, v;   pair<long long, long long> ans[Maxn];   long long query(long long a, long long b) {     printf( ? %I64d %I64d n , a, b);     fflush(stdout);     long long ans;     read(ans);     return ans;   }   long long find(int x, long long k, long long l, long long r) {     long long mid = l + r >> 1;     while (1) {       long long y = query(x, mid);       if (y == k) return mid;       if (y < k)         l = mid + 1;       else         r = mid - 1;       mid = l + r >> 1;     }   }   void kth(int l, int r, int k, long long ql, long long qr) {     if (l == r) return;     int x = rand() % (r - l + 1) + l;     long long y = find(a[x], (L / n) * k, ql, qr);     int mid = k - l + 1;     int l1 = l - 1, l2 = r + 1, l3 = 0;     c[++l3] = a[x];     for (int i = l; i <= r; i++) {       if (i == x) continue;       long long sxz = query(a[i], y);       if (sxz < (L / n) * k) b[--l2] = a[i];       if (sxz == (L / n) * k) c[++l3] = a[i];       if (sxz > (L / n) * k) b[++l1] = a[i];     }     while (l1 < k && l3) b[++l1] = c[l3--];     if (l1 == k) {       v = y;       while (l3) b[--l2] = c[l3--];       for (int i = l; i <= r; i++) a[i] = b[i];       return;     }     if (l1 < k) {       for (int i = l; i <= r; i++) a[i] = b[i];       kth(l1 + 1, r, k, ql, qr);       return;     }     while (l3) b[--l2] = c[l3--];     for (int i = l; i <= r; i++) a[i] = b[i];     kth(l, l1, k, ql, qr);   }   void solve(int l, int r, long long ql, long long qr) {     if (l == r) {       ans[a[l]] = make_pair(ql, qr);       return;     }     int mid = l + r >> 1;     kth(l, r, mid, ql, qr);     long long x = v;     solve(l, mid, ql, x);     solve(mid + 1, r, x, qr);   }   signed main() {     read(n, L);     for (int i = 1; i <= n; i++) a[i] = i;     solve(1, n, 0, 1000000000000000000ll);     puts( ! );     for (int i = 1; i <= n; i++)       printf( %I64d %I64d n , ans[i].first, ans[i].second);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   int t;   int main() {     t = read();     while (t--) {       int n = read(), d = read();       int ans = d;       d--;       int x = sqrt(d);       if (x + d / (x + 1) + 1 < ans) ans = x + d / (x + 1) + 1;       if (x + 1 + d / (x + 2) + 1 < ans) ans = x + 1 + d / (x + 2) + 1;       if (ans <= n)         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 100;   long long x[maxn];   char type[maxn], t;   vector<long long> B, R, G;   long long szR, szB, n, pos;   void Put(long long st, long long en) {     R.clear();     B.clear();     for (int i = st; i <= en; ++i) {       if (type[i] == 1)         R.push_back(i);       else if (type[i] == 2)         B.push_back(i);     }     szR = R.size();     szB = B.size();   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pos >> t;       x[i] = pos;       if (t ==  P )         type[i] = 0, G.push_back(i);       else if (t ==  R )         type[i] = 1;       else         type[i] = 2;     }     long long ans = 0;     int sz = G.size();     if (sz == 0) {       Put(1, n);       if (szR > 0) ans += x[R[szR - 1]] - x[R[0]];       if (szB > 0) ans += x[B[szB - 1]] - x[B[0]];     } else {       Put(1, G[0] - 1);       if (szR > 0) ans += x[G[0]] - x[R[0]];       if (szB > 0) ans += x[G[0]] - x[B[0]];       Put(G[sz - 1] + 1, n);       if (szR > 0) ans += x[R[szR - 1]] - x[G[sz - 1]];       if (szB > 0) ans += x[B[szB - 1]] - x[G[sz - 1]];       for (int i = 0; i < sz - 1; ++i) {         long long x1 = G[i], x2 = G[i + 1];         long long tmp1 = 0, tmp2 = 0;         Put(x1 + 1, x2 - 1);         if (szR > 0) {           tmp1 = x[R[0]] - x[x1];           for (int p = 1; p < szR; ++p) tmp1 = max(tmp1, x[R[p]] - x[R[p - 1]]);           tmp1 = max(tmp1, x[x2] - x[R[szR - 1]]);         } else           tmp1 = x[x2] - x[x1];         if (szB > 0) {           tmp2 = x[B[0]] - x[x1];           for (int p = 1; p < szB; ++p) tmp2 = max(tmp2, x[B[p]] - x[B[p - 1]]);           tmp2 = max(tmp2, x[x2] - x[B[szB - 1]]);         } else           tmp2 = x[x2] - x[x1];         ans += min((x[x2] - x[x1]) * 2, (x[x2] - x[x1]) * 3 - tmp1 - tmp2);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int cys = 998244353, g = 3, invg = (cys + 1) / 3;   int n;   long long ni[200015], fac[200015], inv[200015], tw[200005];   int mod(int x) { return x >= cys ? x - cys : x; }   long long qpow(long long x, long long p) {     long long ret = 1;     for (; p; p >>= 1, x = x * x % cys)       if (p & 1) ret = ret * x % cys;     return ret;   }   vector<long long> operator+(vector<long long> a, vector<long long> b) {     vector<long long> ret(max(a.size(), b.size()));     for (int i = 0; i < ret.size(); i++)       ret[i] = mod((i < a.size() ? a[i] : 0) + (i < b.size() ? b[i] : 0));     return ret;   }   vector<long long> operator-(vector<long long> a, vector<long long> b) {     vector<long long> ret(max(a.size(), b.size()));     for (int i = 0; i < ret.size(); i++)       ret[i] = mod((i < a.size() ? a[i] : 0) + cys - (i < b.size() ? b[i] : 0));     return ret;   }   vector<long long> operator*(vector<long long> a, long long b) {     for (int i = 0; i < a.size(); i++) a[i] = 1ll * a[i] * b % cys;     return a;   }   vector<long long> operator>>(vector<long long> a, int b) {     for (int i = 0; i < a.size() - b; i++) a[i] = a[i + b];     a.resize(a.size() - b);     return a;   }   namespace poly {   int N, l;   int A[1100000], B[1100000], r[1100000], pre1[20][600000], pre2[20][600000];   void pre() {     for (int i = 1, r = 0; i < (1 << 19); i <<= 1, r++) {       int w = 1, wn = qpow(g, (cys - 1) / (i << 1));       for (int j = 0; j < i; j++, w = 1ll * w * wn % cys) pre1[r][j] = w;     }     for (int i = 1, r = 0; i < (1 << 19); i <<= 1, r++) {       int w = 1, wn = qpow(invg, (cys - 1) / (i << 1));       for (int j = 0; j < i; j++, w = 1ll * w * wn % cys) pre2[r][j] = w;     }   }   void ntt(int *A, int N, int f) {     for (int i = 0; i < N; i++)       if (i < r[i]) swap(A[i], A[r[i]]);     for (int i = 1, r = 0; i < N; i <<= 1, r++) {       for (int j = 0; j < N; j += (i << 1)) {         for (int k = j; k < j + i; k++) {           int x = A[k], y = 1ll * A[k + i] *                             (f > 0 ? pre1[r][k - j] : pre2[r][k - j]) % cys;           A[k] = mod(x + y);           A[k + i] = mod(x + cys - y);         }       }     }     if (f < 0) {       int invn = qpow(N, cys - 2);       for (int i = 0; i < N; i++) A[i] = 1ll * A[i] * invn % cys;     }   }   void init(int t) {     N = 1, l = 0;     for (; N < t; N <<= 1) l++;     for (int i = 0; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));   }   void getmul() {     ntt(A, N, 1);     ntt(B, N, 1);     for (int i = 0; i < N; i++) A[i] = 1ll * A[i] * B[i] % cys;     ntt(A, N, -1);   }   vector<long long> mul(vector<long long> a, vector<long long> b) {     init(a.size() + b.size());     for (int i = 0; i < N; i++) A[i] = i < a.size() ? a[i] : 0;     for (int i = 0; i < N; i++) B[i] = i < b.size() ? b[i] : 0;     getmul();     vector<long long> ret(a.size() + b.size() - 1);     for (int i = 0; i < ret.size(); i++) ret[i] = A[i];     return ret;   }   vector<long long> polyinv(vector<long long> a, int l) {     if (l == 1) return vector<long long>(1, qpow(a[0], cys - 2));     a.resize(l);     vector<long long> b = polyinv(a, (l + 1) / 2);     init(l << 1);     for (int i = 0; i < N; i++) A[i] = i < l ? a[i] : 0;     for (int i = 0; i < N; i++) B[i] = i < (l + 1) / 2 ? b[i] : 0;     ntt(A, N, 1);     ntt(B, N, 1);     for (int i = 0; i < N; i++) A[i] = 1ll * A[i] * B[i] % cys * B[i] % cys;     ntt(A, N, -1);     vector<long long> t = b * 2;     t.resize(l);     for (int i = 0; i < l; i++) t[i] = mod(t[i] + cys - A[i]);     return t;   }   vector<long long> polydiff(vector<long long> a) {     for (int i = 0; i < a.size() - 1; i++) a[i] = 1ll * (i + 1) * a[i + 1] % cys;     a.resize(a.size() - 1);     return a;   }   vector<long long> polyint(vector<long long> a) {     a.resize(a.size() + 1);     for (int i = a.size() - 1; i >= 1; i--) a[i] = 1ll * a[i - 1] * ni[i] % cys;     a[0] = 0;     return a;   }   vector<long long> polyln(vector<long long> a, int l) {     return polyint(mul(polydiff(a), polyinv(a, l)));   }   vector<long long> polyexp(vector<long long> a, int l) {     if (l == 1) return vector<long long>(1, 1);     a.resize(l);     vector<long long> b = polyexp(a, (l + 1) / 2);     init(l << 1);     vector<long long> t = mul(b, vector<long long>(1, 1) - polyln(b, l) + a);     t.resize(l);     return t;   }   vector<long long> polypow(vector<long long> a, int l, int k) {     return polyexp(polyln(a, l) * k, l);   }   }  // namespace poly   vector<long long> getans() {     vector<long long> f(0);     for (int i = 0; i <= n + 1; i++) f.push_back(inv[i + 1]);     vector<long long> tmp =         poly::mul(f, poly::polyinv((vector<long long>(1, 1) - f) >> 1, n + 1));     vector<long long> tw(0);     tw.resize(n);     for (int i = 0; i < n; i++) tw[i] = tmp[i + 1];     vector<long long> h(0);     h.push_back(1), h.push_back(1);     h = poly::polyinv(poly::polyln(h, n + 3) >> 1, n + 2);     vector<long long> g =         poly::polyinv((vector<long long>(1, 1) - h) >> 1, n + 1);     vector<long long> ph = poly::polypow(h, n + 1, n + 1);     vector<long long> t1 = poly::mul(g, ph);     vector<long long> tmp1 = poly::mul(poly::polydiff(h), ph);     tmp1.resize(n + 1);     vector<long long> tmp2 = poly::mul(g, g);     tmp2.resize(n + 1);     vector<long long> t2 = poly::mul(tmp1, tmp2);     for (int i = 0; i < n; i++)       tw[i] =           mod(tw[i] + cys -               ni[n + 1] * mod(t1[i + 1] * (n - i + 1) % cys + t2[i + 1]) % cys);     for (int i = 0; i < n; i++) tw[i] = tw[i] * fac[i] % cys;     reverse(tw.begin(), tw.end());     tmp.clear();     for (int i = 0; i < n; i++) tmp.push_back(i & 1 ? cys - inv[i] : inv[i]);     tw = poly::mul(tw, tmp);     tw.resize(n);     reverse(tw.begin(), tw.end());     return tw;   }   int main() {     poly::pre();     n = readint();     fac[0] = inv[0] = 1;     for (int i = 1; i <= n + 5; i++) fac[i] = fac[i - 1] * i % cys;     inv[n + 5] = qpow(fac[n + 5], cys - 2);     for (int i = n + 4; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % cys;     for (int i = 1; i <= n + 5; i++) ni[i] = inv[i] * fac[i - 1] % cys;     vector<long long> res = getans();     for (int i = 0; i < n; i++)       printf( %lld  , res[i] * fac[n] % cys * inv[i] % cys);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   vector<int> a;   long long inv[32][2];   void solve(vector<int> &a, int depth) {     if (depth < 0) return;     if (a.size() == 0) return;     vector<int> left, right;     long long cnt0 = 0, cnt1 = 0, sum01 = 0, sum10 = 0;     for (int i = 0; i < a.size(); ++i) {       if (a[i] >> depth & 1) {         cnt1++;         sum01 += cnt0;         right.push_back(a[i]);       } else {         cnt0++;         sum10 += cnt1;         left.push_back(a[i]);       }     }     inv[depth][0] += sum01;     inv[depth][1] += sum10;     solve(left, depth - 1);     solve(right, depth - 1);   }   int main() {     scanf( %d , &n);     a.resize(n);     for (auto &x : a) cin >> x;     solve(a, 31);     long long ans = 0, x = 0;     for (int i = 0; i <= 31; ++i) {       if (inv[i][0] >= inv[i][1])         ans += inv[i][1];       else         ans += inv[i][0], x |= (1 << i);     }     printf( %lld %lld n , ans, x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = (int)1e9 + 7;   char s[5010], t[5010];   int n, m;   int d[2][5010], ans, cs;   int main() {     int i, j;     gets(s + 1);     n = strlen(s + 1);     gets(t + 1);     m = strlen(t + 1);     d[1][m + 1] = 1;     for (i = n; i >= 1; i--) {       cs = 0;       for (j = m + 1; j >= 1; j--) {         if (s[i] == t[j])           d[0][j] = cs;         else           d[0][j] = 0;         cs += d[1][j];         cs %= mod;       }       for (j = 1; j <= m; j++) {         ans += d[0][j];         ans %= mod;       }       for (j = 1; j <= m; j++) d[1][j] = d[0][j];     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, ans = 0;   const long long maxn = 1e6 + 5;   long long p[maxn];   int main() {     cin >> a >> b >> c >> d;     long long mx = min(b - a, c - b) + 1;     for (long long i = a + b, t = 1; i <= b + c; ++i) {       p[i] = t;       t = min(t + 1, mx);     }     for (long long i = b + c - mx + 1, t = mx; i <= b + c; ++i) {       p[i] = t;       --t;     }     for (long long i = a + b; i <= b + c; ++i) {       p[i] = p[i - 1] + p[i];     }     ans = p[b + c] * (d - c + 1);     for (long long i = c; i <= d; ++i) {       long long ind = min(b + c, i);       ans -= p[ind];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     long long int q = 8 * (n + k) + 9;     long long int y = (-3 + sqrt(q)) / 2;     cout << (y * (y + 1)) / 2 - k <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int a[300005];   bool notprime[8000005];   map<int, int> prims;   vector<int> primes;   void factor(int num) {     for (int i = 0; i < primes.size() && primes[i] * primes[i] <= num; i++) {       if (num % primes[i] == 0) {         prims[primes[i]]++;         while (num % primes[i] == 0) {           num /= primes[i];         }         if (num == 1) {           break;         }       }     }     if (num != 1) prims[num]++;   }   int main() {     std::ios_base::sync_with_stdio(false);     notprime[0] = true;     notprime[1] = true;     int i;     for (i = 2; i * i <= 8000005; i++) {       if (!notprime[i]) {         primes.push_back(i);         for (int j = i * i; j < 8000005; j += i) {           notprime[j] = true;         }       }     }     for (; i < 8000005; i++) {       if (!notprime[i]) primes.push_back(i);     }     int n;     cin >> n;     int commgcd;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i == 0)         commgcd = a[i];       else         commgcd = gcd(a[i], commgcd);     }     for (int i = 0; i < n; i++) {       factor(a[i] / commgcd);     }     int maxprim = -1;     for (auto par : prims) {       if (par.second > maxprim) {         maxprim = par.second;       }     }     if (maxprim == -1)       cout << -1 << endl;     else       cout << n - maxprim << endl;   }


#include <bits/stdc++.h>   int t1, t2;   inline int get() {     char c[10];     scanf( %s , &c);     if (!strcmp(c,  monday )) return 1;     if (!strcmp(c,  tuesday )) return 2;     if (!strcmp(c,  wednesday )) return 3;     if (!strcmp(c,  thursday )) return 4;     if (!strcmp(c,  friday )) return 5;     if (!strcmp(c,  saturday )) return 6;     if (!strcmp(c,  sunday )) return 0;   }   int main() {     t1 = get(), t2 = get();     if ((t1 == t2) || ((t1 + 2) % 7 == t2) || ((t1 + 3) % 7 == t2))       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long i, j, a, n = 0;     string s, str;     cin >> a;     cin >> s >> str;     for (long long i = 0; i < s.size() - 1; i++) {       if (s[i] == str[i]) continue;       if (s[i] != str[i] and s[i + 1] != str[i + 1]) {         swap(s[i], s[i + 1]);         n++;         continue;       }       n++;     }     if (s[a - 1] != str[a - 1]) n++;     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   char str[100005];   int main() {     scanf( %d %d %d , &n, &a, &b);     scanf( %s , str + 1);     if (str[a] == str[b]) {       puts( 0 );       return 0;     }     puts( 1 );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x(0);     cin >> n;     string s;     while (n--) {       cin >> s;       if (s[1] ==  + ) {         ++x;       } else {         --x;       }     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     int bagi = (n / m);     if (bagi * m == n) {       for (int i = 0; i < m; i++) {         printf( %d  , bagi);       }     } else {       int sisa = (n - (m * bagi));       for (int i = 0; i < m; i++) {         int now = 0;         if (sisa > 0) {           now = bagi + 1;           sisa--;         } else {           now = bagi;         }         printf( %d  , now);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       pair<int, int> p[n];       for (int i = 0; i < n; i++) {         cin >> p[i].first >> p[i].second;       }       bool check = true;       for (int i = 0; i < n; i++) {         if (p[i].first < p[i].second) check = false;         if (i > 0) {           if (p[i].first == p[i - 1].first) {             if (p[i].second != p[i - 1].second) check = false;           } else if (p[i].first > p[i - 1].first) {             if (p[i].second < p[i - 1].second) check = false;           } else             check = false;           if (p[i].first - p[i - 1].first < p[i].second - p[i - 1].second)             check = false;         }       }       if (check)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 100003;   long long f[20 * mxn + 10], rs[2 * mxn], ar[mxn + 10];   long long sum = 0;   int n, m, k;   struct data {     int l, r, id;   } query[mxn];   int bs = sqrt(mxn * 14);   bool operator<(data a, data b) {     return a.l / bs == b.l / bs ? a.r < b.r : a.l < b.l;   }   void add(int pos) {     sum += f[ar[pos] ^ k];     f[ar[pos]]++;   }   void rmv(int pos) {     f[ar[pos]]--;     sum -= f[ar[pos] ^ k];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> ar[i];     for (int i = 1; i <= n; i++) {       ar[i] = ar[i - 1] ^ ar[i];     }     for (int i = 0; i < m; i++) {       cin >> query[i].l >> query[i].r;       query[i].l--;       query[i].id = i;     }     sort(query, query + m);     int left = 1, right = 1;     add(1);     for (int i = 0; i < m; i++) {       while (left < query[i].l) {         rmv(left);         left++;       }       while (left > query[i].l) {         left--;         add(left);       }       while (right < query[i].r) {         right++;         add(right);       }       while (right > query[i].r) {         rmv(right);         right--;       }       rs[query[i].id] = sum;     }     for (int i = 0; i < m; i++) {       cout << rs[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a[3];       for (int i = 0; i < 3; i++) {         a[i].assign(n, 0);         for (auto &x : a[i]) cin >> x;       }       vector<int> res;       for (int i = 0; i < n; i++) {         for (int j = 0; j < 3; j++) {           if (!res.empty() && res.back() == a[j][i]) continue;           if (i == n - 1 && !res.empty() && res[0] == a[j][i]) continue;           res.push_back(a[j][i]);           break;         }       }       for (auto &x : res) cout << x <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 2e5 + 5;   const int SZ = 1e6 + 5;   const long long INF = 2e9 + 5;   int n, m, p;   pair<int, long long> a[N], b[N];   pair<int, pair<int, long long> > mon[N];   long long tree[4 * SZ], lazy[4 * SZ], cost[SZ];   void Build(int c, int ss, int se) {     if (ss == se) {       tree[c] = cost[ss];       return;     }     int mid = (ss + se) >> 1;     Build(c << 1, ss, mid);     Build(c << 1 | 1, mid + 1, se);     tree[c] = max(tree[c << 1], tree[c << 1 | 1]);   }   void Push(int c, int ss, int se) {     if (lazy[c]) {       tree[c] += lazy[c];       if (ss != se) {         lazy[c << 1] += lazy[c];         lazy[c << 1 | 1] += lazy[c];       }       lazy[c] = 0;     }   }   void Set(int c, int ss, int se, int qs, int qe, long long val) {     Push(c, ss, se);     if (ss > se || qs > se || qe < ss) return;     if (qs <= ss && se <= qe) {       lazy[c] += val;       Push(c, ss, se);       return;     }     int mid = (ss + se) >> 1;     Set(c << 1, ss, mid, qs, qe, val);     Set(c << 1 | 1, mid + 1, se, qs, qe, val);     tree[c] = max(tree[c << 1], tree[c << 1 | 1]);   }   long long Get(int c, int ss, int se, int qs, int qe) {     Push(c, ss, se);     if (ss > se || qs > se || qe < ss) return -INF;     if (qs <= ss && se <= qe) return tree[c];     int mid = (ss + se) >> 1;     return max(Get(c << 1, ss, mid, qs, qe),                Get(c << 1 | 1, mid + 1, se, qs, qe));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> p;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     for (int i = 1; i <= m; i++) cin >> b[i].first >> b[i].second;     for (int i = 1; i <= p; i++)       cin >> mon[i].first >> mon[i].second.first >> mon[i].second.second;     for (int i = 1; i < SZ; i++) cost[i] = -INF;     for (int i = 1; i <= m; i++) {       cost[b[i].first] = max(cost[b[i].first], -b[i].second);     }     sort(a + 1, a + 1 + n);     sort(mon + 1, mon + 1 + p);     Build(1, 1, SZ - 1);     int j = 0;     long long ans = -2 * INF;     for (int i = 1; i <= n; i++) {       while (j + 1 <= p && a[i].first > mon[j + 1].first) {         j++;         Set(1, 1, SZ - 1, mon[j].second.first + 1, SZ, mon[j].second.second);       }       ans = max(ans, -a[i].second + Get(1, 1, SZ - 1, 1, SZ - 1));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, mod = 1e9 + 7;   int a[N];   int qmi(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = (long long)res * a % mod;       b >>= 1;       a = (long long)a * a % mod;     }     return res;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) scanf( %d , a + i);       if (k == 1) {         printf(n & 1 ?  1  :  0 );         puts(  );         continue;       }       sort(a + 1, a + 1 + n);       int sum = 1, ans = 0, t = 1;       bool flag = true;       for (int i = n - 1; i >= 1; i--) {         int d = a[i + 1] - a[i];         if (sum > 0) {           while (sum < N && d) {             if ((long long)sum * k > N)               sum = N * 2;             else               sum = sum * k;             d--;             t = (long long)t * k % mod;           }         }         t = (long long)t * qmi(k, d) % mod;         if (sum)           sum--, t = ((long long)t + mod - 1) % mod;         else           sum = 1, t = 1;       }       printf( %lld n , (long long)qmi(k, a[1]) * t % mod);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 1000;   char s1[maxn];   char s2[maxn];   int judge(int st1, int en1, int st2, int en2) {     int sign = 0;     for (int i = st1, j = st2; i <= en1; i++, j++) {       if (s1[i] != s2[j]) {         sign = 1;         break;       }     }     if (sign == 0)       return 1;     else {       if ((en1 - st1 + 1) % 2 == 0) {         int mid1 = st1 + (en1 - st1 + 1) / 2 - 1;         int mid2 = st2 + (en2 - st2 + 1) / 2 - 1;         if (judge(st1, mid1, st2, mid2) && judge(mid1 + 1, en1, mid2 + 1, en2))           return 1;         if (judge(st1, mid1, mid2 + 1, en2) && judge(mid1 + 1, en1, st2, mid2))           return 1;       }     }     return 0;   }   int main() {     int len1, len2;     scanf( %s%s , s1, s2);     len1 = strlen(s1);     len2 = strlen(s2);     if (len1 != len2)       cout <<  NO n  << endl;     else {       int sign;       sign = judge(0, len1 - 1, 0, len1 - 1);       if (sign)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     while (cin >> n) {       long long int lcm = 2520;       cout << n / lcm << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string st;   set<string> S;   map<string, int> mp;   map<string, string> mp2;   int n, q;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       S.clear();       cin >> st;       int len = st.length();       for (int fr = 0; fr < len; fr++)         for (int ed = fr; ed < len; ed++) {           string sb = st.substr(fr, ed - fr + 1);           if (S.count(sb)) {           } else {             S.insert(sb);             mp[sb]++;             mp2[sb] = st;           }         }     }     cin >> q;     while (q--) {       cin >> st;       string attr2 =  - ;       if (mp2.count(st)) attr2 = mp2[st];       int attr1 = 0;       if (mp.count(st)) attr1 = mp[st];       cout << attr1 <<     << attr2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tot;   int num[1008];   int is[1005];   int n, pos[1005][5];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         scanf( %d , pos[i] + j);       }     }     int flag = 0;     int yes = 0;     if (n < 3) {       if (n == 1) {         printf( 1 n1 n );       } else {         printf( 2 n1 2 n );       }       return 0;     }     for (int i = 0; i < n; i++) {       flag = 1;       if (is[i]) continue;       is[i] = 1;       for (int j = 0; j < n && flag; j++) {         for (int k = 0; k < n && flag; k++) {           if (i == j || i == k || k == j) {             continue;           }           int x[5] = {0}, y[5] = {0};           for (int m = 0; m < 5; m++) {             x[m] = pos[j][m] - pos[i][m];           }           for (int m = 0; m < 5; m++) {             y[m] = pos[k][m] - pos[i][m];           }           int temp = 0;           for (int m = 0; m < 5; m++) {             temp += x[m] * y[m];           }           if (temp <= 0) {             is[j] = 1;             is[k] = 1;           } else {             is[i] = 1;             flag = 0;           }         }       }       if (flag == 1) {         printf( 1 n%d , i + 1);         yes = 1;         break;       }     }     if (yes == 0) {       printf( 0 n );     }     return 0;   }


#include <bits/stdc++.h>   int x[200010], check[200010];   long long int ans[200010];   long long int size[200010];   int next[200010];   int find(int k) {     if (next[k] == k)       return k;     else       return next[k] = find(next[k]);   }   std::vector<int> V[200010];   int height[200010];   long long int func(int k, int prev, int h) {     height[k] = h;     long long int ans = x[k];     for (int i = 0; i < V[k].size(); i++) {       if (V[k][i] == prev) continue;       ans += func(V[k][i], k, h + 1);     }     return size[k] = ans;   }   std::pair<int, int> edge[200010];   int main() {     int a;     scanf( %d , &a);     for (int i = 1; i <= a; i++) scanf( %d , &x[i]);     for (int i = 1; i <= a; i++) next[i] = i;     int b;     scanf( %d , &b);     for (int i = 1; i <= b; i++) {       int c, d;       scanf( %d%d , &c, &d);       edge[i] = std::make_pair(c, d);       if (find(c) == find(d))         check[i] = 1, ans[i] = 0;       else {         V[c].push_back(d);         V[d].push_back(c);         next[find(c)] = find(d);       }     }     func(1, 0, 1);     long long int sum = 0;     for (int i = 1; i <= a; i++) sum += x[i];     if (sum != 0) {       printf( Impossible );       return 0;     }     for (int i = 1; i <= b; i++) {       if (check[i] == 0) {         long long int s, t;         int c = edge[i].first;         int d = edge[i].second;         if (height[d] < height[c])           ans[i] = size[c];         else           ans[i] = -size[d];       }     }     printf( Possible n );     for (int i = 1; i <= b; i++) printf( %lld n , -ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, *a, q, sum = 0;     cin >> n;     a = new long long int[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q;       cout << sum - a[n - q] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<pair<int, int> > st;   int main() {     int n, k;     cin >> n >> k;     int cnt = 0;     for (int i = 0; i < n; i++) {       int num;       cin >> num;       cnt += num / 10;       if (num < 100) st.insert(make_pair(num % 10, num));     }     while (st.size() > 0 && (*st.rbegin()).first != 0 && k > 0) {       pair<int, int> num = *st.rbegin();       st.erase(st.find(num));       num.first++;       num.second++;       if (num.first == 10) cnt++;       num.first %= 10;       if (num.second < 100) st.insert(num);       k--;     }     while (st.size() > 0) {       pair<int, int> num = *st.begin();       st.erase(st.find(num));       while (num.second < 100 && k > 0) {         k--;         num.second++;         num.first = (num.first + 1) % 10;         if (num.first == 0) cnt++;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long n, t[N], m, res, ans[N];   int dd[N];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> t[i];     sort(t + 1, t + n + 1);     long long sum = 0;     int j = 1;     for (int i = 1; i <= 200000; i++) {       if (sum + i > m) {         res = i - 1;         break;       }       if (j <= n && t[j] == i)         j++;       else         sum += i;     }     int dem = 0;     j = 1;     for (int i = 1; i <= res; i++) {       if (j > n || i != t[j]) {         dem++;         ans[dem] = i;       } else         j++;     }     cout << dem << endl;     for (int i = 1; i <= dem; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long poww(long long x, long long y) {     if (x == 0) return 0;     if (x == 1) return 1;     if (y == 0) return 1;     if (y == 1) return x;     long long d = poww(x, y / 2);     if (y % 2) return x * d * d;     return d * d;   }   int main() {     long long n, m;     cin >> n >> m;     for (int i = 0; i < (n + m) * 2; i++) {       long long aa;       cin >> aa;     }     if (n == m) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int one[100007], zero[100007];   const int mod = 1e9 + 7;   long long FastPow(long long x, long long n, long long mod) {     long long s = 1;     while (n) {       if (n & 1) s = s * x % mod;       x = x * x % mod;       n >>= 1;     }     return s % mod;   }   int main() {     int n, q;     cin >> n >> q;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (i > 0) {         zero[i + 1] = zero[i];         one[i + 1] = one[i];       }       if (s[i] ==  0 ) {         zero[i + 1]++;       } else {         one[i + 1]++;       }     }     while (q--) {       int l, r;       cin >> l >> r;       long long ans = (FastPow(2, one[r] - one[l - 1], mod) - 1 + mod) % mod *                       FastPow(2, zero[r] - zero[l - 1], mod) % mod;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int power(unsigned long long int n,                                unsigned long long int p) {     unsigned long long int m = 1;     while (p > 0) {       m *= n;       p--;     }     return m;   }   void sieveOfEratosthenes(int n, bool prime[]) {     int i, p;     for (i = 2; i * i <= n; i++) {       if (prime[i]) {         for (p = i * i; p <= n; p += i) prime[p] = false;       }     }   }   long long int coins(int n, int a[]) {     int res, mn = INT_MAX;     res = mn = -a[0];     for (int i = 0; i < n - 1; ++i) {       mn = min(mn, res);       res += a[i] - a[i + 1];     }     return max(abs(res), abs(mn));   }   int main() {     int t, i, n, m, d, k, p;     long long int l, r, ret;     cin >> n;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     cout << coins(n, arr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100;   int main() {     long long n, m, a[MAXN], st[MAXN];     scanf( %I64d %I64d , &n, &m);     st[0] = 1;     for (int i = 1; i <= n; i++) st[i] = st[i - 1] * 2;     int l = 0;     int r = n;     for (int i = 1; i < n; i++) {       if (m > st[n - i - 1]) {         a[r - 1] = i;         r--;         m -= st[n - i - 1];       } else {         a[l] = i;         l++;       }     }     a[l] = n;     for (int i = 0; i < n; i++) printf( %I64d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int v;     Edge* next;   };   const int N = 100010;   int n, k;   bool vis[N];   int dis[N], prt[N], deg[N];   Edge* g[N];   void adde(int u, int v);   void dfs(int u);   void pred(int u, int r);   int main() {     scanf( %d%d , &n, &k);     for (int rep = 1; rep < n; ++rep) {       int u, v;       scanf( %d%d , &u, &v);       adde(u, v);       adde(v, u);     }     dfs(1);     int u = max_element(dis + 1, dis + n + 1) - dis;     memset(vis, 0, sizeof(vis));     dis[u] = 0;     prt[u] = 0;     dfs(u);     int m = max_element(dis + 1, dis + n + 1) - dis;     if (dis[m] != k * 2) {       puts( No );       return 0;     }     int cnt = k;     while (cnt--) m = prt[m];     memset(vis, 0, sizeof(vis));     pred(m, k);     puts( YES );     return 0;   }   void pred(int u, int r) {     vis[u] = true;     if (r == 0) {       if (deg[u]) {         puts( NO );         exit(0);       }       return;     }     if (deg[u] < 3) {       puts( NO );       exit(0);     }     for (Edge* p = g[u]; p; p = p->next)       if (!vis[p->v]) {         --deg[p->v];         pred(p->v, r - 1);       }   }   void dfs(int u) {     vis[u] = true;     for (Edge* p = g[u]; p; p = p->next)       if (!vis[p->v]) {         prt[p->v] = u;         dis[p->v] = dis[u] + 1;         dfs(p->v);       }   }   void adde(int u, int v) {     static Edge pool[N * 2];     static Edge* p = pool;     p->v = v;     p->next = g[u];     ++deg[u];     g[u] = p;     ++p;   }