#include <bits/stdc++.h>   using namespace std;   int n, m, q;   char s2[10000006];   char s[205][205];   int vis[205][205];   int dp[205 * 205][20];   int dx[10];   int dy[10];   vector<int> Q;   int id(int x, int y) { return x * m + y; }   void dfs(int x, int y) {     vis[x][y] = 1;     int t = (s[x][y] -  0 ), p = id(x, y);     int xx = x + dx[t], yy = y + dy[t];     if (xx < 0 || xx >= n || yy < 0 || yy >= m)       dp[p][t] = p;     else {       int v = id(xx, yy);       dp[p][t] = id(xx, yy);       if (vis[xx][yy] == 0) dfs(xx, yy);       for (int i = 0; i < 10; i++)         if (i != t) dp[p][i] = dp[v][i];     }   }   int check(char s2[]) {     int len = strlen(s2);     for (int i = 0; i < Q.size(); i++) {       int x = Q[i];       for (int j = 0; j < len; j++) {         x = dp[x][s2[j] -  0 ];         if (x < 0) break;       }       if (x >= 0) return 1;     }     return 0;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < 10; i++) scanf( %d%d , &dx[i], &dy[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!vis[i][j]) {           dfs(i, j);           Q.push_back(id(i, j));         }       }     }     for (int i = 0; i < q; i++) {       scanf( %s , s2);       if (check(s2))         printf( YES n );       else         puts( NO );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   int RAND() { return (rand() << 16) + rand(); }   const long long MOD = 1000000007;   const int N = 2000007;   int n;   long long f[N];   long long power(long long a, long long b) {     if (b == 0) return 1;     if (b & 1) return a * power(a, b - 1) % MOD;     long long r = power(a, b >> 1);     return r * r % MOD;   }   long long inv(long long a) { return power(a, MOD - 2); }   long long C(int n, int k) { return f[n] * inv(f[k] * f[n - k] % MOD) % MOD; }   void solve() {     f[0] = 1;     for (int i = 1; i < N; ++i) f[i] = i * f[i - 1] % MOD;     cin >> n;     long long ans = ((n + 2) * C(2 * n + 2, n) - n - 1) % MOD * inv(n + 1) % MOD;     if (ans < 0) ans += MOD;     cout << ans << endl;   }   void testgen() {     FILE* f = fopen( input.txt ,  w );     fclose(f);   }   int main() {     cout << fixed;     cout.precision(16);     cerr << fixed;     cerr.precision(3);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long calc(int *a, int n) {     long long ret = 0, suml = 0;     stack<pair<int, int> > st;     for (int i = 2; i <= n; i++) {       int l = 1;       while (!st.empty() && abs(a[i] - a[i - 1]) > st.top().first) {         suml -= st.top().first * (long long)st.top().second;         l += st.top().second;         st.pop();       }       st.push(make_pair(abs(a[i] - a[i - 1]), l));       suml += abs(a[i] - a[i - 1]) * (long long)l;       ret += suml;     }     return ret;   }   int n, m, a[100010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d%d , &l, &r);       printf( %I64d n , calc(a + l - 1, r - l + 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, rooms = 0;     char a, b;     scanf( %d n , &n);     int arr[30];     for (int i = 0; i < 26; i++) arr[i] = 0;     for (int i = 0; i < 2 * (n - 1); i += 2) {       scanf( %c%c , &a, &b);       arr[(int)(a -  a )]++;       if (arr[(int)(tolower(b) -  a )] > 0)         arr[(int)(tolower(b) -  a )]--;       else         rooms++;     }     cout << rooms << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     string s;     int t[128];     t[ > ] = 8;     t[ < ] = 9;     t[ + ] = 10;     t[ - ] = 11;     t[ . ] = 12;     t[ , ] = 13;     t[ [ ] = 14;     t[ ] ] = 15;     cin >> s;     int ans = 0;     for (int i = 0; i < (int)(s).size(); ++i) {       ans = (ans * 16 + t[(int)s[i]]) % 1000003;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x, i, m = 1, second = 0;     cin >> n >> x;     long long a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = n - 1; i >= 0; i--) {       second += a[i];       if (((second * 1.0) / m) < (x * 1.0)) break;       m++;     }     cout << m - 1 <<   n ;   }   signed main() {     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<char> veq;   void getVeq() {     string s;     cin >> s;     veq.clear();     n = s.length();     veq.push_back( x );     veq.push_back( x );     for (int i = 0; i < s.length(); i++) veq.push_back(s[i]);     veq.push_back( x );     veq.push_back( x );   }   vector<int> ind;   void getRes() {     char a, b, curr, c, d;     ind.clear();     a = veq[0];     b = veq[1];     curr = veq[2];     c = veq[3];     d = veq[4];     for (int i = 2; i <= n + 1; i++) {       curr = veq[i];       c = veq[i + 1];       d = veq[i + 2];       if (curr ==  e  && b ==  n  && a ==  o ) {         ind.push_back(i - 2);         b =  e ;       } else if (curr ==  o  && b ==  w  && a ==  t ) {         if (c ==  n  && d ==  e ) {           ind.push_back(i - 1);         } else {           ind.push_back(i - 2);           b =  o ;         }       } else {         a = b;         b = curr;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       getVeq();       getRes();       cout << ind.size() <<   n ;       for (int i = 0; i < ind.size(); i++) cout << ind[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, p, x, y, f, kek, all, a[100005];   int main() {     cin >> n >> k >> p >> x >> y;     for (int i = 1; i <= k; i++) cin >> a[i];     int kol = (n + 1) / 2;     for (int i = 1; i <= k; i++)       if (a[i] >= y) kol--;     if (n - k < kol) {       cout << -1;       return 0;     }     if (kol > 0)       for (int j = k + 1; j <= k + kol; j++) a[j] = y;     kol = max(0, kol);     for (int j = k + kol + 1; j <= n; j++) a[j] = 1;     int all = 0;     for (int i = 1; i <= n; i++) all += a[i];     if (all > x) {       cout << -1;       return 0;     }     for (int i = k + 1; i <= n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long INF = 9e18;   const int inf = 2147483647;   long long phi(long long n) {     long long ans = n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         ans = ans / i * (i - 1);         while (n % i == 0) n /= i;       }     }     if (n > 1) ans = ans / n * (n - 1);     return ans;   }   long long qpow(long long a, long long b, long long mod) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = (r * a) % mod;       a = (a * a) % mod;     }     return r;   }   long long C(int n, int m) {     if (m < n - m) m = n - m;     long long ans = 1;     for (int i = m + 1; i <= n; i++) ans *= i;     for (int i = 1; i <= n - m; i++) ans /= i;     return ans;   }   const int N = 2e5 + 5;   int look(int a, int x) {     int q = sqrt(x + 0.5);     int ans = inf;     for (int i = 2; i <= q; i++) {       if (x % i == 0) {         int j = x / i;         if (abs(i - a) < abs(j - a)) {           if (abs(ans - a) > abs(i - a)) {             ans = i;           }         } else {           if (abs(ans - a) > abs(j - a)) {             ans = j;           }         }       }     }     if (ans >= inf) {       if (abs(1 - a) < abs(x - a)) {         ans = 1;       } else {         ans = x;       }     } else {       if (abs(ans - a) > abs(1 - a)) {         ans = 1;       }       if (abs(ans - a) > abs(x - a)) {         ans = x;       }     }     return ans;   }   void work() {     int t;     scanf( %d , &t);     while (t--) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       int ta, tc;       int ans = inf;       int as[5];       for (int i = 1; i <= (int)2e4; i++) {         int tb = i;         if (tb > a) {           ta = look(a, tb);         } else {           ta = tb;         }         if (c > tb) {           int t1 = c / tb;           int xc = t1 * tb, dc = (t1 + 1) * tb;           if (abs(c - xc) < abs(c - dc)) {             tc = xc;           } else {             tc = dc;           }         } else {           tc = tb;         }         int cnt1 = abs(a - ta), cnt2 = abs(b - tb), cnt3 = abs(c - tc);         if (cnt1 + cnt2 + cnt3 < ans) {           ans = cnt1 + cnt2 + cnt3;           as[0] = ta, as[1] = tb, as[2] = tc;         }       }       printf( %d n , ans);       for (int i = 0; i < 3; ++i) {         printf( %d  , as[i]);       }       puts(  );     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   vector<int> adj[MAXN];   vector<pair<int, int>> q[MAXN];   int n, m;   long long ans[MAXN], depval[MAXN];   void dfs(int u, int dep, int pre, long long cur) {     for (auto pr : q[u]) {       depval[dep] += pr.second;       if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] -= pr.second;     }     long long curr = cur + depval[dep];     ans[u] = curr;     for (auto v : adj[u])       if (v != pre) dfs(v, dep + 1, u, curr);     for (auto pr : q[u]) {       depval[dep] -= pr.second;       if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] += pr.second;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int v, d, x;       scanf( %d%d%d , &v, &d, &x);       q[v].emplace_back(d, x);     }     dfs(1, 0, 1, 0);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300 + 5;   const int MBIT = 15 + 5;   const int INF = 0x3f3f3f3f;   int n, m, MT, dp[MBIT][MAXN][MAXN];   int ans[2][MAXN][MAXN];   inline void umax(int& a, const int& b) { a = max(a, b); }   void init() {     MT = (int)floor(log2((long double)n));     for (int s = 0; s <= MT; s++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dp[s][i][j] = -INF;         }         dp[s][i][i] = 0;       }     }   }   void clr(int z) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         ans[z][i][j] = -INF;       }       ans[z][i][i] = 0;     }   }   bool check(int step) {     int z = 0;     clr(z);     for (int s = 0; s <= MT; s++) {       if (((step >> s) & 1) == 0) continue;       z ^= 1;       clr(z);       for (int k = 1; k <= n; k++) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) {             umax(ans[z][i][j], ans[z ^ 1][i][k] + dp[s][k][j]);           }         }       }     }     for (int i = 1; i <= n; i++) {       if (ans[z][i][i] > 0) return true;     }     return false;   }   int main() {     int u, v, a, b;     while (~scanf( %d %d , &n, &m)) {       init();       for (int i = 1; i <= m; i++) {         scanf( %d %d %d %d , &u, &v, &a, &b);         dp[0][u][v] = a, dp[0][v][u] = b;       }       for (int s = 1; s <= MT; s++) {         for (int k = 1; k <= n; k++) {           for (int i = 1; i <= n; i++) {             if (dp[s - 1][i][k] == -INF) continue;             for (int j = 1; j <= n; j++) {               umax(dp[s][i][j], dp[s - 1][i][k] + dp[s - 1][k][j]);             }           }         }       }       int lb = 2, ub = n + 1, mid;       while (lb <= ub) {         mid = (lb + ub) >> 1;         if (check(mid))           ub = mid - 1;         else           lb = mid + 1;       }       if (lb >= n + 1) lb = 0;       printf( %d n , lb);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool matrix[2005][2005];   int main() {     ios::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     string s;     getline(cin, s);     for (int y = 0; y < n; y++) {       getline(cin, s);       for (int x = 0; x < m; x++) matrix[x][y] = s[x] ==  . ;     }     int result = 0;     for (int x = 0; x < m; x++) {       int cnt = 0;       for (int y = 0; y < n; y++) {         if (matrix[x][y])           cnt++;         else {           result += max(0, cnt - k + 1);           cnt = 0;         }       }       result += max(0, cnt - k + 1);     }     if (k != 1) {       for (int y = 0; y < n; y++) {         int cnt = 0;         for (int x = 0; x < m; x++) {           if (matrix[x][y])             cnt++;           else {             result += max(0, cnt - k + 1);             cnt = 0;           }         }         result += max(0, cnt - k + 1);       }     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long Mod = 1e9 + 7;   const long double Pi = acos(-1);   long long n, m, k;   struct Weapon {     long long Pow, Val;   } a[200009], b[200009];   struct Monster {     long long Att, Def, Val;   } c[200009];   bool Cmp1(Weapon x, Weapon y) { return x.Pow < y.Pow; }   bool Cmp2(Monster x, Monster y) { return x.Att < y.Att; }   long long SufMin[200009];   long long Tree[800009], Lzy[800009];   void Merge(long long Node) {     Tree[Node] = max(Tree[Node * 2], Tree[Node * 2 + 1]);   }   void Build(long long Node, long long l, long long r) {     if (l == r) {       Tree[Node] = -a[l].Val;       return;     }     Build(Node * 2, l, (l + r) / 2);     Build(Node * 2 + 1, (l + r) / 2 + 1, r);     Merge(Node);   }   void LzyUpd(long long Node, long long l, long long r) {     Tree[Node] += Lzy[Node];     if (l != r) {       Lzy[Node * 2] += Lzy[Node];       Lzy[Node * 2 + 1] += Lzy[Node];     }     Lzy[Node] = 0;   }   void Upd(long long Node, long long l, long long r, long long s, long long e,            long long x) {     if (l > r || s > e) return;     LzyUpd(Node, l, r);     if (s > r || e < l) return;     if (s <= l && e >= r) {       Lzy[Node] += x;       LzyUpd(Node, l, r);       return;     }     Upd(Node * 2, l, (l + r) / 2, s, e, x);     Upd(Node * 2 + 1, (l + r) / 2 + 1, r, s, e, x);     Merge(Node);   }   long long Query(long long Node, long long l, long long r) {     LzyUpd(Node, l, r);     return Tree[Node];   }   long long Bin1(long long X) {     long long l = -1, r = n;     while (r - l > 1) {       if (a[(l + r) / 2].Pow > X)         r = (l + r) / 2;       else         l = (l + r) / 2;     }     return r;   }   long long Bin2(long long X) {     long long l = -1, r = m;     while (r - l > 1) {       if (b[(l + r) / 2].Pow > X)         r = (l + r) / 2;       else         l = (l + r) / 2;     }     return (r == m ? inf : SufMin[r]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].Pow >> a[i].Val;     }     for (int i = 0; i < m; i++) {       cin >> b[i].Pow >> b[i].Val;     }     for (int i = 0; i < k; i++) {       cin >> c[i].Def >> c[i].Att >> c[i].Val;     }     sort(a, a + n, Cmp1);     sort(b, b + m, Cmp1);     sort(c, c + k, Cmp2);     for (int i = m - 1; i >= 0; i--) {       SufMin[i] = b[i].Val;       SufMin[i] = min(SufMin[i], (long long)(i == m - 1 ? inf : SufMin[i + 1]));     }     Build(1, 0, n - 1);     long long Ans = -Bin2(0) + Query(1, 0, n - 1);     for (int i = 0; i < k; i++) {       long long Id = Bin1(c[i].Def);       Upd(1, 0, n - 1, Id, n - 1, c[i].Val);       long long Best1 = Bin2(c[i].Att);       long long Best2 = Query(1, 0, n - 1);       Ans = max(Ans, -Best1 + Best2);     }     cout << Ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, q = 524288, p, ans = 1, lz;   int s[1048576], r[1048576];   int getsum(int t) {     if (t >= q) {       if (r[t] > lz - q) {         return 0;       } else {         return s[t];       }     }     if (r[t] <= lz - q) {       return s[t];     } else if (r[t * 2] <= lz - q) {       return s[t * 2] + getsum(t * 2 + 1);     } else {       return getsum(t * 2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     cout << 1 << endl;     lz = n - 1 + q;     for (int i = q; i < 2 * q; i++) {       r[i] = i - q;     }     for (int i = q - 1; i > 0; i--) {       r[i] = r[i * 2 + 1];     }     for (int i = 0; i < n; i++) {       cin >> p;       p--;       p += q;       while (p > 0) {         s[p] += 1;         p /= 2;       }       while (s[lz]) lz--;       cout << getsum(1) + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   const int maxn = 100010;   const int mod = 1000000007;   int psum[7][maxn];   int t[7][maxn * 4];   bool needset[7][maxn * 4];   int tset[7][maxn * 4];   int a[maxn];   inline int calcsum(int ti, int fr, int to) {     int result = psum[ti][to];     if (fr) result = (result + mod - psum[ti][fr - 1]) % mod;     return result;   }   inline void push(int ti, int v, int L, int R) {     if (needset[ti][v]) {       int ls = v + v + 1;       int rs = v + v + 2;       needset[ti][v] = false;       if (L != R) {         needset[ti][ls] = needset[ti][rs] = true;         tset[ti][ls] = tset[ti][rs] = tset[ti][v];       }       t[ti][v] = tset[ti][v] * (long long)calcsum(ti, L, R) % mod;     }   }   inline void recalc(int ti, int v, int L, int R) {     int ls = v + v + 1;     int rs = v + v + 2;     int m = (L + R) >> 1;     push(ti, ls, L, m);     push(ti, rs, m + 1, R);     t[ti][v] = (t[ti][ls] + t[ti][rs]) % mod;   }   void build(int ti, int v, int L, int R) {     if (L == R) {       t[ti][v] = a[L];       for (int i = 0; i < ti; ++i) t[ti][v] = (long long)L * t[ti][v] % mod;     } else {       int m = (L + R) >> 1;       build(ti, v + v + 1, L, m);       build(ti, v + v + 2, m + 1, R);       recalc(ti, v, L, R);     }   }   void modify(int ti, int v, int l, int r, int val, int L, int R) {     push(ti, v, L, R);     if (L > r || l > R) return;     if (L >= l && R <= r)       needset[ti][v] = true, tset[ti][v] = val;     else {       int m = (L + R) >> 1;       push(ti, v, L, R);       modify(ti, v + v + 1, l, r, val, L, m);       modify(ti, v + v + 2, l, r, val, m + 1, R);       recalc(ti, v, L, R);     }   }   int comb[7][7];   int query(int ti, int v, int l, int r, int L, int R) {     push(ti, v, L, R);     if (l > R || L > r) return 0;     if (l <= L && r >= R)       return t[ti][v];     else {       int m = (L + R) >> 1;       int q1 = query(ti, v + v + 1, l, r, L, m);       int q2 = query(ti, v + v + 2, l, r, m + 1, R);       return (q1 + q2) % mod;     }   }   int main() {     for (int i = 0; i < maxn; ++i) {       int curval = 1;       for (int j = 0; j < 7; ++j) {         psum[j][i] = curval;         if (i) (psum[j][i] += psum[j][i - 1]) %= mod;         curval = curval * (long long)i % mod;       }     }     for (int i = 0; i < 7; ++i) comb[i][0] = 1;     for (int i = 1; i < 7; ++i)       for (int j = 1; j < 7; ++j)         comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < 6; ++i) build(i, 0, 0, n);     for (int i = 0; i < m; ++i) {       char c = 0;       while (c !=  =  && c !=  ? ) c = getchar();       if (c ==  = ) {         int fr, to, val;         scanf( %d%d%d , &fr, &to, &val);         for (int j = 0; j < 6; ++j) modify(j, 0, fr, to, val, 0, n);       } else {         int fr, to, k;         scanf( %d%d%d , &fr, &to, &k);         int shift = fr - 1;         int answer = 0;         int sg = 1;         int st = 1;         for (int j = k; j >= 0; --j) {           int r = query(j, 0, fr, to, 0, n);           r = ((long long)r * st) % mod * (long long)comb[k][j] % mod;           if (sg == -1) r = (mod - r) % mod;           (answer += r) %= mod;           sg *= -1;           st = st * (long long)shift % mod;         }         printf( %d n , answer);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int n, m;   int a[110], b[110];   int main() {     while (~scanf( %d%d , &n, &m)) {       mp.clear();       for (int i = 0; i < (n); ++i) scanf( %d , a + i);       for (int i = 0; i < (m); ++i) {         string s;         cin >> s;         mp[s]++;       }       int tot = 0;       for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it)         b[tot++] = it->second;       sort(a, a + n);       sort(b, b + tot);       int mint = 0, maxt = 0;       for (int i = 0; i < (tot); ++i)         mint += a[i] * b[tot - 1 - i], maxt += a[n - tot + i] * b[i];       printf( %d %d n , mint, maxt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 250000 + 5;   long long dp[maxn];   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     dp[0] = dp[1] = 1;     for (long long i = 2; i <= n; i++) {       dp[i] = ((dp[i - 1] % m) * (i % m)) % m;     }     long long sum = 0;     for (long long i = 1; i <= n; i++) {       sum += (((dp[i] % m) * (dp[n - i + 1] % m) % m) * ((n - i + 1) % m)) % m;     }     printf( %lld n , sum % m);   }


#include <bits/stdc++.h>   using namespace std;   long n;   vector<long> prec;   int main() {     ios_base::sync_with_stdio(0);     prec.push_back(2);     prec.push_back(7);     prec.push_back(2);     prec.push_back(3);     prec.push_back(3);     prec.push_back(4);     prec.push_back(2);     prec.push_back(5);     prec.push_back(1);     prec.push_back(2);     cin >> n;     cout << prec[n / 10] * prec[n % 10] << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int a[s.length()];     int n = s.length();     int ans = 0;     for (int i = 0; i < n; i++) {       int x = s[i] -  0 ;       a[i] = x % 3;       if (a[i] == 0) {         ans++;       }     }     for (int i = 0; i < n; i++) {       if (a[i] == 1) {         if (i < n - 1) {           if (a[i + 1] == 2) {             ans++;             a[i] = 0;             a[i + 1] = 0;             continue;           }         }         if (i < n - 2) {           if (a[i + 1] == 1 and a[i + 2] == 1) {             ans++;             a[i] = 0;             a[i + 1] = 0;             a[i + 2] = 0;             continue;           }         }       }       if (a[i] == 2) {         if (i < n - 1) {           if (a[i + 1] == 1) {             ans++;             a[i] = 0;             a[i + 1] = 0;             continue;           }         }         if (i < n - 2) {           if (a[i + 1] == 2 and a[i + 2] == 2) {             ans++;             a[i] = a[i + 1] = a[i + 2] = 0;             continue;           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[1005];   vector<long long int> csum;   string str;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     int m;     cin >> n >> m;     long long int x;     cin >> x;     csum.push_back(x);     for (int i = 1; i < n; i++) {       cin >> x;       long long int y = x + csum[i - 1];       csum.push_back(y);     }     for (int i = 0; i < m; i++) {       long long int y;       cin >> y;       int lo = lower_bound(csum.begin(), csum.end(), y) - csum.begin();       if (lo + 1 == 1) {         cout << lo + 1 <<     << y << endl;         continue;       }       cout << lo + 1 <<     << y - csum[lo - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > init(int n, int v) {     vector<vector<int> > ret;     for (int i = 0; i < (n); ++i) {       vector<int> l;       l.resize(n);       for (int j = 0; j < (n); ++j) l[j] = v;       ret.push_back(l);     }     return ret;   }   void dump(const vector<vector<int> >& arr) {     cout <<   dump: n ;     int n = arr.size();     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (n); ++j) {         cout << arr[i][j] + 1 <<    ;       }       cout << endl;     }   }   bool discover(int n, const vector<string>& ma, vector<vector<int> >& has_p) {     bool found = false;     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (n); ++j) {         int points = ma[i][j] -  0 ;         int has_point = 0;         int no_point = 0;         for (int u = 0; u < (2); ++u) {           for (int v = 0; v < (2); ++v) {             int i1 = i + u;             int j1 = j + v;             has_point += has_p[i1][j1] == 1;             no_point += has_p[i1][j1] == -1;           }         }         points -= has_point;         int left_points = 4 - has_point - no_point;         if ((points == 0 || points == left_points) && left_points > 0) {           found = true;           int val = points == 0 ? -1 : 1;           for (int u = 0; u < (2); ++u) {             for (int v = 0; v < (2); ++v) {               int i1 = i + u;               int j1 = j + v;               if (has_p[i1][j1] == 0) {                 has_p[i1][j1] = val;               }             }           }         }       }     }     return found;   }   pair<int, int> del(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int dot(pair<int, int> a, pair<int, int> b) {     return a.first * b.second - a.second * b.first;   }   int main() {     int n;     while (cin >> n) {       if (n == 0) break;       vector<string> ma;       for (int i = 0; i < (n); ++i) {         string line;         cin >> line;         ma.push_back(line);       }       vector<vector<int> > has_p = init(n + 1, 0);       while (discover(n, ma, has_p))         ;       vector<pair<int, int> > points;       for (int i = 0; i < (n + 1); ++i) {         for (int j = 0; j < (n + 1); ++j) {           if (has_p[i][j] == 1) {             points.push_back(make_pair(j, n - i));           }         }       }       sort((points).begin(), points.end());       vector<pair<int, int> > conv;       conv.push_back(points[0]);       conv.push_back(points[1]);       for (int i = 2; i < (points.size()); ++i) {         while (conv.size() > 1 &&                dot(del(points[i], conv[conv.size() - 1]),                    del(conv[conv.size() - 1], conv[conv.size() - 2])) <= 0)           conv.pop_back();         conv.push_back(points[i]);       }       int nl = conv.size();       for (int i = points.size() - 2; i >= 0; i--) {         while (conv.size() > 1 &&                dot(del(points[i], conv[conv.size() - 1]),                    del(conv[conv.size() - 1], conv[conv.size() - 2])) <= 0 &&                conv.size() > nl) {           conv.pop_back();         }         conv.push_back(points[i]);       }       conv.pop_back();       cout << conv.size() << endl;       for (int i = 0; i < (conv.size()); ++i)         cout << conv[i].first <<     << conv[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, a, b;     cin >> n >> m >> a >> b;     if (n % m == 0) {       cout << 0;     } else {       long long j = n % m;       cout << min(j * b, (m - j) * a);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     cin >> a >> b >> c >> n;     int d = n - (a + b - c);     if ((a - c) >= 0 && (b - c) >= 0 && c >= 0 && d > 0) {       cout << d << endl;     } else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int inf = 0x3f3f3f3f;   int b[maxn];   int a[maxn];   int ma[maxn];   int pre[maxn * 10];   int _find(int x) { return x == pre[x] ? x : pre[x] = _find(pre[x]); }   void _union(int x, int y) {     x = _find(x), y = _find(y);     if (x < y)       pre[x] = y;     else       pre[y] = x;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < maxn * 10; ++i) pre[i] = i;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ma[i] = max(ma[i - 1], a[i]);     }     bool flag = true;     int x = 0;     for (int i = n; i > 0; --i) {       if (a[i] > ma[i - 1])         b[i] = ma[i - 1];       else         b[i] = a[i] + 1;       b[i] = _find(b[i]);       _union(b[i], b[i] + 1);       _union(a[i], a[i] + 1);       x = max(x, a[i]);     }     if (!flag)       puts( -1 );     else {       for (int i = 1; i <= n; ++i) printf( %d%c , b[i], i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7, N = 1e6 + 5;   char a[51][51];   int n, m;   int vis[51][51];   void dfs(int i, int j) {     vis[i][j] = 1;     if (i - 1 >= 0 and a[i - 1][j] ==  #  and vis[i - 1][j] == 0) dfs(i - 1, j);     if (i + 1 < n and a[i + 1][j] ==  #  and vis[i + 1][j] == 0) dfs(i + 1, j);     if (j - 1 >= 0 and a[i][j - 1] ==  #  and vis[i][j - 1] == 0) dfs(i, j - 1);     if (j + 1 < m and a[i][j + 1] ==  #  and vis[i][j + 1] == 0) dfs(i, j + 1);   }   int func() {     for (int i = 0; i < 51; i++)       for (int j = 0; j < 51; j++) vis[i][j] = 0;     int check = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  # ) check = 1, dfs(i, j);         if (check) break;       }       if (check) break;     }     check = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  #  and vis[i][j] == 0) {           check = 0;           break;         }       }     }     return check;   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cin >> n >> m;     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  # ) cnt++;       }     }     if (cnt <= 2) cout << -1, exit(0);     int ans = 2;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  # ) {           a[i][j] =  . ;           if (func() == 0) {             ans = 1;             break;           }           a[i][j] =  # ;         }       }       if (ans == 1) break;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, oo = 0x3f3f3f3f;   const long long M = 1e12 + 105;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, -1, 0, 1};   int main() {     int c, r, ans = 0;     scanf( %d %d , &r, &c);     char second[r][c];     for (int i = 0; i < r; i++) scanf( %s , second[i]);     for (int i = 0; i < r; i++) {       int cc = 0;       for (int j = 0; j < c; j++)         if (second[i][j] ==  S )           break;         else if (second[i][j] ==  . )           cc++;       if (cc == c) {         ans += cc;         for (int j = 0; j < c; j++) second[i][j] =  X ;       }     }     for (int i = 0; i < c; i++) {       bool ff = false;       int cc = 0;       for (int j = 0; j < r; j++)         if (second[j][i] ==  S ) {           ff = true;           break;         } else if (second[j][i] ==  . )           cc++, second[j][i] =  X ;       if (!ff) ans += cc;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int sum;   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0, x; i < n; ++i) scanf( %d , &x), sum += x;     for (int i = 0;; ++i) {       if (2 * sum >= (2 * k - 1) * (n + i)) {         printf( %d n , i);         break;       }       sum += k;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t pre[200001];   int64_t dp[200001];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pre[i];       pre[i] += pre[i - 1];     }     int64_t mx = -1e15;     for (int i = n - 1; i >= 1; --i) {       dp[i] = max(pre[n], mx);       mx = max(mx, pre[i] - dp[i]);     }     cout << dp[1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int m = 1000000007;   int size = 1000004;   bool mo(long long int n) {     int t = 0;     while (n) {       if (n % 10 == 3) t++;       n = n / 10;     }     if (t >= 3)       return true;     else       return false;   }   int main() {     long long int n;     cin >> n;     if (n == 1) {       cout << -1 << endl;       return 0;     }     cout << n <<     << n + 1 <<     << n * (n + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long A = 100000000000000LL, N = 300228;   long long t[N * 4], i, j, n, m, a[N], p[N], o, b, l, r;   void modi(long long v, long long l, long long r, long long p, long long g) {     if (p < l || p > r) return;     if (l == r) {       t[v] = g;       return;     }     long long mid = (l + r) / 2;     if (p <= mid)       modi(v * 2, l, mid, p, g);     else       modi(v * 2 + 1, mid + 1, r, p, g);     t[v] = t[v * 2] + t[v * 2 + 1];   }   long long get(long long v, long long l, long long r, long long _l,                 long long _r) {     if (_l > _r) return 0;     if (l == _l && r == _r) return t[v];     long long mid = (l + r) / 2;     return get(v * 2, l, mid, _l, min(_r, mid)) +            get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r);   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) scanf( %d , &a[i]), p[a[i]] = i;     for (i = 1; i < n; i++)       if (p[i] > p[i + 1]) modi(1, 1, n, i + 1, 1);     cin >> m;     while (m--) {       scanf( %d%d%d , &b, &l, &r);       if (b == 1)         printf( %d n , get(1, 1, n, l + 1, r) + 1);       else {         swap(p[a[l]], p[a[r]]), swap(a[l], a[r]);         if (p[a[l]] > p[a[l] + 1])           modi(1, 1, n, a[l] + 1, 1);         else           modi(1, 1, n, a[l] + 1, 0);         if (p[a[r]] > p[a[r] + 1])           modi(1, 1, n, a[r] + 1, 1);         else           modi(1, 1, n, a[r] + 1, 0);         if (p[a[l] - 1] > p[a[l]])           modi(1, 1, n, a[l], 1);         else           modi(1, 1, n, a[l], 0);         if (p[a[r] - 1] > p[a[r]])           modi(1, 1, n, a[r], 1);         else           modi(1, 1, n, a[r], 0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool desc(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long counter = 0, countedge = 0;   void addEdge(vector<long long> adj[], long long u, long long v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   long long fact(long long x) {     long long z = 1;     while (x > 0) {       z *= x;       x--;     }     return z;   }   long long power(long long x, long long y) {     long long z = 1;     while (y-- > 0) {       z *= 2;     }     return z;   }   void dfs(vector<long long> adj[], long long u, bool vis[]) {     int i, j;     vis[u] = true;     counter++;     countedge += adj[u].size();     for (i = 0; i < adj[u].size(); i++) {       if (!vis[adj[u][i]]) dfs(adj, adj[u][i], vis);     }   }   pair<pair<long long, long long>, pair<long long, long long> > Intersect(       pair<long long, long long> a, pair<long long, long long> b,       pair<long long, long long> c, pair<long long, long long> d) {     int i, j, z, lf, rg, up, dwn;     pair<long long, long long> p1, p2;     lf = max(a.first, c.first);     rg = min(b.first, d.first);     dwn = max(a.second, c.second);     up = min(b.second, d.second);     p1 = make_pair(lf, dwn);     p2 = make_pair(rg, up);     if (rg <= lf || up <= dwn) return {{0, 0}, {0, 0}};     return make_pair(p1, p2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, j, n, m, cont = 0, p, d, mn, sum = 0, k, a, b, z, w,                               sum2 = 0, c = 0, first, val, ans, nx, ny, o = 0, mx,                               s1, s2, l, r;     string s, t;     long long flag = 0;     vector<pair<long long, long long> > pt(7);     for (i = 1; i <= 6; i++) {       cin >> pt[i].first >> pt[i].second;     }     pair<pair<long long, long long>, pair<long long, long long> > wb1, wb2, inter;     wb1 = Intersect(pt[1], pt[2], pt[3], pt[4]);     wb2 = Intersect(pt[1], pt[2], pt[5], pt[6]);     inter = Intersect(wb1.first, wb1.second, wb2.first, wb2.second);     long long a1, a2;     a1 = (abs(wb1.first.first - wb1.second.first) *           abs(wb1.first.second - wb1.second.second));     a2 = (abs(wb2.first.first - wb2.second.first) *           abs(wb2.first.second - wb2.second.second));     c = (abs(inter.first.first - inter.second.first) *          abs(inter.first.second - inter.second.second));     long long area = (pt[1].first - pt[2].first) * (pt[1].second - pt[2].second);     if (area > (a1 + a2 - c))       cout <<  YES ;     else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, q, a[2000000], f[2000000], fst[2000000], nx[2000000];   int main() {     srand(time(0));     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (; q--;) {       long long b;       cin >> b;       int answer = 2e9, j = 1;       long long sum = 0;       for (int i = 1; i <= n; i++) {         sum += a[i];         while (sum > b) {           sum -= a[j];           j++;         }         nx[i] = j - 1;       }       f[0] = 0;       for (int i = 1; i <= n; i++) f[i] = f[nx[i]] + 1;       for (int i = 1; i <= n; i++)         if (f[i] == 1)           fst[i] = i;         else           fst[i] = fst[nx[i]];       sum = a[1];       if (sum > b) {         printf( %d n , answer);         continue;       }       int it = 1;       long long rightpart = a[1];       for (int i = 2; i < n; i++) {         if (sum + a[i] > b) break;         sum += a[i];         rightpart += a[i];         it = i;       }       for (int i = n; i >= 2; i--) {         sum += a[i];         while (it > 0 && sum > b) {           sum -= a[it];           rightpart -= a[it];           it--;         }         if (sum > b) break;         if (fst[i - 1] <= it)           answer = min(answer, f[i - 1]);         else           answer = min(answer, f[i - 1] + 1);       }       printf( %d n , answer);     };     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   int n;   int a[N], indexes[N], parent[N], rrank[N], ccount[N];   bool used[N];   int get_set(int v) {     if (v == parent[v]) return v;     return parent[v] = get_set(parent[v]);   }   void create_set(int v) {     parent[v] = v;     rrank[v] = 0;     ccount[v] = 1;   }   void merge_sets(int v, int u) {     v = get_set(v);     u = get_set(u);     if (v != u) {       if (rrank[v] > rrank[u]) swap(v, u);       parent[v] = u;       if (rrank[v] == rrank[u]) rrank[u]++;       ccount[u] += ccount[v];     }   }   bool comp(int i, int j) { return a[i] < a[j]; }   int solve() {     int maxSize = 0, maxSets, sets = 0;     int res = 0, resSets = -1;     for (int i = 0; i < n; i++) {       bool isMerged = false;       int ind = indexes[i];       used[ind] = true;       sets++;       if (ind > 0 && used[ind - 1]) {         isMerged = true;         merge_sets(ind - 1, ind);         sets--;       }       if (ind < n - 1 && used[ind + 1]) {         isMerged = true;         merge_sets(ind + 1, ind);         sets--;       }       int sst = get_set(ind);       if (ccount[sst] > maxSize) {         maxSize = ccount[sst];         maxSets = 1;       } else if (ccount[sst] == maxSize) {         maxSets++;       }       if (i < n - 1 && a[indexes[i]] == a[indexes[i + 1]]) {         continue;       }       if (maxSets == sets && sets > resSets) {         resSets = sets;         res = a[ind] + 1;       }     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       indexes[i] = i;       create_set(i);       used[i] = false;     }     sort(indexes, indexes + n, comp);     cout << solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int m;   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int inv(long long int x) { return power(x, m - 2); }   long long int prime[100009];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> m;     for (long long int i = 2; i <= 100000; i++) {       if (prime[i] == 0) {         for (long long int j = (2 * i); j <= 100000; j += i) {           prime[j] = 1;         }       }     }     if (m == 1) {       cout <<  YES  <<   n  << 1;     } else if (m == 4) {       cout <<  YES  <<   n ;       cout << 1 <<   n  << 3 <<   n  << 2 <<   n  << 4;     } else if (prime[m] == 0) {       cout <<  YES  <<   n ;       cout << 1 <<   n ;       long long int x = 1;       for (long long int j = 2; j < m; j++) {         x = inv((j - 1));         x *= j;         x %= m;         cout << x <<   n ;       }       cout << m;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long u;   long long a[1000];   long long d[1000];   long long minn = -1e17;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       d[i] = minn;     }     for (int i = n; i >= 0; --i) {       for (int j = n; j >= 0; --j) {         if (j == 0) {           u = minn;         } else           u = d[j - 1];         d[j] = max(min(d[j] + a[i], 0LL), u);       }     }     while (m--) {       scanf( %lld , &u);       int k = lower_bound(d, d + n + 1, -u) - d;       cout << k << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1E-9;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double PI = 2 * acos(.0);   int main() {     bool cumple[1005];     for (int i = 0; i < (int)(1005); i++) cumple[i] = false;     string word;     cin >> word;     int n = (word).size();     for (int i = 2; i <= n / 2; i++) {       cumple[i] = 1;       for (int j = 2; i * j <= n; j++) {         cumple[i * j] = 1;       }     }     int cont1 = 0;     for (int i = 1; i < (int)(n + 1); i++) {       if (cumple[i] == 1) cont1++;     }     int numWord[50];     memset(numWord, 0, sizeof(numWord));     for (int i = 0; i < (int)(n); i++) numWord[word[i] -  a ]++;     int maxPos = -1, maxi = -1;     for (int i = 0; i < (int)(50); i++) {       if (maxi < numWord[i]) {         maxi = numWord[i];         maxPos = i;       }     }     if (maxi < cont1)       cout <<  NO  << endl;     else {       string rege;       rege.append(n,  ? );       for (int i = 1; i < (int)(n + 1); i++)         if (cumple[i] == 1) rege[i - 1] =  a  + maxPos;       numWord[maxPos] -= cont1;       int cont = 0, wpos = 0;       while (wpos < n) {         if (rege[wpos] ==  ? ) {           if (numWord[cont] > 0) {             rege[wpos] = ( a  + cont);             numWord[cont]--;           } else             cont++;         } else           wpos++;       }       cout <<  YES  << endl;       cout << rege << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int t;       cin >> t;       while (t--) {           int n, k;           cin >> n >> k;           string s;           cin >> s;           vector<int> pos;           vector<int> v;           for (int i = 0; i < n; i++) {               if (s[i] ==  * ) {                   pos.push_back(i);               }           }           if (pos.size()) {               v.push_back(pos[0]);           }           while (v.size() and v.back() + k < n) {               int i = upper_bound(pos.begin(), pos.end(), v.back() + k) - pos.begin();               if (pos[i - 1] == v.back()) {                   break;               }               v.push_back(pos[i - 1]);           }           if (pos.back() != v.back()) {               v.push_back(pos.back());           }           cout << v.size() <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ToInt(string& s, int len) {     int r = 0;     for (int i = 0, max_ = (len); i < max_; ++i) {       r *= 10;       r += s[i] -  0 ;     }     return r;   }   int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   int SolvePile(long long n) {     if (n < 4)       return 0;     else if (n < 16)       return 1;     else if (n < 82)       return 2;     else if (n < 6724)       return 0;     else if (n < 50626)       return 3;     else if (n < 2562991876LL)       return 1;     else       return 2;   }   int main() {     long long n;     int N, res = 0;     scanf( %d , &N);     for (int i = 0, max_ = (N); i < max_; ++i) {       scanf( %I64d , &n);       res ^= SolvePile(n);     }     if (res > 0)       printf( Furlo n );     else       printf( Rublo n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool flag = true;     int n, m;     cin >> n;     cin >> m;     char prev;     for (int i = 0; i < n; i++) {       string row;       cin >> row;       if (i != 0 && row[0] == prev) {         flag = false;       }       for (int j = 1; j < m; j++) {         if (row[j] != row[0]) {           flag = false;           break;         }       }       prev = row[0];     }     if (flag) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[100010], ans;   int idx = 1;   void dfs(int cur, int prev) {     if ((int)v[cur].size() == 1 && cur != idx)       ans.push_back(cur);     else {       for (int i = 0; i < (int)v[cur].size(); i++) {         int j = v[cur][i];         if (j != prev) dfs(j, cur);       }     }     return;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if ((int)v[i].size() > 2) cnt++, idx = i;     if (cnt > 1) {       printf( No n );       return 0;     }     printf( Yes n );     dfs(idx, -1);     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++) printf( %d %d n , idx, ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 1000000007;   const double pi = 3.1415926535897932, eps = 1e-6;   void chmax(int &x, int y) {     if (x < y) x = y;   }   void chmin(int &x, int y) {     if (x > y) x = y;   }   int B = 333;   int n, top = 101000, cnt;   string s[100005];   int val[300005], ex[300005];   long long sum[444][5];   int num[444], rea[100005];   map<int, int> mp;   void calc(int x) {     int lb = x * B, rb = (x + 1) * B;     int now_cnt = 0;     for (int(i) = (0); (i) <= (4); (i)++) sum[x][i] = 0;     num[x] = 0;     for (int(i) = (lb); (i) < (rb); (i)++) {       if (ex[i]) {         sum[x][now_cnt % 5] += rea[i];         now_cnt++;       }     }     num[x] = now_cnt;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int(i) = (1); (i) <= (n); (i)++) {       cin >> s[i];       if (s[i] !=  sum ) {         cin >> val[i];         mp[val[i]] = 0;       }     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       rea[cnt] = it->first;       it->second = cnt++;     }     for (int(i) = (1); (i) <= (n); (i)++) {       if (s[i] ==  sum ) {         int Top = top / B + 1;         int now_cnt = 0;         long long ans = 0;         for (int(i) = (0); (i) <= (Top); (i)++) {           ans += sum[i][(2 - now_cnt + 555555555) % 5];           now_cnt += num[i];         }         cout << ans <<   n ;       } else {         val[i] = mp[val[i]];         if (s[i] ==  add ) {           int v = val[i];           ex[v] = 1;           int at = v / B;           calc(at);         } else {           int v = val[i];           ex[v] = 0;           int at = v / B;           calc(at);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXn = 100 + 13;   int n, k, t[MAXn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> t[i];     cin >> k;     sort(t, t + n);     int i = 0, j = 0, d = 0, num = 0, ans = 0;     while (j < n) {       d = t[j++] - t[i];       while (d > k) d -= t[i++];       num = j - i;       ans = max(ans, num);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[200010];   int main() {     int n;     cin >> n;     if (n & 1) {       puts( YES );       bool f = true;       for (int i = 0; i < n; i++) {         if (f)           ans[i + n] = (i + 1) * 2, ans[i] = (i + 1) * 2 - 1;         else           ans[i] = (i + 1) * 2, ans[i + n] = (i + 1) * 2 - 1;         f = !f;       }       for (int i = 0; i < (n * 2); i++) {         cout << ans[i] <<    ;       }     } else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long a, b, m;       cin >> a >> b >> m;       if (a == b) {         cout << 1 <<     << a <<   n ;         continue;       }       bool ok = 0;       long long dif = 0;       long long p = a, i = 1ll;       while (p <= b) {         if (b - p <= ((1ll << (i - 1ll)) * m) && b - p >= (1ll << (i - 1ll))) {           ok = 1;           dif = b - p - (1ll << (i - 1ll));           break;         }         i++;         p = (p * 2ll);       }       if (!ok) {         cout << (-1) <<   n ;         continue;       }       long long s1 = min(dif, m - 1);       dif -= s1;       cout << i + 1 <<    ;       long long res[55];       res[0] = a;       for (long long j = 1ll; j < i; j++) {         long long sss = 0;         for (long long u = 0; u < j; u++) sss += res[u];         sss += min((dif / (1ll << (i - j - 1ll))), m - 1ll);         dif -= min((dif / (1ll << (i - j - 1ll))), m - 1ll) *                (long long)((1ll << (i - j - 1ll)));         sss++;         res[j] = sss;       }       long long sss = 0;       for (long long u = 0; u < i; u++) sss += res[u];       sss += s1;       sss++;       res[i] = sss;       for (long long j = 0; j <= i; j++) cout << res[j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, p, d[100005], sum[100005], f[105][100005], s[100005], a[100005],       q[100005], head, tail, g[100005];   inline long long getint() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   void work() {     n = getint(), m = getint(), p = getint();     for (int i = 2; i <= n; ++i) d[i] = getint(), sum[i] = sum[i - 1] + d[i];     for (int i = 1; i <= m; ++i) {       int x, y;       x = getint(), y = getint();       a[i] = y - sum[x];     }     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; ++i) s[i] = s[i - 1] + a[i];     memset(f, 0x3f, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= p; ++i) {       for (int j = 1; j <= m; ++j) g[j] = f[i - 1][j] + s[j];       head = 1, tail = 1;       q[1] = 0;       for (int j = 1; j <= m; ++j) {         while (head < tail &&                g[q[head + 1]] - g[q[head]] <= a[j] * (q[head + 1] - q[head]))           ++head;         f[i][j] = min(f[i - 1][j], g[q[head]] + a[j] * (j - q[head]) - s[j]);         if (g[j] >= 0x3f3f3f3f3f3f3f3fll) continue;         while (head < tail && (g[j] - g[q[tail]]) * (q[tail] - q[tail - 1]) <=                                   (g[q[tail]] - g[q[tail - 1]]) * (j - q[tail]))           --tail;         q[++tail] = j;       }     }     cout << f[p][m] << endl;   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool c5 = true;     string s;     cin >> s;     int d = s.length();     for (int i = 0; i <= d; i++) {       for (char a =  a ; a <=  z ; a++) {         c5 = true;         s.insert(i, 1, a);         int d1 = s.length();         for (int j = 0; j < d1 / 2; j++) {           if (s[j] != s[d1 - 1 - j]) {             c5 = false;           }         }         if (c5 == true) {           break;         }         s.erase(i, 1);       }       if (c5 == true) {         break;       }     }     if (c5 == true) {       cout << s << endl;     } else       cout <<  NA  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int> > j(n);     for (int i = 0; i < n; i++) {       cin >> j[i].first;       j[i].second = i;     }     sort(j.begin(), j.end());     if (n == 1)       cout <<  Exemplary pages. n ;     else if (n == 2) {       if (j[0].first == j[1].first)         cout <<  Exemplary pages. n ;       else if ((j[1].first - j[0].first) % 2 == 0)         cout << (j[1].first - j[0].first) / 2 <<   ml. from cup #               << j[0].second + 1 <<   to cup #  << j[1].second + 1 <<  . n ;       else         cout <<  Unrecoverable configuration. n ;     } else {       if (j[0].first == j[n - 1].first)         cout <<  Exemplary pages. n ;       else if (j[1].first == j[n - 2].first &&                j[0].first + j[n - 1].first == j[1].first * 2)         cout << (j[n - 1].first - j[0].first) / 2 <<   ml. from cup #               << j[0].second + 1 <<   to cup #  << j[n - 1].second + 1 <<  . n ;       else         cout <<  Unrecoverable configuration. n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int vas = min(n, m);     int pet = n + m - 1 - vas;     cout << pet <<     << vas;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::ifstream;   using std::max;   using std::min;   using std::ofstream;   using std::string;   int dp[2204][2204];   int vec[21][2];   int x, y, vec_num_n, max_dist_d;   int dfs(int ori_x, int ori_y, int off_x, int off_y) {     if (dp[off_x][off_y] >= 0) {       return dp[off_x][off_y];     }     int cur_x = ori_x + off_x;     int cur_y = ori_y + off_y;     if (cur_x * cur_x + cur_y * cur_y > max_dist_d * max_dist_d) {       return dp[off_x][off_y] = 0;     }     for (int vec_i = 0; vec_i < vec_num_n; ++vec_i) {       int next_x = vec[vec_i][0] + off_x;       int next_y = vec[vec_i][1] + off_y;       if (dfs(ori_x, ori_y, next_x, next_y)) {         return dp[off_x][off_y] = 0;       }     }     return dp[off_x][off_y] = 1;   }   int main() {     cin >> x >> y >> vec_num_n >> max_dist_d;     for (int vec_i = 0; vec_i < vec_num_n; ++vec_i) {       cin >> vec[vec_i][0] >> vec[vec_i][1];     }     memset(dp, -1, sizeof(dp));     if (!dfs(x, y, 0, 0)) {       cout <<  Anton  << endl;     } else {       cout <<  Dasha  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int mod = 998244353;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar();     return x * f;   }   int qpow(int a, int p, int mod) {     int res = 1;     while (p) {       if (p & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       p >>= 1;     }     return res;   }   int inc(int x, int y, int mo) {     if (y < 0) y += mo;     if (x + y >= mo) x -= mo;     return x + y;   }   const int P = 998244353, gi = 3;   const double pi = acos(-1.0);   int rev[N];   void NTT(int *A, int n, int inv) {     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(A[i], A[rev[i]]);     for (int l = 1; l < n; l <<= 1) {       int tt = qpow(gi, (P - 1) / (l << 1), P);       int temp = (inv == 1 ? tt : qpow(tt, P - 2, P));       for (int i = 0; i < n; i += (l << 1)) {         int omega = 1;         for (int j = 0; j < l; j++, omega = 1ll * omega * temp % P) {           int x = A[i + j], y = 1ll * omega * A[i + j + l] % P;           A[i + j] = inc(x, y, P);           A[i + j + l] = inc(x, -y, P);         }       }     }     int invv = qpow(n, P - 2, P);     if (inv == -1)       for (int i = 0; i < n; i++) A[i] = 1ll * A[i] * invv % P;   }   int NTTinit(int n, int m) {     int ML = 1, bit = 0;     while (ML <= n + m) ML <<= 1, bit++;     for (int i = 0; i < ML; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));     return ML;   }   void NTTX(int *a, int n, int *b, int m) {     int ML = NTTinit(n, m);     NTT(a, ML, 1);     NTT(b, ML, 1);     for (int i = 0; i < ML; i++) a[i] = 1ll * a[i] * b[i] % P;     NTT(a, ML, -1);   }   int b[N];   void solve(int l, int r, int *res) {     if (l == r) {       res[0] = 1;       res[1] = b[l];       return;     }     int mid = (l + r) >> 1;     int n = (mid - l + 1), m = (r - mid + 1);     int ML = NTTinit(n, m);     int L[ML], R[ML];     memset(L, 0, sizeof(L));     memset(R, 0, sizeof(R));     solve(l, mid, L);     solve(mid + 1, r, R);     NTTX(L, n, R, m);     for (int i = 0; i <= r - l + 1; i++) res[i] = L[i];   }   int a[N], C[N];   int main() {     int n = read(), k = read();     for (int i = 1; i <= n; i++) a[i] = read();     int Q = read();     while (Q--) {       int op = read();       memset(C, 0, sizeof(C));       if (op == 1) {         int q = read(), ii = read(), d = read();         for (int i = 1; i <= n; i++)           b[i] = (q - (i == ii ? d : a[i]) + mod) % mod;       } else {         int q = read(), l = read(), r = read(), d = read();         for (int i = 1; i <= n; i++)           b[i] = (q - ((i <= r && i >= l) ? (d + a[i]) : a[i]) + mod) % mod;       }       solve(1, n, C);       printf( %d n , C[k]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d, m;     cin >> n >> d >> m;     long long ans = 0;     long long a[n];     vector<long long> big, small;     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) {       if (a[i] > m)         big.push_back(a[i]);       else         small.push_back(a[i]);     }     sort(big.rbegin(), big.rend());     sort(small.rbegin(), small.rend());     long long p = big.size(), q = small.size();     for (long long i = 1; i < p; i++) big[i] += big[i - 1];     for (long long i = 1; i < q; i++) small[i] += small[i - 1];     if (q > 0) ans = small[q - 1];     for (long long i = 0; i < p; i++) {       if (i * (d + 1) + 1 <= n) {         ans = max(ans, big[i]);         long long rem = n - (i * (d + 1) + 1);         long long ind = -1;         if (q > 0 and rem > 0) {           ind = max(0LL, min(rem - 1LL, q - 1));           ans = max(ans, big[i] + small[ind]);         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using D = double;   using uint = unsigned int;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1000000007;   inline int sum(int a, int b, int mod = MOD) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline int sub(int a, int b, int mod = MOD) {     a -= b;     if (a < 0) a += mod;     return a;   }   inline int mul(int a, int b, int mod = MOD) { return ((long long)a * b) % mod; }   inline int powmod(int a, int b, int mod = MOD) {     int tmp = a;     int ans = 1;     while (b) {       if (b & 1) ans = mul(ans, tmp, mod);       tmp = mul(tmp, tmp, mod);       b >>= 1;     }     return ans;   }   inline int inv(int a, int mod = MOD) { return powmod(a, mod - 2, mod); }   const int maxn = 5000006;   int sm[maxn];   int ans[maxn];   int t, l, r;   int main() {     scanf( %d%d%d , &t, &l, &r);     for (int i = 1; i < maxn; i++) sm[i] = -1;     for (int i = 2; i < maxn; i++) {       for (int j = i; j < maxn; j += i)         if (sm[j] == -1) {           sm[j] = i;         }     }     ans[1] = 0;     for (int i = 2; i < maxn; i++) {       int d = sm[i];       int g = i / d;       ans[i] = sum(ans[i / d], mul(g, ((ll)d * (d - 1) / 2) % MOD));     }     int ml = 1;     int answer = 0;     for (int i = l; i <= r; i++) {       answer = sum(answer, mul(ml, ans[i]));       ml = mul(ml, t);     }     printf( %d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   using vi = vector<ll>;   using vvi = vector<vi>;   using vb = vector<bool>;   using ii = pair<ll, ll>;   constexpr bool LOG = false;   void Log() {     if (LOG) cerr <<   n ;   }   template <class T, class... S>   void Log(T t, S... s) {     if (LOG) cerr << t <<   t , Log(s...);   }   ll SIZE;   vector<bool> bs;   vector<ll> primes, mf;   void sieve(ll size = 3e5) {     SIZE = size;     bs.assign(SIZE + 1, 1);     bs[0] = bs[1] = 0;     for (ll i = 2; i <= SIZE; i++)       if (bs[i]) {         for (ll j = i * i; j <= SIZE; j += i) bs[j] = 0;         primes.push_back(i);       }   }   bool is_prime(ll n) {     if (n <= SIZE) return bs[n];     for (const auto &prime : primes)       if (n % prime == 0) return false;     return true;   }   struct Factor {     ll p;     ll exp;   };   using FS = vector<Factor>;   FS factor(ll n) {     FS fs;     for (const auto &p : primes) {       ll exp = 0;       if (n == 1 || p * p > n) break;       while (n % p == 0) n /= p, exp++;       if (exp > 0) fs.push_back({p, exp});     }     if (n != 1) fs.push_back({n, 1});     return fs;   }   vector<ll> divisors(const FS &fs) {     vector<ll> ds{1};     ll s = 1;     for (auto &f : fs) s *= f.exp + 1;     ds.reserve(s);     for (auto f : fs)       for (auto d : ds)         for (ll i = 0; i < f.exp; ++i) ds.push_back(d *= f.p);     return ds;   }   ll n;   using T = ll;   struct FenwickTree {     int n;     vector<T> tree;     FenwickTree(int n) : n(n) { tree.assign(n + 1, 0); }     T query(int l, int r) { return query(r) - query(l - 1); }     T query(int r) {       T s = 0;       for (; r > 0; r -= (r & (-r))) s += tree[r];       return s;     }     void update(int i, T v) {       Log( FT update , i, v);       for (; i <= n; i += (i & (-i))) tree[i] += v;     }   };   struct S {     FenwickTree ft;     map<ll, ll> m;     S(ll n, vi &init) : ft(n) {       Log( init , n);       m[0] = 0;       m[n] = 1e9;       for (ll i = 0; i < n; ++i) update(i, init[i]);       Log( done init );     }     void update(ll i, ll u) {       Log( update , i, u);       auto it = m.lower_bound(i + 1);       auto p = prev(it);       if (u <= p->second) {         Log( return; no increment );         return;       }       Log( shrink , p->first + 1,  remove , (it->first - i) * p->second);       ft.update(p->first + 1, (i - it->first) * p->second);       while (it->second <= u) {         auto nxt = next(it);         if (nxt == m.end()) break;         ft.update(it->first + 1, -(nxt->first - it->first) * it->second);         it = m.erase(it);       }       m[i] = u;       ft.update(i + 1, (it->first - i) * u);       Log( done update );       Log( Map: );     }     ll query(ll i) {       Log( query , i);       auto it = prev(m.lower_bound(i + 1));       ll part = (i - it->first + 1) * it->second;       ll c = ft.query(1, it->first);       Log( query ans: , c, part, c + part);       return c + part;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     sieve();     cin >> n;     vi v(n);     for (auto &x : v) cin >> x;     vi init(n);     vi count(200001, 0);     vi first(200001, -1);     ll best = 0;     for (ll i = 0; i < n; ++i) {       ll x = v[i];       for (auto div : divisors(factor(x))) {         if (first[div] < 0) first[div] = i;         ++count[div];         if (count[div] >= 2) best = max(best, div);       }       init[i] = best;       Log( init: , i, init[i]);     }     S s(n, init);     ll ans = 0;     ans += s.query(n - 2);     Log(  t t t t t t0..n-2 , ans);     s.update(0, 1);     count.assign(200001, 0);     best = 0;     for (ll i = n - 1; i >= 1; --i) {       Log( suffix from  , i);       ll x = v[i];       for (auto div : divisors(factor(x))) {         ++count[div];         if (count[div] >= 2) {           best = max(best, div);         }         if (first[div] >= 0) s.update(first[div], div);       }       ans += best;       s.update(0, best);       Log(  t t t t t , i,  ..n-1 , best);       if (i - 2 >= 0) {         ll a = s.query(i - 2);         Log(  t t t t tprefix ,  0.. , i - 2, a);         ans += a;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 1e6 + 10;   string s[SIZE];   int row[SIZE], col[SIZE];   int main() {     int ___T;     scanf( %d , &___T);     for (int cs = 1; cs <= ___T; cs++) {       int n, m;       R(n, m);       for (int i = 0; i < (n); ++i) row[i] = 0;       for (int i = 0; i < (m); ++i) col[i] = 0;       for (int i = 0; i < (n); ++i) {         R(s[i]);         for (int j = 0; j < (m); ++j)           if (s[i][j] ==  * ) row[i]++, col[j]++;       }       int an = n + m;       for (int i = 0; i < (n); ++i)         for (int j = 0; j < (m); ++j) {           int me = row[i] + col[j] - (s[i][j] ==  * );           an = min(an, n + m - 1 - me);         }       W(an);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long d1, d2, d3;     cin >> d1 >> d2 >> d3;     long long x1 = d1 + d2 + d3;     long long x2 = d1 + d1 + d2 + d2;     long long x3 = d1 + d1 + d3 + d3;     long long x4 = d2 + d2 + d3 + d3;     x1 = min(x1, min(x2, min(x3, x4)));     cout << x1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e3 + 7;   const int mod = 1e9 + 7;   const int INF = 1e9 + 7;   const int maxl = 20;   const int SQ = 70;   int n;   int a[maxn], ps[maxn];   int dp[maxn][SQ][SQ];   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(), cout.tie();     ;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i];     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < SQ; j++) {         for (int k = 1; k < SQ; k++) {           int l = i;           int r = n - i - j;           if (l >= r) break;           dp[i][j][k] = -INF;           for (int Amove : {k, k + 1}) {             if (r - l >= Amove) {               int p1 = 0, p2 = 0;               for (int Bmove : {Amove, Amove + 1}) {                 if (l + Amove <= r - Bmove)                   p1 = dp[l + Amove][n - l - Amove - r + Bmove][Bmove] +                        ps[l + Amove] - ps[l] - ps[r] + ps[r - Bmove];                 else                   p1 = +INF;                 swap(p1, p2);               }               dp[i][j][k] = max(                   dp[i][j][k],                   (min(p1, p2) == +INF ? ps[l + Amove] - ps[l] : min(p1, p2)));             }           }           dp[i][j][k] = (dp[i][j][k] != -INF ? dp[i][j][k] : 0);         }       }     }     cout << dp[0][0][1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)(1e6 + 7);   const long long oo = (long long)(1e18);   const double esp = (double)1e-6;   const long long MOD = (long long)(1e9 + 7);   int n, x, y, fre[MAXN];   vector<int> adj[MAXN];   void dfs(int u, int t) {     if (u == t) return;     fre[u] = 0;     for (int i = 0; i < (int)adj[u].size(); i++) {       int v = adj[u][i];       if (fre[v]) {         dfs(v, t);       }     }   }   int main() {     while (cin >> n >> x >> y) {       for (int i = 1; i <= n; i++) adj[i].clear();       int a, b;       for (int i = 0; i < n - 1; i++) {         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       long long res = 1LL * n * (n - 1) / 2;       for (int i = 1; i <= n; i++) fre[i] = 1;       dfs(x, y);       long long cnt2 = 0, cnt1 = 0;       for (int i = 1; i <= n; i++) {         if (fre[i]) {           ++cnt1;         }         fre[i] = 1;       }       dfs(y, x);       for (int i = 1; i <= n; i++) {         if (fre[i]) {           ++cnt2;         }         fre[i] = 1;       }       long long z = cnt2 * cnt1;       cout << res + res - z << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0;     long long t = 0;     string s, s2;     cin >> s >> s2;     int n = s2.size() - s.size();     for (int i = 0; i < n; i++) {       c += s2[i] -  0 ;     }     for (int i = 0; i < s.size(); i++) {       c += s2[i + n] -  0 ;       if (i) c -= s2[i - 1] -  0 ;       if (s[i] ==  0 )         t += c;       else         t += n - c + 1;     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx,tune=native )   using namespace std;   bitset<300000013> unprime;   int main() {     if (fopen( FILENAME.in ,  r )) {       freopen( FILENAME.in ,  r , stdin);       freopen( FILENAME.out ,  w , stdout);     }     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long l, r;     cin >> l >> r;     unprime[0] = 1;     unprime[1] = 1;     for (int i = 2; i <= r; i++) {       if (unprime[i]) continue;       if (i < 20000) {         for (int j = i * i; j <= r; j += i) {           unprime[j] = 1;         }       }     }     int answer = (l <= 2 && 2 <= r ? 1 : 0);     int temp = l % 4;     for (int i = l; i <= r; i++) {       if (!unprime[i] && temp == 1) answer++;       temp++;       if (temp == 4) temp = 0;     }     cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     if (n == 1) {       puts( white );       cout << 1 <<     << 2 << endl;       return 0;     }     if (n & 1) {       puts( black );       return 0;     }     puts( white );     cout << 1 <<     << 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   long long dp[N][5];   long long DP[N];   int head[N], nex[N * 2], to[N * 2], tot = 0;   int n, k;   long long ans = 0;   void add(int u, int v) {     to[++tot] = v;     nex[tot] = head[u];     head[u] = tot;   }   void dfs(int u, int fa, int d) {     DP[u] = dp[u][d % k] = 1;     for (int i = head[u]; i > 0; i = nex[i]) {       int v = to[i];       if (v == fa) continue;       dfs(v, u, d + 1);       for (int j = 0; j < k; j++) {         for (int l = 0; l < k; l++) {           ans += (k - (j - d + l - d) % k) % k * dp[u][j] * dp[v][l];         }       }       for (int i = 0; i < k; i++) dp[u][i] += dp[v][i];       ans += ((long long)n - DP[v]) * DP[v];       DP[u] += DP[v];     }   }   int main() {     while (~scanf( %d%d , &n, &k)) {       memset(head, 0, sizeof(head));       memset(dp, 0, sizeof(dp));       memset(DP, 0, sizeof(DP));       tot = 0;       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d%d , &u, &v);         add(u, v);         add(v, u);       }       ans = 0;       dfs(1, 0, 0);       printf( %lld n , ans / k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353, MAXn = 2e5 + 2;   long long arr[MAXn];   long long qp(long long a, long long e) {     if (e == 0) return 1;     if (e == 1) return a;     if (!(e & 1)) {       a = qp(a, e / 2);       return a * a % MOD;     }     return a * qp(a, e - 1) % MOD;   }   long long r[MAXn];   long long p[MAXn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, A;     cin >> n >> m >> A;     r[0] = p[0] = 1;     for (int i = 1; i <= m; i++) {       long long b;       cin >> b;       p[i] = (p[i - 1] + (r[i - 1] * qp(qp(A, b), MOD - 2) % MOD)) % MOD;       r[i] = (r[i - 1] + (p[i - 1] * qp(A, b) % MOD)) % MOD;     }     cout << (p[m] * qp(A, n) % MOD * qp(qp(2, m), MOD - 2) % MOD);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace SHENZHEBEI {   inline char gc() { return getchar(); }   inline long long read() {     long long x = 0, f = 1;     char ch = gc();     for (; !isdigit(ch); ch = gc())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;     return x * f;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   inline char readchar() {     char ch = gc();     for (; isspace(ch); ch = gc())       ;     return ch;   }   inline long long readstr(char *s) {     char ch = gc();     int cur = 0;     for (; isspace(ch); ch = gc())       ;     for (; !isspace(ch); ch = gc()) s[cur++] = ch;     s[cur] =   0 ;     return cur;   }   inline void writeln(long long x) {     write(x);     puts(  );   }   inline double getreal() {     static double lbc;     scanf( %lf , &lbc);     return lbc;   }   }  // namespace SHENZHEBEI   using namespace SHENZHEBEI;   const long long mod = 1e9 + 7, N = 200010;   map<long long, long long> g;   vector<long long> a[1010];   long long ans, n, m, vis[1010], SIZE[1010];   long long id(long long x) {     if (g.find(x) == g.end()) {       long long u = g.size();       g[x] = u;     }     return g[x];   }   void gao(long long x) {     for (; x; x >>= 1) id(x);   }   long long Size(long long x) {     long long L = x, R = x, ans = 0;     for (; L <= n; L = L << 1, R = R << 1 | 1)       ans += ((n) < (R) ? (n) : (R)) - L + 1;     return ans;   }   void dfs(long long x, long long bb) {     vis[x] = 1;     (ans = (ans + (bb * SIZE[x])) % mod);     for (long long i : a[x])       if (!vis[i]) dfs(i, bb);     vis[x] = 0;   }   int main() {     n = read(), m = read();     for (long long i = 1; i <= m; ++i) {       long long x = read(), y = read();       gao(x), gao(y);       a[g[x]].push_back(g[y]);       a[g[y]].push_back(g[x]);     }     gao(1);     for (pair<long long, long long> I : g) {       SIZE[I.second] = Size(I.first);       if (g.count(I.first * 2)) SIZE[I.second] -= Size(I.first * 2);       if (g.count(I.first * 2 + 1)) SIZE[I.second] -= Size(I.first * 2 + 1);       if (I.first > 1)         a[g[I.first / 2]].push_back(g[I.first]),             a[g[I.first]].push_back(g[I.first / 2]);     }     for (long long i = 0; i < g.size(); ++i) dfs(i, SIZE[i]);     writeln(ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> (t);     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a[n + 2];       memset(a, -1, sizeof a);       bool ok = false;       for (long long int i = 0; i < n; ++i) {         cin >> a[i];         if (a[i] == k) ok = true;       }       if (n == 1 && ok) {         cout <<  yes               <<   n ;         continue;       }       if (!ok) {         cout <<  no                <<   n ;         continue;       }       ok = false;       for (long long int i = 0; i < n; i++) {         if ((a[i] >= k && a[i + 1] >= k) || (a[i] >= k && a[i + 2] >= k))           ok = true;       }       if (ok)         cout <<  yes               <<   n ;       else         cout <<  no               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   const int memsize = 20000;   struct Node {     char val;     int kill = 0;     Node *failed = NULL;     Node *pre = NULL;     vector<Node *> child;     Node() {}     Node(char _val, Node *_pre) : val(_val), pre(_pre) {}     int find_char(char c) {       int i = 0;       for (auto it = child.begin(); it != child.end(); it++) {         if ((*it)->val == c) break;         i++;       }       return i;     }   };   Node mem[memsize];   Node *root = mem;   Node *pmem = mem;   void str_insert(char *s) {     int lenS = strlen(s);     Node *cur = root;     for (int i = 0; i < lenS; i++) {       char c = s[i];       if (cur->find_char(c) == cur->child.size()) {         Node *a = new (++pmem) Node(s[i], cur);         if (i == lenS - 1) a->kill = lenS;         (cur->child).push_back(a);         cur = a;       } else {         cur = cur->child[cur->find_char(c)];         if (i == lenS - 1) cur->kill = lenS;       }     }   }   void build_fail() {     queue<Node *> que;     que.push(root);     root->failed = root;     while (!que.empty()) {       Node *cur = que.front();       que.pop();       for (auto it = cur->child.begin(); it != cur->child.end(); it++) {         Node *ptr = cur->failed;         char c = (*it)->val;         while (ptr != root && ptr->find_char(c) == ptr->child.size()) {           ptr = ptr->failed;         }         (*it)->failed = ptr;         if (ptr->find_char(c) != ptr->child.size()) {           (*it)->failed = ptr->child[ptr->find_char(c)];         }         if (cur == root) (*it)->failed = root;         if (cur->kill == 0) cur->kill = cur->failed->kill;         que.push(*it);       }     }   }   int change[N];   int cap[N];   void match(char *name) {     int lenN = strlen(name);     Node *cur = root;     for (int i = 0; i < lenN; i++) {       char c = name[i];       while (cur != root && cur->find_char(c) == cur->child.size()) {         cur = cur->failed;       }       if (cur->find_char(c) != cur->child.size()) {         cur = cur->child[cur->find_char(c)];       }       change[i] = cur->kill;     }   }   int main() {     int n;     scanf( %d , &n);     char s[N];     while (n--) {       scanf( %s , s);       for (int i = 0; i < strlen(s); i++) {         s[i] = tolower(s[i]);       }       str_insert(s);     }     build_fail();     char name[N];     scanf( %s , name);     memset(change, 0, sizeof(change));     memset(cap, 0, sizeof(change));     for (int i = 0; i < strlen(name); i++) {       if (name[i] == toupper(name[i])) cap[i] = 1;       name[i] = tolower(name[i]);     }     char letter;     scanf(  %c , &letter);     match(name);     int rc[N];     memset(rc, 0, sizeof(rc));     for (int i = 0; i < strlen(name); i++) {       int num = change[i];       while (num--) {         rc[i - num] = 1;       }     }     for (int i = 0; i < strlen(name); i++) {       if (rc[i] == 1) {         if (name[i] == letter) {           name[i] = (letter ==  a ) ?  b  :  a ;         } else {           name[i] = letter;         }       }     }     for (int i = 0; i < strlen(name); i++) {       if (cap[i] == 1) {         printf( %c , toupper(name[i]));       } else {         printf( %c , tolower(name[i]));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.length();     for (int i = 0; i < len; i = i + 1) {       if (s[i] !=  a  && s[i] !=  y  && s[i] !=  e  && s[i] !=  i  &&           s[i] !=  o  && s[i] !=  u  && s[i] !=  A  && s[i] !=  Y  &&           s[i] !=  E  && s[i] !=  I  && s[i] !=  O  && s[i] !=  U ) {         if (s[i] >=  A  && s[i] <=  Z ) {           s[i] = s[i] + 32;         }         cout <<  .  << s[i];       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NIL = -1;   template <class T>   inline T mx(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T mi(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline void sw(T &a, T &b) {     T t = a;     a = b;     b = t;   }   template <class T>   inline T mabs(T x) {     return x < 0 ? -x : x;   }   inline char gc() {     char ret;     while ((ret = getchar()) ==     || ret ==   n  || ret ==   t )       ;     return ret;   }   template <class T>   inline T sq(T x) {     return x * x;   }   const int LIM = 1e5 + 10;   long long n, m, seed, vmax;   map<long long, long long> ct;   inline map<long long, long long>::iterator split(long long p) {     map<long long, long long>::iterator ret = --ct.upper_bound(p);     if (ret->first != p) ct[p] = ret->second, ret++;     return ret;   }   inline void add(long long l, long long r, long long diff) {     map<long long, long long>::iterator s = split(l), e = split(r + 1);     while (s != e) (s++)->second += diff;   }   inline void assign(long long l, long long r, long long x) {     map<long long, long long>::iterator s = split(l), e = split(r + 1);     while (s != e) ct.erase(s++);     ct[l] = x;   }   vector<pair<long long, long long> > buff;   inline long long kSmallest(long long l, long long r, long long k) {     map<long long, long long>::iterator s = split(l), e = split(r + 1);     buff.clear();     while (s != e) {       r = (e--)->first;       buff.push_back(make_pair(e->second, r - e->first));     }     sort(buff.begin(), buff.end());     for (int i = 0; i < buff.size(); i++)       if ((k -= buff[i].second) <= 0) return buff[i].first;     return -1;   }   inline long long fp(long long base, long long p, long long mod) {     long long ret = 1;     base %= mod;     do {       if (p & 1) ret = ret * base % mod;       base = base * base % mod;     } while (p >>= 1);     return ret;   }   inline long long powSum(long long l, long long r, long long p, long long mod) {     map<long long, long long>::iterator s = split(l), e = split(r + 1);     long long ret = 0;     while (s != e) {       r = (e--)->first;       ret = (ret + (r - e->first) * fp(e->second, p, mod)) % mod;     }     return ret % mod;   }   inline long long rnd() {     long long ret = seed;     seed = (seed * 7 + 13) % 1000000007;     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> m >> seed >> vmax;     long long x, y;     for (int i = 1; i <= n; i++) ct[i] = (rnd() % vmax) + 1;     for (int i = 1; i <= m; i++) {       long long op = (rnd() % 4) + 1;       long long l = (rnd() % n) + 1;       long long r = (rnd() % n) + 1;       if (l > r) sw(l, r);       if (op == 3)         x = (rnd() % (r - l + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (op == 4) y = (rnd() % vmax) + 1;       switch (op) {         case 1:           add(l, r, x);           break;         case 2:           assign(l, r, x);           break;         case 3:           cout << kSmallest(l, r, x) <<   n ;           break;         case 4:           cout << powSum(l, r, x, y) <<   n ;           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int mod = 1e9 + 7;   int sub[N][N][N];   int pref[N][N];   int suff[N][N];   int ans[N];   int pw[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, X;     cin >> n >> X;     string s;     cin >> s;     s =  &  + s;     for (int i = 1; i <= n; i++) {       if (s[i] ==  0 )         sub[0][i][i] = 1;       else         sub[1][i][i] = 1;     }     if (s[1] ==  0 )       pref[0][1] = 1;     else       pref[1][1] = 1;     if (s[n] ==  0 )       suff[0][n] = 1;     else       suff[1][n] = 1;     pw[0] = pw[1] = 2;     if (s ==  &0 ) ans[0] = 1;     if (s ==  &1 ) ans[1] = 1;     for (int i = 2; i <= X; i++) {       pw[i] = 1ll * pw[i - 1] * pw[i - 2] % mod;       for (int l = 1; l <= n; l++) {         for (int r = l; r <= n; r++) {           sub[i][l][r] = (sub[i - 1][l][r] + sub[i - 2][l][r]) % mod;           for (int m = l; m < r; m++) {             sub[i][l][r] += 1ll * sub[i - 1][l][m] * sub[i - 2][m + 1][r] % mod;             sub[i][l][r] %= mod;           }         }       }       for (int l = 1; l <= n; l++) {         pref[i][l] = pref[i - 1][l];         pref[i][l] += 1ll * pref[i - 2][l] * pw[i - 1] % mod;         pref[i][l] %= mod;         for (int x = 1; x < l; x++) {           pref[i][l] += 1ll * pref[i - 1][x] * sub[i - 2][x + 1][l] % mod;           pref[i][l] %= mod;         }       }       for (int r = 1; r <= n; r++) {         suff[i][r] = suff[i - 2][r];         suff[i][r] += 1ll * suff[i - 1][r] * pw[i - 2] % mod;         suff[i][r] %= mod;         for (int x = r; x < n; x++) {           suff[i][r] += 1ll * suff[i - 2][x + 1] * sub[i - 1][r][x] % mod;           suff[i][r] %= mod;         }       }       for (int m = 1; m < n; m++) {         ans[i] += 1ll * pref[i - 1][m] * suff[i - 2][m + 1] % mod;         ans[i] %= mod;       }       ans[i] += 1ll * ans[i - 1] * pw[i - 2] % mod;       ans[i] %= mod;       ans[i] += 1ll * ans[i - 2] * pw[i - 1] % mod;       ans[i] %= mod;     }     cout << ans[X] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int memo[2700][2700];   string S;   int N;   int doit(int lo, int hi) {     if (lo == hi) {       return 1;     }     if (lo > hi) {       return 0;     }     int &ret = memo[lo][hi];     if (ret != -1) return ret;     ret = 0;     if (S[lo] == S[hi]) {       ret = max(ret, doit(lo + 1, hi - 1) + 2);     }     ret = max(ret, doit(lo + 1, hi));     ret = max(ret, doit(lo, hi - 1));     return ret;   }   string prefixStr, suffixStr, middleStr;   void doitG(int lo, int hi) {     if (lo == hi) {       middleStr += S[lo];       return;     }     if (lo > hi) return;     if (S[lo] == S[hi]) {       prefixStr += S[lo];       suffixStr += S[lo];       doitG(lo + 1, hi - 1);     } else {       if (doit(lo + 1, hi) > doit(lo, hi - 1)) {         doitG(lo + 1, hi);       } else {         doitG(lo, hi - 1);       }     }   }   int main() {     cin >> S;     N = S.size();     if (N > 2600) {       for (char c =  a ; c <=  z ; c++) {         int cnt = 0;         for (int i = 0; i < S.size(); i++) {           if (S[i] == c) {             cnt++;           }         }         if (cnt >= 100) {           for (int i = 0; i < 100; i++) cout << c;           cout << endl;           return 0;         }       }       assert(0);     } else {       memset(memo, -1, sizeof(memo));       int ret = doit(0, N - 1);       prefixStr = suffixStr = middleStr =   ;       doitG(0, N - 1);       reverse(suffixStr.begin(), suffixStr.end());       string res =   ;       for (int i = 0; i < prefixStr.size(); i++) res += prefixStr[i];       for (int i = 0; i < middleStr.size(); i++) res += middleStr[i];       for (int i = 0; i < suffixStr.size(); i++) res += suffixStr[i];       if (res.size() < 100) {         int n = res.size();         cout << res << endl;       } else {         if (res.size() == 100) {           cout << res << endl;         } else {           int n = res.size();           for (int i = 0; i < 50; i++) cout << res[i];           for (int j = n - 50; j < n; j++) cout << res[j];           cout << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int> > sort_positions;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       sort_positions.push_back(make_pair(a[i], i));     }     sort(a, a + n);     sort(sort_positions.begin(), sort_positions.end());     set<vector<int> > subsets;     for (int i = 0; i < n; i++) {       bool isempty = true;       vector<int> next_subset;       for (int j = 0; j < i; j++)         if (a[j] > i) {           next_subset.push_back(1);           isempty = false;         } else           next_subset.push_back(0);       int next_num = min(a[i], i + 1);       set<vector<int> > next_subsets;       if (isempty) {         next_subset.push_back(1);         next_subsets.insert(next_subset);         next_num--;         for (set<vector<int> >::iterator it = subsets.begin();              it != subsets.end(); it++) {           vector<int> subset(*it);           if (next_num > 0)             subset.push_back(1);           else             subset.push_back(0);           next_subsets.insert(subset);           next_num--;         }       } else {         for (set<vector<int> >::iterator it = subsets.begin();              it != subsets.end(); it++) {           vector<int> subset(*it);           if (next_num > 0)             subset.push_back(1);           else             subset.push_back(0);           next_subsets.insert(subset);           next_num--;         }         next_subset.push_back(0);         next_subsets.insert(next_subset);         if (next_num == 1) {           vector<int> subset(i, 0);           subset.push_back(1);           next_subsets.insert(subset);         }       }       subsets = next_subsets;     }     vector<int> ox[n];     for (int i = 0; i < sort_positions.size(); i++) {       int idx = sort_positions[i].second;       ox[idx].resize(0);       for (set<vector<int> >::iterator it = subsets.begin(); it != subsets.end();            it++)         ox[idx].push_back((*it)[i]);     }     cout << subsets.size() << endl;     for (int i = 0; i < subsets.size(); i++) {       for (int j = 0; j < n; j++) cout << ox[j][i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   int n, m;   char a[1010][1010];   int d1[1010][1010], d2[1010][1010], d3[1010][1010];   vector<pair<int, int> > s1, s2, s3;   int ans = 0x3f3f3f3f;   int ax, ay;   void bfs(int d[1010][1010], char id) {     queue<pair<int, int> > qq;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] == id) d[i][j] = 0, qq.push(make_pair(i, j));     while (!qq.empty()) {       pair<int, int> from = qq.front();       int x = from.first, y = from.second;       qq.pop();       for (int i = 0; i < 4; i++) {         int tx = x + dx[i], ty = y + dy[i];         int dis = d[x][y] + (a[tx][ty] ==  . );         if ((d[tx][ty] != 0x3f3f3f3f && d[tx][ty] <= dis) || a[tx][ty] ==  # )           continue;         d[tx][ty] = dis;         qq.push(make_pair(tx, ty));       }     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 0; i <= n + 1; i++) a[i][0] = a[i][m + 1] =  # ;     for (int j = 1; j <= m; j++) a[0][j] = a[n + 1][j] =  # ;     memset(d1, 0x3f, sizeof(d1));     memset(d2, 0x3f, sizeof(d2));     memset(d3, 0x3f, sizeof(d3));     bfs(d1,  1 );     bfs(d2,  2 );     bfs(d3,  3 );     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (d1[i][j] != 0x3f3f3f3f && d2[i][j] != 0x3f3f3f3f &&             d3[i][j] != 0x3f3f3f3f) {           int calc;           if (a[i][j] ==  . ) {             calc = d1[i][j] + d2[i][j] + d3[i][j] - 2;             if (ans > calc) ans = calc, ax = i, ay = j;           } else if (isdigit(a[i][j])) {             calc = d1[i][j] + d2[i][j] + d3[i][j];             if (ans > calc) ans = calc, ax = i, ay = j;           }         }     cout << (ans == 0x3f3f3f3f ? -1 : ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 1000010;   int n, cnt[N], ans, val[N];   long long a[N];   template <typename T>   void gi(T &x) {     x = 0;     register char c = getchar(), pre = 0;     for (; c <  0  || c >  9 ; pre = c, c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10ll + (c ^ 48);     if (pre ==  - ) x = -x;   }   int main() {     gi(n);     for (int i = (1); i <= (n); i++) {       gi(a[i]);       long long t = a[i];       int w = 0;       for (; t % 2 == 0; t /= 2, ++w)         ;       ++cnt[w], val[i] = w;     }     for (int i = (1); i <= (70); i++)       if (cnt[i] > cnt[ans]) ans = i;     printf( %d n , n - cnt[ans]);     for (int i = (1); i <= (n); i++)       if (val[i] != ans) printf( %lld  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7, mod = 1e9 + 7, inf = 1e9 + 7;   const long long linf = (long long)1e18 + 7;   const long double eps = 1e-15, pi = 3.141592;   const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1},             dy[] = {0, 1, 0, -1, 1, -1, 1, -1};   int n, sz;   long long ans;   long long a[N], suff[N];   int t[N * 20][2];   inline void add(long long x) {     int v = 0;     for (int i = 40; i >= 0; --i) {       int type = ((x & (1LL << i)) > 0);       if (!t[v][type]) t[v][type] = ++sz;       v = t[v][type];     }   }   inline long long get(long long x) {     int v = 0;     long long res = 0;     for (int i = 40; i >= 0; --i) {       int type = 1 - ((x & (1LL << i)) > 0);       if (t[v][type])         res += 1LL << i, v = t[v][type];       else         v = t[v][1 - type];     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);     for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] ^ a[i];     long long pref = 0;     add(0);     for (int i = 1; i <= n + 1; ++i) {       ans = max(ans, get(suff[i]));       add(pref ^= a[i]);     }     cout << ans;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, sum, t;   int main() {     scanf( %I64d%I64d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %I64d , &t);       sum += t;       if (t && sum >= m) {         printf( %I64d  , sum / m);         sum %= m;       } else         printf( 0  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int s[maxn];   priority_queue<int, vector<int>, greater<int> > que;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);       que.push(s[i]);     }     sort(s, s + n);     int ans = 0;     for (int i = 0; i < n; i++) {       while (!que.empty() && que.top() <= s[i]) {         que.pop();       }       if (que.empty()) break;       if (que.top() > s[i]) {         ans++;         que.pop();       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, bool> childL, childR;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     int n, a;     cin >> n;     cin >> a;     multiset<int> mulset;     mulset.insert(a);     for (int i = 1; i < n; i++) {       cin >> a;       auto ite = mulset.lower_bound(a);       if (childL[*ite] || ite == mulset.end()) {         ite--;         childR[*ite] = 1;       } else         childL[*ite] = 1;       if (i > 1) cout <<    ;       cout << *ite;       mulset.insert(a);     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   int pow3[10];   int main() {     pow3[0] = 1;     pow3[1] = 3;     pow3[2] = pow3[1] * 3;     pow3[3] = pow3[2] * 3;     pow3[4] = pow3[3] * 3;     pow3[5] = pow3[4] * 3;     pow3[6] = pow3[5] * 3;     map<char, int> myMap;     char c;     long long n, k = 0, cnt = 0, res = 1;     for (int i = 48; i <= 57; i++) {       c = i;       myMap.insert(make_pair(c, k));       k++;     }     for (int i = 65; i <= 90; i++) {       c = i;       myMap.insert(make_pair(c, k));       k++;     }     for (int i = 97; i <= 122; i++) {       c = i;       myMap.insert(make_pair(c, k));       k++;     }     myMap.insert(make_pair( - , 62));     k++;     myMap.insert(make_pair( _ , 63));     k++;     while (cin >> c) {       n = myMap[c];       cnt = 0;       for (int i = 0; i < 6; i++) {         if (n % 2 == 0) cnt++;         n /= 2;       }       res = ((res % p) * pow3[cnt]) % p;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 1e6 + 5;   int a[maxm];   int n;   struct BIT {     int c[maxm];     int lowbit(int i) { return i & -i; }     void add(int i, int t) {       while (i < maxm) {         c[i] += t, i += lowbit(i);       }     }     int ask(int i) {       int ans = 0;       while (i) {         ans += c[i], i -= lowbit(i);       }       return ans;     }   } T;   signed main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += i - T.ask(a[i]);       T.add(a[i], 1);     }     if (ans % 2 == 0) {       puts( Petr );     } else {       puts( Um_nik );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string str;     cin >> str;     int L = 0;     for (int l = n / 2; l >= 1; l--) {       if (str.substr(0, l) == str.substr(l, l)) {         L = l;         break;       }     }     if (L == 0)       cout << n;     else       cout << n - L + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       bool flag = false;       for (int i = 1; i <= n; i++) {         if (s[i - 1] ==  0 ) {           if (i <= n / 2) {             cout << i <<     << n <<     << i + 1 <<     << n << endl;             flag = true;             break;           } else {             cout << 1 <<     << i <<     << 1 <<     << i - 1 << endl;             flag = true;             break;           }         }       }       int sz = n / 2;       if (!flag)         cout << 1 <<     << 1 + sz - 1 <<     << n - sz + 1 <<     << n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int S = 320;   int a[N];   int dp[S + 1][N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int q, p, k;     cin >> q;     for (int j = 1; j <= S; j++) {       for (int i = n; i >= 1; i--) {         if (i + a[i] + j > n)           dp[j][i] = 1;         else           dp[j][i] = dp[j][i + a[i] + j] + 1;       }     }     for (int i = 0; i < q; i++) {       cin >> p >> k;       int cnt = 0;       if (k <= S)         cout << dp[k][p] << endl;       else {         while (p <= n) {           cnt++;           p += a[p] + k;         }         cout << cnt << endl;       }     }     return 0;   }