# include <algorithm>   # include <iostream>   # include <numeric>   # include <vector>   # include <set>      using namespace std;      int main() {     int n, a, b;     while (cin >> n >> a >> b) {       string s;       cin >> s;       set<char> chars_set;       for (char c : s) {         chars_set.insert(c);       }       vector<char> chars(chars_set.begin(), chars_set.end());       int cc = (int)chars.size();       vector<int> L(cc, n + 1);       vector<int> R(cc, -1);       vector<int> cnt(cc, 0);       for (int i = 0; i < n; i++) {         for (int j = 0; j < cc; j++) {           if (s[i] == chars[j]) {             L[j] = min(L[j], i);             R[j] = max(R[j], i);             cnt[j] += 1;           }         }       }       vector<int> order(cc);       iota(order.begin(), order.end(), 0);       sort(order.begin(), order.end(), [&](int i, int j) {         return L[i] < L[j];       });       vector<int> order2 = order;       sort(order2.begin(), order2.end(), [&](int i, int j) {         return R[i] < R[j];       });       vector<int> order3 = order;       sort(order3.begin(), order3.end(), [&](int i, int j) {         return (L[i] + R[i]) / 2 < (L[j] + R[j]) / 2;       });       vector<int> order4 = order;       sort(order4.begin(), order4.end(), [&](int i, int j) {         return cnt[i] < cnt[j];       });       vector<bool> can(1 << cc, 0);       can[0] = 1;       for (int t = 1; t < (1 << cc); t++) {         int max_R = -1;         int min_L = -1;         int total = 0;         for (int i : order) {           if (!(t & (1 << i))) {             continue;           }           if (min_L == -1) {             min_L = L[i];           }           total += cnt[i];           max_R = max(max_R, R[i]);         }         int len = max_R - min_L + 1;         if (total * b >= a * len) {           can[t] = 0;           for (int i = 0; i < cc; i++) {             if (t & (1 << i)) {               if (can[t ^ (1 << i)]) {                 can[t] = 1;                 break;               }             }           }           if (can[t]) {             continue;           }         }         int nt = 0;         for (auto& v : {order, order2, order3, order4}) {           for (int i : v) {             if (!(t & (1 << i))) {               continue;             }             nt |= (1 << i);             if (nt != t && can[nt] && can[t ^ nt]) {               can[t] = 1;               break;             }           }         }       }       string ret =   ;       for (int i = 0; i < cc; i++) {         if (can[(1 << cc) - 1 - (1 << i)]) {           ret += chars[i];         }       }       cout << ret.size();       for (char c : ret) {         cout <<     << c;       }       cout <<   n ;     }     return 0;   } //


#include <bits/stdc++.h>   const int maxn = 10010;   const int mod = 1000000007;   int n;   char ch[4][maxn];   int f[maxn][8][2];   int obs[maxn];   int ot, vt;   void part0() {     memset(obs, 0, sizeof(obs));     for (int j = 1; j <= n; j++)       for (int i = 3; i >= 1; i--)         obs[j] = (obs[j] << 1) + ((ch[i][j] !=  . ) ? 1 : 0);     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= n; j++)         if (ch[i][j] ==  O ) {           ot = j;           vt = 1 << (i - 1);         }   }   void init() {     scanf( %d , &n);     for (int i = 1; i <= 3; i++) scanf( %s , ch[i] + 1);   }   void solve() {     part0();     memset(f, 0, sizeof(f));     f[0][7][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j < 8; j++)         for (int k = 0; k < 2; k++) {           if (!f[i - 1][j][k]) continue;           int cnt = j ^ 7;           if (cnt & obs[i]) continue;           int oc = cnt | obs[i];           for (int c = 0; c <= 6; c += 3) {             if (oc & c) continue;             int oct = oc | c;             if ((i == ot - 1) && (cnt & vt) ||                 (i == ot) && (!(oc ^ vt)) && (vt != 2) ||                 (i - 2 == ot) && (cnt & vt)) {               f[i][oct][1] = (f[i][oct][1] + f[i - 1][j][k]) % mod;             } else               f[i][oct][k] = (f[i][oct][k] + f[i - 1][j][k]) % mod;           }         }   }   void print() { printf( %d n , f[n][7][1]); }   int main() {     init();     solve();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int bs(int arr[], int n, int target) {     int left = 0, mid, right = n - 1;     while (left <= right) {       mid = left + (right - left) / 2;       if (arr[mid] < target)         left = mid + 1;       else         right = mid - 1;     }     return left + 1;   }   int main() {     int n, m;     cin >> n >> m;     int songs[n];     int c, t, sum = 0;     for (int i = 0; i < n; i++) {       cin >> c >> t;       sum += (c * t);       songs[i] = sum;     }     int query;     while (m--) {       cin >> query;       cout << bs(songs, n, query) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 5e5;   int main() {     long long n, a, b, c, t;     cin >> n >> a >> b >> c >> t;     long long arr[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> arr[i];     }     long long s = n * a;     if (b >= c) {       cout << s << endl;     } else {       long long q = 1;       long long s2 = 0;       long long q2 = 1;       long long s3 = 0;       for (long long i = 1; i <= n; i++) {         if (arr[i] != t) {           s2 += (t - arr[i]) * c;           q++;         }       }       for (long long i = 1; i <= n; i++) {         arr[i] = a - (t - arr[i]) * b;       }       for (long long i = 1; i <= n; i++) {         s3 += arr[i];       }       cout << s2 + s3;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int main() {     int n, d, h;     cin >> n >> d >> h;     if (h * 2 < d || h > n || d > n || h > d || n < d + 1 ||         (h == 1 && d == 1 && (n != 2)))       cout << -1;     else {       if (h == 1) {         for (int i = 2; i <= n; i++) cout << 1 <<     << i << endl;         return 0;       }       for (int i = 1; i <= h; i++) cout << i <<     << i + 1 << endl;       for (int i = 1; i <= d - h; i++)         cout << ((i == 1) ? 1 : i + h) <<     << i + h + 1 << endl;       for (int i = 0; i < n - d - 1; i++) cout << 2 <<     << n - i << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse2 )   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long min(long long a, long long b) { return (a < b) ? a : b; }   void amax(long long& a, long long b) { a = max(a, b) % 1000000007; }   void amin(long long& a, long long b) { a = min(a, b) % 1000000007; }   void inc(long long& a, long long b) { a = (a + b) % 1000000007; }   void dec(long long& a, long long b) { a = (a - b + 1000000007) % 1000000007; }   long long solve() {     long long n, p;     cin >> n >> p;     vector<long long> in(n + 10, 1e9), out(n + 10, 0);     for (long long i = 0; i < p; i++) {       long long x;       cin >> x;       amin(in[x], i + 1);       amax(out[x], i + 1);     }     long long ans = 0;     for (long long i = 1; i < n + 1; i++) {       if (out[i] == 0) {         ans++;       }       long long cur = out[i];       if (in[i] > out[i + 1] && i + 1 <= n) ans++;       if (in[i] > out[i - 1] && i > 1) ans++;     }     cout << ans;     return 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, res;     cin >> n;     while (1) {       if (n % 3 != 0) {         res = (n / 3) + 1;         break;       }       n = n / 3;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[206];   char str[206];   inline bool check1() {     for (int i = 0; i < (n >> 1); ++i) {       if (arr[i] >= arr[i + (n >> 1)]) return 0;     }     return 1;   }   inline bool check2() {     for (int i = 0; i < (n >> 1); ++i) {       if (arr[i] <= arr[i + (n >> 1)]) return 0;     }     return 1;   }   int main() {     scanf( %d , &n);     scanf( %s , str);     n = strlen(str);     for (int i = 0; i < n; ++i) arr[i] = (int)(str[i] -  0 );     sort(arr, arr + (n / 2));     sort(arr + (n / 2), arr + n);     puts((check1() || check2()) ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k;   void inp() {     cin >> n >> k;     return;   }   void solve() {     set<long long int> second;     for (long long int i = 1; i <= k; i++)       if (second.count(n % i))         return void(cout <<  No n );       else         second.insert(n % i);     cout <<  Yes n ;     return;   }   int main() {     clock_t beg = clock();     {       cin.tie(0);       ios_base::sync_with_stdio(false);     };     inp();     solve();     clock_t end = clock();     fprintf(stderr,  %.3f sec n , (double)(end - beg) / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 5;   const double eps = 1e-4;   struct node {     double x, y;     node(double x = 0, double y = 0) : x(x), y(y) {}     inline bool operator<(const node &rhs) const {       if (fabs(x - rhs.x) >= eps) return x < rhs.x;       if (fabs(y - rhs.y) >= eps) return y < rhs.y;       return 0;     }     inline bool operator==(const node &rhs) const {       return !(*this < rhs) && !(rhs < *this);     }   } p[MAXN * MAXN << 1];   struct circle {     double a, b, r;     circle(double a = 0, double b = 0, double r = 0) : a(a), b(b), r(r) {}   } c[MAXN];   std::vector<node> ans;   inline void getcircle_intersection(circle x, circle y) {     if (x.r < y.r) std::swap(x, y);     if (fabs((x.r + y.r) * (x.r + y.r) - (x.a - y.a) * (x.a - y.a) -              (x.b - y.b) * (x.b - y.b)) < eps) {       const double dx = (y.a - x.a), dy = (y.b - x.b), k = x.r / (x.r + y.r);       ans.push_back(node(x.a + dx * k, x.b + dy * k));       return;     }     if (fabs(y.r + sqrt((x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b)) -              x.r) < eps) {       const double dx = (y.a - x.a), dy = (y.b - x.b), k = x.r / (x.r - y.r);       ans.push_back(node(x.a + dx * k, x.b + dy * k));       return;     }     if ((x.r + y.r) * (x.r + y.r) <         (x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b))       return;     if (y.r + sqrt((x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b)) < x.r)       return;     const double lk = (x.a - y.a) / (y.b - x.b),                  lb = (x.r * x.r - y.r * y.r + y.a * y.a - x.a * x.a + y.b * y.b -                        x.b * x.b) /                       (2 * y.b - 2 * x.b);     const double fa = lk * lk + 1, fb = 2 * lk * lb - 2 * x.a - 2 * x.b * lk,                  fc = x.a * x.a + x.b * x.b + lb * lb - 2 * x.b * lb - x.r * x.r;     double dt = fb * fb - 4 * fa * fc;     if (fabs(dt) > eps && dt < 0) return;     dt = fabs(dt);     const double ax1 = (-fb + sqrt(dt)) / (2 * fa),                  ax2 = (-fb - sqrt(dt)) / (2 * fa);     ans.push_back(node(ax1, lk * ax1 + lb));     ans.push_back(node(ax2, lk * ax2 + lb));   }   inline bool point_on_circle(const node &x, const circle &y) {     return fabs((x.x - y.a) * (x.x - y.a) + (x.y - y.b) * (x.y - y.b) -                 y.r * y.r) <= eps;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       double a, b, r;       scanf( %lf%lf%lf , &a, &b, &r);       c[i].a = a * cos(233) + b * sin(233);       c[i].b = -a * sin(233) + b * cos(233);       c[i].r = r;     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) getcircle_intersection(c[i], c[j]);     std::sort(ans.begin(), ans.end());     int sz = std::unique(ans.begin(), ans.end()) - ans.begin();     int tot = 0;     for (int i = 1; i <= n; i++) {       int ptot = 0;       for (unsigned j = 0; j < sz; j++) ptot += point_on_circle(ans[j], c[i]);       tot += ptot + !ptot;     }     if (sz == 0) tot--;     printf( %d n , tot - sz + 2);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 5;   using namespace std;   int a[maxn * 2];   int main() {     int n;     cin >> n;     int flag = 0;     for (int t = 0; t < n; t++) {       scanf( %d , &a[t]);       if (a[t] == 1) {         flag = 1;       }     }     for (int t = n; t < 2 * n; t++) {       a[t] = a[t - n];     }     int s = 1;     int maxnn = -1;     for (int t = 1; t < 2 * n; t++) {       if (a[t] == a[t - 1] && a[t] == 1) {         s++;       } else {         s = 1;       }       if (s > maxnn) {         maxnn = s;       }     }     if (maxnn > n) {       maxnn = n;     }     if (flag == 1)       cout << maxnn << endl;     else {       cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> computer(100, 0);   int n, q, free_computers;   long s;   int t, k, d;   void question() {     cin >> t >> k >> d;     free_computers = 0;     for (int j = 0; j < n && free_computers < k; j++) {       if (computer[j] <= t) free_computers++;     }     if (k > free_computers)       cout << -1 <<   n ;     else {       s = 0;       for (int j = 0; j < n && k != 0; j++) {         if (computer[j] <= t) {           k--;           computer[j] = d + t;           s += j + 1;         }       }       cout << s <<   n ;     }   }   int main() {     cin >> n >> q;     for (int i = 0; i < q; i++) question();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Int() {     int x;     cin >> x;     return x;   }   double din() {     double x;     cin >> x;     return x;   }   string Str() {     string x;     getline(cin, x);     return x;   }   char Ch() {     char x;     cin >> x;     return x;   }   int main() {     int h1 = Int();     char ch = Ch();     int m1 = Int();     int h2 = Int();     ch = Ch();     int m2 = Int();     int x = (((h2 * 60) + m2) - ((h1 * 60) + m1)) / 2;     int y = ((h1 * 60) + m1) + x;     int z;     h1 = y / 60;     m1 = y % 60;     cout << setfill( 0 ) << setw(2) << h1 <<  :  << setfill( 0 ) << setw(2) << m1          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200008], sign[200008];   int b[200008];   int main() {     int n;     scanf( %d , &n);     int t;     memset(a, 0, sizeof(a));     memset(sign, 0, sizeof(sign));     for (int i = 0; i < n; i++) {       scanf( %d , &t);       int k = t;       int time = 0;       b[i] = t;       while (k) {         a[k] += time;         sign[k]++;         if (k & 1 && k > 1) {           int kk = k / 2 * 2, tim = time + 2;           while (kk < 200008) {             a[kk] += tim;             sign[kk]++;             kk <<= 1;             tim++;           }         }         k >>= 1;         time++;       }       k = t, time = 0;       while (k < 200008) {         a[k] += time;         sign[k]++;         k <<= 1;         time++;       }       sign[t]--;     }     int res = 0x3f3f3f3f;     for (int i = 1; i < 200008; i++) {       if (sign[i] == n) {         res = min(res, a[i]);       }     }     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long pows(long long b, long long e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long a = pow(b, e / 2);       return a * a;     } else {       long long a = pow(b, e / 2);       return b * a * a;     }   }   long long powm(long long x, long long y, long long m) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long modInverse(long long a, long long m = 1000000007) {     if (m == 1) return 0;     long long m0 = m, y = 0, x = 1;     while (a > 1) {       long long q = a / m, t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, i, j, k, x, y, z, e, f, p, q, g, l, r, w, h,         count1 = 0, prod = 1, a, b, c, d, index, x1, x2, diff, ans = 0, sum = 0,         sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;     string s, s1, s2;     cin >> n;     if (n == 1) {       cout <<  1 ;       return 0;     } else {       ans = 1;       k = 3;       for (i = 2; i <= n; i++) {         ans += k * 4;         k += 3;       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename A, size_t N, typename T>   void Fill(A (&array)[N], const T &val) {     std::fill((T *)array, (T *)(array + N), val);   }   class Graph {    public:     int vn;     int sumcost = 0;     vector<vector<pair<int, int>>> g;     Graph(int n) {       vn = n;       g.resize(n);     }     virtual void con(int a, int b, int w) = 0;     int getWeight(int f, int t) {       auto itr = lower_bound((g[f]).begin(), (g[f]).end(), make_pair(t, INT_MIN));       if (itr != g[f].end()) return itr->second;       return INT_MIN;     }     int Costsum() { return sumcost; }     void scan(int edcount, bool oindexed, bool w) {       for (int i = (0); (edcount) > i; i++) {         int a, b, c = 1;         scanf( %d %d , &a, &b);         if (w) scanf( %d , &c);         con(a - oindexed, b - oindexed, c);       }     }   };   class BiDGraph : public Graph {    public:     BiDGraph(int n) : Graph(n) {}     void con(int a, int b, int w = 1) {       g[a].push_back({b, w});       g[b].push_back({a, w});       sumcost++;     }   };   class DGraph : public Graph {    public:     DGraph(int n) : Graph(n) {}     void con(int a, int b, int w = 1) {       g[a].push_back({b, w});       sumcost++;     }   };   signed main() {     int n;     scanf( %d , &n);     printf( %d n , (n - 1) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> arr;     int n, a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       arr.push_back(a);     }     sort(arr.begin(), arr.end());     cout << arr[n - 1] << endl;     arr.clear();     return 0;   }


#include <bits/stdc++.h>   int len, p;   char s[111111], buf[111111];   void add(char ch) { buf[len++] = ch; }   void out() {     printf( < );     for (int i = 0; i < len; i++) printf( %c , buf[i]);     printf( > n );     len = 0;   }   int main() {     gets(s);     len = p = 0;     for (p = 0; s[p]; p++) {       if (s[p] ==    ) {         p++;         while (s[p] !=    ) {           add(s[p]);           p++;         }         out();       } else if (s[p] ==    ) {         if (len) out();       } else         add(s[p]);     }     if (len) out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2, s3, s4;     long long int n;     cin >> s1 >> s2;     cin >> n;     for (long long int i = 0; i < n; i++) {       cout << s1 <<     << s2 << endl;       cin >> s3 >> s4;       if (s1.compare(s3) == 0) {         s1 = s4;       } else {         s2 = s4;       }     }     cout << s1 <<     << s2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   char s[maxn];   int l;   long long make(int x, long long u) {     int z = l - x;     long long k = 1, u1 = 0;     for (int i = 0; i < z; i++) {       u1 += (s[l - 1 - i] -  0 ) * k;       k *= 10;     }     u1 += u / k * k;     if (u1 <= u) u1 += k;     return u1;   }   int main() {     int t;     cin >> t;     while (t--) {       scanf( %s , s);       l = strlen(s);       long long u = 1988;       for (int i = l - 1; i >= 4; i--) {         u = make(i, u);       }       cout << u << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, g[13][13], lca[13][13];   long long dp[1 << 13][13];   long long f(int s, int root) {     s &= ~(1 << root);     if (s == 0) return 1;     if (dp[s][root] != -1) return dp[s][root];     long long res = 0;     int must = 0;     for (int i = (0); i < (n); i++)       if (s & 1 << i) {         must = i;         break;       }     for (int x = (0); x < (1 << n); x++)       if (((x | s) == s) && (x & 1 << must)) {         int ny = s ^ x;         int y = ny | 1 << root;         bool bad = false;         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (x & 1 << j)) {               if (lca[i][j] != -1 && (y & 1 << lca[i][j])) {                 bad = true;               }             }         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (y & 1 << j)) {               if (lca[i][j] != -1 && lca[i][j] != root) {                 bad = true;               }             }         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             if ((x & 1 << i) && (ny & 1 << j)) {               if (g[i][j]) bad = true;             }         int c = 0, x_root = -1;         for (int i = (0); i < (n); i++)           if (x & 1 << i) {             if (g[root][i]) {               c++;               x_root = i;             }           }         if (c >= 2) bad = true;         if (bad) continue;         for (int i = (0); i < (n); i++)           if (x & 1 << i) {             if (x_root != -1 && i != x_root) continue;             res += f(x, i) * f(y, root);           }       }     return dp[s][root] = res;   }   int main() {     cin >> n >> m >> q;     for (int i = (0); i < (m); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u][v] = g[v][u] = 1;     }     memset(lca, -1, sizeof(lca));     for (int i = (0); i < (n); i++) lca[i][i] = i;     for (int i = (0); i < (q); i++) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       c--;       if (lca[a][b] != -1 && lca[a][b] != c) {         cout << 0 << endl;         return 0;       }       lca[a][b] = lca[b][a] = c;     }     memset(dp, -1, sizeof(dp));     cout << f((1 << n) - 1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   inline bool isDigit(char c) { return  0  <= c && c <=  9 ; }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline bool isSquare(T x) {     int y = sqrt(x + 0.5);     return (y * y) == x;   }   template <class T1, class T2>   inline T1 gcd(T1 a, T2 b) {     return b ? gcd(b, a % b) : a;   }   template <class T1, class T2>   inline T1 eqMin(T1& x, const T2& y) {     if (T1(y) < x) return x = y;     return x;   }   template <class T1, class T2>   inline T1 eqMax(T1& x, const T2& y) {     if (T1(y) > x) return x = y;     return x;   }   template <class T1, class T2>   inline T1 min(const T1& x, const T2& y) {     return x < (T1)y ? x : (T1)y;   }   template <class T1, class T2>   inline T1 max(T1& x, const T2& y) {     return x > (T1)y ? x : (T1)y;   }   template <typename T>   inline T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  { ;     bool was = false;     for (const T& x : v) {       if (was) os <<  ,  ;       was = true;       os << x;     }     os <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& v) {     os <<  [ ;     bool was = false;     for (const T& x : v) {       if (was) os <<  ,  ;       was = true;       os << x;     }     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const multiset<T>& v) {     os <<  [ ;     bool was = false;     for (const T& x : v) {       if (was) os <<  ,  ;       was = true;       os << x;     }     os <<  ] ;     return os;   }   template <class T1, class T2>   ostream& operator<<(ostream& os, const map<T1, T2>& m) {     os <<  < ;     bool was = false;     for (const auto& x : m) {       if (was) os <<  ,  ;       was = true;       os << x;     }     os <<  > ;     return os;   }   template <size_t sz>   ostream& operator<<(ostream& os, const bitset<sz>& bit) {     os <<  / ;     for (int i = 0; i < sz; i++) os << bit[i];     os <<     ;     return os;   }   const double PI = acos(-1);   const double EPS = 1e-8;   const int INF = (int)2e9;   const long long LINF = (long long)2e18;   const int MOD = (int)1e9 + 7;   const int MAXN = (int)1e5 + 10;   int n, s, x;   int val[MAXN], nxt[MAXN];   int p[MAXN];   bool us[MAXN];   int cnt = 0;   void read(int x) {     if (us[x]) return;     us[x] = true;     cout <<  ?   << x <<   n ;     cout.flush();     cin >> val[x] >> nxt[x];     cout.flush();   }   int main() {     ios_base::sync_with_stdio(false);     srand(time(NULL));     cin >> n >> s >> x;     cout.flush();     for (int i = 1; i <= n; i++) {       p[i] = i;     }     random_shuffle(p + 1, p + n + 1);     read(s);     int ss = s;     s = 0;     val[0] = -1;     for (int i = 1; i <= min(n / 2, 1300); i++) {       read(p[i]);       if (val[p[i]] < x && val[p[i]] > val[s]) {         s = p[i];       }     }     if (val[ss] < x && val[ss] > val[s]) {       s = ss;     }     if (s) {       while (val[s] < x) {         s = nxt[s];         if (s == -1) {           cout <<  ! -1                 <<   n ;           cout.flush();           return 0;         }         read(s);         if (val[s] >= x) {           cout <<  !   << val[s] <<   n ;           cout.flush();           return 0;         }         if (nxt[s] == -1) {           cout <<  ! -1                 <<   n ;           cout.flush();           return 0;         }       }     }     cout <<  !   << val[ss] <<   n ;     cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510, mod = 1LL * 1000 * 1000 * 1000 + 7;   int dp[N][N], n, b[N], num[N][N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     for (int j = 1; j <= n; j++)       for (int i = j - 1; i >= 0; i--) {         if (j - i <= 2) {           dp[i][j] = num[i][j] = 1;           continue;         }         for (int k = i + 1; k + 1 < j; k++)           if (b[k] < b[j - 1])             (num[i][j] += 1LL * num[i][k + 1] * dp[k][j - 1] % mod) %= mod;         for (int k = i + 1; k < j; k++)           (dp[i][j] += 1LL * num[i][k + 1] * dp[k][j] % mod) %= mod;       }     cout << dp[0][n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mini;   map<char, int> M;   set<int> s;   int n;   void rec(int ind, vector<int> c, vector<int> d) {     if (ind == 10) {       int rem = n;       int X = c.size() + d.size();       int i, j;       set<int> S = s;       set<int>::iterator it;       for (i = 0; i < c.size(); i++) {         for (j = 0; j < d.size(); j++) {           if (S.find(5 * c[i] + d[j]) != S.end()) {             S.erase(5 * c[i] + d[j]);           }         }       }       for (i = 0; i < c.size(); i++) {         int count = 0, flag;         for (j = 0; j < 5; j++) {           if (S.find(5 * c[i] + j) != S.end()) {             count++;             flag = j;           }         }         if (count == 1) {           S.erase(5 * c[i] + flag);         }       }       for (i = 0; i < d.size(); i++) {         int count = 0, flag;         for (j = 0; j < 5; j++) {           if (S.find(5 * j + d[i]) != S.end()) {             count++;             flag = j;           }         }         if (count == 1) {           S.erase(5 * flag + d[i]);         }       }       if (S.size() == 1 || S.size() == 0) {         mini = min(mini, X);       }       return;     }     if (ind < 5) {       rec(ind + 1, c, d);       c.push_back(ind);       rec(ind + 1, c, d);     } else {       rec(ind + 1, c, d);       d.push_back(ind - 5);       rec(ind + 1, c, d);     }   }   int main() {     mini = 10;     M[ R ] = 0;     M[ G ] = 1;     M[ B ] = 2;     M[ Y ] = 3;     M[ W ] = 4;     cin >> n;     int i;     string st;     for (i = 0; i < n; i++) {       cin >> st;       s.insert(5 * M[st[0]] + st[1] -  1 );     }     vector<int> c;     vector<int> d;     rec(0, c, d);     cout << mini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   const int M = 1100000;   const long long mod = 1e9 + 7;   int n, m;   vector<pair<int, int> > g[N];   int edge[N];   int col[N], dep[N];   int val[N], f[N];   void dfs(int x, int fa) {     f[x] = fa;     dep[x] = dep[fa] + 1;     for (auto p : g[x]) {       int y = p.first, id = p.second;       if (y == fa) continue;       edge[y] = id;       dfs(y, x);     }   }   struct query {     int x, y, w;     friend bool operator<(query a, query b) { return a.w < b.w; }   } a[N], b[N];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(make_pair(y, i)), g[y].push_back(make_pair(x, i));     }     dfs(1, 0);     scanf( %d , &m);     for (int i = 1; i <= n; i++) val[i] = 1e6;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &a[i].x, &a[i].y, &a[i].w);       b[i] = a[i];     }     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; i++) {       int nx = a[i].x, ny = a[i].y;       while (dep[nx] != dep[ny]) {         if (dep[nx] > dep[ny])           val[edge[nx]] = a[i].w, nx = f[nx];         else           val[edge[ny]] = a[i].w, ny = f[ny];       }       while (nx != ny) {         val[edge[nx]] = a[i].w, nx = f[nx];         val[edge[ny]] = a[i].w, ny = f[ny];       }     }     int flag = 0;     for (int i = 1; i <= m; i++) {       int nx = b[i].x, ny = b[i].y;       int mn = 1e9;       while (dep[nx] != dep[ny]) {         if (dep[nx] > dep[ny])           mn = min(mn, val[edge[nx]]), nx = f[nx];         else           mn = min(mn, val[edge[ny]]), ny = f[ny];       }       while (nx != ny) {         mn = min(mn, val[edge[nx]]), nx = f[nx];         mn = min(mn, val[edge[ny]]), ny = f[ny];       }       if (mn != b[i].w) flag = 1;     }     if (flag)       printf( -1 n );     else {       for (int i = 1; i < n; i++) printf( %d  , val[i]);     }     return 0;   }


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


#include<iostream>   #include<algorithm>   using namespace std;   long long cmp(long long a,long long b)   {    return a > b;   }   int main()   {    int t,n,i;    long long array[200000],alice,bob;    cin>>t;    while(t--)    {     alice=0;     bob=0;     cin>>n;     for(i=0;i<n;i++)     {      scanf( %lld ,&array[i]);     }     sort(array,array+n,cmp);     for(i=0;i<n;i++)     {      if(i%2==0)      {       if(array[i]%2==0)alice+=array[i];      }      else      {       if(array[i]%2!=0)bob+=array[i];      }     }     if(alice>bob)cout<< Alice <<endl;     else if(alice<bob)cout<< Bob <<endl;     else cout<< Tie <<endl;    }   }


#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   struct Node {     long long mx, lz;   };   Node t[1 << 19];   int a[1 << 18];   long long build(int u, int b, int e, long long s = 0) {     if (b + 1 == e) {       t[u].mx = a[b] - s;       return s + a[b];     }     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     s = build(lc, b, m, s);     s = build(rc, m, e, s);     t[u].mx = max(t[lc].mx, t[rc].mx);     return s;   }   void push(int u, int sz) {     if (!t[u].lz) return;     t[u].mx += t[u].lz;     if (sz > 1) {       t[2 * u].lz += t[u].lz;       t[2 * u + 1].lz += t[u].lz;     }     t[u].lz = 0;   }   void upd(int u, int b, int e, int pos, int d) {     int sz = e - b;     if (pos >= e) return push(u, e - b);     if (pos < b) return t[u].lz -= d, push(u, sz);     if (sz == 1) return t[u].lz += d, push(u, sz);     push(u, sz);     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     upd(lc, b, m, pos, d);     upd(rc, m, e, pos, d);     t[u].mx = max(t[lc].mx, t[rc].mx);   }   int get(int u, int b, int e) {     push(u, e - b);     if (t[u].mx < 0) return -2;     if (b + 1 == e) return t[u].mx == 0 ? b : -2;     int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;     int res = get(lc, b, m);     if (res < 0) res = get(rc, m, e);     return res;   }   int main() {     canhazfast();     int n, q;     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> a[i];     build(1, 0, n);     for (; q; --q) {       int p, x;       cin >> p >> x;       --p;       upd(1, 0, n, p, x - a[p]);       a[p] = x;       cout << get(1, 0, n) + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string t;     cin >> t;     int n = t.size();     int start = (n % 2) ? n / 2 : n / 2 - 1;     int j = 1;     int k = n / 2;     putchar(t[start]);     while (k--) {       if (start + j <= n - 1) {         putchar(t[start + j]);       }       if (start - j >= 0) {         putchar(t[start - j]);       }       ++j;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, c[long(1e7 + 50)], cnt;   void sieve() {     c[1] = 1;     for (long i = 2; i <= long(1e7); ++i)       if (!c[i])         for (long j = 2; i * j <= long(1e7); ++j) c[i * j] = 1;   }   bool Prime(long x) {     if (x < long(1e7)) {       if (c[x]) return false;       return true;     }     for (long i = 2; i <= trunc(sqrt(x)); ++i)       if (!(x % i)) return false;     return true;   }   int main() {     scanf( %ld , &n);     if (n <= 7)       printf( 1 n%ld , n);     else {       printf( 3 n );       sieve();       n -= 3;       for (long i = n; i >= 1; --i)         if (Prime(i) && Prime(n - i)) {           printf( %ld %ld %ld , i, n - i, 3);           return 0;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = 1e5 + 5;   int n, m, k, p[105], second[105], mx[105];   int ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &p[i]);     for (int i = 1; i <= n; ++i) {       scanf( %d , &second[i]);       if (mx[second[i]] < p[i]) mx[second[i]] = p[i];     }     for (int i = 1; i <= k; ++i) {       int v;       scanf( %d , &v);       if (mx[second[v]] > p[v]) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   const long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt = 1;     while ((tt)--) {       long long n, m;       cin >> n >> m;       if (min(n, m) & 1) {         cout <<  Akshat  <<   n ;       } else {         cout <<  Malvika  <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[205], max1, n, k, t;   int main() {     cin >> t;     while (t > 0) {       t--;       scanf( %d%d , &n, &k);       for (int i = 0; i < k; i++) scanf( %d , &a[i]);       max1 = 0;       if (k == 1)         cout << max(n - a[0] + 1, a[0]) << endl;       else {         for (int i = 1; i < k; i++) {           if ((a[i] - a[i - 1]) / 2 + 1 > max1) max1 = (a[i] - a[i - 1]) / 2 + 1;         }         int d = max(n - a[k - 1] + 1, a[0]);         if (d > max1)           cout << d << endl;         else {           cout << max1 << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long b, long long e, long long m) {     b %= m;     if (e == 0) return 1;     if (e % 2 == 1) return (b * modpow(b, e - 1, m)) % m;     return modpow((b * b) % m, e / 2, m);   }   long long powten[1005];   vector<long long> mods;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < 1005; i++) {       if (i == 0)         powten[i] = 1;       else         powten[i] = (10 * powten[i - 1]) % k;     }     mods.resize(k, 0);     for (int i = 0; i < 10; i++) {       if (i % k != 0 or i == 0) mods[i % k] = (mods[i % k] + 1) % m;     }     for (int i = 1; i < n; i++) {       vector<long long> temp;       temp.resize(k, 0);       for (int j = 0; j < 10; j++) {         if (i == n - 1 and j == 0) continue;         long long del = (j * powten[i]) % k;         for (int prev = 0; prev < k; prev++)           temp[(prev + del) % k] = (temp[(prev + del) % k] + mods[prev]) % m;       }       temp[0] = ((i == n - 1) ? 0 : 1);       mods = temp;     }     if (n == 1) mods[0] = 0;     long long total = (9 * modpow(10, n - 1, m)) % m;     for (int i = 0; i < k; i++) total = (total - mods[i] + m) % m;     cout << total <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortin(const pair<long long int, long long int> &e,               const pair<long long int, long long int> &f) {     return (e.first < f.first);   }   bool POT(long long int x) { return x && (!(x & (x - 1))); }   long long int a, b, c, i, j, k, l, m, n, p, q, r, x, y, z, ts, mn = 10e17,                                                                  mod = 10e8 + 7;   long long int ar[1000002], br[1000002], xr[1000002];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     string s;     cin >> s >> a >> b;     n = s.size();     p = 1;     for (long long int i = n - 1; i >= 0; i--) {       xr[i] = ((s[i] -  0 ) * p + xr[i + 1]) % b;       p = (p * 10) % b;     }     xr[n] = 1;     p = 0;     for (long long int i = 0; i <= n - 2; i++) {       p = (p * 10 + s[i] -  0 ) % a;       if (p == 0 and xr[i + 1] == 0 and s[i + 1] !=  0 ) {         cout <<  YES ;         cout << endl;         cout << s.substr(0, i + 1);         cout << endl;         cout << s.substr(i + 1, n - i - 1);         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unrolled-loops )   int n, m, b, w, color[200010], ok[200010];   vector<int> a[200010];   void dfs(int u, int c) {     color[u] = c;     ok[u] = 1;     b += (c == 0);     w += (c == 1);     for (int i = 0; i < a[u].size(); i++)       if (!ok[a[u][i]]) dfs(a[u][i], 1 - c);   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       a[i].clear();       color[i] = 0;       ok[i] = 0;     }     int u, v;     for (int i = 0; i < m; i++) {       cin >> u >> v;       a[u].push_back(v);       a[v].push_back(u);     }     b = 0;     w = 0;     dfs(1, 0);     cout << min(b, w) <<   n ;     if (b < w)       for (int i = 1; i <= n; i++) {         if (!color[i]) cout << i <<    ;       }     else       for (int i = 1; i <= n; i++) {         if (color[i]) cout << i <<    ;       }     cout <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   inline int Get() {     int res = 0, q = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return res * q;   }   const double eps = 1e-12, pi = M_PI;   const int oo = (int)2e9, mod = (int)1e9 + 7;   const long long INF = (long long)1e17;   int T;   long long a, n, p, h;   long long Calc(long long a, long long n, long long p) {     long long rd = a * n / p;     if (!rd) return ((a) > (p - a * n) ? (a) : (p - a * n));     long long dt = a * n % p, st = p - p % a - a;     if (dt < st) --rd;     return Calc(min(a - p % a, p % a), rd, a);   }   int main() {     for (scanf( %d                   n ,                &T);          T--;) {       scanf(            %I64d             %I64d             %I64d             %I64d              n ,           &a, &n, &p, &h),           a %= p;       if (a * n < p)         printf( %s n , a <= h ?  YES  :  NO );       else         printf( %s n , Calc(a, n, p) <= h ?  YES  :  NO );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int mex(set<int> s) {     int v = 0;     while (s.count(v) > 0) v++;     return v;   }   int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,  4,  5,  5,  5,  5, 5, 5,             6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,  7,  8,  8,  8,  8, 8, 8,             8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10};   const int MAXN = 1000007;   int s[MAXN];   map<pair<int, long long>, int> dp;   int grundy(pair<int, long long> s) {     if (dp.find(s) != dp.end()) return dp[s];     long long mask = s.second;     int &res = dp[s];     set<int> S;     for (int i = 1; i <= 60; i++) {       if (!(mask & (1ll << i)) && s.first >= i) {         S.insert(grundy(make_pair(s.first - i, (mask | (1ll << i)))));       }     }     while (S.count(res) > 0) res++;     return res;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);     }     if (n == 1)       printf( NO n );     else {       int XOR = 0;       for (int i = 0; i < n; i++) {         XOR ^= grundy(make_pair(s[i], 0));       }       if (XOR == 0)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long L, v, l, r;       cin >> L >> v >> l >> r;       long long tot = L / v;       long long minus = r / v;       minus -= (l - 1) / v;       cout << tot - minus <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000];   int ans[1000000];   int cnt;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ans[a[i]]++;     }     for (int j = 1; j <= n; j++)       if (ans[j] == 0) cnt++;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct habijabi {     long int start_time, end_time;   } work[500500];   bool cmp(habijabi a, habijabi b) {     if (a.end_time == b.end_time) {       return a.start_time < b.start_time;     }     return a.end_time < b.end_time;   }   int main() {     long int t, n, i, j;     scanf( %ld , &n);     for (i = 0; i < n; i++) {       scanf( %ld %ld , &work[i].start_time, &work[i].end_time);     }     sort(work, work + n, cmp);     int ans = 0, prev_end = -1;     for (i = 0; i < n; i++) {       if (work[i].start_time > prev_end) {         ans++;         prev_end = work[i].end_time;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   using namespace std;   int v[5005];   int main() {     int t1;     cin >> t1;     for (int t = 1; t <= t1; t++) {       int n, d;       cin >> n >> d;       memset(v, 0, sizeof(v));       int l = 1, nr = n - 1;       v[0] = 1;       for (; nr >= v[l - 1] * 2; l++) {         v[l] = v[l - 1] * 2;         d -= v[l] * l;         nr -= v[l];       }       if (nr == 0)         l--;       else         d -= nr * l, v[l] = nr;       if (d < 0) {         cout <<  NO n ;         continue;       }       int l2;       for (l2 = l; d > 0 && l >= 1; l--) {         if (v[l] == 1) continue;         if (l2 + 1 - l > d) {           v[l]--;           v[l + d]++;           d = 0;           break;         }         v[++l2] = 1;         d -= l2 - l;         v[l]--;         l++;       }       if (d == 0) {         cout <<  YES n ;         queue<int> p[5005];         p[0].push(1);         p[0].push(1);         for (int i = 1, node = 2; i <= l2; i++)           if (v[i] > 0) {             cout << p[i - 1].front() <<    ;             p[i - 1].pop();             p[i].push(node);             p[i].push(node);             v[i--]--;             node++;           }         cout <<   n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, i, j, n, mx, p, b[1001], m;     cin >> n >> m;     for (i = 1; i <= 1000; i++) b[i] = 0;     for (i = 1; i <= m; i++) {       mx = -1;       p = -1;       for (j = 1; j <= n; j++) {         cin >> a;         if (a > mx) {           mx = a;           p = j;         }       }       b[p]++;     }     int bmax = b[1], pmax = 1;     for (i = 2; i <= 1000; i++)       if (b[i] > bmax) {         bmax = b[i];         pmax = i;       }     cout << pmax;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   bool solve(int, int);   bool trySolve(int, int);   bool trySolve(int w, int m) { return (m % w == 0 && solve(w, m / w)); }   bool solve(int w, int m) {     return (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) ||             trySolve(w, m + 1));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int w, m;     cin >> w >> m;     if (w == 2 || w == 3)       cout <<  YES ;     else {       if (solve(w, m))         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int c, d, x, y, a, b;     cin >> a >> b >> x >> y >> c >> d;     if (c == 0 and d == 0) {       if ((a == x and b == y) or (a == -x and b == -y) or (a == y and b == -x) or           (a == -y and b == x))         cout <<  YES  << endl;       else         cout <<  NO  << endl;       return 0;     }     bool possible = false;     long long int X = x, Y = y;     if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and         (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0)       possible = true;     x = -Y, y = X;     if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and         (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0)       possible = true;     x = -X, y = -Y;     if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and         (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0)       possible = true;     x = Y, y = -X;     if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and         (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0)       possible = true;     if (possible)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int chkmax(T& a, T b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   template <class T>   int chkmin(T& a, T b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   template <class iterator>   void output(iterator begin, iterator end, ostream& out = cerr) {     while (begin != end) {       out << (*begin) <<    ;       begin++;     }     out << endl;   }   template <class T>   void output(T x, ostream& out = cerr) {     output(x.begin(), x.end(), out);   }   void fast_io() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int INF = 1e9;   const int N = 26;   const int A = 5e4 + 10;   vector<int> value;   int p[N][A * N];   signed main() {     fast_io();     int n;     cin >> n;     for (int i = 0; i < 2 * n; ++i) {       int x;       cin >> x;       value.push_back(x);     }     sort(value.begin(), value.end());     int sum = 0;     for (int i = 2; i < 2 * n; ++i) {       sum += value[i];     }     for (int i = 0; i < N; ++i) {       for (int j = 0; j < A * N; ++j) {         p[i][j] = -1;       }     }     p[0][0] = -2;     for (int i = 2; i < value.size(); ++i) {       int cur = value[i];       for (int j = n - 1; j > 0; --j) {         for (int x = cur; x < A * N; ++x) {           if (p[j - 1][x - cur] != -1 && p[j][x] == -1) {             p[j][x] = i;           }         }       }     }     int best = INF;     for (int i = 0; i < N * A; ++i) {       if (abs(i - (sum - i)) < abs(best - (sum - best)) && p[n - 1][i] != -1) {         best = i;       }     }     vector<int> type(2 * n);     type[1] = 1;     for (int i = n - 1; i > 0; --i) {       type[p[i][best]] = 1;       best -= value[p[i][best]];     }     vector<vector<int> > ans(2);     for (int i = 0; i < 2 * n; ++i) {       ans[type[i]].push_back(value[i]);     }     sort(ans[0].begin(), ans[0].end());     sort(ans[1].rbegin(), ans[1].rend());     for (auto v : ans) {       for (auto x : v) {         cout << x <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int sum = accumulate(a.begin(), a.end(), 0);     vector<vector<int>> dp(n + 1, vector<int>(2, -1));     function<int(int, int)> solve = [&](int idx, int cur) {       if (idx == n) return 0;       if (dp[idx][cur] != -1) return dp[idx][cur];       int res = 0;       if (cur == 0)         res = max(a[idx] + solve(idx + 1, !cur), solve(idx + 1, cur));       else         res = min(solve(idx + 1, !cur), a[idx] + solve(idx + 1, cur));       return dp[idx][cur] = res;     };     int ans = solve(0, 0);     cout << sum - ans <<     << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 3e5 + 42;   int n, m;   struct edge {     int u, v, c;   };   edge inp[nmax];   edge make_edge(int u, int v, int c) {     edge x;     x.u = u;     x.v = v;     x.c = c;     return x;   }   bool cmp(edge a, edge b) { return a.c < b.c; }   int ans[nmax], new_values[nmax];   int main() {     cin >> n >> m;     int a, b, c;     for (int i = 1; i <= m; i++) {       scanf( %i%i%i , &a, &b, &c);       inp[i] = make_edge(a, b, c);     }     sort(inp + 1, inp + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int j = i + 1;       while (j <= m && inp[i].c == inp[j].c) j++;       for (int k = i; k < j; k++) {         new_values[inp[k].v] = max(new_values[inp[k].v], ans[inp[k].u] + 1);       }       for (int k = i; k < j; k++) {         ans[inp[k].v] = new_values[inp[k].v];       }       i = j - 1;     }     int outp = 0;     for (int i = 1; i <= n; i++) outp = max(outp, ans[i]);     cout << outp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 28;   int x[24 + 2], y[24 + 2];   int dist[24 + 2][24 + 2];   int dp[(1 << 24) + 2];   int nxt[(1 << 24) + 2];   int n;   int sqr_dis(int a, int b) {     return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);   }   int solve(int mask) {     if (!mask) return 0;     int &ret = dp[mask];     if (ret != -1) return ret;     int i, j, k;     ret = inf;     for (i = 0; i < n; i++)       if (mask & (1 << i)) {         for (j = 0; j < n; j++)           if (mask & (1 << j)) {             k = dist[0][i + 1] + dist[i + 1][j + 1] + dist[j + 1][0] +                 solve((mask & ~(1 << i)) & ~(1 << j));             if (k < ret) {               ret = k;               nxt[mask] = (1 << i) | (1 << j);             }           }         break;       }     return ret;   }   int main() {     int i, j, k;     scanf( %d %d %d , &x[0], &y[0], &n);     for (i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) dist[i][j] = dist[j][i] = sqr_dis(i, j);     k = 1 << n;     for (i = 0; i < k; i++) dp[i] = -1;     printf( %d n , solve(k - 1));     printf( 0 );     k--;     while (k) {       for (i = 0; i < n; i++)         if (nxt[k] & (1 << i)) printf(  %d , i + 1);       printf(  0 );       k ^= nxt[k];     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[1000], dp[1000][10];   int solve(int i, int flag) {     if (i >= n) return 0;     if (dp[i][flag] != -1) return dp[i][flag];     if (arr[i] == 0)       dp[i][flag] = 1 + solve(i + 1, 0);     else if (arr[i] == 1) {       if (flag == 0 || flag == 1) {         dp[i][flag] = min(solve(i + 1, 2), 1 + solve(i + 1, 0));       } else         dp[i][flag] = 1 + solve(i + 1, 0);     } else if (arr[i] == 2) {       if (flag == 0 || flag == 2) {         dp[i][flag] = min(1 + solve(i + 1, 0), solve(i + 1, 1));       } else         dp[i][flag] = 1 + solve(i + 1, 0);     } else {       if (flag == 0) {         dp[i][flag] =             min(solve(i + 1, 2), min(1 + solve(i + 1, 0), solve(i + 1, 1)));       } else if (flag == 1) {         dp[i][flag] = min(solve(i + 1, 2), 1 + solve(i + 1, 0));       } else {         dp[i][flag] = min(solve(i + 1, 1), 1 + solve(i + 1, 0));       }     }     return dp[i][flag];   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     memset(dp, -1, sizeof(dp));     cout << solve(0, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void hike() {     int64_t n;     cin >> n;     string s, t;     cin >> s >> t;     vector<int64_t> f;     for (int64_t i = 0; i < n; ++i) {       if (s[i] != t[i]) {         f.push_back(i);       }     }     if (f.size() != 2) {       cout <<  No n ;       return;     }     char x1 = s[f[0]], y1 = t[f[0]];     char x2 = s[f[1]], y2 = t[f[1]];     s[f[0]] = y2;     t[f[1]] = x1;     if (s == t) {       cout <<  Yes n ;       return;     }     s[f[0]] = x1;     t[f[1]] = y2;     s[f[1]] = y1;     t[f[0]] = x2;     if (s == t) {       cout <<  Yes n ;       return;     }     cout <<  No n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int64_t t = 1;     cin >> t;     while (t--) hike();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   const int infinity = (int)1e9 + 42;   const int64_t llInfinity = (int64_t)1e18 + 256;   const int module = (int)1e9 + 7;   const long double eps = 1e-8;   mt19937_64 randGen(system_clock().now().time_since_epoch().count());   inline void raiseError(string errorCode) {     cerr <<  Error :   << errorCode << endl;     exit(42);   }   struct Treap {     int x, y;     int size;     int64_t sum;     Treap *l, *r;     Treap(int x) : x(x), y(randGen()), size(1), sum(x), l(nullptr), r(nullptr) {}     ~Treap() {       if (l != nullptr) {         delete l;       }       if (r != nullptr) {         delete r;       }     }   };   typedef Treap* pTreap;   inline int getSize(pTreap t) { return (t != nullptr) ? t->size : 0; }   inline int64_t getSum(pTreap t) { return (t != nullptr) ? t->sum : 0; }   inline void update(pTreap t) {     if (t != nullptr) {       t->size = getSize(t->l) + 1 + getSize(t->r);       t->sum = getSum(t->l) + t->x + getSum(t->r);     }   }   inline void split(pTreap t, pTreap& l, pTreap& r, int x) {     if (t == nullptr) {       l = r = nullptr;     } else if (x <= t->x) {       split(t->l, l, t->l, x);       r = t;     } else {       split(t->r, t->r, r, x);       l = t;     }     update(l);     update(r);   }   inline void splitSize(pTreap t, pTreap& l, pTreap& r, int count) {     if (t == nullptr) {       l = r = nullptr;     } else if (count <= getSize(t->l)) {       splitSize(t->l, l, t->l, count);       r = t;     } else {       splitSize(t->r, t->r, r, count - getSize(t->l) - 1);       l = t;     }     update(l);     update(r);   }   void merge(pTreap& t, pTreap l, pTreap r) {     if (l == nullptr || r == nullptr) {       t = (l != nullptr) ? l : r;     } else if (l->y > r->y) {       merge(l->r, l->r, r);       t = l;     } else {       merge(r->l, l, r->l);       t = r;     }     update(t);   }   inline void insert(pTreap& t, pTreap it) {     if (t == nullptr) {       t = it;     } else if (it->y > t->y) {       split(t, it->l, it->r, it->x);       t = it;     } else if (it->x <= t->x) {       insert(t->l, it);     } else {       insert(t->r, it);     }     update(t);   }   inline void erase(pTreap& t, int x) {     if (t != nullptr) {       if (x == t->x) {         pTreap oldT = t;         merge(t, t->l, t->r);         oldT->l = oldT->r = nullptr;         delete oldT;       } else if (x < t->x) {         erase(t->l, x);       } else {         erase(t->r, x);       }     }     update(t);   }   inline void unite(pTreap& t, pTreap l, pTreap r) {     if (l == nullptr || r == nullptr) {       t = (l != nullptr) ? l : r;     } else {       if (r->y > l->y) {         swap(l, r);       }       pTreap rl, rr;       split(r, rl, rr, l->x);       unite(l->l, l->l, rl);       unite(l->r, l->r, rr);       t = l;     }     update(t);   }   void outItem(pTreap t) { cout << t->x <<    ; }   void out(pTreap t) {     if (t != nullptr) {       out(t->l);       outItem(t);       out(t->r);     }   }   pTreap nthElement(pTreap t, int n) {     if (t == nullptr) {       return nullptr;     } else if (n == getSize(t->l)) {       return t;     } else if (n < getSize(t->l)) {       return nthElement(t->l, n);     } else {       return nthElement(t->r, n - getSize(t->l) - 1);     }   }   pTreap find(pTreap t, int x) {     if (t == nullptr) {       return nullptr;     } else if (x == t->x) {       return t;     } else if (x < t->x) {       return find(t->l, x);     } else {       return find(t->r, x);     }   }   signed main() {     ios_base::sync_with_stdio(false);     int64_t n, m;     cin >> n >> m;     vector<int64_t> l(n);     for (int64_t i = 1; i < n; i++) {       cin >> l[i];     }     vector<pair<int64_t, int64_t> > q(m);     for (int64_t i = 0; i < m; i++) {       cin >> q[i].first >> q[i].second;       q[i].first--;     }     vector<vector<pair<int64_t, int64_t> > > sumByLen(n);     for (int64_t i = 0; i < m; i++) {       int64_t v = q[i].first;       int64_t rng = q[i].second;       int64_t len = 0;       sumByLen[v].emplace_back(rng, -1);       while (v != 0) {         int64_t p = (v - 1) / 2;         len += l[v];         int64_t pL = p * 2 + 1, pR = p * 2 + 2;         int64_t q = -1;         if (pL < n && pL != v) {           q = pL;         } else if (pR < n && pR != v) {           q = pR;         }         if (q >= 0) {           sumByLen[q].emplace_back(rng - len - l[q], -1);         }         v = p;       }     }     for (int64_t i = 0; i < n; i++) {       sort(sumByLen[i].begin(), sumByLen[i].end());     }     function<pTreap(int64_t, int64_t)> dfs = [&](int64_t v, int64_t fUp) {       pTreap p = new Treap(fUp);       for (int64_t i = 1; i <= 2; i++) {         if (v * 2 + i < n) {           pTreap add = dfs(v * 2 + i, fUp + l[v * 2 + i]);           unite(p, p, add);         }       }       vector<pTreap> pieces;       pieces.reserve(sumByLen[v].size());       int64_t cumSize = 0, cumSum = 0;       for (auto& it : sumByLen[v]) {         int64_t val = it.first + fUp;         int64_t& res = it.second;         pieces.push_back(nullptr);         split(p, pieces.back(), p, val);         cumSize += getSize(pieces.back());         cumSum += getSum(pieces.back());         res = (int64_t)val * cumSize - cumSum;       }       pTreap q = nullptr;       for (auto it : pieces) {         merge(q, q, it);       }       merge(q, q, p);       return q;     };     dfs(0, 0);     vector<int64_t> answers(m);     for (int64_t i = 0; i < m; i++) {       int64_t v = q[i].first;       int64_t rng = q[i].second;       int64_t len = 0;       answers[i] += lower_bound(sumByLen[v].begin(), sumByLen[v].end(),                                 make_pair(rng, (int64_t)-1))                         ->second;       while (v != 0) {         int64_t p = (v - 1) / 2;         len += l[v];         if (rng >= len) {           answers[i] += rng - len;         }         int64_t pL = p * 2 + 1, pR = p * 2 + 2;         int64_t q = -1;         if (pL < n && pL != v) {           q = pL;         } else if (pR < n && pR != v) {           q = pR;         }         if (q >= 0) {           answers[i] += lower_bound(sumByLen[q].begin(), sumByLen[q].end(),                                     make_pair(rng - len - l[q], (int64_t)-1))                             ->second;         }         v = p;       }       cout << answers[i] << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long int v[N];   inline void outv(vector<long long int> v) {     for (long long int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   inline long long int pow(long long int x, long long int n) {     long long int ans = 1;     while (n > 0) {       if (n & 1) ans *= x;       x *= x;       n >>= 1;     }     return ans;   }   int solve() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     string n;     cin >> n;     int even = 0;     int s = 0;     int z = 0;     for (auto c : n) {       if ((c) % 2 == 0) even++;       s += c -  0 ;       if (c ==  0 ) z++;     }     if (s % 3 == 0 && even > 1 && z > 0) return cout <<  red  <<   n , 0;     ;     return cout <<  cyan  <<   n , 0;     ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k;     scanf( %d %d , &n, &k);     switch (k) {       case 1:         printf( -1 n );         break;       case 2:         if (n < 5) {           printf( -1 n );           break;         }         printf( %d n , n - 1);         for (int i = 1; i < n; i++) printf( %d %d n , i, i + 1);         break;       case 3:         if (n < 4) {           printf( -1 n );           break;         }         printf( %d n1 2 n2 3 n , n - 1);         for (int i = 4; i <= n; i++) printf( 3 %d n , i);         break;       default:         printf( -1 n );         break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int MAX = 1000 * 100 + 47;   long long A[MAX];   long long P[MAX];   long long Q[MAX];   long long R[MAX];   int main() {     int n;     long long p, q, r;     cin >> n >> p >> q >> r;     for (int i = (0); i < (n); i++) cin >> A[i];     for (int i = (0); i < (n); i++) {       P[i] = p * A[i];       if (i) P[i] = max(P[i], P[i - 1]);       Q[i] = P[i] + q * A[i];       if (i) Q[i] = max(Q[i], Q[i - 1]);       R[i] = Q[i] + r * A[i];       if (i) R[i] = max(R[i], R[i - 1]);     }     cout << R[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist(double a, double b, double c, double d) {     return sqrt((a - c) * (a - c) + (b - d) * (b - d));   }   int main() {     double x, y, r, a, b, c, d;     cin >> x >> y >> r >> a >> b >> c;     d = dist(x, y, a, b);     if (d - r - c > 0)       printf( %.9lf n , (d - r - c) / 2);     else {       if (d >= abs(r - c) && d <= r + c)         printf( 0.000000000000 n );       else {         if (r > c)           printf( %.9lf n , (r - (d + c)) / 2);         else           printf( %.9lf n , (c - (d + r)) / 2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(const T &a) {     return a * a;   }   int x, k, timer, n[3], t[3], y[3], head[3], tail[3];   pair<int, int> z[3][100000];   int main() {     scanf( %d%d%d%d%d%d%d , &k, &n[0], &n[1], &n[2], &t[0], &t[1], &t[2]);     while (1) {       timer++;       if (timer >= t[0] + t[1] + t[2]) {         for (int i = 0; i < (int)3; i++)           if (z[i][tail[i]].first == timer)             y[i] -= z[i][tail[i]].second, tail[i]++;         x = min(n[2] - y[2], min(n[1] - y[1], n[0] - y[0]));         if (x) {           k -= x;           y[2] += x, y[1] += x, y[0] += x;           z[0][head[0]++] = make_pair(timer + t[0], x);           z[1][head[1]++] = make_pair(timer + t[1], x);           z[2][head[2]++] = make_pair(timer + t[2], x);         }         if (k <= 0) {           printf( %d n , timer);           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 55;   const int MAXM = 105;   const int inf = 0x3f3f3f3fLL;   struct NODE {     long long a, b;     int c, id;   };   struct ANS {     int prei, prej, prek;     long long val;     ANS() {}     ANS(int _i, int _j, int _k, long long _val)         : prei(_i), prej(_j), prek(_k), val(_val) {}   };   NODE a[MAXN];   long long d[MAXN][MAXN][MAXM];   ANS pre[MAXN][MAXN][MAXM];   bool cmp(NODE a, NODE b) { return a.c < b.c; }   void update(int i, int j, int k, int x, int y, int z, long long val) {     if (j == y) {       j = y;     }     if (d[i][j][k] == -1 || d[i][j][k] < d[x][y][z] + val) {       d[i][j][k] = d[x][y][z] + val;       pre[i][j][k] = ANS(x, y, z, val);     }   }   void printans(int i, int j, int k) {     if (i == 0) return;     printans(i - 1, pre[i][j][k].prej, pre[i][j][k].prek);     printf( %d %I64d n , a[j].id, pre[i][j][k].val);   }   void solved(int cas) {     int n, m;     long long K;     scanf( %d %d %I64d , &m, &n, &K);     for (int i = 1; i <= n; i++) {       scanf( %I64d %I64d %d , &a[i].a, &a[i].b, &a[i].c);       a[i].id = i;     }     sort(a + 1, a + n + 1, cmp);     memset(d, -1, sizeof(d));     a[0].a = a[0].b = 0;     for (int i = 1; i <= n; i++)       for (long long j = a[i].a; j <= a[i].b; j++) {         d[1][i][j - a[i].a] = j;         pre[1][i][j - a[i].a] = ANS(0, -1, -1, j);       }     for (int i = 1; i < m; i++) {       for (int j = i; j <= n; j++) {         for (int k = 0; k <= a[j].b - a[j].a; k++) {           if (d[i][j][k] == -1) continue;           long long lastnum = a[j].a + k;           for (int l = j + 1; l <= n; l++) {             if (a[l].c == a[j].c) continue;             long long temp = lastnum + K;             if (temp >= a[l].a && temp <= a[l].b)               update(i + 1, l, temp - a[l].a, i, j, k, temp);             temp = lastnum * K;             if (temp >= a[l].a && temp <= a[l].b)               update(i + 1, l, temp - a[l].a, i, j, k, temp);           }         }       }     }     long long ans = -1;     int ansi, ansj;     for (int i = m; i <= n; i++)       for (int j = 0; j <= 100; j++) {         if (d[m][i][j] > ans) {           ans = d[m][i][j];           ansi = i;           ansj = j;         }       }     if (ans == -1)       printf( NO n );     else {       printf( YES n );       printans(m, ansi, ansj);     }   }   int main() {     int nT = 1;     for (int i = 1; i <= nT; i++) solved(i);   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1.0L);   signed main() {     long long n;     cin >> n;     long double x[n], y[n];     for (long long i = (0); i < (n); ++i) cin >> x[i] >> y[i];     long long ans = 0;     for (long long i = (0); i < (n); ++i) {       vector<long double> v;       for (long long j = (0); j < (n); ++j)         if (j != i) {           v.push_back(atan2(y[j] - y[i], x[j] - x[i]));         }       sort(v.begin(), v.end());       long long f[n - 1], s[n - 1];       long long k = 0;       for (long long j = (0); j < (n - 1); ++j) {         while (k < n - 1 && v[k] < v[j] + pi) ++k;         f[j] = k;         s[j] = (j ? s[j - 1] : 0) + f[j];       }       for (long long j = (0); j < (n - 1); ++j) {         ans += (s[f[j] - 1] - s[j]) - (f[j]) * (f[j] - j - 1);       }     }     cout << ans * (n - 4) / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 0, s = 0;     char c = getchar();     while (c >  9  || c <  0 ) f = (c ==  - ), c = getchar();     while (c >=  0  && c <=  9 )       s = (s << 3) + (s << 1) + (c ^  0 ), c = getchar();     return f ? -s : s;   }   long long n, m, k;   vector<long long> ch[200005];   vector<long long> he[200005];   long long it1, it2;   long long t1, t2;   long long sx, sy, sfx;   long long tx, ty, tfx;   long long nx, ny;   char cc[5];   long long ans = 0;   bool flag = 0;   inline long long ne(long long op, long long t, long long x) {     if (op == 1)       return ch[t][upper_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin()];     else       return he[t][upper_bound(he[t].begin(), he[t].end(), x) - he[t].begin()];   }   inline long long ft(long long op, long long t, long long x) {     if (op == 1)       return ch[t]                [lower_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin() - 1];     else       return he[t]                [lower_bound(he[t].begin(), he[t].end(), x) - he[t].begin() - 1];   }   inline long long fd(long long op, long long t, long long x) {     if (op == 1) {       long long tt = lower_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin();       if (tt >= ch[t].size()) return -1;       if (ch[t][tt] == x)         return tt;       else         return -1;     } else {       long long tt = lower_bound(he[t].begin(), he[t].end(), x) - he[t].begin();       if (tt >= he[t].size()) return -1;       if (he[t][tt] == x)         return tt;       else         return -1;     }   }   bool ff = 1, fff = 1;   int main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= k; i++) {       t1 = read();       t2 = read();       ch[t2 - t1 + n + 1].push_back(t1);       he[t1 + t2].push_back(t1);     }     for (int i = 0; i <= n + 1; i++) {       ch[m + 1 - i + n + 1].push_back(i);       he[m + 1 + i].push_back(i);       ch[-i + n + 1].push_back(i);       he[i].push_back(i);     }     for (int i = 0; i <= m + 1; i++) {       ch[i + n + 1].push_back(0);       he[i].push_back(0);       ch[i - n - 1 + n + 1].push_back(n + 1);       he[n + 1 + i].push_back(n + 1);     }     for (int i = 0; i <= n + m + 2; i++) sort(he[i].begin(), he[i].end());     for (int i = 0; i <= m + n + 2; i++) sort(ch[i].begin(), ch[i].end());     sx = read();     sy = read();     scanf( %s , cc);     if (cc[0] ==  N ) {       if (cc[1] ==  E )         sfx = 0;       else         sfx = 1;     } else {       if (cc[1] ==  E )         sfx = 2;       else         sfx = 3;     }     tx = sx;     ty = sy;     tfx = sfx;     sx = sy = sfx = -1;     while (tx != sx || ty != sy || tfx != sfx || fff) {       if (fff && tx == sx && ty == sy && tfx == sfx) fff = 0;       if (tfx == 0) {         nx = ne(2, tx + ty, tx);         ny = tx + ty - nx;         ans += nx - tx;         it1 = fd(2, tx + ty - 1, nx - 1);         it2 = fd(2, tx + ty + 1, nx);         if (it1 != -1 && it2 != -1) {           tfx = 3;           tx = nx - 1;           ty = ny + 1;           flag = 1;         } else if (it1 != -1) {           tfx = 2;           tx = nx;           ty = ny + 1;         } else if (it2 != -1) {           tfx = 1;           tx = nx - 1;           ty = ny;         } else {           tfx = 3;           tx = nx - 1;           ty = ny + 1;           flag = 1;         }       } else if (tfx == 3) {         nx = ft(2, tx + ty, tx);         ny = tx + ty - nx;         ans += tx - nx;         it1 = fd(2, tx + ty - 1, nx);         it2 = fd(2, tx + ty + 1, nx + 1);         if (it1 != -1 && it2 != -1) {           tfx = 0;           tx = nx + 1;           ty = ny - 1;           flag = 1;         } else if (it1 != -1) {           tfx = 2;           tx = nx + 1;           ty = ny;         } else if (it2 != -1) {           tfx = 1;           tx = nx;           ty = ny - 1;         } else {           tfx = 0;           tx = nx + 1;           ty = ny - 1;           flag = 1;         }       } else if (tfx == 2) {         nx = ne(1, ty - tx + n + 1, tx);         ny = ty - tx + nx;         ans += nx - tx;         it1 = fd(1, ty - tx + n + 1 - 1, nx);         it2 = fd(1, ty - tx + n + 1 + 1, nx - 1);         if (it1 != -1 && it2 != -1) {           tfx = 1;           tx = nx - 1;           ty = ny - 1;           flag = 1;         } else if (it1 != -1) {           tfx = 3;           tx = nx - 1;           ty = ny;         } else if (it2 != -1) {           tfx = 0;           tx = nx;           ty = ny - 1;         } else {           tfx = 1;           tx = nx - 1;           ty = ny - 1;           flag = 1;         }       } else if (tfx == 1) {         nx = ft(1, ty - tx + n + 1, tx);         ny = ty - tx + nx;         ans += tx - nx;         it1 = fd(1, ty - tx + n + 1 - 1, nx + 1);         it2 = fd(1, ty - tx + n + 1 + 1, nx);         if (it1 != -1 && it2 != -1) {           tfx = 2;           tx = nx + 1;           ty = ny + 1;           flag = 1;         } else if (it1 != -1) {           tfx = 3;           tx = nx;           ty = ny + 1;         } else if (it2 != -1) {           tfx = 0;           tx = nx + 1;           ty = ny;         } else {           tfx = 2;           tx = nx + 1;           ty = ny + 1;           flag = 1;         }       }       if (ff) {         sx = tx;         sy = ty;         sfx = tfx;         ff = 0;         ans = 0;       }     }     while (tx != sx || ty != sy || tfx != sfx)       ;     if (flag)       printf( %lld , ans / 2);     else       printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   long long n, k, sum;   long long a[maxn];   long long goal[maxn];   long long max(long long x, long long y) { return x > y ? x : y; }   long long cntmx = -9e18, cntmn = 9e18;   void solve3() {     long long m = k;     for (register int i = n; i >= 1; --i) {       if (m >= (n - i + 1) * (a[i] - a[i - 1])) {         m -= (n - i + 1) * (a[i] - a[i - 1]);       } else {         cntmn = a[i] - m / (n - i + 1);         break;       }     }     if (cntmn == 9e18) cntmn = a[1] - m / n;     m = k;     for (register int i = 1; i <= n; ++i) {       if (m >= i * (a[i + 1] - a[i])) {         m -= i * (a[i + 1] - a[i]);       } else {         cntmx = a[i] + m / i;         break;       }     }     if (cntmx == -9e18) cntmx = a[n] + m;     if (cntmn - cntmx <= 0) {       if (sum % n == 0)         printf( 0 n );       else         printf( 1 n );     } else       printf( %lld n , max(0LL, cntmn - cntmx));   }   int main() {     scanf( %lld%lld , &n, &k);     for (register int i = 1; i <= n; ++i) scanf( %lld , &a[i]), sum += a[i];     sort(a + 1, a + n + 1);     solve3();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     char mi, ma;     int max = 0, min = INT_MAX;     pair<int, char> p[4];     for (int i = 0; i < 4; ++i) {       cin >> s;       p[i].first = s.length() - 2;       p[i].second = s[0];     }     sort(p, p + 4);     int flag1 = 0, flag2 = 0;     for (int j = 1; j < 4; ++j) {       if (2 * (p[0].first) <= p[j].first) flag1 += 1;     }     for (int j = 0; j < 3; ++j) {       if (p[3].first >= 2 * (p[j].first)) flag2 += 1;     }     if (flag1 == 3 && flag2 != 3)       cout << p[0].second <<   n ;     else if (flag2 == 3 && flag1 != 3)       cout << p[3].second <<   n ;     else       cout <<  C n ;     return 0;   }


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


#include <bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   using namespace std;   // using namespace __gnu_pbds;   #define lli long long int   #define llu unsigned long long int   #define pb push_back   #define rt return 0   #define endln   n    #define all(x) x.begin(), x.end()   #define sz(x) (lli)(x.size())   #define len(x) (lli)(x.length())   const lli MOD = 1e9 + 7;   const double PI = 2 * acos(0.0);   // cout << fixed << setprecision(0) << pi <<endl;   // typedef tree<int, null_type, less<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // for multiset   // typedef tree<int, null_type, less_equal<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // order_of_key(val): returns the number of values less than val   // find_by_order(k): returns an iterator to the kth largest element (0-based)      void solve() {       lli n, a;       cin >> n;       vector<lli> v;       for (lli i = 0; i < n; i++) {           cin >> a;           v.pb(a);       }          for (lli i = 0; i < n; i++) {           lli tmp = v[i], ind = 0, one;           while (tmp > 0) {               if (tmp % 2 == 1) {                   one = ind;               }               tmp /= 2;               ind++;           }              lli p = pow(2, one);           cout << p <<    ;       }       cout << endl;   }      int main(void) {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       lli t;       cin >> t;       while (t--)           solve();       rt;   }


#include <bits/stdc++.h>   using namespace std;   const int Max_N = 1E6 + 10;   int n, m, ans = 1, p[Max_N], color[Max_N];   vector<int> chil[Max_N];   bool mark[Max_N];   int dfs(int i) {     int res = 0;     mark[i] = true;     for (int u : chil[i])       if (!mark[u] && color[i] != color[u]) ++res;     return res;   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> p[i];       p[i]--;       chil[p[i]].push_back(i);     }     for (int i = 0; i < n; i++) cin >> color[i];     for (int i = 0; i < n; i++)       if (!mark[i]) ans += dfs(i);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const int MAXK = 1000010;   int n, m, k, p, a[N][N], row[N], col[N];   long long ans1[MAXK], ans2[MAXK];   multiset<long long> Unis;   void solve(long long *ans, int n, int *a, int dta) {     Unis.clear();     for (int i = 1; i <= n; ++i) {       Unis.insert(-a[i]);     }     long long now = 0;     for (int kk = 1; kk <= k; ++kk) {       long long val = *Unis.begin();       now += val;       Unis.erase(Unis.begin());       Unis.insert(val + dta);       ans[kk] = -now;     }   }   int main() {     scanf( %d %d %d %d , &n, &m, &k, &p);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         scanf( %d , &a[i][j]);         row[i] += a[i][j];         col[j] += a[i][j];       }     solve(ans1, n, row, p * m);     solve(ans2, m, col, p * n);     long long zans = -1e18;     for (int i = 0; i <= k; ++i) {       zans = max(zans, ans1[i] + ans2[k - i] - (long long)i * (k - i) * p);     }     cout << zans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int c, hi, hb, wi, wb;   inline long long f(int x) {     long long k1 = x;     long long k2 = 1ll * (0ll + c - 1ll * x * wi) / wb;     return k1 * hi + k2 * hb;   }   int main() {     cin >> c >> hi >> hb >> wi >> wb;     int kek1 = c / wi;     int l = 0;     int r = kek1;     long long ans = 0;     ans = max(ans, f(0));     ans = max(ans, f(kek1));     for (int i = 0; i <= 10000000; ++i)       if (i <= kek1) ans = max(ans, f(i));     while (r - l > 1) {       int m = (r - l + 1) / 3;       int k1 = l + m;       int k2 = r - m;       if (f(k1) > f(k2))         r = k2;       else         l = k1;     }     for (int i = l - 9000000; i <= r + 9000000; ++i)       if (i >= 0 && i <= kek1) ans = max(ans, f(i));     swap(wi, wb);     swap(hi, hb);     kek1 = c / wi;     l = 0;     r = kek1;     for (int i = 0; i <= 10000000; ++i)       if (i <= kek1) ans = max(ans, f(i));     while (r - l > 1) {       int m = (r - l + 1) / 3;       int k1 = l + m;       int k2 = r - m;       if (f(k1) > f(k2))         r = k2;       else         l = k1;     }     for (int i = l - 9000000; i <= r + 9000000; ++i)       if (i >= 0 && i <= kek1) ans = max(ans, f(i));     ans = max(ans, f(0));     ans = max(ans, f(kek1));     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[101000], tmp;   struct C {     int b, p;   } c[101000];   long long ans = 0, tot;   bool cmp(C c1, C c2) { return c1.b < c2.b; }   priority_queue<int, vector<int>, greater<int> > q;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) scanf( %d , &c[i].b);     for (int i = 1; i <= m; i++) scanf( %d , &c[i].p);     sort(c + 1, c + m + 1, cmp);     int p, pos = 0;     for (int now = n; now > 0; now = p - 1) {       p = now;       tot = a[p];       for (; a[p - 1] <= a[now] && p > 1;) tot += a[--p];       for (; pos < m && c[pos + 1].b <= a[now];) q.push(c[++pos].p);       for (; !q.empty();) {         if (tot >= q.top()) {           ans++;           tot -= q.top();           q.pop();         } else {           tmp = q.top() - tot;           q.pop();           q.push(tmp);           tot = 0;           break;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int t, n, a[N];   int main() {     ios::sync_with_stdio(false);     for (cin >> t; t; t--) {       cin >> n;       long long l = 0, r = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         l += a[i];         r ^= a[i];       }       cout << 2 <<   n  << r <<     << (l + r) <<   n ;     }     return 0;   }


#include  bits/stdc++.h    using namespace std;   #define ll               long long int   #define pb                push_back   #define ppb               pop_back   #define pf                push_front   #define ppf               pop_front   #define all(x)            (x).begin(),(x).end()   #define uniq(v)           (v).erase(unique(all(v)),(v).end())   #define sz(x)             (int)((x).size())   #define fr                first   #define sc                second   #define pii               pair<int,int>   #define rep(i,a,b)        for(int i=a;i<b;i++)   #define mem1(a)           memset(a,-1,sizeof(a))   #define mem0(a)           memset(a,0,sizeof(a))   #define ppc               __builtin_popcount   #define ppcll             __builtin_popcountll          template<typename T,typename T1>T max_self(T &a,T1 b){if(b>a)a=b;return a;}   template<typename T,typename T1>T min_self(T &a,T1 b){if(b<a)a=b;return a;}       const long long int INF=1e9;   const int N=0;   const int modn=1e9+7;                  void solve(){   int n,m;cin>>n>>m;    string s,t;    cin>>s>>t;    int left[m],right[m];    int i=0,j=0;     while(j<m)      {while(s[i]!=t[j])         i++;        left[j]=i;        j++,i++;       }      i=n-1; j=m-1;      while(~j)      {       while(s[i]!=t[j])         i--;         right[j]=i;         i--,j--;    }     int ans=0;    //rep(i,0,m)    //cout<<left[i]<<   ;       rep(i,1,m)       max_self(ans,right[i]-left[i-1]);    cout<<ans<<  n  ;       }   int main(){    ios_base::sync_with_stdio(false);    cin.tie(0);cout.tie(0);    int t=1;    //cin>>t;    while(t--) solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   void XsliferX() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   long long f_p(long long x, int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return f_p(x * x, y / 2);     else       return x * f_p(x * x, y / 2);   }   long long l_p(long long n) {     n = n | (n >> 1);     n = n | (n >> 2);     n = n | (n >> 4);     n = n | (n >> 8);     return (n + 1) >> 1;   }   int dp[5005];   int a[5005];   int n;   int L[5005], R[5005];   bool vis[5005];   int solve(int idx) {     int x = 0;     int lft = L[a[idx]], rit = R[a[idx]];     if (idx == n) return 0;     if (dp[idx] != -1) return dp[idx];     for (int i = L[a[idx]]; i <= R[a[idx]]; i++) {       if (lft > L[a[i]]) lft = L[a[i]];       if (rit < R[a[i]]) rit = R[a[i]];     }     bool v[5005] = {0};     if (idx == lft) {       int xo = 0;       for (int i = lft; i <= rit; i++) {         if (!v[a[i]]) {           xo ^= a[i];           v[a[i]] = 1;         }         vis[a[i]] = 1;       }       x = max(x, solve(rit + 1) + xo);       for (int i = lft; i < rit; i++) {         vis[a[i]] = 0;       }     }     vis[a[idx]] = 1;     x = max(x, solve(idx + 1));     vis[a[idx]] = 0;     return dp[idx] = x;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], R[a[i]] = i;     memset(L, -1, sizeof L);     for (int i = 0; i < n; i++)       if (L[a[i]] == -1) L[a[i]] = i;     cout << solve(0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   constexpr long long MAX = 5100000;   constexpr long long INF = 1LL << 60;   constexpr int inf = 1000000007;   constexpr long long mod = 998244353LL;   const long double PI = acos((long double)(-1));   using namespace std;   struct mint {     long long x;     mint(long long x = 0) : x((x % mod + mod) % mod) {}     mint& operator+=(const mint a) {       if ((x += a.x) >= mod) x -= mod;       return *this;     }     mint& operator-=(const mint a) {       if ((x += mod - a.x) >= mod) x -= mod;       return *this;     }     mint& operator*=(const mint a) {       (x *= a.x) %= mod;       return *this;     }     mint operator+(const mint a) const {       mint res(*this);       return res += a;     }     mint operator-(const mint a) const {       mint res(*this);       return res -= a;     }     mint operator*(const mint a) const {       mint res(*this);       return res *= a;     }     mint pow(long long t) const {       if (!t) return 1;       mint a = pow(t >> 1);       a *= a;       if (t & 1) a *= *this;       return a;     }     mint inv() const { return pow(mod - 2); }     mint& operator/=(const mint a) { return (*this) *= a.inv(); }     mint operator/(const mint a) const {       mint res(*this);       return res /= a;     }   };   mint dp[2][4001];   void init(int x) {     for (int i = 0; i <= 4000; i++) dp[x][i] = 0;   }   long long fac[MAX], finv[MAX], inv[MAX];   void COMinit() {     fac[0] = fac[1] = 1;     finv[0] = finv[1] = 1;     inv[1] = 1;     for (int i = 2; i < MAX; i++) {       fac[i] = fac[i - 1] * i % mod;       inv[i] = mod - inv[mod % i] * (mod / i) % mod;       finv[i] = finv[i - 1] * inv[i] % mod;     }   }   mint COM(int n, int k) {     if (n < k) return 0;     if (n < 0 || k < 0) return 0;     return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod);   }   int main() {     COMinit();     long long n, k;     scanf( %lld %lld , &n, &k);     vector<long long> h(n);     for (int i = 0; i < n; i++) scanf( %lld , &h[i]);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (h[i] != h[(i + 1) % n]) {         cnt++;       }     }     mint res = 0;     vector<mint> k2(n + 1);     k2[0] = 1;     for (int i = 1; i <= n; i++) k2[i] = k2[i - 1] * (k - 2);     vector<mint> tw(n + 1);     tw[0] = 1;     for (int i = 1; i <= n; i++) tw[i] = tw[i - 1] * 2;     mint tinv = mint(2).inv();     for (int i = 0; i < cnt; i++) {       int r = cnt - i;       if (r & 1)         res += COM(cnt, i) * k2[i] * tw[r - 1];       else         res += COM(cnt, i) * k2[i] * (tw[r] - COM(r, r / 2)) * tinv;     }     res *= mint(k).pow(n - cnt);     cout << res.x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000ll * 1000ll * 1000ll;   const long long inf64 = inf * inf;   const double pi = acos(-1.0);   long long Abs(long long a) { return (a >= 0 ? a : -a); }   template <typename T>   inline T Sqr(T a) {     return a * a;   }   vector<int> par, sz;   bool solve() {     ios_base::sync_with_stdio(0);     ifstream fin( run.in );     ofstream fout( run.out );     int n, a, b;     cin >> n;     vector<int> d(n - 1);     for (int i(0); i < n - 1; i++) cin >> d[i];     cin >> a >> b;     a--, b--;     long long ans = 0;     for (int i(a); i < b; i++) ans += d[i];     cout << ans <<   n ;     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const int inf = 1e9;   int arr[N], pos[N], rMax[N];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       pos[arr[i]] = i;     }     fill(rMax, rMax + N, n - 1);     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       if (pos[a] < pos[b]) {         rMax[a] = min(pos[b] - 1, rMax[a]);       } else {         rMax[b] = min(pos[a] - 1, rMax[b]);       }     }     long long ans = 1;     for (int i = n - 2; i >= 0; i--) {       int k = arr[i];       int j = arr[i + 1];       rMax[k] = min(rMax[k], rMax[j]);       ans += rMax[k] - i + 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void change_stream(char* in, char* out) {     ifstream fin;     fin.open(in);     ofstream fout;     fout.open(out);     if (fin && fout) {       freopen(in,  r , stdin);       freopen(out,  w , stdout);     }   }   long long a[500], renum[500];   void shift(long long i) {     long long p = a[i];     a[i] = a[i + 2];     a[i + 2] = a[i + 1];     a[i + 1] = p;     renum[a[i]] = i;     renum[a[i + 1]] = i + 1;     renum[a[i + 2]] = i + 2;   }   void solve() {     long long n;     cin >> n;     pair<long long, long long> s[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       s[i] = {a[i], i};     }     sort(s, s + n);     for (long long i = 0; i < n; i++) {       renum[i] = s[i].second;       a[renum[i]] = i;     }     long long sdv = 0;     for (long long i = 0; i < n; i++)       for (long long j = i + 1; j < n; j++)         if (a[i] > a[j]) sdv++;     if (sdv % 2) {       bool flag = false;       for (long long i = 0; i < n - 1; i++)         if (s[i].first == s[i + 1].first) {           swap(a[s[i].second], a[s[i + 1].second]);           renum[a[s[i].second]] = s[i].second;           renum[a[s[i + 1].second]] = s[i + 1].second;           flag = true;           break;         }       if (!flag) {         cout <<  -1 n ;         return;       }     }     vector<long long> ans;     for (long long i = n - 1; i > 1; i--) {       while (renum[i] < i) {         long long l = max(0ll, renum[i] - 1);         ans.push_back(l);         shift(l);       }     }     cout << ans.size() <<   n ;     for (long long i : ans) cout << i + 1 <<    ;     cout <<   n ;   }   signed main() {     change_stream( in ,  out );     ios::sync_with_stdio(0);     cin.tie(0);     long long test_count = 1;     cin >> test_count;     while (test_count--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long dist(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     pair<long long, long long> p1, p2;     cin >> p1.first >> p1.second >> p2.first >> p2.second;     vector<pair<long long, long long>> v(n);     for (int i = 0; i < n; ++i) {       pair<long long, long long> tmp;       cin >> tmp.first >> tmp.second;       v[i] = {dist(p1, tmp), dist(p2, tmp)};     }     long long ans = (1LL << 62);     v.push_back({0, 0});     for (int i = 0; i < v.size(); ++i) {       long long r2 = 0;       for (int j = 0; j < v.size(); ++j) {         if (i == j || v[j].first <= v[i].first)           continue;         else           r2 = max(r2, v[j].second);       }       ans = min(ans, v[i].first + r2);     }     if (n == 1) ans = min(ans, v[0].second);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010];   int base;   int n, tmp;   int main() {     cin >> n;     cin >> base;     a[100000]++;     for (int i = 1; i <= n - 1; i++) {       cin >> tmp;       int offset = tmp - base;       if (abs(offset) > 100000) {         cout <<  NO  << endl;         return 0;       }       a[offset + 100000]++;     }     int ub = 100000, lb = 100000;     int cnt = n + a[100000];     while (a[ub]) {       cnt -= a[ub];       ub++;     }     while (a[lb]) {       cnt -= a[lb];       lb--;     }     lb++;     ub--;     if (cnt != 0) {       cout <<  NO ;       return 0;     }     for (int i = lb + 1; i <= ub - 1; i++) {       if (a[i] < 2) {         cout <<  NO ;         return 0;       }       a[i] -= 2;     }     a[lb]--;     a[ub]--;     for (int i = lb; i <= ub; i++) {       if (a[i + 1] < a[i]) {         cout <<  NO ;         return 0;       }       a[i + 1] -= a[i];     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   inline int read() {     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;   }   int n;   int a[maxn];   int flag = 0;   int flag1 = 0;   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       if (i <= n - 1 && a[i] == 0) flag1 = 1;     }     if (a[n] == 0) flag = 1;     if (flag) {       if (flag1 == 0) {         printf( YES n );         for (int i = 1; i <= n - 1; i++) {           printf( %d-> , a[i]);         }         printf( %d n , a[n]);         return 0;       }       int place = 0;       for (int i = n - 2; i >= 1; i--) {         if (a[i] == 0) {           place = i;           break;         }       }       if (place == 0) {         printf( NO n );         return 0;       }       printf( YES n );       for (int i = 1; i <= place - 1; i++) {         printf( %d-> , a[i]);       }       printf( (%d-> , a[place]);       printf( ( );       for (int i = place + 1; i <= n - 2; i++) {         printf( %d-> , a[i]);       }       printf( %d , a[n - 1]);       printf( ))-> );       printf( %d n , a[n]);     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   inline int chkmax(T &x, const T2 &y) {     return x < y ? x = y, 1 : 0;   }   template <class T, class T2>   inline int chkmin(T &x, const T2 &y) {     return x > y ? x = y, 1 : 0;   }   const int MAXN = (1 << 20);   int n, sum = 0;   vector<int> li1;   vector<pair<int, int> > li;   void read() {     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 1)         li1.push_back(i);       else         sum += x - 2, li.push_back({x - 2, i});     }   }   vector<pair<int, int> > answer;   void solve() {     if (sum < ((int)li1.size()) - 2) {       cout <<  NO  <<   n ;       return;     }     int d = ((int)li.size()) - 1;     for (int i = 0; i < ((int)li.size()) - 1; i++)       answer.push_back({li[i].second, li[i + 1].second});     if (((int)li1.size()) >= 1) {       int x = li1.back();       li1.pop_back();       answer.push_back({x, li[0].second});       d++;     }     if (((int)li1.size()) >= 1) {       int x = li1.back();       li1.pop_back();       answer.push_back({x, li.back().second});       d++;     }     for (auto &it : li) {       while (it.first >= 1 && ((int)li1.size())) {         int x = li1.back();         li1.pop_back();         answer.push_back({x, it.second});         it.first--;       }     }     cout <<  YES           <<     << d <<   n ;     cout << ((int)answer.size()) <<   n ;     for (auto e : answer) cout << e.first <<     << e.second <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, ans, ghor, j, k, flag = 0;     cin >> n;     for (i = 0;; i++) {       ans = (n - 1) / (5 * pow(2, i));       if (ans == 0) break;       n = n - (5 * pow(2, i));     }     ghor = i + 1;     long long p = pow(2, i);     long long cnt = 1;     for (j = 1; j <= 5; j++) {       for (k = 1; k <= p; k++) {         if (cnt == n) {           flag = 1;           break;         }         cnt++;       }       if (flag == 1) break;     }     switch (j) {       case 1:         cout <<  Sheldon  << endl;         break;       case 2:         cout <<  Leonard  << endl;         break;       case 3:         cout <<  Penny  << endl;         break;       case 4:         cout <<  Rajesh  << endl;         break;       case 5:         cout <<  Howard  << endl;         break;     }     return 0;   }