#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     vector<pair<long long, long long>> a((size_t)n);     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.rbegin(), a.rend());     vector<long long> b((size_t)n);     for (long long i = 0; i < n; i++) {       b[i] = a[i].second * 2;       if (i >= 1) {         cout << b[i - 1] + 1 <<     << b[i] + 1 <<   n ;       }     }     for (long long i = 0; i < n; i++) {       cout << a[i].second * 2 + 1 + 1 <<     << b[i + a[i].first - 1] + 1 <<   n ;       if (i + a[i].first - 1 == (long long)b.size() - 1) {         b.push_back(a[i].second * 2 + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       cout << 0 <<     << 0 <<     << n;     }   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 50;   int n, m, w[N], dep[N];   vector<pair<int, int>> g[N];   vector<pair<int, long long>> route[N];   void dfs(int first, int d) {     dep[first] = d;     for (auto &e : g[first]) dfs(e.first, d + e.second);   }   int p(int f, int first) {     if (first == f * 2) return first + 1;     return first - 1;   }   long long qry(int a, int h, int c) {     if (a > n || c > h) return 0;     auto p = --upper_bound(route[a].begin(), route[a].end(),                            pair<int, long long>(h - c, 1e18));     long long cnt = p - route[a].begin() + 1;     return cnt * (h - c) - p->second;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; ++i) {       int u = i / 2, v = i;       scanf( %d , w + i);       g[u].push_back({v, w[i]});     }     dfs(1, 0);     for (int i = 1; i <= n; ++i) {       int j = i;       route[i].push_back({0, 0ll});       while (j != 1) {         j /= 2;         route[j].push_back({dep[i] - dep[j], 0ll});       }     }     for (int i = 1; i <= n; ++i) {       sort(route[i].begin(), route[i].end());       int sz = route[i].size();       for (int j = 1; j <= sz - 1; ++j)         route[i][j].second = route[i][j].first + route[i][j - 1].second;     }     while (m--) {       int a, h;       scanf( %d%d , &a, &h);       long long ans = qry(a, h, 0);       int c = 0;       while (1) {         c += w[a];         if (a == 1 || c > h) break;         int t = p(a / 2, a);         ans += qry(t, h, c + w[t]);         ans += h - c;         a /= 2;       }       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, vector<long long>, greater<long long>> pq1, pq2;   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       res *= a;       b--;     }     return res;   }   long long parent[200005], sz[200005], visit[200005] = {0}, cnt[200005] = {0};   vector<pair<long long, long long>> vt[200005];   vector<long long> v[200005];   struct Test {     long long a, b, c;   };   bool comp(const Test &p1, const Test &p2) { return p1.a < p2.a; }   long long find_parent(long long a) {     if (a == parent[a])       return a;     else       return parent[a] = find_parent(parent[a]);   }   long long dfs(long long a) {     visit[a] = 1;     cnt[a]++;     for (int i = 0; i < v[a].size(); ++i) {       long long b = v[a][i];       if (visit[b] == 0) {         dfs(b);       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, x, y, st1, st2, z;     vector<Test> w;     cin >> n >> m;     long long cnt1 = 0;     for (int i = 0; i < m; ++i) {       cin >> x >> y >> z;       vt[x].push_back({y, z});       vt[y].push_back({x, z});       if (cnt1 == 0) {         w.push_back({0, x, y});         st1 = x;         st2 = y;       } else         w.push_back({z, x, y});       cnt1++;     }     for (int i = 1; i < n + 1; ++i) {       sz[i] = 0;       parent[i] = i;     }     sort(w.begin(), w.end(), comp);     for (int i = 0; i < w.size(); ++i) {       long long p1 = w[i].b;       long long p2 = w[i].c;       long long par1 = find_parent(p1);       long long par2 = find_parent(p2);       if (par1 != par2) {         v[p1].push_back(p2);         v[p2].push_back(p1);         if (sz[par1] <= sz[par2]) {           sz[par2] += sz[par1];           parent[par1] = par2;         } else {           sz[par1] += sz[par2];           parent[par2] = par1;         }       }     }     if (v[st1].size() == 1) {       if (vt[st1].size() == 1)         cout <<  1000000000  << endl;       else {         long long mn = 1000000000;         for (int j = 0; j < vt[st1].size(); ++j) {           if (v[st1][j] == st2) continue;           mn = min(mn, vt[st1][j].second);         }         cout << mn << endl;       }     } else {       visit[st1] = 1;       dfs(st2);       long long mn = 1000000000;       for (int i = 1; i < n + 1; ++i) {         if (cnt[i] > 0) {           for (int j = 0; j < vt[i].size(); ++j) {             if (i == st2 && vt[i][j].first == st1) continue;             if (cnt[vt[i][j].first] == 0) mn = min(mn, vt[i][j].second);           }         }       }       cout << mn << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int N = 1000005;   class cmp {    public:     bool operator()(long long &A, long long &B) { return A > B; }   };   bool by_sec(pair<long long, long long> &A, pair<long long, long long> &B) {     return A.second < B.second;   }   bool is(pair<long long, long long> a, pair<long long, long long> b) {     return !((a.first > b.second && a.second > b.second) ||              (a.first < b.first && a.second < b.first));   }   long double dist(pair<long long, long long> p1, pair<long long, long long> p2) {     return (long double)sqrt(         (long double)(p1.first - p2.first) * (p1.first - p2.first) +         (long double)(p1.second - p2.second) * (p1.second - p2.second));   }   pair<bool, vector<long long> > is_in(vector<long long> v, long long sum) {     long long n = v.size();     bool dp[30][1000];     memset(dp, 0, sizeof(dp));     ;     for (int i = 0; i < sum + 1; i++) dp[0][i] = 0;     for (int i = 0; i < n + 1; i++) dp[i][0] = 1;     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < sum + 1; j++) {         dp[i][j] = dp[i - 1][j];         if (v[i - 1] <= j) dp[i][j] = dp[i][j] | dp[i - 1][j - v[i - 1]];       }     long long i = n;     long long currSum = sum;     vector<long long> set1, set2;     if (!dp[n][sum]) return (make_pair(dp[n][sum], set1));     while (i > 0 && currSum >= 0) {       if (dp[i - 1][currSum]) {         i--;         set2.push_back(v[i]);       } else {         i--;         currSum -= v[i];         set1.push_back(v[i]);       }     }     return make_pair(dp[n][sum], set1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     bool mp[8000 + 5];     long long t;     cin >> t;     while (t--) {       long long n;       memset(mp, 0, sizeof(mp));       ;       cin >> n;       vector<long long> v(n);       for (int i = 0; i < n; i++) cin >> v[i], mp[v[i]] = 1;       for (int i = 0; i < n; i++) {         long long s = v[i];         for (int j = i + 1; j < n; j++) {           s += v[j];           if (s <= n && mp[s]) mp[s] = 0;         }       }       long long cnt = 0;       for (int i = 0; i < n; i++)         if (!mp[v[i]]) cnt++;       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long mnr = 1e9, mxl = -1e9;       for (long long i = 0; i < n; i++) {         long long l, r;         cin >> l >> r;         mnr = min(mnr, r);         mxl = max(mxl, l);       }       cout << (n == 1 ? 0 : max(mxl - mnr, 0ll)) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10000 + 20;   int sa[N], cc[N], t1[N], t2[N], height[N], rk[N];   int n;   char s[N], t[N];   bool cmp(int *y, int a, int b, int k) {     int a1 = y[a], a2 = (a + k >= n) ? -1 : y[a + k];     int b1 = y[b], b2 = (b + k >= n) ? -1 : y[b + k];     return a1 == b1 && a2 == b2;   }   void buildSa(int m) {     int *x = t1, *y = t2;     for (int i = 0; i < m; i++) cc[i] = 0;     for (int i = 0; i < n; i++) cc[x[i] = s[i]]++;     for (int i = 1; i < m; i++) cc[i] += cc[i - 1];     for (int i = n - 1; i >= 0; i--) sa[--cc[x[i]]] = i;     for (int k = 1; k <= n; k <<= 1) {       int p = 0;       for (int i = n - k; i < n; i++) y[p++] = i;       for (int i = 0; i < n; i++)         if (sa[i] >= k) y[p++] = sa[i] - k;       for (int i = 0; i < m; i++) cc[i] = 0;       for (int i = 0; i < n; i++) cc[x[y[i]]]++;       for (int i = 1; i < m; i++) cc[i] += cc[i - 1];       for (int i = n - 1; i >= 0; i--) sa[--cc[x[y[i]]]] = y[i];       swap(x, y);       x[sa[0]] = 0;       m = 1;       for (int i = 1; i < n; i++) {         x[sa[i]] = cmp(y, sa[i], sa[i - 1], k) ? m - 1 : m++;       }       if (m >= n) break;     }   }   void buildH() {     for (int i = 0; i < n; i++) rk[sa[i]] = i;     height[0] = 0;     int k = 0;     for (int i = 0; i < n; i++) {       if (!rk[i]) continue;       int j = sa[rk[i] - 1];       if (k) k--;       while (s[i + k] == s[j + k]) k++;       height[rk[i]] = k;     }   }   int main() {     scanf( %s , t);     int len1 = strlen(t);     for (int i = 0; t[i]; i++) s[n++] = t[i];     s[n++] =  # ;     scanf( %s , t);     for (int i = 0; t[i]; i++) s[n++] = t[i];     buildSa(1000);     buildH();     int ans = 1e9 + 7;     for (int i = 1; i < n; i++) {       if (height[i]) {         if ((sa[i] >= len1 && sa[i - 1] < len1) ||             (sa[i] < len1 && sa[i - 1] >= len1)) {           if (height[i - 1] < height[i] && height[i + 1] < height[i])             ans = min(ans, max(height[i - 1], height[i + 1]) + 1);         }       }     }     if (ans == 1e9 + 7) ans = -1;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   string s;   int sz;   vector<pair<int, string> > e;   int v[2][200009];   int c[200009];   int Call(int in, int count) {     if (c[in] != -1) {       Call(c[in] - 1, count + 1);     } else {       int i;       printf(  n%d  , count + 1);     }   }   int Pr(int in) {     printf( %d  , in + 1);     if (c[in] != -1) {       Pr(c[in] - 1);       c[in] = 0;     } else {       c[in] = 0;     }   }   int main() {     int i, j, k = 0, n = 0, m = 0;     cin >> s;     sz = s.size();     for (i = 0; i < sz; i++) {       if (s[i] - 48 == 0)         v[0][n++] = i + 1;       else         v[1][m++] = i + 1;     }     int u = 0;     for (i = 0, j = 0; i < sz; i++) {       if (s[i] - 48 == 0) {         if (j == m)           c[i] = -1;         else if (i + 1 > v[1][j])           return 0 * printf( -1 );         else {           c[i] = v[1][j];           j++;         }       } else {         while (i + 1 > v[0][u]) {           u++;           if (u >= n) return 0 * printf( -1 );         }         c[i] = v[0][u];         u++;       }     }     string q;     for (i = 0; i < sz; i++)       if (c[i] == -1) k++;     printf( %d , k);     for (i = 0; i < sz; i++) {       q = i + 1 + 48;       if (c[i] == -1)         printf(  n1 %d , i + 1);       else if (c[i] != 0) {         Call(i, 0);         Pr(i);       }     }   }


#include <bits/stdc++.h>   const int N = 105;   char matrix[N][N];   void solve(int i, int j, int type) {     char c =  a ;     switch (type) {       case 0:         while (1) {           if (matrix[i - 1][j] == c || matrix[i - 1][j + 1] == c ||               matrix[i + 1][j] == c || matrix[i + 1][j + 1] == c ||               matrix[i][j - 1] == c || matrix[i][j + 2] == c) {             c = (char)(c + 1);           } else {             break;           }         }         matrix[i][j] = matrix[i][j + 1] = c;         break;       case 1:         while (1) {           if (matrix[i - 1][j] == c || matrix[i + 2][j] == c ||               matrix[i][j - 1] == c || matrix[i + 1][j - 1] == c ||               matrix[i][j + 1] == c || matrix[i + 1][j + 1] == c) {             c = (char)(c + 1);           } else {             break;           }         }         matrix[i][j] = matrix[i + 1][j] = c;         break;       case 2:         while (1) {           if (matrix[i - 1][j] == c || matrix[i - 1][j + 1] == c ||               matrix[i + 1][j] == c || matrix[i + 1][j + 1] == c ||               matrix[i][j - 1] == c || matrix[i + 1][j - 1] == c ||               matrix[i][j + 2] == c || matrix[i + 1][j + 2] == c) {             c = (char)(c + 1);           } else {             break;           }         }         matrix[i][j] = matrix[i + 1][j] = matrix[i][j + 1] =             matrix[i + 1][j + 1] = c;         break;     }   }   int main() {     int n, m, a, b, c, i, j;     bool ok = true;     scanf( %d%d%d%d%d , &n, &m, &a, &b, &c);     if (n & 1 && m & 1) {       ok = false;     } else if (n & 1) {       for (i = 1; i <= n - 1 && ok; i += 2) {         for (j = 1; j <= m && ok; j += 2) {           if (c) {             solve(i, j, 2);             c--;           } else if (b >= 2) {             solve(i, j, 1);             solve(i, j + 1, 1);             b -= 2;           } else if (a >= 2) {             solve(i, j, 0);             solve(i + 1, j, 0);             a -= 2;           } else {             ok = false;           }         }       }       for (j = 1; j <= m && ok; j += 2) {         if (a) {           solve(i, j, 0);           a--;         } else {           ok = false;         }       }     } else if (m & 1) {       for (i = 1; i <= n && ok; i += 2) {         for (j = 1; j <= m - 1 && ok; j += 2) {           if (c) {             solve(i, j, 2);             c--;           } else if (a >= 2) {             solve(i, j, 0);             solve(i + 1, j, 0);             a -= 2;           } else if (b >= 2) {             solve(i, j, 1);             solve(i, j + 1, 1);             b -= 2;           } else {             ok = false;           }         }       }       for (i = 1; i <= n && ok; i += 2) {         if (b) {           solve(i, j, 1);           b--;         } else {           ok = false;         }       }     } else {       for (i = 1; i <= n && ok; i += 2) {         for (j = 1; j <= m && ok; j += 2) {           if (c) {             solve(i, j, 2);             c--;           } else if (a >= 2) {             solve(i, j, 0);             solve(i + 1, j, 0);             a -= 2;           } else if (b >= 2) {             solve(i, j, 1);             solve(i, j + 1, 1);             b -= 2;           } else {             ok = false;           }         }       }     }     if (ok) {       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           printf( %c , matrix[i][j]);         }         printf(  n );       }     } else {       printf( IMPOSSIBLE n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     int n, m;     cin >> n >> m;     vector<int> ans(n);     for (int i = 0; i < n; i++) {       ans[i] = i + 1;     }     vector<int> check;     do {       int sm = 0;       for (int i = 0; i < n; i++) {         for (int j = i; j < n; j++) {           int mn = INF;           for (int y = i; y <= j; y++) {             mn = min(mn, ans[y]);           }           sm += mn;         }       }       check.push_back(sm);     } while (next_permutation(ans.begin(), ans.end()));     int mx = -1;     for (int i = 0; i < check.size(); i++) {       mx = max(mx, check[i]);     }     int now = 0, s = 0;     for (int i = 0; i < check.size(); i++) {       if (check[i] == mx) {         now++;         if (now == m) {           break;         }       }       next_permutation(ans.begin(), ans.end());     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 5;   const int INF = 1e9 + 5;   const int mod = 1000000007;   const double eps = 1e-7;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long a, b, k;     while (cin >> k >> a >> b) {       if (b <= 0) {         a = -a;         b = -b;         swap(a, b);       }       long long ans = b / k - a / k;       if (a % k == 0 || a < 0) ans++;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int M = 7;   int n, p, k;   int s[N + 1][M + 1];   long long dp[N + 1][1 << M + 1];   pair<int, int> a[N + 1];   long long go(int idx, int mask) {     if (idx > n) {       if (mask == ((1 << p) - 1)) {         return 0;       } else {         return -1e18;       }     }     if (dp[idx][mask] != -1) {       return dp[idx][mask];     }     int players = __builtin_popcount(mask);     int aud = idx - players - 1;     long long ans = 0;     if (players < p) {       for (int i = 0; i < p; i++) {         int val = mask & (1 << i);         if (!val) {           ans = max(ans, 1LL * s[a[idx].second][i + 1] +                              1LL * go(idx + 1, mask | (1 << i)));         }       }     }     if (aud < k) {       ans = max(ans, 1LL * a[idx].first + 1LL * go(idx + 1, mask));     } else {       ans = max(ans, go(idx + 1, mask));     }     return dp[idx][mask] = ans;   }   int main() {     cin >> n >> p >> k;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[i] = {x, i};     }     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= p; j++) {         cin >> s[i][j];       }     }     memset(dp, -1, sizeof(dp));     cout << go(1, 0);   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<short> g[10003];   int main() {     scanf( %d , &n);     int maxi;     for (maxi = 1; ((maxi * maxi - maxi) >> 1) <= n; maxi++)       ;     maxi--;     int end = 1;     int i, j;     for (i = 1; i < maxi; i++) {       for (j = 0; j < maxi - i; j++) g[i].push_back(end + j);       for (j = i + 1; j <= maxi; j++) g[j].push_back(end + (j - i - 1));       end += maxi - i;     }     printf( %d n , maxi);     for (i = 1; i <= maxi; i++) {       printf( %d , (int)g[i][0]);       for (j = 1; j < g[i].size(); j++) printf(  %d , (int)g[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     if (x < y) swap(x, y);     while (y > 0) {       T f = x % y;       x = y;       y = f;     }     return x;   }   template <typename T>   pair<T, T> exgcd(T x, T y) {     if (x < y) swap(x, y);     pair<T, T> r = make_pair(1, 0);     while (y > 0) {       T f = x % y;       r = make_pair(r.second, r.first - (x / y) * r.second);       x = y;       y = f;     }     return r;   }   const int maxn = 1e5;   int n;   int P[maxn + 1], T[maxn + 1];   int SP[maxn + 1];   int TP[maxn + 1];   int lvl[maxn + 1];   vector<int> child[maxn + 1];   int bg[maxn + 1];   int ed[maxn + 1];   int tt = 0;   void dfs(int u, bool sp = false) {     bg[u] = tt++;     for (auto c : child[u]) lvl[c] = lvl[u] + 1, dfs(c);     ed[u] = tt++;   }   bool isAsc(int u, int v) { return bg[u] <= bg[v] && ed[v] <= ed[u]; }   int main(int argc, char *argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     {       for (int i = 1; i <= n; i++) {         cin >> P[i] >> T[i];         if (T[i] == 0) {           SP[i] = SP[P[i]];           TP[i] = i;         } else if (T[i] == 1) {           SP[i] = i;           TP[i] = TP[P[i]];         } else {           TP[i] = i;           SP[i] = i;         }         bg[i] = ed[i] = 0;       }       for (int i = 1; i <= n; i++) {         if (P[i] != -1) {           child[P[i]].push_back(i);         }       }       tt = 1;       for (int i = 1; i <= n; i++) {         if (!bg[i]) {           lvl[i] = 1;           dfs(i);         }       }       int q;       cin >> q;       while (q--) {         int t, u, v, ov;         cin >> t >> u >> v;         if (u == v) {           cout <<  NO  << endl;           continue;         }         if (t == 1) {           if ((isAsc(u, v) && lvl[SP[v]] <= lvl[u]))             cout <<  YES  << endl;           else             cout <<  NO  << endl;         } else {           int av = TP[v];           if (av != v && (isAsc(av, u) && lvl[SP[u]] <= lvl[av]))             cout <<  YES  << endl;           else {             int au = SP[u];             if (au != v && isAsc(au, v) && lvl[TP[v]] <= lvl[au])               cout <<  YES  << endl;             else               cout <<  NO  << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 300010, modP = 1e9 + 7, oo = 23041997, maxB = 600;   const double PI = acos(-1);   int prime[maxN], a[maxN], cnt[maxN], n, POW[maxN], res, p[maxN], maxv;   void sieve() {     for (int i = 2; i <= maxv; ++i)       if (prime[i] == 0) {         int s = 2 * i;         while (s <= maxv) {           prime[s] = i;           s += i;         }       }   }   void factorize(int x) {     p[0] = 0;     while (prime[x]) {       p[++p[0]] = prime[x];       x /= prime[x];     }     p[++p[0]] = x;   }   int main() {     cin >> n;     maxv = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       maxv = max(maxv, a[i]);       for (int j = 1; j <= (int)sqrt(a[i]); ++j)         if (a[i] % j == 0) {           ++cnt[j];           if (a[i] / j != j) ++cnt[a[i] / j];         }     }     POW[0] = 1;     for (int i = 1; i <= n; ++i) POW[i] = (1ll * POW[i - 1] * 2) % modP;     sieve();     res = POW[n] - 1;     for (int i = 2; i <= maxv; ++i) {       factorize(i);       bool check = true;       for (int j = 2; j <= p[0]; ++j)         if (p[j] == p[j - 1]) check = false;       if (check && cnt[i]) {         int tmp = (((POW[cnt[i]] - 1) % modP) + modP) % modP;         if ((p[0] % 2) == 0)           res = (res + tmp) % modP;         else           res = (((res - tmp) % modP) + modP) % modP;       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string ans;       for (int i = 0; i < n; i++) {         ans += s[2 * i];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using pcc = pair<char, char>;   using pdd = pair<double, double>;   using vi = vector<int>;   using vs = vector<string>;   using vll = vector<ll>;   using vpii = vector<pii>;   using vc = vector<char>;   using vd = vector<double>;   bool cmp(pii a, pii b) {     if (a.second * b.first < b.second * a.first) return true;     return false;   }   int main(int argc, char* argv[]) {     ll t, a, b, p, i, j, l;     char str[200100];     scanf( %d%*c , &(t));     while (t--) {       scanf( %lld %lld %lld , &a, &b, &p);       scanf( %s , str);       l = strlen(str);       ll pre = 0, tot = 0;       for (i = 1; i < l; i++) {         if (str[i] != str[pre]) {           if (str[pre] ==  A ) {             tot += a;           } else             tot += b;           pre = i;         }       }       if (pre < l - 1) {         if (str[pre] ==  A ) {           tot += a;         } else           tot += b;       }       pre = 0;       for (i = 0; i < l; i++) {         if (tot <= p) break;         if (str[i] != str[pre]) {           if (str[pre] ==  A ) {             tot -= a;           } else             tot -= b;           pre = i;         }       }       if (tot > p)         pre = l;       else         pre++;       printf( %lld , (pre)), printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, d;     cin >> n >> d;     long long k = 0, c = 0, a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     c = 0;     for (long long i = 1; i < n; i++) {       if (a[i - 1] < a[i]) continue;       k = a[i - 1] - a[i] + d;       c += k / d;       a[i] += (k / d) * d;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, z, l, i, lc;     cin >> n >> m >> z;     l = max(n, m);     for (i = l; i <= n * m; i += l) {       if (i % n == 0 && i % m == 0) break;     }     cout << z / i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> g(n + 1);     vector<int> a(n);     for (int i = 0; i < m; i++) {       int maxj = 0;       for (int j = 0; j < n; j++) {         cin >> a[j];         if (a[j] > a[maxj])           maxj = j;         else if (a[j] == a[maxj]) {           if (j < maxj) maxj = j;         }       }       g[maxj + 1]++;       a.resize(n);     }     int ma = 0;     for (int i = 1; i <= n; i++) {       if (g[i] > g[ma])         ma = i;       else if (g[i] == g[ma]) {         if (i < ma) ma = i;       }     }     cout << ma;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int len = str.length();     int mx = 0;     for (int j = 0; j < len; j++) {       char ch = str[j];       str[j] =  V ;       int ans = 0;       bool flag = false;       for (int i = 0; i < len; i++) {         if (str[i] ==  V )           flag = true;         else {           if (str[i] ==  K  && flag) {             ans++;             flag = false;           } else             flag = false;         }       }       str[j] = ch;       mx = max(ans, mx);     }     for (int j = 0; j < len; j++) {       char ch = str[j];       str[j] =  K ;       int ans = 0;       bool flag = false;       for (int i = 0; i < len; i++) {         if (str[i] ==  V )           flag = true;         else {           if (str[i] ==  K  && flag) {             ans++;             flag = false;           } else             flag = false;         }       }       str[j] = ch;       mx = max(ans, mx);     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n;       cin >> n;       vector<long long int> a(n);       for (long long int i = 0; i < n; i++) cin >> a[i];       vector<long long int> t(n);       t[0] = 1;       for (long long int i = 1; i < n; i++) t[i] = max(a[i] + 1, t[i - 1]);       for (int i = n - 2; i >= 0; i--) t[i] = max(t[i + 1] - 1, t[i]);       long long s = 0;       for (long long int i = 0; i < n; i++) s += t[i] - a[i] - 1;       cout << s;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int inf = 1061109567;   const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   map<int, int> mp[100005], vis;   int tot;   int lowbit(int x) { return x & (-x); }   void update(int t, int x, int val) {     for (int i = t; i <= 1e9 + 2; i += lowbit(i)) {       mp[x][i] += val;     }   }   int query(int t, int x) {     int ret = 0;     for (int i = t; i > 0; i -= lowbit(i)) {       ret += mp[x][i];     }     return ret;   }   int main() {     int n, sign, t, x;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &sign, &t, &x);       if (!vis[x]) {         vis[x] = ++tot;       }       if (sign == 1) {         update(t, vis[x], 1);       } else if (sign == 2) {         update(t, vis[x], -1);       } else {         printf( %d n , query(t, vis[x]));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   int a[100005];   int main() {     int n;     scanf( %d , &n);     bool one = true;     for (int i = 0; i < n + 1; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] > 1 && a[i] > 1) {         one = false;         break;       }     }     if (one) {       cout <<  perfect ;       return 0;     }     cout <<  ambiguous n0  ;     int c = 2;     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] == 1) {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       } else {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       }     }     cout <<   n0  ;     c = 2;     for (int i = 1; i < n + 1; ++i) {       if (a[i - 1] == 1) {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - 1);         }         c += a[i];       } else {         for (int j = 0; j < a[i]; ++j) {           printf( %d  , c - ((j + 1) % a[i - 1]) - 1);         }         c += a[i];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD9 = 1e9 + 7;   const int MOD91 = 1e9 + 9;   const unsigned long long MOD12 = 1e12 + 39LL;   const unsigned long long MOD15 = 1e15 + 37LL;   const int INF = 1e9;   const int base = 1e9;   const int MAX = 2e5;   const long double EPS = 1e-10;   string second;   int n, k;   int a[30][30];   int dpt[101][30][101];   int dp(int pos, int prev, int left) {     if (pos == second.size()) {       return 0;     }     if (dpt[pos][prev][left] != -1) {       return dpt[pos][prev][left];     }     if (left == 0) {       return dpt[pos][prev][left] = dp(pos + 1, second[pos] -  a , left) +                                     a[prev][second[pos] -  a ];     }     int b = -INF;     for (int i = (0); i < (26); ++i) {       b = max(b,               dp(pos + 1, i, left - (i != int(second[pos] -  a ))) + a[prev][i]);     }     return dpt[pos][prev][left] = b;   }   int main() {     cin >> second >> k;     cin >> n;     memset(dpt, -1, sizeof(dpt));     for (int i = (0); i < (n); ++i) {       char x, y;       int xx;       cin >> x >> y >> xx;       a[x -  a ][y -  a ] = xx;     }     cout << dp(0, 27, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 85;   double l[N], r[N], ans[N][N], ago[N], now[N], dp[N][N];   int main() {     vector<double> g;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &l[i], &r[i]);       g.push_back(l[i]), g.push_back(r[i]);     }     sort(g.begin(), g.end());     g.erase(unique(g.begin(), g.end()), g.end());     vector<pair<double, double> > p;     for (int i = 0; i < g.size() - 1; ++i) p.push_back(make_pair(g[i], g[i + 1]));     for (int t = 0; t < p.size(); ++t) {       for (int i = 1; i <= n; ++i) {         double L = p[t].first, R = p[t].second;         if (!(l[i] >= R || r[i] <= L)) {           for (int j = 0; j <= n; ++j)             for (int k = 0; k <= n; ++k) dp[j][k] = 0.0;           dp[0][0] = 1.0;           int cnt = 0;           vector<int> used;           for (int k = 1; k <= n; ++k) {             if (l[k] >= R || r[k] <= L) {               now[k] = 0.0;               if (r[k] <= L) cnt++;             } else               now[k] = (R - L) / (r[k] - l[k]), used.push_back(k);           }           int m = used.size();           for (int _ = 0; _ < m; ++_) {             int x = used[_];             if (x == i) continue;             for (int k = _ + 1; k >= 0; --k)               for (int o = _ + 1 - k; o >= 0; --o) {                 dp[k + 1][o] += dp[k][o] * ago[x];                 dp[k][o + 1] += dp[k][o] * now[x];                 dp[k][o] *= 1.0 - now[x] - ago[x];               }           }           for (int j = 0; j < m; ++j)             for (int k = 0; k < m - j; ++k) {               ans[i][cnt + j] += dp[j][k] * now[i] / (1 + k);               ans[i][cnt + j + k + 1] -= dp[j][k] * now[i] / (1 + k);             }         }       }       for (int i = 1; i <= n; ++i) ago[i] += now[i];     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < n; ++j) {         if (j) {           ans[i][j] += ans[i][j - 1];         }         printf( %.12f%c , ans[i][j], j == n - 1 ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double p, e[100010], dp[100010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf , &p);       e[i] = p * (e[i - 1] + 1);       dp[i] = dp[i - 1] + (2 * e[i - 1] + 1) * p;     }     printf( %.9lf , dp[n]);   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   const ll MAX = 1e5 + 100;   const ll inf = 1e9;   const ll mod = 998244353;   ll a[MAX], c[MAX], t[MAX];   string b[] = { 50 ,  25 ,  75 ,  00 };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ll tc = 1, n, m, ans = 0, v, r;     cin >> n >> m;     for (ll i = 1; i < n + 1; i++) cin >> c[i] >> t[i];     ll ini = 1, time = 0;     while (m--) {       cin >> v;       while (v > time + c[ini] * t[ini]) time += c[ini] * t[ini], ini++;       cout << ini << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000006, LG = 21, mod = 1e9 + 7, M = N;   const double eps = 1e-3, pi = acos(-1.0);   const long long INF = 1123456789123456789LL;   int main() {     string str;     cin >> str;     char mi =  a ;     bool ans = true;     for (char c : str)       if (c > mi + 1) {         ans = false;         break;       } else         mi = max(mi, c);     if (ans && str[0] ==  a )       printf( YES n );     else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005], n, s, ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     while (n--) {       long long x;       cin >> x;       s += x;       a[x]++;     }     if (s == 1 or s == 2 or s == 5) return cout << -1, 0;     while (a[1] > 0 and a[2] > 0) {       a[3]++;       ans++;       a[1]--;       a[2]--;     }     if (a[1] > 0) {       ans += a[1] - a[1] / 3;       if (a[1] == 1 and a[3] == 0) ans++;     }     if (a[2] > 0) {       ans += a[2] - a[2] / 3;       if (a[2] % 3 == 1 and a[4] == 0) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = 101000;   int tot, n, root, a[1001000], temp, tx, ty, rx, rxl;   struct Node {     int lc, rc, x, y, X, Y, l, r, L, R, minx, maxn, lmax, rmax, lmin, rmin, sum,         tag;   } tree[1001000];   pair<int, int> key[1111];   void update(int p, int lc, int rc) {     tree[p].sum = tree[lc].sum + tree[rc].sum;     int t = (tree[lc].maxn > tree[rc].maxn) ? lc : rc;     if (tree[lc].rmax + tree[rc].lmax > tree[t].maxn) {       tree[p].maxn = tree[lc].rmax + tree[rc].lmax;       tree[p].X = tree[lc].x;       tree[p].Y = tree[rc].y;     } else {       tree[p].maxn = tree[t].maxn;       tree[p].X = tree[t].X;       tree[p].Y = tree[t].Y;     }     if (tree[lc].lmax > tree[lc].sum + tree[rc].lmax) {       tree[p].lmax = tree[lc].lmax;       tree[p].y = tree[lc].y;     } else {       tree[p].lmax = tree[lc].sum + tree[rc].lmax;       tree[p].y = tree[rc].y;     }     if (tree[rc].rmax > tree[rc].sum + tree[lc].rmax) {       tree[p].rmax = tree[rc].rmax;       tree[p].x = tree[rc].x;     } else {       tree[p].rmax = tree[rc].sum + tree[lc].rmax;       tree[p].x = tree[lc].x;     }     t = (tree[lc].minx < tree[rc].minx) ? lc : rc;     if (tree[lc].rmin + tree[rc].lmin < tree[t].minx) {       tree[p].minx = tree[lc].rmin + tree[rc].lmin;       tree[p].L = tree[lc].l;       tree[p].R = tree[rc].r;     } else {       tree[p].minx = tree[t].minx;       tree[p].L = tree[t].L;       tree[p].R = tree[t].R;     }     if (tree[lc].lmin < tree[lc].sum + tree[rc].lmin) {       tree[p].lmin = tree[lc].lmin;       tree[p].r = tree[lc].r;     } else {       tree[p].lmin = tree[lc].sum + tree[rc].lmin;       tree[p].r = tree[rc].r;     }     if (tree[rc].rmin < tree[rc].sum + tree[lc].rmin) {       tree[p].rmin = tree[rc].rmin;       tree[p].l = tree[rc].l;     } else {       tree[p].rmin = tree[rc].sum + tree[lc].rmin;       tree[p].l = tree[lc].l;     }   }   void push(int p, int l, int r) {     swap(tree[p].maxn, tree[p].minx);     swap(tree[p].lmax, tree[p].lmin);     swap(tree[p].rmax, tree[p].rmin);     swap(tree[p].x, tree[p].l);     swap(tree[p].y, tree[p].r);     swap(tree[p].X, tree[p].L);     swap(tree[p].Y, tree[p].R);     tree[p].maxn *= -1;     tree[p].lmax *= -1;     tree[p].rmax *= -1;     tree[p].minx *= -1;     tree[p].lmin *= -1;     tree[p].rmin *= -1;     tree[p].sum *= -1;     tree[p].tag *= -1;     if (tree[p].lc) tree[tree[p].lc].tag *= -1;     if (tree[p].rc) tree[tree[p].rc].tag *= -1;   }   int build(int l, int r) {     int p = ++tot;     tree[p].tag = -Inf;     if (l == r) {       tree[p].lc = tree[p].rc = 0;       tree[p].sum = a[l];       tree[p].lmax = tree[p].rmax = tree[p].maxn = a[l];       tree[p].x = tree[p].y = tree[p].X = tree[p].Y = l;       tree[p].lmin = tree[p].rmin = tree[p].minx = a[l];       tree[p].l = tree[p].r = tree[p].L = tree[p].R = l;     } else {       int mid = (l + r) >> 1;       tree[p].lc = build(l, mid);       tree[p].rc = build(mid + 1, r);       update(p, tree[p].lc, tree[p].rc);     }     return p;   }   void ins(int p, int x, int y, int z, int l, int r) {     if (tree[p].tag != -Inf) push(p, l, r);     if (x <= l && r <= y)       tree[p].tag *= -1;     else {       int mid = (l + r) >> 1;       if (x <= mid) ins(tree[p].lc, x, y, z, l, mid);       if (y > mid) ins(tree[p].rc, x, y, z, mid + 1, r);       if (tree[p].lc && tree[tree[p].lc].tag != -Inf) push(tree[p].lc, l, mid);       if (tree[p].rc && tree[tree[p].rc].tag != -Inf)         push(tree[p].rc, mid + 1, r);       update(p, tree[p].lc, tree[p].rc);     }   }   void change(int p, int x, int y, int l, int r) {     if (tree[p].tag != -Inf) push(p, l, r);     if (l == r && l == x) {       tree[p].sum = y;       tree[p].lmax = tree[p].rmax = tree[p].maxn = y;       tree[p].lmin = tree[p].rmin = tree[p].minx = y;     } else {       int mid = (l + r) >> 1;       if (x <= mid)         change(tree[p].lc, x, y, l, mid);       else         change(tree[p].rc, x, y, mid + 1, r);       if (tree[p].lc && tree[tree[p].lc].tag != -Inf) push(tree[p].lc, l, mid);       if (tree[p].rc && tree[tree[p].rc].tag != -Inf)         push(tree[p].rc, mid + 1, r);       update(p, tree[p].lc, tree[p].rc);     }   }   void merge(int p) {     if (tx == -1) {       temp = tree[p].maxn;       rx = tree[p].rmax;       rxl = tree[p].x;       tx = tree[p].X;       ty = tree[p].Y;     } else {       if (max(tree[p].maxn, tree[p].lmax + rx) > temp) {         if (tree[p].maxn > tree[p].lmax + rx) {           temp = tree[p].maxn;           tx = tree[p].X;           ty = tree[p].Y;         } else {           temp = tree[p].lmax + rx;           tx = rxl;           ty = tree[p].y;         }       }       if (tree[p].rmax > tree[p].sum + rx) {         rx = tree[p].rmax;         rxl = tree[p].x;       } else         rx += tree[p].sum;     }   }   void query(int p, int x, int y, int l, int r) {     if (tree[p].tag != -Inf) push(p, l, r);     if (x <= l && r <= y)       merge(p);     else {       int mid = (l + r) >> 1;       if (x <= mid) query(tree[p].lc, x, y, l, mid);       if (y > mid) query(tree[p].rc, x, y, mid + 1, r);       if (tree[p].lc && tree[tree[p].lc].tag != -Inf) push(tree[p].lc, l, mid);       if (tree[p].rc && tree[tree[p].rc].tag != -Inf)         push(tree[p].rc, mid + 1, r);       update(p, tree[p].lc, tree[p].rc);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     tot = 0;     root = build(1, n);     int T;     for (scanf( %d , &T); T; T--) {       int opt, L, R, x;       scanf( %d , &opt);       if (opt) {         scanf( %d%d%d , &L, &R, &x);         int ans = 0, t = 0;         for (int i = 1; i <= x; i++) {           temp = -1;           rxl = rx = tx = ty = 0;           query(root, L, R, 1, n);           if (temp >= 0) {             ans += temp;             key[i] = make_pair(tx, ty);             ins(root, tx, ty, Inf, 1, n);           } else             break;           t = i;         }         printf( %d n , ans);         for (int i = t; i; i--) ins(root, key[i].first, key[i].second, Inf, 1, n);       } else {         scanf( %d%d , &L, &x);         change(root, L, x, 1, n);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     if (a.size() > 26) {       cout <<  -1 n ;     } else {       int count = 0;       int hash[26] = {0};       for (int i = 0; i < a.size(); i++) {         if (hash[a[i] - 97])           count++;         else           hash[a[i] - 97]++;       }       cout << count <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   void OJ() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     vector<string> v;     long long num = 0, k = 0;     v.push_back( 4 ), v.push_back( 7 );     while (1) {       long long n = v.size();       for (long long i = 0; i < n; i++) {         for (long long j = k; j < n; j++) {           string s = v[i] + v[j];           v.push_back(s);           num = max(num, stoll(s, nullptr, 10));           if (num >= 1e9) break;         }         if (num >= 1e9) break;       }       k = n;       if (num >= 1e9) break;     }     vector<long long> ar;     for (auto s : v) {       ar.push_back(stoll(s, nullptr, 10));     }     long long i = 0;     sort(ar.begin(), ar.end());     unordered_map<long long, long long> m;     for (auto s : ar) {       if (m.find(s) == m.end()) m[s] = (++i);     }     long long in;     cin >> in;     cout << m[in];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<vector<int>> g(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     vector<bool> alive(n, true);     vector<int> sz(n);     vector<int> pv(n);     vector<pair<int, int>> ret;     vector<int> all;     vector<int> tin(n);     vector<int> tout(n);     int T = -1;     function<void(int)> Dfs = [&](int v) {       all.push_back(v);       tin[v] = ++T;       sz[v] = 1;       for (int u : g[v]) {         if (alive[u] && u != pv[v]) {           pv[u] = v;           Dfs(u);           sz[v] += sz[u];         }       }       tout[v] = ++T;     };     function<void(int)> Solve = [&](int v) {       all.clear();       pv[v] = -1;       Dfs(v);       int total = sz[v];       while (true) {         bool found = false;         for (int u : g[v]) {           if (alive[u] && pv[u] == v && 2 * sz[u] >= total) {             v = u;             found = true;             break;           }         }         if (!found) {           break;         }       }       alive[v] = false;       set<int> best;       for (int u : g[v]) {         if (alive[u]) {           all.clear();           pv[u] = -1;           Dfs(u);           set<int> cur;           for (int w : g[u]) {             if (alive[w]) {               cur.insert(w);             }           }           if (cur.size() > best.size()) {             best = cur;           }         }       }       all.clear();       pv[v] = -1;       Dfs(v);       for (int u : all) {         if (u != v && pv[u] != v && best.find(u) == best.end()) {           ret.emplace_back(u, v);         }       }       vector<int> children;       for (int u : g[v]) {         if (alive[u]) {           children.push_back(u);         }       }       for (int u : children) {         Solve(u);       }     };     Solve(0);     assert((int)ret.size() <= 10 * n);     cout << ret.size() <<   n ;     for (auto& p : ret) {       cout << p.first + 1 <<     << p.second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fact(int x);   int main() {     int a, b;     cin >> a >> b;     int m = min(a, b);     cout << fact(m);   }   int fact(int x) {     int sum = 1;     for (int i = 2; i < x; i++) sum *= i;     return sum * x;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const int MAXN = 1e6 + 5;   char arr[8][8];   bool vis[8][8];   int dx[] = {0, 0, 1, -1, -1, 1, -1, 1, 0};   int dy[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};   bool dfs(int x, int y, int steps) {     if (steps > 8) return true;     vis[x][y] = true;     if (arr[x][y] ==  A ) return true;     bool ok = false;     for (int i = 0; i < 9; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) continue;       if (nx - steps >= 0 && arr[nx - steps][ny] ==  S ) continue;       if (nx - steps - 1 >= 0 && arr[nx - steps - 1][ny] ==  S ) continue;       if (dfs(nx, ny, steps + 1)) return true;     }     return false;   }   void cp() {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) cin >> arr[i][j];     bool win = dfs(7, 0, 0);     if (win)       cout <<  WIN ;     else       cout <<  LOSE ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long int n = ((int)s[1] -  0 ) + 10 * ((int)s[3] -  0 ) +                       100 * ((int)s[4] -  0 ) + 1000 * ((int)s[2] -  0 ) +                       10000 * ((int)s[0] -  0 );     long long int result = (n * n) % 100000;     result = (result * result) % 100000;     result = (result * n) % 100000;     int digits = (int)log10(result + 1);     digits = 4 - digits;     for (int i = 0; i < digits; i++) cout <<  0 ;     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     int c = 0;     if (k == 0)       cout << s << endl;     else if (n == 1) {       cout <<  0  << endl;     } else if (k >= 1 && n > 1) {       int x = s[0] -  0 ;       if (x > 1) {         s[0] =  1 ;         k--;       }       for (int i = 1; i < n && k > 0; i++) {         x = s[i] -  0 ;         if (x > 0) {           s[i] =  0 ;           k--;         }       }       cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int n, i, j, dn, x;   long long Min = 200000000000000000, Max = 0;   int main() {     cin >> n;     dn = n;     for (i = 1; i * i <= n; i++)       if (dn % i == 0) {         a.push_back(i);         if (dn != i * i) a.push_back(dn / i);       }     for (i = 0; i < a.size(); i++) {       dn = n / a[i];       for (j = 1; j * j <= dn; j++)         if (dn % j == 0) {           x = dn / j;           Min = min(Min, (long long)(a[i] + 1) * (j + 2) * (x + 2));           Max = max(Max, (long long)(a[i] + 1) * (j + 2) * (x + 2));         }     }     cout << Min - n <<     << Max - n;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     return (b > 0) ? gcd(b, a % b) : a;   }   template <typename T>   T lcm(T a, T b) {     return (a * b == 0) ? 0 : (a * b) / gcd(a, b);   }   void solution() {     int candy;     cin >> candy;     int x = 0;     for (; pow(x, 2) + x <= candy * 2; ++x) {     }     --x;     cout << x << endl;     int give = 1;     while (x--) {       if (x == 0) {         cout << candy <<    ;         return;       }       candy -= give;       cout << give <<    ;       ++give;     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int t = 1;     while (t--) {       solution();     }   }


#include <bits/stdc++.h>   using namespace std;   const unsigned int tb[32] = {13, 0,  27, 1,  28, 18, 23, 2,  29, 21, 19,                                12, 24, 9,  14, 3,  30, 26, 17, 22, 20, 11,                                8,  13, 25, 16, 10, 7,  15, 6,  5,  4};   int n, m, tot;   priority_queue<long long, std::vector<long long>, std::greater<long long> > q1,       q2, q3;   void calc(priority_queue<long long, std::vector<long long>,                            std::greater<long long> >& q,             long long& ans) {     while (q.size() > 1) {       if (q.size() >= 3) {         long long x = q.top();         q.pop();         long long y = q.top();         q.pop();         long long z = q.top();         q.pop();         ans += x + y + z;         q.push(x + y + z);       } else {         ans += q.top();         q.pop();         ans += q.top();       }     }   }   int main() {     int T = 1;     for (int ci = 1; ci <= T; ++ci) {       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         int x;         scanf( %d , &x);         q1.push(x);         q2.push(x);         q3.push(x);       }       long long ans1 = 0, ans2 = 0, ans3 = 0;       if (q1.size() >= 2) {         int x = q1.top();         q1.pop();         int y = q1.top();         q1.pop();         ans1 = x + y;         q1.push(x + y);       }       if (q2.size() >= 4) {         int x = q2.top();         q2.pop();         int y = q2.top();         q2.pop();         ans2 = x + y;         int u = q2.top();         q2.pop();         int v = q2.top();         q2.pop();         ans2 += u + v;         q2.push(x + y);         q2.push(u + v);       }       calc(q1, ans1);       calc(q2, ans2);       calc(q3, ans3);       long long ans = min(min(ans1, ans2), ans3);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Network {     int N, source, sink;     int M;     struct Edge {       int source, target, id, reverse;     };     vector<vector<Edge>> adjacency_list;     vector<int> capacities, flows, costs;     Network(const int N, const int source, const int sink)         : N(N), source(source), sink(sink), M(0), adjacency_list(N) {}     void add_edge(const int v, const int w, const int capacity, const int cost) {       const auto id = M++;       capacities.push_back(capacity);       costs.push_back(cost);       flows.push_back(0);       const auto reverse = M++;       capacities.push_back(0);       costs.push_back(-cost);       flows.push_back(0);       adjacency_list[v].push_back({v, w, id, reverse});       adjacency_list[w].push_back({w, v, reverse, id});     }     int mcmf() {       auto cost = 0;       while (true) {         const auto infinity = numeric_limits<int>::max();         auto distances = vector<int>(N, infinity);         auto predecessors = vector<Edge>(N);         auto queue = std::queue<int>();         distances[source] = 0;         queue.push(source);         while (!queue.empty()) {           const auto v = queue.front();           queue.pop();           const auto d = distances[v];           for (const auto e : adjacency_list[v]) {             if (flows[e.id] == capacities[e.id]) continue;             const auto relax = d + costs[e.id];             if (relax < distances[e.target]) {               distances[e.target] = relax;               predecessors[e.target] = e;               queue.push(e.target);             }           }         }         if (distances[sink] == infinity)           break;         else {           cost += distances[sink];           for (auto v = sink; v != source; v = predecessors[v].source) {             const auto e = predecessors[v];             flows[e.id]++;             flows[e.reverse]--;           }         }       }       return cost;     }   };   int main() {     ios::sync_with_stdio(false);     cout << setprecision(4) << fixed;     int n, a, b;     cin >> n >> a >> b;     auto p = vector<int>(n);     for (auto i = 0; i < n; i++) {       double x;       cin >> x;       p[i] = int(round(x * 1000));     }     auto u = vector<int>(n);     for (auto i = 0; i < n; i++) {       double x;       cin >> x;       u[i] = int(round(x * 1000));     }     auto source = n, sink = n + 1, pokeball = n + 2, ultraball = n + 3;     auto network = Network(n + 4, source, sink);     network.add_edge(source, pokeball, a, 0);     network.add_edge(source, ultraball, b, 0);     for (auto i = 0; i < n; i++) {       network.add_edge(pokeball, i, 1, -p[i] * 1000);       network.add_edge(ultraball, i, 1, -u[i] * 1000);       network.add_edge(i, sink, 1, 0);       network.add_edge(i, sink, 1, p[i] * u[i]);     }     cout << double(-network.mcmf()) / 1e6 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10;   long long n;   pair<char, long long> ar[N];   vector<long long> vec;   set<long long> st;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     n *= 2;     for (long long i = 0; i < n; i++) {       char c;       long long x;       cin >> c;       if (c ==  + )         ar[i].first = c;       else {         cin >> x;         ar[i] = {c, x};       }     }     bool check = 1;     for (long long i = 0; i < n; i++) {       if (ar[i].first ==  + )         vec.push_back(i);       else {         if (!vec.size()) {           check = 0;           break;         }         long long indx = vec.back();         vec.pop_back();         ar[indx].second = ar[i].second;       }     }     if (!check) return cout <<  NO n , 0;     for (long long i = 0; i < n; i++)       if (ar[i].first ==  + )         st.insert(ar[i].second);       else {         if (!st.size()) {           check = 0;           break;         }         long long x = (*st.begin());         st.erase(x);         if (x != ar[i].second) {           check = 0;           break;         }       }     if (!check) return cout <<  NO n , 0;     cout <<  YES n ;     for (long long i = 0; i < n; i++)       if (ar[i].first ==  + ) cout << ar[i].second <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int up = 100000;   int n, m, s[100050], mx[100050], rp[100050];   int b[100050], c[100050];   long long sum[100050];   pair<long long, long long> operator+(const pair<long long, long long> &a,                                        const pair<long long, long long> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   struct Presidentree {     bool op;     int rt[100050], ls[100050 * 20], rs[100050 * 20], node;     long long val[100050 * 20], sum[100050 * 20];     void modify(int &x, int las, int l, int r, int pos, int p) {       x = ++node;       ls[x] = ls[las];       rs[x] = rs[las];       val[x] = val[las] + rp[p];       sum[x] = sum[las] + mx[p] - (op ? 0 : s[p]);       if (l == r) return;       int mid = (l + r) >> 1;       if (pos <= mid)         modify(ls[x], ls[las], l, mid, pos, p);       else         modify(rs[x], rs[las], mid + 1, r, pos, p);     }     pair<long long, long long> query(int a, int b, int l, int r, int L, int R) {       if (!a) return make_pair(0, 0);       if (L <= l && r <= R) return make_pair(val[a] - val[b], sum[a] - sum[b]);       int mid = (l + r) >> 1;       pair<long long, long long> ans = make_pair(0, 0);       if (L <= mid) ans = ans + query(ls[a], ls[b], l, mid, L, R);       if (R > mid) ans = ans + query(rs[a], rs[b], mid + 1, r, L, R);       return ans;     }   } T[2];   struct Node {     int l, r, v;     Node(int _l = 0, int _r = 0, int _v = 0) : l(_l), r(_r), v(_v) {}     bool operator<(const Node &a) const { return l < a.l; }   };   set<Node> S;   set<Node>::iterator split(int p) {     set<Node>::iterator it = S.lower_bound(Node(p));     if (it != S.end() && it->l == p) return it;     it--;     int l = it->l, r = it->r, v = it->v;     S.erase(it);     S.insert(Node(l, p - 1, v));     it = S.lower_bound(Node(l, p - 1, v));     return S.insert(Node(p, r, v)).first;   }   long long ask(int t, int x, int y) {     set<Node>::iterator R = split(y + 1), L = split(x);     long long ans = sum[y] - sum[x - 1];     for (set<Node>::iterator it = L; it != R; it++) {       pair<long long, long long> res;       if (it->v == 0)         res = T[0].query(T[0].rt[it->r], T[0].rt[it->l - 1], 0, up + 1,                          min(up + 1, t - it->v + 1), up + 1);       else         res = T[1].query(T[1].rt[it->r], T[1].rt[it->l - 1], 0, up + 1,                          min(up + 1, t - it->v + 1), up + 1);       ans += 1ll * res.first * (t - it->v) - res.second;     }     S.erase(L, R);     S.insert(Node(x, y, t));     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &s[i], &mx[i], &rp[i]);       sum[i] = sum[i - 1] + (long long)mx[i];       if (rp[i] == 0)         b[i] = c[i] = up + 1;       else {         b[i] = (mx[i] - s[i]) / rp[i] + ((mx[i] - s[i]) % rp[i] > 0);         c[i] = mx[i] / rp[i] + (mx[i] % rp[i] > 0);       }     }     T[0].op = 0;     T[1].op = 1;     for (int i = 1; i <= n; i++)       T[0].modify(T[0].rt[i], T[0].rt[i - 1], 0, up + 1, b[i], i);     for (int i = 1; i <= n; i++)       T[1].modify(T[1].rt[i], T[1].rt[i - 1], 0, up + 1, c[i], i);     S.insert(Node(1, n, 0));     S.insert(Node(n + 1, n + 1, 0));     scanf( %d , &m);     while (m--) {       int t, l, r;       scanf( %d%d%d , &t, &l, &r);       cout << ask(t, l, r) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int to, next;   } e[400005];   int head[200005], cnt, c[200005], deg[200005];   inline int read() {     int x = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   void addedge(int x, int y) {     ++cnt;     e[cnt].to = y;     e[cnt].next = head[x];     head[x] = cnt;     ++cnt;     e[cnt].to = x;     e[cnt].next = head[y];     head[y] = cnt;   }   int main() {     int n = read();     cnt = 0;     for (int i = 1; i < n; i++) {       int x = read(), y = read();       addedge(x, y);     }     for (int i = 1; i <= n; i++) c[i] = read();     cnt = 0;     for (int i = 1; i <= n; i++)       for (int x = head[i]; x; x = e[x].next)         if (c[i] != c[e[x].to]) {           deg[i]++;           deg[e[x].to]++;           cnt++;         }     if (!cnt)       cout <<  YES n  << 1 << endl;     else {       int i = 1;       for (; i <= n; i++)         if (deg[i] == cnt) break;       if (i <= n)         cout <<  YES n  << i << endl;       else         cout <<  NO n  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, c = 1;     cin >> n;     char s[n + 2];     vector<long long> d(n + 1);     cin >> (s + 1);     for (i = 1; i <= n; ++i) {       cin >> d[i];     }     for (i = 1;;) {       if (s[i] ==  > )         i += d[i];       else         i -= d[i];       if (i > n || i < 1) break;       c++;       if (c > n) break;     }     if (c > n)       cout <<  INFINITE ;     else       cout <<  FINITE ;     return 0;   }


#include <bits/stdc++.h>   int last[1000100], next[1000100];   long long val[1000100];   int cnt[1000100];   int c[3010];   int prime[3010], top, pp, tmp;   inline void add(long long s, int &ss) {     val[++top] = s;     cnt[top] = ss;     s %= 1000007;     next[top] = last[s];     last[s] = top;   }   inline int find(long long &x) {     for (int i = last[x % 1000007]; i; i = next[i])       if (x == val[i]) return cnt[i];     return -1;   }   int f(int x, int y, int z, int p) {     if (p == 0) return 1;     if (x > y) {       tmp = x;       x = y;       y = tmp;     }     if (x > z) {       tmp = x;       x = z;       z = tmp;     }     if (y > z) {       tmp = y;       y = z;       z = tmp;     }     long long s = ((((long long)((x << 11) | y) << 11) | z) << 9) | p;     if (~find(s)) return find(s);     int a, b, c, aa, bb, cc, ret = 0;     for (a = 0, aa = 1; aa <= x; ++a, aa *= prime[p])       for (b = 0, bb = 1; bb <= y; ++b, bb *= prime[p])         for (c = 0, cc = 1; cc <= z; ++c, cc *= prime[p])           ret = ((long long)(a + b + c + 1) * f(x / aa, y / bb, z / cc, p - 1) +                  ret) &                 1073741823;     add(s, ret);     return ret;   }   int main() {     int i, j, x, y, z;     for (i = 2; i <= 2000; ++i)       if (c[i] == 0) {         prime[++top] = i;         for (j = i * i; j <= 2000; j += i) c[j] = 1;       }     pp = top;     top = 0;     scanf( %d%d%d , &x, &y, &z);     while (pp && prime[pp] > x && prime[pp] > y && prime[pp] > z) --pp;     printf( %d n , f(x, y, z, pp));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     string s;     cin >> s;     long long open = count(s.begin(), s.end(),  ( );     if (open != n - open) {       cout << -1 <<   n ;       return 0;     }     long long count = 0, ans = 0;     stack<char> st;     for (char ch : s) {       if (ch ==  ( ) {         if (count == 0) {           st.push(ch);         } else {           count++;           ans++;         }       } else {         if (st.empty()) {           count--;           ans++;         } else if (st.top() ==  ( ) {           st.pop();         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> v;     int n;     cin >> n;     v.resize(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.rbegin(), v.rend());     long long ans = v[0];     for (int i = 1; i < n; i++) {       if (v[i] >= v[i - 1]) v[i] = max(v[i - 1] - 1, 0LL);       ans += v[i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   double PI = 3.141592653589793;   const int P = 1e9 + 9;   class mint {    public:     static int init_siz;     static vector<mint> inverse, factorial;     static int mintP;     int n;     static mint exp(mint a, long long e) {       mint res = 1;       while (e) {         if (e & 1) res *= a;         a *= a;         e >>= 1;       }       return res;     }     static void init(int n) {       init_siz = n;       inverse.resize(n + 1);       factorial.resize(n + 1);       factorial[0] = 1;       for (int i = 1; i <= n; i++) factorial[i] = factorial[i - 1] * i;       inverse[n] = exp(factorial[n], mintP - 2);       for (int i = n - 1; i >= 0; i--) inverse[i] = inverse[i + 1] * (i + 1);     }     static mint inv(mint const& a) {       return (init_siz >= a.n ? inverse[a.n] * (a.n > 1 ? fac(a - 1) : 1)                               : exp(a, mintP - 2));     }     static mint cinv(mint const& a) {       return (init_siz >= a.n ? inverse[a.n] : exp(fac(a), mintP - 2));     }     static mint fac(mint const& a) {       if (init_siz >= a.n)         return factorial[a.n];       else {         mint out = 1;         for (int i = 0; i < a.n; i++) out *= (i + 1);         return out;       }     }     mint(long long val = 0) {       n = val % mintP;       if (n < 0) n += mintP;     }     mint& operator+=(mint const& b) {       n += b.n;       if (n >= mintP) n -= mintP;       return *this;     }     mint& operator-=(mint const& b) {       n -= b.n;       if (n < 0) n += mintP;       return *this;     }     mint& operator*=(mint const& b) {       n = (long long)n * b.n % mintP;       return *this;     }     mint exp(long long e) { return exp(*this, e); }     mint inv() { return inv(*this); }     mint& operator/=(mint const& b) { return *this *= inv(b); }     friend std::ostream& operator<<(std::ostream& os, mint const& a) {       return os << (a.n < 0 ? a.n + mintP : a.n);     }     friend mint operator+(mint a, mint const b) { return a += b; }     friend mint operator-(mint a, mint const b) { return a -= b; }     friend mint operator-(mint const a) { return 0 - a; }     friend mint operator*(mint a, mint const b) { return a *= b; }     friend mint operator/(mint a, mint const b) { return a /= b; }     friend bool operator==(mint const& a, mint const& b) { return a.n == b.n; }     friend bool operator!=(mint const& a, mint const& b) { return a.n != b.n; }   };   int mint::init_siz = 0;   int mint::mintP = P;   vector<mint> mint::factorial, mint::inverse;   class dsu {    private:     int N;     vector<int> par;     int getpar(int v) {       if (par[v] != v) par[v] = getpar(par[v]);       return par[v];     }     pair<int, int> getparhei(int v) {       if (par[v] == v)         return {v, 0};       else {         auto temp = getparhei(par[v]);         temp.second++;         return temp;       }     }       public:     dsu(int siz) {       N = siz;       par.resize(N);       iota(par.begin(), par.end(), 0);     }     int id(int v) { return getpar(v); }     void merge(int v1, int v2) {       auto par1 = getparhei(v1);       auto par2 = getparhei(v2);       if (par1.second < par2.second) swap(par1, par2);       par[par2.first] = par1.first;     }     bool same(int v1, int v2) { return getpar(v1) == getpar(v2); }   };   void solve() {     int n, m;     cin >> n >> m;     dsu id(n);     int cnt = 0;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       if (id.id(u) == id.id(v))         cnt++;       else         id.merge(u, v);       cout << mint::exp(2, cnt) - 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int T = 1;     for (int c = 1; c < T + 1; c++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int loc[400000];   long long sumlen[400000];   double profit[400000];   int a[400000];   int b[400000];   double hit[200000];   class MaxSubstringSum {    public:     MaxSubstringSum(int n) {       int real_n = 1;       while (real_n < n) {         real_n *= 2;       }       lb_ = new int[2 * real_n + 1];       ub_ = new int[2 * real_n + 1];       max_value_ = new double[2 * real_n + 1];       max_left_ = new double[2 * real_n + 1];       max_right_ = new double[2 * real_n + 1];       sum_all_ = new double[2 * real_n + 1];       for (int(i) = 0; (i) < (2 * real_n + 1); ++(i)) {         lb_[i] = ub_[i] = 0;         max_value_[i] = max_left_[i] = max_right_[i] = sum_all_[i] = 0.0;       }       for (int i = 0; i < real_n; ++i) {         lb_[real_n + i] = i;         ub_[real_n + i] = i;       }       for (int i = real_n - 1; i >= 1; --i) {         lb_[i] = lb_[i * 2];         ub_[i] = ub_[i * 2 + 1];       }     }     void Build(int node) {       if (lb_[node] == ub_[node]) {         max_value_[node] = max_left_[node] = max_right_[node] =             max(0.0, profit[lb_[node]]);         sum_all_[node] = profit[lb_[node]];       } else {         Build(node * 2);         Build(node * 2 + 1);         sum_all_[node] = sum_all_[node * 2] + sum_all_[node * 2 + 1];         max_left_[node] = max(max_left_[node * 2],                               sum_all_[node * 2] + max_left_[node * 2 + 1]);         max_right_[node] = max(max_right_[node * 2 + 1],                                sum_all_[node * 2 + 1] + max_right_[node * 2]);         max_value_[node] =             max(max_value_[node * 2],                 max(max_value_[node * 2 + 1],                     max_right_[node * 2] + max_left_[node * 2 + 1]));       }     }     double GetLMax(int low, int hi, int node = 1) {       if (lb_[node] >= low && ub_[node] <= hi) {         return max_left_[node];       }       if (lb_[node] > hi || ub_[node] < low) return 0.0;       double ret = GetLMax(low, hi, node * 2);       if (lb_[node * 2] >= low && ub_[node * 2] <= hi) {         ret = max((ret), (GetLMax(low, hi, node * 2 + 1) + sum_all_[node * 2]));       }       return ret;     }     double GetRMax(int low, int hi, int node = 1) {       if (lb_[node] >= low && ub_[node] <= hi) {         return max_right_[node];       }       if (lb_[node] > hi || ub_[node] < low) return 0.0;       double ret = GetRMax(low, hi, node * 2 + 1);       if (lb_[node * 2 + 1] >= low && ub_[node * 2 + 1] <= hi) {         ret = max((ret), (GetRMax(low, hi, node * 2) + sum_all_[node * 2 + 1]));       }       return ret;     }     double GetMax(int low, int hi, int node = 1) {       if (lb_[node] >= low && ub_[node] <= hi) {         return max_value_[node];       }       if (lb_[node] > hi || ub_[node] < low) return 0.0;       double best = max(GetMax(low, hi, node * 2), GetMax(low, hi, node * 2 + 1));       best = max((best),                  (GetRMax(low, hi, node * 2) + GetLMax(low, hi, node * 2 + 1)));       return best;     }       private:     int* lb_;     int* ub_;     double* max_value_;     double* max_left_;     double* max_right_;     double* sum_all_;   };   int main() {     int n, m, c;     cin >> n >> m >> c;     for (int(i) = 0; (i) < (n); ++(i)) {       scanf( %d , loc + i);     }     sumlen[0] = 0;     for (int(i) = (1); (i) < (n); ++(i)) {       sumlen[i] = sumlen[i - 1] + (long long)loc[i] - (long long)loc[i - 1];     }     for (int(i) = 0; (i) < (n - 1); ++(i)) {       int x;       scanf( %d , &x);       hit[i] = (double)x / 100.0;     }     for (int(i) = 0; (i) < (m); ++(i)) {       scanf( %d%d , a + i, b + i);     }     for (int(i) = 0; (i) < (n - 1); ++(i)) {       profit[i] =           (double)(loc[i + 1] - loc[i]) / 2.0 - (double)hit[i] * (double)c;     }     MaxSubstringSum tree(n);     tree.Build(1);     double ret = 0.0;     for (int(i) = 0; (i) < (m); ++(i)) {       ret += tree.GetMax(a[i] - 1, b[i] - 2, 1);     }     printf( %.10lf n , ret);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   void FAIL() {     printf( 0 );     exit(0);   }   const int N = 5e5 + 10, mod = 1e9 + 7;   int In[N], Out[N], To[N], vis[N], n;   int sol(vector<int> &G, vector<pair<int, int> > &E) {     G.push_back(0), G.push_back(n + 1);     for (int i = 0; i < E.size(); ++i)       Out[E[i].first]++, In[E[i].second]++, To[E[i].first] = E[i].second;     for (int i = 0; i < G.size(); ++i)       if (In[G[i]] > 1 || Out[G[i]] > 1) FAIL();     for (int i = 0; i < G.size(); ++i)       if (!vis[G[i]]) {         int cur = G[i];         vis[cur] = 1;         while (~To[cur] && !vis[To[cur]]) cur = To[cur], vis[cur] = 1;         if (To[cur] == G[i]) FAIL();       }     int cur = 0;     while (~To[cur]) cur = To[cur];     if (cur == n + 1 && (int)G.size() - (int)E.size() > 1) FAIL();     for (int i = 0; i < G.size(); ++i)       In[G[i]] = Out[G[i]] = vis[G[i]] = 0, To[G[i]] = -1;     return max((int)G.size() - (int)E.size() - 2, 0);   }   vector<int> G[N];   vector<pair<int, int> > E[N];   int fa[N], dep[N];   void dfs1(int u, int last) {     fa[u] = last, dep[u] = dep[last] + 1;     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       if (v == last) continue;       dfs1(v, u);     }   }   vector<int> P, Q;   void getpath(int x, int y) {     P.clear(), Q.clear();     int flg = 0;     if (dep[x] < dep[y]) swap(x, y), flg = 1;     P.push_back(x);     while (dep[x] > dep[y]) x = fa[x], P.push_back(x);     if (x == y) {       if (flg) reverse(P.begin(), P.end());       return;     }     Q.push_back(y);     while (fa[x] != fa[y]) x = fa[x], y = fa[y], P.push_back(x), Q.push_back(y);     P.push_back(fa[x]);     for (int i = (int)Q.size() - 1; i >= 0; --i) P.push_back(Q[i]);     if (flg) reverse(P.begin(), P.end());   }   int tot;   int a[N];   int fac[N];   int main() {     rd(n);     for (int i = 1, x, y; i < n; ++i)       rd(x), rd(y), G[x].push_back(y), G[y].push_back(x);     dfs1(1, 0);     for (int i = 1; i <= n; ++i) rd(a[i]);     for (int i = 1; i <= n; ++i)       if (a[i]) {         if (a[i] == i) FAIL();         getpath(a[i], i);         if ((tot += (int)P.size() - 1) > 2 * n - 2) FAIL();         int m = (int)P.size() - 1;         E[P[0]].push_back(make_pair(0, P[1]));         E[P[m]].push_back(make_pair(P[m - 1], n + 1));         for (int i = 1; i < m; ++i)           E[P[i]].push_back(make_pair(P[i - 1], P[i + 1]));       }     memset(To, -1, sizeof(To));     int ans = 1;     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * (long long)i % mod;     for (int i = 1; i <= n; ++i)       ans = ans * (long long)fac[sol(G[i], E[i])] % mod;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void rot(vector<string>& a) {     int n = (int)(a).size();     int m = (int)(a[0]).size();     vector<string> b(m);     for (int j = 0; j < m; ++j) {       b[j] =   ;       for (int i = n - 1; i >= 0; --i) {         b[j] += a[i][j];       }     }     a.swap(b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a, b;     cin >> a >> b;     vector<string> q(a);     for (int i = 0; i < a; ++i) {       cin >> q[i];     }     int cnt = 0;     int optx = -1, opty;     for (int x = 1; x <= a; ++x) {       for (int y = 1; y <= b; ++y) {         if (a % x || b % y) {           continue;         }         set<vector<string> > setik;         bool valid = true;         for (int i = 0; i < a / x; ++i) {           for (int j = 0; j < b / y; ++j) {             vector<string> vct;             for (int u = i * x; u < (i + 1) * x; ++u) {               string s =   ;               for (int v = j * y; v < (j + 1) * y; ++v) {                 s += q[u][v];               }               vct.push_back(s);             }             if (setik.count(vct)) {               valid = false;             }             for (int t = 0; t < 3; ++t) {               rot(vct);               if (setik.count(vct)) {                 valid = false;               }             }             for (int t = 0; t < 4; ++t) {               rot(vct);               setik.insert(vct);             }           }         }         if (valid) {           ++cnt;           if (optx == -1 || optx * opty > x * y ||               (optx * opty == x * y && optx > x)) {             optx = x, opty = y;           }         }       }     }     cout << cnt <<   n ;     cout << optx <<     << opty <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int onexor = 0;     bool ok = true;     long long s, x;     cin >> s >> x;     for (int i = 40; i >= 0; i--) {       if (s & (1LL << i)) {         if (x & (1LL << i)) {           continue;         } else {           bool foun = false;           for (int j = i - 1; j >= 0; j--) {             if (!(x & (1LL << j))) {               foun = true;               i = j + 1;               break;             }             if (s & (1LL << (j))) {               ok = false;               break;             }           }           if (!foun) {             ok = false;             break;           }         }       } else if (x & (1LL << i)) {         ok = false;       }     }     long long ans = 1LL;     for (int i = 40; i >= 0; i--) {       if (x & (1LL << i)) {         ans = ans * 2LL;       }     }     if (x == s) ans -= 2LL;     if (ok) {       cout << ans << endl;     } else       cout << 0 << endl;     cin >> s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1 >> s2;     if (s2.size() > s1.size()) swap(s1, s2);     int x = s1.size() - s2.size();     for (int i = 0; i < s1.size() && i < s2.size(); ++i) {       if (s1[s1.size() - i - 1] != s2[s2.size() - i - 1]) {         x = s1.size() - i + s2.size() - i;         break;       }     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5;   int n, q;   int all;   int pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5];   int node[MaxN + 5];   int father[MaxN + 5];   int gcd(int x, int y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   void build(int x, int y) {     pre[++all] = last[x];     last[x] = all;     other[all] = y;   }   void Dfs(int x, int fa) {     father[x] = fa;     int ed = last[x], dr;     while (ed != -1) {       dr = other[ed];       if (dr != fa) {         Dfs(dr, x);       }       ed = pre[ed];     }   }   int main() {     while (scanf( %d %d , &n, &q) != EOF) {       all = -1;       memset(last, -1, sizeof(last));       for (int i = 1; i <= n; i++) scanf( %d , &node[i]);       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         build(u, v);         build(v, u);       }       Dfs(1, 0);       for (int i = 1; i <= q; i++) {         int op;         scanf( %d , &op);         if (op == 1) {           int v;           int ans = -1;           scanf( %d , &v);           int now = v;           while (father[v] != 0) {             v = father[v];             if (gcd(node[v], node[now]) > 1) {               ans = v;               break;             }           }           printf( %d n , ans);         } else {           int v, w;           scanf( %d %d , &v, &w);           node[v] = w;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     x *= f;   }   void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar(x % 10 + 48);   }   void write(int x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   const int maxn = 1e6 + 10;   const int inf = 1e9;   const double eps = 1e-8;   const int mod = 1e9 + 7;   int v[maxn];   map<pair<int, int>, int> s;   int n, t, z[maxn], ans[maxn];   int query(int x, int y) {     if (x > y) swap(x, y);     if (s[make_pair(x, y)]) return s[make_pair(x, y)];     printf( ? %d %d n , x, y);     fflush(stdout);     int a;     read(a);     assert(a != -1);     return s[make_pair(x, y)] = a;   }   int get(int x) {     int a = (1 << t) - 1;     for (int i = 0; i < t; i++)       if (x != z[i])         a &= query(z[i], x);       else if ((a >> i) & 1)         a ^= 1 << i;     return a;   }   int main() {     srand(time(0));     read(n);     for (int i = 1; i < n; i <<= 1) t++;     while (1) {       int x = rand() % n + 1, y = rand() % n + 1, bo = 1;       for (int i = 0; i < t; i++)         if (!z[i]) bo = 0;       if (bo) break;       if (x == y) continue;       int a = query(x, y);       for (int i = 0; i < t; i++)         if (!((a >> i) & 1)) z[i] = x;     }     int a = get(1), pre = 1;     for (int i = 2; i <= n; i++)       if (query(pre, i) == a) a = get(i), pre = i;     for (int i = 1; i <= n; i++)       if (i != pre) ans[i] = query(pre, i);     printf( !  );     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long k, n, m, x = 10;     int i = 1;     cin >> k;     k -= 9;     if (k <= 0) {       k = k + 9;       cout << k;       exit(0);     }     while (++i) {       k -= 9 * i * x;       if (k <= 0) {         k += 9 * i * x;         n = k / i;         m = k % i;         n = x + n;         if (m == 0) n -= 1;         ostringstream s;         s << n;         string s1 = s.str();         if (m == 0)           cout << s1[i - 1];         else           cout << s1[m - 1];         exit(0);       }       x = x * 10;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, c, val;   vector<vector<long long>> F1;   vector<vector<long long>> getNewMat() {     vector<vector<long long>> ans;     ans.resize(3 + 1);     for (auto &it : ans) it.resize(3 + 1);     return ans;   }   vector<vector<long long>> mult(vector<vector<long long>> A,                                  vector<vector<long long>> B) {     vector<vector<long long>> C;     C.resize(3 + 1);     for (long long i = 1; i <= 3; i++) C[i].resize(3 + 1);     for (long long i = 1; i <= 3; i++) {       for (long long j = 1; j <= 3; j++) {         for (long long k = 1; k <= 3; k++) {           C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % (1000000007 - 1);         }       }     }     return C;   }   vector<vector<long long>> _pow(vector<vector<long long>> mat, long long x) {     if (x == 1) return mat;     vector<vector<long long>> ansM = _pow(mult(mat, mat), x / 2);     if (x % 2) return mult(ansM, mat);     return ansM;   }   long long __pow(long long a, long long b) {     if (b == 0) return 1LL;     if (b == 1) return a;     if (b % 2) return __pow(a * a % 1000000007, b / 2) * a % 1000000007;     return __pow(a * a % 1000000007, b / 2) % 1000000007;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> a >> b >> c >> val;     F1 = getNewMat();     F1[1][1] = F1[1][2] = F1[1][3] = F1[2][1] = F1[3][2] = 1;     if (n < 4) {       if (n == 1) cout << a <<   n ;       if (n == 2) cout << b <<   n ;       if (n == 3) cout << c <<   n ;       return 0;     }     long long ans = 1;     F1 = _pow(F1, n - 3);     a = a * val % 1000000007;     b = b * __pow(val, 2) % 1000000007;     c = c * __pow(val, 3) % 1000000007;     ans = __pow(a, (F1[1][3])) * __pow(b, (F1[1][2])) % 1000000007;     ans = ans * __pow(c, (F1[1][1])) % 1000000007;     val = __pow(val, n);     val = __pow(val, 1000000007 - 2);     ans = ans * val % 1000000007;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int n, m;   int graph[21][21];   int deg[21];   int odd_cnt;   int odd[21];   int check[21];   int min1, sum;   void dfs(int u, int v, int len) {     int i, j;     if (len > min1) return;     for (i = 0; i < odd_cnt; i++) {       if (check[i] == 0) break;     }     if (i == odd_cnt) {       if (min1 > len) min1 = len;       return;     }     for (j = i + 1; j < odd_cnt; j++) {       if (!check[j]) {         check[i] = check[j] = 1;         dfs(i, j, len + graph[odd[i]][odd[j]]);         check[i] = check[j] = 0;       }     }   }   int chinese_postman() {     int i, j, k;     for (k = 1; k <= n; k++) {       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           graph[i][j] = ((graph[i][j]) > (graph[i][k] + graph[k][j])                              ? (graph[i][k] + graph[k][j])                              : (graph[i][j]));         }       }     }     for (i = 1; i <= n; i++) {       if (graph[1][i] == 999999999 && deg[i] > 0) return -1;     }     memset(odd, 0, sizeof(odd));     odd_cnt = 0;     for (i = 1; i <= n; i++) {       if (deg[i] & 1) {         odd[odd_cnt++] = i;       }     }     memset(check, 0, sizeof(check));     if (odd_cnt)       min1 = 999999999;     else       min1 = 0;     for (i = 1; i < odd_cnt; i++) {       check[0] = check[i] = 1;       dfs(0, i, graph[odd[0]][odd[i]]);       check[0] = check[i] = 0;     }     return min1 + sum;   }   int main() {     int i, j, a, b, c, res;     while (scanf( %d%d , &n, &m) == 2) {       memset(deg, 0, sizeof(deg));       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) graph[i][j] = 999999999;         graph[i][j] = 0;       }       sum = 0;       for (i = 0; i < m; i++) {         scanf( %d%d%d , &a, &b, &c);         sum += c;         graph[a][b] = graph[b][a] = ((graph[a][b]) > (c) ? (c) : (graph[a][b]));         deg[a]++;         deg[b]++;       }       res = chinese_postman();       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int N = 5005;   int t[N], cnt[N], ans[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &t[i]);     for (int i = 0; i < n; i++) {       memset(cnt, 0, sizeof(cnt));       int mx = 0, mxi = 1;       for (int j = i; j < n; j++) {         cnt[t[j]]++;         if (cnt[t[j]] > mx) {           mx = cnt[t[j]];           mxi = t[j];         } else if (cnt[t[j]] == mx) {           mxi = min(mxi, t[j]);         }         ans[mxi]++;       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 10;   const int inf = 0x3f3f3f3f;   int main() {     int n, a, b, c, d, start, len;     cin >> n >> a >> b >> c >> d >> start >> len;     vector<int> t(n), q(n);     for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &q[i]);     int j = 0;     long long df = 0, mn = 0, ac = start;     vector<int> T;     T.push_back(-1);     for (int i = 0; i < n; i++) T.push_back(t[i]);     for (int i = 0; i < n; i++) {       while (j < n && t[j] - t[i] < len) {         df += (q[j] ? c : -d);         mn = min(mn, df);         j++;       }       if (ac + mn >= 0) {         cout << T[i] + 1 << endl;         return 0;       }       df -= (q[i] ? c : -d);       mn -= (q[i] ? c : -d);       ac += (q[i] ? a : -b);       if (ac < 0) {         puts( -1 );         return 0;       }     }     cout << T[n] + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, m;   long long dis[N];   bool vis[N];   vector<pair<int, int> > g[N];   map<pair<int, long long>, long long> M;   struct node {     long long dist;     int u;     inline bool operator<(const node &p) const { return dist > p.dist; }   };   long long Solve(void) {     fill(vis + 1, vis + 1 + n, 0);     fill(dis + 1, dis + 1 + n, -1);     priority_queue<node> q;     dis[1] = M[make_pair(1, 0)];     q.push((node){0LL, 1});     while (!q.empty()) {       node now = q.top();       q.pop();       int x = now.u;       if (vis[x]) continue;       vis[x] = 1;       for (int i = 0; i < (int)g[x].size(); ++i) {         int y = g[x][i].first, d = g[x][i].second;         long long tmp = M[make_pair(y, dis[x] + d)];         if (tmp == 0 || y == n) tmp = dis[x] + d;         if (dis[y] == -1 || dis[y] > tmp) dis[y] = tmp, q.push((node){tmp, y});       }     }     return dis[n];   }   int main(void) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));     }     for (int x = 1; x <= n; ++x) {       int num, t[N], p = 1;       scanf( %d , &num);       for (int i = 1; i <= num; ++i) {         scanf( %d , t + i);         if (i > 1 && t[i] - t[i - 1] > 1) {           for (int j = p; j < i; ++j) M[make_pair(x, t[j])] = t[i - 1] + 1;           p = i;         }       }       for (int i = p; i <= num; ++i) M[make_pair(x, t[i])] = t[num] + 1;     }     printf( %lld n , Solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX_SZ = 105;   struct request {     int type;     int r;     int x, y, val;     request(int type0, int r0) {       type = type0;       r = r0;     }     request(int type0, int x0, int y0, int val0) {       type = type0;       x = x0;       y = y0;       val = val0;     }   };   int main() {     ios_base::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     int a[MX_SZ][MX_SZ];     memset(a, 0, sizeof(a));     vector<request> v;     for (int i = 0; i < q; i++) {       int type;       cin >> type;       if (type != 3) {         int r;         cin >> r;         v.push_back(request(type, r));       } else {         int x, y, val;         cin >> x >> y >> val;         v.push_back(request(type, x, y, val));       }     }     reverse(v.begin(), v.end());     int tmp[MX_SZ];     for (int i = 0; i < q; i++) {       if (v[i].type == 1) {         for (int j = 1; j <= m; j++) {           if (j == m) {             tmp[1] = a[v[i].r][j];           } else {             tmp[j + 1] = a[v[i].r][j];           }         }         for (int j = 1; j <= m; j++) {           a[v[i].r][j] = tmp[j];         }       }       if (v[i].type == 2) {         for (int j = 1; j <= n; j++) {           if (j == n) {             tmp[1] = a[j][v[i].r];           } else {             tmp[j + 1] = a[j][v[i].r];           }         }         for (int j = 1; j <= n; j++) {           a[j][v[i].r] = tmp[j];         }       }       if (v[i].type == 3) {         a[v[i].x][v[i].y] = v[i].val;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cout << a[i][j] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string val;     cin >> val;     int cngIn1 = -1;     int lDigit = int(val[val.length() - 1] -  0 );     for (int i = val.length() - 2; i >= 0; i--) {       int dig = int(val[i] -  0 );       if ((dig % 2 == 0) && (dig < lDigit)) {         cngIn1 = i;       }     }     string sNewVal1 = val;     if (cngIn1 != -1) {       sNewVal1[sNewVal1.length() - 1] = val[cngIn1];       sNewVal1[cngIn1] = val[sNewVal1.length() - 1];     }     int cngIn2 = -1;     for (int i = val.length() - 2; i >= 0; i--) {       int dig = int(val[i] -  0 );       if ((dig % 2 == 0) && (dig > lDigit)) {         cngIn2 = i;         break;       }     }     string sNewVal2 = val;     if (cngIn2 != -1) {       sNewVal2[sNewVal2.length() - 1] = val[cngIn2];       sNewVal2[cngIn2] = val[sNewVal2.length() - 1];     }     if ((sNewVal1 == val) && (sNewVal2 == val)) {       cout << -1;     } else if (sNewVal1 == val) {       cout << sNewVal2;     } else if (sNewVal2 == val) {       cout << sNewVal1;     } else {       cout << sNewVal1;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m[100005], a[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       m[i] = a[i] + 1;     }     long long ans = 0;     for (int i = n - 1; i >= 1; --i) m[i] = max(m[i], m[i + 1] - 1);     for (int i = 1; i <= n; ++i) m[i] = max(m[i], m[i - 1]);     for (int i = 1; i <= n; ++i) ans += (m[i] - a[i] - 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void in(T &a) {     for (auto &x : a) cin >> x;   }   template <class T>   void out(T &a, string sep =    ) {     for (auto x : a) cout << x << sep;     cout <<   n ;   }   template <class T>   void err(T &a, string sep =    ) {     for (auto x : a) cerr << x << sep;     cerr <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int l;     cin >> l;     string a;     cin >> a;     int i = ((int)(a).size()) - 1;     while (i >= 0 && a[i] ==  9 ) {       a[i] =  0 ;       i--;     }     if (i >= 0) a[i]++;     if (i < 0 || ((int)(a).size()) % l) {       for (int i = 0; i <= ((int)(a).size()) / l; i++) {         cout <<  1 ;         for (int j = 1; j < l; j++) cout <<  0 ;       }       cout <<   n ;       return 0;     }     int in = 0;     for (int i = l; i < ((int)(a).size()); i++) {       if (a[i] < a[i % l]) {         break;       }       if (a[i] > a[i % l]) {         in = 1;         break;       }     }     if (in) {       int i = l - 1;       while (a[i] ==  9 ) {         a[i] =  0 ;         i--;       }       a[i]++;     }     for (int i = 0; i < ((int)(a).size()) / l; i++) cout << a.substr(0, l);     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, x, y, lev;     cin >> a >> y >> x;     a *= 2;     x *= 2;     y *= 2;     if (x % a == 0) {       cout << -1;       return 0;     } else       lev = (x / a) + 1;     if (lev == 1)       if (abs(y) >= a / 2) {         cout << -1;         return 0;       } else {         cout << 1;         return 0;       }     else if (lev % 2 == 0)       if (abs(y) >= a / 2) {         cout << -1;         return 0;       } else {         cout << (3 * lev) / 2 - 1;         return 0;       }     else if (abs(y) >= a || y == 0) {       cout << -1;       return 0;     } else if (y < 0) {       cout << (3 * (lev - 1)) / 2;       return 0;     } else {       cout << (3 * (lev - 1)) / 2 + 1;       return 0;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {     for (Tp current = _begin; current != _end; ++current) {       std::cout << *current << _delim;     }     std::cout <<   n ;   }   using ll = long long;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<const int>(1e9 + 7);   constexpr int MAXN = 20005;   int dp[2][MAXN];   int cnt[MAXN];   int sum[MAXN];   int Add(int x, int y) {     x += y;     return x < MOD ? x : x - MOD;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < (n); ++i) {       cin >> arr[i];     }     int off = 10000;     int cur = 0;     int ans = 0;     dp[0][off] = 1;     cnt[off] = 1;     for (int i = 0; i < (n); ++i) {       int pre = cur;       cur ^= 1;       memset(dp[cur], 0, sizeof(dp[cur]));       for (int j = -10000; j <= 10000; ++j) {         if (j - arr[i] >= -10000) {           dp[cur][j - arr[i] + off] =               Add(dp[cur][j - arr[i] + off], dp[pre][j + off]);         }         if (j + arr[i] <= 10000) {           dp[cur][j + arr[i] + off] =               Add(dp[cur][j + arr[i] + off], dp[pre][j + off]);         }       }       ans = Add(ans, dp[cur][off]);       dp[cur][off] = Add(dp[cur][off], 1);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans(0);     cin >> n;     int h[n], a[n];     for (int i = 0; i < n; i++) {       cin >> h[i] >> a[i];     }     for (int b = 0; b < n; b++) {       for (int c = 0; c < n; c++) {         if (c != b) {           if (h[b] == a[c]) ans++;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   long long inv(long long a) {     long long p = md - 2;     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % md;       a = a * a % md;       p >>= 1;     }     return ret;   }   int mp[1010][1010];   int xn[2100], yyyn[2100], dn[2100];   void range(int &x0, int &y0, int &x1, int &y1) {     x0 = max(x0, 1);     y0 = max(y0, 1);     x1 = min(x1, 1000);     y1 = min(y1, 1000);   }   int cnt(int x0, int y0, int x1, int y1) {     range(x0, y0, x1, y1);     return mp[x1][y1] - mp[x0 - 1][y1] - mp[x1][y0 - 1] + mp[x0 - 1][y0 - 1];   }   long long cn[2100];   void init(int m) {     memset(cn, 0, sizeof(cn));     cn[m] = 1;     for (int i = m + 1; i < 2100; i++) {       cn[i] = cn[i - 1] * i % md * inv(i - m) % md;     }   }   long long c(int n, int m) { return cn[n]; }   int main() {     int z;     int n, m, r;     int i, j, k;     memset(mp, 0, sizeof(mp));     cin >> n >> m >> r;     for (i = 0; i < n; i++) {       cin >> xn[i] >> yyyn[i] >> dn[i];       mp[xn[i]][yyyn[i]] = 1;     }     for (i = 1; i <= 1000; i++) {       for (j = 1; j <= 1000; j++) {         mp[i][j] = mp[i - 1][j] + mp[i][j - 1] - mp[i - 1][j - 1] + mp[i][j];       }     }     long long ans = 0;     init(m);     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         int xi = xn[i], yi = yyyn[i];         int xj = xn[j], yj = yyyn[j];         int dx = abs(xi - xj), dy = abs(yi - yj);         int u, v, w;         u = cnt(xi - r, yi - r, xi + r, yi + r);         v = cnt(xj - r, yj - r, xj + r, yj + r);         if (dx <= 2 * r && dy <= 2 * r) {           int x0, y0, x1, y1;           if (xi > xj) swap(xi, xj);           x0 = xj - r, x1 = xi + r;           if (yi > yj) swap(yi, yj);           y0 = yj - r, y1 = yi + r;           w = cnt(x0, y0, x1, y1);         } else {           w = 0;         }         u -= w;         v -= w;         long long sum = ((c(n, m) - c(n - w, m) + md) +                          (c(n - w, m) - c(n - w - u, m) - c(n - w - v, m) +                           c(n - w - u - v, m) + 2 * md)) %                         md;         ans = (ans + 2 * sum % md * dn[i] % md * dn[j] % md) % md;       }       int ni = cnt(xn[i] - r, yyyn[i] - r, xn[i] + r, yyyn[i] + r);       ans = (ans + (c(n, m) - c(n - ni, m) + md) % md * dn[i] % md * dn[i] % md) %             md;     }     cout << ans % md << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[7];   int y[7];   bool inside1(float x1, float y1) {     if (x1 + .5 >= x[3] && x1 + .5 <= x[4] && y1 + .5 >= y[3] && y1 + .5 <= y[4])       return 1;     return 0;   }   bool inside2(float x1, float y1) {     if (x1 + .5 >= x[5] && x1 + .5 <= x[6] && y1 + .5 >= y[5] && y1 + .5 <= y[6])       return 1;     return 0;   }   int main() {     for (int i = 0; i < (int)(6); ++i) cin >> x[i + 1] >> y[i + 1];     for (int i = (y[1]); i < (int)(y[2]); ++i) {       for (int j = (x[1]); j < (int)(x[2]); ++j) {         if (inside1(j, i) && inside2(j, i)) {           j = max(x[4], x[6]);           if (j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else if (inside1(j, i)) {           j = x[4];           if (!inside2(j, i) && j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else if (inside2(j, i)) {           j = x[6];           if (!inside1(j, i) && j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else {           cout <<  YES  << endl;           return 0;         }       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limB = 1 << 20;   const int limN = 20;   bool usdA[limB][limN], usdB[limB][limN];   int ansA[limB][limN], ansB[limB][limN];   int ja(int n, int k);   int jb(int n, int k);   int ja(int n, int k) {     if (k == 2) return n;     if (usdA[n][k]) return ansA[n][k];     usdA[n][k] = true;     int &ans = ansA[n][k];     ans = jb(n >> 1, k - 1);     for (int i = 1; i < k; i++) {       ans = min(ans, jb(((n >> (i + 1)) << i) + n % (1 << i), k - 1));     }     return ans;   }   int jb(int n, int k) {     if (k == 2) return n;     if (usdB[n][k]) return ansB[n][k];     usdB[n][k] = true;     int &ans = ansB[n][k];     ans = ja(n >> 1, k - 1);     for (int i = 1; i < k; i++) {       ans = max(ans, ja(((n >> (i + 1)) << i) + n % (1 << i), k - 1));     }     return ans;   }   void pint(int n, int k) {     int w = 0;     for (int i = k - 1; i >= 0; i--) {       printf( %d , (1 << i) & n ? 1 : 0);       if ((1 << i) & n) w++;     }     printf(  => %d n , w);   }   char str[limB];   int main() {     scanf( %s , str);     int mino = 0, maxo = 0, n = 0;     char ut =  ? ;     for (char *c = str; *c; c++) {       mino += *c ==  1  ? 1 : 0;       maxo += *c !=  0  ? 1 : 0;       ut = *c;       n++;     }     n = (n + 1) / 2;     if (mino <= n - 1) printf( 00 n );     if (mino <= n && n <= maxo) {       if (ut ==  1  || (ut ==  ?  && mino + 1 <= n)) printf( 01 n );       if (ut ==  0  || (ut ==  ?  && n <= maxo - 1)) printf( 10 n );     }     if (n + 1 <= maxo) printf( 11 n );   }