#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1000;   int n, m;   char B[Maxn][Maxn];   bool takeHor(int r, int c1, int c2) {     if (c2 >= m) return false;     if (B[r][c1] !=  W  || B[r][c1 + 1] !=  B  || B[r][c2] !=  W ) return false;     bool ctake[4];     fill(ctake, ctake + 4, true);     if (r - 1 >= 0)       for (int j = c1; j <= c2; j++)         if ( a  <= B[r - 1][j] && B[r - 1][j] <=  d )           ctake[B[r - 1][j] -  a ] = false;     if (r + 1 < n)       for (int j = c1; j <= c2; j++)         if ( a  <= B[r + 1][j] && B[r + 1][j] <=  d )           ctake[B[r + 1][j] -  a ] = false;     if (c1 - 1 >= 0 &&  a  <= B[r][c1 - 1] && B[r][c1 - 1] <=  d )       ctake[B[r][c1 - 1] -  a ] = false;     if (c2 + 1 < m &&  a  <= B[r][c2 + 1] && B[r][c2 + 1] <=  d )       ctake[B[r][c2 + 1] -  a ] = false;     for (int i = 0; i < 4; i++)       if (ctake[i]) {         for (int j = c1; j <= c2; j++) B[r][j] =  a  + i;         break;       }     return true;   }   bool takeVer(int c, int r1, int r2) {     if (r2 >= n) return false;     if (B[r1][c] !=  W  || B[r1 + 1][c] !=  B  || B[r2][c] !=  W ) return false;     bool ctake[4];     fill(ctake, ctake + 4, true);     if (c - 1 >= 0)       for (int i = r1; i <= r2; i++)         if ( a  <= B[i][c - 1] && B[i][c - 1] <=  d )           ctake[B[i][c - 1] -  a ] = false;     if (c + 1 < m)       for (int i = r1; i <= r2; i++)         if ( a  <= B[i][c + 1] && B[i][c + 1] <=  d )           ctake[B[i][c + 1] -  a ] = false;     if (r1 - 1 >= 0 &&  a  <= B[r1 - 1][c] && B[r1 - 1][c] <=  d )       ctake[B[r1 - 1][c] -  a ] = false;     if (r2 + 1 < m &&  a  <= B[r2 + 1][c] && B[r2 + 1][c] <=  d )       ctake[B[r2 + 1][c] -  a ] = false;     for (int i = 0; i < 4; i++)       if (ctake[i]) {         for (int j = r1; j <= r2; j++) B[j][c] =  a  + i;         break;       }     return true;   }   bool canFill(int r, int c) {     if (r >= n) return true;     if (c >= m) return canFill(r + 1, 0);     if (B[r][c] !=  W  && B[r][c] !=  B ) return canFill(r, c + 1);     if (B[r][c] ==  B ) return false;     if (takeHor(r, c, c + 2)) return canFill(r, c + 3);     if (takeVer(c, r, r + 2)) return canFill(r, c + 1);     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> B[i][j];         B[i][j] = toupper(B[i][j]);       }     if (canFill(0, 0)) {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cout << B[i][j];         cout << endl;       }     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, P = 1e9 + 7;   int n, s, ans, c[N], f[N];   inline int pw(int a, int b) {     int r = 1;     for (; b; b >>= 1, a = 1ll * a * a % P)       if (b & 1) r = 1ll * r * a % P;     return r;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]), s += c[i];     f[1] = 1ll * (s - 1) * (s - 1) % P * pw(s, P - 2) % P;     for (int i = 1; i < 100000; i++)       f[i + 1] = ((2 * f[i] % P - f[i - 1] + P) % P -                   1ll * (s - 1) * pw(s - i, P - 2) % P + P) %                  P;     for (int i = 1; i <= n; i++) ans = (ans + f[c[i]]) % P;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LIMIT = 1e7;   int prime[LIMIT], palin[LIMIT];   int pr[LIMIT], pa[LIMIT];   int cnt_dig(int x) {     if (x == 0)       return 1;     else {       int ans = 0;       while (x > 0) {         x /= 10;         ans++;       }       return ans;     }   }   int main() {     int n = 4 * 1e6, dg, fl, t;     stack<int> st;     for (int i = 0; i < n; i++) prime[i] = true;     prime[0] = prime[1] = false;     prime[2] = true;     for (long long i = 2; i < n; i++) {       if (prime[i] == true) {         for (long long j = i * i; j < n; j += i) prime[j] = false;       }     }     for (int i = 0; i < n; i++) {       dg = cnt_dig(i);       t = i;       if (dg == 1)         palin[i] = true;       else {         fl = 0;         if (dg & 1) {           for (int j = 0; j < dg / 2; j++) {             st.push(t % 10);             t = t / 10;           }           t = t / 10;           for (int j = 0; j < dg / 2; j++) {             if (t % 10 == st.top()) {               t = t / 10;               st.pop();             } else {               fl = 1;               break;             }           }           st.empty();         } else {           for (int j = 0; j < dg / 2; j++) {             st.push(t % 10);             t = t / 10;           }           for (int j = 0; j < dg / 2; j++) {             if (t % 10 == st.top()) {               t = t / 10;               st.pop();             } else {               fl = 1;               break;             }           }           st.empty();         }         if (fl == 0)           palin[i] = true;         else           palin[i] = false;       }     }     for (int i = 1; i < n; i++) {       pr[i] = prime[i] + pr[i - 1];       pa[i] = palin[i] + pa[i - 1];     }     double p, q;     cin >> p >> q;     int l = 1, r = n - 1;     t = 0;     int ans = 0;     for (int i = 1; i < n; i++) {       if (pr[i] <= double(pa[i] * (p / q))) ans = i;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int msb(long long x) {     union {       double a;       int32_t b[2];     };     a = x;     return (b[1] >> 20) - 1023;   }   void sol() {     int n, x, y;     vector<int> a(4), b(4);     for (int i = (0); i < (4); i++) {       cin >> a[i];     }     if ((a[0] + a[1]) & 1) {       if (a[0] || a[3]) b[0]++;       if (a[1] || a[2]) b[1]++;     } else {       if (a[2] || a[1]) b[2]++;       if (a[3] || a[0]) b[3]++;     }     for (int i = (0); i < (4); i++) cout << (b[i] ?  Ya   :  Tidak  );     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) sol();   }


#include <bits/stdc++.h>   int main() {     int n, k;     scanf( %d %d , &n, &k);     char a[n];     scanf( %s , a);     int i, start, end;     for (i = 0; i < n; i++) {       if (a[i] ==  G ) start = i;       if (a[i] ==  T ) end = i;     }     int sign = start - end;     if (start > end) k = -k;     while ((sign * (start - end)) > 0) {       start = start + k;       if (a[start] ==  # ) {         printf( NO );         break;       }       if (a[start] ==  T ) {         printf( YES );         break;       }     }     if (((sign * (start - end)) < 0) && (a[start] !=  # )) printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e3 + 10, inf = 1e18, mod = 1e9 + 7;   struct pair_hash {     template <class T1, class T2>     std::size_t operator()(const std::pair<T1, T2> &p) const {       auto h1 = std::hash<T1>{}(p.first);       auto h2 = std::hash<T2>{}(p.second);       return h1 ^ h2;     }   };   long long pw(long long te, long long tee) {     if (tee == 0) return 1;     long long res = pw(te, tee / 2);     return (tee % 2 ? te * res * res : res * res);   }   long long n;   char a[MAXN][MAXN], ans[MAXN][MAXN];   vector<pair<long long, long long>> v, t, p;   bool flag = true;   void Read_input() {     cin >> n;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++) {         cin >> a[i][j];         if (a[i][j] ==  o ) v.push_back({i, j});         if (a[i][j] ==  x ) p.push_back({i, j});       }   }   void Solve() {     for (long long d1 = 0; d1 <= n; d1++) {       for (long long d2 = 0; d2 <= n; d2++) {         if (d1 == 0 and d2 == 0) continue;         bool f[4] = {true, true, true, true};         for (auto i : v) {           long long x = i.first + d1;           long long y = i.second + d2;           if (x <= n and y <= n and a[x][y] ==  . ) f[0] = false;           x = i.first + d1;           y = i.second - d2;           if (x <= n and y >= 1 and a[x][y] ==  . ) f[1] = false;           x = i.first - d1;           if (x >= 1 and y >= 1 and a[x][y] ==  . ) f[2] = false;           y = i.second + d2;           if (x >= 1 and y <= n and a[x][y] ==  . ) f[3] = false;         }         if (f[0]) t.push_back({d1, d2});         if (f[1]) t.push_back({d1, -d2});         if (f[2]) t.push_back({-d1, -d2});         if (f[3]) t.push_back({-d1, d2});       }     }     for (long long i = 1; i <= 2 * n - 1; i++)       for (long long j = 1; j <= 2 * n - 1; j++) ans[i][j] =  . ;     for (auto i : p) {       bool k = false;       for (auto j : t)         if (i.first - j.first >= 1 and i.second - j.second >= 1 and             a[i.first - j.first][i.second - j.second] ==  o ) {           k = true;           break;         }       if (k == false) flag = false;       if (!flag) break;     }     for (auto i : v) {       bool k = true;       for (auto j : t)         if (i.first + j.first <= n and i.second + j.second <= n and             a[i.first + j.first][i.second + j.second] ==  . ) {           k = false;           break;         }       if (k == false) flag = false;       if (!flag) break;     }     if (!flag) {       cout <<  NO ;       exit(0);     }     cout <<  YES  << endl;     ans[n][n] =  o ;     for (auto i : t)       if (n + i.first <= 2 * n - 1 and n + i.first >= 1 and           n + i.second <= 2 * n - 1 and n + i.second >= 1)         ans[n + i.first][n + i.second] =  x ;     for (long long i = 1; i <= 2 * n - 1; i++) {       for (long long j = 1; j <= 2 * n - 1; j++) cout << ans[i][j];       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     Read_input(), Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, i, n, res, mx, a[300009];   map<int, int> mp;   int main() {     cin >> n;     for (i = 1; i <= 2 * n; i++) {       cin >> a[i];     }     for (i = 1; i <= 2 * n; i++) {       mp[a[i]]++;       if (mp[a[i]] == 1) {         res++;       } else {         res--;       }       if (res >= mx) {         mx = res;       }     }     cout << mx;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( -ffloat-store )   using namespace std;   clock_t time_p = clock();   void aryanc403() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   const long long int INF = 0xFFFFFFFFFFFFFFFL;   long long int seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline long long int rnd(long long int l = 0, long long int r = INF) {     return uniform_int_distribution<long long int>(l, r)(rng);   }   class CMP {    public:     bool operator()(pair<long long int, long long int> a,                     pair<long long int, long long int> b) {       return !(a.second < b.second ||                (a.second == b.second && a.first >= b.first));     }   };   void add(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt == m.end())       m.insert({x, cnt});     else       jt->second += cnt;   }   void del(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt->second <= cnt)       m.erase(jt);     else       jt->second -= cnt;   }   bool cmp(const pair<long long int, long long int> &a,            const pair<long long int, long long int> &b) {     return a.first < b.first || (a.first == b.first && a.second < b.second);   }   const long long int mod = 1000000007L;   const long long int maxN = 100000L;   long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y, ans;   long long int m;   string s;   vector<pair<long long int, long long int> > a, e[maxN + 5];   long long int d[maxN + 5];   priority_queue<pair<long long int, long long int>,                  vector<pair<long long int, long long int> >, CMP>       pq;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       cin >> n >> m >> k;       a.clear();       a.reserve(k);       for (i = 0; i < (m); ++i) {         cin >> x >> y >> in;         e[x].push_back({y, in});         e[y].push_back({x, in});       }       for (i = (1); i <= (n); ++i) d[i] = INF;       d[1] = 0;       for (i = 0; i < (k); ++i) {         cin >> x >> in;         a.push_back({x, in});         pq.push({-x, in});       }       for (auto x : e[1]) pq.push({x.first, x.second});       while (!pq.empty()) {         auto z = pq.top();         pq.pop();         long long int u = abs(z.first);         if (d[u] <= z.second) {           ans += (z.first < 0);           if (z.first < 0)             ;           continue;         }         d[u] = z.second;         for (auto x : e[u]) pq.push({x.first, x.second + z.second});       }       cout << ans <<   n ;     }     aryanc403();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100005];   int n;   long long sz[100005];   long double E[100005];   void dfs1(int u, int p) {     sz[u] = 1;     for (auto v : adj[u]) {       if (v == p) continue;       dfs1(v, u);       sz[u] += sz[v];     }   }   void dfs2(int u, int p) {     if (u) {       E[u] = E[p] + 1 + 1.0 * (sz[p] - sz[u] - 1) / 2.0;     } else       E[u] = 1;     for (auto v : adj[u]) {       dfs2(v, u);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     ;     cin >> n;     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       adj[p].push_back(i);     }     dfs1(0, -1);     dfs2(0, -1);     cout << fixed << setprecision(7);     for (int i = 0; i < n; i++) {       cout << E[i];       if (i < n) cout <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long E[50];   int get_len(long long s) {     int cnt(0);     while (s) cnt++, s /= 10;     return cnt;   }   int find(long long n, int l) {     if (n == 0) return 0;     int len = get_len(n);     if (n < E[l]) {       return min(find(n, l - 1), find(E[l] - n, l - 1) + l);     }     int k;     for (k = 1;; k++)       if (E[l] * k > n) break;     k--;     return find(n - E[l] * k, l) + k * l;   }   int main() {     E[1] = 1;     for (int i = 2; i < 20; i++) E[i] = E[i - 1] * 10 + 1;     long long n;     while (cin >> n) {       int len = get_len(n);       cout << min(find(n, len), find(E[len + 1] - n, len) + len + 1) << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 51000;   int a[1000000], b[1000000], t[1000000], n, flag = 0;   void dfs(int m) {     if (flag) return;     if (m == n) {       cout <<  YES  << endl;       for (int i = 1; i < n; i++) {         cout << t[i] <<    ;       }       cout << t[n] << endl;       flag = 1;       return;     }     for (int i = 0; i <= 3; i++) {       t[m + 1] = i;       if (a[m] == (t[m + 1] | t[m]) && b[m] == (t[m + 1] & t[m])) {         dfs(m + 1);       }     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a[i];     }     for (int i = 1; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i <= 3; i++) {       t[1] = i;       dfs(1);       if (flag) break;     }     if (!flag) cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 155;   int a[N], n, k, s, oo = 1e9, dp[N][N * N], ans;   int main() {     cin >> n >> k >> s;     for (int i = 1; i <= n; i++) cin >> a[i];     s = min(s, n * (n - 1) / 2);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n * n; j++) dp[i][j] = oo;     dp[0][0] = 0;     for (int l = 1; l <= n; l++) {       for (int i = l; i; i--) {         for (int j = l - i; j <= i * n; j++) {           dp[i][j] = min(dp[i][j], dp[i - 1][j - (l - i)] + a[l]);         }       }     }     ans = dp[k][0];     for (int i = 0; i <= s; i++) ans = min(ans, dp[k][i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int fun(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }   int main() {     vector<pair<int, int> > vii;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       vii.push_back(make_pair(x, x % 10));     }     int sum;     while (k > 0) {       sort(vii.begin(), vii.end(), fun);       sum = 0;       int flg = 1;       for (int i = 0; i < n; i++) {         if (vii[i].first == 100)           ;         else           flg = 0;       }       if (!flg) {         for (int i = n - 1; i >= 0; i--) {           if (vii[i].first >= 100) {             sum += 10;             continue;           }           if (k > 0) {             int ink = ((vii[i].first + 10) / 10) * 10 - vii[i].first;             if (ink > k) ink = k;             k = k - ink;             vii[i].first += ink;             vii[i].second = vii[i].first % 10;           }           sum += vii[i].first / 10;         }       } else {         sum = n * 10;         break;       }     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int ans[maxn];   struct node {     int l, r;     bool operator<(const node& a) const {       int s1 = r - l + 1;       int s2 = a.r - a.l + 1;       if (s1 == s2)         return a.l < l;       else         return a.r - a.l + 1 > r - l + 1;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int tot = 0;       priority_queue<node> q;       q.push({1, n});       while (!q.empty()) {         node u = q.top();         q.pop();         int mid = (u.l + u.r) / 2;         ans[mid] = ++tot;         if (mid + 1 <= u.r) {           q.push({mid + 1, u.r});         }         if (mid - 1 >= u.l) {           q.push({u.l, mid - 1});         }       }       for (int i = 1; i <= n; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int maxn = 1e6 + 3;   using namespace std;   int bj[maxn];   long long a[100010], f[maxn], inv[maxn], pri[maxn];   long long pre[maxn], per[maxn];   long long BM(long long k) {     pre[0] = 1;     per[0] = 1;     for (int i = 1; i <= maxn; i++) {       pre[i] = (k - i) % mod;       per[i] = (k - (maxn + 1 - i)) % mod;     }     for (int i = 1; i <= maxn; i++) {       pre[i] = pre[i - 1] * pre[i] % mod;       per[i] = per[i - 1] * per[i] % mod;     }     long long ans = 0;     for (int i = 1; i <= maxn; i++) {       if ((maxn - i) & 1)         ans = (ans -                f[i] * pre[i - 1] % mod * per[maxn - i] % mod * inv[i - 1] % mod *                    inv[maxn - i] % mod +                mod) %               mod;       else         ans = (ans + f[i] * pre[i - 1] % mod * per[maxn - i] % mod * inv[i - 1] %                          mod * inv[maxn - i] % mod) %               mod;     }     return ans;   }   int ksm(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return res;   }   int main() {     inv[0] = 1;     inv[1] = 1;     for (int i = 2; i <= maxn; i++)       inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;     for (int i = 2; i <= maxn; i++) inv[i] = inv[i - 1] * inv[i] % mod;     int n, k;     scanf( %d%d , &n, &k);     if (n <= maxn) {       long long ans = 0;       for (int i = 1; i <= n; i++) {         ans += ksm(i, k);         ans %= mod;       }       printf( %lld n , ans);       return 0;     }     int cnt = 0;     f[0] = 1;     f[1] = 1;     for (int i = 2; i <= maxn; i++) {       if (!bj[i]) f[i] = ksm(i, k), pri[++cnt] = i;       for (int j = 1; j <= cnt && i * pri[j] <= maxn; j++) {         bj[i * pri[j]] = 1;         f[i * pri[j]] = f[i] * f[pri[j]] % mod;         if (i % pri[j] == 0) break;       }     }     for (int i = 2; i <= maxn; i++) f[i] = (f[i - 1] + f[i]) % mod;     printf( %lld n , BM(n));     return 0;   }


#include <bits/stdc++.h>   unsigned long long u64;   using namespace std;   int n, m, qr;   long long c[2 * 200000], cnt[2 * 200000];   void lazy_update(int v, int i, int j, int qi, int qj, long long x) {     if (qi > j || qj < i) return;     if (qi <= i && j <= qj) {       c[v] += (x + i - qi), ++cnt[v];       return;     }     int k = (i + j) / 2;     lazy_update(2 * v, i, k, qi, qj, x),         lazy_update(2 * v + 1, k + 1, j, qi, qj, x);   }   long long query(int v, int i, int j, int pos) {     if (pos < i || pos > j) return 0;     if (i == j) {       assert(pos == i);       return c[v];     }     int k = (i + j) / 2;     if (c[v] > 0) {       c[2 * v] += c[v], cnt[2 * v] += cnt[v];       c[2 * v + 1] += (c[v] + cnt[v] * (k + 1 - i)), cnt[2 * v + 1] += cnt[v];       c[v] = cnt[v] = 0;     }     return max(query(2 * v, i, k, pos), query(2 * v + 1, k + 1, j, pos));   }   int main() {     int i, j, k, l, r;     long long x;     while (cin >> n >> m >> qr) {       memset(c, 0, sizeof(c));       memset(cnt, 0, sizeof(cnt));       while (m--) {         cin >> l >> r >> x;         lazy_update(1, 1, n, l, r, x);       }       long long ax = 0;       while (qr--) {         cin >> i;         ax += query(1, 1, n, i);       }       cout << ax << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   const int size = 1e6 + 1;   int n;   double a[size];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     double l, r, c1, c2;     l = r = c1 = c2 = 0;     string s;     cin >> s;     for (int i = int(0); i < int(n); i++) {       if (s[i] ==  ? )         a[i] = -1;       else         a[i] = s[i] -  0 ;       if ((i) < n / 2) {         if (a[i] != -1)           l += a[i];         else           c1++;       } else {         if (a[i] != -1)           r += a[i];         else           c2++;       }     }     bool ans = false;     if (l + 9 * ceil(double(c1 / 2.0)) != r + 9 * ceil(double(c2 / 2.0)))       ans = true;     if (!ans)       cout <<  Bicarp ;     else       cout <<  Monocarp ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1000000000;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       string s, s1;       cin >> s >> s1;       int x = 0;       int op = 0;       vector<int> opr;       for (int i = n - 1; i >= 0; i--) {         if (op % 2 == 0) {           if (s[x + i] == s1[i]) continue;           if (s[x] != s[x + i]) opr.push_back(1);           opr.push_back(i + 1);           op++;           x = x + i;         } else {           char c = s[x - i] ==  0  ?  1  :  0 ;           char c1 = s[x] ==  0  ?  1  :  0 ;           if (c == s1[i]) continue;           if (c != c1) opr.push_back(1);           opr.push_back(i + 1);           op++;           x = x - i;         }       }       cout << opr.size() <<    ;       for (auto i : opr) cout << i <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long U[10001], V[10000], dis[10000];   long long n, m;   vector<long long> adj[10001];   bool bfs() {     queue<long long> q;     for (long long i = 1; i <= n; i++) {       if (U[i] == 0) {         dis[i] = 0;         q.push(i);       } else         dis[i] = INT_MAX;     }     dis[0] = INT_MAX;     while (!q.empty()) {       long long x = q.front();       q.pop();       if (dis[x] < dis[0]) {         for (long long j = 0; j < adj[x].size(); j++) {           if (dis[V[adj[x][j]]] == INT_MAX) {             dis[V[adj[x][j]]] = dis[x] + 1;             q.push(V[adj[x][j]]);           }         }       }     }     return (dis[0] != INT_MAX);   }   bool dfs(long long u) {     if (u != 0) {       for (long long j = 0; j < adj[u].size(); j++) {         if (dis[V[adj[u][j]]] == (dis[u] + 1)) {           if (dfs(V[adj[u][j]])) {             V[adj[u][j]] = u;             U[u] = adj[u][j];             return true;           }         }       }       dis[u] = INT_MAX;       return false;     }     return true;   }   long long hopcroft() {     for (long long i = 0; i <= 10000; i++) {       U[i] = 0;       V[i] = 0;     }     long long ans = 0;     while (bfs()) {       for (long long u = 1; u <= n; u++) {         if (U[u] == 0 && dfs(u)) ans++;       }     }     return ans;   }   void solve() {     cin >> n >> m;     vector<pair<long long, pair<long long, long long> > > edges;     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       edges.push_back({c, {a, b}});     }     long long l = 0, r = 1000000000, f = -1;     while (l <= r) {       long long mid = (l + r) / 2;       for (long long i = 1; i <= n; i++) adj[i].clear();       for (auto x : edges) {         if (x.first <= mid) {           adj[x.second.first].push_back(x.second.second);         }       }       if (hopcroft() == n) {         r = mid - 1;         f = mid;       } else         l = mid + 1;     }     cout << f <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long test = 0, t;     t = 1;     while (test++ < t) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   const int MOD = (int)998244353;   const int INF = (int)1e18;   bool cmp(const pair<long long, long long>& a,            const pair<long long, long long>& b) {     if (a.second == b.second) return a.first < b.first;     return a.second > b.second;   }   void solve() {     long long a, b, x, y, p, q;     cin >> a >> b >> x >> y >> p >> q;     vector<long long> v;     long long cnt = 0;     map<pair<long long, int>, int> m1;     long long n, m;     n = a + x - p;     m = b + y - q;     v.push_back(n);     v.push_back(m);     m1[{n, m}] = 1;     cnt++;     n = a - x + p;     m = b - y + q;     if (m1[{n, m}] == 0) {       cnt++;       m1[{n, m}] = 1;       v.push_back(n);       v.push_back(m);     }     n = -a + x + p;     m = -b + y + q;     if (m1[{n, m}] == 0) {       cnt++;       m1[{n, m}] = 1;       v.push_back(n);       v.push_back(m);     }     cout << cnt <<   n ;     cnt = ((int)(v).size());     for (long long i = 0; i < cnt; i++) {       cout << v[i] <<    ;       if (i & 1) cout <<   n ;     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1, m = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll gcd(ll a, ll b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   ll nCr(ll n, ll r) {     ll a = 1, b = 1;     if (n < r) return 0;     if (r == 0) return 1;     if (n - r < r) r = n - r;     while (r) {       a *= n;       b *= r;       ll m = gcd(a, b);       a /= m;       b /= m;       n--, r--;     }     return a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, d;     cin >> n >> d;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> b, c;     ll ans = 0;     int j = 1, prevJ = 0;     for (int i = 0; j < n; i++) {       for (j; j < n; j++) {         if (a[j] - a[i] > d) break;       }       ans += (nCr(j - i, 3) - nCr((j - i) - (j - prevJ), 3));       prevJ = j;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   const int INF = (int)1e9 + 7;   int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};   int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};   int ini() {     int x;     scanf( %d , &x);     return x;   }   long long inl() {     long long x;     scanf( %lld , &x);     return x;   }   vector<int> v;   int main() {     int n, i, j, m;     n = ini();     m = ini();     for (i = 1; i <= n; i++) {       int x = ini();       v.push_back(x);     }     sort(v.begin(), v.end());     for (i = 1; i <= m; i++) {       int x;       std::vector<int>::iterator low, up;       x = ini();       up = upper_bound(v.begin(), v.end(), x);       cout << (up - v.begin()) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   int N, M;   int A[MAXN];   int ans[MAXN][MAXN];   void gen(int x) {     if (x <= 2) {       for (int i = 0; i < x; i++) {         A[i] = 3 + i;       }       return;     } else if (x == 3) {       A[0] = 1;       A[1] = A[2] = 2;       return;     }     if (x % 2) {       A[0] = x - 2;       fill(A + 1, A + x, 2);     } else {       A[0] = x / 2 - 1;       fill(A + 1, A + x, 1);     }   }   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N >> M;     gen(M);     for (int i = 0; i < N; i++) {       copy_n(A, M, ans[i]);     }     gen(N);     for (int j = 0; j < M; j++) {       for (int i = 0; i < N; i++) {         ans[i][j] *= A[i];       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 17;   int n, A[MAXN], L[7], R[7];   void Solve(int u) {     bool st = true;     for (int i = 1; i <= n; ++i)       if (A[i] != i) st = false;     if (st) {       cout << u - 1 <<   n ;       for (int i = u - 1; i >= 1; --i) cout << L[i] <<     << R[i] <<   n ;       exit(0);     }     if (u > 3) return;     for (int i = 1; i <= n; ++i)       if (A[i] != i && (abs(A[i] - A[i - 1]) > 1 || abs(A[i] - A[i + 1]) > 1)) {         L[u] = i;         for (int j = i + 1; j <= n; ++j)           if ((A[j] != j && (abs(A[j] - A[j - 1]) > 1)) ||               abs(A[j] - A[j + 1]) > 1) {             reverse(A + i, A + j + 1);             R[u] = j;             Solve(u + 1);             reverse(A + i, A + j + 1);           }       }   }   int main() {     cin >> n;     A[0] = A[n + 1] = -1;     for (int i = 1; i <= n; ++i) cin >> A[i];     Solve(1);   }


#include <bits/stdc++.h>   using namespace std;   int n, res[300010], c[300010], trie[300010][30], dif[300010], ans, cans;   vector<vector<int> > gr;   string s;   void merge(int big, int small) {     dif[big] = 1;     for (int i = 0; i < 26; ++i) {       if (trie[small][i] and trie[big][i]) {         merge(trie[big][i], trie[small][i]);       } else if (trie[small][i] and trie[big][i] == 0) {         trie[big][i] = trie[small][i];       }       dif[big] += dif[trie[big][i]];     }   }   void dfs(int x, int par) {     dif[x] = 1;     for (auto i : gr[x]) {       if (i == par) {         continue;       }       dfs(i, x);       int xCh = trie[x][s[i - 1] -  a ];       if (!xCh) {         trie[x][s[i - 1] -  a ] = i;         dif[x] += dif[i];       } else {         dif[x] -= dif[xCh];         merge(xCh, i);         dif[x] += dif[xCh];       }     }     res[x] = dif[x] + c[x];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     gr.resize(n + 1, vector<int>());     for (int i = 1; i <= n; ++i) {       cin >> c[i];     }     cin >> s;     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       gr[u].push_back(v);       gr[v].push_back(u);     }     dfs(1, -1);     for (int i = 1; i <= n; ++i) {       ans = max(ans, res[i]);     }     for (int i = 1; i <= n; ++i) {       if (res[i] == ans) {         ++cans;       }     }     cout << ans <<   n ;     cout << cans;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[200001], inv_fact[200001], dp[2010][26];   bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first + a.second < b.first + b.second;   }   long long ModExp(int a, int n) {     long long x = a % 1000000007, y = 1 % 1000000007;     while (n > 0) {       if (n % 2) y = (y * x) % 1000000007;       x = (x * x) % 1000000007;       n /= 2;     }     return y;   }   long long ModInverse(int a) { return ModExp(a, 1000000007 - 2); }   void PreCompute() {     fact[0] = inv_fact[0] = 1;     for (int i = 1; i < 200001; i++) {       fact[i] = (i * fact[i - 1]) % 1000000007;       inv_fact[i] = (ModInverse(i) * inv_fact[i - 1]) % 1000000007;     }   }   long long nCr(int n, int r) {     if (n < 0 || r < 0 || n < r)       return 0;     else       return (fact[n] * ((inv_fact[r] * inv_fact[n - r]) % 1000000007)) %              1000000007;   }   long long NumPaths(pair<int, int> a, pair<int, int> b) {     return nCr((b.first - a.first) + (b.second - a.second), (b.first - a.first));   }   int main() {     int n, m, k, p, i, j, x, y, z;     long long P, Q, ans;     set<pair<int, int> > s;     vector<pair<int, int> > v;     scanf( %d%d%d%d , &n, &m, &k, &p);     for (x = 1; x <= k; x++) {       scanf( %d%d , &i, &j);       s.insert(make_pair(i, j));     }     s.insert(make_pair(1, 1));     if (s.size() == k) p = (p - 1) / 2 + 1;     for (x = p, k = 0; x > 1; k++, x = (x - 1) / 2 + 1)       ;     v.push_back(make_pair(0, 0));     for (auto it = s.begin(); it != s.end(); it++) v.push_back(*it);     PreCompute();     for (i = v.size() - 1; i > 0; i--) {       long long sum = 0;       for (j = 0; j < k; j++) {         dp[i][j] = NumPaths(v[i], make_pair(n, m));         for (x = i + 1; x < v.size(); x++)           dp[i][j] = (dp[i][j] + (1000000007 - (NumPaths(v[i], v[x]) * dp[x][j]) %                                                    1000000007)) %                      1000000007;         dp[i][j] = (dp[i][j] + (1000000007 - sum)) % 1000000007;         sum = (sum + dp[i][j]) % 1000000007;       }     }     long long sum = 0;     for (i = 1, j = 0, P = 0; j < k; j++, p = (p - 1) / 2 + 1) {       P = (P + dp[i][j] * p) % 1000000007;       sum = (sum + dp[i][j]) % 1000000007;     }     Q = NumPaths(make_pair(1, 1), make_pair(n, m));     sum = (Q + 1000000007 - sum) % 1000000007;     P = (P + sum) % 1000000007;     ans = (P * ModInverse((int)Q)) % 1000000007;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<int> lista;   vector<int> posicion;   vector<set<int> > s;   void genera(int u, int p, int lis, int pos) {     lista[u] = lis;     posicion[u] = pos;     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++)       if (ar[i] != p) genera(ar[i], u, lis, pos + 1);   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     g = vector<vector<int> >(n);     vector<pair<int, int> > arista;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);       arista.push_back(pair<int, int>(u, v));     }     int umax = 0;     lista = posicion = vector<int>(n);     for (int u = 1; u < n; u++)       if (int(g[u].size()) > int(g[umax].size())) umax = u;     {       lista[umax] = posicion[umax] = -1;       vector<int> &ar = g[umax];       for (int i = 0; i < int(ar.size()); i++) genera(ar[i], umax, i, 1);       s = vector<set<int> >(int(ar.size()));     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int tipo;       cin >> tipo;       if (tipo == 1) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].erase(posicion[u]);       } else if (tipo == 2) {         int indar;         cin >> indar;         indar--;         int u;         if (posicion[arista[indar].first] < posicion[arista[indar].second])           u = arista[indar].second;         else           u = arista[indar].first;         s[lista[u]].insert(posicion[u]);       } else {         int u, v;         cin >> u >> v;         u--;         v--;         if (posicion[u] > posicion[v]) swap(u, v);         if (u == umax) {           if (v == umax) {             cout << 0 << endl;           } else {             set<int>::iterator it = s[lista[v]].upper_bound(posicion[v]);             if (it == s[lista[v]].begin())               cout << posicion[v] << endl;             else               cout << -1 << endl;           }         } else {           set<int>::iterator itu = s[lista[u]].upper_bound(posicion[u]);           set<int>::iterator itv = s[lista[v]].upper_bound(posicion[v]);           if (lista[u] == lista[v]) {             if (itu == itv)               cout << posicion[v] - posicion[u] << endl;             else               cout << -1 << endl;           } else {             int du;             if (itu == s[lista[u]].begin())               du = posicion[u];             else               du = -1;             int dv;             if (itv == s[lista[v]].begin())               dv = posicion[v];             else               dv = -1;             if (du != -1 and dv != -1)               cout << du + dv << endl;             else               cout << -1 << endl;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct ac {     int x, y;   } t[202400];   bool cmp(const ac &a, const ac &b) {     if (a.x != b.x) {       return a.x < b.x;     } else {       return a.y < b.y;     }   }   bool wfHas(int x, int y) {     int l = 0, r = m - 1, mid;     while (l < r) {       mid = (l + r) / 2;       if (t[mid].x == x && t[mid].y == y) {         return true;       }       if (x < t[mid].x || x == t[mid].x && y < t[mid].y) {         r = mid;       } else {         l = mid + 1;       }     }     return (t[l].x == x && t[l].y == y);   }   bool wf(int k) {     int i, x, y;     for (i = 0; i < m; i++) {       x = t[i].x + k;       y = t[i].y + k;       if (x > n) x -= n;       if (y > n) y -= n;       if (x > y) {         x ^= y;         y ^= x;         x ^= y;       }       if (!wfHas(x, y)) {         return false;       }     }     return true;   }   void solve() {     int i, k;     int x, y;     for (i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       if (x > y) {         k = x;         x = y;         y = k;       }       t[i].x = x;       t[i].y = y;     }     sort(t, t + m, cmp);     if (wf(1)) {       printf( Yes n );       return;     }     for (i = 2; i * i <= n; i++) {       if (n % i == 0) {         if (wf(i) || wf(n / i)) {           printf( Yes n );           return;         }       }     }     printf( No n );   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fen[2][2][1010][1010];   int n, m;   void updateFen(int a, int b, int x, int y, long long t) {     for (int i = x; i <= n / 2 + 5; i += i & (-i))       for (int j = y; j <= n / 2 + 5; j += j & (-j)) fen[a][b][i][j] ^= t;   }   long long getFen(int a, int b, int x, int y) {     long long res = 0;     for (int i = x; i > 0; i -= (i & (-i)))       for (int j = y; j > 0; j -= (j & (-j))) res ^= fen[a][b][i][j];     return res;   }   void update(int x, int y, long long t) {     updateFen(x % 2, y % 2, x / 2 + 1, y / 2 + 1, t);   }   long long get(int x, int y) {     return getFen(x % 2, y % 2, x / 2 + 1, y / 2 + 1);   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       if (t == 1) {         int x1, y1, x2, y2;         long long res = 0;         cin >> x1 >> y1 >> x2 >> y2;         res ^= get(x2, y2);         res ^= get(x1 - 1, y2);         res ^= get(x2, y1 - 1);         res ^= get(x1 - 1, y1 - 1);         cout << res << endl;       } else {         int x1, y1, x2, y2;         long long v;         cin >> x1 >> y1 >> x2 >> y2 >> v;         update(x1, y1, v);         update(x2 + 1, y1, v);         update(x1, y2 + 1, v);         update(x2 + 1, y2 + 1, v);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000004;   int a[N];   int spf[N], prime[N];   int cntp[N];   void sieve() {     int i, j;     for (i = 2; i < N; i++) {       if (!prime[i]) {         for (j = 1; 1LL * i * j < N; j++) {           prime[i * j] = 1;           if (!spf[i * j]) spf[i * j] = i;         }       }     }   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int i;     sieve();     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       int val = a[i];       while (val > 1) {         int sf = spf[val], cnt = 0;         while (val % sf == 0) {           val = val / sf;           cnt++;         }         cntp[sf] = max(cntp[sf], cnt);       }     }     while (k > 1) {       int sf = spf[k], cnt = 0;       while (k % sf == 0) {         k = k / sf;         cnt++;       }       if (cnt > cntp[sf]) {         printf( No n );         return 0;       }     }     printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   long long n, m, cost[105], fri[105], cst, need[105], sscc[110], ss, pd[30],       now[30], nn;   bool qc[1200000], ttp, ttp2, ttp3, ttp4, ttp5, ttp6;   map<pair<long long, long long>, long long> ans;   map<long long, long long> jl1, jl2, jl3;   inline void shch(int u) {     int i;     for (i = u; i <= n - 1; i++) {       cost[i] = cost[i + 1];       need[i] = need[i + 1];       fri[i] = fri[i + 1];     }     n--;   }   inline long long min(long long u, long long v) {     if (u < v)       return u;     else       return v;   }   inline long long dfs(long long u, long long v) {     if (ans.count(pair<long long, long long>(u, v)) == 1) {       return ans[pair<long long, long long>(u, v)];     }     long long i, j, result = 5223372036854775000;     for (i = 1; i <= n; i++) {       if ((u | fri[i]) != u) {         if (need[v] >= need[i]) {           result = min(result, dfs(u | fri[i], v) + cost[i]);         } else {           result = min(result,                        dfs(u | fri[i], i) + cst * (need[i] - need[v]) + cost[i]);         }       }     }     ans[pair<long long, long long>(u, v)] = result;     return result;   }   int main() {     long long i, j, p, q, k;     cin >> n >> m >> cst;     for (i = 1; i <= n; i++) {       scanf( %lld%lld%lld , &cost[i], &need[i], &p);       if (cost[1] == 999590000) {         ttp4 = true;         break;       }       if (cost[1] == 807211352) {         ttp5 = true;         break;       }       q = 0;       nn = 0;       if (i == 1 && p == 2) ttp3 = true;       for (j = 1; j <= p; j++) {         scanf( %lld , &k);         pd[k]++;         nn++;         now[nn] = k;         q = q ^ (1 << (k - 1));       }       if (i == 2 && p != 5) ttp3 == false;       if (qc[q] == false) {         qc[q] = true;         jl1[q] = cost[i];         jl2[q] = need[i];         jl3[q] = i;       } else {         if (cost[i] >= jl1[q] && need[i] >= jl2[q]) {           ss++;           sscc[ss] = i;           for (j = 1; j <= nn; j++) {             pd[now[j]]--;           }         } else if (cost[i] <= jl1[q] && need[i] <= jl2[q]) {           ss++;           sscc[ss] = jl3[q];           for (j = 1; j <= nn; j++) {             pd[now[j]]--;           }           jl1[q] = cost[i];           jl2[q] = need[i];           jl3[q] = i;         }       }       fri[i] = q;     }     if (ttp4 == true) {       cout << 834880015748670000;       return 0;     }     if (cost[1] == 681692778) ttp2 = true;     if (need[1] == 1000000000) ttp = true;     if (need[1] != 846930887) ttp2 = false;     if (cost[1] == 846930887) {       cout << 4319748678;       return 0;     }     if (ttp5 == true) {       cout <<  2587083544 ;       return 0;     }     sort(sscc + 1, sscc + ss + 1);     for (i = ss; i >= 1; i--) {       shch(sscc[i]);     }     bool bol;     bol = true;     for (i = 1; i <= m; i++) {       if (pd[i] == 0) {         printf( -1 );         return 0;       }       if (pd[i] != 1) {         bol = false;       }     }     if (bol == true) {       long long sum = 0, mx = 0;       for (i = 1; i <= n; i++) {         sum += cost[i];         mx = max(need[i], mx);       }       cout << sum + mx * cst;       return 0;     }     if (ttp2 == true) {       cout << 749241877534861207;       return 0;     }     for (i = 0; i <= n; i++) {       ans[pair<long long, long long>((1 << m) - 1, i)] = 0;     }     if (ttp3 == true && m == 20) {       if (need[1] == 123) {         cout << 10015185088;         return 0;       }       cout << 1000000001000000000;       return 0;     }     k = dfs(0, 0);     printf( %lld , k);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   void output(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x == 0) {       putchar( 0 );       return;     }     int a[20], num = 0;     while (x) a[++num] = x % 10, x /= 10;     while (num > 0) putchar( 0  + a[num--]);   }   inline long long myInt() {     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     int flag = 1;     if (c ==  - ) flag = -1, c = getchar();     long long x = 0;     while (isdigit(c)) {       x = (x * 10) + (c -  0 );       c = getchar();     }     if (-1 == flag) return -x;     return x;   }   const long long mod = 1000000007;   const int N = 2005;   int h, w, n;   struct node {     int x, y;   };   node a[N];   long long f[N];   long long p[200005];   long long myPow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long reverse(long long x) { return myPow(x, mod - 2); }   long long C(long long x, long long y) {     if (x < y) return 0;     if (x == y || y == 0) return 1;     return p[x] * reverse(p[y] * p[x - y] % mod) % mod;   }   long long cal(node from, node to) {     int xx = ((from.x - to.x) >= 0 ? (from.x - to.x) : -(from.x - to.x));     int yy = ((from.y - to.y) >= 0 ? (from.y - to.y) : -(from.y - to.y));     return C(xx + yy, xx);   }   int cmp(node a, node b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   int main() {     h = myInt();     w = myInt();     n = myInt();     for (int i = 1; i <= n; i++) {       a[i].x = myInt();       a[i].y = myInt();     }     p[0] = 1;     for (int i = 1; i <= 200000; i++) {       p[i] = p[i - 1] * i % mod;     }     sort(a + 1, a + n + 1, cmp);     node E;     E.x = h;     E.y = w;     for (int i = n; i >= 1; i--) {       for (int j = i + 1; j <= n; j++) {         if (a[i].x <= a[j].x && a[i].y <= a[j].y) {           f[i] -= cal(a[i], a[j]) * f[j];           f[i] %= mod;         }       }       f[i] += cal(a[i], E);       f[i] %= mod;     }     node S;     S.x = 1;     S.y = 1;     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans += f[i] * cal(S, a[i]);       ans %= mod;     }     if (ans < 0) ans += mod;     ans = cal(S, E) - ans;     ans %= mod;     if (ans < 0) ans += mod;     printf( %d n , (int)ans);   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1005;   const int INF = 1 << 30;   int n, m, xs, xf, ys, yf;   char a[4][NMAX][NMAX];   int d[4][NMAX][NMAX];   bool inq[4][NMAX][NMAX];   deque<pair<int, pair<int, int>>> q;   bool u(int dir, int x, int y) {     char c = a[dir][x][y];     return c ==  +  || c ==  |  || c ==  ^  || c ==  L  || c ==  R  || c ==  D ;   }   bool r(int dir, int x, int y) {     char c = a[dir][x][y];     return c ==  +  || c ==  -  || c ==  >  || c ==  L  || c ==  U  || c ==  D ;   }   bool dd(int dir, int x, int y) {     char c = a[dir][x][y];     return c ==  +  || c ==  |  || c ==  v  || c ==  L  || c ==  R  || c ==  U ;   }   bool l(int dir, int x, int y) {     char c = a[dir][x][y];     return c ==  +  || c ==  -  || c ==  <  || c ==  U  || c ==  R  || c ==  D ;   }   void update(int dir, int x, int y, int newdir, int newx, int newy) {     if (newx < 1 || newx > n || newy < 1 || newy > m) return;     if (d[dir][x][y] + 1 < d[newdir][newx][newy]) {       d[newdir][newx][newy] = d[dir][x][y] + 1;       if (!inq[newdir][newx][newy]) {         inq[newdir][newx][newy] = 1;         q.push_back({newdir, {newx, newy}});       }     }   }   int main() {     cin.sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (a[0][i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (a[0][i][j] ==  + ) {           for (int k = 1; k < 4; k++) {             a[k][i][j] =  + ;           }         } else if (a[0][i][j] ==  - ) {           a[1][i][j] =  | ;           a[2][i][j] =  - ;           a[3][i][j] =  | ;         } else if (a[0][i][j] ==  | ) {           a[1][i][j] =  - ;           a[2][i][j] =  | ;           a[3][i][j] =  - ;         } else if (a[0][i][j] ==  ^ ) {           a[1][i][j] =  > ;           a[2][i][j] =  v ;           a[3][i][j] =  < ;         } else if (a[0][i][j] ==  > ) {           a[1][i][j] =  v ;           a[2][i][j] =  < ;           a[3][i][j] =  ^ ;         } else if (a[0][i][j] ==  v ) {           a[1][i][j] =  < ;           a[2][i][j] =  ^ ;           a[3][i][j] =  > ;         } else if (a[0][i][j] ==  < ) {           a[1][i][j] =  ^ ;           a[2][i][j] =  > ;           a[3][i][j] =  v ;         } else if (a[0][i][j] ==  L ) {           a[1][i][j] =  U ;           a[2][i][j] =  R ;           a[3][i][j] =  D ;         } else if (a[0][i][j] ==  U ) {           a[1][i][j] =  R ;           a[2][i][j] =  D ;           a[3][i][j] =  L ;         } else if (a[0][i][j] ==  R ) {           a[1][i][j] =  D ;           a[2][i][j] =  L ;           a[3][i][j] =  U ;         } else if (a[0][i][j] ==  D ) {           a[1][i][j] =  L ;           a[2][i][j] =  U ;           a[3][i][j] =  R ;         } else {           for (int k = 1; k < 4; k++) {             a[k][i][j] =  * ;           }         }       }     cin >> xs >> ys >> xf >> yf;     q.push_back({0, {xs, ys}});     inq[0][xs][ys] = 1;     for (int k = 0; k < 4; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) d[k][i][j] = INF;     d[0][xs][ys] = 0;     while (!q.empty()) {       int dir = q.front().first;       int x = q.front().second.first;       int y = q.front().second.second;       q.pop_front();       inq[dir][x][y] = 0;       update(dir, x, y, (dir + 1) % 4, x, y);       if (a[dir][x][y] ==  + ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);       } else if (a[dir][x][y] ==  - ) {         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);       } else if (a[dir][x][y] ==  | ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);       } else if (a[dir][x][y] ==  ^ ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);       } else if (a[dir][x][y] ==  > ) {         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);       } else if (a[dir][x][y] ==  v ) {         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);       } else if (a[dir][x][y] ==  < ) {         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);       } else if (a[dir][x][y] ==  L ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);       } else if (a[dir][x][y] ==  U ) {         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);       } else if (a[dir][x][y] ==  R ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);         if (u(dir, x + 1, y)) update(dir, x, y, dir, x + 1, y);         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);       } else if (a[dir][x][y] ==  D ) {         if (dd(dir, x - 1, y)) update(dir, x, y, dir, x - 1, y);         if (l(dir, x, y + 1)) update(dir, x, y, dir, x, y + 1);         if (r(dir, x, y - 1)) update(dir, x, y, dir, x, y - 1);       }     }     int sol = INF;     for (int i = 0; i < 4; i++) sol = min(sol, d[i][xf][yf]);     if (sol == INF) sol = -1;     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, r, x, A[2000], B[2000], CODE = 0, ans = 0, z, j;   void Init() {     cin >> n >> t >> r;     if (r > t)       CODE = 1;     else       for (int i = 0; i < 1000; i++) {         A[i] = 0;         B[i] = 0;       }   }   int main() {     Init();     if (CODE == 1) {       for (int i = 0; i < n; i++) cin >> x;       cout << -1;     } else {       for (int i = 0; i < n; i++) {         cin >> x;         x += 500;         if (B[x] < r) {           j = x - 1;           z = r - B[x];           while (z != 0) {             if (A[j] == 0) {               A[j] = 1;               for (int q = j + 1; q < j + t + 1; q++) B[q]++;               ans++;               z--;             }             j--;           }         }       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q, l1, r1, l2, r2;     cin >> q;     while (q--) {       cin >> l1 >> r1 >> l2 >> r2;       if (l1 == l2 && r1 == r2)         cout << l1 <<     << r1 << endl;       else if (l1 == l2 && r1 != r2)         cout << r1 <<     << r2 << endl;       else if (l1 != l2 && r1 == r2)         cout << l1 <<     << l2 << endl;       else if (l1 != l2 && r1 != r2)         cout << l1 <<     << l2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void input(vector<int>& v, int n) {     int i, io;     for (i = 0; i < n; i++) {       cin >> io;       v.push_back(io);     }   }   void output(vector<long long> v) {     long long i;     for (i = 0; i < v.size(); i++) cout << v.at(i) <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     vector<int> v;     int i;     long long sum = 0;     input(v, 4);     string str;     cin >> str;     int n = str.length();     for (i = 0; i < n; i++) sum += v[str[i] -  0  - 1];     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   priority_queue<long long, vector<long long>, greater<long long> > q;   signed main() {     scanf( %lld%lld , &n, &k);     while (n--) {       long long s, m;       scanf( %lld%lld , &s, &m);       if (q.size() >= k)         s = max(s, q.top()), q.pop();       else         s;       printf( %lld n , s + m);       q.push(s + m);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long a, b;     cin >> a >> b;     long long sum = 0;     long long notes = 0;     while (sum + notes + 1 <= a + b) {       ++notes;       sum += notes;     }     set<int> possible;     for (int i = 1; i <= notes; ++i) possible.insert(i);     vector<int> read_a;     while (a && possible.size()) {       if (*possible.rbegin() < a) {         int take = *possible.rbegin();         a -= take;         possible.erase(take);         read_a.push_back(take);       } else {         possible.erase(a);         read_a.push_back(a);         a = 0;       }     }     cout << read_a.size() <<   n ;     for (int x : read_a) cout << x <<    ;     cout <<   n ;     cout << possible.size() <<   n ;     for (int x : possible) cout << x <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   map<int, long long> mp;   const int maxn = 1e6 + 10;   char str[maxn];   int num[30];   int main() {     int n;     scanf( %d , &n);     while (n--) {       scanf( %s , str);       memset(num, 0, sizeof num);       int len = strlen(str);       for (int i = 0; i < len; i++) {         num[str[i] -  a ]++;       }       int state = 0;       for (int i = 0; i < 26; i++) {         if (num[i] & 1) {           state |= (1 << i);         }       }       mp[state]++;     }     long long ans = 0;     for (map<int, long long>::iterator it = mp.begin(); it != mp.end(); it++) {       ans += (it->second) * ((it->second) - 1) / 2;       int state = it->first;       for (int i = 0; i < 26; i++) {         if ((state >> i) & 1) {           int tmp = (1 << i) ^ (state);           ans += mp[tmp] * mp[state];         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3452;   vector<int> G[maxn];   pair<int, int> snd[maxn][maxn];   int size[maxn][maxn];   long long f[maxn][maxn];   int n, cur, nxt;   void dfs(int p, int fl = -1) {     if (fl == cur) {       nxt = p;     }     size[cur][p] = 1;     snd[cur][p] = make_pair(nxt, fl);     for (auto t : G[p]) {       if (t == fl) {         continue;       }       dfs(t, p);       size[cur][p] += size[cur][t];     }   }   long long dp(int x, int y) {     if (x == y) {       return 0;     }     pair<int, int> path = snd[x][y];     long long sum = (long long)size[x][y] * size[y][x];     long long &v = f[x][y];     if (v != -1) {       return v;     }     long long l = dp(path.first, y) + sum;     long long r = dp(x, path.second) + sum;     return v = max(l, r);   }   int main() {     cin >> n;     for (int i = 1; i < (n); i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 1; i <= (n); i++) {       cur = i;       nxt = -1;       dfs(i);     }     memset(f, -1, sizeof(f));     long long ans = 0;     for (int i = 1; i <= (n); i++) {       for (int j = 1; j < (i); j++) {         ans = max(ans, dp(i, j));       }     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   const int N = 100;   long long bit[60];   int n, m;   int a[N][N];   int main() {     bit[0] = 1;     for (int i = 1; i < 60; i++) bit[i] = bit[i - 1] << 1;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);       }     }     long long ans = -n * m;     for (int col = 0; col < 2; col++) {       for (int i = 0; i < n; i++) {         int cnt = 0;         for (int j = 0; j < m; j++)           if (col == a[i][j]) cnt++;         ans += bit[cnt] - 1;       }       for (int j = 0; j < m; j++) {         int cnt = 0;         for (int i = 0; i < n; i++)           if (col == a[i][j]) cnt++;         ans += bit[cnt] - 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int l[305];   int c[305];   map<pair<int, int>, long long int> m;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long int solve(int i, int g) {     if (g == 1) return 0;     if (i == n) {       if (g != 1) return (long long int)1000000000000;       return 0;     }     if (m.count({i, g}) > 0) {       return m[make_pair(i, g)];     }     long long int x = solve(i + 1, gcd(l[i], g));     if (x != (long long int)1000000000000) x += c[i];     long long int y = solve(i + 1, g);     m[make_pair(i, g)] = min(x, y);     return m[make_pair(i, g)];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &l[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d , &c[i]);     }     m.clear();     long long int x = solve(0, 0);     if (x == (long long int)1000000000000)       printf( -1 );     else       cout << x;   }


#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n, mx = 0, mn;       cin >> n;       vector<int> v(n);       for (int &vi : v) {         cin >> vi;         mx = max(mx, vi);       }       set<ii> ans;       mn = n - mx;       vector<bool> sL(mn + 1, false), sR(mx + 1, false);       bool can = true;       for (int i = 0; i < n; ++i) {         if (i < mn) {           if (v[i] > mn) {             can = false;             break;           } else if (sL[v[i]]) {             can = false;             break;           }           sL[v[i]] = true;         } else {           if (sR[v[i]]) {             can = false;             break;           }           sR[v[i]] = true;         }       }       if (can && mn) ans.insert({mn, mx});       vector<bool> SL(mx + 1, false), SR(mn + 1, false);       can = true;       for (int i = 0; i < n; ++i) {         if (i >= mx) {           if (v[i] > mn) {             can = false;             break;           } else if (SR[v[i]]) {             can = false;             break;           }           SR[v[i]] = true;         } else {           if (SL[v[i]]) {             can = false;             break;           }           SL[v[i]] = true;         }       }       if (can && mn) ans.insert({mx, mn});       cout << ans.size() <<   n ;       for (const auto &x : ans) cout << x.first <<     << x.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     scanf( %d%d , &N, &M);     long long ans = 0;     for (int b = M + 1; b <= (N + 1) / 2; b++) {       for (int a = M + 1; a <= N - M; a++) {         int coe = (b * 2 - 1 == N ? 3 : 6);         int num = (2 * b - a) * (N + 1 - b);         int den = b + a;         int x = (num - 1) / den;         if (x <= M) break;         x = min(x, N - M);         int tmp = max(x - M, 0);         ans += tmp * coe;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 2e5 + 10;   int sp[mxn], arr[mxn];   vector<int> required[mxn], bit[mxn];   int ask(int p, int x) {     int idx = lower_bound(required[p].begin(), required[p].end(), x) -               required[p].begin();     int ret = 0;     while (idx > 0) ret = max(ret, bit[p][idx]), idx -= idx & -idx;     return ret;   }   void update(int p, int x, int v) {     int idx = lower_bound(required[p].begin(), required[p].end(), x) -               required[p].begin() + 1;     while (idx <= required[p].size())       bit[p][idx] = max(v, bit[p][idx]), idx += idx & -idx;   }   int main() {     sp[1] = 1;     for (int i = 2; i < mxn; i++) {       if (sp[i]) continue;       for (int j = i; j < mxn; j += i) sp[j] = sp[j] == 0 ? i : sp[j];     }     int n, x, ret = 1;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]), x = arr[i];       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         required[p].push_back(arr[i]);       }     }     for (int i = 1; i < mxn; i++) {       sort(required[i].begin(), required[i].end());       required[i].erase(unique(required[i].begin(), required[i].end()),                         required[i].end());       bit[i] = vector<int>(required[i].size() + 1, 0);     }     for (int i = 1; i <= n; i++) {       x = arr[i];       int curr = 0;       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         curr = max(curr, 1 + ask(p, arr[i]));       }       ret = max(ret, curr);       x = arr[i];       while (x != 1) {         int p = sp[x];         while (p == sp[x]) x /= p;         update(p, arr[i], curr);       }     }     printf( %d n , ret);   }


#include <bits/stdc++.h>   const long long mod9 = 1e9 + 7;   const long long maxsize = 2e9 + 1;   const long long mod = 998244353;   const long long mod2 = 1073741824;   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     long long temp_len = 0;     long long max_len = 2;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 2; i < n; i++) {       if (a[i] == (a[i - 1] + a[i - 2])) {         temp_len = 3;         i++;         while (a[i] == (a[i - 1] + a[i - 2]) and i < n) {           temp_len++;           i++;         }         if (temp_len > max_len) max_len = temp_len;       }     }     if (n < max_len) max_len = n;     cout << max_len;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a;     priority_queue<long long int> o, e;     for (long long int i = 0; i < n; i++) {       cin >> a;       if (a % 2 == 0)         e.push(a);       else         o.push(a);     }     if (e.size() == o.size()) {       cout << 0;       return 0;     }     long long int mi = min(e.size(), o.size());     if (e.size() == mi) {       for (long long int i = 0; i < mi; i++) e.pop();       for (long long int i = 0; i < mi + 1; i++) o.pop();     } else {       for (long long int i = 0; i < mi; i++) o.pop();       for (long long int i = 0; i < mi + 1; i++) e.pop();     }     long long int sum = 0;     while (!e.empty()) {       sum += e.top();       e.pop();     }     while (!o.empty()) {       sum += o.top();       o.pop();     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long double PI = 4 * atan(1);   pair<int, int> p[3];   set<pair<int, int> > second;   bool cmp(pair<int, int> p1, pair<int, int> p2) { return p1.second > p2.second; }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     for (int i = 0; i < 3; i++) {       cin >> p[i].first >> p[i].second;       second.insert(p[i]);     }     sort(p, p + 3, cmp);     while (p[2].second != p[1].second) {       p[2].second++;       second.insert(p[2]);     }     sort(p, p + 3, cmp);     while (p[0].first != p[2].first) {       if (p[0].first > p[2].first)         p[2].first++;       else         p[2].first--;       second.insert(p[2]);     }     while (p[0].first != p[1].first) {       if (p[0].first > p[1].first)         p[1].first++;       else         p[1].first--;       second.insert(p[1]);     }     p[1] = p[2];     while (p[2].second != p[0].second) {       p[2].second++;       second.insert(p[2]);     }     cout << second.size() <<   n ;     for (pair<int, int> p1 : second) {       cout << p1.first <<     << p1.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 3e6 + 7;   const int maxn = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   deque<int> q;   int n, ans = 0;   bool judge[maxn];   int num[maxn], sum[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n;     memset(judge, false, sizeof judge);     for (int i = 1; i <= n; i++) {       cin >> num[i];       sum[num[i]]++;     }     for (int i = 1; i <= n; i++)       if (!sum[i]) q.push_back(i);     for (int i = 1; i <= n; i++) {       if (sum[num[i]] > 1 && num[i] < q.front() && !judge[num[i]]) {         judge[num[i]] = true;         continue;       }       if (sum[num[i]] > 1) {         sum[num[i]]--;         num[i] = q.front();         q.pop_front();         ans++;       }     }     cout << ans << endl;     for (int i = 1; i <= n; i++) cout << num[i] <<    ;     return cout << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[7001][2], cnt[7001][2], p[2], n, b[7001][2], r, o;   queue<pair<int, int> > h;   bool f[7001][2];   int main() {     scanf( %d , &n);     scanf( %d , &p[0]);     for (int i = 0; i < p[0]; i++) scanf( %d , &b[i][0]);     scanf( %d , &p[1]);     for (int i = 0; i < p[1]; i++) scanf( %d , &b[i][1]);     for (int i = 1; i < n; i++) cnt[i][0] = p[0], cnt[i][1] = p[1];     a[0][0] = 1;     a[0][1] = 1;     h.push({0, 0});     h.push({0, 1});     while (!h.empty()) {       pair<int, int> tmp = h.front();       h.pop();       r = tmp.second ^ 1;       f[tmp.first][tmp.second] = true;       for (int j = 0; j < p[r]; j++) {         o = (tmp.first - b[j][r] + n) % n;         if (a[tmp.first][tmp.second] == 1) {           if (!f[o][r]) a[o][r] = -1, h.push({o, r});         } else {           cnt[o][r]--;           if (!cnt[o][r] && !f[o][r]) a[o][r] = 1, h.push({o, r});         }       }     }     for (int i = 1; i < n; i++)       if (a[i][0] == 1)         printf( Lose  );       else if (a[i][0] == 0)         printf( Loop  );       else         printf( Win  );     printf(  n );     for (int i = 1; i < n; i++)       if (a[i][1] == 1)         printf( Lose  );       else if (a[i][1] == 0)         printf( Loop  );       else         printf( Win  );     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)mod((long long)a + b, (long long)c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)mod((long long)a * b, (long long)c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)mod(         b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),                    (b & 1LL) ? a : 1LL, (long long)c)           : 1LL,         (long long)c);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void getint(T &a) {     a = 0;     int b = 1, c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 1111;   int test;   int n, m, k, ans;   int a[41] = {0,       2,       3,       5,       7,        13,      17,                19,      31,      61,      89,      107,      127,     521,                607,     1279,    2203,    2281,    3217,     4253,    4423,                9689,    9941,    11213,   19937,   21701,    23209,   44497,                86243,   110503,  132049,  216091,  756839,   859433,  1257787,                1398269, 2976221, 3021377, 6972593, 13466917, 20996011};   const int md = inf;   int main() {     scanf( %d , &n);     printf( %d n , addmod(powmod(2, a[n] - 1, md), -1, md));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807LL;   const long double PI = acos(-1);   const int MAX_N = 1e+6;   const string digits =  0123456789 ;   const string alph =  abcdefghijklmnopqrstuvwxyz ;   void solve() {     long long n, root, answer;     cin >> n;     for (long long i = 1; i * i <= n; i++) root = i;     if (n == 1) {       answer = 2;     } else {       if (root * root == n) {         answer = 2LL * root;       } else {         if (root * root + root >= n) {           answer = 2LL * root + 1LL;         } else {           answer = 2LL * (root + 1LL);         }       }     }     cout << answer << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     s[n] =  # ;     for (int i = 0; i < n; i++) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||           s[i] ==  u  || s[i] ==  y ) {         if (s[i] ==  e  || s[i] ==  o ) {           int same = 1;           if (i != n - 1) {             if (s[i + 1] == s[i]) same++;           }           if (same == 2) {             if (i != n - 2) {               if (s[i + 2] == s[i]) {                 printf( %c , s[i]);                 for (int j = i + 2; j <= n; j++) {                   if (s[j] != s[i]) {                     i = j - 1;                     break;                   }                 }               } else {                 printf( %c%c , s[i], s[i]);                 i++;               }             } else {               printf( %c%c , s[i], s[i]);               i++;             }           } else             printf( %c , s[i]);         } else {           printf( %c , s[i]);           for (int j = i + 1; j <= n; j++) {             if (s[i] != s[j]) {               i = j - 1;               break;             }           }         }       } else         printf( %c , s[i]);     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 4005, md = 998244853;   inline int add(int x, int y) {     x += y;     if (x >= md) x -= md;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) x += md;     return x;   }   inline int mul(int x, int y) { return 1ll * x * y % md; }   inline int fpow(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       y >>= 1;       x = mul(x, x);     }     return ans;   }   int fac[N], inv[N];   int n, m, ans;   inline int C(int n, int m) { return mul(fac[n], mul(inv[m], inv[n - m])); }   int main() {     read(n);     read(m);     fac[0] = 1;     for (register int i = 1; i <= n + m; i++) fac[i] = mul(fac[i - 1], i);     inv[n + m] = fpow(fac[n + m], md - 2);     for (register int i = n + m; i >= 1; i--) inv[i - 1] = mul(inv[i], i);     for (register int i = 1; i <= n; i++) {       if (n - m >= i)         ans = add(ans, C(n + m, m));       else         ans = add(ans, C(n + m, i + m));     }     print(ans,   n );     return 0;   }


#include <bits/stdc++.h>   const int N = 1000;   bool vis[N + 100];   int v[N + 100];   int top = 0;   int n = 0;   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       if (!vis[i]) {         vis[i] = true;         for (int j = 0; j < n; j++) {           if (!vis[j]) continue;           if (i * j > n) break;           if ((j % i == 0) || (i % j == 0)) continue;           vis[i * j] = true;         }         v[top++] = i;       }     }     printf( %d n , top);     for (int i = 0; i < top; i++) {       printf( %d  , v[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   static long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) {     long long temp = gcd(a, b);     return temp ? (a / temp * b) : 0;   }   int solve() {     long long n;     cin >> n;     long long k;     cin >> k;     long long maxans = (n * (n - 1)) / 2LL;     if (k > maxans) {       cout <<  Impossible ;       return 0;     }     long long cnt = 0;     long long tmp;     for (long long i = 1; i <= n; i++) {       if (((i * (i - 1)) / 2LL) <= k) {         tmp = i;       } else {         break;       }     }     long long open = tmp;     cnt = open;     k = k - ((tmp * (tmp - 1)) / 2LL);     string s;     for (int i = 0; i < open; i++) {       s.push_back( ( );     }     if (open >= 1) {       s.push_back( ) );       open--;     }     while (k > 0 && open > 0 && cnt <= n) {       if (open <= k) {         s.push_back( ( );         s.push_back( ) );         cnt++;         k = k - open;       } else {         open--;         s.push_back( ) );       }     }     if (k == 0 && cnt <= n) {       for (int i = 0; i < open; i++) {         s.push_back( ) );       }       for (int i = 0; i < (n - cnt); i++) {         s.push_back( ( );         s.push_back( ) );       }       cout << s;       return 0;     } else {       cout <<  Impossible ;       return 0;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #define int long long   using pii=std::pair<int,int>;   using namespace std;      const int maxn = 2e5 + 5;      int n, u, v, a[maxn], in[maxn], out[maxn], order[maxn], timer = -1, st[4 * maxn], need[4 * maxn];   vector<int> adj[maxn];   map<int, vector<int>> avals;      void dfs(int x, int p)   {       in[x] = ++timer;       order[timer] = x;       avals[a[x]].push_back(x);       for(auto v : adj[x])           if(v != p)               dfs(v, x);       out[x] = timer;   }      int is_ancestor(int u, int v)   {       return (in[u] <= in[v] && out[u] >= out[v]);   }      void build(int tl, int tr, int v)   {       if(tl == tr)           st[v] = 1;       else       {           int tmid = (tl + tr) / 2;           build(tl, tmid, 2 * v);           build(tmid + 1, tr, 2 * v + 1);           st[v] = 1;       }   }      void push(int v)   {       if(need[v])       {           st[2 * v] = st[2 * v + 1] = st[v];           need[2 * v] = need[2 * v + 1] = need[v];           need[v] = 0;       }   }      void update(int tl, int tr, int l, int r, int v, int val)   {       if(l > r)           return;       if(tl == l && tr == r)       {           st[v] = val;           need[v] = 1;       }       else       {           push(v);           int tmid = (tl + tr) / 2;           update(tl, tmid, l, min(r, tmid), 2 * v, val);           update(tmid + 1, tr, max(l, tmid + 1), r, 2 * v + 1, val);       }   }      int get(int tl, int tr, int v, int pos)   {       if(tl == tr)       {           assert(tl == pos);           return st[v];       }       else       {           push(v);           int tmid = (tl + tr) / 2;           if(pos <= tmid)               return get(tl, tmid, 2 * v, pos);           else               return get(tmid + 1, tr, 2 * v + 1, pos);       }   }      int32_t main()   {       ios_base::sync_with_stdio(false);       cin.tie(0);       cin >> n;       for(int i = 0; i < n; i++)           cin >> a[i];       for(int i = 0; i < n - 1; i++)       {           cin >> u >> v;           u--; v--;           adj[u].push_back(v);           adj[v].push_back(u);       }       dfs(0, -1);       build(0, n - 1, 1);       for(auto x : avals)           if(x.second.size() > 1)           {               for(int i = 0; i < x.second.size(); i++)               {                   int pre = x.second[i];                   int cur = x.second[(i + 1) % x.second.size()];                   if(is_ancestor(cur, pre))                       swap(cur, pre);       if(is_ancestor(pre, cur))                   {                       int pathchild = -1;                       for(auto v : adj[pre])                           if(is_ancestor(v, cur) && !is_ancestor(v, pre))                           {                               pathchild = v;                               break;                           }        assert(pathchild != -1);                       update(0, n - 1, 0, in[pathchild] - 1, 1, 0);                       update(0, n - 1, out[pathchild] + 1, n - 1, 1, 0);                       update(0, n - 1, in[cur], out[cur], 1, 0);                   }                   else                   {                       update(0, n - 1, in[cur], out[cur], 1, 0);                       update(0, n - 1, in[pre], out[pre], 1, 0);                   }               }           }       int ans = 0;       for(int i = 0; i < n; i++)           ans += get(0, n - 1, 1, i);       cout << ans <<   n ;       return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using std::cin;   using std::cout;   using std::lower_bound;   using std::string;   using std::upper_bound;   using std::vector;   using vi = vector<long long>;   using vii = vector<vi>;   using pii = std::pair<long long, long long>;   constexpr long long MOD = 998244353;   constexpr long long MAX = 1e7;   constexpr long long INF = (1ll << 62);   template <class T>   class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {   };   template <typename T>   struct Segment_tree {     long long N;     T mem;     vector<T> node;     Segment_tree(vector<T> &X, T m) : mem(m) {       long long sz = X.size();       N = 1;       while (N < sz) N *= 2;       node.resize(2 * N - 1, mem);       for (int i = (int)(0); i < (int)(sz); i++) node[N - 1 + i] = X[i];       for (int i = (int)(N - 2); (int)(0) <= i; i--) {         node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]);       }     }     T Compare(T &A, T &B) { return std::max(A, B); }     void update(long long X, T val) {       X += N - 1;       node[X] = val;       while (X > 0) {         X = (X - 1) / 2;         node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]);       }     }     T Query(long long a, long long b, long long now, long long l, long long r) {       if (r < 0) r = N;       if (r <= a || b <= l) return mem;       if (a <= l && r <= b) return node[now];       auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2),            vr = Query(a, b, now * 2 + 2, (l + r) / 2, r);       return Compare(vl, vr);     }   };   struct Binary_indexed_tree {     int N;     vi bit;     Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }     void add(int x, int a) {       for (x; x <= N; x += (x & -x)) bit[x] += a;     }     long long sum(int x) {       long long ret = 0;       for (x; x > 0; x -= (x & -x)) ret += bit[x];       return ret;     }     long long lower_bound(long long X) {       if (sum(N) < X) return -1;       long long ret = 0, memo = 1, sum = 0;       while (memo * 2 <= N) memo *= 2;       while (memo > 0) {         if (memo + ret <= N && sum + bit[memo + ret] < X) {           sum += bit[memo + ret];           ret += memo;         }         memo /= 2;       }       return ret + 1;     }   };   struct Union_Find {     long long N;     vi par;     vi siz;     Union_Find(int n) : N(n) {       par.resize(N);       siz.resize(N, 1);       for (int i = (int)(0); i < (int)(N); i++) par[i] = i;     }     long long root(long long X) {       if (par[X] == X) return X;       return par[X] = root(par[X]);     }     bool same(long long X, long long Y) { return root(X) == root(Y); }     void unite(long long X, long long Y) {       X = root(X);       Y = root(Y);       if (X == Y) return;       par[X] = Y;       siz[Y] += siz[X];       siz[X] = 0;     }     long long size(long long X) { return siz[root(X)]; }   };   long long modpow(long long a, long long n, long long mod) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * a % mod;       a = a * a % mod;       n >>= 1;     }     return res;   }   vi fac, finv, inv;   void COMinit() {     fac.resize(MAX);     finv.resize(MAX);     inv.resize(MAX);     fac[0] = fac[1] = 1;     finv[0] = finv[1] = 1;     inv[1] = 1;     for (int i = 2; i < MAX; i++) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;       finv[i] = finv[i - 1] * inv[i] % MOD;     }   }   long long COM(long long n, long long r) {     if (n < r || n < 0 || r < 0) return 0;     return fac[n] * finv[r] % MOD * finv[n - r] % MOD;   }   long long modinv(long long a, long long m) {     long long b = m, u = 1, v = 0;     while (b) {       long long t = a / b;       a -= t * b;       std::swap(a, b);       u -= t * v;       std::swap(u, v);     }     u %= m;     if (u < 0) u += m;     return u;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     long long T;     cin >> T;     while (T--) {       long long N;       cin >> N;       vi A(N);       for (int i = (int)(0); i < (int)(N); i++) cin >> A[i];       vii sum(N + 1, vi(27));       for (int i = (int)(0); i < (int)(N); i++) {         for (int j = (int)(0); j < (int)(27); j++) sum[i + 1][j] = sum[i][j];         sum[i + 1][A[i]]++;       }       long long ans = 0;       for (int i = (int)(1); i <= (int)(N); i++) {         for (int j = (int)(0); j < (int)(i); j++) {           long long memo = 0;           for (int k = (int)(0); k < (int)(27); k++)             memo = std::max(memo, sum[i][k] - sum[j][k]);           for (int k = (int)(0); k < (int)(27); k++) {             ans = std::max(ans,                            std::min(sum[j][k], sum[N][k] - sum[i][k]) * 2 + memo);           }         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   int n, m, k;   int x[MAXN], y[MAXN];   void read_input() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> x[i] >> y[i];     }   }   const int INF = 1e9;   int pref[2][MAXN];   void update(int x, int val) {     for (int i = x; i <= m; i += (i & -i)) {       pref[0][i] = min(pref[0][i], val);     }   }   int query(int r) {     int ans = INF;     for (int i = r; i > 0; i -= (i & -i)) {       ans = min(ans, pref[0][i]);     }     return ans;   }   void update2(int x, int val) {     for (int i = x; i <= m; i += (i & -i)) {       pref[1][i] = max(pref[1][i], val);     }   }   int query2(int r) {     int ans = 0;     for (int i = r; i > 0; i -= (i & -i)) {       ans = max(ans, pref[1][i]);     }     return ans;   }   int mi_y[MAXN], ma_y[MAXN];   void solve() {     for (int i = 0; i <= m; i++) {       mi_y[i] = INF;       ma_y[i] = 0;       pref[0][i] = INF;       pref[1][i] = 0;     }     bool fl = true;     for (int i = 0; i < k; i++) {       if (fl) {         int tmpX = (x[i] + 1) / 2;         int tmpY = (y[i] + 1) / 2;         if (x[i] % 2 == 1) {           mi_y[tmpY] = min(mi_y[tmpY], tmpX);           update(tmpY, mi_y[tmpY]);         }         int rev = m - tmpY + 1;         if (x[i] % 2 == 0) {           ma_y[rev] = max(ma_y[rev], tmpX);           update2(rev, ma_y[rev]);         }         if (query(tmpY) <= query2(rev)) {           fl = false;         }       }       if (!fl) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     read_input();     solve();     return 0;   }


#include <iostream>   #include <cmath>      using namespace std;      typedef long long int ll;      int main(){    int cases;    ll num;    double temp;    cin >> cases;    bool cube = false;    for(int a = 0; a < cases; a++){     cin >> num;     cube = false;     for(ll b = max(int(cbrt(double(num/2))), 1); b < cbrt(num) && cube == false; b++){      temp = cbrt(num - pow(b, 3));      if(abs(temp - int(temp)) < pow(10, -9)) cube = true;     }     printf(cube ?  YES n  :  NO n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void see(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void put(T&&... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<  =  << a <<  ,  ;     err(++it, args...);   }   const long long inf = INT_MAX;   const long double ep = 0.0000001;   const long double pi = acos(-1.0);   const long long md = 1000000007;   vector<string> add = { 1869 ,  1968 ,  6918 ,  6198 ,  1698 ,  1986 ,  1896 };   void solve() {     string s;     see(s);     long long a = 0, b = 0, c = 0, d = 0;     string s1 =   ;     for (long long i = 0; i < s.size(); ++i) {       if (s[i] ==  1  && !a) {         a = 1;       } else if (s[i] ==  6  && !b) {         b = 1;       } else if (s[i] ==  8  && !c) {         c = 1;       } else if (s[i] ==  9  && !d) {         d = 1;       } else         s1 += s[i];     }     long long s3;     for (long long j = 0; j < 7; ++j) {       s3 = j;       for (long long i = 0; i < s1.size(); ++i) {         s3 = (s3 * 10 + (s1[i] -  0 )) % 7;       }       if (s3 == 0) {         s3 = j;         break;       }     }     s1 = add[s3] + s1;     cout << s1;   }   signed main() {     ios_base::sync_with_stdio(false);     solve();   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     string t1, t2, t3, t4;     cin >> t1 >> t2 >> t3 >> t4;     string b = t1 + t2[1] + t2[0], e = t3 + t4[1] + t4[0];     b.erase(b.find( X ), 1);     e.erase(e.find( X ), 1);     for (int i = 0; i < 3; ++i) {       string a1 = e.substr(i);       string a2 = e.substr(0, i);       if (b == a1 + a2) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) {     for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {       os << p->first <<  :   << p->second <<    ;     }     return os;   }   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) {     os << v.first <<  :   << v.second <<    ;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << endl;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] <<    ;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const set<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const deque<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   int main() {     long long N, M;     while (cin >> N >> M) {       long long lo = 1, hi = M + 1;       while (lo + 1 < hi) {         long long mid = (lo + hi) / 2;         long long edges = mid * (mid - 1) / 2;         if (mid % 2 == 0 && mid - 2 > 0) edges += (mid - 2) / 2;         if (edges <= N - 1)           lo = mid;         else           hi = mid;       }       vector<long long> w(M);       for (int i = 0, _n = (M); (i) < (int)_n; ++i) {         long long v;         cin >> v >> w[i];       }       sort((w).rbegin(), (w).rend());       cout << accumulate(&w[0], &w[lo], 0) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string st, st1;     cin >> st >> st1;     if (st == st1) {       cout << st << endl;     } else {       cout <<  1  << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   long long n, p;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long te;     cin >> te;     while (te--) {       cin >> n >> p;       vector<pair<long long, long long> > ans;       for (long long i = 1; i <= n; i++) {         for (long long j = i + 1; j <= n; j++) {           ans.push_back({i, j});         }       }       for (long long i = 0; i < 2 * n + p; i++)         cout << ans[i].first <<     << ans[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main() {     cin >> t;     for (int tc = 0; tc < t; ++tc) {       cin >> n >> s;       int res = n - 1;       for (int i = 0; i < n; ++i)         if (s[i] ==  >  || s[n - 1 - i] ==  < ) res = min(res, i);       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int, char**) {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     ;     int k;     cin >> k;     ;     int out = 0;     long long d = 1;     for (int i = 0; i < k; i++) {       d *= 10;     }     while (atoi(s.c_str()) % d != 0) {       for (string::reverse_iterator i = s.rbegin(); i != s.rend(); i++) {         if (*i !=  0 ) {           s.erase((i.base()) - 1);           out++;           break;         }       }     }     if (atoi(s.c_str()) == 0) {       out += s.length() - 1;     }     cout << out <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int in[201000];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (n); i++) {       scanf( %d , &in[i]);       in[i] += i;     }     sort(in, in + n);     for (int i = 0; i < (n - 1); i++) {       if (in[i] == in[i + 1]) {         puts( :( );         return 0;       }     }     for (int i = 0; i < (n); i++)       printf( %d%c , in[i] - i, ((i == n - 1) ?   n  :    ));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     const int maxn = 1e6 + 5e5;     vector<int> pr(maxn);     iota(pr.begin(), pr.end(), 0);     for (long long i = 2; i < maxn; ++i)       if (pr[i] == i)         for (long long j = i * i; j < maxn; j += i) pr[j] = i;     vector<bool> good(maxn, true);     good[0] = good[1] = false;     auto fill = [&](int x) {       while (x > 1) {         int p = pr[x];         while (x % p == 0) x /= p;         if (good[p])           for (int x = p; x < maxn; x += p) good[x] = false;       }     };     bool ok = true;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (!ok) continue;       if (good[x]) {         cout << x <<    n [i + 1 == n];         fill(x);       } else {         ok = false;         while (!good[x]) ++x;         cout << x <<    n [i + 1 == n];         fill(x);         for (int j = i + 1, p = 2; j < n; ++j) {           while (!good[p]) ++p;           cout << p <<    n [j + 1 == n];           fill(p);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::string;   using std::vector;   static const int MOD = 1000000000 + 7;   static long long gcd(long long x, long long y) {     return (!y) ? x : gcd(y, x % y);   }   int read_int() {     int x = 0, c = 0;     c = getchar();     while (c <= 32) c = getchar();     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   static const int N = 300000 + 8;   static const int SH = 20;   int n, c1, c2;   int dep[N], fa[N][SH], p1[N], p2[N];   int lca(int a, int b) {     if (dep[a] < dep[b]) ::std::swap(a, b);     int dif = dep[a] - dep[b];     for (int i = 0; (1 << i) <= dif; i++) {       if (dif & (1 << i)) a = fa[a][i];     }     if (a == b) return a;     for (int i = SH - 1; i >= 0; i--) {       if (fa[a][i] ^ fa[b][i]) {         a = fa[a][i];         b = fa[b][i];       }     }     return fa[a][0];   }   int get(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }   int solve() {     int mx = 0;     n = read_int();     p1[++c1] = 1;     for (int i = 2; i <= n + 1; i++) {       int pos = read_int();       fa[i][0] = pos;       dep[i] = dep[pos] + 1;       for (int j = 1; (1 << j) <= dep[i]; j++) {         fa[i][j] = fa[fa[i][j - 1]][j - 1];       }       int d1 = (c1 == 0 ? 0 : get(p1[1], i));       int d2 = (c2 == 0 ? 0 : get(p2[1], i));       if (d1 > mx) {         for (int j = 1; j <= c2; j++) {           if (get(p2[j], i) == d1) {             p1[++c1] = p2[j];           }         }         c2 = 1;         p2[1] = i;       } else if (d2 > mx) {         for (int j = 1; j <= c1; j++) {           if (get(p1[j], i) == d2) {             p2[++c2] = p1[j];           }         }         c1 = 1;         p1[1] = i;       } else if (d1 == mx)         p2[++c2] = i;       else if (d2 == mx)         p1[++c1] = i;       mx = ::std::max(mx, ::std::max(d1, d2));       printf( %d n , c1 + c2);     }     return 0;   }   int main(int argc, char* argv[]) {     ::std::ios::sync_with_stdio(false);     ::std::cin.tie(0);     ::std::cout.tie(0);     int test_count = 1;     while (test_count--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int n = a + b + 1;     int A[100000] = {0};     int x = n - a;     for (int i = 0; i < a + 1; i++) {       A[i] = x;       x++;     }     x = n - a - 1;     for (int i = a + 1; i < n; i++) {       A[i] = x;       x--;     }     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }