#include <bits/stdc++.h>   using namespace std;   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   struct node {     int x, y;   } f[2203456], ans[2203456];   bool cmp(node x, node y) { return x.x == y.x ? x.y > y.y : x.x < y.x; }   int main() {     int n, k;     cin >> n >> k;     int tot = 0;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       f[tot].x = a, f[tot].y = 1;       tot++;       f[tot].x = b, f[tot].y = -1;       tot++;     }     sort(f, f + tot, cmp);     int cnt = 0, ansi = 0, start = 0;     for (int i = 0; i < tot; i++) {       if (cnt == k - 1 && f[i].y == 1) {         start = f[i].x;       }       if (cnt == k && f[i].y == -1) {         ans[ansi].x = start;         ans[ansi].y = f[i].x;         ansi++;       }       cnt += f[i].y;     }     cout << ansi << endl;     for (int i = 0; i < ansi; i++) {       printf( %d %d n , ans[i].x, ans[i].y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t;     cin >> n >> t;     long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     float mxdif = INT_MIN;     for (int i = 1; i < n; i++) {       if (arr[i] - arr[i - 1] > mxdif) {         mxdif = arr[i] - arr[i - 1];       }     }     double z = (mxdif + 0.000) / 2;     double maxcnr = max(arr[0] - 0, t - arr[n - 1]);     printf( %.9lf , max(z, maxcnr));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long memo[4][1001][1001];   long long mp[1001][1001];   int n, m;   long long REC(int x, int y, int st) {     if (x >= n || y >= m || x < 0 || y < 0) return 0;     if (st == 0 && x == n - 1 && y == m - 1) return mp[x][y];     if (st == 1 && x == 0 && y == 0) return mp[x][y];     if (st == 2 && x == 0 && y == m - 1) return mp[x][y];     if (st == 3 && x == n - 1 && y == 0) return mp[x][y];     if (~memo[st][x][y]) return memo[st][x][y];     long long a, b;     if (st == 0) {       a = REC(x + 1, y, st) + mp[x][y];       b = REC(x, y + 1, st) + mp[x][y];       return memo[st][x][y] = a >= b ? a : b;     } else if (st == 1) {       a = REC(x - 1, y, st) + mp[x][y];       b = REC(x, y - 1, st) + mp[x][y];       return memo[st][x][y] = a >= b ? a : b;     } else if (st == 2) {       a = REC(x - 1, y, st) + mp[x][y];       b = REC(x, y + 1, st) + mp[x][y];       return memo[st][x][y] = a >= b ? a : b;     } else if (st == 3) {       a = REC(x + 1, y, st) + mp[x][y];       b = REC(x, y - 1, st) + mp[x][y];       return memo[st][x][y] = a >= b ? a : b;     }   }   long long check(int x, int y) {     long long a, b, aa, bb, res = 0, tmp;     b = memo[3][x + 1][y];     a = memo[1][x][y - 1];     bb = memo[2][x - 1][y];     aa = memo[0][x][y + 1];     tmp = aa + bb + a + b;     res = tmp >= res ? tmp : res;     b = memo[3][x][y - 1];     a = memo[1][x - 1][y];     bb = memo[2][x][y + 1];     aa = memo[0][x + 1][y];     tmp = aa + bb + a + b;     res = tmp >= res ? tmp : res;     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> mp[i][j];       }     }     memset(memo, -1, sizeof memo);     REC(0, 0, 0);     REC(n - 1, m - 1, 1);     REC(n - 1, 0, 2);     REC(0, m - 1, 3);     long long maxi = 0;     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         long long tmp = check(i, j);         maxi = tmp >= maxi ? tmp : maxi;       }     }     cout << maxi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int NMAX = 5005;   const int INF = 2e5;   int n;   vector<int> arr;   vector<vector<int>> dp(NMAX, vector<int>(NMAX, INF));   int rec(int i, int j) {     if (dp[i][j] != INF) return dp[i][j];     if (i == j) return dp[i][j] = 0;     if (arr[i] == arr[j]) return dp[i][j] = 1 + rec(i + 1, j - 1);     return dp[i][j] = 1 + min(rec(i + 1, j), rec(i, j - 1));   }   void solve() {     cin >> n;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       if (!i)         arr.push_back(tmp);       else if (tmp != arr[(int)(arr.size()) - 1])         arr.push_back(tmp);     }     n = (int)(arr.size());     cout << rec(0, n - 1) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int x, y, z;   int sum = 0;   map<int, pair<char, int> > ans;   map<int, pair<char, int> >::iterator t;   int main() {     scanf( %d%d , &n, &q);     ans[0] = { U , 0};     ans[n + 1] = { L , 0};     for (int i = 1; i <= q; i++) {       scanf( %d%d%c%c , &x, &y, &z, &z);       t = ans.lower_bound(x);       if (t->first == x) {         printf( 0 n );         continue;       }       if (z ==  L ) t--;       sum = abs(x - t->first);       if (t->second.first == z) sum += t->second.second;       ans[x] = {z, sum};       printf( %d n , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long qr() {     register long long ret = 0, f = 0;     register char c = getchar();     while (c < 48 || c > 57) f |= c == 45, c = getchar();     while (c >= 48 && c <= 57) ret = ret * 10 + c - 48, c = getchar();     return f ? -ret : ret;   }   const int maxn = 1e5 + 5;   int n, m, p;   int dis[maxn];   long long sumd[maxn];   long long sumdata[maxn];   long long x[maxn];   long long y[maxn];   long long ans;   deque<int> q;   struct NODE {     int pos, time;     long long limit;     NODE() { ans = pos = time = 0; }     inline bool operator<(const NODE& a) const { return limit < a.limit; }     inline void scan() {       pos = qr();       time = qr();       limit = time - sumd[pos];     }   } data[maxn];   long long dp[101][maxn];   inline void wk() {     memset(dp, 5, sizeof dp);     dp[0][0] = 0;     deque<int>::iterator ita;     for (register int i = 0; i <= m; ++i) x[i] = i;     for (register int t = 1; t <= p; ++t) {       for (register int i = 0; i <= m; ++i) {         dp[t][i] = dp[t - 1][i];         y[i] = dp[t - 1][i] + sumdata[i];       }       q.clear();       for (register int i = 1; i <= m; ++i) {         q.push_back(i - 1);         ita = q.begin();         while (q.size() > 1 && y[*(ita + 1)] - y[*ita] <=                                    1ll * data[i].limit * ((*(ita + 1)) - (*ita)))           q.pop_front(), ita = q.begin();         register int j = q.front();         dp[t][i] = min(dp[t][i], dp[t - 1][j] + 1ll * (i - j) * data[i].limit -                                      (sumdata[i] - sumdata[j]));         ita = q.end() - 1;         while (q.size() > 1 &&                (y[*ita] - 1ll * y[*(ita - 1)]) * (i - (*ita)) >=                    1ll * (y[i] - y[*ita]) * ((*ita) - (*(ita - 1))))           q.pop_back(), ita = q.end() - 1;         ;       }     }     cout << dp[p][m] << endl;   }   int main() {     n = qr();     m = qr();     p = qr();     for (register int t = 2; t <= n; ++t) sumd[t] = (dis[t] = qr()) + sumd[t - 1];     for (register int t = 1; t <= m; ++t) data[t].scan();     sort(data + 1, data + m + 1);     for (register int t = 1; t <= m; ++t)       sumdata[t] = data[t].limit + sumdata[t - 1];     wk();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   namespace _buff {   const size_t BUFF = 1 << 19;   char ibuf[BUFF], *ib = ibuf, *ie = ibuf;   char getc() {     if (ib == ie) {       ib = ibuf;       ie = ibuf + fread(ibuf, 1, BUFF, stdin);     }     return ib == ie ? -1 : *ib++;   }   }  // namespace _buff   LL read() {     using namespace _buff;     LL ret = 0;     bool pos = true;     char c = getc();     for (; (c <  0  || c >  9 ) && c !=  - ; c = getc()) {       assert(~c);     }     if (c ==  - ) {       pos = false;       c = getc();     }     for (; c >=  0  && c <=  9 ; c = getc()) {       ret = (ret << 3) + (ret << 1) + (c ^ 48);     }     return pos ? ret : -ret;   }   const size_t N = 2e2 + 5;   const size_t AL = 21;   const size_t V = N * AL;   const size_t K = 5e2 + 5;   const int MOD = 1e9 + 7;   void iadd(int &dp, int val) {     dp += val;     if (dp >= MOD) {       dp -= MOD;     }   }   int val[V], ch[V][AL], fail[V], tot = 1;   int dp[2][V][K][2], m, k;   int new_node(int &x) {     if (!x) x = ++tot;     return x;   }   void add(const vector<int> &vc, int v) {     int cur = 1;     for (int dig : vc) {       cur = new_node(ch[cur][dig]);     }     val[cur] += v;   }   void build() {     queue<int> que;     for (int i = 0; i < m; ++i) {       int &x = ch[1][i];       if (x) {         fail[x] = 1;         que.emplace(x);       } else {         x = 1;       }     }     while (!que.empty()) {       int x = que.front();       que.pop();       val[x] += val[fail[x]];       for (int i = 0; i < m; ++i) {         if (ch[x][i]) {           fail[ch[x][i]] = ch[fail[x]][i];           que.emplace(ch[x][i]);         } else {           ch[x][i] = ch[fail[x]][i];         }       }     }   }   int solve(const vector<int> &vc) {     int pi = 0, ci = 1;     memset(dp[pi], 0, sizeof dp[pi]);     for (unsigned i = 0; i < vc.size(); ++i) {       memset(dp[ci], 0, sizeof dp[ci]);       int rb = i ? m : vc[0];       for (int j = 1, _ = min(rb, m - 1); j <= _; ++j) {         int nxt = ch[1][j];         iadd(dp[ci][nxt][val[nxt]][j < rb], 1);       }       for (int x = 1; x <= tot; ++x) {         for (int d = 0; d < m; ++d) {           int y = ch[x][d];           for (int k1 = 0, k2 = val[y]; k2 <= k; ++k1, ++k2) {             if (d <= vc[i] && dp[pi][x][k1][0]) {               if (d < vc[i]) {                 iadd(dp[ci][y][k2][1], dp[pi][x][k1][0]);               } else {                 iadd(dp[ci][y][k2][0], dp[pi][x][k1][0]);               }             }             if (dp[pi][x][k1][1]) {               iadd(dp[ci][y][k2][1], dp[pi][x][k1][1]);             }           }         }       }       swap(pi, ci);     }     int ans = 0;     for (int x = 1; x <= tot; ++x) {       for (int i = 0; i <= k; ++i) {         iadd(ans, dp[pi][x][i][0]);         iadd(ans, dp[pi][x][i][1]);       }     }     return ans;   }   int main() {     int n = read();     m = read();     k = read();     vector<int> lb;     {       vector<int> vc(read());       generate(vc.begin(), vc.end(), read);       while (!vc.back()) {         lb.emplace_back(m - 1);         vc.pop_back();       }       --vc.back();       lb.insert(lb.begin(), vc.begin(), vc.end());       while (!lb.empty() && lb.front() == 0) {         lb.erase(lb.begin());       }     }     vector<int> rb;     {       rb = vector<int>(read());       generate(rb.begin(), rb.end(), read);     }     while (n--) {       vector<int> vc(read());       generate(vc.begin(), vc.end(), read);       add(vc, read());     }     build();     int ans = solve(rb);     iadd(ans, MOD - solve(lb));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int now;   int n, m, c, a[MAX];   int main() {     cin >> n >> m >> c;     c /= 2;     while (m--) {       int x;       scanf( %d , &x);       if (x <= c) {         for (int i = 1; i <= n; i++) {           if (a[i] == 0 || a[i] > x) {             a[i] = x;             printf( %d n , i);             fflush(stdout);             break;           }         }       } else {         for (int i = n; i >= 1; i--) {           if (a[i] == 0 || a[i] < x) {             a[i] = x;             printf( %d n , i);             fflush(stdout);             break;           }         }       }       now = 0;       for (int i = 1; i <= n; i++) {         if (a[i] != 0) now++;       }       if (now == n) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   long long grundy(long long k) {     long long i = 1;     long long sum = 1;     while (sum <= k) {       i++;       sum += i;     }     return i - 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long stxor = 0;     for (long long i = 0; i < n; i++) {       long long num;       cin >> num;       stxor ^= grundy(num);     }     if (stxor == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int distance(char a, char b) {     int d = abs(a - b);     int d1 = 26 - d;     return min(d, d1);   }   int main() {     int n;     string A;     int cursor;     cin >> n >> cursor >> A;     cursor--;     n--;     cursor = min(cursor, n - cursor);     int middle = n / 2;     int leftmost = cursor, rightmost = cursor;     for (int i = cursor; i <= middle; i++)       if (A[i] != A[n - i]) rightmost = i;     for (int i = cursor; i >= 0; i--)       if (A[i] != A[n - i]) leftmost = i;     int vertical_moves = 0;     for (int i = leftmost; i <= rightmost; i++)       vertical_moves += min(abs(A[i] - A[n - i]), 26 - abs(A[i] - A[n - i]));     int horizontal_moves = min((cursor - leftmost) + (rightmost - leftmost),                                (rightmost - cursor) + (rightmost - leftmost));     int total_moves = horizontal_moves + vertical_moves;     cout << total_moves;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int arr[n];       set<long long int> s;       for (int i = 0; i < n; i++) cin >> arr[i];       for (int i = 0; i < n; i++) {         s.insert(arr[i]);       }       if (s.size() == 1)         cout << n <<   n ;       else         cout << 1 <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<long long int> primes;   void SOE(long long int n) {     primes.erase(primes.begin(), primes.end());     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (prime[p]) {         primes.push_back(p);       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int i, c = 0, j, k, t, f = 0, q, n, f1 = 0, y, x, m, l = 0, r, p;     string s, s1, s2;     cin >> t;     while (t--) {       cin >> n;       long long int a[n];       for (i = 0; i < n; i++) {         cin >> a[i];       }       a[0] < a[n - 1] ? cout <<  YES n  : cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string ans =   ;   set<int> s[26];   map<int, bool> vis;   void solve(char a) {     ans += a;     vis[a -  a ] = true;     for (auto it : s[a -  a ]) {       if (!vis[it -  a ]) {         solve(it);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string str;       cin >> str;       int n = str.length();       string alp =  abcdefghijklmnopqrstuvwxyz ;       if (n == 1) {         cout <<  YES  << endl;         cout << alp << endl;         continue;       }       for (int i = 0; i < 26; i++) s[i].clear();       vis.clear();       ans =   ;       for (long long int i = 1; i < n - 1; i++) {         s[str[i] -  a ].insert(str[i - 1]);         s[str[i] -  a ].insert(str[i + 1]);       }       s[str[0] -  a ].insert(str[1]);       s[str[n - 1] -  a ].insert(str[n - 2]);       int flag = 0, cnt = 0;       char st;       for (long long int i = 0; i < 26; i++) {         if (s[i].size() > 2) {           flag = 1;         } else if (s[i].size() == 1) {           cnt++;           st = alp[i];         }       }       if (flag or cnt < 2) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       solve(st);       for (int i = 0; i < 26; i++) {         if (!vis[alp[i] -  a ]) ans += alp[i];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   string bin(long long n) {     string ans =   ;     while (n > 0) {       if (n % 2 == 0)         ans =  0  + ans;       else         ans =  1  + ans;       n /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long pmd(long long a, long long b) {     if (b == 1) return (a + md) % md;     if (b % 2 == 0)       return (pmd(a * a, b / 2) + md) % md;     else       return (a * pmd(a * a, b / 2) + md) % md;   }   const int xn = 7e1 + 10;   const int xm = 1e2 + 10;   map<pair<pair<int, int>, int>, pair<pair<int, int>, int> > mp;   map<pair<pair<int, int>, int>, pair<int, int> > ans;   map<pair<pair<int, int>, int>, int> m;   vector<pair<int, int> > vec;   char a[xn][xn];   pair<pair<int, int>, int> srt(pair<pair<int, int>, int> g) {     int sm = g.first.first + g.first.second + g.second;     pair<pair<int, int>, int> ns;     int mn = g.first.first;     mn = min(mn, g.first.second);     mn = min(mn, g.second);     int mx = g.first.first;     mx = max(mx, g.first.second);     mx = max(mx, g.second);     ns.first.first = mn, ns.second = mx, ns.first.second = sm - (mn + mx);     return ns;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int s1, s2, s3;     cin >> s1 >> s2 >> s3;     for (int i = 1; i <= n; i++) {       string g;       cin >> g;       for (int j = 1; j <= n; j++) a[i][j] = g[j - 1];     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         for (int k = j + 1; k <= n; k++) m[{{i, j}, k}] = -1;     queue<pair<pair<int, int>, int> > q;     q.push(srt({{s1, s2}, s3}));     m[srt({{s1, s2}, s3})] = 0;     while (q.size()) {       int v = q.front().first.first, u = q.front().first.second,           s = q.front().second;       q.pop();       for (int i = 1; i <= n; i++) {         if (i == v || i == u || i == s) continue;         if (a[v][i] == a[u][s] && m[srt({{i, u}, s})] == -1)           q.push(srt({{i, u}, s})),               mp[srt({{i, u}, s})] = {{v, u}, s}, ans[srt({{i, u}, s})] = {v, i},                               m[srt({{i, u}, s})] = m[{{v, u}, s}] + 1;       }       for (int i = 1; i <= n; i++) {         if (i == v || i == u || i == s) continue;         if (a[u][i] == a[v][s] && m[srt({{i, v}, s})] == -1)           q.push(srt({{i, v}, s})),               mp[srt({{i, v}, s})] = {{v, u}, s}, ans[srt({{i, v}, s})] = {u, i},                               m[srt({{i, v}, s})] = m[{{v, u}, s}] + 1;       }       for (int i = 1; i <= n; i++) {         if (i == v || i == u || i == s) continue;         if (a[s][i] == a[u][v] && m[srt({{i, u}, v})] == -1)           q.push(srt({{i, u}, v})),               mp[srt({{i, u}, v})] = {{v, u}, s}, ans[srt({{i, u}, v})] = {s, i},                               m[srt({{i, u}, v})] = m[{{v, u}, s}] + 1;       }     }     if (m[{{1, 2}, 3}] == -1) {       cout << -1 <<   n ;       return 0;     }     pair<pair<int, int>, int> d;     d = {{1, 2}, 3};     cout << m[{{1, 2}, 3}] <<   n ;     while (m[srt(d)] > 0) {       vec.push_back(ans[srt(d)]);       d = srt(mp[srt(d)]);     }     for (int i = vec.size() - 1; i >= 0; i--)       cout << vec[i].first <<     << vec[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxF = (long long)1e9 * 1e9;   const int maxn = 100, maxm = 100, maxlen = maxn + maxm + 1;   int n, m, len, map[maxn + 5][maxm + 5], pri[maxlen], cir[maxlen];   long long dp[maxlen][(maxlen >> 1) + 1], k;   long long cal() {     memset(dp, 0, sizeof(dp));     dp[0][1] = 1;     int up = len >> 1;     for (int p = 1; p < len; p++)       for (int d = 0; d <= up; d++) {         if (cir[p] != 1 && d < up) dp[p][d] += dp[p - 1][d + 1];         if (cir[p] != -1 && d > 0) dp[p][d] += dp[p - 1][d - 1];         if (dp[p][d] >= maxF) dp[p][d] = maxF;       }     return dp[len - 1][0];   }   int main() {     cin >> n >> m >> k;     memset(pri, -1, sizeof(pri));     for (int i = 0, t; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> t;         pri[i + j] = pri[i + j] == -1 ? t : min(pri[i + j], t);       }     len = n + m - 1;     memset(cir, 0, sizeof(cir));     cir[0] = 1;     cir[len - 1] = -1;     for (int t = 1; t < len - 1; t++) {       int pos, minPri = 100000000;       for (int p = 1; p < len - 1; p++)         if (cir[p] == 0 && minPri > pri[p]) pos = p, minPri = pri[p];       cir[pos] = 1;       long long s = cal();       if (k > s) k -= s, cir[pos] = -1;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << (cir[i + j] == 1 ?  (  :  ) );       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T checkmin(T &a, T b) {     return (a < b) ? a : a = b;   }   template <class T>   inline T checkmax(T &a, T b) {     return (a > b) ? a : a = b;   }   template <class T>   T GCD(T a, T b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (a == 0) ? b : GCD(b % a, a);   }   template <class T>   T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;   }   template <class T>   inline T sqr(T X) {     return X * X;   }   namespace Poor {   const int MaxiL = 1000005;   const int MaxiN = 205;   const int MaxiM = 205;   const int MaxiQL = 3005;   int N, L;   char St[MaxiL];   char Rule[MaxiQL];   int SeqX[MaxiM], SeqY[MaxiM];   int Stack[MaxiL];   inline bool Same(const int a, const int b, const int c, const int d) {     if (b - a != d - c) return 0;     for (register int i = 0; i < b - a; ++i)       if (St[a + i] != Rule[c + i]) return 0;     return 1;   }   void Run() {     gets(St);     L = strlen(St);     scanf( %d n , &N);     for (int i = 0; i < N; ++i) {       gets(Rule);       int M = 0;       for (int p = 0; Rule[p] !=   0 ; ++p)         if (isalpha(Rule[p])) {           int q = p;           for (; isalpha(Rule[q]); ++q)             ;           SeqX[M] = p;           SeqY[M] = q;           ++M;           p = q - 1;         }       register int res = 0;       register int *Top = Stack;       *Top = 0;       ++Top;       for (register int p = 0, q = 0; p < L; p = q + 1) {         for (q = p; St[q] !=  > ; ++q)           ;         if (St[p + 1] ==  / ) {           --Top;           continue;         }         if (St[q - 1] ==  / ) {           if (*(Top - 1) >= M - 1 && Same(p + 1, q - 1, SeqX[M - 1], SeqY[M - 1]))             ++res;           continue;         }         *Top = *(Top - 1);         if (*Top < M - 1) {           if (Same(p + 1, q, SeqX[*Top], SeqY[*Top])) ++*Top;         } else {           if (Same(p + 1, q, SeqX[M - 1], SeqY[M - 1])) ++res;         }         ++Top;       }       printf( %d n , res);     }   }   }  // namespace Poor   int main() {     Poor::Run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long seg[200005], h[100005], dp[100005];   int n, cnt, arr[100005], a[100005], b[100005];   map<int, int> mn;   map<int, long long> tot;   inline void modify(int pos, long long x) {     for (seg[pos += cnt] += x; pos; pos >>= 1)       seg[pos >> 1] = max(seg[pos], seg[pos ^ 1]);   }   inline long long query(int l, int r) {     long long res = 0;     for (l += cnt, r += cnt; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, seg[l++]);       if (r & 1) res = max(res, seg[--r]);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a, b, h;       scanf( %d%d%d , &a, &b, &h);       if (mn.count(b))         mn[b] = min(mn[b], a);       else         mn[b] = a;       tot[b] += h;     }     for (map<int, int>::iterator it = mn.begin(); it != mn.end(); it++) {       arr[cnt] = it->first;       a[cnt] = it->second;       b[cnt] = it->first;       h[cnt++] = tot[it->first];     }     long long ans = 0;     for (int i = 0; i < cnt; i++) {       dp[i] = query(lower_bound(arr, arr + cnt, a[i] + 1) - arr,                     lower_bound(arr, arr + cnt, b[i]) - arr + 1) +               h[i];       modify(lower_bound(arr, arr + cnt, b[i]) - arr, dp[i]);       ans = max(ans, dp[i]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Direction[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   const int Nmax = 200010;   int n, k;   long long a[20000], pref[20000];   long long f[60][500][500];   long long diff[500][2];   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       pref[i] = pref[i - 1] + a[i];     };     for (int i = 0; i <= n; i++) diff[i][0] = diff[i][1] = -2000000000;     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) {         diff[j][0] = max(diff[j][0], pref[j] - pref[i - 1]);         diff[j][1] = max(pref[i - 1] - pref[j], diff[j][1]);       };     long long answer = 0;     for (int t = 2; t <= k; t++) {       for (int i = 1; i <= n; i++)         for (int j = i; j <= n; j++)           f[t][i][j] = max(diff[i - 1][0] - pref[j] + pref[i - 1],                            diff[i - 1][1] - pref[i - 1] + pref[j]);       for (int i = 0; i < n; i++) diff[i][0] = diff[i][1] = -2000000000;       for (int i = 1; i <= n; i++)         for (int j = i; j <= n; j++) {           diff[j][0] = max(diff[j][0], f[t][i][j] + pref[j] - pref[i - 1]);           diff[j][1] = max(diff[j][1], f[t][i][j] - pref[j] + pref[i - 1]);         };     };     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) answer = max(answer, (long long)f[k][i][j]);     cout << answer << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b, long long p = 1000000007) {     long long c = a + b;     if (c >= p) c -= p;     return c;   }   inline long long sub(long long a, long long b, long long p = 1000000007) {     long long c = a - b;     if (c < 0) c += p;     return c;   }   inline long long mul(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long power(long long x, long long y, long long p = 1000000007) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   vector<int> g[200005];   int t = 0;   int tim[500005];   void dfs(int u, int v = -1) {     tim[t++] = u;     for (auto x : g[u]) {       if (x == v) continue;       dfs(x, u);     }     tim[t++] = u;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     int a;     cin >> n;     int p[n + 1];     for (int i = 2; i <= n; i++) {       cin >> a;       g[i].push_back(a);       g[a].push_back(i);     }     dfs(1);     map<int, int> mp;     for (int i = 0; i <= 2 * n - 1; i++) {       mp[tim[i]]++;       if (tim[i] == n) break;     }     for (auto it = mp.begin(); it != mp.end(); it++) {       if (it->second == 1) {         cout << it->first <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long infll = powl(2, 63) - 1;   struct cup {     long long a, b, c;   };   bool comp(cup x, cup y) { return x.c < y.c; }   bool cmp1(cup x, cup y) {     if (x.a == y.a) return x.c < y.c;     return x.a > y.a;   }   int32_t main() {     long long n, tea;     cin >> n >> tea;     vector<cup> arr(n);     for (long long i = 0; i < (long long)(n); ++i) cin >> arr[i].a;     for (long long i = 0; i < (long long)(n); ++i) {       arr[i].b = ceil(arr[i].a / 2.0);       arr[i].c = i;       tea -= arr[i].b;       if (tea < 0) {         cout << -1 << endl;         return 0;       }     }     sort((arr).begin(), (arr).end(), cmp1);     for (long long i = 0; i < (long long)(n); ++i) {       long long temp = min(tea, arr[i].a - arr[i].b);       arr[i].b += temp;       tea -= temp;       if (tea == 0) break;     }     sort((arr).begin(), (arr).end(), comp);     for (long long i = 0; i < (long long)(n); ++i) cout << arr[i].b <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long x, y, m;     cin >> x >> y >> m;     long long sol = 0ll;     if (x >= m || y >= m) {       cout <<  0 n ;       return 0;     }     if (x <= 0ll && y <= 0ll) {       cout <<  -1 n ;       return 0;     }     if (x > y) {       swap(x, y);     }     if (x < 0ll) {       sol += ((-x) / y);       x = -((-x) % y);     }     while (x < m && y < m) {       if (x <= y) {         x += y;       } else {         y += x;       }       sol++;     }     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using std::bitset;   const double Pi = acos(-1);   namespace fastIO {   template <class T>   inline void read(T &x) {     x = 0;     bool fu = 0;     char ch = 0;     while (ch >  9  || ch <  0 ) {       ch = getchar();       if (ch ==  - ) fu = 1;     }     while (ch <=  9  && ch >=  0 ) x = (x * 10 - 48 + ch), ch = getchar();     if (fu) x = -x;   }   inline int read() {     int x = 0;     bool fu = 0;     char ch = 0;     while (ch >  9  || ch <  0 ) {       ch = getchar();       if (ch ==  - ) fu = 1;     }     while (ch <=  9  && ch >=  0 ) x = (x * 10 - 48 + ch), ch = getchar();     return fu ? -x : x;   }   char _n_u_m_[40];   template <class T>   inline void write(T x) {     if (x == 0) {       putchar( 0 );       return;     }     T tmp = x > 0 ? x : -x;     if (x < 0) putchar( - );     register int cnt = 0;     while (tmp > 0) {       _n_u_m_[cnt++] = tmp % 10 +  0 ;       tmp /= 10;     }     while (cnt > 0) putchar(_n_u_m_[--cnt]);   }   template <class T>   inline void write(T x, char ch) {     write(x);     putchar(ch);   }   }  // namespace fastIO   using namespace fastIO;   const int MAXN = 1000005;   int len[MAXN], ch[MAXN][26], fail[MAXN], cnt, lst, up[MAXN], orz[MAXN];   long long qwq[MAXN], ans[MAXN];   char c[MAXN], ccf[MAXN];   int now, n;   inline void insert(int pos) {     while (c[pos] != c[pos - len[lst] - 1]) lst = fail[lst];     if (!ch[lst][c[pos] - 97]) {       len[++cnt] = len[lst] + 2;       register int i = fail[lst];       while (c[pos] != c[pos - len[i] - 1]) i = fail[i];       fail[cnt] = ch[i][c[pos] - 97];       ch[lst][c[pos] - 97] = cnt;       orz[cnt] = len[cnt] - len[fail[cnt]];       if (orz[cnt] == orz[fail[cnt]])         up[cnt] = up[fail[cnt]];       else         up[cnt] = fail[cnt];     }     lst = ch[lst][c[pos] - 97];   }   int main() {     len[1] = -1;     fail[0] = 1;     up[0] = 1;     ans[0] = 1;     cnt = 1;     scanf( %s , ccf + 1);     n = strlen(ccf + 1);     if (n % 2) {       cerr <<  Fuck CCF!!!  << endl;       cout << 0;       return 0;     }     for (register int i = 1, iend = n / 2; i <= iend; ++i) {       c[2 * i - 1] = ccf[i];       c[i << 1] = ccf[n - i + 1];     }     for (register int i = 1, iend = n; i <= iend; ++i) {       insert(i);       for (register int j = lst; j; j = up[j]) {         qwq[j] = ans[i - len[up[j]] - orz[j]];         if (up[j] != fail[j]) qwq[j] += qwq[fail[j]];         qwq[j] %= 1000000007ll;         if (!(i & 1)) ans[i] += qwq[j], ans[i] %= 1000000007ll;       }     }     cout << ans[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int T, n;   long long W;   pair<long long, int> w[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     for (cin >> T; T--;) {       vector<int> id;       cin >> n >> W;       long long x = W;       for (int i = 1; i <= n; ++i) cin >> w[i].first, w[i].second = i;       sort(w + 1, w + n + 1, greater<pair<int, int> >());       for (int i = 1; i <= n; ++i)         if (w[i].first <= x) x -= w[i].first, id.push_back(w[i].second);       if (W - x < (W + 1) / 2)         cout <<  -1 n ;       else {         cout << id.size() <<   n ;         for (int i : id) cout << i <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int n, siz[N];   vector<int> e[N];   double f[N][N], sav[N], C[N][N], fac[N];   void dfs(int x, int fa) {     siz[x] = 0, f[x][0] = 1;     for (const int &v : e[x])       if (v != fa) {         dfs(v, x), ++siz[v];         double sum = 0, o;         for (int a = (0); a <= (siz[v]); a++)           o = f[v][a], f[v][a] = f[v][a] * (siz[v] - a) + sum / 2, sum += o;         for (int a = (0); a <= (siz[x]); a++)           for (int b = (0); b <= (siz[v]); b++)             sav[a + b] += C[a + b][a] *                           C[(siz[x] - a) + (siz[v] - b)][siz[x] - a] * f[x][a] *                           f[v][b];         siz[x] += siz[v];         for (int a = (0); a <= (siz[x]); a++) f[x][a] = sav[a], sav[a] = 0;       }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(12), cout << fixed;     cin >> n;     fac[0] = C[0][0] = 1;     for (int i = (1); i <= (n); i++) fac[i] = fac[i - 1] * i, C[i][0] = 1;     for (int i = (1); i <= (n); i++)       for (int j = (1); j <= (i); j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     for (int i = 1, u, v; i < n; i++)       cin >> u >> v, e[u].push_back(v), e[v].push_back(u);     for (int i = (1); i <= (n); i++)       memset(f, 0, sizeof(f)), dfs(i, -1),           cout << f[i][n - 1] / fac[n - 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     long long int sum = 0;     long long int x = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       x = x ^ a[i];     }     cout << 2 <<   n ;     cout << x <<     << sum + x <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 305000;   const int INF = 105000;   int main() {     long long n, k;     cin >> n >> k;     long long g = (n / 2) / (k + 1);     long long d = g * k;     long long ost = n - d - g;     cout << g <<     << d <<     << ost;   }


#include <bits/stdc++.h>   using namespace std;   map<string, vector<string> > graph;   unsigned long long int countSetBits(long long int n) {     unsigned long long int count = 0;     while (n) {       n &= (n - 1);       count++;     }     return count;   }   bool valid(set<string>& t) {     for (auto i = t.begin(); i != t.end(); i++) {       for (auto k : graph[*i]) {         if (t.find(k) != t.end()) {           return false;         }       }     }     return true;   }   void solve() {     long long int n, m;     cin >> n >> m;     vector<string> players(n);     for (long long int i = 0; i < n; i++) {       cin >> players[i];     }     for (long long int i = 0; i < m; i++) {       string a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     set<string> ans;     for (long long int i = 1; i < (1 << (n + 1)); i++) {       set<string> tmp;       for (long long int j = 0; j <= log2(i); j++) {         if (i & (1 << j)) {           tmp.insert(players[min(n - 1, j)]);         }       }       if (ans.size() < tmp.size() && valid(tmp)) {         ans = tmp;       }       tmp.clear();     }     cout << ans.size() <<   n ;     for (string s : ans) {       cout << s <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int T = 1;     while (T--) {       solve();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 1ll << 60;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(25);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       string s;       cin >> s;       int cnt = 1;       vector<int> v;       for (int i = 1; i < n; i++) {         if (s[i] == s[i - 1])           cnt++;         else {           v.push_back(cnt);           cnt = 1;         }       }       v.push_back(cnt);       int ans = 0;       int l = (int)v.size();       for (int i = 0; i < l; i++) ans = min(i + 1, ans + v[i] - 1);       cout << ans + (l - ans + 1) / 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 8;   bool vis[N][N];   int n, m, ans, a[8];   vector<pair<int, int> > edges;   vector<int> v;   int calc() {     memset(vis, 0, sizeof vis);     for (auto X : edges) {       int x = X.first;       int y = X.second;       vis[a[x]][a[y]] = vis[a[y]][a[x]] = 1;     }     int ret = 0;     for (int i = 1; i <= 6; i++)       for (int j = i; j <= 6; j++) ret += vis[i][j];     return ret;   }   void bt(int i) {     if (i == n + 1) {       for (int i = 1; i <= n; i++) a[i] = v[i];       ans = max(ans, calc());       return;     }     for (int j = 1; j <= 6; j++) {       v.push_back(j);       bt(i + 1);       v.pop_back();     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edges.push_back({a, b});     }     if (n <= 6) {       printf( %d n , m);       return 0;     }     v.push_back(69);     bt(1);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 3;   int a[MAXN], b[MAXN], p[MAXN];   int read() {     int x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c - 48;       c = getchar();     }     return x * w;   }   int main() {     int n = read(), ans = 0;     for (int i = 1; i <= n; i++) a[i] = read(), p[a[i]] = 0;     for (int i = 1; i <= n; i++) b[i] = read(), p[b[i]] = i;     if (p[1]) {       int i, j;       for (i = 1; p[i] == p[1] + i - 1; i++)         ;       if (p[i - 1] == n) {         for (j = i; j <= n && p[j] <= j - i; j++)           ;         if (j > n) {           printf( %d n , n - i + 1);           return 0;         }       }     }     for (int i = 1; i <= n; i++) ans = max(ans, p[i] - (i - 1) + n);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 501000;   int n, a[N];   bool check(int p) {     for (int i = p - 1; i >= 0; i--) {       if (a[i] * 2 > a[n - p + i]) return false;     }     return true;   }   int work() {     int l = 0, r = n >> 1;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid))         l = mid + 1;       else         r = mid - 1;     }     return n - (l - 1);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     printf( %d n , work());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   template <class T = int>   T __rand(T range = numeric_limits<T>::max()) {     return (T)(rng() % range);   }   int debug = 0;   int __db_level = 0;   struct debug_block {     string name;     debug_block(const string& name_) : name(name_) {       if (debug) cerr << string(__db_level * 2,    ) <<  {   << name << endl;       ++__db_level;     }     ~debug_block() {       --__db_level;       if (debug) cerr << string(__db_level * 2,    ) <<  }   << name << endl;     }   };   template <class U, class V>   ostream& operator<<(ostream& out, const pair<U, V>& p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class A, class B>   ostream& operator<<(ostream& out, const tuple<A, B>& t) {     return out <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ) ;   }   template <class A, class B, class C>   ostream& operator<<(ostream& out, const tuple<A, B, C>& t) {     return out <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ,   << get<2>(t)                <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& container) {     out <<  { ;     if (((int)container.size())) out << container[0];     for (int i = 0; i++ < ((int)container.size()) - 1;)       out <<  ,   << container[i];     return out <<  } ;   }   template <class x>   vector<typename x::value_type> $v(const x& a) {     return vector<typename x::value_type>(a.begin(), a.end());   }   template <class u>   vector<typename iterator_traits<u>::value_type> $v(u a, u b) {     return vector<typename iterator_traits<u>::value_type>(a, b);   }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int ntest;     cin >> ntest;     for (int testcase = 0; testcase++ < ntest;) {       ;       int n, m, k;       cin >> n >> m >> k;       vector<int> a(n);       for (auto& i : a) cin >> i;       int ans = 0;       k = min(k, m - 1);       int left = m - 1 - k;       int width = n - k - left;       if (debug)         cerr << string(__db_level * 2,    ) <<  [               <<  width               <<  ] = [  << width <<  ]  << endl;       for (int i = -1; ++i < k + 1;) {         int cur_ans = INT_MAX;         for (int f = -1; ++f < left + 1;) {           int t = max(a[i + f], a[i + f + width - 1]);           if (debug)             cerr << string(__db_level * 2,    ) <<  [                   <<  i _ f _ t                   <<  ] = [  << i <<  ,   << f <<  ,   << t <<  ]  << endl;           cur_ans = min(cur_ans, t);         }         if (debug)           cerr << string(__db_level * 2,    ) <<  [                 <<  i _ cur_ans                 <<  ] = [  << i <<  ,   << cur_ans <<  ]  << endl;         ans = max(ans, cur_ans);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char dat[1048576];   long long countSub(long long a, long long b, long long left, long long right,                      long long d) {     long long low = b * d - a;     if (low < 0) {       if (a % b != 0) {         low = b - a % b;       } else {         low = 0;       }     }     long long high = left + right;     if (low > high) return 0;     high -= (high - low) % b;     if (left > right) swap(left, right);     long long ans = 0;     long long firstcnt = 0, fb = low;     long long secondcnt = 0, sb = 0;     long long thirdcnt = 0, tb = 0;     if (fb <= left) {       if (high <= left) {         firstcnt = (high - fb) / b + 1;       } else {         firstcnt = (left - fb) / b + 1;       }     }     sb = fb + firstcnt * b;     if (high >= sb && sb <= right) {       if (high <= right) {         secondcnt = (high - sb) / b + 1;       } else if (high > right) {         secondcnt = (right - sb) / b + 1;       }     }     tb = sb + secondcnt * b;     if (high >= tb) {       thirdcnt = (high - tb) / b + 1;     }     if (firstcnt > 0)       ans += ((fb + 1) + (fb + (firstcnt - 1) * b + 1)) * firstcnt / 2;     if (secondcnt > 0) ans += ((left + 1) + (left + 1)) * secondcnt / 2;     if (thirdcnt > 0)       ans += ((left + right + 1 - (tb)) +               (left + right + 1 - (tb + (thirdcnt - 1) * b))) *              thirdcnt / 2;     return ans;   }   int main() {     scanf( %s , dat);     int n = (int)strlen(dat);     int n0 = 0, n1 = 0;     for (int i = 0; i < n; i++) {       if (dat[i] ==  0 ) {         n0++;       } else {         n1++;       }     }     long long ans = 0;     int maxratio = 0;     for (int ratio = 0; ratio <= 100 || 12 * ratio * ratio <= n; ratio++) {       maxratio = ratio;       long long depth = 0;       unordered_map<long long, int> cnt;       cnt.reserve(n + 10);       cnt[0] = 1;       for (int i = 0; i < n; i++) {         if (dat[i] ==  0 ) {           depth--;         } else {           depth += ratio;         }         ans += (cnt[depth]++);       }     }     vector<int> ones;     for (int i = 0; i < n; i++)       if (dat[i] ==  1 ) ones.emplace_back(i);     for (int i = 0; i < ones.size(); i++) {       for (int j = i; j < ones.size(); j++) {         int onecnt = j - i + 1;         if (onecnt * maxratio > n0) break;         int left = (i == 0 ? ones[0] : (ones[i] - ones[i - 1] - 1));         int right = (j + 1 == ones.size() ? (n - 1 - ones[j])                                           : (ones[j + 1] - ones[j] - 1));         int zerocnt = ones[j] - ones[i] + 1 - onecnt;         ans += countSub(zerocnt, onecnt, left, right, maxratio + 1);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, s[200005], d[200005], k;     while (cin >> n >> t) {       int maxx = 0x3f3f3f3f;       for (int i = 1; i <= n; i++) {         cin >> s[i] >> d[i];         int change = s[i];         while (change < t) {           change += d[i];         }         if (change - t < maxx) {           maxx = change - t;           k = i;         }       }       cout << k << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5;   const double eps = 1e-10;   int n, m, cnt, v[N], tr[N << 1];   double a[N], b[N];   pair<double, int> e[N << 1];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int lowbit(int x) { return x & (-x); }   void add(int x, int y) {     while (x <= cnt) tr[x] += y, x += lowbit(x);   }   int query(int x) {     int res = 0;     while (x) res += tr[x], x -= lowbit(x);     return res;   }   void work(double r) {     cnt = 0;     for (int i = 1; i <= n; i++) {       double a = ::a[i], b = ::b[i],              d = 4.0 * (a * a * b * b - (a * a + 1.0) * (b * b - r * r));       if (d < eps) continue;       d = sqrt(d);       double x = (-2.0 * a * b - d) / ((a * a + 1.0) * 2.0),              xx = (-2.0 * a * b + d) / ((a * a + 1.0) * 2.0);       double y = a * x + b, yy = a * xx + b;       e[++cnt] = make_pair(atan2(y, x), i);       e[++cnt] = make_pair(atan2(yy, xx), i);     }     sort(e + 1, e + cnt + 1);     for (int i = 1; i <= cnt; i++) v[e[i].second] = i;   }   int check(double r) {     work(r);     for (int i = 1; i <= cnt; i++) tr[i] = 0;     long long ans = 0;     for (int i = 1; i <= cnt; i++)       if (v[e[i].second] != i) {         ans += query(v[e[i].second]) - query(i - 1);         add(v[e[i].second], 1);       }     return ans >= m;   }   double calc(int i, int j) {     double x = (b[j] - b[i]) / (a[i] - a[j]), y = a[i] * x + b[i];     return sqrt(x * x + y * y);   }   double calc(double r) {     work(r);     set<pair<double, int> > s;     double ans = 0;     int tot = 0;     for (int i = 1; i <= cnt; i++)       if (v[e[i].second] != i) {         auto it = s.upper_bound(make_pair(i + 1, 0));         while (it != s.end() && it->first < v[e[i].second])           ans += calc(e[i].second, it->second), it++, tot++;         s.insert(make_pair(v[e[i].second], e[i].second));       }     return ans + (m - tot) * r;   }   int main() {     n = read();     double p = (double)read() / 1000.0, q = (double)read() / 1000.0;     m = read();     for (int i = 1; i <= n; i++) {       a[i] = (double)read() / 1000.0;       b[i] = (double)read() / 1000.0;       b[i] += a[i] * p - q;     }     double l = 0, r = 1e10;     for (int i = 1; i <= 100; i++) {       double mid = (l + r) / 2.0;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10f n , max((double)0, calc(r)));     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     string s;     string t;     cin >> s >> t;     string result(s);     int carry = 1;     for (int ii = s.length() - 1; ii >= 0; --ii) {       result[ii] = (char)(s[ii] + carry);       if (result[ii] >  z ) {         result[ii] =  a ;         carry = 1;       } else {         carry = 0;       }     }     if (result == t) {       cout <<  No such string  << endl;     } else {       cout << result << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s[100007];   long long l[100007];   int main() {     long long n, k, r = 0;     cin >> n >> k;     map<int, int> m;     map<int, int> e[10];     long long ki = 0;     for (int i = 0; i < n; i++) {       scanf( %I64d , &s[i]);       r += s[i] / 10;       if (s[i] != 100) {         m[10 - (s[i] % 10)]++;       }       if ((s[i] % 10) == 0) {         ki += (10 - s[i] / 10);       }       if (s[i] / 10 <= 9) {         e[s[i] / 10][10 - (s[i] % 10)]++;       }     }     map<int, int>::iterator it;     for (it = m.begin(); it != m.end() && k > 0; it++) {       long long gap = it->first;       if (gap == 10) {         break;       }       long long tot = it->second;       if (gap * tot <= k) {         if (gap < 10) {           k -= gap * tot;           r += tot;           m[10] += tot;           m[gap] = 0;           for (int i = 9; i > 0; i--) {             e[i][10] += e[i - 1][gap];             ki += (10 - i) * e[i - 1][gap];           }           m[10] -= e[9][gap];         } else if (gap == 10) {           r += tot;         }       } else {         r += (k / gap);         m[10] += (k / gap);         k = 0;       }     }     if (it != m.end() && k > 0) {       long long gap = it->first;       long long tot = it->second;       if (gap * ki <= k) {         r += ki;       } else {         r += (k / gap);       }     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[110];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> k;       for (int j = k; j <= n; ++j)         if (a[j] == 0) a[j] = k;     }     for (int i = 1; i <= n; ++i) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[10000], b, c, d, e, f, i, j, k, l, t;     cin >> t;     while (t--) {       d = 0;       cin >> b >> c;       for (i = 0; i < b; i++) {         cin >> a[i];         d += a[i];       }       if (d < c) {         cout << d << endl;       } else if (d >= c) {         cout << c << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string a, b;   void perform(int len) {     for (int i = 0; i < len / 2; ++i) {       if (a[i] == a[len - 1 - i]) {         a[i] =  0  +  1  - a[i];         a[len - 1 - i] =  0  +  1  - a[len - 1 - i];       }     }     if (len & 1) a[len / 2] =  0  +  1  - a[len / 2];   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> a >> b;       int k = 0;       vector<int> ops;       for (int i = n - 1; i >= 0; --i) {         if (a[i] != a[0]) perform(1), ++k, ops.push_back(1);         if (a[i] != b[i]) perform(i + 1), ++k, ops.push_back(i + 1);       }       cout << k <<    ;       for (int x : ops) cout << x <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   mt19937 rnd(time(nullptr));   const int N = 1e5 + 5;   unordered_set<int> g[N];   bool check(int v) {     for (auto i : g[v])       for (auto j : g[v])         if (i != j && !g[i].count(j)) return false;     cout <<  2 n  << v <<    ;     for (auto i : g[v]) cout << i <<    ;     cout <<   n ;     return true;   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) g[i].clear();     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       g[u].insert(v), g[v].insert(u);     }     set<pair<int, int> > st;     for (int i = 1; i <= n; ++i) {       st.insert({g[i].size(), i});     }     if ((long long)k * (k - 1) > 2 * m) {       cout <<  -1 n ;       return;     }     while (st.size()) {       pair<int, int> v = *st.begin();       if (v.first >= k) break;       if (v.first == k - 1 && check(v.second)) return;       st.erase(st.begin());       for (auto to : g[v.second]) {         st.erase({g[to].size(), to});         g[to].erase(v.second);         st.insert({g[to].size(), to});       }     }     if (st.size()) {       cout <<  1   << st.size() <<   n ;       for (auto v : st) cout << v.second <<    ;       cout <<   n ;     } else       cout <<  -1 n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, h, l, r, dp[2005][2005];   int main() {     scanf( %d%d%d%d , &n, &h, &l, &r);     memset(dp, 0xc0, sizeof(dp));     dp[0][0] = 0;     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       for (int j = 0; j < h; j++) {         dp[i][j] = max(dp[i][j], dp[i - 1][(j - x + h) % h] + (j >= l && j <= r));         dp[i][j] =             max(dp[i][j], dp[i - 1][(j - x + 1 + h) % h] + (j >= l && j <= r));       }     }     int ans = 0;     for (int i = 0; i < h; i++) ans = max(ans, dp[n][i]);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void File() {     freopen( output.txt ,  w , stdout);     freopen( input.txt ,  r , stdin);   }   int countDivisors(long long n) {     int cnt = 0;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt += 2;       }     }     return cnt;   }   int const N = 5e5 + 9, MOD = 1e9 + 7, oo = 1e9 + 7;   vector<vector<int>> adj(N);   vector<bool> visited(N);   vector<int> start(N), finish(N);   int n = 5;   long long arr[N];   int one, zero;   int main() {     cin >> n;     for (int i = 0; i < int(n); i++) cin >> arr[i];     sort(arr, arr + n);     for (int i = n - 1; i >= 0; i--) {       swap(arr[i], arr[n - 1]);       int l = i - 1;       int r = i + 1;       if (r == n) r = 0;       if (l == -1) l = n - 1;       if (arr[l] + arr[r] > arr[i]) {         cout <<  YES n ;         for (int i = 0; i < int(n); i++) cout << arr[i] <<    ;         return 0;       }       swap(arr[i], arr[n - 1]);     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n % 3 == 0 || n % 3 == 1) {       cout << 1 <<     << 1 <<     << n - 2;     } else {       cout << 1 <<     << 2 <<     << n - 3;     }     return 0;   }


#ifdef LOCAL   #include <prettyprint.hpp>   #endif   #include<bits/stdc++.h>   #define endl   n    #define all(x) x.begin(), x.end()   #define rall(x) x.rbegin(), x.rend()   #define lg2(x) __lg(x)   #define rem_dupl(x) sort(all(x)); x.erase(unique(all(x)), x.end())   using namespace std;      typedef long long ll;   typedef double db;   typedef pair<int,int> ii;   #define x first   #define y second      mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());      const db eps = 1e-9;   const int maxn = (int)2e5 + 5;   const ll mod = (int)1e9 + 7; // 998244353      int main() {       ios_base::sync_with_stdio(0); cin.tie(0);       cout.setf(ios::fixed); cout.precision(0);          int n, m, p;       cin >> n >> m >> p;       vector<ll> a(n);       for(auto &x:a){           x = 0;           for(int i = 0; i < m; i++){               char j; cin >> j;               if(j ==  1 )                   x |= (1ll<<i);           }       }          ll ans = 0;          for(int iter = 0; iter < 50; iter++){              ll s = a[rand32() % n];           vector<int> bits;              for(int i = 0; i < m; i++)               if(s & (1ll<<i))                   bits.push_back(i);              int p = bits.size();               vector<int>cnt(1<<p, 0), cnt2(1<<p, 0);              for(auto &x:a){               int y = 0;               for(int i = 0; i < p; i++){                   if(x & (1ll<<bits[i]))                       y |= (1<<i);               }               cnt[y]++;           }              for(int mask = (1<<p) - 1; mask >= 0; mask--){                 for(int s = mask; s; s = (s - 1) & mask){                   cnt2[s] += cnt[mask];               }           }               for(int mask = 0; mask < (1<<p); mask++){               if(2*cnt2[mask] >= n){                   if(__builtin_popcountll(ans) < __builtin_popcount(mask)){                       ans = 0;                       for(int i = 0; i < p; i++)                           if(mask & (1ll<<i))                               ans |= (1ll<<bits[i]);                   }               }           }       }                for(int i = 0; i < m; i++)           cout << ((ans >> i) & 1);              return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, x, y, cnt;   void RUL(int);   void DLU(int);   void LDR(int);   void URD(int);   void disp_res(int x, int y) {     printf( %d %d n , x, y);     exit(0);   }   void RUL(int n) {     if (cnt == b) {       disp_res(x, y);     };     if (n <= 0) return;     URD(n - 1);     x += 1;     cnt++;     RUL(n - 1);     y += 1;     cnt++;     RUL(n - 1);     x -= 1;     cnt++;     DLU(n - 1);   }   void DLU(int n) {     if (cnt == b) {       disp_res(x, y);     };     if (n <= 0) return;     LDR(n - 1);     y -= 1;     cnt++;     DLU(n - 1);     x -= 1;     cnt++;     DLU(n - 1);     y += 1;     cnt++;     RUL(n - 1);   }   void LDR(int n) {     if (cnt == b) {       disp_res(x, y);     };     if (n <= 0) return;     DLU(n - 1);     x -= 1;     cnt++;     LDR(n - 1);     y -= 1;     cnt++;     LDR(n - 1);     x += 1;     cnt++;     URD(n - 1);   }   void URD(int n) {     if (cnt == b) {       disp_res(x, y);     };     if (n <= 0) return;     RUL(n - 1);     y += 1;     cnt++;     URD(n - 1);     x += 1;     cnt++;     URD(n - 1);     y -= 1;     cnt++;     LDR(n - 1);   }   int main() {     cnt = 0;     x = 0, y = 0;     scanf( %d %d , &a, &b);     URD(a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int n;     cin >> n;     long long int a[n];     long long int mx = 0;     long long int sum = 0;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       mx = max(mx, a[i]);       sum += a[i];     }     long long int aa = sum;     long long int bb = n - 1;     long long int ans = (aa + bb - 1) / (bb);     cout << max(ans, mx) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int dx4[] = {1, 0, -1, 0};   int dy4[] = {0, 1, 0, -1};   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 <<   n ;     ;   }   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...);   }   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &a) {     return out <<  (  << a.first <<  ,  << a.second <<  ) ;   }   template <class A>   ostream &operator<<(ostream &out, const vector<A> &a) {     for (const A &it : a) out << it <<    ;     return out;   }   template <class A, class B>   istream &operator>>(istream &in, pair<A, B> &a) {     return in >> a.first >> a.second;   }   template <class A>   istream &operator>>(istream &in, vector<A> &a) {     for (A &i : a) in >> i;     return in;   }   template <typename T, typename T1>   T amax(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T &a, T1 b) {     if (b < a) a = b;     return a;   }   void solve() {     long long n, m, k;     cin >> n >> m >> k;     multiset<long long> mp;     vector<long long> v(n);     cin >> v;     vector<long long> t = v;     sort((t).begin(), (t).end(), greater<long long>());     long long sum = 0;     for (long long i = 0; i < m * k; i++) {       mp.insert(t[i]);       sum += t[i];     }     int i = 0;     vector<long long> res;     while (i < n) {       int j = i;       int cnt = 0;       while (j < n && cnt < m) {         if (mp.find(v[j]) != mp.end()) {           mp.erase(mp.find(v[j]));           cnt++;         }         j++;       }       res.push_back(j);       if ((int)((mp).size()) == m) {         break;       }       i = j;     }     cout << sum <<   n ;     ;     cout << res <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const MAX_N = 100001;   int main() {     int n, m;     cin >> n >> m;     vector<int> v;     vector<int> u;     int t = m;     for (int i = 0; i < m; i++) {       v.push_back((i + 1));     }     for (int i = 0; i < m; i++) {       u.push_back(v[(int)((v.size() + 1) / 2) - 1]);       v.erase(v.begin() + (int)((v.size() + 1) / 2) - 1);     }     for (int i = 0; i < n; i++) {       cout << u[i - m * ((int)i / m)] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9 + 10;   const int MOD = 1e9 + 7;   const int N = 1e3 + 10;   int n, k;   int a[N];   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     if ((a[1] & 1) && (a[n] & 1) && (n & 1))       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int M = 1000000000;   char s[30];   bool answer(int x, int y) {     printf( %d %d n , x, y);     fflush(stdout);     scanf( %s , s);     return s[0] ==  b ;   }   int n;   int main() {     scanf( %d , &n);     bool ty = answer(0, M / 2);     int vl = 0, vr = M;     int l = 1, r = M;     for (int i = 1; i < n; i++) {       int mid = (l + r) >> 1;       bool ty2 = answer(mid, M / 2);       if (ty2 == ty) {         vl = max(vl, mid);         l = mid + 1;       } else {         vr = min(vr, mid);         r = mid - 1;       }     }     printf( %d %d %d %d n , vl, 0, vr, M);   }


#include <bits/stdc++.h>   using namespace std;   int sum[64];   long long a[200200];   long long calc() {     long long ans = 0;     for (int i = 0; i < 64; i++) {       ans += (1LL << i) * (sum[i] > 0);     }     return ans;   }   int main() {     int n, k, x;     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) {       scanf( %I64d , a + i);       for (int j = 0; j < 32; j++) {         sum[j] += ((a[i] >> j) & 1LL);       }     }     long long ans = calc();     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 32; j++) {         sum[j] -= ((a[i] >> j) & 1LL);       }       long long b = a[i];       for (int j = 0; j < k; j++) b *= x;       for (int j = 0; j < 64; j++) {         sum[j] += ((b >> j) & 1LL);       }       ans = max(ans, calc());       for (int j = 0; j < 32; j++) {         sum[j] += ((a[i] >> j) & 1LL);       }       for (int j = 0; j < 64; j++) {         sum[j] -= ((b >> j) & 1LL);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<int> v;   long long s[100100];   void init() {     scanf( %d , &n);     scanf( %d , &k);     v.resize(1 + n);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     sort(v.begin() + 1, v.end());     v[0] = 0;     s[0] = v[0];     for (int i = 1; i <= n; i++) s[i] = s[i - 1] + v[i];     int pos = 1, sol = 1, best = 1, val = v[1];     for (int i = 2; i <= n; i++) {       while ((long long)(i - pos + 1) * v[i] - (s[i] - s[pos - 1]) > k) pos++;       if (i - pos + 1 > best) {         best = i - pos + 1;         val = v[i];       }     }     cout << best <<     << val << endl;   }   int main() {     init();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long a[60][60], b[60][60], n, m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> b[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         long long mn = min(a[i][j], b[i][j]);         long long mx = max(a[i][j], b[i][j]);         a[i][j] = mn;         b[i][j] = mx;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])           return cout <<  Impossible , 0;         if (b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])           return cout <<  Impossible , 0;       }     }     cout <<  Possible ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000007;   vector<int> edg[MAX];   int lvl[MAX];   multiset<int>* msets[MAX];   int k;   void mergesets(int frm, int to, int height) {     if (msets[frm]->size() > msets[to]->size()) {       swap(msets[frm], msets[to]);     }     height *= 2;     for (int x : *msets[frm]) {       int g = *(msets[to]->begin());       if (g + x - height > k) {         msets[to]->insert(x);         continue;       }       g = max(g, x);       msets[to]->erase(msets[to]->begin());       msets[to]->insert(g);     }     msets[frm]->clear();   }   void dfs(int u, int p = 0) {     lvl[u] = lvl[p] + 1;     msets[u] = new multiset<int>();     if (edg[u].size() == 1) {       msets[u]->insert(lvl[u]);     }     for (int v : edg[u]) {       if (v == p) continue;       dfs(v, u);       mergesets(v, u, lvl[u]);     }   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       edg[u].push_back(v);       edg[v].push_back(u);     }     int r = 1;     for (int i = 2; i <= n; i++) {       if (edg[i].size() > edg[r].size()) {         r = i;       }     }     dfs(r);     cout << msets[r]->size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, cnt1 = 0;     cin >> n >> k;     int y = k + 1;     bool ab[y], a = false;     for (int i = 0; i < y; i++) ab[i] = false;     for (int i = 0; i < n; i++) {       string x;       cin >> x;       for (int j = 0; j < x.length(); j++) {         int h = x[j] -  0 ;         ab[h] = true;       }       for (int l = 0; l < k + 1; l++)         if (ab[l] == false) a = true;       if (!a) {         cnt1++;       }       if (a) a = false;       fill(ab, ab + y, false);     }     cout << cnt1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643383279;   const long double EPS = 1e-6;   const int INF = 1e9 + 7;   const long long MOD = INF;   const long long maxn = 5e5 + 2;   const long long HASH_MODS[] = {1000000007333, 1000000009367, 1000000075747,                                  1000000158923, 1000000203119};   int n, m;   int num[maxn];   int f[maxn];   int child[maxn];   int tin[maxn];   int tout[maxn];   int cnt = 0;   int timer;   string s;   vector<pair<int, int> > hsh[maxn];   void add_edge(int a, int b) {     child[++cnt] = b;     num[cnt] = f[a];     f[a] = cnt;   }   void dfs(int v, int h) {     tin[v] = ++timer;     hsh[h].push_back({timer, hsh[h].back().second ^ (1 << (s[v] -  a ))});     for (int e = f[v]; e; e = num[e]) {       dfs(child[e], h + 1);     }     tout[v] = ++timer;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = (0); i < (n); ++i) hsh[i].resize(1);     for (int i = (1); i < (n); ++i) {       int t;       cin >> t;       add_edge(t - 1, i);     }     cin >> s;     dfs(0, 0);     while (m--) {       int v, h;       cin >> v >> h;       v--;       h--;       int l = lower_bound(hsh[h].begin(), hsh[h].end(), make_pair(tin[v], -1)) -               hsh[h].begin() - 1;       int r = lower_bound(hsh[h].begin(), hsh[h].end(), make_pair(tout[v], -1)) -               hsh[h].begin() - 1;       int t = hsh[h][r].second ^ hsh[h][l].second;       bool ok = t - (t & -t);       if (!ok)         cout <<  Yes n ;       else         cout <<  No n ;     }   }


#include <bits/stdc++.h>   using namespace std;   char inp[5];   void try_catch(long long int l, long long int r) {     long long int mid = l + rand() % (r - l + 1);     printf( %lld %lld n , mid, mid);     fflush(stdout);     scanf( %s , inp);     if (inp[0] ==  Y ) exit(0);   }   int main() {     srand(time(NULL));     long long int n, k;     cin >> n >> k;     long long int l = 1, r = n;     while (1) {       while (r - l < 60) {         try_catch(max(1LL, l - k), min(n, r + k));         l = max(1LL, l - 2 * k);         r = min(n, r + 2 * k);       }       long long int mid = (l + r) / 2;       printf( %lld %lld n , l, mid);       fflush(stdout);       scanf( %s , inp);       if (inp[0] ==  Y ) {         if (l == mid) exit(0);         r = min(n, mid + k);         l = max(1LL, l - k);       } else {         l = max(1LL, mid - k);         r = min(n, r + k);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 10;   int d[M];   long long int pred[M];   long long int a[M];   long long int dp[110][M];   long long int pres[M];   long long int dq[M];   long long int yk(int i, int k) {     long long int val = dp[i][k] + pres[k];     return val;   }   int main() {     int n, m, p;     cin >> n >> m >> p;     for (int i = 2; i <= n; i++) {       cin >> d[i];       pred[i] = pred[i - 1] + d[i];     }     for (int i = 1; i <= m; i++) {       int h, t;       cin >> h >> t;       int val = t - pred[h];       a[i] = val;     }     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) {       pres[i] = pres[i - 1] + a[i];     }     for (int i = 1; i <= m; i++) {       dp[1][i] = (i - 0) * a[i] - (pres[i] - pres[0]);     }     for (int i = 2; i <= p; i++) {       int s = 0;       int t = 0;       for (int j = 1; j <= m; j++) {         while ((t - s) >= 2 &&                (yk(i - 1, dq[t - 1]) - yk(i - 1, dq[t - 2])) * (j - dq[t - 1]) >                    (yk(i - 1, j) - yk(i - 1, dq[t - 1])) *                        (dq[t - 1] - dq[t - 2])) {           t--;         }         dq[t] = j;         t++;         while ((t - s) >= 2 &&                dp[i - 1][dq[s]] - dq[s] * a[j] + pres[dq[s]] >                    dp[i - 1][dq[s + 1]] - dq[s + 1] * a[j] + pres[dq[s + 1]]) {           s++;         }         dp[i][j] =             dp[i - 1][dq[s]] + (j - dq[s]) * a[j] - (pres[j] - pres[dq[s]]);       }     }     cout << dp[p][m] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, t;   int TM[maxn], wait, ans;   priority_queue<int> in;   int main() {     scanf( %d%d , &n, &t);     for (int i = 1; i <= n; ++i) scanf( %d , &TM[i]);     for (int i = 1; i <= n + 1; ++i) {       wait = t - i;       if (wait < 0) break;       while (!in.empty() && in.top() > wait) in.pop();       ans = max(ans, (int)in.size());       in.push(TM[i] - i);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void run() {     int n;     scanf( %d , &n);     if (n & 1)       printf( %d %d n , 9, n - 9);     else       printf( %d %d n , 4, n - 4);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k;     cin >> n >> k;     string a;     cin >> a;     bool no = false;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  N  && (i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) {         int count = 0;         int j;         for (j = i; j < i + k; j++) {           if (a[j] ==  N )             count++;           else             break;         }         if (count == k && j < a.size() && a[j] ==  N ) {           cout <<  NO ;           return 0;         }       }     }     for (int i = 0; i < a.size(); i++) {       if ((i + k) <= a.size() && (i == 0 || a[i - 1] !=  N )) {         int count = 0;         int j;         for (j = i; j < i + k; j++) {           if (a[j] ==  ?  || a[j] ==  N )             count++;           else             break;         }         if (count == k && (i + k == a.size() || a[j] !=  N )) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   int a, n, m, k, p;   int main() {     std::cin >> n >> m, a = 0, p = 1;     for (int i = 1; i <= n; ++i) {       std::cin >> k;       if (a + k <= m)         a += k;       else         a = k, ++p;     }     std::cout << p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T, class U>   inline void print(T first, U second) {     printsp(first);     println(second);   }   template <class T, class U, class V>   inline void print(T first, U second, V z) {     printsp(first);     printsp(second);     println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int fail[101010];   char s[101010], s1[101010], t[101010], t1[101010], s2[101010];   void build_fail_function(char B[], int len) {     int j = fail[0] = -1;     for (int i = 1; i < len; i++) {       while (j != -1 and B[j + 1] != B[i]) j = fail[j];       if (B[j + 1] == B[i]) j++;       fail[i] = j;     }   }   int main() {     int n;     gn(n);     scanf( %s%s , s, t);     strcpy(s1, s);     strcpy(t1, t);     sort(s1, s1 + n);     sort(t1, t1 + n);     if (strcmp(s1, t1)) return puts( -1 ), 0;     int now = 0, m;     vector<int> ans;     char *p, *q;     while (now < n) {       while (now < n && s[now] == t[now]) now++;       q = s + now;       m = n - now;       p = t + now;       build_fail_function(p, m);       int j = -1, res = 0, k = -1;       for (int i = 0; i < m; i++) {         while (j != -1 and p[j + 1] != q[i]) j = fail[j];         if (p[j + 1] == q[i]) j++;         if (res < j + 1) res = j + 1, k = i;         if (j == m - 1) j = fail[j];       }       int A = now, B = k + 1 - res, C = res, D = n - A - B - C;       ans.push_back(n);       if (A + B) ans.push_back(A + B);       ans.push_back(n);       if (A) ans.push_back(A);       for (int i = 0; i < B; i++) s1[i] = q[B - 1 - i];       s1[B] = 0;       for (int i = 0; i < D; i++) t1[i] = q[i + k + 1];       t1[D] = 0;       for (int i = 0; i < C; i++) s2[i] = q[k - res + 1 + i];       s2[C] = 0;       for (int i = 0; i < C; i++) *q = s2[i], q++;       for (int i = 0; i < D; i++) *q = t1[i], q++;       for (int i = 0; i < B; i++) *q = s1[i], q++;       now += res;     }     println(ans.size());     for (int i = 0; i < ans.size(); i++) printsp(ans[i]);     puts(  );     assert(strcmp(s, t) == 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long a[(long long)1e5 + 10];   long long b[(long long)1e5 + 10];   long long c[(long long)1e5 + 10];   long long d[(long long)1e5 + 10];   int main() {     cin >> n >> m >> k;     for (long long i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> c[i];     }     for (long long i = 0; i < k; i++) {       cin >> d[i];     }     long long sum = 0;     for (long long i = 0; i < k; i++) {       for (long long j = 0; j < m; j++) {         if (a[j] <= d[i] && d[i] <= b[j]) {           sum += c[j] + d[i] - a[j];         }       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXK = 1 << 12;   const int P = 7340033;   const int G = 3;   const int MAXH = 30;   int dp[MAXH + 7][MAXK + 7], buff[MAXK + 7];   int qpow(int a, int b) {     if (b == 0) return 1;     if (a == 0) return 0;     int aux = qpow(1LL * a * a % P, b >> 1);     if (b & 1) aux = 1LL * aux * a % P;     return aux;   }   inline int inv(int x) { return qpow(x, P - 2); }   void NTT(int *a, int N, int dir) {     int t = 0;     for (int i = (0); i <= (N - 1); ++i) {       if (t < i) swap(a[t], a[i]);       for (int j = (N >> 1); (t ^= j) < j; j >>= 1)         ;     }     for (int i = 2; i <= N; i <<= 1) {       int wn = qpow(G, (P - 1) / i);       for (int j = 0; j < N; j += i) {         int w = 1, t;         for (int k = 0; k < (i >> 1); k++, w = 1LL * w * wn % P) {           t = 1LL * w * a[j + k + (i >> 1)] % P;           a[j + k + (i >> 1)] = a[j + k] - t;           a[j + k] = a[j + k] + t;           if (a[j + k + (i >> 1)] < 0) a[j + k + (i >> 1)] += P;           if (a[j + k] >= P) a[j + k] -= P;         }       }     }     if (dir == -1) {       for (int i = 1; i < (N >> 1); i++) swap(a[i], a[N - i]);       int INV_N = inv(N);       for (int i = (0); i <= (N - 1); ++i) a[i] = 1LL * a[i] * INV_N % P;     }   }   void pre() {     dp[0][0] = 1;     for (int i = (1); i <= (MAXH); ++i) {       memset(buff, 0, sizeof(buff));       for (int j = (0); j <= (1000); ++j) buff[j] = dp[i - 1][j];       NTT(buff, MAXK, 1);       for (int j = (0); j <= (MAXK); ++j) buff[j] = qpow(buff[j], 4);       NTT(buff, MAXK, -1);       for (int j = (1); j <= (1000); ++j) dp[i][j] = buff[j - 1];       dp[i][0] = 1;     }   }   inline int height(int N) {     int h = 0;     while (N > 1 && N & 1) {       ++h;       N = (N - 1) >> 1;     }     return h;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     int Q;     cin >> Q;     while (Q--) {       int n, k;       cin >> n >> k;       cout << dp[height(n)][k] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0;     string s;     cin >> n;     cin.ignore();     for (int i = 1; i <= n; i++) {       getline(cin, s);       if (s[1] ==  + ) {         x++;         continue;       }       if (s[1] ==  - ) {         x--;         continue;       }     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long POW(long long a, long long b, long long MMM = MOD) {     long long ret = 1;     for (; b; b >>= 1, a = (a * a) % MMM)       if (b & 1) ret = (ret * a) % MMM;     return ret;   }   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) {     if (a == 0 || b == 0) return a + b;     return a * (b / gcd(a, b));   }   int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1};   int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};   int main() {     int n;     scanf( %d , &n);     puts( YES );     while (n--) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       printf( %d n , (x1 & 1) % 2 + ((y1 & 1) % 2) * 2 + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, n, day, ans, flag;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     day = 1;     ans = 0;     j = 0;     while (1) {       flag = 0;       for (i = j; i < n; i++) {         if (a[i] >= day) {           j = i + 1;           flag = 1;           ans++;           break;         }       }       if (flag == 0) break;       day++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long t = bin_pow(a, b / 2);       return t * t % 1000000007;     } else       return a * bin_pow(a, b - 1) % 1000000007;   }   vector<long long> graph[500000];   bool used[500000];   long long w[500000], comp;   map<pair<long long, long long>, long long> mp1;   void dfs(long long v) {     used[v] = 1;     comp++;     for (auto u : graph[v]) {       if (w[u] == 0 || used[u] || mp1[{u, v}] == 0) continue;       dfs(u);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0,               ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;     cin >> n >> m >> k;     vector<long long> a(n), b;     map<long long, vector<pair<long long, long long>>> mp;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       z = a[x] ^ a[y];       b.push_back(z);       mp[z].push_back({x, y});       graph[x].push_back(y);       graph[y].push_back(x);     }     sort(b.begin(), b.end());     b.erase(unique(b.begin(), b.end()), b.end());     for (int i = 0; i < b.size(); i++) {       z = b[i];       long long k1 = 0;       l = 0;       for (auto u : mp[z]) {         x = u.first, y = u.second;         w[x] = w[y] = 1;         mp1[{x, y}] = mp1[{y, x}] = 1;       }       for (auto u : mp[z]) {         x = u.first, y = u.second;         if (used[x]) continue;         comp = 0;         dfs(x);         l += comp;         k1++;       }       x = bin_pow(2, n - l) * bin_pow(2, k1) % 1000000007;       ans += x;       ans %= 1000000007;       for (auto u : mp[z]) {         x = u.first, y = u.second;         w[x] = w[y] = used[x] = used[y] = 0;         mp1[{x, y}] = mp1[{y, x}] = 0;       }     }     t = ((bin_pow(2, k) - (long long)b.size()) % 1000000007 + 1000000007) %         1000000007;     t *= bin_pow(2, n);     t %= 1000000007;     ans += t;     ans %= 1000000007;     cout << ans;     return 0;   }


#include <iostream>      using namespace std;      long long n,mod;   long long cnt[55][2505];   long long cntS[55][2505];   long long per[55];   long long ans[55];      void calcCnt()   {       cnt[0][0]=1;          for(int i=1;i<=n;i++)       {           for(int inv=0;inv<=i*i;inv++)               for(int nval=1;nval<=i;nval++)               {                   if(inv>=i-nval)                   {                       cnt[i][inv]+=cnt[i-1][inv-(i-nval)];                       cnt[i][inv]%=mod;                   }               }              cntS[i][0]=cnt[i][0];           for(int inv=1;inv<=i*i;inv++)               cntS[i][inv]=(cntS[i][inv-1]+cnt[i][inv])%mod;       }   }      void calcPer()   {       for(int i=1;i<=n;i++)           for(int dif=1;dif<i;dif++)           {               long long nr=i-dif;               for(int invP=dif+1;invP<=i*i;invP++)               {                   long long nans=cnt[i-1][invP]*cntS[i-1][invP-dif-1];                   nans%=mod;                   nans*=nr;                   nans%=mod;                      per[i]+=nans;                   per[i]%=mod;               }           }   }   void calcAns()   {       for(int i=1;i<=n;i++)       {           ans[i]=i*ans[i-1]+per[i];           ans[i]%=mod;       }   }   int main()   {       cin>>n>>mod;          calcCnt();       calcPer();       calcAns();          cout<<ans[n];       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, k, p, len, n;     cin >> n >> k >> s;     int arr[30] = {0};     char x =  a ;     for (i = 0; i < 26; i++) {       x =  a  + i;       p = 0;       for (j = 0; j < n; j++) {         if (s[j] == x)           p++;         else           p = 0;         if (p == k) {           arr[i]++;           p = 0;         }       }     }     p = 0;     for (i = 0; i < 26; i++) {       p = max(p, arr[i]);     }     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n;   int f[MAXN];   bool read() {     if (scanf( %d , &n) < 1) {       return 0;     }     for (int i = 0; i < int(n); ++i) {       scanf( %d , &f[i]);       --f[i];     }     return 1;   }   vector<int> inv_f[MAXN];   int g[MAXN];   int h[MAXN];   bool solve() {     for (int i = 0; i < int(n); ++i) {       inv_f[i].clear();     }     for (int i = 0; i < int(n); ++i) {       inv_f[f[i]].push_back(i);     }     memset(g, -1, sizeof g);     int m = 0;     for (int i = 0; i < int(n); ++i) {       if (inv_f[i].empty()) {         continue;       }       if (f[i] != i) {         return 0;       }       for (int j : inv_f[i]) {         g[j] = m;       }       h[m] = i;       ++m;     }     for (int x = 0; x < int(m); ++x) {       assert(g[h[x]] == x);     }     for (int x = 0; x < int(n); ++x) {       assert(h[g[x]] == f[x]);     }     printf( %d n , m);     for (int i = 0; i < int(n); ++i) {       printf( %d  , g[i] + 1);     }     puts(  );     for (int i = 0; i < int(m); ++i) {       printf( %d  , h[i] + 1);     }     puts(  );     return 1;   }   int main() {     while (read()) {       if (!solve()) {         puts( -1 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (1 << 22) + 5;   int full, n, m;   bool v[MAX], b[MAX], h[MAX];   void dfsans(int now);   void dfs(int now) {     if (v[now]) return;     v[now] = true;     if (h[now]) dfsans(now);     for (int i = 0; i < n; i++) {       if (!(now & (1 << i))) continue;       dfs(now ^ (1 << i));     }   }   void dfsans(int now) {     if (b[now]) return;     b[now] = true;     dfs(now ^ full);   }   int main() {     scanf( %d%d , &n, &m);     full = (1 << n) - 1;     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       h[x] = true;     }     int ans = 0;     for (int i = 0; i < (full + 1); i++) {       if (!h[i] || b[i]) continue;       ans++;       dfsans(i);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];         a[i]--;       }       vector<long long int> pos(n);       for (long long int i = 0; i < n; i++) {         pos[a[i]] = i;       }       long long int mnpos = pos[0];       long long int mx = pos[0];       vector<long long int> ans(n);       for (long long int i = 0; i < n; i++) {         mnpos = min(mnpos, pos[i]);         mx = max(mx, pos[i]);         if (mx - mnpos == i) {           ans[i] = 1;         } else {           ans[i] = 0;         }       }       for (long long int x : ans) cout << x;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (1) {       if (a == b) {         cout <<  YES n ;         return 0;       }       if (a == x || b == y) {         break;       }       if (++a > n) {         a = 1;       }       if (--b < 1) {         b = n;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000;   int c[MAXN + 10], d[MAXN + 10], l[MAXN + 10], r[MAXN + 10];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; ++i) {       cin >> x[i];       ++c[x[i]];     }     for (int i = 1; i <= MAXN; ++i) {       if (c[i] == 0) continue;       if (c[i] == 1) {         d[i] = 0;         l[i] = 1;       } else {         d[i] = c[i];         l[i] = d[i] + l[i - 1];       }     }     memset(d, 0, sizeof(d));     for (int i = MAXN; i >= 1; --i) {       if (c[i] == 0) continue;       if (c[i] == 1) {         d[i] = 0;         r[i] = 1;       } else {         d[i] = c[i];         r[i] = d[i] + r[i + 1];       }     }     int ans = 0, p = -1;     for (int i = 1; i <= MAXN; ++i) {       if (l[i] + r[i] - c[i] > ans) {         ans = l[i] + r[i] - c[i];         p = i;       }     }     if (ans == 1) {       for (int i = 1; i + 1 <= MAXN; ++i) {         if (c[i] > 0 && c[i + 1] > 0) {           cout << 2 << endl;           cout << i <<     << i + 1 << endl;           return 0;         }       }       cout << ans << endl;       cout << p << endl;       return 0;     }     vector<int> cir;     int q = p;     while (c[p] > 1) {       cir.push_back(p);       --c[p];       ++p;     }     while (p > q) {       while (c[p] > 0) {         cir.push_back(p);         --c[p];       }       --p;     }     cir.push_back(p);     --c[p];     --p;     while (c[p] > 1) {       cir.push_back(p);       --c[p];       --p;     }     while (p <= q) {       while (c[p] > 0) {         cir.push_back(p);         --c[p];       }       ++p;     }     cout << ans << endl;     for (int i : cir) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, q;   pair<int, int> pro[100010];   long long cross(int x1, int y1, int x2, int y2) {     return x1 * (long long)y2 - x2 * (long long)y1;   }   double cross2(double x1, double y1, double x2, double y2) {     return x1 * y2 - x2 * y1;   }   bool check(pair<int, int> c, pair<int, int> b, pair<int, int> a) {     return cross(b.first - a.first, b.second - a.second, c.first - b.first,                  c.second - b.second) >= 0;   }   pair<int, int> st[100010];   int tp = -1;   int main() {     scanf( %d%d%d , &n, &p, &q);     int maxa = 0, maxb = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &pro[i].first, &pro[i].second);       maxa = max(maxa, pro[i].first);       maxb = max(maxb, pro[i].second);     }     sort(pro + 1, pro + n + 1);     st[++tp] = make_pair(0, maxb);     for (int i = 1; i <= n; i++) {       while (tp > 0 && check(pro[i], st[tp], st[tp - 1])) tp--;       st[++tp] = pro[i];     }     st[++tp] = make_pair(maxa, 0);     int line;     for (int i = 0; i < tp; i++) {       if ((atan2(q, p) - atan2(st[i + 1].second, st[i + 1].first) >= -1e-9) &&           (atan2(st[i].second, st[i].first) - atan2(q, p) >= -1e-9))         line = i;     }     double lo = 0, hi = 1e6;     while (lo < hi - 1e-9) {       double mi = (lo + hi) / 2;       if ((0 - cross2(p / mi - st[line].first, q / mi - st[line].second,                       p / mi - st[line + 1].first,                       q / mi - st[line + 1].second) >=            -1e-9))         hi = mi;       else         lo = mi;     }     printf( %.10f n , lo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, x, c = 0, value[1000001], sign[1000001];   stack<int> s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &value[i]);       sign[i] = 1;     }     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       scanf( %d , &x);       sign[x] = -1;     }     for (int i = n; i >= 1; i--) {       if (sign[i] == -1) {         s.push(i);       } else {         if (!s.empty() && value[i] == value[s.top()]) {           s.pop();         } else {           s.push(i);           sign[i] = -1;         }       }     }     if (!s.empty()) {       printf( NO );     } else {       printf( YES n );       for (int i = 1; i <= n; i++) {         printf( %d  , value[i] * sign[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, j, a = 0, b = 0, c, k, n;     std::vector<int> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> k;       for (j = 0; j < k / 2; j++) cin >> c, a += c;       if (k & 1) cin >> c, v.push_back(c);       for (j = 0; j < k / 2; j++) cin >> c, b += c;     }     sort(v.begin(), v.end(), greater<int>());     for (i = 0; i < v.size(); i++)       if (i & 1)         b += v[i];       else         a += v[i];     cout << a <<     << b;   }