#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   string b[maxn];   int p[maxn], n[maxn];   void get_id(string);   bool is_legal(string);   int main() {     int N;     scanf( %d , &N);     memset(p, 0, sizeof(p));     memset(n, 0, sizeof(n));     for (int i = 0; i < N; i++) {       cin >> b[i];       get_id(b[i]);     }     int ans = 0;     ans += (p[0] / 2);     for (int i = 1; i < maxn; i++) {       ans += min(p[i], n[i]);     }     printf( %d n , ans);     return 0;   }   void get_id(string c) {     if (is_legal(c)) {       p[0]++;       return;     }     int len = c.size();     int count = 0;     bool find = false;     for (int i = 0; i < len; i++) {       if (c[i] ==  ( )         count++;       else         count--;       if (count < 0) find = true;     }     if (count > 0 && !find) p[count]++;     find = false;     count = 0;     for (int i = len - 1; i >= 0; i--) {       if (c[i] ==  ) )         count++;       else         count--;       if (count < 0) find = true;     }     if (count > 0 && !find) n[count]++;   }   bool is_legal(string c) {     int len = c.size();     int count = 0;     for (int i = 0; i < len; i++) {       if (c[i] ==  ( )         count++;       else         count--;       if (count < 0) return false;     }     if (!count)       return true;     else       return false;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int n;   string s;   string A[] = { 123456 ,  154236 ,  145326 ,  516324 ,  261453 ,  132546 };   string B[] = { 123456 ,  523164 ,  623541 ,  423615 };   vector<string> P;   vector<string> T;   vector<string> H;   bool BB[1000];   bool F(string a, string b) {     for (long long(i) = (0); (i) < (T.size()); ++(i)) {       string t = a;       for (long long(j) = (0); (j) < (6); ++(j)) t[j] = a[T[i][j] -  0 ];       if (t == b) return true;     }     return false;   }   int main() {     cin >> s;     int Q[6];     for (long long(i) = (0); (i) < (6); ++(i)) Q[i] = i;     do {       string p =   ;       for (long long(i) = (0); (i) < (6); ++(i)) p += char( 0  + Q[i]);       P.push_back(p);     } while (next_permutation(Q, Q + 6));     for (long long(i) = (0); (i) < (6); ++(i))       for (long long(j) = (0); (j) < (4); ++(j)) {         string t = A[i];         string p = t;         for (long long(k) = (0); (k) < (6); ++(k)) {           int x = B[j][k] -  0 ;           x--;           p[k] = t[x];           p[k]--;         }         T.push_back(p);       }     for (long long(i) = (0); (i) < (P.size()); ++(i)) {       string t =   ;       for (long long(j) = (0); (j) < (6); ++(j)) t += s[P[i][j] -  0 ];       H.push_back(t);     }     int res = 0;     for (long long(i) = (0); (i) < (H.size()); ++(i))       if (BB[i] == false) {         res++;         for (long long(j) = (i + 1); (j) < (H.size()); ++(j))           if (F(H[i], H[j])) BB[j] = true;       }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (a > b * c)         cout << -1 <<   n ;       else {         long long k = (a / (b * d));         cout << a * (k + 1) - k * (k + 1) / 2 * b * d <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m, l, r, k, ans;   map<long long, long long> F;   long long f(long long n) {     if (F.count(n)) return F[n];     long long k = n / 2;     if (n % 2 == 0) return F[n] = (f(k) * f(k) + f(k - 1) * f(k - 1)) % m;     return F[n] = (f(k) * f(k + 1) + f(k - 1) * f(k)) % m;   }   vector<long long> poss;   void get(long long x) {     for (long long i = 1, la; i <= x; i = la + 1) {       la = x / (x / i);       poss.push_back(la);     }   }   int32_t main() {     cin >> m >> l >> r >> k;     get(l - 1), get(r);     for (auto i : poss)       if (r / i - (l - 1) / i >= k) ans = max(ans, i);     F[0] = F[1] = 1 % m;     cout << f(ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 3;   long long n, x, a, cnt, ans, sum;   string g;   deque<long long> v;   void DNM() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a;       v.push_back(a);       if (a > 0) cnt = i;     }     for (long long i = 0; i <= cnt; i++) {       if (i == cnt and i == n - 1) {         for (long long j = 1; j <= v[i]; j++) {           if (j == v[i])             g +=  P ;           else             g +=  P , g +=  L , g +=  R ;         }         break;       }       for (long long j = 0; j < v[i]; j++) {         g +=  P ;         g +=  R ;         g +=  L ;       }       g +=  R ;     }     cout << g << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int Qu_l_uQ = 1;     while (Qu_l_uQ--) DNM();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l, r, p, q, w[100000 + 2], ans = 2100000000, sum = 0, sub = 0;     scanf( %d%d%d%d%d , &n, &l, &r, &p, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);       sum += w[i];     }     for (int i = 0; i <= n; i++) {       int ret = sum * r + sub * l;       if (i <= n - i) {         ret += max(0, n - i - i - 1) * q;       } else {         ret += max(0, i - n + i - 1) * p;       }       if (ret < ans) ans = ret;       if (i != n) {         sum -= w[i];         sub += w[i];       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, i, g = 0, s = 0, b = 0, j;       cin >> n;       long long a[n];       vector<long long> v(n, 1);       for (i = 0; i < n; i++) {         cin >> a[i];       }       if (n < 6)         cout <<  0 0 0 n ;       else {         for (i = 0; i < n - 1; i++) {           if (a[i] == a[i + 1]) v[i + 1] = v[i] + 1;         }         for (i = 0; i < n - 1; i++) {           if (a[i] != a[i + 1]) {             g = g + v[i];             break;           }         }         for (j = i + 1; j < n - 1; j++) {           if (a[j] != a[j + 1] && j < n / 2) {             s = s + v[j];             if (s > g) {               break;             }           }         }         for (long long l = j + 1; l < n - 1; l++) {           if (l < n / 2 && a[l] != a[l + 1]) {             b = b + v[l];           }         }         if (g > 0 && s > 0 && b > 0 && g < s && g < b) {           cout << g <<     << s <<     << b <<   n ;         } else           cout <<  0 0 0 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, k;     cin >> n >> k;     long long int arr1[n], arr2[n];     for (long long int i = 0; i < n; i++) cin >> arr1[i];     for (long long int i = 0; i < n; i++) cin >> arr2[i];     multiset<pair<long long int, pair<long long int, long long int> > > s;     for (long long int i = 0; i < n; i++) {       s.insert(make_pair(arr2[i] / arr1[i], make_pair(arr1[i], arr2[i])));     }     multiset<pair<long long int, pair<long long int, long long int> > >::iterator         it1;     while (true) {       pair<long long int, pair<long long int, long long int> > pp = *s.begin();       long long int num = pp.first, a = pp.second.first, b = pp.second.second;       long long int req = a - (b % a);       if (k >= req) {         k -= req;         s.erase(s.begin());         s.insert(make_pair(num + 1, make_pair(a, b + req)));       } else {         break;       }     }     it1 = s.begin();     cout << it1->first;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], w[100010], h[100010];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d%d , &w[i], &h[i]);     ;     a[n] = min(w[n], h[n]);     for (int i = n - 1; i >= 1; i--) {       if (min(w[i], h[i]) >= a[i + 1])         a[i] = min(w[i], h[i]);       else         a[i] = max(w[i], h[i]);       if (a[i] < a[i + 1]) {         printf( NO );         return 0;       }     }     printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int inf = (-1u) >> 1;   bool v[maxn];   int n, m, k, num;   vector<int> g[maxn];   void dfs(int x) {     v[x] = true;     ++num;     for (vector<int>::iterator it = g[x].begin(); it != g[x].end(); ++it) {       if (!v[*it]) {         dfs(*it);       }     }   }   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 0; i < (n); ++i) {         g[i].clear();         v[i] = false;       }       for (int i = 0; i < (m); ++i) {         int a, b;         scanf( %d%d , &a, &b);         --a, --b;         g[a].push_back(b), g[b].push_back(a);       }       int cnt = 0, ecnt = 0, totcnt = 0;       for (int i = 0; i < (n); ++i)         if (!v[i]) {           num = 0;           dfs(i);           ++totcnt;           if (num == 1) {             ++cnt;           } else {             ecnt += min(k, num) - 2;           }         }       if (k >= 2) {         ecnt += 2;         cnt -= ecnt;         if (totcnt > cnt) cnt += 2;         printf( %d n , max(0, (cnt - 1) / 2));       } else {         printf( %d n , max(0, totcnt - 2));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 66;   long long n, k, a[maxn], d[maxn][maxn];   int main(void) {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] += a[i - 1];     }     long long rt = 0;     for (int i = 55; i >= 0; --i) {       rt += ((1LL * 1) << i);       memset(d, 0, sizeof(d));       d[0][0] = 1;       for (int j = 1; j <= n; ++j) {         for (int q = 1; q <= j; ++q) {           for (int w = j - 1; w >= q - 1; --w) {             if (((a[j] - a[w]) & rt) < rt) continue;             if (d[w][q - 1] == 1) d[j][q] = 1;           }         }       }       if (d[n][k] == 0) rt -= ((1LL * 1) << i);     }     cout << rt << endl;   }


#include <bits/stdc++.h>   using namespace std;   char xB[1 << 15], *xS = xB, *xTT = xB;   template <typename T>   inline void rd(T& xaa) {     char xchh;     T f = 1;     xaa = 0;     while (xchh = (xS == xTT && (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin),                                  xS == xTT)                        ? 0                        : *xS++),            !((xchh >=  0  && xchh <=  9 ) || (xchh ==  - )))       ;     if (xchh ==  - ) {       f = -1;       xchh = (xS == xTT &&                       (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin), xS == xTT)                   ? 0                   : *xS++);     }     xaa = xchh -  0 ;     while (xchh = (xS == xTT && (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin),                                  xS == xTT)                        ? 0                        : *xS++),            ((xchh >=  0  && xchh <=  9 ) || (xchh ==  - )))       xaa = xaa * 10 + xchh -  0 ;     xaa *= f;     return;   }   long long geta(long long x, long long y, long long a, long long b) {     return x * a + y * b;   }   long long getb(long long x, long long y, long long a, long long b) {     return x * b - y * a;   }   int n;   long long a, b, res;   int main() {     rd(n);     rd(a);     rd(b);     map<long long, vector<long long> > val;     for (int i = 1; i <= n; i++) {       long long e, x, y;       rd(e);       rd(x);       rd(y);       long long px = geta(x, y, 1, a), py = getb(x, y, 1, a);       val[py].push_back(px);     }     long long res = 0;     for (map<long long, vector<long long> >::iterator it = val.begin();          it != val.end(); it++) {       vector<long long>& tv = it->second;       sort(tv.begin(), tv.end());       long long nv = 0, nc = 0;       bool st = 0;       int len = static_cast<int>(tv.size());       for (vector<long long>::iterator it1 = tv.begin(); it1 != tv.end(); it1++) {         if (!st) {           nv = *it1;           nc = 1;           st = 1;         } else {           if (*it1 == nv)             nc++;           else {             res += nc * (len - nc);             nv = *it1;             nc = 1;           }         }       }       res += nc * (len - nc);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long mod2 = 998244353;   long long mod3 = 1000003;   long long mod4 = 998244853;   long long inf = 1LL << 60;   long double pi = 3.14159265358979323846L;   double eps = 1e-12;   int dh[4] = {1, -1, 0, 0};   int dw[4] = {0, 0, 1, -1};   int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     if (a % b == 0) return b;     return gcd(b, a % b);   }   long long Pow(long long n, long long k) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k & 1) ret *= now;       now *= now;       k /= 2;     }     return ret;   }   long long beki(long long n, long long k, long long md) {     long long ret = 1;     long long now = n;     while (k > 0) {       if (k % 2 == 1) {         ret *= now;         ret %= md;       }       now *= now;       now %= md;       k /= 2;     }     return ret;   }   long long gyaku(long long n, long long md) { return beki(n, md - 2, md); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (long long i = 0; i < t; i++) {       long long n, m;       cin >> n >> m;       long long a[m];       long long sum = 0;       unordered_map<long long, long long> mp;       for (long long j = 0; j < m; j++) {         cin >> a[j];         sum += a[j];         mp[a[j]]++;       }       if (sum < n) {         cout << -1 << endl;         continue;       }       unordered_map<long long, bool> ok;       long long nn = n;       for (long long j = 0; j < 60; j++) {         long long now = 1LL << j;         if (nn % 2) {           ok[now] = false;         } else           ok[now] = true;         nn /= 2;       }       long long now = 1;       sum = 0;       set<long long> st;       long long ans = 0;       for (;;) {         sum += mp[now] * now;         if (mp[now] > 0) {           long long u = *st.begin();           long long uu = now;           while (uu > u) {             ans++;             uu /= 2;           }           for (auto itr = st.begin(); itr != st.end(); itr++) {             sum -= *itr;           }           st.clear();         }         if (ok[now] == false) {           if (sum >= now) {             sum -= now;             ok[now] = true;           } else {             st.insert(now);           }         }         now *= 2;         if (now > 1000000000000000000) break;       }       cout << ans << endl;     }   }


#include<bits/stdc++.h>   #include<math.h>      using namespace std;      #define ll long long      #define endl   n       #define pb push_back      #define eraseO(s, x) if(s.find(x) != s.end()) { s.erase(s.lower_bound(x)); }      #define vi vector<int>      #define vc vector<char>      #define vl vector<ll>      #define ip pair<int, int>      #define cip pair<int, char>      #define vip vector<ip>      #define msi multiset<int>      #define REP(d, i) for(int i = 0; i < d; ++i)      #define REPD(d, i) for(int i = d - 1; i >= 0; i--)      #define REPM(d, d1, i, j) for(int i = 0; i < d; ++i){for(int j = 0; j < d1; ++j)      #define REPV(v, i) REP(v.size(), i)      #define REPVD(v, i) REPD(v.size(), i)      #define FOR(d) REP(d, i)      #define FORD(d) REPD(d, i)      #define FORM(d, d1) REPM(d, d1, i, j)      #define FORV(v) REPV(v, i)      #define FORVD(v) REPVD(v, i)      #define INA(a, d) FOR(d) { cin >> a[i]; }      #define INM(a, d, d1) FORM(d, d1) { cin >> a[i][j];}}      #define OUTA(a, d) FOR(d) { cout << a[i] <<    ; }      #define OUTV(a) FORV(a) { cout << a[i] <<    ; }      #define OUTM(c, d, d1) FORM(d, d1) { cout << c[i][j] <<    ; } cout << endl;}      void solve() {          int n;       cin >> n;          map<int, int> oc1;       map<int, int> ec1;       map<int, int> oc2;       map<int, int> ec2;          set<int> nums;          int a[n];       INA(a, n);          FOR(n) {           if(i % 2) {               oc1[a[i]]++;           } else {               ec1[a[i]]++;           }           nums.insert(a[i]);       }       sort(a, a + n);          FOR(n) {           if(i % 2) {               oc2[a[i]]++;           } else {               ec2[a[i]]++;           }       }          bool ok = 1;          for(int i : nums) {           if(oc1[i] != oc2[i] || ec1[i] != ec2[i]) {               ok = 0;           }       }          if(ok) {           cout <<  YES  << endl;       } else {           cout <<  NO  << endl;       }   }      int main() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       int t;       cin >> t;       FOR(t) {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int a[100] = {0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4};   int n;   int main() {     scanf( %d , &n);     if (n <= 10)       puts( 0 );     else       printf( %d n , a[n - 10]);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const long long INFL = (long long)9e18;   const int MAXINT = ((~0) ^ (1 << 31));   const long long MAXLL = ((~0) ^ ((long long)1 << 63));   template <class T>   inline T pow2(T a) {     return a * a;   }   template <class T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, true) : false;   }   template <class T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, true) : false;   }   const int maxn = 2e2, maxn2 = 1e5, mod = 1e9 + 7;   long long n, b, k, x, m[40][maxn][maxn], a[maxn2], res[maxn][maxn];   void mul(long long n, long long ans[maxn][maxn], long long a[maxn][maxn],            long long b[maxn][maxn]) {     long long t[maxn][maxn];     for (int i = 0; i < n; i++) memset(t[i], 0, sizeof t[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int z = 0; z < n; z++)           t[i][j] = (t[i][j] + (a[i][z] * b[z][j] + mod) % mod + mod) % mod;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) ans[i][j] = t[i][j];     }   }   void pow(long long n, long long ans[maxn][maxn], long long t[maxn][maxn],            long long k) {     for (int i = 0; i < n; i++) memset(ans[i], 0, sizeof ans[i]);     if (k == 0) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) ans[i][j] = (i == j);       }       return;     }     pow(n, ans, t, k / 2);     mul(n, ans, ans, ans);     if (k % 2 != 0) mul(n, ans, t, ans);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> b >> k >> x;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < x; i++) {       for (int j = 0; j < n; j++) m[0][i][(10 * i + a[j]) % x]++;     }     for (int i = 1; i < 40; i++) mul(x, m[i], m[i - 1], m[i - 1]);     pow(x, res, m[0], b);     cout << res[0][k];   }


#include <bits/stdc++.h>   const int N = 5e4 + 5;   struct Point {     int x, y, z, id;     void input() { scanf( %d%d%d , &x, &y, &z); }   } a[N];   int main() {     std::map<std::pair<int, int>, std::vector<Point> > f;     std::map<int, std::vector<Point> > g;     std::vector<Point> h;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       a[i].input();       a[i].id = i;       f[std::pair<int, int>(a[i].x, a[i].y)].push_back(a[i]);     }     for (auto &p : f) {       auto &v = p.second;       std::sort(v.begin(), v.end(),                 [](const Point &a, const Point &b) { return a.z < b.z; });       if (v.size() & 1) g[v.back().x].push_back(v.back()), v.pop_back();       for (int i = 0; i < v.size(); i += 2)         printf( %d %d n , v[i].id, v[i + 1].id);     }     for (auto &p : g) {       auto &v = p.second;       std::sort(v.begin(), v.end(),                 [](const Point &a, const Point &b) { return a.y < b.y; });       if (v.size() & 1) h.push_back(v.back()), v.pop_back();       for (int i = 0; i < v.size(); i += 2)         printf( %d %d n , v[i].id, v[i + 1].id);     }     for (int i = 0; i < h.size(); i += 2) printf( %d %d n , h[i].id, h[i + 1].id);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void DEBUG(vector<long long> a) {     printf( { );     for (long long x : a) printf( %lld  , x);     printf( } n );   }   int mod;   void DEBUG(long long mask) {     printf( mask:  );     for (int i = 0; i < mod; ++i) printf( %d , (mask >> i) & 1);     printf(  n );   }   struct TorSum {     int n, m;     long long** a;     long long** pref;     TorSum(){};     TorSum(long long** _a) : n(mod), m(mod) {       a = new long long*[n];       for (int i = 0; i < n; ++i) {         a[i] = new long long[m];         for (int j = 0; j < m; ++j) a[i][j] = _a[i][j];       }       pref = new long long*[n + 1];       for (int i = 0; i <= n; ++i) {         pref[i] = new long long[m + 1];         for (int x = 0; x < mod; ++x) pref[i][x] = 0;       }       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j)           pref[i + 1][j + 1] =               a[i][j] + pref[i + 1][j] + pref[i][j + 1] - pref[i][j];     }     long long stupid(int lx, int rx, int ly, int ry) {       if (lx == -1 || rx == -1 || ly == -1 || ry == -1) return 0;       long long res = 0;       for (int x = lx;; x = (x + 1) % n) {         for (int y = ly;; y = (y + 1) % m) {           res += a[x][y];           if (y == ry) break;         }         if (x == rx) break;       }       return res;     }     long long get_sum_safe(int lx, int rx, int ly, int ry) {       return pref[rx][ry] - pref[rx][ly] - pref[lx][ry] + pref[lx][ly];     }     long long get_sum(int lx, int rx, int ly, int ry) {       if (lx == -1 || rx == -1 || ly == -1 || ry == -1) return 0;       if (lx <= rx) {         if (ly <= ry) {           return get_sum_safe(lx, rx + 1, ly, ry + 1);         }         return get_sum_safe(lx, rx + 1, 0, m) -                get_sum_safe(lx, rx + 1, ry + 1, ly);       } else {         if (ly <= ry) {           return get_sum_safe(0, n, ly, ry + 1) -                  get_sum_safe(rx + 1, lx, ly, ry + 1);         }         return get_sum_safe(0, n, 0, m) - get_sum_safe(0, n, ry + 1, ly) -                get_sum_safe(rx + 1, lx, 0, m) +                get_sum_safe(rx + 1, lx, ry + 1, ly);       }     }   };   int mlog(long long r, long long d) {     int k = 0;     for (long long pw = 1; pw <= r / d; ++k) pw *= d;     return k;   }   long long mpow(long long x, int k) {     long long res = 1;     while (k--) res *= x;     return res;   }   int a[66];   vector<pair<int, int>> split_segment(long long mask) {     int n = mod;     int cnt = 0;     for (int i = 0; i < n; ++i) {       a[i] = (mask >> i) & 1;       cnt += a[i];     }     if (cnt == 0) return {};     if (cnt == n) return {{0, n - 1}};     vector<pair<int, int>> res;     for (int i = 0; i < n; ++i) {       int l = i;       while (l < n && !a[l]) ++l;       if (l == n) break;       int r = l;       while (r < n && a[r]) ++r;       res.push_back({l, r - 1});       i = r;     }     if (res[0].first == 0 && res.back().second == n - 1) {       int r = res[0].second;       int l = res.back().first;       res.erase(res.begin());       res.erase(--res.end());       res.push_back({l, r});     }     return res;   }   const int D = 22;   const int MOD = 66;   const int N = 30000;   const int LOG = 16;   using Zet = long long*;   int d;   int logn;   int gen[D];   vector<int> big_gen;   long long pwd[66];   long long jump[N][LOG];   pair<vector<pair<int, int>>, vector<pair<int, int>>> segments[N * D];   void add(Zet arr, Zet to_add, int shift) {     for (int i = 0; i + shift < mod; ++i) arr[i] += to_add[i + shift];     for (int i = mod - shift; i < mod; ++i) arr[i] += to_add[i + shift - mod];   }   Zet zeroes;   unordered_map<long long, Zet> cnt;   Zet get_cnt(long long r) {     if (r <= 0) return zeroes;     if (cnt.count(r)) return cnt[r];     Zet res = new long long[mod];     for (int x = 0; x < mod; ++x) res[x] = 0;     int k = mlog(r, d);     long long dk = mpow(d, k);     if (dk == r) dk /= d;     int i = 0;     for (; r >= (i + 1) * dk; ++i) add(res, get_cnt(dk), (mod - gen[i]) % mod);     add(res, get_cnt(r - i * dk), (mod - gen[i % d]) % mod);     cnt[r] = res;     return res;   };   void inters(long long& mask1, long long mask2, int shift) {     long long shift_mask = mask2 & ((1LL << shift) - 1);     mask1 &= ((mask2 >> shift) | (shift_mask << (mod - shift)));   }   long long query(int l, int r, int pos) {     long long res = (1LL << mod) - 1;     while (l != r) {       for (int i = logn;; --i) {         if (l % pwd[i] == 0 && l + pwd[i] <= r) {           inters(res, jump[pos][i], big_gen[l]);           l += pwd[i];           pos += pwd[i];           break;         }       }     }     return res;   };   unordered_map<long long, TorSum> solver;   long long get_sum(long long R, int lx, int rx, int ly, int ry) {     if (!solver.count(R)) {       Zet* a = new Zet[mod];       for (int i = 0; i < mod; ++i) {         a[i] = new long long[mod];         for (int x = 0; x < mod; ++x) a[i][x] = 0;       }       for (int i = 0; pwd[i] - 1 <= R; ++i) {         for (int digit = 0; digit < d - 1; ++digit) {           if (R < (digit + 1) * pwd[i] - 1) break;           Zet kek = get_cnt((R - (digit + 1) * pwd[i] + 1) / pwd[i + 1] + 1);           for (int r = 0; r < mod; ++r)             a[(r + gen[digit] + i * gen[d - 1]) % mod]              [(r + gen[digit + 1]) % mod] += kek[r];         }       }       solver[R] = TorSum(a);     }     return solver[R].get_sum(lx, rx, ly, ry);   };   long long solve(long long R) {     long long res = 0;     for (int rem = 0; rem < pwd[logn] && rem <= R; ++rem) {       vector<pair<int, int>>& v1 = segments[rem].first;       vector<pair<int, int>>& v2 = segments[rem].second;       for (auto& [lx, rx] : v1)         for (auto& [ly, ry] : v2)           res += get_sum((R - rem) / pwd[logn], lx, rx, ly, ry);     }     return res;   };   int main() {     scanf( %d %d , &d, &mod);     for (int i = 0; i < d; ++i) scanf( %d , &gen[i]);     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     logn = 1;     for (int i = 0; i < d; ++i) big_gen.push_back(gen[i]);     for (; (int)(big_gen).size() < n; ++logn) {       vector<int> new_big_gen;       for (int i = 0; i < d; ++i) {         for (int x : big_gen) new_big_gen.push_back((x + gen[i]) % mod);       }       big_gen = new_big_gen;     }     int pos = 0;     pwd[pos] = 1;     while (pwd[pos] < (long long)4e17) {       long long x = d * pwd[pos];       pwd[++pos] = x;     }     int start, end;     double time;     start = clock();     for (int i = n - 1; i >= 0; --i) {       jump[i][0] = (1LL << (a[i] + 1)) - 1;       for (int k = 1; i + pwd[k] <= n; ++k) {         jump[i][k] = (1LL << mod) - 1;         for (int ii = 0; ii < d; ++ii)           inters(jump[i][k], jump[i + ii * pwd[k - 1]][k - 1], gen[ii]);       }     }     end = clock();     start = clock();     for (int rem = 0; rem <= pwd[logn] - n; ++rem) {       long long draw = query(rem, rem + n, 0);       segments[rem] = {split_segment(draw), {{0, mod - 1}}};     }     end = clock();     start = clock();     for (int rem = pwd[logn] - n + 1; rem < pwd[logn]; ++rem) {       long long draw1 = query(rem, pwd[logn], 0);       long long draw2 = query(0, n - (pwd[logn] - rem), pwd[logn] - rem);       segments[rem] = {split_segment(draw1), split_segment(draw2)};     }     end = clock();     zeroes = new long long[mod];     for (int x = 0; x < mod; ++x) zeroes[x] = 0;     cnt[0] = zeroes;     Zet ozero = new long long[mod];     for (int x = 0; x < mod; ++x) ozero[x] = 0;     ozero[0] = 1;     cnt[1] = ozero;     start = clock();     long long l, r;     scanf( %lld %lld , &l, &r);     --l;     --r;     printf( %lld n , solve(r - n + 1) - solve(l - 1));     end = clock();   }


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


#include <bits/stdc++.h>   const int maxn = 3005, maxm = maxn << 1;   int n, e, ans, minn;   int start[maxn], to[maxm], then[maxm], worth[maxm], f[maxn], tot[maxn],       xx[maxm], yy[maxm];   inline int min(int a, int b) { return a < b ? a : b; }   inline int max(int a, int b) { return a > b ? a : b; }   inline void add(int x, int y, int z) {     then[++e] = start[x], start[x] = e, to[e] = y, worth[e] = z;   }   void dfs(int x, int last) {     minn = min(minn, tot[x]);     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (y == last) continue;       tot[y] = tot[x] + (worth[i] == 0 ? -1 : 1);       dfs(y, x);       f[x] += f[y] + (worth[i] ^ 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y, 1), add(y, x, 0);     }     ans = n - 1;     for (int i = 1; i <= n; i++)       for (int j = start[i]; j; j = then[j])         if (worth[j] == 1) {           int k = to[j], sum = 0;           for (int p = 1; p <= n; p++) f[p] = tot[p] = 0;           dfs(i, 0), ans = min(ans, f[i]);           for (int p = 1; p <= n; p++) f[p] = tot[p] = 0;           minn = 1000000000, dfs(i, k);           sum += f[i] + minn;           for (int p = 1; p <= n; p++) f[p] = tot[p] = 0;           minn = 1000000000, dfs(k, i);           sum += f[k] + minn;           ans = min(ans, sum);         }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 4;   int n, A, B, a[N], par[N];   map<int, int> Map;   int root(int u) { return (par[u] < 0) ? u : (par[u] = root(par[u])); }   void Merge(int u, int v) {     u = root(u);     v = root(v);     if (u != v) {       if (par[u] > par[v]) swap(u, v);       par[u] += par[v];       par[v] = u;     }   }   void sol() {     for (int i = 0; i <= n + 1; ++i) par[i] = -1;     for (int i = 1; i <= n; ++i) {       if (Map.count(A - a[i]))         Merge(i, Map[A - a[i]]);       else         Merge(i, n + 1);       if (Map.count(B - a[i]))         Merge(i, Map[B - a[i]]);       else         Merge(i, 0);     }     int u = root(0), v = root(n + 1);     if (u == v)       cout <<  NO ;     else {       cout <<  YES  n ;       for (int i = 1; i <= n; ++i) {         int tmp = root(i);         if (tmp == u)           cout << 0 <<    ;         else           cout << 1 <<    ;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> A >> B;     for (int i = 1; i <= n; ++i) cin >> a[i], Map[a[i]] = i;     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<int> v) {     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;     return;   }   bool isSubsetSum(vector<int> set, int n, int sum) {     bool subset[n + 1][sum + 1];     for (int i = 0; i <= n; i++) subset[i][0] = true;     for (int i = 1; i <= sum; i++) subset[0][i] = false;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= sum; j++) {         if (j < set[i - 1]) subset[i][j] = subset[i - 1][j];         if (j >= set[i - 1])           subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]];       }     }     return subset[n][sum];   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N;     cin >> N;     for (int I = 0; I < N; I++) {       int n;       cin >> n;       vector<int> v(2 * n);       for (int i = 0; i < 2 * n; i++) {         cin >> v[i];       }       int p = 0;       int t = v[0];       vector<int> temp;       for (int i = 0; i < 2 * n; i++) {         if (v[i] > t) {           t = v[i];           temp.push_back(i - p);           p = i;         }       }       temp.push_back(2 * n - p);       if (isSubsetSum(temp, temp.size(), n)) {         cout <<  YES               <<   n ;       } else {         cout <<  NO               <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m, k, A, B;     cin >> n;     int r1 = -1, p2 = 100000, p1 = -1;     for (int(i) = 0; (i) < (n); (i)++) {       int x;       cin >> x;       r1 = max(x, r1);     }     cin >> m;     for (int(i) = 0; (i) < (m); (i)++) {       int x;       cin >> x;       p1 = max(p1, x);     }     cin >> k;     for (int(i) = 0; (i) < (k); (i)++) {       int x;       cin >> x;       p2 = min(p2, x);     }     cin >> A >> B;     double a = r1, b = p1, c = p2;     double ans = (a * a * B * b) / (B * b + A * c);     cout << fixed << setprecision(10) << sqrt(ans) <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   bool isFile;   using namespace std;   const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};   const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   void _();   void faster() {     _();     if (isFile) {       freopen(            taskA             .in ,            r , stdin);       freopen(            taskA             .out ,            w , stdout);     }     if (1) {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     }   }   const long long INF = 9e18;   const int inf = 2e9;   const int MOD = 998244353;   const long double PI = acos(-1);   const long double EPS = 1e-7;   const int N = (int)2e5 + 5;   const int M = 1234;   vector<int> g[N];   int dp[N];   void dfs(int v, int pr = -1, int lvl = 0) {     dp[lvl % 2]++;     for (int to : g[v])       if (to != pr) dfs(to, v, lvl + 1);   }   void solve() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     cout << min(dp[0], dp[1]) - 1 << endl;   }   void _() {}   int main() {     faster();     int t = 1;     int id = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       vector<int> cnt(n + 1, 0);       for (int i = 0; i < n; i++) {         cin >> v[i];         cnt[v[i]]++;       }       long long sum = 0, ans = 0, len = 0;       for (int i = 0; i < n; i++) {         sum = v[i], len = 1;         for (int j = i + 1; j < n; j++) {           sum += v[j];           len++;           if (len >= 2) {             if (sum <= n) {               ans += cnt[sum];               cnt[sum] = 0;             } else               break;           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   #define maxn 200005   #define endl   n    using namespace std;       int n,m,a[maxn],dis[maxn];   vector<int> e[maxn];       queue<int> q;       void bfs()   {    while(!q.empty())    {     int u=q.front();     q.pop();     for(int i=0;i<e[u].size();i++)     {      int v=e[u][i];      if(dis[v]!=-1) continue;      dis[v]=dis[u]+1;      q.push(v);     }    }   }               int mx[maxn],ans[maxn],ok[maxn];   vector<int> b[maxn];       void bfs2(int tt)   {    while(!q.empty())    {     int u=q.front();     q.pop();     for(int i=0;i<e[u].size();i++)     {      int v=e[u][i];      if(ok[v]) continue;      ans[v]=max(ans[v],tt);      if(mx[v]>=mx[u]-1) continue;      mx[v]=mx[u]-1;      q.push(v);     }    }   }       signed main()   {    ios::sync_with_stdio(0);    cin>>n;    for(int i=1,u,v;i<n;i++)     {     cin>>u>>v;     e[u].push_back(v);     e[v].push_back(u);    }    cin>>m;    memset(dis,-1,sizeof(dis));    for(int i=1;i<=m;i++)     {     cin>>a[i];     ok[a[i]]=1;     dis[a[i]]=0;     q.push(a[i]);    }    bfs();    for(int i=1;i<=n;i++)     b[dis[i]].push_back(i),ans[i]=dis[i];    for(int i=n;i>=1;i--)    {     if(b[i].size()==0) continue;     while(!q.empty()) q.pop();   //  q.clear();     for(int j=0;j<b[i].size();j++)      {      q.push(b[i][j]);      if(mx[b[i][j]]>=i-1) continue;      mx[b[i][j]]=i-1;      ans[b[i][j]]=max(i,ans[b[i][j]]);     }     bfs2(i);    }    for(int i=1;i<=n;i++)     cout<<ans[i]<<   ;    cout<<endl;   }


#include <bits/stdc++.h>   int main() {     int h, l;     float a;     scanf( %d %d , &h, &l);     a = l * tan(atan(1.0 * h / l) - atan(1.0 * l / h));     if (a < 0) a = -a;     printf( %.10f , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     double a;     int b;     friend const bool operator<(const node& x, const node& y) {       if (fabs(x.a - y.a) < 1e-10)         return x.b < y.b;       else         return x.a < y.a;     }   };   int n, t, q, p[200007], l[200007], cnt[200007];   double res;   set<node> a, b;   int read() {     int num = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     return num;   }   int ins(int x) {     if (cnt[x] < l[x])       a.insert(node{((((double)cnt[x] + 1) / (l[x] + cnt[x] + 1)) * p[x]) -                         ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]),                     x});     if (cnt[x])       b.insert(node{((((double)cnt[x] - 1) / (l[x] + cnt[x] - 1)) * p[x]) -                         ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]),                     x});     res += ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]);     return 0;   }   int del(int x) {     if (cnt[x] < l[x])       a.erase(node{((((double)cnt[x] + 1) / (l[x] + cnt[x] + 1)) * p[x]) -                        ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]),                    x});     if (cnt[x])       b.erase(node{((((double)cnt[x] - 1) / (l[x] + cnt[x] - 1)) * p[x]) -                        ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]),                    x});     res -= ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]);     return 0;   }   int add(int x) {     del(x);     cnt[x]++;     t--;     ins(x);     return 0;   }   int era(int x) {     del(x);     cnt[x]--;     t++;     ins(x);     return 0;   }   int main() {     n = read();     t = read();     q = read();     for (int i = 1; i <= n; i++) p[i] = read();     for (int i = 1; i <= n; i++) l[i] = read();     for (int i = 1; i <= n; i++)       a.insert(node{((((double)1) / (l[i] + 1)) * p[i]), i});     while (t && !a.empty()) add(a.rbegin()->b);     for (int i = 1; i <= q; i++) {       int tp = read(), x = read();       if (tp == 2 && cnt[x] == l[x]) era(x);       del(x);       if (tp == 1)         l[x]++;       else         l[x]--;       ins(x);       if (t && !a.empty()) add(a.rbegin()->b);       if (!a.empty() && !b.empty() && (a.rbegin()->a + b.rbegin()->a) > 0) {         int x = a.rbegin()->b, y = b.rbegin()->b;         era(y);         add(x);       }       printf( %.010lf n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool sortbysec(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     return (a.second > b.second);   }   string decToBin(long long int n) {     string s =  0 ;     if (n == 0) return s;     s =   ;     while (n > 0) {       s += (n % 2) +  0 ;       n = n / 2;     }     reverse(s.begin(), s.end());     return s;   }   long long int binToDec(string s) {     long long int ans = 0;     reverse(s.begin(), s.end());     for (__typeof(s.size()) i = (0) - ((0) > (s.size()));          i != (s.size()) - ((0) > (s.size())); i += 1 - 2 * ((0) > (s.size()))) {       ans += pow(2, i) * (s[i] -  0 );     }     return ans;   }   long long int nCr(long long int n, long long int r) {     vector<long long int> fac(200000);     fac.push_back(1);     for (long long int i = 1; i < n + 1; i++) {       fac.push_back((fac[i - 1] * i) % 1000000007);     }     long long int ans = fac[n] / (fac[n - r] * fac[r]);     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     string s;     cin >> s;     long long int mn = 0;     vector<long long int> st;     if (n % 2 == 1) {       cout << -1 << endl;       exit(0);     }     long long int op = 0, cl = 0;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       if (s[i] ==  ( ) {         st.push_back(0);         op++;       } else {         if (st.size() != 0) {           st.pop_back();         }         cl++;       }       if (cl == op) {         if (st.size() == 0) {           cl = 0;           op = 0;           continue;         }         mn += cl + op;         cl = 0;         op = 0;         st.clear();       }     }     if (cl == 0 && op == 0)       cout << mn << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b;       int cnt = 0;       cin >> a >> b;       long long d = abs(a - b);       if (d % 10 == 0) {         cout << d / 10 << endl;       } else {         cout << d / 10 + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> alph(26, 0);   vector<int> comp(26, 0);   int main() {     int n, t, even = 0, l1, l2;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (t % 2 == 0) {         even++;         l1 = i;       } else {         even--;         l2 = i;       }     }     if (even > 0)       cout << l2 + 1;     else       cout << l1 + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int z = 1000000007;   map<int, int> parent;   map<int, int> XOR;   pair<long long int, long long int> finding(int n, int xo) {     if (parent.find(n) == parent.end())       return pair<long long int, long long int>(n, 0);     pair<long long int, long long int> temp = finding(parent[n], 0);     int pa = temp.first;     parent[n] = pa;     XOR[n] = (temp.second) ^ XOR[n];     return pair<long long int, long long int>(parent[n], XOR[n]);   }   void unite(int a, int b, int xo) {     parent[a] = b;     XOR[a] = xo;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> q;     int ans = 0;     for (int i = 1; i <= q; i++) {       int op;       cin >> op;       if (op == 1) {         int l, r, x;         cin >> l >> r >> x;         l = l ^ ans;         r = r ^ ans;         if (l > r) swap(l, r);         r = r + 1;         x = x ^ ans;         int xl = 0, xr = 0;         pair<long long int, long long int> temp = finding(l, xl);         int nl = temp.first;         xl = temp.second;         temp = finding(r, xr);         int nr = temp.first;         xr = temp.second;         if (nl != nr) unite(nl, nr, ((xl ^ xr) ^ x));       } else {         int l, r;         cin >> l >> r;         l = l ^ ans;         r = r ^ ans;         if (l > r) swap(l, r);         r = r + 1;         int xl = 0, xr = 0;         pair<long long int, long long int> temp = finding(l, xl);         int nl = temp.first;         xl = temp.second;         temp = finding(r, xr);         int nr = temp.first;         xr = temp.second;         if (nl == nr) {           cout << (xl ^ xr) << endl;           ans = (xl ^ xr);         } else {           ans = 1;           cout << -1 << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void ckmin(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   void ckmax(T &a, U b) {     if (a < b) a = b;   }   int N;   bitset<200013> bs;   int nxt[200013];   long long ans;   long long c(int r, int m, int mod) { return (r + (mod - m)) / mod; }   int cc(int lt, int rt, int m, int mod) {     if (lt > rt) return 0;     return c(rt, m, mod) - c(lt - 1, m, mod);   }   int32_t main() {     cout << fixed << setprecision(12);     cerr << fixed << setprecision(4);     ios_base::sync_with_stdio(false);     cin.tie(0);     string temps;     cin >> temps;     N = ((int)(temps).size());     for (auto i = (1); i < (N + 1); i++) {       bs[i] = (temps[i - 1] ==  1 );     }     nxt[N + 1] = N + 1;     for (auto i = (N + 1) - 1; i >= (0); i--) {       nxt[i] = (bs[i + 1] ? i + 1 : nxt[i + 1]);     }     int co = N / (213 - 1) + 5;     for (auto i = (1); i < (N + 1); i++) {       long long num = bs[i], lt = i, rt = nxt[i] - 1;       while (true) {         if (num) {           ans += cc(max(num * 213 + i - 1, lt), rt, (i - 1) % num, num);         }         rt++;         lt = rt;         if (rt > N) break;         rt = nxt[rt] - 1;         num++;         if (num > co) break;       }     }     for (auto i = (1); i < (213); i++) {       vector<long long> vec;       vec.push_back(0);       for (auto j = (1); j < (N + 1); j++) {         vec.push_back(vec.back() + 1 - (bs[j] ? i : 0));       }       sort((vec).begin(), (vec).end());       long long dp = 0;       for (auto j = (0); j < (((int)(vec).size())); j++) {         ans += dp;         if (j != ((int)(vec).size()) - 1 && vec[j] == vec[j + 1]) {           dp++;         } else {           dp = 0;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( O1 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( Os )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx2 )   #pragma GCC optimization( unroll-loops )   long long int gcd(long long int a, long long int b) {     return (b ? gcd(b, a % b) : a);   }   long long int P(long long int B, long long int power, long long int modulo) {     long long int ans = 1LL;     while (power > 0LL) {       if (power % 2LL == 1LL) {         ans = (ans * B) % modulo;       }       B = (B * B) % modulo;       power /= 2LL;     }     return ans;   }   bool isPrime(long long int n) {     if (n <= 1LL) {       return false;     }     if (n <= 3LL) {       return true;     }     if (n % 2 == 0LL || n % 3 == 0LL) {       return false;     }     for (long long int i = 5LL; (i * i) <= n; i += 6LL) {       if (n % i == 0LL || n % (i + 2LL) == 0LL) {         return false;       }     }     return true;   }   using namespace std;   void vok() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);   }   const int mxN = int(1e5) + 100;   int dp[mxN];   bool vis[mxN];   void dfs(int u, vector<int> graph[]) {     vis[u] = 1;     for (auto x : graph[u]) {       if (!vis[x]) {         dfs(x, graph);       }       dp[u] = max(dp[u], dp[x] + 1);     }   }   int main() {     vok();     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n);       set<int> index;       for (int i = 0; i < n; i++) {         cin >> v[i];         if (v[i] == k) {           index.insert(i);         }       }       if (int(index.size()) == 0) {         cout <<  no               <<   n ;         continue;       }       bool flag = false;       for (int i = 0; i < n - 1; i++) {         if (v[i] >= k && v[i + 1] >= k) {           flag = true;           break;         }         if (i < n - 2) {           if (v[i] >= k && v[i + 2] >= k) {             flag = true;             break;           }         }       }       if (flag || int(index.size()) == n || n == 1) {         cout <<  yes               <<   n ;         continue;       }       cout <<  no             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long lb = n / m;     long long ub = (n + m - 1) / m;     vector<long long> seat;     for (long long i = 0; i <= m; i++) {       long long remain = n - i * lb;       if (remain >= 0 && remain % ub == 0 && (i + remain / ub == m)) {         for (long long j = 0; j < i; j++) seat.push_back(lb);         for (long long j = 0; j < remain / ub; j++) seat.push_back(ub);         break;       }     }     sort(seat.begin(), seat.end());     priority_queue<pair<long long, long long>> pq;     for (long long i = 0; i < n; i++) pq.push({0, i});     while (k--) {       priority_queue<pair<long long, long long>> temp;       for (auto &x : seat) {         cout << x <<    ;         for (long long i = 0; i < x; i++) {           long long p = pq.top().first, u = pq.top().second;           pq.pop();           p += (x != lb);           cout << (u + 1) <<    n [i == x - 1];           temp.push({p, u});         }       }       pq = temp;     }     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int IINF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const double DINF = numeric_limits<double>::infinity();   const long long MOD = 1000000007;   const double EPS = 1e-9;   const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long sqr(long long x) { return x * x; }   long long sqr(int x) { return (long long)x * x; }   double sqr(double x) { return x * x; }   long double sqr(long double x) { return x * x; }   const int N = 200500;   class SSet {     multiset<int> s1, s2;     long long sum = 0;       public:     void insert(int x) {       if (s2.empty() || (*s2.begin()) > x) {         s1.insert(x);         sum += x;       } else         s2.insert(x);     }     void erase(int x) {       auto it = s1.find(x);       if (it != s1.end()) {         s1.erase(it);         sum -= x;       } else         s2.erase(s2.find(x));     }     long long getSum(int m) {       if (((int)((s1).size())) + ((int)((s2).size())) < m || m < 0) return LINF;       while (((int)((s1).size())) > m) {         auto it = s1.end();         --it;         s2.insert(*it);         sum -= *it;         s1.erase(it);       }       while (((int)((s1).size())) < m) {         auto it = s2.begin();         s1.insert(*it);         sum += *it;         s2.erase(it);       }       return sum;     }   } ss;   int n, m, k;   int costs[N];   bool good1[N], good2[N];   vector<int> c[2][2];   vector<long long> cs[2][2];   int main() {     ios::sync_with_stdio(false);     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; ++i) scanf( %d , &costs[i]);     int gc;     scanf( %d , &gc);     for (int i = 0; i < gc; ++i) {       int x;       scanf( %d , &x);       --x;       good1[x] = 1;     }     scanf( %d , &gc);     for (int i = 0; i < gc; ++i) {       int x;       scanf( %d , &x);       --x;       good2[x] = 1;     }     for (int i = 0; i < n; ++i) c[good1[i]][good2[i]].push_back(costs[i]);     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j) {         sort(c[i][j].begin(), c[i][j].end());         cs[i][j].push_back(0);         for (int x : c[i][j]) cs[i][j].push_back(cs[i][j].back() + x);       }     for (int x : c[0][0]) ss.insert(x);     for (int i = k; i < ((int)((c[0][1]).size())); ++i) ss.insert(c[0][1][i]);     for (int i = k; i < ((int)((c[1][0]).size())); ++i) ss.insert(c[1][0][i]);     long long ans = LINF;     for (int cnt11 = 0; cnt11 <= ((int)((c[1][1]).size())); ++cnt11) {       if (cnt11 >= k)         ans = min(ans, cs[1][1][cnt11] + ss.getSum(m - cnt11));       else if (k - cnt11 <= ((int)((c[1][0]).size())) &&                k - cnt11 <= ((int)((c[0][1]).size())))         ans = min(ans, cs[1][1][cnt11] + cs[0][1][k - cnt11] +                            cs[1][0][k - cnt11] + ss.getSum(m - 2 * k + cnt11));       if (cnt11 != ((int)((c[1][1]).size()))) {         if (k - cnt11 - 1 >= 0 && k - cnt11 - 1 < ((int)((c[0][1]).size())))           ss.insert(c[0][1][k - cnt11 - 1]);         if (k - cnt11 - 1 >= 0 && k - cnt11 - 1 < ((int)((c[1][0]).size())))           ss.insert(c[1][0][k - cnt11 - 1]);       }     }     if (ans >= LINF) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, a[maxn], ans;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int x = gcd(a[1], a[2]);     for (int i = 3; i <= n; i++)       if (x > 1) {         x = gcd(x, a[i]);       }     if (x > 1) {       cout <<  YES  << endl;       cout <<  0  << endl;     } else {       for (int i = 1; i < n; i++) {         if (a[i] % 2 == 0)           continue;         else if (a[i + 1] % 2 == 0)           ans += 2, a[i] = 0;         else           ans++, a[i + 1] = 0, a[i] = 0;       }       if (a[n] % 2 == 0) {         cout <<  YES  << endl;         cout << ans << endl;       } else {         cout <<  YES  << endl;         cout << ans + 2 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   char s[100005];   bool vis[30];   void fmain(int ID) {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int(i) = 1; (i) <= (int)(n); (i)++) vis[s[i] -  a ] = 1;     if (n < k) {       for (int(i) = 1; (i) <= (int)(n); (i)++) printf( %c , s[i]);       for (int(j) = 0; (j) < (int)(26); (j)++)         if (vis[j]) {           for (int(cc) = 0; (cc) < (int)(k - n); (cc)++) printf( %c ,  a  + j);           break;         }       return;     }     for (int i = k; i; i--) {       for (int j = (s[i] -  a ) + 1; j < 26; j++)         if (vis[j]) {           for (int(z) = 1; (z) <= (int)(i - 1); (z)++) printf( %c , s[z]);           printf( %c ,  a  + j);           for (int(tar) = 0; (tar) < (int)(26); (tar)++)             if (vis[tar]) {               for (int z = i + 1; z <= k; z++) printf( %c ,  a  + tar);               return;             }           return;         }     }   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline bool rd(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void pt(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) pt(x / 10);     putchar(x % 10 +  0 );   }   using namespace std;   const long long inf = 1e10;   const int N = 10019;   const int M = 10000000;   template <class T>   struct Max_Flow {     int n;     int Q[N], sign;     int head[N], level[N], cur[N], pre[N];     int nxt[M], pnt[M], E;     T cap[M];     void Init(int n) {       this->n = n + 1;       E = 0;       std::fill(head, head + this->n, -1);     }     void add(int from, int to, T c, T rw) {       pnt[E] = to;       cap[E] = c;       nxt[E] = head[from];       head[from] = E++;       pnt[E] = from;       cap[E] = rw;       nxt[E] = head[to];       head[to] = E++;     }     bool Bfs(int s, int t) {       sign = t;       std::fill(level, level + n, -1);       int *front = Q, *tail = Q;       *tail++ = t;       level[t] = 0;       while (front < tail && level[s] == -1) {         int u = *front++;         for (int e = head[u]; e != -1; e = nxt[e]) {           if (cap[e ^ 1] > 0 && level[pnt[e]] < 0) {             level[pnt[e]] = level[u] + 1;             *tail++ = pnt[e];           }         }       }       return level[s] != -1;     }     void Push(int t, T &flow) {       T mi = inf;       int p = pre[t];       for (int p = pre[t]; p != -1; p = pre[pnt[p ^ 1]]) {         mi = std::min(mi, cap[p]);       }       for (int p = pre[t]; p != -1; p = pre[pnt[p ^ 1]]) {         cap[p] -= mi;         if (!cap[p]) {           sign = pnt[p ^ 1];         }         cap[p ^ 1] += mi;       }       flow += mi;     }     void Dfs(int u, int t, T &flow) {       if (u == t) {         Push(t, flow);         return;       }       for (int &e = cur[u]; e != -1; e = nxt[e]) {         if (cap[e] > 0 && level[u] - 1 == level[pnt[e]]) {           pre[pnt[e]] = e;           Dfs(pnt[e], t, flow);           if (level[sign] > level[u]) {             return;           }           sign = t;         }       }     }     T Dinic(int s, int t) {       pre[s] = -1;       T flow = 0;       while (Bfs(s, t)) {         std::copy(head, head + n, cur);         Dfs(s, t, flow);       }       return flow;     }   };   Max_Flow<long long> F;   struct node {     int x, y;     long long t;     node(int a = 0, int b = 0, long long c = 0) : x(a), y(b), t(c) {}   } AA[N], B[N], C;   int n, m, a, b;   char mp[24][24];   long long Dis[24][24][24][24];   int has1(int x) { return x - 1; }   int has2(int x, int y) { return a + (x - 1) * m + y - 1; }   int has3(int x, int y) { return a + n * m + (x - 1) * m + y - 1; }   int has4(int x) { return a + 2 * n * m + x - 1; }   bool ok(long long now) {     int from = has4(b) + 1, to = from + 1;     F.Init(to + 10);     for (int i = 1; i <= a; i++) {       F.add(from, has1(i), 1, 0);       for (int x = 1; x <= n; x++)         for (int y = 1; y <= m; y++)           if (Dis[x][y][AA[i].x][AA[i].y] < inf &&               Dis[x][y][AA[i].x][AA[i].y] * AA[i].t <= now)             F.add(has1(i), has2(x, y), 1, 0);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (mp[i][j] ==  . ) F.add(has2(i, j), has3(i, j), 1, 0);     for (int i = 1; i <= b; i++) {       F.add(has4(i), to, 1, 0);       for (int x = 1; x <= n; x++)         for (int y = 1; y <= m; y++)           if (Dis[x][y][B[i].x][B[i].y] < inf &&               Dis[x][y][B[i].x][B[i].y] * B[i].t <= now)             F.add(has3(x, y), has4(i), 1, 0);     }     return F.Dinic(from, to) == b;   }   long long solve() {     if (a != b) return -1;     long long ans = -1, l = 0, r = 1e18;     while (l <= r) {       long long mid = (l + r) >> 1;       if (ok(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     return ans;   }   void pre() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int x = 1; x <= n; x++)           for (int y = 1; y <= m; y++) Dis[i][j][x][y] = inf;     int step[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (mp[i][j] ==  * ) continue;         Dis[i][j][i][j] = 0;         for (int k = 0; k < 4; k++) {           int x = i + step[k][0], y = j + step[k][1];           if (1 <= x && x <= n && 1 <= y && y <= m && mp[x][y] ==  . )             Dis[i][j][x][y] = 1;         }       }     for (int x1 = 1; x1 <= n; x1++)       for (int y1 = 1; y1 <= m; y1++)         if (mp[x1][y1] ==  . )           for (int x2 = 1; x2 <= n; x2++)             for (int y2 = 1; y2 <= m; y2++)               if (mp[x2][y2] ==  .  && Dis[x2][y2][x1][y1] < inf)                 for (int x3 = 1; x3 <= n; x3++)                   for (int y3 = 1; y3 <= m; y3++)                     if (mp[x3][y3] ==  . )                       Dis[x2][y2][x3][y3] =                           min(Dis[x2][y2][x3][y3],                               Dis[x2][y2][x1][y1] + Dis[x1][y1][x3][y3]);     if (a > b)       B[++b] = C;     else       AA[++a] = C;   }   void input() {     rd(n);     rd(m);     rd(a);     rd(b);     for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     rd(C.x);     rd(C.y);     rd(C.t);     for (int i = 1; i <= a; i++) {       rd(AA[i].x);       rd(AA[i].y);       rd(AA[i].t);     }     for (int i = 1; i <= b; i++) {       rd(B[i].x);       rd(B[i].y);       rd(B[i].t);     }   }   int main() {     input();     pre();     cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int hr = s[0] -  0 ;     hr = hr * 10 + s[1] -  0 ;     if (hr >= 12) hr -= 12;     int min = s[3] -  0 ;     min = min * 10 + s[4] -  0 ;     double b = min * 6;     double a = ((double)hr + (double)min / 60) * 30;     printf( %.9lf %.9lf , a, b);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 0, counterarr[3] = {5, 7, 5}, c = 0;     string x;     bool arr[3] = {};     while (t < 3) {       getline(cin, x);       for (int i = 0; i < x.length(); i++) {         if (x[i] ==  a  || x[i] ==  e  || x[i] ==  u  || x[i] ==  i  ||             x[i] ==  o )           c++;       }       if (c == counterarr[t]) {         arr[t] = true;       }       c = 0;       t++;     }     if (arr[0] == 1 && arr[1] == 1 && arr[2] == 1)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum1 = 0, sum2 = 0, sum3 = 0;     int n;     cin >> n;     int a, b, c;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       sum1 += a;       sum2 += b;       sum3 += c;     }     if (sum1 == 0 && sum2 == 0 && sum3 == 0)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       n *= 2;       int arr[n];       vector<int> ans;       unordered_set<int> s;       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (s.find(arr[i]) == s.end()) {           ans.push_back(arr[i]);           s.insert(arr[i]);         }       }       for (int i = 0; i < ans.size(); i++) {         cout << ans[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int64_t INF = 1e18, MOD = 1e9 + 7;   const int64_t MAXN = 1e3;   pair<int64_t, int64_t> last = {0, 0};   pair<int64_t, int64_t> ask(int64_t i) {     if (i != -1) cout <<  +   << (i + 1) << endl;     int64_t a, b;     cin >> a >> b;     a -= last.first, b -= last.second;     last = {a + last.first, b + last.second};     return {a, b};   }   int64_t search(int64_t v) {     for (int64_t i = 1; i < MAXN; i++) {       if ((i * (i - 1)) / 2 == v) return i;     }     return -1;   }   int32_t main() {     ios_base::sync_with_stdio(false);     int64_t n;     cin >> n;     ask(-1);     vector<int64_t> ans(n);     pair<int64_t, int64_t> q1 = ask(0);     pair<int64_t, int64_t> q2 = ask(1);     pair<int64_t, int64_t> q3 = ask(2);     pair<int64_t, int64_t> q4 = ask(0);     ans[0] = search(q4.first) + 1;     if (q2.second == 0)       ans[2] = 1;     else       ans[2] = search(q3.first) + 1;     ans[1] = q4.second / ans[2];     int64_t carry = q3.second - ans[1] * (ans[0] - 1);     for (int64_t i = 3; i < n - 1; i++) {       pair<int64_t, int64_t> qur = ask(i);       if (carry == 0)         ans[i] = 1;       else         ans[i] = search(qur.first) + 1;       carry = qur.second - ans[i - 1] * ans[i - 2];     }     if (carry == 0)       ans[n - 1] = 0;     else       ans[n - 1] = carry / ans[n - 3];     ans[0]--;     for (int64_t i = 0; i < n - 1; i++) ans[i]--;     cout <<  !  ;     for (int64_t i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int Maxn = 1005;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   struct pos {     int first, second, third;   };   string s;   int n, k;   pair<int, int> d[11111];   int main() {     scanf( %d%d , &n, &k);     cin >> s;     int ans = INF;     string as =   ;     string os = s;     for (char c =  0 ; c <=  9 ; c++) {       s = os;       for (int(i) = 0; (i) < (int)(n); i++)         d[i] = {abs(s[i] - c), s[i] >= c ? -(n - i) : n - i};       sort(d, d + n);       int cur = 0;       for (int(i) = 0; (i) < (int)(k); i++) {         cur += d[i].first;         int x = d[i].second;         if (x < 0) x = -x;         x = -x + n;         s[x] = c;       }       if (cur < ans || (cur == ans && s < as)) {         as = s;         ans = cur;       }     }     printf( %d n , ans);     puts(as.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int L[100000 + 10], dp1[100000 + 10], dp2[100000 + 10];   int lis(int *seq, int *ls, int N) {     int len = 0;     for (int i = 1; i <= N; ++i) {       int lo = 1, hi = len;       while (lo <= hi) {         int m = (lo + hi) / 2;         if (L[m] <= seq[i])           lo = m + 1;         else           hi = m - 1;       }       L[lo] = seq[i], ls[i] = lo;       if (len < lo) len = lo;     }     return len;   }   int A[100000 + 10], Rev[100000 + 10];   int solve(int n) {     lis(A, dp1, n);     lis(Rev, dp2, n);     int ans = 0;     for (int i = 1, j = n; i <= n; i++, j--) {       ans = max(ans, dp1[i] + dp2[j] - 1);     }     return ans;   }   int go(vector<int> &arr, int n) {     for (int i = 1, j = n; i <= n; i++, j--) A[i] = arr[i - 1], Rev[j] = A[i];     return solve(n);   }   vector<int> V;   int arr[100000 + 5];   int main() {     int n, m, i, l, r, ans = 0;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d %d , &l, &r);       arr[l]++;       arr[r + 1]--;     }     for (i = 1; i <= m; i++) arr[i] += arr[i - 1];     for (int i = 1; i <= m; i++) {       V.push_back(arr[i]);     }     cout << go(V, V.size()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long left(long long i, long long n) {     if (i == 0) return n - 1;     return i - 1;   }   long long solve(string a, long long n) {     long long cw = 0;     long long ccw = 0;     for (long long i = 0; i < n; i++) {       if (a[i] ==  - ) continue;       if (a[i] ==  < )         ccw++;       else         cw++;     }     if (cw == 0 || ccw == 0) return n;     long long cnt = 0;     for (long long i = 0; i < n; i++) {       if (a[left(i, n)] ==  -  || a[i] ==  - ) cnt++;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string a;       cin >> a;       cout << solve(a, n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int read() {     int ans = 0, c, f = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) f *= -1;     do ans = ans * 10 + c -  0 ;     while (isdigit(c = getchar()));     return ans * f;   }   const int N = 10050;   int n, A[N], B[N];   int m, a[N], b[N], c[N], d[N];   void por(int x1, int y1, int x2, int y2) {     a[m] = x1;     b[m] = y1;     c[m] = x2;     d[m] = y2;     ++m;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) A[i] = read();     for (int i = 1; i <= n; ++i) B[i] = read();     for (int k = 1; k <= n; ++k) {       int ti = 0, tj = 0;       for (int i = k; i <= n; ++i) {         if (A[i] == k) ti = i;         if (B[i] == k) tj = i;       }       if (ti == k && tj == k)         ;       else if (ti == k)         por(k, k, k, tj);       else if (tj == k)         por(k, k, ti, k);       else         por(ti, k, k, tj);       std::swap(A[k], A[ti]);       std::swap(B[k], B[tj]);     }     printf( %d n , m);     for (int i = 0; i < m; ++i) printf( %d %d %d %d n , a[i], b[i], c[i], d[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     int x = m - n, r = 0, t = 14;     if (b >= a && a * 8 < x) {       cout << -1;       return 0;     }     while (x > 0) {       if (10 <= t && t < 22)         x -= a;       else         x += b;       t++;       if (t == 24) r++, t = 0;     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, str[10];     cin >> s;     for (int i = 0; i < 10; i++) cin >> str[i];     for (int i = 0; i < s.length(); i += 10) {       string w;       for (int j = i; j < i + 10; j++) w = w + s[j];       for (int i = 0; i < 10; i++) {         if (w.compare(str[i]) == 0) {           cout << i;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string &w, string &s, map<char, int> &cnt) {     int used[ z  -  a  + 1] = {};     int arr[ z  -  a  + 1] = {};     for (int i = 0; i < w.size(); ++i) {       if (w[i] !=  * ) {         used[w[i] -  a ] = 1;       }     }     for (int i = 0; i < w.size(); ++i) {       if (w[i] ==  * ) {         if (used[s[i] -  a ]) {           return false;         }         arr[s[i] -  a ] += 1;       } else if (w[i] != s[i]) {         return false;       }     }     for (int i = 0; i <  z  -  a  + 1; ++i) {       if (arr[i]) {         cnt[ a  + i] += 1;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string w;     cin >> w;     map<char, int> cnt;     int k = 0;     int m;     cin >> m;     string s;     for (int i = 0; i < m; ++i) {       cin >> s;       if (check(w, s, cnt)) {         k++;       }     }     int ans = 0;     for (auto p : cnt) {       if (p.second == k) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, h;     cin >> n >> h;     for (int i = 1; i < n; i++) printf( %.10f  , h * sqrt(1. * i / n));     puts(  );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   vector<int> primes(int n) {     vector<int> p(n + 1, 1);     for (int i = 2; i * i <= n; ++i)       if (p[i])         for (int j = i * i; j <= n; j += i) p[j] = 0;     vector<int> res;     for (int i = 2; i <= n; ++i)       if (p[i]) res.push_back(i);     return res;   }   int a[128], b[128];   int dp[128][1 << 16];   int pr[128][1 << 16];   int bit[64];   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)(n); i++) cin >> a[i];     vector<int> prime = primes(54);     for (int i = 0; i < (int)(128); i++)       for (int j = 0; j < (int)(1 << 16); j++) dp[i][j] = INF;     dp[0][0] = 0;     for (int i = 0; i < (int)(64); i++)       for (int j = 0; j < (int)(16); j++)         if (i % prime[j] == 0) bit[i] += (1 << j);     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(1 << 16); j++) {         for (int k = 0; k < (int)(54); k++)           if ((bit[k] & j) == 0)             if (dp[i + 1][bit[k] | j] > dp[i][j] + abs(a[i] - k)) {               dp[i + 1][bit[k] | j] = dp[i][j] + abs(a[i] - k);               pr[i + 1][bit[k] | j] = k;             }       }     int pos = 0;     for (int i = 0; i < (int)(1 << 16); i++)       if (dp[n][pos] > dp[n][i]) pos = i;     vector<int> res;     for (int i = n; i > 0; --i) {       res.push_back(pr[i][pos]);       int k = pr[i][pos];       pos = pos - bit[k];     }     reverse((res).begin(), (res).end());     for (int i = 0; i < (int)(res.size()); i++) {       if (i > 0) cout <<    ;       cout << res[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   int T, n, A, B, C, cnt, p[N], mu[N], du[N], fe[N], tot;   long long a[N], b[N], c[N];   bool np[N];   void init() {     mu[1] = 1;     for (int i = 2; i <= n; i++) {       if (!np[i]) p[++cnt] = i, mu[i] = -1;       for (int j = 1; j <= cnt && i * p[j] <= n; j++) {         np[i * p[j]] = 1;         if (i % p[j] == 0) break;         mu[i * p[j]] = -mu[i];       }     }   }   struct edge {     int u, v, w;   };   struct _ {     int v, w;   };   vector<_> G[N];   int main() {     n = 10000;     init();     scanf( %d%d%d , &A, &B, &C);     n = max(A, max(B, C));     for (int i = 0; i <= n; i++) a[i] = b[i] = c[i] = du[i] = 0, G[i].clear();     for (int i = 1; i <= A; i++)       for (int j = i; j <= A; j += i) a[i] += A / j;     for (int i = 1; i <= B; i++)       for (int j = i; j <= B; j += i) b[i] += B / j;     for (int i = 1; i <= C; i++)       for (int j = i; j <= C; j += i) c[i] += C / j;     long long ans = 0;     for (int i = 1; i <= n; i++)       ans += mu[i] * mu[i] * mu[i] * a[i] * b[i] * c[i];     vector<edge> e;     for (int d = 1; d <= n; d++)       for (int i = 1, l = n / d; i <= l; i++)         if (mu[i * d])           for (int j = i + 1, r = n / d / i; j <= r; j++)             if (mu[j * d] && gcd(i, j) == 1) {               int u = i * d, v = j * d, lcm = i * j * d;               ans += mu[u] * mu[u] * mu[v] *                      (a[u] * b[lcm] * c[lcm] + a[lcm] * b[u] * c[lcm] +                       a[lcm] * b[lcm] * c[u]);               ans += mu[u] * mu[v] * mu[v] *                      (a[v] * b[lcm] * c[lcm] + a[lcm] * b[v] * c[lcm] +                       a[lcm] * b[lcm] * c[v]);               ++du[u];               ++du[v];               e.push_back((edge){u, v, lcm});             }     for (auto &f : e)       if (du[f.u] > du[f.v] || (du[f.u] == du[f.v] && f.u < f.v))         G[f.u].push_back((_){f.v, f.w});       else         G[f.v].push_back((_){f.u, f.w});     for (int u = 1; u <= n; u++) {       for (auto &f : G[u]) fe[f.v] = f.w;       for (auto &f : G[u])         for (auto &p : G[f.v])           if (fe[p.v])             ans += mu[u] * mu[f.v] * mu[p.v] *                    (a[f.w] * b[p.w] * c[fe[p.v]] + a[f.w] * b[fe[p.v]] * c[p.w] +                     a[p.w] * b[f.w] * c[fe[p.v]] + a[fe[p.v]] * b[f.w] * c[p.w] +                     a[fe[p.v]] * b[p.w] * c[f.w] + a[p.w] * b[fe[p.v]] * c[f.w]);       for (auto &f : G[u]) fe[f.v] = 0;     }     printf( %d n , int(ans & ((1 << 30) - 1)));   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     set<long long> myset;     for (int i = 0; i < n; i++) {       int c;       cin >> c;       myset.insert(c);     }     auto it = myset.begin();     int ans = 0;     do {       long long x = (*it) * k;       if (x != *it) {         if (myset.count(x)) myset.erase(x);       }       ans++;       if (it != myset.end()) it++;     } while (it != myset.end());     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, k;   int a[maxn];   long long pre[maxn];   void read_input() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];   }   void init() {     for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + a[i];   }   vector<int> get_divs(int x) {     vector<int> res;     for (int i = 2; i * 1LL * i <= x; ++i)       if (x % i == 0) {         res.push_back(i);         if (i * i != x) res.push_back(x / i);       }     return res;   }   void solve() {     if (pre[n] % k != 0) {       cout <<  No n ;       return;     }     int x = pre[n] / k;     int cur = 1, lst = 0;     vector<int> ans;     for (int i = 1; i <= n; ++i)       if (pre[i] == cur * x) {         ans.push_back(i - lst);         lst = i;         ++cur;       }     if ((int)ans.size() != k) {       cout <<  No n ;       return;     }     cout <<  Yes n ;     for (auto& x : ans) cout << x <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     read_input();     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long s, x;   int main() {     cin >> s >> x;     s -= x;     if (s < 0 || s % 2 != 0) {       cout << 0 << endl;       return 0;     }     s /= 2;     if (s & x) {       cout << 0 << endl;       return 0;     }     long long bit = 0, result = 0;     if (!s) result -= 2;     while (x > 0) {       bit += x & 1;       x >>= 1;     }     result += 1LL << bit;     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, n, trans = 0, cnt = 0, b, c, m, s, d;     vector<int> v, vd;     cin >> n;     for (long long x = 0; x < n; x++) {       cin >> m;       v.clear();       for (long long j = 0; j < m; j++) {         cin >> d;         v.push_back(d);       }       sort(v.rbegin(), v.rend());       vd.clear();       trans = 0;       for (long long j = 1; j < v.size(); j++) {         if ((v[j] - v[0]) % 2 != 0) {           trans = 1;           cout <<  NO  << endl;           break;         }       }       if (trans == 0) cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[303][303], dp[602][301][301], n;   bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < n); }   int update(int d, int x1, int x2) {     if (x2 < x1) swap(x1, x2);     int y1 = d - x1, y2 = d - x2;     if (!valid(x1, y1) || !valid(x2, y2)) return INT_MIN;     if (dp[d][x1][x2] != INT_MIN) return dp[d][x1][x2];     for (long long mask = 0; mask < 4; mask++) {       dp[d][x1][x2] = max(dp[d][x1][x2],                           update(d - 1, x1 - (mask & 1), x2 - ((mask & 2) >> 1)));     }     if (dp[d][x1][x2] == INT_MIN) dp[d][x1][x2] = 0;     dp[d][x1][x2] += a[x1][y1] + (x1 != x2 ? a[x2][y2] : 0);     return dp[d][x1][x2];   }   int main() {     cin >> n;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) cin >> a[i][j];     for (long long i = 0; i < 2 * n; i++)       for (long long j = 0; j < n; j++)         for (long long k = 0; k < n; k++) dp[i][j][k] = INT_MIN;     cout << update(2 * n - 2, n - 1, n - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long int, long int>> adj[100001];   bool visit[100001] = {};   long int val[100001];   long int ans = 0;   void dfs(long int node, long int w) {     if (w > val[node]) {       return;     }     ans++;     for (long int i = 0; i < (int)adj[node].size(); i++) {       dfs(adj[node][i].first, max(w + adj[node][i].second, (long int)0));     }     return;   }   int main() {     long int n;     cin >> n;     for (long int i = 1; i <= n; i++) cin >> val[i];     for (long int i = 1; i <= n - 1; i++) {       long int x, y;       cin >> x >> y;       adj[x].push_back(make_pair(i + 1, y));     }     dfs(1, 0);     cout << n - ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   struct Fraction {     long long p, q;     static inline __attribute__((always_inline)) long long gcd(long long a,                                                                long long b) {       while (b ^= a ^= b ^= a = a % b)         ;       return a;     }     inline __attribute__((always_inline)) void clear() { p = 0, q = 1; }     inline __attribute__((always_inline)) Fraction() { clear(); }     inline __attribute__((always_inline)) Fraction(long long a, long long b) {       p = a, q = b;     }     inline __attribute__((always_inline)) Fraction& simplify() {       long long x = gcd(p, q);       p /= x, q /= x;       return *this;     }     inline __attribute__((always_inline)) bool operator<(         const Fraction& rhs) const {       return p * rhs.q < rhs.p * q;     }     inline __attribute__((always_inline)) bool operator==(         const Fraction& rhs) const {       return p * rhs.q == rhs.p * q;     }   };   const int N = 1e5 + 5;   pair<Fraction, Fraction> d[N];   int n;   long long ans;   inline __attribute__((always_inline)) bool pffcomp(       const pair<Fraction, Fraction>& a, const pair<Fraction, Fraction>& b) {     return a.first < b.first || (a.first == b.first && a.second > b.second);   }   void mergesort(int l, int r) {     static pair<Fraction, Fraction> tmp[N];     if (l >= r) return;     int mid = (l + r) >> 1;     mergesort(l, mid);     mergesort(mid + 1, r);     int pl = l, pr = mid + 1, pt = l;     while (pl <= mid && pr <= r) {       if (d[pl].second < d[pr].second)         tmp[pt++] = d[pl++];       else {         ans += mid - pl + 1;         tmp[pt++] = d[pr++];       }     }     while (pl <= mid) tmp[pt++] = d[pl++];     while (pr <= r) tmp[pt++] = d[pr++];     for (pt = l; pt <= r; ++pt) d[pt] = tmp[pt];   }   int main() {     int w;     scanf( %d%d , &n, &w);     for (int i = 1, x, v; i <= n; ++i) {       scanf( %d%d , &x, &v);       d[i] = make_pair(Fraction(-x, v - w).simplify(),                        Fraction(-x, v + w).simplify());     }     sort(d + 1, d + 1 + n, pffcomp);     mergesort(1, n);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void imGonnaDoIt() {     long long r, x, y, xx, yy;     cin >> r >> x >> y >> xx >> yy;     cout << ceil(hypot((x - xx), (y - yy)) / (r * 2));   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     imGonnaDoIt();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, int> puncte, cnt, goluri, rateu;     int x, y;     char c1[25], c2[25];     for (int i = 0; i < 5; i++) {       scanf( %s%s%d:%d , c1, c2, &x, &y);       cnt[c1]++;       cnt[c2]++;       if (x > y) {         puncte[c1] += 3;       }       if (x < y) {         puncte[c2] += 3;       }       if (x == y) {         puncte[c1]++;         puncte[c2]++;       }       goluri[c1] += x;       rateu[c1] += y;       goluri[c2] += y;       rateu[c2] += x;     }     string czn;     vector<string> echipe;     for (auto &s : cnt) {       echipe.push_back(s.first);       if (s.second == 2 && s.first !=  BERLAND ) {         czn = s.first;       }     }     for (int i = 1; i < 100; i++) {       for (int j = 0; j < 100; j++) {         int k = i + j;         goluri[ BERLAND ] += k;         rateu[ BERLAND ] += j;         goluri[czn] += j;         rateu[czn] += k;         puncte[ BERLAND ] += 3;         vector<tuple<int, int, int, string>> w;         for (auto &s : echipe) {           w.push_back(               make_tuple(-puncte[s], -goluri[s] + rateu[s], -goluri[s], s));         }         sort(w.begin(), w.end());         if (get<3>(w[0]) ==  BERLAND  || get<3>(w[1]) ==  BERLAND ) {           printf( %d:%d , k, j);           return 0;         }         puncte[ BERLAND ] -= 3;         goluri[ BERLAND ] -= k;         rateu[ BERLAND ] -= j;         goluri[czn] -= j;         rateu[czn] -= k;       }     }     printf( IMPOSSIBLE );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     cin >> n;     int cnt = 0;     int jump = 1;     int arr[n];     for (int k = 1; k <= n; k++) {       arr[k] = k;     }     for (i = 1; i <= n * n; i++) {       jump += i;       if (jump <= n) {         cout << arr[jump] <<    ;       } else {         cout << arr[jump % n] <<    ;       }       cnt++;       if (cnt == n - 1) {         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long sum[55][100005], f[55][100005], t[100005];   int l[55], r[55];   int add(int p, int x, int y) {     if (x < 0) return 0;     if (y < 0) return sum[p][x];     return sum[p][x] - sum[p][y];   }   long long solve1(int n, int m) {     long long ans = 0;     for (int i = l[1]; i <= r[1]; i++) f[1][i] = 1;     for (int i = 1; i <= m; i++) sum[1][i] = (sum[1][i - 1] + f[1][i]) % mod;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         f[i][j] = add(i - 1, j - l[i], j - r[i] - 1);         sum[i][j] = (sum[i][j - 1] + f[i][j]) % mod;       }     }     for (int i = 1; i <= m; i++) ans = (ans + f[n][i]) % mod;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) f[i][j] = sum[i][j] = 0;     return ans;   }   long long solve2(int n, int m, int d) {     long long ans = 0;     for (int i = d; i <= m; i += d)       if (i >= l[1] && i <= r[1]) f[1][i] = 1;     for (int i = d; i <= m; i += d) sum[1][i] = f[1][i] + sum[1][i - d];     for (int i = 2; i <= n; i++) {       for (int j = d; j <= m; j += d) {         int R = j - l[i] - ((j - l[i]) % d + d) % d;         int L = j - r[i] - ((j - r[i]) % d + d) % d;         if ((j - r[i]) % d == 0) L -= d;         f[i][j] = add(i - 1, R, L);         sum[i][j] = (sum[i][j - d] + f[i][j]) % mod;       }     }     for (int i = d; i <= m; i += d) ans = (ans + f[n][i]) % mod;     for (int i = 1; i <= n; i++)       for (int j = d; j <= m; j += d) f[i][j] = sum[i][j] = 0;     return ans;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]);     long long ans = solve1(n, m);     for (int d = 2; d <= m / n; d++) {       ans = ((ans - (1 - t[d]) * solve2(n, m, d)) % mod + mod) % mod;       for (int j = 2; j * d <= m; j++) t[j * d] += 1 - t[d];     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   void solve() {     int n, z;     std::cin >> n >> z;     std::vector<int> xs(n);     for (auto& x : xs) std::cin >> x;     std::sort(xs.begin(), xs.end());     int ok = 0, ng = n / 2 + 1;     while (ng - ok > 1) {       int k = (ok + ng) / 2;       bool judge = true;       for (int i = 0; i < k; ++i) {         if (xs[n - k + i] - xs[i] < z) judge = false;       }       if (judge) {         ok = k;       } else {         ng = k;       }     }     std::cout << ok <<   n ;   }   int main() {     std::cin.tie(nullptr);     std::ios::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     bool flag = 0;     int by1, by2;     int x, y;     for (int i = 0; i <= a; i++) {       x = a - i;       y = i;       by1 = b - x;       by2 = c - y;       if (by1 == by2 and by1 >= 0) {         flag = 1;         break;       }     }     if (flag)       cout << x <<     << by1 <<     << y << endl;     else       cout <<  Impossible  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100100];   vector<int> adj[100100];   int cnt[100100];   queue<int> q[2];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) scanf( %d , &arr[i]);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[v].push_back(u);       cnt[u]++;     }     for (int i = 0; i < n; ++i) {       if (cnt[i] == 0) {         q[arr[i]].push(i);       }     }     int ans = 0;     while (1) {       int a = q[0].size(), b = q[1].size();       if (a + b == 0) break;       for (int i = 0; i < 2; ++i) {         if (!q[i].empty() && i == 1) ans++;         while (!q[i].empty()) {           int u = q[i].front();           q[i].pop();           for (int j = 0; j < adj[u].size(); ++j) {             int to = adj[u][j];             cnt[to]--;             if (!cnt[to]) {               q[arr[to]].push(to);             }           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     int total = 0;     for (int i = 1; i <= n; ++i) {       int temp;       cin >> temp;       if (n - i < m) {         total += min(k, temp);       } else {         total += temp;       }     }     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     long long int k;     cin >> n;     cin >> k;     long long int arr[k];     for (long long int i = 0; i < k; i++) cin >> arr[i];     long long minrem = n % arr[0];     long long number = 0;     long long pos = 0;     for (long long int i = 0; i < k; i++) {       long long int rem = n % arr[i];       if (minrem >= rem) {         number = n / arr[i];         minrem = rem;         pos = i;       }     }     cout << (pos + 1) <<     << number;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int M = 128;   const int inf = 0x7fffffff;   const long long INF = 9E18;   const int mod = 1e9 + 7;   int tree[maxn << 2][2], a[maxn];   int in[maxn], out[maxn], dis[maxn];   int dfs_clock = 0;   vector<int> g[maxn];   void dfs(int u, int fa) {     dis[u] = dis[fa] ^ 1;     in[u] = ++dfs_clock;     for (int i = 0; i < g[u].size(); i++) {       int to = g[u][i];       if (to == fa) continue;       dfs(to, u);     }     out[u] = dfs_clock;   }   void pushdown(int rt, int odd) {     if (tree[rt][odd]) {       tree[rt << 1 | 1][odd] += tree[rt][odd];       tree[rt << 1][odd] += tree[rt][odd];       tree[rt][odd] = 0;     }   }   void update(int x, int y, int l, int r, int val, int odd, int rt) {     if (x <= l && r <= y) {       tree[rt][odd] += val;       return;     }     pushdown(rt, odd);     int mid = (l + r) >> 1;     if (x <= mid) update(x, y, l, mid, val, odd, rt << 1);     if (y > mid) update(x, y, mid + 1, r, val, odd, rt << 1 | 1);   }   int query(int p, int l, int r, int rt, int odd) {     if (l == r) {       return tree[rt][odd];     }     pushdown(rt, odd);     int mid = (l + r) >> 1;     if (p <= mid)       return query(p, l, mid, rt << 1, odd);     else       return query(p, mid + 1, r, rt << 1 | 1, odd);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     dis[0] = 0;     dfs(1, 0);     for (int i = 0; i < m; i++) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, val;         scanf( %d%d , &x, &val);         update(in[x], out[x], 1, n, val, dis[x], 1);         update(in[x], out[x], 1, n, -val, dis[x] ^ 1, 1);       } else {         int num;         scanf( %d , &num);         cout << query(in[num], 1, n, 1, dis[num]) + a[num] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, q, ans;   int mat[maxn][maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int k;         scanf( %d , &k);         if (i == j) {           ans += k;         }       }     }     ans %= 2;     cin >> q;     for (int i = 0; i < q; i++) {       int c;       scanf( %d , &c);       if (c == 1 || c == 2) {         int bucket;         scanf( %d , &bucket);         ans = (ans + 1) % 2;       } else {         printf( %d , ans);       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 81;   const int inf = 1e9;   int n, c, a[N];   int dp[N][N][N * N];   vector<int> vc;   int main() {     scanf( %d , &n);     c = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       c += a[i];       if (a[i]) vc.push_back(i);     }     int m = n * (n - 1) / 2;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= c; j++) {         for (int k = 0; k <= m; k++) {           dp[i][j][k] = (j == 0 && k == 0) ? 0 : -inf;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= c; j++) {         for (int k = 0; k <= m; k++) {           if (j > i) continue;           int tmp = vc[j - 1];           for (int p = 1; p <= i; p++) {             int ops = abs(tmp - p);             if (k < ops) continue;             dp[i][j][k] =                 max(dp[i][j][k], dp[p - 1][j - 1][k - ops] + (p - j) * (i - p));           }         }       }     }     int mx = -inf;     for (int i = 0; i <= n * (n - 1) / 2; i++) {       mx = max(mx, dp[n][c][i]);       printf( %d  , mx);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   void cass() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int N = 10;   int n, a[N], res = 1e9, x[N];   string s;   void read() {     cin >> s;     n = 6;     for (int i = 0; i < s.length(); ++i) a[i + 1] = s[i] -  0 ;   }   void cmp() {     int sum1 = x[1] + x[2] + x[3];     int sum2 = x[4] + x[5] + x[6];     if (sum1 != sum2) return;     int dem = 0;     for (int i = 1; i <= n; ++i)       if (a[i] != x[i]) dem++;     res = min(res, dem);   }   void tried(int i) {     for (int j = 0; j <= 9; ++j) {       x[i] = j;       if (i == n)         cmp();       else         tried(i + 1);     }   }   int main() {     cass();     read();     tried(1);     cout << res;     return 0;   }


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


#include<bits/stdc++.h>      #define pb push_back   #define x first   #define y second   #define all(a) (a).begin(), (a).end()      using namespace std;      typedef long long ll;   typedef pair<int, int> ii;      const int maxn = 3e5 + 5;      int n, m, X;   ll A[maxn];   int par[maxn];   set<pair<ll, ii>> adj[maxn];   map<ii, int> pos;   set<pair<ll, int>> s;   int exists = 1;      int find(int x) {return (x == par[x]) ? x : par[x] = find(par[x]);}      int merge(int x, int y) {    x = find(x), y = find(y);    if(x == y) return 0;        if(adj[x].size() < adj[y].size()) swap(x, y);    par[y] = x;    s.erase({A[y], y});    s.erase({A[x], x});    A[x] += A[y];    A[x] -= X;    s.insert({A[x], x});    if(A[x] < 0) exists = 0;    for(auto p : adj[y]) adj[x].insert(p);    return 1;   }      int main() {    scanf( %d %d %d , &n, &m, &X);    for(int i = 0;i < n;i++) scanf( %lld , A + i);    for(int i = 0;i < n;i++) par[i] = i;    for(int i = 0;i < m;i++) {     int x, y;     scanf( %d %d , &x, &y);     x--, y--;     if(x > y) swap(x, y);     pos[{x, y}] = i + 1;     adj[x].insert({A[y], {x, y}});     adj[y].insert({A[x], {x, y}});    }        vector<int> ans;    for(int i = 0;i < n;i++) s.insert({A[i], i});    for(int i = 0;i < n - 1;i++) {     auto it1 = s.end();it1--;     auto p1 = *it1;          while(1) {      auto it2 = adj[p1.y].end();it2--;      auto p2 = *it2;      int flag = merge(p2.y.x, p2.y.y);      if(flag) {       ans.pb(pos[{p2.y.x, p2.y.y}]);       break;      }      adj[p1.y].erase(it2);     }     if(!exists) {printf( NO n );return 0;}    }        printf( YES n );    for(int i : ans) printf( %d n , i);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200100;   struct seat {     int w, id;     bool operator<(const seat& st) const { return w < st.w; }     bool operator>(const seat& st) const { return w > st.w; }   };   seat st[maxn];   int n;   char tp[maxn * 2];   int main() {     while (scanf( %d , &n) == 1) {       for (int i = 1; i <= n; i++) {         scanf( %d , &st[i].w);         st[i].id = i;       }       scanf( %s , tp);       sort(st + 1, st + 1 + n);       priority_queue<seat, vector<seat>, less<seat>> que;       int cnt = 1;       for (int i = 0; i < n * 2; i++) {         if (tp[i] ==  0 ) {           printf( %d  , st[cnt].id);           que.push(st[cnt]);           cnt++;         } else {           printf( %d  , que.top().id);           que.pop();         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 9;   int arr[maxn];   int vis[maxn];   int n;   int mu;   long long re[111];   long long gcd(long long a, long long b) {     long long c = 1;     while (b) {       c = a % b;       a = b;       b = c;     }     return a;   }   int sol(int a) {     vis[a] = 1;     int e = arr[a];     if (vis[e]) {       if (e == mu) {         return 1;       } else {         return -1;       }     } else {       int g = sol(e);       if (g == -1)         return -1;       else         return g + 1;     }   }   int main() {     int a, b, c, d, e, f, g, h;     while (scanf( %d , &n) == 1) {       for (d = 1; d <= n; d++) {         scanf( %d , &arr[d]);       }       memset(vis, 0, sizeof(vis));       g = 0;       h = 0;       a = 0;       for (d = 1; d <= n; d++) {         if (!vis[d]) {           mu = d;           e = sol(d);           if (e == -1) {             g = -1;             break;           }           if (e % 2) {             re[a++] = e;           } else             re[a++] = e / 2;         }       }       if (g < 0) {         printf( -1 n );       } else {         long long res = 1, tmp;         for (d = 0; d < a; d++) {           tmp = gcd(res, re[d]);           res = res * re[d] / tmp;         }         cout << res << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ar[500009], br[500009];   int main() {     long long int a, b, c, i, j = 999999999999, k, e, f, g, w, h, i1, j1;     string s, d;     cin >> a >> b >> c;     e = a;     c = c * 5;     j = a;     for (i = 1;; i++) {       a = e;       if (a - (i * b) < 0) {         break;       }       a = a - (i * b);       a = a - ((a / c) * c);       j = min(j, a);     }     for (i = 1;; i++) {       a = e;       if (a - (i * c) < 0) {         break;       }       a = a - (i * c);       a = a - ((a / b) * b);       j = min(j, a);     }     cout << j << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cerr << *i <<    ;     cerr << endl;   }   int main() {     for (long long N, M; cin >> N >> M;) {       for (int i = 0; i < (int)(N); ++i) {         long long S, F, T;         cin >> S >> F >> T;         if (S == F) {           cout << T << endl;           continue;         }         long long loop = (M - 1) * 2;         long long ans = 0;         if (S < F) {           ans = T / loop * loop;           T = T % loop;           if (S - 1 < T) ans += (M - 1) * 2;           ans += F - 1;         } else {           ans = T / loop * loop;           T = T % loop;           if (M - S + M - 1 < T) ans += (M - 1) * 2;           ans += M - 1;           ans += (M - F);         }         cout << ans << endl;       }     }     return 0;   }