/*    * author: zhaoyiping    * time: 2021-06-04 23:08:02    */   #include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   // vector<int> g[MAXN];   long long a[MAXN];   long long c[MAXN];   int fa[MAXN][20];   int deep[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q >> a[0] >> c[0];     for (int i = 1; i <= q; i++) {       int op;       cin >> op;       if (op == 1) {         int p, aa, cc;         cin >> p >> aa >> cc;         a[i] = aa;         c[i] = cc;         fa[i][0] = p;         deep[i] = deep[p] + 1;         for (int j = 1; j < 20; j++) {           fa[i][j] = fa[fa[i][j - 1]][j - 1];         }       } else {         int v;         long long w;         cin >> v >> w;         int beg = v;         for (int i = 19; i >= 0; i--)           if (a[fa[beg][i]])             beg = fa[beg][i];         long long tt = 0;         long long ans = 0;         for (int i = deep[v] - deep[beg]; i >= 0; i--) {           int now = v;           for (int j = 0; j < 20; j++) {             if ((1 << j) & i)               now = fa[now][j];           }           if (a[now] >= w) {             tt += w;             ans += c[now] * w;             a[now] -= w;             w = 0;             break;           } else {             tt += a[now];             ans += c[now] * a[now];             w -= a[now];             a[now] = 0;           }         }         cout << tt <<     << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string toBinary(long long n) {     string r;     while (n != 0) {       r = (n % 2 == 0 ?  0  :  1 ) + r;       n /= 2;     }     return r;   }   int main() {     int total;     cin >> total;     while (total--) {       string binaryNum;       long long num;       cin >> num;       binaryNum = toBinary(num);       long long length = binaryNum.length();       long long counter = 1;       long long ans = 0;       long long powers = 2;       long long value = 0;       ans = ans + num;       while (counter < length) {         value = num / powers;         ans = ans + value;         powers = powers * 2;         counter++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:667772160 )   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   string str;   int main() {     int n;     scanf( %d , &n);     getchar();     getline(cin, str);     int ans = 0, cont = 0;     for (int i = 0; i < n; i++) {       if (isalpha(str[i])) {         if (isupper(str[i])) cont++;       } else {         ans = max(ans, cont);         cont = 0;       }     }     ans = max(ans, cont);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int M = 1000005;   const int nmax = 500010;   const int MOD = (1e9) + 7;   int nextX[] = {1, -1, 0, 0};   int nextY[] = {0, 0, 1, -1};   int n, m, t;   int f[1010][1010];   char s[1010][1010];   bool good(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> t;     for (int i = 1; i <= n; i++) cin >> s[i] + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) f[i][j] = -1;     queue<pair<int, int> > que;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int nr = 0;         for (int k = 0; k < 4; k++) {           int x = i + nextX[k];           int y = j + nextY[k];           if (!good(x, y)) continue;           if (s[i][j] == s[x][y]) nr++;         }         if (nr > 0) {           que.push({i, j});           f[i][j] = 0;         }       }     while (!que.empty()) {       int x = que.front().first;       int y = que.front().second;       que.pop();       for (int k = 0; k < 4; k++) {         int nxt_x = x + nextX[k];         int nxt_y = y + nextY[k];         if (!good(nxt_x, nxt_y)) continue;         if (s[nxt_x][nxt_y] != s[x][y] && f[nxt_x][nxt_y] == -1) {           f[nxt_x][nxt_y] = f[x][y] + 1;           que.push({nxt_x, nxt_y});         }       }     }     for (int i = 1; i <= t; i++) {       int x, y;       long long int p;       cin >> x >> y >> p;       if (f[x][y] == -1 || p < f[x][y])         cout << s[x][y] <<   n ;       else {         long long int diff = p - f[x][y];         if (diff % 2 == 0)           cout << s[x][y] <<   n ;         else if (s[x][y] ==  1 )           cout <<  0 n ;         else           cout <<  1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c0, d0, hsl;   int a[15], b[15], c[15], d[15];   int dp[1005][15];   bool dpf[1005][15];   int proc(int x, int num) {     if (num == 0) {       return 0;     } else if (dpf[x][num]) {       return dp[x][num];     } else {       int &ret = dp[x][num];       ret = 0;       dpf[x][num] = true;       for (int i = 0; (i <= (a[num] / b[num])) && (x >= c[num] * i); i++) {         ret = max(ret, proc(x - c[num] * i, num - 1) + d[num] * i);       }       return ret;     }   }   int main() {     scanf( %d %d %d %d , &n, &m, &c0, &d0);     for (int i = 1; i <= m; i++) {       scanf( %d %d %d %d , &a[i], &b[i], &c[i], &d[i]);     }     hsl = 0;     for (int i = 0; i <= n; i++) {       hsl = max(hsl, proc(i, m) + ((n - i) / c0) * d0);     }     printf( %d n , hsl);   }


#include <bits/stdc++.h>   using namespace std;   long long l, w, k;   int main() {     cin >> l >> w >> k;     if (k > l + w - 2) {       cout << -1;       return 0;     }     if (k + 1 <= max(l, w)) {       long long e = max(l, w);       long long t = min(l, w);       long long j = (t / (k + 1)) * max(l, w);       long long u = (e / (k + 1)) * min(l, w);       if (j > u)         cout << j;       else         cout << u;     } else {       long long e = min(l, w);       cout << (e / (k + 2 - max(l, w)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T maxs(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T mins(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const int N = 1e6 + 5;   int a[N];   int p[N];   pair<int, int> rnk[N];   int root(int first) {     if (p[first] == first) return first;     return p[first] = root(p[first]);   }   int solve() {     int n;     cin >> n;     vector<int> v(n + 1), r(n + 1);     for (int i = 1; i < n + 1; i++) {       char c;       cin >> c;       if (c ==  ? )         v[i] = -1;       else         v[i] = c - 48;     }     int j1 = n + 1;     int j2 = n + 1;     for (int i = n; i > 0; i--) {       if (v[i] == 0) {         j1 = i;       } else if (v[i] == 1) {         j2 = i;       }       a[i] = max(j1, j2) - i;       rnk[i] = {a[i], i};     }     sort(rnk + 1, rnk + 1 + n);     for (int i = 1; i <= n + 1; i++) p[i] = i;     int j = 1;     for (int i = 1; i <= n; i++) {       while (j <= n && rnk[j].first < i) {         p[rnk[j].second] = rnk[j].second + 1;         j++;       }       int cnt = 0;       int l = 1;       while (1) {         int j = root(l);         if (j > n) break;         cnt++;         l = j + i;       }       cout << cnt <<    ;     }     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct e {     int a, b;   };   e p[100005];   int n, k;   bool use[100005];   priority_queue<int, vector<int>, std::greater<int> > Q;   bool criteriu(e a, e b) { return a.b > b.b; }   long long af;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].a);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].b);     }     sort(p + 1, p + n + 1, criteriu);     for (int i = 1; i <= n; i++) {       if (!use[p[i].a]) {         use[p[i].a] = true;       } else {         Q.push(p[i].b);       }     }     for (int i = 1; i <= k; i++) {       if (!use[i]) {         af += Q.top();         Q.pop();       }     }     printf( %lld n , af);     return 0;   }


#include <bits/stdc++.h>   long long n, m, Q;   long long T;   std::vector<long long> req, l, r;   std::vector<long long> fill(std::vector<long long>& req) {     std::vector<long long> ans(m + 1);     long long tem = T;     for (long long i = m; i; i--) {       ans[i] = 0;       if (i < m) ans[i] = ans[i + 1];       if (~req[i]) ans[i] = req[i];       tem -= ans[i];     }     if (tem < 0) return std::vector<long long>();     for (long long i = m, last = m + 1; tem && ~i; i--) {       if (~req[i]) {         long long mx = (i < m) ? (last - 1 - i) * (req[i] - ans[i + 1]) : 0;         if (mx <= tem) {           for (long long j = i + 1; j < last; j++) ans[j] = req[i];           tem -= mx;         } else {           for (long long j = i + 1; j < last; j++)             ans[j] +=                 (tem / (last - 1 - i)) + ((tem % (last - 1 - i)) >= (j - i));           tem = 0;         }         last = i;       }     }     if (tem) return std::vector<long long>();     return ans;   }   long long q[100001], h, t;   bool check(std::vector<long long> a, std::vector<long long> b) {     long long n = (long long)a.size() - 1, m = (long long)b.size() - 1;     h = t = 0;     for (long long i = 2; i <= n; i++) a[i] += a[i - 1];     for (long long i = 2; i <= m; i++) b[i] += b[i - 1];     for (long long i = 1; i <= n; i++) a[i] -= 1ll * i * m;     for (long long i = 1; i <= m; i++) b[i] -= 1ll * i * n;     for (long long i = 1; i <= m; i++) {       while (h < t - 1 && (1ll * (b[q[t]] - b[i]) * (q[t] - q[t - 1]) >=                            1ll * (b[q[t - 1]] - b[q[t]]) * (i - q[t])))         --t;       q[++t] = i;     }     for (long long i = 1; i <= n; i++) {       while (h < t - 1 && (b[q[t]] + q[t] * i) >= (b[q[t - 1]] + q[t - 1] * i))         --t;       if (b[q[t]] + q[t] * i < a[n] - a[i]) return 0;     }     return 1;   }   bool judge(long long x, long long y = -1) {     std::vector<long long> Req = req;     if (~y) {       for (long long i = 1; i <= x; i++) Req[i] = y;     }     std::vector<long long> now = fill(Req);     if (now.empty()) return 0;     if (now[1] != now[x]) {       for (long long i = 1; i <= x; i++)         if (~req[i] && req[i] != now[1]) return 0;       for (long long i = 1; i <= x; i++) Req[i] = now[1];       now = fill(Req);       if (now.empty()) return 0;     }     std::reverse(now.begin() + 1, now.end());     return check(l, now) & check(now, r);   }   signed main() {     scanf( %lld%lld , &n, &m);     l.resize(n + 1), r.resize(n + 1);     for (long long i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]);     std::sort(l.begin() + 1, l.end());     std::sort(r.begin() + 1, r.end());     req.resize(m + 1);     for (long long i = 1; i <= m; i++) req[i] = -1;     req[0] = 0x7f7f7f7f;     scanf( %lld , &Q);     for (long long i = 1, a, b; i <= Q; i++) {       scanf( %lld%lld , &a, &b);       req[a] = b;     }     scanf( %lld , &T);     long long l = 1, r = m, mid, ans = -1;     while (l <= r) {       mid = (l + r) >> 1;       if (judge(mid))         ans = mid, l = mid + 1;       else         r = mid - 1;     }     if (!~ans) {       printf( -1 -1 );       return 0;     }     for (long long i = 1; i <= ans; i++)       if (~req[i]) {         printf( %lld %lld n , ans, req[i]);         return 0;       }     l = fill(req)[1], r = n;     long long ans1;     while (l <= r) {       mid = (l + r) >> 1;       if (judge(ans, mid))         ans1 = mid, l = mid + 1;       else         r = mid - 1;     }     printf( %lld %lld n , ans, ans1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   const int MOD = 1e9 + 7;   long long a[maxn];   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       ans += a[i] * (n - a[i] + 1);       if (i == 1) continue;       long long t1 = a[i - 1], t2 = a[i];       if (t1 > t2) swap(t1, t2);       ans -= t1 * (n - t2 + 1);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000][1000];   int main(int argc, const char* argv[]) {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int r[1000];     int c[1000];     for (int i = 0; i < 1000; i++) {       r[i] = c[i] = i;     }     for (int i = 0; i < k; i++) {       char cc;       int x, y;       cin >> cc >> x >> y;       if (cc ==  c ) {         swap(c[x - 1], c[y - 1]);       } else if (cc ==  r ) {         swap(r[x - 1], r[y - 1]);       } else {         cout << a[r[x - 1]][c[y - 1]] << endl;         ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     long long cur = 9;     long long ans = 0;     long long dig = 1;     cin >> n;     while (n > 0) {       ans += min(n * dig, cur * dig);       n -= cur;       cur *= 10;       dig++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e3 + 10;   bool f[2][mx];   int nxt[mx], bef[mx];   int d[mx];   int main() {     int n, x, u;     scanf( %d %d , &n, &x);     memset(bef, -1, sizeof bef);     memset(nxt, -1, sizeof nxt);     for (int i = 1; i <= n; i++) {       scanf( %d , &u);       if (u != 0) {         nxt[i] = u;         bef[u] = i;       }     }     int lx = 0;     int c = 0;     for (int i = 1; i <= n; i++) {       if (bef[i] == -1) {         u = i;         int len = 0;         int lenx = 0;         while (u != -1) {           if (u == x || lenx > 0) lenx++;           len++;           u = nxt[u];         }         if (lenx == 0)           d[c++] = len;         else           lx = lenx;       }     }     int rw = 0;     f[0][0] = true;     for (int i = 0; i < c; i++) {       rw ^= 1;       for (int s = 0; s < mx; s++) {         f[rw][s] = f[rw ^ 1][s];         if (s >= d[i]) f[rw][s] |= f[rw ^ 1][s - d[i]];       }     }     vector<int> ans;     for (int s = 0; s < n; s++)       if (f[rw][s]) printf( %d n , s + lx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int L = 20;   int h[N], par[N][L];   int getLca(int u, int v) {     if (h[v] < h[u]) swap(u, v);     int k = h[v] - h[u];     for (int i = 0; i < L; i++)       if (k >> i & 1) v = par[v][i];     if (u == v) return v;     for (int i = L - 1; i >= 0; i--)       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     return par[u][0];   }   int dis(int u, int v) { return h[u] + h[v] - 2 * h[getLca(u, v)]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 5, mx = 2, ans = 2;     for (int i = 2; i <= 4; i++) h[i] = par[i][0] = 1;     int q;     cin >> q;     while (q--) {       int v;       cin >> v;       h[n] = h[v] + 1;       par[n][0] = v;       for (int i = 1; i < L; i++) par[n][i] = par[par[n][i - 1]][i - 1];       n++;       h[n] = h[v] + 1;       par[n][0] = v;       for (int i = 1; i < L; i++) par[n][i] = par[par[n][i - 1]][i - 1];       if (h[v] == h[mx]) mx = n, ans++;       ans = max(ans, dis(n, mx));       n++;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     string str;     cin >> t;     while (t--) {       cin >> str;       sort(str.begin(), str.end());       int sz = str.size();       if (str[0] == str[sz - 1])         cout << -1 << endl;       else         cout << str << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const long long INF = 1e15;   const int mod = 1e9 + 7;   const double Pi = acos(-1);   void Fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int n, cnt = 0;   long long x, y;   bool Deg[200005];   vector<int> Adj[200005];   void DFS(int node, int p = -1) {     int c = 0;     for (auto x : Adj[node]) {       if (x != p) {         DFS(x, node);         if (Deg[x]) {           c++;         }       }     }     cnt += min(2, c);     if (c < 2) {       Deg[node] = true;     }   }   signed main() {     Fastio();     cin >> n >> x >> y;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       Adj[u].emplace_back(v);       Adj[v].emplace_back(u);     }     if (x >= y) {       for (int i = 1; i <= n; i++) {         if (Adj[i].size() == n - 1) {           cout << y * (n - 2) + x;           return 0;         }       }       cout << y * (n - 1);       return 0;     }     DFS(1);     cout << x * cnt + y * (n - 1 - cnt);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   const long long INF = (long long)0x7fffffffffff;   long long dp[maxn][maxn][maxn], wi[maxn], c[maxn];   long long min(long long a, long long b) { return a > b ? b : a; }   int main() {     int n, m, k, temp, flag = 1, ans1 = 0;     cin >> n >> m >> k;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int l = 0; l <= n; l++) {           dp[i][j][l] = INF;         }       }     }     for (int i = 1; i <= n; i++) {       cin >> c[i];     }     for (int i = 1; i <= m; i++) cin >> wi[i];     if (c[1] == 0)       for (int i = 1; i <= m; i++) dp[1][i][1] = wi[i];     else       dp[1][c[1]][1] = 0;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> wi[j];         for (int l = 1; l <= i; l++) {           if (c[i] == 0) {             for (int p = 1; p <= m; p++) {               if (p == j) {                 dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j][l] + wi[j]);               } else {                 dp[i][j][l] = min(dp[i][j][l], dp[i - 1][p][l - 1] + wi[j]);               }             }           } else {             for (int p = 1; p <= m; p++) {               if (p == c[i]) {                 dp[i][c[i]][l] = min(dp[i][c[i]][l], dp[i - 1][c[i]][l]);               } else {                 dp[i][c[i]][l] = min(dp[i][c[i]][l], dp[i - 1][p][l - 1]);               }             }           }         }       }     }     long long ans = INF;     for (int i = 1; i <= m; i++) ans = min(ans, dp[n][i][k]);     if (ans >= INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e3 + 5;   const int mod = 998244353;   inline void add_mod(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   inline void chk_mod(int &a) {     if (a < 0) a += mod;   }   inline long long pw(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long pw2[MAXN], icoef[MAXN];   int n, c;   int a[MAXN];   namespace Subtask1 {   int sum[MAXN][MAXN], f[MAXN][MAXN], g[MAXN][MAXN];   void solve(void) {     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= c; ++j) sum[i][j] = sum[i - 1][j];       ++sum[i][a[i]];     }     for (int i = 1; i <= n; ++i) {       if (c == 1) {         f[i][i] = 1;         continue;       }       static int t[MAXN];       for (int j = 1; j <= c; ++j) t[j] = 0;       int cnt = 0, cur = 1;       for (int j = i; j <= n; ++j) {         int ct = ++t[a[j]];         if (ct == 1) {           ++cnt;           if (cnt == c) {             for (int k = 1; k <= c; ++k)               if (k != a[i]) cur = cur * (pw2[t[k]] - 1) % mod;             chk_mod(cur);           }         } else if (cnt == c && a[j] != a[i])           chk_mod(cur = cur * icoef[ct - 1] % mod * (pw2[ct] - 1) % mod);         if (cnt == c && a[j] != a[i])           f[i][j] = cur * icoef[ct] % mod * pw2[t[a[i]] - 1] % mod;       }     }     g[n + 1][0] = 1;     for (int i = n; i >= 1; --i) {       int mxp = (n - i + 1) / c;       for (int j = i; j <= n; ++j)         if (f[i][j])           for (int k = 1; k <= mxp; ++k)             g[i][k] = (g[i][k] + (long long)g[j + 1][k - 1] * f[i][j]) % mod;       g[i][0] = pw2[n - i];       for (int j = 1; j <= n; ++j) add_mod(g[i][0], mod - g[i][j]);       for (int j = 0; j <= n; ++j) add_mod(g[i][j], g[i + 1][j]);     }     add_mod(g[1][0], mod - 1);     for (int i = 0; i <= n; ++i) printf( %d  , g[1][i]);     exit(0);   }   }  // namespace Subtask1   namespace Subtask2 {   const int ALL = (1 << 12) + 5;   long long g[MAXN][ALL];   void solve(void) {     int all = (1 << c) - 1;     g[0][0] = 1;     for (int k = n; k >= 1; --k) {       int mxp = (n - k + 1) / c;       int cura = (1 << (a[k] - 1));       for (int i = mxp; i >= 0; --i)         for (int mask = all - 1; mask >= 0; --mask)           if (g[i][mask]) {             if ((mask | cura) == all)               g[i + 1][0] += g[i][mask];             else               g[i][mask | cura] += g[i][mask];           }       if (k % 20 == 0) {         for (int i = 0; i <= mxp; ++i)           for (int mask = 0; mask <= all; ++mask) g[i][mask] %= mod;       }     }     g[0][0] += mod - 1;     int mxp = n / c;     for (int i = 0; i <= n; ++i) {       if (i > mxp) {         printf( 0  );         continue;       }       int res = 0;       for (int mask = 0; mask < all; ++mask) add_mod(res, g[i][mask] % mod);       printf( %d  , res);     }     exit(0);   }   }  // namespace Subtask2   int main(void) {     pw2[0] = 1;     for (int i = 1; i < MAXN; ++i) pw2[i] = pw2[i - 1] * 2 % mod;     for (int i = 0; i < MAXN; ++i)       icoef[i] = pw((pw2[i] - 1 + mod) % mod, mod - 2);     scanf( %d%d , &n, &c);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     if (c <= 12)       Subtask2::solve();     else       Subtask1::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long long int n;     cin >> n;     long long int k;     cin >> k;     long long int sum = k;     for (int i = (int)2; i <= (int)n; i++) {       cin >> k;       sum = sum + ((k - 1ll) * ((long long int)i - 1ll)) + k;     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     return gcd(b % a, a);   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2 != 0) res = (res * 1ll * a);       b /= 2;       a = (a * 1ll * a);     }     return res;   }   void solve() {     string s;     cin >> s;     long long n = s.length();     bool v = false;     bool h = false;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (!h) {           h = true;           cout << 1 <<     << 1 << endl;         } else {           h = false;           cout << 1 <<     << 3 << endl;         }       } else {         if (!v) {           v = true;           cout << 3 <<     << 4 << endl;         } else {           v = false;           cout << 1 <<     << 4 << endl;         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string s;   vector<string> t;   vector<pair<pair<int, int>, int> > cro;   bool cmp(const pair<pair<int, int>, int> &x,            const pair<pair<int, int>, int> &y) {     if (x.second == y.second) {       if (x.first.first == y.first.first) return x.first.second < y.first.second;       return x.first.first < y.first.first;     }     return x.second < y.second;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < (n); i++) {       cin >> s;       t.push_back(s);     }     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (m); j++) {         if (t[i][j] ==  * ) {           for (int r = (1); r <= (min(i, min(j, min(n - i - 1, m - j - 1))));                r++) {             if ((t[i - r][j] ==  * ) && (t[i + r][j] ==  * ) &&                 (t[i][j - r] ==  * ) && (t[i][j + r] ==  * ))               cro.push_back(make_pair(make_pair(i, j), r));           }         }       }     }     if (cro.size() < k)       cout <<  -1 n ;     else {       sort((cro).begin(), (cro).end(), cmp);       cout << cro[k - 1].first.first + 1 <<     << cro[k - 1].first.second + 1            <<   n ;       cout << cro[k - 1].first.first + 1 - cro[k - 1].second <<                << cro[k - 1].first.second + 1 <<   n ;       cout << cro[k - 1].first.first + 1 + cro[k - 1].second <<                << cro[k - 1].first.second + 1 <<   n ;       cout << cro[k - 1].first.first + 1 <<                << cro[k - 1].first.second + 1 - cro[k - 1].second <<   n ;       cout << cro[k - 1].first.first + 1 <<                << cro[k - 1].first.second + 1 + cro[k - 1].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fio() {}   void pti() {     double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC;     cerr <<  Timeuse   << timeuse <<  ms  << endl;   }   void end() { exit(0); }   namespace io {   const int SIZ = 55;   int que[SIZ], op, qr;   char ch;   template <class I>   inline void gi(I& w) {     ch = getchar(), op = 1, w = 0;     while (!isdigit(ch)) {       if (ch ==  - ) op = -1;       ch = getchar();     }     while (isdigit(ch)) {       w = w * 10 + ch -  0 ;       ch = getchar();     }     w *= op;   }   template <typename T, typename... Args>   inline void gi(T& t, Args&... args) {     gi(t);     gi(args...);   }   template <class I>   inline void print(I w) {     qr = 0;     if (!w) putchar( 0 );     if (w < 0) putchar( - ), w = -w;     while (w) que[++qr] = w % 10 +  0 , w /= 10;     while (qr) putchar(que[qr--]);   }   }  // namespace io   using io::gi;   using io::print;   const int N = 5005;   int n, m;   int a[N];   int main() {     fio();     gi(n, m);     int t = 0;     for (int i = 1; i <= n; ++i) {       a[i] = i;       t += (i - 1) >> 1;       if (t >= m) {         int res = (t - m) << 1;         a[i] += res;         for (int j = n, s = 1e9; j > i; --j, s -= a[i] + 1) a[j] = s;         for (int j = 1; j <= n; ++j) print(a[j]), putchar(   );         end();       }     }     print(-1);     end();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   const int Mod = 1e9 + 7;   struct Mat {     long long A[2][2];     Mat() { memset(A, 0, sizeof(A)); }     void init(void) {       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) A[i][j] = (i == j);     }     Mat operator+(struct Mat A) {       struct Mat B;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           B.A[i][j] = this->A[i][j] + A.A[i][j];           B.A[i][j] %= Mod;         }       }       return B;     }     Mat operator*(struct Mat A) {       struct Mat B;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           for (int k = 0; k < 2; k++) {             B.A[i][j] += (this->A[i][k] * A.A[k][j]);             B.A[i][j] %= Mod;           }         }       }       return B;     }     Mat operator^(int t) {       struct Mat A, B;       A.init();       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) B.A[i][j] = this->A[i][j];       while (t) {         if (t & 1) A = A * B;         t >>= 1;         B = B * B;       }       return A;     }   };   struct Mat Tree[N << 2], Laze[N << 2], f;   int A[N];   void pushUp(int n) { Tree[n] = (Tree[n << 1] + Tree[n << 1 | 1]); }   void pushDown(int n) {     Tree[n << 1] = Laze[n] * Tree[n << 1];     Tree[n << 1 | 1] = Laze[n] * Tree[n << 1 | 1];     Laze[n << 1] = Laze[n] * Laze[n << 1];     Laze[n << 1 | 1] = Laze[n] * Laze[n << 1 | 1];     Laze[n].init();   }   void build(int l, int r, int rt) {     Laze[rt].init();     if (l == r) {       Tree[rt] = f ^ (A[l] - 1);       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushUp(rt);   }   void update(int l, int r, int rt, int _l, int _r, struct Mat x) {     if (l >= _l && r <= _r) {       Tree[rt] = x * Tree[rt];       Laze[rt] = x * Laze[rt];       return;     }     pushDown(rt);     int mid = (l + r) >> 1;     if (_r <= mid) {       update(l, mid, rt << 1, _l, _r, x);     } else if (_l > mid) {       update(mid + 1, r, rt << 1 | 1, _l, _r, x);     } else {       update(l, mid, rt << 1, _l, _r, x);       update(mid + 1, r, rt << 1 | 1, _l, _r, x);     }     pushUp(rt);   }   int query(int l, int r, int rt, int _l, int _r) {     if (l >= _l && r <= _r) {       return Tree[rt].A[0][0];     }     pushDown(rt);     int mid = (l + r) >> 1;     if (_r <= mid) {       return query(l, mid, rt << 1, _l, _r);     } else if (_l > mid) {       return query(mid + 1, r, rt << 1 | 1, _l, _r);     }     return (query(l, mid, rt << 1, _l, _r) +             query(mid + 1, r, rt << 1 | 1, _l, _r)) %            Mod;   }   int main(void) {     int n, m;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) f.A[i][j] = 1;     f.A[1][1] = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     build(1, n, 1);     while (m--) {       int type, l, r;       cin >> type >> l >> r;       if (type == 1) {         int x;         cin >> x;         update(1, n, 1, l, r, f ^ x);       } else if (type == 2) {         cout << query(1, n, 1, l, r) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve() {     int a, b;     scanf( %d %d , &a, &b);     int both = int(floor(pow((double)a * b, 1.0 / 3) + 0.5));     if (both == 0) return a == 1 && b == 1;     if (a % both != 0 || b % both != 0) return false;     if ((long long)a * b != (long long)both * both * both) return false;     long long A = a / both;     long long B = b / both;     if (B * B * A != b || A * A * B != a) return false;     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       if (solve())         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   void cline() { cout <<   n ; }   template <typename T, typename... V>   void cline(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cline(v...);   }   void cspc() { cout <<    ; }   template <typename T, typename... V>   void cspc(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cspc(v...);   }   const long long N = 2e5 + 4;   long long state[2 * N][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(state, 0, sizeof(state));     long long n, m;     cin >> n >> m;     long long ind = -1;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (m == a[i]) ind = i;     }     long long oki = 0, cnt = 0;     for (long long i = 0; i < n; i++) {       if (a[i] < m)         oki--;       else if (a[i] > m)         oki++;       if (i >= ind) state[N + oki][i & 1]++;     }     oki = 0;     for (long long i = 0; i <= ind; ++i) {       if (i % 2 == 1) {         cnt += state[N + oki + 1][0];         cnt += state[N + oki][1];       } else {         cnt += state[N + oki][0];         cnt += state[N + oki + 1][1];       }       if (a[i] < m)         oki--;       else         oki++;     }     cspc(cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T& x, T y) {     if (x < y) x = y;   }   template <typename T>   void chkmin(T& x, T y) {     if (x > y) x = y;   }   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (c < 48) f |= c ==  - , c = getchar();     while (c > 47) x = x * 10 + (c ^ 48), c = getchar();     return f ? -x : x;   }   const int maxn = 5e5 + 10, P = 998244353;   int n, m, A[maxn];   char str[maxn];   inline void Add(int& x, int y) {     x += y;     if (x >= P) x -= P;   }   struct matrix {     int arr[2][2];     void clear() { memset(arr, 0, sizeof arr); }     inline int* operator[](const int& pos) { return arr[pos]; }     inline void print() {       for (int i = (0), iend = (1); i <= iend; ++i)         for (int j = (0), jend = (1); j <= jend; ++j)           printf( %d%c , arr[i][j],   n  [j < 1]);     }   } E;   matrix operator*(matrix A, matrix B) {     matrix res;     res.clear();     for (int k = (0), kend = (1); k <= kend; ++k)       for (int i = (0), iend = (1); i <= iend; ++i)         for (int j = (0), jend = (1); j <= jend; ++j)           Add(res[i][j], 1ll * A[i][k] * B[k][j] % P);     return res;   }   matrix qp(matrix A, long long k) {     matrix res = E;     for (; k; k >>= 1, A = A * A)       if (k & 1) res = res * A;     return res;   }   void minit() {     E.clear();     for (int i = (0), iend = (1); i <= iend; ++i) E[i][i] = 1;   }   matrix val[maxn << 2];   void ins(int k, int l, int r, int x) {     if (l == r) {       auto tmp = val[k].arr;       tmp[1][1] = 0, tmp[0][1] = 1;       tmp[0][0] = (A[x] + 1), tmp[1][0] = x > 1 && A[x - 1] == 1 ? 9 - A[x] : 0;       return;     }     x <= ((l + r) >> 1) ? ins(k << 1, l, ((l + r) >> 1), x)                         : ins(k << 1 | 1, ((l + r) >> 1) + 1, r, x),         val[k] = val[k << 1] * val[k << 1 | 1];   }   void solve() {     minit();     scanf( %d%d%s , &n, &m, str + 1);     for (int i = (1), iend = (n); i <= iend; ++i)       A[i] = str[i] -  0 , ins(1, 1, n, i);     while (m--) {       int xx = read(), yy = read();       A[xx] = yy;       ins(1, 1, n, xx);       if (xx < n) ins(1, 1, n, xx + 1);       printf( %d n , val[1][0][0]);     }   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void minu(T& x, T y) {     x = min(x, y);   }   template <class T>   inline void maxu(T& x, T y) {     x = max(x, y);   }   inline long long bit(long long n) { return 1LL << n; }   template <class T>   ostream& operator<<(ostream& os, vector<T> x) {     for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)       os << *it <<    ;     return os;   }   long long dx[8] = {1, -1, 0, 0, -1, 1, 1, -1};   long long dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};   const long long mod = 1e9 + 7;   long long pow2[200005];   long long memo[505][505];   long long rec(long long n, long long k, long long t) {     if (k < 0) return 0;     if (t == 0) {       return k == 0 ? 1 : 0;     }     if (n == 0) {       return (k == 0 && t == 0) ? 1 : 0;     }     if (t < n) {       return rec(t, k, t) * pow2[t * (n - t)] % mod;     }     long long& ret = memo[n][k];     if (ret >= 0) return ret;     ret = 0;     for (long long bt = 0; bt < ((long long)n); ++bt) {       ret +=           rec(n - 1, k - 1, bt) * (pow2[n - bt] - 1 + mod) % mod * pow2[bt] % mod;       ret %= mod;     }     return ret;   }   int main() {     long long n, k;     cin >> n >> k;     pow2[0] = 1;     for (long long i = 0; i < ((long long)200000); ++i)       pow2[i + 1] = pow2[i] * 2 % mod;     long long ans = 0;     for (long long i = 0; i < ((long long)505); ++i)       for (long long j = 0; j < ((long long)505); ++j) memo[i][j] = -1;     for (long long t = 0; t < ((long long)n + 1); ++t)       ans = (ans + rec(n, k, t)) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[200005], n, k, a[200010], ans, sum, num = 1;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % k) {       cout <<  No ;       return 0;     } else {       sum /= k;       for (int i = 1; i < n; i++) {         ans += a[i];         cnt[num]++;         if (ans > sum) {           cout <<  No ;           return 0;         }         if (ans == sum) {           ans = 0;           num++;         }       }       ans += a[n];       if (ans != sum) {         cout <<  No ;         return 0;       } else         cnt[num]++;       cout <<  Yes  << endl;       for (int i = 1; i <= num; i++) cout << cnt[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int isreq(char c) { return (c ==  H ) || (c ==  Q ) || (c ==  9 ); }   int main() {     int n;     cin >> n;     int cnt = 0;     string str;     for (int i = 0; i < n; i++) {       cin >> str;       if (str[1] ==  + ) {         cnt++;       } else if (str[1] ==  - ) {         cnt--;       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int len(const T& c) {     return (int)c.size();   }   int main() {     int n, bb;     double b1;     vector<double> b;     cin >> n >> bb;     for (int i(0), _n(n); i < _n; ++i) {       cin >> b1;       b.push_back(b1);     }     double sum = accumulate(b.begin(), b.end(), 0);     double mx = *max_element(b.begin(), b.end());     double avg = (sum + bb) / n;     if (mx > avg) {       cout << -1;       return 0;     }     for (int i(0), _n(n); i < _n; ++i) printf( %.6f n , avg - b[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     int j, i;     cin >> r >> c;     char a;     map<int, int> m, n;     for (j = 0; j < r; j++) {       for (i = 0; i < c; i++) {         cin >> a;         if (a ==  S ) {           m[i]++;           n[j]++;         }       }     }     cout << (r * c) - (m.size() * n.size());   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 402;   int a[maxn], f[maxn][2];   int n, m, s, ans;   int main() {     int i, j, k;     scanf( %d%d , &n, &m);     while (m--) {       scanf( %d , &k);       while (k--) {         scanf( %d , &i);         a[i] = ++s;       }     }     for (k = 1; k <= n; k++)       if (!a[k]) break;     for (i = 1; i <= s; i++) {       if (a[i] != i) {         for (j = i + 1; j <= n; j++)           if (a[j] == i) break;         if (i != k) {           f[++ans][0] = i;           f[ans][1] = k;         }         f[++ans][0] = j;         f[ans][1] = i;         a[k] = a[i];         a[i] = i;         k = j;       }     }     printf( %d n , ans);     for (i = 1; i <= ans; i++) printf( %d %d n , f[i][0], f[i][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a, b;   int main() {     int n, m;     cin >> n >> m;     int x = n + m;     int mx = 1;     while (1LL * mx * (mx + 1) / 2 <= x) mx++;     mx--;     for (int i = mx; i >= 1; i--) {       if (n >= i) {         n -= i;         a.push_back(i);       } else {         m -= i;         b.push_back(i);       }     }     printf( %d n , (int)a.size());     for (int i : a) printf( %d  , i);     puts(  );     printf( %d n , (int)b.size());     for (int i : b) printf( %d  , i);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int N, M, A, B;   int main() {     scanf( %d%d%d%d , &N, &M, &A, &B);     int rA = (A - 1) / M + 1, cA = A - (rA - 1) * M;     int rB = (B - 1) / M + 1, cB = B - (rB - 1) * M;     if (B == N) cB = M;     if (rA == rB) {       puts( 1 );       exit(0);     }     if (rA + 1 == rB) {       if (cA == 1 && cB == M)         puts( 1 );       else         puts( 2 );       exit(0);     }     int fA = (cA == 1);     int fB = (cB == M);     if (fA + fB) {       printf( %d n , 3 - fA - fB);       exit(0);     }     if (cB + 1 == cA)       puts( 2 );     else       puts( 3 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[11][11];   bool ok;   string s;   int sol;   queue<int> dulj, broj;   int pomocnopolje[11][11];   void bfs(int x, int y, int a, int b) {     broj.push(a);     dulj.push(1);     int v[10] = {0};     while (!broj.empty()) {       int duljina = dulj.front();       dulj.pop();       int br = broj.front();       broj.pop();       if (!v[(br + x) % 10]) {         v[(br + x) % 10] = duljina;         broj.push((br + x) % 10);         dulj.push(duljina + 1);       }       if (!v[(br + y) % 10]) {         v[(br + y) % 10] = duljina;         broj.push((br + y) % 10);         dulj.push(duljina + 1);       }     }     pomocnopolje[a][b] = v[b] - 1;     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i < 10; i++) {       for (int j = i; j < 10; j++) {         ok = 1;         sol = 0;         for (int k = 0; k < 10; k++) {           for (int l = 0; l < 10; l++) {             bfs(i, j, k, l);           }         }         for (int znj = 1; znj < s.size() and ok; znj++) {           int a = s[znj - 1] -  0 , b = s[znj] -  0 ;           if (pomocnopolje[a][b] >= 0)             sol += pomocnopolje[a][b];           else             ok = 0;         }         if (ok) {           ans[i][j] = sol;           ans[j][i] = sol;         } else {           ans[i][j] = -1;           ans[j][i] = -1;         }       }     }     for (int i = 0; i < 10; i++) {       for (int j = 0; j < 10; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int INF = 0x3f3f3f3f;   template <typename Tp>   struct RMQ {     int n;     int len[MAXN];     Tp mx[MAXN][21];     Tp mi[MAXN][21];     void build_rmq() {       for (int j = 1; (1 << j) <= n; j++)         for (int i = 1; i + (1 << j) - 1 <= n; i++) {           mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);           mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);         }     }     int QueryMax(int L, int R) {       if (L > R) return 0;       int k = len[R - L + 1];       return max(mx[L][k], mx[R - (1 << k) + 1][k]);     }     int QueryMin(int L, int R) {       if (L > R) return INF;       int k = len[R - L + 1];       return min(mi[L][k], mi[R - (1 << k) + 1][k]);     }     void init(Tp *a, int sz) {       n = sz;       for (int i = 1; i <= n; i++) mx[i][0] = mi[i][0] = a[i];       build_rmq();       for (int i = 0; i <= n; i++) len[i] = (i == 0 ? -1 : len[i >> 1] + 1);     }   };   RMQ<int> st;   int n, q, mx = 0, tim = 0;   vector<int> E[MAXN];   int in[MAXN], out[MAXN], pos[MAXN], dep[MAXN], fa[MAXN][20];   void dfs(int now, int f = 1, int dp = 0) {     mx = max(mx, dp);     fa[now][0] = f;     for (int i = 1; i < 20; i++) fa[now][i] = fa[fa[now][i - 1]][i - 1];     in[now] = ++tim;     dep[now] = dp;     pos[tim] = now;     for (int v : E[now]) {       dfs(v, now, dp + 1);     }     out[now] = tim;   }   int up(int L, int R, int now) {     if (in[now] <= L && out[now] >= R) return dep[now];     for (int i = 19; i >= 0; i--) {       int f = fa[now][i];       if (in[f] <= L && out[f] >= R) continue;       now = fa[now][i];     }     return dep[fa[now][0]];   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++) {       int x;       scanf( %d , &x);       E[x].push_back(i);     }     dfs(1);     st.init(in, n);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (l == r) {         printf( %d %d n , l, mx);       } else {         int Mi = st.QueryMin(l, r);         int Mx = st.QueryMax(l, r);         int dep1, dep2;         int now1, now2;         int st1, st2;         now1 = min(st.QueryMin(l, pos[Mi] - 1), st.QueryMin(pos[Mi] + 1, r));         now2 = max(st.QueryMax(l, pos[Mx] - 1), st.QueryMax(pos[Mx] + 1, r));         st1 = pos[Mx], st2 = pos[Mi];         dep1 = up(now1, Mx, st1);         dep2 = up(Mi, now2, st2);         if (dep1 > dep2)           printf( %d %d n , st2, dep1);         else           printf( %d %d n , st1, dep2);       }     }     return 0;   }


#include <bits/stdc++.h>   namespace std {   template <typename A, typename B>   inline string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   inline string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   inline string to_string(tuple<A, B, C, D> p);   inline string to_string(const string& s) { return     + s +    ; }   inline string to_string(const char* s) { return to_string((string)s); }   inline string to_string(bool b) { return (b ?  true  :  false ); }   inline string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   inline string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   inline string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   inline string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   inline string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   inline string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   }  // namespace std   inline void debug_out() { std::cerr << std::endl; }   template <typename Head, typename... Tail>   inline void debug_out(Head H, Tail... T) {     std::cerr <<     << std::to_string(H);     debug_out(T...);   }   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<vector<int>> e(n);     for (int i = 0; i < m; i++) {       int v, u;       scanf( %d%d , &v, &u);       v--;       u--;       e[v].push_back(u);       e[u].push_back(v);     }     vector<pair<int, int>> color(n);     vector<int> b(n);     for (int i = 0; i < n; i++) {       scanf( %d , &color[i].first);       color[i].first--;       color[i].second = i;       b[i] = color[i].first;     }     sort((color).begin(), (color).end());     bool good = true;     vector<int> use(n);     for (int i = 0; i < n; i++) {       int v = color[i].second;       int tgt = color[i].first;       vector<int> mask(tgt + 1);       for (auto u : e[v]) {         if (use[u]) {           assert(b[u] <= tgt);           mask[b[u]] = 1;         }       }       for (int j = 0; j < tgt; j++) {         if (mask[j] == 0) {           good = false;         }       }       if (mask[tgt]) {         good = false;       }       use[v] = 1;     }     if (!good) {       puts( -1 );       return 0;     }     for (auto x : color) {       cout << x.second + 1 <<    ;     }     cout << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   const int M = 1000000007;   const double eps = 1e-9;   const double PI = acos(-1);   const int oo = 1000000000;   typedef double TT;   struct point {     TT x, y;     point() : x(0), y(0) {}     point(TT a, TT b) {       x = a;       y = b;     }     point operator+(const point& p) const { return point(x + p.x, y + p.y); }     friend ostream& operator<<(ostream& os, const point& p) {       return os <<  (  << p.x <<  ,  << p.y <<  ) ;     }     point operator-(const point& p) const { return point(x - p.x, y - p.y); }     bool operator<(const point& p) const {       if (x - p.x) return x < p.x;       return y < p.y;     }     bool operator==(const point& p) const { return x == p.x && y == p.y; }     bool operator!=(const point& p) const { return !(*this == p); }     void scan() { scanf( %lf%lf , &x, &y); }     double len() { return sqrt(x * x + y * y); }     double dist(const point& p) const { return (p - *this).len(); }     point operator*(TT d) { return point(x * d, y * d); }     point operator/(TT d) { return point(x / d, y / d); }     TT operator*(const point& p) const { return x * p.x + y * p.y; }     TT operator^(const point& p) const { return x * p.y - y * p.x; }     double linePointDist(point a, point b, bool seg = false) {       point c = *this;       if (seg) {         if ((b - a) * (c - b) > 0) return b.dist(c);         if ((a - b) * (c - a) > 0) return a.dist(c);       }       return abs((b - a) ^ (c - a)) / a.dist(b);     }     void rotate(double theta, point Z = point(0, 0)) {       TT ox = x - Z.x;       TT oy = y - Z.y;       x = ox * cos(theta) - oy * sin(theta) + Z.x;       y = ox * sin(theta) + oy * cos(theta) + Z.y;     }   };   double areaOfTri(point a, point b, point c) {     point x = b - a;     point y = c - a;     return (x ^ y) / 2.0;   }   double areaOfPolygon(vector<point>& P) {     TT area = 0;     for (int i = 1; i < P.size() - 1; ++i)       area += (P[i] - P[0]) ^ (P[i + 1] - P[0]);     return abs(area / 2.0);   }   bool collinear(point a, point b, point c) { return areaOfTri(a, b, c) == 0; }   vector<point> x(4), y(4);   int main() {     double mnx = oo, mxx = -oo, mny = oo, mxy = -oo;     for (int i = 0; i < 4; ++i) {       x[i].scan();       mnx = min(mnx, x[i].x);       mny = min(mny, x[i].y);       mxx = max(mxx, x[i].x);       mxy = max(mxy, x[i].y);     }     point dx((mnx + mxx) / 2, (mny + mxy) / 2);     for (int i = 0; i < 4; ++i) y[i].scan();     for (int i = 0; i < 4; ++i)       if (y[i].x >= mnx && y[i].x <= mxx && y[i].y >= mny && y[i].y <= mxy)         return cout <<  YES , 0;     double area = abs(areaOfPolygon(y));     for (int i = 0; i < 4; ++i) {       double cc = abs(areaOfTri(y[3], y[0], x[i]));       for (int j = 1; j < 4; ++j) cc += abs(areaOfTri(y[j - 1], y[j], x[i]));       if (abs(cc - area) < eps) return cout <<  YES , 0;     }     double cc = abs(areaOfTri(y[3], y[0], dx));     for (int j = 1; j < 4; ++j) cc += abs(areaOfTri(y[j - 1], y[j], dx));     if (abs(cc - area) < eps) return cout <<  YES , 0;     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, l;   long long sum;   int main() {     cin >> a >> b >> c >> l;     sum = ((l + 1) * (l + 2) * (l + 3)) / 6;     for (long long i = 0; i <= l; i++) {       long long temp1 = a - b - c + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     for (long long i = 0; i <= l; i++) {       long long temp1 = b - a - c + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     for (long long i = 0; i <= l; i++) {       long long temp1 = c - b - a + i;       if (temp1 >= 0) {         long long temp2 = l - i;         long long x = min(temp1, temp2);         sum -= (x + 1) * (x + 2) / 2;       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using pii = pair<int, int>;   constexpr int ALPHABET_SIZE =  z  -  a  + 1;   constexpr int MAX_SIZE = 256;   constexpr int INF = 1e8;   int n;   string s;   string as, bs, cs;   vector<int> next_pos[ALPHABET_SIZE];   int calced_pos[MAX_SIZE][MAX_SIZE][MAX_SIZE];   int calced_mark[MAX_SIZE][MAX_SIZE][MAX_SIZE];   int added_mark[MAX_SIZE][MAX_SIZE][MAX_SIZE];   int dda[(int)3e5];   int ddb[(int)3e5];   int ddc[(int)3e5];   void promote(int s_pos, int mark, int type) {     int dsize = 0;     int dptr = 0;     if (type == 1) {       for (int bb = 0; bb <= bs.size(); bb++) {         for (int cc = 0; cc <= cs.size(); cc++) {           dda[dsize] = s_pos;           ddb[dsize] = bb;           ddc[dsize] = cc;           dsize++;           calced_mark[s_pos][bb][cc] = mark;           added_mark[s_pos][bb][cc] = mark;         }       }     } else if (type == 2) {       for (int aa = 0; aa <= as.size(); aa++) {         for (int cc = 0; cc <= cs.size(); cc++) {           dda[dsize] = aa;           ddb[dsize] = s_pos;           ddc[dsize] = cc;           dsize++;           calced_mark[aa][s_pos][cc] = mark;           added_mark[aa][s_pos][cc] = mark;         }       }     } else {       for (int aa = 0; aa <= as.size(); aa++) {         for (int bb = 0; bb <= bs.size(); bb++) {           dda[dsize] = aa;           ddb[dsize] = bb;           ddc[dsize] = s_pos;           dsize++;           calced_mark[aa][bb][s_pos] = mark;           added_mark[aa][bb][s_pos] = mark;         }       }     }     while (dptr < dsize) {       int a = dda[dptr];       int b = ddb[dptr];       int c = ddc[dptr];       dptr++;       int &m = calced_mark[a][b][c];       m = mark;       added_mark[a][b][c] = mark;       int &pos = calced_pos[a][b][c];       if (a == 0 && b == 0 && c == 0) {         pos = 0;       }       if (a < as.size()) {         int &p = calced_pos[a + 1][b][c];         int &mm = calced_mark[a + 1][b][c];         int &am = added_mark[a + 1][b][c];         if (am != mark) {           if (mm != mark) {             p = INF;             mm = mark;             dda[dsize] = a + 1;             ddb[dsize] = b;             ddc[dsize] = c;             dsize++;           }           if (pos < n) p = min(p, next_pos[as[a] -  a ][pos] + 1);         }       }       if (b < bs.size()) {         int &p = calced_pos[a][b + 1][c];         int &mm = calced_mark[a][b + 1][c];         int &am = added_mark[a][b + 1][c];         if (am != mark) {           if (mm != mark) {             p = INF;             mm = mark;             dda[dsize] = a;             ddb[dsize] = b + 1;             ddc[dsize] = c;             dsize++;           }           if (pos < n) p = min(p, next_pos[bs[b] -  a ][pos] + 1);         }       }       if (c < cs.size()) {         int &p = calced_pos[a][b][c + 1];         int &mm = calced_mark[a][b][c + 1];         int &am = added_mark[a][b][c + 1];         if (am != mark) {           if (mm != mark) {             p = INF;             mm = mark;             dda[dsize] = a;             ddb[dsize] = b;             ddc[dsize] = c + 1;             dsize++;           }           if (pos < n) p = min(p, next_pos[cs[c] -  a ][pos] + 1);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> n >> q;     cin >> s;     memset(calced_mark, 0, sizeof(calced_mark));     memset(added_mark, 0, sizeof(added_mark));     for (int i = 0; i < ALPHABET_SIZE; i++) {       next_pos[i].resize(n, INF);     }     for (int i = n - 1; i >= 0; i--) {       if (i + 1 < n) {         for (int z = 0; z < ALPHABET_SIZE; z++) {           next_pos[z][i] = next_pos[z][i + 1];         }       }       int c = s[i] -  a ;       next_pos[c][i] = i;     }     int mark = 228;     char c, which;     int num;     while (q--) {       mark++;       cin >> c >> num;       if (c ==  - ) {         if (num == 1) {           as.pop_back();         } else if (num == 2) {           bs.pop_back();         } else if (num == 3) {           cs.pop_back();         }       } else {         cin >> which;         if (num == 1) {           as.push_back(which);           promote(as.size() - 1, mark, num);         } else if (num == 2) {           bs.push_back(which);           promote(bs.size() - 1, mark, num);         } else if (num == 3) {           cs.push_back(which);           promote(cs.size() - 1, mark, num);         }       }       cout << (calced_pos[as.size()][bs.size()][cs.size()] <= s.size() ?  YES                                                                         :  NO )            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 2e5 + 5;   const int T = 1e3 + 10;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   long long binpow(long long val, long long deg) {     if (!deg) return 1;     if (deg & 1) return binpow(val, deg - 1) * val % MOD;     long long res = binpow(val, deg / 2);     return (res * res) % MOD;   }   long long inv(long long a) { return binpow(a, MOD - 2); }   pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first - b.first, a.second - b.second);   }   void rotate90(int& first, int& second, int x0, int y0) {     first = first - x0;     second = second - y0;     swap(first, second);     first = -first;     first += x0;     second += y0;   }   long long i, j;   long long n, m;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout.precision(10);     cin >> n >> m;     set<int> column, line;     while (m--) {       int first, second;       cin >> first >> second;       column.insert(first);       line.insert(second);       cout << (n - column.size()) * (n - line.size()) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const double PI = 3.141592653589793238463;   const int INF = 0x3f3f3f3f;   const int INFS = 1000000000;   const long long LLINF = 9223372036854775807;   const int M = 1000000007;   const double EPS = 1e-9;   set<int> get(int n) {     set<int> ans = {};     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         ans.insert(i);         while (n % i == 0) n /= i;       }     }     if (n != 1) ans.insert(n);     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<set<int> > a(n + 1);     for (int i = 1; i < n + 1; i++) a[i] = get(i);     map<int, int> curr;     vector<bool> on(n + 1, false);     char t;     int i;     while (m--) {       cin >> t >> i;       if (t ==  + ) {         if (on[i])           cout <<  Already on  << endl;         else {           bool ok = true;           int j;           for (auto x : a[i]) {             if (curr[x] != 0) {               ok = false;               j = curr[x];               break;             }           }           if (ok) {             cout <<  Success  << endl;             for (auto x : a[i]) curr[x] = i;             on[i] = true;           } else {             cout <<  Conflict with   << j << endl;           }         }       } else {         if (!on[i])           cout <<  Already off  << endl;         else {           cout <<  Success  << endl;           for (auto x : a[i]) curr[x] = 0;           on[i] = false;         }       }     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;      typedef vector<int> vi;   typedef vector<ll> vll;      typedef vector<vi> vvi;   typedef vector<vll> vvll;      typedef pair<int, int> pii;   typedef pair<ll, ll> pll;      typedef vector<pii> vpii;   typedef vector<pll> vpll;      typedef vector<vpii> vvpii;   typedef vector<vpll> vvpll;      #define pb push_back   #define mp make_pair   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define sz(x) (int)(x).size()   #define fi first   #define se second      template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}   template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}      namespace debug {       void __print(int x) {cerr << x;}       void __print(long long x) {cerr << x;}       void __print(double x) {cerr << x;}       void __print(long double x) {cerr << x;}       void __print(char x) {cerr <<      << x <<     ;}       void __print(const string &x) {cerr <<     << x <<    ;}       void __print(bool x) {cerr << (x ?  true  :  false );}          template<typename T, typename V>       void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}       template<typename T>       void __print(const T &x) {int f = 0; cerr <<  { ; for(auto z : x) cerr << (f++ ?  ,  :   ), __print(z); cerr <<  } ;}       void _print() {cerr <<  ] n ;}       template <typename T, typename... V>       void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr <<  ,  ; _print(v...);}      #ifdef ljuba   #define dbg(x...) cerr <<  LINE(  << __LINE__ <<  ) ->   <<  [  << #x <<  ] = [ ; _print(x)   #else   #define dbg(x...)   #endif   }      using namespace debug;      const char nl =   n ;      mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());      int mat[1000][1000];   int m, k;      bool moze(int n, const vi &v) {       for(int i = 0; i < n; ++i) {           for(int j = 0; j < n; ++j) {               mat[i][j] = -1;           }       }          vpii nz;       for(int i = 0; i < k; ++i) {           if(v[i]) {               nz.pb({v[i], i+1});           }       }       sort(all(nz));          for(int i = 1; i < n; i += 2) {           for(int j = 0; j < n; j += 2) {               if(mat[i][j] != -1) continue;               if(sz(nz) && nz.back().fi > 0) {                   nz.back().fi--;                   mat[i][j] = nz.back().se;                   if(nz.back().fi == 0)                       nz.pop_back();               }           }       }          pii kasnije{-1, -1};          if(sz(nz) && nz.back().fi > 0) {           kasnije = nz.back();           nz.pop_back();       }          dbg(kasnije);          for(int i = 0; i < n; i += 2) {           for(int j = 1; j < n; j += 2) {               if(mat[i][j] != -1) continue;               if(sz(nz) && nz.back().fi > 0) {                   nz.back().fi--;                   mat[i][j] = nz.back().se;                   if(nz.back().fi == 0)                       nz.pop_back();               }           }       }          if(kasnije.fi != -1)           nz.pb(kasnije);          for(int i = 0; i < n; i += 2) {           for(int j = 0; j < n; j += 2) {               if(mat[i][j] != -1) continue;               if(sz(nz) && nz.back().fi > 0) {                   nz.back().fi--;                   mat[i][j] = nz.back().se;                   if(nz.back().fi == 0)                       nz.pop_back();               }           }       }          for(int i = 0; i < n; ++i) {           for(int j = 0; j < n; ++j) {               if(i % 2 == 1 && j % 2 == 1) continue;               if(sz(nz)) {                   nz.back().fi--;                   mat[i][j] = nz.back().se;                   if(nz.back().fi == 0)                       nz.pop_back();               }           }       }          return nz.empty();   }      void solve() {       cin >> m >> k;       vi v(k);       for(auto &z : v) cin >> z;          int mx = *max_element(all(v));       int n = -1;       for(int i = 1; ; ++i) {           ll izraz = i * 1LL * ((i + 1) / 2);           if(mx <= izraz) {               ckmax(n, i);               break;           }       }       for(int i = 1; ; ++i) {           ll izraz = i * 1LL * i;           ll temp = i / 2;           izraz -= temp * 1LL * temp;           if(m <= izraz) {               ckmax(n, i);               break;           }       }          while(!moze(n, v))           ++n;          cout << n << nl;       for(int i = 0; i < n; ++i) {           for(int j = 0; j < n; ++j) {               if(mat[i][j] == -1) mat[i][j] = 0;               cout << mat[i][j] <<    ;           }           cout << nl;       }   }      int main() {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);      #ifdef ljuba       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);       freopen( error.txt ,  w , stderr);   #endif          int testCases = 1;       cin >> testCases;       while(testCases--)           solve();      }


#include <bits/stdc++.h>   using namespace std;   int n, ans, kol[100500];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (kol[j] <= v[i]) {           kol[j]++;           break;         }     for (int i = 0; i < n; i++) ans += (kol[i] > 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s;     int a;     int x = 0, y = n + 1;     for (int i = 0; i < m; i++) {       cin >> s;       cin >> s;       cin >> s;       if (s[0] ==  r ) {         cin >> s;         cin >> a;         if (a > x) x = a;       } else {         cin >> s;         cin >> a;         if (a < y) y = a;       }     }     if (y - x <= 1 || x == n || y == 1)       cout << -1;     else       cout << y - x - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       vector<int> original;       int temp;       for (int i = 0; i < n; i++) {         cin >> temp;         original.push_back(temp);       }       for (int i = 0; i < original.size(); i++) {         int days = 0;         int origpos = i;         int newpos = original[i];         bool home = false;         while (!home) {           newpos = original[newpos - 1];           if (newpos == original[i]) {             home = true;           }           days++;         }         cout << days <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     priority_queue<int> q;     for (int i = 0; i < 32; i++) {       if (n & (1 << i)) {         q.push(i);       }     }     if (q.size() > k) {       cout <<  NO n ;     } else {       while (q.size() != k) {         int f = q.top();         q.pop();         if (f == 0) {           cout <<  NO n ;           return 0;         }         q.push(f - 1);         q.push(f - 1);       }       cout <<  YES n ;       while (!q.empty()) {         int val = 1 << q.top();         cout << val <<    ;         q.pop();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T mod_v(T num) {     if (num >= 0)       return num % 1000000007;     else       return (num % 1000000007 + 1000000007) % 1000000007;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <class T>   T fast_pow(T n, T p) {     if (p == 0) return 1;     if (p % 2) {       T g = mod_v(mod_v(n) * mod_v(fast_pow(n, p - 1)));       return g;     } else {       T g = fast_pow(n, p / 2);       g = mod_v(mod_v(g) * mod_v(g));       return g;     }   }   template <class T>   inline T modInverse(T n) {     return fast_pow(n, 1000000007 - 2);   }   template <class T>   inline void debug(string S1, T S2, string S3) {     cout << S1 << S2 << S3;   }   template <class T>   inline T in() {     register char c = 0;     register T num = 0;     bool n = false;     while (c < 33) c = getchar();     while (c > 33) {       if (c ==  - )         n = true;       else         num = num * 10 + c -  0 ;       c = getchar();     }     return n ? -num : num;   }   class data {    public:     int t, w;   };   int dp[108][208][208];   int n;   data ara[108];   vector<int> ans;   int re(int p, int s, int u) {     if (p == n) {       return s;       return ((s >= u) ? s : 100000000);     }     if (dp[p][s][u] != -1) return dp[p][s][u];     dp[p][s][u] = 1 << 30;     if (u - ara[p].w - ara[p].t >= 0) {       dp[p][s][u] =           min(dp[p][s][u], re(p + 1, s - ara[p].t, u - ara[p].t - ara[p].w));     }     ans.push_back(p + 1);     dp[p][s][u] = min(dp[p][s][u], re(p + 1, s, u));     ans.pop_back();     return dp[p][s][u];   }   int main() {     n = in<int>();     int t = 0, w = 0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i].t, &ara[i].w);       t += ara[i].t;     }     memset(dp, -1, sizeof(dp));     ;     printf( %d n , re(0, t, t));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<long long int> vec(n);       for (int i = 0; i < n; i++) {         cin >> vec[i];       }       sort(vec.begin(), vec.end());       long long int sum = vec[n - 1];       int x = n - 2;       while (k--) {         sum += vec[x];         x--;       }       cout << sum <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int ans = 0;     for (int i = 1; i < n; i++) {       int a = max(0, k - (arr[i] + arr[i - 1]));       arr[i] += a;       ans += a;     }     cout << ans <<   n ;     for (int i = 0; i < n; i++) cout << arr[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int main(void) {     char arr1[N] = {0};     char arr2[N] = {0};     char str1[2] = {0}, str2[2] = {0};     scanf( %[^ n]s , arr1);     scanf(  %[^ n]s , arr2);     if (strlen(arr1) != strlen(arr2)) {       cout <<  NO n ;       return 0;     }     int a = 0;     for (int i = 0, j = 0, k = 0; i < strlen(arr1); i++) {       if (arr1[i] != arr2[i]) {         a++;         if (a <= 2) {           str1[j++] = arr1[i];           str2[k++] = arr2[i];         }       }     }     if (a == 2) {       if ((str1[1] == str2[0]) && (str1[0] == str2[1]))         cout <<  YES n ;       else         cout <<  NO n ;     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     cin >> n >> k;     if (n / 2 > k) return !printf( -1 );     if (n == 1) {       if (k == 0)         printf( 1 );       else         printf( -1 );       return 0;     }     int t = k - (n - 2) / 2;     printf( %d %d , t, 2 * t);     for (int i = 1; i <= n - 2; ++i) printf(  %d , i + 2 * t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input() {}   void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n][m];     long long int flag = 1, temp = 0;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         char ch;         cin >> ch;         if (ch ==  A ) {           a[i][j] = 1;         } else {           a[i][j] = 0;         }         if (a[i][j]) {           flag = 0;         }         temp += a[i][j];       }     }     if (temp == n * m) {       cout <<  0 ;       return;     }     if (flag) {       cout <<  MORTAL ;       return;     }     for (long long int i = 0; i < 1; i++) {       long long int cnt1 = 0, cnt2 = 0;       for (long long int j = 0; j < m; j++) {         if (a[0][j]) {           cnt1++;         }         if (a[n - 1][j]) {           cnt2++;         }       }       if (cnt1 == m || cnt2 == m) {         cout <<  1 ;         return;       }     }     for (long long int j = 0; j < 1; j++) {       long long int cnt1 = 0, cnt2 = 0;       for (long long int i = 0; i < n; i++) {         if (a[i][0]) {           cnt1++;         }         if (a[i][m - 1]) {           cnt2++;         }       }       if (cnt1 == n || cnt2 == n) {         cout <<  1 ;         return;       }     }     for (long long int i = 1; i < n - 1; i++) {       long long int cnt = 0;       for (long long int j = 0; j < m; j++) {         if (a[i][j]) {           cnt++;         }       }       if (cnt == m) {         cout <<  2 ;         return;       }     }     for (long long int j = 1; j < m - 1; j++) {       long long int cnt = 0;       for (long long int i = 0; i < n; i++) {         if (a[i][j]) {           cnt++;         }       }       if (cnt == n) {         cout <<  2 ;         return;       }     }     if (a[0][m - 1] || a[0][0] || a[n - 1][0] || a[n - 1][m - 1]) {       cout <<  2 ;       return;     }     long long int cnt = 0;     for (long long int i = 0; i < n; i++) {       cnt += a[i][0];       cnt += a[i][m - 1];     }     for (long long int i = 0; i < m; i++) {       cnt += a[0][i];       cnt += a[n - 1][i];     }     if (cnt) {       cout <<  3 ;     } else {       cout <<  4 ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     input();     int t = 1, i = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long pow(long long p, long long r, long long m) {     long long ans = 1;     while (r > 0) {       if (r & 1) {         ans = ((ans % m) * (p % m)) % m;       }       r = r >> 1;       p = ((p % m) * (p % m)) % m;     }     return ans;   }   string con(string s) {     for (long long i = 0; i < s.length(); i++) {       s[i] = toupper(s[i]);     }     return s;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       stack<long long> s1;       for (char i : s) {         if (!s1.empty() && i ==  B )           s1.pop();         else           s1.push(i);       }       cout << s1.size() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string dna =  ACGT ;   string word[20];   set<string> words;   map<string, int> mp;   string pm[110];   pair<int, int> graph[110][20][4];   long long dp[1010][110][20];   int main() {     ios::sync_with_stdio(false);     int N, K, i, j, k, l, x;     cin >> N >> K;     for (i = 0; i < K; i++) cin >> word[i];     for (i = 0; i < K; i++) words.insert(word[i]);     for (i = 0; i < K; i++)       for (j = 1; j <= word[i].length(); j++) mp[word[i].substr(0, j)] = 0;     mp[  ] = 0;     int s = 0;     for (auto itr = mp.begin(); itr != mp.end(); itr++) {       (itr->second) = s;       pm[s] = (itr->first);       s++;     }     for (i = 0; i < s; i++) {       for (j = 0; j < pm[i].length() + 1; j++) {         for (k = 0; k < 4; k++) {           string s = pm[i] + dna[k];           int nextst = -1;           for (l = 0;; l++) {             if (mp.find(s.substr(l)) != mp.end()) {               nextst = mp[s.substr(l)];               break;             }           }           bool cover = false;           for (l = 0; l < pm[i].length() - j + 1; l++)             if (words.find(s.substr(l)) != words.end()) cover = true;           graph[i][j][k] = make_pair(-1, -1);           int nextcover = j + 1;           if (cover) nextcover = 0;           if (nextcover >= 10 || nextcover > pm[nextst].length()) continue;           graph[i][j][k] = make_pair(nextst, nextcover);         }       }     }     int start = mp[  ];     dp[0][start][0] = 1;     for (i = 0; i < N; i++) {       for (j = 0; j < s; j++) {         for (k = 0; k < 10; k++) {           if (dp[i][j][k] != 0) {             for (x = 0; x < 4; x++) {               pair<int, int> p = graph[j][k][x];               if (p.first != -1) {                 int i2 = i + 1, j2 = p.first, k2 = p.second;                 dp[i2][j2][k2] = (dp[i][j][k] + dp[i2][j2][k2]) % 1000000009ll;               }             }           }         }       }     }     long long ans = 0;     for (i = 0; i < s; i++) ans = (ans + dp[N][i][0]) % 1000000009ll;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<int> v[2][N];   int a[N], q[N], n;   bool vst[2][N];   void bfs(int val) {     int i, j, qh = 0, qe = 0, k = val - 1, s, out;     for (i = 1; i <= n; i++)       if (a[i] == val) q[qe++] = i, vst[k][i] = 1;     while (qh < qe) {       out = q[qh++];       if (val != 2 || a[out] != 1)         for (i = 0, s = v[k][out].size(); i < s; i++)           if (!vst[k][j = v[k][out][i]]) q[qe++] = j, vst[k][j] = 1;     }   }   int main() {     int i, j, e;     while (2 == scanf( %d%d , &n, &e)) {       for (i = 1; i <= n; i++)         scanf( %d , a + i), v[0][i].clear(), v[1][i].clear();       while (e--) {         scanf( %d%d , &i, &j);         v[0][i].push_back(j);         v[1][j].push_back(i);       }       memset(vst, 0, sizeof vst);       bfs(1);       bfs(2);       for (i = 1; i <= n; i++) puts(vst[0][i] && vst[1][i] ?  1  :  0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPossible(long long k, long long x, long long y, long long p,                   long long q) {     p = p * k;     q = q * k;     if (x > p || y > q) {       return false;     }     if (q - y < p - x) {       return false;     }     return true;   }   long long solve(long long x, long long y, long long p, long long q) {     long long low = 1;     long long high = 1e9;     while (low < high) {       long long mid = low + (high - low) / 2;       if (!isPossible(mid, x, y, p, q)) {         low = mid + 1;       } else {         high = mid;       }     }     if (!isPossible(low, x, y, p, q)) {       return -1;     }     return (q * low - y);   }   int main() {     long long t;     cin >> t;     while (t--) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       cout << solve(x, y, p, q) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; }   const long long int inf = 1e15;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   string str;   string sol(int n) {     string ans;     for (int i = (0); i < (n); i++) {       ans = ans + (i < n / 2 ?  4  :  7 );     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> str;     int n = str.length();     if (n & 1) {       cout << sol(n + 1) << endl;     } else {       int ind = -1, c4 = 0, c7 = 0;       for (int i = (0); i < (n); i++) {         if (str[i] >  7 ) {           if (ind == -1) {             cout << sol(n + 2) << endl;             return 0;           } else {             str[ind] =  7 ;             str[i] =  4 ;             c7++;             if (abs(c4 - c7) > n - i - 1) {               cout << sol(n + 2) << endl;               return 0;             } else {               int j = i + 1;               for (int k = (j); k < (n); k++) {                 str[k] =  4 ;                 c4++;               }               for (int k = (n - 1); k >= (i + 1); k--) {                 if (c4 > c7) {                   str[k] =  7 ;                   c4--;                   c7++;                 } else {                   break;                 }               }               cout << str << endl;               return 0;             }           }         } else if (str[i] !=  4  && str[i] !=  7 ) {           if (str[i] <  4 ) {             str[i] =  4 ;             c4++;           } else {             str[i] =  7 ;             c7++;           }           if (abs(c4 - c7) > n - i - 1) {             cout << sol(n + 2) << endl;             return 0;           } else {             int j = i + 1;             for (int k = (j); k < (n); k++) {               str[k] =  4 ;               c4++;             }             for (int k = (n - 1); k >= (i + 1); k--) {               if (c4 > c7) {                 str[k] =  7 ;                 c4--;                 c7++;               } else {                 break;               }             }             cout << str << endl;             return 0;           }         } else {           if (str[i] ==  4 ) {             ind = i;             c4++;           } else             c7++;         }       }       if (c4 > c7) {         for (int i = (ind); i >= (0); i--) {           if (c4 > c7) {             str[i] =  7 ;             c4--;             c7++;           } else {             break;           }         }         cout << str << endl;       } else if (c7 > c4) {         int cc4 = 0, cc7 = 0;         for (int i = 0; i <= ind; i++) {           if (str[i] ==  4 )             cc4++;           else             cc7++;         }         c4 = cc4, c7 = cc7;         for (int i = (ind); i >= (0); i--) {           if (str[i] ==  4 ) {             if (abs(c4 - c7 - 1) <= n - i - 1) {               str[i] =  7 ;               c4--;               c7++;               int j = i + 1;               for (int k = (j); k < (n); k++) {                 str[k] =  4 ;                 c4++;               }               for (int k = (n - 1); k >= (i + 1); k--) {                 if (c4 > c7) {                   str[k] =  7 ;                   c4--;                   c7++;                 } else {                   break;                 }               }               cout << str << endl;               return 0;             }             c4--;           } else {             c7--;           }         }         cout << sol(n + 2) << endl;       } else {         cout << str << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d, m, n, x[25], a[30005];   vector<long long> ok;   long long L, R;   map<long long, vector<long long> > ans;   map<long long, vector<long long> > zip;   vector<long long> calc(long long lim) {     if (zip.find(lim) != zip.end()) return zip[lim];     vector<long long> ret(m, 0);     if (lim == 0) {       ret[0] = 1;       return ret;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> R = calc(nxt_lim);       for (int i = 0; i < m; i++) {         int a = (i + x[beg]);         if (a >= m) a -= m;         ret[a] += R[i];       }     }     return zip[lim] = ret;   }   void rec(long long lim, vector<long long> mask, bool F) {     if (mask.size() == 1) {       if (ans.find(lim) == ans.end()) {         ans[lim] = vector<long long>(m, 0);       }       for (int i = 0; i < m; i++) {         if (((mask[0] >> i) & 1LL)) {           if (F)             ans[lim][i]++;           else             ans[lim][i]--;         }       }       return;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> vec;       int zan = mask.size();       int bb = (d - beg);       int xx = 1 + (zan - bb + d - 1) / d;       vec.resize(xx, 0LL);       long long B = (1LL << m) - 1;       int cur = beg;       int id = 0;       for (int i = 0; i < mask.size(); i++) {         int add = x[cur];         long long nw = 0;         nw = (mask[i] >> add) | (mask[i] << (m - add));         B &= nw;         if (cur == d - 1 || i == mask.size() - 1) {           vec[id++] = B;           B = (1LL << m) - 1;         }         cur++;         if (cur == d) cur = 0;       }       assert(id == xx);       rec(nxt_lim, vec, F);     }   }   int main() {     cin >> d >> m;     for (int i = 0; i < d; i++) {       cin >> x[i];     }     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       ok.push_back((2LL << a[i]) - 1LL);     }     cin >> L >> R;     L--;     R--;     rec(R - n + 1, ok, true);     if (L - 1 >= 0) rec(L - 1, ok, false);     long long ret = 0;     for (map<long long, vector<long long> >::iterator it = ans.begin();          it != ans.end(); it++) {       vector<long long> tbl = calc(it->first);       for (int i = 0; i < m; i++) {         ret += tbl[i] * it->second[i];       }     }     cout << ret << endl;   }


#include <bits/stdc++.h>   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   long long pow(long long a, int p) {     long long ans = 1;     while (p) {       if (p & 1) ans *= a;       a *= a;       p >>= 1;     }     return ans;   }   int main() {     int n, l, r;     scanf( %d%d%d , &n, &l, &r);     if (n == 1) {       printf( %d n , r - l + 1);       return 0;     }     if (n == 2) {       printf( %lld n , (long long)(r - l + 1) * (r - l));       return 0;     }     if (n > 30) {       printf( 0 n );       return 0;     }     n--;     int M = 1;     while (pow(M + 1, n) <= r) M++;     long long ans = 0;     for (int y = 1; y <= M; y++) {       for (int x = y + 1; x <= M; x++)         if (gcd(x, y) == 1) {           int py = pow(y, n), px = pow(x, n);           int L = 1, R = l / py + 1;           int RR = r / px;           while (L < R) {             int M = (L + R) / 2;             if (M * py < l)               L = M + 1;             else               R = M;           }           if (L <= RR) ans += RR - L + 1;         }     }     printf( %lld n , ans << 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n, m;     cin >> n >> m;     long long int a[n], b[m];     long long int aux[n];     for (long long int i = 0; i < n; ++i) {       cin >> a[i];       if (i == 0)         aux[i] = a[i];       else         aux[i] = aux[i - 1] + a[i];     }     for (long long int i = 0; i < m; ++i) cin >> b[i];     long long int j = 0;     for (long long int i = 0; i < m; ++i) {       while (j < n && aux[j] < b[i]) ++j;       if (j == 0)         cout << j + 1 <<     << b[i] << endl;       else         cout << j + 1 <<     << b[i] - aux[j - 1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   set<long long> bms[6];   long long to_bit(string &s) {     long long x = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) continue;       x |= (1LL << i);     }     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     bms[0].insert(0);     for (int j = 1; j <= n; j++) {       for (int i = min(j, 5); i >= 1; i--) {         for (long long x : bms[i - 1]) {           bms[i].insert(x | (1LL << (j - 1)));         }       }     }     int c;     long long x;     string s;     set<long long> poss;     cin >> s >> c;     x = to_bit(s);     for (long long bm : bms[c]) {       poss.insert(~(x ^ bm));     }     for (int i = 1; i < m; i++) {       cin >> s >> c;       x = to_bit(s);       set<long long> tposs;       for (long long bm : bms[c]) {         if (!poss.count(~(x ^ bm))) continue;         tposs.insert(~(x ^ bm));       }       poss = tposs;     }     cout << poss.size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int g[100000], cnt[100000];   int v[100000], b[100000];   int s[100005], sc[100005], sz;   bool used[100005] = {}, dead[100005] = {}, marked[100005] = {};   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(n); ++i) scanf( %d , g + i), --g[i], cnt[i] = 1;     for (int i = 0; i < (int)(m); ++i) scanf( %d , v + i);     for (int i = 0; i < (int)(m); ++i) scanf( %d , b + i);     int prevAns = 0;     for (int q = 0; q < (int)(m); ++q) {       int a = (v[q] + prevAns - 1) % n;       int ans = 0;       int rem = b[q];       --rem;       if (!used[a]) {         ans = 1;         used[a] = true;       }       while (true) {         sz = 0;         while (used[g[a]]) {           if (marked[a] || dead[a]) break;           s[sz] = a;           marked[a] = true;           rem -= cnt[a];           a = g[a];           ++sz;         }         if (marked[a] || dead[a]) {           for (int i = 0; i < (int)(sz); ++i) dead[s[i]] = true;           for (int i = 0; i < (int)(sz); ++i) marked[s[i]] = false;           break;         }         for (int i = 0; i < (int)(sz); ++i) marked[s[i]] = false;         for (int i = sz - 1; i >= 0; --i) {           cnt[s[i]] += cnt[g[s[i]]];           g[s[i]] = g[g[s[i]]];         }         rem -= cnt[a];         if (rem < 0) {           break;         }         a = g[a];         used[a] = true;         ++ans;       }       printf( %d n , ans);       prevAns = ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int a[MAXN];   int b[MAXN];   int tmp[MAXN];   int main() {     int n;     cin >> n;     int aidx;     for (int i = 0; i < n; i++) {       cin >> tmp[i];       if (tmp[i] == 0) aidx = i;     }     for (int i = 0; i < n; i++) a[i] = tmp[(i + aidx) % n];     int bidx;     for (int i = 0; i < n; i++) {       cin >> tmp[i];       if (tmp[i] == 0) bidx = i;     }     for (int i = 0; i < n; i++) b[i] = tmp[(i + bidx) % n];     for (int i = 0; i < n - 1; i++) {       a[i] = a[i + 1];       b[i] = b[i + 1];     }     for (int i = 0; i < n - 1; i++)       if (b[i] == a[0]) bidx = i;     for (int i = 0; i < n - 1; i++)       if (a[i] != b[(i + bidx) % (n - 1)]) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-11;   const int INF = 101e7;   template <class T>   T sqr(T first) {     return first * first;   }   template <class T>   T abs(T first) {     return (first < 0) ? -first : first;   }   int main() {     int n, m, h;     cin >> n >> m >> h;     n--;     int sh = 0, sum = 0;     for (int _b = (m), i = (1); i <= _b; i++) {       if (i == h) {         cin >> sh;         sh--;       } else {         int k;         cin >> k;         sum += k;       }     }     if (n > sh + sum) {       cout <<  -1 n ;       return 0;     }     double c = 1;     for (int i = 0, _n = (n); i < _n; i++) {       c *= (double(sum) / (sum + sh));       sum--;     }     printf( %.8f n , 1 - c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long k;     cin >> k;     long long i = 0, prev = 0;     while (k > prev + (9 * pow(10, i) * (i + 1))) {       prev += 9 * pow(10, i) * (i + 1);       i++;     }     k -= prev;     long long temp;     temp = pow(10, i) + (k / (i + 1)) - 1;     if (k % (i + 1) != 0) {       temp++;     }     if (k % (i + 1) == 0) {       cout << temp % 10 <<   n ;     } else {       long long ans = temp / pow(10, i + 1 - (k % (i + 1)));       ans %= 10;       cout << ans <<   n ;     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t N = 1e3 + 5, M = 1e9 + 7;   int64_t a[N][N];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int64_t n, m, s = 0;     cin >> n >> m;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < m; j++) cin >> a[i][j];     for (int64_t i = n - 2; i; i--)       for (int64_t j = m - 2; j; j--)         if (!a[i][j]) a[i][j] = min(a[i + 1][j], a[i][j + 1]) - 1;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 1; j < m; j++)         if (a[i][j] <= a[i][j - 1]) return cout << -1, 0;     for (int64_t j = 0; j < m; j++)       for (int64_t i = 1; i < n; i++)         if (a[i][j] <= a[i - 1][j]) return cout << -1, 0;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < m; j++) s += a[i][j];     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   long long line[maxn];   int sum, q1, q2;   int flag1, k, qw, wa, flag2;   int main() {     int n, zz = 1;     cin >> n;     for (int i = (int)(1); i < (int)(n + 1); i++) cin >> line[i];     while (zz <= n) {       q1 = 0, q2 = 0, flag1 = 0, k = 0, wa = 0, flag2 = 0;       sum++;       for (int i = (int)(zz); i < (int)(n + 1); i++) {         qw = i;         if (line[i] != -1 && flag1 == 0) {           q1 = line[i];           flag1 = 1;           continue;         }         if (flag1 == 1 && line[i] == -1) {           k++;           continue;         }         if (line[i] == -1 && flag1 == 0) {           wa++;           continue;         }         if (line[i] != -1 && flag1 == 1) {           q2 = line[i];           flag2 = 1;           break;         }       }       zz = qw;       if (qw > n) break;       if (qw == n && (flag2 == 0 || flag1 == 0)) break;       if ((q2 - q1) % (k + 1) != 0) continue;       long long d = (q2 - q1) / (k + 1);       if (q1 - wa * d <= 0) continue;       zz = qw + 1;       while (zz <= n) {         if (line[zz] == -1) {           if (line[zz - 1] + d <= 0) break;           line[zz] = line[zz - 1] + d;           zz++;         } else {           if (line[zz] - line[zz - 1] != d) break;           zz++;         }       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b = 1, c, can[100000 * 10], cc, M, tmp[100000 * 10],                      ans = 0x3f3f3f3f3f3f3f3f, XH;   inline long long cheng(long long u, long long v) {     long long res = 0;     for (; v; v >>= 1) {       if (v & 1) res = (res + u) % M;       u = u * 2 % M;     }     return res;   }   struct Jz {     long long num[2][2];     Jz() { memset(num, 0, sizeof(num)); }     Jz operator*(const Jz &u) const {       Jz res;       long long i, j, k;       for (i = 0; i < 2; i++) {         for (j = 0; j < 2; j++) {           for (k = 0; k < 2; k++) {             res.num[i][j] = (res.num[i][j] + cheng(num[i][k], u.num[k][j])) % M;           }         }       }       return res;     }   } dw;   inline Jz po(Jz u, long long v) {     Jz res;     res.num[0][0] = res.num[1][1] = 1;     for (; v;) {       if (v & 1) res = res * u;       u = u * u;       v >>= 1;     }     return res;   }   inline long long ask(long long u) {     Jz res = po(dw, u);     return res.num[0][0];   }   int main() {     dw.num[0][1] = dw.num[1][0] = dw.num[1][1] = 1;     long long i, j, k, t;     cin >> n;     t = n % 100000;     for (i = 1;; i++) {       if (t == a) can[++cc] = i;       c = (a + b) % 100000;       a = b, b = c;       if (!a && b == 1) break;     }     for (M = 100000 * 10, XH = 150000; M <= (long long)1e13; M *= 10, XH *= 10) {       t = n % M, k = 0;       for (i = 1; i <= cc; i++) {         for (j = 0; j <= 9; j++) {           if (ask(can[i] + XH * j) % M == t) {             tmp[++k] = can[i] + XH * j;           }         }       }       for (i = 1; i <= k; i++) can[i] = tmp[i];       cc = k;     }     if (!cc) {       puts( -1 );       return 0;     }     for (i = 1; i <= cc; i++) ans = min(ans, can[i]);     cout << ans - 1;   }


#include <bits/stdc++.h>   using namespace std;   int store[20][1 << 20];   struct trie {     int k;     struct Node {       Node* ch[2];       Node() { ch[0] = ch[1] = NULL; }     };     Node* root;     trie(int k) : k(k) { root = new Node(); }     void insert(int x) {       Node* cur = root;       for (int i = k - 1; i >= 0; i--) {         int side = x >> i & 1;         if (!cur->ch[side]) cur->ch[side] = new Node();         cur = cur->ch[side];       }     }     void eval() {       vector<int> ret(1 << k);       for (int i = 0; i <= k; i++) fill(store[i], store[i] + (1 << k), 1 << 30);       function<vector<pair<int, int> >(Node*, int)> dfs = [&](Node* node, int h) {         if (!node) return vector<pair<int, int> >();         if (h == 0) {           vector<pair<int, int> > ret = {{0, 0}};           return ret;         }         vector<pair<int, int> > A = dfs(node->ch[0], h - 1),                                 B = dfs(node->ch[1], h - 1);         vector<pair<int, int> > ret(1 << h);         for (int x = 0; x < (1 << h); x++) {           int add = 1 << (h - 1);           int rem = x & (add - 1);           if (x >> (h - 1) & 1) {             ret[x].first = node->ch[1] ? B[rem].first : A[rem].first + add;             ret[x].second = node->ch[0] ? A[rem].second + add : B[rem].second;           } else {             ret[x].first = node->ch[0] ? A[rem].first : B[rem].first + add;             ret[x].second = node->ch[1] ? B[rem].second + add : A[rem].second;           }           if (!A.empty() && !B.empty()) {             if (x >> (h - 1) & 1)               store[h][x] = min(store[h][x], A[rem].first + add - B[rem].second);             else               store[h][x] = min(store[h][x], B[rem].first + add - A[rem].second);           }           assert(max(ret[x].first, ret[x].second) < (1 << h) &&                  min(ret[x].first, ret[x].second) >= 0);         }         return ret;       };       dfs(root, k);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     trie T(k);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       T.insert(x);     }     T.eval();     for (int x = 0; x < (1 << k); x++) {       int ans = 1 << 30;       for (int h = k; h; h--) {         ans = min(ans, store[h][x & ((1 << h) - 1)]);       }       cout << ans <<    ;     }     cout <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   struct app {     int x, y;   };   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int m1, m2;     vector<app> arr(n);     for (__typeof(0) i = 0; i <= n - 1; i++) {       scanf( %d , &arr[i].x);       scanf( %d , &arr[i].y);       if (i == 0) {         m1 = arr[i].x;         m2 = arr[i].y;       } else {         if (arr[i].x * m2 < arr[i].y * m1) {           m1 = arr[i].x;           m2 = arr[i].y;         }       }     }     double ans = m * m1;     ans = ans * 1.0 / m2 * 1.0;     cout << fixed << setprecision(8) << ans;     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     long long s = 0;     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       s += x;     }     long long add = (s - n * (n - 1) / 2) / n;     long long cnt = s - (n * (n - 1) / 2 + add * n);     for (int i = 0; i < n; ++i) {       cout << i + add + int(i < cnt) <<    ;     }   }