#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long inf64 = 1e18;   const int mod = inf + 7;   inline int _sum(int a, int b) { return a + b < mod ? a + b : a + b - mod; }   inline int _mul(int a, int b) { return (1ll * a * b) % mod; }   inline int _sub(int a, int b) { return a >= b ? a - b : a - b + mod; }   inline void _inc(int& x, int y) {     if ((x += y) >= mod) {       x -= mod;     }   }   inline void _dec(int& x, int y) {     if ((x -= y) < 0) {       x += mod;     }   }   inline int _binpow(int x, int pw) {     int res = 1;     int tmp = x;     while (pw > 0) {       if (pw & 1) {         res = _mul(res, tmp);       }       tmp = _mul(tmp, tmp);       pw >>= 1;     }     return res;   }   inline int _div(int a, int b) { return _mul(a, _binpow(b, mod - 2)); }   void read(string& s) { cin >> s; }   void gen(string& s) {     mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());     int n = 2 * (rnd() % 3 + 1);     s.resize(n,  ? );     for (int i = 0; i < n; i++) {       s[i] = rnd() % 5 == 0 ?  a  :  b ;     }   }   string join_halfs(string s) {     int n = (int)s.size();     string t;     for (int i = 0; i < n / 2; i++) {       t.push_back(s[i]);       t.push_back(s[n - 1 - i]);     }     return t;   }   int slow(string s) {     s = join_halfs(s);     int n = (int)s.size();     s =  #  + s;     vector<int> dp(n + 1);     dp[0] = 1;     cout << s <<   n ;     for (int i = 1; i <= n; i++) {       for (int j = i; j >= 1; j--) {         if ((i - j + 1) % 2) continue;         string hlp = s.substr(j, i - j + 1);         string rhlp = hlp;         reverse(rhlp.begin(), rhlp.end());         if (hlp == rhlp) {           _inc(dp[i], dp[j - 1]);         }       }     }     return dp[n];   }   const int N = 2e6 + 5;   struct Node {     map<int, int> nxt;     int link = -1;     int dp = 0;     int slink = -1;     int len = 0;     int diff = 0;     Node() = default;   };   Node t[N];   int sz, max_suff;   int fast(string s) {     {       sz = 0;       t[sz++] = Node();       t[sz++] = Node();       max_suff = 1;       t[0].link = 1;       t[1].link = 0;       t[0].len = -1;       t[1].len = 0;     }     int n = (int)s.size();     s =  #  + join_halfs(s);     vector<int> dp(n + 1);     dp[0] = 1;     max_suff = 1;     for (int i = 1; i <= n; i++) {       {         while (s[i] != s[i - t[max_suff].len - 1]) {           max_suff = t[max_suff].link;         }         if (!t[max_suff].nxt.count(s[i])) {           t[sz++] = Node();           t[sz - 1].len = t[max_suff].len + 2;           int next_max_suff = t[max_suff].link;           while (s[i] != s[i - t[next_max_suff].len - 1]) {             next_max_suff = t[next_max_suff].link;           }           t[sz - 1].link =               t[next_max_suff].nxt.count(s[i]) ? t[next_max_suff].nxt[s[i]] : 1;           t[sz - 1].diff = t[sz - 1].len - t[t[sz - 1].link].len;           if (t[sz - 1].diff == t[t[sz - 1].link].diff) {             t[sz - 1].slink = t[t[sz - 1].link].slink;           } else {             t[sz - 1].slink = t[sz - 1].link;           }           t[max_suff].nxt[s[i]] = sz - 1;         }         max_suff = t[max_suff].nxt[s[i]];       }       for (int x = max_suff; t[x].len > 0; x = t[x].slink) {         {           int j = i - t[t[x].slink].len - t[x].diff;           t[x].dp = dp[j];         }         if (t[x].diff == t[t[x].link].diff) {           _inc(t[x].dp, t[t[x].link].dp);         }         if (i % 2 == 0) {           _inc(dp[i], t[x].dp);         }       }     }     return dp[n];   }   void WORK() {     string s;     read(s);     cout << fast(s) <<   n ;   }   void TEST() {     while (1) {       string s;       gen(s);       cout <<  s =   << s << endl;       int sl = slow(s);       int fs = fast(s);       if (sl == fs) {         cout <<  OK (  << fs <<  )  << endl;       } else {         cout <<  WA  << endl;         cout <<  exp =   << sl << endl;         cout <<  fnd =   << fs << endl;         break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     WORK();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxm = 3e5 + 5;   const long long mod = 998244353;   long long fac[maxm], inv[maxm];   long long l[maxm], r[maxm];   pair<long long, long long> p[25];   long long sum[maxm][45];   long long num[maxm];   long long n, m;   long long ppow(long long a, long long b, long long mod) {     long long ans = 1 % mod;     a %= mod;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans;   }   void init() {     fac[0] = 1;     for (long long i = 1; i < maxm; i++) fac[i] = fac[i - 1] * i % mod;     inv[maxm - 1] = ppow(fac[maxm - 1], mod - 2, mod);     for (long long i = maxm - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;   }   long long cal(long long x) {     long long ans = 0;     while (x) {       ans++;       x &= (x - 1);     }     return ans;   }   long long C(long long n, long long m) {     if (m < 0 || m > n) return 0;     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     ios::sync_with_stdio(0);     init();     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> l[i] >> r[i];     }     for (long long i = 0; i < m; i++) {       cin >> p[i].first >> p[i].second;     }     for (long long i = 1; i <= n; i++) {       num[l[i]]++;       num[r[i] + 1]--;     }     for (long long i = 1; i <= n; i++) {       num[i] += num[i - 1];     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= m * 2; j++) {         sum[i][j] = (sum[i - 1][j] + C(num[i] - j, i - j)) % mod;       }     }     long long ans = 0;     for (long long i = 0; i < (1 << m); i++) {       set<long long> s;       for (long long j = 0; j < m; j++) {         if (i >> j & 1) {           s.insert(p[j].first);           s.insert(p[j].second);         }       }       long long tot = s.size();       long long L = 1, R = n;       for (auto x : s) {         L = max(L, l[x]);         R = min(R, r[x]);       }       if (L > R) continue;       long long t = (sum[R][tot] - sum[L - 1][tot] + mod) % mod;       if (cal(i) & 1) {         ans = (ans - t + mod) % mod;       } else {         ans = (ans + t) % mod;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5, R = 1e4;   int n, l[N], r[N];   long long cnt[R + 1];   double all;   bool used[N];   long long f(int cur, int c, int mn, int x = N) {     if (cur == n) {       if (mn > 0) {         return 0;       }       long long cnt = 1;       for (int i = 0; i < n; i++) {         if (!used[i] && i != x) {           cnt *= max(0, min(c, r[i] + 1) - l[i]);         }       }       return cnt;     }     long long cnt = f(cur + 1, c, mn, x);     if (cur != x && l[cur] <= c && c <= r[cur]) {       used[cur] = true;       cnt += f(cur + 1, c, mn - 1, x);       used[cur] = false;     }     return cnt;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , l + i, r + i);     }     for (int cur = 0; cur <= R; cur++) {       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += f(0, cur, 1, i) * max(0, r[i] - max(cur, l[i] - 1));       }       sum += f(0, cur, 2);       all += sum;       cnt[cur] = sum;     }     double ans = 0;     for (int i = 0; i <= R; i++) {       ans += cnt[i] / all * i;     }     printf( %.10f , ans);   }


#include <bits/stdc++.h>   using namespace std;   int i, n, k, x, ans, c;   pair<int, int> a[100005];   int main() {     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> x;       a[i].first = 10 - x % 10;       a[i].second = x;     }     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i].second < 100 && (k - (10 - a[i].second % 10) >= 0)) {         a[i].second += 10 - a[i].second % 10;         k -= a[i].first;       } else {         break;       }       if (i == n - 1) {         break;       }     }     for (i = 0; i < n; i++) {       ans += a[i].second / 10;     }     cout << min(n * 10, ans + k / 10);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h;     cin >> n >> m >> h;     int f[m];     int l[n];     int t[n][m];     int ans[n][m];     for (int i = 0; i < m; i++) cin >> f[i];     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> t[i][j];         if (t[i][j] == 1) {           ans[i][j] = 1;         }       }     memset(ans, 0, sizeof(ans));     for (int i = 0; i < m; i++) {       int h1 = f[i];       for (int j = 0; j < n; j++) {         if (t[j][i] == 1 && l[j] >= h1) {           ans[j][i] = h1;         }       }     }     for (int i = 0; i < n; i++) {       int h1 = l[i];       for (int j = 0; j < m; j++) {         if (t[i][j] == 1 && f[j] >= h1) {           ans[i][j] = h1;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, now, t, mx, gcd, m, a[107];     scanf( %d , &n);     for (i = 0; i ^ n; i++) {       scanf( %d , a + i);     }     sort(a, a + n);     mx = gcd = a[0];     m = 1;     for (i = 1; i ^ n; i++) {       if (a[i - 1] != a[i]) {         mx = mx < a[i] ? a[i] : mx;         m++;         now = a[i];         while (gcd) {           t = now;           now = gcd;           gcd = t % gcd;         }         gcd = now;       }     }     mx /= gcd;     mx -= m;     printf(mx & 1 ?  Alice n  :  Bob n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100009];   int b[100009];   int main() {     int n;     cin >> n;     map<int, int> mp;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     for (int j = 0; j < n; j++) {       cin >> b[j];       mp[b[j]]++;     }     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (mp.find(a[i] xor b[j]) != mp.end()) c++;       }     }     if (c & 1) {       cout <<  Koyomi n ;     } else {       cout <<  Karen n ;     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     int n;     cin >> n;     int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     int max_n = pow(2, n);     bool ans = false;     for (int i = 0; i < max_n; i++) {       int temp = i;       int val = 0;       for (int j = 0; j < n; j++) {         if (temp & 1) {           val = (val + ar[j]) % 360;         } else {           val = (val - ar[j] + 360) % 360;         }         temp = temp >> 1;       }       if (val == 0) {         ans = true;         break;       }     }     if (ans) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const int GRAPH_SIZE = 20010;   int pin[GRAPH_SIZE], dep[GRAPH_SIZE], s = 0, t = GRAPH_SIZE - 1;   struct EDGE {     int u, v, c;   };   vector<EDGE> e;   vector<int> each[GRAPH_SIZE];   bool bfs() {     queue<int> Q;     Q.push(s);     while (!Q.empty()) {       int now = Q.front();       Q.pop();       for (auto it : each[now]) {         int next = e[it].v;         if (e[it].c)           if (dep[next] > dep[now] + 1) {             dep[next] = dep[now] + 1;             Q.push(next);           }       }     }     return dep[t] != INF;   }   int dfs(int now, int flow) {     if (now == t) {       return flow;     }     for (int& i = pin[now]; i < each[now].size(); i++) {       int it = each[now][i];       if (e[it].c && dep[e[it].v] == dep[now] + 1) {         int tmp;         if (tmp = dfs(e[it].v, min(flow, e[it].c))) {           e[it].c -= tmp;           e[it ^ 1].c += tmp;           return tmp;         }       }     }     return 0;   }   int Dinic() {     int max_flow = 0;     for (int i = 0; i < GRAPH_SIZE; ++i) {       dep[i] = INF;     }     dep[s] = 0;     while (bfs()) {       for (int i = 0; i < GRAPH_SIZE; ++i) {         pin[i] = 0;       }       int tmp;       while (tmp = dfs(s, INF)) {         max_flow += tmp;       }       for (int i = 0; i < GRAPH_SIZE; ++i) {         dep[i] = INF;       }       dep[s] = 0;     }     return max_flow;   }   void make_edge(int U, int V, int C) {     EDGE tmp;     tmp.u = U;     tmp.v = V;     tmp.c = C;     e.push_back(tmp);     each[U].push_back(e.size() - 1);     swap(tmp.u, tmp.v);     tmp.c = 0;     e.push_back(tmp);     each[V].push_back(e.size() - 1);   }   void init() {     e.clear();     for (int i = 0; i < GRAPH_SIZE; ++i) {       each[i].clear();     }   }   vector<pair<int, pair<int, int> > > edges;   int n;   int m;   bool check(int x) {     init();     for (int i = 1; i <= n; ++i) make_edge(s, i, 1);     for (int i = 1; i <= n; ++i) make_edge(i + n, t, 1);     for (int i = 0; i < x; ++i) {       make_edge(edges[i].second.first, edges[i].second.second + n, 1);     }     if (Dinic() == n) return true;     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v, d;       cin >> u >> v >> d;       edges.push_back(make_pair(d, make_pair(u, v)));     }     sort(edges.begin(), edges.end());     if (!check(m)) {       cout << -1 << endl;       return 0;     }     int l = 1, r = m;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid)) {         r = mid;       } else {         l = mid + 1;       }     }     cout << edges[l - 1].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     cin >> tt;     for (int tc = 1; tc <= tt; tc++) {       int a;       cin >> a;       if (360 % (180 - a))         cout <<  NO n ;       else         cout <<  YES n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[57 + 7][57 + 7];   long long mdp[57 + 7][57 + 7];   bool vis[57 + 7][57 + 7];   int n, K;   long long ncr[57 + 7][57 + 7];   int L, R;   long long func(int l, int r, int i, int j, int k, int m) {     long long ret = (ncr[l][i] * ncr[r][j]) % mod;     ret = (ret * ncr[L - l + i][k]) % mod;     ret = (ret * ncr[R - r + j][m]) % mod;     return ret;   }   void back(int l, int r) {     if (vis[l][r]) return;     mdp[l][r] = 200000007;     dp[l][r] = 0;     vis[l][r] = true;     if (l == 0 && r == 0) {       mdp[l][r] = 0;       dp[l][r] = 1;       return;     }     if (l * 50 + r * 100 <= K) {       mdp[l][r] = 1;       dp[l][r] = 1;       return;     }     for (int i = 0; i <= l && i * 50 <= K; i++) {       for (int j = 0; j <= r; j++) {         if (i == 0 && j == 0) continue;         if (i * 50 + j * 100 > K) break;         for (int k = 0; k <= L - l + i; k++) {           for (int m = 0; m <= R - r + j; m++) {             if (k * 50 + m * 100 == 0) continue;             if (k * 50 + m * 100 > K) break;             if (l * 50 + r * 100 <= (l - i + k) * 50 + (r - j + m) * 100)               continue;             back(l - (i - k), r - (j - m));             mdp[l][r] = min(mdp[l][r], mdp[l - i + k][r - j + m] + 2);           }         }       }     }     for (int i = 0; i <= l && i * 50 <= K; i++) {       for (int j = 0; j <= r; j++) {         if (i == 0 && j == 0) continue;         if (i * 50 + j * 100 > K) break;         for (int k = 0; k <= L - l + i; k++) {           for (int m = 0; m <= R - r + j; m++) {             if (k * 50 + m * 100 == 0) continue;             if (k * 50 + m * 100 > K) break;             if (l * 50 + r * 100 <= (l - i + k) * 50 + (r - j + m) * 100)               continue;             if (mdp[l - i + k][r - j + m] + 2 == mdp[l][r]) {               dp[l][r] +=                   (func(l, r, i, j, k, m) * dp[l - i + k][r - j + m]) % mod;               dp[l][r] %= mod;             }           }         }       }     }   }   int main() {     ncr[0][0] = 1;     for (int i = 1; i <= 57; i++) {       ncr[i][0] = 1;       ncr[i][i] = 1;       ncr[i][1] = i;     }     for (int i = 2; i <= 57; i++) {       for (int j = 2; j < i; j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % mod;       }     }     scanf( %d%d , &n, &K);     int l = 0;     int r = 0;     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       if (v == 50)         l++;       else         r++;     }     L = l;     R = r;     back(l, r);     if (mdp[l][r] != 200000007) {       printf( %d n , (int)mdp[l][r]);       printf( %d n , (int)dp[l][r]);     } else {       printf( -1 n0 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 410, MOD = 10007;   char s[maxn];   int n, m, mat_s;   typedef long long Mat[maxn][maxn];   void print(Mat A) {     for (int i = 0; i < (mat_s); i++) {       for (int j = 0; j < (mat_s); j++) {         cout << A[i][j] <<    ;       }       cout << endl;     }     cout << endl;   }   void mat_mul(Mat A, Mat B, Mat res) {     static Mat C;     memset(C, 0, sizeof(C));     for (int i = 0; i < (mat_s); i++)       for (int k = (i); k <= (mat_s - 1); k++)         for (int j = (k); j <= (mat_s - 1); j++) {           C[i][j] += A[i][k] * B[k][j];         }     for (int i = 0; i < (mat_s); i++)       for (int j = 0; j < (mat_s); j++) {         C[i][j] %= MOD;       }     memcpy(res, C, sizeof(C));   }   void mat_pow(Mat A, long long k, Mat res) {     static Mat a, r;     memcpy(a, A, sizeof(a));     memset(r, 0, sizeof(r));     for (int i = 0; i < (mat_s); i++) r[i][i] = 1;     while (k) {       if (k & 1) {         mat_mul(r, a, r);       }       if (!(k >>= 1)) {         break;       }       mat_mul(a, a, a);     }     memcpy(res, r, sizeof(r));   }   int dp[210][210][210];   int rec(int l, int r, int n24) {     int& res = dp[l][r][n24];     if (~res) {       return res;     }     if (l == r) {       return res = !n24;     }     if (s[l] == s[r]) {       if (l + 1 == r) {         return res = !n24;       }       return res = rec(l + 1, r - 1, n24);     } else {       if (n24 > 0) {         return res = (rec(l + 1, r, n24 - 1) + rec(l, r - 1, n24 - 1)) % MOD;       } else {         return res = 0;       }     }   }   int n24, n25, n26, times;   int mat_at(Mat A, int c24, int c25) {     int i24 = n24 - c24;     int i25 = n24 + c25 - 1;     int i26 = i25 + n25;     return A[i24][i26];   }   int main() {     scanf( %s%d , s, &n);     m = strlen(s);     n += m;     times = (n + 1) >> 1;     n24 = m - 1;     n26 = n25 = (m + 1) >> 1;     mat_s = n24 + n25 + n26;     static Mat A, B;     for (int i = 0; i < (mat_s); i++) {       if (i < n24) {         A[i][i] = 24;         A[i][i + 1] = 1;       } else if (i < n24 + n25) {         A[i][i] = 25;         if (i + 1 < n24 + n25) {           A[i][i + 1] = 1;         }         A[i][i + n25] = 1;       } else {         A[i][i] = 26;       }     }     mat_pow(A, times - 1, B);     mat_mul(B, A, A);     int ans = 0;     memset(dp, -1, sizeof(dp));     for (int c24 = 0; c24 < (m); c24++) {       int c25 = (m - c24 + 1) >> 1;       if (times - c24 - c25 < 0) {         continue;       }       int ways = rec(0, m - 1, c24);       ans = (ans + ways * mat_at(A, c24, c25)) % MOD;       if ((n & 1) && (!((m - c24) & 1))) {         ans = (ans + MOD - ways * B[n24 - c24][n24 + c25 - 1] % MOD) % MOD;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long int, long long int> pa1,            pair<long long int, long long int> pa2) {     return pa1.second < pa2.second;   }   int main() {     long long int n, k, i, mn, cnt;     cin >> n >> k;     long long int a[5001];     for (i = 0; i < n; i++) cin >> a[i];     long long int has[5001] = {0};     for (i = 0; i < n; i++) {       has[a[i]]++;     }     mn = *max_element(has, has + 5001);     if (mn <= k && k <= n) {       cout <<  YES n ;       pair<long long int, long long int> pa[5001];       for (i = 0; i < n; i++) {         pa[i].first = a[i];         pa[i].second = i;       }       sort(pa, pa + n);       cnt = 1;       for (i = 0; i < n; i++) {         pa[i].first = cnt;         cnt++;         if (cnt == k + 1) cnt = 1;       }       sort(pa, pa + n, cmp);       for (i = 0; i < n; i++) cout << pa[i].first <<    ;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int f[150000];   int find(int x) {     if (x == f[x])       return f[x];     else {       return f[x] = find(f[x]);     }   }   int a[150000];   int num[150000];   int main() {     ios::sync_with_stdio(false);     int n, m;     while (cin >> n >> m) {       memset(a, 0, sizeof(a));       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) f[i] = i;       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         a[x]++;         a[y]++;         x = find(x), y = find(y);         if (x != y) f[x] = y;       }       for (int i = 1; i <= n; i++) {         find(i);       }       for (int i = 1; i <= n; i++) {         num[f[i]]++;       }       bool flag = true;       for (int i = 1; i <= n; i++) {         if (a[i] != num[f[i]] - 1) {           flag = false;           break;         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   struct node {     int tim, a, b, id;     bool operator<(const node& aa) const { return tim < aa.tim; }   } a[N];   deque<node> s[5], rt[5];   int vis[N];   vector<int> ad, de;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++)       scanf( %d%d%d , &a[i].tim, &a[i].a, &a[i].b), a[i].id = i;     sort(a + 1, a + 1 + n);     int na = 0, nb = 0, ans = 2e9;     for (int i = 1; i <= n; i++) {       int ne = 0;       if (a[i].a) ne |= 1;       if (a[i].b) ne |= 2;       rt[ne].push_back(a[i]);     }     int sum = 0;     int x = (int)rt[1].size(), y = (int)rt[2].size();     int mi = min(x, y);     if ((int)rt[3].size() + min(mi, (m - (int)rt[3].size()) / 2) < k)       return 0 * printf( -1 n );     while (s[3].size() + min(mi, (m - (int)s[3].size()) / 2) < k ||            s[3].size() + rt[1].size() + rt[2].size() + rt[0].size() < m) {       s[3].push_back(rt[3].front());       sum += rt[3].front().tim;       vis[rt[3].front().id] = 1;       rt[3].pop_front();     }     int ned = k - s[3].size();     for (int i = 1; i <= ned; i++) {       s[2].push_back(rt[2].front());       sum += rt[2].front().tim;       vis[rt[2].front().id] = 1;       rt[2].pop_front();       s[1].push_back(rt[1].front());       sum += rt[1].front().tim;       vis[rt[1].front().id] = 1;       rt[1].pop_front();     }     int res = m - s[3].size() - max(0, 2 * (k - (int)s[3].size()));     for (int i = 1; i <= res; i++) {       int add = -1;       if (rt[0].size()) add = 0;       if (rt[1].size() && (add == -1 || rt[add].front().tim > rt[1].front().tim))         add = 1;       if (rt[2].size() && (add == -1 || rt[add].front().tim > rt[2].front().tim))         add = 2;       s[add].push_back(rt[add].front());       sum += rt[add].front().tim;       vis[rt[add].front().id] = 1;       rt[add].pop_front();     }     ans = sum;     for (; rt[3].size() && s[3].size() < m;) {       sum = ans;       ad.clear(), de.clear();       s[3].push_back(rt[3].front());       ad.push_back(rt[3].front().id);       sum += rt[3].front().tim;       rt[3].pop_front();       int num = 0;       if (s[2].size()) {         rt[2].push_front(s[2].back());         de.push_back(s[2].back().id);         sum -= s[2].back().tim;         s[2].pop_back();         num++;       }       if (s[1].size()) {         rt[1].push_front(s[1].back());         de.push_back(s[1].back().id);         sum -= s[1].back().tim;         s[1].pop_back();         num++;       }       if (s[0].size()) {         rt[0].push_front(s[0].back());         de.push_back(s[0].back().id);         sum -= s[0].back().tim;         s[0].pop_back();         num++;       }       while (num > 1) {         int add = -1;         if (rt[0].size()) add = 0;         if (rt[1].size() &&             (add == -1 || rt[add].front().tim > rt[1].front().tim))           add = 1;         if (rt[2].size() &&             (add == -1 || rt[add].front().tim > rt[2].front().tim))           add = 2;         s[add].push_back(rt[add].front());         sum += rt[add].front().tim;         ad.push_back(rt[add].front().id);         rt[add].pop_front();         num--;       }       if (sum < ans) {         for (int i : ad) vis[i]++;         for (int i : de) vis[i]--;         ans = sum;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       if (vis[i]) printf( %d  , i);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, c, a[100005], sign[100005];   bool sign_ch[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     sign[n] = 1;     c = a[n];     for (int i = n - 1; i >= 1; i--) {       if (c >= a[i]) {         c -= a[i];         sign[i] = -1;       } else {         c = a[i] - c;         sign[i] = 1;         sign_ch[i + 1] = true;       }     }     int flip = 0;     for (int i = 1; i <= n; i++) {       if (sign_ch[i] == true) flip = !flip;       char ch;       ch = sign[i] == 1 ?  +  :  - ;       if (flip) ch = ch ==  +  ?  -  :  + ;       putchar(ch);     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, r[1010], c[1010], rc[1010], rr[1010], tr[1010], tc[1010], rtc[1010],       rtr[1010];   class portal {    public:     int ix, iy, ox, oy;   };   vector<portal> ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &r[i]);       rr[r[i]] = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       rc[c[i]] = i;     }     for (int i = 1; i <= n; i++) tr[i] = tc[i] = rtr[i] = rtc[i] = i;     for (int i = 1; i <= n; i++) {       if (tc[i] == rc[i] && tr[i] == rr[i]) continue;       ans.push_back((portal){i, rtc[rc[i]], rtr[rr[i]], i});       int t1 = tc[i], t2 = tr[i];       swap(tc[i], tc[rtc[rc[i]]]);       swap(tr[i], tr[rtr[rr[i]]]);       swap(rtc[rc[i]], rtc[t1]);       swap(rtr[rr[i]], rtr[t2]);     }     printf( %d n , ans.size());     for (portal x : ans) printf( %d %d %d %d n , x.ix, x.iy, x.ox, x.oy);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> row, col, A;   vector<pair<pair<int, int>, int> > mat;   int grid[111][111];   void shift_up(int c, int n, int m) {     int i, temp;     temp = grid[n][c];     for (i = n; i > 1; i--) grid[i][c] = grid[i - 1][c];     grid[1][c] = temp;   }   void shift_left(int r, int n, int m) {     int i, temp;     temp = grid[r][m];     for (i = m; i > 1; i--) grid[r][i] = grid[r][i - 1];     grid[r][1] = temp;   }   int main() {     int n, q, i, m, j, type, id, r, c, x;     cin >> n >> m >> q;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) grid[i][j] = 0;     while (q--) {       cin >> type;       A.push_back(type);       if (type == 2) {         cin >> id;         col.push_back(id);       } else if (type == 1) {         cin >> id;         row.push_back(id);       } else {         cin >> r >> c >> x;         mat.push_back(make_pair(make_pair(r, c), x));       }     }     int im = mat.size() - 1, ir = row.size() - 1, ic = col.size() - 1;     for (i = A.size() - 1; i >= 0; i--) {       type = A[i];       if (type == 2) {         c = col[ic];         ic--;         shift_up(c, n, m);       } else if (type == 1) {         r = row[ir];         ir--;         shift_left(r, n, m);       } else {         r = mat[im].first.first;         c = mat[im].first.second;         x = mat[im].second;         grid[r][c] = x;         im--;       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cout << grid[i][j] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct sir {     int val, ind;   };   sir sv[200005];   int n, m, k, v[200005], part[200005], t = 0;   long long sum = 0;   bool B[200005];   bool comp(sir X, sir Y) { return X.val > Y.val; }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) {       cin >> v[i];       sv[i].val = v[i];       sv[i].ind = i;     }     sort(sv + 1, sv + n + 1, comp);     for (int i = 1; i <= m * k; ++i) {       B[sv[i].ind] = 1;       sum += sv[i].val;     }     int nr = 0;     for (int i = 1; i <= n; ++i) {       if (B[i]) nr++;       if (nr == m && t < k - 1) {         nr = 0;         part[++t] = i;       }     }     cout << sum <<   n ;     for (int i = 1; i <= t; ++i) cout << part[i] <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   long long h[100000];   int main() {     int n;     cin >> n;     for (int j = 0; j < n; ++j) {       cin >> h[j];     }     long long max = h[n - 1];     long long answer[100000];     answer[n - 1] = 0;     for (int i = n - 2; i >= 0; --i) {       if (h[i] > max) {         max = h[i];         answer[i] = 0;       } else {         answer[i] = max - h[i] + 1;       }     }     for (int i = 0; i < n; ++i) {       cout << answer[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int>> parent[1000001], hv[1000001], vv[1000001];   vector<vector<pair<int, int>>> edges[1000001];   vector<int> vals[1000001], done[1000001];   pair<int, int> get(pair<int, int> x) {     pair<int, int> k = parent[x.first][x.second];     if (parent[k.first][k.second] == k)       return k;     else       return parent[k.first][k.second] = get(k);   }   void unite(pair<int, int> a, pair<int, int> c) {     a = get(a), c = get(c);     if (a == c) return;     parent[c.first][c.second] = a;   }   int dp(pair<int, int> x) {     x = get(x);     if (edges[x.first][x.second].size() == 0) return 1;     if (done[x.first][x.second]) return done[x.first][x.second];     sort(edges[x.first][x.second].begin(), edges[x.first][x.second].end());     edges[x.first][x.second].erase(         unique(edges[x.first][x.second].begin(), edges[x.first][x.second].end()),         edges[x.first][x.second].end());     int ans = 0;     for (pair<int, int> i : edges[x.first][x.second]) ans = max(ans, dp(i));     return done[x.first][x.second] = (ans + 1);   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++)       parent[i].resize(n), edges[i].resize(n), vals[i].resize(n),           done[i].resize(n);     for (int j = 0; j < n; j++)       for (int i = 0; i < m; i++) {         pair<int, int> x = make_pair(i, j);         scanf( %d , &vals[x.first][x.second]), parent[x.first][x.second] = x;         vv[i].push_back(make_pair(vals[x.first][x.second], j)),             hv[j].push_back(make_pair(vals[x.first][x.second], i));       }     for (int i = 0; i < m; i++) {       sort(vv[i].begin(), vv[i].end());       for (int j = 0; j < n - 1; j++)         if (vv[i][j].first == vv[i][j + 1].first)           unite(make_pair(i, vv[i][j].second), make_pair(i, vv[i][j + 1].second));     }     for (int j = 0; j < n; j++) {       sort(hv[j].begin(), hv[j].end());       for (int i = 0; i < m - 1; i++)         if (hv[j][i].first == hv[j][i + 1].first)           unite(make_pair(hv[j][i].second, j), make_pair(hv[j][i + 1].second, j));     }     for (int i = 0; i < m; i++)       for (int j = 0; j < n - 1; j++)         if (vv[i][j].first < vv[i][j + 1].first) {           pair<int, int> a = get(make_pair(i, vv[i][j + 1].second));           pair<int, int> c = get(make_pair(i, vv[i][j].second));           edges[a.first][a.second].push_back(c);         }     for (int j = 0; j < n; j++)       for (int i = 0; i < m - 1; i++)         if (hv[j][i].first < hv[j][i + 1].first) {           pair<int, int> a = get(make_pair(hv[j][i + 1].second, j));           pair<int, int> c = get(make_pair(hv[j][i].second, j));           edges[a.first][a.second].push_back(c);         }     for (int j = 0; j < n; j++) {       for (int i = 0; i < m; i++) printf( %d  , dp(make_pair(i, j)));       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 10;   string s[101];   string x;   long long dp[101];   long long n;   int m;   int fail[N];   struct matrix {     long long v[4][4];     matrix() {       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++) v[i][j] = 0;     }     matrix(long long u[4][4]) {       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++) v[i][j] = u[i][j];     }     matrix operator*(const matrix a) const {       matrix ans;       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++)           for (int k = 0; k < 4; k++) {             ans.v[i][j] += (v[i][k] * a.v[k][j]);             ans.v[i][j] = (ans.v[i][j] + mod) % mod;           }       return ans;     }     void setunit() {       for (int i = 0; i < 4; i++) v[i][i] = 1;     }   };   long long mtx[4][4] = {       {1, 2, -1, -1},       {1, 0, 0, 0},       {0, 1, 0, 0},       {0, 0, 1, 0},   };   matrix calc(long long i) {     matrix tmp(mtx);     matrix ans;     ans.setunit();     while (i) {       if (i & 1ll) ans = tmp * ans;       tmp = tmp * tmp;       i = i / 2ll;     }     return ans;   }   long long kmp(int p) {     int m = x.length(), n = s[p].length();     if (m > n) return 0;     for (int i = 1, j = fail[0] = -1; i < m; i++) {       while (j >= 0 && x[j + 1] != x[i]) j = fail[j];       if (x[j + 1] == x[i]) j++;       fail[i] = j;     }     int ans = 0;     for (int i = 0, j = -1; i < n; i++) {       while (j >= 0 && x[j + 1] != s[p][i]) j = fail[j];       if (x[j + 1] == s[p][i]) j++;       if (j == m - 1) {         ans++;         j = fail[j];       }     }     return (long long)ans;   }   long long calc(int a, int b) {     string p = s[a] + s[b];     int s1 = s[a].length();     int m = x.length(), n = p.length();     if (m > n) return 0;     for (int i = 1, j = fail[0] = -1; i < m; i++) {       while (j >= 0 && x[j + 1] != x[i]) j = fail[j];       if (x[j + 1] == x[i]) j++;       fail[i] = j;     }     int ans = 0;     for (int i = 0, j = -1; i < n; i++) {       while (j >= 0 && x[j + 1] != p[i]) j = fail[j];       if (x[j + 1] == p[i]) j++;       if (j == m - 1) {         if ((i - m + 1 < s1) && (i + 1) > s1) ans++;         j = fail[j];       }     }     return (long long)ans;   }   int main() {     s[1] =  a ;     s[2] =  b ;     for (int i = 3; i <= 30; i++) s[i] = s[i - 1] + s[i - 2];     cin >> n >> m;     while (m--) {       cin >> x;       if (n <= 25) {         cout << kmp((int)n) << endl;         continue;       }       int len = x.length();       int r = 1;       while (s[r].length() < len) r++;       long long add1 = calc(r, r), add2 = calc(r + 1, r);       for (int i = 1; i <= r + 2; i++) dp[i] = kmp(i);       dp[r + 3] = dp[r + 2] + dp[r + 1] + add1;       dp[r + 4] = dp[r + 3] + dp[r + 2] + add2;       dp[r + 5] = dp[r + 4] + dp[r + 3] + add1;       dp[r + 6] = dp[r + 5] + dp[r + 4] + add2;       if (n <= r + 6) {         cout << dp[n] << endl;         continue;       }       matrix mat = calc(n - r - 6);       long long ans = 0;       for (int i = 0; i < 4; i++) ans += mat.v[0][i] * dp[r + 6 - i];       ans = ans % mod;       while (ans < 0) ans += mod;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long int pre = 0;     int counter = 0;     while (counter < n && arr[counter] != 0) {       pre++;       counter++;     }     long long int post = 0;     counter = n - 1;     while (counter >= 0 && arr[counter] != 0) {       counter--;       post++;     }     counter = 0;     long long int mx = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == 0) {         if (mx < counter) mx = counter;         counter = 0;       } else {         counter++;       }     }     if (counter > mx) mx = counter;     if (mx < pre + post) mx = pre + post;     cout << mx <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using iii = tuple<int, int, int>;   using vi = vector<int>;   int main(void) {     ios::sync_with_stdio(false), cin.tie(NULL);     int n;     cin >> n;     vector<iii> a(n);     int maxr = 0, i = 0;     for (auto &[r, l, ix] : a) {       cin >> l >> r;       ix = i++;       maxr = max(maxr, r);     }     sort(begin(a), end(a));     vi used(maxr + 1, 0), ans(n);     for (auto [r, l, i] : a) {       while (used[l]) l++;       ans[i] = l;       used[l] = true;     }     for (auto x : ans) cout << x <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     size_t n, w, m;     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),         cin >> n >> w >> m;     struct bottle_t {       size_t amount, id;     } bottle, poured;     stack<bottle_t> bottles, non_empty;     vector<bottle_t> cup[m];     for (bottle.amount = m, bottle.id = 1; bottle.id <= n; bottle.id++)       bottles.push(bottle);     for (size_t i = 0, unfilled = n; i < m; i++, unfilled = n) {       while (!non_empty.empty()) bottles.push(non_empty.top()), non_empty.pop();       do {         bottle = bottles.top(), bottles.pop();         if (bottle.amount > unfilled && bottle.amount < m) {           cout <<  NO ;           return 0;         }         poured = bottle;         if (unfilled < poured.amount) poured.amount = unfilled;         cup[i].push_back(poured);         if ((bottle.amount -= poured.amount) > 0) non_empty.push(bottle);       } while ((unfilled -= poured.amount) > 0);     }     cout <<  YES  <<   n ;     long double scale_factor = (long double)w / (long double)m;     for (size_t i = 0; i < m; i++, cout <<   n )       for (size_t j = 0, k = cup[i].size(); j < k; j++)         cout << cup[i][j].id <<     << fixed << setprecision(6)              << scale_factor * cup[i][j].amount <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int min(int s, int t) {     if (s <= t) return s;     return t;   }   int max(int s, int t) {     if (s >= t) return s;     return t;   }   int main(void) {     int cases;     int n, s, t, m, k;     cin >> cases;     while (cases--) {       cin >> n >> s >> t;       m = s + t;       k = m - n;       cout << max(s - k, t - k) + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     int a[2] = {0};     char c;     while (scanf( %c , &c) != -1) {       a[c -  x ]++;     }     if (a[0] > a[1]) {       x = a[0] - a[1];       for (int i = 0; i < x; i++) {         printf( %c ,  x );       }       printf(  n );     } else {       x = a[1] - a[0];       for (int i = 0; i < x; i++) {         printf( %c ,  y );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   bool myComp(pair<int, int> x, pair<int, int> y) {     if (x.first < y.first) return true;     if (x.first > y.first) return false;     return x.second > y.second;   }   int lucky[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};   int main() {     int n, m;     cin >> n >> m;     int last = m - 1;     for (int i = 0; i < n; i++) {       bool print = false;       for (int j = 0; j < m; j++) {         if (i % 2 == 0)           cout <<  # ;         else {           if (j != last) {             cout <<  . ;           } else {             cout <<  # ;           }         }       }       if (i % 2 != 0) {         if (last == 0)           last = m - 1;         else           last = 0;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int it;     int TUX;     cin >> TUX;     int FOO = 0, BAR = 0, BAZ = 0, QUZ = 1;     for (int i = TUX; i != 0; i--) {       int PUR;       cin >> PUR;       FOO += PUR;       BAR++;       it = ((max((FOO * QUZ), (BAR * BAZ))) == (FOO * QUZ));       if (it) {         BAZ = FOO;         QUZ = BAR;       }     }     cout << ((double)BAZ) / ((double)QUZ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool areParanthesisBalanced(string expr) {     stack<char> s;     char x;     for (int i = 0; i < expr.length(); i++) {       if (expr[i] ==  (  || expr[i] ==  [  || expr[i] ==  { ) {         s.push(expr[i]);         continue;       }       if (s.empty()) return false;       switch (expr[i]) {         case  ) :           x = s.top();           s.pop();           if (x ==  {  || x ==  [ ) return false;           break;         case  } :           x = s.top();           s.pop();           if (x ==  (  || x ==  [ ) return false;           break;         case  ] :           x = s.top();           s.pop();           if (x ==  (  || x ==  { ) return false;           break;       }     }     return (s.empty());   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     cin.ignore();     string s;     cin >> s;     int op = 0;     int ans = 0;     int st = -1, en = -1;     for (int i = 0; i < n; ++i) {       if (st == -1) {         st = i;       }       if (s[i] ==  ( ) {         op++;       } else {         op--;       }       if (op == 0) {         if (areParanthesisBalanced(s.substr(st, i - st + 1))) {         } else {           ans += i - st + 1;         }         st = -1;       }     }     if (op == 0) {       cout << ans <<   n ;     } else {       cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j, k = 0, z, x;     scanf( %d , &n);     for (i = 1; i < n; i++) {       for (j = i; j < n; j++) {         z = i * i + j * j;         x = sqrt(z);         if (x * x == z && x <= n) {           k++;         }       }     }     printf( %d , k);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 200005;   int n, m, tot, a[MAXN], b[MAXN], pa[MAXN], pb[MAXN], tr[MAXN], ans[MAXN * 10];   bool tag[MAXN * 10], used[MAXN * 10];   template <typename T>   inline void read(T &x) {     int fl = 0, ch;     while (ch = getchar(), ch < 48 || 57 < ch) fl ^= !(ch ^ 45);     x = (ch & 15);     while (ch = getchar(), 47 < ch && ch < 58) x = x * 10 + (ch & 15);     if (fl) x = -x;   }   struct ASK {     int opt, x, y, id;   } q[MAXN * 10], qq[MAXN * 10];   void upd(int i, int x) {     for (; i <= n; i += i & -i) tr[i] += x;   }   int qry(int i) {     int res = 0;     for (; i; i &= i - 1) res += tr[i];     return res;   }   void cdq(int l, int r) {     if (l >= r) return;     int mid = l + r >> 1;     cdq(l, mid), cdq(mid + 1, r);     int i = l, j = mid + 1;     for (int k = l; k <= r; ++k) {       if (i <= mid && (j > r || q[i].x <= q[j].x)) {         if (q[i].opt == 2) upd(q[i].y, 1);         if (q[i].opt == 3) upd(q[i].y, -1);         qq[k] = q[i++], used[k] = 1;       } else {         if (q[j].opt == 1) ans[q[j].id] += qry(q[j].y);         qq[k] = q[j++];       }     }     for (int k = l; k <= r; ++k) {       q[k] = qq[k];       if (used[k] == 1) {         if (q[k].opt == 2)           upd(q[k].y, -1);         else if (q[k].opt == 3)           upd(q[k].y, 1);         used[k] = 0;       }     }   }   int main() {     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]), pa[a[i]] = i;     for (int i = 1; i <= n; ++i) read(b[i]), pb[b[i]] = i;     for (int i = 1; i <= n; ++i) ++tot, q[tot] = (ASK){2, pa[i], pb[i]};     for (int i = 1; i <= m; ++i) {       ++tot, read(q[tot].opt);       if (q[tot].opt == 1) {         int l1, r1, l2, r2;         read(l1), read(r1), read(l2), read(r2);         tag[tot--] = 1;         ++tot, q[tot] = (ASK){1, r1, r2, tot};         ++tot, q[tot] = (ASK){1, l1 - 1, r2, tot};         ++tot, q[tot] = (ASK){1, r1, l2 - 1, tot};         ++tot, q[tot] = (ASK){1, l1 - 1, l2 - 1, tot};       } else {         int x, y;         read(x), read(y);         --tot;         ++tot, q[tot] = (ASK){3, pa[b[x]], x, 0};         ++tot, q[tot] = (ASK){3, pa[b[y]], y, 0};         ++tot, q[tot] = (ASK){2, pa[b[x]], y, 0};         ++tot, q[tot] = (ASK){2, pa[b[y]], x, 0};         std::swap(b[x], b[y]), std::swap(pb[b[x]], pb[b[y]]);       }     }     cdq(1, tot);     for (int i = 1; i <= tot; ++i)       if (tag[i] == 1)         printf( %d n , ans[i] - ans[i + 1] - ans[i + 2] + ans[i + 3]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000100;   const long long MOD = 1e9 + 7;   int N, M;   string P;   int y[MAXN], fail[MAXN];   bool good[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin >> N >> M >> P;     for (int i = 0; i < M; i++) {       cin >> y[i];       y[i]--;     }     fail[0] = -1;     for (int i = 1; i < P.length(); i++) {       int cloc = fail[i - 1];       while (cloc > -1 && P[i] != P[cloc + 1]) cloc = fail[cloc];       if (cloc == -1 && P[i] != P[0]) cloc = -2;       fail[i] = cloc + 1;     }     for (int i = 0; i < MAXN; i++) good[i] = false;     int cloc = (int)P.length() - 1;     while (cloc != -1) {       good[cloc] = true;       cloc = fail[cloc];     }     for (int i = 0; i < M - 1; i++) {       int diff = (y[i + 1] - y[i]);       if (diff >= P.length()) continue;       if (!good[P.length() - 1 - diff]) {         cout <<  0 n ;         return 0;       }     }     int xloc = 0;     long long res = 1;     for (int i = 0; i < N; i++) {       if (xloc < M - 1 && y[xloc + 1] == i) xloc++;       if (xloc >= M || y[xloc] > i || y[xloc] + P.size() <= i) {         res = (26 * res) % MOD;       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   pair<long double, long double> a[N];   int n;   bool f(long double mid) {     long double l[n], r[n];     multiset<pair<long double, int>> xex;     for (int i = 0; i < n; i++) {       l[i] = 1.0 * a[i].first - a[i].second * mid;       xex.insert({l[i], -1});       r[i] = 1.0 * a[i].first + a[i].second * mid;       xex.insert({r[i], 1});     }     int cnt = 0;     for (auto it = xex.begin(); it != xex.end(); it++) {       if ((*it).second == -1) {         cnt++;       } else {         cnt--;       }       if (cnt == n) return true;     }     {       bool f = true;       for (int i = 0; i < n; i++) {         if (l[i] <= a[0].first) {           f = false;           break;         }       }       if (f) return true;     }     {       bool f = true;       for (int i = 0; i < n; i++) {         if (a[n - 1].first <= r[i]) {           f = false;           break;         }       }       if (f) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first;     }     for (int i = 0; i < n; i++) {       cin >> a[i].second;     }     sort(a, a + n);     long double ans = 1e9;     long double l = 0.0, r = 1e9;     while (r - l >= 0.0000001) {       long double mid = (1.0 * l + r) / 2.0;       if (f(mid)) {         ans = mid;         r = mid;       } else {         l = mid;       }     }     cout << fixed << setprecision(8) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[15];   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   int main() {     int t = read();     while (t--) {       int n = read(), x = 0, y = 0, s = 0, xx = 0, yy = 0;       while (n) a[++s] = n % 10, n /= 10;       for (int i = s; i; i--)         if (i & 1)           x = x * 10 + a[i];         else           y = y * 10 + a[i];       printf( %d n , (x + 1) * (y + 1) - 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200007];   void input() {     scanf( %d , &n);     int i;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }   }   void solve() {     int i;     for (i = 1; i <= n; i++) {       if ((a[i] % 2) == 1) {         if (i != n && (a[i + 1] != 0)) {           a[i]--;           a[i + 1]--;         }       }     }     for (i = 1; i <= n; i++) {       if ((a[i] % 2) != 0) {         printf( NO n );         return;       }     }     printf( YES n );   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[10010];   int main() {     int n;     cin >> n;     while (n--) {       string a;       cin >> a;       for (int i = 0; i < a.size(); i++) {         s[i] = a[i];       }       sort(s, s + a.size());       if (s[0] == s[a.size() - 1]) {         cout << -1 << endl;       } else {         for (int i = 0; i < a.size(); i++) {           cout << s[i];         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mara = (int)(1e6) + 5;   vector<long long> a(mara), prime(mara), v(mara), luck;   map<long long, bool> flag;   long long bigmod(long long a, long long b, long long m) {     long long res = 1;     while (b) {       if (b & 1) {         res = (res * a) % m;         b--;       } else {         b /= 2;         a = (a * a) % m;       }     }     return res;   }   void soln() {     long long a, b, sum = 0;     cin >> a >> b;     for (long long i = 1; i <= 10; i++) {       long long as = i * b;       as %= 10;       sum += as;     }     long long vajok = 10 * b;     long long div = a / vajok;     long long rem = a % vajok;     long long res = sum * div;     for (long long i = b; i <= rem; i += b) {       long long temp = i;       temp %= 10;       res += temp;     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       soln();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     n& n - 1 ? printf( NO ) : printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<pair<long long, int> > c(n);     vector<int> ans(n);     for (int i = 0; i < n; ++i) {       cin >> c[i].first;       c[i].second = i;     }     set<pair<long long, int> > av;     for (int i = 0; i < k; ++i) av.insert(c[i]);     int now = k;     long long cost = 0;     for (int i = 0; i < n; ++i) {       if (now < n) av.insert(c[now]);       ans[av.rbegin()->second] = ++now;       cost += av.rbegin()->first * (now - av.rbegin()->second - 1);       av.erase(*av.rbegin());     }     cout << cost <<   n ;     for (int i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005, maxv = 4e6 + 5;   long long a, b, c, X1, X2, Y1, Y2;   pair<long double, long double> va[6], vb[6];   void exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   long double sqr(long double x) { return x * x; }   int main() {     scanf( %lld %lld %lld , &a, &b, &c);     scanf( %lld %lld %lld %lld , &X1, &Y1, &X2, &Y2);     long double ans = abs(X1 - X2) + abs(Y1 - Y2);     if (a != 0 && b != 0) {       va[0] = make_pair(X1, (long double)(-c - a * X1) / b);       va[1] = make_pair((long double)(-c - b * Y1) / a, Y1);       vb[0] = make_pair(X2, (long double)(-c - a * X2) / b);       vb[1] = make_pair((long double)(-c - b * Y2) / a, Y2);       for (int i = 0; i <= 1; i++)         for (int j = 0; j <= 1; j++) {           long double ans1 = fabs(X1 - va[i].first) + fabs(Y1 - va[i].second) +                              fabs(X2 - vb[j].first) + fabs(Y2 - vb[j].second);           ans1 += sqrt(sqr(va[i].first - vb[j].first) +                        sqr(va[i].second - vb[j].second));           ans = min(ans, ans1);         }     }     printf( %.9f n , (double)ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edges[100006];   int given[100006] = {0};   int dfs(int i, int c) {     if (given[i] != 0) {       if ((given[i] == 1 && c == 2) || (given[i] == 2 && c == 1)) return 0;     }     if (edges[i].size() != 0) given[i] = c;     int fl = 1;     for (int j = 0; j < edges[i].size(); j++) {       int v = edges[i][j];       if (given[v] != 0) {         if (given[v] == c) return 0;       } else {         int t;         if (c == 1)           t = 2;         else           t = 1;         fl = dfs(v, t) & fl;       }     }     return fl;   }   int main() {     int u, v, n, m;     scanf( %d , &n), scanf( %d , &m);     for (int i = (0); i < (m); ++i) {       scanf( %d , &u), scanf( %d , &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     for (int i = (0); i < (100004); ++i) given[i] = 0;     int flag = 1;     for (int i = 1; i <= n && flag; i++) {       if (given[i] == 0) flag = dfs(i, 1) & flag;     }     if (flag == 0)       puts( -1 );     else {       int a = 0, s = 0, tempp = 22;       for (int i = 1; i <= n; i++)         if (given[i] == 1)           a++;         else if (given[i] == 2)           s++;       printf( %d n , a);       for (int i = 1; i <= n; i++)         if (given[i] == 1) printf( %d  , i);       printf(  n );       printf( %d n , s);       for (int i = 0; i <= n; i++)         if (given[i] == 2) printf( %d  , i);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   struct Widget {     string type, name;     vector<Widget *> childs;     long long h, w, s, b;     Widget(string _name =   , string _type =   , long long _h = -1,            long long _w = -1) {       h = _h, w = _w;       type = _type;       name = _name;       s = 0;       b = 0;     }     void pack(Widget *W) { childs.push_back(W); }     long long getW() {       if (type ==  normal )         return w;       else if (type ==  VBox ) {         if (childs.size() == 0) return 0;         if (w != -1) return w;         w = 0;         for (int i = 0; i < childs.size(); ++i) w = max(w, childs[i]->getW());         return w = w + 2 * b;       } else {         if (childs.size() == 0) return 0;         if (w != -1) return w;         w = 0;         for (int i = 0; i < childs.size(); ++i) w += childs[i]->getW();         return w = w + 2 * b + s * max(0LL, (long long)childs.size() - 1);       }     }     long long getH() {       if (type ==  normal )         return h;       else if (type ==  HBox ) {         if (childs.size() == 0) return 0;         if (h != -1) return h;         h = 0;         for (int i = 0; i < childs.size(); ++i) h = max(h, childs[i]->getH());         return h = h + 2 * b;       } else {         if (childs.size() == 0) return 0;         if (h != -1) return h;         h = 0;         for (int i = 0; i < childs.size(); ++i) h += childs[i]->getH();         return h = h + 2 * b + s * max(0LL, (long long)childs.size() - 1);       }     }   };   map<string, Widget> M;   int main() {     int N;     cin >> N;     for (int i = 0; i < N; ++i) {       string com;       cin >> com;       if (com ==  Widget ) {         string name;         cin >> name;         int p1 = name.find( ( );         int p2 = name.find( , );         int p3 = name.find( ) );         string rname = name.substr(0, p1);         string val1 = name.substr(p1 + 1, p2 - p1 - 1);         string val2 = name.substr(p2 + 1, p3 - p2 - 1);         int h, w;         sscanf((val1 +     + val2).c_str(),  %d %d , &w, &h);         M[rname] = Widget(name,  normal , h, w);       } else if (com ==  VBox  || com ==  HBox ) {         string name;         cin >> name;         M[name] = Widget(name, com);       } else {         string name, method, val;         int p1 = com.find( . );         int p2 = com.find( ( );         int p3 = com.find( ) );         name = com.substr(0, p1);         method = com.substr(p1 + 1, p2 - p1 - 1);         val = com.substr(p2 + 1, p3 - p2 - 1);         if (method ==  pack ) {           M[name].pack(&M[val]);         } else {           int n;           sscanf(val.c_str(),  %d , &n);           if (method ==  set_spacing )             M[name].s = n;           else             M[name].b = n;         }       }     }     for (map<string, Widget>::iterator it = M.begin(); it != M.end(); ++it)       cout << (it->first) <<     << (it->second.getW()) <<                << (it->second.getH()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[1000], l[1000], r[1000], mn, mx, ans, mx2, mn2, ansi = -1, ans2;   string s;   int main() {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i == 0) mn = a[i], mx = a[i];       mn = min(mn, a[i]), mx = max(a[i], mx), ans = mx - mn;     }     for (int j = 0; j < m; j++) cin >> l[j] >> r[j];     for (int i = 1; i <= n; i++) {       for (int j = 0; j < m; j++) {         if (i >= l[j] && i <= r[j]) {           for (int k = l[j] - 1; k < r[j]; k++) {             a[k]--;           }         }       }       for (int j = 0; j < n; j++) {         if (j == 0) mn2 = a[j], mx2 = a[j];         mn2 = min(mn2, a[j]), mx2 = max(a[j], mx2);       }       if (ans < mx2 - mn2) ans = mx2 - mn2, ansi = i;       for (int j = 0; j < m; j++) {         if (i >= l[j] && i <= r[j]) {           for (int k = l[j] - 1; k < r[j]; k++) {             a[k]++;           }         }       }     }     cout << ans << endl;     for (int i = 0; i < m; i++) {       if (ansi >= l[i] && ansi <= r[i]) {         ans2++;       }     }     cout << ans2 << endl;     for (int i = 0; i < m; i++) {       if (ansi >= l[i] && ansi <= r[i]) {         cout << i + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int ans = 0;     cin >> n;     string arr[11] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM ,                        SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE };     for (int i = 0; i < n; i++) {       string a;       cin >> a;       if (isdigit(a[0]) != 0) {         if (stoi(a) < 18) {           ans++;         }       } else {         for (int j = 0; j < 11; j++) {           if (a == arr[j]) {             ans++;           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 1e5 + 10;   int n, p[N], h[N];   vector<int> g[N];   vector<pair<int, int> > ans;   void build(int x, int y) {     int m1 = g[x].size();     if (x == y) {       for (auto i = 0; i < m1 - 1; i++)         ans.push_back(pair<int, int>(g[x][i], g[x][i + 1]));       return;     }     for (auto i = 0; i < g[y].size(); i++)       ans.push_back(pair<int, int>(g[x][i % m1], g[y][i]));   }   void solve() {     int m = 0;     for (auto i = 1; i <= n; i++)       if (!h[i]) {         m++;         int cur = i;         while (!h[cur]) {           h[cur] = 1;           g[m].push_back(cur);           cur = p[cur];         }       }     int root = 1;     for (auto i = 1; i <= m; i++)       if (g[i].size() < g[root].size()) root = i;     if (g[root].size() > 2) {       printf( NO );       return;     }     for (auto i = 1; i <= m; i++)       if (g[i].size() % g[root].size()) {         printf( NO );         return;       }     for (auto i = 1; i <= m; i++) build(root, i);     if (ans.size() != n - 1) {       printf( NO n );       return;     }     printf( YES n );     for (auto i : ans) printf( %d %d n , i.first, i.second);   }   int main() {     scanf( %d , &n);     for (auto i = 1; i <= n; i++) scanf( %d , p + i);     solve();   }


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


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <class A>   void read(vector<A>& v);   template <class A, size_t S>   void read(array<A, S>& a);   template <class T>   void read(T& x) {     cin >> x;   }   void read(double& d) {     string t;     read(t);     d = stod(t);   }   void read(long double& d) {     string t;     read(t);     d = stold(t);   }   template <class H, class... T>   void read(H& h, T&... t) {     read(h);     read(t...);   }   template <class A>   void read(vector<A>& x) {     for (auto& a : x) read(a);   }   template <class A, size_t S>   void read(array<A, S>& x) {     for (auto& a : x) read(a);   }   const int MAXN = 2e5 + 5;   long long mod = 998244353;   vector<pair<long long, long long> > gr[200005];   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     read(a);     long long sum = 0;     for (long long i = int(n); i >= int(n - k + 1); i--) {       sum += i;     }     cout << sum <<    ;     long long i = 0, j = n - 1;     while (a[i] < n - k + 1) {       i++;     }     while (a[j] < n - k + 1) j--;     long long cnt = 0;     long long ans = 1;     for (long long r = int(i); r < int(j + 1); r++) {       if (a[r] < (n - k + 1)) {         cnt++;       } else {         if (cnt != 0) ans = (ans * cnt) % mod;         cnt = 1;       }     }     if (cnt != 0) ans = (ans * cnt) % mod;     cout << ans % mod <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     test = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long calc(int n, int k) {     int c = n / k;     long long ans = c;     ans += (long long)(n - k) * c / 2;     return ans;   }   int main() {     int n;     cin >> n;     vector<long long> a;     for (int i = 1; i * i <= n; i++)       if (n % i == 0) {         a.push_back(calc(n, i));         if (i * i != n) a.push_back(calc(n, n / i));       }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     for (long long first : a) printf( %I64d  , first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > dis(100005), edge;   long long int cnt[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 0, n, e, x, y, z, i, j, k, g, q, ans = 0, sum = 0, c = 0, h;     cin >> n >> t;     for (i = 1; i <= n; i++) {       cin >> x;       dis[i].first = x;       dis[i].second = i;     }     sort(dis.begin() + 1, dis.begin() + n + 1);     if (dis[1].first != 0) {       cout <<  -1 n ;       return 0;     }     if (n == 1) {       cout <<  0 n ;       return 0;     }     if (dis[1].first == dis[2].first) {       cout <<  -1 n ;       return 0;     }     vector<long long int> v1, v2;     v1.push_back(dis[1].second);     i = 2;     long long int next = 1;     while (i <= n) {       for (j = i; j <= n; j++) {         if (dis[j].first != next) break;         v2.push_back(dis[j].second);       }       i = j;       long long int s1 = v1.size();       long long int s2 = v2.size();       for (j = 0, k = 0; j < s2 && k < s1;) {         if (cnt[v1[k]] == t) {           k++;           continue;         }         edge.push_back(make_pair(v1[k], v2[j]));         cnt[v1[k]]++;         cnt[v2[j]]++;         if (cnt[v1[k]] == t) k++;         j++;       }       if (j != s2) {         cout <<  -1 n ;         return 0;       }       v1.clear();       next++;       for (j = 0; j < s2; j++) {         v1.push_back(v2[j]);       }       v2.clear();     }     ans = edge.size();     cout << ans <<   n ;     for (i = 0; i < edge.size(); i++) {       cout << edge[i].first <<     << edge[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, max = 0;     string a[100];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (i != j) {           if (a[i].compare(a[j]) == 0) count++;         }       }       if (count > max) max = count;     }     cout << max + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, as = 0;   template <class T>   void read(T &x) {     char ch;     bool ok;     for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) ok = 1;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     if (ok) x = -x;   }   int fp(int x, int y) {     int asi = 1;     while (y) {       if (y & 1) asi = 1ll * asi * x % 1000000007;       x = 1ll * x * x % 1000000007;       y >>= 1;     }     return asi;   }   int get_miu(int x) {     int asi = 1;     for (int i = (2), en = (x); i <= en; ++i) {       if (i * i > x) break;       if (x % i == 0) {         asi = 1000000007 - asi;         x /= i;         if (x % i == 0) return 0;       }     }     if (x != 1) asi = 1000000007 - asi;     return asi;   }   int main() {     read(n);     read(m);     if (m % n) {       puts( 0 );       return 0;     };     m /= n;     for (int i = (1), en = (m); i <= en; ++i) {       if (i * i > m) break;       if (m % i == 0) {         as = (as + 1ll * fp(2, m / i - 1) * get_miu(i) % 1000000007) % 1000000007;         if (i * i != m)           as = (as + 1ll * fp(2, i - 1) * get_miu(m / i) % 1000000007) %                1000000007;       }     }     printf( %d n , as);     return 0;   }


/******************************    *                            *    *    author :  rion_cse      *    *    created:  11.07.2021    *    *                            *    ******************************/       /*******************************************************    *                                                     *    *  ***-->    BISMILLAHIR RAHMANIR RAHIM    <--***     *    *  ***--> ISLAMIC UNIVERSITY OF BANGLADESH <--***     *    *  ***--> COMPUTER SCIENCE AND ENGINEERING <--***     *    *                                                     *    *******************************************************/       #include<bits/stdc++.h>   const int MOD=1e9+7;       #define  pf                 printf   #define  sc                 scanf       #define  s1(n)              scanf( %d ,&n)   #define  s2(n1,n2)          scanf( %d %d ,&n1,&n2)   #define  s3(n1,n2,n3)       scanf( %d %d %d ,&n1,&n2,&n3)   #define  s4(n1,n2,n3,n4)    scanf( %d %d %d %d ,&n1,&n2,&n3,&n4)       #define  ss1(n)             scanf( %lld ,&n)   #define  ss2(n1,n2)         scanf( %lld %lld ,&n1,&n2)   #define  ss3(n1,n2,n3)      scanf( %lld %lld %lld ,&n1,&n2,&n3)   #define  ss4(n1,n2,n3,n4)   scanf( %lld %lld %lld %lld ,&n1,&n2,&n3,&n4)       #define  p1(x)              printf( %I64d ,x)   #define  p2(x,y)            printf( %I64d %I64d ,x,y)   #define  p3(x,y,z)          printf( %I64d %I64d %I64d ,x,y,z)       #define  fi(i,a,b)          for(long long i=a;i<=b;i++)   #define  fm(i , a)          for(long long i=1;i<=a;i++)   #define  fd(i,a,b)          for(long long i=b;i>=a;i--)       #define  clr(x)             memset(x,0,sizeof(x))   #define  cln(x)             memset(x,-1,sizeof(x))       #define  fw                 freopen( output.txt , w ,stdout);       typedef long long int ll;   ///ll ar[1009],arr[1009];   using namespace std;       /*ll LCM(ll a,ll b)   {       return (a/(__gcd(a,b)))*b;   }*/       int main()   {        ll t;        cin>>t;        while(t--)        {         ll n,i,j;         cin>>n;         ll ar[n+5],br[n+5],s=0,s1=0;         vector< ll > v,vc;         for(i=1;i<=n;i++)         {          cin>>ar[i];          s+=ar[i];         }            for(i=1;i<=n;i++)         {           cin>>br[i];            s1+=br[i];         }                  if(s!=s1) cout<< -1 <<endl;         else {                for(i=1;i<=n;i++)                {                 if(ar[i]>br[i]){                   for(j=1;j<=(ar[i]-br[i]);j++)                   v.push_back(i);                 }                    else if(ar[i]<br[i]){                    for(j=1;j<=(br[i]-ar[i]);j++)                   vc.push_back(i);                 }                }                cout<<v.size()<<endl;                for(i=0;i<v.size();i++)                 cout<<v[i]<<   <<vc[i]<<endl;              }      }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = (int)1e9 + 7;   const int mod = (int)1e9 + 7;   const int MAX = (int)1e5 + 5;   int main(void) {     ios_base::sync_with_stdio(false);     int n;     while (cin >> n) {       vector<pair<int, int> > h;       for (int i = 0; i < n; i++) {         int cur;         cin >> cur;         h.push_back(make_pair(cur, i));       }       sort(h.begin(), h.end());       set<pair<int, int> > s;       for (int i = 0; i < n; i++) {         int l = min(i, h[i].second), r = max(i, h[i].second);         auto it = s.lower_bound(make_pair(l, -1));         if (it == s.end()) {           s.insert(make_pair(r, l));         } else {           int cl = it->second, cr = it->first;           if (r > cl) {             s.erase(it);             s.insert(make_pair(max(cr, r), min(cl, l)));           } else {             s.insert(make_pair(r, l));           }         }       }       int seg = s.size(), tot = 0;       for (auto it = s.begin(); it != s.end(); it++) {         tot += it->first - it->second + 1;       }       cout << seg + (n - tot) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long inf = 3e18;   long long t, a[maxn], b[maxn], x[maxn];   long long l[maxn], r[maxn];   int n;   int main() {     scanf( %d%lld , &n, &t);     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     for (int i = 1; i <= n; i++) scanf( %lld , x + i);     for (int i = 1; i <= n; i++) {       if (i < n && x[i] > x[i + 1]) {         puts( No );         return 0;       }       l[i] = a[i] + t;       r[i] = inf;       if (x[i] < i) {         puts( No );         return 0;       }     }     int now = 1;     for (int i = 1; i < n; i++) {       for (now = max(now, i); now < x[i]; now++) {         l[now] = max(l[now], a[now + 1] + t);       }       if (now != n) r[now] = min(r[now], a[now + 1] + t - 1);     }     for (int i = 1; i <= n; i++) {       if (l[i] > r[i]) {         puts( No );         return 0;       }       b[i] = min(r[i], max(b[i - 1] + 1, l[i]));       if (b[i] <= b[i - 1] || b[i - 1] + 1 > r[i]) {         puts( No );         return 0;       }     }     puts( Yes );     for (int i = 1; i <= n; i++) printf( %lld  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     long long n, k, a[55];     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     if (k > n)       cout << -1 << endl;     else {       cout << a[n + 1 - k] <<     << a[n + 1 - k] << endl;     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000;   vector<int> nei[maxn];   bool mark[maxn];   vector<int> nei2[maxn];   bool markk[maxn];   int n, m, comp = 0, comp2 = 0;   void dfs(int v) {     mark[v] = true;     for (int i = 0; i < nei[v].size(); i++) {       int u = nei[v][i];       if (!mark[u]) dfs(u);     }     return;   }   bool dfs_all() {     for (int d = 0; d < n * m; d++) {       if (!mark[d]) {         dfs(d);         comp++;       }     }     if (comp == 1)       return true;     else       return false;   }   void dfs2(int v) {     markk[v] = true;     for (int p = 0; p < nei2[v].size(); p++) {       int u = nei2[v][p];       if (!markk[u]) {         dfs2(u);       }     }     return;   }   bool dfs2_all() {     for (int j = 0; j < n * m; j++) {       if (!markk[j]) {         dfs2(j);         comp2++;       }     }     if (comp2 == 1)       return true;     else       return false;   }   int main() {     string hor, ver;     cin >> n >> m;     cin >> hor >> ver;     for (int j = 0; j < n; j++) {       if (hor[j] ==  > ) {         for (int p = j * m; p < j * m + m - 1; p++) {           nei[p].push_back(p + 1);           nei2[p + 1].push_back(p);         }       } else {         for (int p = j * m + m - 1; p > j * m; p--) {           nei[p].push_back(p - 1);           nei2[p - 1].push_back(p);         }       }     }     for (int j = 0; j < m; j++) {       if (ver[j] ==  v ) {         for (int p = j; p < (n - 1) * m + j; p += m) {           nei[p].push_back(p + m);           nei2[p + m].push_back(p);         }       } else {         for (int p = (n - 1) * m + j; p > j; p -= m) {           nei[p].push_back(p - m);           nei2[p - m].push_back(p);         }       }     }     if (dfs_all() && dfs2_all())       cout <<  YES   << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   void solve() {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < a.size(); i++) {       cin >> a[i];     }     sort((a).begin(), (a).end());     long long int ans = a[n - 1];     for (long long int i = n - 2; i >= 0; i--) {       if (a[i] == 0) continue;       if (k > 0) {         ans += a[i];         k--;       } else {         break;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pre[2010000];   int n, i, m, j, vis[2010000], la[2010000], lr[2010000], s[2010000], q[2010000],       tr[2010000], a[2010000], tim, jid;   inline int gi() {     int s = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return s;   }   void Work(long long x) {     int j = 1;     for (i = 1; i <= n + n; i++) {       while (j < min(i, n) + n && pre[j] - pre[i - 1] <= x) ++j;       la[i] = j - 1;     }     ++tim;     int ans = n + 1;     for (i = 1; i <= la[1]; i++) {       int h = 0;       if (i > n) i -= n, h = 1;       int t = 0, sum = 0, ed = i + n - 1;       for (j = i; j <= ed; j = la[j] + 1) {         if (vis[j] == tim) {           sum += s[j];           if (lr[j] < ed) sum++, j = lr[j] + 1;           q[++t] = j, tr[t] = sum;           break;         } else           q[++t] = j, tr[t] = ++sum;       }       for (j = t; j >= 1; j--)         vis[q[j]] = tim, lr[q[j]] = la[q[t]], s[q[j]] = tr[t] - tr[j - 1];       ans = min(ans, sum);       if (h) i += n;     }     i = la[1] + 1;     if (i <= n) {       int ed = i + n - 1, sum = 0;       for (j = i; j <= ed; j = la[j] + 1) ++sum;       ans = min(ans, sum);     }     printf( %d n , ans);   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) a[i] = a[i + n] = gi();     for (i = 1; i <= n + n; i++) pre[i] = pre[i - 1] + a[i];     while (m--) {       long long x;       scanf( %I64d , &x);       Work(x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   long long dp[N], a[N];   int n, k, ans;   bool check(long long x) {     for (int i = 1; i <= n; i++) {       dp[i] = i - 1;       for (int j = 1; j < i; j++) {         if (abs(a[i] - a[j]) <= (i - j) * x) {           dp[i] = min(dp[i], dp[j] + (i - j - 1));         }       }       if (dp[i] + n - i <= k) return 1;     }     return 0;   }   int main() {     scanf( %d%d , &n, &k);     long long L = 0, R = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i != 1) R = max((long long)R, abs(a[i] - a[i - 1]));     }     while (L <= R) {       long long mid = (L + R) >> 1;       if (check(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int N, V, M;   int Size[310], Final[310], T[310];   vector<int> G[310];   vector<pair<pair<int, int>, int> > ANS;   int source, sink, flow;   void FindSource(int node) {     if (Size[node] > Final[node]) {       source = node;       return;     }     for (vector<int>::iterator it = G[node].begin(); it != G[node].end(); ++it)       if (T[*it] == 0 && *it != sink) {         T[*it] = node;         FindSource(*it);       }   }   void Transfer(int source, int sink, int flow) {     Size[source] -= flow;     Size[sink] += flow;     ANS.push_back(make_pair(make_pair(source, sink), flow));   }   void Push(int node) {     int next = T[node];     if (next == sink) {       Transfer(node, sink, flow);       return;     }     int add = 0;     if (Size[next] < flow) {       add = flow - Size[next];       Transfer(node, next, add);     }     Push(next);     Transfer(node, next, flow - add);   }   void Fill(int node) {     sink = node;     while (Size[node] < Final[node]) {       source = 0;       memset(T, 0, sizeof(T));       FindSource(node);       if (source == 0) break;       flow = min(Size[source] - Final[source], Final[sink] - Size[sink]);       Push(source);     }   }   int main() {     cin >> N >> V >> M;     for (int i = 1; i <= N; i++) cin >> Size[i];     for (int i = 1; i <= N; i++) cin >> Final[i];     for (int i = 1; i <= M; i++) {       int a, b;       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 1; i <= N; i++)       if (Size[i] < Final[i]) Fill(i);     bool OK = 1;     for (int i = 1; i <= N; i++)       if (Size[i] != Final[i]) OK = 0;     if (OK == 0)       cout <<  NO  <<   n ;     else {       cout << ANS.size() <<   n ;       for (vector<pair<pair<int, int>, int> >::iterator it = ANS.begin();            it != ANS.end(); ++it)         cout << (it->first).first <<     << (it->first).second <<                  << (it->second) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int flag = 0, ans = 0;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       set<int> check;       flag = 1;       for (int j = 0; j < k; j++) {         int t;         cin >> t;         if (check.count(-t)) {           flag = 0;         }         check.insert(t);       }       if (flag) ans = 1;     }     if (ans) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T Abs(const T& x) {     return x < 0 ? -x : x;   }   template <class T>   inline T Sqr(const T& x) {     return x * x;   }   const int maxn = 110;   const int maxk = 210;   double a[maxn][maxn][maxk];   int n, k;   int Get(int l, int r, int pos) {     if (pos < l || pos > r) {       return pos;     } else {       return l + r - pos;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     vector<int> p(n);     for (int i = 0; i < n; ++i) {       cin >> p[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         a[i][j][0] = (i < j ? 1.0 : 0.0);       }     }     double cnt = 0;     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         cnt += 1.0;       }     }     for (int iter = 1; iter <= k; ++iter) {       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           a[i][j][iter] = 0;           for (int l = 0; l < n; ++l) {             for (int r = l; r < n; ++r) {               int i1 = Get(l, r, i);               int j1 = Get(l, r, j);               a[i][j][iter] += 1 / cnt * a[i1][j1][iter - 1];             }           }         }       }     }     double ans = 0.0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (p[i] < p[j]) {           ans += a[j][i][k];         } else {           ans += a[i][j][k];         }       }     }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, a[100010], b[100010], posA[100010];   multiset<int> S;   int get(int x) {     multiset<int>::iterator it = S.lower_bound(x), jt = it;     return min(abs(*it - x), abs(*--jt - x));   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &a[i]), posA[a[i]] = i;     for (int i = 1; i <= N; i++) scanf( %d , &b[i]), S.insert(i - posA[b[i]]);     S.insert(-1e9);     for (int x = 1; x <= N; x++) {       printf( %d n , get(x - 1));       S.erase(S.find(x - posA[b[x]]));       S.insert(x - posA[b[x]] + N);     }   }


#include <bits/stdc++.h>   using namespace std;   double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }   long long GI(long long& x) { return scanf( %lld , &x); }   const long long MOD = 1e9 + 7;   const long long MN = 1000111;   long long gt[MN];   vector<long long> h[MN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout << (fixed) << setprecision(9);     const long long MOD = 1e9 + 7;     gt[0] = 1;     for (long long i = (1), _b = (MN - 1); i <= _b; ++i)       gt[i] = gt[i - 1] * i % MOD;     long long n, m;     while (GI(n) == 1 && GI(m) == 1) {       for (long long i = (1), _b = (m); i <= _b; ++i) h[i].clear();       for (long long i = (1), _b = (n); i <= _b; ++i) {         long long k;         GI(k);         while (k--) {           long long u;           GI(u);           h[u].push_back(i);         }       }       sort(h + 1, h + m + 1);       long long i = 1;       long long res = 1;       while (i <= m) {         long long j = i;         while (j < m && h[j + 1] == h[i]) j++;         res = res * gt[j - i + 1] % MOD;         i = j + 1;       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x;     int i;   };   node a[300010];   int b[300010];   map<int, int> mp;   bool cmp(node p, node q) { return (p.x < q.x); }   int main() {     int x, y, i, j, n, k;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i].x;       mp[a[i].x]++;       a[i].i = i;     }     sort(a, a + n, cmp);     for (i = 0, j = 1; i < n; i++) {       if (i == 0)         b[a[i].i] = a[i].x;       else if ((a[i].x == a[i - 1].x)) {         j = max(j, a[i].x + 1);         while (1) {           if (j <= a[i].x || mp[j] > 0) {             j++;             continue;           }           break;         }         b[a[i].i] = j;         mp[j]++;       } else {         b[a[i].i] = a[i].x;       }     }     for (i = 0; i < n; i++) cout << b[i] <<    ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define forg(i,x) for(register int i=fir[x];i;i=nxt[i])   #define uu unsigned   #define scanf a14=scanf   #define rint register int   #define fre(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout)   typedef long long ll;   typedef uu long long ull;   typedef pair<int,int>pii;   int a14;   inline int rd(int l,int r){return rand()%(r-l+1)+l;}      const int mxn=1e5+3,sq=400,qs=320;   int n,b[mxn],lp[mxn],rp[mxn],kn,be[mxn],po[mxn],qn;   int ju[mxn/sq+2][mxn],ad[mxn/sq+2][mxn/qs+1];   int TG;   struct shu{       int a[mxn],tg[mxn];       void add(int x){for(;x<=n;x+=x&-x){if(tg[x]!=TG)tg[x]=TG,a[x]=0;++a[x];}}       int ask(int x){           int su=0,p=0;           for(int i=1<<16;i;i>>=1){               if(p+i>=n)continue;               p+=i;if(tg[p]!=TG)tg[p]=TG,a[p]=0;               if(p+a[p]+su>=x)p-=i;else su+=a[p];           }           return p+1;       }       void gb(int t){for(int i=1;i<=n;++i){if(tg[i]!=TG)a[i]=0;ju[t][i]=ju[t][i-(i&-i)]+a[i];}for(int i=1;i<=n;++i)ju[t][i]+=i;}   }ar;   void add2(int t,int x,int y){       int k=(x-1)/qs;       for(int i=x;i<=(k+1)*qs;++i)ju[t][i]+=y;       for(++k;k*qs+1<=n;++k)ad[t][k]+=y;   }   int main(){   //cout<<(sizeof(ju)>>20)<<endl;       scanf( %d ,&n);for(int i=1;i<=n;++i)scanf( %d ,b+i),b[i]=i-b[i];scanf( %d ,&qn);       for(int l=1,r;r!=n;l=r+1){r=min(l+sq-1,n);lp[++kn]=l,rp[kn]=r;for(int i=l;i<=r;++i)be[i]=kn;}       for(int t=1;t<=kn;++t){           ++TG; for(int i=lp[t];i<=rp[t];++i)po[i]=ar.ask(b[i]),ar.add(po[i]);           ar.gb(t);       }       while(qn--){           int o,x,y;scanf( %d%d ,&o,&x);if(o==1){               scanf( %d ,&y);b[x]=x-y;int k=be[x],ls;               ++TG;for(int i=lp[k];i<=rp[k];++i){                   if(i<x)ar.add(po[i]);else{                       ls=po[i],po[i]=ar.ask(b[i]),ar.add(po[i]);                       if(ls==po[i])continue;                       if(ls==po[i]-1){--ju[k][ls];continue;}                       if(ls==po[i]+1){++ju[k][po[i]];continue;}                       assert(i==x);                       add2(k,ls,-1),add2(k,po[i],1);                   }               }           }else{               int t=be[x],re=b[x];for(int i=x+1;i<=rp[t];++i)re+=b[i]<=re;               for(++t;t<=kn;++t)re=ju[t][re]+ad[t][(re-1)/qs];               printf( %d n ,re);           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[105], a[105], sum[105];   int main() {     int n, b;     cin >> n >> b;     for (int i = 0; i < n; i++) scanf( %d , a + i);     int t = 0, nn = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i] % 2)         t++;       else         t--;       if (t == 0) {         ans[nn] = abs(a[i] - a[i + 1]);         nn++;       }     }     sort(ans, ans + nn);     sum[0] = 0;     for (int i = 0; i < nn; i++) sum[i + 1] = ans[i] + sum[i];     t = nn;     for (;; t--) {       if (sum[t] <= b) {         cout << t << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, sumaP, sumaI, ultimo, primero;     cin >> t;     while (t--) {       cin >> n;       if (n % 4 != 0)         cout <<  NO  << endl;       else {         sumaP = (n / 2) * (n / 2 + 1);         sumaI = (n / 2 - 1) * (n / 2 - 1);         ultimo = sumaP - sumaI;         cout <<  YES  << endl;         primero = 2;         for (int i = 0; i < n / 2; i++) {           cout << primero <<    ;           primero += 2;         }         primero = 1;         for (int i = n / 2; i < n - 1; i++) {           cout << primero <<    ;           primero += 2;         }         cout << ultimo << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << setprecision(20) << fixed;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       vector<long long> b, c;       long long s = 0, z = 0;       for (long long i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > 0) {           b.push_back(a[i]);           s += a[i];         } else if (a[i] == 0)           z++;         else           c.push_back(a[i]);       }       long long f = 0;       for (long long i = 0; i < c.size(); i++) {         if (s + c[i] != 0) {           s += c[i];           b.push_back(c[i]);         } else {           f = 1;           b.push_back(c[i]);           s += c[i];         }       }       if (f == 1) reverse(b.begin(), b.end());       for (long long i = 0; i < z; i++) b.push_back(0);       if (s == 0)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         for (long long i = 0; i < n; i++) cout << b[i] <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   struct Side {     int x, y;     Side(int x, int y) : x(x), y(y) {}   };   struct Part {     int id, z;     Part() {}     Part(int id, int z) : id(id), z(z) {}   };   struct Answer {     int a, b;     Answer(){};     Answer(int a, int b) : a(a), b(b) {}   };   bool operator<(const Side &left, const Side &right) {     if (left.x != right.x) {       return left.x < right.x;     }     return left.y < right.y;   }   int min(int x, int y, int z) { return std::min(x, std::min(y, z)); }   void check(int id, int x, int y, int z, std::map<Side, Part> &sides,              Answer &ans, int &bestV) {     if (x > y) {       check(id, y, x, z, sides, ans, bestV);       return;     }     auto it = sides.find(Side(x, y));     if (it == sides.end()) {       return;     }     z += (*it).second.z;     int minV = min(x, y, z);     if (minV > bestV) {       bestV = minV;       ans.a = (*it).second.id;       ans.b = id;     }   }   void add(int id, int x, int y, int z, std::map<Side, Part> &sides) {     if (x > y) {       add(id, y, x, z, sides);       return;     }     auto it = sides.find(Side(x, y));     if (it != sides.end()) {       if ((*it).second.z >= z) {         return;       }     }     sides[Side(x, y)] = Part(id, z);   }   int main() {     std::map<Side, Part> sides;     int n;     scanf( %d , &n);     Answer ans;     int bestV = 0;     for (int i = 1; i <= n; i++) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       int minV = min(x, y, z);       if (minV > bestV) {         bestV = minV;         ans = Answer(i, -1);       }       check(i, x, y, z, sides, ans, bestV);       check(i, x, z, y, sides, ans, bestV);       check(i, y, z, x, sides, ans, bestV);       add(i, x, y, z, sides);       add(i, x, z, y, sides);       add(i, y, z, x, sides);     }     if (ans.b == -1) {       printf( 1 n%d , ans.a);     } else {       printf( 2 n%d %d , ans.a, ans.b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N, H;     cin >> N >> H;     vector<int> A(N);     for (int i = 0; i < N; i++) cin >> A[i];     vector<long long> b;     int ans = 0;     for (int i = 0; i < N; i++) {       b.push_back(A[i]);       sort(b.begin(), b.end());       long long sum = 0;       for (int i = b.size() - 1; i >= 0; i -= 2) {         sum += b[i];       }       if (sum <= H)         ans++;       else         break;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool MySort(const pair<int, int>& A, const pair<int, int>& B) {     return A.first > B.first;   }   int main() {     int T;     cin >> T;     while (T--) {       long long X, Y, K;       cin >> X >> Y >> K;       long long Ans = 0;       long long All = Y * K + K;       All--;       if (All % (X - 1) == 0) {         Ans += (All / (X - 1));       } else {         Ans += (All / (X - 1)) + 1;       }       Ans += K;       cout << Ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     while (k--) {       if (n % 10 == 0)         n = n / 10;       else         n--;     }     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long arr[2 * n];     for (long long i = 0; i < 2 * n; i++) cin >> arr[i];     long long m = 0;     for (long long i = 0; i < 2 * n; i++) {       if (arr[i] != arr[i + 1]) {         for (long long j = i + 1; j < 2 * n; j++) {           if (arr[i] == arr[j]) {             for (long long k = j; k > i + 1; k--) {               swap(arr[k], arr[k - 1]);               m++;             }             break;           }         }         i++;       } else         i++;     }     cout << m;   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   const ll N = 1e5 + 1, mod = 1e9 + 7;   struct point {     ll x, y;   } p[N];   ll n;   bool line[N];   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (ll i = 1; i <= n; ++i) {       cin >> p[i].x >> p[i].y;     }     if (n <= 4) {       return cout <<  YES , 0;     }     for (ll i = 1; i <= 3; ++i) {       for (ll j = i + 1; j <= 3; ++j) {         memset(line, 0, sizeof line);         ll a = p[i].y - p[j].y, b = p[j].x - p[i].x;         ll c = a * p[i].x + b * p[i].y;         for (ll k = 1; k <= n; ++k) {           if (a * p[k].x + b * p[k].y != c) {             line[k] = 1;           }         }         ll cnt0 = 0;         point p1 = {INT_MAX, 0}, p2 = {INT_MAX, 0};         for (ll k = 1; k <= n && cnt0 < 2; ++k) {           if (line[k]) {             if (!cnt0) {               p1 = p[k];             } else {               p2 = p[k];             }             cnt0++;           }         }         if (p1.x == INT_MAX || p2.x == INT_MAX) {           return cout <<  YES , 0;         }         a = p1.y - p2.y, b = p2.x - p1.x;         c = a * p1.x + b * p1.y;         bool yes = 1;         for (ll k = 1; k <= n; ++k) {           if (line[k] && a * p[k].x + b * p[k].y != c) {             yes = 0;           }         }         if (yes) {           return cout <<  YES , 0;         }       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(int a, int b) {     if (!b) return a;     return gcd(b, a % b);   }   bool isprime(long long n) {     if (n == 2) {       return true;     }     if (n % 2 == 0) {       return false;     }     for (long long i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long a[1005][2];   int main() {     long long n, m;     cin >> n >> m;     long long flag[m];     memset(flag, 0, sizeof(flag));     for (int(i) = (0); (i) < (m); (i)++) {       long long k;       cin >> k;       map<int, int> m;       for (int(j) = (0); (j) < (k); (j)++) {         long long x;         cin >> x;         m[x]++;         if (m.find(-x) != m.end()) flag[i] = 1;       }     }     for (int(i) = (0); (i) < (m); (i)++) {       if (flag[i] == 0) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int r, c, id;   } q[100001];   int m, n;   bool cmph(Q a, Q b) {     if (a.r != b.r) return a.r < b.r;     return a.c < b.c;   }   bool cmps(Q a, Q b) {     if (a.c != b.c) return a.c < b.c;     return a.r < b.r;   }   bool cmpp(Q a, Q b) {     if (a.r + a.c != b.r + b.c) return a.r + a.c < b.r + b.c;     return a.r < b.r;   }   bool cmpn(Q a, Q b) {     if (a.r - a.c != b.r - b.c) return a.r - a.c < b.r - b.c;     return a.r < b.r;   }   int cnt[100001];   int main(int argc, char *argv[]) {     scanf( %d%d , &m, &n);     do {       memset(cnt, 0, sizeof(cnt));     } while (0);     for (int i = 0; i < n; i++) {       scanf( %d%d , &(q[i].r), &(q[i].c));       q[i].id = i;     }     sort(q, q + n, cmph);     for (int i = 1; i < n; i++) {       if (q[i - 1].r == q[i].r) {         cnt[q[i - 1].id]++;         cnt[q[i].id]++;       }     }     sort(q, q + n, cmps);     for (int i = 1; i < n; i++) {       if (q[i - 1].c == q[i].c) {         cnt[q[i - 1].id]++;         cnt[q[i].id]++;       }     }     sort(q, q + n, cmpp);     for (int i = 1; i < n; i++) {       if (q[i - 1].r + q[i - 1].c == q[i].r + q[i].c) {         cnt[q[i - 1].id]++;         cnt[q[i].id]++;       }     }     sort(q, q + n, cmpn);     for (int i = 1; i < n; i++) {       if (q[i - 1].r - q[i - 1].c == q[i].r - q[i].c) {         cnt[q[i - 1].id]++;         cnt[q[i].id]++;       }     }     int cc[9];     do {       memset(cc, 0, sizeof(cc));     } while (0);     for (int i = 0; i < n; i++) cc[cnt[i]]++;     for (int i = 0; i < 9; i++) {       printf( %d  , cc[i]);     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int n;   vector<int> point[2];   vector<pair<long long, int> > area[2], vec[4];   long long query(int type, int i, int j, int k) {     printf( %d %d %d %d n , type, i, j, k);     fflush(stdout);     long long res;     scanf( %lld , &res);     return res;   }   int main() {     scanf( %d , &n);     for (int i = 3; i <= n; i++) {       if (query(2, 1, 2, i) < 0)         point[0].emplace_back(i);       else         point[1].emplace_back(i);     }     for (int i = 0; i < point[0].size(); i++)       area[0].emplace_back(make_pair(query(1, 1, 2, point[0][i]), point[0][i]));     for (int i = 0; i < point[1].size(); i++)       area[1].emplace_back(make_pair(query(1, 1, 2, point[1][i]), point[1][i]));     pair<long long, int> L, R;     for (int i = 0; i < area[0].size(); i++) L = max(L, area[0][i]);     for (int i = 0; i < area[1].size(); i++) R = max(R, area[1][i]);     for (int i = 0; i < point[0].size(); i++) {       if (point[0][i] == L.second) continue;       if (query(2, 1, L.second, point[0][i]) < 0)         vec[0].push_back(area[0][i]);       else         vec[1].push_back(area[0][i]);     }     for (int i = 0; i < point[1].size(); i++) {       if (point[1][i] == R.second) continue;       if (query(2, 1, R.second, point[1][i]) < 0)         vec[2].emplace_back(area[1][i]);       else         vec[3].emplace_back(area[1][i]);     }     for (int i = 0; i <= 3; i++) sort(vec[i].begin(), vec[i].end());     printf( 0 1  );     for (int i = 0; i < vec[0].size(); i++) printf( %d  , vec[0][i].second);     if (L.second) printf( %d  , L.second);     for (int i = vec[1].size() - 1; i >= 0; i--) printf( %d  , vec[1][i].second);     printf( 2  );     for (int i = 0; i < vec[2].size(); i++) printf( %d  , vec[2][i].second);     if (R.second) printf( %d  , R.second);     for (int i = vec[3].size() - 1; i >= 0; i--) printf( %d  , vec[3][i].second);     printf(  n );     fflush(stdout);   }