#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 105;   const int mod = 998244353;   const double Pi = acos(-1.0);   const long long INF = 1e18;   const int G = 3, Gi = 332748118;   long long qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int T, n, m;   long long dp[105][105], a[105][105];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) scanf( %lld , &a[i][j]);       }       long long res = INF;       for (int x = 1; x <= n; ++x) {         for (int y = 1; y <= m; ++y) {           for (int i = 0; i <= n; ++i)             for (int j = 0; j <= m; ++j) dp[i][j] = INF;           dp[1][0] = 0;           for (int i = 1; i <= n; ++i) {             for (int j = 1; j <= m; ++j) {               long long dis = abs(x - i) + abs(y - j);               if (i <= x && j <= y && a[i][j] >= a[x][y] - dis) {                 dp[i][j] =                     min(dp[i - 1][j], dp[i][j - 1]) + a[i][j] - (a[x][y] - dis);               }               if (i >= x && j >= y && a[i][j] >= a[x][y] + dis) {                 dp[i][j] =                     min(dp[i - 1][j], dp[i][j - 1]) + a[i][j] - (a[x][y] + dis);               }             }           }           res = min(res, dp[n][m]);         }       }       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 100010, inf = 2147483233;   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, q, tot, nxt[MAXN << 1], to[MAXN << 1], fst[MAXN], cnt;   int fa[MAXN], hsh[MAXN], dep[MAXN], f[MAXN][25], HSH[MAXN], size[MAXN];   int mx[MAXN << 2][2], mn[MAXN << 2][2], mx1, mx2, mn1, mn2;   namespace hh {   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = 10 * x + ch -  0 ;     return x * f;   }   const int maxn = 500010;   int n, m, lastans;   int first[maxn], to[maxn << 1], nx[maxn << 1], cnt;   inline void add(int u, int v) {     to[++cnt] = v;     nx[cnt] = first[u];     first[u] = cnt;   }   inline void ins(int u, int v) {     add(u, v);     add(v, u);   }   namespace LCA {   int dep[maxn], bl[maxn], fa[maxn], size[maxn];   inline void dfs1(int x) {     size[x] = 1;     for (int i = first[x]; i; i = nx[i]) {       if (to[i] == fa[x]) continue;       fa[to[i]] = x;       dep[to[i]] = dep[x] + 1;       dfs1(to[i]);       size[x] += size[to[i]];     }   }   inline void dfs2(int x, int col) {     int k = 0;     bl[x] = col;     for (int i = first[x]; i; i = nx[i])       if (dep[to[i]] > dep[x] && size[to[i]] > size[k]) k = to[i];     if (!k) return;     dfs2(k, col);     for (int i = first[x]; i; i = nx[i])       if (dep[to[i]] > dep[x] && to[i] != k) dfs2(to[i], to[i]);   }   inline int lca(int x, int y) {     while (bl[x] != bl[y]) {       if (dep[bl[x]] < dep[bl[y]]) swap(x, y);       x = fa[bl[x]];     }     return dep[x] > dep[y] ? y : x;   }   }  // namespace LCA   namespace SEG {   int root[maxn][2], ls[maxn << 4], rs[maxn << 4], val[maxn << 4], size;   inline void Insert(int &x, int l, int r, int pos, int va) {     if (!x) x = ++size;     val[x] += va;     if (l == r) return;     int mid = (l + r) >> 1;     if (pos <= mid)       Insert(ls[x], l, mid, pos, va);     else       Insert(rs[x], mid + 1, r, pos, va);   }   inline int query(int x, int l, int r, int L, int R) {     if (!x) return 0;     if (L <= l && r <= R) return val[x];     int mid = (l + r) >> 1, ans = 0;     if (L <= mid) ans += query(ls[x], l, mid, L, R);     if (R > mid) ans += query(rs[x], mid + 1, r, L, R);     return ans;   }   }  // namespace SEG   inline int q_dis(int x, int y) {     return LCA::dep[x] + LCA::dep[y] - (LCA::dep[LCA::lca(x, y)] << 1);   }   int size[maxn], f[maxn], vis[maxn], d[maxn], v[maxn], son, root;   int nfa[maxn];   inline void solve(int rt, int type, int x, int fa) {     SEG::Insert(SEG::root[rt][type], 0, n, d[x], v[x]);     for (int i = first[x]; i; i = nx[i]) {       if (to[i] == fa || vis[to[i]]) continue;       d[to[i]] = d[x] + 1;       solve(rt, type, to[i], x);     }   }   inline void getroot(int x, int fa) {     size[x] = 1, f[x] = 0;     for (int i = first[x]; i; i = nx[i]) {       if (to[i] == fa || vis[to[i]]) continue;       getroot(to[i], x);       size[x] += size[to[i]];       f[x] = max(f[x], size[to[i]]);     }     f[x] = max(f[x], son - size[x]);     if (f[x] < f[root]) root = x;   }   inline void work(int x) {     vis[x] = 1;     d[x] = 0;     solve(x, 0, x, 0);     for (int i = first[x]; i; i = nx[i]) {       if (vis[to[i]]) continue;       son = size[to[i]];       root = 0;       d[to[i]] = 1;       getroot(to[i], 0);       solve(root, 1, to[i], x);       nfa[root] = x;       work(root);     }   }   inline int query(int x, int k) {     int ret = SEG::query(SEG::root[x][0], 0, n, 0, k);     for (int i = x; nfa[i]; i = nfa[i]) {       int du = q_dis(x, nfa[i]);       ret += SEG::query(SEG::root[nfa[i]][0], 0, n, 0, k - du);       ret -= SEG::query(SEG::root[i][1], 0, n, 0, k - du);     }     return ret;   }   inline void update(int x, int k) {     int delt = k - SEG::query(SEG::root[x][0], 0, n, 0, 0);     SEG::Insert(SEG::root[x][0], 0, n, 0, delt);     for (int i = x; nfa[i]; i = nfa[i]) {       int du = q_dis(x, nfa[i]);       SEG::Insert(SEG::root[nfa[i]][0], 0, n, du, delt);       SEG::Insert(SEG::root[i][1], 0, n, du, delt);     }   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) v[i] = read();     for (int i = 2; i <= n; i++) {       int u = read(), v = read();       ins(u, v);     }     LCA::dfs1(1);     LCA::dfs2(1, 1);     f[0] = son = n;     getroot(1, 0);     work(root);     while (m--) {       int opt = read(), x = read() ^ lastans, y = read() ^ lastans;       if (opt)         update(x, y);       else         printf( %d n , lastans = query(x, y));     }   }   }  // namespace hh   void dfs(int x) {     hsh[x] = ++tot, HSH[tot] = x;     dep[x] = dep[f[x][0]] + 1;     for (int i = 1; i <= 23; i++) f[x][i] = f[f[x][i - 1]][i - 1];     for (int i = fst[x]; i; i = nxt[i]) dfs(to[i]);   }   int lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     int t = dep[u] - dep[v];     for (int i = 23; i >= 0; i--)       if ((1 << i) & t) u = f[u][i];     if (u == v) return u;     for (int i = 23; i >= 0; i--)       if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];     return f[u][0];   }   void pushup(int x) {     mx[x][0] = max(mx[(x << 1)][0], mx[((x << 1) | 1)][0]);     mx[x][1] = max(min(mx[(x << 1)][0], mx[((x << 1) | 1)][0]),                    max(mx[(x << 1)][1], mx[((x << 1) | 1)][1]));     mn[x][0] = min(mn[(x << 1)][0], mn[((x << 1) | 1)][0]);     mn[x][1] = min(max(mn[(x << 1)][0], mn[((x << 1) | 1)][0]),                    min(mn[(x << 1)][1], mn[((x << 1) | 1)][1]));   }   void build(int x, int l, int r) {     if (l == r) {       mx[x][1] = 0;       mn[x][1] = inf;       mx[x][0] = mn[x][0] = hsh[l];       return;     }     int mid = l + r >> 1;     build((x << 1), l, mid);     build(((x << 1) | 1), mid + 1, r);     pushup(x);   }   void query(int x, int l, int r, int a, int b) {     if (a <= l && r <= b) {       if (mx[x][0] > mx1)         mx2 = mx1, mx1 = mx[x][0];       else if (mx[x][0] > mx2)         mx2 = mx[x][0];       if (mx[x][1] > mx2) mx2 = mx[x][1];       if (mn[x][0] < mn1)         mn2 = mn1, mn1 = mn[x][0];       else if (mn[x][0] < mn2)         mn2 = mn[x][0];       if (mn[x][1] < mn2) mn2 = mn[x][1];       return;     }     int mid = l + r >> 1;     if (a <= mid) query((x << 1), l, mid, a, b);     if (b > mid) query(((x << 1) | 1), mid + 1, r, a, b);   }   void init() {     cin >> n >> q;     for (int i = 2; i <= n; i++) {       f[i][0] = read();       to[++cnt] = i, nxt[cnt] = fst[f[i][0]], fst[f[i][0]] = cnt;     }   }   void work() {     dfs(1);     build(1, 1, n);   }   int a, b;   void gogo() {     mx1 = mx2 = 0;     mn1 = mn2 = inf;     query(1, 1, n, a, b);   }   void print() {     while (q--) {       int l1, l2;       cin >> a >> b;       gogo();       l1 = lca(HSH[mx1], HSH[mn2]);       l2 = lca(HSH[mx2], HSH[mn1]);       if (dep[l1] > dep[l2])         printf( %d %d n , HSH[mn1], dep[l1] - 1);       else         printf( %d %d n , HSH[mx1], dep[l2] - 1);     }   }   int main() {     init();     work();     print();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int from, to, next, w, dir, id;   } e[1500000];   int head[350000];   int in[350000];   int out[350000];   int ans[350000];   int n, m, cont;   void add(int from, int to, int w, int dir, int id) {     e[cont].from = from;     e[cont].to = to;     e[cont].w = w;     e[cont].dir = dir;     e[cont].id = id;     e[cont].next = head[from];     head[from] = cont++;   }   void Top() {     queue<int> s;     s.push(1);     in[1] = out[1] = 0;     while (!s.empty()) {       int u = s.front();       s.pop();       for (int i = head[u]; i != -1; i = e[i].next) {         int v = e[i].to;         int w = e[i].w;         int dir = e[i].dir;         if (v == 1 || (in[v] == out[v] && v != n)) continue;         if (u == 1 || v == n) {           if (u == 1) {             ans[e[i].id] = dir;             in[v] += w;           } else {             ans[e[i].id] = dir;           }         } else {           if (in[v] != out[v]) {             in[v] += w;             ans[e[i].id] = dir;           } else             ans[e[i].id] = 1 - dir;         }         if (in[v] == out[v] && v != n) {           s.push(v);         }       }     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }   int main() {     while (~scanf( %d%d , &n, &m)) {       cont = 0;       memset(in, 0, sizeof(in));       memset(out, 0, sizeof(out));       memset(head, -1, sizeof(head));       for (int i = 1; i <= m; i++) {         int x, y, w;         scanf( %d%d%d , &x, &y, &w);         add(x, y, w, 0, i);         add(y, x, w, 1, i);         out[y] += w;         out[x] += w;       }       for (int i = 1; i <= n; i++) out[i] = out[i] / 2;       Top();     }   }


#include <bits/stdc++.h>   using namespace std;   void solution() {     int n, k;     cin >> n >> k;     vector<long long> v(n * k + 1, 0), brr(n * k + 1, 0);     long long sum = 0;     for (int i = 1; i <= n * k; i++) {       cin >> v[i];       brr[i] = v[i];     }     brr[0] = INT_MAX;     sort(brr.rbegin(), brr.rend());     if (n % 2 == 0) {       int right = n / 2 + 1;       int i = right;       int j = 0;       while (j < k) {         sum = sum + brr[i];         i = i + right;         j++;       }     } else {       int right = n / 2 + n % 2;       int i = right;       int j = 0;       while (j < k) {         sum = sum + brr[i];         i = i + right;         j++;       }     }     cout << sum << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solution();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MXN = 80 + 10;   const long long MX5 = 4e5 + 10;   const long long MX6 = 1e6 + 10;   const long long LOG = 20;   const long long INF = 8e18;   const double eps = 1e-9;   const long long MOD = 1e9 + 7;   long long power(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * power(a * a % md, b / 2, md) % md                         : power(a * a % md, b / 2, md) % md));   }   long long bmm(long long a, long long b) {     return (a % b == 0 ? b : bmm(b, a % b));   }   string base2(long long n) {     string a =   ;     while (n >= 2) {       a += (char)(n % 2 +  0 );       n /= 2;     }     a += (char)(n +  0 );     reverse((a).begin(), (a).end());     return a;   }   long long n;   long long PS[MX5], Ans[MX5], ex[MX5];   vector<long long> second, T;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       second.push_back(x);     }     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       T.push_back(x);     }     PS[0] = T[0];     for (int i = 1; i < n; i++) PS[i] = PS[i - 1] + T[i];     PS[n] = INF;     for (int i = 0; i < n; i++) {       long long men = (i - 1 < 0 ? 0 : PS[i - 1]);       if (second[i] <= T[i]) {         ex[i] += second[i];         continue;       }       long long l = i, r = n;       while (r - l > 1) {         long long mid = (l + r) / 2;         if (PS[mid] - men <= second[i]) {           l = mid;         } else {           r = mid;         }       }       Ans[l + 1]--, Ans[i]++;       if (PS[l] - men < second[i]) {         ex[l + 1] += second[i] - PS[l] + men;       }     }     for (int i = 1; i < n; i++) Ans[i] += Ans[i - 1];     for (int i = 0; i < n; i++) {       cout << Ans[i] * T[i] + ex[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int points(int p, int t) {     int first = 75 * p;     int second = 250 * p - p * t;     return max(first, second);   }   int main() {     int a, b, c, d;     scanf( %d %d %d %d , &a, &b, &c, &d);     int misha = points(a, c);     int vasia = points(b, d);     if (misha > vasia) {       cout <<  Misha  << endl;     } else if (vasia > misha) {       cout <<  Vasya  << endl;     } else {       cout <<  Tie  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxn = 50;   int k, w, h;   int read() {     int x = 0, y = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) y = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();     return x * y;   }   int pw[5];   inline int add(int x) { return x >= mod ? x - mod : x; }   inline int sub(int x) { return x < 0 ? x + mod : x; }   inline int power(int x, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1ll * res * x % mod;       x = 1ll * x * x % mod;       b >>= 1;     }     return res;   }   vector<int> p[6];   int pos[maxn];   void dfs1(int d, int v, int S) {     if (!d) {       v = add(v + 1ll * p[d][0] * w % mod);       pos[p[d][0]] = 1;       if (v == S) {         for (int i = 1; i <= (1 << k); i++) printf( %d  , pos[i]);         puts(  );         exit(0);       }       return;     }     int len = (1 << (d - 1));     p[d - 1].resize(len);     for (int s = 0; s < (1 << len); s++) {       int val = 0;       for (int i = 0; i < len; i++) {         int u = p[d][2 * i], v = p[d][2 * i + 1];         if (s & (1 << i))           p[d - 1][i] = v, pos[u] = len + 1,                 val = add(val + 1ll * u * pw[d - 1] % mod);         else           p[d - 1][i] = u, pos[v] = len + 1,                 val = add(val + 1ll * v * pw[d - 1] % mod);       }       dfs1(d - 1, add(v + val), S);     }     return;   }   unordered_map<int, bool> mp[(1 << 16) + 5];   void dfs2(int S, int d, int v) {     if (!d) {       v = add(v + 1ll * w * p[d][0] % mod);       mp[S][v] = 1;       return;     }     int len = (1 << (d - 1));     p[d - 1].resize(len);     for (int s = 0; s < (1 << len); s++) {       int val = 0;       for (int i = 0; i < len; i++) {         int u = p[d][2 * i], v = p[d][2 * i + 1];         if (s & (1 << i))           p[d - 1][i] = v, val = add(val + 1ll * u * pw[d - 1] % mod);         else           p[d - 1][i] = u, val = add(val + 1ll * v * pw[d - 1] % mod);       }       dfs2(S, d - 1, add(v + val));     }     return;   }   void dfs3(int d, int v) {     if (d == 3) {       int s = 0;       for (int i = 7; i >= 0; i--) s <<= 2, s |= (p[d][i] - 4 * i - 1);       if (mp[s][sub(h - v)]) {         dfs1(d, v, h);         exit(0);       }       return;     }     int len = (1 << (d - 1));     p[d - 1].resize(len);     for (int s = 0; s < (1 << len); s++) {       int val = 0;       for (int i = 0; i < len; i++) {         int u = p[d][2 * i], v = p[d][2 * i + 1];         if (s & (1 << i))           p[d - 1][i] = v, pos[u] = len + 1,                 val = add(val + 1ll * u * pw[d - 1] % mod);         else           p[d - 1][i] = u, pos[v] = len + 1,                 val = add(val + 1ll * v * pw[d - 1] % mod);       }       dfs3(d - 1, add(v + val));     }     return;   }   int main() {     k = read();     w = read();     h = read();     for (int i = 0; i <= 4; i++) pw[i] = power(w, (1 << i) + 1);     if (k <= 4) {       p[k].resize(1 << k);       for (int i = 0; i < p[k].size(); i++) p[k][i] = i + 1;       dfs1(k, 0, h);       puts( -1 );       return 0;     }     for (int s = 0; s < (1 << 16); s++) {       p[3].resize(8);       for (int i = 0; i < 8; i++) {         int op = (s >> (2 * i)) & 3;         p[3][i] = 4 * i + op + 1;       }       dfs2(s, 3, 0);     }     p[5].resize(32);     for (int i = 0; i < p[5].size(); i++) p[5][i] = i + 1;     dfs3(k, 0);     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 6000 + 10;   int n, t, arr[MAXN][MAXN];   void dfs(int i, int j, int val) {     arr[i][j] += val;     if (arr[i][j] < 4) return;     int me = arr[i][j] / 4;     arr[i][j] %= 4;     dfs(i + 1, j, me);     dfs(i - 1, j, me);     dfs(i, j + 1, me);     dfs(i, j - 1, me);     return;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> t;     dfs(MAXN / 2, MAXN / 2, n);     for (int i = 0; i < t; i++) {       int l, r;       cin >> l >> r;       l += MAXN / 2;       r += MAXN / 2;       if (l < 0 || r < 0 || l > MAXN || r > MAXN) {         cout << 0 << endl;         continue;       }       cout << arr[l][r] << endl;     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   struct edge {     int x, y, w, p;     edge() {}     void input() { scanf( %d%d%d%d , &x, &y, &w, &p); }   } E[N], EE[N];   int n;   vector<int> G[N];   long long W[N], WW[N];   void dfs(int x, int y, int id, int mi) {     if (id) {       int tmp = EE[id].p - E[id].p;       tmp = min(mi, tmp);       E[id].p += tmp;       E[id].w += tmp;       mi = min(mi - tmp, E[id].p - (int)W[y]);       WW[id] = tmp;     }     for (int i = 0; i < G[y].size(); i++) {       int ID = G[y][i];       if (id == 0) mi = 2e9;       dfs(E[ID].x, E[ID].y, ID, mi);       mi -= WW[ID];       WW[id] += WW[ID];     }   }   void dfs(int x, int y, int id) {     for (int i = 0; i < G[y].size(); i++) {       int ID = G[y][i];       dfs(E[ID].x, E[ID].y, ID);     }     if (id == 0) return;     if (E[id].p < W[y]) {       puts( -1 );       exit(0);     }     long long tmp = min(E[id].p - W[y], (long long)E[id].w - 1);     E[id].p -= tmp;     E[id].w -= tmp;     W[x] += W[y];     W[x] += E[id].w;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       E[i].input();       EE[i] = E[i];       G[E[i].x].push_back(i);     }     dfs(0, 1, 0);     dfs(0, 1, 0, 2e9);     cout << n << endl;     for (int i = 1; i < n; i++) {       printf( %d %d %d %d n , E[i].x, E[i].y, E[i].w, E[i].p);     }   }


#include <bits/stdc++.h>   using namespace std;   long long unsigned int n;   long long unsigned int val(long long unsigned int x, long long unsigned int k) {     if (x >= 1e10) return n + 1;     long long unsigned int ans = x * (x - 1);     ans /= 2;     long long unsigned int kt = k;     if (ans > n) return n + 1;     while (k--) {       x *= 2;       if (x > 1e19) return n + 1;     }     for (int i = 1; i <= kt; i++) {       ans = ans + x / 2;       if (ans > n) return n + 1;       x /= 2;     }     if (ans > n) return n + 1;     return ans;   }   long long unsigned int calc(long long unsigned int k) {     long long unsigned int lo = 0;     long long unsigned int hi = 1e10;     long long unsigned int mid;     while (hi - lo > 1) {       mid = (hi + lo) / 2;       if (val(2 * mid - 1, k) >= n)         hi = mid;       else         lo = mid;     }     if (val(2 * hi - 1, k) == n) {       return (2 * hi - 1) * (1LL << k);     }     return 0;   }   int main() {     cin >> n;     long long unsigned int g;     vector<long long unsigned int> ans;     for (int i = 0; i <= 60; i++) {       g = calc(i);       if (g != 0) ans.push_back(g);     }     sort(ans.begin(), ans.end());     for (auto x : ans) {       cout << x <<    ;     }     if (ans.size() == 0) cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, t;     int n;     int a[100005];     int b[100005];     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + n);     int cnt = 0;     for (i = 0; i < n; i++) {       if (a[i] != b[i]) cnt++;     }     if (cnt == 0 || cnt == 2)       printf( YES n );     else       printf( NO n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, a[10];   char c[100007];   int main() {     scanf( %d , &n);     scanf( %s , &c);     for (int i = 0; i < n; i++) {       if (c[i] ==  L ) {         for (int j = 0; j < 10; j++) {           if (a[j] == 0) {             a[j] = 1;             break;           }         }       } else if (c[i] ==  R ) {         for (int j = 9; j >= 0; j--) {           if (a[j] == 0) {             a[j] = 1;             break;           }         }       } else {         a[c[i] -  0 ] = 0;       }     }     for (int i = 0; i <= 9; i++) {       printf( %d , a[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     for (int t = 0; t < T; ++t) {       long long int n;       long long int a, b;       cin >> n >> a >> b;       string s;       cin >> s;       long long int bc = n * (a + b) + b;       bool ftram = true;       bool ztram = true;       long long int fzero = -1;       long long int nc = 0;       for (int i = 0; i < n; ++i) {         if (s[i] ==  0 ) {           if (!ztram) {             fzero = i;             ztram = true;           }         } else {           if (ztram) {             if (ftram) {               nc += a;               ftram = false;             } else {               nc += min(2 * a, (i - fzero - 1) * b);             }             ztram = false;             nc += b;           }           nc += b;         }       }       if (!ftram) nc += a;       cout << bc + nc << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); }   double pi = 3.141592653589793238462643;   int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   inline int add(int a, int b, int m = 1000000007) {     a += b;     if (a >= m) a -= m;     return a;   }   inline int mul(int a, int b, int m = 1000000007) {     return (int)(((long long)a * (long long)b) % m);   }   inline bool ispalin(string &str) {     int n = str.length();     for (int i = 0; i < n / 2; i++)       if (str[i] != str[n - i - 1]) return false;     return true;   }   long long expo(long long base, long long pow) {     long long ans = 1;     while (pow != 0) {       if (pow & 1 == 1) {         ans = ans * base;         ans = ans % 1000000007;       }       base *= base;       base %= 1000000007;       pow /= 2;     }     return ans;   }   void swapp(int *a, int *b) {     int temp = *a;     *a = *b;     *b = temp;   }   long long invt(long long x) { return expo(x, 1000000007 - 2); }   int expFactor(int n, int p) {     int x = p;     int exponent = 0;     while ((n / x) > 0) {       exponent += n / x;       x *= p;     }     return exponent;   }   inline int countsetbit(int n) {     unsigned int count = 0;     while (n) {       n &= (n - 1);       count++;     }     return count;   }   inline int abs(int x) {     if (x < 0) return -x;     return x;   }   bool isPal(string ss) {     int len = ss.length();     for (int i = 0; i < len / 2; i++) {       int comp = len - i - 1;       if (ss[i] != ss[comp]) return false;     }     return true;   }   vector<long long> fact, inv;   void calfal(int maxn) {     fact.resize(maxn);     inv.resize(maxn);     fact[0] = inv[0] = inv[1] = 1;     for (int i = (1); i <= (maxn - 1); ++i)       fact[i] = i * fact[i - 1] % 1000000007;     for (int i = (2); i <= (maxn - 1); ++i)       inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;     for (int i = (1); i <= (maxn - 1); ++i)       inv[i] = inv[i] * inv[i - 1] % 1000000007;   }   long long ncr(int n, int r) {     if (r > n) return 0;     return (fact[n] * inv[r] % 1000000007) * inv[n - r] % 1000000007;   }   long long _sieve_size;   bitset<10000010> bs;   vector<int> primes;   void sieve(long long upperbound) {     _sieve_size = upperbound + 1;     bs.set();     bs[0] = bs[1] = 0;     for (long long i = 2; i <= _sieve_size; i++)       if (bs[i]) {         for (long long j = i * i; j <= _sieve_size; j += i) bs[j] = 0;         primes.push_back((int)i);       }   }   bool isPrime(long long N) {     if (N <= _sieve_size) return bs[N];     for (int i = 0; i < (int)primes.size(); i++)       if (N % primes[i] == 0) return false;     return true;   }   map<int, int> v, p;   int main() {     int n, m;     cin >> n >> m;     int d = 0;     for (int i = (0); i <= (m - 1); ++i) {       int k;       cin >> k;       int f = 0;       for (int j = (0); j <= (k - 1); ++j) {         int x;         cin >> x;         if (x > 0) {           v[x] = 1;           if (p[x]) {             f = 1;           }         } else {           x = -x;           p[x] = 1;           if (v[x]) {             f = 1;           }         }       }       if (f == 0) {         d = 1;       } else {         v.clear();         p.clear();       }     }     if (d) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     return (a.second < b.second);   }   int main() {     vector<pair<long long int, long long int>> v;     long long int n, m, k;     cin >> n >> m >> k;     long long int a[n];     for (long long int i = 0; i < n; i++) {       cin >> a[i];       v.push_back(make_pair(a[i], i));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long int beauty = 0;     for (long long int i = 0; i < m * k; i++) {       beauty += v[i].first;     }     cout << beauty <<   n ;     long long int j = 0, q = 0;     int pos[999999];     for (int i = 0; i < n; i++) {       pos[v[i].second] = i;     }     for (int i = 0; i < n; i++) {       if (pos[i] < m * k) {         j++;         if (j == m) {           q++;           if (q < k) {             cout << i + 1 <<    ;             j = 0;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long triple(long long x) {     long long ans = x * max(1LL, x - 1LL) * max(1LL, x - 2LL);     if (x % 2 == 0) {       return x * max(1LL, x - 1LL) * max(1LL, x - 3LL);     }     if (x >= 4 && x % 2 == 0) {       ans /= 2;     }     return ans;   }   int main() {     std::ios::sync_with_stdio(false);     int N;     cin >> N;     long long ans;     switch (N) {       case 1: {         ans = 1;         break;       }       case 2: {         ans = 2;         break;       }       default: {         if (N % 2 != 0) {           ans = N * (N - 1LL) * (N - 2LL);         } else {           ans = (N - 1LL) * (N - 2LL) * (N - 3LL);           long long tmp = N * (N - 1LL);           for (int i = N - 2; i >= 1; i--) {             long long val = lcm(tmp, i);             if (val > ans) {               ans = val;               break;             }           }         }         break;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return a > b; }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) {         return false;       }     }     return true;   }   void primeFactors(int n) {     while (n % 2 == 0) {       cout << 2 <<    ;       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         cout << i <<    ;         n = n / i;       }     }     if (n > 2) {       cout << n <<    ;     }   }   int dayofweek(int d, int m, int y) {     static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};     y -= m < 3;     return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;   }   void BellmanFord(int graph[][3], int V, int E, int src) {     int dis[V];     for (int i = 0; i < V; i++) dis[i] = INT_MAX;     dis[src] = 0;     for (int i = 0; i < V - 1; i++) {       for (int j = 0; j < E; j++) {         if (dis[graph[j][0]] + graph[j][2] < dis[graph[j][1]])           dis[graph[j][1]] = dis[graph[j][0]] + graph[j][2];       }     }     bool flag = true;     for (int i = 0; i < E; i++) {       int x = graph[i][0], y = graph[i][1], weight = graph[i][2];       if (dis[x] != INT_MAX && dis[x] + weight < dis[y]) {         flag = false;         break;       }     }   }   void topoSort(int n, int m, vector<vector<bool>> &e, vector<bool> &visited,                 int x) {     visited[x] = true;     for (int i = n - 1; i >= 0; i--) {       if (e[x][i] and !visited[i]) {         topoSort(n, m, e, visited, i);       }     }     return;   }   void convertGraphToTree(int x, vector<vector<int>> &v, vector<bool> &visited,                           vector<vector<int>> &newedges) {     visited[x] = true;     for (int i = 0; i < v[x].size(); i++) {       if (!visited[v[x][i]]) {         newedges[x].push_back(v[x][i]);         convertGraphToTree(v[x][i], v, visited, newedges);       }     }     return;   }   int subtreeCount(int x, vector<vector<int>> &v, vector<bool> &visited,                    vector<int> &count) {     visited[x] = true;     int ans = 1;     for (int i = 0; i < v[x].size(); i++) {       if (!visited[v[x][i]]) {         ans += subtreeCount(v[x][i], v, visited, count);       }     }     count[x] = ans;     return ans;   }   void helper(int n) {     double ans = 0.0;     for (int i = n; i >= 1; i--) {       double temp = 1.0 / double(i);       ans += temp;     }     cout << ans << endl;     return;   }   int main() {     int n;     cin >> n;     helper(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int ALF_SIZE = 26;   int val[200], sizeB = 1;   struct bor {     char q;     int a[ALF_SIZE];     int val, par;     int go[ALF_SIZE];     int link;     bool updated;     void init(int q) {       this->q = q;       val = par = 0;       link = -1;       updated = 0;       for (int w = 0; w < ALF_SIZE; w++) {         a[w] = -1;         go[w] = -1;       }     }   };   bor a[201];   int go(int c, char v);   int get_link(int c) {     if (a[c].link < 0) {       if ((c == 0) || (a[c].par == 0)) {         a[c].link = 0;       } else {         a[c].link = go(get_link(a[c].par), a[c].q);       }     }     return a[c].link;   }   int go(int c, char v) {     if (a[c].go[v] < 0) {       if (a[c].a[v] >= 0) {         a[c].go[v] = a[c].a[v];       } else {         if (c == 0) {           a[c].go[v] = 0;         } else {           a[c].go[v] = go(get_link(c), v);         }       }     }     return a[c].go[v];   }   char h[201];   int calc_val(int c) {     if (a[c].updated == 0) {       a[c].updated = 1;       a[c].val += calc_val(get_link(c));     }     return a[c].val;   }   long long d[201][201];   void mult(long long **a, long long **s, long long **f) {     int w, e, r;     for (e = 0; e < sizeB; e++) {       for (r = 0; r < sizeB; r++) {         d[e][r] = -1;       }     }     for (w = 0; w < sizeB; w++) {       for (e = 0; e < sizeB; e++) {         for (r = 0; r < sizeB; r++) {           if ((a[w][e] >= 0) && (s[e][r] >= 0)) {             d[w][r] = max(d[w][r], a[w][e] + s[e][r]);           }         }       }     }     for (e = 0; e < sizeB; e++) {       for (r = 0; r < sizeB; r++) {         f[e][r] = d[e][r];       }     }   }   int main() {     int q, w, e, r, t, c, v;     long long len;     a[0].init(0);     cin >> q >> len;     for (w = 0; w < q; w++) {       scanf( %d , &val[w]);     }     for (w = 0; w < q; w++) {       scanf( %s , h);       c = 0;       for (e = 0; h[e]; e++) {         h[e] -=  a ;         if (a[c].a[h[e]] == -1) {           a[sizeB].init(h[e]);           a[sizeB].par = c;           a[c].a[h[e]] = sizeB;           sizeB++;         }         c = a[c].a[h[e]];       }       a[c].val += val[w];     }     for (w = 0; w < sizeB; w++) {       calc_val(w);     }     long long **s = new long long *[sizeB];     long long **d = new long long *[sizeB];     for (e = 0; e < sizeB; e++) {       s[e] = new long long[sizeB];       d[e] = new long long[sizeB];       for (r = 0; r < sizeB; r++) {         s[e][r] = -1;         d[e][r] = -1;       }     }     d[0][0] = 0;     for (e = 0; e < sizeB; e++) {       for (c = 0; c < 26; c++) {         if (a[e].a[c] >= 0) {           v = a[e].a[c];           s[e][v] = max(s[e][v], (long long)(a[v].val));         } else {           v = go(get_link(e), c);           s[e][v] = max(s[e][v], (long long)a[v].val);         }       }     }     for (; len; len /= 2) {       if (len % 2 == 1) {         mult(d, s, d);       }       mult(s, s, s);     }     long long ans = 0;     for (w = 0; w < sizeB; w++) {       ans = max(ans, d[0][w]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double s = 10000000, a, b, m;   int n;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       s = min(s, a / b);     }     printf( %.8f , s * m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if (a > b) swap(a, b);       long long ans = 0;       while (a * 8 <= b) {         a *= 8;         ans++;       }       while (a * 4 <= b) {         a *= 4;         ans++;       }       while (a * 2 <= b) {         a *= 2;         ans++;       }       if (a == b) {         cout << ans <<   n ;       } else {         cout << -1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   int n, m;   vector<int> V[200005];   int res[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = (1); i <= (n); ++i) {       int x;       cin >> x;       V[x].push_back(i);     }     int RR = 1;     for (int i = (1); i <= (m); ++i) {       int x;       cin >> x;       if (V[x].size() > 1 && RR == 1) {         RR = 2;       } else if (V[x].size() == 0) {         RR = 0;       }       if (RR == 1) {         res[i] = V[x][0];       }     }     if (!RR) {       cout <<  Impossible  << endl;     } else if (RR == 1) {       cout <<  Possible  << endl;       for (int i = (1); i <= (m); ++i) cout << res[i] <<    ;     } else {       cout <<  Ambiguity  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 7;   char s[maxn];   int sa[maxn], str[maxn], _rank[maxn], height[maxn];   int t1[maxn], t2[maxn], c[maxn];   int RMQ[maxn], mm[maxn], best[20][maxn], len;   bool cmp(int *r, int a, int b, int l) {     return r[a] == r[b] && r[a + l] == r[b + l];   }   void da(int n, int m) {     int i, j, p, *x = t1, *y = t2;     for (i = 0; i < m; i++) c[i] = 0;     for (i = 0; i < n; i++) c[x[i] = str[i]]++;     for (i = 1; i < m; i++) c[i] += c[i - 1];     for (i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;     for (j = 1; j <= n; j <<= 1) {       p = 0;       for (i = n - j; i < n; i++) y[p++] = i;       for (i = 0; i < n; i++)         if (sa[i] >= j) y[p++] = sa[i] - j;       for (i = 0; i < m; i++) c[i] = 0;       for (i = 0; i < n; i++) c[x[y[i]]]++;       for (i = 1; i < m; i++) c[i] += c[i - 1];       for (i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];       swap(x, y);       p = 1;       x[sa[0]] = 0;       for (i = 1; i < n; i++)         x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;       if (p >= n) break;       m = p;     }     int k = 0;     n--;     for (i = 0; i <= n; i++) _rank[sa[i]] = i;     for (i = 0; i < n; i++) {       if (k) k--;       j = sa[_rank[i] - 1];       while (str[i + k] == str[j + k]) k++;       height[_rank[i]] = k;     }   }   void initRMQ(int n) {     mm[0] = -1;     for (int i = 1; i <= n; i++)       mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1];     for (int i = 1; i <= n; i++) best[0][i] = i;     for (int i = 1; i <= mm[n]; i++)       for (int j = 1; j + (1 << i) - 1 <= n; j++) {         int a = best[i - 1][j];         int b = best[i - 1][j + (1 << (i - 1))];         if (RMQ[a] < RMQ[b])           best[i][j] = a;         else           best[i][j] = b;       }   }   int askRMQ(int a, int b) {     int t = mm[b - a + 1];     b -= (1 << t) - 1;     a = best[t][a];     b = best[t][b];     return RMQ[a] < RMQ[b] ? a : b;   }   int lcp(int a, int b) {     if (a == b) return len - a;     a = _rank[a];     b = _rank[b];     if (a > b) swap(a, b);     return height[askRMQ(a + 1, b)];   }   int _stack[maxn][2];   int main() {     int q, lim, x;     scanf( %d%d , &len, &q);     scanf( %s , s);     for (int i = 0; i < len; i++) str[i] = s[i];     str[len] = 0;     da(len + 1, 256);     for (int i = 1; i <= len; i++) RMQ[i] = height[i];     initRMQ(len);     while (q--) {       int n, m;       long long ans = 0;       vector<pair<int, int> > Q;       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; i++) scanf( %d , &x), Q.emplace_back(x - 1, 1);       for (int i = 1; i <= m; i++) scanf( %d , &x), Q.emplace_back(x - 1, 0);       sort(Q.begin(), Q.end(),            [](const pair<int, int> &L, const pair<int, int> &R) {              if (L.first == R.first) return L.second < R.second;              int l = lcp(L.first, R.first);              return s[L.first + l] < s[R.first + l];            });       int sz = Q.size();       for (int ss = 0; ss < 2; ss++) {         long long tot = 0;         map<int, int> W;         for (int i = 0; i < sz; i++) {           int id = Q[i].first;           int state = Q[i].second;           if (state == 0)             ans += tot;           else             W[len - id]++, tot += len - id;           if (i < sz - 1) {             int LCP = lcp(Q[i].first, Q[i + 1].first);             while (!W.empty()) {               auto it = --W.end();               if (it->first <= LCP) break;               tot -= 1LL * (it->first - LCP) * it->second;               W[LCP] += it->second;               W.erase(it);             }           }         }         reverse(Q.begin(), Q.end());       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, s, e, cc, sz, t, l, r;   long long tt[150000];   void inc(int i, long long w) {     for (; i <= n; i |= i + 1) tt[i] += w;   }   long long sum(int i) {     long long sum = 0;     for (; i >= 0; i = (i & (i + 1)) - 1) sum += tt[i];     return sum;   }   long long que(int l, int r) {     if (l > r) swap(l, r);     return sum(r) - sum(l - 1);   }   int conv(int i) {     if (!cc)       return i + s;     else       return e - i;   }   int main() {     cin >> n >> q;     e = n - 1;     for (int i = 0; i < n; i++) inc(i, 1);     while (q--) {       sz = e - s + 1;       cin >> t >> l;       if (t == 1) {         if (!(sz / 2 >= l)) {           l = sz - l;           cc ^= 1;         }         for (int i = 1; i <= l; i++)           inc(conv(2 * l - i), que(conv(i - 1), conv(i - 1)));         if (!cc)           s += l;         else           e -= l;       } else {         cin >> r;         cout << que(conv(l), conv(r - 1)) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, curr;   vector<long long int> v;   void start() {     cin >> n;     int times = 0;     bool flag = false;     for (int i = 0; i < n; i++) {       cin >> a;       if (i == 0) {         curr = a;         times++;         if (i == n - 1) v.push_back(times);         continue;       } else if (curr != a) {         v.push_back(times);         times = 1;         if (i == n - 1) v.push_back(times);         curr = a;       } else {         times++;         if (i == n - 1) v.push_back(times);       }     }     long long int sol = 0;     for (int i = 0; i < v.size(); i++) {       long long int t = v[i];       sol += (t * (t + 1)) / 2;     }     cout << sol <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     start();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int minx, maxx, miny, maxy, sumofarea = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (i == 0) {         minx = x1;         maxx = x2;         miny = y1;         maxy = y2;       } else {         minx = min(minx, x1);         maxx = max(maxx, x2);         miny = min(miny, y1);         maxy = max(maxy, y2);       }       sumofarea += ((x2 - x1) * (y2 - y1));     }     int final_square_area = (maxx - minx) * (maxy - miny);     int lengthofside1 = maxx - minx;     int lengthofside2 = maxy - miny;     if (sumofarea == final_square_area && (lengthofside1 == lengthofside2)) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T, typename TT>   inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {     return os << t.first <<     << t.second;   }   template <typename T>   inline ostream &operator<<(ostream &os, const vector<T> &t) {     for (auto i : t) os << i <<    ;     return os;   }   template <typename T>   inline istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T1, typename T2>   inline istream &operator>>(istream &is, pair<T1, T2> &t) {     is >> t.first >> t.second;     return is;   }   const long long mod = 1e9 + 7;   void solve() {     int a, b, c, d;     cin >> a >> b >> c >> d;     vector<string> s(50, string(50,  D ));     for (int i = 0; i < 36; i++) {       for (int j = 0; j < 50; j++) {         s[i][j] = char( A  + (i / 12));       }     }     a--, b--, c--, d--;     for (int i = 1; i < 11; i += 2) {       for (int j = 0; j < 50 and b; j += 2, b--) s[i][j] =  B ;     }     for (int i = 13; i < 23; i += 2) {       for (int j = 0; j < 50 and c; j += 2, c--) s[i][j] =  C ;     }     for (int i = 25; i < 35; i += 2) {       for (int j = 0; j < 50 and d; j += 2, d--) s[i][j] =  D ;     }     for (int i = 37; i < 50; i += 2) {       for (int j = 0; j < 50 and a; j += 2, a--) s[i][j] =  A ;     }     cout << 50 <<     << 50 <<   n ;     for (auto x : s) cout << x <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a;       int b;       cin >> a;       cin >> b;       if (a != b) {         cout <<  Happy Alex ;         return 0;       }     }     cout <<  Poor Alex ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long int mod = 1e9 + 7;   const long long int mod1 = 998244353;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int rand(long long int l, long long int r) {     uniform_int_distribution<long long int> uid(l, r);     return uid(rng);   }   const long long int N = 2e5 + 5;   long long int lazy[4 * N], tr[4 * N];   long long int a[N], b[N], c[N];   void build(long long int nd, long long int s, long long int e) {     if (s == e) {       tr[nd] = b[s];       return;     }     long long int m = (s + e) >> 1;     build(nd << 1, s, m);     build(nd << 1 | 1, m + 1, e);     tr[nd] = min(tr[nd << 1], tr[nd << 1 | 1]);   }   void push_down(long long int nd, long long int s, long long int e) {     if (lazy[nd]) {       tr[nd] += lazy[nd];       if (s != e) {         lazy[nd << 1] += lazy[nd];         lazy[nd << 1 | 1] += lazy[nd];       }       lazy[nd] = 0;     }   }   void update(long long int nd, long long int s, long long int e, long long int l,               long long int r, long long int x) {     push_down(nd, s, e);     if (s > r || e < l) return;     if (l <= s && e <= r) {       lazy[nd] += x;       push_down(nd, s, e);       return;     }     long long int m = (s + e) >> 1;     update(nd << 1, s, m, l, r, x);     update(nd << 1 | 1, m + 1, e, l, r, x);     tr[nd] = min(tr[nd << 1], tr[nd << 1 | 1]);   }   vector<pair<long long int, long long int> > g[N];   void build1(long long int nd, long long int s, long long int e) {     if (s == e) {       tr[nd] = a[s] + c[s];       return;     }     long long int m = (s + e) >> 1;     build1(nd << 1, s, m);     build1(nd << 1 | 1, m + 1, e);     tr[nd] = min(tr[nd << 1], tr[nd << 1 | 1]);   }   void update1(long long int nd, long long int s, long long int e,                long long int idx, long long int x) {     if (s == e) {       a[s] = x;       tr[nd] = x + c[s];       return;     }     long long int m = (s + e) >> 1;     if (idx <= m)       update1(nd << 1, s, m, idx, x);     else       update1(nd << 1 | 1, m + 1, e, idx, x);     tr[nd] = min(tr[nd << 1], tr[nd << 1 | 1]);   }   void solve() {     long long int n, m, q;     cin >> n >> m >> q;     for (long long int i = 1; i <= n - 1; i++) {       cin >> a[i] >> b[i];     }     build(1, 0, n - 1);     for (long long int i = 1; i <= m; i++) {       long long int x, y, z;       cin >> x >> y >> z;       g[x].push_back({y, z});     }     for (long long int i = 1; i <= n; i++) {       for (pair<long long int, long long int> x : g[i]) {         update(1, 0, n - 1, 0, x.first - 1, x.second);       }       c[i] = tr[1];     }     build1(1, 1, n);     cout << tr[1] <<   n ;     for (long long int i = 1; i <= q; i++) {       long long int v, x;       cin >> v >> x;       update1(1, 1, n, v, x);       cout << tr[1] <<   n ;     }   }   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     clock_t clk = clock();     long long int t;     t = 1;     for (long long int i = 1; i <= t; i++) {       solve();     }     cerr <<   n           << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a;     int b;     int idx;     int k;     int actor;     node() {}     node(int a, int b, int idx, int k, int actor)         : a(a), b(b), idx(idx), k(k), actor(actor) {}   };   const int MAXN = (int)1e5 + 5;   set<node> s;   vector<node> v;   int res[MAXN];   bool operator<(const node &x, const node &y) {     return x.b < y.b || (x.b == y.b && x.idx < y.idx);   }   bool comp(const node &x, const node &y) {     return x.a < y.a || (x.a == y.a && x.actor > y.actor);   }   int main(void) {     int n, m;     int a, b;     int c, d, k;     scanf(  %d , &n);     for (int i = 0; i < n; i++) {       scanf(  %d %d , &a, &b);       v.push_back(node(a, b, i, 0, 0));     }     scanf(  %d , &m);     for (int i = 1; i <= m; i++) {       scanf(  %d %d %d , &c, &d, &k);       v.push_back(node(c, d, i, k, 1));     }     sort(v.begin(), v.end(), comp);     int ok = 1;     for (int i = 0; i < (int)v.size(); i++) {       a = v[i].a;       b = v[i].b;       k = v[i].k;       int idx = v[i].idx;       int actor = v[i].actor;       if (actor) {         s.insert(v[i]);       } else {         v[i].idx = 0;         set<node>::iterator it = s.lower_bound(v[i]);         if (it == s.end()) {           ok = 0;         } else {           node aux = *it;           res[idx] = aux.idx;           s.erase(it);           aux.k--;           if (aux.k > 0) {             s.insert(aux);           }         }       }     }     if (ok) {       printf( YES n );       for (int i = 0; i < n; i++) {         if (i != 0) {           printf(   );         }         printf( %d , res[i]);       }     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const int INF = 0x3f3f3f3f;   int n, s;   int a[maxn << 1], vis[maxn], nxt[maxn << 1][maxn], prv[maxn << 1][maxn],       lst[maxn];   int f[maxn][maxn], h[maxn][maxn];   vector<int> g[maxn][maxn];   vector<int> vec;   vector<int> pos[maxn];   inline void disC(int p1, int p2, int &nf, vector<int> &ng) {     if (p1 > p2) p2 += n;     nf += p2 - p1;     ng.push_back(p2 - p1);     return;   }   inline void disR(int p1, int p2, int &nf, vector<int> &ng) {     if (p1 < p2) p1 += n;     nf += p1 - p2;     ng.push_back(p2 - p1);     return;   }   inline bool between(int x, int y, int z) {     x %= n;     y %= n;     z %= n;     if (z <= x) z += n;     if (y < x) y += n;     return y > x && y < z;   }   inline void calcCGB(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = prv[p1 + n][a[p2]] % n;     if (between(p2, to, p1)) {       disC(p1, p2, resf, resg);       disC(p2, to, resf, resg);       disR(to, p2, resf, resg);     } else       disC(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcCBG(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = nxt[p2][a[p2]] % n;     if (between(p2, to, p1)) {       disR(p1, to, resf, resg);       disC(to, p2, resf, resg);     } else       disC(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcRGB(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = nxt[p1][a[p2]] % n;     if (between(p1, to, p2)) {       disR(p1, to, resf, resg);       disC(to, p2, resf, resg);     } else       disR(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;     return;   }   inline void calcRBG(int p1, int p2, int &nf, vector<int> &ng) {     int resf = 0;     vector<int> resg;     resg.clear();     int to = prv[p2 + n][a[p2]] % n;     if (between(p1, to, p2)) {       disC(p1, to, resf, resg);       disR(to, p2, resf, resg);     } else       disR(p1, p2, resf, resg);     if (resf < nf) nf = resf, ng = resg;   }   inline void calc(int p1, int p2, int &nf, vector<int> &ng) {     nf = INF;     calcCGB(p1, p2, nf, ng);     calcCBG(p1, p2, nf, ng);     calcRGB(p1, p2, nf, ng);     calcRBG(p1, p2, nf, ng);     return;   }   inline void print(int x) {     printf( %c%d n , x < 0 ?  -  :  + , abs(x));     return;   }   int x, dlt;   inline void go(int i, int j) {     if (i > 0) go(i - 1, h[i][j]);     for (int k = (0); k < (g[i][j].size()); ++k) {       int d = (g[i][j][k] < 0 ? -1 : 1), len = abs(g[i][j][k]);       for (int l = (0); l <= (len); ++l) {         if (a[x] == i && !vis[x]) print(dlt), dlt = 0, vis[x] = true;         ((x += d) += n) %= n;         dlt += d;       }       ((x -= d) += n) %= n;       (dlt -= d);     }     return;   }   int main() {     scanf( %d%d , &n, &s);     --s;     for (int i = (0); i < (n); ++i) {       scanf( %d , a + i);       vec.push_back(a[i]);     }     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());     int mx = 0;     for (int i = (0); i < (n); ++i) {       a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin(),       mx = max(mx, a[i]);       pos[a[i]].push_back(i);     }     for (int i = (0); i < (n); ++i) a[n + i] = a[i];     memset(lst, -1, sizeof(lst));     for (int i = (n << 1) - 1; i >= 0; --i) {       for (int j = (0); j <= (mx); ++j) nxt[i][j] = lst[j];       lst[a[i]] = i;     }     memset(lst, -1, sizeof(lst));     for (int i = (0); i < (n << 1); ++i) {       for (int j = (0); j <= (mx); ++j) prv[i][j] = lst[j];       lst[a[i]] = i;     }     memset(f, 0x3f, sizeof(f));     for (int i = (0); i < (pos[0].size()); ++i)       calc(s, pos[0][i], f[0][i], g[0][i]);     for (int i = (1); i <= (mx); ++i)       for (int j = (0); j < (pos[i].size()); ++j)         for (int k = (0); k < (pos[i - 1].size()); ++k)           if (f[i - 1][k] != INF) {             int nf = 0;             vector<int> ng;             calc(pos[i - 1][k], pos[i][j], nf, ng);             nf += f[i - 1][k];             if (nf < f[i][j]) f[i][j] = nf, g[i][j] = ng, h[i][j] = k;           }     int best = -1;     for (int i = (0); i < (pos[mx].size()); ++i)       if (!~best || f[mx][i] < f[mx][best]) best = i;     printf( %d n , f[mx][best]);     x = s, dlt = 0;     go(mx, best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int a[N], sum[N], f[N], ans[N];   int n, r, c;   char ch[N * 6];   int main() {     scanf( %d%d%d , &n, &r, &c);     for (int i = 1; i <= n; i++) {       scanf( %s , ch + sum[i - 1] + 2);       a[i] = strlen(ch + sum[i - 1] + 2);       sum[i] = sum[i - 1] + 1 + a[i];     }     for (int i = 1; i <= n; i++)       for (f[i] = max(f[i - 1], i); f[i] <= n && sum[f[i]] - sum[i - 1] - 1 <= c;            f[i]++)         ;     f[n + 1] = n + 1;     for (int i = 1; i <= n; i++) ans[i] = i;     for (; r; r >>= 1)       for (int i = 1; i <= n; i++) {         if (r & 1) ans[i] = f[ans[i]];         f[i] = f[f[i]];       }     int pos = 1;     for (int i = 2; i <= n; i++)       if (ans[i] - i > ans[pos] - pos) pos = i;     int last = 0;     for (int i = pos; i <= ans[pos] - 1; i++) {       if (last + a[i] > c) {         last = 0;         puts(  );       }       if (last) putchar(   );       last += a[i] + 1;       printf( %s , ch + sum[i - 1] + 2);     }     return 0;   }


#include <bits/stdc++.h>   inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); }   inline void out(int MAGNUS) { printf( %d n , MAGNUS); }   inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); }   inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); }   inline void inl(long long &LIV) { scanf( %lld , &LIV); }   inline void inl(long long &LIV, long long &MART) {     scanf( %lld%lld , &LIV, &MART);   }   inline void outl(long long LIV) { printf( %lld n , LIV); }   inline void outl(long long LIV, long long MART) {     printf( %lld %lld n , LIV, MART);   }   using namespace std;   int R;   string s, res;   vector<string> kata;   bool ok(int C) {     int r = 1, c = 0;     for (int i = 0; i <= (int)kata.size() - 1; i++) {       if (kata[i].size() > C) return 0;       if (c + (int)kata[i].size() <= C) {         c += (int)kata[i].size();       } else {         r++;         c = 0;         c += (int)kata[i].size();       }     }     return r <= R;   }   int main() {     in(R);     getchar();     getline(cin, s);     res =   ;     for (int i = 0; i <= (int)s.size() - 1; i++) {       if (s[i] ==    ) s[i] =  . ;       res += (char)s[i];       if (!isalpha(s[i])) {         kata.push_back(res);         res =   ;       }     }     kata.push_back(res);     int lo = 1, hi = (int)s.size(), ans = 1 << 30;     while (lo <= hi) {       int mid = (lo + hi) / 2;       if (ok(mid)) {         hi = mid - 1;         ans = mid;       } else         lo = mid + 1;     }     out(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     long long int mn, mx, noob;     cin >> t;     while (t--) {       long long int flag = 0;       cin >> mn >> mx >> noob;       if (mn > mx) swap(mx, mn);       if (noob >= mn) {         cout << mn << endl;         flag = 1;         continue;       }       long long int ans = 0;       ans = noob;       mn -= noob;       mx -= noob;       long long int p = (mx - mn);       if (p > mn)         ans += mn;       else {         ans += p;         mx -= p * 2;         mn -= p;         ans += (mn + mx) / 3;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long DP[100005][25];   long long arr[100005];   long long l = 1, r, ans;   long long freq[100005];   void alter_range(long long l1, long long r1) {     while (l1 < l) {       ans += freq[arr[l - 1]];       freq[arr[l - 1]]++;       l--;     }     while (r < r1) {       ans += freq[arr[r + 1]];       freq[arr[r + 1]]++;       r++;     }     while (l < l1) {       ans -= freq[arr[l]] - 1;       freq[arr[l]]--;       l++;     }     while (r1 < r) {       ans -= freq[arr[r]] - 1;       freq[arr[r]]--;       r--;     }   }   void make_layer(long long layer, long long l1, long long r1, long long a,                   long long b) {     if (l1 > r1) return;     long long i, j, mid = (l1 + r1) >> 1, &curr = DP[mid][layer], best = mid;     for (i = a; i <= min(b, mid); i++) {       alter_range(i, mid);       if (curr > DP[i - 1][layer - 1] + ans) {         curr = DP[i - 1][layer - 1] + ans;         best = i;       }     }     make_layer(layer, l1, mid - 1, a, best);     make_layer(layer, mid + 1, r1, best, b);   }   int main() {     long long i, j, n, k;     scanf( %lld %lld , &n, &k);     for (i = 1; i <= n; i++) scanf( %lld , &arr[i]);     for (i = 0; i <= n; i++)       for (j = 0; j <= k; j++) DP[i][j] = 1e18;     DP[0][0] = 0;     for (i = 1; i <= k; i++) {       make_layer(i, 1, n, 1, n);     }     printf( %lld n , DP[n][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long aa[N + 2], bb[N + 2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long k1, k2, k3;     cin >> k1 >> k2 >> k3;     long long t1, t2, t3;     cin >> t1 >> t2 >> t3;     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> aa[i], bb[i] = aa[i];     multiset<long long> st;     vector<long long> v;     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k1) {         st.insert(aa[i] + t1 - 1);         v.push_back(aa[i] + t1);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t1);         v.push_back(x + t1 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k2) {         st.insert(aa[i] + t2 - 1);         v.push_back(aa[i] + t2);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t2);         v.push_back(x + t2 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     for (long long i = 1; i <= n; i++) {       while (true) {         if (st.size() == 0) break;         long long x = *st.begin();         if (x < aa[i])           st.erase(st.find(x));         else           break;       }       if (st.size() < k3) {         st.insert(aa[i] + t3 - 1);         v.push_back(aa[i] + t3);       } else {         long long x = *st.begin();         st.erase(st.find(x));         st.insert(x + t3);         v.push_back(x + t3 + 1);       }     }     for (long long i = 1; i <= n; i++) aa[i] = v[i - 1];     v.clear();     st.clear();     long long mx = 0;     for (long long i = 1; i <= n; i++) mx = max(mx, aa[n] - bb[n]);     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int main() {     int n;     scanf( %d , &n);     int q = n / 3;     int r = n % 3;     if (r > 0) {       printf( %d , 2 * q + 1);     } else {       printf( %d , 2 * q);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long T, n;   long long getFirst(long long n) {     long long cur = 4;     while (n > cur) {       n -= cur;       cur *= 4;     }     return cur + n - 1;   }   long long getSecond(long long n) {     long long cur = 4;     while (n > cur) {       n -= cur;       cur *= 4;     }     n--;     vector<long long> d;     while (n) {       d.push_back(n % 4);       n /= 4;     }     long long f[4] = {0, 2, 3, 1};     reverse(d.begin(), d.end());     for (auto i : d) n = n * 4ll + f[i];     return 2ll * cur + n;   }   long long getThird(long long n) { return getFirst(n) ^ getSecond(n); }   int init() {     scanf( %lld , &n);     if (n <= 3) return printf( %lld n , n), 0;     if (n % 3 == 1) return printf( %lld n , getFirst(n / 3));     if (n % 3 == 2) return printf( %lld n , getSecond(n / 3));     return printf( %lld n , getThird(n / 3 - 1));   }   int main() {     scanf( %lld , &T);     while (T--) init();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k, a[1200000];   int n;   int main() {     cin >> a[0] >> k;     n = 0;     while ((a[n] >= k) || (a[n] < 0)) {       if (a[n] >= k) {         long long x = a[n] / k;         a[n] -= k * x;         a[++n] = -x;       } else {         long long x = (-a[n] + k - 1) / k;         a[n] += k * x;         a[++n] = x;       }     }     cout << n + 1 << endl;     for (int i = 0; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0, ans1 = 0, ans2 = 0, tar;     cin >> n;     tar = n / 3;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       int val = s[i] -  0 ;       if (val == 0)         ans++;       else if (val == 1)         ans1++;       else         ans2++;     }     for (int i = 0; tar > ans; i++) {       if (i == n) break;       if (s[i] ==  1  and tar < ans1) {         s[i] =  0 ;         ans++;         ans1--;         continue;       }       if (s[i] ==  2  and tar < ans2) {         s[i] =  0 ;         ans++;         ans2--;         continue;       }     }     for (int i = n - 1; (tar < ans1) and ans2 < tar; i--) {       if (i < 0) break;       if (s[i] ==  1 ) {         s[i] =  2 ;         ans2++;         ans1--;       }     }     for (int i = n - 1; (tar < ans) and ans2 < tar; i--) {       if (i < 0) break;       if (s[i] ==  0 ) {         s[i] =  2 ;         ans2++;         ans--;       }     }     for (int i = 0; (tar < ans2) and ans1 < tar; i++) {       if (i == n) break;       if (s[i] ==  2 ) {         s[i] =  1 ;         ans1++;         ans2--;       }     }     for (int i = n - 1; (tar < ans) and ans1 < tar; i--) {       if (i < 0) break;       if (s[i] ==  0 ) {         s[i] =  1 ;         ans1++;         ans--;       }     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   inline int sign(double x) {     if (x < -eps) return -1;     return x > eps;   }   struct Tpoint {     double x, y;     Tpoint() {}     Tpoint(double x, double y) : x(x), y(y) {}     inline double norm() { return sqrt(x * x + y * y); }     inline void rotate(double ang) {       double co = cos(ang), si = sin(ang);       double tx = x, ty = y;       x = tx * co - ty * si;       y = tx * si + ty * co;     }   };   inline Tpoint operator+(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x + b.x, a.y + b.y);   }   inline Tpoint operator-(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x - b.x, a.y - b.y);   }   inline Tpoint operator*(const Tpoint &a, const double &b) {     return Tpoint(a.x * b, a.y * b);   }   inline Tpoint operator/(const Tpoint &a, const double &b) {     return Tpoint(a.x / b, a.y / b);   }   inline double det(const Tpoint &a, const Tpoint &b) {     return a.x * b.y - a.y * b.x;   }   inline double dot(const Tpoint &a, const Tpoint &b) {     return a.x * b.x + a.y * b.y;   }   const int dx[] = {-1, -1, 1, 1};   const int dy[] = {-1, 1, -1, 1};   int main() {     int n, m, x, y;     scanf( %d%d , &n, &m);     char sdir[100];     scanf( %d%d%s , &x, &y, sdir);     int dir = 0;     if (sdir[0] ==  D ) {       dir |= 2;     }     if (sdir[1] ==  R ) {       dir |= 1;     }     int target = 0;     for (int i = 1; i <= n; ++i) {       if ((i + 1) % 2 == (x + y) % 2) {         ++target;       }       if ((i + m) % 2 == (x + y) % 2) {         ++target;       }     }     for (int i = 2; i < m; ++i) {       if ((i + 1) % 2 == (x + y) % 2) {         ++target;       }       if ((i + n) % 2 == (x + y) % 2) {         ++target;       }     }     set<pair<int, int> > visit;     long long total_time = 1;     for (int t = 0; t < (n + m) * 4; ++t) {       visit.insert(make_pair(x, y));       if ((int)visit.size() == target) {         printf( %I64d n , total_time);         return 0;       }       int l = 0, r = max(n, m) + 1;       while (l + 1 < r) {         int mid = (l + r) / 2;         int xx = x + dx[dir] * mid;         int yy = y + dy[dir] * mid;         if (xx >= 1 && xx <= n && yy >= 1 && yy <= m) {           l = mid;         } else {           r = mid;         }       }       total_time += l;       x += dx[dir] * l;       y += dy[dir] * l;       if (x == 1 || x == n) {         dir ^= 2;       }       if (y == 1 || y == m) {         dir ^= 1;       }       if (x == 1 && y == 1) {         dir = 3;       } else if (x == 1 && y == m) {         dir = 2;       } else if (x == n && y == 1) {         dir = 1;       } else if (x == n && y == m) {         dir = 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int i, j, n, k, c = 0;     int a[100];     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) {       if (a[i] <= k) {         c++;       } else         break;     }     for (i = n - 1; i >= 0; i--) {       if (a[i] <= k) {         c++;       } else         break;     }     if (c > n) c = n;     printf( %d n , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long b;     while (cin >> b) {       long long ans = 0;       long long i;       for (i = 1; i * i < b; i++) {         if (b % i == 0) ans += 2;       }       if (i * i == b) ans++;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, ans = 0, sum = 0, sum2 = 0;       cin >> n;       int a[n + 1];       a[0] = 0;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a, a + (n + 1));       for (int i = 1; i <= n; i++) {         sum = (sum, a[i]);         sum2++;         if ((ans + sum2) >= sum) {           ans += sum2;           sum2 = 0;         }       }       cout << ans + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100000];   int n, k;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int l = 0, r = n;     while (r - l > 1) {       int m = (l + r) / 2;       if ((long long)k > (long long)m * (m + 1) / 2)         l = m;       else         r = m;     }     printf( %d , a[k - l * (l + 1) / 2 - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ls[2005], rs[2005], fa[2005], sz[2005], z[2005];   int id, n, m, rt, mn, Sz;   char s[10];   void getrt(int x, int F) {     sz[x] = 1;     int mx = 0;     if (ls[x] && ls[x] != F && !z[ls[x]]) {       getrt(ls[x], x);       sz[x] += sz[ls[x]];       if (sz[ls[x]] > mx) mx = sz[ls[x]];     }     if (rs[x] && rs[x] != F && !z[rs[x]]) {       getrt(rs[x], x);       sz[x] += sz[rs[x]];       if (sz[rs[x]] > mx) mx = sz[rs[x]];     }     if (fa[x] && fa[x] != F && !z[fa[x]]) {       getrt(fa[x], x);       sz[x] += sz[fa[x]];       if (sz[fa[x]] > mx) mx = sz[fa[x]];     }     if (Sz - sz[x] > mx) mx = Sz - sz[x];     if (mx < mn || (mx == mn && x > rt)) mn = mx, rt = x;   }   int getsz(int x, int F) {     sz[x] = 1;     if (ls[x] && ls[x] != F && !z[ls[x]]) sz[x] += getsz(ls[x], x);     if (rs[x] && rs[x] != F && !z[rs[x]]) sz[x] += getsz(rs[x], x);     if (fa[x] && fa[x] != F && !z[fa[x]]) sz[x] += getsz(fa[x], x);     return sz[x];   }   int getleaf(int x) { return x <= n ? x : getleaf(ls[x]); }   void dfs(int x) {     z[x] = 1;     if (x <= n) {       m++;       if (ls[fa[x]] == x)         ls[fa[x]] = m;       else         rs[fa[x]] = m;       fa[m] = fa[x];       fa[x] = m;       fa[id] = m;       ls[m] = x;       rs[m] = id;       return;     }     int a1 = getleaf(ls[x]);     int a2 = getleaf(rs[x]);     printf( %d %d %d n , a1, a2, id);     fflush(stdout);     scanf( %s , s);     char ch = s[0];     if (ch ==  X ) {       if (z[fa[x]] || !fa[x]) {         m++;         if (fa[x]) {           if (ls[fa[x]] == x)             ls[fa[x]] = m;           else             rs[fa[x]] = m;           fa[m] = fa[x];         }         fa[x] = m;         fa[id] = m;         ls[m] = x;         rs[m] = id;         return;       }       Sz = getsz(fa[x], 0);       mn = 1e9;       getrt(fa[x], 0);       dfs(rt);     }     if (ch ==  Y ) {       if (z[rs[x]]) {         m++;         fa[rs[x]] = fa[id] = m;         ls[m] = rs[x];         rs[m] = id;         rs[x] = m;         fa[m] = x;         return;       }       Sz = getsz(rs[x], 0);       mn = 1e9;       getrt(rs[x], 0);       dfs(rt);     }     if (ch ==  Z ) {       if (z[ls[x]]) {         m++;         fa[ls[x]] = fa[id] = m;         ls[m] = ls[x];         rs[m] = id;         ls[x] = m;         fa[m] = x;         return;       }       Sz = getsz(ls[x], 0);       mn = 1e9;       getrt(ls[x], 0);       dfs(rt);     }   }   int main() {     scanf( %d , &n);     m = n;     m++;     ls[m] = 1;     rs[m] = 2;     fa[1] = fa[2] = m;     for (id = 3; id <= n; id++) {       memset(z, 0, sizeof(z));       Sz = 2 * id - 3;       mn = 1e9;       getrt(1, 0);       dfs(rt);     }     puts( -1 );     for (int i = 1; i <= m; i++) printf( %d  , fa[i] ? fa[i] : -1);   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> parent[100005];   unordered_map<int, int> depth[100005];   unordered_map<int, int> memo[100005];   int Find(int node, int color) {     if (parent[node][color] == node) return node;     parent[node][color] = Find(parent[node][color], color);     return parent[node][color];   }   void Union(int a, int b, int color) {     if (!parent[a].count(color)) {       parent[a][color] = a;     }     if (!parent[b].count(color)) {       parent[b][color] = b;     }     int roota(Find(a, color));     int rootb(Find(b, color));     if (depth[roota][color] < depth[rootb][color]) swap(roota, rootb);     if (depth[roota][color] == depth[rootb][color]) depth[roota][color]++;     parent[rootb][color] = roota;   }   int solve(int a, int b) {     if (memo[a].count(b)) return memo[a][b];     int res(0);     if (parent[a].size() > parent[b].size()) swap(a, b);     unordered_map<int, int>::iterator it;     for (it = parent[a].begin(); it != parent[a].end(); it++) {       int color(it->first);       if (!parent[b].count(color)) continue;       if (Find(a, color) == Find(b, color)) res++;     }     memo[a][b] = memo[b][a] = res;     return res;   }   int main() {     int n, m, q;     cin >> n >> m;     for (int a, b, c, i = 0; i < m; i++) {       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       Union(a, b, c);     }     cin >> q;     for (int a, b, i = 0; i < q; i++) {       scanf( %d%d , &a, &b);       a--;       b--;       printf( %d n , solve(a, b));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, z, i, y, x = 1;     string line;     cin >> n >> k >> line;     for (i = 0; i < line.length(); i++) {       if (line[i] ==  G ) {         z = i;       }       if (line[i] ==  T ) {         y = i;       }     }     if (y < z) {       k = -k;     }     if ((y - z) % k == 0) {       for (i = z; i != y; i = i + k) {         if (line[i] ==  # ) {           cout <<  NO ;           x = 0;           break;         }       }       if (x != 0) {         cout <<  YES ;       }     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, t[110], tot = 0;     cin >> n >> d;     for (int i = 0; i < n; i++) cin >> t[i], tot += t[i];     if (tot + (n - 1) * 10 > d)       cout << -1 << endl;     else {       cout << (n - 1) * 2 + (d - tot - (n - 1) * 10) / 5 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, m, aux, rs = 0;   void neg() {     rs = (-y) / x;     rs++;     y = y + rs * x;   }   void rec() {     aux = x + y;     rs++;     if (aux < m) {       y = x;       x = aux;       rec();     }   }   int main() {     cin >> x >> y >> m;     aux = max(x, y);     y = min(x, y);     x = aux;     if (x >= m) {       cout <<  0  << endl;       return 0;     }     if (x < 1) {       cout <<  -1  << endl;       return 0;     }     if (y < 1 && x > 0) {       neg();     }     rec();     cout << rs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300007;   const double eps = 1e-9;   int n, m;   double C;   inline int Read() {     register int ch, a, flag;     while (ch = getchar(), (ch <  0  || ch >  9 ) && (ch !=  - ))       ;     flag = (ch ==  - );     a = flag ? 0 : ch -  0 ;     while (ch = getchar(), ch >=  0  && ch <=  9 )       a = (a << 1) + (a << 3) + ch -  0 ;     a = flag ? -a : a;     return a;   }   inline int dcmp(double a) {     if (fabs(a) <= eps) return 0;     return a < 0 ? -1 : 1;   }   struct Point {     double x, y;     Point(double a = 0, double b = 0) { x = a, y = b; }     bool operator==(const Point &A) const {       return dcmp(x - A.x) == 0 && dcmp(y - A.y) == 0;     }   };   inline Point operator+(const Point &A, const Point &B) {     return Point(A.x + B.x, A.y + B.y);   }   inline Point operator-(const Point &A, const Point &B) {     return Point(A.x - B.x, A.y - B.y);   }   inline Point operator*(const Point &A, const double &d) {     return Point(A.x * d, A.y * d);   }   inline Point operator/(const Point &A, const double &d) {     return Point(A.x / d, A.y / d);   }   inline double Dot(const Point &A, const Point &B) {     return A.x * B.x + A.y * B.y;   }   inline double Cross(const Point &A, const Point &B) {     return A.x * B.y - A.y * B.x;   }   inline double Length(const Point &A) { return sqrt(A.x * A.x + A.y * A.y); }   struct Segment {     double len;     Point v;     Point p;     inline Point Trans(double t) { return p + v * t; }   } s[maxn];   struct Pos {     int id;     Point p;   } p[maxn];   struct Func {     double a, b, c;     double be, ed;     Func() {}     Func(double s, double t, double q, double w, double e) {       be = s, ed = t, a = q, b = w, c = e;     }   };   vector<Func> f[maxn];   double ti[maxn << 1];   int tot;   bool cmp(const double &a, const double &b) { return dcmp(a - b) <= 0; }   void Load(int a, int b) {     double be = -Length(p[a].p - s[p[a].id].p), ed;     ti[++tot] = 0;     double Rem = C / m - be;     for (int i = p[a].id; i != p[b].id; i = i % n + 1) {       ed = be + s[i].len;       ti[++tot] = ed;       be = ed;       Rem -= s[i].len;     }     ti[++tot] = be + Rem;   }   void Insert(int a, int b, int c) {     tot = 0;     Load(a, b), Load(b, c);     sort(ti + 1, ti + 1 + tot);     tot = unique(ti + 1, ti + 1 + tot) - (ti + 1);     Point A = p[a].p, B = p[b].p;     int ida = p[a].id, idb = p[b].id;     for (int i = 1; i < tot; i++) {       double al = A.x - B.x, bt = s[ida].v.x - s[idb].v.x, gm = A.y - B.y,              om = s[ida].v.y - s[idb].v.y;       double alpha = bt * bt + om * om, beta = 2 * (al * bt + gm * om),              gama = al * al + gm * gm;       f[a].push_back(Func(ti[i], ti[i + 1] - ti[i], alpha, beta, gama));       A = A + s[ida].v * (ti[i + 1] - ti[i]);       B = B + s[idb].v * (ti[i + 1] - ti[i]);       if (A == s[ida % n + 1].p) ida = ida % n + 1;       if (B == s[idb % n + 1].p) idb = idb % n + 1;     }   }   void Initation() {     double dlt = C / m;     p[1].p = s[1].p, p[1].id = 1;     int j = 1;     double rem = 0;     for (int i = 2; i <= m; i++) {       rem += dlt;       while (dcmp(rem - s[j].len) >= 0) rem -= s[j++].len;       p[i].id = j;       p[i].p = s[j].Trans(rem);     }     for (int i = 1; i <= m; i++) Insert(i, i % m + 1, (i % m + 1) % m + 1);   }   struct Arr {     double L, R;   } A[maxn << 1], B[maxn << 1];   int Ta, Tb;   inline Arr Calc(Func F, double R) {     double A = F.a, B = F.b, C = F.c - R * R, le, ri;     if (dcmp(A) == 0) {       if (dcmp(B) < 0)         le = 0, ri = -C / B;       else if (dcmp(B) == 0) {         if (C > 0) return (Arr){1, -1};         le = 0, ri = F.ed;       } else         le = -C / B, ri = F.ed;     } else {       double dlt = B * B - 4 * A * C;       if (dcmp(dlt) < 0) return (Arr){1, -1};       dlt = sqrt(dlt + eps);       le = (-B - dlt) / (2 * A), ri = (-B + dlt) / (2 * A);       if (le > ri) swap(le, ri);     }     le = max(le, (double)0);     ri = min(ri, F.ed);     if (le > ri) return (Arr){1, -1};     return (Arr){le + F.be, ri + F.be};   }   void Add(Arr *s, int &Top, int id, double R) {     Top = 0;     for (int i = 0; i < f[id].size(); i++) {       Arr t = Calc(f[id][i], R);       if (t.R < 0) continue;       if (Top && dcmp(s[Top].R - t.L) >= 0)         s[Top].R = t.R;       else         s[++Top] = t;     }   }   Arr tmp[maxn << 1];   int Top;   void Merge() {     Top = 0;     int i = 1, j = 1, k = 0;     double L, R;     while (i <= Ta && j <= Tb) {       L = max(A[i].L, B[j].L), R = min(A[i].R, B[j].R);       if (L < R) tmp[++Top] = (Arr){L, R};       if (A[i].R >= B[j].R)         j++;       else         i++;     }     memcpy(A, tmp, sizeof(Arr) * (Top + 3));     Ta = Top;   }   bool Check(double mid) {     Add(A, Ta, 1, mid);     if (!Ta) return 0;     for (int i = 2; i <= m; i++) {       Add(B, Tb, i, mid);       Merge();       if (!Ta) return 0;     }     return 1;   }   int main() {     n = Read(), m = Read();     for (int i = 1; i <= n; i++) s[i].p.x = Read(), s[i].p.y = Read();     for (int i = 1; i < n; i++) {       s[i].v = s[i + 1].p - s[i].p, s[i].len = Length(s[i].v);       s[i].v = s[i].v / s[i].len;       C += s[i].len;     }     s[n].v = s[1].p - s[n].p, s[n].len = Length(s[n].v);     s[n].v = s[n].v / s[n].len;     C += s[n].len;     Initation();     double le = 0, ri = 6666, mid;     for (int r = 1; r <= 100; r++) {       mid = (le + ri) / 2;       if (!Check(mid))         le = mid;       else         ri = mid;     }     printf( %.10f n , mid);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int l;   int a[1000007];   int minn[1000007], maxn[1000007], cnt;   int cmp(int x, int y) { return x > y; }   int main() {     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &l);       int flag = 0;       for (int j = 1; j <= l; j++) {         scanf( %d , &a[j]);         if (j == 1) continue;         if (a[j] > a[j - 1]) flag = 1;       }       if (flag == 0) {         minn[++cnt] = a[l];         maxn[cnt] = a[1];       }     }     sort(minn + 1, minn + 1 + cnt);     for (int i = 1; i <= cnt; i++) {       int pos = lower_bound(minn + 1, minn + 1 + cnt, maxn[i]) - minn - 1;       ans += cnt - pos;     }     printf( %lld , 1ll * n * n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 1e5 + 7;   const double eps = 0.00000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   int n, m;   int i, j, k;   int main() {     scanf( %d , &n);     printf( %d , (n - 1) / 2);   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> f, num;   int Q;   int find(int x) {     if (!f.count(x)) return x;     int fa = find(f[x]);     num[x] ^= num[f[x]];     return f[x] = fa;   }   int main() {     scanf( %d , &Q);     int last = 0;     while (Q--) {       int opt, l, r, x;       scanf( %d %d %d , &opt, &l, &r);       l ^= last, r ^= last;       if (l > r) swap(l, r);       l--;       if (opt & 1) {         scanf( %d , &x);         x ^= last;         int fl = find(l), fr = find(r);         if (fl != fr) f[fr] = fl, num[fr] = x ^ num[l] ^ num[r];       } else {         int fl = find(l), fr = find(r);         if (fl != fr)           last = 1, printf( -1 n );         else           last = num[l] ^ num[r], printf( %d n , last);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     int ar[n], lock[n];     for (int i = 0; i < n; i++) cin >> ar[i];     vector<int> temp, res;     bool flag = false;     for (int i = 0; i < n - 1; i++) {       if (ar[i] > ar[i + 1]) {         flag = true;       }     }     if (flag == false) {       cout <<  YES  << endl;       return;     }     int minn = *min_element(ar, ar + n);     for (int i = 0; i < n; i++) {       if (ar[i] % minn == 0) {         temp.push_back(ar[i]);       }     }     sort(temp.begin(), temp.end());     int j = 0;     for (int i = 0; i < n; i++) {       if (ar[i] % minn != 0) {         res.push_back(ar[i]);       } else         res.push_back(temp[j++]);     }     for (int i = 0; i < n - 1; i++) {       if (res[i] > res[i + 1]) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   int main() {     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using i64 = long long int;   using ii = pair<int, int>;   using ii64 = pair<i64, i64>;   int main() {     int n;     scanf( %d , &n);     string s;     cin >> s;     int maxPhone = n / 11;     int eight = 0;     for (auto& c : s)       if (c ==  8 ) eight++;     printf( %d n , min(maxPhone, eight));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   int num[N], n, res[N], a[N];   void ReadData() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> num[i];   }   void Update(int x, int y) {     if (x > y) return;     ++a[x];     --a[y + 1];   }   void Solve() {     for (int i = 0; i < n; ++i) {       int k = 1;       for (; k * k <= (i - 1); ++k)         if (num[i] < num[(i - 1) / k]) ++res[k];       for (int j = 0; j <= (i - 1) / k; ++j)         if (num[i] < num[j]) {           if (0 == j)             Update(i, n - 1);           else             Update(max(k, (i - 1) / (j + 1) + 1), (i - 1) / j);         }     }     for (int i = 1; i < n; ++i) {       a[i] += a[i - 1];       res[i] += a[i];     }   }   void Output() {     for (int i = 1; i < n; ++i) cout << res[i] << endl;   }   int main() {     ReadData();     Solve();     Output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp(int a, int b) {     if ((a == 1 && b == 1) || b == 0) return 0;     return dp(max(b + 1, a - 2), min(b + 1, a - 2)) + 1;   }   int main() {     int n, m;     cin >> n >> m;     printf( %d , dp(max(n, m), min(n, m)));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, d;     scanf( %d , &T);     while (T--) {       scanf( %d , &d);       double a = 0, b = 0;       double x = d * d - 4 * d;       if (x < 0) {         printf( N n );         continue;       } else {         a = (d - sqrt(x)) / 2.0;         b = d - a;         if (a < b) swap(a, b);         printf( Y %.9lf %.9lf n , a, b);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i = 0;     string str;     scanf( %d , &n);     cin >> str;     if (n % 2 == 0) {       i = 2;       printf( %c%c , str[0], str[1]);     } else {       i = 3;       printf( %c%c%c , str[0], str[1], str[2]);     }     for (; i < n; i += 2) {       printf( -%c%c , str[i], str[i + 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > grafo[212345];   int marc[212345], dp[212345], ans[212345], ansmin = 1e9;   void dfs(int x) {     marc[x] = 1;     for (int i = 0; i < grafo[x].size(); i++) {       int viz = grafo[x][i].first;       int type = grafo[x][i].second;       if (marc[viz]) continue;       dfs(viz);       dp[x] += dp[viz];       if (type) dp[x]++;     }   }   void dfs2(int x) {     marc[x] = 0;     ans[x] = dp[x];     ansmin = min(ansmin, ans[x]);     for (int i = 0; i < grafo[x].size(); i++) {       int viz = grafo[x][i].first;       int type = grafo[x][i].second;       if (!marc[viz]) continue;       int dpx = dp[x];       int dpv = dp[viz];       dp[x] -= dp[viz];       if (type) dp[x]--;       dp[viz] += dp[x];       if (!type) dp[viz]++;       dfs2(viz);       dp[x] = dpx;       dp[viz] = dpv;     }   }   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       grafo[u].push_back(make_pair(v, 0));       grafo[v].push_back(make_pair(u, 1));     }     dfs(1);     dfs2(1);     printf( %d n , ansmin);     for (int i = 1; i <= n; i++) {       if (ansmin == ans[i]) printf( %d  , i);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, m, i, j, k, a[N], u, v, q, x;   vector<int> b[N];   long long ans;   long long f(int x) { return 1LL * b[x].size() * (a[x] - b[x].size()); }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       b[u].push_back(v);       a[u]++;       a[v]++;     }     scanf( %d , &q);     for (i = 1; i <= n; i++) ans += f(i);     printf( %lld n , ans);     for (j = 1; j <= q; j++) {       scanf( %d , &x);       ans -= f(x);       for (i = 0; i < b[x].size(); i++)         ans -= f(b[x][i]), b[b[x][i]].push_back(x), ans += f(b[x][i]);       b[x].clear();       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 9;   int n;   int fs[maxn];   int pj[maxn];   long long ansji, ansou;   void solve() {     int i;     for (i = 1; i <= n; ++i) fs[i] += fs[i - 1];     for (i = 1; i <= n; ++i) {       pj[i] = pj[i - 1] + (fs[i] & 1);     }     for (i = 1; i <= n; ++i) {       if (fs[i] & 1) {         ansji += i - pj[i - 1];         ansou += pj[i - 1];       } else {         ansji += pj[i - 1];         ansou += i - pj[i - 1];       }     }   }   void _solve() {     solve();     cout << ansji <<     << ansou << endl;   }   void _prepare() {     cin >> n;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       fs[i] = x < 0;     }   }   int _main_prog() {     _prepare();     _solve();     return 0;   }   int main() { return _main_prog(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int i, m, n;     double add, ans, t1, t2;     scanf( %ld%ld , &m, &n);     for (i = 1; i <= m; i++) {       t1 = (double)i / m;       t2 = (double)(i - 1) / m;       add = i * (pow(t1, n) - pow(t2, n));       ans += add;     }     printf( %.7lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110], n = 0, res[1010], ch = 0, k = 0;   string s;   int main() {     cin >> s;     memset(a, 0, sizeof a);     memset(res, 0, sizeof res);     for (int i = 0; i < (int)s.length(); ++i)       if (s[i] !=  , ) {         a[n] *= 10;         a[n] += (int)(s[i] -  0 );       } else         ++n;     ++n;     for (int i = 0; i < n; ++i) res[a[i]] = 1;     for (int i = 0; i < 1010; ++i) {       if (res[i] == 1)         ++ch;       else {         if (k > 0 && ch) cout <<  , ;         if (ch && k == 0) ++k;         if (ch == 1)           cout << i - 1;         else if (ch)           cout << i - ch <<  -  << i - 1;         ch = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long sz = 10000001;   bool vis[sz];   int cs[sz], a[sz], n, m;   void run() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     run();     cin >> n;     int x;     for (int i = 0; i < n; i++) {       cin >> x;       a[x]++;     }     for (int i = 2; i < sz; i++)       if (!vis[i])         for (int j = i; j < sz; j += i) {           vis[j] = 1;           if (a[j]) cs[i] += a[j];         }     for (int i = 3; i < sz; i++) cs[i] = cs[i] + cs[i - 1];     cin >> m;     while (m--) {       long long l, r;       cin >> l >> r;       r = min(r, sz - 1);       l = min(l, sz - 1);       cout << cs[r] - cs[l - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   char ch[maxn][maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i <= n + 1; i++) {       for (int j = 0; j <= n + 1; j++) {         ch[i][j] =  # ;       }     }     for (int i = 1; i <= n; i++) {       getchar();       for (int j = 1; j <= n; j++) {         scanf( %c , &ch[i][j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (ch[i][j] ==  # ) {           continue;         }         if (ch[i - 1][j] ==  # ) {           continue;         }         if (ch[i][j - 1] ==  # ) {           continue;         }         if (ch[i + 1][j] ==  # ) {           continue;         }         if (ch[i][j + 1] ==  # ) {           continue;         }         ch[i][j] =  # ;         ch[i][j + 1] =  # ;         ch[i][j - 1] =  # ;         ch[i + 1][j] =  # ;         ch[i - 1][j] =  # ;       }     }     bool ans = true;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (ch[i][j] ==  . ) {           ans = false;         }       }     }     if (ans) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ma = -1, mi = 1000000000000000;   inline long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   inline long long int lcm(long long int a, long long int b, long long int MOD) {     return a / gcd(a, b) * b % MOD;   }   long long int power(long long int x, unsigned int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, j = 1, k = 0, b;     cin >> n >> k;     if (k % 2 == 1) {       cout << 1 << endl;       return 0;     }     while (true) {       if (k % 2 == 1) break;       j++;       k /= 2;     }     cout << j << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int var;     scanf( %ld , &var);     if (var >= 0)       cout << var;     else {       int a, b;       a = var % 10;       var /= 10;       b = var % 10;       var /= 10;       if (a > b)         var = var * 10 + a;       else         var = var * 10 + b;       cout << var;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int n, r, m;   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return a.first * a.first + a.second * a.second >            b.first * b.first + b.second * b.second;   }   inline int get_dis(const int& first, const int& second) {     return first * first + second * second;   }   void init() {     v.clear();     for (int i = -r; i <= r; ++i)       for (int j = -r; j <= r; ++j)         if (i * i + j * j <= r * r) v.push_back(make_pair(i, j));     sort(v.begin(), v.end(), cmp);     m = min((int)v.size(), 30 - n * 2);   }   int b[120], ans[120], ansdist;   int dist[39][39];   void dfs(int first, int last, int sum) {     if (first == n) {       if (sum > ansdist) {         for (int i = 0; i < n; ++i) ans[i] = b[i];         ansdist = sum;       }       return;     }     int ndist;     for (int i = last; i < m; ++i) {       ndist = 0;       for (int j = 0; j < first; ++j) ndist += dist[i][b[j]];       b[first] = i;       dfs(first + 1, i, sum + ndist);     }   }   void solve() {     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j)         dist[i][j] = get_dis(v[i].first - v[j].first, v[i].second - v[j].second);     ansdist = 0;     dfs(0, 0, 0);     printf( %d n , ansdist);     for (int i = 0; i < n; ++i)       printf( %d %d n , v[ans[i]].first, v[ans[i]].second);   }   int main() {     while (scanf( %d%d , &n, &r) != EOF) {       init();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   long long powerMod(long long x, long long y) {     long long res = 1;     x %= 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, i, j, k, l;     cin >> n;     long long p[n + 1], q[n + 1];     for (i = 1; i <= n; i++) {       cin >> p[i];       q[p[i]] = i;     }     long long m = 0;     vector<pair<long long, long long> > swaps;     for (i = 1; i <= n; i++) {       if (p[i] != i) {         j = q[i];         if (2 * abs(i - j) >= n) {           m++;           swaps.push_back({i, j});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else if (i <= n / 2 && j <= n / 2) {           k = max(i, j) + n / 2;           m += 3;           swaps.push_back({i, k});           swaps.push_back({j, k});           swaps.push_back({i, k});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else if (i > n / 2 && j > n / 2) {           k = min(i, j) - n / 2;           m += 3;           swaps.push_back({i, k});           swaps.push_back({j, k});           swaps.push_back({i, k});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         } else {           m += 5;           if (i <= n / 2 && j > n / 2)             k = i + n / 2, l = j - n / 2;           else             k = i - n / 2, l = j + n / 2;           swaps.push_back({j, l});           swaps.push_back({l, k});           swaps.push_back({k, i});           swaps.push_back({k, l});           swaps.push_back({l, j});           p[j] = p[i];           q[p[i]] = j;           p[i] = i;           q[i] = i;         }       }     }     cout << m << endl;     for (pair<long long, long long> p : swaps) {       cout << p.first <<     << p.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 0;     int n;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  Cube )         c += 6;       else if (s ==  Tetrahedron )         c += 4;       else if (s ==  Octahedron )         c += 8;       else if (s ==  Icosahedron )         c += 20;       else         c += 12;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, k, h[200010];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     int ans = 0, x;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x % (a + b) == 0)         x -= (x / (a + b) - 1) * (a + b);       else         x -= (x / (a + b)) * (a + b);       if (x <= a)         ans++;       else {         if (x % a == 0)           x = x / a - 1;         else           x = x / a;         h[i] = x;       }     }     sort(h + 1, h + 1 + n);     for (int i = 1; i <= n; i++)       if (h[i] > 0 && k >= h[i]) k -= h[i], ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   ,  ;     err(++it, args...);   }   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 3e5 + 7;   const int N = 5e5 + 10;   int a[N];   int main() {     int n;     cin >> n;     int mx = 0;     for (int i = 1; i <= n; ++i) cin >> a[i], mx = max(mx, a[i]);     int ans = 1;     int len = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] == mx)         len++;       else         len = 0;       ans = max(ans, len);     }     cout << ans << endl;   }