#include <bits/stdc++.h>   using namespace std;   const int bits = 1000;   bitset<bits> node[4 * 100060];   long long int leftOver[4 * 100060];   int n;   int treeSize[100060];   vector<int> adj[100060];   int dfsOrder[100060];   int o = 1;   void dfs(int curr = 1, int par = -1) {     treeSize[curr] = 1;     dfsOrder[curr] = o++;     for (int nxt : adj[curr]) {       if (nxt != par) {         dfs(nxt, curr);         treeSize[curr] += treeSize[nxt];       }     }   }   int m;   bitset<bits> rotate(std::bitset<bits> b, unsigned k) {     b = b << (k) | b >> (m - (k));     b = b | (b >> m);     return b;   }   void build(int pos, int bit, int id = 1, int l = 1, int r = n) {     if (l == r) {       node[id][bit] = 1;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       build(pos, bit, id << 1, l, mid);     else       build(pos, bit, (id << 1) + 1, mid + 1, r);     node[id] = node[id << 1] | node[(id << 1) + 1];   }   void push(int id) {     if (leftOver[id] > 0) {       leftOver[id << 1] = (leftOver[id] + leftOver[id << 1]) % m;       leftOver[(id << 1) + 1] = (leftOver[id] + leftOver[(id << 1) + 1]) % m;       leftOver[id] = 0;     }   }   void add(int val, int L, int R, int id = 1, int l = 1, int r = n) {     if (L <= l && r <= R) {       leftOver[id] = (leftOver[id] + val) % m;       return;     }     push(id);     int mid = (l + r) >> 1;     if (L <= mid) add(val, L, R, id << 1, l, mid);     if (R > mid) add(val, L, R, (id << 1) + 1, mid + 1, r);     node[id] = rotate(node[id << 1], leftOver[id << 1]) |                rotate(node[(id << 1) + 1], leftOver[(id << 1) + 1]);   }   bitset<bits> ans;   void query(int qL, int qR, int id = 1, int l = 1, int r = n) {     if (qL <= l && qR >= r) {       ans = ans | rotate(node[id], leftOver[id]);       return;     }     push(id);     int mid = (l + r) >> 1;     if (qL <= mid) query(qL, qR, id << 1, l, mid);     if (qR > mid) query(qL, qR, (id << 1) + 1, mid + 1, r);     node[id] = rotate(node[id << 1], leftOver[id << 1]) |                rotate(node[(id << 1) + 1], leftOver[(id << 1) + 1]);   }   vector<int> primes;   vector<int> sieve(int limit) {     vector<int> primes;     bool in[limit + 1];     memset(in, true, sizeof(in));     for (int i = 2; i <= limit; i++) {       if (in[i]) {         primes.push_back(i);         for (int j = i; j <= limit; j += i) in[j] = false;       }     }     return primes;   }   int a[100060];   int aTemp[100060];   int addBrute(int l, int r, int x) {     for (int i = l; i < r + 1; i++) a[i] = (a[i] + x) % m;   }   bitset<bits> findBrute(int l, int r) {     bitset<bits> temp = 0;     for (int i = l; i < r + 1; i++) temp[a[i] % m] = 1;     return temp;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> n >> m;     primes = sieve(m);     for (int i = 0; i < n; i++) cin >> a[i + 1];     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs();     for (int i = 0; i < n; i++) {       build(dfsOrder[i + 1], a[i + 1] % m);     }     for (int i = 1; i < n + 1; i++) {       aTemp[dfsOrder[i]] = a[i];     }     for (int i = 1; i < n + 1; i++) {       a[i] = aTemp[i];     }     cin >> q;     for (int i = 0; i < q; i++) {       int t, v;       cin >> t >> v;       if (t == 1) {         int x;         cin >> x;         add(x % m, dfsOrder[v], dfsOrder[v] + treeSize[v] - 1);       } else {         ans = 0;         query(dfsOrder[v], dfsOrder[v] + treeSize[v] - 1);         int k = 0;         for (int j = 0; j < primes.size(); j++) {           if (primes[j] < m) {             if (ans[primes[j]]) {               k++;             }           }         }         cout << k <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   struct seg {     vector<int> t;     int n;     seg(int n = 0) : t(2 * n), n(n) {}     int query(int l, int r) {       int ans = 0;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) ans += t[l++];         if (r & 1) ans += t[--r];       }       return ans;     }     void update(int p, int v) {       for (t[p += n] += v; p > 1; p >>= 1) {         t[p >> 1] = t[p] + t[p ^ 1];       }     }   };   seg s[4][11][10];   void modify(int p, int c, int m) {     for (int i = 1; i <= 10; i++) {       s[c][i][p % i].update(p, m);     }   }   void convert(string& s) {     for (char& c : s) {       switch (c) {         case  A :           c = 0;           break;         case  T :           c = 1;           break;         case  C :           c = 2;           break;         case  G :           c = 3;           break;       }     }   }   int main() {     string k;     cin >> k;     convert(k);     for (int i = 0; i < 4; i++) {       for (int j = 1; j <= 10; j++) {         for (int l = 0; l < j; l++) {           s[i][j][l] = seg(k.size());         }       }     }     for (int i = 0; i < k.size(); i++) {       modify(i, k[i], 1);     }     int q;     cin >> q;     while (q--) {       int op;       cin >> op;       if (op == 1) {         int x;         string c;         cin >> x >> c;         convert(c);         x--;         modify(x, k[x], -1);         k[x] = c[0];         modify(x, k[x], 1);       } else {         int l, r;         cin >> l >> r;         l--;         string e;         cin >> e;         convert(e);         int a = 0;         for (int i = l; i < l + e.size(); i++) {           a += s[e[i - l]][e.size()][i % e.size()].query(l, r);         }         cout << a <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};   const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},             d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};   void DBG() { cout <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cout << to_string(h);     if (sizeof...(t)) cout <<  ,  ;     DBG(t...);   }   template <class T>   bool umin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool umax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   int n;   vector<pair<long long, long long>> cards[(long long)(200002)],       need[(long long)(200002)];   vector<array<long long, 3>> valid[(long long)(200002)];   void prepare() {     for (int i = (1), _c = (n); i <= _c; ++i) {       vector<int> cnt(4, 0);       sort((cards[i]).begin(), (cards[i]).end(),            [](pair<long long, long long> a, pair<long long, long long> b) {              return a.first < b.first ||                     (a.first == b.first && a.second > b.second);            });       for (auto j : cards[i]) {         if (j.first == 1 && cnt[j.first] >= 3) continue;         if (j.first == 2 && cnt[j.first] >= 1) continue;         if (j.first == 3 && cnt[j.first] >= 1) continue;         need[i].push_back(j);         ++cnt[j.first];       }     }     for (int i = (1), _c = (n); i <= _c; ++i) {       for (int j = (0), _c = ((1ll << (((int)((need[i]).size())))) - 1); j <= _c;            ++j) {         long long cost = 0, ma = 0, dame = 0;         for (int k = (0), _c = (((int)((need[i]).size())) - 1); k <= _c; ++k) {           if ((((j) >> (k)) & 1ll)) {             cost += need[i][k].first;             dame += need[i][k].second;             umax(ma, need[i][k].second);           }         }         if (cost <= 3) {           int bonus = __builtin_popcountll(j);           valid[i].push_back({bonus, dame, ma});         }       }     }   }   long long dp[(long long)(200002)][11];   void test_case() {     cin >> n;     for (int i = (1), _c = (n); i <= _c; ++i) {       int k;       cin >> k;       cards[i].assign(k, {0, 0});       for (int j = (0), _c = (k - 1); j <= _c; ++j)         cin >> cards[i][j].first >> cards[i][j].second;     }     prepare();     for (auto i : valid[1]) umax(dp[1][i[0]], i[1]);     for (int i = (1), _c = (n - 1); i <= _c; ++i)       for (int j = (0), _c = (10); j <= _c; ++j)         if (dp[i][j] || j == 0) {           for (auto k : valid[i + 1]) {             int nxtNum = j + k[0];             if (nxtNum < 10)               umax(dp[i + 1][nxtNum], dp[i][j] + k[1]);             else               umax(dp[i + 1][nxtNum % 10], dp[i][j] + k[1] + k[2]);           }         }     long long ans = 0;     for (int i = (0), _c = (10); i <= _c; ++i) umax(ans, dp[n][i]);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     auto time = clock();     int test = 1;     while (test--) {       test_case();     }     cerr <<  [It took   << fixed << setprecision(3)          << double(clock() - time) / CLOCKS_PER_SEC <<  s]           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Get(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int N;   void Init() { Get(N); }   int T[55][55];   void Mul(int A[][55], int B[][55], int N, int K, int M) {     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) {         T[i][j] = 0;         for (int k = 1; k <= K; k++) (T[i][j] ^= (A[i][k] & B[k][j]));       }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) A[i][j] = T[i][j];   }   int A[55][55];   int B[55][55];   int T2[55][55];   void Pow(int X[][55], long long P) {     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) T2[i][j] = (i == j);     for (; P; P >>= 1) {       if (P & 1) Mul(T2, X, N, N, N);       Mul(X, X, N, N, N);     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) X[i][j] = T2[i][j];   }   long long Factor[100005];   int FactorTop;   bool I() {     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (B[i][j] != (i == j)) return 0;     return 1;   }   bool Check() {     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) B[i][j] = A[i][j];     Pow(B, (1ll << N) - 1);     int Ans = I();     if (Ans == 0) return 0;     for (int k = 1; k <= FactorTop; k++) {       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) B[i][j] = A[i][j];       Pow(B, ((1ll << N) - 1) / Factor[k]);       int Ans = I();       if (Ans == 1) return 0;     }     return 1;   }   void Debug() {     FactorTop = 0;     long long X = 1ll << N;     X--;     Factor[0] = 1;     for (long long i = 2; i * i <= X; i++) {       for (;; X /= i) {         if (X % i != 0) break;         Factor[++FactorTop] = i;       }     }     if (X > 1) Factor[++FactorTop] = X;     for (int i = 1; i < N; i++) A[i + 1][i] = 1;     for (;;) {       for (int i = 1; i <= N; i++) A[i][N] = rand() & 1;       int Ans = Check();       if (Ans) break;     }   }   void Work() { Debug(); }   void Output() {     for (int i = N; i >= 1; i--) printf( %d  , A[i][N]);     puts(  );     for (int i = N; i >= 1; i--) printf( %d  , 1);     puts(  );   }   int main() {     srand(time(0));     Init();     Work();     Output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t;   long long n;   long long tmp;   long long gcd(long long a, long long b) {     long long temp;     if (a < b) {       temp = a;       a = b;       b = temp;     }     while (b != 0) {       temp = a % b;       a = b;       b = temp;     }     return a;   }   long long lcm(long long a, long long b) {     long long temp_lcm;     temp_lcm = a * b / gcd(a, b);     return temp_lcm;   }   int main() {     cin >> t;     while (t--) {       cin >> n;       if (n % 2 == 0) {         long long a, b;         tmp = n / 2;         while (tmp--) {           cin >> a >> b;           cout << b <<     << -a <<    ;         }         cout << endl;       } else {         long long a, b, c;         tmp = (n - 2) / 2;         while (tmp--) {           cin >> a >> b;           cout << b <<     << -a <<    ;         }         cin >> a >> b >> c;         tmp = lcm(a, b);         tmp = lcm(tmp, c);         cout << tmp / a <<     << tmp / b <<     << -2 * tmp / c;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int max = 0, min = 0;     int a[m], b[m];     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + m, greater<int>());     for (int i = 0; i < n; i++) {       if (a[0] != 0) {         max = max + a[0];         a[0] = a[0] - 1;         sort(a, a + m, greater<int>());       } else {         break;       }     }     sort(b, b + m);     int i = 0, k = 0;     while (i != n) {       if (b[k] != 0) {         min = min + b[k];         b[k] = b[k] - 1;       } else {         k++;         min = min + b[k];         b[k] = b[k] - 1;       }       i++;     }     cout << max <<     << min;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime[1000005] = {false};   vector<long long int> SPF(1000005);   long long int fastPower(long long int a, long long int b) {     if (b == 0) return 1;     long long int prod = 1;     while (b > 0) {       if (b & 1) prod = prod * a;       b = b >> 1;       a = a * a;     }     return prod;   }   void sieve() {     int i;     for (i = 2; i < 1000005; ++i) isPrime[i] = 1;     for (i = 2; i * i < 1000005; ++i) {       if (isPrime[i]) {         for (int j = i * i; j < 1000005; j += i) isPrime[j] = 0;       }     }   }   void printa(bool f) {     if (f)       cout <<  YES ;     else       cout <<  NO ;     cout <<   n ;   }   bool flip(bool f) {     if (f) return 0;     return 1;   }   void solve() {     long long int i, n;     cin >> n;     vector<long long int> a(n);     for (i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     long long int s = 0, m = a[n - 1];     for (i = 0; i < n - 1; ++i) s += a[i];     cout << abs(m - s) + 1 <<   n ;   }   int main() {     int tc = 1;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int m, n, p, count = 0;     cin >> m >> n;     if (m % n == 0)       cout << m / n;     else {       count = count + (m / n);       m = m % n;       for (;;) {         if (m > n) {           if (m % n == 0) {             count += m / n;             break;           }           m = m - n;           count++;         } else if (n > m) {           if (n % m == 0) {             count += n / m;             break;           }           n = n - m;           count++;         }       }       cout << count;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5;   const int MAXM = 20;   int n, m;   int a[MAXN], b[MAXM];   int num[MAXM];   char ans[MAXN][MAXM];   set<int> states[MAXM];   int getState(int mask, int num[MAXM]) {     int res = mask;     for (int i = 0; i < n; ++i) {       res = res * MAXN + num[i];     }     return res;   }   bool dfs(int j, int lastState = 0) {     if (j == m) {       for (int i = 0; i < n; ++i) {         if (num[i] != a[i]) {           return false;         }       }       return true;     }     if (j) {       if (states[j].find(lastState) != states[j].end()) {         return false;       }       states[j].insert(lastState);     }     int origin[MAXM];     memcpy(origin, num, sizeof(num));     for (int k = 0; k < (1 << n); ++k) {       int cnt = 0;       for (int i = 0; i < n; ++i) {         if (k & (1 << i)) {           ans[i][j] =  * ;           if (i == 0 || ans[i - 1][j] ==  . ) {             ++cnt;           }         } else {           ans[i][j] =  . ;         }       }       if (cnt != b[j]) {         continue;       }       for (int i = 0; i < n; ++i) {         if (ans[i][j] ==  * ) {           if (j == 0 || ans[i][j - 1] ==  . ) {             ++num[i];           }         }       }       bool valid = true;       for (int i = 0; i < n; ++i) {         if (num[i] > a[i]) {           valid = false;           break;         }         if (ans[i][j] ==  * ) {           if (a[i] - num[i] > (m - j - 1) / 2) {             valid = false;             break;           }         } else {           if (a[i] - num[i] > (m - j) / 2) {             valid = false;             break;           }         }       }       if (valid) {         if (dfs(j + 1, getState(k, num))) {           return true;         }       }       memcpy(num, origin, sizeof(origin));     }     return false;   }   int main() {     while (cin >> n >> m) {       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       for (int i = 0; i < m; ++i) {         cin >> b[i];       }       for (int i = 0; i < n; ++i) {         states[i].clear();       }       memset(num, 0, sizeof(num));       dfs(0);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           cout << ans[i][j];         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   const int INF = 2 * (1e9);   int n, m;   vector<pair<int, int> > edge[N];   vector<pair<int, int> > delay[N];   int dist[N];   int main() {     cin.sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int from, to, len;       cin >> from >> to >> len;       from--;       to--;       edge[from].push_back(make_pair(to, len));       edge[to].push_back(make_pair(from, len));     }     for (int i = 0; i < n; i++) {       int num;       cin >> num;       int cur;       for (int j = 0; j < num; j++) {         cin >> cur;         if (j == 0 or delay[i].back().second != cur)           delay[i].push_back(make_pair(cur, cur + 1));         else           delay[i].back().second++;       }     }     for (int i = 0; i < n; i++) dist[i] = INF;     dist[0] = 0;     if (delay[0].size() >= 1 and delay[0][0].first == 0)       dist[0] = delay[0][0].second;     set<pair<int, int> > dijkstra;     dijkstra.insert(make_pair(dist[0], 0));     for (int i = 0; i < n; i++) {       if (dijkstra.empty()) break;       pair<int, int> now = *dijkstra.begin();       dijkstra.erase(now);       for (const pair<int, int> &next : edge[now.second]) {         int arrival = next.first;         int tm = next.second + now.first;         int idx = lower_bound(delay[arrival].begin(), delay[arrival].end(),                               make_pair(tm, INF)) -                   delay[arrival].begin();         if (idx > 0 and arrival != n - 1) {           idx--;           if (delay[arrival][idx].first <= tm and tm < delay[arrival][idx].second)             tm = delay[arrival][idx].second;         }         if (dist[arrival] > tm) {           dijkstra.erase(make_pair(dist[arrival], arrival));           dist[arrival] = tm;           dijkstra.insert(make_pair(dist[arrival], arrival));         }       }     }     if (dist[n - 1] == INF) dist[n - 1] = -1;     cout << dist[n - 1] << endl;     return 0;   }


#include <cstdio>   #include <vector>   #include <cstring>   #include <algorithm>   const int Maxn=200000;   const int Inf=0x3f3f3f3f;   int n;   int a[Maxn+5];   std::vector<int> v_lis[Maxn+5];   struct Segment_Tree{    struct Segment_Node{     int minn,maxn;     int lazy;    }seg[Maxn<<2|5];    void update_tag(int root,int a){     seg[root].lazy+=a;     seg[root].minn+=a,seg[root].maxn+=a;    }    void push_up(int root){     seg[root].minn=std::min(seg[root<<1].minn,seg[root<<1|1].minn);     seg[root].maxn=std::max(seg[root<<1].maxn,seg[root<<1|1].maxn);    }    void push_down(int root){     if(seg[root].lazy==0){      return;     }     update_tag(root<<1,seg[root].lazy);     update_tag(root<<1|1,seg[root].lazy);     seg[root].lazy=0;    }    void update(int l,int r,int v,int root=1,int left=0,int right=n){     if(l>right||r<left){      return;     }     if(l<=left&&r>=right){      update_tag(root,v);      return;     }     push_down(root);     int mid=(left+right)>>1;     update(l,r,v,root<<1,left,mid);     update(l,r,v,root<<1|1,mid+1,right);     push_up(root);    }    int query_min(int l,int r,int root=1,int left=0,int right=n){     if(l>right||r<left){      return Inf;     }     if(l<=left&&r>=right){      return seg[root].minn;     }     push_down(root);     int mid=(left+right)>>1;     return std::min(query_min(l,r,root<<1,left,mid),query_min(l,r,root<<1|1,mid+1,right));    }    int query_max(int l,int r,int root=1,int left=0,int right=n){     if(l>right||r<left){      return -Inf;     }     if(l<=left&&r>=right){      return seg[root].maxn;     }     push_down(root);     int mid=(left+right)>>1;     return std::max(query_max(l,r,root<<1,left,mid),query_max(l,r,root<<1|1,mid+1,right));    }   }seg_1,seg_2;   int ans[Maxn+5];   int main(){    scanf( %d ,&n);    for(int i=1;i<=n;i++){     scanf( %d ,&a[i]);     v_lis[a[i]].push_back(i);    }    for(int i=1;i<=n;i++){     seg_1.update(i>>1,(n-1)>>1,1);     seg_2.update((i+1)>>1,n>>1,1);    }    for(int i=1;i<=n;i++){     for(int j=0;j<(int)v_lis[i].size();j++){      int pos=v_lis[i][j];      int pos_1_max=seg_1.query_max(pos>>1,(n-1)>>1);      int pos_1_min=seg_1.query_min(0,(pos>>1)-1);      int pos_2_max=seg_2.query_max((pos+1)>>1,n>>1);      int pos_2_min=seg_2.query_min(0,(pos-1)>>1);      ans[pos]=std::max(std::max((pos_2_max-pos_2_min)>>1,(pos_1_max-pos_1_min)>>1),      std::max((pos_2_max-pos_1_min-1)>>1,(pos_1_max-pos_2_min-1)>>1));     }     for(int j=0;j<(int)v_lis[i].size();j++){      seg_1.update(v_lis[i][j]>>1,(n-1)>>1,-2);      seg_2.update((v_lis[i][j]+1)>>1,n>>1,-2);     }     for(int j=0;j<(int)v_lis[i].size();j++){      int pos=v_lis[i][j];      int pos_1_min=seg_1.query_min(pos>>1,(n-1)>>1);      int pos_1_max=seg_1.query_max(0,(pos>>1)-1);      int pos_2_min=seg_2.query_min((pos+1)>>1,n>>1);      int pos_2_max=seg_2.query_max(0,(pos-1)>>1);      ans[pos]=std::max(ans[pos],std::max(      std::max((pos_2_max-pos_2_min)>>1,(pos_1_max-pos_1_min)>>1)-1,      std::max((pos_2_max-pos_1_min-1)>>1,(pos_1_max-pos_2_min-1)>>1)));     }    }    for(int i=1;i<=n;i++){     printf( %d  ,ans[i]);    }    puts(  );;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> V[100005];   int main() {     int N, M, K, ans = 1;     scanf( %d%d%d , &N, &M, &K);     for (int i = 1; i <= N; ++i) {       int c;       scanf( %d , &c);       V[c].push_back(i);     }     for (int c = 1; c <= M; ++c) {       int L = V[c].size(), rem = 0, st = 0;       for (int j = 1; j < L; ++j) {         rem += V[c][j] - V[c][j - 1] - 1;         while (rem > K) {           rem -= V[c][st + 1] - V[c][st] - 1;           ++st;         }         ans = max(ans, j - st + 1);       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     string s;     cin >> s;     string h = s.substr(0, 2);     int hour = atoi(h.c_str());     string m = s.substr(3, 2);     int minute = atoi(m.c_str());     long long time = 60 * hour + minute;     long long add;     cin >> add;     long long sum = time + add;     long long n = sum % (24 * 60);     cout << setfill( 0 ) << setw(2) << right << (n / 60);     cout <<  : ;     cout << setfill( 0 ) << setw(2) << right << (n % 60) << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[7];   int b[7];   int main() {     string s;     int k;     cin >> s >> k;     int kol = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         kol++;       }     }     if (kol < k) {       cout << s.length() - 1;     } else {       kol = 0;       int res = 0;       for (int i = s.length() - 1; i >= 0; i--) {         if (s[i] ==  0 ) {           kol++;         } else {           res++;         }         if (kol == k) {           cout << res;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s1[5010], s2[5010], str[5010];   int num[30];   int len1, len2;   int dfs(int k, int m) {     if (!s1[k]) return m;     for (int i = 0; i < 26; i++)       if (num[i] && (m || (i >= s2[k] -  a ))) {         str[k] = i +  a ;         num[i]--;         if (dfs(k + 1, m || (i > s2[k] -  a ))) return 1;         num[i]++;       }     return 0;   }   int main() {     while (EOF != scanf( %s %s , s1, s2)) {       memset(num, 0, sizeof(num));       len1 = strlen(s1), len2 = strlen(s2);       for (int i = 0; i < len1; i++) num[s1[i] -  a ]++;       if (!dfs(0, 0))         printf( -1 n );       else {         printf( %s n , str);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Rectangle {     int x1;     int x2;     int y1;     int y2;     Rectangle() {}     Rectangle(int a, int b, int c, int d) {       x1 = a;       y1 = b;       x2 = c;       y2 = d;       if (x1 > x2) {         swap(x1, x2);       }       if (y1 > y2) {         swap(y1, y2);       }     }     bool operator<(Rectangle r) const {       if (x1 != r.x1) {         return x1 < r.x1;       } else if (x2 != r.x2) {         return x2 < r.x2;       } else if (y1 != r.y1) {         return y1 < r.y1;       } else {         return y2 < r.y2;       }     }   };   int Area(Rectangle r) { return (r.x2 - r.x1) * (r.y2 - r.y1); }   set<Rectangle> rec;   set<Rectangle> lines;   int main() {     int W, H, N;     scanf( %d , &W);     ;     scanf( %d , &H);     ;     scanf( %d , &N);     ;     rec.insert(Rectangle(0, 0, W, H));     for (int(n) = 0; n < (int)N; n++) {       int a, b, c, d;       scanf( %d , &a);       ;       scanf( %d , &b);       ;       scanf( %d , &c);       ;       scanf( %d , &d);       ;       lines.insert(Rectangle(a, b, c, d));     }     for (int(n) = 0; n < (int)N; n++) {       for (__typeof(rec).begin() t = rec.begin(); t != rec.end(); t++) {         Rectangle r = *t;         for (__typeof(lines).begin() it = lines.begin(); it != lines.end();              it++) {           if (it->x1 == it->x2) {             if (r.x1 < it->x1 && it->x2 < r.x2 && r.y1 == it->y1 &&                 r.y2 == it->y2) {               lines.erase(lines.find(*it));               rec.erase(*t);               rec.insert(Rectangle(r.x1, r.y1, it->x2, r.y2));               rec.insert(Rectangle(it->x2, r.y1, r.x2, r.y2));               goto end;             }           } else if (it->y1 == it->y2) {             if (r.y1 < it->y1 && it->y2 < r.y2 && r.x1 == it->x1 &&                 r.x2 == it->x2) {               lines.erase(lines.find(*it));               rec.erase(*t);               rec.insert(Rectangle(r.x1, r.y1, r.x2, it->y1));               rec.insert(Rectangle(r.x1, it->y1, r.x2, r.y2));               goto end;             }           }         }       }     end:       int sol = 42;     }     vector<int> res;     for (__typeof(rec).begin() it = rec.begin(); it != rec.end(); it++) {       res.push_back(Area(*it));     }     sort(res.begin(), res.end());     for (__typeof(res).begin() it = res.begin(); it != res.end(); it++) {       printf(  %d , *it);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 10;   long long q, x, v, u, w, ans;   map<long long, long long> len;   int main() {     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> x >> v >> u;       if (x == 1) {         cin >> w;         while (v != u) {           if (v > u) {             len[v] += w;             v = v / 2;           } else {             len[u] += w;             u = u / 2;           }         }       } else {         ans = 0;         while (v != u) {           if (v > u) {             ans += len[v];             v = v / 2;           } else {             ans += len[u];             u = u / 2;           }         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000000ll;   long long x[6], y[6];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     if (n == 1) {       cout << -1 << endl;       return 0;     }     if (n == 2) {       if (x[0] == x[1] || y[0] == y[1]) {         cout << -1 << endl;         return 0;       }       long long s = (abs(x[0] - x[1]) * abs(y[0] - y[1]));       cout << s << endl;       return 0;     }     long long X = 0, Y = 0;     for (int i = 1; i < n; i++) {       X = max(X, abs(x[0] - x[i]));       Y = max(Y, abs(y[0] - y[i]));     }     cout << X * Y << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)3e5 + 7;   char read_char() {     char c;     for (;;) {       c = getchar();       if (c >=  A  && c <=  Z ) return c;     }   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= MOD;     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long add(long long a, long long b) {     a = ((a + b) % MOD + MOD) % MOD;     return a;   }   long long mul(long long a, long long b) { return a * b % MOD; }   int n, p, cnt[N], tmp[N];   pair<int, int> a[N];   void Init() {     memset(cnt, 0, sizeof(cnt));     for (int i = (0); i < (n); ++i) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       a[i].first = u, a[i].second = v;       cnt[u]++;       cnt[v]++;     }     for (int i = (1); i < (n + 1); ++i) tmp[i] = cnt[i];     sort(tmp + 1, tmp + n + 1);     sort(a, a + n);   }   int Solve() {     long long ans = 0;     for (int i = n, j = 1; j < i; i--) {       while (tmp[j] + tmp[i] < p && j < i) j++;       ans += i - j;     }     for (int i = 0, j; i < n; i = j) {       j = i + 1;       while (j < n && a[i] == a[j]) j++;       int u = a[i].first, v = a[i].second;       if (cnt[u] + cnt[v] >= p && cnt[u] + cnt[v] - (j - i) < p) {         ans--;       }     }     return !printf( %lld n , ans);   }   int main() {     while (~scanf( %d%d , &n, &p)) {       Init();       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> s;   long long n, b[500005], c[500005];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       s[x]++;     }     long long m, mx1 = 0, mx2 = 0, index = 1;     cin >> m;     for (int i = 0; i < m; i++) {       cin >> b[i];     }     for (int i = 0; i < m; i++) {       cin >> c[i];     }     for (int i = 0; i < m; i++) {       if (s[b[i]] > mx1) {         mx1 = s[b[i]];         index = i + 1;       }     }     for (int i = 0; i < m; i++) {       if (s[b[i]] == mx1) {         if (s[c[i]] > mx2) {           index = i + 1;           mx2 = s[c[i]];         }       }     }     cout << index << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1010;   const double EPS = 0.0000001;   struct Point {     int x, y;     Point() {}     Point(int a, int b) : x(a), y(b) {}   };   int n;   long long k;   Point centers[MAX_N];   int radii[MAX_N];   double GetDist(int x1, int y1, int x2, int y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   void AddEvents(vector<pair<double, int> > &events, double ang1, double ang2) {     for (int i = 0; i < 3; ++i) {       events.push_back(make_pair(ang1 + i * 2 * M_PI + EPS, 1));       events.push_back(make_pair(ang2 + i * 2 * M_PI - EPS, -1));     }   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> x >> y >> radii[i];       centers[i] = Point(x, y);     }     int best = 0;     for (int i = 1; i <= n; ++i) {       vector<pair<double, int> > events;       int cnt = 0;       for (int j = 1; j <= n; ++j) {         if (i != j) {           double ang =               atan2(centers[j].y - centers[i].y, centers[j].x - centers[i].x);           double d =               GetDist(centers[i].x, centers[i].y, centers[j].x, centers[j].y);           double u1 = asin((radii[i] - radii[j]) / d);           double u2 = asin((radii[i] + radii[j]) / d);           AddEvents(events, ang + u1 - M_PI / 2, ang + u2 - M_PI / 2);           AddEvents(events, ang - u2 + M_PI / 2, ang - u1 + M_PI / 2);         }       }       sort(events.begin(), events.end());       for (size_t j = 0; j < events.size(); ++j) {         cnt += events[j].second;         if (cnt < 0) {           cnt = 0;         }         best = max(best, cnt);       }     }     long long sol = k * (k + 1) / 2 + (k + 1) * best + (n - best);     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long calc(const long long &x, const long long &pow, const long long &pp) {     long long res = 1, tmp = (x % pp);     long long cur = pow;     while (cur > 0) {       if (cur % 2 == 0) {         tmp = (tmp * tmp) % pp;         cur = cur / 2;       } else {         res = (res * tmp) % pp;         cur = cur - 1;       }     }     return res;   }   int obr() {     long long k, l, r, p;     cin >> k >> l >> r >> p;     long long ans;     if (p == 2) {       cout << (1 - (k % 2)) << endl;       return 0;     }     if (k == 1)       ans = 2 % p;     else {       long long st_l = calc(2, l, p - 1), st_r = calc(2, r + 1, p - 1);       long long rev_2 = (p + 1) / 2;       long long ch = (calc(k, st_r, p) + p - 1) % p;       long long zn = (calc(k, st_l, p) + p - 1) % p;       if (k % p == 0) zn = ch = p - 1;       if (zn == 0) {         ch = calc(2, r - l + 1, p);       } else {         zn = calc(zn, p - 2, p);         ch = (ch * zn) % p;       }       if (k % 2) {         long long to_div = calc(rev_2, r - l, p);         ch = (ch * to_div) % p;       }       ans = ch;     }     cout << ans << endl;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     for (int i = 1; i <= t; ++i) obr();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int x[500010], y[500010];   bitset<2010 * 2> A[2010];   void Work() {     for (int i = 1; i <= n; i++) {       int t = i;       for (int j = i + 1; j <= n; j++)         if (A[j][i]) t = j;       swap(A[i], A[t]);       for (int j = 1; j <= n; j++)         if (A[j][i] && j != i) A[j] ^= A[i];     }     for (int i = 1; i <= m; i++)       if (A[y[i]][x[i] + n])         puts( NO );       else         puts( YES );   }   void Init() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x[i], &y[i]);       A[x[i]][y[i]] = 1;     }     for (int i = 1; i <= n; i++) A[i][i + n] = 1;   }   int main() {     Init();     Work();     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 60;   int n, P, A[MAXN];   const int mod = 1000000007;   void reduce(int& x) { x += x >> 31 & mod; }   int mul(int a, int b) { return (long long)a * b % mod; }   int pow(int a, int b, int res = 1) {     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) res = mul(res, a);     return res;   }   int dp[MAXN][MAXN][MAXN];   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     std::cin >> n >> P;     for (int i = 1; i <= n; ++i) std::cin >> A[i];     dp[0][0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= i; ++j)         for (int k = 0; k <= i; ++k)           if (dp[i - 1][j][k]) {             if (A[i] == 0 || A[i] == -1) {               int t = pow(2, i - 1 - (!!k), dp[i - 1][j][k]);               reduce(dp[i][j + 1][k] += t - mod);               if (k) reduce(dp[i][j][k] += t - mod);             }             if (A[i] == 1 || A[i] == -1) {               int t = pow(2, i - 1 - (!!j), dp[i - 1][j][k]);               reduce(dp[i][j][k + 1] += t - mod);               if (j) reduce(dp[i][j][k] += t - mod);             }           }     int ans = 0;     for (int i = 0; i <= n; ++i)       for (int j = 0; j <= n; ++j)         if ((i + j & 1) == P) reduce(ans += dp[n][i][j] - mod);     std::cout << ans << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[200001], t1[200001];     long long n, x, y, t, con = 0;     cin >> n >> x >> y;     getchar();     gets(s);     t = n - x;     for (long long i = t; s[i] !=   0 ; i++) {       if (i == n - 1 - y && s[i] !=  1 ) con++;       if (i != n - 1 - y && s[i] !=  0 ) con++;     }     cout << con << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, r;     cin >> k >> r;     int n = 1;     while (true) {       if ((k * n - r) % 10 == 0 || (k * n) % 10 == 0) {         cout << n <<   n ;         return 0;       }       n++;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c h, c n) {     return {h, n};   }   template <class c>   auto dud(c* r) -> decltype(cerr << *r);   template <class c>   char dud(...);   struct muu {     template <class c>     muu& operator<<(const c&) {       return *this;     }     muu& operator()() { return *this; }   };   const int N = 1e5 + 7;   long long tab[N];   int n;   long long inf = 1e18;   void fail() {     printf( No n );     exit(0);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i += 2) scanf( %lld , tab + i);     long long sum = 0;     for (int i = 2; i <= n; i += 2) {       long long nsum = inf;       for (int d = 1; d * d <= tab[i]; ++d) {         if (tab[i] % d == 0) {           long long a = (tab[i] / d) - d;           long long b = (tab[i] / d) + d;           if (a % 2 == 0 && b % 2 == 0) {             if (a * a > 4 * sum) {               nsum = min(nsum, (b * b) / 4);             }           }         }       }       (muu() << __FUNCTION__ <<  #  << 67 <<  :  ) << i <<     << nsum;       if (nsum == inf) fail();       tab[i - 1] = nsum - sum - tab[i];       sum = nsum;     }     printf( Yes n );     for (int i = 1; i <= n; ++i) printf( %lld  , tab[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50;   vector<int> e[N];   int dp[N], res, deg[N];   void dfs(int u, int pre) {     dp[u] = deg[u];     for (int v : e[u]) {       if (v == pre) continue;       dfs(v, u);       res = max(res, dp[u] + dp[v]);       dp[u] = max(dp[u], dp[v] + deg[u] - 2 + 1);     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) e[i].clear(), deg[i] = 0;       for (int i = 0; i < n - 1; i++) {         int u, v;         scanf( %d%d , &u, &v);         e[u].push_back(v);         e[v].push_back(u);         deg[u]++;         deg[v]++;       }       res = 0;       dfs(1, 0);       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int maxN = (int)1e6 + 10;   vector<int> g[maxN];   int p[maxN];   int a[maxN];   long long s = 0;   long long tr[maxN];   set<long long> all;   void dfs(int v) {     tr[v] = a[v];     for (int to : g[v]) {       dfs(to);       tr[v] += tr[to];     }     if (s % tr[v] == 0) {       all.insert(tr[v]);     }   }   int val[maxN];   const int mod = (int)1e9 + 7;   int sum(int a, int b) {     int s = a + b;     if (s >= mod) s -= mod;     return s;   }   set<long long> ok;   long long id[maxN];   long long sm[maxN];   map<long long, int> f;   int dp[maxN];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     for (int i = 1; i < n; i++) {       cin >> p[i];       g[p[i]].push_back(i + 1);     }     dfs(1);     int sz = 1;     int oth = 1;     for (long long t : all) {       memset(sm, 0, sizeof sm);       bool can = true;       for (int i = n; i >= 1; i--) {         if (sm[i] + a[i] > t) {           can = false;           break;         }         if (sm[i] + a[i] == t) {           continue;         }         if (i == 1) {           can = false;           break;         }         sm[p[i - 1]] += (sm[i] + a[i]);       }       if (can) {         f[t] = oth;         oth++;         ok.insert(t);       }     }     for (long long x : ok) {       int id = f[x];       dp[id] = 1;       for (long long y : ok) {         if (y >= x) continue;         if (x % y == 0) dp[id] = sum(dp[id], dp[f[y]]);       }     }     cout << dp[f[s]];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)2e5 + 7;   int tree[N << 1];   void update(int x, int n) {     x += n;     if (tree[x]) return;     while (x) {       tree[x]++;       x >>= 1;     }   }   int query(int l, int r, int n) {     int re = 0;     l += n, r += n;     while (l <= r) {       if (l & 1) re += tree[l++];       if (~r & 1) re += tree[r--];       l >>= 1, r >>= 1;     }     return re;   }   pair<int, int> p[N];   vector<int> x;   int l[N];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i) {       scanf( %d%d , &p[i].first, &p[i].second);       x.push_back(p[i].first);     }     sort((x).begin(), (x).end());     sort(p, p + n);     for (int i = (0); i < (n); ++i) {       p[i].first = lower_bound((x).begin(), (x).end(), p[i].first) - x.begin();       swap(p[i].first, p[i].second);     }     sort(p, p + n);     long long ans = 0;     for (int i = n - 1, j; i >= 0; i = j) {       for (j = i; j >= 0 && p[i].first == p[j].first; j--)         ;       int z = 0;       for (int k = (j + 1); k < (i + 1); ++k) {         l[k] = query(z, p[k].second - 1, n);         update(p[k].second, n);         z = p[k].second + 1;       }       for (int k = (j + 1); k < (i + 1); ++k) {         ans += (long long)(l[k] + 1) * (query(p[k].second + 1, n, n) + 1);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double l, p, q;     cin >> l >> p >> q;     double qq = l / (p + q) * p;     cout << setiosflags(ios::fixed);     cout << setprecision(4) << qq;   }


#include <bits/stdc++.h>   using namespace std;   long long exp(long long x, long long y) {     x %= 1000000007;     long long res = 1;     while (y) {       if (y & 1) res = res * x % 1000000007;       x = x * x % 1000000007;       y >>= 1;     }     return res;   }   long long fact(long long n) {     long long res = 1;     for (long long i = 2; i <= n; ++i) (res *= i) %= 1000000007;     return res;   }   bool isprime(long long n) {     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   int main() {     int n, m;     cin >> n >> m;     const long long inf = 1e17;     vector<long long> sum(n), pre(n), s(n);     vector<long long> t(n);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       long long val = -inf;       long long mx = -inf;       vector<long long> v1, v2;       for (int j = 0; j < x; ++j) {         long long k;         cin >> k;         val = max(k, val + k);         mx = max(mx, val);         v1.push_back(k);         v2.push_back(k);       }       t[i] = mx;       for (int j = 1; j < x; ++j) v1[j] += v1[j - 1];       for (int j = x - 2; j >= 0; --j) v2[j] += v2[j + 1];       sum[i] = v1[x - 1];       pre[i] = *max_element(v1.begin(), v1.end());       s[i] = *max_element(v2.begin(), v2.end());     }     long long to = -inf;     vector<int> v(m + 1);     for (int i = 1; i <= m; ++i) {       cin >> v[i];       to = max(to, t[v[i] - 1]);     }     long long dp[m + 1][3];     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= m; ++i) {       dp[i][0] = s[v[i] - 1];       dp[i][1] = max(dp[i - 1][0] + sum[v[i] - 1], dp[i - 1][1] + sum[v[i] - 1]);       dp[i][2] = max(dp[i - 1][0] + pre[v[i] - 1], dp[i - 1][1] + pre[v[i] - 1]);     }     long long ans = -inf;     for (int i = 1; i <= m; ++i) ans = max(ans, dp[i][2]);     cout << max(ans, to);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = -1;   struct disk {     long long L;     double p;     disk(long long L = 0, double p = 0.) : L(L), p(p) {}   };   bool operator<(disk a, disk b) {     return (a.L * a.p * (1 - b.p)) > (b.L * b.p * (1 - a.p));   }   int n;   vector<disk> P;   int main() {     while (cin >> n) {       P.resize(n);       for (int i = (0); i < (int)(n); i++)         scanf( %lld %lf , &P[i].L, &P[i].p), P[i].p /= 100;       sort(P.begin(), P.end());       double ans = 0., E = 0.;       for (int i = ((int)n) - 1; i >= 0; i--) {         disk D = P[i];         ans += D.L * (1 + E * D.p);         E = D.p * E + (1 - D.p) * (E + 1);       }       printf( %.6f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, n, now, ans, hh, m, p = 1000000009;   int main() {     scanf( %lld , &n);     if (n == 2) {       puts( 10 );       return 0;     }     m = n / 2;     now = 4;     hh = 1;     for (i = 3; i <= m; i++) {       now = now * 2 % p;       hh = hh * (now - 3) % p;       ans = (ans + hh) % p;     }     ans = ans * 4 + 6;     ans %= p;     ans = ans * ans % p;     ans++;     ans = ans * 2 % p;     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int m(int x, int md) { return (((x) % md) + md) % md; }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     set<int> st;     for (int r = 0; r < n; r++) {       st.insert(m(r + a[r], n));     }     if (st.size() == n)       cout <<  YES n ;     else       cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     for (int testcase = 1; testcase <= T; testcase++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct event {     int pos, type, p;     event(int pos = 0, int type = -1, int p = 0) : pos(pos), type(type), p(p) {}     bool operator<(const event &e) const {       if (pos == e.pos) return type < e.type;       return pos < e.pos;     }   };   const int maxE = 5e5 + 10;   event E[maxE];   int cnt[111];   double fpow(double a, int n) {     double r = 1;     for (; n; n = n >> 1) {       if (n & 1) r *= a;       a = a * a;     }     return r;   }   int main() {     memset((cnt), (0), sizeof(cnt));     int n, m, x, h, l, r, sz = 0, b, z;     scanf( %d%d , &n, &m);     for (int _n(n), i(0); i < _n; i++) {       scanf( %d%d%d%d , &x, &h, &l, &r);       l = 100 - l;       r = 100 - r;       E[sz++] = event(x - h, 0, l);       E[sz++] = event(x, 0, -1 - l);       E[sz++] = event(x + 1, 0, r);       E[sz++] = event(x + h + 1, 0, -1 - r);     }     for (int _n(m), i(0); i < _n; i++) {       scanf( %d%d , &b, &z);       E[sz++] = event(b, z);     }     sort(E, E + sz);     double expectation = 0, pro = 0;     for (int _n(sz), i(0); i < _n; i++) {       if (E[i].type == 0) {         if (E[i].p >= 0) {           cnt[E[i].p]++;         } else           cnt[-E[i].p - 1]--;       } else {         pro = 1;         for (int _n(101), i(0); i < _n; i++) pro *= fpow(0.01 * i, cnt[i]);         expectation += pro * E[i].type;       }     }     printf( %.7f n , expectation);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100011;   const long long INF = (1 << 29) + 123;   const long long MOD = 1000000007;   const long double PI = 4 * atan((long double)1);   int fenw[2 * MAX_N];   int n;   void mod(int i, int v) {     while (i <= n) {       fenw[i] += v;       i += i & -i;     }   }   int query(int i) {     int sum = 0;     while (i > 0) {       sum += fenw[i];       i -= i & -i;     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<pair<int, int> > p;     int x[n], v[n];     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) {       cin >> v[i];       p.push_back(make_pair(v[i], x[i]));     }     unordered_map<int, int> m;     int rev_map[n];     sort(x, x + n);     for (int i = 0; i < n; i++) {       m[x[i]] = i + 1;       rev_map[i] = x[i];     }     for (int i = 0; i < n; i++) {       p[i].second = m[p[i].second];     }     sort(p.begin(), p.end());     long long ans = 0;     for (int i = 0; i < n; i++) {       int q = query(p[i].second);       ans += 1LL * q * rev_map[p[i].second - 1];       ans -=           1LL * ((n - i - 1) - (p[i].second - 1 - q)) * rev_map[p[i].second - 1];       mod(p[i].second, 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p1 = 0, p2 = 0;     cin >> n;     int mid[1000], index = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a % 2 == 0) {         for (int j = 1; j <= (a / 2); j++) {           int t;           cin >> t;           p1 += t;         }         for (int j = 1; j <= (a / 2); j++) {           int t;           cin >> t;           p2 += t;         }       } else {         for (int j = 1; j <= (a / 2); j++) {           int t;           cin >> t;           p1 += t;         }         cin >> mid[index++];         for (int j = 1; j <= (a / 2); j++) {           int t;           cin >> t;           p2 += t;         }       }     }     sort(mid, mid + index);     for (int i = index - 1; i >= 0; i--) {       if (((index - 1) % 2 == 0 && i % 2 == 0) ||           ((index - 1) % 2 == 1 && i % 2 == 1))         p1 += mid[i];       else         p2 += mid[i];     }     cout << p1 <<     << p2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6010;   vector<int> a[N];   int L[N], cnt, r[N], n, res = 0;   void Refresh() {     L[0] = cnt = 0;     for (int i = 1; i <= n + 1; i++) L[i] = 10000000;   }   void DFS(int u, int p) {     int Oldval, Oldid, Oldcnt = cnt;     if (cnt == 0 || r[u] > L[cnt])       L[++cnt] = r[u];     else {       Oldid = lower_bound(L, L + n + 1, r[u]) - L;       Oldval = L[Oldid];       L[Oldid] = r[u];     }     res = max(res, cnt);     for (int i = 0; i < a[u].size(); i++) {       int v = a[u][i];       if (v != p) DFS(v, u);     }     if (Oldcnt != cnt)       L[cnt--] = 10000000;     else       L[Oldid] = Oldval;   }   int main() {     ios_base::sync_with_stdio(0);     int u, v;     cin >> n;     for (int i = 1; i <= n; i++) cin >> r[i];     for (int i = 1; i < n; i++) {       cin >> u >> v;       a[u].push_back(v);       a[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       Refresh();       DFS(i, 0);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pow1(int a, int b) {     long long res = 1;     for (int i = 1; i <= b; i++) res *= a;     return res;   }   int main() {     int n;     cin >> n;     long long sum = 2 * (pow1(2, n) - 1);     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     std::cout.precision(12);     int t;     cin >> t;     while (t--) {       bool f = 0;       int n, m;       cin >> n >> m;       char a[n][m];       char ans[n][m];       vector<pair<int, int>> v[26];       int ma = -1;       int r, c;       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           cin >> a[i][j];           ans[i][j] =  . ;           if (a[i][j] >= 97 && a[i][j] <=  z ) {             v[a[i][j] -  a ].push_back({i + 1, j + 1});             if (a[i][j] -  a  > ma) {               ma = a[i][j] -  a ;               r = i + 1;               c = j + 1;             }           }         }       }       vector<pair<int, int>> start[ma + 1], end[ma + 1];       for (long long int i = 0; i < ma + 1; i++) {         if (v[i].size() == 0) {           start[i].push_back({r, c});           end[i].push_back({r, c});         } else if (v[i].size() == 1) {           ans[v[i][0].first - 1][v[i][0].second - 1] =  a  + i;           start[i].push_back({v[i][0].first, v[i][0].second});           end[i].push_back({v[i][0].first, v[i][0].second});         } else {           if (v[i][1].first == v[i][0].first) {             int mi = m + 6, m = 0;             for (int j = 0; j < v[i].size(); j++) {               if (v[i][j].first != v[i][0].first) {                 f = 1;                 break;               }               mi = min(mi, v[i][j].second);               m = max(m, v[i][j].second);             }             if (f == 1) break;             for (int j = mi - 1; j < m; j++) {               ans[v[i][0].first - 1][j] =  a  + i;             }             start[i].push_back({v[i][0].first, mi});             end[i].push_back({v[i][0].first, m});           } else if (v[i][1].second == v[i][0].second) {             int mi = n + 6, m = 0;             for (int j = 0; j < v[i].size(); j++) {               if (v[i][j].second != v[i][0].second) {                 f = 1;                 break;               }               mi = min(mi, v[i][j].first);               m = max(m, v[i][j].first);             }             if (f == 1) break;             for (int j = mi - 1; j < m; j++) {               ans[j][v[i][0].second - 1] =  a  + i;             }             start[i].push_back({mi, v[i][0].second});             end[i].push_back({m, v[i][0].second});           } else {             f = 1;             break;           }         }       }       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           if (a[i][j] != ans[i][j]) {             f = 1;             break;           }         }         if (f == 1) break;       }       if (f == 0) {         cout <<  YES n ;         cout << ma + 1 << endl;         for (long long int i = 0; i < ma + 1; i++)           cout << start[i][0].first <<     << start[i][0].second <<                    << end[i][0].first <<     << end[i][0].second << endl;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const long long linf = 4000000000000000000LL;   const long long inf = 998244353;   const long double pi = 3.1415926535;   void pv(vector<int> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<long long> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<vector<int>> a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);       cout <<   n ;     }   }   void pv(vector<vector<long long>> a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);     }     cout <<   n ;   }   void pv(vector<string> a) {     for (auto& x : a) cout << x <<   n ;     cout <<   n ;   }   void build_primes(vector<int>& primes, int size) {     vector<int> visited;     visited.resize(size, 0);     for (int i = (2); i < (size); ++i) {       if (visited[i] == 0) {         primes.push_back(i);         int a = i;         while (a < size) {           visited[a] = 1;           a += i;         }       }     }   }   vector<vector<long long>> matrix_mult(vector<vector<long long>>& a,                                         vector<vector<long long>>& b) {     int n = a.size();     vector<vector<long long>> answer;     answer.resize(n);     for (int i = 0; i < n; i++) answer[i].resize(n, 0);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < n; k++)           answer[i][j] = (answer[i][j] + a[i][k] * b[k][j]) % inf;       }     }     return answer;   }   int modInverse(int a, int m) {     int m0 = m;     int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       int q = a / m;       int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long power(long long x, long long y) {     long long k = 1LL << 60;     long long z = 1;     while (k != 0) {       z *= z;       z %= inf;       if (y >= k) {         z *= x;         z %= inf;         y -= k;       }       k >>= 1;     }     return z;   }   struct point {     long double x, y;     bool operator<(const point& rhs) const {       if (x == rhs.x) return y < rhs.y;       return x < rhs.x;     }   };   struct pt {     long long x, y;     bool operator<(const point& rhs) const {       if (x == rhs.x) return y < rhs.y;       return x < rhs.x;     }   };   long double area(point x, point y, point z) {     return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y -             z.x * x.y) /            2.0;   }   bool clockwise(point x, point y, point z) { return area(x, y, z) > 0; }   long double area(pt x, pt y, pt z) {     return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y -             z.x * x.y) /            2.0;   }   bool clockwise(pt x, pt y, pt z) { return area(x, y, z) > 0; }   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(a, b % a);   }   int popcount(long long a) {     int count = 0;     while (a) {       count += (a & 1);       a >>= 1;     }     return count;   }   long long choose(long long n, long long r) {     long long p = 1, k = 1;     if (n - r < r) r = n - r;     if (r != 0) {       while (r) {         p *= n;         k *= r;         long long m = gcd(p, k);         p /= m;         k /= m;         n--;         r--;       }     } else       p = 1;     return p;   }   vector<long long> prefix_hash(string& a, vector<long long>& powers) {     int n = int(a.size());     vector<long long> prefix(n + 1);     for (int i = (0); i < (n); ++i)       prefix[i + 1] = (prefix[i] + powers[i] * (a[i] -  a  + 1)) % inf;     return prefix;   }   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     uint64_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   struct custom_hash_fast {     uint64_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       x ^= FIXED_RANDOM;       return x ^ (x >> 16);     }   };   void setIO(string second) {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int main() {     setIO(  );     int testc;     cin >> testc;     while (testc--) {       int n;       cin >> n;       string a;       cin >> a;       int i = n - 1;       for (; i >= 0; i--)         if ((a[i] -  0 ) & 1) break;       if (i == -1) {         cout << -1 <<   n ;         continue;       }       int j = 0;       for (; j < i; j++) {         if ((a[j] -  0 ) % 2 == 1) break;       }       if (j == i) {         cout << -1 <<   n ;         continue;       }       cout << a[j] << a[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       int cardsPlayer = n / k;       double maxCard;       int jokerMax = min(m, cardsPlayer);       maxCard = ceil((m - jokerMax) / (k - 1.0));       if (jokerMax - maxCard > 0)         cout << jokerMax - maxCard << endl;       else         cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     long long j, x1, x2;   } inter;   struct comp1 {     bool operator()(const inter& a, const inter& b) const { return a.x1 < b.x1; };   };   struct comp2 {     bool operator()(const inter& a, const inter& b) const {       return (a.x2 == b.x2) ? (a.x1 < b.x1) : (a.x2 < b.x2);     };   };   void solve() {     long long n;     cin >> n;     vector<long long> a(n), b(n), m(n);     unordered_map<long long, vector<long long>> dsize;     for (long long i = 0; i < (n); i++) {       cin >> a[i] >> b[i] >> m[i];       dsize[a[i] + b[i] - m[i]].push_back(i);     }     long long c = 0;     vector<long long> ea(n);     for (auto& x : dsize) {       multiset<inter, comp1> inter1;       multiset<inter, comp2> inter2;       for (auto& i : x.second) {         long long eamax = min(m[i], a[i]);         long long eamin = max(m[i] - b[i], 0LL);         inter1.insert(inter{i, a[i] - eamax, a[i] - eamin});         inter2.insert(inter{i, a[i] - eamax, a[i] - eamin});       }       auto p1 = inter1.begin();       while (!inter2.empty()) {         long long targ = inter2.begin()->x2;         while ((p1 == inter1.end()) ? false : (p1->x1 <= targ)) {           inter2.erase(*p1);           ea[p1->j] = a[p1->j] - targ;           p1++;         }         c++;       }     }     cout << c << endl;     for (long long i = 0; i < (n); i++)       cout << ea[i] <<     << m[i] - ea[i] << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ifstream ifs;     if (  [0]) cin.rdbuf((ifs = ifstream(  )).rdbuf());     ;     ofstream ofs;     if (  [0]) cout.rdbuf((ofs = ofstream(  )).rdbuf());     ;     ofstream lfs;     if (  [0]) clog.rdbuf((lfs = ofstream(  )).rdbuf());     ;     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long a[2000], dp[2000];   long long qmod(long long y) {     long long res = 1, two = (long long)2;     for (; y; y >>= 1) {       if (y & 1) res = res * two % mod;       two = two * two % mod;     }     return res;   }   int main() {     long long x, y;     int cnt = 0;     scanf( %lld%lld , &x, &y);     if (y % x) return 0 * puts( 0 );     for (long long i = 1; i <= sqrt(y); ++i) {       if (y % i == 0) {         if (i % x == 0) a[++cnt] = i;         if (i * i != y && y / i % x == 0) a[++cnt] = y / i;       }     }     sort(a + 1, a + 1 + cnt);     for (int i = cnt; i > 0; --i) {       dp[i] = qmod(y / a[i] - 1);       for (int j = i + 1; j <= cnt; ++j)         if (a[j] % a[i] == 0) dp[i] = ((dp[i] - dp[j]) % mod + mod) % mod;     }     printf( %lld n , dp[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void Input_Output() {}   const double eps = 0.000001;   const long double pi = acos(-1);   const int maxn = 1e7 + 9;   const int mod = 1e9 + 7;   const long long MOD = 1e18 + 9;   const long long INF = 1e18 + 123;   const int inf = 2e9 + 11;   const int mxn = 1e6 + 9;   const int N = 6e5 + 123;   const int K = 80;   const int pri = 997;   const int Magic = 2101;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, -1, 0, 1};   int n, m, k, x;   vector<int> state;   int ids[(1 << 8)];   struct Mat {     long long d[K][K];     Mat(long long val = INF) {       for (int i = 0; i < K; ++i)         for (int j = 0; j < K; ++j) d[i][j] = INF;       for (int i = 0; i < K; ++i) d[i][i] = val;     }     Mat operator+(Mat &b) {       Mat res;       for (int i = 0; i < K; ++i)         for (int j = 0; j < K; ++j)           for (int k = 0; k < K; ++k)             res.d[i][j] = min(res.d[i][j], d[i][k] + b.d[k][j]);       return res;     }     void print() {       for (int i = 0; i < K; ++i) {         for (int j = 0; j < K; ++j) {           if (d[i][j] == INF) {             cout <<  bd  ;             continue;           }           cout << d[i][j] <<    ;         }         cout <<   n ;       }     }   };   Mat make_matrix(vector<long long> &c) {     assert((int)(c.size()) == k);     Mat res;     for (int id = 0; id < (int)(state.size()); ++id) {       int msk = state[id];       if (msk % 2 == 0) {         int nmsk = msk / 2;         res.d[id][ids[nmsk]] = 0;         continue;       }       for (int i = 0; i < k; ++i) {         int nmsk = (msk >> 1);         if (nmsk & (1 << i)) {           continue;         }         nmsk |= (1 << i);         res.d[id][ids[nmsk]] = min(res.d[id][ids[nmsk]], c[i]);       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> x >> k >> n >> m;     for (int msk = 0; msk < (1 << k); ++msk) {       ids[msk] = -1;       if (__builtin_popcount(msk) != x) {         continue;       }       ids[msk] = (int)(state.size());       state.push_back(msk);     }     vector<long long> c(k);     for (auto &e : c) cin >> e;     vector<int> pos = {0, n - x};     vector<pair<int, int> > spec(m);     for (auto &it : spec) {       cin >> it.first >> it.second;       it.first--;       for (int i = 0; i <= k; ++i) {         int s = it.first - i;         s = max(s, 0);         s = min(s, n - x);         pos.push_back(s);       }     }     sort(pos.begin(), pos.end());     pos.resize(unique(pos.begin(), pos.end()) - pos.begin());     vector<Mat> Pw;     Pw.push_back(make_matrix(c));     int bit = 0;     while ((1 << bit) <= n) {       ++bit;       Pw.push_back(Pw.back() + Pw.back());     }     Mat cur = 0;     for (int it = 0; it + 1 < (int)(pos.size()); ++it) {       int l = pos[it], r = pos[it + 1];       vector<long long> nc = c;       for (auto s : spec) {         if (s.first > l && s.first <= l + k) {           nc[s.first - l - 1] += s.second;         }       }       if (nc != c) {         Mat cn = make_matrix(nc);         cur = cur + cn;       } else {         int dif = r - l;         for (int i = 0; i < (int)(Pw.size()); ++i) {           if (dif & (1 << i)) {             cur = cur + Pw[i];           }         }       }     }     int fin = (1 << x) - 1;     fin = ids[fin];     assert(fin != -1);     cout << cur.d[fin][fin] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[2][100005];   char c[2][100005];   int main() {     queue<pair<int, pair<int, int> > > q;     bool flag = 0;     int n, k;     cin >> n >> k;     scanf( %s%s , c[0], c[1]);     q.push(make_pair(0, make_pair(0, 0)));     while (!q.empty()) {       int x = q.front().first, y = q.front().second.first,           de = q.front().second.second;       q.pop();       if (y >= n) {         flag = 1;         break;       }       if (vis[x][y] || de > y) continue;       vis[x][y] = 1;       if (y - 1 >= 0 && c[x][y - 1] !=  X  && y - 1 >= de + 1 && !vis[x][y - 1]) {         q.push(make_pair(x, make_pair(y - 1, de + 1)));       }       if (y + 1 >= n || (c[x][y + 1] !=  X  && !vis[x][y + 1])) {         q.push(make_pair(x, make_pair(y + 1, de + 1)));       }       if (y + k >= n || (c[x ^ 1][y + k] !=  X  && !vis[x ^ 1][y + k])) {         q.push(make_pair(x ^ 1, make_pair(y + k, de + 1)));       }     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n, k, sum = 0;     cin >> n >> k;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     string s;     cin >> s;     vector<long long int> v;     v.push_back(a[0]);     for (long long int i = 1; s[i]; i++) {       if (s[i] == s[i - 1])         v.push_back(a[i]);       else {         sort(v.rbegin(), v.rend());         for (long long int i = 0; i < k && i < v.size(); i++) {           sum += v[i];         }         v.clear();         v.push_back(a[i]);       }     }     sort(v.rbegin(), v.rend());     for (long long int i = 0; i < k && i < v.size(); i++) sum += v[i];     cout << sum;   }


#include<bits/stdc++.h>   using namespace std;   int a[10];   int main() {       int T;scanf( %d ,&T);       while(T--) {           int sum = 0;           for(int i = 1;i <= 3;i++) {               scanf( %d ,&a[i]);               sum += a[i];           }           if(sum % 9 == 0) {               if(a[1] >= sum / 9 && a[2] >= sum / 9 && a[3] >= sum / 9) {                   printf( YES n );               } else {                   printf( NO n );               }           } else {               printf( NO n );           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ld = long double;   using vi = vector<int>;   using vll = vector<ll>;   using vd = vector<double>;   using vvi = vector<vi>;   int ctoi(char c) { return c -  0 ; }   int slen(string s) { return s.length(); }   int vsize(vi a) { return (int)a.size(); }   int in() {     int x;     cin >> x;     return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int N;     cin >> N;     vi d(N);     for (auto& x : d) cin >> x;     int mn = abs(d[N - 1] - d[0]);     int a = N - 1, b = 0;     for (int i = 1; i < N; i++) {       if (abs(d[i] - d[i - 1]) < mn) {         mn = abs(d[i] - d[i - 1]);         a = i;         b = i - 1;       }     }     cout << a + 1 <<     << b + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int result = 0;     for (int i = 0; i < n; i++) {       int k, a;       cin >> k >> a;       long x = k * a;       int c = 0;       if (a % 4 == 0) a--;       while (a) {         a /= 4;         c++;       }       result = (((result) < (k + c)) ? (k + c) : (result));     }     cout << result;   }


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


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 100010;   int x0[maxn], x1[maxn], d[maxn], c[maxn];   int main() {     int n, m, y0, y1;     scanf( %d %d %d %d , &n, &m, &y0, &y1);     for (int i = 0; i < n; ++i) {       scanf( %d , &x0[i]);     }     memset(d, -1, sizeof(d));     for (int i = 0; i < m; ++i) {       scanf( %d , &x1[i]);     }     int p = 0, k = 0, last = -1;     for (int i = 0; i < n; ++i) {       while (p < m && abs(x0[i] - x1[p]) > abs(x0[i] - x1[p + 1])) ++p;       if (last < p || abs(x0[i - 1] - x1[p]) == abs(x0[i] - x1[p]))         ++k, last = p;       else if (p < m && abs(x0[i] - x1[p]) == abs(x0[i] - x1[p + 1]))         ++k, last = ++p;       else         last = p;     }     printf( %d n , n - k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     long long int x = a.length();     std::vector<long long int> v;     long long int c = 0;     long long int d = 0;     for (long long int i = 0; i < x; i++) {       if (a[i] ==  b ) {         d++;       }       if (a[i] ==  a ) {         if (d > 0 && c > 0) {           v.push_back(c);           d = 0;           c = 0;         }         c++;         d = 0;       }     }     if (c > 0) v.push_back(c);     long long int res = 1;     for (long long int i = 0; i < v.size(); i++) {       res = (res * (v[i] + 1)) % 1000000007;     }     cout << res - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[16], b[16];   int main() {     double cnt = 0;     ios::sync_with_stdio(false);     cin >> n;     for (register int i = 0; i < n; i++) cin >> a[i];     for (register int i = 0; i < n; i++) cin >> b[i];     for (register int i = 0; i < 1e6; ++i) {       register bool f = false;       for (register int j = 0; !f && j < n; ++j) f |= i % a[j] == b[j];       cnt += f;     }     cout.setf(ios::fixed, ios::floatfield);     return (cout << setprecision(7) << cnt / 1e6 << endl) && 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k1, k2;   long long a[1005];   long long b[1005];   void ReadData() {     cin >> n >> k1 >> k2;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];   }   long long c[1005];   void process() {     long long k = k1 + k2;     priority_queue<long long> heap;     for (long long i = 1; i <= n; i++) {       c[i] = abs(a[i] - b[i]);       heap.push(c[i]);     }     while (k--) {       long long tmp = heap.top();       heap.pop();       tmp--;       heap.push(abs(tmp));     }     long long res = 0;     while (!heap.empty()) {       long long tmp = heap.top();       heap.pop();       res += tmp * tmp;     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ReadData();     process();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1002, M = 10002;   pair<int, long long> dp[N][M];   map<long long, int> di;   bool vis[N][M];   int nxt[N][M];   long long a[N], b[N], k;   int T[M][N];   int n;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     scanf( %d %lld , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %lld , b + i);       a[i] = gcd(b[i], k);     }     if (k == 1) return printf( %d n%ld n , 1, min_element(b, b + n) - b + 1), 0;     vector<long long> divisor;     for (long long i = 1; i * i <= k; ++i)       if (k % i == 0) {         divisor.push_back(i);         divisor.push_back(k / i);       }     sort(divisor.begin(), divisor.end());     divisor.resize(unique(divisor.begin(), divisor.end()) - divisor.begin());     int m = divisor.size();     for (int i = 0; i < m; ++i) di[divisor[i]] = i;     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j)         T[i][j] = di[divisor[i] / gcd(divisor[i], a[j])];     nxt[n][0] = -1;     dp[n][0] = {0, 0};     for (int i = 1; i < m; ++i) dp[n][i] = {n + 1, 0};     for (int i = 0; i < m; ++i)       for (int j = n - 1; j >= 0; --j) {         pair<int, long long> ans1 = dp[j + 1][i];         pair<int, long long> ans2 = dp[j + 1][T[i][j]];         ans2.first += 1;         ans2.second += b[j];         if (ans1 <= ans2) {           nxt[j][i] = nxt[j + 1][i];           dp[j][i] = ans1;         } else {           nxt[j][i] = j;           dp[j][i] = ans2;         }       }     pair<int, long long> ans = dp[0][m - 1];     if (ans.first > n) return puts( -1 ), 0;     printf( %d n , ans.first);     int pos = 0;     int nx = m - 1;     while (pos != -1) {       if (nxt[pos][nx] != pos)         pos = nxt[pos][nx];       else {         nx = T[nx][pos];         printf( %d  , pos + 1);         pos += 1;       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int a[100005];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (n == 1) {       cout << -1 << endl;       return 0;     }     bool flag = true;     for (int i = 1; i < n; i++) flag = flag && (a[0] == a[i]);     if (flag) {       cout << 1 << endl;       cout << a[0] << endl;       return 0;     }     if (n == 2) {       if ((a[0] + a[1]) % 2 == 0)         cout << 3 << endl;       else         cout << 2 << endl;       cout << 2 * a[0] - a[1] <<    ;       if ((a[0] + a[1]) % 2 == 0) cout << (a[1] + a[0]) / 2 <<    ;       cout << 2 * a[1] - a[0] <<    ;       return 0;     }     flag = true;     for (int i = 2; i < n; i++) flag = flag && (a[1] - a[0] == a[i] - a[i - 1]);     if (flag) {       cout << 2 << endl;       cout << 2 * a[0] - a[1] <<    ;       cout << 2 * a[n - 1] - a[n - 2] << endl;       return 0;     }     vector<int> diff;     set<int> di;     for (int i = 1; i < n; i++) {       diff.push_back(a[i] - a[i - 1]);       di.insert(a[i] - a[i - 1]);     }     if (di.size() != 2) {       cout << 0 << endl;       return 0;     }     sort(diff.begin(), diff.end());     int chan = diff[n - 2];     if (chan != 2 * diff[0]) {       cout << 0 << endl;       return 0;     }     for (int i = n - 3; i >= 0; i--) {       if (diff[i] == chan || diff[i] != diff[0]) {         cout << 0 << endl;         return 0;       }     }     for (int i = 1; i < n; i++) {       if (a[i] - a[i - 1] == chan) {         if ((a[i] + a[i - 1]) % 2 == 0) {           cout << 1 << endl;           cout << (a[i] + a[i - 1]) / 2 << endl;           return 0;         } else {           cout << 0 << endl;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long int> fib(46, -1);   int adv_fib(int n) {     if (n == 0 || n == 1) {       return 1;     } else if (fib[n] == -1) {       return fib[n] = adv_fib(n - 1) + adv_fib(n - 2);     } else {       return fib[n];     }   }   int main() {     int n, curr = 1;     cin >> n;     for (int i = 1; i <= n; i++) {       if (adv_fib(curr) == i) {         cout <<  O ;         curr++;       } else {         cout <<  o ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (auto &x : v) cin >> x;     int mine = *min_element(v.begin(), v.end());     vector<int> temp;     for (int i = 0; i < n; i++) {       if (v[i] == mine) temp.push_back(i);     }     for (int i = 0; i < temp.size() - 1; i++) temp[i] = temp[i + 1] - temp[i];     cout << *min_element(temp.begin(), temp.end() - 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   int n, a[maxn], ans, maxx = 0;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       maxx = max(maxx, a[i]);     }     cout << maxx;     return 0;   }