#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 1];     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int sums = 0;     int sumd = 0;     bool turns = true;     int l = 0, r = n - 1;     while (l <= r) {       if (turns) {         sums += max(arr[l], arr[r]);         turns = false;         arr[l] > arr[r] ? l++ : r--;       } else {         sumd += max(arr[l], arr[r]);         turns = true;         arr[l] > arr[r] ? l++ : r--;       }     }     cout << sums <<     << sumd << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100005];   map<int, int> mymap;   int main() {     int n;     map<int, int>::iterator it;     int d;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       mymap[A[i]]++;       d = A[i];       while (mymap[d] % 2 == 0) {         mymap[d + 1]++;         mymap[d] = mymap[d] - 2;         d = d + 1;       }     }     int c = 0;     for (it = mymap.begin(); it != mymap.end(); it++) {       if (it->second == 1) c++;     }     it--;     cout << it->first - c + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string col[1000];   int main() {     cin >> n >> col[0];     for (int i = 1; i < 1000; ++i) col[i] = col[0];     for (int i = 0, a, b; i < n; ++i) {       scanf( %d%d , &a, &b);       char now = col[0][i];       for (int j = b; j < 1000; j += a) {         now =  0  +  1  - now;         for (int t = j; t < min(1000, j + a); ++t) col[t][i] = now;       }     }     int ans = 0;     for (int i = 0; i < 1000; ++i)       ans = max(ans, (int)count(col[i].begin(), col[i].end(),  1 ));     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 900;   vector<int> neighbours[MAXN + 1];   vector<int> neighboursNoBridge[MAXN + 1];   vector<pair<int, int> > bridges;   bool used[MAXN + 1];   int timer, tin[MAXN + 1], fup[MAXN + 1];   void dfs(int node, int parent = -1) {     used[node] = true;     tin[node] = fup[node] = timer++;     for (int child : neighbours[node]) {       if (child == parent) continue;       if (used[child])         fup[node] = min(fup[node], tin[child]);       else {         dfs(child, node);         fup[node] = min(fup[node], fup[child]);         if (fup[child] > tin[node])           bridges.push_back({node, child});         else           neighboursNoBridge[node].push_back(child),               neighboursNoBridge[child].push_back(node);       }     }   }   void find_bridges(int n) {     timer = 0;     for (int i = 1; i <= n; ++i) {       if (!used[i]) dfs(i);     }   }   int groupIndex[MAXN + 1];   vector<int> groupDegree;   vector<int> groupNodes[MAXN + 1];   void dfsEnumerate(int node) {     used[node] = true;     groupIndex[node] = timer;     groupNodes[timer].push_back(node);     for (int child : neighboursNoBridge[node]) {       if (!used[child]) dfsEnumerate(child);     }   }   bool usedGroup[MAXN + 1];   vector<int> groupLeaves;   void dfsOrder(int node) {     used[node] = true;     int gr = groupIndex[node];     if (!usedGroup[gr]) {       usedGroup[gr] = true;       if (groupDegree[gr] <= 1) groupLeaves.push_back(gr);     }     for (int child : neighbours[node]) {       if (!used[child]) dfsOrder(child);     }   }   void compress_graph(int n) {     timer = 1;     for (int i = 1; i <= n; ++i) used[i] = false;     for (int i = 1; i <= n; ++i) {       if (!used[i]) dfsEnumerate(i), timer++;     }   }   void compress_graph2(int n) {     groupDegree.resize(timer);     for (pair<int, int> edge : bridges) {       if (groupIndex[edge.first] != groupIndex[edge.second]) {         ++groupDegree[groupIndex[edge.first]];         ++groupDegree[groupIndex[edge.second]];       }     }     for (int i = 1; i <= n; ++i) used[i] = false;     dfsOrder(1);   }   int matrix[901][901];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       neighbours[a].push_back(b);       neighbours[b].push_back(a);       matrix[a][b] = matrix[b][a] = 1;     }     if (n == 2) {       cout << -1 << endl;       return 0;     }     find_bridges(n);     compress_graph(n);     int groupCount = timer - 1;     if (groupCount == 1) {       cout << 0 << endl;       return 0;     }     if (groupCount == 2) {       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           if (groupIndex[i] != groupIndex[j] && !matrix[i][j]) {             cout << 1 << endl << i <<     << j << endl;             return 0;           }         }       }     }     compress_graph2(n);     int leafPairs = (groupLeaves.size() + 1) / 2;     cout << leafPairs << endl;     for (int i = 0; i < leafPairs; ++i) {       int leaf1 = groupLeaves[i], leaf2 = groupLeaves[i + groupLeaves.size() / 2];       int node1 = -1, node2 = -1;       bool found = false;       for (int j : groupNodes[leaf1]) {         for (int k : groupNodes[leaf2]) {           if (!matrix[j][k]) {             node1 = j, node2 = k;             found = true;             break;           }         }         if (found) break;       }       cout << node1 <<     << node2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000 + 5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       bool can = false;       for (int i = 1; i < n; i++) {         if (a[i] >= a[i - 1]) {           can = true;           break;         }       }       if (can)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int r, c;   string s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> r >> c;     while (r--) cin >> s;     long long int ans = 0;     for (long long int i = 0; i <= c - 1; ++i) {       if (s[i] !=  B ) continue;       ans++;       while (i <= c - 1 && s[i] ==  B ) i++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     cout << (n - 1) / 2;     return 0;   }


#include <bits/stdc++.h>   long long p[2750131 + 5];   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long left = 0, right = n - 1, past = 0;     string s =   ;     long long flag = 1;     while (left < right && flag) {       if (a[left] < a[right]) {         if (a[left] > past) {           s +=  L ;           past = a[left];           left++;         } else if (a[right] > past) {           s +=  R ;           past = a[right];           right--;         } else {           flag = 0;         }       } else if (a[right] < a[left]) {         if (a[right] > past) {           s +=  R ;           past = a[right];           right--;         } else if (a[left] > past) {           s +=  L ;           past = a[left];           left++;         } else {           flag = 0;         }       } else {         if (a[left] <= past) {           flag = 0;           continue;         }         past = a[left];         left++;         long long sum1 = 1;         while (a[left] > past) {           sum1++;           past = a[left];           left++;         }         past = a[right];         right--;         long long sum2 = 1;         while (a[right] > past) {           sum2++;           past = a[right];           right--;         }         if (sum1 > sum2) {           while (sum1--) {             s +=  L ;           }         } else {           while (sum2--) {             s +=  R ;           }         }         flag = 0;       }     }     if (left == right && flag && a[left] > past) {       s +=  L ;     }     cout << s.size() <<   n ;     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   char s[5010];   long long dp[5010][5010];   bool vis[5010][5010];   long long f(int i, int ind, int n) {     if (vis[i][ind]) return dp[i][ind];     if (i > n) {       if (ind == 0) return 1;       return 0;     }     long long ans = 0;     vis[i][ind] = true;     if (s[i] ==  f )       ans = f(i + 1, ind + 1, n);     else {       ans = f(i + 1, ind, n);       if (ind > 0) ans = (ans + f(i, ind - 1, n)) % mod;     }     dp[i][ind] = ans;     return ans;   }   int main() {     int i, j, n;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf(  %c , &s[i]);     printf( %lld n , f(1, 0, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int l[maxn], r[maxn], a[maxn], pos[40];   map<int, int> m;   int main() {     int n;     scanf( %d , &n);     long long ans = (long long)n * (n + 1) / 2;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       l[i] = m[a[i]];       for (int j = 0; j < 32; j++) {         if (!(a[i] & (1 << j))) {           l[i] = max(l[i], pos[j]);         }       }       for (int j = 0; j < 32; j++) {         if ((a[i] & (1 << j))) {           pos[j] = i;         }       }       m[a[i]] = i;     }     for (int i = 0; i <= 32; i++) pos[i] = n + 1;     for (int i = 1; i <= n; i++) r[i] = n + 1;     for (int i = n; i > 0; i--) {       for (int j = 0; j < 32; j++) {         if (!(a[i] & (1 << j))) {           r[i] = min(r[i], pos[j]);         }       }       for (int j = 0; j < 32; j++) {         if ((a[i] & (1 << j))) {           pos[j] = i;         }       }       long long t = 1LL * (i - l[i]) * (r[i] - i);       ans -= t;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double ans = 0.0000;   void bfs();   list<int> arr[100005];   int visited[100005], dep[100005];   int main() {     int n, i, start, end;     cin >> n;     n--;     while (n--) {       cin >> start;       cin >> end;       arr[start].push_back(end);       arr[end].push_back(start);     }     bfs();     cout.precision(7);     cout << fixed << ans;     return 0;   }   void bfs() {     int node;     dep[1] = 1;     queue<int> qu;     list<int>::iterator iter = arr[1].begin();     node = 1;     visited[1] = 1;     qu.push(1);     while (!qu.empty()) {       for (iter = arr[node].begin(); iter != arr[node].end(); ++iter) {         if (!visited[*iter]) {           qu.push(*iter);           visited[*iter] = 1;           dep[*iter] = dep[node] + 1;         }       }       int k = qu.front();       qu.pop();       node = qu.front();       ans += 1 / (double)dep[k];     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vv;   int main() {     int t, n, x, c1, c2;     scanf( %d , &t);     vv.clear();     c1 = c2 = 0;     for (int i = 0; i < t; i++) {       scanf( %d , &n);       for (int j = 0; j < n / 2; j++) {         scanf( %d , &x);         c1 += x;       }       if (n % 2) {         scanf( %d , &x);         vv.push_back(x);       }       for (int j = 0; j < n / 2; j++) {         scanf( %d , &x);         c2 += x;       }     }     sort(vv.begin(), vv.end());     int flag = 1;     for (int i = vv.size() - 1; i >= 0; i--) {       if (flag == 1)         c1 += vv[i];       else         c2 += vv[i];       flag = -flag;     }     printf( %d %d n , c1, c2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int CNT[7002];   struct seg {     seg(int _l, int _r, int _val) : l(_l), r(_r), val(_val){};     int l, r, val;   };   vector<seg> q[7002];   int pw2[200002];   int up(int lev, int pos) {     int l = 0, r = 200000;     while (r - l > 1) {       int m = (l + r) >> 1;       if (m + pw2[m] >= pos)         r = m;       else         l = m;     }     return r;   }   int down_l(int lev, int pos) { return pos - 1 + pw2[pos - 1] + 1; }   int down_r(int lev, int pos) { return pos + pw2[pos]; }   int find(int lev, int pos) {     set<int> ret;     int l = pos, r = pos;     for (; lev <= 7000; ++lev) {       for (int j = 0; j < q[lev].size(); ++j) {         if (q[lev][j].r < l || q[lev][j].l > r)           ;         else {           ret.insert(q[lev][j].val);         }       }       l = down_l(lev, l);       r = down_r(lev, r);     }     return ret.size();   }   int main() {     for (int i = 0; (1 << i) <= 200000; ++i) {       pw2[1 << i] = 1;     }     for (int i = 1; i <= 200000; ++i) {       pw2[i] += pw2[i - 1];     }     int n, m;     scanf( %d%d , &n, &m);     int cnt = 1, total = 1;     CNT[1] = 1;     for (int i = 2; i <= n; ++i) {       int my = 0, pw = 1;       while (pw <= cnt) {         ++my;         pw <<= 1;       }       cnt = 2 * my + cnt - my;       total += cnt;       CNT[i] = cnt;     }     for (int i = 0; i < m; ++i) {       int t, lev, l, r, x, pos;       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d%d , &lev, &l, &r, &x);         q[lev].push_back(seg(l, r, x));       } else {         scanf( %d%d , &lev, &pos);         printf( %d n , find(lev, pos));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10, mod = 1e9 + 9;   const int maxn = 500010;   const long double eps = 1e-5;   const int EPS = 500 * 500;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long first = 1;     while (!isdigit(ch)) {       if (ch ==  - ) first *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= first;   }   template <typename T, typename... Args>   void read(T &first, Args &...args) {     read(first);     read(args...);   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int _;     cin >> _;     while (_--) {       int n, second;       cin >> n >> second;       cout << second / (n / 2 + 1) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> Dn;   int L[310];   int C[310];   int N;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , L + i);     for (int i = 1; i <= N; i++) scanf( %d , C + i);     for (int i = 1; i <= N; i++) {       if (Dn.find(L[i]) == Dn.end() || Dn[L[i]] > C[i]) Dn[L[i]] = C[i];       for (map<int, int>::iterator it = Dn.begin(); it != Dn.end(); it++) {         int temp = gcd(it->first, L[i]);         if (Dn.find(temp) == Dn.end() || Dn[temp] > it->second + C[i]) {           Dn[temp] = it->second + C[i];         }       }     }     if (Dn.find(1) == Dn.end())       printf( -1 n );     else       printf( %d n , Dn[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = (long double)1e-9;   const long double PI = acos(0) * 2;   bool isZero(const long double& x) { return abs(x) <= EPS; }   int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }   long long gcd(long long a, long long b) {     for (; b; a %= b, swap(a, b)) {     }     return abs(a);   }   pair<long long, long long> operator+(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first + b.first, a.second + b.second);   }   pair<long long, long long> operator-(const pair<long long, long long>& a,                                        const pair<long long, long long>& b) {     return pair<long long, long long>(a.first - b.first, a.second - b.second);   }   pair<long long, long long> operator*(const pair<long long, long long>& a,                                        const long long& b) {     return pair<long long, long long>(a.first * b, a.second * b);   }   long long operator*(const pair<long long, long long>& a,                       const pair<long long, long long>& b) {     return a.first * b.second - b.first * a.second;   }   long long ccw(const pair<long long, long long>& a,                 const pair<long long, long long>& b,                 const pair<long long, long long>& c) {     return a * b + b * c + c * a;   }   void fg(vector<int> G[], int a, int b) {     G[a].push_back(b);     G[b].push_back(a);   }   void fg(vector<pair<int, int> > G[], int a, int b, int c) {     G[a].push_back({b, c});     G[b].push_back({a, c});   }   const int MAXN = 1000055;   int E[MAXN][2];   int D[MAXN];   char A[MAXN][6];   int B[MAXN], C[MAXN];   int N;   void dfs1(int i) {     if ( I  == A[i][0]) {       D[i] = B[i];       return;     }     if ( N  == A[i][0]) {       dfs1(B[i]);       D[i] = !D[B[i]];       return;     }     dfs1(B[i]);     dfs1(C[i]);     if ( A  == A[i][0]) {       D[i] = D[B[i]] & D[C[i]];     } else if ( O  == A[i][0]) {       D[i] = D[B[i]] | D[C[i]];     } else {       D[i] = D[B[i]] ^ D[C[i]];     }   }   void dfs2(int i) {     if ( I  == A[i][0]) return;     if ( N  == A[i][0]) {       E[B[i]][0] = E[i][1];       E[B[i]][1] = E[i][0];       dfs2(B[i]);       return;     }     if ( A  == A[i][0]) {       E[B[i]][0] = E[i][0];       E[B[i]][1] = E[i][D[C[i]]];       E[C[i]][0] = E[i][0];       E[C[i]][1] = E[i][D[B[i]]];     } else if ( O  == A[i][0]) {       E[B[i]][0] = E[i][D[C[i]]];       E[B[i]][1] = E[i][1];       E[C[i]][0] = E[i][D[B[i]]];       E[C[i]][1] = E[i][1];     } else {       E[B[i]][0] = E[i][D[C[i]]];       E[B[i]][1] = E[i][D[C[i]] ^ 1];       E[C[i]][0] = E[i][D[B[i]]];       E[C[i]][1] = E[i][D[B[i]] ^ 1];     }     dfs2(B[i]);     dfs2(C[i]);   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf(  %s%d , A[i], &B[i]);       if ( I  != A[i][0] &&  N  != A[i][0]) scanf( %d , &C[i]);     }     dfs1(1);     E[1][0] = 0;     E[1][1] = 1;     dfs2(1);     for (int i = 1; i <= N; i++)       if ( I  == A[i][0]) putchar(E[i][!B[i]] ?  1  :  0 );     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 6;   long long int arr[2000005], brr[2000005], crr[2000005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, k, ans;     cin >> n >> k;     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) cin >> arr[i];     while (k--) {       int mx = 0;       for (int i = 1; i <= n; i++)         if (!mx || arr[i] > arr[mx]) mx = i;       int mn = 0;       for (int i = 1; i <= n; i++)         if (!mn || arr[i] < arr[mn]) mn = i;       if (mx == mn) {         ans = 0;         break;       }       arr[mx]--;       arr[mn]++;       v.push_back({mx, mn});     }     int mx = 0;     for (int i = 1; i <= n; i++)       if (!mx || arr[i] > arr[mx]) mx = i;     int mn = 0;     for (int i = 1; i <= n; i++)       if (!mn || arr[i] < arr[mn]) mn = i;     ans = arr[mx] - arr[mn];     cout << ans <<     << v.size() << endl;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  L ) {         if (i - 1 >= 0 && s[i - 1] !=  * ) {           for (int j = i - 1; j >= 0; j--) {             if (s[j] ==  R ) {               int aux = i - j + 1;               if (aux % 2 != 0) s[j + aux / 2] =  . ;               break;             } else {               if (s[j] ==  . ) s[j] =  * ;             }           }         }       }       if (s[i] ==  R ) {         if (i + 1 < s.size() && s[i + 1] !=  * ) {           for (int j = i; j < s.size(); j++) {             if (s[j] ==  L ) {               int aux = j - i + 1;               if (aux % 2 != 0) s[i + aux / 2] =  . ;               break;             } else {               if (s[j] ==  . ) s[j] =  * ;             }           }         }       }     }     int ans = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  . ) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edge[1005];   int vis[2][1005];   int d[2][1005];   int adj[1005][1005];   void djikstra(int s, int id) {     priority_queue<pair<int, int> > PQ;     PQ.push(make_pair(0, s));     d[id][s] = 0;     while (!PQ.empty()) {       pair<int, int> p = PQ.top();       PQ.pop();       int v = p.second;       int cd = -p.first;       if (cd != d[id][v] || vis[id][v]) continue;       vis[id][v] = 1;       for (int i = 0; i < edge[v].size(); i++) {         int u = edge[v][i];         int nd = cd + 1;         if (!vis[id][u] && nd < d[id][u]) {           d[id][u] = nd;           PQ.push(make_pair(-nd, u));         }       }     }   }   int main() {     int n, m, s, t;     scanf( %d%d%d%d , &n, &m, &s, &t);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       edge[u].push_back(v);       edge[v].push_back(u);       adj[u][v] = adj[v][u] = 1;     }     for (int i = 1; i <= n; i++) {       d[0][i] = d[1][i] = n;     }     djikstra(s, 0);     djikstra(t, 1);     int th = d[0][t];     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (adj[i][j]) continue;         int dist = min(d[0][i] + d[1][j], d[0][j] + d[1][i]);         if (dist + 1 >= th) ans++;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int nx[1000514 * 2][26], spt;   int fl[1000514 * 2], ll[1000514 * 2], lp[1000514 * 2];   int newnode() {     memset(nx[spt], 0, sizeof(nx[spt]));     fl[spt] = ll[spt] = lp[spt] = 0;     return spt++;   }   void add(int root, int& last, char A) {     int a = A -  a ;     int p = last;     int np = last = newnode();     ll[np] = ll[p] + 1;     lp[np] = 0;     for (; p && nx[p][a] == 0; p = fl[p]) nx[p][a] = np;     int q = nx[p][a];     if (p == 0)       fl[np] = root;     else if (ll[q] == ll[p] + 1)       fl[np] = q;     else {       int nq = spt++;       memcpy(nx[nq], nx[q], sizeof(nx[q]));       fl[nq] = fl[q];       ll[nq] = ll[p] + 1;       lp[nq] = lp[q] + ll[q] - 1 - ll[p];       fl[q] = fl[np] = nq;       for (; p && nx[p][a] == q; p = fl[p]) nx[p][a] = nq;     }   }   char s[1000514], r[1000514 * 2];   vector<int> bk[1000514];   int dp[1000514 * 2];   int vs[1000514 * 2], vt;   void make_z(int* z, char* s, int l) {     int j = z[0] = 0;     for (int i = 1; i < l; i++) {       z[i] = (i > j + z[j] - 1) ? 0 : min(z[i - j], j + z[j] - i);       for (; i + z[i] < l && s[z[i]] == s[i + z[i]]; z[i]++)         ;       if (i + z[i] > j + z[j]) j = i;     }   }   int z[1000514 * 2];   void sol() {     spt = 1;     int last;     int root = last = newnode();     int sl = 0;     for (; s[sl]; sl++)       ;     for (int i = 0; i < sl; i++) add(root, last, s[i]);     for (int i = 1; i < spt; i++) {       bk[ll[i]].push_back(i);     }     for (int p = last; p; p = fl[p]) {       dp[p] = 1;     }     for (int i = sl; i >= 0; i--) {       int sz = (int)bk[i].size();       for (int j = 0; j < sz; j++) {         int w = bk[i][j];         for (int k = 0; k < 26; k++) {           int t = nx[w][k];           if (t) dp[w] += dp[t];         }       }     }     int Q;     scanf( %d , &Q);     for (int T = 0; T < Q; T++) {       scanf( %s , r);       int rl = 0;       for (; r[rl]; rl++)         ;       for (int i = 0; i < rl; i++) r[rl + i] = r[i];       r[rl + rl] = 0;       make_z(z, r, rl * 2);       int t = 0;       for (int i = 1; i <= rl; i++) {         if (rl % i) continue;         int flag = 0;         for (int j = i; j < rl; j += i) {           if (z[j] < rl / i) {             flag = 1;           }         }         if (flag) continue;         t = i;         break;       }       int p = root;       int l = 0;       for (int i = 0; i < rl; i++) {         int a = r[i] -  a ;         for (; p && nx[p][a] == 0; p = fl[p])           ;         if (p == 0) {           l = 0;           p = root;         } else {           l = min(l, ll[p]) + 1;           p = nx[p][a];         }       }       vt++;       int ans = 0;       if (l >= rl && vs[p] != vt) {         vs[p] = vt;         ans += dp[p];       }       for (int i = 0; i < rl - 1; i++) {         int a = r[i] -  a ;         for (; p && nx[p][a] == 0; p = fl[p])           ;         if (p == 0) {           l = 0;           p = root;         } else {           l = min(l, ll[p]) + 1;           p = nx[p][a];         }         for (; p && ll[fl[p]] >= rl; p = fl[p])           ;         l = min(l, ll[p]);         if (l >= rl && vs[p] != vt) {           vs[p] = vt;           ans += dp[p];         }       }       printf( %d n , (int)ans);     }   }   int main() {     scanf( %s , s);     sol();   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> a, b;   int main() {     int n, m, k, x;     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) {       cin >> x;       a.push_back(x);     }     for (int i = 0; i < m; ++i) {       cin >> x;       b.push_back(x);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int i = a.size() - 1;     int j = b.size() - 1;     while (i >= 0 && j >= 0 && a[i] <= b[j]) {       --i;       --j;     }     if (i >= 0)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     if (m == 3 && n != 4 && n != 3) {       cout << -1;       return false;     }     int x = 0, y = 0;     for (int i = 1; i <= m; i++) {       cout << x <<     << y << endl;       x++;       y += i;     }     x = 1000000, y = 0;     for (int i = 1; i <= n - m; i++) {       cout << x <<     << y << endl;       x--;       y += i;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100, M = 10 + 10, SQ = 333;   pair<int, int> nxt[N][M];   char a[N][M];   bool mark[N][M];   int n, m, q;   bool OK(pair<int, int> x) {     return x.first > 0 && x.second > 0 && x.second <= m;   }   pair<int, int> go(int x, int y) {     if (!OK({x, y})) return {x, y};     if (nxt[x][y].first != -2) return nxt[x][y];     if (a[x][y] ==  ^ )       return x % SQ ? nxt[x][y] = go(x - 1, y) : nxt[x][y] = {x - 1, y};     if (mark[x][y]) return nxt[x][y] = {-1, -1};     mark[x][y] = true;     if (a[x][y] ==  > ) nxt[x][y] = go(x, y + 1);     if (a[x][y] ==  < ) nxt[x][y] = go(x, y - 1);     mark[x][y] = false;     return nxt[x][y];   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) nxt[i][j] = {-2, -2};     cin >> n >> m >> q;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) go(i, j);     while (q--) {       char tp;       int x, y;       cin >> tp >> x >> y;       if (tp ==  A ) {         pair<int, int> tmp = {x, y};         while (OK(tmp)) tmp = nxt[tmp.first][tmp.second];         cout << tmp.first <<     << tmp.second <<   n ;       } else {         cin >> a[x][y];         int A = 0;         while (A <= x) A += SQ;         for (int i = x; i <= min(A, n); i++)           for (int j = 1; j <= m; j++) nxt[i][j] = {-2, -2};         for (int i = x; i <= min(A, n); i++)           for (int j = 1; j <= m; j++) go(i, j);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int arr[n];     for (auto& elem : arr) {       cin >> elem;     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < n; ++j) {         if (arr[j] == i) {           cout << j + 1 <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   const int mod = 1000000007;   int a, b, c, d, e, f, g, h, i, j;   int Mi[N * N];   int F[N][N], K;   void Work() {     Mi[0] = 1;     for (int ii = 1; ii <= a * a; ii++) Mi[ii] = (Mi[ii - 1] << 1) % mod;     F[0][0] = 1;     for (int ii = 1; ii <= a; ii++)       for (int jj = 1; jj <= K; jj++) {         for (int kk = 0; kk < ii; kk++)           (F[ii][jj] += (long long)F[kk][jj - 1] * (Mi[ii - kk] - 1) % mod *                         (Mi[(ii - kk) * kk]) % mod) %= mod;       }     int an = 0;     for (int ii = 0; ii <= a; ii++)       (an += (long long)F[ii][K] * Mi[(a - ii) * ii] % mod) %= mod;     cout << an << endl;   }   int main() {     cin >> a >> K;     Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q, a[555555], k, l, m, n, o, p;   const long long mod = 1e9 + 7;   queue<long long> qq[100005];   struct node {     node *left, *right;     long long val;     node() {       val = 0;       left = right = this;     }     node(node *le, node *re, long long va) {       le = left, re = right;       val = va;     }   };   node *ver[555555];   void build(long long s, long long e, node *r) {     if (s == e) {       return;     }     r->left = new node(NULL, NULL, 0);     r->right = new node(NULL, NULL, 0);     build(s, ((s + e) / 2), r->left), build(((s + e) / 2) + 1, e, r->right);   }   void update(long long s, long long e, long long id, long long val, node *r1,               node *r2) {     if (s > id || e < id) return;     if (s == e) {       r2->val = val;       return;     }     if (id <= ((s + e) / 2)) {       r2->right = r1->right;       r2->left = new node(NULL, NULL, 0);       update(s, ((s + e) / 2), id, val, r1->left, r2->left);     } else {       r2->left = r1->left;       r2->right = new node(NULL, NULL, 0);       update(((s + e) / 2) + 1, e, id, val, r1->right, r2->right);     }     r2->val = r2->left->val + r2->right->val;   }   long long query(long long s, long long e, node *r1, long long l, long long r) {     if (l > e || s > r) return 0;     if (l <= s && e <= r) return r1->val;     return query(s, ((s + e) / 2), r1->left, l, r) +            query(((s + e) / 2) + 1, e, r1->right, l, r);   }   void solve() {     cin >> n >> m;     ver[0] = new node();     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) {       k = a[i];       ver[i * 2 - 1] = new node(NULL, NULL, 0);       ver[i * 2] = new node(NULL, NULL, 0);       update(1, n, i, 1, ver[i * 2 - 2], ver[i * 2 - 1]);       if (qq[k].size() == m) {         long long op = qq[k].front();         qq[k].pop();         update(1, n, op, 0, ver[i * 2 - 1], ver[i * 2]);       } else         ver[i * 2] = ver[i * 2 - 1];       qq[k].push(i);     }     long long last = 0, s, e;     cin >> l;     while (l--) {       cin >> s >> e;       o = (s + last) % n + 1;       p = (e + last) % n + 1;       if (o > p) swap(o, p);       last = query(1, n, ver[2 * p], o, n);       cout << last << endl;     }   }   int main() {     q = 1;     while (q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[5010][5010]={};   long long cnt[5010]={};   long long a[5000];   long long mod=1e9+7;   signed main()   {       int n,k,q;       cin>>n>>k>>q;       for(int i=0;i<n;i++){           cin>>a[i];       }       for(int i=0;i<n;i++)dp[i][0]=1;       for(int j=1;j<=k;j++){           dp[0][j]=dp[1][j-1];           for(int i=1;i<n-1;i++){               dp[i][j]=dp[i-1][j-1]+dp[i+1][j-1];               dp[i][j]%=mod;           }           dp[n-1][j]=dp[n-2][j-1];       }       long long b;       long long sum=0;       for(int i=0;i<n;i++){           for(int j=0;j<=k;j++){               b=dp[i][j]*dp[i][k-j];               b%=mod;               cnt[i]+=b;               cnt[i]%=mod;           }           sum+=(cnt[i]*a[i])%mod;           sum%=mod;       }       for(int i=0;i<q;i++){           long long x,y;           cin>>x>>y;           long long f=cnt[x-1]*(y),g=cnt[x-1]*a[x-1];           sum+=mod+(f%mod+mod)%mod-(g%mod+mod)%mod;           sum%=mod;           a[x-1]=y;           cout<<sum<<  n ;       }      }


#include <bits/stdc++.h>   using namespace std;   int main() {     string t;     cin >> t;     string s;     bool a = true;     for (int i = 0; i < t.size(); i++) {       if (a && t[i] ==  0 ) {         a = false;         continue;       }       s.push_back(t[i]);     }     if (a) s.erase(s.begin());     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   int a[105];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     int s = 0;     for (int i = 0; i < n; ++i) {       int t = 0;       for (int j = i; j < n; ++j) {         t ^= a[j];         if (s < t) s = t;       }     }     printf( %d n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> O;   map<pair<long long, long long>, long long>::iterator oit;   map<long long, long long> X, Y;   map<long long, long long>::iterator it;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       double x, y;       cin >> x >> y;       O[make_pair(x, y)]++;       X[x]++;       Y[y]++;     }     long long cnt = 0;     for (it = X.begin(); it != X.end(); ++it)       if (it->second > 1) cnt += (it->second - 1) * (it->second) / 2;     for (it = Y.begin(); it != Y.end(); ++it)       if (it->second > 1) cnt += (it->second - 1) * (it->second) / 2;     for (oit = O.begin(); oit != O.end(); ++oit)       if (oit->second > 1) cnt -= (oit->second - 1) * (oit->second) / 2;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> num, con, a;   vector<vector<int> > g(1000001);   bool used[1000001];   void dfs(int v) {     num.push_back(v);     con.push_back(a[v - 1]);     used[v] = true;     if (g[v].empty()) return;     for (int i = 0; i < g[v].size(); i++)       if (!used[g[v][i]]) dfs(g[v][i]);     return;   }   int main() {     int n, m;     cin >> n >> m;     int x, y;     a.assign(n, 0);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       num.resize(0);       con.resize(0);       if (used[i]) continue;       dfs(a[i - 1]);       sort(num.begin(), num.end());       sort(con.rbegin(), con.rend());       for (int j = 0; j < num.size(); j++) {         a[num[j] - 1] = con[j];       }     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   const int M = 2e6 + 7;   const int lim = 1e6;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   long long ksm(long long a, long long b, long long p) {     long long ret = 1;     while (b) {       if (b & 1) (ret *= a) %= p;       (a *= a) %= p;       b >>= 1;     }     return ret;   }   long long inv(long long x) { return ksm(x, mod - 2, mod); }   int main() {     long long k, x, a = 1, b = 1, f1 = 0, f2 = 0;     scanf( %lld , &k);     for (int i = 1; i <= k; i++) {       scanf( %lld , &x);       if (x % 2 == 0) f1 = 1;       if (x == 0) f2 = 1;       (b *= x % (mod - 1)) %= mod - 1;       (a *= x % 2) %= 2;     }     b = (b - 1 + mod - 1) % (mod - 1);     long long bb = ksm(2, b, mod);     if (f1 == 0) f1 = -1;     long long aa = (bb + f1 + mod) % mod, t = ksm(2, (a - 1 + 2) % 2, 3);     t = (t + f1 + 3) % 3;     if (t == 0)       aa = aa * inv(3) % mod;     else       bb *= 3;     printf( %lld/%lld n , aa, bb);     return 0;   }


#include <bits/stdc++.h>   inline long long gcd(long long a, long long b) {     return (b ? gcd(b, a % b) : a);   }   inline long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   inline int cmp(double x, double y = 0, double tol = 1e-7) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   using namespace std;   const int MAXN = 1e5 + 5;   vector<int> adj[MAXN];   int y[MAXN];   int qy[MAXN];   void G(int n, int pai) {     y[n] = 0;     for (int i = 0; i < adj[n].size(); i++) {       int x = adj[n][i];       if (x != pai && adj[x].size() <= 2) G(x, n);     }   }   int main() {     int n, a, b, x;     cin >> n;     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 0; i < MAXN; i++) y[i] = 1;     memset(qy, 0, sizeof qy);     for (int i = 1; i < n + 1; i++) {       if (adj[i].size() == 1 && y[i]) G(i, -1);     }     for (int i = 1; i < n + 1; i++) {       int a = 0, b = 0;       for (int j = 0; j < adj[i].size(); j++) {         x = adj[i][j];         if (y[x])           a++;         else           b++;       }       qy[i] = a + max(b - 2, 0);     }     bool ans = true;     for (int i = 1; i < n + 1; i++) {       if (!y[i]) continue;       int cnt = 0;       for (int j = 0; j < adj[i].size(); j++) {         a = adj[i][j];         if (qy[a] > 1) cnt++;       }       if (cnt > 2) {         ans = false;         break;       }     }     cout << (ans ?  Yes n  :  No n );   }


#include <bits/stdc++.h>      #define ln                   n    #define all(dat)           dat.begin(), dat.end()   #define loop(i, to)        for (int i = 0; i < to; ++i)   #define cont(i, to)        for (int i = 1; i <= to; ++i)   #define circ(i, fm, to)    for (int i = fm; i <= to; ++i)   #define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)      typedef long long          num;      using namespace std;      const int nsz = 2e5;   bool on[nsz + 5], vis[nsz + 5];   int n, m, rt = 1, dis[nsz + 5], ans[nsz + 5];   int pr[nsz + 5], dep[nsz + 5], siz[nsz + 5], mxs[nsz + 5];      struct graph {    int sz, hd[nsz + 5];        struct edge {     int nxt, to;          edge() {}     edge(int nxt, int to) {      this->nxt = nxt, this->to = to;     }    } e[2 * nsz + 5];        inline edge& operator [] (int id) { return e[id]; }        void inline link(int u, int v) {     e[++sz] = edge(hd[u], v), hd[u] = sz;     e[++sz] = edge(hd[v], u), hd[v] = sz;    }   };   graph g;      struct fenwick_tree {    int t, tr[nsz + 5], tm[nsz + 5];        void inline clear() { ++t; }        void inline chg(int u) {     if (tm[u] != t) tm[u] = t, tr[u] = 0;    }        void inline upd(int u, int w) {     for (++u; u > 0; u -= u & -u) chg(u), tr[u] = max(tr[u], w);    }        int inline qry(int u) {     int res = 0;     for (++u; u <= n + 1; u += u & -u) chg(u), res = max(res, tr[u]);     return res;    }   };   fenwick_tree tr;      void inline bfs() {    static int q[nsz + 5];    int ql = 0, qr = 0;    cont (u, n) dis[u] = n;    cont (u, n) if (on[u]) dis[u] = 0, q[qr++] = u;    for (; ql != qr;) {     int u = q[ql++];     for (int i = g.hd[u]; i; i = g[i].nxt) {      int v = g[i].to;      if (dis[v] > dis[u] + 1) dis[v] = dis[u] + 1, q[qr++] = v;     }    }   }      void dfs1(vector<int> &nd, int u, int p = -1) {    siz[u] = mxs[u] = 1;    nd.push_back(u);    for (int i = g.hd[u]; i; i = g[i].nxt) {     int v = g[i].to;     if (v == p || vis[v]) continue;     dfs1(nd, v, u);     siz[u] += siz[v];     mxs[u] = max(mxs[u], siz[v]);    }   }      void dfs2(int u, int p = -1) {    for (int i = g.hd[u]; i; i = g[i].nxt) {     int v = g[i].to;     if (v == p || vis[v]) continue;     dep[v] = dep[u] + 1;     dfs2(v, u);    }   }      int inline find_rt(vector<int> &nd, int u) {    dfs1(nd, u);    int sz = siz[u];    loop (i, nd.size()) {     int u = nd[i], cur = max(mxs[u], sz - siz[u]);     if (cur * 2 <= sz) return u;    }    return u;   }      void inline calc(vector<int> &nd, int u) {    dep[u] = 0, dfs2(u);    loop (i, nd.size()) {     int u = nd[i], k = dis[u] - dep[u] - 1;     if (k >= 0) tr.upd(k, dis[u]);    }    loop (i, nd.size()) {     int u = nd[i], k = dep[u];     ans[u] = max(ans[u], tr.qry(k));    }    tr.clear();   }      void solve(int u = rt) {    vector<int> nd;    u = find_rt(nd, u);    calc(nd, u);    vis[u] = 1;    for (int i = g.hd[u]; i; i = g[i].nxt) {     int v = g[i].to;     if (!vis[v]) solve(v);    }   }      int main() {    scanf( %d , &n);    cont (i, n - 1) {     int u, v;     scanf( %d%d , &u, &v);     g.link(u, v);    }    scanf( %d , &m);    cont (i, m) {     int u;     scanf( %d , &u);     on[u] = 1;    }    bfs();    solve();    cont (u, n) printf( %d%c , ans[u],   n  [u < n]);   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, k, t;   int main() {     cin >> t;     while (t--) {       cin >> a >> b >> c >> d >> k;       bool isok = 0;       for (int i = 1; i <= k; i++) {         if (i * c >= a && (k - i) * d >= b) {           isok = 1;           cout << i <<     << k - i << endl;           break;         }       }       if (!isok) cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200002;   double eps = 1e-9;   int T, N, M, K, mx, sum, ans;   int a, b, c;   bool visit[MAXN], call[MAXN];   int color[MAXN];   vector<int> v[MAXN];   map<int, int> mp;   void dfs(int n) {     mp[color[n]]++;     for (auto i : v[n])       if (!visit[i]) {         visit[i] = 1;         dfs(i);       }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> N >> M >> K;     for (int i = 0; i < N; i++) cin >> color[i];     for (int i = 0; i < M; i++) {       cin >> a >> b;       --a, --b;       call[a] = call[b] = 1;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 0; i < N; i++)       if (call[i] && !visit[i]) {         visit[i] = 1;         mp.clear();         dfs(i);         mx = 0;         sum = 0;         for (auto i : mp) {           mx = max(mx, i.second);           sum += i.second;         }         ans += (sum - mx);       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char arr[1001][1001];   long long int used[1001][1001];   long long int ans[1001][1001];   long long int n, m;   long long int inf = 1e18;   long long int p = 1e9 + 7;   long long int phi(long long int n) {     long long int result = n;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   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;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int dfs(long long int x, long long int y) {     long long int cur = 0;     long long int temp = 0;     char s = arr[x][y];     char f;     if (used[x][y] == 2) {       return ans[x][y];     }     ans[x][y] = 0;     used[x][y] = 1;     if (s ==  D )       f =  I ;     else if (s ==  I )       f =  M ;     else if (s ==  M )       f =  A ;     else       f =  D ;     if (x + 1 <= n && arr[x + 1][y] == f) {       if (used[x + 1][y] != 1) {         temp = std::max(temp, 1 + dfs(x + 1, y));       } else if (used[x + 1][y] == 1)         return inf;     }     if (x - 1 >= 0 && arr[x - 1][y] == f) {       if (used[x - 1][y] != 1) {         temp = std::max(temp, 1 + dfs(x - 1, y));       } else if (used[x - 1][y] == 1)         return inf;     }     if (y + 1 <= m && arr[x][y + 1] == f) {       if (used[x][y + 1] != 1) {         temp = std::max(temp, 1 + dfs(x, y + 1));       } else if (used[x][y + 1] == 1)         return inf;     }     if (y - 1 >= 0 && arr[x][y - 1] == f) {       if (used[x][y - 1] != 1) {         temp = std::max(temp, 1 + dfs(x, y - 1));       } else if (used[x][y - 1] == 1)         return inf;     }     if (temp >= inf) temp = inf;     used[x][y] = 2;     ans[x][y] = temp;     return ans[x][y];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, j, t, a, b, temp, k, x, y, ctr;     cin >> n >> m;     long long int ans = 0;     memset(used, 0, sizeof(used));     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> arr[i][j];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (arr[i][j] ==  D  && used[i][j] == 0) {           ans = std::max(ans, 1 + dfs(i, j));         }       }     }     if (ans >= inf)       cout <<  Poor Inna! ;     else {       ans /= 4;       if (ans == 0)         cout <<  Poor Dima! ;       else         cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e9;   const long long MOD = (long long)1e9 + 7;   const long long P = 239;   const long long MAX_N = 1000;   const long long CNT = 5;   const long double pi = 3.1415926535897932384626;   const long double eps = 1e-6;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, l, v1, v2, k;     cin >> n >> l >> v1 >> v2 >> k;     long long cnt = (n + k - 1) / k;     long double f = (long double)(v2 - v1) / (v2 + v1);     long double t = (long double)l / (v2 * cnt - v2 * (cnt - 1) * f);     cout.precision(30);     t = t * cnt + t * f * (cnt - 1);     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 3e5 + 10, inf = 1000111222;   struct node {     int p0, p1;     int cnt;     node() {       p0 = p1 = 0;       cnt = 0;     }   };   int root = 1;   node A[max_n * 33];   int last_used = 1;   int new_node() { return ++last_used; }   int a[max_n];   long long cost_if_set[33][2];   void add_number(int a) {     int cur = root;     for (int i = 30; i >= 0; i--) {       if (a & (1ll << i)) {         if (A[cur].p0) {           cost_if_set[i][0] += A[A[cur].p0].cnt;         }         if (!A[cur].p1) {           A[cur].p1 = new_node();         }         cur = A[cur].p1;         A[cur].cnt++;       } else {         if (A[cur].p1) {           cost_if_set[i][1] += A[A[cur].p1].cnt;         }         if (!A[cur].p0) {           A[cur].p0 = new_node();         }         cur = A[cur].p0;         A[cur].cnt++;       }     }   }   int n;   void calc_costs() {     for (int i = n; i >= 1; i--) {       add_number(a[i]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     calc_costs();     long long ans = 0;     int x = 0;     for (int i = 0; i < 31; i++) {       if (cost_if_set[i][0] <= cost_if_set[i][1]) {         ans += cost_if_set[i][0];       } else {         x |= (1ll << i);         ans += cost_if_set[i][1];       }     }     cout << ans <<     << x <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       long long l, r;       cin >> l >> r;       long long i = 1;       while ((l | i) <= r) {         l |= i;         i <<= 1;       }       cout << l <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   basic_string<int> e[500005][2];   basic_string<int> f[500005][2];   int n, m;   int d[500005], w[500005][2];   const int inf = 123123123;   int main() {     ios::sync_with_stdio(!cin.tie(0));     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, t;       cin >> u >> v >> t;       e[u][t] += v;       f[v][t] += u;     }     for (int i = 1; i <= n; i++) {       d[i] = w[i][0] = w[i][1] = inf;     }     d[n] = 0;     set<pair<int, int>> pq;     pq.insert({d[n], n});     while (pq.size()) {       auto [dx, x] = *pq.begin();       pq.erase(pq.begin());       for (int c = 0; c < 2; c++) {         for (int y : f[x][c]) {           w[y][c] = min(w[y][c], dx);           int dy = max(w[y][0], w[y][1]) + 1;           if (dy < d[y]) {             pq.erase({d[y], y});             d[y] = dy;             pq.insert({d[y], y});           }         }       }     }     cout << (d[1] > inf / 2 ? -1 : d[1]) <<   n ;     for (int i = 1; i <= n; i++) {       cout << (w[i][0] < w[i][1]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXS = 75, MAXK = 10, MAXQ = 30;   const long long INF = 0x3f3f3f3f3f3f3f3f;   int x, k, n, q, c[MAXK];   struct node {     int p, w;   } d[MAXQ];   bool operator<(const node &aa, const node &bb) { return aa.p < bb.p; }   int sta[MAXS], scn, cnt[300], id[300];   struct Matrix {     long long s[MAXS][MAXS];     Matrix() { memset(s, 0x3f, sizeof(s)); }   } X, A, pw[30];   Matrix operator*(const Matrix &aa, const Matrix &bb) {     Matrix cc;     for (int i = 1; i <= scn; i++)       for (int j = 1; j <= scn; j++)         for (int k = 1; k <= scn; k++)           cc.s[i][j] = min(cc.s[i][j], aa.s[i][k] + bb.s[k][j]);     return cc;   }   void build_pw() {     pw[0] = X;     for (int i = 1; i < 30; i++) pw[i] = pw[i - 1] * pw[i - 1];   }   Matrix get(int a) {     Matrix ret;     for (int i = 1; i <= scn; i++) ret.s[i][i] = 0;     for (int i = 0; i < 30; i++)       if (a >> i & 1) ret = ret * pw[i];     return ret;   }   int main() {     scanf( %d%d%d%d , &x, &k, &n, &q);     for (int i = 1; i <= k; i++) scanf( %d , &c[i]);     for (int i = 1; i <= q; i++) scanf( %d%d , &d[i].p, &d[i].w);     sort(d + 1, d + q + 1);     for (int s = 1; s < (1 << k); s++) {       cnt[s] = cnt[s >> 1] + (s & 1);       if (cnt[s] == x) sta[++scn] = s, id[s] = scn;     }     for (int i = 1; i <= scn; i++) {       if (sta[i] & 1) {         for (int j = 1; j <= k; j++)           if (!(sta[i] >> j & 1)) X.s[i][id[(sta[i] | (1 << j)) >> 1]] = c[j];       } else         X.s[i][id[sta[i] >> 1]] = 0;     }     build_pw();     int cur = 1;     long long delta = 0;     for (int i = 1; i <= scn; i++) A.s[i][i] = 0;     for (int i = 1; i <= q; i++) {       if (d[i].p > n - x)         delta += d[i].w;       else {         A = A * get(d[i].p - cur), cur = d[i].p;         for (int j = 1; j <= scn; j++)           for (int k = 1; k <= scn; k++)             if (sta[k] & 1) A.s[j][k] += d[i].w;       }     }     A = A * get(n - x + 1 - cur);     printf( %lld n , A.s[1][1] + delta);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 507;   const long long INF = 1e9 + 7;   long long n, m, mod;   long long Pow(long long x, long long y) {     long long ans = 1, now = x;     while (y) {       if (y & 1) ans = ans * now % mod;       now = now * now % mod;       y >>= 1;     }     return ans;   }   long long fac[N], inv[N], f[N], g[N], F[N][N], G[N][N];   long long C(long long x, long long y) {     return fac[x] * inv[y] % mod * inv[x - y] % mod;   }   int main() {     scanf( %lld%lld%lld , &n, &m, &mod);     fac[0] = 1;     for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;     inv[n] = Pow(fac[n], mod - 2);     for (long long i = n; i; i--) inv[i - 1] = inv[i] * i % mod;     f[0] = 1;     for (long long i = 1; i <= n; i++) {       f[i] = g[i] = 0;       for (long long j = 1; j <= i; j++) {         f[i] =             (f[i] + f[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] =             (g[i] + f[j - 1] * g[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] =             (g[i] + g[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] = (g[i] + f[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod *                            ((j - 1) * j / 2 + (i - j) * (i - j + 1) / 2)) %                mod;       }     }     F[0][0] = 1;     for (long long i = 1; i <= n; i++) {       F[i][i] = f[i];       G[i][i] = g[i];     }     for (long long i = 0; i <= n - 1; i++) {       for (long long j = 0; j <= m + 1 - 1; j++) {         F[i + 1][j] = (F[i + 1][j] + F[i][j]) % mod;         G[i + 1][j] = (G[i + 1][j] + G[i][j]) % mod;         for (long long k = 1; k <= n; k++) {           if (j + k > m || i + k + 1 > n) break;           F[i + k + 1][j + k] =               (F[i + k + 1][j + k] + F[i][j] * f[k] % mod * C(j + k, k)) % mod;           G[i + k + 1][j + k] =               (G[i + k + 1][j + k] +                (G[i][j] * f[k] + F[i][j] * g[k]) % mod * C(j + k, k)) %               mod;         }       }     }     printf( %lld n , G[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t-- > 0) {       int n;       string s;       cin >> n >> s;       vector<int> a(n, 0), b(n, 0), c;       int flag1 = 1, flag2 = 1;       for (int i = 0; i < n - 1; i++) {         if (s[i] ==  < ) {           b[i] = flag1++;         }       }       for (int i = n - 2; i >= 0; i--) {         if (s[i] ==  < ) {           while (i > 0 && s[i - 1] ==  < ) {             i--;           }           int x = i;           while (s[x] ==  < ) {             a[x] = flag2++;             x++;           }         }       }       for (int i = n - 1; i >= 0; i--) {         if (b[i] == 0) {           b[i] = flag1++;         }         if (a[i] == 0) {           a[i] = flag2++;         }       }       for (int i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;       for (int i = 0; i < n; i++) {         cout << b[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x[100005], h[100005];     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i] >> h[i];     int count = 1;     int newarr[100005];     newarr[1] = x[0] - h[0];     for (int i = 1; i < n - 1; ++i) {       if ((x[i] - h[i] > x[i - 1]) && (x[i] - h[i] > newarr[count])) {         count++;         newarr[count] = x[i] - h[i];       } else if (x[i] + h[i] < x[i + 1]) {         count++;         newarr[count] = x[i] + h[i];       } else         continue;     }     if (n == 1)       puts( 1 );     else       cout << count + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   vector<vector<pair<int, int> > > graph;   vector<pair<int, int> > edges;   class SegmentTree {     struct node_t {       int best[2];       int lazy;       node_t() {         best[0] = 0;         best[1] = 0;         lazy = 0;       }       node_t operator+(const node_t &other) const {         node_t ans;         for (int i = 0; i < 2; i++) {           ans.best[i] = max(this->best[i], other.best[i]);         }         ans.lazy = 0;         return ans;       }       void propag(int lazy) {         if (lazy) {           swap(best[0], best[1]);           this->lazy ^= lazy;         }       }     };     int n;     vector<node_t> aint;     void propag(int nod, int st, int dr) {       if (st == dr || aint[nod].lazy == 0) {         return;       }       aint[nod * 2].propag(aint[nod].lazy);       aint[nod * 2 + 1].propag(aint[nod].lazy);       aint[nod].lazy = 0;     }     void build(int nod, int st, int dr, const vector<int> &lvl,                const vector<int> &tp) {       if (st == dr) {         aint[nod].best[tp[st]] = lvl[st];         aint[nod].best[tp[st] ^ 1] = 0;         return;       }       int mid = (st + dr) / 2;       build(nod * 2, st, mid, lvl, tp);       build(nod * 2 + 1, mid + 1, dr, lvl, tp);       aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];     }     void flip(int nod, int st, int dr, int l, int r) {       propag(nod, st, dr);       if (dr < l || st > r) {         return;       }       if (l <= st && dr <= r) {         aint[nod].propag(1);         return;       }       int mid = (st + dr) / 2;       flip(nod * 2, st, mid, l, r);       flip(nod * 2 + 1, mid + 1, dr, l, r);       aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];     }       public:     SegmentTree(int n, const vector<int> &lvl, const vector<int> &tp) {       this->n = n;       aint = vector<node_t>(4 * n + 5, node_t());       build(1, 1, n, lvl, tp);     }     SegmentTree() { ; }     void flip(int l, int r) { flip(1, 1, n, l, r); }     int query() { return aint[1].best[0]; }   };   class TreeWrapper {     SegmentTree aint;     vector<int> lvl;     vector<int> tp;     vector<int> l;     vector<int> r;     int lst = 0;     void dfs(int nod, pair<int, int> tata,              const vector<vector<pair<int, int> > > &graph) {       l[nod] = ++lst;       lvl[l[nod]] = 1 + lvl[l[tata.first]];       tp[l[nod]] = tp[l[tata.first]] ^ tata.second;       for (auto it : graph[nod]) {         if (it.first == tata.first) {           continue;         }         dfs(it.first, {nod, it.second}, graph);       }       r[nod] = lst;     }       public:     TreeWrapper(int root, const vector<vector<pair<int, int> > > &graph) {       lst = 0;       l = vector<int>(graph.size(), 0);       r = vector<int>(graph.size(), 0);       lvl = vector<int>(graph.size(), 0);       tp = vector<int>(graph.size(), 0);       dfs(root, {0, 0}, graph);       aint = SegmentTree((int)graph.size() - 1, lvl, tp);     }     void flip(pair<int, int> a) {       if (lvl[l[a.first]] > lvl[l[a.second]]) {         swap(a.first, a.second);       }       aint.flip(l[a.second], r[a.second]);     }     int query() { return aint.query(); }   };   pair<int, int> dfs(int nod, int tata) {     pair<int, int> ans = {0, nod};     for (auto it : graph[nod]) {       if (it.first == tata) {         continue;       }       pair<int, int> tmp = dfs(it.first, nod);       tmp.first++;       ans = max(ans, tmp);     }     return ans;   }   int main() {     scanf( %d , &n);     graph = vector<vector<pair<int, int> > >(n + 1, vector<pair<int, int> >());     edges = vector<pair<int, int> >(n, {0, 0});     for (int i = 1; i < n; i++) {       int x, y, t;       scanf( %d %d %d , &x, &y, &t);       graph[x].push_back({y, t});       graph[y].push_back({x, t});       edges[i] = {x, y};     }     int a = dfs(1, 0).second;     int b = dfs(a, 0).second;     TreeWrapper fst(a, graph), snd(b, graph);     scanf( %d , &q);     while (q--) {       int id;       scanf( %d , &id);       fst.flip(edges[id]);       snd.flip(edges[id]);       printf( %d n , max(fst.query(), snd.query()) - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> cnt1, cnt2;   const int maxn = 1e5 * 3;   int x[maxn];   int y[maxn];   int main() {     int n = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       cnt1[x[i] - y[i]]++;       cnt2[x[i] + y[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       long long c1 = cnt1[x[i] - y[i]];       long long c2 = cnt2[x[i] + y[i]];       ans += c1 + c2 - 2;     }     cout << ans / 2;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     string s[n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j <= i; j++) cout <<  ( ;       for (long long j = 0; j <= i; j++) cout <<  ) ;       for (long long j = 0; j < n - i - 1; j++) cout <<  () ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1, x = 0;     cin >> t;     while (t--) {       x++;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int K = 269;   const int MS = 2;   const int MOD[MS] = {(int)1e9 + 7, (int)1e9 + 9};   const int MAXN = 1e6 + 69;   using hsh = vector<long long>;   struct hj {     int shift = MS == 1 ? 0 : 32 / (MS - 1);     size_t operator()(const hsh& h) const {       long long res = 0;       for (int M = 0; M < MS; M++) res <<= shift, res ^= h[M];       return res;     }   };   int t;   int n;   set<int> a[MAXN];   unordered_map<hsh, int, hj> mp;   vector<string> str;   int check[MAXN];   int cnt;   int ans;   void build(hsh& h, char c) {     for (int M = 0; M < MS; M++) h[M] = (c + h[M] * K) % MOD[M];   }   void init() {     for (int i = 1; i <= cnt; i++) {       a[i].clear();       check[i] = 0;     }     mp.clear();     cnt = 0;     ans = 0;   }   bool dfs(int u) {     check[u] = 1;     int tookChild = 0;     for (int v : a[u])       if (!check[v]) tookChild |= dfs(v);     ans += tookChild ^ 1;     return tookChild ^ 1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       init();       cin >> n;       str.resize(n + 1);       for (int i = 1; i <= n; i++) cin >> str[i], str[i] =     + str[i];       for (int i = 1; i <= n; i++) {         string& s = str[i];         hsh h(MS);         for (int j = 1; j < (int)s.size(); j++) {           build(h, s[j]);           if (!mp.count(h)) mp[h] = ++cnt;         }       }       for (int i = 1; i <= n; i++) {         string& s = str[i];         hsh h(MS), h2(MS);         for (int j = 1; j < (int)s.size(); j++) {           build(h, s[j]);           if (j >= 2) {             build(h2, s[j]);             if (mp.count(h2)) {               int u = mp[h], v = mp[h2];               a[u].insert(v);               a[v].insert(u);             }           }         }       }       for (int i = 1; i <= cnt; i++)         if (!check[i]) dfs(i);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int dp[55][55][4];   int f(int n, int m, int p) {     if ((n == m && n == 0) || (n == 0 && p == 1) || (m == 0 && p == 2)) {       return dp[n][m][p] = 0;     }     if (dp[n][m][p] != -1) {       return dp[n][m][p];     }     bool g = 0;     if (p == 1) {       for (int i = 1; i <= min(a, n); i++) {         g = (g || (!f(n - i, m, 2)));       }     } else {       for (int i = 1; i <= min(b, m); i++) {         g = (g || (!f(n, m - i, 1)));       }     }     return dp[n][m][p] = g;   }   int main() {     int n, m;     cin >> n >> m >> a >> b;     memset(dp, -1, sizeof(dp));     if (f(n, m, 1)) {       cout <<  First ;     } else {       cout <<  Second ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, mas[1000], ans[1000], anss;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> mas[i];     for (int i = 2; i <= n; i++) {       if (mas[i] + mas[i - 1] < k) {         anss += k - mas[i - 1] - mas[i];         mas[i] = k - mas[i - 1];       }     }     cout << anss <<   n ;     for (int i = 1; i <= n; i++) cout << mas[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   int got[21], n, m, id[1000010], id_cnt;   int stk[21], tot, f[2000010];   bool vis[1000010];   int cnt, to[2000010], nxt[2000010], head[1000010], in[1000010], out[1000010];   inline void insert(int x, int y) {     to[++cnt] = y, nxt[cnt] = head[x], head[x] = cnt;     out[x]++, in[y]++;   }   inline void dfs(int u, int s) {     vis[u] = s;     if (id[u]) {       got[s] |= (1 << id[u] - 1);     }     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (vis[v] == s) continue;       dfs(v, s);     }     return;   }   inline int getcnt(int x) {     int res = 0;     while (x) res++, x -= x & -x;     return res;   }   int main() {     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++) x = read(), y = read(), insert(x, y);     for (int i = 1; i <= n; i++)       if (!out[i]) id[i] = ++id_cnt;     for (int i = 1; i <= n; i++)       if (!in[i]) {         stk[++tot] = i;         dfs(i, i);       }     for (int i = 1; i <= tot; i++)       for (int j = 0; j < (1 << tot); j++) f[j | (1 << i - 1)] |= got[stk[i]];     for (int j = 1; j < (1 << tot) - 1; j++) {       if (getcnt(j) == getcnt(f[j])) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   long long c[N << 2], a[N];   void pushup(int rt) { c[rt] = c[rt << 1] | c[rt << 1 | 1]; }   void build(int rt, int l, int r) {     if (l == r) {       scanf( %I64d , c + rt);       a[l] = c[rt];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   long long query(int rt, int l, int r, int x, int y) {     if (x > y) return 0;     if (x <= l && r <= y) {       return c[rt];     }     int mid = (l + r) >> 1;     long long ret = 0;     if (x <= mid) ret |= query(rt << 1, l, mid, x, y);     if (mid < y) ret |= query(rt << 1 | 1, mid + 1, r, x, y);     return ret;   }   int main() {     int n, k, c;     while (~scanf( %d%d%d , &n, &c, &k)) {       long long tmp = 1;       for (int i = 1; i <= c; i++) {         tmp *= k;       }       build(1, 1, n);       long long ans = (tmp * a[1]) | query(1, 1, n, 2, n);       ans = max(ans, (tmp * a[n]) | query(1, 1, n, 1, n - 1));       for (int i = 2; i < n; i++) {         ans = max(ans, query(1, 1, n, 1, i - 1) | (tmp * a[i]) |                            query(1, 1, n, i + 1, n));       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     set<int> col[26];     vector<int> ans;     int cnt = 0;     for (int i = 0; i < n; i++) {       set<int> used;       for (int j = s[i] -  a  + 1; j < 26; j++)         for (int num : col[j]) used.insert(num);       int newCol = 1;       while (used.count(newCol)) newCol++;       col[s[i] -  a ].insert(newCol);       ans.push_back(newCol);       cnt = max(cnt, newCol);     }     cout << cnt <<   n ;     for (int i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   double ans;   int a[N];   int n, u, p;   int main() {     scanf( %d%d , &n, &u);     ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; i++) {       if (i <= n - 2) {         p = lower_bound(a + i + 2, a + n + 1, a[i] + u) - a;         if (p > n || a[i] + u != a[p]) p--;         if (p >= i + 2) {           ans = max(ans, (a[p] - a[i + 1]) * 1.0 / (a[p] - a[i]));         }       }     }     if (ans == 0)       printf( -1 n );     else       printf( %.11lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, ans = -1, dist[2020];   vector<int> adj[2020], vet;   int main() {     scanf( %d%d , &n, &k);     for (int(i) = (0); (i) < (k); (i)++) {       int v;       scanf( %d , &v);       vet.push_back(v - n);     }     sort((vet).begin(), (vet).end());     vet.resize(unique((vet).begin(), (vet).end()) - vet.begin());     for (int(i) = (0); (i) < (2020); (i)++)       for (int(j) = (0); (j) < (((int)(vet).size())); (j)++)         if (i + vet[j] >= 0 && i + vet[j] < 2020) adj[i].push_back(i + vet[j]);     queue<int> fila;     fila.push(1010);     while (!fila.empty()) {       int v = fila.front();       fila.pop();       if (v == 1010 && dist[v]) {         ans = dist[v];         break;       }       for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)         if (!dist[adj[v][i]]) dist[adj[v][i]] = dist[v] + 1, fila.push(adj[v][i]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > upd;   struct query {     int l, r, t, id, ans;     query() {}     query(int _l, int _r, int _t, int _id) {       l = _l;       r = _r;       t = _t;       id = _id;     }   };   vector<query> que;   stack<pair<int, int> > S;   vector<int> V;   int M[1005][105];   int sz[1005];   int cnt[300005];   int data[100005];   int B;   int l = 1, r = 0, t = 0, Ans = 1;   int cmp(query a, query b) {     if (a.l / B != b.l / B) return a.l < b.l;     if (a.r / B != b.r / B) return a.r < b.r;     return a.t < b.t;   }   int cmpid(query a, query b) { return a.id < b.id; }   int Upd() {     for (int i = (Ans / 100); i < (1000); i++)       if (sz[i] < 100) {         for (int j = (0); j < (100); j++)           if (!M[i][j]) {             return i * 100 + j;           }       }   }   void Add(int a) {     if (!M[a / 100][a % 100]) sz[a / 100]++;     M[a / 100][a % 100]++;     if (Ans == a) Ans = Upd();   }   void Del(int a) {     M[a / 100][a % 100]--;     if (!M[a / 100][a % 100]) {       sz[a / 100]--;       if (Ans > a) Ans = a;     }   }   void add(int a) {     Del(cnt[a]);     Add(++cnt[a]);   }   void del(int a) {     Del(cnt[a]);     Add(--cnt[a]);   }   int main() {     M[0][0] = 1e9;     int n, m;     scanf( %d%d , &n, &m);     B = pow(n, 2.0 / 3);     for (int i = (1); i < (n + 1); i++)       scanf( %d , &data[i]), V.push_back(data[i]);     while (m--) {       int co, a, b;       scanf( %d%d%d , &co, &a, &b);       if (co == 1)         que.push_back(query(a, b, (int)(upd).size(), (int)(que).size()));       else         upd.push_back(make_pair(a, b)), V.push_back(b);     }     sort(V.begin(), V.end());     V.erase(unique(V.begin(), V.end()), V.end());     for (int i = (1); i < (n + 1); i++)       data[i] = lower_bound(V.begin(), V.end(), data[i]) - V.begin() + 1;     for (int i = (0); i < ((int)(upd).size()); i++)       upd[i].second =           lower_bound(V.begin(), V.end(), upd[i].second) - V.begin() + 1;     sort(que.begin(), que.end(), cmp);     for (int i = (0); i < ((int)(que).size()); i++) {       while (l > que[i].l) {         l--;         add(data[l]);       }       while (r < que[i].r) {         r++;         add(data[r]);       }       while (r > que[i].r) {         del(data[r]);         r--;       }       while (l < que[i].l) {         del(data[l]);         l++;       }       while (t < que[i].t) {         int pos = upd[t].first;         S.push(make_pair(pos, data[pos]));         if (l <= pos && pos <= r) del(data[pos]);         data[pos] = upd[t].second;         if (l <= pos && pos <= r) add(data[pos]);         t++;       }       while (t > que[i].t) {         t--;         int pos = S.top().first;         if (l <= pos && pos <= r) del(data[pos]);         data[pos] = S.top().second;         if (l <= pos && pos <= r) add(data[pos]);         S.pop();       }       que[i].ans = Ans;     }     sort(que.begin(), que.end(), cmpid);     for (int i = (0); i < ((int)(que).size()); i++) printf( %d n , que[i].ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long N = 1e5 + 7;   long long p[N], cnt;   bool vis[N];   long long res1 = 0;   long long res2 = 0;   long long res3 = 0;   inline void init(long long NN) {     res1 = res2 = res3 = 0;     for (long long i = 2; i <= NN + res1 + res2 + res3; i++) {       res1 = res2 = res3 = 0;       if (vis[i]) continue;       p[++cnt] = i + res1 + res2 + res3;       res1 = res2 = res3 = 0;       for (long long j = 2; i * j <= NN; j++) vis[i * j] = true;       res1 = res2 = res3 = 0;     }   }   void solve() {     long long a, b;     cin >> a >> b;     res1 = res2 = res3 = 0;     long long now = b;     res1 = res2 = res3 = 0;     if (a % b)       printf( %lld n , a + res1 + res2 + res3);     else {       res1 = res2 = res3 = 0;       long long ans = 1;       res1 = res2 = res3 = 0;       for (long long j = 1; j <= cnt + res1 + res2 + res3; j++) {         res1 = res2 = res3 = 0;         if (b % p[j] == 0) {           res1 = res2 = res3 = 0;           long long tmp = a;           res1 = res2 = res3 = 0;           while (tmp % now == 0) tmp /= p[j];           res1 = res2 = res3 = 0;           ans = max(ans, tmp) + res1 + res2 + res3;           res1 = res2 = res3 = 0;           while (b % p[j] == 0) b /= p[j];           res1 = res2 = res3 = 0;         }       }       long long tmp = a;       if (b != 1) {         res1 = res2 = res3 = 0;         while (tmp % now == 0) tmp /= b;         res1 = res2 = res3 = 0;         ans = max(ans, tmp) + res1 + res2 + res3;         res1 = res2 = res3 = 0;       }       printf( %lld n , ans + res1 + res2 + res3);     }   }   signed main() {     long long t = 1;     res1 = res2 = res3 = 0;     init(100000);     cin >> t;     res1 = res2 = res3 = 0;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fib[100], A[100], B[100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, najwieksza = 2;     fib[0] = 1;     fib[1] = 1;     for (; fib[najwieksza - 1] + fib[najwieksza - 2] <= 1e18; najwieksza++)       fib[najwieksza] = fib[najwieksza - 1] + fib[najwieksza - 2];     cin >> t;     while (t--) {       cin >> n;       vector<int> miejsca;       for (int i = najwieksza - 1; i > 0; i--)         if (fib[i] <= n) {           n -= fib[i];           miejsca.push_back(i);         }       miejsca.push_back(0);       reverse(miejsca.begin(), miejsca.end());       A[1] = 1;       B[1] = (miejsca[1] - 1) / 2;       for (int i = 2; i < (int)miejsca.size(); i++) {         A[i] = A[i - 1] + B[i - 1];         B[i] = A[i - 1] * ((miejsca[i] - miejsca[i - 1] - 1) / 2) +                B[i - 1] * ((miejsca[i] - miejsca[i - 1]) / 2);       }       cout << A[miejsca.size() - 1] + B[miejsca.size() - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mediana(vector<int> &v) {     if (int(v.size()) % 2 == 1) return v[int(v.size()) / 2];     return v[int(v.size()) / 2 - 1];   }   bool esta(vector<int> &v, int x) {     for (int i = 0; i < int(v.size()); i++)       if (v[i] == x) return true;     return false;   }   int main() {     int n, x;     cin >> n >> x;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int amount = 0;     while (mediana(v) != x) {       if (not esta(v, x))         v.push_back(x);       else if (mediana(v) < x)         v.push_back(1000000001);       else         v.push_back(-1);       amount++;       sort(v.begin(), v.end());     }     cout << amount << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 10;   const long long mod = 998244353;   const long long inf = (long long)4e17 + 5;   const int INF = 1e9 + 7;   const double pi = acos(-1.0);   long long inv(long long b) {     if (b == 1) return 1;     return (mod - mod / b) * inv(mod % b) % mod;   }   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n;   int ans[105];   int more[maxn], les[maxn];   int mmax, mmin;   int nex[maxn], pre[maxn];   inline void ask_m(int x) {     printf( ? );     fflush(stdout);     for (int i = 1; i <= n; i++) {       if (i == x)         printf(  2 );       else         printf(  1 );     }     puts(  );     fflush(stdout);     scanf( %d , more + x);     if (more[x] == 0) {       ans[x] = n;       mmax = x;     }   }   inline void ask_l(int x) {     printf( ? );     fflush(stdout);     for (int i = 1; i <= n; i++) {       if (i == x)         printf(  1 );       else         printf(  2 );     }     puts(  );     fflush(stdout);     scanf( %d , les + x);     if (les[x] == 0) {       ans[x] = 1;       mmin = x;     }   }   void solve() {     for (int i = 1; i <= n; i++) {       ask_m(i);     }     for (int i = 1; i <= n; i++) {       ask_l(i);     }     for (int i = 1; i <= n; i++) {       if (more[i] == i || !more[i]) continue;       nex[i] = more[i];       pre[more[i]] = i;     }     for (int i = 1; i <= n; i++) {       if (les[i] == i || !les[i]) continue;       nex[les[i]] = i;       pre[i] = les[i];     }     int fr;     for (int i = 1; i <= n; i++) {       if (!nex[i]) {         fr = i;         break;       }     }     for (int i = n; i >= 1; i--) {       ans[fr] = i;       fr = pre[fr];     }     printf( ! );     for (int i = 1; i <= n; i++) printf(  %d , ans[i]);     puts(  );     fflush(stdout);   }   int main() {     scanf( %d , &n);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int n, ans;   int Dpos[N + 3];   char str[N + 10], Nstr[N + 10];   int main() {     scanf( %d%s , &n, str + 1);     int Ncnt = 0, Ned = n, Nmin = 0;     for (int i = 1; i <= n; i++) {       if (str[i] ==  ( )         Ncnt++;       else         Ncnt--;       if (Nmin > Ncnt) {         Nmin = Ncnt;         Ned = i;       }     }     if (Ncnt) printf( 0 n1 1 n ), exit(0);     int Npos = 1;     for (int i = Ned + 1; i <= n; i++) Dpos[Npos] = i, Nstr[Npos++] = str[i];     for (int i = 1; i <= Ned; i++) Dpos[Npos] = i, Nstr[Npos++] = str[i];     for (int i = 1, Icnt = 0; i <= n; i++) {       if (Nstr[i] ==  ( )         Icnt++;       else         Icnt--;       if (!Icnt) ans++;     }     int fans = ans;     int ansl = 1, ansr = 1;     for (int i = 1; i <= n;) {       int Pcnt = 0;       int j;       for (j = i; j <= n; j++) {         if (Nstr[j] ==  ( )           Pcnt++;         else           Pcnt--;         if (!Pcnt) break;       }       vector<pair<int, int> > vec;       Pcnt = 0;       int Ptot = 0;       for (int k = i + 1; k < j; k++) {         if (Nstr[k] ==  ( )           Pcnt++;         else           Pcnt--;         if (Pcnt == 0) {           if (vec.empty())             vec.push_back(make_pair(i + 1, k));           else             vec.push_back(make_pair(vec.back().second + 1, k));         }       }       for (auto it : vec) {         int L = it.first, R = it.second;         int Kcnt = 0, Ktot = 0;         for (int k = L + 1; k <= R - 1; k++) {           if (Nstr[k] ==  ( )             Kcnt++;           else             Kcnt--;           if (!Kcnt) Ktot++;         }         if (ans < fans - 1 + 2 + Ktot) {           ans = fans - 1 + 2 + Ktot;           ansl = L;           ansr = R;         }       }       Ptot = vec.size();       if (ans < Ptot + 1) {         ans = Ptot + 1;         ansl = i;         ansr = j;       }       i = j + 1;     }     ansl = Dpos[ansl];     ansr = Dpos[ansr];     if (ansl > ansr) swap(ansl, ansr);     printf( %d n%d %d n , ans, ansl, ansr);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5005] = {0};   void ge(int a) {     if (a == 1)       printf( one n );     else if (a == 2)       printf( two n );     else if (a == 3)       printf( three n );     else if (a == 4)       printf( four n );     else if (a == 5)       printf( five n );     else if (a == 6)       printf( six n );     else if (a == 7)       printf( seven n );     else if (a == 8)       printf( eight n );     else if (a == 9)       printf( nine n );   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     if (n == 0)       printf( zero n );     else if (n == 1)       printf( one n );     else if (n == 2)       printf( two n );     else if (n == 3)       printf( three n );     else if (n == 4)       printf( four n );     else if (n == 5)       printf( five n );     else if (n == 6)       printf( six n );     else if (n == 7)       printf( seven n );     else if (n == 8)       printf( eight n );     else if (n == 9)       printf( nine n );     else if (n == 10)       printf( ten n );     else if (n == 11)       printf( eleven n );     else if (n == 12)       printf( twelve n );     else if (n == 13)       printf( thirteen n );     else if (n == 14)       printf( fourteen n );     else if (n == 15)       printf( fifteen n );     else if (n == 16)       printf( sixteen n );     else if (n == 17)       printf( seventeen n );     else if (n == 18)       printf( eighteen n );     else if (n == 19)       printf( nineteen n );     else if (n == 20)       printf( twenty n );     else if (n > 20 && n <= 29) {       printf( twenty- );       int k = n % 10;       ge(k);     } else if (n == 30) {       printf( thirty n );     } else if (n > 30 && n <= 39) {       printf( thirty- );       int k = n % 10;       ge(k);     } else if (n == 40)       printf( forty n );     else if (n > 40 && n <= 49) {       printf( forty- );       int k = n % 10;       ge(k);     } else if (n == 50)       printf( fifty n );     else if (n > 50 && n <= 59) {       printf( fifty- );       int k = n % 10;       ge(k);     } else if (n == 60)       printf( sixty n );     else if (n > 60 && n <= 69) {       printf( sixty- );       int k = n % 10;       ge(k);     } else if (n == 70)       printf( seventy n );     else if (n > 70 && n <= 79) {       printf( seventy- );       int k = n % 10;       ge(k);     } else if (n == 80)       printf( eighty n );     else if (n > 80 && n <= 89) {       printf( eighty- );       int k = n % 10;       ge(k);     } else if (n == 90)       printf( ninety n );     else if (n > 90 && n <= 99) {       printf( ninety- );       int k = n % 10;       ge(k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y, alpha;     int num;   };   int n, c[1510] = {}, ans[1510] = {};   vector<int> a[1510];   point p[1510];   int rec(int v, int pr) {     int r = 0;     for (int i = 0; i < a[v].size(); i++)       if (a[v][i] != pr) r += rec(a[v][i], v);     return (c[v] = r) + 1;   }   bool comp(point p1, point p2) { return (p1.alpha < p2.alpha); }   int rec2(int v, int t, int pr) {     int s = t;     for (int i = t + 1; i <= t + c[v]; i++)       if (p[i].x < p[s].x || (p[i].x == p[s].x && p[i].y < p[s].y)) s = i;     swap(p[s], p[t]);     for (int i = t + 1; i <= t + c[v]; i++)       if (p[i].x != p[t].x)         p[i].alpha = atan((p[i].y - p[t].y) / (p[i].x - p[t].x));       else if (p[i].y > p[t].y)         p[i].alpha = 3.1415926536 / 2;       else         p[i].alpha = -3.1415926536 / 2;     sort(p + t + 1, p + t + c[v] + 1, comp);     ans[p[t++].num] = v;     for (int i = 0; i < a[v].size(); i++)       if (a[v][i] != pr) t += rec2(a[v][i], t, v);     return c[v] + 1;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       a[u].push_back(v);       a[v].push_back(u);     }     for (int i = 0; i < n; i++) {       cin >> p[i].x >> p[i].y;       p[i].num = i;     }     rec(0, -1);     rec2(0, 0, -1);     for (int i = 0; i < n; i++) cout << ans[i] + 1 <<    ;   }


#include <bits/stdc++.h>   const int maxn = (int)1e6;   const int mod = (int)1e9 + 7;   using namespace std;   int n;   long long dp[maxn];   long long a[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     dp[0] = abs(a[0]);     for (int i = 1; i < n; i++) {       dp[i] = abs(a[i] - a[i - 1]) + dp[i - 1];     }     cout << dp[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool mycomp(vector<long long int> a, vector<long long int> b) {     long long int acost = min(2 * a[0], a[1]) - min(a[0], a[1]);     long long int bcost = min(2 * b[0], b[1]) - min(b[0], b[1]);     return acost > bcost;   }   long long int fn(vector<vector<long long int> > arr, long long int n,                    long long int f) {     sort(arr.begin(), arr.end(), mycomp);     long long int productSold = 0;     for (long long int i = 0; i < f; i++) {       productSold += min(2 * arr[i][0], arr[i][1]);     }     for (long long int i = f; i < n; i++) {       productSold += min(arr[i][0], arr[i][1]);     }     return productSold;   }   int32_t main() {     long long int n, f;     cin >> n >> f;     vector<vector<long long int> > arr(n);     for (long long int i = 0; i < n; i++) {       long long int k, l;       cin >> k >> l;       arr[i].push_back(k);       arr[i].push_back(l);     }     long long int ans = fn(arr, n, f);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long f(int x, int len) {     if (len == 0) return 0;     if (x > len)       return (long long)len * (2 * x - len - 1) / 2;     else       return (long long)x * (x - 1) / 2 + len - x + 1;   }   bool ok(int x) {     if (f(x, k - 1) + f(x, n - k) + x <= m)       return 1;     else       return 0;   }   int main() {     cin >> n >> m >> k;     int l = 1, r = 1e9;     while (r - l > 1) {       int mid = (l + r) / 2;       if (ok(mid)) {         l = mid;       } else {         r = mid;       }     }     int res = 0;     if (ok(l)) res = l;     if (ok(r)) res = r;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[310], nex[310], T, N;   bool can, isRoot[310];   void dfs(int x, int val) {     if (T < 0) return;     arr[x] += val;     if (nex[x] != -1) {       T -= arr[x];       dfs(nex[x], arr[x]);     }   }   long long int memo[310][100000 + 100];   long long int solve(int pos, int val) {     if (pos == 0) return val == 0;     if (val <= 0) return val == 0;     if (memo[pos][val] != -1) return memo[pos][val];     long long int ret = solve(pos - 1, val);     if (val - arr[pos] >= 0)       ret = (ret + solve(pos, val - arr[pos])) % 1000000007;     return memo[pos][val] = ret;   }   long long int t[100000 + 100];   int main() {     int Q, x, y;     while (cin >> N >> Q >> T) {       for (int i = 1; i <= N; i++) scanf( %d , &arr[i]);       memset(nex, -1, sizeof nex);       memset(isRoot, true, sizeof isRoot);       for (int i = 0; i < Q; i++) {         scanf( %d %d , &x, &y);         nex[x] = y;         isRoot[y] = false;       }       bool in = false;       for (int i = 1; i <= N; i++)         if (isRoot[i] && nex[i] != -1) {           in = true;           dfs(i, 0);         }       if ((Q > 0 && in == false) || T < 0) {         cout << 0 << endl;         return 0;       }       memset(memo, -1, sizeof memo);       t[0] = 1;       for (int i = 1; i <= N; i++)         for (int j = 0; j <= T; j++) {           if (j - arr[i] >= 0) t[j] = (t[j] + t[j - arr[i]]) % 1000000007;         }       cout << t[T] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150, M = 150, OO = 0x3f3f3f3f;   int n, arr[2005], temp, ans;   void DFS(int u) {     temp++;     if (arr[u] == -1) return;     DFS(arr[u]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , arr + i);     }     for (int i = 1; i <= n; ++i) {       temp = 0;       DFS(i);       ans = max(ans, temp);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int convert(int k) {     if (k < 2)       return k;     else if (k < 5)       return k - 1;     else       return k - 2;   }   int main() {     string s[6];     int A[6][6] = {3, 3, 4, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 2, 3, 3, 2, 2,                    2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1};     for (int i = 0; i < 6; i++) {       cin >> s[i];     }     int best = 0, besti = 0, bestj = 0;     for (int i = 0; i < 6; i++) {       for (int j = 0; j < 8; j++) {         if (s[i][j] ==  . ) {           if (A[i][convert(j)] > best) {             best = A[i][convert(j)];             besti = i;             bestj = j;           }         }       }     }     s[besti][bestj] =  P ;     for (int i = 0; i < 6; i++) {       cout << s[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (a < b) a = b;   }   const int oo = 1 << 30;   const double eps = 1e-7;   const int N = 1 << 10;   const int M = 1;   const long long P = 1000000007;   long long dp[N][N];   int mx;   char s[N];   inline int is(int k) { return 4 == k || 7 == k; }   inline int to(int f, int flag) {     flag = is(flag);     if (0 == f) return 0;     if (1 == f || mx + 1 == f) return flag ? f - 1 : (mx + 1);     return flag ? 0 : f - 1;   }   long long dfs(int id, int f) {     if (id < 0) return !f;     long long &r = dp[id][f];     if (-1 != r) return r;     r = 0;     id--;     r += 8 * dfs(id, to(f, 0));     r += 2 * dfs(id, to(f, 4));     return r %= P;   }   void pre() {     (memset((dp), -1, sizeof(dp)));     dfs(1001, mx + 1);   }   long long dfs_d(int id, int f) {     if (id < 0) return !f;     int k, u;     long long r = 0;     u = s[id];     id--;     for (k = 0; k < (u); k++) r += dfs(id, to(f, k));     r += dfs_d(id, to(f, k));     return r %= P;   }   long long doit(int flag) {     (memset((s), 0, sizeof(s)));     scanf( %s , s);     int i, sn;     sn = strlen(s);     for (i = 0; i < (sn); i++) s[i] -=  0 ;     reverse(s, s + sn);     s[0] -= flag;     for (i = 0; s[i] < 0; i++) {       s[i] = 9;       s[i + 1]--;     }     return dfs_d(sn, mx + 1);   }   int main() {     int T, _ = 0;     long long ans = 0;     scanf( %d %d , &T, &mx);     pre();     while (_++ < T) {       ans = -doit(1);       ans += doit(0);       ans = (ans % P + P) % P;       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     int b;     int c;     int d;     int e;     cin >> a;     int aa[a];     for (b = 0; b < a; ++b) {       cin >> aa[b];     }     d = aa[0];     c = 0;     b = 0;     vector<int> ab;     while (b < a) {       if (aa[b] > d) d = aa[b];       if ((b + 1) == d) c = c + 1;       b = b + 1;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q, a[100100], head, tail;   long long n;   long long solve(long long n, long long k) {     if (k & 1) return (k + 1) / 2;     if (n & 1)       if (k == 2)         return solve(n / 2, n / 2) + (n + 1) / 2;       else         return solve(n / 2, k / 2 - 1) + (n + 1) / 2;     else       return solve(n / 2, k / 2) + n / 2;   }   int main() {     scanf( %I64d , &n);     for (scanf( %d , &q); q--;) {       long long x;       scanf( %I64d , &x);       printf( %I64d n , solve(n, x));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k;   vector<long long int> v[100005];   vector<long long int> res;   long long int ares[100005];   long long int was[100005];   int dfs(long long int ind, long long int c) {     if (c > 100005) {       return -1;     }     if (ares[ind]) return 1;     if (!v[ind].size()) {       ares[ind] = 1;       res.push_back(ind);       return 1;     }     for (auto i : v[ind]) {       int r = dfs(i, c + 1);       if (r < 0) {         return -1;       }     }     ares[ind] = 1;     res.push_back(ind);     return 1;   }   int main() {     cin >> n >> k;     long long int *arr = new long long int[k];     for (long long int i = 0; i < k; i++) {       cin >> arr[i];       arr[i]--;     }     for (long long int i = 0; i < n; i++) {       ares[i] = 0;       long long int a, b;       cin >> b;       for (long long int j = 0; j < b; j++) {         cin >> a;         a--;         v[i].push_back(a);       }     }     for (long long int i = 0; i < k; i++) {       int r = dfs(arr[i], 0);       if (r < 0) {         cout << -1;         return 0;       }     }     cout << res.size() << endl;     for (auto i : res) {       cout << (i + 1) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   const int MAXN = 55;   template <typename T>   inline T sqr(T n) {     return n * n;   }   int n;   long long m;   long long weight[MAXN];   int ans[MAXN];   int main() {     scanf( %d%I64d , &n, &m);     weight[0] = 1ll << (n - 1);     for (int i = 1; i <= n; i++) {       weight[i] = max(weight[i - 1] >> 1, 1ll);     }     int l = 1, r = n;     int num = 1;     long long cur = 0;     while (l <= r) {       if (l == r || cur + weight[num] >= m) {         ans[l] = num;         l++;       } else {         cur += weight[num];         ans[r] = num;         r--;       }       num++;     }     for (int i = 1; i <= n; i++) {       printf( %d%c , ans[i],    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 32005;   int n, m, i, j, f;   int a[N];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (i = m + 1; i <= (n + 1) / 2; i++) {       for (j = m + 1; j < 2 * i; j++) {         f = (i * (2 * i - j) + (n + 1) * (2 * j - i)) / (i + j);         f = max(f, m);         if (f > n - m) continue;         a[i] += n - m - f;       }     }     for (i = m + 1; i <= (n + 1) / 2; i++) ans += 2 * a[i];     if (n & 1) ans -= a[i - 1];     printf( %I64d n , 3 * ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long mod = 1e9 + 7;   long long n, m;   struct mat {     int a[105][105];     mat() { memset(a, 0, sizeof(a)); }     mat operator*(const mat &b) const {       mat c;       for (int i = (1); i < (m + 1); i++) {         for (int j = (1); j < (m + 1); j++) {           for (int k = (1); k < (m + 1); k++) {             c.a[i][j] = (c.a[i][j] + a[i][k] % mod * b.a[k][j] % mod) % mod;           }         }       }       return c;     }   };   mat mod_pow(mat x, long long n) {     mat res;     for (int i = (1); i < (m + 1); i++) res.a[i][i] = 1;     while (n > 0) {       if (n & 1) res = res * x;       x = x * x;       n >>= 1;     }     return res;   }   int main() {     cin >> n >> m;     mat b, x, ans;     for (int i = (1); i < (m + 1); i++) b.a[i][1] = 1;     for (int i = (2); i < (m + 1); i++) x.a[i][i - 1] = 1;     x.a[1][1] = 1;     x.a[1][m] = 1;     ans = mod_pow(x, n - m + 1) * b;     cout << ans.a[1][1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 210000;   int n;   int oke[maxn], okp[maxn];   struct edge {     int y, nex;   } a[maxn << 1];   int len, fir[maxn];   inline void ins(const int x, const int y) {     a[++len] = (edge){y, fir[x]};     fir[x] = len;   }   int siz[maxn], mxs[maxn];   void dfs(const int x, const int fa) {     siz[x] = 1;     for (int k = fir[x], y = a[k].y; k; k = a[k].nex, y = a[k].y)       if (y != fa) {         dfs(y, x);         siz[x] += siz[y];         mxs[x] = max(mxs[x], siz[y]);       }   }   int root, t1, t2;   int d[maxn], f[maxn], f2[maxn];   bool cmp(const int x, const int y) {     return f[x] == f[y] ? f2[x] < f2[y] : f[x] < f[y];   }   int t[maxn], tp;   void Hash(const int x, const int fa) {     siz[x] = 1;     for (int k = fir[x], y = a[k].y; k; k = a[k].nex, y = a[k].y)       if (y != fa && oke[k]) Hash(y, x), siz[x] += siz[y];     tp = 0;     for (int k = fir[x], y = a[k].y; k; k = a[k].nex, y = a[k].y)       if (y != fa && oke[k]) t[++tp] = y;     sort(t + 1, t + tp + 1, cmp);     d[x] = tp + (fa != 0);     f[x] = f2[x] = siz[x];     for (int i = 1; i <= tp; i++) {       int y = t[i];       f[x] = f[x] * (siz[y] + 1) * f[y];       f2[x] = f2[x] + (siz[y] + 2) * (f2[y] + 1);     }   }   int ans[maxn];   void cal(const int x, const int fa) {     if (okp[x] && d[x] < 4) ans[x]++;     for (int k = fir[x], y = a[k].y; k; k = a[k].nex, y = a[k].y)       if (y != fa && oke[k]) cal(y, x);     tp = 0;     for (int k = fir[x], y = a[k].y; k; k = a[k].nex, y = a[k].y)       if (y != fa && oke[k]) t[++tp] = y;     sort(t + 1, t + tp + 1, cmp);     for (int i = 1; i <= tp; i++) {       int y = t[i], ty = t[i - 1];       if (f[y] != f[ty] || f2[y] != f2[ty]) ans[x] += ans[y];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       ins(x, y), ins(y, x);     }     dfs(1, 0);     for (int i = 1; i <= n; i++)       if (mxs[i] * 2 <= n && (n - siz[i]) * 2 <= n) {         if (!t1)           t1 = i;         else           t2 = i;       }     for (int i = 1; i <= len; i++) oke[i] = 1;     for (int i = 1; i <= n; i++) okp[i] = 1;     if (t2) {       for (int k = fir[t1], y = a[k].y; k; k = a[k].nex, y = a[k].y)         if (y == t2) oke[k] = 0;       for (int k = fir[t2], y = a[k].y; k; k = a[k].nex, y = a[k].y)         if (y == t1) oke[k] = 0;       okp[root = ++n] = 0;       ins(root, t1), ins(root, t2);       oke[len - 1] = oke[len] = 1;     } else       root = t1;     Hash(root, 0);     cal(root, 0);     printf( %d n , ans[root]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int ts;     cin >> ts;     while (ts--) {       string s, t;       cin >> s >> t;       int n = (int)s.size();       map<string, int> cnt;       for (int i = 0; i < n; i += 2) {         string cur =   ;         cur += s[i];         cur += s[i + 1];         sort(cur.begin(), cur.end());         cnt[cur]++;       }       for (int i = 0; i < n; i += 2) {         string cur =   ;         cur += t[i];         cur += t[i + 1];         sort(cur.begin(), cur.end());         cnt[cur]--;       }       bool bad = false;       for (auto c : cnt) {         if (c.second != 0) {           bad = true;         }       }       if (bad) {         cout << -1 <<   n ;         continue;       }       while (true) {         int start = rnd() % (n / 2 + 1);         vector<int> ord;         if (start != 0) {           ord.push_back(start - 1);         }         string cur = s, me = t;         reverse(cur.begin(), cur.begin() + 2 * start);         int its = 0;         bool bad = false;         while (cur.size() > 0) {           int ind = (int)me.size() - 2;           vector<int> sh;           for (int i = (int)cur.size() - 2; i >= 0; i -= 2) {             sh.push_back(i);           }           shuffle(sh.begin() + 1, sh.end(), rnd);           bool mda = false;           for (int i : sh) {             if (cur[i] == me[ind] && cur[i + 1] == me[ind + 1]) {               if (i + 2 != (int)cur.size()) {                 ord.push_back(i / 2);                 reverse(cur.begin(), cur.begin() + i + 2);                 ord.push_back(ind / 2);                 reverse(cur.begin(), cur.end());               }               mda = true;               break;             }           }           if (!mda) {             vector<int> sh;             for (int i = 0; i < (int)cur.size(); i += 2) {               sh.push_back(i);             }             shuffle(sh.begin(), sh.end(), rnd);             for (int i : sh) {               if (cur[i] == me[ind + 1] && cur[i + 1] == me[ind]) {                 ord.push_back(i / 2);                 reverse(cur.begin(), cur.begin() + i + 2);                 ord.push_back(0);                 reverse(cur.begin(), cur.begin() + 2);                 ord.push_back(ind / 2);                 reverse(cur.begin(), cur.end());                 break;               }             }           }           if (ord.size() > n + 1) {             bad = true;             break;           }           for (int it = 0; it < 2; it++) {             cur.pop_back(), me.pop_back();           }         }         if (bad) {           continue;         } else {           cout << ord.size() <<   n ;           string f = s, g = t;           for (int a : ord) {             cout << 2 * (a + 1) <<    ;           }           cout <<   n ;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long n;   bool len(char x) {     return x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u  || x ==  y ;   }   int main() {     cin >> n;     cin >> s;     cout << s[0];     for (int i = 1; i < n; i++) {       if (len(s[i]) && len(s[i - 1])) continue;       cout << s[i];     }     cout << endl;     return 0;   }