#include <bits/stdc++.h>   using namespace std;   const long long maxS = 2e5 + 5;   long long N, M;   long long A[201], B[201];   long long DP[201][515];   long long go(long long pos, long long prev) {     if (pos == N + 1) return 0;     if (DP[pos][prev] != -1) return DP[pos][prev];     long long ans = INT_MAX;     for (long long i = 1; i <= M; i++)       ans = min(ans,                 (prev | (A[pos] & B[i]) | go(pos + 1, (prev | (A[pos] & B[i])))));     return DP[pos][prev] = ans;   }   void code_idhr_h() {     cin >> N >> M;     for (long long i = 1; i <= N; i++) cin >> A[i];     for (long long i = 1; i <= M; i++) cin >> B[i];     memset(DP, -1, sizeof DP);     cout << go(1, 0) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long T = 1;     for (long long t = 1; t <= T; t++) {       code_idhr_h();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000000 + 10;   const int mod = 51123987;   int n;   long long p[maxn], sum;   char s1[maxn], s[maxn];   long long min(int a, int b) { return a < b ? a : b; }   inline void init() {     s[0] =  $ ;     for (int i = 1; i <= n; ++i) s[2 * i] = s1[i], s[2 * i - 1] =  # ;     s[2 * n + 1] =  # ;     n = 2 * n + 1;   }   inline void manacher() {     init();     p[0] = 0;     for (int i = 1, id = 0, mx = 0; i <= n; ++i) {       if (mx > i)         p[i] = min(mx - i + 1, p[2 * id - i]);       else         p[i] = 0;       while (s[i - p[i]] == s[i + p[i]]) ++p[i];       if (i + p[i] - 1 > mx) id = i, mx = i + p[i] - 1;       sum += (p[i] - 1) / 2;       if (i % 2 == 0) ++sum;     }   }   long long f[maxn], g[maxn];   inline void solve() {     sum %= mod;     sum = sum * (sum - 1) / 2;     sum %= mod;     for (int i = 2; i <= n; i += 2) {       ++f[i - p[i] + 2];       --f[i + 2];       ++g[i];       --g[i + p[i]];     }     for (int i = 1; i <= n; i += 2) {       ++f[i - p[i] + 2];       --f[i + 1];       ++g[i + 1];       --g[i + p[i]];     }     for (int i = 2; i <= n; i += 2) {       f[i] += f[i - 2];       f[i] %= mod;       g[i] += g[i - 2];       g[i] %= mod;     }     f[n + 1] = 0;     for (int i = n - 1; i >= 1; i -= 2) f[i] += f[i + 2];     for (int i = 2; i <= n; i += 2) {       sum = sum - (g[i] * f[i + 2]) % mod;       sum = (sum + mod) % mod;     }     sum = (sum + mod) % mod;     printf( %I64d n , sum);   }   int main() {     scanf( %d%s , &n, s1 + 1);     manacher();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   constexpr int MOD = 998244353;   int sum(int a, int b, int mod = MOD) {     int c = a + b;     if (c >= mod) {       c -= mod;     }     return c;   }   inline int prod(int a, int b, int mod = MOD) { return (1LL * a * b) % mod; }   int modpow(int base, ll exp, int mod = MOD) {     int res = 1;     int cur = base;     for (ll p = 1LL; p <= exp; p <<= 1LL) {       if (p & exp) {         res = prod(res, cur, mod);       }       cur = prod(cur, cur, mod);     }     return res;   }   inline int inv(int x, int mod = MOD) { return modpow(x, mod - 2, mod); }   constexpr int MAXN = 1e6 + 6;   int fact[MAXN], tcaf[MAXN];   void gen_fact() {     fact[0] = 1;     for (int i = 1; i < MAXN; ++i) {       fact[i] = prod(fact[i - 1], i);     }     tcaf[MAXN - 1] = inv(fact[MAXN - 1]);     for (int i = MAXN - 2; i >= 0; --i) {       tcaf[i] = prod(tcaf[i + 1], i + 1);     }   }   int choose(int n, int k) {     assert(n >= 0);     assert(0 <= k and k <= n);     return prod(fact[n], prod(tcaf[k], tcaf[n - k]));   }   int solve(ll n) {     int ans = modpow(3, 1LL * n * n);     for (int i = 1; i <= n; ++i) {       int x = prod(choose(n, i), modpow(3, 1LL * (n * (n - i)) + i));       int v = prod(2, x);       if (i % 2 == 0) {         ans = sum(ans, v);       } else {         ans = sum(ans, MOD - v);       }     }     for (int i = 1; i < n; ++i) {       int v = prod(6, choose(n, i));       if ((i + n) % 2 == 0) {         ans = sum(ans, v);       } else {         ans = sum(ans, MOD - v);       }     }     ans = sum(ans, 3);     int square_sum = 0;     for (int i = 1; i < n; ++i) {       int row_sum = modpow(1 + MOD - modpow(3, i), n);       row_sum = sum(row_sum, MOD - 1);       row_sum = sum(row_sum, MOD - modpow(MOD - modpow(3, i), n));       square_sum =           sum(square_sum, prod(modpow(MOD - 1, i), prod(choose(n, i), row_sum)));     }     ans = sum(ans, prod(3, square_sum));     return sum(modpow(3, 1LL * n * n), MOD - ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     gen_fact();     int n;     cin >> n;     cout << solve(n);     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     long long l = -1, r = -1;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  [ ) {         l = i;         break;       }     }     for (long long i = s.length(); i >= 0; i--) {       if (s[i] ==  ] ) {         r = i;         break;       }     }     if (l == -1 || r == -1 || r < l)       cout <<  -1             <<   n ,           exit(0);     s = s.substr(l, r - l + 1);     l = -1;     r = -1;     for (long long i = 1; i < s.length() - 1; i++) {       if (s[i] ==  : ) {         l = i;         break;       }     }     for (long long i = s.length() - 2; i >= 1; i--) {       if (s[i] ==  : ) {         r = i;         break;       }     }     if (l == r || l == -1) cout <<  -1 n , exit(0);     string v = s.substr(l, r - l + 1);     long long ct = 0;     for (auto it : v) {       if (it ==  | ) ct++;     }     cout << ct + 4 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, car[101][101];     bool t[101] = {0};     vector<int> ans;     ans.clear();     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &car[i][j]);         if (car[i][j] == 2) {           t[j] = true;         } else if (car[i][j] == 1) {           t[i] = true;         } else if (car[i][j] == 3) {           t[i] = true;           t[j] = true;         }       }     }     for (int i = 0; i < n; i++) {       if (t[i] == false) ans.push_back(i + 1);     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d , ans[i]);       if (i < ans.size() - 1) printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4003;   int t[N][N];   int a;   string s;   map<long long, long long> mp;   long long acc[N];   int main() {     cin >> a >> s;     int n = s.size();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) t[i][j] = (s[i] -  0 ) * (s[j] -  0 );     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j <= i; j++) sum += (s[j] -  0 );       acc[i] = sum;     }     acc[-1] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= i; j++) {         long long sum = acc[i] - acc[j - 1];         mp[sum]++;       }     long long ans = 0;     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j <= i; j++) {         sum = acc[i] - acc[j - 1];         if (sum)           if (a % sum == 0) {             ans += mp[a / sum];           }         if (!sum && !a) ans += n * (n + 1) / 2;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T X) {     return X * X;   }   const int maxn = 110;   const double zero = 1e-8;   int n, K;   double omiga;   struct COO {     double x, y;   } ob[maxn], nuclear;   double p[maxn], f[maxn][maxn];   double numb;   double ans;   void init() {     scanf( %d , &n);     scanf( %d%lf , &K, &omiga);     omiga = 1.0 - omiga / 1000;     scanf( %lf%lf , &nuclear.x, &nuclear.y);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &ob[i].x, &ob[i].y);   }   int ZO(double comX, double comY) {     if (abs(comY - comX) <= zero) return 0;     if (comX < comY)       return -1;     else       return 1;   }   void work1(double R) {     for (int i = 1; i <= n; i++) {       double Di = sqr(nuclear.x - ob[i].x) + sqr(nuclear.y - ob[i].y);       if (ZO(Di, sqr(R)) <= 0)         p[i] = 1.0;       else         p[i] = exp(1 - Di / sqr(R));     }   }   void dp() {     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) f[i][j] = 0.0;     f[0][0] = 1.0;     for (int i = 1; i <= n; i++) f[i][0] = f[i - 1][0] * (1 - p[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++)         f[i][j] = f[i - 1][j - 1] * p[i] + f[i - 1][j] * (1.0 - p[i]);     numb = 0.0;     for (int j = K; j <= n; j++) numb += f[n][j];   }   void solve() {     double Lx = 0, Rx = 4000.0;     while (ZO(Lx, Rx) < 0) {       double mid = (Lx + Rx) / 2;       work1(mid);       dp();       if (numb >= omiga)         Rx = mid;       else         Lx = mid;     }     ans = Lx;   }   void print() { printf( %.10lf n , ans); }   int main() {     init();     solve();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int nax = 1e3 + 20;   const int mod = 1e9 + 7;   int fact[nax];   int binpow(int a, int e) {     int ans = 1;     while (e > 1) {       if (e & 1) {         ans = (1LL * ans * a) % mod;         --e;       }       a = (1LL * a * a) % mod;       e >>= 1;     }     ans = (1LL * ans * a) % mod;     return ans;   }   int C(int n, int k) {     if (k > n) return 0;     return (1LL * fact[n] *             (1LL * binpow(fact[n - k], mod - 2) * binpow(fact[k], mod - 2) %              mod)) %            mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(20) << fixed;     fact[0] = 1;     for (int i = 1; i <= (int)nax - 1; ++i) {       fact[i] = (1LL * fact[i - 1] * i) % mod;     }     int n, m, k;     cin >> n >> m >> k;     cout << (1LL * C(n - 1, 2 * k) * C(m - 1, 2 * k)) % mod <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void amax(X& x, const Y& y) {     if (x < y) x = y;   }   template <class X, class Y>   void amin(X& x, const Y& y) {     if (x > y) x = y;   }   const int INF = 1e9 + 10;   const long long INFL = (long long)1e18 + 10;   const int MAX = 2e5 + 10;   int n;   long long l[MAX], r[MAX];   map<long long, long long> cnt, inc, ddec;   void process() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];     long long maxr = 0, minl = INFL;     for (int i = 1; i <= n; i++) {       inc[l[i]] = ddec[l[i]] = 0;       inc[r[i]] = ddec[r[i]] = 0;       amax(maxr, r[i]);       amin(minl, l[i]);     }     ddec[maxr + 1] = 0;     for (int i = 1; i <= n; i++) {       inc[l[i]]++;       auto p2 = ddec.find(r[i]);       p2 = next(p2);       p2->second++;     }     long long ppost = minl - 1;     int psum = 0;     for (auto p : inc) {       psum -= ddec[p.first];       cnt[psum] += p.first - ppost - 1;       psum += p.second;       cnt[psum]++;       ppost = p.first;     }     for (int i = 1; i <= n; i++) cout << cnt[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     process();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[200000 + 5];   int main() {     int T, n;     int m, p;     scanf( %d , &T);     for (int t = 1; t <= T; ++t) {       scanf( %d , &n);       for (int i = 0; i <= n; ++i) e[i].clear();       for (int i = 1; i <= n; ++i) {         scanf( %d%d , &m, &p);         e[m].push_back(p);       }       priority_queue<int, vector<int>, greater<int> > que;       long long ans = 0;       for (int i = n; i >= 0; --i) {         int len = e[i].size();         for (int j = 0; j < len; ++j) que.push(e[i][j]);         while (que.size() > n - i) {           ans += que.top();           que.pop();         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200009];   set<int> ss;   pair<int, int> help[200009];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       v[a].push_back(b);     }     for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());     help[0] = pair<int, int>(0, 0);     for (int i = 1; i <= n; i++)       if (v[i].size() != 0)         help[i] = pair<int, int>(v[i][v[i].size() - 1], i);       else         help[i] = pair<int, int>(0, 0);     sort(help, help + n + 1);     int q;     cin >> q;     for (int i = 0; i < q; i++) {       ss.clear();       int k;       cin >> k;       for (int i = 0; i < k; i++) {         int a;         scanf( %d , &a);         ss.insert(a);       }       int A, B;       A = B = -1;       for (int j = n; j >= 1; j--) {         if (help[j].first == 0) break;         if (A != -1 && B != -1) break;         if (A == -1) {           if (ss.find(help[j].second) == ss.end() && help[j].second != 0)             A = help[j].second;         } else {           if (ss.find(help[j].second) == ss.end() && help[j].second != 0)             B = help[j].second;         }       }       if (B == -1 && A == -1)         printf( 0 0 n );       else if (B == -1)         printf( %d %d n , A, v[A][0]);       else {         int x = v[B][v[B].size() - 1];         int y = *lower_bound(v[A].begin(), v[A].end(), x);         printf( %d %d n , A, y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100010];   int c[100010];   const int mod = 1000000007;   long long Pow(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       b >>= 1;       a = a * a % c;     }     return ans;   }   int main() {     scanf( %s , a);     int n = strlen(a), k;     int cnt0 = count(a, a + n,  0 );     int cnt5 = count(a, a + n,  5 );     int cnt = 0;     for (int i = 0; i <= n - 1; i++) {       if (a[i] ==  0  || a[i] ==  5 ) {         c[cnt++] = i;       }     }     scanf( %d , &k);     long long tmp1 = Pow(2, (long long)n * k, mod);     tmp1 -= 1;     if (tmp1 < 0) tmp1 += mod;     long long tmp2 = Pow(2, n, mod);     tmp2 -= 1;     if (tmp2 < mod) tmp2 += mod;     tmp2 = Pow(tmp2, mod - 2, mod);     long long ans = 0;     for (int i = 0; i <= cnt - 1; i++) {       ans += Pow(2, c[i], mod) * tmp1 % mod * tmp2 % mod;       if (ans >= mod) ans -= mod;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0, xs, ys, xe, ye;     char q[105][105];     cin >> n >> m;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> q[i][j];         if (q[i][j] ==  S ) {           xs = i;           ys = j;         }         if (q[i][j] ==  E ) {           xe = i;           ye = j;         }       }     }     string line;     cin >> line;     int x, y;     for (int w = 0; w <= 3; ++w) {       for (int l = 0; l <= 3; ++l) {         for (int s = 0; s <= 3; ++s) {           for (int r = 0; r <= 3; ++r) {             if (w == l || w == s || w == r) {               continue;             }             if (l == s || l == r) {               continue;             }             if (s == r) {               continue;             }             x = xs;             y = ys;             for (int i = 0; i < line.size(); ++i) {               int p = line[i] -  0 ;               if (p == w) {                 x++;                 if (x >= n) {                   break;                 }               }               if (p == l) {                 y--;                 if (y < 0) {                   break;                 }               }               if (p == s) {                 x--;                 if (x < 0) {                   break;                 }               }               if (p == r) {                 y++;                 if (y >= m) {                   break;                 }               }               if (x == xe && y == ye) {                 break;               }               if (q[x][y] ==  # ) {                 break;               }             }             if (x == xe && y == ye) {               ans++;             }           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double TOLL = 1e-9;   int N, L, K;   int a[210];   double p[210];   const int maxn = 400;   double dp[201][401][maxn + 2];   double rec(int ind, int l, int cap) {     if (cap < -202) cap = -200;     if (cap > 202) cap = 200;     if (ind == N) {       if (l <= 0 && cap >= 0) return 1;       return 0;     }     if (dp[ind][l + 200][cap + 200] > -.5) return dp[ind][l + 200][cap + 200];     double rv = p[ind] * rec(ind + 1, l - 1, cap + a[ind]) +                 (1 - p[ind]) * rec(ind + 1, l, cap);     return dp[ind][l + 200][cap + 200] = rv;   }   int main() {     while (cin >> N >> L >> K) {       for (int i = 0; i < N; i++) {         cin >> p[i];         p[i] /= 100;       }       for (int i = 0; i < N; i++) cin >> a[i];       memset(dp, -1, sizeof dp);       printf( %.12lf n , rec(0, L, K));     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   using namespace std;   const int N = 2e5 + 100, sq = 1002, nsq = 200;   int cnt[nsq][N], b[nsq][N / 2];   int a[N];   map<int, int> mp, nmp;   vector<pair<int, pair<int, int> > > q;   void add(int id, int val) {     while (id < nsq) {       cnt[id][val]++;       b[id][cnt[id][val]]++;       id++;     }   }   void rem(int id, int val) {     while (id < nsq) {       b[id][cnt[id][val]]--;       cnt[id][val]--;       id++;     }   }   int get1(int id) {     int val = a[id];     int pid = id / sq;     int ans = cnt[pid][val];     int x = pid * sq;     for (int i = x; i <= id; i++) {       if (a[i] == val) ans++;     }     return ans;   }   int get2(int id) {     int val = a[id];     int pid = id / sq;     int w = cnt[pid][val];     int x = pid * sq;     for (int i = x; i <= id; i++) {       if (a[i] == val) w++;     }     int ans = b[pid][w];     for (int i = x; i <= id; i++) {       cnt[pid][a[i]]++;       if (cnt[pid][a[i]] == w) ans++;     }     for (int i = x; i <= id; i++) {       cnt[pid][a[i]]--;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     vector<int> mol;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mol.push_back(a[i]);     }     int q1;     cin >> q1;     for (int i = 0; i < q1; i++) {       int t, u, v;       cin >> t >> u >> v;       if (t == 1) mol.push_back(u);       q.push_back({t, {u, v - 1}});     }     sort(mol.begin(), mol.end());     mol.resize(unique(mol.begin(), mol.end()) - mol.begin());     for (int i = 0; i < mol.size(); i++) {       mp[mol[i]] = i + 1;       nmp[i + 1] = mol[i];     }     for (int i = 0; i < n; i++) a[i] = mp[a[i]];     for (int i = 0; i < q1; i++)       if (q[i].first == 1) q[i].second.first = mp[q[i].second.first];     int id = 0;     while (id < n) {       for (int i = 0; i < id; i++) {         cnt[id / sq][a[i]]++;       }       for (int i = 0; i < N; i++) {         b[id / sq][cnt[id / sq][i]]++;       }       for (int i = N - 1; i; i--) {         b[id / sq][i] += b[id / sq][i + 1];       }       id += sq;     }     for (int i = 0; i < q1; i++) {       if (q[i].first == 1) {         int v = q[i].second.first, p = q[i].second.second;         int z = a[p];         add(p / sq + 1, v);         rem(p / sq + 1, a[p]);         a[p] = v;       } else {         int x = q[i].second.first, y = q[i].second.second;         if (x == 1)           cout << nmp[a[y]] <<   n ;         else if (x % 2 == 0) {           int ans = get1(y);           cout << ans <<   n ;         } else {           int ans = get2(y);           cout << ans <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   const int maxn = (int)6e5 + 10;   const int inf = (int)1e9 + 5;   const int mod = (int)1e9 + 7;   const long long llinf = (long long)1e18 - 1;   const long double pi = acos(-1.0);   int nxt[maxn][26];   bool leaf[maxn];   int diff[maxn];   int c[maxn];   char s[maxn];   int n;   vector<int> g[maxn];   int sz[maxn];   int root[maxn];   int T = 1;   int calc(int v) {     int ret = leaf[v];     for (int i = (0); i < (26); i++)       if (nxt[v][i]) ret += calc(nxt[v][i]);     return ret;   }   void addTrie(int globroot, int root, int v) {     for (int c = (0); c < (26); c++) {       if (nxt[v][c] == 0) continue;       if (nxt[root][c] == 0) {         diff[globroot] += calc(nxt[v][c]);         nxt[root][c] = nxt[v][c];         continue;       }       diff[globroot] += leaf[nxt[v][c]] - leaf[nxt[root][c]];       leaf[nxt[root][c]] |= leaf[nxt[v][c]];       addTrie(globroot, nxt[root][c], nxt[v][c]);     }   }   void dfs(int v, int par = -1) {     sz[v] = 1;     int chi = -1;     for (int x : g[v]) {       if (x == par) continue;       dfs(x, v);       sz[v] += sz[x];       if (chi == -1 || sz[x] > sz[chi]) {         chi = x;       }     }     int &rt = root[v];     rt = T++;     int &link = nxt[rt][s[v] -  a ];     if (chi != -1) {       link = root[chi];       diff[rt] += diff[link];       for (int x : g[v]) {         if (x == par || x == chi) continue;         addTrie(rt, link, root[x]);       }     } else {       link = T++;     }     leaf[link] = true;     diff[rt]++;     c[v] += diff[rt];   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); i++) scanf( %d , c + i);     gets(s);     gets(s);     for (int i = (0); i < (n - 1); i++) {       int x, y;       scanf( %d%d , &x, &y);       --x;       --y;       g[x].push_back(y), g[y].push_back(x);     }     dfs(0, -1);     int mx = c[0] + diff[0], cnt = 1;     for (int i = (1); i < (n); i++) {       int val = c[i];       if (val > mx) mx = val, cnt = 0;       if (val == mx) cnt++;     }     printf( %d n%d n , mx, cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd;   const int N = 1e5 + 10;   long long a[N], pref[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, d, m;     cin >> n >> d >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       pref[i] = pref[i - 1] + a[i];     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (a[i] <= m) {         cnt++;       }     }     long long ans = 0;     for (int k = 0; k <= n - cnt; k++) {       if (1ll * k * d + k + cnt < n) {         continue;       }       if (1ll * (k - 1) * d + k > n) {         continue;       }       int x = min(cnt, n - (k - 1) * d - k);       ans = max(ans, pref[cnt] - pref[cnt - x] + pref[n] - pref[n - k]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<pair<long long, long long>> vp;     long long p, a, l = 0, r = 0, ss = 0;     for (int i = 0; i < n; i++) {       cin >> p >> a;       if (p < 0) {         ++l;       } else {         ++r;       }       ss += a;       vp.push_back(make_pair(p, a));     }     if (l == r or l == r + 1 or r == l + 1) {       cout << ss <<   n ;       return;     }     sort(vp.begin(), vp.end());     if (l == 0) {       cout << vp[0].second <<   n ;       return;     } else if (r == 0) {       cout << vp[n - 1].second <<   n ;       return;     }     long long ans = 0;     if (l < r) {       for (int i = 0; i <= 2 * l; i++) {         ans += vp[i].second;       }     } else {       for (int i = l - r - 1; i < n; i++) {         ans += vp[i].second;       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double work(int x) {     if (x == 0) return 1;     double n = 1.000000011;     double ans = 1;     while (x > 0) {       if ((x & 1) == 1) ans *= n;       n *= n;       x /= 2;     }     return ans;   }   int main() {     int n, t;     cin >> n >> t;     printf( %0.20lf n , work(t) * n);     return 0;   }


//Template Made By: Ojassvi Kumar   #include<bits/stdc++.h>   using namespace std;       #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);   #define ll long long int   #define fo(i,a,b) for(long long int i=a; i<b; i++)   #define endl   n    #define max3(a,b,c) max(max((a),(b)),(c))   #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))   #define min3(a,b,c) min(min((a),(b)),(c))   #define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))   #define pb push_back   #define lb lower_bound   #define up upper_bound   #define all(V) V.begin(),V.end()   #define itv vector<long long int>::iterator   #define pll pair<long long int,long long int>   #define mp make_pair   #define itp vector<pair<long long int,long long int>>::iterator   #define sll set<long long int,greater<long long int>>   #define its set<long long int,greater<long long int>>::iterator   #define d0(x) cout<<(x)<<      #define d1(x) cout<<(x)<<endl   #define d2(x,y) cout<<(x)<<   <<(y)<<endl       //const long double pi = 3.14159265358979323846264338;   //Template Ends       int main(){       ios       #ifndef ONLINE_JUDGE       freopen( INPUT.txt ,  r , stdin);       freopen( OUTPUT.txt ,  w , stdout);       #endif       ll Tests=1;       cin>>Tests;       while(Tests--){           ll N,L,R,S;           cin>>N>>L>>R>>S;           ll num=R-L+1;           ll Hsum=0,Lsum=0;           fo(i,0,num){               Hsum+=(N-i);               Lsum+=(i+1);           }           if(S>Hsum||S<Lsum){               cout<<-1<<endl;           }           else{               vector<ll> V(num);               fo(i,0,V.size())                   V[i]=i+1;               ll curS=Lsum;               ll j=num-1;               ll ceill=N;               while(1){                   if(curS==S){                       break;                   }                   else{                       V[j]++;                       curS++;                       if(V[j]==ceill){                           j--;                           ceill--;                       }                   }               }               set<ll> ST;               fo(i,0,num)                   ST.insert(V[i]);               vector<ll> VV;               fo(i,0,N){                   if(!ST.count(i+1)){                       VV.pb(i+1);                   }               }               ll jj=0,jjj=0;               fo(i,0,N){                   if(i>=(L-1)&&i<=(R-1)){                       cout<<V[jj]<<   ;                       jj++;                   }                   else{                       cout<<VV[jjj]<<   ;                       jjj++;                   }               }               cout<<endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   double PI = 3.1415926536;   const int inf = 1e9 + 7;   long long MAX(long long a, long long b) { return a > b ? a : b; }   long long MIN(long long a, long long b) { return a > b ? b : a; }   inline bool ispalindrome(string s) {     int n = s.length(), i = 0, j = n - 1;     while (i <= j) {       if (s[i] != s[j]) return false;       i++, j--;     }     return true;   }   inline bool isprime(long long n) {     if (n % 2 == 0) return false;     for (int i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   void solve() {     int n, k;     cin >> n >> k;     queue<int> q;     set<int> vals;     for (int i = 0; i < n; ++i) {       int id;       cin >> id;       if (!vals.count(id)) {         if (int(q.size()) >= k) {           int cur = q.front();           q.pop();           vals.erase(cur);         }         vals.insert(id);         q.push(id);       }     }     vector<int> res;     while (!q.empty()) {       res.push_back(q.front());       q.pop();     }     reverse(res.begin(), res.end());     cout << res.size() <<   n ;     for (auto it : res) cout << it <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     string a[2 * n], b[2 * m];     for (int i = 0; i < 2 * n; i += 2) {       cin >> a[i] >> a[i + 1];     }     for (int i = 0; i < 2 * m; i += 2) {       cin >> b[i] >> b[i + 1];     }     for (int i = 1; i < 2 * m; i += 2) {       for (int j = 1; j < 2 * n; j += 2) {         string x = b[i];         if ((x.erase(x.size() - 1)).compare(a[j]) == 0) {           cout << b[i - 1] <<     << b[i] <<   #  << a[j - 1];         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     double n;     cin >> t;     while (t--) {       cin >> n;       if (n * n - 4 * n < 0) {         cout <<  N  << endl;         continue;       }       if (n == 0) {         double x = 0, y = 0;         cout <<  Y   << fixed << setprecision(9) << x <<     << y << endl;         continue;       }       double x = n + sqrt(n * n - 4 * n);       x /= 2;       double y = x / (x - 1);       cout <<  Y   << fixed << setprecision(9) << x <<     << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   struct three_t {     int x, y, z;     inline three_t(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}   };   std::vector<int> next[100010];   std::vector<three_t> to[100010];   int n, q, t[100010], v[100010], spc[100010], clr[100010], tag[100010],       col[100010], tmp[100010];   void build(int x, int p, int count, int delta) {     if (spc[x]) {       if (p) to[p].emplace_back(x, count, delta);       count = delta = 0;       p = x;     } else {       count += !col[x];       delta += 1;     }     for (auto &y : next[x]) build(y, p, count, delta);   }   void setBlack(int x) {     if (!col[x]) return void(col[x] = 1);     tag[x]++;     for (auto &y : to[x]) {       if (y.y < tag[x]) {         setBlack(y.x);       }     }   }   void setWhite(int x) {     clr[x] = 1;     col[x] = 0;     tag[x] = 0;     for (auto &y : to[x]) {       y.y = y.z;       setWhite(y.x);     }   }   void restore(int x, int setWhite, int setBlack) {     if (spc[x]) {       setWhite |= clr[x];       setBlack = tag[x];     } else {       col[x] = tmp[x] && !setWhite;       if (setBlack && !col[x]) col[x] = 1, --setBlack;     }     for (auto &y : next[x]) restore(y, setWhite, setBlack);   }   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     std::cout.tie(0);     std::cin >> n >> q;     for (int i = 2, x; i <= n; i++) std::cin >> x, next[x].push_back(i);     for (int i = 1; i <= q; i++) std::cin >> t[i] >> v[i];     for (int i = 1; i <= q; i += 480) {       memset(spc, 0, sizeof(spc));       memset(clr, 0, sizeof(clr));       memset(tag, 0, sizeof(tag));       memcpy(tmp, col, sizeof(tmp));       for (int i = 1; i <= n; i++) to[i].clear();       for (int j = 0; j < 480 && i + j <= q; j++) spc[v[i + j]] = 1;       build(1, 0, 0, 0);       for (int j = 0; j < 480 && i + j <= q; j++) {         if (t[i + j] == 1) {           setBlack(v[i + j]);         } else if (t[i + j] == 2) {           setWhite(v[i + j]);         } else {           std::cout << (col[v[i + j]] ?  black  :  white ) << std::endl;         }       }       restore(1, 0, 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void bktk(int i, char *s, int val, int &ans, vector<int> &cnt) {     if (!s[i]) {       ans += cnt[val];       return;     }     val *= 3;     if (s[i] ==  A ) {       bktk(i + 1, s, val, ans, cnt);       bktk(i + 1, s, val + 1, ans, cnt);     }     if (s[i] ==  a ) {       bktk(i + 1, s, val + 2, ans, cnt);     }     if (s[i] ==  O ) {       bktk(i + 1, s, val, ans, cnt);     }     if (s[i] ==  o ) {       bktk(i + 1, s, val + 1, ans, cnt);       bktk(i + 1, s, val + 2, ans, cnt);     }     if (s[i] ==  X ) {       bktk(i + 1, s, val, ans, cnt);       bktk(i + 1, s, val + 2, ans, cnt);     }     if (s[i] ==  x ) {       bktk(i + 1, s, val + 1, ans, cnt);     }   }   int main() {     int w, n, m;     scanf( %d %d %d , &w, &n, &m);     vector<int> f(1 << w, 0);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       f[x]++;     }     vector<int> b3(1 << w, 0);     for (int i = 0; i < (1 << w); i++) {       for (int k = w - 1; k >= 0; k--) {         b3[i] = b3[i] * 3 + ((i >> k) & 1);       }     }     vector<int> cnt(531441, 0);     for (int i = 0; i < (1 << w); i++) {       for (int j = 0; j < (1 << w); j++) {         cnt[b3[i] + b3[j]] += f[i] * f[j];       }     }     while (m--) {       char s[14];       scanf( %s , s);       int ans = 0;       bktk(0, s, 0, ans, cnt);       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, w, x, sum = 0, mmax = 0, us = 0;     cin >> n >> w;     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       sum += x;       us = min(us, sum);       mmax = max(mmax, sum);     }     if (us < 0)       us = -us;     else       us = 0;     printf( %d n , max(w - mmax - us + 1, 0));     return 0;   }


#include <bits/stdc++.h>   int MOD = 1000000007;   long long inf = 1e18;   using namespace std;   vector<int> A, B, C;   int as, bs, cs;   int a, b, c;   int k, n1, n2, n3, t1, t2, t3;   bool ok(int t) {     if (a == n1) return false;     int cntb = 0;     for (int i = bs; i < B.size(); i++) {       if (t + t1 < B[i] + t2) {         cntb++;       }     }     for (int i = as; i < A.size(); i++) {       if (t + t1 < A[i] + t1 + t2) {         cntb++;       }     }     if (cntb >= n2) return false;     int cntc = 0;     for (int i = cs; i < C.size(); i++) {       if (t + t1 + t2 < C[i] + t3) {         cntc++;       }     }     for (int i = bs; i < B.size(); i++) {       if (t + t1 + t2 < B[i] + t2 + t3) {         cntc++;       }     }     for (int i = as; i < A.size(); i++) {       if (t + t1 + t2 < A[i] + t1 + t2 + t3) {         cntc++;       }     }     if (cntc >= n3) return false;     return true;   }   int main() {     ios::sync_with_stdio(0);     cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;     int t, x;     bool cont;     for (t = 1; t <= 30000001; t++) {       if (k == 0 && c == 0 && b == 0 && a == 0) {         break;       }       cont = true;       while (c != 0 && cont) {         x = C[cs];         cont = false;         if (x + t3 == t) {           cs++;           c--;           cont = true;         }       }       cont = true;       while (b != 0 && cont) {         x = B[bs];         cont = false;         if (x + t2 == t) {           bs++;           b--;           cont = true;           C.push_back(t);           c++;         }       }       cont = true;       while (a != 0 && cont) {         x = A[as];         cont = false;         if (x + t1 == t) {           as++;           a--;           cont = true;           B.push_back(t);           b++;         }       }       cont = true;       while (k != 0 && cont) {         x = t;         cont = false;         if (ok(t)) {           A.push_back(x);           a++;           cont = true;           k--;         }       }     }     cout << t - 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = (int)5e5 + 5;   int n;   struct node {     int x, y;   } a[MAXN];   struct BIT {     long long sum[MAXN];     int n;     void init(int _n) {       n = _n;       memset(sum, 0, sizeof(sum));       ;     }     int lowbit(int x) { return x & -x; }     void update(int x, long long num) {       while (x <= n) {         sum[x] += num;         x += lowbit(x);       }       return;     }     long long query(int x) {       long long ans = 0;       while (x) {         ans += sum[x];         x -= lowbit(x);       }       return ans;     }   } bita;   vector<int> v;   int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }   map<int, int> mpx;   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++)         scanf( %d%d , &a[i].x, &a[i].y), v.push_back(a[i].x), v.push_back(a[i].y);       sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());       for (int i = 1; i <= n; i++) {         a[i].x = getid(a[i].x);         a[i].y = getid(a[i].y);       }       sort(a + 1, a + 1 + n, [](node a, node b) {         if (a.y != b.y) return a.y > b.y;         return a.x < b.x;       });       mpx.clear();       bita.init(MAXN);       long long ans = 0;       for (int i = 1; i <= n; i++) {         int xx = a[i].x, yy = a[i].y, pre = 0;         int now = i;         while (a[now].y == a[i].y && now <= n) {           if (!mpx[a[now].x]) {             mpx[a[now].x] = 1;             bita.update(a[now].x, 1ll);           }           now++;         }         now--;         for (int j = i; j <= now; j++) {           long long l = bita.query(a[j].x - 1) - bita.query(pre);           long long r = bita.query(2 * n + 1) - bita.query(a[j].x);           pre = a[j].x;           ans += (long long)l * r + l + r + 1;         }         i = now;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     scanf( %d%d , &a, &b);     if (b > a) {       printf( -1 n );     } else if (a == b) {       printf( %d.000000000 n , a);     } else {       int k((a - b) / b);       if (k & 1) {         k--;       }       double ans1(1. * (a - b) / k);       k = (a + b) / b;       if (k & 1) {         k--;       }       double ans2(1. * (a + b) / k);       printf( %.9f n , min(ans1, ans2));     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, k, i, j, a[200002], sum = 0;     vector<long long int> v;     set<pair<long long int, long long int>> s;     cin >> n >> m >> k;     for (i = 0; i < n; i++) {       cin >> a[i];       s.insert(make_pair(a[i], i));     }     set<pair<long long int, long long int>>::iterator it1, it2;     it1 = s.begin();     it2 = s.end();     for (i = 0; i < m * k; i++) {       it2--;     }     s.erase(it1, it2);     for (i = 0; i < n; i++) {       if (s.find(make_pair(a[i], i)) != s.end()) {         sum += a[i];       }     }     long long int cnt = 0;     for (i = 0; i < n; i++) {       auto it = s.find(make_pair(a[i], i));       if (cnt == m * (k - 1)) {         break;       }       if (it != s.end()) {         cnt++;         if (cnt % m == 0) {           v.push_back(it->second + 1);         }       }     }     long long int sz = v.size();     cout << sum << endl;     for (i = 0; i < sz; i++) {       cout << v[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char zf = 1;     char ch = getchar();     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   void write(long long y) {     if (y < 0) putchar( - ), y = -y;     if (y > 9) write(y / 10);     putchar(y % 10 + 48);   }   void writeln(const long long y) {     write(y);     putchar(  n );   }   int i, j, k, m, n, x, y, z, cnt, dx[10010], dy[10010];   struct now {     int t, x, y, p;   } q[1000010];   int h, t;   long long dis[105][12][12][3];   bool vis[105][12][12][3];   void push(now x, long long ds) {     if (x.x == dx[x.t] && x.y == dy[x.t]) x.t++;     if (ds >= dis[x.t][x.x][x.y][x.p]) return;     dis[x.t][x.x][x.y][x.p] = ds;     if (!vis[x.t][x.x][x.y][x.p])       q[++t] = {x.t, x.x, x.y, x.p}, vis[x.t][x.x][x.y][x.p] = 1;   }   int main() {     n = read();     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= n; j++) {         x = read();         dx[x] = i;         dy[x] = j;       }     memset(dis, 10, sizeof(dis));     long long ans = 1000000000000ll;     for (register int i = 0; i <= 2; i++)       dis[2][dx[1]][dy[1]][i] = 0, vis[2][dx[1]][dy[1]][i] = 1;     t = 3;     q[1] = {2, dx[1], dy[1], 0};     q[2] = {2, dx[1], dy[1], 1};     q[3] = {2, dx[1], dy[1], 2};     while (h < t) {       now u = q[++h];       vis[u.t][u.x][u.y][u.p] = 0;       long long ds = dis[u.t][u.x][u.y][u.p];       if (u.t > n * n) {         ans = min(ans, ds);         continue;       }       long long b1 = ds + 1000000;       if (u.p == 0) {         for (register int i = 1; i <= n; i++) {           push({u.t, i, u.y, u.p}, b1);           push({u.t, u.x, i, u.p}, b1);         }       }       if (u.p == 1) {         for (register int i = -2; i <= 2; i++)           for (register int j = -2; j <= 2; j++)             if (i * j == 2 || i * j == -2) {               int xx = u.x + i, yy = u.y + j;               if (xx < 1 || xx > n || yy < 1 || yy > n) continue;               push({u.t, xx, yy, u.p}, b1);             }       }       if (u.p == 2) {         for (register int i = -n; i <= n; i++)           for (register int j = -1; j <= 1; j += 2) {             int xx = u.x + i, yy = u.y + i * j;             if (xx < 1 || xx > n || yy < 1 || yy > n) continue;             push({u.t, xx, yy, u.p}, b1);           }       }       for (register int i = 0; i <= 2; i++) push({u.t, u.x, u.y, i}, b1 + 1);     }     cout << ans / 1000000 <<     << ans % 1000000;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x0, y0, x, y;     cin >> x0 >> y0 >> x >> y;     if (x0 != x && y != y0 && abs(x - x0) != abs(y - y0)) {       cout <<  -1  << endl;       return 0;     }     int dx = abs(y - y0);     int dy = abs(x0 - x);     if (x0 == x)       cout << x0 + dx <<     << y0 <<     << x + dx <<     << y << endl;     else if (y0 == y)       cout << x0 <<     << y0 + dy <<     << x <<     << y + dy << endl;     else       cout << x0 <<     << y <<     << x <<     << y0 << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, d, i, j, k = 0, h, c, p1, p2, q1, q2, A, B, c1, c2, l, m = 0,                              n, t = 1, q = 0, r, e, x = 0, y = 0, o, s, mx1,                              mx2 = 0, mx = 0, p = 0, v, mn = 0, z, w;     string s1, s2, s3, s4;     cin >> n;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     x = arr[0];     t = n / 2;     i = 1;     while (t--) {       cout << arr[i] <<     << x << endl;       i++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int nvertices, nedges;   vector<vector<pair<int, int>>> adjList(110);   vector<bool> visited;   void dfs(int u, int c) {     visited[u] = true;     for (auto e : adjList[u]) {       if (!visited[e.first] && (e.second == c)) {         dfs(e.first, c);       }     }   }   int main() {     cin >> nvertices >> nedges;     for (int i = 0; i < nedges; i++) {       int u, v, c;       cin >> u >> v >> c;       adjList[u].push_back({v, c});       adjList[v].push_back({u, c});     }     int m;     cin >> m;     while (m--) {       int u, v;       cin >> u >> v;       set<int> ans;       for (auto e : adjList[u]) {         visited.assign(110, false);         visited[u] = true;         dfs(e.first, e.second);         if (visited[v] == true) ans.insert(e.second);       }       cout << ans.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int readint() {     char c;     while (c = getchar(), (c <  0  || c >  9 ) && c !=  - )       ;     bool flag = (c ==  - );     if (flag) c = getchar();     int x = 0;     while (c >=  0  && c <=  9 ) {       x = x * 10 + c - 48;       c = getchar();     }     return flag ? -x : x;   }   char readchar() {     char c;     while (c = getchar(),            c !=  A  && c !=  C  && c !=  <  && c !=  >  && c !=  ^ )       ;     return c;   }   const int maxn = 100005;   const int maxm = 15;   const int block = 300;   int n, m, q, x, y;   pair<int, int> pos;   char t[maxn][maxm];   pair<int, int> nxt[maxn][maxm], go[maxn][maxm];   inline bool on(pair<int, int> pos) {     return pos.first >= 1 && pos.first <= n && pos.second >= 1 && pos.second <= m;   }   void calc(int x, int y) {     if (!on(make_pair(x, y))) {       nxt[x][y] = make_pair(x, y);       return;     }     if (nxt[x][y].first != -2) return;     if (t[x][y] ==  < ) {       if (t[x][y - 1] ==  > )         nxt[x][y] = make_pair(-1, -1);       else         calc(x, y - 1), nxt[x][y] = nxt[x][y - 1];     } else if (t[x][y] ==  > ) {       if (t[x][y + 1] ==  < )         nxt[x][y] = make_pair(-1, -1);       else         calc(x, y + 1), nxt[x][y] = nxt[x][y + 1];     } else       nxt[x][y] = make_pair(x - 1, y);   }   void jump(int start, int finish) {     for (int i = start; i <= finish && i <= n; i++) {       if (i % block == 1) {         for (int j = 1; j <= m; j++) go[i][j] = nxt[i][j];       } else {         for (int j = 1; j <= m; j++) {           if (!on(nxt[i][j]))             go[i][j] = nxt[i][j];           else             go[i][j] = go[nxt[i][j].first][nxt[i][j].second];         }       }     }   }   int main() {     n = readint();     m = readint();     q = readint();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         t[i][j] = readchar(), nxt[i][j] = make_pair(-2, -2);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) calc(i, j);     jump(1, n);     while (q--) {       char type = readchar();       if (type ==  A ) {         pos.first = readint();         pos.second = readint();         while (on(pos)) {           pos = go[pos.first][pos.second];         }         printf( %d %d n , pos.first, pos.second);       } else {         x = readint();         y = readint();         char op = readchar();         t[x][y] = op;         for (int j = 1; j <= m; j++) nxt[x][j] = make_pair(-2, -2);         for (int j = 1; j <= m; j++) calc(x, j);         jump(x, x);         jump(x + 1, (x / block + (x % block == 0 ? 0 : 1)) * block);       }     }     return 0;   }


#include <bits/stdc++.h>   using std::cerr;   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::fixed;   using std::ios_base;   using std::list;   using std::make_pair;   using std::make_tuple;   using std::map;   using std::nth_element;   using std::pair;   using std::queue;   using std::reverse;   using std::set;   using std::sort;   using std::stack;   using std::string;   using std::tuple;   using std::unordered_map;   using std::unordered_set;   using std::vector;   const int MAXN = 100000;   const int INF = 1e9;   const int MOD = 1e9 + 7;   const int64_t L_INF = 4e18;   int n;   vector<int64_t> numbers[64];   list<int64_t> ans;   int get_top(int64_t num) {     for (int i = 62; i >= 0; i--) {       if (num & (1ll << i)) {         return i;       }     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     cin >> n;     for (int i = 0; i < n; i++) {       int64_t b;       cin >> b;       numbers[get_top(b)].push_back(b);     }     for (int i = 62; i >= 0; i--) {       if (numbers[i].empty()) {         continue;       }       if (numbers[i].size() > ans.size() + 1) {         cout <<  No n ;         exit(0);       }       auto iter = ans.begin();       iter = ans.insert(iter, numbers[i][0]);       iter++;       int j = 1;       int64_t sum = numbers[i][0];       while (j < (int)numbers[i].size() && iter != ans.end()) {         sum ^= *iter;         iter++;         if ((sum ^ numbers[i][j]) > sum) {           iter = ans.insert(iter, numbers[i][j]);           sum ^= *iter;           iter++;           j++;         }       }       if (j != (int)numbers[i].size()) {         cout <<  No n ;         exit(0);       }     }     cout <<  Yes n ;     for (int64_t b : ans) {       cout << b <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[101][101];   long long b[101];   int main() {     int m, n;     cin >> m >> n;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < m; i++) {       long long minn = 100000000000000;       for (int j = 0; j < n; j++) {         if (a[i][j] < minn) minn = a[i][j];       }       b[i] = minn;     }     long long maxx = 0;     for (int i = 0; i < m; i++) {       if (b[i] > maxx) maxx = b[i];     }     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d , &(n));     scanf( %d , &(k));     int A[101];     for (int(i) = 0; (i) < (n); (i)++) {       scanf( %d , &(A[i]));     }     int x, y, ans = 0;     for (int(i) = 0; (i) < (k); (i)++) {       x = 0;       y = 0;       for (int(j) = 0; (j) < (n / k); (j)++) {         if (A[j * k + i] == 2)           y++;         else           x++;       }       ans += min(x, y);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int MAX_VAL = 1000000;   struct AInt {     int sum;     int minSum;   };   AInt aInt[1 << 21];   void update(int index, int left, int right, int addIndex, int addValue) {     if (left == right) {       aInt[index].sum += addValue;       aInt[index].minSum += addValue;     } else {       int avg = (left + right) / 2;       if (addIndex <= avg) {         update(2 * index + 0, left, avg, addIndex, addValue);       } else {         update(2 * index + 1, avg + 1, right, addIndex, addValue);       }       aInt[index].sum = aInt[2 * index].sum + aInt[2 * index + 1].sum;       aInt[index].minSum =           std::min(aInt[2 * index].minSum + aInt[2 * index + 1].sum,                    aInt[2 * index + 1].minSum);     }   }   int query(int index, int suffSum, int left, int right) {     if (aInt[index].minSum + suffSum >= 0) {       return -1;     } else if (left == right) {       return left;     } else {       int avg = (left + right) / 2;       int q2 = query(2 * index + 1, suffSum, avg + 1, right);       if (q2 == -1) {         int q1 =             query(2 * index + 0, aInt[2 * index + 1].sum + suffSum, left, avg);         return q1;       } else {         return q2;       }     }   }   void update(int value, int sign) { update(1, 1, MAX_VAL, value, sign); }   int query() { return query(1, 0, 1, MAX_VAL); }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int a[n];     int b[m];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       update(a[i], -1);     }     for (int i = 0; i < m; i++) {       scanf( %d , &b[i]);       update(b[i], +1);     }     int q;     scanf( %d , &q);     for (int z = 0; z < q; z++) {       int t, i, x;       scanf( %d%d%d , &t, &i, &x);       i--;       if (t == 1) {         update(a[i], +1);         a[i] = x;         update(a[i], -1);       } else {         update(b[i], -1);         b[i] = x;         update(b[i], +1);       }       printf( %d n , query());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long findGCD(long long a, long long b) {     return ((b == 0) ? a : findGCD(b, a % b));   }   map<long long, long long> width;   long long wit = 0;   vector<pair<long long, long long> > rect[200005];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = (1); i <= (n); i += (1)) {       long long w, h, f;       scanf( %lld %lld %lld , &h, &w, &f);       if (width.find(w) == width.end()) {         width[w] = ++wit;       }       rect[width[w]].push_back({h, f});     }     sort(rect[1].begin(), rect[1].end());     for (long long i = (2); i <= (wit); i += (1)) {       if (rect[i - 1].size() != rect[i].size()) {         printf( 0 n );         return 0;       }       sort(rect[i].begin(), rect[i].end());       for (long long j = (0); j <= ((long long)rect[i].size() - 1); j += (1)) {         if (rect[i - 1][j].first != rect[i][j].first) {           printf( 0 n );           return 0;         }       }       long long gcd = findGCD(rect[i - 1][0].second, rect[i][0].second);       long long n = rect[i - 1][0].second / gcd, dn = rect[i][0].second / gcd;       for (long long j = (1); j <= ((long long)rect[i].size() - 1); j += (1)) {         gcd = findGCD(rect[i - 1][j].second, rect[i][j].second);         if (rect[i - 1][j].second / gcd != n || rect[i][j].second / dn != gcd) {           printf( 0 n );           return 0;         }       }     }     long long tgcd = -1;     for (long long j = (0); j <= ((long long)rect[1].size() - 1); j += (1)) {       long long gcd = rect[1][j].second;       for (long long i = (2); i <= (wit); i += (1)) {         gcd = findGCD(gcd, rect[i][j].second);       }       if (tgcd == -1)         tgcd = gcd;       else         tgcd = findGCD(tgcd, gcd);     }     long long ans = 0;     for (long long i = (1); i <= (sqrt(tgcd)); i += (1)) {       if (tgcd % i == 0) {         if (tgcd == i * i)           ans++;         else           ans += 2;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 11;   const int MAXN = 5e7 + 1;   const int BITMAX = 18;   const int INF = 2e9 + 88;   const long long LLINF = 1e17 + 3;   const int MOD = 1e9 + 7;   const long double Pi = acos(-1);   int a[MAX];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     if (n == 1) return puts( 0 ), 0;     sort(a + 1, a + n + 1);     long long res = 0;     int mx = 0;     for (int i = 1; i < n; ++i) {       res += a[i] - 1;       if (a[i] > mx) mx++;     }     if (a[n] > mx)       res += mx;     else       res += a[n] - 1;     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init() {     cin.tie(0);     cin.sync_with_stdio(0);   }   int main() {     init();     int n, z;     cin >> n >> z;     for (int i = 0; i < z; i++) {       (n % 10 == 0) ? n /= 10 : n -= 1;     }     cout << n << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   const int mod = 998244353;   char str[N];   char s[2][N];   int nxt[2][N];   int extend[2][N];   void get_nxt(char *s, int *nxt) {     int n = strlen(s), r = 0, pos = 1;     nxt[0] = n;     while (r + 1 < n && s[r] == s[r + 1]) ++r;     nxt[1] = r;     for (int i = 2; i < n; ++i) {       nxt[i] = max(0, min(nxt[i - pos], r - i + 1));       while (i + nxt[i] < n && s[i + nxt[i]] == s[nxt[i]]) ++nxt[i];       if (i + nxt[i] - 1 > r) {         r = i + nxt[i] - 1;         pos = i;       }     }   }   void get_extend(char *s, char *t, int *nxt, int *extend) {     int n = strlen(s), m = strlen(t), pos = 0, r;     while (s[extend[0]] == t[extend[0]]) ++extend[0];     r = extend[0] - 1;     for (int i = 1; i < n; ++i) {       extend[i] = max(0, min(nxt[i - pos], r - i + 1));       while (i + extend[i] < n && extend[i] < m &&              s[i + extend[i]] == t[extend[i]])         ++extend[i];       if (i + extend[i] - 1 > r) {         r = i + extend[i] - 1;         pos = i;       }     }   }   int a[N << 2];   int tag[N << 2];   void pushdown(int x) {     a[(x << 1)] = (a[(x << 1)] + tag[x]) % mod;     tag[(x << 1)] = (tag[(x << 1)] + tag[x]) % mod;     a[(x << 1 | 1)] = (a[(x << 1 | 1)] + tag[x]) % mod;     tag[(x << 1 | 1)] = (tag[(x << 1 | 1)] + tag[x]) % mod;     tag[x] = 0;   }   void add(int x, int l, int r, int ll, int rr, int p) {     if (ll > rr) return;     if (l >= ll && r <= rr) {       a[x] = (a[x] + p) % mod;       tag[x] = (tag[x] + p) % mod;     } else {       if (tag[x]) pushdown(x);       if (((l + r) >> 1) >= ll) add((x << 1), l, ((l + r) >> 1), ll, rr, p);       if (((l + r) >> 1) < rr)         add((x << 1 | 1), ((l + r) >> 1) + 1, r, ll, rr, p);     }   }   int query(int x, int l, int r, int pos) {     if (pos == -1) return 1;     if (l == r)       return a[x];     else {       if (tag[x]) pushdown(x);       if (pos <= ((l + r) >> 1))         return query((x << 1), l, ((l + r) >> 1), pos);       else         return query((x << 1 | 1), ((l + r) >> 1) + 1, r, pos);     }   }   int sum[N];   int now;   int main() {     scanf( %s %s %s , str, s[0], s[1]);     int len = strlen(str);     int lenl = strlen(s[0]);     int lenr = strlen(s[1]);     int f = (lenl == 1 && s[0][0] ==  0 );     get_nxt(s[0], nxt[0]);     get_nxt(s[1], nxt[1]);     get_extend(str, s[0], nxt[0], extend[0]);     get_extend(str, s[1], nxt[1], extend[1]);     int now = 1;     sum[0] = mod - 1;     for (int i = 0; i < len; ++i) {       int l, r;       if (str[i] ==  0 ) {         if (f)           l = r = i;         else {           now = (now + sum[i]) % mod;           continue;         }       } else {         l = i + lenl - 1;         if (extend[0][i] != lenl && s[0][extend[0][i]] > str[i + extend[0][i]])           ++l;         r = i + lenr - 1;         if (extend[1][i] != lenr && (s[1][extend[1][i]] < str[i + extend[1][i]]))           --r;       }       sum[l] = (sum[l] + now) % mod;       sum[r + 1] = (sum[r + 1] - now + mod) % mod;       now = (now + sum[i]) % mod;     }     printf( %d n , now);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t;   std::vector<pair<long long, long long> > v;   long long dp[(1 << 15) + 5][226][4];   long long solve(long long x, long long y, long long z) {     if (x == 0) return 1;     if (x < 0) return 0;     if (dp[y][x][z] != -1) return dp[y][x][z];     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (v[i].second != z and (y & (1 << i))) {         ans = (ans +                (solve(x - v[i].first, y - (1 << i), v[i].second)) % 1000000007) %               1000000007;       }     }     dp[y][x][z] = ans;     return dp[y][x][z] % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     long long t1, t2;     for (long long i = 0; i < (1 << 15) + 5; i++)       for (long long j = 0; j < 226; j++)         for (long long k = 0; k < 4; k++) dp[i][j][k] = -1;     for (long long i = 0; i < n; i++) {       cin >> t1 >> t2;       v.push_back(make_pair(t1, t2));     }     cout << solve(t, (1 << n) - 1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, pair<int, int> > p;   int res[100 + 10][100 + 10];   int main() {     int n, m, q, k, d, t, tem1, tem2, tem3, tem4, y = 1, sum = 0, ans = 0;     string s, c;     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         p[{i, j}] = {i, j};       }     }     for (int i = 0; i < q; i++) {       scanf( %d%d , &tem1, &tem2);       tem2--;       if (tem1 != 3) {         if (tem1 == 1) {           pair<int, int> here = p[{tem2, 0}];           for (int j = 0; j < m - 1; j++) {             p[{tem2, j}] = p[{tem2, j + 1}];           }           p[{tem2, m - 1}] = here;         } else {           pair<int, int> here = p[{0, tem2}];           for (int j = 0; j < n - 1; j++) {             p[{j, tem2}] = p[{j + 1, tem2}];           }           p[{n - 1, tem2}] = here;         }       } else {         scanf( %d%d , &tem3, &tem4);         tem3--;         pair<int, int> here = p[{tem2, tem3}];         res[here.first][here.second] = tem4;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         printf( %d  , res[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct square {     int r1, c1, r2, c2;     square(int R1, int C1, int R2, int C2) {       r1 = R1;       c1 = C1;       r2 = R2;       c2 = C2;     }     bool same(int R1, int C1, int R2, int C2) {       if (R1 != r1) return false;       if (C1 != c1) return false;       if (R2 != r2) return false;       if (C2 != c2) return false;       return true;     }     bool in(int x, int y) {       if (r1 <= x && x <= r2 && c1 <= y && y <= c2) return true;       return false;     }   };   vector<square *> S;   int main(void) {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     while (q--) {       int op;       scanf( %d , &op);       int r1, c1, r2, c2;       scanf( %d %d %d %d , &r1, &c1, &r2, &c2);       if (op == 1) {         square *s = new square(r1, c1, r2, c2);         S.push_back(s);       } else if (op == 2) {         int size = S.size();         for (int i = 0; i < size; i++) {           square *s = S[i];           if (s->same(r1, c1, r2, c2)) {             S.erase(S.begin() + i);             break;           }         }       } else if (op == 3) {         bool find = false;         for (square *s : S)           if (s->in(r1, c1) != s->in(r2, c2)) {             printf( No n );             find = true;             break;           }         if (!find) printf( Yes n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 333333;   int ans[maxn];   int fa[maxn];   int nx[maxn];   int visit[maxn];   int n, m;   inline int query(int a) { return a == fa[a] ? a : fa[a] = query(fa[a]); }   inline void conbine(int a, int b) {     a = query(a), b = query(b);     if (a != b) fa[a] = b;   }   inline void paint(int l, int r, int x) {     int i = l;     while (i <= r) {       int a = query(i);       int j = nx[a];       if (j > r) return;       if (ans[j] == 0) ans[j] = x;       int b = query(j + 1);       int _nx = nx[b];       conbine(a, b);       nx[query(a)] = _nx;       i = _nx;     }   }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i <= n + 1; ++i) fa[i] = nx[i] = i, ans[i] = 0;       for (int i = 0; i < m; ++i) {         int l, r, x;         scanf( %d%d%d , &l, &r, &x);         paint(l, x - 1, x);         paint(x + 1, r, x);       }       for (int i = 1; i <= n; ++i) {         int tmp = ans[i];         printf( %d , tmp);         if (i == n)           printf(  n );         else           printf(   );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   const long long INF = 2e18;   template <typename T, typename T1>   void amax(T &a, T1 b) {     if (b > a) a = b;   }   template <typename T, typename T1>   void amin(T &a, T1 b) {     if (b < a) a = b;   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long modinv(long long a, long long m) { return power(a, m - 2, m); }   int TLE_TERROR() {     long long n, ans = 0;     cin >> n;     long long a[n], c[n + 1];     memset(c, 0, sizeof(c));     for (long long i = 0; i < n; i++) {       cin >> a[i];       ans ^= a[i];     }     for (long long i = 2; i <= n; i++) {       long long z = n / i;       c[i - 1] += z;       z *= i;       long long zz = n - z;       c[zz]++;     }     for (long long i = n - 1; i >= 0; i--) c[i] += c[i + 1];     for (long long i = 1; i <= n; i++) {       if (c[i] % 2 != 0) ans ^= i;     }     cout << ans;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int TESTS = 1;     while (TESTS--) TLE_TERROR();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   int s, p, i, j, k, z;   string s1, s2;   int const md = 1000000;   stack<char> st;   int a[5];   int main() {     int k1 = 0, k2 = 0, k3 = 0;     cin >> k1 >> k2;     for (i = 1; i <= k1; i++) {       cin >> k3;       n = n * k2 + k3;     }     cin >> k1 >> k2;     for (i = 1; i <= k1; i++) {       cin >> k3;       m = m * k2 + k3;     }     if (n > m)       cout <<  > ;     else if (n < m)       cout <<  < ;     else       cout <<  = ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   inline long long read() {     long long k = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       k = k * 10 + ch -  0 ;       ch = getchar();     }     return k * f;   }   long long n, h, w, minx = 0, maxx = 0, miny = 0, maxy = 0, ans;   long long a[500010], b[500010];   char s[500010];   inline void shuchu() {     printf( %lld , ans);     exit(0);   }   signed main() {     n = read();     h = read();     w = read();     scanf( %s , s + 1);     long long cnt = 0, x = 0, y = 0, cc = 0;     for (long long i = 1; i <= n; i++) {       cnt++;       if (s[i] ==  U ) x--;       if (s[i] ==  D ) x++;       if (s[i] ==  L ) y--;       if (s[i] ==  R ) y++;       if (x < minx) minx = x, ans = (ans + cnt * w) % MOD, h--;       if (x > maxx) maxx = x, ans = (ans + cnt * w) % MOD, h--;       if (y < miny) miny = y, ans = (ans + cnt * h) % MOD, w--;       if (y > maxy) maxy = y, ans = (ans + cnt * h) % MOD, w--;       if (h == 0 || w == 0) shuchu();     }     if (x == 0 && y == 0) return puts( -1 ) & 0;     for (long long i = 1; i <= n; i++) {       cnt++;       if (s[i] ==  U ) x--;       if (s[i] ==  D ) x++;       if (s[i] ==  L ) y--;       if (s[i] ==  R ) y++;       if (x < minx)         minx = x, ans = (ans + cnt * w) % MOD, h--, a[++cc] = 1, b[cc] = cnt % n;       if (x > maxx)         maxx = x, ans = (ans + cnt * w) % MOD, h--, a[++cc] = 2, b[cc] = cnt % n;       if (y < miny)         miny = y, ans = (ans + cnt * h) % MOD, w--, a[++cc] = 3, b[cc] = cnt % n;       if (y > maxy)         maxy = y, ans = (ans + cnt * h) % MOD, w--, a[++cc] = 4, b[cc] = cnt % n;       if (h == 0 || w == 0) shuchu();       if (cc && b[cc] == 0) b[cc] = n;     }     long long p = 2, i = 1;     while (h != 0 && w != 0) {       if (a[i] == 1 || a[i] == 2)         ans = (ans + (p * n % MOD + b[i]) * w) % MOD, h--;       if (a[i] == 3 || a[i] == 4)         ans = (ans + (p * n % MOD + b[i]) * h) % MOD, w--;       if (i == cc)         i = 1, p++;       else         i++;     }     shuchu();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 1e4 + 20;   vector<int> adj[MN], topo;   vector<pair<int, int>> edge;   int scc, st, s[MN], h[MN], t[MN];   bool os[MN];   stack<int> ms;   int n, m;   void add(int u, int v) {     adj[u + m].push_back(v);     adj[v + m].push_back(u);     adj[u].push_back(v + m);     adj[v].push_back(u + m);   }   void dfs(int v) {     os[v] = 1;     s[v] = h[v] = ++st;     ms.push(v);     for (int i : adj[v]) {       if (!s[i]) dfs(i);       if (os[i]) h[v] = min(h[v], h[i]);     }     if (h[v] == s[v]) {       for (int i = ms.top();; i = ms.top()) {         ms.pop();         os[i] = 0;         h[i] = h[v];         t[i] = topo.size();         if (i == v) break;       }       scc++;       topo.push_back(h[v]);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       if (v > u) swap(u, v);       for (int j = 0; j < i; j++) {         if (u == edge[j].first || u == edge[j].second || v == edge[j].first ||             v == edge[j].second)           continue;         if ((u < edge[j].first && u > edge[j].second) ^             (v < edge[j].first && v > edge[j].second))           add(i, j);       }       edge.push_back({u, v});     }     for (int i = 0; i < 2 * m; i++)       if (!s[i]) dfs(i);     reverse(topo.begin(), topo.end());     for (int i = 0; i < m; i++) {       if (h[i] == h[i + m]) return cout <<  Impossible , 0;     }     for (int i = 0; i < m; i++) {       t[i] < t[i + m] ? cout <<  i  : cout <<  o ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v, cap, cost, next;   } edge[555 * 1111];   int head[555];   int NV, NE, vs, vt;   void addEdge(int u, int v, int cap, int cost) {     edge[NE].u = u;     edge[NE].v = v;     edge[NE].cap = cap;     edge[NE].cost = cost;     edge[NE].next = head[u];     head[u] = NE++;     edge[NE].u = v;     edge[NE].v = u;     edge[NE].cap = 0;     edge[NE].cost = -cost;     edge[NE].next = head[v];     head[v] = NE++;   }   bool vis[555];   int d[555], pre[555];   bool SPFA() {     for (int i = 0; i < NV; ++i) {       vis[i] = 0;       d[i] = (1 << 30);     }     vis[vs] = 1;     d[vs] = 0;     queue<int> que;     que.push(vs);     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = head[u]; i != -1; i = edge[i].next) {         int v = edge[i].v;         if (edge[i].cap && d[v] > d[u] + edge[i].cost) {           d[v] = d[u] + edge[i].cost;           pre[v] = i;           if (!vis[v]) {             vis[v] = 1;             que.push(v);           }         }       }       vis[u] = 0;     }     return d[vt] != (1 << 30);   }   int MCMF() {     int res = 0;     while (SPFA()) {       int flow = (1 << 30), cost = 0;       for (int u = vt; u != vs; u = edge[pre[u]].u) {         flow = min(flow, edge[pre[u]].cap);       }       for (int u = vt; u != vs; u = edge[pre[u]].u) {         edge[pre[u]].cap -= flow;         edge[pre[u] ^ 1].cap += flow;         cost += flow * edge[pre[u]].cost;       }       res += cost;     }     return res;   }   int tn, ch[55500][26], fail[55500];   vector<int> vec[55500];   void insert(char *s, int k) {     int x = 0;     for (int i = 0; s[i]; ++i) {       int y = s[i] -  a ;       if (ch[x][y] == 0) ch[x][y] = ++tn;       x = ch[x][y];     }     vec[x].push_back(k);   }   void getfail() {     queue<int> que;     for (int i = 0; i < 26; ++i) {       if (ch[0][i]) que.push(ch[0][i]);     }     while (!que.empty()) {       int x = que.front();       que.pop();       for (int i = 0; i < 26; ++i) {         if (ch[x][i]) {           fail[ch[x][i]] = ch[fail[x]][i];           que.push(ch[x][i]);         } else           ch[x][i] = ch[fail[x]][i];       }     }   }   int val[111], len[111];   void ac(char *s) {     int x = 0;     for (int i = 0; s[i]; ++i) {       int y = s[i] -  a ;       x = ch[x][y];       for (int tmp = x; tmp; tmp = fail[tmp]) {         for (int j = 0; j < vec[tmp].size(); ++j) {           int k = vec[tmp][j];           addEdge(i - len[k] + 1, i + 1, 1, -val[k]);         }       }     }   }   char S[555], T[555];   int main() {     int n, m, x;     scanf( %d%s%d , &n, S, &m);     for (int i = 1; i <= m; ++i) {       scanf( %s%d , T, val + i);       len[i] = strlen(T);       insert(T, i);     }     scanf( %d , &x);     vs = n + 1;     vt = vs + 1;     NV = vt + 1;     NE = 0;     memset(head, -1, sizeof(head));     addEdge(vs, 0, x, 0);     addEdge(n, vt, x, 0);     for (int i = 1; i <= n; ++i) {       addEdge(i - 1, i, (1 << 30), 0);     }     getfail();     ac(S);     printf( %d , -MCMF());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x;   int f(int a, int b) { return (a * b + 1) / 2; }   bool ok(int n) {     if (x == 3 && n == 3) return false;     if (n % 2 == 0 && x % 4) return false;     if (n % 2 == 0) {       if (x / 4 <= f(n / 2 - 1, n / 2 - 1)) return true;       return false;     }     int z = f(n, n);     if (x > z) return false;     return true;   }   int main() {     cin >> x;     for (int i = (int)(1), _n = (int)(100000); i < _n; i++)       if (ok(i)) {         cout << i << endl;         break;       }     {       int _;       cin >> _;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   inline int get_power(int a, int n) {     int res = 1;     while (n > 0) {       res = n & 1 ? 1ll * res * a % mod : res;       a = 1ll * a * a % mod;       n >>= 1;     }     return res;   }   inline int get_inv(int x) { return get_power(x, mod - 2); }   inline int C2(int x) { return (x * (x - 1ll) >> 1) % mod; }   const int max_n = 2e3 + 5;   int power_p[max_n], power_q[max_n];   int f[max_n], g[max_n], h[max_n][max_n];   int main() {     int n, a, b;     scanf( %d%d%d , &n, &a, &b);     int p = 1ll * a * get_inv(b) % mod;     power_p[0] = power_q[0] = 1;     for (int i = 1; i <= n; ++i) {       power_p[i] = 1ll * power_p[i - 1] * p % mod;       power_q[i] = power_q[i - 1] * (mod + 1ll - p) % mod;     }     h[1][0] = h[1][1] = 1;     for (int i = 2; i <= n; ++i)       for (int j = 0; j <= i; ++j)         h[i][j] = (1ll * h[i - 1][j] * power_p[j] +                    (j > 0 ? 1ll * h[i - 1][j - 1] * power_q[i - j] : 0)) %                   mod;     for (int i = 1; i <= n; ++i) {       g[i] = 1;       for (int j = 1; j <= i - 1; ++j) {         g[i] -= 1ll * g[j] * h[i][j] % mod;         g[i] += g[i] < 0 ? mod : 0;       }     }     for (int i = 1; i <= n; ++i) {       f[i] = 1ll * g[i] * h[i][i] % mod * C2(i) % mod;       for (int j = 1; j <= i - 1; ++j)         f[i] = (f[i] + 1ll * g[j] * h[i][j] % mod *                            (1ll * f[j] + f[i - j] + C2(i) - C2(i - j) + mod)) %                mod;       f[i] = 1ll * f[i] * get_inv(mod + 1 - 1ll * g[i] * h[i][i] % mod) % mod;     }     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<char> > table(n + 1, vector<char>(m + 1));     int row = 0, col = 0, count = 0;     for (int i = 1; i <= n; i++) {       string tmp;       cin >> tmp;       for (int j = 0; j < tmp.length(); j++) {         table[i][j + 1] = tmp[j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (table[i][j] ==  B ) {           count++;           row += i;           col += j;         }       }     }     row /= count;     col /= count;     cout << row <<     << col << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     if (a < b) {       swap(a, b);     }     T t;     while (b > 0) {       t = a % b;       a = b;       b = t;     }     return a;   }   template <class T>   T gcdL(vector<T>& v) {     int l = v.size();     if (l == 1) return v[0];     T g = gcd(v[0], v[1]);     for (int i = 2; i < l; i++) {       g = gcd(g, v[i]);     }     return g;   }   long long foo(long long x) {     while (x % 2 == 0) x /= 2;     while (x % 3 == 0) x /= 3;     return x;   }   bool ok(vector<long long>& v) {     for (int i = 0; i < (int)v.size(); i++) {       v[i] = foo(v[i]);     }     for (int i = 0; i < (int)v.size(); i++) {       if (v[i] == 1)         continue;       else         return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << setprecision(10);     long long n, x;     vector<long long> v;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     long long g = gcdL(v);     for (int i = 0; i < n; i++) {       v[i] /= g;     }     if (ok(v))       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, input = 0, temp = 0, sum = 0, c = 0;     cin >> n;     for (int i = 0; i < 2 * n; i++) {       cin >> temp;     }     if (sum % 2 == 0) {       cout <<  Karen ;     } else       cout <<  Koyomi ;   }


#include <bits/stdc++.h>   using namespace std;   int output(int n) {     int sum = 0;     while (n != 1) {       int i;       for (i = 2; i * i <= n; i++)         if (n % i == 0) {           sum += n;           n /= i;           break;         }       if (i * i > n) {         sum += n;         break;       }     }     return ++sum;   }   int main() {     int t;     t = 1;     while (t--) {       int n;       cin >> n;       cout << output(n) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   long long a, b, c, s;   long long gao(long long a, long long b, long long xl, long long xr) {     if (xl > xr) return 0;     if (a * xl + b < 0 && a * xr + b < 0) return 0;     double key = -b * 1.0 / a;     long long keyx;     if (a > 0) {       keyx = (key - EPS);       keyx++;     } else {       keyx = (key + EPS);     }     if (a * xl + b < 0) {       xl = keyx;     }     if (a * xr + b < 0) {       xr = keyx;     }     long long ans = b * (xr - xl + 1);     long long tmp = (xr + xl) * (xr - xl + 1) / 2;     ans += tmp * a;     return ans;   }   long long first_old(long long a, long long b, long long c) {     long long ans = 0;     long long i1, i2;     long long jl, jr;     long long tmp, oldAns;     for (long long x = 0; x <= s; x++) {       tmp = 0;       oldAns = ans;       long long keyi = min(a + x - b, s - x);       if (keyi < 0) continue;       i1 = a + x + 1 - b - c;       i2 = s - 2 * x - a + c;       i1 = min(keyi, i1);       i2 = min(keyi, i2);       if (i1 < 0 && i2 < 0) {         jl = 0;         jr = keyi;         ans += gao(-1, s - x + 1, jl, jr);       } else if (i1 < 0) {         jl = 0;         jr = i2;         ans += gao(0, a + x - c + 1, jl, jr);         jl = i2 + 1;         jr = keyi;         ans += gao(-1, s - x + 1, jl, jr);       } else if (i2 < 0) {         jl = 0;         jr = i1;         ans += gao(0, s - 2 * x - a - 1 + b + c + 1, jl, jr);         jl = i1 + 1;         jr = keyi;         ans += gao(-1, s - x + 1, jl, jr);       } else {         if (i1 == i2) {           jl = 0;           jr = i1;           ans += gao(1, b - 1 + 1, jl, jr);           jl = i1 + 1;           jr = keyi;           ans += gao(-1, s - x + 1, jl, jr);         } else if (i1 < i2) {           jl = 0;           jr = i1;           ans += gao(1, b - 1 + 1, jl, jr);           jl = i1 + 1;           jr = i2;           ans += gao(0, a + x - c + 1, jl, jr);           jl = i2 + 1;           jr = keyi;           ans += gao(-1, s - x + 1, jl, jr);         } else {           jl = 0;           jr = i2;           ans += gao(1, b - 1 + 1, jl, jr);           jl = i2 + 1;           jr = i1;           ans += gao(0, s - 2 * x - a - 1 + b + c + 1, jl, jr);           jl = i1 + 1;           jr = keyi;           ans += gao(-1, s - x + 1, jl, jr);         }       }     }     return ans;   }   long long first(long long a, long long b, long long c) {     long long ans = 0;     for (long long x = 0; x <= s; x++) {       if (b > a + x || c > a + x) continue;       long long tmp = (s - x + 2) * (s - x + 1) / 2;       if (s - x - (a + x + 1 - b) >= 0)         tmp -= (s - x - (a + x + 1 - b) + 2) * (s - x - (a + x + 1 - b) + 1) / 2;       if (s - x - (a + x + 1 - c) >= 0)         tmp -= (s - x - (a + x + 1 - c) + 2) * (s - x - (a + x + 1 - c) + 1) / 2;       if (s - x - (a + x + 1 - b) - (a + x + 1 - c) >= 0) {         tmp += (s - x - (a + x + 1 - b) - (a + x + 1 - c) + 2) *                (s - x - (a + x + 1 - b) - (a + x + 1 - c) + 1) / 2;       }       long long sum = a + x - b - c;       if (sum >= 0) {         sum = min(sum, s - x);         tmp -= (sum + 2) * (sum + 1) / 2;       }       ans += tmp;     }     return ans;   }   long long second(long long a, long long b, long long c) {     long long ans = 0;     for (long long i = max(a, b);; i++) {       if (i < c) continue;       long long t = i - a + i - b;       t = s - t;       if (t < 0) break;       if (c + t > i) {         ans += i - c + 1;       } else {         ans += t + 1;       }     }     return ans;   }   long long third(long long a, long long b, long long c) {     long long ans = 0;     long long t = max(a, b);     t = max(t, c);     for (long long i = t;; i++) {       long long used = 3 * i - a - b - c;       if (used > s) break;       ans++;     }     return ans;   }   void solve_old() {     long long ans = 0;     ans += first(a, b, c);     ans += first(b, a, c);     ans += first(c, a, b);     ans -= second(a, b, c);     ans -= second(b, c, a);     ans -= second(a, c, b);     ans += third(a, b, c);     printf( %I64d n , ans);   }   long long new_first(long long a, long long b, long long c) {     long long ans = 0;     for (long long x = 0; x <= s; x++) {       if (a + x - b - c < 0) continue;       long long tmp = min(a + x - b - c, s - x);       ans += (tmp + 2) * (tmp + 1) / 2;     }     return ans;   }   long long new_second(long long a, long long b, long long c) {     long long ans = 0;     for (long long x = max(a, b);; x++) {       if (x - a + x - b > s) break;       long long tmp = s - (x - a + x - b);       if (2 * x - c > 0) tmp -= (2 * x - c);       if (tmp >= 0) ans += tmp + 1;     }     return ans;   }   void solve() {     long long ans = (s + 3) * (s + 2) * (s + 1) / 6;     ans -= new_first(a, b, c);     ans -= new_first(b, a, c);     ans -= new_first(c, a, b);     printf( %I64d n , ans);   }   int main() {     while (scanf( %I64d%I64d%I64d%I64d , &a, &b, &c, &s) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long l, r;     int now;     vector<pair<int, int> > v;   } st[250005 * 4];   int pi, ri, n, N;   int p[250005], m[250005];   long long r, sp[250005];   pair<long long, int> d[250005];   queue<int> q;   vector<long long> rr;   bool vis[250005];   void init(int id, int l, int r) {     if (l == r) {       st[id].l = rr[l - 1] + 1;       st[id].r = rr[l];       int L = lower_bound(d + 2, d + n + 2, make_pair(rr[l - 1] + 1, 0)) - d;       int R = upper_bound(d + 2, d + n + 2, make_pair(rr[l], 1000000000)) - d;       for (int i = L; i < R; i++) {         st[id].v.push_back(make_pair(m[d[i].second], d[i].second));       }       sort(st[id].v.begin(), st[id].v.end());       return;     }     int mid = l + r >> 1;     init(id * 2, l, mid);     init(id * 2 + 1, mid + 1, r);     st[id].l = st[id * 2].l;     st[id].r = st[id * 2 + 1].r;     st[id].v.insert(st[id].v.begin(), st[id * 2].v.begin(), st[id * 2].v.end());     st[id].v.insert(st[id].v.end(), st[id * 2 + 1].v.begin(),                     st[id * 2 + 1].v.end());     sort(st[id].v.begin(), st[id].v.end());   }   void query(int id, int l, int r, long long L, long long R, int p) {     if (R < st[id].l || st[id].r < L) return;     if (L <= st[id].l && st[id].r <= R) {       int len = st[id].v.size();       while (st[id].now < len && st[id].v[st[id].now].first <= p) {         if (!vis[st[id].v[st[id].now].second])           q.push(st[id].v[st[id].now].second);         vis[st[id].v[st[id].now].second] = 1;         st[id].now++;       }       return;     }     int mid = l + r >> 1;     query(id * 2, l, mid, L, R, p);     query(id * 2 + 1, mid + 1, r, L, R, p);   }   int main() {     long long x, y, xi, yi;     scanf( %I64d%I64d%d%I64d%d , &xi, &yi, &p[1], &r, &n);     r *= r;     sp[1] = r;     rr.push_back(r);     for (int i = 2; i <= n + 1; i++) {       scanf( %I64d%I64d%d%d%I64d , &x, &y, &m[i], &p[i], &r);       x -= xi;       y -= yi;       d[i].first = x * x + y * y;       d[i].second = i;       r *= r;       sp[i] = r;       rr.push_back(r);     }     rr.push_back(0);     sort(rr.begin(), rr.end());     rr.resize(unique(rr.begin(), rr.end()) - rr.begin());     N = rr.size() - 1;     sort(d + 2, d + n + 2);     init(1, 1, N);     q.push(1);     while (!q.empty()) {       int now = q.front();       q.pop();       query(1, 1, N, 1, sp[now], p[now]);     }     int cnt = 0;     for (int i = 2; i <= n + 1; i++) {       if (vis[i]) {         cnt++;       }     }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     for (int i = 1; i < str.size() - 1; i++) {       if (str[i + 1] !=  .  && str[i - 1] !=  .  && str[i] !=  . ) {         if (str[i + 1] != str[i - 1] && str[i - 1] != str[i] &&             str[i + 1] != str[i]) {           cout <<  Yes  << endl;           return 0;         }       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100;   int mem[MAXN + 10];   int main() {     int N;     cin >> N;     mem[0] = 0, mem[1] = 1, mem[2] = 2, mem[3] = 4;     for (int i = 4; i <= N; ++i) {       mem[i] = i + mem[i - 2];     }     cout << mem[N] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long modexp(long long base, long long exp) {     if (exp == 1)       return base;     else if (exp == 0)       return 1;     else {       if (exp % 2 == 0) {         long long base1 = pow(modexp(base, exp / 2), 2);         if (base1 >= 1000000007)           return base1 % 1000000007;         else           return base1;       } else {         long long ans = (base * pow(modexp(base, (exp - 1) / 2), 2));         if (ans >= 1000000007)           return ans % 1000000007;         else           return ans;       }     }   }   long long gcd(long long a, long long b) {     if (!a) return b;     return gcd(b % a, a);   }   map<int, int> d;   set<int> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n; ++i) d[a[i]]++;     long long ans = 0;     for (long long i = 0; i < n; ++i) {       d[a[i]]--;       if (!d[a[i]]) {         d.erase(a[i]);       }       if (s.find(a[i]) == s.end()) {         ans += d.size();         s.insert(a[i]);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   bool valid;   int n, p[maxn], a[maxn], head, tail;   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &p[i]);         a[p[i]] = i;       }       head = a[1], tail = n;       valid = true;       for (int i = 1; i <= n; ++i) {         if (a[i] != a[i - 1] + 1 && a[i] != head) {           valid = false;           break;         }         if (a[i] == tail) {           tail = head - 1;           head = a[i + 1];         }       }       if (valid)         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N=2e5+10;   int a[N],tt;   int cnt[N];   int pre[N];   int main(){       int t;       scanf( %d ,&t);       while(t--){           int n;           tt=0;           scanf( %d ,&n);           for(int i=1;i<=n;i++) scanf( %d ,&a[i]);           sort(a+1,a+n+1);           for(int i=1;i<=n;i++){               if(a[i]==a[i-1]) cnt[tt]++;               else{                   tt++;                   cnt[tt]++;               }           }           priority_queue<int>s;           for(int i=1;i<=tt;i++) {               s.push(cnt[i]);               cnt[i]=0;           }           int sh=0;           int ans;           while(1){               if(s.size()==1) {                   ans = s.top();                   break;               }               if(s.empty()){                   ans=0;                   break;               }               int a=s.top();               s.pop();               int b=s.top();               s.pop();               a--;               b--;               if(a!=0)                   s.push(a);               if(b!=0)                   s.push(b);              }           printf( %d n ,ans);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     while (cin >> t) {       string a;       cin >> a;       int s = 0;       for (int i = 0; i < t - 1;) {         if (a.at(i) == a.at(i + 1)) {           if (a.at(i) ==  a )             a.at(i) =  b ;           else             a.at(i) =  a ;           s++;         }         i += 2;         if (i >= a.size()) break;       }       cout << s << endl << a << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<long long, short> > mass;     long n, k;     scanf( %li %li , &n, &k);     long long a, b;     for (long i = 0; i < n; i++) {       scanf( %I64d %I64d , &a, &b);       mass.push_back(make_pair(a, -1));       mass.push_back(make_pair(b, 1));     }     sort(mass.begin(), mass.end());     vector<pair<long long, long long> > ans(n);     long long x = 0, balance = 0;     for (long i = 0; i < n * 2; i++) {       if (mass[i].second == -1 && balance == k - 1) ans[x].first = mass[i].first;       if (balance == k && mass[i].second == 1) ans[x++].second = mass[i].first;       balance -= mass[i].second;     }     printf( %I64d  n , x);     for (long i = 0; i < x; i++)       printf( %I64d %I64d  n , ans[i].first, ans[i].second);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const long long _INF = 0x7ffffffffffffffll;   const double EPS = 1e-9;   const double PI = acos(-1.0);   template <class T, class INT>   inline T pow(T x, INT y) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res *= tt;       tt *= tt;     }     return res;   }   template <class T, class INT>   inline T pow(T x, INT y, T p) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res = res * tt % p;       tt = tt * tt % p;     }     return res;   }   int toInt(string s) {     int x = 0;     istringstream sin(s);     sin >> x;     return x;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class INT>   inline INT gcd(INT x, INT y) {     return y ? gcd(y, x % y) : x;   }   template <class INT>   inline int calc_bits(INT x) {     return x ? (x & 1) + calc_bits(x >> 1) : 0;   }   int n, x, xx, y, yy, ans;   int main(int argc, char* argv[]) {     cin >> n >> x >> y >> xx >> yy;     ans = abs(x - xx) + abs(y - yy);     if (x == 0 && xx == n || x == n && xx == 0)       ans += min(n - max(y, yy), min(y, yy)) * 2;     if (y == 0 && yy == n || y == n && yy == 0)       ans += min(n - max(x, xx), min(x, xx)) * 2;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[1001][1001];   set<int> r[1001], c[1001];   map<int, int> r_m[1001], c_m[1001];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         r[i].insert(a[i][j]);         c[j].insert(a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       int w = 1;       for (int x : r[i]) {         r_m[i][x] = w;         w++;       }     }     for (int i = 1; i <= m; i++) {       int w = 1;       for (int x : c[i]) {         c_m[i][x] = w;         w++;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x = r_m[i][a[i][j]];         int y = c_m[j][a[i][j]];         if (x > y) {           printf( %d  , max((int)r[i].size(), (int)c[j].size() + x - y));         } else {           printf( %d  , max((int)r[i].size() + y - x, (int)c[j].size()));         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)(2e9);   const long long linf = (long long)(2e18);   void solve();   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(20);     solve();     return 0;   }   void solve() {     int n = 8;     unordered_map<char, int> w, W;     w[ q ] = 9;     w[ r ] = 5;     w[ b ] = 3;     w[ n ] = 3;     w[ p ] = 1;     w[ k ] = 0;     w[ . ] = 0;     w[ Q ] = 0;     w[ R ] = 0;     w[ B ] = 0;     w[ N ] = 0;     w[ P ] = 0;     w[ K ] = 0;     W[ q ] = 0;     W[ r ] = 0;     W[ b ] = 0;     W[ n ] = 0;     W[ p ] = 0;     W[ k ] = 0;     W[ . ] = 0;     W[ Q ] = -9;     W[ R ] = -5;     W[ B ] = -3;     W[ N ] = -3;     W[ P ] = -1;     W[ K ] = 0;     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         char x;         cin >> x;         ans += (w[x] + W[x]);       }     }     if (!ans)       cout <<  Draw n ;     else if (ans < 0)       cout <<  White n ;     else       cout <<  Black n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int extgcd(int a, int b, long long &x, long long &y) {     int d = a;     if (b != 0) {       d = extgcd(b, a % b, y, x);       y -= (a / b) * x;     } else {       x = 1;       y = 0;     }     return d;   }   int main() {     int n;     scanf( %d , &n);     int i = 2;     int t = n;     while (t > 1 && i <= sqrt(n)) {       if (t % i == 0) {         while (t % i == 0) t /= i;         v.push_back(i);       }       i++;     }     if (t > 1) v.push_back(t);     if (v.size() == 1) {       printf( NO n );       return 0;     }     int j;     bool f = true;     for (i = 0; i < v.size() && f; i++)       for (j = i + 1; j < v.size(); j++) {         long long p, q;         extgcd(v[i], v[j], p, q);         p *= n - 1;         q *= n - 1;         int a = v[i], b = v[j];         if (q < 0) {           swap(a, b);           swap(p, q);         }         long long t = (-p) / b + 1;         p += b * t;         q -= a * t;         if (q > 0) {           printf( YES n2 n );           printf( %d %d n%d %d n , (int)p, (int)n / a, (int)q, (int)n / b);           f = false;           break;         }       }     if (f) printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5050];   int solve(int l, int r, int h) {     int m, i;     if (l > r)       return 0;     else if (l == r)       return (a[l] > h);     else       for (i = m = l; i <= r; i++)         if (a[m] > a[i]) m = i;     return min(r - l + 1,                a[m] - h + solve(l, m - 1, a[m]) + solve(m + 1, r, a[m]));   }   int main() {     int i, j;     int n;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     cout << solve(0, n - 1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     tuple<long long, long long, long long> arr[n - 1];     long long s1, e1;     cin >> s1 >> e1;     for (long long i = 0; i < n - 1; ++i) {       long long s2, e2;       cin >> s2 >> e2;       arr[i] = make_tuple(e2 - s1 + 1, s2 - e1 - 1, i);       s1 = s2, e1 = e2;     }     pair<long long, long long> blen1[m];     long long blen2[m];     for (long long i = 0; i < m; ++i) {       long long b;       cin >> b;       blen1[i] = make_pair(b, i);       blen2[i] = b;     }     sort(arr, arr + n - 1);     sort(blen1, blen1 + m);     sort(blen2, blen2 + m);     pair<long long, long long> num_b[n - 1];     for (long long i = 0; i < n - 1; ++i) {       long long end, start, idx, u = 0, l = 0;       tie(end, start, idx) = arr[i];       l = upper_bound(blen2, blen2 + m, start) - blen2;       u = lower_bound(blen2, blen2 + m, end) - blen2;       if (u - l == 0) {         cout <<  No  << endl;         return 0;       } else {         num_b[i] = make_pair(l, u);       }     }     set<pair<long long, long long> > bg;     for (long long i = 0; i < m; ++i) {       bg.insert(blen1[i]);     }     long long ans[n - 1];     for (long long i = 0; i < n - 1; ++i) {       long long u = num_b[i].second, l = num_b[i].first;       set<pair<long long, long long> >::iterator itr =           bg.upper_bound({blen2[l], -1});       if (itr == bg.end() || (u != m && (*itr).first >= blen2[u])) {         cout <<  No  << endl;         return 0;       }       ans[get<2>(arr[i])] = (*itr).second + 1;       bg.erase(itr);     }     cout <<  Yes  << endl;     for (long long i = 0; i < n - 1; ++i) {       cout << ans[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   const long double pi = 3.141592654;   using namespace std;   int n, k;   int dx[] = {0, 0, 1, -1, 1, -1, -1, 1};   int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};   bool valid(int r, int c) { return r >= 0 && c >= 0 && r < n && c < n; }   char grid[120][120];   bool vis[100074];   vector<int> initial;   vector<vector<int>> graph;   int parent[100074];   void topological_sort(int student) {     vis[student] = 1;     for (auto child : graph[student]) {       if (!vis[child]) topological_sort(child);     }     initial.push_back(student);   }   int main() {     long long n;     cin >> n;     if (n == 2) {       cout << 2;     } else {       if (n % 2 == 0)         cout << 2;       else         cout << 1;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {     fin >> pr.first >> pr.second;     return fin;   }   template <class T0, class T1, class T2>   inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {     fin >> get<0>(t) >> get<1>(t) >> get<2>(t);     return fin;   }   template <class T>   inline istream& operator>>(istream& fin, vector<T>& a) {     for (auto& u : a) fin >> u;     return fin;   }   template <class T, size_t n>   inline istream& operator>>(istream& fin, array<T, n>& a) {     for (auto& u : a) fin >> u;     return fin;   }   template <class FwdIter>   inline auto dump(FwdIter first, FwdIter last, const char* dlm) -> void {     copy(first, last,          ostream_iterator<typename iterator_traits<FwdIter>::value_type>(cout,                                                                          dlm));   }   inline int64_t powmod(int64_t a, int64_t n, const int64_t mod) {     if (a == 1 || !n) return mod != 1 ? 1 : 0;     int64_t out = 1;     for (; n; n >>= 1) {       if (n & 1) out = out * a % mod;       a = a * a % mod;     }     return out;   }   int64_t probB() {     const int64_t mod = 1000000007;     int64_t p, k;     cin >> p >> k;     if (k == 0) {       return powmod(p, p - 1, mod);     }     vector<bool> tag(p, false);     int64_t out = k == 1 ? p : 1;     for (int64_t i = 1; i < p; ++i)       if (!tag[i]) {         out = (out * p) % mod;         for (auto j = i; !tag[j]; j = (j * k) % p) tag[j] = true;       }     return out;   }   int main(const int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << probB();     return EXIT_SUCCESS;   }