#include <bits/stdc++.h>   const long long MOD = 1000 * 1000 * 1000 + 7;   const long long MOD1 = 998244353;   const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (long long)(res * x);       y = y >> 1;       if (x <= 100000000) x = (long long)(x * x);     }     return res;   }   long long val[5001][5001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n + 1];     for (int(i) = (1); (i) < (n + 1); ++(i)) {       cin >> a[i];       val[i][i] = a[i];     }     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= n - i + 1; j++) {         val[j][j + i - 1] = val[j][j + i - 2] ^ val[j + 1][j + i - 1];       }     }     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= n - i + 1; j++) {         val[j][j + i - 1] =             max(val[j][j + i - 1], max(val[j][j + i - 2], val[j + 1][j + i - 1]));       }     }     long long q;     cin >> q;     while (q--) {       long long x, y;       cin >> x >> y;       cout << val[x][y] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename TT>   ostream& operator<<(ostream& out, pair<T, TT> t) {     return out <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> t) {     for (int i = 0; i < ((int)(t).size()); i++) out << t[i] <<    ;     return out;   }   template <typename T>   inline bool cmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   void read(T& x) {     int f = 1;     char ch;     x = 0;     while (!isdigit(ch = getchar()))       ;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int NX = 201234;   int n, m, p[NX];   map<int, int> e[NX];   int main() {     read(n);     read(m);     for (int i = 1, u, v; i <= m; i++) {       read(u);       read(v);       e[u][v] = e[v][u] = true;     }     for (int i = 1; i <= n; i++) p[i] = i;     for (int T = 200; T--;) {       random_shuffle(p + 1, p + n + 1);       int cnt = 0;       for (int i = 1; i <= n; i++) {         int l = p[i], r = p[i % n + 1];         cnt += !e[l].count(r);       }       if (cnt >= m) {         for (int i = 1; i <= n; i++) {           int l = p[i], r = p[i % n + 1];           if (!e[l].count(r)) {             printf( %d %d n , l, r);             if (!--m) return 0;           }         }       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1e9 + 7, len = 1 << 16;   char ch[100012];   int n, m, dp[502][100012], js, s[100012], tot, f[100012], val[100012];   inline void fwt_or(int x[], int mde) {     for (int i = 2; i <= len; i <<= 1)       for (int j = 0, stp = i >> 1; j < len; j += i)         for (int k = j; k < j + stp; k++)           (x[k + stp] += 1ll * mde * x[k] % p) %= p;   }   inline void fwt_and(int x[], int mde) {     for (int i = 2; i <= len; i <<= 1)       for (int j = 0, stp = i >> 1; j < len; j += i)         for (int k = j; k < j + stp; k++)           (x[k] += 1ll * mde * x[k + stp] % p) %= p;   }   int solve(int l, int r) {     int ret = ++js, mid;     if (l == r) {       if (ch[l] ==  ? ) {         for (int i = 0; i < 4; i++) {           int va = 0;           for (int j = 0; j < 16; j++)             if (j & (1 << i)) va |= 1 << j;           dp[ret][va]++;           va = 0;           for (int j = 0; j < 16; j++)             if (!(j & (1 << i))) va |= 1 << j;           dp[ret][va]++;         }       } else if (ch[l] >=  A  && ch[l] <=  D ) {         int va = 0;         for (int j = 0; j < 16; j++)           if (j & (1 << (ch[l] -  A ))) va |= 1 << j;         dp[ret][va]++;       } else {         int va = 0;         for (int j = 0; j < 16; j++)           if (!(j & (1 << (ch[l] -  a )))) va |= 1 << j;         dp[ret][va]++;       }       return ret;     }     tot = 0;     for (int i = l; i <= r; i++) {       if (ch[i] ==  ( )         s[++tot] = i;       else if (ch[i] ==  ) )         tot--;       else {         if (!tot) {           mid = i;           break;         }       }     }     int ls = solve(l + 1, mid - 2), rs = solve(mid + 2, r - 1);     if (ch[mid] ==  ? ) {       fwt_or(dp[ls], 1);       fwt_or(dp[rs], 1);       for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p;       fwt_or(dp[ret], p - 1);       fwt_or(dp[ls], p - 1);       fwt_or(dp[rs], p - 1);       fwt_and(dp[ls], 1);       fwt_and(dp[rs], 1);       for (int i = 0; i < len; i++) f[i] = 1ll * dp[ls][i] * dp[rs][i] % p;       fwt_and(f, p - 1);       fwt_and(dp[ls], p - 1);       fwt_and(dp[rs], p - 1);       for (int i = 0; i < len; i++) (dp[ret][i] += f[i]) %= p;     } else if (ch[mid] ==  | ) {       fwt_or(dp[ls], 1);       fwt_or(dp[rs], 1);       for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p;       fwt_or(dp[ret], p - 1);       fwt_or(dp[ls], p - 1);       fwt_or(dp[rs], p - 1);     } else {       fwt_and(dp[ls], 1);       fwt_and(dp[rs], 1);       for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p;       fwt_and(dp[ret], p - 1);       fwt_and(dp[ls], p - 1);       fwt_and(dp[rs], p - 1);     }     return ret;   }   int main() {     scanf( %s , ch + 1);     n = strlen(ch + 1);     int rt = solve(1, n);     memset(val, -1, sizeof(val));     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int a, b, c, d, w;       scanf( %d%d%d%d%d , &a, &b, &c, &d, &w);       val[a | (b << 1) | (c << 2) | (d << 3)] = w;     }     int ans = 0;     for (int i = 0; i < len; i++) {       bool flag = true;       for (int j = 0; j < 16; j++)         if (val[j] != -1) {           if (((i >> j) & 1) != val[j]) {             flag = false;             break;           }         }       if (flag) ans = (ans + dp[rt][i]) % p;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int func(int n) {     int sum = 1;     if (n == 3) return 4;     if (n == 2) return 2;     if (n == 1) return 1;     if (n % 2 == 0) {       sum += 2 * (n / 2 - 1) + 1 + func(n - 2);     } else {       sum += 2 * (n - 1) / 2 + func(n - 2);     }     return sum;   }   int main() {     {       int n;       int r = 1;       int i = 0;       cin >> n;       cout << func(n);       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   int a[N], n;   int dp[N][N / 2][2][2];   int solve(int idx, int lft, bool b4, bool b44) {     if (lft < 0) return 1e9;     if (idx == n) {       if (lft) return 1e9;       return 0;     }     int &ret = dp[idx][lft][b4][b44];     if (~ret) return ret;     ret = solve(idx + 1, lft, 0, b4);     if (!b4) {       int x;       int cost1 = 0, cost2 = 0;       if (b44) {         x = min(a[idx - 1], a[idx - 2] - 1);       } else         x = a[idx - 1];       if (idx) cost1 = max(0, x - (a[idx] - 1));       if (idx != n - 1) {         cost2 = max(0, a[idx + 1] - (a[idx] - 1));       }       ret = min(ret, solve(idx + 1, lft - 1, 1, 0) + cost1 + cost2);     }     return ret;   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 1; i <= (n + 1) / 2; i++) {       printf( %d  , solve(0, i, 0, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1e9 + 7;   const int sz = 1e5 + 10;   int main() {     int n, x;     set<int> ans, st, ha;     while (cin >> n) {       ans.clear();       st.clear();       for (int i = 0; i < n; i++) {         ha.clear();         cin >> x;         ha.insert(x);         ans.insert(x);         for (int xx : st) {           ha.insert(x | xx);           ans.insert(x | xx);         }         st = ha;       }       cout << ans.size() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n + 1, -1);     for (int i = 1; i <= n; i++) {       int temp;       cin >> temp;       arr[i] = temp;     }     int ans = 0;     vector<int> mini(n + 1, -1);     vector<int> maxi(n + 1, -1);     vector<int> equal(n + 1, -1);     equal[1] = 1;     mini[1] = 1;     maxi[1] = 1;     for (int i = 2; i <= n; i++) {       if (arr[i] != arr[i - 1])         equal[i] = 1;       else {         equal[i] = equal[i - 1] + 1;         mini[i] = mini[i - 1] + 1;         maxi[i] = maxi[i - 1] + 1;       }       if (arr[i] > arr[i - 1]) {         maxi[i] = max(mini[i - 1] + 1, equal[i - 1] + 1);         mini[i] = 1;       }       if (arr[i] < arr[i - 1]) {         mini[i] = max(maxi[i - 1] + 1, equal[i - 1] + 1);         maxi[i] = 1;       }       int temp = max(mini[i], max(maxi[i], equal[i]));       if (temp > ans) ans = temp;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int val, l, r;   } a[100010];   int rt, n;   bool to[100010];   map<int, bool> ma;   vector<int> v;   void dfs(int u, int maxx, int minn) {     if (u == -1) return;     if (a[u].val > maxx && a[u].val < minn) ma[a[u].val] = true;     dfs(a[u].l, maxx, min(a[u].val, minn));     dfs(a[u].r, max(a[u].val, maxx), minn);     return;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i].val, &a[i].l, &a[i].r);       if (a[i].l != -1) to[a[i].l] = true;       if (a[i].r != -1) to[a[i].r] = true;     }     for (int i = 1; i <= n; i++)       if (to[i] == false) rt = i;     dfs(rt, -1, 1e9 + 1);     int ans = 0;     for (int i = 1; i <= n; i++)       if (ma[a[i].val] == false) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int sig;     int bz;     char s[11];     int get() {       int len = strlen(s);       int x = 0;       if (s[0] ==  0 ) return 0;       for (int i = 0; i < len; i++)         if (s[i] <  0  || s[i] >  9 )           return 0;         else           x = x * 10 + s[i] -  0 ;       return x;     }   } f[200000], g[200000], c[200000], d[200000];   int a[200000 * 4], b[200000 * 4];   int tot, m, calc, totc, totd;   int ans[200000][2];   void ins(int* f, int l, int r, int s, int ll, int v) {     if (l == r) {       f[s] = v;       return;     }     if ((l + r) / 2 >= ll)       ins(f, l, (l + r) / 2, s + s, ll, v);     else       ins(f, (l + r) / 2 + 1, r, s + s + 1, ll, v);     f[s] = min(f[s + s], f[s + s + 1]);   }   int get(int* f, int l, int r, int s) {     if (l == r) {       f[s] = 1;       return l;     }     if (!f[s + s]) {       int x = get(f, l, (l + r) / 2, s + s);       f[s] = min(f[s + s], f[s + s + 1]);       return x;     } else {       int x = get(f, (l + r) / 2 + 1, r, s + s + 1);       f[s] = min(f[s + s], f[s + s + 1]);       return x;     }   }   void clear(int* f, int l, int r, int s, int ll) {     if (l == r) {       f[s] = 0;       return;     }     if ((l + r) / 2 >= ll)       clear(f, l, (l + r) / 2, s + s, ll);     else       clear(f, (l + r) / 2 + 1, r, s + s + 1, ll);     f[s] = min(f[s + s], f[s + s + 1]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf(  %s %d , f[i].s, &f[i].sig);       f[i].bz = i;       m += f[i].sig;     }     for (int i = 1; i <= n; i++) {       int x = f[i].get();       if (x && x <= m) {         ins(a, 1, m, 1, x, i);         if (!f[i].sig) c[++totc] = f[i];       } else if (x && x <= n) {         ins(b, 1, n - m, 1, x - m, i);         if (f[i].sig) d[++totd] = f[i];       } else         g[++tot] = f[i];     }     int lc = 1, ld = 1, extra = n;     int tot1 = tot;     while (lc <= totc || ld <= totd) {       if (!b[1] && lc <= totc) {         ans[++calc][0] = c[lc].bz;         ans[calc][1] = get(b, 1, n - m, 1) + m;         clear(a, 1, m, 1, c[lc].get());         lc++;       } else if (!a[1] && ld <= totd) {         ans[++calc][0] = d[ld].bz;         ans[calc][1] = get(a, 1, m, 1);         clear(b, 1, n - m, 1, d[ld].get() - m);         ld++;       } else if (lc <= totc) {         ans[++calc][0] = c[lc].bz;         ans[calc][1] = ++extra;         clear(a, 1, m, 1, c[lc].get());         g[++tot] = c[lc];         lc++;       } else {         ans[++calc][0] = d[ld].bz;         ans[calc][1] = ++extra;         clear(b, 1, n - m, 1, d[ld].get() - m);         g[++tot] = d[ld];         ld++;       }     }     for (int i = 1; i <= tot1; i++)       if (g[i].sig) {         ans[++calc][0] = g[i].bz;         ans[calc][1] = get(a, 1, m, 1);       } else {         ans[++calc][0] = g[i].bz;         ans[calc][1] = get(b, 1, n - m, 1) + m;       }     for (int i = tot; i > tot1; i--)       if (g[i].sig) {         ans[++calc][0] = -(extra);         extra--;         ans[calc][1] = get(a, 1, m, 1);       } else {         ans[++calc][0] = -(extra);         extra--;         ans[calc][1] = get(b, 1, n - m, 1) + m;       }     printf( %d n , calc);     for (int i = 1; i <= calc; i++)       if (ans[i][0] < 0)         printf( move %d %d n , -ans[i][0], ans[i][1]);       else         printf( move %s %d n , f[ans[i][0]].s, ans[i][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     bool used[n];     for (int i = 0; i <= n - 1; i++) used[i] = false;     int a = 0, b = n - 1;     for (int i = 0; i <= k - 1; i++) {       if (i & 1)         used[b] = true;       else         used[a] = true;       if (i & 1)         cout << (1 + (b--));       else         cout << (1 + (a++));       cout <<    ;     }     if (k & 1) {       for (int i = 0; i <= n - 1; i++) {         if (!used[i]) {           cout << i + 1 <<    ;         }       }     } else {       for (int i = n - 1; i >= 0; --i) {         if (!used[i]) {           cout << i + 1 <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d, n, a, s = 0, k;     scanf( %d , &d);     scanf( %d , &n);     scanf( %d , &a);     for (k = 1; k < n; k++) {       s += d - a;       scanf( %d , &a);     }     printf( %d n , s);     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n, m;     scanf( %d %d , &n, &m);     long long a[1000 + 1];     long long t[1000 + 1 + 1][1000 + 1];     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (int j = 0; j <= n; j++) t[n + 1][j] = 0;     for (int i = n; i >= 1; i--) {       for (int j = 0; j <= n; j++) {         t[i][j] =             std::min(t[i + 1][j] - a[i], (j > 0) ? t[i + 1][j - 1] : 1LL << 60LL);         t[i][j] = std::max(t[i][j], 0LL);       }     }     std::vector<std::pair<long long, int>> values;     for (int j = 0; j <= n; j++) {       if (j == 0 || t[1][j] != t[1][j - 1])         values.push_back(std::make_pair(t[1][j], j));     }     std::sort(values.begin(), values.end());     for (int i = 0; i < m; i++) {       long long b;       scanf( %lld , &b);       auto it =           std::lower_bound(values.begin(), values.end(), std::make_pair(b, -1));       if (it == values.end() || it->first > b) it--;       printf( %d n , it->second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 7;   long long f[53], fac[53];   long long add(long long a, long long b) { return min(INF, a + b); }   long long mul(long long a, long long b) {     if (INF / a < b) return INF;     return a * b;   }   const int N = 50;   long long g(int n) {     if (n == 1) return 1;     return fac[n - 2];   }   void init() {     fac[0] = 1;     for (int i = 1; i <= N; i++) fac[i] = mul(fac[i - 1], i);     f[0] = 1;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= i; j++) f[i] = add(f[i], mul(f[i - j], g(j)));     return;   }   int p[53];   int q[53];   bool vis[53];   int find(int x) {     while (q[x]) x = q[x];     return x;   }   void getq(int n, long long k) {     if (n == 1) {       q[1] = 1;       return;     }     for (int i = 1; i <= n; i++) q[i] = vis[i] = 0;     q[1] = n;     vis[n] = 1;     for (int i = 2; i < n; i++) {       long long num = fac[n - i - 1];       for (int j = 1; j <= n; j++)         if (j != i && !vis[j] && find(j) != i) {           if (k <= num) {             q[i] = j;             vis[j] = true;             break;           }           k -= num;         }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) q[n] = i;     return;   }   void getp(int n, long long k) {     if (!n) return;     int len = 0;     for (int i = 1; i <= n; i++) {       long long num = mul(g(i), f[n - i]);       if (k <= num) {         len = i;         break;       }       k -= num;     }     long long num = f[n - len];     long long need = (k - 1) / num + 1;     getp(n - len, k - (need - 1) * num);     for (int i = n; i > len; i--) p[i] = p[i - len] + len;     getq(len, need);     for (int i = 1; i <= len; i++) p[i] = q[i];     return;   }   int main() {     init();     int t;     scanf( %d , &t);     while (t--) {       int n;       long long k;       scanf( %d %lld , &n, &k);       if (f[n] < k)         printf( -1 n );       else {         getp(n, k);         for (int i = 1; i <= n; i++) printf( %d  , p[i]);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 300011, log_n = 32, max_m = 111, mod = 1000000007,             inf = 1011111111;   const long double eps = 1e-7;   struct bor {     stack<pair<int, int> > st;     int t[max_n][27], res[max_n], sz[max_n], n;     bor() {       for (int i = 0; i < max_n; ++i) {         for (int q = 0; q < 27; ++q) {           t[i][q] = -1;         }       }     }     void add(int x, int y, char c) { t[x][c -  a ] = y; }     int get_sz(int v) {       int ans = 1;       for (int i = 0; i < 26; ++i) {         if (t[v][i] != -1) {           ans += get_sz(t[v][i]);         }       }       return sz[v] = ans;     }     int mrg(int v, int v1) {       int ans = 1;       for (int i = 0; i < 27; ++i) {         if (t[v][i] != -1 && t[v1][i] != -1) {           ans += mrg(t[v][i], t[v1][i]);         } else if (t[v][i] != -1) {           t[v1][i] = t[v][i];           st.push(make_pair(v1, i));         }       }       return ans;     }     void get(int v, int p) {       int mx = 0, mxx = -1;       for (int i = 0; i < 26; ++i) {         if (t[v][i] != -1 && mx < sz[t[v][i]]) {           mx = sz[t[v][i]];           mxx = i;         }       }       if (mxx == -1) {         return;       }       res[p]++;       for (int i = 0; i < 26; ++i) {         if (i == mxx) continue;         if (t[v][i] != -1) {           res[p] += mrg(t[v][i], t[v][mxx]);         }       }       while (st.size()) {         t[st.top().first][st.top().second] = -1;         st.pop();       }     }     void get_all(int v, int p) {       get(v, p);       for (int i = 0; i < 26; ++i) {         if (t[v][i] != -1) {           get_all(t[v][i], p + 1);         }       }     }   };   bor br;   int n;   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int a, b;       char c;       cin >> a >> b >> c;       br.add(a - 1, b - 1, c);     }     br.get_sz(0);     br.get_all(0, 0);     int mx = 0, mxx = 0;     for (int i = 0; i < n; ++i) {       if (mx < br.res[i]) {         mx = br.res[i];         mxx = i;       }     }     cout << n - mx << endl << mxx + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c, d;     cin >> a >> b >> c >> d;     double mx;     mx = (a / b) * (1 / (1 - (1 - a / b) * (1 - c / d)));     std::cout << std::setprecision(9) << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void Read(T &x) {     int f = 1;     char t = getchar();     while (t <  0  || t >  9 ) {       if (t ==  - ) f = -1;       t = getchar();     }     x = 0;     while (t >=  0  && t <=  9 ) {       x = x * 10 + t -  0 ;       t = getchar();     }     x *= f;   }   template <class T>   inline void chkmin(T &x, T y) {     if (x > y) x = y;   }   template <class T>   inline void chkmax(T &x, T y) {     if (x < y) x = y;   }   const int maxn = 200005;   const double inf = 2e18;   const double pi = acos(-1.0);   struct point {     long double x, y;     point() {}     point(long double x, long double y) : x(x), y(y) {}     void read() { cin >> x >> y; }   };   point operator+(const point &a, const point &b) {     return point(a.x + b.x, a.y + b.y);   }   point operator-(const point &a, const point &b) {     return point(a.x - b.x, a.y - b.y);   }   point operator*(const point &a, long double v) {     return point(a.x * v, a.y * v);   }   point operator/(const point &a, long double v) {     return point(a.x / v, a.y / v);   }   long double operator^(const point &a, const point &b) {     return a.x * b.y - a.y * b.x;   }   int n;   point P, g[maxn];   long double dis(point &a, point &b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   long double maxr = -inf, minr = inf;   void calc(point &a, point &b) {     long double A = dis(a, P), B = dis(b, P), C = dis(a, b);     long double area = (a - P) ^ (b - P);     long double Height = area * area / C;     if (A < B) swap(A, B);     if (A > B + C) return;     chkmax(maxr, Height);     chkmin(minr, Height);   }   void input() {     Read(n);     P.read();     for (register int i = 1; i <= n; i++) g[i].read();     g[0] = g[n];     for (register int i = 1; i <= n; i++) calc(g[i], g[i - 1]);   }   void solve() {     for (register int i = 1; i <= n; i++) {       chkmax(maxr, dis(g[i], P));       chkmin(minr, dis(g[i], P));     }     printf( %.18lf n , (double)(maxr - minr) * pi);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long power(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * power(a * a % md, b / 2, md) % md                         : power(a * a % md, b / 2, md) % md));   }   const int xn = 1e3 + 10;   const int xm = 2e4 + 10;   const int sq = 300;   const int inf = 1e9 + 10;   const long long INF = 1e18 + 10;   const int mod = 1e6 + 7;   const int base = 257;   const int SIG = 26;   int n, k, tb[1 << 20], dp[xn][xm], ptr, a[xm], C[xm][SIG], ans = inf;   string S;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> S >> k, n = int(S.size());     if (k == 1) {       ans = 0;       for (int i = 0; i < n; ++i) ans += (S[i] ==  1 );       return cout << ans <<   n , 0;     }     for (int mask = 0; mask < (1 << k); ++mask) {       bool flag = true;       for (int i = 0; i < k; ++i)         flag &= (!((mask & (1 << i))) | !(mask & (1 << (i + 1))));       flag &= !(mask & 1), flag &= !(mask & 2);       if (flag) tb[mask] = ptr, a[ptr++] = mask;     }     for (int t = 0; t < ptr; ++t) {       int mask = a[t] + 1;       for (int i = 2; i < 10; ++i) {         for (int bit = i; bit <= k; ++bit)           if ((mask & (1 << (bit - i)))) C[t][i] += (1 << bit);         bool flag = !(C[t][i] & (1 << k));         for (int j = 1; j < k; ++j)           if (k % j == 0) flag |= (C[t][i] & (1 << j));         for (int b1 = 2; b1 < k; ++b1)           for (int b2 = b1 + 1; b2 <= k; ++b2)             if ((C[t][i] & (1 << b1)) && (C[t][i] & (1 << b2)))               flag |= (k % (b2 - b1) == 0);         C[t][i] = (C[t][i] & (C[t][i] ^ (1 << k)));         if (!flag) C[t][i] = -1;       }     }     for (int i = 0; i < xn; ++i)       for (int j = 0; j < ptr; ++j) dp[i][j] = inf;     dp[0][0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < ptr; ++j) {         int mask = a[j];         if (S[i] ==  1 )           dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);         else {           dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);           int x = C[j][S[i] -  0 ];           if (x != -1) dp[i + 1][tb[x]] = min(dp[i + 1][tb[x]], dp[i][j]);         }       }     }     for (int i = 0; i < ptr; ++i) ans = min(ans, dp[n][i]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 109;   int a[MAX], n, k, t = 1e9, s;   int main() {     cin >> n;     for (int i = 0; i < 2 * n - 1; i++) {       cin >> a[i], s += abs(a[i]), t = min(t, abs(a[i]));       if (a[i] < 0) k++;     }     if (k % 2 && n % 2 == 0) s -= 2 * t;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int nor[200100 * 2], n, t, m, a[200100], b[200100], sola, solb, sol, pcta, pctb;   int main() {     cin >> n;     nor[++t] = 0;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       nor[++t] = a[i];     }     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> b[i];       nor[++t] = b[i];     }     sort(nor + 1, nor + t + 1);     sort(a + 1, a + n + 1);     sort(b + 1, b + m + 1);     nor[++t] = max(a[n], b[n]) + 1;     sol = -(1 << 30);     for (int i = 1; i <= t; ++i) {       int mij;       int st = 1, dr = n;       while (st <= dr) {         mij = (st + dr) >> 1;         if (a[mij] <= nor[i])           st = mij + 1;         else           dr = mij - 1;       }       pcta = (st - 1) * 2 + (n - (st - 1)) * 3;       st = 1, dr = m;       while (st <= dr) {         mij = (st + dr) >> 1;         if (b[mij] <= nor[i])           st = mij + 1;         else           dr = mij - 1;       }       pctb = (st - 1) * 2 + (m - (st - 1)) * 3;       if (pcta - pctb > sol) {         sol = pcta - pctb;         sola = pcta;         solb = pctb;       } else if (pcta - pctb == sol && pcta > sola) {         sola = pcta;         solb = pctb;       }     }     cout << sola <<  :  << solb;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<int> Edge[510];   std::vector<int> Current[510];   int Right[510];   int Left[510];   int Vis[510];   int N, M;   bool dfs(int idx) {     if (Vis[idx]) return false;     Vis[idx] = 1;     for (int i = 0; i < Current[idx].size(); i++) {       int v = Current[idx][i];       if (Left[v] == -1 || dfs(Left[v])) {         Left[v] = idx;         Right[idx] = v;         return true;       }     }     return false;   }   int bpm() {     int Ans = 0;     memset(Left, -1, sizeof(Left));     memset(Right, -1, sizeof(Right));     for (int i = 0; i < N; i++) {       memset(Vis, false, sizeof(Vis));       Ans += dfs(i);     }     return Ans;   }   int main() {     cin >> N >> M;     int u, v;     for (int i = 0; i < M; i++) {       cin >> u >> v;       u -= 1, v -= 1;       Edge[u].push_back(v);     }     int Ans = 1e9;     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) Current[j].clear();       int cnt = 0, other = 0;       for (int j = 0; j < N; j++) {         for (int k = 0; k < Edge[j].size(); k++) {           if (j == i || Edge[j][k] == i) {             cnt += 1;             continue;           }           other += 1;           Current[j].push_back(Edge[j][k]);         }       }       int max_match = bpm();       Ans = min(Ans, 2 * N - 1 + other - cnt - 2 * max_match + N - 1);     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n, t1, t2;     double k;     cin >> n >> t1 >> t2 >> k;     k /= 100;     k = 1 - k;     double c[n + 1];     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b;       int tema = a;       int temb = b;       a = max(a, temb);       b = min(tema, b);       if (t1 * k >= t2) {         c[i] = t1 * a * k + t2 * b;       } else {         c[i] = t1 * b * k + t2 * a;       }     }     int g[n + 1];     for (int i = 1; i <= n; i++) {       g[i] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         if (c[j] > c[i] || (c[j] == c[i] && g[j] < g[i])) {           double temb = c[i];           c[i] = c[j];           c[j] = temb;           int temb2 = g[i];           g[i] = g[j];           g[j] = temb2;         }       }     }     for (int i = 1; i <= n; i++) {       cout << g[i] <<     << fixed << setprecision(2) << c[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 10;   vector<int> u[N], v[N], v2[N];   vector<pair<int, int> > q[N];   int t, st[N], fi[N], di[N], g[N], par[N];   int root(int u) { return (par[u] == u) ? u : par[u] = root(par[u]); }   void merge1(int x, int y) {     int dx = root(x), dy = root(y);     if (dx == dy) return;     par[dy] = dx;   }   bool mark[N], ans[N];   void dfs(int u) {     mark[u] = true;     st[u] = t++;     for (int i = 0; i < v[u].size(); i++) {       if (!mark[v[u][i]]) dfs(v[u][i]);     }     fi[u] = t++;   }   int main() {     int n, m, p = 1, j = 1;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a;       u[i].push_back(a);       if (a == 1) {         cin >> b >> c;         u[i].push_back(b);         u[i].push_back(c);         v[c].push_back(b);         di[b]++;       }       if (a == 2) {         cin >> b;         u[i].push_back(b);         u[i].push_back(p);         p++;       }       if (a == 3) {         cin >> b >> c;         u[i].push_back(b);         u[i].push_back(c);         q[c].push_back({b, j++});       }     }     for (int i = 1; i <= n; i++) par[i] = i;     for (int i = 1; i <= n; i++) {       if (di[i] == 0) dfs(i);     }     for (int i = 1; i <= n; i++) {     }     for (int i = 0; i < m; i++) {       int a = u[i][0], b = u[i][1], c = u[i][2];       if (u[i][0] == 1) merge1(b, c);       if (u[i][0] == 2) {         for (int i = 0; i < q[c].size(); i++) {           int qu = q[c][i].first, kj = q[c][i].second;           if (st[qu] <= st[b] && fi[qu] >= fi[b] && root(qu) == root(b))             ans[kj] = true;           else             ans[kj] = false;         }       }     }     for (int i = 1; i < j; i++) {       if (ans[i])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     int b;     cin >> a >> b;     cout.precision(13);     if (b > a) {       cout << -1;     } else if ((a % b == 0) && ((a / b) % 2 == 1)) {       cout << b;     } else {       int k = a / b;       if (k % 2 == 0) {         k--;       }       int dist = a - k * b;       double x1 = b;       double x2 = (double)dist / (double)k + (double)b;       double x = x1;       double ang;       double x_old;       for (int i = 0; i < 50; i++) {         ang = (x - b) / (k * x - a);         x_old = x;         if (ang > -1) {           x = (x + x2) / 2.0;           x1 = x_old;         } else if (ang < -1) {           x = (x + x1) / 2.0;           x2 = x_old;         } else {           cout << x;           return 0;         }       }       cout << x;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long maxn = 3e6;   const long long mod = 1e9 + 7;   const long double PI = acos((long double)-1);   long long pw(long long a, long long b, long long md = mod) {     long long res = 1;     while (b) {       if (b & 1) {         res = (a * res) % md;       }       a = (a * a) % md;       b >>= 1;     }     return (res);   }   string s[4];   bool hor(int x, int y) {     if (x < 1 or x > 2) return (0);     int cnt = 0;     if (s[x][y] ==  o ) return (0);     if (s[x][y] ==  . ) cnt++;     if (s[x - 1][y] ==  o ) return (0);     if (s[x - 1][y] ==  . ) cnt++;     if (s[x + 1][y] ==  o ) return (0);     if (s[x + 1][y] ==  . ) cnt++;     return (cnt < 2);   }   bool ver(int x, int y) {     if (y < 1 or y > 2) return (0);     int cnt = 0;     if (s[x][y] ==  o ) return (0);     if (s[x][y] ==  . ) cnt++;     if (s[x][y - 1] ==  o ) return (0);     if (s[x][y - 1] ==  . ) cnt++;     if (s[x][y + 1] ==  o ) return (0);     if (s[x][y + 1] ==  . ) cnt++;     return (cnt < 2);   }   bool dia(int x, int y) {     int cnt = 0;     if (x < 1 or x > 2) return (0);     if (y < 1 or y > 2) return (0);     if (s[x][y] ==  o ) return (0);     if (s[x][y] ==  . ) cnt++;     if (s[x - 1][y - 1] ==  o ) return (0);     if (s[x - 1][y - 1] ==  . ) cnt++;     if (s[x + 1][y + 1] ==  o ) return (0);     if (s[x + 1][y + 1] ==  . ) cnt++;     return (cnt < 2);   }   bool diag(int x, int y) {     int cnt = 0;     if (x < 1 or x > 2) return (0);     if (y < 1 or y > 2) return (0);     if (s[x][y] ==  o ) return (0);     if (s[x][y] ==  . ) cnt++;     if (s[x - 1][y + 1] ==  o ) return (0);     if (s[x - 1][y + 1] ==  . ) cnt++;     if (s[x + 1][y - 1] ==  o ) return (0);     if (s[x + 1][y - 1] ==  . ) cnt++;     return (cnt < 2);   }   bool chk(int x, int y) {     if (ver(x, y)) return (1);     if (hor(x, y)) return (1);     if (dia(x, y)) return (1);     if (diag(x, y)) return (1);     return (0);   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (int i = 0; i < 4; i++) cin >> s[i];     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++)         if (chk(i, j)) cout <<  YES , exit(0);     cout <<  NO ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() { puts( INTERCAL ); }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, sy, sx;     cin >> n >> m >> sy >> sx;     int up = sy;     int down = sy + 1;     int l = sx;     int r = sx + 1;     int k = 2;     while (up >= 1) {       while (l >= 1) {         cout << up <<     << l << endl;         l--;       }       while (r <= m) {         cout << up <<     << r << endl;         r++;       }       up--;       if (k % 2 == 0)         l = m;       else         r = 1;       k++;     }     while (down <= n) {       while (l >= 1) {         cout << down <<     << l << endl;         l--;       }       while (r <= m) {         cout << down <<     << r << endl;         r++;       }       down++;       if (k % 2 == 0)         l = m;       else         r = 1;       k++;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > a_sent;   vector<pair<int, int> > b_sent;   set<pair<int, int> > a_possible;   set<pair<int, int> > b_possible;   int vis[10];   bool certain(pair<int, int> a, vector<pair<int, int> > sent) {     bool can_x = false;     bool can_y = false;     for (pair<int, int> b : sent) {       if (0) {         printf( has: [%d, %d], try: [%d, %d] n , a.first, a.second, b.first,                b.second);       }       if (a.first == b.first && a.second == b.second) continue;       if (a.first == b.second && a.second == b.first) continue;       if (a.first != b.first && a.second != b.second && a.first != b.second &&           a.second != b.first)         continue;       if (a.first == b.first || a.first == b.second) can_x = true;       if (a.second == b.first || a.second == b.second) can_y = true;     }     if (0) printf( can_x: %d, can_y: %d n , can_x, can_y);     return (can_x && !can_y) || (can_y && !can_x);   }   int main() {     cin >> n >> m;     while (n--) {       pair<int, int> pair;       cin >> pair.first >> pair.second;       if (pair.first < pair.second) swap(pair.first, pair.second);       a_sent.push_back(pair);     }     while (m--) {       pair<int, int> pair;       cin >> pair.first >> pair.second;       if (pair.first < pair.second) swap(pair.first, pair.second);       b_sent.push_back(pair);     }     for (pair<int, int> a : a_sent) {       for (pair<int, int> b : b_sent) {         if (a.first == b.first && a.second == b.second) continue;         if (a.first == b.second && a.second == b.first) continue;         if (a.first != b.first && a.second != b.second && a.first != b.second &&             a.second != b.first)           continue;         if (a.first == b.first) vis[a.first]++;         if (a.second == b.second) vis[a.second]++;         if (a.first == b.second) vis[a.first]++;         if (a.second == b.first) vis[a.second]++;         a_possible.insert(a);         b_possible.insert(b);       }     }     int cnt = 0;     for (int i = 1; i <= 9; ++i) {       cnt += vis[i] >= 1;       if (0) printf( vis[%d] = %d n , i, vis[i]);     }     if (0) cout << cnt << endl;     if (cnt == 1) {       for (int i = 1; i <= 9; ++i) {         if (vis[i] >= 1) {           cout << i << endl;           return 0;         }       }     }     for (pair<int, int> a : a_possible) {       if (!certain(a, b_sent)) {         cout << -1 << endl;         return 0;       }     }     for (pair<int, int> b : b_possible) {       if (!certain(b, a_sent)) {         cout << -1 << endl;         return 0;       }     }     cout << 0 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z, e, s, max1, max2, max3, max4;     cin >> a >> b >> c;     x = a + b * c;     y = a * (b + c);     z = a * b * c;     e = (a + b) * c;     s = a + b + c;     max1 = (x + y + abs(x - y)) / 2;     max2 = (max1 + z + abs(max1 - z)) / 2;     max3 = (max2 + e + abs(max2 - e)) / 2;     max4 = (max3 + s + abs(max3 - s)) / 2;     cout << max4 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const int SZ = 2e5 + 10;   const int mod = 1e9 + 7;   long long read() {     long long n = 0;     char a = getchar();     bool flag = 0;     while (a >  9  || a <  0 ) {       if (a ==  - ) flag = 1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       n = n * 10 + a -  0 , a = getchar();     }     if (flag) n = -n;     return n;   }   int a[SZ], b[SZ], p[SZ], pri[SZ], vis[SZ];   int main() {     int n = read(), x = read();     for (int i = 1, j = 0; i < (1 << n); i++) {       if (i == x)         continue;       else {         if (x < (1 << n)) {           int ii = x ^ i;           if (ii < i) a[++a[0]] = i;         } else           a[++a[0]] = i;       }     }     for (int i = a[0]; i >= 2; i--) a[i] ^= a[i - 1];     printf( %d n , a[0]);     for (int i = 1; i <= a[0]; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int main()   {       int t;       cin >> t;       while(t--){           int n;           cin >> n;           if((n / 2020 > 0) && ((n % 2020) <= (n / 2020))){               cout <<  YES n ;           }else{               cout <<  NO n ;           }       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100;   long long f[N + 5][N + 5][N + 5];   long long fac[N + 5], C[N + 5][N + 5];   long long mod;   long long dfs(int n, int m, int k) {     if (n == 0) return k == 0;     if (m == 1) return k == 1 ? fac[n] : 0;     if (n == 1) return k == 0;     if (2 * k > n + 1) return 0;     if (m > n) return k == 0 ? fac[n] : 0;     if (f[n][m][k] != -1) return f[n][m][k];     long long ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= k; j++)         ans = (ans + C[n - 1][i] * dfs(i, m - 1, j) % mod *                          dfs(n - i - 1, m - 1, k - j) % mod) %               mod;     return f[n][m][k] = ans;   }   int main() {     memset(f, 0xff, sizeof(f));     int n, m, k;     scanf( %d%d%d%lld , &n, &m, &k, &mod);     for (int i = 0; i <= N; i++) C[i][0] = C[i][i] = 1;     for (int i = 1; i <= N; i++)       for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     fac[0] = fac[1] = 1;     for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mod;     printf( %lld , dfs(n, m, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int P[N], I[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &P[i]);     }     int id = 1;     for (int i = 1; i <= n; i++) {       int cur = i;       while (I[cur] != id) {         I[cur] = id;         cur = P[cur];       }       id++;       printf( %d  , cur);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long maxu = 200005;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, k = 0, n, t = 1, m, l = 0;     cin >> t;     while (t--) {       cin >> n;       long long a[n];       long long b[n + 2];       long long cnt = 0;       long long idx = -1;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] != i + 1) {           if (idx == -1) {             idx = i;           }           b[i] = 0;           cnt++;         } else           b[i] = 1;       }       if (cnt == 0) {         cout << 0 <<   n ;         continue;       }       if (cnt == n) {         cout << 1 <<   n ;         continue;       }       long long ans = 0;       for (i = idx; i <= idx + cnt - 1; i++) {         if (b[i] == 0) ans++;       }       if (ans == cnt) {         cout << 1 <<   n ;       } else         cout << 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, k, op, val1, val2;     while (cin >> x >> k) {       int mini = 0, maxi = 0;       maxi = x - 1;       vector<int> T(4005);       for (int i = 0; i < k; ++i) {         cin >> op;         if (op == 2) {           cin >> val1;           T[val1] = 1;         } else {           cin >> val1 >> val2;           T[val1] = T[val2] = 1;         }         if (op == 2)           maxi--;         else           maxi -= 2;       }       T[x] = 1;       for (int i = 1; i <= x; ++i)         if (T[i] == 0) {           int ind;           for (int j = i; j <= x; ++j)             if (T[j] == 0)               ind = j;             else               break;           mini += ((ind - i + 1) - 1) / 2 + 1;           i = ind;         }       cout << mini <<     << maxi << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void file() {}   using lli = long long int;   using pii = pair<int, int>;   using vi = vector<int>;   using vvi = vector<vi>;   void solve() {     string s;     cin >> s;     string res =   ;     int z = 0, ones = 0, two = s.size();     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       if (x == 1) ones++;       if (x == 2 && two == s.size()) two = i;       if (x == 0 && two == s.size()) z++;     }     res += string(z,  0 );     res += string(ones,  1 );     for (int i = two; i < s.size(); i++) {       int x = s[i] -  0 ;       if (x == 1) continue;       res += s[i];     }     cout << res << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, ans, m, j, k;     string s;     cin >> n >> s;     ans = 0;     char ch;     for (i = 25; i >= 0; i--) {       ch = i +  a ;       for (j = 1; j < (long long)s.size(); j++) {         if (s[j] == ch and s[j - 1] + 1 == ch) {           s.erase(s.begin() + j);           ans++;           j--;         }       }       for (j = 0; j < (long long)s.size() - 1; j++) {         if (s[j] == ch and s[j + 1] + 1 == ch) {           s.erase(s.begin() + j);           ans++;           j -= 2;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long ara[20], ara1[20];     for (long long i = 1; i <= 14; i++) {       scanf( %I64d , &ara[i]);     }     long long maxi = 0;     long long sum, c;     for (long long i = 1; i <= 14; i++) {       if (ara[i] == 0) {         continue;       }       long long d = ara[i] / 14;       long long e = ara[i] % 14;       memset(ara1, 0, sizeof(ara1));       sum = 0, c = 0;       if (d > 0) {         for (long long j = i + 1;; j++) {           if (j > 14) {             j = j % 14;             if (j == 0) {               j = 14;             }           }           if (i == j) {             ara1[j] = d;             break;           }           ara1[j] = ara[j] + d;         }       }       for (long long j = i + 1;; j++) {         if (j > 14) {           j = j % 14;           if (j == 0) {             j = 14;           }         }         if (d == 0) {           ara1[j] = ara[j] + 1;         } else {           ara1[j] = ara1[j] + 1;         }         c++;         if (c >= e) {           break;         }       }       for (int j = 1; j <= 14; j++) {         if (ara1[j] % 2 == 0) {           sum = sum + ara1[j];         }       }       if (sum > maxi) {         maxi = sum;       }     }     printf( %I64d n , maxi);   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     vector<int> v, v1;     long long a, b, c, d, e;     cin >> a >> b >> c;     for (int i = 0; i < b; i++) {       cin >> d;       v.push_back(d);     }     for (int i = 0; i < c; i++) {       cin >> e;       v1.push_back(e);     }     for (int i = 1; i <= a; i++) {       long long n = 0;       for (int j = 0; j < v.size(); j++) {         if (mp[v[j]] != 5 and i == v[j]) {           cout << 1 <<    ;           n++;           mp[v[j]] = 5;           break;         }       }       if (n == 0) {         for (int j = 0; j < v1.size(); j++) {           if (mp[v1[j]] != 5 and i == v1[j]) {             cout << 2 <<    ;             mp[v1[j]] = 5;             break;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long INF = 4e17;   const int mod = 1e9 + 7;   const double eps = 1e-9;   const int N = 2e5 + 10;   long long n, arr[N], tree[N << 2], lazy[N << 2];   void build(int node = 1, int L = 1, int R = n) {     if (L == R) {       tree[node] = arr[L];       lazy[node] = 0;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     build(lc, L, mid), build(rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   void set0(int l, int r, int node = 1, int L = 1, int R = n) {     if (r < L || R < l || r < l) return;     if (l <= L && R <= r) {       tree[node] = 0;       lazy[node] = 1;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (lazy[node]) return;     set0(l, r, lc, L, mid), set0(l, r, rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   void upd(int pos, int v, int node = 1, int L = 1, int R = n) {     if (L == R) {       tree[node] += v;       return;     }     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (pos <= mid)       upd(pos, v, lc, L, mid);     else       upd(pos, v, rc, mid + 1, R);     tree[node] = tree[lc] + tree[rc];   }   long long getsum(int l, int r, int node = 1, int L = 1, int R = n) {     if (r < L || R < l) return 0;     if (l <= L && R <= r) return tree[node];     if (lazy[node]) return 0;     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     return getsum(l, r, lc, L, mid) + getsum(l, r, rc, mid + 1, R);   }   long long getcap(int pos, int node = 1, int L = 1, int R = n) {     if (L == R) return tree[node];     if (lazy[node]) return 0;     int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1;     if (pos <= mid) return getcap(pos, lc, L, mid);     return getcap(pos, rc, mid + 1, R);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     int m;     scanf( %d , &m);     build();     while (m--) {       long long t, x, p, k;       scanf( %lld , &t);       if (t == 1) {         scanf( %lld %lld , &p, &x);         long long cap = getcap(p);         if (cap > x) {           if (!1) cout <<  no overflow decrease   << x <<   from cap n ;           upd(p, -x);           if (!1) cout <<  at   << p <<   now   << getcap(p) <<   n ;         } else {           long long got = 0;           int lo = p, hi = n, pos = n + 1;           while (lo <= hi) {             int mid = (lo + hi) >> 1;             got = getsum(p, mid);             if (!1)               cout <<  from   << p <<   ->   << mid <<   sum   << got <<   n ;             if (got >= x)               hi = mid - 1, pos = mid;             else               lo = mid + 1;           }           long long usedup = getsum(p, pos - 1);           if (!1)             cout <<  overflow ends at   << pos <<   and used up   << usedup                  <<   out of   << x <<   n ;           upd(pos, usedup - x);           if (!1) cout <<  set 0 to all in   << p <<   ->   << pos - 1 <<   n ;           set0(p, pos - 1);         }       } else {         scanf( %lld , &k);         if (!1) cout <<  found   << getcap(k) <<   amount left n ;         printf( %lld n , arr[k] - getcap(k));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string strA, strB, strAux;   char aux;   int main() {     cin >> strA;     cin >> strAux;     aux = strAux[1];     strAux[1] = strAux[0];     strAux[0] = aux;     strA += strAux;     cin >> strB;     cin >> strAux;     aux = strAux[1];     strAux[1] = strAux[0];     strAux[0] = aux;     strB += strAux;     strA.erase(strA.find( X ), 1);     strB.erase(strB.find( X ), 1);     int posA = strA.find( A );     int posB = strB.find( A );     bool flag = true;     for (int i = 0; i < 3; i++) {       if (strA[posA] != strB[posB]) {         flag = false;         break;       }       posA++;       if (posA == 3) {         posA = 0;       }       posB++;       if (posB == 3) {         posB = 0;       }     }     if (flag) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr static int MAXN = 1e6;   int main() {     int k, a, b;     cin >> k >> a >> b;     if (a > b) swap(a, b);     int x = a / k;     int y = b / k;     if (x == 0 && y == 0) {       cout << -1 << endl;       return 0;     }     if (x == 0 && b % k > 0) {       cout << -1 << endl;       return 0;     }     cout << x + y << endl;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long l, r;   inline void solve() {     cin >> t;     while (t--) {       cin >> l >> r;       long long ans = l;       for (int i = 0; i <= 62; ++i) {         if (ans + (1ll << i) <= r && (ans & (1ll << i)) == 0) {           ans += (1ll << i);         }       }       cout << ans << endl;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     set<int> a;     int n, t;     cin >> n;     while (n--) {       cin >> t;       a.insert(t);     }     cout << ((a.count(0) == 1) ? a.size() - 1 : a.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long a[1005];   long long fac[1000005];   long long ppow(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return c;   }   long long work(long long m, long long i) {     return ((fac[m] % 1000000007) *             (ppow((fac[i] * fac[m - i]) % 1000000007, 1000000007 - 2) %              1000000007)) %            1000000007;   }   int main() {     long long i, j, k;     fac[0] = 1;     for (int i = 1; i < 1000005; i++) {       fac[i] = (fac[i - 1] * i) % 1000000007;     }     long long ans = 1, sum = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = n; i >= 1; i--) {       ans *= work(sum - 1, a[i] - 1);       ans %= 1000000007;       sum -= a[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct city {     int x, y, p;     double dis;   } t[1010];   int cmp(city a, city b) { return a.dis < b.dis; }   int main() {     int s, n, i;     while (scanf( %d%d , &n, &s) > 0) {       for (i = 0; i < n; i++) {         scanf( %d%d%d , &t[i].x, &t[i].y, &t[i].p);         t[i].dis = sqrt(t[i].x * t[i].x + t[i].y * t[i].y);       }       sort(t, t + n, cmp);       double ans;       for (i = 0; i < n; i++) {         s += t[i].p;         if (s >= 1e6) {           ans = t[i].dis;           break;         }       }       if (i == n) {         printf( -1 n );         continue;       }       printf( %lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   int n, m;   int a[100005];   int main() {     unordered_map<int, long long> cnt1;     unordered_map<int, long long> cnt2;     cnt1.clear();     cnt2.clear();     cin >> n >> m;     bool isone = false;     for (int i = 1; i <= m; ++i) {       cin >> a[i];       if (a[i] == 1) isone = true;     }     if (n == 1) {       if (isone)         cout << 0 << endl;       else         cout << 1 << endl;       return 0;     }     for (int i = m; i >= 1; --i) {       cnt1[a[i] - i] = cnt1[a[i] - i - 1] + 1;       cnt2[a[i] + i] = cnt2[a[i] + i + 1] + 1;     }     long long tot = 0LL;     for (int i = 1; i <= n; ++i) {       long long rn =           min((long long)(n - i), max((long long)m + 1 - cnt1[i], 0LL));       long long ln =           min((long long)(i - 1), max((long long)m + 1 - cnt2[i], 0LL));       tot += ln + rn + 1;     }     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     cin >> n;     cin >> x >> y;     if (x + y <= n + 1) {       cout <<  white ;     } else {       cout <<  black ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string Decod, s;     cin >> n >> s;     int i = 0;     while (n) {       if (n % 2 != 0) {         Decod += s[i];       } else {         Decod = s[i] + Decod;       }       n = n - 1;       i++;     }     cout << Decod << endl;   }


#include <bits/stdc++.h>   using namespace std;   void rwFile() {     freopen( INP.inp ,  r , stdin);     freopen( OUT.out ,  w , stdout);   }   void solveB_MakeThemOdd() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr, arr + n, greater<int>());       map<int, int> M;       for (int i = 0; i < n; i++) {         while (arr[i] % 2 == 0) {           if (M[arr[i]] == 1) break;           if (M[arr[i]] == 0) M[arr[i]] = 1;           arr[i] /= 2;         }       }       int res = 0;       for (auto i : M) res++;       cout << res <<   n ;     }   }   void solveC_EveryoneIsAWinner() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> res;       int i = 1;       while (i <= n) {         int x = n / i;         res.push_back(x);         i = n / x + 1;       }       cout << res.size() + 1 <<   n ;       cout <<  0  ;       for (int j = res.size() - 1; j >= 0; j--) cout << res[j] <<    ;       cout <<   n ;     }   }   void solveA_TilePainting() {     long long n;     cin >> n;     long long res = n;     for (int i = 2; i <= 1e6 + 5; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         res = i;         break;       }     }     if (res == n) {       cout << res;       return;     }     if (n == 1)       cout << res;     else       cout << 1;   }   void solveA_BearAndPoker() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       while (arr[i] % 2 == 0) arr[i] /= 2;       while (arr[i] % 3 == 0) arr[i] /= 3;     }     int able = 1;     for (int i = 1; i < n; i++) {       if (arr[i] != arr[i - 1]) {         able = 0;         break;       }     }     if (able)       cout <<  Yes ;     else       cout <<  No ;   }   void solveC_NewYearAndTheSphereTransmission() {     long long n;     cin >> n;     vector<long long> res;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         long long tmp = (n / i + 1) * (n + 2) / 2 - n - 1;         res.push_back(tmp);         if (i * i != n) {           int j = n / i;           tmp = (n / j + 1) * (n + 2) / 2 - n - 1;           res.push_back(tmp);         }       }     }     sort(res.begin(), res.end());     for (long long i : res) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     solveC_NewYearAndTheSphereTransmission();   }


#include <bits/stdc++.h>   using namespace std;   template <typename F, typename S>   ostream& operator<<(ostream& os, const pair<F, S>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, vector<T> const& x) {     os <<  {  ;     for (auto& y : x) os << y <<    ;     return os <<  } ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> const& x) {     os <<  {  ;     for (auto& y : x) os << y <<    ;     return os <<  } ;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& v) {     os <<  [ ;     typename multiset<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const map<F, S>& v) {     os <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   string s[200];   vector<pair<int, int> > ans;   void cng(int x1, int y1, int x2, int y2, int x3, int y3) {     s[x1][y1] = s[x1][y1] ==  1  ?  0  :  1 ;     s[x2][y2] = s[x2][y2] ==  1  ?  0  :  1 ;     s[x3][y3] = s[x3][y3] ==  1  ?  0  :  1 ;     ans.push_back({x1, y1});     ans.push_back({x2, y2});     ans.push_back({x3, y3});   }   void _main_main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     ans.clear();     for (int i = 0; i < n - 2; i++) {       for (int j = 0; j < m - 1; j++) {         if (s[i][j] ==  1 ) cng(i, j, i, j + 1, i + 1, j);       }       if (s[i][m - 1] ==  1 ) cng(i, m - 1, i + 1, m - 1, i + 1, m - 2);     }     for (int j = 0; j < m - 2; j++) {       if (s[n - 2][j] ==  1 ) cng(n - 2, j, n - 2, j + 1, n - 1, j + 1);       if (s[n - 1][j] ==  1 ) cng(n - 1, j, n - 2, j + 1, n - 1, j + 1);     }     int j = m - 2;     while (1) {       int cnt = 0;       if (s[n - 2][j] ==  1 ) cnt++;       if (s[n - 2][j + 1] ==  1 ) cnt++;       if (s[n - 1][j] ==  1 ) cnt++;       if (s[n - 1][j + 1] ==  1 ) cnt++;       if (cnt == 0)         break;       else if (cnt == 1) {         if (s[n - 2][j] ==  1 )           cng(n - 2, j, n - 2, j + 1, n - 1, j);         else if (s[n - 2][j + 1] ==  1 )           cng(n - 2, j, n - 2, j + 1, n - 1, j);         else if (s[n - 1][j] ==  1 )           cng(n - 2, j, n - 2, j + 1, n - 1, j);         else if (s[n - 1][j + 1] ==  1 )           cng(n - 1, j + 1, n - 2, j + 1, n - 1, j);       } else if (cnt == 2) {         if (s[n - 2][j] ==  1 )           cng(n - 1, j + 1, n - 2, j + 1, n - 1, j);         else if (s[n - 2][j + 1] ==  1 )           cng(n - 2, j, n - 1, j + 1, n - 1, j);         else if (s[n - 1][j] ==  1 )           cng(n - 2, j, n - 2, j + 1, n - 1, j + 1);         else if (s[n - 1][j + 1] ==  1 )           cng(n - 2, j, n - 2, j + 1, n - 1, j);       } else if (cnt == 3) {         if (s[n - 2][j] ==  0 )           cng(n - 1, j + 1, n - 2, j + 1, n - 1, j);         else if (s[n - 2][j + 1] ==  0 )           cng(n - 2, j, n - 1, j + 1, n - 1, j);         else if (s[n - 1][j] ==  0 )           cng(n - 2, j, n - 2, j + 1, n - 1, j + 1);         else if (s[n - 1][j + 1] ==  0 )           cng(n - 2, j, n - 2, j + 1, n - 1, j);       } else {         cng(n - 2, j, n - 2, j + 1, n - 1, j);       }     }     cout << ans.size() / 3 << endl;     int cnt = 0;     for (auto i : ans) {       cnt++;       cout << i.first + 1 <<     << i.second + 1 <<    ;       if (cnt == 3) {         cnt = 0;         cout << endl;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testCase = 1;     cin >> testCase;     for (int i = 0; i < testCase; i++) {       _main_main();     }   }


#include <bits/stdc++.h>   using namespace std;   int c[100001], l[100001], r[100001], vis[100001], a[100001];   int f(int o, int ll, int rr) {     if (!~o) return rr - ll + 1;     int x = lower_bound(a + ll, a + rr + 1, c[o]) - a, y = x - 1;     while (y < rr && a[y + 1] == c[o]) y++;     return f(l[o], ll, x - 1) + f(r[o], y + 1, rr);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d%d%d , c + i, l + i, r + i), vis[l[i]] = vis[r[i]] = 1,                                             a[++a[0]] = c[i];     int o;     for (int i = 1; i <= n; i++)       if (!vis[i]) o = i;     sort(a + 1, a + n + 1);     printf( %d , f(o, 1, n));   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> A[105];   vector<int> ans;   int main() {     int n, days;     cin >> n >> days;     for (int i = 0; i < n; i++) scanf( %d , &A[i].first), A[i].second = i;     sort(A, A + n);     for (int i = 0; i < n; i++) {       if (days < A[i].first) break;       ans.push_back(A[i].second + 1);       days -= A[i].first;     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       if (i) printf(   );       printf( %d , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200000;   int ans[MAX_N + 5];   int main() {     int tc;     cin >> tc;     while (tc--) {       int n, i, j;       string s;       cin >> n >> s;       int num = n, last = 0;       for (i = 0; i < n; i++) {         if (i == n - 1 || s[i] ==  > ) {           for (j = i; j >= last; j--) ans[j] = num--;           last = i + 1;         }       }       for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    );       num = 1, last = 0;       for (i = 0; i < n; i++) {         if (i == n - 1 || s[i] ==  < ) {           for (j = i; j >= last; j--) ans[j] = num++;           last = i + 1;         }       }       for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    );     }   }


#include <bits/stdc++.h>   using namespace std;   int ar[50][50];   int n;   int check(int r, int c) {     int v = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ar[r][i] + ar[j][c] == ar[r][c]) {           return 1;         }       }     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cin >> ar[i][j];     }     int flag = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ar[i][j] != 1) {           flag = flag && check(i, j);         }         if (!flag) {           break;         }       }       if (!flag) {         break;       }     }     if (flag) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int A[110];   int main() {     int n, k, x;     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     int ans = 0;     for (int i = 0; i < n - k; i++) {       ans += A[i];     }     ans += (k * x);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5005;   long long n, m, dp[N];   char s[N];   inline long long read() {     long long ret = 0, f = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       ret = ret * 10 + c - 48;       c = getchar();     }     if (f) return -ret;     return ret;   }   long long lowbit(long long x) { return x & -x; }   signed main() {     scanf( %s , s + 1);     n = strlen(s + 1);     m = log2(n);     for (long long i = 0; i < (1 << m); i++) dp[i] = 1;     for (long long i = 1; i <= n - (1 << m) + 1; i++) {       char mi =  z ;       for (long long j = 0; j < (1 << m); j++)         if (dp[j]) mi = min(mi, s[i + j]);       for (long long j = 0; j < (1 << m); j++) dp[j] &= (s[i + j] == mi);       for (long long j = 0; j < (1 << m); j++)         if (dp[j])           for (long long k = 0; k < m; k++) dp[j | (1 << k)] = 1;       putchar(mi);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(long long x, long long y) {     if (x >= y) return true;     return false;   }   bool compare(const pair<long long, long long> &i,                const pair<long long, long long> &j) {     return i.first <= j.first;   }   bool compare1(const pair<long long, long long> &i,                 const pair<long long, long long> &j) {     return i.first > j.first;   }   string decitobinary(long long n, long long bit) {     char c[bit];     memset(c,  0 , sizeof(c));     long long i = 0;     while (n > 0) {       c[i] = n % 2 + 48;       n = n / 2;       i++;     }     string s =   ;     for (long long j = bit - 1; j >= 0; j--) s += c[j];     return s;   }   long long binarytodeci(string n) {     string num = n;     long long dec_value = 0;     long long base = 1;     long long len = num.length();     for (long long i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   double intlog(double base, double x) { return (log(x) / log(base)); }   long long fact(long long n) {     long long res = 1;     for (long long i = 2; i <= n; i++) res = res * i;     return res;   }   long long ncr(long long n, long long k) {     long long res = 1;     if (k > n - k) k = n - k;     for (long long i = 0; i < k; ++i) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   bool ispalindrome(string str, long long l, long long h) {     while (h > l) {       if (str[l++] != str[h--]) return 0;     }     return 1;   }   long long compute_hash(string s) {     long long p = 31, hash = 0, po = 1;     for (char c : s) {       hash += (c -  a  + 1) * po % 1000000007;       po = (po * p) % 1000000007;     }     return hash;   }   vector<vector<long long>> group_identical_strings(vector<string> const &s) {     long long n = s.size();     vector<pair<long long, long long>> hashes(n);     for (long long i = 0; i < n; i++) hashes[i] = {compute_hash(s[i]), i};     sort(hashes.begin(), hashes.end());     vector<vector<long long>> groups;     for (long long i = 0; i < n; i++) {       if (i == 0 || hashes[i].first != hashes[i - 1].first) groups.emplace_back();       groups.back().push_back(hashes[i].second);     }     return groups;   }   bool isarraysort(long long a[], long long i, long long j) {     if (j == i) return 1;     if (a[j] < a[j - 1]) return 0;     return isarraysort(a, i, j - 1);   }   void sieve(long long n, long long prime[]) {     for (long long i = 1; i <= n; i++) prime[i] = 1;     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == 1) {         for (long long i = p * p; i <= n; i += p) prime[i] = 0;       }     }   }   bool isprime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   long long pow_mod(long long base, long long exp) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % 1000000007;       exp = exp >> 1;       base = (base * base) % 1000000007;     }     return res;   }   const long long N = 1e6 + 3;   vector<vector<long long>> adj;   bool visited[N];   long long depth[N] = {0};   long long size[N] = {0};   long long parent[N];   void dfs(long long v) {     visited[v] = true;     for (long long u : adj[v]) {       if (!visited[u]) {         dfs(u);       }     }   }   long long time_in[N], time_out[N];   long long dfs_timer = 0;   long long color[N];   void dfs_time(long long v) {     time_in[v] = ++dfs_timer;     color[v] = 1;     for (long long u : adj[v]) {       if (color[u] == 0) {         dfs_time(u);       }     }     color[v] = 2;     time_out[v] = ++dfs_timer;   }   long long count1[N];   void numberOfNodes(long long s) {     count1[s] = 1;     for (long long u : adj[s]) {       if (u == parent[s]) continue;       numberOfNodes(u);       count1[s] += count1[u];     }   }   long long call(long long a[], long long x, long long y) {     long long mxi = x;     long long mx = a[x];     for (long long i = x + 1; i <= y; i++) {       if (a[i] > mx) {         mx = a[i];         mxi = i;       }     }     return mxi;   }   void solve(long long countu) {     long long n;     cin >> n;     long long x[n], y[n];     long long cnt[100001] = {0};     for (long long i = 0; i < n; i++) {       cin >> x[i] >> y[i];       cnt[x[i]]++;     }     for (long long i = 0; i < n; i++)       cout << n - 1 + cnt[y[i]] <<     << n - 1 - cnt[y[i]] <<   n ;   }   int32_t main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1, countu = 1;     while (t--) {       solve(countu);       countu++;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   vector<int> sosedi[maxn];   int parent[maxn], shagi[maxn], start[maxn], finish[maxn], n;   void dfs(int v, int predok) {     parent[v] = predok;     shagi[v] = shagi[predok] + 1;     for (auto p : sosedi[v])       if (p != predok) dfs(p, v);   }   vector<int> circles;   int rt, lp, lq;   bool find_circle() {     circles.clear();     static bool visit_vertex[maxn];     int p = 0;     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && shagi[i] > shagi[p]) p = i;     if (!p) return 1;     for (int u = p; visit_vertex[u] = 1, circles.push_back(u),              start[parent[u]] != finish[parent[u]];          u = parent[u])       ;     int q = 0;     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && !visit_vertex[i] && shagi[i] > shagi[q]) q = i;     if (q) {       reverse(circles.begin(), circles.end());       for (int u = q; visit_vertex[u] = 1, circles.push_back(u),                start[parent[u]] != finish[parent[u]];            u = parent[u])         ;     } else       q = parent[circles.back()];     for (int i = 1; i <= n; i++)       if (start[i] != finish[i] && !visit_vertex[i]) return 0;     int u, v;     for (u = p, v = q; u != v; u = parent[u])       if (shagi[u] < shagi[v]) swap(u, v);     rt = u;     if (circles.size() != shagi[p] + shagi[q] - 2 * shagi[rt]) return 0;     lp = p, lq = q;     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> start[i];     }     for (int i = 1; i <= n; i++) {       cin >> finish[i];     }     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       sosedi[u].push_back(v), sosedi[v].push_back(u);     }     int pa = find(start + 1, start + n + 1, 0) - start,         pb = find(finish + 1, finish + n + 1, 0) - finish;     shagi[0] = -1;     dfs(pb, 0);     for (int u = pa; u != pb; u = parent[u]) swap(start[u], start[parent[u]]);     long long ans = shagi[pa];     if (!find_circle()) {       printf( -1 n );       return 0;     }     if (!circles.size()) {       printf( 0 %d n , ans);       return 0;     }     int gap = 0, len = circles.size();     for (int i = 0; i < len; i++)       if (finish[circles[i]] == start[circles[0]]) gap = i;     for (int i = 1; i < len; i++)       if (finish[circles[(i + gap) % len]] != start[circles[i]]) {         printf( -1 n );         return 0;       }     static bool visit_vertex[maxn];     for (int i = pa; i; i = parent[i]) visit_vertex[i] = 1;     if (visit_vertex[circles[0]] || visit_vertex[circles.back()]) {       int po = circles.size();       for (int i = 0; i < circles.size(); i++)         if (!visit_vertex[circles[i]]) {           po = i;           break;         }       ans = ans - po +             min(po + gap * 1ll * (len + 1),                 abs((len - gap) * 1ll * (len + 1) - po));     } else       ans = (ans + min(gap, len - gap) * 1ll * (len + 1));     for (; !visit_vertex[rt]; rt = parent[rt]) ans += 2;     if (lp > lq) swap(lq, lp);     printf( %d %d %lld n , lp, lq, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool home = 1;   signed realMain();   signed main() {     home = 0;     if (home) {       freopen( tony_stark ,  r , stdin);     } else {       ios::sync_with_stdio(0);       cin.tie(0);     }     realMain();   }   const int N = 100000 + 7;   int n, k;   long long sol[N];   vector<int> co;   struct pt {     int x, y;   } a[N];   bool operator<(pt a, pt b) { return a.y < b.y; }   struct upd {     int rw;     int l, r;     int sgn;   };   bool operator<(upd a, upd b) { return a.rw < b.rw; }   int fnd(int x) {     int l = 0, r = (int)co.size() - 1;     while (l <= r) {       int m = (l + r) / 2;       if (co[m] == x) return m;       if (co[m] < x)         l = m + 1;       else         r = m - 1;     }     assert(0);   }   signed realMain() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       int go = a[i].y - k + 1;       if (!co.empty() && go <= co.back()) go = co.back() + 1;       for (int j = go; j <= a[i].y; j++) co.push_back(j);     }     vector<upd> evs;     for (int i = 1; i <= n; i++) {       int lft = a[i].y - k + 1, rgh = a[i].y;       int l = fnd(lft), r = fnd(rgh);       evs.push_back({a[i].x - k + 1, l, r, +1});       evs.push_back({a[i].x + 1, l, r, -1});     }     vector<int> cnt((int)co.size()), utime;     swap(utime, co);     sort(evs.begin(), evs.end());     int ret = 0;     for (auto &it : evs) {       int rw = it.rw;       int l = it.l;       int r = it.r;       int sgn = it.sgn;       for (int j = l; j <= r; j++) {         sol[cnt[j]] += (rw - utime[j]);         cnt[j] += sgn;         utime[j] = rw;       }     }     for (int j = 1; j <= n; j++) {       cout << sol[j] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void pre() {}   void solve() {}   const long long mod = 998244353;   long long pw[1000009], a[1000009];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     pw[0] = 1;     for (int i = 1; i <= (1000000); ++i) pw[i] = pw[i - 1] * 2 % mod;     int n;     cin >> n;     for (int i = 0; i < (n); ++i) cin >> a[i + 1];     long long ans = a[n];     for (int i = 1; i <= (n - 1); ++i) {       ans += 1ll * pw[n - i] * a[i] % mod;       ans += 1ll * (n - i) * a[i] % mod * pw[n - 1 - i] % mod;     }     cout << ans % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);     putchar(   );   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   template <typename R, typename D>   inline void Min(R &a, D b) {     if (a > b) a = b;   }   template <typename D, typename R>   inline void Max(D &a, R b) {     if (a < b) a = b;   }   const int N = 10005, M = 300005;   bool dd[10];   int T, n;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     cin >> T;     while (T--) {       cin >> n;       if ((n / 2) & 1) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       for (int i = 1; i <= n / 2; ++i) cout << i * 2 <<    ;       for (int i = 1; i <= n / 2 - 1; ++i) cout << i * 2 - 1 <<    ;       cout << n + n / 2 - 1;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool options(long a, long b) { return a > b; }   int main() {     long n, i, *arr, *arrSort, *index;     map<long, long> res;     cin >> n;     arr = new long[n];     arrSort = new long[n];     index = new long[n];     for (i = 0; i < n; i++) {       cin >> arr[i];       arrSort[i] = arr[i];     }     sort(arrSort, arrSort + n, options);     for (i = 0; i < n; i++) {       index[i] = i + 1;     }     for (i = 1; i < n; i++) {       if (arrSort[i] == arrSort[i - 1]) {         index[i] = index[i - 1];       }     }     for (i = 0; i < n; i++) {       res[arrSort[i]] = index[i];     }     for (i = 0; i < n; i++) {       cout << res[arr[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main(void) {     unsigned int const max_skill_level = 100;     unsigned int number_of_boys;     unsigned int number_of_girls;     unsigned int number_of_pairs = 0;     std::vector<unsigned int> number_of_boys_with_each_skill_level(         max_skill_level + 1, 0);     std::vector<unsigned int> number_of_girls_with_each_skill_level(         max_skill_level + 1, 0);     std::ios_base::sync_with_stdio(false);     std::cin >> number_of_boys;     for (unsigned int i = 0; i < number_of_boys; ++i) {       std::size_t skill_level;       std::cin >> skill_level;       ++number_of_boys_with_each_skill_level[skill_level];     }     std::cin >> number_of_girls;     for (unsigned int i = 0; i < number_of_girls; ++i) {       std::size_t skill_level;       std::cin >> skill_level;       ++number_of_girls_with_each_skill_level[skill_level];     }     for (std::size_t i = 0; i < max_skill_level; ++i) {       unsigned int number_of_new_pairs;       number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i],                                      number_of_girls_with_each_skill_level[i]);       number_of_boys_with_each_skill_level[i] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;       number_of_new_pairs =           std::min(number_of_boys_with_each_skill_level[i],                    number_of_girls_with_each_skill_level[i + 1]);       number_of_boys_with_each_skill_level[i] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i + 1] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;       number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i + 1],                                      number_of_girls_with_each_skill_level[i]);       number_of_boys_with_each_skill_level[i + 1] -= number_of_new_pairs;       number_of_girls_with_each_skill_level[i] -= number_of_new_pairs;       number_of_pairs += number_of_new_pairs;     }     number_of_pairs += std::min(number_of_boys_with_each_skill_level.back(),                                 number_of_girls_with_each_skill_level.back());     std::cout << number_of_pairs <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   void pre() {}   void solve() {     long long k, b, n;     cin >> k >> b >> n;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     map<long long, long long> m;     long long curr = 0;     long long ans = 0;     m[0]++;     if (b == k - 1) {       long long cur = 0;       for (int i = 0; i < n; i++) {         cur = 0;         while (i < n && arr[i] == 0) {           cur++;           i++;         }         if (cur != 0) {           i--;         }         ans -= (cur * (cur + 1)) / 2;       }     }     if (b == 0) {       long long cur = 0;       for (int i = 0; i < n; i++) {         cur = 0;         while (i < n && arr[i] == 0) {           cur++;           i++;         }         if (cur != 0) {           i--;         }         ans += (cur * (cur + 1)) / 2;       }       cout << ans <<   n ;       return;     }     b %= (k - 1);     for (int i = 0; i < n; i++) {       curr += arr[i];       curr %= (k - 1);       ans += m[(curr - b + k - 1) % (k - 1)];       m[curr]++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pre();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, adj[166][166];   bool h[166];   vector<char> V[166], r;   string a[105];   void dfs(char x) {     h[x] = true;     for (typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++)       if (!h[*it]) dfs(*it);     r.push_back(x);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) {       int q = 0;       while (a[i][q] == a[i + 1][q]) q++;       if (q >= a[i + 1].size() and q < a[i].size())         return puts( Impossible ) && 0;       else if (q >= a[i].size())         continue;       adj[a[i + 1][q]][a[i][q]] = 1;       for (typeof(V[a[i][q]].begin()) it = V[a[i][q]].begin();            it != V[a[i][q]].end(); it++)         adj[a[i + 1][q]][*it] = 1;       V[a[i + 1][q]].push_back(a[i][q]);     }     for (int i =  a ; i <=  z ; i++)       if (!h[i]) dfs(i);     for (int i = 0; i <= r.size() - 1; i++)       for (int j = 0; j <= i; j++)         if (adj[r[j]][r[i]]) return puts( Impossible ) && 0;     for (typeof(r.begin()) it = r.begin(); it != r.end(); it++) cout << *it;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int total[N];   vector<pair<pair<int, int>, int> > e[N];   int dir[N], from[N], to[N];   int visit[N];   int n, m;   int main() {     scanf( %d%d , &n, &m);     memset(total, 0, sizeof(total));     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       from[i] = u;       to[i] = v;       e[u].push_back(make_pair(make_pair(v, w), i));       e[v].push_back(make_pair(make_pair(u, w), i));       total[u] += w;       total[v] += w;       dir[i] = -1;     }     for (int i = 1; i <= n; i++) total[i] >>= 1;     memset(visit, false, sizeof(visit));     queue<int> q;     q.push(1);     visit[1] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < e[u].size(); i++) {         int id = e[u][i].second, v = e[u][i].first.first,             w = e[u][i].first.second;         if (dir[id] == -1) {           if (u == from[id])             dir[id] = 0;           else             dir[id] = 1;           total[v] -= w;           if (total[v] == 0 && (!visit[v]) && v != n) {             visit[v] = true;             q.push(v);           }         }       }     }     for (int i = 1; i <= m; i++) printf( %d n , dir[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read(void)   {       int sum = 0, sign = 1;       char ch = getchar();       while (ch >  9  || ch <  0 )       {           if (ch ==  - )               sign = -1;           ch = getchar();       }       while (ch >=  0  && ch <=  9 )       {           sum = sum * 10 + ch -  0 ;           ch = getchar();       }       return sum * sign;   }   const int maxn = 2e5 + 5;   typedef long long ll;   int main()   {       int T = read();       for (int cas = 1; cas <= T; cas++)       {           string str;           cin >> str;           int bol = 0;           for (int i = str.length() - 1; i >= 1; i--){               if (bol == 0 && str[i] ==  0  && str[i - 1] ==  0 )                   bol = 1;               if (bol == 1 && str[i] ==  1  && str[i - 1] ==  1 )                   bol = 2;           }           if (bol == 2)               cout <<  NO n ;           else               cout <<  YES n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = 104;   const double EPS = 1e-7;   int a, b, c;   void read() { cin >> a >> b >> c; }   void solve() {     a -= a / b * b;     for (int i = 0; i < 1e5; ++i) {       a *= 10;       if (c == a / b) {         cout << i + 1;         return;       }       a -= a / b * b;     }     cout << -1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5;   int a[maxn], b[maxn], c[maxn];   int n, K, i, j, x, y, bl, la;   int main() {     scanf( %d%d , &n, &K);     x = K;     for (i = 2; i <= x; i++)       if (x % i == 0) {         a[++la] = i;         while (x % i == 0) {           b[la]++;           x /= i;         }       }     for (i = 1; i <= n; i++) {       scanf( %d , &x);       for (j = 1; j <= la; j++) {         y = 0;         while (x % a[j] == 0) {           y++;           x /= a[j];         }         c[j] = max(c[j], y);       }     }     bl = 1;     for (i = 1; i <= la; i++)       if (c[i] < b[i]) {         bl = 0;         break;       }     if (bl)       printf( Yes );     else       printf( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char st[8][20] = { err ,       monday ,  tuesday ,   wednesday ,                      thursday ,  friday ,  saturday ,  sunday };   int main() {     char s1[20], s2[20];     scanf(  %s %s , s1, s2);     int t1 = 0, t2 = 0;     for (int i = 1; i <= 7; i++)       if (strcmp(s1, st[i]) == 0) {         t1 = i;         break;       }     for (int i = 1; i <= 7; i++)       if (strcmp(s2, st[i]) == 0) {         t2 = i;         break;       }     bool flag = false;     if (t1 == t2) flag = true;     int tmp = t1 + 2;     if (tmp > 7) tmp -= 7;     if (tmp == t2) flag = true;     tmp = t1 + 3;     if (tmp > 7) tmp -= 7;     if (tmp == t2) flag = true;     puts(flag ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long tc, n, x, cnt1, cnt2, i, max_;     scanf( %lld , &tc);     while (tc--) {       scanf( %lld , &n);       vector<long long> v;       vector<long long> v1;       for (i = 0; i < n; i++) {         scanf( %lld , &x);         v.push_back(x);       }       sort(v.begin(), v.end());       cnt1 = 0;       v1.push_back(0);       for (i = 0; i < n; i++) {         cnt1++;         if (cnt1 >= v[i]) v1.push_back(i + 1);       }       max_ = *max_element(v1.begin(), v1.end());       printf( %lld n , max_ + 1);     }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   set<pair<int, int> > Sx;   vector<int> conn[200050];   bool pchk[200050];   int lc = 1;   vector<int> Vl[200050];   int r[200050];   int sz[200050];   int root(int x) { return (x == r[x]) ? x : (r[x] = root(r[x])); }   int main() {     int N, M, i, j;     scanf( %d %d , &N, &M);     for (i = 1; i <= M; i++) {       int t1, t2;       scanf( %d %d , &t1, &t2);       Sx.emplace(t1, t2);       Sx.emplace(t2, t1);       conn[t1].push_back(t2);       conn[t2].push_back(t1);     }     int p = 1;     for (i = 2; i <= N; i++)       if (conn[i].size() < conn[p].size()) p = i;     for (auto it : conn[p]) pchk[it] = true;     for (i = 1; i <= N; i++)       if (!pchk[i]) Vl[1].push_back(i);     for (i = 1; i <= N; i++) {       if (!pchk[i]) continue;       lc++;       Vl[lc].push_back(i);     }     for (i = 1; i <= lc; i++) r[i] = i;     for (i = 1; i <= lc; i++) {       for (j = i + 1; j <= lc; j++) {         bool chk = false;         for (auto it1 : Vl[i]) {           for (auto it2 : Vl[j]) {             if (Sx.count(pair<int, int>(it1, it2))) continue;             chk = true;             break;           }         }         if (chk) r[root(i)] = root(j);       }     }     int cnt = 0;     for (i = 1; i <= lc; i++) sz[root(i)] += Vl[i].size();     vector<int> Va;     for (i = 1; i <= lc; i++)       if (r[i] == i) Va.push_back(sz[i]);     sort((Va).begin(), (Va).end());     printf( %d n , (int)Va.size() - 1);   }


#include <bits/stdc++.h>   using namespace std;   int h, w, k, Q;   int V;   int a[1005][1005];   vector<int> G[1100005];   short d[1100005];   short dist[45][1000005];   vector<int> vec[45];   bool used[45];   int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};   void bfs(int c, short dist[]) {     queue<int> Q;     for (int i = 0; i < h * w; i++) dist[i] = 30000;     for (int i = 1; i <= k; i++) used[i] = false;     for (int i = 0; i < vec[c].size(); i++) {       Q.push(vec[c][i]);       dist[vec[c][i]] = 0;     }     used[c] = true;     int v, x, y;     while (Q.size()) {       v = Q.front();       Q.pop();       x = v % w, y = v / w, c = a[x][y];       if (!used[c]) {         used[c] = true;         for (int i = 0; i < vec[c].size(); i++) {           if (dist[vec[c][i]] < 30000) continue;           dist[vec[c][i]] = dist[v] + 1;           Q.push(vec[c][i]);         }       }       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i], nv = ny * w + nx;         if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;         if (dist[nv] < 30000) continue;         dist[nv] = dist[v] + 1;         Q.push(nv);       }     }   }   int main(void) {     scanf( %d %d %d , &h, &w, &k);     int p;     for (int y = 0; y < h; y++) {       for (int x = 0; x < w; x++) {         scanf( %d , &p);         a[x][y] = p;       }     }     int n = h * w;     for (int y = 0; y < h; y++) {       for (int x = 0; x < w; x++) {         vec[a[x][y]].push_back(y * w + x);       }     }     for (int i = 1; i <= k; i++) {       bfs(i, d);       for (int j = 0; j < n; j++) dist[i][j] = d[j];     }     scanf( %d , &Q);     int sx, sy, tx, ty;     for (int q = 0; q < Q; q++) {       scanf( %d %d %d %d , &sy, &sx, &ty, &tx);       sx--, sy--, tx--, ty--;       int S = sy * w + sx, T = ty * w + tx;       int ans = abs(sx - tx) + abs(sy - ty);       for (int i = 1; i <= k; i++) {         ans = min(ans, dist[i][S] + dist[i][T] + 1);       }       printf( %d n , ans);     }     flush(cout);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 3010;   vector<int> g[maxn];   int vis[maxn], dis[maxn][maxn];   void bfs(int s) {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     vis[s] = 1;     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (vis[v]) continue;         vis[v] = 1;         dis[s][v] = dis[s][u] + 1;         que.push(v);       }     }   }   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       for (int i = 0; i <= n; i++) g[i].clear();       for (int i = 0; i < m; i++) {         int u, v;         scanf( %d%d , &u, &v);         g[u].push_back(v);         g[v].push_back(u);       }       int s1, t1, d1, s2, t2, d2;       scanf( %d%d%d%d%d%d , &s1, &t1, &d1, &s2, &t2, &d2);       for (int i = 1; i <= n; i++) bfs(i);       if (dis[s1][t1] > d1 || dis[s2][t2] > d2) {         puts( -1 );         continue;       }       int ans = dis[s1][t1] + dis[s2][t2];       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) {           if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 &&               dis[s2][i] + dis[i][j] + dis[j][t2] <= d2)             ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[s2][i] +                                dis[j][t2]);           if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 &&               dis[t2][i] + dis[i][j] + dis[j][s2] <= d2)             ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[t2][i] +                                dis[j][s2]);           if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 &&               dis[s2][i] + dis[i][j] + dis[j][t2] <= d2)             ans = min(ans, dis[t1][i] + dis[i][j] + dis[j][s1] + dis[s2][i] +                                dis[j][t2]);           if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 &&               dis[t2][i] + dis[i][j] + dis[j][s2] <= d2)             ans = min(ans, dis[t1][i] + dis[j][s1] + dis[t2][i] + dis[i][j] +                                dis[j][s2]);         }       cout << m - ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, max1 = 0;     cin >> n;     long long int a[n];     long long int b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     b[n - 1] = 0;     max1 = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       if (a[i] > max1) {         b[i] = 0;         max1 = a[i];       } else {         b[i] = max1 - a[i] + 1;       }     }     for (int i = 0; i < n; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<pair<int, int>, pair<int, int> > > ans;   bool invert;   void print(vector<vector<string> > &mat) {     for (auto vs : mat) {       for (string s : vs) {         printf( |%6s|  , s.c_str());       }       cout << endl;     }   }   void move(int si, int sj, int ti, int tj) {     assert(si != ti || sj != tj);     if (si != ti && sj != tj) {       move(si, sj, si, tj);       move(si, tj, ti, tj);     } else       ans.push_back({{si + 1, sj + 1}, {ti + 1, tj + 1}});   }   void clean(vector<vector<string> > &mat, int i, int j) {     if (invert) reverse(mat[i][j].begin(), mat[i][j].end());     for (char c : mat[i][j]) {       if (c ==  1 ) {         move(i, j, 0, 1);         mat[0][1].push_back(c);       }       if (c ==  0 ) {         move(i, j, 0, 0);         mat[0][0].push_back(c);       }     }     mat[i][j].clear();   }   void simulate(vector<vector<string> > mat) {     printf(  npart 1: n );     print(mat);     int cnt = 0;     int n = ans.size();     assert(!ans.empty());     for (auto p : ans) {       int si = p.first.first - 1;       int sj = p.first.second - 1;       int ti = p.second.first - 1;       int tj = p.second.second - 1;       assert(!mat[si][sj].empty());       char c = mat[si][sj].back();       mat[si][sj].pop_back();       string aux;       aux.push_back(c);       mat[ti][tj] = aux + mat[ti][tj];       cnt++;       printf( step %d: n , cnt);       print(mat);       if (2 * cnt == n) printf(  npart 2 n );     }   }   void go(vector<vector<string> > &mat) {     string z0, z1, o0, o1;     if (invert) {       reverse(mat[0][0].begin(), mat[0][0].end());       reverse(mat[0][1].begin(), mat[0][1].end());     }     for (char c : mat[0][0]) {       if (c ==  0 )         z0.push_back(c), move(0, 0, 1, 0);       else         o0.push_back(c), move(0, 0, 0, 1);     }     for (char c : mat[0][1]) {       if (c ==  0 )         z1.push_back(c), move(0, 1, 0, 0);       else         o1.push_back(c), move(0, 1, 1, 1);     }     if (invert) {       mat[1][0] = z0 + mat[1][0];       mat[1][1] = o1 + mat[1][1];     } else {       mat[1][0] = mat[1][0] + z0;       mat[1][1] = mat[1][1] + o1;     }     mat[0][0] = z1;     mat[0][1] = o0;     for (int i = 0; (i) < int(n); (i)++) {       if (i == 0) continue;       string aux;       if (invert) reverse(mat[i][0].begin(), mat[i][0].end());       for (char c : mat[i][0]) {         if (c ==  0 ) {           move(i, 0, 0, 0);           mat[0][0].push_back(c);         } else {           aux.push_back(c);           move(i, 0, i, 1);         }       }       if (invert)         mat[i][1] = aux + mat[i][1];       else         mat[i][1] = mat[i][1] + aux;       mat[i][0].clear();     }     for (int i = 0; (i) < int(n); (i)++)       for (int j = 0; (j) < int(m); (j)++) {         if (j == 0) continue;         if (i == 0 && j == 1) continue;         clean(mat, i, j);       }   }   vector<vector<string> > from, to;   int main() {     while (cin >> n >> m) {       from.resize(n);       for (int i = 0; (i) < int(n); (i)++) {         from[i].resize(m);         for (int j = 0; (j) < int(m); (j)++) cin >> from[i][j];       }       to.resize(n);       for (int i = 0; (i) < int(n); (i)++) {         to[i].resize(m);         for (int j = 0; (j) < int(m); (j)++) cin >> to[i][j];       }       vector<vector<string> > aux = from;       invert = true;       ans.clear();       go(from);       auto p1 = ans;       invert = false;       ans.clear();       go(to);       auto p2 = ans;       for (auto &pp : p2) swap(pp.first, pp.second);       reverse(p2.begin(), p2.end());       ans = p1;       ans.insert(ans.end(), p2.begin(), p2.end());       printf( %d n , int(ans.size()));       for (auto pp : ans) {         printf( %d %d %d %d n , pp.first.first, pp.first.second, pp.second.first,                pp.second.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b);   int main() {     long long t, w, b;     cin >> t >> w >> b;     long long tie = 0;     long long total = t;     bool overflow = false;     long long gcdValue = gcd(w, b);     if (LLONG_MAX / double(w) < double(b) / gcdValue) overflow = true;     long long lcm = b / gcdValue * w;     tie += min(w, b) * (t / lcm);     if (t % lcm < min(w, b))       tie += t % lcm;     else       tie += min(w, b) - 1;     if (overflow == true) {       if (t < min(w, b)) {         tie = 1;         total = 1;       } else         tie = min(w, b) - 1;     }     long long gcdans = gcd(tie, total);     tie /= gcdans;     total /= gcdans;     cout << tie <<  /  << total << endl;     ;     return 0;   }   long long gcd(long long a, long long b) {     if (a % b == 0) return b;     if (b % a == 0) return a;     return gcd(max(a, b) % min(a, b), min(a, b));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, x, rev;     cin >> n;     while (n % 10 == 0) n = n / 10;     rev = 0;     x = n;     while (x > 0) {       rev = rev * 10 + x % 10;       x = x / 10;     }     if (rev == n)       cout <<  YES ;     else       cout <<  NO ;   }