#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > T;   int n, sum;   vector<pair<int, int> > loc;   void input();   void solve();   int main() {     input();     solve();     return 0;   }   void input() {     assert(scanf( %d , &n) == 1);     T.resize(n);     for (int i = 0; i < n; i++) {       int c;       assert(scanf( %d , &c) == 1);       sum += c;       T[i].resize(c);     }     loc.resize(sum);     for (int i = 0; i < n; i++)       for (int j = 0; j < ((int)(T[i].size())); j++) {         assert(scanf( %d , &T[i][j]) == 1);         loc[T[i][j] - 1] = make_pair(i, j);       }   }   void solve() {     vector<int> ans[4];     int cnt = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < ((int)(T[i].size())); j++) {         int x = loc[cnt].first, y = loc[cnt].second;         if (i != x || j != y) {           ans[0].push_back(i + 1);           ans[1].push_back(j + 1);           ans[2].push_back(x + 1);           ans[3].push_back(y + 1);           swap(T[i][j], T[x][y]);           swap(loc[T[i][j] - 1], loc[T[x][y] - 1]);         }         cnt++;       }     cout << ((int)(ans[0].size())) << endl;     for (int i = 0; i < ((int)(ans[0].size())); i++) {       for (int j = 0; j < 4; j++) cout << ans[j][i] <<    ;       cout << endl;     }   }


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


#include <bits/stdc++.h>   template <typename A, typename B>   inline char smax(A &a, const B &b) {     return a < b ? a = b, 1 : 0;   }   template <typename A, typename B>   inline char smin(A &a, const B &b) {     return b < a ? a = b, 1 : 0;   }   template <typename I>   inline void read(I &x) {     int f = 0, c;     while (!isdigit(c = getchar())) c ==  -  ? f = 1 : 0;     x = c & 15;     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);     f ? x = -x : 0;   }   const int N = 500 + 7;   const int M = (1 << 16) + 7;   const int P = 1e9 + 7;   int n, m, S, nod;   int A, B, C, D, F;   int fa[N], lc[N], rc[N], v[N], dp[N][M];   char a[N];   inline void sadd(int &x, const int &y) {     x += y;     x >= P ? x -= P : x;   }   inline int smod(const int &x) { return x >= P ? x - P : x; }   inline int fpow(int x, int y) {     int ans = 1;     for (; y; y >>= 1, x = (long long)x * x % P)       if (y & 1) ans = (long long)ans * x % P;     return ans;   }   inline void fwt_and(int *a, int n, int f) {     for (int i = 1; i < n; i <<= 1)       for (int j = 0; j < n; j += i << 1)         for (int k = 0; k < i; ++k) {           int x = a[j + k], y = a[i + j + k];           if (f > 0)             a[j + k] = smod(x + y);           else             a[j + k] = smod(x + P - y);         }   }   inline void fwt_or(int *a, int n, int f) {     for (int i = 1; i < n; i <<= 1)       for (int j = 0; j < n; j += i << 1)         for (int k = 0; k < i; ++k) {           int x = a[j + k], y = a[i + j + k];           if (f > 0)             a[i + j + k] = smod(x + y);           else             a[i + j + k] = smod(y + P - x);         }   }   int tA[M], tB[M];   inline void mul_and(int *a, int *b, int *c) {     memcpy(tA, a, sizeof(*a) * S);     memcpy(tB, b, sizeof(*b) * S);     fwt_and(tA, S, 1), fwt_and(tB, S, 1);     for (int i = 0; i < S; ++i) tA[i] = (long long)tA[i] * tB[i] % P;     fwt_and(tA, S, -1);     for (int i = 0; i < S; ++i) sadd(c[i], tA[i]);   }   inline void mul_or(int *a, int *b, int *c) {     memcpy(tA, a, sizeof(*a) * S);     memcpy(tB, b, sizeof(*b) * S);     fwt_or(tA, S, 1), fwt_or(tB, S, 1);     for (int i = 0; i < S; ++i) tA[i] = (long long)tA[i] * tB[i] % P;     fwt_or(tA, S, -1);     for (int i = 0; i < S; ++i) sadd(c[i], tA[i]);   }   inline void dfs(int x, int fa = 0) {     if (!lc[x]) {       if (v[x] == 1)         dp[x][A] = 1;       else if (v[x] == 2)         dp[x][B] = 1;       else if (v[x] == 3)         dp[x][C] = 1;       else if (v[x] == 4)         dp[x][D] = 1;       else if (v[x] == 5)         dp[x][(S - 1) ^ A] = 1;       else if (v[x] == 6)         dp[x][(S - 1) ^ B] = 1;       else if (v[x] == 7)         dp[x][(S - 1) ^ C] = 1;       else if (v[x] == 8)         dp[x][(S - 1) ^ D] = 1;       else if (v[x] == 0)         ++dp[x][A], ++dp[x][(S - 1) ^ A], ++dp[x][B], ++dp[x][(S - 1) ^ B],             ++dp[x][C], ++dp[x][(S - 1) ^ C], ++dp[x][D], ++dp[x][(S - 1) ^ D];     } else {       dfs(lc[x], x), dfs(rc[x], x);       if (v[x] == -1 || v[x] == 0) mul_and(dp[lc[x]], dp[rc[x]], dp[x]);       if (v[x] == -2 || v[x] == 0) mul_or(dp[lc[x]], dp[rc[x]], dp[x]);     }   }   inline void build() {     int curs = nod = 1;     n = strlen(a + 1);     for (int i = 1; i <= n; ++i) {       if (a[i] ==  ( )         fa[++nod] = curs, curs = nod;       else if (a[i] ==  ) ) {         if (lc[fa[curs]])           rc[fa[curs]] = curs;         else           lc[fa[curs]] = curs;         curs = fa[curs];       } else if (a[i] >=  A  && a[i] <=  D )         v[curs] = a[i] -  A  + 1;       else if (a[i] >=  a  && a[i] <=  d )         v[curs] = a[i] -  a  + 5;       else if (a[i] ==  & )         v[curs] = -1;       else if (a[i] ==  | )         v[curs] = -2;     }   }   inline void work() {     build();     dfs(1);     printf( %d n , dp[1][F]);   }   inline void init() {     scanf( %s , a + 1);     read(m), S = 1 << m;     int x;     for (int i = 1; i <= m; ++i) {       read(x), x && (A |= 1 << (i - 1));       read(x), x && (B |= 1 << (i - 1));       read(x), x && (C |= 1 << (i - 1));       read(x), x && (D |= 1 << (i - 1));       read(x), x && (F |= 1 << (i - 1));     }   }   int main() {     init();     work();     fclose(stdin), fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 6;   int n, l, r, h[N], b[N], ans[N], S;   vector<int> X, Y;   int main() {     scanf( %d%d%d , &n, &l, &r);     for (int i = 1; i <= n; ++i) scanf( %d , h + i), S += h[i];     for (int i = 1; i <= n; ++i) scanf( %d , b + i);     int _l = S - r, _r = S - l;     for (int i = 1; i <= n; ++i) (b[i] ? Y : X).push_back(h[i]);     sort(X.rbegin(), X.rend()), sort(Y.rbegin(), Y.rend());     for (int i = 1; i <= 10000; ++i) ans[i] = -1e9;     for (int s : X)       for (int i = 10000; i >= s; --i)         if (ans[i - s] >= 0) ans[i] = max(ans[i], ans[i - s]);     for (int s : Y)       for (int i = 10000; i >= s; --i)         if (ans[i - s] >= 0)           ans[i] = max(ans[i], ans[i - s] + (_l <= i && i <= _r));     printf( %d n , *max_element(ans, ans + 10001));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   int n, p[N];   int mx1[N], mx2[N], ans[N];   int main() {     scanf( %d , &n);     for (int v, best, i = 2; i <= n + 1; i++) {       scanf( %d , p + i);       v = i;       while (v != 0) {         best = max(mx1[v], mx2[v] + 1);         if (best <= ans[v]) break;         ans[v] = best;         if (mx2[p[v]] < best) mx2[p[v]] = best;         if (mx1[p[v]] < mx2[p[v]]) swap(mx1[p[v]], mx2[p[v]]);         v = p[v];       }       printf( %d  , max(mx1[1], mx2[1]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxD = 1001;   vector<int> temp;   int main() {     int n, w[MaxD] = {0}, h[MaxD] = {0}, maximum = 0, minimum = MaxD, ilgis;     unsigned long long ats = 1e18;     bool ar;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> w[i] >> h[i];       if (max(w[i], h[i]) > maximum) maximum = max(w[i], h[i]);       if (min(w[i], h[i]) < minimum) minimum = min(w[i], h[i]);     }     for (int i = minimum; i <= maximum; i++) {       ilgis = 0;       int vietos = n / 2;       ar = true;       temp.clear();       for (int j = 1; j <= n; j++) {         if (min(w[j], h[j]) > i) {           ar = false;           break;         }         if (h[j] > i && w[j] <= i) {           vietos--;           ilgis += h[j];         } else if (w[j] > i && h[j] <= i) {           ilgis += w[j];         } else {           ilgis += w[j];           if (w[j] > h[j] && w[j] <= i) temp.push_back(h[j] - w[j]);         }         if (vietos < 0) {           ar = false;           break;         }       }       sort(temp.begin(), temp.end());       if (ar) {         for (int j = 0; j < temp.size() && vietos; j++) {           ilgis += temp[j];           vietos--;         }       }       if (ar && (ilgis * i) < ats) ats = ilgis * i;     }     cout << ats;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int x;     cin >> x;     cout << 25;   }


#include <bits/stdc++.h>   using namespace std;   int n, dp[300005], k = 0, b[300005];   vector<int> ke[300005];   void dfs(int u, int par) {     if (ke[u].size() == 1 && u != 1) {       dp[u] = 1;       k++;       return;     }     if (b[u])       dp[u] = 1e9;     else       dp[u] = 0;     for (int v : ke[u])       if (v != par) {         dfs(v, u);         if (b[u])           dp[u] = min(dp[u], dp[v]);         else           dp[u] += dp[v];       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int u;     for (int i = 2; i <= n; i++) {       cin >> u;       ke[u].push_back(i);       ke[i].push_back(u);     }     dfs(1, 0);     cout << k - dp[1] + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)2e3 + 10;   const long long INF = (long long)2242545357980376863;   const long double EPS = (long double)1e-8;   long long dp[MAXN][2048];   long long pw[MAXN], cnt[MAXN];   long long a[MAXN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pw[0] = 1;     for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] << 1) % MOD;     long long n, k;     cin >> n >> k;     k = (1ll << k);     for (int i = 1; i <= n; i++) cin >> a[i];     long long c0 = 0;     for (int i = n; i >= 0; i--) {       cnt[i] = c0;       if (a[i] == 0) c0++;     }     if (a[1] == 2) {       dp[1][2] = 1;     }     if (a[1] == 4) {       dp[1][4] = 1;     }     if (a[1] == 0) {       dp[1][2] = dp[1][4] = 1;     }     long long ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 2; j < 2048; j++) {         if (dp[i][j] == 0) continue;         long long nx = a[i + 1];         if (nx != 4) {           long long sm = j + 2;           if (sm >= k) {             ans += (pw[cnt[i + 1]] * dp[i][j]);             ans %= MOD;           } else {             dp[i + 1][sm] += dp[i][j];             dp[i + 1][sm] %= MOD;           }         }         if (nx != 2) {           if (j % 4 == 2) {             dp[i + 1][4] += dp[i][j];           } else {             long long sm = j + 4;             if (sm >= k) {               ans += (pw[cnt[i + 1]] * dp[i][j]);               ans %= MOD;             } else {               dp[i + 1][sm] += dp[i][j];               dp[i + 1][sm] %= MOD;             }           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long ans = (a + b + c) / 2;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> A(n);     vector<int> P(n + 1);     for (auto &x : A) cin >> x;     for (int i = 0; i < n; ++i) P[A[i]] = i;     int cnt = 0;     vector<vector<int>> sol;     for (int kk = 0; kk < n; ++kk) {       if (is_sorted(A.begin(), A.end())) break;       ++cnt;       int goal = -1;       for (int i = 1; i <= n - 1; ++i) {         if (P[i] > P[i + 1]) {           goal = i;           break;         }       }       vector<vector<int>> G;       G.push_back({});       int state = 0;       for (int i = 0; i < n; ++i) {         if (state == 0) {           if (A[i] != goal + 1) {             G.back().push_back(A[i]);           } else {             G.push_back({A[i]});             state = 1;           }         } else if (state == 1) {           if (A[i] == goal) {             G.push_back({A[i]});             state = 3;             G.push_back({});           } else if (A[i] == A[i - 1] + 1)             G.back().push_back(A[i]);           else {             G.push_back({A[i]});             state = 2;           }         } else if (state == 2) {           G.back().push_back(A[i]);           if (A[i] == goal) {             state = 3;             G.push_back({});           }         } else {           G.back().push_back(A[i]);         }       }       sol.push_back({});       for (auto &x : G) {         if (!x.empty()) sol.back().push_back(x.size());       }       reverse(G.begin(), G.end());       {         int i = 0;         for (auto &g : G)           for (auto x : g) A[i++] = x;       }       for (int i = 0; i < n; ++i) P[A[i]] = i;     }     assert(is_sorted(A.begin(), A.end()));     cout << cnt <<   n ;     for (auto &s : sol) {       cout << s.size() <<    ;       for (auto &x : s) cout << x <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   int n, a[2505], mx, s, ch, ans;   long long f[100005];   long long ksm(long long x, int y) {     long long sun = 1;     x %= p;     while (y) {       if (y & 1) sun = sun * x % p;       y >>= 1;       x = x * x % p;     }     return sun;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), mx = max(a[i], mx), s += a[i];     f[1] = ksm(s - 1, 2) * ksm(s, p - 2) % p;     ch = f[1];     for (int i = 2; i <= mx; i++) {       ch = (ch - ksm(s - i + 1, p - 2) * (s - 1) % p + p) % p;       f[i] = (f[i - 1] + ch) % p;     }     for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % p;     cout << ans;   }


#include <cstdio>   #include <cstring>   #include <queue>   #include <cmath>   #include <set>   #include <cstdlib>   #include <iostream>   #include <map>   #include <algorithm>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uii;   typedef pair<int, ll> pii;   template<typename T>   inline void rd(T& x)   {    int tmp = 1; char c = getchar(); x = 0;    while (c >  9  || c <  0 ) { if (c ==  - )tmp = -1; c = getchar(); }    while (c >=  0  && c <=  9 ) { x = x * 10 + c -  0 ; c = getchar(); }    x *= tmp;   }   const int N = 2e5 + 10;   const int M = 1e6 + 10;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   int sgn(double x) {    if (fabs(x) < eps) return 0;    if (x > 0) return 1;    return -1;   }   int n, m, k;   int head[N], cntE;   struct edge {    int to, next;    int w;   }e[M];   void add(int u, int v, int w = 0) {    e[cntE].to = v;    e[cntE].next = head[u];    e[cntE].w = w;    head[u] = cntE++;   }   bool vis[N];   int stk[N], top;   bool dfs(int x) {    if (vis[x ^ 1]) return false;    if (vis[x]) return true;    vis[x] = true;    stk[++top] = x;    for (int i = head[x]; ~i; i = e[i].next) {     int v = e[i].to;     if (!dfs(v)) return false;    }    return true;   }   bool two_sat() {    memset(vis, false, sizeof(bool) * (2 * n + 10));    for (int i = 0; i < n; ++i) {     if (vis[i << 1] || vis[i << 1 | 1]) continue;     top = 0;     if (!dfs(i << 1)) {      while (top) vis[stk[top--]] = false;      if (!dfs(i << 1 | 1)) return false;     }    }    return true;   }   ll a[N], b[N], c[N], maxn[N];   ll solve() {    maxn[n] = c[n] - 1 + 2;    ll ans = 0;    for (int i = n - 1; i > 0; --i) {     ans = max(ans, maxn[i + 1] + b[i + 1] - a[i + 1]);     maxn[i] = c[i] - 1;     if (b[i+1] == a[i+1]) {     // maxn[i] = c[i] + 1;     }     else {      maxn[i] = max(maxn[i], maxn[i + 1] + (c[i] - 1 - (b[i + 1] - a[i + 1])));     }     maxn[i] += 2;    }    return ans;   }   int main() {   #ifdef _DEBUG    FILE* _INPUT = freopen( input.txt ,  r , stdin);    // FILE* _OUTPUT = freopen( output.txt ,  w , stdout);   #endif // !_DEBUG    int cas = 0, T;    rd(T);    while (T--) {   // while (~scanf( %d , &n)) {     rd(n);     for (int i = 1; i <= n; ++i) rd(c[i]);     for (int i = 1; i <= n; ++i) rd(a[i]);     for (int i = 1; i <= n; ++i) rd(b[i]);     for (int i = 1; i <= n; ++i) if (a[i] > b[i]) swap(a[i], b[i]);     printf( %lld n , solve());    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n / 2 * 3;   }


#include <bits/stdc++.h>   using namespace std;   void printv(vector<long long int> v) {     long long int sz = v.size();     for (long long int i = 0; i < sz; i++) {       if (i == sz - 1)         cout << v[i] <<   n ;       else         cout << v[i] <<    ;     }   }   void input(long long int a[], long long int sz) {     for (long long int i = 0; i < sz; i++) cin >> a[i];   }   void print(long long int a[], long long int sz) {     for (long long int i = 0; i < sz; i++) {       if (i == sz - 1)         cout << a[i] <<   n ;       else         cout << a[i] <<    ;     }   }   long long int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};   long long int dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long int dx2[] = {1, 0, -1, 0};   long long int dy2[] = {0, 1, 0, -1};   long long int mul(long long int a, long long int b,                     long long int p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long int add(long long int a, long long int b,                     long long int p = 1000000007) {     return (a % p + b % p) % p;   }   long long int power(long long int x, long long int y,                       long long int p = 1000000007) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, long long int p = 1000000007) {     return power(n, p - 2, p);   }   long long int ncrMod(long long int n, long long int r,                        long long int p = 1000000007) {     if (r == 0) return 1;     long long int fac[n + 1];     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   bool ispeed2ime(long long int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   bool isPowerof2(long long int n) {     while (n > 1) {       if (n % 2 != 0) {         return true;       }       n /= 2;     }     return false;   }   string reverse(string str, int len, int l, int r) {     if (l < 0 || r >= len || l > r) return str;     while (l < r) {       char c = str[l];       str[l] = str[r];       str[r] = c;       l++;       r--;     }     return str;   }   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     string temp =   ;     long long int maxi1 = 0, maxi2 = 0;     for (int i = 0; i < n - 1; i++) {       temp += s[i];       temp += s[i + 1];       if (temp ==  10 ) {         maxi1++;       } else if (temp ==  01 ) {         maxi2++;       }       temp =   ;     }     long long int maxi = max(maxi1, maxi2);     long long int cnt = n / 2 - (maxi);     cout << cnt <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   bool QQQQ;   const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   const int dy[] = {0, 0, -1, 1, 1, -1, 1, -1};   using namespace std;   int ttt = 1;   int n, k, res = 100256, z, cnt;   string s, t, ans;   void solve() {     cin >> n >> k >> s;     ans = s;     for (int i = 0; i < n; i++) ans[i] =  9 ;     for (int i = 0; i < 10; i++) {       t = s;       z = k;       cnt = 0;       for (int j = 0; j < 10; j++) {         for (int l = 0; l < n; l++)           if (z && t[l] -  0  == i + j) {             z--;             t[l] = i +  0 ;             cnt += j;           }         if (j)           for (int l = n - 1; l >= 0; l--)             if (z && t[l] -  0  == i - j) {               z--;               t[l] = i +  0 ;               cnt += j;             }       }       if (cnt < res) res = cnt, ans = t;       if (cnt == res) ans = min(ans, t);     }     cout << res << endl << ans;   }   int main() {     for (int tt = 1; tt <= (ttt = ttt); tt++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio();     cin.tie();     int t, n, a, b;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int c = abs(a - b);       int ans = 0;       int tmp = c / 5;       ans += tmp;       c -= tmp * 5;       tmp = c / 2;       ans += tmp;       c -= tmp * 2;       tmp = c / 1;       ans += tmp;       c -= tmp * 1;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int dist[1150][1150], visited[1150][1150];   char ans[1050][1050];   void solve() {     long long n, i, j, m;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cin >> ans[i][j];     }     int startx, starty, endx, endy;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (ans[i][j] ==  E ) {           endx = i;           endy = j;         }         if (ans[i][j] ==  S ) {           startx = i;           starty = j;         }       }     }     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         dist[i][j] = INT_MAX;         visited[i][j] = 0;       }     int rowcol[] = {0, 0, 1, -1};     int colcol[] = {1, -1, 0, 0};     dist[endx][endy] = 0;     visited[endx][endy] = 1;     queue<pair<int, int> > q;     q.push({endx, endy});     while (q.empty() == 0) {       pair<int, int> point = q.front();       q.pop();       int x = point.first;       int y = point.second;       for (i = 0; i < 4; i++) {         int x1 = x + rowcol[i];         int y1 = y + colcol[i];         if (x1 >= 0 && y1 >= 0 && x1 < n && y1 < m && ans[x1][y1] !=  T ) {           if (visited[x1][y1] == 0) {             dist[x1][y1] = dist[x][y] + 1;             visited[x1][y1] = 1;             q.push({x1, y1});           }         }       }     }     unsigned long long int count = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (startx == i && starty == j) {           continue;         }         if (dist[startx][starty] >= dist[i][j] && ans[i][j] !=  0  &&             ans[i][j] !=  T  && ans[i][j] !=  E )           count += ans[i][j] -  0 ;       }     }     cout << count << endl;   }   int main() {     long long n = 1, x1, y1, x2, y2, i;     while (n--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x3f3f3f3f;   long long dp[maxn];   int n, m;   struct node {     int lb, lu;     long long w;   };   vector<node> ve[maxn];   int lb, lu;   long long w, cost[maxn];   struct seg {     long long ma, lazy;   } tr[maxn << 2];   void build(int o, int l, int r) {     tr[o].ma = 0;     tr[o].lazy = 0;     if (l == r) {       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);   }   void pushup(int o) { tr[o].ma = max(tr[o << 1].ma, tr[o << 1 | 1].ma); }   void pushdown(int o) {     if (tr[o].lazy) {       tr[o << 1].ma += tr[o].lazy;       tr[o << 1 | 1].ma += tr[o].lazy;       tr[o << 1].lazy += tr[o].lazy;       tr[o << 1 | 1].lazy += tr[o].lazy;       tr[o].lazy = 0;     }   }   void update(int o, int l, int r, int ql, int qr, long long val) {     if (ql <= l && qr >= r) {       tr[o].ma += val;       tr[o].lazy += val;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (ql <= mid) update(o << 1, l, mid, ql, qr, val);     if (qr > mid) update(o << 1 | 1, mid + 1, r, ql, qr, val);     pushup(o);   }   long long query(int o, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) {       return tr[o].ma;     }     pushdown(o);     int mid = (l + r) >> 1;     long long maxx = 0;     if (ql <= mid) maxx = max(maxx, query(o << 1, l, mid, ql, qr));     if (qr > mid) maxx = max(maxx, query(o << 1 | 1, mid + 1, r, ql, qr));     return maxx;   }   int main() {     while (cin >> n >> m) {       for (int i = 1; i <= n; i++) {         scanf( %lld , &cost[i]);       }       for (int i = 1; i <= m; i++) {         scanf( %d%d%lld , &lb, &lu, &w);         ve[lu].push_back({lb, lu, w});       }       build(1, 0, n + 1);       long long maxx = 0;       for (int i = 1; i <= n + 1; i++) {         dp[i] = dp[i - 1];         update(1, 0, n + 1, 0, i - 1, -cost[i]);         for (int j = 0; j < ve[i].size(); j++) {           lb = ve[i][j].lb, w = ve[i][j].w;           update(1, 0, n + 1, 0, lb - 1, w);         }         dp[i] = max(dp[i], query(1, 0, n + 1, 0, i - 1));         update(1, 0, n + 1, i, i, dp[i]);         maxx = max(maxx, dp[i]);       }       printf( %lld n , maxx);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int cntrow[21];   int cntcol[6];   vector<int> sol;   vector<int> allmasks[6];   bool DP[20][11][11][11][11][11][(1 << 5) + 1];   bool solve(int row, int c1, int c2, int c3, int c4, int c5, int mask) {     if (row == m) {       int tmp = c1 + c2 + c3 + c4 + c5;       if (tmp == 0) return true;       return false;     }     bool &temp = DP[row][c1][c2][c3][c4][c5][mask];     if (temp) return false;     temp = true;     for (int i = 0; i < allmasks[cntrow[row]].size(); i++) {       int tmp = allmasks[cntrow[row]][i];       int nc1 = c1;       int nc2 = c2;       int nc3 = c3;       int nc4 = c4;       int nc5 = c5;       if ((mask & (1 << 0)) == 0 && (tmp & (1 << 0)) != 0) nc1--;       if ((mask & (1 << 1)) == 0 && (tmp & (1 << 1)) != 0) nc2--;       if ((mask & (1 << 2)) == 0 && (tmp & (1 << 2)) != 0) nc3--;       if ((mask & (1 << 3)) == 0 && (tmp & (1 << 3)) != 0) nc4--;       if ((mask & (1 << 4)) == 0 && (tmp & (1 << 4)) != 0) nc5--;       if (nc1 < 0 || nc2 < 0 || nc3 < 0 || nc4 < 0 || nc5 < 0) continue;       if (solve(row + 1, nc1, nc2, nc3, nc4, nc5, tmp)) {         sol.push_back(tmp);         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> cntcol[i];     for (int i = 0; i < m; i++) cin >> cntrow[i];     for (int i = 0; i < (1 << n); i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (j == 0 || ((i & (1 << (j - 1))) == 0))           if ((i & (1 << j)) != 0) cnt++;       }       allmasks[cnt].push_back(i);     }     solve(0, cntcol[0], cntcol[1], cntcol[2], cntcol[3], cntcol[4], 0);     reverse(sol.begin(), sol.end());     for (int j = 0; j < n; j++) {       for (int i = 0; i < sol.size(); i++) {         if (sol[i] & (1 << j))           cout <<  * ;         else           cout <<  . ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void f(int& r, int& g, int& b) {     if (r >= 3 && g % 3 == 2 && b % 3 == 2) {       r += 4;       g -= 2;       b -= 2;     }   }   int main(void) {     int r, g, b;     cin >> r >> g >> b;     f(r, g, b);     f(g, r, b);     f(b, r, g);     cout << r / 3 + g / 3 + b / 3 + min(r % 3, min(g % 3, b % 3)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       n *= 2;       vector<int> a(n);       for (int &x : a) {         cin >> x;       }       map<int, int> left, right;       map<int, bool> was;       int red = 0, blue = 0;       int res = n;       for (int i = n - 1; i >= n / 2; i--) {         int toEat = n / 2 - (n - i);         red += (a[i] == 1);         blue += (a[i] == 2);         right[red - blue] = toEat;         was[red - blue] = true;         if (i == n / 2 && red == blue) {           res = min(res, n / 2);         }         if (red == blue) {           res = min(res, n / 2 + toEat);         }       }       red = blue = 0;       for (int i = 0; i < n / 2; i++) {         int toEat = n / 2 - i - 1;         red += (a[i] == 1);         blue += (a[i] == 2);         if (red == blue) {           res = min(res, n / 2 + toEat);         }         if (was[blue - red]) {           res = min(res, toEat + right[blue - red]);         }         if (i == n / 2 - 1 && red == blue) {           res = min(res, n / 2);         }       }       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     int n = str.size();     int fl = 1;     vector<char> v;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  / ) {         while (str[i] ==  / ) {           i++;         }         i--;         v.push_back( / );       } else {         v.push_back(str[i]);       }     }     for (int i = 0; i < v.size(); i++) {       if (v[i] !=  / ) {         fl = 0;         break;       }     }     if (fl == 1) {       cout <<  /  << endl;     } else {       int t = v.size();       for (int i = 0; i < t; i++) {         if (i == t - 1 && v[i] ==  / ) {           continue;         } else {           cout << v[i];         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int k;     cin >> k;     string s;     cin >> s;     long long tot = 0;     int av[11];     memset(av, 0, sizeof(av));     int ans = 0;     for (char a : s) tot += a -  0 , av[9 - (a -  0 )]++;     for (int i = 10; i; i--) {       if (tot >= k) break;       if (k - av[i] * i < tot) {         while (k > tot) {           k -= i;           ans++;         }         break;       } else {         k -= av[i] * i;         ans += av[i];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     scanf( %d , &n);     if (n == 1)       printf( 1 n1 n );     else if (n == 2)       printf( 1 n1 n );     else if (n == 3)       printf( 2 n1 3 n );     else if (n == 4)       printf( 4 n2 4 1 3 n );     else {       printf( %d n , n);       for (j = 2; j <= n; j += 2) printf( %d  , j);       for (j = 1; j <= n; j += 2) printf( %d  , j);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[11000111];   int el[5100];   int q, x, k, n;   long long t;   int min(int a, int b) {     if (a < b) {       return a;     }     return b;   }   int main() {     scanf( %d , &n);     scanf( %d , &k);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       ar[x] = 1;       el[i] = x;     }     scanf( %d , &q);     for (int qq = 0; qq < q; ++qq) {       scanf( %I64d , &t);       int ans = 100;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < k + 1; ++j) {           long long temp = t - el[i] * j;           if (temp > 0) {             for (int l = 1; l <= k - l + 1; ++l) {               if (temp % l == 0 && temp / l <= 10111000 && ar[temp / l] == 1) {                 ans = min(ans, l + j);               }             }           }         }       }       if (ans <= k) {         printf( %d n , ans);       } else {         printf( -1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),         cout.precision(15);     int t;     cin >> t;     while (t--) {       int n, x;       set<int> s;       cin >> n;       for (int i = int(0); i < int(n); i++) {         cin >> x;         s.insert(x);       }       cout << s.size() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10000000], b[10000000], memo[10000000], pos[10000000];   int min(int l, int r) {     if (l <= r) {       return l;     }     return r;   }   int main() {     int n, m, i, j, k, ind, p, l, x;     fscanf(stdin,  %d %d , &n, &m);     for (i = 1; i <= n; i++) {       fscanf(stdin,  %d , &a[i]);     }     i = 1;     ind = 1;     while (i <= n) {       j = i;       k = a[i];       memo[ind] = k;       pos[ind] = i;       while (j <= n && a[j] == k) {         b[j] = ind;         j++;       }       i = j;       ind++;     }     for (i = 1; i <= m; i++) {       fscanf(stdin,  %d %d %d , &p, &l, &x);       if (b[p] == b[l]) {         if (x == a[p]) {           cout <<  -1  << endl;         } else {           cout << p << endl;         }       } else {         ind = b[p];         if (memo[b[p]] != x) {           cout << p << endl;         } else {           ind = 1;           while (pos[b[p] + ind] == x) {             ind++;           }           cout << pos[b[p] + ind] << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1005];   long long t, ans = 0;   int x, l;   int main() {     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; i++) {       if (isalpha(s[i])) {         if (t) {           if (l == 2)             ans += t;           else             ans += t * 100;         }         t = 0;         x = 0;         l = 0;       } else {         if (isdigit(s[i])) {           t = t * 10 + s[i] -  0 ;           if (x) {             l++;           }         } else {           x = 1;           l = 0;         }       }     }     if (t) {       if (l == 2) {         ans += t;       } else         ans += t * 100;     }     long long temp = ans / 100;     long long temp1 = ans % 100;     len = 0;     string A =   ;     if (temp == 0) A = A +  0 ;     while (temp) {       if (len && len % 3 == 0) {         A = A +  . ;       }       char c =  0  + temp % 10;       A = A + c;       temp /= 10;       len++;     }     reverse(A.begin(), A.end());     cout << A;     if (temp1) {       printf( .%.2I64d , temp1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[1000010];   int n, k;   bool r[1000010];   int s[1000010];   int m[1000010];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);     }     int v = 0;     for (int i = 1; i <= n; i++) {       if (r[i]) continue;       s[v++] = i;       r[i] = true;       for (int j = 0; j < (int)g[i].size(); j++) r[g[i][j]] = true;     }     int sz = 0;     for (int i = 1; i <= n; i++) r[i] = false;     for (int i = v - 1; i >= 0; i--) {       if (!r[s[i]]) {         m[sz++] = s[i];         for (int j = 0; j < (int)g[s[i]].size(); j++) r[g[s[i]][j]] = true;       }     }     printf( %d n , sz);     for (int i = 0; i < sz; i++) printf( %d  , m[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int n, k, a[1010][1010];   vector<pair<int, int>> ans;   int main() {     int is = 0;     ans.clear();     memset(a, 0, sizeof(a));     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int cnt = 0;       for (int j = 1; j <= n; ++j) {         if (i == j) continue;         if (cnt == k) break;         if (a[j][i] == 0) {           a[i][j] = 1;           ++cnt;           ans.push_back({i, j});         }       }       if (cnt != k) {         cout <<  -1 ;         return 0;       }     }     if (!is) {       cout << ans.size() <<   n ;       for (auto i : ans) {         cout << i.first <<     << i.second <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> adjs[510];   char type[510];   bool visited[510];   int dfs(int v, int adj, char c) {     visited[v] = true;     type[v] = c;     int totV = 1;     for (int i = 0; i < (adj); i++) {       int adjV = adjs[v][i];       if (!visited[adjV] && adjs[adjV].size() == adj) totV += dfs(adjV, adj, c);     }     return totV;   }   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int var = 0; var < (n); var++) type[var] = ( x );     for (int var = 0; var < (n); var++) visited[var] = (false);     for (int i = 0; i < (m); i++) {       int u, v;       cin >> u >> v;       u--;       v--;       adjs[u].push_back(v);       adjs[v].push_back(u);     }     int adja = -1, adjb = n - 1, adjc = -1;     int na = 0, nb = 0, nc = 0;     bool pos = true;     for (int i = 0; i < (n); i++) {       int k = adjs[i].size();       if (k == adjb) {         nb++;         type[i] =  b ;         visited[i] = true;       } else if (!visited[i]) {         if (na == 0) {           adja = adjs[i].size();           na = dfs(i, adja,  a );         } else if (nc == 0) {           adjc = adjs[i].size();           nc = dfs(i, adjc,  c );         } else           pos = false;       }     }     type[n] =   0 ;     if (pos && na + nb + nc == n && (adja == -1 || adja == na + nb - 1) &&         (adjc == -1 || adjc == nb + nc - 1)) {       cout << ( Yes ) <<   n ;       cout << (type) <<   n ;     } else {       cout << ( No ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   const int L = 301;   const int INF = 1e9 + 239;   int n;   int a[N];   int cnt[N];   vector<int> pos[N];   int mn[2 * N];   void solve(vector<pair<int, int>> v, int &ans) {     v.push_back({n - 1, 0});     int prev = -1;     int c = 0;     mn[N] = 0;     for (auto [pos, val] : v) {       if (abs(prev) < 2) ans = max(ans, (pos - 1) - mn[c + N] + 1);       c += val;       ans = max(ans, pos - mn[c + N] + 1);       mn[c + N] = min(mn[c + N], pos + 1);       prev = val;     }     c = 0;     mn[0] = INF;     for (auto [pos, val] : v) {       c += val;       mn[c + N] = INF;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     fill(mn, mn + 2 * N, INF);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       cnt[a[i]]++;       pos[a[i]].push_back(i);     }     int ans = 0;     int mx = max_element(cnt, cnt + N) - cnt;     int pnt = -1;     int sz = -1;     vector<pair<int, int>> vplus, vminus;     auto add = [&](int p) {       int imx = lower_bound(pos[mx].begin(), pos[mx].end(), p) - pos[mx].begin();       int l = max(pnt + 1, imx - (sz + 3));       if (pnt + 1 < imx - (sz + 3)) {         vplus.push_back({pos[mx][pnt + 1], imx - (sz + 3) - (pnt + 1)});       }       for (int i = l; i <= imx + (sz + 3) && i < (int)pos[mx].size(); i++) {         vplus.push_back({pos[mx][i], 1});         pnt = i;       }     };     auto relax_small = [&](int s) {       if (pos[s].empty()) {         return;       }       vplus.clear();       vminus.clear();       sz = (int)pos[s].size();       pnt = -1;       { add(0); }       for (auto p : pos[s]) {         add(p);         vminus.push_back({p, -1});       }       { add(n - 1); }       vector<pair<int, int>> vall(vplus.size() + vminus.size());       merge(vplus.begin(), vplus.end(), vminus.begin(), vminus.end(),             vall.begin());       solve(vall, ans);     };     auto relax_big = [&](int s) {       if (pos[s].empty()) {         return;       }       vplus.clear();       vminus.clear();       for (auto p : pos[mx]) {         vplus.push_back({p, 1});       }       for (auto p : pos[s]) {         vminus.push_back({p, -1});       }       vector<pair<int, int>> vall(vplus.size() + vminus.size());       merge(vplus.begin(), vplus.end(), vminus.begin(), vminus.end(),             vall.begin());       solve(vall, ans);     };     for (int other = 0; other < N; other++) {       if (other == mx) {         continue;       }       if (pos[other].size() > L) {         relax_big(other);       } else {         relax_small(other);       }     }     cout << ans <<   n ;   }


#pragma GCC optimize ( O3 )   #pragma GCC target ( sse4 )   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double ld;   typedef vector<int> vi;   typedef pair<int, int> pi;   #define debug(x) cerr << #x <<  :   << x <<   n    #define debug2(x, y) debug(x), debug(y)   #define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)   #define rep(i, a) for(int i = 0; i < (int)(a); i++)   #define all(v) v.begin(), v.end()   #define mp make_pair   #define pb push_back   #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #define sq(x) ((x) * (x))   const int MOD = 1e9 + 7;   const int mxN = 205;      template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }      vi g[mxN];   int up[mxN][10];   ll p[mxN][mxN];   int st[mxN], en[mxN], d[mxN];   int cnt = 0;      void dfs(int cur, int prev, int di = 0){    st[cur] = cnt++;    d[cur] = di;    up[cur][0] = prev;    repn(i, 1, 10) up[cur][i] = up[up[cur][i - 1]][i - 1];    for(int x : g[cur]) if(x != prev) dfs(x, cur, di + 1);    en[cur] = cnt++;   }      bool upper(int a, int b){    return st[a] <= st[b] && en[a] >= en[b];   }      int lca(int a, int b){    if(upper(a, b)) return a;    if(upper(b, a)) return b;    for(int i = 9; i >= 0; i--) if(!upper(up[a][i], b)) a = up[a][i];    return up[a][0];   }      ll mypow(ll a, ll p){    if(p == 0) return 1;    if(p == 1) return (a % MOD);    if(p & 1) return ((a % MOD) * (mypow(a, p - 1) % MOD)) % MOD;    ll x = mypow(a, p / 2) % MOD;    return (x * x) % MOD;   }      ll inv(ll base){    return mypow(base, MOD - 2);   }      int main(){    ios_base::sync_with_stdio(false);    cin.tie(0);    //freopen( input.in ,  r , stdin);    //freopen( output.out ,  w , stdout);    ll n;    cin >> n;    rep(i, n - 1){     int x, y;     cin >> x >> y;     x--, y--;     g[x].pb(y);     g[y].pb(x);    }    p[0][0] = 1LL;    rep(i, mxN - 1){     rep(j, i + 1){      int k = i - j;      (p[j + 1][k] += (p[j][k] * inv(2)) % MOD) %= MOD;      (p[j][k + 1] += (p[j][k] * inv(2)) % MOD) %= MOD;     }    }    rep(k, n) repn(j, 1, n) (p[j][k] += p[j - 1][k]) %= MOD;    ll ans = 0LL;    rep(i, n){     cnt = 0;     dfs(i, i);     rep(j, n) repn(k, j + 1, n){      if(upper(k, j)) ans++;      else if(!upper(j, k)){       int c = lca(j, k);       int a = d[j] - d[c], b = d[k] - d[c];       (ans += (p[a - 1][b - 1] * inv(2)) % MOD) %= MOD;      }     }    }    cout << (ans * inv(n)) % MOD <<   n ;    return 0;   }   /*   Things to look out for:    - Integer overflows    - Make sure that max is large enough (2e9, 4e18)    - Special cases   Be careful!   */


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:2000000 )   #pragma comment(linker,  /HEAP:2000000 )   using namespace std;   void print_width(long long x) {     std::cout << std::fixed;     std::cout << std::setprecision(x);   }   long long power(long long x, long long y, long long p = 1000000007) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void printArr(long long a[], long long n) {     for (long long i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   void printVector(std::vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void printVectorPair(std::vector<pair<long long, long long>> v) {     for (long long i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second <<   n ;     ;     cout <<   n ;   }   void initialize(long long arr[], long long n) {     for (long long i = 0; i <= n; i++) arr[i] = i;   }   long long root(long long arr[], long long i) {     while (arr[i] != i) {       arr[i] = arr[arr[i]];       i = arr[i];     }     return i;   }   void Union(long long arr[], long long a, long long b) {     long long root_a = root(arr, a);     long long root_b = root(arr, b);     arr[root_a] = root_b;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power_wm(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   std::vector<long long> vsum(std::vector<long long> a) {     std::vector<long long> s(a.size());     s[0] = a[0];     for (long long i = 1; i <= a.size() - 1; i++) {       s[i] = s[i - 1] + a[i];     }     return s;   }   void time() {}   long long sti(string s) {     long long ans = 0;     long long p = 1;     for (long long i = s.size() - 1; i >= 0; i--) {       ans = (ans + ((long long)(s[i] -  0 ) * p) % 1000000007) % 1000000007;       p = (p * 10) % 1000000007;     }     return ans;   }   long long bfs(long long x, long long y, vector<vector<long long>> &g) {     std::vector<long long> vis(100001, 0);     vis[x] = 1;     queue<long long> q;     q.push(x);     std::vector<long long> level(100001, (long long)1e18);     level[x] = 0;     while (!q.empty()) {       long long p = q.front();       q.pop();       for (long long i = 0; i < g[p].size(); i++) {         long long p2 = g[p][i];         if (vis[p2] == 0) {           if (x == p and y == p2) {             continue;           } else {             q.push(p2);             vis[p2] = 1;             level[p2] = level[p] + 1;           }         }       }     }     return level[y];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long N = 5000001;     std::vector<long long> lp(N, 0);     std::vector<long long> pr;     for (long long i = 2; i <= N - 1; i++) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (long long j = 0;            j < (long long)pr.size() and pr[j] <= lp[i] and i * pr[j] <= N; j++)         lp[i * pr[j]] = pr[j];     }     lp[1] = 1;     std::vector<long long> count(N, 0);     for (long long i = 2; i <= N - 1; i++) {       long long prm = i;       count[i]++;       while (lp[prm] != prm) {         count[i]++;         prm = prm / lp[prm];       }     }     count = vsum(count);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       cout << count[a] - count[b] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   clock_t __stt;   inline void TStart() { __stt = clock(); }   inline void TReport() {     printf(  nTaken Time : %.3lf sec n ,            (double)(clock() - __stt) / CLOCKS_PER_SEC);   }   template <typename T>   T MIN(T a, T b) {     return a < b ? a : b;   }   template <typename T>   T MAX(T a, T b) {     return a > b ? a : b;   }   template <typename T>   T ABS(T a) {     return a > 0 ? a : (-a);   }   template <typename T>   void UMIN(T &a, T b) {     if (b < a) a = b;   }   template <typename T>   void UMAX(T &a, T b) {     if (b > a) a = b;   }   const int bc = 6, mc = 64;   int n, m, subcnt[mc], chcnt[mc], avai[100005];   char s[100005], tmp[10];   int main() {     int i, j, k;     scanf( %s , s);     n = strlen(s);     scanf( %d , &m);     fill(avai, avai + n, mc - 1);     while (m--) {       scanf( %d%s , &j, tmp);       k = strlen(tmp);       avai[--j] = 0;       for (i = 0; i < k; ++i) {         avai[j] += (1 << (tmp[i] -  a ));       }     }     for (i = 0; i < n; ++i) {       for (j = 0; j < mc; ++j) {         if ((avai[i] & j) == avai[i]) {           ++subcnt[j];         }         if ((1 << (s[i] -  a )) & j) {           ++chcnt[j];         }       }     }     for (i = 0; i < n; ++i) {       for (j = 0; j < bc; ++j) {         if (!(avai[i] & (1 << j))) continue;         s[i] =  a  + j;         for (k = 0; k < mc; ++k) {           if ((avai[i] & k) == avai[i]) {             --subcnt[k];           }           if ((1 << j) & k) {             --chcnt[k];           }         }         for (k = 0; k < mc; ++k) {           if (chcnt[k] < subcnt[k]) break;         }         if (k == mc) break;         for (k = 0; k < mc; ++k) {           if ((avai[i] & k) == avai[i]) {             ++subcnt[k];           }           if ((1 << j) & k) {             ++chcnt[k];           }         }       }       if (j == bc) {         printf( Impossible n );         return 0;       }     }     printf( %s n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lastr, lastc;   int n, m, a, b;   int row1[10], rcnt, ans;   int main() {     int i, j, k;     while (scanf( %d%d%d%d , &n, &m, &a, &b) != EOF) {       if (m == 1) {         printf( 1 n );         continue;       }       lastr = (n + m - 1) / m;       lastc = n % m;       lastc = lastc == 0 ? m : lastc;       ans = 0, rcnt = 0;       row1[++rcnt] = (a + m - 1) / m;       if ((b + m - 1) / m != (a + m - 1) / m) {         if ((b + m - 1) / m == (a + m - 1) / m + 1)           row1[++rcnt] = (b + m - 1) / m;         else           row1[++rcnt] = row1[1] + 1, row1[++rcnt] = (b + m - 1) / m;       }       int ta = a % m, tb = b % m;       if (ta == 0) ta = m;       if (tb == 0) tb = m;       if (rcnt == 1)         printf( 1 n );       else if (rcnt == 2) {         if (ta == 1 &&             (row1[2] != lastr && tb == m || row1[2] == lastr && tb == lastc))           printf( 1 n );         else           printf( 2 n );       } else {         if (ta == 1 &&             (row1[3] != lastr && tb == m || row1[3] == lastr && tb == lastc))           printf( 1 n );         else if (ta == 1 || tb == m || ta - 1 == tb ||                  (lastr == row1[3] && lastc == tb))           printf( 2 n );         else           printf( 3 n );       }     }   }


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


#include <bits/stdc++.h>   long long minus(long long k) { return (1000000009LL - 1 + k) % 1000000009LL; }   long long multiply(long long k) { return (k * 2) % 1000000009LL; }   long long multiply(long long a, long long b) { return (a * b) % 1000000009LL; }   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long p = 1;     for (int i = 0; i < m; i++) p = multiply(p);     if (m < 20 && p < n) {       printf( 0 n );       return 0;     }     long long ans = 1;     for (int i = 0; i < n; i++) {       p = minus(p);       ans = multiply(ans, p);     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   const long long MOD = 1e9 + 7;   set<char> seen;   void solve() {     int n;     cin >> n;     string a;     string b;     cin >> a >> b;     for (int i = 0; i < n; i++) {       if (a[i] > b[i]) {         cout <<  -1 n ;         return;       }     }     int ans = 0;     for (char c =  a ; c <=  t ; c++) {       char smallest =  z ;       for (int i = 0; i < n; i++) {         if (a[i] == c) {           if (a[i] != b[i]) smallest = min(smallest, b[i]);         }       }       if (smallest !=  z ) {         ans++;         for (int i = 0; i < n; i++) {           if (a[i] == c) {             if (a[i] != b[i]) {               a[i] = smallest;             }           }         }       }     }     cout << ans <<   n ;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int TC;     cin >> TC;     while (TC--) {       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma G++ optimize(2)   using namespace std;   char nc() { return getchar(); }   int read() {     int x = 0, y = 1;     char c = nc();     while (!isdigit(c)) {       if (c ==  - ) y = -1;       c = nc();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = nc();     }     return x * y;   }   int n, p, q, up, prime[135], vst[135], bin[135];   unsigned int now = 1, C[135], ANS = 0;   void divide(int x, int op) {     for (int i = 1; i <= prime[0]; i++)       while (!(x % prime[i])) bin[i] += op, x /= prime[i];     if (op == 1 && x > 1) now *= (unsigned int)x;   }   unsigned int quick_pow(unsigned int x, int y) {     unsigned int re = 1;     while (y) {       if (y & 1) re = re * x;       x = x * x;       y >>= 1;     }     return re;   }   void pre() {     for (int i = 2; i <= up; i++) {       if (!vst[i]) prime[++prime[0]] = i;       for (int j = 1; j <= prime[0]; j++) {         if (i * prime[j] > up) break;         vst[i * prime[j]] = 1;         if (!(i % prime[j])) break;       }     }     C[0] = 1;     for (int i = 1; i <= up; i++) {       divide(n - i + 1, 1);       divide(i, -1);       C[i] = now;       for (int j = 1; j <= prime[0]; j++) C[i] *= quick_pow(prime[j], bin[j]);     }   }   int main() {     n = read();     p = read();     q = read();     up = min(n - 1, p);     pre();     for (int i = 1; i <= q; i++) {       unsigned int sm = 0, ha = 1;       for (int j = 0; j <= up; j++) sm += C[j] * ha, ha *= (unsigned int)i;       ANS ^= (sm * (unsigned int)i);     }     cout << ANS;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string s;   long long ans;   bool flag;   struct A {     int id, p, s;   };   bool comp(A a, A b) {     if (a.p > b.p) return true;     return false;   }   void solve() {     cin >> n >> m >> k;     vector<int> p(n);     for (auto i = 0; i < n; i++) cin >> p[i];     ;     vector<int> s(n);     for (auto i = 0; i < n; i++) cin >> s[i];     ;     vector<A> v(n);     for (auto i = 0; i < n; i++) {       v[i].id = i + 1;       v[i].s = s[i];       v[i].p = p[i];     }     sort(v.begin(), v.end(), comp);     unordered_set<int> school;     unordered_set<int> kid;     for (auto i = 0; i < n; i++) {       if (school.find(v[i].s) == school.end()) {         school.insert(v[i].s);         kid.insert(v[i].id);       }       int mm = school.size();       if (mm == m) break;     }     vector<int> K(k);     for (auto i = 0; i < k; i++) cin >> K[i];     ;     int count = 0;     for (auto i = 0; i < k; i++) {       if (kid.find(K[i]) == kid.end()) {         count++;       }     }     cout << count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 3, mod = 1e9 + 7, inf = 3e18 + 7;   long long tc, n, m, a, b, c, d, i, j, k;   long long A[N], odd[N], even[N];   string s[N];   vector<long long> vec;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> tc;     while (tc--) {       cin >> n;       long long sum = 0, ans = 0, mx;       for (i = 1; i <= n; i++) cin >> A[i], sum += (i % 2 ? A[i] : 0);       A[n + 1] = A[n];       for (i = 2; i <= n; i += 2) even[i] = even[i - 2] + A[i] - A[i - 1];       for (i = 2; i <= n; i += 2) odd[i] = odd[i - 2] + A[i] - A[i + 1];       if (n % 2) n--;       for (i = n, mx = even[n]; i > 0; i -= 2)         mx = max(mx, even[i]), ans = max(ans, mx - even[i - 2]);       for (i = n, mx = odd[n]; i > 0; i -= 2)         mx = max(mx, odd[i]), ans = max(ans, mx - odd[i - 2]);       cout << ans + sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y;     cin >> x >> y;     long long n;     cin >> n;     n %= 6;     if (n == 0) n = 6;     long long data[7];     data[1] = x;     data[2] = y;     for (int i = 3; i <= 6; i++) {       data[i] = data[i - 1] - data[i - 2];     }     for (int i = 1; i <= 6; i++)       if (data[i] < 0) data[i] += 1000000007;     if (data[n] < 0) data[n] += 1000000007;     cout << data[n] % 1000000007 <<   n ;     return 0;   }


#include <bits/stdc++.h>   long long read() {     long long res = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();     return res * flag;   }   void print(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   const long long N = 5000 + 5;   long long n, k, a[N], c[N];   std::vector<long long> g[N];   void solution() {     n = read(), k = read();     long long tot = 0;     for (long long i = (1); i <= (n); ++i) a[i] = read(), g[a[i]].push_back(i);     for (long long i = (1); i <= (N - 1); ++i) {       if (g[i].size() > k) {         puts( NO );         return;       }       for (auto v : g[i]) c[v] = ++tot, tot %= k;     }     puts( YES );     for (long long i = (1); i <= (n); ++i) print(c[i]), putchar(   );     putchar(  n );   }   signed main() {     42;     solution();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> v(n), vec;       for (int i = 0; i < n; i++) cin >> v[i];       for (int i = 0; i < n; i++) {         if (v[i] == -1) continue;         if (i - 1 >= 0 && v[i - 1] == -1) vec.push_back(v[i]);         if (i + 1 < n && v[i + 1] == -1) vec.push_back(v[i]);       }       sort(vec.begin(), vec.end());       long long num, res = -1;       if (vec.size() == 0) num = 1;       if (vec.size() == 1) num = vec[0];       if (vec.size() >= 2) num = (vec[vec.size() - 1] + vec[0]) / 2;       for (int i = 0; i < n; i++) {         if (v[i] == -1) v[i] = num;       }       for (int i = 0; i < n - 1; i++) {         res = max(res, abs(v[i] - v[i + 1]));       }       cout << res <<     << num << endl;     }     return 0;   }


// annotshy      #include <bits/stdc++.h>   #define Task  CF    #define pb push_back   #define MOD 1000000007   #define F first   #define S second   #define int long long      using namespace std;      const int maxn = 2005;      int n, m, w;   int a[maxn][maxn];   int dx[5] = {1, 0, -1, 0};   int dy[5] = {0, 1, 0, -1};   long long dp[maxn][maxn], to1 = 0, to2 = 0;      long long BFS(int i, int j) {     queue<pair<int, int> > Q;     Q.push({i, j});     for(int p = 1; p <= n; ++ p) {       for(int q = 1; q <= m; ++ q) dp[p][q] = 1e18;     }     dp[i][j] = 0;     while(Q.size()) {       int u = Q.front().F;       int v = Q.front().S;       Q.pop();       for(int k = 0; k < 4; ++ k) {         int x = u + dx[k];         int y = v + dy[k];         if(x < 1 || y < 1 || x > n || y > m || a[x][y] == -1) continue;         if(dp[x][y] > dp[u][v] + w) {           dp[x][y] = dp[u][v] + w;           Q.push({x, y});         }       }     }     long long res = 1e18;     if(i == 1 && j == 1) to1 = dp[n][m];     if(i == n && j == m) to2 = dp[1][1];     for(int i = 1; i <= n; ++ i) {       for(int j = 1; j <= m; ++ j) if(a[i][j] > 0) {         res = min(res, dp[i][j] + a[i][j]);       }     }     return res;   }      void Solve() {     cin >> n >> m >> w;     for(int i = 1; i <= n; ++ i) {       for(int j = 1; j <= m; ++ j) cin >> a[i][j];     }     long long res1 = BFS(1, 1);     long long res2 = BFS(n, m);     if(res1 + res2 >= 1e18 && to1 == 1e18 && to2 == 1e18) cout << - 1 <<   n ;     else cout << min({to1, to2, res1 + res2}) <<   n ;   }      signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     if(fopen(Task .inp ,  r )) {       freopen(Task .inp ,  r , stdin);       freopen(Task .out ,  w , stdout);     }     int test = 1;   //  cin >> test;     while(test --) {       Solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, cv;   long long level[3501];   long long vis[3501] = {};   vector<long long> graph[3501];   vector<long long> cycles[3501];   vector<long long> z;   void dfs_cycle(long long u, long long p, long long color[], long long mark[],                  long long par[], long long& cyclenumber) {     if (color[u] == 2) {       return;     }     if (color[u] == 1) {       cyclenumber++;       long long cur = p;       mark[cur] = cyclenumber;       while (cur != u) {         cur = par[cur];         mark[cur] = cyclenumber;       }       return;     }     par[u] = p;     color[u] = 1;     for (long long v : graph[u]) {       if (v == par[u]) {         continue;       }       dfs_cycle(v, u, color, mark, par, cyclenumber);     }     color[u] = 2;   }   void printCycles(long long edges, long long mark[], long long& cyclenumber) {     for (long long i = 1; i <= edges; i++) {       if (mark[i] != 0) cycles[mark[i]].push_back(i);     }     for (long long i = 1; i <= cyclenumber; i++) {       for (long long x : cycles[i]) z.push_back(x);     }   }   void bfs(long long s) {     queue<long long> q;     q.push(s);     level[s] = 0;     vis[s] = 1;     while (!q.empty()) {       long long p = q.front();       q.pop();       for (long long i = 0; i < graph[p].size(); i++) {         if (vis[graph[p][i]] == 0) {           level[graph[p][i]] = min(level[graph[p][i]], level[p] + 1);           q.push(graph[p][i]);           vis[graph[p][i]] = 1;         }       }     }   }   void quickly_quickly_kro() {     cin >> n;     for (long long i = 1; i < n + 1; i++) {       long long a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     long long color[3501];     long long par[3501];     long long mark[3501];     long long cyclenumber = 0;     long long edges = n;     dfs_cycle(1, 0, color, mark, par, cyclenumber);     printCycles(edges, mark, cyclenumber);     for (long long i = 1; i < n + 1; i++) level[i] = (long long)2e18;     for (auto k : z) {       for (long long i = 1; i < n + 1; i++) {         vis[i] = 0;       }       bfs(k);     }     for (long long i = 1; i < n + 1; i++) {       cout << level[i] <<    ;     }   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       quickly_quickly_kro();       cout <<   n ;     }     return 0;   }


#include <iostream>   #include <map>   #include <set>   #include <queue>   #include <stack>   #include <algorithm>   #include <vector>   #include <string>   #include <iomanip>   #include <cmath>   #include <cstdio>   #include <cstring>   #include <climits>   #define Buff std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)   #define ll long long   #define inf LONG_LONG_MAX   #define Inf INT_MAX   #define endl   n       using namespace std;      const int Maxn = 1e3 + 10;   const ll Mod = 1e9 + 7;      int t, n;   char bd[Maxn][Maxn];   bool firPos1;   int posX1, posX2, posX3, posX4;   int posY1, posY2, posY3, posY4;   int dis;      void work()   {       firPos1 = false;       cin >> n;       for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)       {           cin >> bd[i][j];           if (bd[i][j] ==  * )           {               if (firPos1 == false)               {                   posX1 = i;                   posY1 = j;                   firPos1 = true;               }else               {                   posX2 = i;                   posY2 = j;               }           }       }       if (posX2 == posX1)       {           dis = 1;           if (posX1 - dis >= 1)           {               posX3 = posX1 - dis;               posX4 = posX1 - dis;               posY3 = posY1;               posY4 = posY2;           }else           {               posX3 = posX1 + dis;               posX4 = posX1 + dis;               posY3 = posY1;               posY4 = posY2;           }       }else       if (posY2 == posY1)       {           dis = 1;           if (posY1 - dis >= 1)           {               posY3 = posY1 - dis;               posY4 = posY1 - dis;               posX3 = posX1;               posX4 = posX2;           }else           {               posY3 = posY1 + dis;               posY4 = posY1 + dis;               posX3 = posX1;               posX4 = posX2;           }       }else       {           int minx = min(posX1,posX2);           int maxx = max(posX1,posX2);           int miny = min(posY1,posY2);           int maxy = max(posY1,posY2);           posX1 = minx;           posY1 = miny;           posX2 = minx;           posY2 = maxy;           posX3 = maxx;           posY3 = miny;           posX4 = maxx;           posY4 = maxy;       }       bd[posX1][posY1] =  * ;       bd[posX2][posY2] =  * ;       bd[posX3][posY3] =  * ;       bd[posX4][posY4] =  * ;       for (int i = 1; i <= n; i++)       {           for (int j = 1; j <= n; j++)               cout << bd[i][j];           cout << endl;       }   }      int main()   {       Buff;       cin >> t;       while (t--)           work();       return 0;   }


#include <bits/stdc++.h>   int main() {     int t, i, j, k;     scanf( %d , &t);     int ranges[t][2000];     int len[t];     for (i = 0; i < t; ++i) {       scanf( %d , &len[i]);       for (j = 0; j < (2 * len[i]); j += 2) {         scanf( %d %d , &ranges[i][j], &ranges[i][j + 1]);       }     }     for (i = 0; i < t; ++i) {       int num[len[i]];       for (j = 0; j < len[i]; ++j) {         num[j] = j + 1;       }       int sort[2 * len[i]];       int c = 0, diff = 0;       while (c < 2 * len[i]) {         for (j = 0; j < (2 * len[i]); j += 2) {           if (ranges[i][j + 1] - ranges[i][j] == diff) {             sort[c] = ranges[i][j];             sort[c + 1] = ranges[i][j + 1];             c += 2;           }         }         diff += 1;       }       for (j = 0; j < (2 * len[i]); j += 2) {         int d;         diff = sort[j + 1] - sort[j];         if (diff == 0) {           d = sort[j];           num[d - 1] = 0;           printf( %d %d %d n , sort[j], sort[j + 1], d);         } else {           c = sort[j + 1];           while (c >= sort[j]) {             if (num[c - 1] != 0) {               d = c;               num[c - 1] = 0;               printf( %d %d %d n , sort[j], sort[j + 1], d);               break;             }             c -= 1;           }         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pp(int n) {     for (int i = 2; i <= floor(sqrt(n)); i++) {       if (n % i == 0) return i;     }     return 1;   }   void solve() {     long long int n, k;     cin >> n >> k;     if (k > n)       cout << max(0ll, n - k / 2) << endl;     else       cout << max(0ll, (k - 1) / 2) << endl;   }   int main() {     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     ;     int n, m;     cin >> n >> m;     vector<vector<char>> v(n, vector<char>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> v[i][j];     bool st = 1;     int mx = 0;     set<int> se;     for (int i = 0; i < n; i++) {       int s = -1, g = -1;       for (int j = 0; j < m; j++) {         if (v[i][j] ==  G )           g = j;         else if (v[i][j] ==  S )           s = j;       }       if (s < g)         st = 0;       else         se.insert(s - g);     }     if (st)       cout << se.size();     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     priority_queue<int, vector<int>, greater<int> > a;     int temp;     int n, i;     int sum = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &temp);       a.push(temp);     }     temp = -1;     while (!a.empty()) {       if (a.top() == temp) {         printf( -1 n );         return 0;       } else if (a.top() == 0) {         a.pop();       } else {         temp = a.top();         a.pop();         if (!a.empty() && a.top() == temp) {           sum++;           a.pop();         }       }     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   int main() {     using namespace std;     int num, t1, t2, k;     cin >> num >> t1 >> t2 >> k;     double ms[1000];     double ms2[1000];     for (int i = 0; i < 1000; i++) {       ms[i] = 0;       ms2[i] = 0;     }     for (int i = 0; i < num; i++) {       int a, b;       cin >> a >> b;       double s1, s2;       s1 = a * t1 * ((100 - k) / 100.0) + t2 * b;       s2 = b * t1 * ((100 - k) / 100.0) + t2 * a;       if (s1 >= s2)         ms[i] = s1;       else         ms[i] = s2;       ms2[i] = ms[i];     }     stable_sort(ms, ms + num);     int same;     for (int i = num - 1; i >= 0; i--) {       if (i < num - 1 && ms[i] == ms[i + 1])         same++;       else         same = 0;       int p;       int pass = same;       for (int j = 0; j < num; j++) {         if (ms2[j] == ms[i]) {           if (pass > 0) {             pass--;             continue;           }           p = j + 1;           break;         }       }       double d = ((int)(ms[i] * 100 + 0.5)) / 100.0;       printf( %d %3.2f n , p, d);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int x[1000007], y[1000007], z[1000007], n;   string s, S;   vector<long long int> v;   int main() {     {       long long int a = 0, b = 0, c = 0, d, e, f, g, i, j, k, l, m, p, q, r, u, w,                     t, tc, in, mod, loc, diff, val, sz, lo, hi, mid,                     mn = 2134567891, mx = 0, sum = 0, ans = 0;       cin >> s;       l = s.size();       for (i = 0; i < l; i++)         if (s[i] ==  a ) a++;       if (a * 2 > l)         cout << l << endl;       else         cout << a * 2 - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643l;   void solve();   int main() {     solve();     return 0;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void solve() {     long long a, b, x1, y1, x2, y2;     cin >> a >> b >> x1 >> y1 >> x2 >> y2;     long long ans1, ans2;     long long eps11 = 0, eps12 = 0, eps21 = 0, eps22 = 0;     if (x1 + y1 < 0) eps11 = -2 * a;     if (x2 + y2 < 0) eps12 = -2 * a;     if (x1 - y1 < 0) eps21 = -2 * b;     if (x2 - y2 < 0) eps22 = -2 * b;     ans1 = (x1 + y1 + eps11) / (2 * a) - (eps12 + x2 + y2) / (2 * a);     ans2 = (eps21 + x1 - y1) / (2 * b) - (eps22 + x2 - y2) / (2 * b);     if (ans1 < 0) ans1 = -ans1;     if (ans2 < 0) ans2 = -ans2;     cout << max(ans1, ans2);   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, L, R, k, l, kk, ll, l1, r1, l2, r2, x, gcd, lcm;   inline long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       return x = 1, y = 0, a;     }     long long t = exgcd(b, a % b, y, x);     return y -= a / b * x, t;   }   int main() {     scanf( %lld%lld%lld%lld%lld%lld , &a, &c, &b, &d, &L, &R);     gcd = exgcd(a, b, k, l), lcm = a * b / gcd;     if ((d - c) % gcd) return puts( 0 ), 0;     k *= (d - c) / gcd, kk = lcm / a;     l *= (c - d) / gcd, ll = lcm / b;     l1 = max(0ll, (L - c) / a + (L - c > 0 ? (!!((L - c) % a)) : 0));     r1 = (R - c) / a - (R - c < 0 ? (!!((R - c) % a)) : 0);     l2 = max(0ll, (L - d) / b + (L - d > 0 ? (!!((L - d) % b)) : 0));     r2 = (R - d) / b - (R - d < 0 ? (!!((R - d) % b)) : 0);     x = max((l1 - k) / kk, (l2 - l) / ll);     k += x * kk, l += x * ll;     if (k < l1 || l < l2) k += kk, l += ll;     if (k > r1 || l > r2) return puts( 0 ), 0;     printf( %lld n , min((r1 - k) / kk, (r2 - l) / ll) + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t = 1;   template <class myType>   void print_arr(myType &arr, long long L, string sep) {     for (long long(i) = (0); (i) < (L); ++(i)) {       cout << arr[i];       if (i < L - 1) {         cout << sep;       }     }     cout <<   n ;     return;   }   long long merge(long long arr[], long long temp_arr[], long long left,                   long long mid, long long right) {     long long i, j, k;     i = left;     j = mid + 1;     k = left;     long long inv_count = 0;     while (i <= mid && j <= right) {       if (arr[i] <= arr[j]) {         temp_arr[k] = arr[i];         k += 1;         i += 1;       } else {         temp_arr[k] = arr[j];         inv_count += (mid - i + 1);         k += 1;         j += 1;       }     }     while (i <= mid) {       temp_arr[k] = arr[i];       k += 1;       i += 1;     }     while (j <= right) {       temp_arr[k] = arr[j];       k += 1;       j += 1;     }     for (long long loop_var = left; loop_var <= right; loop_var++) {       arr[loop_var] = temp_arr[loop_var];     }     return inv_count;   }   long long _mergeSort(long long arr[], long long temp_arr[], long long left,                        long long right) {     long long inv_count = 0;     if (left < right) {       long long mid;       mid = (left + right) / 2;       inv_count += _mergeSort(arr, temp_arr, left, mid);       inv_count += _mergeSort(arr, temp_arr, mid + 1, right);       inv_count += merge(arr, temp_arr, left, mid, right);     }     return inv_count;   }   long long mergeSort(long long arr[], long long n) {     long long temp_arr[n];     for (long long(i) = (0); (i) < (n); ++(i)) temp_arr[i] = 0;     return _mergeSort(arr, temp_arr, 0, n - 1);   }   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long(i) = (0); (i) < (n); ++(i)) cin >> a[i];     long long invs, invs2;     long long b[n];     for (long long(i) = (0); (i) < (n); ++(i)) b[i] = a[i];     invs = mergeSort(b, n);     long long ans = 0;     long long p;     for (long long(i) = (0); (i) < (30); ++(i)) {       p = (1 << i);       for (long long(j) = (0); (j) < (n); ++(j)) b[j] = a[j] ^ p;       invs2 = mergeSort(b, n);       if (invs2 < invs) {         ans += p;       }     }     for (long long(j) = (0); (j) < (n); ++(j)) b[j] = a[j] ^ ans;     cout << mergeSort(b, n) <<     << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     bool arr[26] = {false};     for (int i = 0; i < k; i++) {       char c;       cin >> c;       arr[c -  a ] = true;     }     long long ans = 0;     long long co = 0;     for (int i = 0; i < n; i++) {       int x;       x = s[i] -  a ;       if (arr[s[i] -  a ] == true)         co++;       else {         ans += (co * (co + 1)) / 2;         co = 0;       }     }     ans += (co * (co + 1)) / 2;     cout << ans;   }


#include <bits/stdc++.h>   inline int gi() {     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;   }   std::set<std::pair<int, int> > M;   struct yyb {     int x, y, i;     long double k, b;   } s[300010], stk[300010];   inline bool cmp_k(const yyb& a, const yyb& b) {     if (a.y != b.y)       return a.y < b.y;     else       return a.x > b.x;   }   inline bool cmp_i(const yyb& a, const yyb& b) { return a.i < b.i; }   int main() {     int n = gi();     for (int i = 1; i <= n; ++i)       s[i].x = gi(), s[i].y = gi(), s[i].i = i, s[i].k = 1000000000.0 / s[i].y,       s[i].b = 1000000000.0 / s[i].x;     std::sort(s + 1, s + n + 1, cmp_k);     int top = 0;     stk[++top] = (yyb){0, 0, 0, 1e18, 0};     for (int i = 1; i <= n; ++i) {       if (s[i].y == s[i - 1].y) continue;       while (top > 1 && stk[top].y != stk[top - 1].y &&              (-(s[i].b - stk[top].b) / (s[i].k - stk[top].k) + 1e-15 <               -(stk[top].b - stk[top - 1].b) / (stk[top].k - stk[top - 1].k))) {         --top;       }       stk[++top] = s[i];     }     std::sort(s + 1, s + n + 1, cmp_i);     for (int i = 1; i <= top; ++i) M.insert(std::make_pair(stk[i].x, stk[i].y));     for (int i = 1; i <= n; ++i)       if (M.find(std::make_pair(s[i].x, s[i].y)) != M.end()) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6 + 1;   const int INF = 2e9 + 1;   const int MOD = (1e9 + 7);   void bye(string s =   ) {     cout << s <<   n ;     exit(0);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> arr(2);       for (int i = 0; i < n; i++) {         int a;         cin >> a;         arr[a % 2]++;       }       if (arr[1] % 2 || (arr[1] && arr[0])) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     bye();   }


#include <bits/stdc++.h>   using namespace std;   const bool debug = false;   const int maxn = 1002003;   const long long magic = 1000 * 1000 * 1000 + 7;   int n, k;   long long aa[maxn];   struct RMQ {     int l, r;     RMQ *left, *right;     long long res;     int resIndex;   };   RMQ* build(long long* vs, int l, int r) {     RMQ* res = new RMQ();     res->l = l;     res->r = r;     if (r - l >= 2) {       int m = (l + r) / 2;       res->left = build(vs, l, m);       res->right = build(vs, m, r);       if (res->left->res >= res->right->res) {         res->res = res->left->res;         res->resIndex = res->left->resIndex;       } else {         res->res = res->right->res;         res->resIndex = res->right->resIndex;       }     } else {       res->left = nullptr;       res->right = nullptr;       res->res = vs[l];       res->resIndex = l;     }     return res;   }   pair<long long, int> rmqGet(RMQ* q, int l, int r) {     if (q->r <= l || r <= q->l) return make_pair(-100, -1);     if (l <= q->l && q->r <= r) return make_pair(q->res, q->resIndex);     auto [res1, res1index] = rmqGet(q->left, l, r);     auto [res2, res2index] = rmqGet(q->right, l, r);     if (res1 >= res2)       return make_pair(res1, res1index);     else       return make_pair(res2, res2index);   }   int ls[maxn];   int rs[maxn];   RMQ* rmq;   void findLR(int l, int r) {     if (debug) cout <<  findLR:   << l <<     << r << endl;     if (r - l < 2) return;     auto [res, resIndex] = rmqGet(rmq, l + 1, r);     if (debug)       cout <<  rmqGet:   << (l + 1) <<     << r <<     << res <<     << resIndex            << endl;     ls[resIndex] = l;     rs[resIndex] = r;     findLR(l, resIndex);     findLR(resIndex, r);   }   long long countLen(int len) {     if (len < k) return 0;     int rest = len - k;     long long count = rest / (k - 1);     long long res =         (len + 1) * (count + 1) - (count + 1) * (k + k + count * (k - 1)) / 2;     return res;   }   long long countIndex(int i) {     int len = rs[i] - (ls[i] + 1);     long long res =         countLen(len) - countLen(i - (ls[i] + 1)) - countLen(rs[i] - (i + 1));     if (debug) cout <<  countIndex:   << i <<     << res << endl;     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> aa[i];     aa[0] = aa[n + 1] = 1200ll * 1000 * 1000;     rmq = build(aa, 0, n + 2);     findLR(0, n + 1);     if (debug)       for (int i = 1; i <= n; i++) cout << ls[i] <<     << rs[i] << endl;     long long res = 0;     for (int i = 1; i <= n; i++) {       long long c = countIndex(i) % magic;       res = (res + aa[i] * c) % magic;     }     cout << res << endl;     if (debug)       for (int i = 0; i <= 20; i++)         cout <<  len:   << i <<  :   << countLen(i) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ans =  1001010111001010 ;   int n;   int main() {     cin >> n;     cout << ans[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n, k, size[maxn];   bool f[maxn];   long long dp[maxn];   vector<int> g[maxn];   void dfs(int u, int fa) {     if (f[u])       size[u] = 1;     else       size[u] = 0;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       dfs(v, u);       size[u] += size[v];       dp[u] += dp[v] + size[v];     }   }   long long ans = 0;   int solve(int u, int fa) {     int sum = (f[u] ? 1 : 0);     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       sum += solve(v, u);     }     ans += min(sum, 2 * k - size[u]);     return min(sum, 2 * k - size[u]);   }   int main() {     scanf( %d%d , &n, &k);     int x;     for (int i = 1; i <= 2 * k; i++) scanf( %d , &x), f[x] = 1;     int u, v;     for (int i = 1; i <= n - 1; i++)       scanf( %d%d , &u, &v), g[u].push_back(v), g[v].push_back(u);     dfs(1, -1);     solve(1, -1);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> c(n);     bool d[2];     for (int i = 0; i < n; i++) {       cin >> c[i];       d[c[i] % 2] = 1;     }     if (d[0] && d[1]) {       sort(c.begin(), c.end());     }     for (int i : c) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 5e5 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   int n, id, a, b;   vector<int> v[MAX], ans[MAX];   void dfs(int nw, int par) {     for (auto i : v[nw]) {       if (i == par) continue;       ans[i].push_back(++id);     }     ans[nw].push_back(++id);     reverse(v[nw].begin(), v[nw].end());     for (auto i : v[nw]) {       if (i == par) continue;       dfs(i, nw);     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i)       cin >> a >> b, v[a].push_back(b), v[b].push_back(a);     ans[1].push_back(++id);     dfs(1, 0);     for (int i = 1; i <= n; ++i) cout << ans[i][0] <<     << ans[i][1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const vector<int> mods = {998244353, 1000000007, 1000000009};   const long long inf = 3e18;   const double pi = acos(-1.0);   const double eps = 0.0000001;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class... K>   using umap = unordered_map<K...>;   template <class... K>   using uset = unordered_set<K...>;   double dp[200];   long long lad[200];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.precision(13);     fill(&dp[0], &dp[0] + sizeof(dp) / sizeof(dp[0]), 0);     for (long long i = (0); i < (10); ++i)       for (long long j = (0); j < (10); ++j) {         long long fw = i & 1;         long long up;         cin >> up;         if (!up) continue;         long long node = 10 * (9 - i) + (fw ? j : 9 - j);         long long nxfw = (i + up) & 1;         long long nx = 10 * (9 - i + up) + (nxfw ? j : 9 - j);         lad[node] = nx;       }     dp[99] = 0.0;     for (long long i = 98; i >= 0; i--) {       double mv = 0;       double ex = 0;       for (long long j = (1); j < (7); ++j) {         double nx = dp[i + j];         if (lad[i + j]) {           nx = min(nx, dp[lad[i + j]]);         }         mv += 1.0 / 6 * nx;         if (i + j > 99) ex++;       }       mv++;       mv /= (1 - ex / 6.0);       dp[i] = mv;     }     cout << dp[0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++) {       int val;       cin >> val;       if (val >= 0)         ans += val;       else         ans -= val;     }     cout << ans << endl;   }


#include <iostream>   #include <unordered_map>   #include <list>   #include <queue>   #include <string.h>   #include <stack>   #include <set>   #include <unordered_set>   #include <map>   #include <climits>   #include <algorithm>   #include <math.h>   #include <vector>   #include <iomanip>   #include <ctype.h>   using namespace std;   #define ll long long int   const int MOD = 1e9 + 7;   ll facto[200010];   void fact()   {       facto[0] = 1;       for (ll i = 1; i < 200010; i++)       {           facto[i] = (i * facto[i - 1]) % MOD;       }   }   bool is(ll cnt[])   {       for (int i = 0; i < 26; i++)       {           if (cnt[i] >= 2)               return false;       }       return true;   }   int main()   {       // fact();       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll n;       cin >> n;       ll a[n];       ll sum = 0;       for (ll i = 0; i < n; i++)       {           cin >> a[i];           sum += a[i];       }       if ((sum % 2) != 0)       {           cout <<  0  n ;           return 0;       }       bool dp[n + 1][sum / 2 + 1];       for (ll i = 0; i <= n; i++)       {           for (ll j = 0; j <= sum / 2; j++)           {               dp[i][j] = false;           }       }       for (ll i = 0; i <= n; i++)       {           dp[i][0] = true;       }       for (ll j = 0; j <= sum / 2; j++)       {           dp[0][j] = false;       }       for (ll i = 1; i <= n; i++)       {           for (ll j = 1; j <= sum / 2; j++)           {               dp[i][j] = dp[i - 1][j];               if (j - a[i - 1] >= 0)               {                   dp[i][j] = dp[i][j] || dp[i - 1][j - a[i - 1]];               }           }       }       if (dp[n][sum / 2] == false)       {           cout <<  0  n ;           return 0;       }       ll mini = LLONG_MAX;       ll pos = -1;       for (ll i = 0; i < n; i++)       {           if (a[i] % 2)           {               cout <<  1  n ;               cout << i + 1 <<   n ;               return 0;           }       }       for (ll i = 0; i < n; i++)       {           ll steps = 0;           while (a[i] % 2 == 0)           {               a[i] /= 2;               steps++;           }           if (mini > steps)           {               mini = steps;               pos = i;           }       }       cout <<  1  n ;       cout << pos + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000;   int n, t;   double p, dp[MAXN + 1][MAXN + 1], ans = 0;   int main() {     cin >> n >> p >> t;     dp[0][0] = 1;     for (int i = 0; i < t; i++)       for (int j = 0; j <= n; j++) {         if (j < n) {           dp[i + 1][j + 1] += dp[i][j] * p;           dp[i + 1][j] += dp[i][j] * (1 - p);         } else           dp[i + 1][j] += dp[i][j];       }     for (int i = 1; i <= n; i++) ans += dp[t][i] * i;     cout << fixed;     cout << setprecision(9) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q_pow(long long n, long long temp) {     long long ans = 1;     long long x = temp;     while (n) {       if (n & 1) {         ans *= x;         ans %= 1000000007;       }       x *= x;       x %= 1000000007;       n /= 2;     }     return ans;   }   int main() {     string str;     long long k;     while (cin >> str >> k) {       int len = str.size();       long long sum = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  0  || str[i] ==  5 ) {           long long a1 = q_pow(i, 2);           sum += a1;           sum %= 1000000007;         }       }       long long a = (q_pow(len * k, 2) - 1 + 1000000007) % 1000000007;       long long b = (q_pow(len, 2) - 1 + 1000000007) % 1000000007;       long long c = (a * q_pow(1000000007 - 2, b)) % 1000000007;       printf( %I64d n , (sum * c) % 1000000007);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct info {     int id, d;     bool operator<(const info &rhs) const { return d < rhs.d; }   } a[200007];   vector<pair<int, int> > res;   priority_queue<info> q;   stack<info> st;   int main() {     int n, m;     int k = 0;     int M = 0;     scanf( %d%d , &n, &m);     for (int i = 1, v; i <= n; i++) {       scanf( %d , &v);       if (v == 0) continue;       M = max(M, v);       a[i] = {i, v};       q.push(a[i]);       k++;     }     if (M >= k) {       puts( No );       return 0;     }     while (!q.empty()) {       info x = q.top();       q.pop();       if (x.d != a[x.id].d) continue;       while (x.d--) {         info g;         if (q.empty()) {           puts( No );           return 0;         }         while (!q.empty()) {           g = q.top();           q.pop();           if (g.d == a[g.id].d) break;         }         g.d--;         a[g.id].d--;         res.push_back({g.id, x.id});         if (g.d != 0) st.push(g);       }       a[x.id].d = 0;       while (!st.empty()) {         q.push(st.top());         st.pop();       }     }     puts( Yes );     if (res.size() != 0) printf( %d n , (int)res.size());     for (auto e : res) printf( %d %d n , e.first, e.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   int main() {     double r, x1, y1, x2, y2;     cin >> r >> x1 >> y1 >> x2 >> y2;     if (dist(x1, y1, x2, y2) >= r) {       printf( %.12f %.12f %.12f n , x1, y1, r);     } else if (x1 == x2 && y1 == y2) {       double r1 = r / 2.0;       double x3 = x1 - r1;       double y3 = y1;       printf( %.12f %.12f %.12f n , x3, y3, r1);     } else {       double r1 = (dist(x1, y1, x2, y2) + r) / 2.0;       double d1 = dist(x1, y1, x2, y2);       double d2 = r1 - d1;       double alpha1 = d1 / (d1 + d2);       double alpha2 = d2 / (d1 + d2);       double x3 = (x1 - alpha2 * x2) / alpha1;       double y3 = (y1 - alpha2 * y2) / alpha1;       printf( %.12f %.12f %.12f n , x3, y3, r1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int m = 0;     while (n > 9) {       n -= 9;       m += 9 + n % 10;       n /= 10;     }     cout << m + n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t, n, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     long long int ans = 0;     long long int pre[n + 1];     memset(pre, 0, sizeof(pre));     for (i = 1; i < n + 1; i++) pre[i] = pre[i - 1] + a[i - 1];     set<long long int> s;     int start = -1;     for (i = 0; i < n; i++) {       if (start < i) {         start = i;         s.insert(pre[i]);       }       while (start < n && !s.count(pre[start + 1])) {         start++;         s.insert(pre[start]);       }       s.erase(pre[i]);       ans += start - i;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int dx[] = {0, -1, 0, 1};   int dy[] = {-1, 0, 1, 0};   char a[505][505];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i] + 1;     bool flag = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (int k = 0; k <= 3; k++) {           if (a[i + dx[k]][j + dy[k]] ==  S  && a[i][j] ==  W ) flag = 0;           if (a[i + dx[k]][j + dy[k]] ==  W  && a[i][j] ==  S ) flag = 0;         }         if (a[i][j] !=  W  && a[i][j] !=  S ) a[i][j] =  D ;       }     if (flag == 0) {       cout <<  No  << endl;     } else {       cout <<  Yes  << endl;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cout << a[i][j];         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int fa[N], mx[N], n;   vector<int> son[N];   vector<int> ans;   bool cmp(const int x, const int y) { return mx[x] < mx[y]; }   void dfs(int x) {     int s = son[x].size();     for (int i = 0; i < s; ++i) {       int& sn = son[x][i];       dfs(sn);       mx[x] = max(mx[x], mx[sn] + 1);     }     sort(son[x].begin(), son[x].end(), cmp);   }   void DFS(int x) {     printf( %d  , x);     for (int i = 0; i < son[x].size(); ++i) {       int& sn = son[x][i];       DFS(sn);       if (i == 0) continue;       for (int j = 0; j <= mx[son[x][i - 1]]; ++j) ans.push_back(sn);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d , &fa[i]);       son[fa[i]].push_back(i);     }     dfs(0);     DFS(0);     int s = ans.size();     printf(  n%d n , s);     for (int i = 0; i < s; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = long double;   using str = string;   using pi = pair<int, int>;   template <class T>   using V = vector<T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   using vi = V<int>;   using vb = V<bool>;   using vpi = V<pi>;   const int MOD = 1e9 + 7;   const db PI = acos((db)-1);   mt19937 rng(0);   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U first) {     ++hi;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   using T = db;   const T EPS = 1e-9;   using P = pair<T, T>;   using vP = V<P>;   using Line = pair<P, P>;   int sgn(T a) { return (a > EPS) - (a < -EPS); }   T sq(T a) { return a * a; }   T norm(P p) { return sq(p.first) + sq(p.second); }   T abs(P p) { return sqrt(norm(p)); }   T arg(P p) { return atan2(p.second, p.first); }   P conj(P p) { return P(p.first, -p.second); }   P perp(P p) { return P(-p.second, p.first); }   P dir(T ang) { return P(cos(ang), sin(ang)); }   const int mx = 100005;   struct Eff {     int n, k;     P hab[mx];     bool works(db r) {       V<pair<db, int>> ch;       for (int i = 1; i <= n; i++) {         if (abs(hab[i]) <= 2.0 * r - EPS) {           db theta_diff = PI / 2.0 - asin(abs(hab[i]) / 2.0 / r);           db theta = arg(hab[i]);           assert(theta_diff <= PI / 2.0);           ch.push_back(make_pair(theta - theta_diff, +1));           ch.push_back(make_pair(theta + theta_diff, -1));           ch.push_back(make_pair(theta - theta_diff + 2 * PI, +1));           ch.push_back(make_pair(theta + theta_diff + 2 * PI, -1));         }       }       sort(begin(ch), end(ch));       int running_sum = 0;       for (auto u : ch) {         running_sum += u.second;         if (0 <= u.first && u.first <= 2 * PI) {           if (running_sum >= k) return true;         }       }       return false;     }     void solve() {       cin >> n >> k;       for (int i = 1; i <= n; i++) {         cin >> hab[i].first >> hab[i].second;       }       db lo = EPS;       db hi = 200005.0;       for (int i = 0; i < 50; i++) {         db mid = (lo + hi) / 2;         if (works(mid)) {           hi = mid;         } else {           lo = mid;         }       }       cout << lo <<   n ;     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     cout << fixed << setprecision(10);     Eff e;     e.solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   long long n, a[200005], c[200005], cc[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 1; i < n + 1; i++) cin >> a[i];       for (long long i = 1; i < n + 1; i++) {         long long k = 1;         if (c[i - 1] == 1) k = 2;         long long j = i;         while (j <= n && a[j] == a[i]) c[j] = k, j++;         i = j - 1;       }       if (c[1] == c[n] && a[1] != a[n]) {         bool ok = false;         for (long long i = 1; i < n; i++) {           if (c[i] == c[i + 1]) {             for (long long j = i + 1; j < n + 1; j++) {               if (c[j] == 1)                 c[j] = 2;               else                 c[j] = 1;             }             ok = true;             break;           }         }         if (!ok) c[n] = 3;       }       long long mx = 0;       for (long long i = 1; i < n + 1; i++) mx = max(mx, c[i]);       cout << mx <<   n ;       for (long long i = 1; i < n + 1; i++) cout << c[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h1, h2, n;   int v[111];   char c[111];   int a[111];   int b[111];   const double eps = 1e-9;   int main() {     cin >> h1 >> h2 >> n;     for (int i = (0); i < (n); i++) cin >> v[i] >> c[i] >> a[i] >> b[i];     int best = 0;     for (int i = -200; i <= 200; i++) {       bool good = 1;       int sum = 0;       set<int> used;       int x1 = 0;       int y1 = h1;       int x2 = 100000;       int y2 = h2 + i * 100;       if (i % 2) y2 = 100 - h2 + i * 100;       if (i > 0) {         for (int j = (0); j < (i); j++) {           int y = 100 + 100 * j;           double x = double(x2 - x1) / (y2 - y1) * (y - y1);           bool found = 0;           for (int k = (0); k < (n); k++)             if (a[k] <= x + eps && b[k] >= x - eps) {               if (j % 2 == 0 && c[k] ==  T  || j % 2 == 1 && c[k] ==  F ) {                 if (used.count(k)) good = 0;                 used.insert(k);                 sum += v[k];                 found = 1;                 break;               }             }           if (!found) good = 0;         }       } else if (i < 0) {         for (int j = (0); j < (-i); j++) {           int y = -100 * j;           double x = double(x2 - x1) / double(y2 - y1) * (y - y1);           bool found = 0;           for (int k = (0); k < (n); k++)             if (a[k] <= x + eps && b[k] >= x - eps) {               if (j % 2 == 0 && c[k] ==  F  || j % 2 == 1 && c[k] ==  T ) {                 if (used.count(k)) good = 0;                 used.insert(k);                 sum += v[k];                 found = 1;                 break;               }             }           if (!found) good = 0;         }       }       if (good) best = max(best, sum);     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, i, j, b, c, a;       cin >> a >> b >> c;       long long int y = a + b + c;       y--;       cout << y << endl;     }   }