#include <bits/stdc++.h>   using namespace std;   void smain();   int main() {     ios::sync_with_stdio(false);     smain();     return 0;   }   const int maxn = 300000 + 10;   int num[maxn];   int num1[maxn], num2[maxn];   int tot = 1;   int min1[maxn], min2[maxn];   int la1[maxn], la2[maxn];   int flo(int a, int b) {     int ans = a / b;     if (a % b != 0) ans++;     return ans;   }   const int INF = 2e9;   int a1[maxn], a2[maxn];   int flag[maxn];   bool cal(int n, int *Min, int *La, int *This, int *a1, int *a2) {     bool flagg = false;     int A1, A2;     for (int i = (2); i <= (n); ++i) {       if (Min[i - 1] == INF || This[i] == INF) continue;       if (Min[i - 1] + This[i] <= i) {         flagg = true;         A1 = La[i - 1];         A2 = i;         break;       }     }     if (!flagg) return false;     a1[0] = Min[A1];     a2[0] = This[A2];     int i = 1, j = 1;     for (j = 1; j < a1[0]; ++i) {       a1[j] = flag[i];       ++j;     }     a1[j] = flag[A1];     for (j = 1; j < a2[0]; ++i) {       if (i == A1) continue;       a2[j] = flag[i];       ++j;     }     a2[j] = flag[A2];     return true;   }   struct Node {     int o, flag;   } node[maxn];   bool cmp(Node a, Node b) { return a.o > b.o; }   void smain() {     int n, x1, x2;     cin >> n >> x1 >> x2;     for (int i = (1); i <= (n); ++i) cin >> num[i];     for (int i = (1); i <= (n); ++i) node[i].o = num[i], node[i].flag = i;     sort(node + 1, node + n + 1, cmp);     for (int i = (1); i <= (n); ++i) num[i] = node[i].o, flag[i] = node[i].flag;     int tmp;     for (int i = (1); i <= (n); ++i) {       tmp = flo(x1, num[i]);       if (tmp > i) tmp = INF;       min1[i] = num1[i] = tmp;       tmp = flo(x2, num[i]);       if (tmp > i) tmp = INF;       min2[i] = num2[i] = tmp;       la1[i] = la2[i] = i;     }     for (int i = (2); i <= (n); ++i) {       if (min1[i - 1] <= min1[i]) {         min1[i] = min1[i - 1];         la1[i] = la1[i - 1];       }       if (min2[i - 1] <= min2[i]) {         min2[i] = min2[i - 1];         la2[i] = la2[i - 1];       }     }     int ans1 = -1, ans2 = -1;     if (cal(n, min1, la1, num2, a1, a2)) {     } else if (cal(n, min2, la2, num1, a2, a1)) {     } else {       cout <<  No  << endl;       return;     }     cout <<  Yes  << endl;     cout << a1[0] <<     << a2[0] << endl;     for (int i = 1; a1[i] != 0; ++i) cout << a1[i] <<    ;     cout << endl;     for (int i = 1; a2[i] != 0; ++i) cout << a2[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};   int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   void fast() {     std::ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   string t;   bool solve(int m) { return t.substr(0, m) == t.substr(t.size() - m); }   int main() {     fast();     ;     int n, k;     cin >> n >> k;     cin >> t;     int idx = 1;     int mx = 0;     while (idx <= t.size() / 2) {       if (solve(idx)) {         mx = max(mx, idx);       }       idx++;     }     string s = t.substr(mx);     string a = t;     for (int i = 0; i < k - 1; i++) a += s;     mx = 0;     while (k) {       for (idx = 0; k; idx++) {         if (a.substr(idx, t.size()) == t) {           k--;           mx = idx + t.size();           if (k == 0) break;         }       }     }     cout << a.substr(0, mx) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int query(int x) {     printf( ? %d n , x);     int res;     fflush(stdout);     scanf( %d , &res);     return res;   }   int main() {     int n;     scanf( %d , &n);     int m = n / 2;     if (m % 2 == 1) {       printf( ! -1 n );       exit(0);     }     int d = query(1) - query(m + 1);     if (d == 0) {       printf( ! 1 n );       exit(0);     }     int l = 2, r = m;     while (l <= r) {       int mid = (l + r) / 2;       int t = query(mid) - query(mid + m);       if (!t) {         printf( ! %d n , mid);         exit(0);       }       if ((t < 0 && d < 0) || (t > 0 && d > 0))         l = mid + 1;       else         r = mid - 1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n), b;     for (auto i = 0; i < (n); i++) {       cin >> a[i];     };     int cnt = 0, pos1 = 0, pos2 = 0;     for (auto i = 0; i < (n); i++)       if (a[i] != i + 1) {         b.push_back((i));         cnt++;       }     bool flag = true;     long long int x = b.size();     for (auto i = 0; i < (x - 1); i++) {       if (b[i + 1] - b[i] != 1) flag = false;     }     if (cnt == 0)       cout << 0;     else if (flag)       cout << 1;     else if (cnt == 2) {       cout << 2;     } else if (cnt == n)       cout << 1;     else if (cnt > 2)       cout << 2;   }   void template1() {     long long int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     template1();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int BASE = 27;   const int N = 200000 + 2;   const int LOGN = 20;   const long long oo = 1e18;   const double EPS = 1e-9;   int n, q, a[N], mn[N], mx[N], freq[N], dsu[N], bst[N], sum[N];   int find(int i) { return dsu[i] == i ? i : dsu[i] = find(dsu[i]); }   struct seg {     int l, r, val;     seg(int _l, int _r, int _val) { l = _l, r = _r, val = _val; }     bool operator<(const seg& sg) const { return l < sg.l; }   };   vector<seg> cln;   vector<seg> sg;   int main() {     memset(mn, -1, sizeof mn);     cin >> n >> q;     for (int i = 1; i <= 200000; ++i) dsu[i] = i;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       freq[a[i]]++;       if (mn[a[i]] == -1) {         mn[a[i]] = mx[a[i]] = i;       }       mx[a[i]] = max(mx[a[i]], i);       mn[a[i]] = min(mn[a[i]], i);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       sg.push_back(seg(mn[i], mx[i], i));     }     sort(sg.begin(), sg.end());     for (int i = 0; i < sg.size(); ++i) {       if (cln.size() && cln.back().r >= sg[i].l) {         dsu[find(cln.back().val)] = find(sg[i].val);         cln.back().r = max(cln.back().r, sg[i].r);         continue;       }       cln.push_back(sg[i]);     }     for (int i = 1; i <= 200000; ++i) {       if (mn[i] == -1) continue;       bst[find(i)] = max(bst[find(i)], freq[i]);       sum[find(i)] += freq[i];     }     int ans = 0;     for (int i = 1; i <= 200000; ++i) {       if (find(i) == i) {         ans += sum[i] - bst[i];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     int t = 0, row = 0, col = 0;     long long x = 0;   };   int n, m;   vector<vector<long long>> mat;   void rotate_row(int row) {     long long temp = mat[row][m];     for (int i = m; i > 1; i--) {       mat[row][i] = mat[row][i - 1];     }     mat[row][1] = temp;   }   void rotate_col(int col) {     long long temp = mat[n][col];     for (int i = n; i > 1; i--) {       mat[i][col] = mat[i - 1][col];     }     mat[1][col] = temp;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       long long q;       cin >> n >> m >> q;       for (int i = 0; i <= n; i++) {         vector<long long> temp(m + 1, 0);         mat.push_back(temp);       }       stack<query> s;       while (q--) {         int t, row, col;         long long x;         query temp;         cin >> t;         if (t == 1) {           cin >> row;           temp.t = t;           temp.row = row;         }         if (t == 2) {           cin >> col;           temp.t = t;           temp.col = col;         }         if (t == 3) {           cin >> row >> col >> x;           temp.row = row;           temp.col = col;           temp.x = x;           temp.t = t;         }         s.push(temp);       }       while (!s.empty()) {         int t = s.top().t;         int row = s.top().row;         int col = s.top().col;         long long x = s.top().x;         if (t == 1) {           rotate_row(row);         }         if (t == 2) {           rotate_col(col);         }         if (t == 3) {           mat[row][col] = x;         }         s.pop();       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cout << mat[i][j] <<    ;         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (~scanf( %d , &n)) {       int t = sqrt(n * 1.0);       for (int i = t; i >= 1; i--) {         if (n % i == 0) {           cout << i <<     << n / i << endl;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     int a, b;     int draw = 0, awin = 0, bwin = 0;     cin >> a >> b;     for (i = 1; i < 7; i++) {       if (abs(i - a) == abs(i - b))         draw++;       else if (abs(i - a) > abs(i - b))         bwin++;       else         awin++;     }     cout << awin <<     << draw <<     << bwin << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long double pii = 3.14159265359;   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 200001;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string str;     cin >> str;     vector<int> v(6);     for (int x = 0; x < (6); x++) v[x] = str[x] -  0 ;     vector<int> val(6);     int mn = INT_MAX;     for (int z = 0; z < (10); z++) {       if (z == v[0])         val[0] = 1;       else         val[0] = 0;       for (int b = 0; b < (10); b++) {         if (b == v[1])           val[1] = 1;         else           val[1] = 0;         for (int c = 0; c < (10); c++) {           if (c == v[2])             val[2] = 1;           else             val[2] = 0;           for (int d = 0; d < (10); d++) {             if (d == v[3])               val[3] = 1;             else               val[3] = 0;             for (int e = 0; e < (10); e++) {               if (e == v[4])                 val[4] = 1;               else                 val[4] = 0;               for (int first = 0; first < (10); first++) {                 if (first == v[5])                   val[5] = 1;                 else                   val[5] = 0;                 if (z + b + c == d + e + first)                   ckmin(mn, 6 - (val[0] + val[1] + val[2] + val[3] + val[4] +                                  val[5]));               }             }           }         }       }     }     cout << mn << nl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int N = 2e5 + 5, M = 998244353, INF = 0x3f3f3f3f;   void Main();   void print() { cout <<   n ; }   template <typename T, typename... U>   void print(const T& x, const U&... y) {     ((sizeof...(y) == 0) ? (cout << x) : (cout << x <<    ));     print(y...);   }   template <typename T>   void print(const T& a, int l, int r, char c) {     for (int i = l; i <= r; ++i) {       cout << a[i];       if (i == r)         cout <<   n ;       else         cout << c;     }   }   void input() {}   template <typename T, typename... U>   void input(T& x, U&... y) {     cin >> x;     input(y...);   }   template <typename T>   void input(T& a, int l, int r, bool f) {     for (int i = l; i <= r; ++i) cin >> a[i];   }   template <typename T>   void Max(T& a, T b) {     a < b ? a = b : 1;   }   template <typename T>   void Min(T& a, T b) {     a > b ? a = b : 1;   }   template <typename T>   void Add(T& a, T b) {     a += b, a > M ? a -= M : 1;   }   template <typename T>   void Mul(T& a, T b) {     a = a * b % M;   }   int main(int argc, char** argv) {     ios::sync_with_stdio(0), cin.tie(0);     Main();   }   struct Dinic {     int tot, S, T;     struct edge {       int v, w, rev;     };     vector<edge> G[N];     void add(int u, int v, int w) {       G[u].push_back({v, w, (int)G[v].size()});       G[v].push_back({u, 0, (int)G[u].size() - 1});     }     void init(int tot_) {       tot = tot_;       for (int i = 0; i <= tot_; i++) G[i].clear();     }     int dis[N], cur[N], num[N], pv[N], pe[N];     void bfs() {       for (int i = 0; i <= tot; i++) dis[i] = INF;       dis[T] = 0;       queue<int> q;       q.push(T);       while (!q.empty()) {         int u = q.front();         q.pop();         for (edge& e : G[u])           if (G[e.v][e.rev].w && dis[e.v] == INF)             dis[e.v] = dis[u] + 1, q.push(e.v);       }     }     int augment() {       int u = T, ans = INF;       while (u != S) {         ans = min(ans, G[pv[u]][pe[u]].w);         u = pv[u];       }       u = T;       while (u != S) {         G[pv[u]][pe[u]].w -= ans;         G[u][G[pv[u]][pe[u]].rev].w += ans;         u = pv[u];       }       return ans;     }     int maxflow(int S_, int T_) {       S = S_, T = T_;       bfs();       for (int i = 1; i <= tot; i++) num[i] = 0, cur[i] = 0;       for (int i = 1; i <= tot; i++)         if (dis[i] != INF) num[dis[i]]++;       int ans = 0, u = S;       while (dis[S] < tot) {         if (u == T) {           ans += augment();           u = S;         }         bool adv = 0;         for (int& i = cur[u]; i < G[u].size(); i++) {           int v = G[u][i].v, w = G[u][i].w;           if (w <= 0 || dis[u] != dis[v] + 1) continue;           cur[u] = i;           adv = 1, pv[v] = u, pe[v] = i, u = v;           break;         }         if (!adv) {           if (dis[u] != INF && --num[dis[u]] == 0) break;           dis[u] = tot - 1;           for (const edge& e : G[u])             if (e.w > 0) dis[u] = min(dis[u], dis[e.v]);           num[++dis[u]]++;           cur[u] = 0;           if (u != S) u = pv[u];         }       }       return ans;     }   } D;   int tot, n, m, id[N << 2], L, R, now;   void build(int o, int l, int r) {     if (l == r) {       id[o] = ++tot;       D.add(id[o], n + l, 1);       return;     }     id[o] = ++tot;     int mid = (l + r) / 2;     build((o << 1), l, mid), build(((o << 1) | 1), mid + 1, r);     D.add(id[o], id[(o << 1)], INF), D.add(id[o], id[((o << 1) | 1)], INF);   }   void update(int o, int l, int r) {     if (l > R || r < L) return;     if (L <= l && r <= R) {       D.add(now, id[o], 1);       return;     }     int mid = (l + r) / 2;     update((o << 1), l, mid), update(((o << 1) | 1), mid + 1, r);   }   void dfs(int u, int fa, int& ans) {     if (u <= n) {       ans = u;       return;     }     for (int i = (int)D.G[u].size() - 1; i >= 0; --i) {       Dinic::edge& e = D.G[u][i];       if (e.v && e.w > 0) {         dfs(e.v, u, ans);         --e.w;         return;       }     }   }   int A[N], B[N], C[N], ans[N], num[N];   void Main() {     input(n, m);     tot = n + m;     build(1, 1, m);     D.tot = tot + 2;     const int S = tot + 1, T = tot + 2;     for (int i = 1, op, k, x; i <= n; ++i) {       input(op);       if (op == 0) {         D.add(S, i, 1);         input(k);         while (k--) {           input(x);           D.add(i, x + n, 1);         }       } else if (op == 1) {         D.add(S, i, 1);         input(L, R);         now = i;         update(1, 1, m);       } else {         D.add(S, i, 2);         input(A[i], B[i], C[i]);         D.add(i, A[i] + n, 1);         D.add(i, B[i] + n, 1);         D.add(i, C[i] + n, 1);       }     }     for (int i = 1; i <= m; ++i) D.add(i + n, T, 1);     print(D.maxflow(S, T));     for (Dinic::edge e : D.G[T])       if (e.w) dfs(e.v, T, ans[e.v - n]);     for (int i = 1; i <= m; ++i) ++num[ans[i]];     for (int i = 1; i <= n; ++i)       if (A[i] && num[i] == 1) {         if (ans[A[i]] != i)           ans[A[i]] = i;         else           ans[B[i]] = i;       }     for (int i = 1; i <= m; ++i)       if (ans[i]) print(ans[i], i);   }


#include <bits/stdc++.h>   using namespace std;   int i;   double x, y, n, a, b, rsa, rsb = 1;   long long cmmdc(long long a, long long b) {     while (a && b) (a > b ? a %= b : b %= a);     return a + b;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> x >> y >> n;     for (b = 1; b <= n; ++b) {       a = max(0LL, (long long)(x * b / y) - 5);       for (i = 0; i < 10; ++i, ++a) {         double gmb = fabs(x * b - y * a) / (y * b);         double fnc = fabs(x * rsb - y * rsa) / (y * rsb);         if (gmb < fnc)           rsb = b, rsa = a;         else if (gmb == fnc && a / cmmdc(a, b) < rsa / cmmdc(rsa, rsb))           rsa = a, rsb = b;       }     }     long long ggg = cmmdc(rsa, rsb);     cout << (long long)(rsa) / ggg <<  /  << (long long)(rsb) / ggg <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, R, C, g[110][110];   vector<int> A, B;   int main() {     scanf( %d %d %d , &N, &R, &C);     for (int i = 1; i <= (N); i++) {       if (i & 1)         A.push_back(i);       else         B.push_back(i);     }     for (int r = 1; r <= (R); r++)       for (int c = 1; c <= (C); c++) {         if ((r + c) % 2 == 0 && A.size()) g[r][c] = A.back(), A.pop_back();         if ((r + c) % 2 == 1 && B.size()) g[r][c] = B.back(), B.pop_back();       }     if (A.size() || B.size())       puts( -1 );     else {       for (int r = 1; r <= (R); r++) {         for (int c = 1; c <= (C); c++) printf( %d  , g[r][c]);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int s[100005];   int mask[25];   struct Reg {     int l, r;   } reg[23][100];   bool test(int p) {     if (p == n) return true;     set<int> q[2];     set<int>::iterator pp;     int now = 1, nxt = 1;     q[0].insert(mask[p] - 1);     for (int i = p; i < n; i++) {       nxt = now;       now = now ^ 1;       for (pp = q[now].begin(); pp != q[now].end(); pp++) {         int mask_n = *pp;         bool ok = false;         for (int j = 1; j <= reg[i][0].l; j++) {           if ((mask[reg[i][j].l] & mask_n) && (mask[reg[i][j].r] & mask_n)) {             ok = true;             break;           }         }         if (ok) {           for (int j = 0; j < i; j++) {             if (mask_n & mask[j]) {               q[nxt].insert((mask_n - mask[j]) | mask[i]);             }           }         }       }       q[now].clear();     }     return (!q[now ^ 1].empty());   }   int main() {     mask[0] = 1;     for (int i = 1; i < 25; i++) mask[i] = (mask[i - 1] << 1);     cin >> n;     for (int i = 0; i < (n); i++) cin >> s[i];     bool ok = true;     for (int i = 1; i < n; i++) {       ok = false;       for (int j = 0; j < i; j++) {         for (int k = 0; k <= j; k++) {           if (s[j] + s[k] == s[i]) {             ok = true;             reg[i][0].l++;             reg[i][reg[i][0].l].l = j;             reg[i][reg[i][0].l].r = k;           }         }       }       if (ok == false) break;     }     if (!ok) {       cout << -1 << endl;       return 0;     }     int l = 1, r = n;     int ret = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (test(mid)) {         r = mid - 1;         ret = mid;       } else {         l = mid + 1;       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, s;     cin >> a >> b >> s;     if (s < abs(a) + abs(b))       cout <<  NO  << endl;     else if (s == abs(a) + abs(b))       cout <<  YES  << endl;     else {       s -= abs(a);       s -= abs(b);       if (s % 2 == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(NULL);     unordered_map<int, int> idx;     int N, x;     cin >> N;     while (N--) {       cin >> x;       if (x) idx[x] = 1;     }     cout << idx.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   int main() {     canhazfast();     static int a[100016];     static char b[100016];     int n;     int l = -1000000000, r = 1000000000;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     cin >> b;     for (int i = 4; i < n; ++i) {       if (b[i] != b[i - 1]) {         if (b[i] ==  0 )           for (int j = 0; j <= 4; ++j) r = min(r, a[i - j] - 1);         else           for (int j = 0; j <= 4; ++j) l = max(l, a[i - j] + 1);       }     }     cout << l <<     << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000;   const long long INF = 1e18;   const int sqrtConst = 550;   const int alphabet = 26;   const long long mod = 998244353;   void solve() {     string s;     cin >> s;     bool has1 = false;     for (int i = 1; i < s.size(); i++) {       if (s[i] ==  1 ) {         has1 = true;         break;       }     }     int cnt = (s.size() + 1) / 2;     if (!has1 && (s.size() % 2)) cnt--;     cout << cnt;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cout << setprecision(6) << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Q, N, M, K, L;   bool board[10001][3];   long long dp[10001][8];   int bitCheck[4][2][2] = {       {{-2, 0}, {-1, 0}}, {{1, 0}, {2, 0}}, {{0, 1}, {0, 2}}, {{0, -1}, {0, -2}}};   void getNextStates(int n, int m, int thisState, int nextState,                      vector<int>& res) {     if (m == 3) {       res.push_back(nextState);       return;     }     if (board[n][m] || (thisState & (1 << m))) {       getNextStates(n, m + 1, thisState, nextState, res);       return;     }     if (n < N - 1) {       if (!board[n + 1][m])         getNextStates(n, m + 1, thisState, nextState | (1 << m), res);     }     if (m < 2) {       if (!board[n][m + 1] && !(thisState & (1 << (m + 1))))         getNextStates(n, m + 2, thisState, nextState, res);     }   }   long long solve(int n, int state) {     if (n == N) {       return 1LL;     }     long long& ret = dp[n][state];     if (~ret) return ret;     ret = 0;     vector<int> next;     getNextStates(n, 0, state, 0, next);     for (int i = 0; i < next.size(); i++) {       ret += solve(n + 1, next[i]);       ret %= 1000000007LL;     }     return ret;   }   int x, y;   long long ret;   void solve2(int n, int cnt) {     if (n == 4) {       if (!cnt) return;       memset(dp, -1, sizeof dp);       long long t = solve(0, 0);       if (cnt % 2)         ret += t;       else         ret -= t;       ret = (ret + 1000000007LL) % 1000000007LL;       return;     }     solve2(n + 1, cnt);     bool flag = true;     for (int j = 0; j < 2; j++) {       int nx = x + bitCheck[n][j][0];       int ny = y + bitCheck[n][j][1];       if (nx < 0 || ny < 0 || nx >= N || ny >= 3 || board[nx][ny]) flag = false;     }     if (!flag) return;     for (int j = 0; j < 2; j++) {       int nx = x + bitCheck[n][j][0];       int ny = y + bitCheck[n][j][1];       board[nx][ny] = 1;     }     solve2(n + 1, cnt + 1);     for (int j = 0; j < 2; j++) {       int nx = x + bitCheck[n][j][0];       int ny = y + bitCheck[n][j][1];       board[nx][ny] = 0;     }   }   int main() {     cin >> N;     board[N][0] = board[N][1] = board[N][2] = 1;     for (int i = 0; i < 3; i++) {       string s;       cin >> s;       for (int j = 0; j < N; j++) {         board[j][i] = s[j] ==  .  ? false : true;         if (s[j] ==  O ) {           y = i;           x = j;         }       }     }     solve2(0, 0);     cout << ret;     cin >> N;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, mex = N, ans[N];   pair<int, int> a[N];   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int l, r;       cin >> l >> r;       a[i] = {l, r};       mex = min(mex, r - l + 1);     }     int cur = 0;     cout << mex <<   n ;     for (int i = 1; i <= n; ++i) {       if (cur == mex) cur = 0;       cout << cur++ <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, m, l, r, q, nr;     string s;     string t;     cin >> n >> m >> q;     cin >> s >> t;     int cnt[1001] = {0};     for (int i = 0; i <= n - m; i++) {       if (s.substr(i, m) == t) {         cnt[i] = 1;       }     }     l = 0;     r = 0;     for (i = 1; i <= q; i++) {       cin >> l >> r;       nr = 0;       for (j = l - 1; j <= r - m; j++) {         if (cnt[j]) nr++;       }       cout << nr <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<string> s;     string str;     int n, i, j, flag = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> str;       s.push_back(str);     }     sort(s.begin(), s.end(), compare);     for (i = 0; i < n - 1; i++) {       j = 0;       while (j < s[i + 1].length()) {         int l = s[i].length();         flag = 0;         if (s[i] == s[i + 1].substr(j, l)) {           flag = 1;           break;         }         j++;       }       if (flag != 1) {         cout <<  NO n ;         break;       }     }     if (flag == 1 || n == 1) {       cout <<  YES n ;       for (i = 0; i < n; i++) {         cout << s[i] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a, b, t, c, j, k, T, i, A[1028], B[1028], C[1028];   int main() {     cin >> a >> b;     while (a > 0) {       a--;       t++;       if (t == b) {         t = 0;         a++;       }       j++;     }     cout << j;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const long long INF = 2e18;   const int maxn = 1e6 + 6;   const int mod = 1e9 + 6;   const double eps = 1e-15;   inline bool read(long long &num) {     char in;     bool IsN = false;     in = getchar();     if (in == EOF) return false;     while (in !=  -  && (in <  0  || in >  9 )) in = getchar();     if (in ==  - ) {       IsN = true;       num = 0;     } else       num = in -  0 ;     while (in = getchar(), in >=  0  && in <=  9 ) {       num *= 10, num += in -  0 ;     }     if (IsN) num = -num;     return true;   }   long long n, m, p;   long long num[maxn];   vector<long long> v;   int vis[maxn];   int getid(long long x) {     return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;   }   long long dp[maxn][2];   long long pre[maxn], first[maxn], sc[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       read(n);       v.clear();       for (int i = 1; i <= n; i++) {         vis[i] = 0;         dp[i][0] = dp[i][1] = 0;         pre[i] = 0;         first[i] = 0;         sc[i] = -(1e9 + 7);       }       for (int i = 1; i <= n; i++) {         read(num[i]);         v.push_back(num[i]);       }       long long maxl = 0;       sort(v.begin(), v.end());       v.erase((unique(v.begin(), v.end())), v.end());       for (int i = 1; i <= n; i++) vis[getid(num[i])]++;       for (int i = 1; i <= n; i++) {         int id = getid(num[i]);         pre[id]++;         dp[id][0] = dp[id][0] + 1;         if (pre[id] == 1) first[id] = max(dp[id - 1][0], dp[id - 1][1]);         if (pre[id] == vis[id]) dp[id][1] = first[id] + vis[id];         sc[id] =             max(sc[id], max(dp[id - 1][0] - pre[id], dp[id - 1][1] - pre[id]));         maxl = max(maxl, sc[id] + pre[id] + 1);         maxl = max(maxl, max(dp[id][0], dp[id][1]));       }       printf( %lld n , n - maxl);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long Mode = 1e9 + 7;   void Modulo(unsigned long long &x) { x = ((x % Mode + Mode) % Mode); }   unsigned long long Pow(unsigned long long x, unsigned long long y) {     unsigned long long res = 1;     for (unsigned long long i = 0; (1ULL << i) <= y; i++, x *= x, Modulo(x))       if (y & (1ULL << i)) res *= x, Modulo(res);     return res;   }   int main() {     unsigned long long n, ans = 1, D = 1;     cin >> n;     D = n;     for (unsigned long long i = 2ULL * n - 1; i > 0; i--) ans *= i, Modulo(ans);     for (unsigned long long i = 1; i <= n - 1; i++) D *= i * i, Modulo(D);     ans *= Pow(D, Mode - 2);     ans *= 2ULL;     Modulo(ans);     ans -= n;     Modulo(ans);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int vals[N], found[N];   struct node {     node *left, *right;     int val, size, priority;     node(int v) {       val = v, size = 1, priority = rand(), left = NULL, right = NULL;     }   };   int sz(node* t) { return (t) ? t->size : 0; }   void upd_sz(node*& t) {     if (t) t->size = sz(t->left) + 1 + sz(t->right);   }   void split(node* t, node*& l, node*& r, int k) {     if (!t)       l = r = NULL;     else if (sz(t->left) + 1 <= k)       split(t->right, t->right, r, k - sz(t->left) - 1), l = t;     else       split(t->left, l, t->left, k), r = t;     upd_sz(t);   }   void merge(node*& t, node* l, node* r) {     if (!l || !r)       t = l ? l : r;     else if (l->priority >= r->priority)       merge(l->right, l->right, r), t = l;     else       merge(r->left, l, r->left), t = r;     upd_sz(t);   }   int main() {     srand(time(NULL));     int n, m, x, y;     scanf( %d %d , &n, &m);     node* t = NULL;     for (int i = 1; i <= n; i++) {       merge(t, t, new node(i));     }     node* a;     node* b;     while (m--) {       scanf( %d %d , &x, &y);       split(t, a, t, y);       split(a, a, b, y - 1);       if (vals[b->val] == x) {       } else if (vals[b->val] == 0 && found[x] == 0)         vals[b->val] = x;       else {         printf( -1 n );         return 0;       }       found[x] = 1;       merge(a, b, a);       merge(t, a, t);     }     int f = 1;     for (int i = 1; i <= n; i++) {       if (vals[i] == 0) {         while (found[f] != 0) {           f++;         }         vals[i] = f++;       }     }     for (int i = 1; i <= n; i++) {       printf( %d  , vals[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n, t[1000001];   struct data {     int num, loc, vis;   } b[1000001];   int a[1000001];   int lowbit(int x) { return x & (-x); }   int Query(int x) {     int sum = 0;     while (x > 0) {       sum = max(sum, t[x]);       x -= lowbit(x);     }     return sum;   }   void Add(int x, int va) {     while (x <= N) {       t[x] = max(t[x], va);       x += lowbit(x);     }   }   bool cmp(data p, data q) { return p.num < q.num; }   bool cmp2(data p, data q) { return p.vis < q.vis; }   int work() {     memset(t, 0, sizeof(t));     for (int i = 1; i <= n; i++) {       b[i].num = a[i];       b[i].vis = i;     }     sort(b + 1, b + n + 1, cmp);     for (int i = 1; i <= n; i++) b[i].loc = n + 1 - i;     sort(b + 1, b + n + 1, cmp2);     int ans = 0;     for (int i = 1; i <= n; i++) {       int nowans = Query(b[i].loc);       Add(b[i].loc, i);       if (nowans == 0) continue;       ans = max(ans, b[i].num ^ b[nowans].num);     }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans = work();     for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]);     ans = max(ans, work());     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string s;   int main() {     cin.tie(0);     std::ios::sync_with_stdio(false);     cin >> n >> k;     cin >> s;     if (k == 2) {       string s1 =   , s2 =   ;       for (int i = 0; i < s.size(); i++)         if (i & 1)           s1 +=  A , s2 +=  B ;         else           s1 +=  B , s2 +=  A ;       int x = 0, y = 0;       for (int i = 0; i < s.size(); i++)         x += (s[i] == s1[i] ? 1 : 0), y += (s[i] == s2[i] ? 1 : 0);       if (x > y)         cout << s.size() - x << endl << s1 << endl;       else         cout << s.size() - y << endl << s2 << endl;       return 0;     }     string h;     int z = 1;     map<int, char> mop;     map<char, int> mops;     for (char c =  A ; c <=  Z ; c++) {       mop[z] = c, mops[c] = z, z++;       if (z > k) break;     }     string t = s;     int ans = 0;     for (int i = 0; i < s.size() - 1; i++) {       if (s[i] == s[i + 1]) {         h = s[i], h += s[i + 1];         int f = i + 1;         for (int j = i + 2; j < s.size(); j++) {           if (s[j] != s[i]) break;           f++;           h += s[j];         }         char prev = s[i - 1], next = h[1];         if (h.size() % 2 == 0)           for (int j = 0; j < h.size(); j += 2) {             for (__typeof((mops).begin()) it = (mops).begin(); it != (mops).end();                  it++)               if (it->first != prev && it->first != next) {                 h[j] = it->first;                 prev = h[j + 1], next = h[j + 3];                 ans++;                 break;               }           }         else {           prev = h[0], next = h[2];           for (int j = 1; j < h.size(); j += 2) {             for (__typeof((mops).begin()) it = (mops).begin(); it != (mops).end();                  it++)               if (it->first != prev && it->first != next) {                 h[j] = it->first;                 prev = h[j + 1];                 next = h[j + 3];                 ans++;                 break;               }           }         }         int n = 0;         for (int j = i; j < f; j++) s[j] = h[n++];         i = f - 1;       }     }     cout << ans << endl;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int conversion(string p) {     int o;     o = atoi(p.c_str());     return o;   }   string toString(int h) {     stringstream ss;     ss << h;     return ss.str();   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }   long long toi(string p) {     long long x;     istringstream in(p);     in >> x;     return x;   }   long long square(long long n) { return n * n; }   long long fastexp(long base, long power) {     if (power == 0)       return 1;     else if (power % 2 == 0)       return square(fastexp(base, power / 2));     else       return base * (fastexp(base, power - 1));   }   bool is_prime(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   int logba(int a, int b) { return log(a) / log(b); }   long long sum(long long x) { return ((x) * (x - 1)) / 2; }   int main() {     long long n, x, y, res = 0;     cin >> n;     map<long long, long long> M, N;     map<pair<long long, long long>, long long> R;     set<pair<long long, long long> > S;     for (int i = 0; i < n; i++) {       cin >> x >> y;       M[x]++;       N[y]++;       S.insert(make_pair(x, y));       R[make_pair(x, y)]++;     }     if (S.size() == 1) {       cout << ((n) * (n - 1)) / 2 << endl;       return 0;     }     for (map<long long, long long>::iterator it = M.begin(); it != M.end();          it++) {       res += sum(it->second);     }     for (map<long long, long long>::iterator it = N.begin(); it != N.end();          it++) {       res += sum(it->second);     }     for (map<pair<long long, long long>, long long>::iterator it = R.begin();          it != R.end(); it++) {       res -= sum(it->second);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int bignumlen = 2200;   const int Blen = 8;   const long long base = 100000000;   struct bignum {     int len;     long long data[bignumlen];     long long &operator[](int x) { return (data[x]); }     const long long &operator[](int x) const { return (data[x]); }     bignum() {       memset(data, 0, sizeof(data));       len = 0;     }     void clear() {       for (int i = len; i >= 1; --i) data[i] = 0;       len = 0;     }     int check(const bignum &a, const bignum &b) {       if (a.len > b.len) return (0);       if (b.len > a.len) return (1);       for (int i = a.len; i >= 1; --i) {         if (a.data[i] < b.data[i]) return (1);         if (b.data[i] < a.data[i]) return (0);       }       return 2;     }     bool operator<(const bignum &b) { return (check(*this, b) == 1); }     bool operator>(const bignum &b) { return (check(*this, b) == 0); }     bool operator<=(const bignum &b) { return (check(*this, b) >= 1); }     bool operator>=(const bignum &b) { return (check(*this, b) % 2 == 0); }     bool operator!=(const bignum &b) { return (check(*this, b) != 2); }     bool operator==(const bignum &b) { return (check(*this, b) == 2); }     bignum operator=(const bignum &x) {       for (int i = x.len + 1; i <= len; ++i) data[i] = 0;       for (int i = 1; i <= x.len; ++i) data[i] = x.data[i];       len = x.len;       return *this;     }     bignum operator=(long long x) {       for (int i = len; i >= 0; --i) data[i] = 0;       len = 0;       while (x) {         data[++len] = x % base;         x /= base;       }       return *this;     }     bignum(long long x) {       memset(data, 0, sizeof(data));       len = 0;       (*this) = x;     }     bignum operator*(const bignum &b) {       int i, j;       bignum tmp;       for (i = 1; i <= len; ++i)         if (data[i] != 0)           for (j = 1; j <= b.len; ++j)             if (b.data[j] != 0) {               tmp.data[i + j - 1] += data[i] * b.data[j];               tmp.data[i + j] += tmp.data[i + j - 1] / base;               tmp.data[i + j - 1] %= base;             }       tmp.len = len + b.len - 1;       while (tmp.data[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator*(long long x) {       int i;       bignum tmp;       for (i = 1; i <= len; ++i) tmp[i] = data[i] * x;       tmp.len = len;       for (i = 1; i <= len; ++i) {         tmp[i + 1] += tmp[i] / base, tmp[i] %= base;         if (tmp[i + 1] && i + 1 > tmp.len) tmp.len++;       }       return tmp;     }     bignum operator/(long long x) {       int i;       bignum tmp;       long long y = 0;       for (i = len; i >= 1; --i) {         y = y * base + data[i];         tmp[i] = y / x;         y %= x;       }       tmp.len = len;       while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;       return tmp;     }     bignum operator/(const bignum &b) {       if (b.len <= 1 && b[1] == 0) {         printf( error! 被0除! );         for (;;)           ;       }       int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;       long long x = data[len], y = b[b.len];       while (x) x /= 10, l1++;       while (y) y /= 10, l2++;       bignum tmp, chu, B;       chu = *this;       B = b;       for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;       for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;       for (i = l1 - l2; i >= 0; --i) {         x = 0;         while (chu >= B) chu -= B, x++;         tmp[i / Blen + 1] = tmp[i / Blen + 1] * 10 + x;         B /= 10;       }       tmp.len = (l1 - l2) / Blen + 1;       while (tmp.len >= 1 && !tmp[tmp.len]) tmp.len--;       return tmp;     }     bignum operator+(const bignum &b) {       bignum tmp;       int i, l = max(len, b.len);       for (i = 1; i <= l; ++i) tmp[i] = data[i] + b[i];       for (i = 1; i <= l; ++i) tmp[i + 1] += tmp[i] / base, tmp[i] %= base;       tmp.len = l;       if (tmp[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator+(long long x) {       bignum tmp;       tmp = *this;       tmp[1] += x;       for (int i = 1; i <= len && tmp[i] >= base; ++i)         tmp[i + 1] += tmp[i] / base, tmp[i] %= base;       while (tmp[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator-(const bignum &b) {       int i;       bignum tmp;       for (i = 1; i <= len; ++i) tmp.data[i] = data[i] - b.data[i];       for (i = 1; i <= len; ++i) {         if (tmp[i] < 0) tmp.data[i] += base, tmp.data[i + 1]--;       }       tmp.len = len;       while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;       return tmp;     }     bignum operator-(long long x) {       bignum tmp;       tmp = *this;       tmp[1] -= x;       for (int i = 1; i <= len && tmp[i] < 0; ++i) {         tmp[i + 1] += (tmp[i] + 1) / base - 1;         tmp[i] = (tmp[i] + 1) % base + base - 1;       }       while (!tmp[tmp.len] && tmp.len > 1) tmp.len--;       return tmp;     }     long long operator%(long long x) {       int i;       long long y = 0;       for (i = len; i >= 1; --i) y = (y * base + data[i]) % x;       return y;     }     bignum operator%(const bignum &b) {       if (b.len <= 1 && b[1] == 0) {         printf( error! 被0 mod! );         for (;;)           ;       }       int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;       long long x = data[len], y = b[b.len];       while (x) x /= 10, l1++;       while (y) y /= 10, l2++;       bignum chu, B;       chu = *this;       B = b;       for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;       for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;       for (i = l1 - l2; i >= 0; --i) {         while (chu >= B) chu -= B;         B /= 10;       }       return chu;     }     bignum operator+=(const bignum &b) { return *this = (*this + b); }     bignum operator*=(const bignum &b) { return *this = (*this * b); }     bignum operator-=(const bignum &b) { return *this = (*this - b); }     bignum operator/=(const bignum &b) { return *this = (*this / b); }     bignum operator%=(const bignum &b) { return *this = (*this % b); }     bignum operator*=(long long x) { return (*this = (*this * x)); }     bignum operator+=(long long x) { return (*this = (*this + x)); }     bignum operator-=(long long x) { return (*this = (*this - x)); }     bignum operator/=(long long x) { return (*this = (*this / x)); }     void read() {       char c[bignumlen * Blen + 10];       scanf( %s , c + 1);       int l = strlen(c + 1);       (*this).clear();       long long x;       for (int i = 1; i <= (l - 1) / Blen + 1; ++i) {         x = 0;         for (int j = l - Blen * i + 1; j <= l - Blen * i + Blen; ++j)           if (j >= 1) x = x * 10 + c[j] - 48;         data[++len] = x;       }     }     void write() {       printf( %I64d , data[len]);       for (int i = len - 1; i >= 1; --i) printf( %0*I64d , Blen, data[i]);     }   } p, q, pp, qq;   bignum gcd(const bignum &A, const bignum &B) {     bignum a = A, b = B, res = 1;     while (!(a[1] & 1) && !(b[1] & 1)) a /= 2, b /= 2, res *= 2;     for (;;) {       if (a.len == 1 && a[1] == 0) return b * res;       if (b.len == 1 && b[1] == 0) return a * res;       while (!(a[1] & 1)) a /= 2;       while (!(b[1] & 1)) b /= 2;       if (a > b)         a -= b;       else         b -= a;     }   }   void YF(bignum &A, bignum &B) {     bignum tmp = gcd(A, B);     A /= tmp;     B /= tmp;   }   int n, i, x, num;   int main() {     scanf( %d , &n);     while (n % 2 == 0) {       n /= 2;       num++;     }     if (n == 1) {       printf( %d/%d n , num, 1);       return 0;     }     p = 0;     q = 1;     pp = 1;     qq = 1;     for (i = n + 1;;) {       if (i > n) {         if (q % (i - n) == 0)           q /= i - n;         else           p *= i - n;         if (qq % (i - n) == 0)           qq /= i - n;         else           pp *= i - n;         if (p % i == 0)           p /= i;         else           q *= i;         if (pp % i == 0)           pp /= i;         else           qq *= i;       } else         p += q;       if (i == 1) break;       if (i % 2 == 0)         i /= 2;       else         i += n;     }     YF(p, q);     p = p * qq;     q = q * (qq - pp);     p += q * num;     bignum tmp = gcd(p, q);     (p / tmp).write();     printf( / );     (q / tmp).write();   }


#include <bits/stdc++.h>   using namespace std;   long long v2[34];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int i = 0; i <= 33; ++i) {       if (i == 0) {         v2[i] = 1;       } else {         v2[i] = 2 * v2[i - 1];       }     }     while (t--) {       int n;       cin >> n;       vector<long long> v(n);       for (int i = 0; i < n; ++i) {         cin >> v[i];       }       int ans = 0;       for (int i = 1; i < n; ++i) {         if (v[i] < v[i - 1]) {           long long aux = 0;           int k = 0;           long long dif = v[i - 1] - v[i];           for (int j = 0; j < 34; ++j) {             aux += v2[j];             if (aux >= dif) {               ans = max(ans, j + 1);               k = j;               break;             }           }           v[i] += dif;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1000005;   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   int a[N];   int main() {     long long n;     cin >> n;     long long d, d1, ans;     for (long long i = 0; i < n; i++) cin >> a[i];     d1 = gcd(a[0], a[1]);     ans = a[0] / d1 * a[1];     for (long long i = 2; i < n; i++) {       ans = gcd(ans, a[i]);       long long gg = gcd(d1, ans);       ans = d1 / gg * ans;       d1 = gg;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   inline void print(long long x) {     if (x < 0) putchar( - ), x = ~x + 1;     if (x >= 10) print(x / 10);     putchar((x % 10) | 48);   }   long long n;   struct node {     long long x, y;   } a[2510], v[5010];   long long xiangxian(node x) {     if (x.x >= 0) {       if (x.y >= 0)         return 1;       else         return 4;     } else {       if (x.y >= 0)         return 2;       else         return 3;     }   }   long long cross(node x, node y) { return x.x * y.y - y.x * x.y; }   bool cmp(node x, node y) {     long long x1 = xiangxian(x);     long long x2 = xiangxian(y);     if (x1 != x2)       return x1 < x2;     else       return cross(x, y) > 0;   }   long long ans;   long long C(long long x, long long y) {     if (x < 0) return 0;     long long res = 1;     for (long long i = 1; i <= y; ++i) res *= (x - i + 1);     for (long long i = 1; i <= y; ++i) res /= i;     return res;   }   signed main() {     n = read();     for (long long i = 1; i <= n; ++i) a[i].x = read(), a[i].y = read();     for (long long i = 1; i <= n; ++i) {       long long cnt = 0;       for (long long j = 1; j <= n; ++j) {         if (j == i) continue;         v[++cnt].x = a[j].x - a[i].x;         v[cnt].y = a[j].y - a[i].y;       }       sort(v + 1, v + cnt + 1, cmp);       for (long long j = 1; j <= cnt; ++j) v[j + cnt] = v[j];       long long lst = 1;       for (long long j = cnt + 1; j <= 2 * cnt; ++j) {         while (lst + cnt < j || cross(v[j], v[lst + 1]) >= 0) {           ++lst;           if (lst + 1 == j) break;         }         ans += C(j - lst - 1, 3);       }     }     print(5 * C(n, 5) - ans);   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, m, n;   int main() {     cin >> a;     cout << a / 2520;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       vector<int> what(m);       for (int x = 0; x < m; x++) {         int y = m - 1 - x;         what[x] = max(a[x], a[n - 1 - y]);       }       k = min(k, m - 1);       int ans = 0;       for (int fix = 0; fix <= k; fix++) {         int fiy = k - fix;         int mn = (int)2e9;         for (int i = fix; i <= m - 1 - fiy; i++) {           mn = min(mn, what[i]);         }         ans = max(ans, mn);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60777216 )   using namespace std;   int err;   vector<char> best;   vector<char> curr;   int n, r;   int it;   void go(int pos, int f1, int f2, int errors) {     if (err <= errors) return;     if (pos == -1) {       err = errors;       best = curr;     } else {       if (f1 == f2) {         curr[pos] =  T ;         go(-1, 0, 0, errors + (pos + 1 < n && curr[pos + 1] == curr[pos]));       } else if (f1 > f2) {         curr[pos] =  T ;         go(pos - 1, f1 - f2, f2,            errors + (pos + 1 < n && curr[pos + 1] == curr[pos]));       } else {         curr[pos] =  B ;         go(pos - 1, f1, f2 - f1,            errors + (pos + 1 < n && curr[pos + 1] == curr[pos]));       }     }   }   int gcd(int a, int b) {     while (a && b)       if (a > b)         a %= b;       else         b %= a;     return a + b;   }   int ngcd(int a, int b) {     int res = 0;     while (a && b)       if (a > b)         res += a / b, a %= b;       else         res += b / a, b %= a;     return res;   }   int main() {     cin >> n >> r;     vector<int> nm;     for (int other = 1; other <= r; other++) {       int g = gcd(other, r);       if (g == 1) {         int t = ngcd(other, r);         if (t == n) {           nm.push_back(other);         }       }     }     if (nm.size() == 0)       puts( IMPOSSIBLE );     else {       err = n + 1;       curr.resize(n);       for (int i = (0); i < (nm.size()); i++) {         go(n - 1, r, nm[i], 0);         go(n - 1, nm[i], r, 0);       }       cout << err << endl;       for (int i = (0); i < (best.size()); i++) printf( %c , best[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnnnd(chrono::steady_clock::now().time_since_epoch().count());   inline int read() {     int x = 0, f = 1, c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   const int N = 1e5 + 4;   int n, m, c[N], vis[N], dep[N], up1[N], up2[N];   vector<int> e[N], ans;   void upd(int x, int v) {     if (!v || dep[v] >= dep[x]) return;     if (!up1[x] || dep[v] < dep[up1[x]]) {       up2[x] = up1[x];       up1[x] = v;     } else if (!up2[x] || dep[v] < dep[up2[x]])       up2[x] = v;   }   bool dfs_1(int x) {     vis[x] = 2;     for (auto v : e[x]) {       if (!vis[v]) {         dep[v] = dep[x] + 1;         if (dfs_1(v)) return 1;         upd(x, up1[v]);         upd(x, up2[v]);       } else if (vis[v] == 1)         return 1;       else         upd(x, v);     }     vis[x] = 1;     return 0;   }   void dfs_3(int x) {     vis[x] = 3;     if (!up1[x] || (!up2[x] && up1[up1[x]])) {       up1[x] = 1;       ans.push_back(x);     } else       up1[x] = 0;     for (auto v : e[x])       if (vis[v] != 3) dfs_3(v);   }   inline void solve() {     for (int i = 1; i <= n; i++) e[i].clear();     n = read();     m = read();     for (int i = 1, u, v; i <= m; i++) {       u = read();       v = read();       e[u].push_back(v);     }     for (int i = 1; i <= n; i++) c[i] = i;     shuffle(c + 1, c + n + 1, rnnnd);     for (int i = 1; i <= min(n, 100); i++) {       memset(vis, 0, sizeof(int) * (n + 1));       memset(up1, 0, sizeof(int) * (n + 1));       memset(up2, 0, sizeof(int) * (n + 1));       memset(dep, 0, sizeof(int) * (n + 1));       if (dfs_1(c[i])) continue;       dfs_3(c[i]);       if (ans.size() * 5 >= n) {         sort(ans.begin(), ans.end());         for (auto v : ans) cout << v <<    ;         puts(  );       } else         puts( -1 );       ans.clear();       return;     }     puts( -1 );   }   int main() {     for (int T = read(); T--;) solve();     return (0 - 0);   }


#include <bits/stdc++.h>   using namespace std;   int b[105];   int main() {     int n, t, m, k;     cin >> t;     while (t--) {       cin >> n >> m >> k;       for (int i = 0; i < n; i++) cin >> b[i];       for (int i = 0; i < n - 1; i++) {         if (b[i] + k < b[i + 1])           m -= (b[i + 1] - b[i] - k);         else           m += min(b[i] - b[i + 1] + k, b[i]);         if (m < 0) {           puts( NO );           goto end;         }       }       puts( YES );     end:       continue;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   const pair<double, double> inf = make_pair(-1, -1);   pair<double, double> T[N << 2];   double f[N];   int n, m;   inline int read() {     int n = 0;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;     return n;   }   pair<double, double> merg(pair<double, double> t1, pair<double, double> t2) {     double l1 = t1.first, r1 = t1.second, l2 = t2.first, r2 = t2.second;     return make_pair(l1 * l2 / (1 + (l2 - 1) * r1),                      r2 + l2 * (1 - r2) * r1 / (1 - (1 - l2) * r1));   }   void up(int x) { T[x] = merg(T[x << 1], T[x << 1 | 1]); }   void build(int x, int l, int r) {     if (l == r) {       T[x] = make_pair(f[l], f[l]);       return;     }     int mi = (l + r) >> 1;     build(x << 1, l, mi);     build(x << 1 | 1, mi + 1, r);     up(x);   }   void modify(int x, int l, int r, int pos) {     if (l == r) {       T[x] = make_pair(f[l], f[l]);       return;     }     int mi = (l + r) >> 1;     if (pos <= mi)       modify(x << 1, l, mi, pos);     else       modify(x << 1 | 1, mi + 1, r, pos);     up(x);   }   pair<double, double> qry(int x, int l, int r, int L, int R) {     if (L <= l && r <= R) return T[x];     int mi = (l + r) >> 1;     pair<double, double> t1 = inf, t2 = inf;     if (L <= mi) t1 = qry(x << 1, l, mi, L, R);     if (mi < R) t2 = qry(x << 1 | 1, mi + 1, r, L, R);     return t1 == inf ? t2 : (t2 == inf ? t1 : merg(t1, t2));   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) {       int x = read(), y = read();       f[i] = x * 1.0 / y;     }     build(1, 1, n);     while (m--) {       int kd, x, y, z;       kd = read(), x = read(), y = read();       if (kd == 2) {         pair<double, double> ans = qry(1, 1, n, x, y);         printf( %.10lf n , ans.first);       } else {         z = read();         f[x] = y * 1.0 / z;         modify(1, 1, n, x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool endline = false;   template <class T>   istream& operator>>(istream& inp, vector<T>& v) {     for (auto& it : v) inp >> it;     return inp;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (auto& it : v) out << it << (endline ?   n  :    );     return out;   }   template <class T, class U>   istream& operator>>(istream& inp, pair<T, U>& v) {     inp >> v.first >> v.second;     return inp;   }   template <class T, class U>   ostream& operator<<(ostream& out, pair<T, U>& v) {     out << v.first <<     << v.second;     return out;   }   const int mod1 = 998244353, mod = 1e9 + 7;   const int MAXN = 1e6 + 6, MAXM = 5e5 + 5;   const int inf = 2e9;   const long long linf = 1e18;   long long n, m, a[5050];   void Solve() {     cin >> n >> m;     long long tmp = 0, i;     for (i = 1; i <= n; i++) {       if (tmp + (i - 1) / 2 < m) {         a[i] = i;         tmp += (i - 1) / 2;       } else {         long long gap = m - tmp;         if (gap == 0) {           a[i] = i;         } else {           a[i] = a[i - 1] + a[i - 2 * gap];         }         tmp += gap;         i++;         break;       }     }     if (tmp < m) {       cout << -1;       return;     }     for (; i <= n; i++) {       a[i] = 1e8 + i * i;     }     for (i = 1; i <= n; i++) {       cout << a[i] <<    ;     }   }   signed main() {     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     };     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long TC = 1;     while (TC--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     priority_queue<pair<int, int> > pq1, pq2;     int n, w;     cin >> n;     for (int i = 0; i < n; i++) cin >> w, pq1.push({-w, i});     n <<= 1;     for (int i = 0; i < n; i++) {       char ch;       cin >> ch;       pair<int, int> cur;       int ret;       if (ch ==  0 )         cur = pq1.top(), ret = cur.second, pq2.push({-cur.first, cur.second}),         pq1.pop();       else         ret = pq2.top().second, pq2.pop();       cout << ret + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = acos(-1);   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   int main() {     ios_base::sync_with_stdio(0);     int n, t, k, d;     cin >> n >> t >> k >> d;     cout << ((d / t + 1) * k >= n ?  NO  :  YES ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long val[100000], dp[100000][2];   vector<int> g[100000];   void dfs(int v, int p) {     long long c1 = 0, c2 = 0;     for (int i = 0; i < (g[v].size()); i++) {       int next = g[v][i];       if (next != p) {         dfs(next, v);         c1 = max(c1, dp[next][0]);         c2 = max(c2, dp[next][1]);       }     }     long long d = c1 - c2;     if (val[v] + d > 0)       c2 += val[v] + d;     else       c1 += -(val[v] + d);     dp[v][0] = c1, dp[v][1] = c2;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       g[a - 1].push_back(b - 1);       g[b - 1].push_back(a - 1);     }     for (int i = 0; i < n; i++) cin >> val[i];     dfs(0, -1);     cout << dp[0][0] + dp[0][1];   }


#include <bits/stdc++.h>   const int inf = 0x3f3f3f3f;   using namespace std;   int yh() {     int ret = 0;     bool f = 0;     char c = getchar();     while (!isdigit(c)) {       if (c == EOF) return -1;       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar();     return f ? -ret : ret;   }   template <typename T>   void yh(T& ret) {     ret = 0;     bool f = 0;     char c = getchar();     while (!isdigit(c)) {       if (c == EOF) return ret = -1, void();       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar();     ret = f ? -ret : ret;   }   char s[200005];   int main() {     for (register int _ = (yh()); _ >= (1); _--) {       int n = yh();       queue<int> q;       scanf( %s , s + 1);       int bloc = 0;       for (register int i = (1); i <= (n); i++) {         if (s[i] == s[i - 1]) {           q.push(bloc);         } else           bloc++;       }       int opts = 0, dlt = 0;       for (register int i = (1); i <= (n); i++) {         if (q.empty()) break;         q.pop();         opts++;         dlt++;         while (!q.empty() && q.front() == i) {           q.pop();           dlt++;         }         dlt++;       }       opts += (n - dlt + 1) / 2;       cout << opts <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int last1[510][5010], last2[510][5100], pre[510][5100];   int main() {     int s, d;     cin >> s >> d;     memset(last1, -1, sizeof(last1));     memset(last2, -1, sizeof(last2));     memset(pre, -1, sizeof(pre));     queue<pair<int, int> > q;     q.push(make_pair(0, 0));     while (!q.empty()) {       pair<int, int> cur = q.front();       q.pop();       for (int i = 0; i < 10; i++) {         if (i == 0 && cur.first == 0 && cur.second == 0) continue;         int nx1 = (cur.first * 10 + i) % s, nx2 = cur.second + i;         if (nx2 > d) continue;         if (pre[nx1][nx2] != -1) continue;         last1[nx1][nx2] = cur.first, last2[nx1][nx2] = cur.second;         pre[nx1][nx2] = i;         q.push(make_pair(nx1, nx2));       }     }     if (pre[0][d] == -1) {       cout << -1;       return 0;     }     vector<int> ans;     int nx1 = 0, nx2 = d;     while (1) {       if (pre[nx1][nx2] == -1) break;       ans.push_back(pre[nx1][nx2]);       int tmp1 = last1[nx1][nx2];       int tmp2 = last2[nx1][nx2];       nx1 = tmp1, nx2 = tmp2;     }     for (int i = ans.size() - 1; i >= 0; i--) {       cout << ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, Q;   vector<vector<int> > ad;   vector<int> val, par;   void fun(int c, int p) {     par[c] = p;     int i;     for (i = 0; i < ad[c].size(); i++) {       if (ad[c][i] != p) fun(ad[c][i], c);     }   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int query(int c, int v) {     if (c == -1) return c;     if (gcd(val[c], v) > 1) return c + 1;     return query(par[c], v);   }   int main() {     int i, j, k;     cin >> N >> Q;     ad.resize(N);     val.resize(N);     par.resize(N);     for (i = 0; i < N; i++) cin >> val[i];     for (i = 1; i < N; i++) {       cin >> j >> k;       ad[j - 1].push_back(k - 1);       ad[k - 1].push_back(j - 1);     }     fun(0, -1);     while (Q) {       Q--;       cin >> k;       if (k == 2) {         cin >> j >> k;         val[j - 1] = k;       } else {         cin >> j;         cout << query(par[j - 1], val[j - 1]) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m(0), a(0), b(0), c(0), x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (i % 3 == 0)         a += x;       else if (i % 3 == 1)         b += x;       else         c += x;     }     m = max(max(a, b), c);     if (m == a)       cout <<  chest ;     else if (m == b)       cout <<  biceps ;     else       cout <<  back ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long months, monthlen, weeklen;       cin >> months >> monthlen >> weeklen;       long long n2 = monthlen - 1;       long long n1 = weeklen / gcd(n2, weeklen);       long long lim = min(months, monthlen);       long long ini = lim - n1;       long long sum = 0;       long long len = (ini + n1 - 1) / n1;       sum = ini * len - n1 * ((len - 1) * (len - 1) + (len - 1)) / 2;       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long INF = 1e9;   inline long long pwr(long long base, long long n, long long m) {     long long ans = 1;     while (n > 0) {       if (n % 2 == 1) ans = (ans * base) % m;       base = (base * base) % m;       n /= 2;     }     return ans;   }   const int N = 1e6 + 10;   int a[N], n, dp[1 << 22];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       dp[a[i]] = a[i];     }     for (int i = 0; i < 22; i++) {       for (int mask = 0; mask < 1 << 22; mask++) {         if ((mask & (1 << i))) dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);       }     }     for (int i = 0; i < n; i++) {       int temp = a[i];       a[i] = (((1 << 22) - 1) ^ a[i]);       if (!dp[a[i]]) dp[a[i]] = -1;       cout << dp[a[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a <= b)       cout <<  Second ;     else       cout <<  First ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void file() {     freopen( alost.in ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   bool ar[10000005];   void sieve() {     ar[0] = ar[1] = 1;     for (long long i = 2; i * i <= (int)1e7; i++)       if (!ar[i])         for (long long j = i * i; j <= (int)1e7; j += i) ar[j] = 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);     ;     sieve();     int n;     cin >> n;     for (int i = 2; i <= (int)1e7 && n; i++)       if (!ar[i]) cout << i <<    , n--;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 5;   inline int readint() {     char c = getchar();     int ans = 0;     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 , c = getchar();     }     return ans;   }   vector<int> tree[N];   bool check[N];   int father[N][21];   int deep[N];   void dfs(int x, int level) {     for (int i = 0; father[father[x][i]][i]; i++) {       father[x][i + 1] = father[father[x][i]][i];     }     deep[x] = level;     for (int i = 0; i < tree[x].size(); i++) {       int to = tree[x][i];       if (to == father[x][0]) {         continue;       }       father[to][0] = x;       dfs(to, level + 1);     }   }   int main() {     int n, k;     n = readint(), k = readint();     int u, v;     for (int i = 1; i < n; i++) {       u = readint(), v = readint();       tree[u].push_back(v);       tree[v].push_back(u);     }     k = n - k;     k--, check[n] = 1;     dfs(n, 1);     for (int i = n - 1; i >= 1 && k; i--) {       int aim = -1;       int now = i;       if (check[i]) {         continue;       }       for (int j = 20; j >= 0; j--) {         if (father[now][j] == 0 || check[father[now][j]]) {           continue;         }         now = father[now][j];       }       if (deep[i] - deep[now] + 1 <= k) {         now = i;         while (now != 0 && !check[now]) {           check[now] = 1;           k--;           now = father[now][0];         }       }     }     for (int i = 1; i <= n - 1; i++) {       if (!check[i]) {         cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   const int32_t mod = 1e9 + 7;   using namespace std;   unordered_map<long long, long long> mp;   void fun(vector<long long>& v, long long idx, long long sum) {     if (idx == (long long)v.size()) {       mp[sum]++;       return;     }     fun(v, idx + 1, sum);     fun(v, idx + 1, sum - v[idx]);     fun(v, idx + 1, sum + v[idx]);   }   void solve(long long test) {     long long n;     cin >> n;     mp.clear();     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     fun(v, 0, 0);     if (mp[0] > 1)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     long long i = 1;     while (i <= t) {       solve(i);       i++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     list<int> L;     int N, M;     cin >> N >> M;     set<pair<int, int> > S;     for (int i = 0; i < M; ++i) {       int u, v;       cin >> u >> v;       S.insert(pair<int, int>(u, v));     }     L.push_back(1);     for (int i = 2; i <= N; ++i) {       list<int>::iterator it = L.begin();       while (it != L.end() && S.count(pair<int, int>(i, *it))) it++;       L.insert(it, i);     }     for (list<int>::iterator it = L.begin(); it != L.end(); ++it) {       cout << *it <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, ans = 0, n, k, a[100000];     scanf( %d%d , &n, &k);     for (i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (i = 0; i < k && a[i] < 0; ++i) a[i] *= -1;     if (i < k) {       sort(a, a + n);       k -= i;       if (k & 1) {         a[0] *= -1;       }     }     for (j = 0; j < n; ++j) {       ans += a[j];     }     printf(  n%d , ans);     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;      const ll DIM = 1e6 + 7;   const ll INF = 1e16 + 7;   const ll MODULO = 1e9 + 7;      ll n,m,nt,k,q;      ll val,val1,last,res,c0,c1,c2;      int main()   {       ios_base::sync_with_stdio();       cin.tie();       cout.tie();          cin>>nt;       for(int t=1; t<=nt; t++)       {              cin>>n;              res=0;           c0=0;           c1=0;           c2=0;              for(int i=1; i<=n; i++)           {               cin>>val;                  if(val%3==0)c0++;               else if(val%3==1)c1++;               else c2++;           }              for(int i=1; i<=2; i++)           {                  if(c0>n/3)               {                   val=c0-n/3;                   res+=val;                   c1+=val;                   c0-=val;               }                  if(c1>n/3)               {                   val=c1-n/3;                   res+=val;                   c2+=val;                   c1-=val;               }                  if(c2>n/3)               {                   val=c2-n/3;                   res+=val;                   c0+=val;                   c2-=val;               }           }              cout<<res<<endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0l);   const long long MOD = 1e9 + 7;   bool debug = 1;   const int N = 3e3 + 10;   int seg[2 * N];   int n, m;   void build() {     for (int i = n - 1; i > 0; i--) seg[i] = seg[i << 1] + seg[i << 1 | 1];   }   int qry(int l, int r) {     int ans = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) ans += seg[l++];       if (r & 1) ans += seg[--r];     }     return ans;   }   void up(int pos, int x) {     for (seg[pos += n] = x; pos > 1; pos >>= 1) {       seg[pos >> 1] = seg[pos] + seg[pos ^ 1];     }   }   char mat[N][N];   int dpesq[N][N], dpdir[N][N], dpdia[N][N];   bool ok(int i, int j) { return i >= 0 and i < n and j >= 0 and j < m; }   vector<int> ev[N];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf(  %c , mat[i] + j);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int ant = 0;         if (j) ant = dpesq[i][j - 1];         if (mat[i][j] ==  z ) dpesq[i][j] = ant + 1;       }     }     for (int i = 0; i < n; i++) {       for (int j = m - 1; j >= 0; j--) {         int ant = 0;         if (j < m - 1) ant = dpdir[i][j + 1];         if (mat[i][j] ==  z ) dpdir[i][j] = ant + 1;       }     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < m; j++) {         int ant = 0;         if (ok(i + 1, j - 1)) ant = dpdia[i + 1][j - 1];         if (mat[i][j] ==  z ) dpdia[i][j] = ant + 1;       }     }     long long ans = 0;     for (int inic = 0; inic < n; inic++) {       int i = inic, j = 0;       memset(seg, 0, sizeof(seg));       for (int jj = 0; jj < m; jj++) ev[jj].clear();       while (ok(i, j)) {         for (auto it : ev[j]) {           up(it, 0);         }         if (mat[i][j] ==  z ) {           up(j, 1);           ev[j + dpdir[i][j]].push_back(j);           int mind = min(dpesq[i][j], dpdia[i][j]);           ans += qry(j - mind + 1, j + 1);         }         i--, j++;       }     }     for (int inicj = 1; inicj <= m - 1; inicj++) {       int i = n - 1, j = inicj;       memset(seg, 0, sizeof(seg));       for (int jj = 0; jj < m; jj++) ev[jj].clear();       while (ok(i, j)) {         for (auto it : ev[j]) {           up(it, 0);         }         if (mat[i][j] ==  z ) {           up(j, 1);           ev[j + dpdir[i][j]].push_back(j);           int mind = min(dpesq[i][j], dpdia[i][j]);           ans += qry(j - mind + 1, j + 1);         }         i--, j++;       }     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define pb push_back      int i,j,n,m,e;   vector<int>v,s;      int main()   {   #ifndef ONLINE_JUDGE    freopen( input.txt , r ,stdin);    freopen( output.txt , w ,stdout);   #endif       int t;    cin>>t;    while(t--)    {     int k,sum=0;     cin>>n>>k;     int a[n+5];        for(i=0;i<n;i++)     {      cin>>a[i];     }     sort(a,a+n);          for(i=0;i<n;i++)     {      sum+=a[i];      if(sum==k)v.pb(a[i]);      else s.pb(a[i]);     }     if(v.size()==0)     {      cout<< YES <<endl;            for(auto it : s)cout<<it<<   ;            cout<<endl;     }        else        {         for(auto it:v)s.pb(it);                   sum=0;         string ans= YES ;            for(auto it:s)         {          sum+=it;          if(sum==k)          {           ans= NO ;break;          }         }         if(ans== NO )cout<<ans<<endl;         else         {          cout<<ans<<endl;                for(auto it : s)cout<<it<<   ;cout<<endl;         }        }         v.clear();        s.clear();       }   }


#include <bits/stdc++.h>   using namespace std;   int l, r, p, prim[100], cnt, a[4000000], n, f[4000000], ans;   bool ok[4000000];   void DFS(int x, long long now) {     if (x > cnt) return;     while (now <= r) {       DFS(x + 1, now);       now = now * prim[x];       if (now <= r) a[++n] = now;     }   }   int main() {     scanf( %d%d%d , &l, &r, &p);     for (int i = 2; i <= p; ++i) {       bool OK = true;       for (int j = 2; j * j <= i; ++j)         if (i % j == 0) {           OK = false;           break;         }       if (OK) prim[++cnt] = i;     }     a[++n] = 1;     DFS(1, 1);     sort(a + 1, a + n + 1);     for (int i = 2; i <= n; ++i) f[i] = p + 1;     for (int q = 1; q <= p; ++q) {       int now = 1;       for (int i = 1; i <= n; ++i) {         long long tmp = a[i] * q;         while (now <= n && a[now] < tmp) ++now;         if (now > n) break;         if (a[now] == tmp && f[now] > f[i] + 1) {           f[now] = f[i] + 1;           if (f[now] + q <= p) ok[now] = 1;         }       }     }     for (int i = 1; i <= n; ++i)       if (a[i] >= l && ok[i]) ++ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     int n;     long long a = 1, b = 1;     char s[10];     scanf( %d , &n);     for (int i = int(1); i <= int(n); ++i) {       scanf( %s , s);       if (strlen(s) == 4) {         a++;         b++;       } else {         if (s[0] ==  U  && s[1] ==  L ) b++;         if (s[0] ==  U  && s[1] ==  R ) a++;         if (s[0] ==  D  && s[1] ==  L ) a++;         if (s[0] ==  D  && s[1] ==  R ) b++;       }     }     cout << a * b << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long temp;     long long a[n];     int fg = 0;     for (int(i) = 0; (i) < (n); (i)++) {       cin >> temp;       fg++;       a[i] = temp;     }     sort(a, a + n);     for (int(i) = 0; (i) < (n - 1); (i)++) {       if (a[i] == a[i + 1]) continue;       if (a[i + 1] < 2 * a[i]) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, x, n, m;     scanf( %d%d%d%d , &k, &x, &n, &m);     for (int f1 = 0; f1 <= 1; f1++) {       for (int f2 = 0; f2 <= 1; f2++) {         for (int f3 = 0; f3 <= 1; f3++) {           int h1 = n, h2 = m;           if (f1) h1--;           if (f1 || f3) h2--;           if (f2) h1--, h2--;           if (!f2 && f3) h2--;           if (h1 < 0 || h2 < 0) continue;           for (int i = 0; i <= h1 / 2; i++) {             for (int j = 0; j <= h2 / 2; j++) {               long long las1 = i, las2 = j;               for (int t = 3; t <= k; t++) {                 long long tmp1 = las2, tmp2 = las1 + las2;                 las1 = tmp1, las2 = tmp2;                 if (t == 3 && f1) las2++;                 if (t >= 4 && t % 2 == 0 && f2) las2++;                 if (t >= 4 && t % 2 == 1 && f3) las2++;               }               if (las2 == x) {                 if (f2) printf( C );                 for (int h = 1; h <= i; h++) printf( AC );                 for (int h = 1; h <= h1 - 2 * i; h++) printf( Z );                 if (f1) printf( A );                 printf(  n );                 if (f1 || f3) printf( C );                 for (int h = 1; h <= j; h++) printf( AC );                 for (int h = 1; h <= h2 - 2 * j; h++) printf( Z );                 if (f2 || f3) printf( A );                 printf(  n );                 return 0;               }             }           }         }       }     }     printf( Happy new year! n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using db = double;   using str = string;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pd = pair<db, db>;   using vi = vector<int>;   using vb = vector<bool>;   using vl = vector<ll>;   using vd = vector<db>;   using vs = vector<str>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpd = vector<pd>;   template <class T>   using V = vector<T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const ll INF = 1e18;   const ld PI = acos((ld)-1);   const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   constexpr int pct(int x) { return __builtin_popcount(x); }   constexpr int bits(int x) { return 31 - __builtin_clz(x); }   ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }   ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U first) {     hi++;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T, class U>   T lstTrue(T lo, T hi, U first) {     lo--;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo + 1) / 2;       first(mid) ? lo = mid : hi = mid - 1;     }     return lo;   }   template <class T>   void remDup(vector<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   template <class T, class U>   void erase(T& t, const U& u) {     auto it = t.find(u);     assert(it != end(t));     t.erase(u);   }   template <class T>   void re(complex<T>& c);   template <class T, class U>   void re(pair<T, U>& p);   template <class T>   void re(vector<T>& v);   template <class T, size_t SZ>   void re(AR<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(db& d) {     str t;     re(t);     d = stod(t);   }   void re(ld& d) {     str t;     re(t);     d = stold(t);   }   template <class T, class... U>   void re(T& t, U&... u) {     re(t);     re(u...);   }   template <class T>   void re(complex<T>& c) {     T a, b;     re(a, b);     c = {a, b};   }   template <class T, class U>   void re(pair<T, U>& p) {     re(p.first, p.second);   }   template <class T>   void re(vector<T>& x) {     for (auto& a : x) re(a);   }   template <class T, size_t SZ>   void re(AR<T, SZ>& x) {     for (auto& a : x) re(a);   }   str to_string(char c) { return str(1, c); }   str to_string(const char* second) { return (str)second; }   str to_string(str second) { return second; }   str to_string(bool b) { return to_string((int)b); }   template <class T>   str to_string(complex<T> c) {     stringstream ss;     ss << c;     return ss.str();   }   str to_string(vector<bool> v) {     str res =  { ;     for (int i = (0); i < ((int)(v).size()); ++i) res += char( 0  + v[i]);     res +=  } ;     return res;   }   template <size_t SZ>   str to_string(bitset<SZ> b) {     str res =   ;     for (int i = (0); i < (SZ); ++i) res += char( 0  + b[i]);     return res;   }   template <class T, class U>   str to_string(pair<T, U> p);   template <class T>   str to_string(T v) {     bool fst = 1;     str res =   ;     for (const auto& x : v) {       if (!fst) res +=    ;       fst = 0;       res += to_string(x);     }     return res;   }   template <class T, class U>   str to_string(pair<T, U> p) {     return to_string(p.first) +     + to_string(p.second);   }   template <class T>   void pr(T x) {     cout << to_string(x);   }   template <class T, class... U>   void pr(const T& t, const U&... u) {     pr(t);     pr(u...);   }   void ps() { pr(  n ); }   template <class T, class... U>   void ps(const T& t, const U&... u) {     pr(t);     if (sizeof...(u)) pr(   );     ps(u...);   }   void DBG() { cerr <<  ]  << endl; }   template <class T, class... U>   void DBG(const T& t, const U&... u) {     cerr << to_string(t);     if (sizeof...(u)) cerr <<  ,  ;     DBG(u...);   }   void setIn(str second) { freopen(second.c_str(),  r , stdin); }   void setOut(str second) { freopen(second.c_str(),  w , stdout); }   void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }   void setIO(str second =   ) {     unsyncIO();     if ((int)(second).size()) {       setIn(second +  .in ), setOut(second +  .out );     }   }   int N, A[1000][1000];   bool active[1000][1000];   deque<int> pref[1000];   int propose[1000], proposed[1000];   void fin() {     ps(-1);     exit(0);   }   void rem(int x, int y) { active[x][y] = active[y][x] = 0; }   void clip(int x) {     while ((int)(pref[x]).size() && !active[x][pref[x].front()])       pref[x].pop_front();     while ((int)(pref[x]).size() && !active[x][pref[x].back()])       pref[x].pop_back();     if (!(int)(pref[x]).size()) fin();   }   void ad(int x, int y) {     assert(x != y && propose[x] == -1 && proposed[y] == -1);     propose[x] = y, proposed[y] = x;     while (1) {       clip(y);       if (pref[y].back() != x)         rem(y, pref[y].back());       else         break;     }     assert(pref[y].back() == x);   }   int nex(int x) {     assert((int)(pref[x]).size() > 1);     clip(x);     int y = pref[x].front();     pref[x].pop_front();     clip(x);     pref[x].push_front(y);     return proposed[pref[x][1]];   }   int main() {     setIO();     re(N);     if (N & 1) fin();     for (int i = (0); i < (N); ++i) {       for (int j = (0); j < (N); ++j)         if (i != j) {           re(A[i][j]);           pref[i].push_back(j);           active[i][j] = 1;         }       sort(begin(pref[i]), end(pref[i]),            [&](int x, int y) { return A[i][x] < A[i][y]; });     }     for (int i = (0); i < (N); ++i) propose[i] = proposed[i] = -1;     queue<int> q;     for (int i = (0); i < (N); ++i) q.push(i);     while ((int)(q).size()) {       int x = q.front();       q.pop();       assert(propose[x] == -1);       while (1) {         clip(x);         int y = pref[x].front(), X = proposed[y];         if (X != -1 && A[y][X] < A[y][x]) {           rem(x, y);           continue;         }         if (X != -1) propose[X] = -1, proposed[y] = -1, q.push(X);         ad(x, y);         break;       }     }     for (int i = (0); i < (N); ++i) assert(propose[i] != -1);     int cur = 0;     while (1) {       for (; cur < N; ++cur) {         clip(cur);         assert(proposed[cur] != -1 && pref[cur].back() == proposed[cur]);         if ((int)(pref[cur]).size() > 1) break;       }       for (int i = (0); i < (N); ++i) {         vi tmp;         for (auto& j : pref[i])           if (active[i][j]) tmp.push_back(j);       }       if (cur == N) {         for (int i = (0); i < (N); ++i) {           assert(proposed[propose[i]] == i);           ps(propose[i] + 1);         }         exit(0);       }       vi cyc, CYC;       {         int x = cur, y = cur;         do {           x = nex(x), y = nex(nex(y));         } while (x != y);         do {           cyc.push_back(y);           y = nex(y);         } while (x != y);       }       for (auto& x : cyc) {         int y = propose[x];         CYC.push_back(y);         assert(y != -1);         propose[x] = -1, proposed[y] = -1, rem(x, y);       }       for (int i = (0); i < ((int)(cyc).size()); ++i)         ad(cyc[i], CYC[(i + 1) % (int)(cyc).size()]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e9;   const long long N = 1000 + 5;   long long ar[N], done[N], cnt[N];   long long n;   long long mex() {     for (long long i = 0; i < n; i++) cnt[i] = 0;     for (long long i = 0; i < n; i++) cnt[ar[i]] = 1;     long long mex = 0;     while (cnt[mex]) mex++;     return mex;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i < n; i++) {         cin >> ar[i];       }       vector<long long> ans;       while (1) {         long long m = mex();         if (m < n) {           ar[m] = m;           ans.push_back(m + 1);         } else {           long long ind = 0;           while (ind < n && ar[ind] == ind) ind++;           if (ind == n) break;           long long p = -1;           for (long long i = 0; i < n && p == -1; i++)             if (ar[i] == ind) p = i;           ar[p] = n;           ans.push_back(p + 1);         }       }       cout << ans.size() <<   n ;       for (auto &inx : ans) cout << inx <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:32100000 )   #pragma GCC optimize( O3 )   using namespace std;   void solve() {     int n, k;     string str;     cin >> n >> k >> str;     string need;     for (int i = 0; i < k - 1; i++) {       need +=  () ;     }     for (int i = 0; i < (n - 2 * k + 2) / 2; i++) {       need +=  ( ;     }     for (int i = 0; i < (n - 2 * k + 2) / 2; i++) {       need +=  ) ;     }     vector<pair<int, int>> ans;     for (int i = 0; i < n; i++) {       if (str[i] == need[i]) {         continue;       }       int pos = i + 1;       for (; pos < n && str[pos] != need[i]; pos++)         ;       ans.push_back({i, pos});       for (int j = 0; j < (pos - i + 1) / 2; j++) {         swap(str[i + j], str[pos - j]);       }     }     cout << ans.size() <<   n ;     for (auto &i : ans) {       cout << i.first + 1 <<     << i.second + 1 <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     cout.precision(9);     srand(time(0));     int q;     cin >> q;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[111111];   int isp2[222222];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1, p = 1; i < 222222; i *= 2, ++p) {       isp2[i] = p;     }     sort(a, a + n);     int ans = 1e9;     for (int dv = 0; a[n - 1] >= (1 << dv); ++dv) {       for (int mul = 0; mul <= dv + 1; ++mul) {         int val = a[n - 1];         for (int i = 0; i < dv; ++i) {           val /= 2;         }         for (int i = 0; i < mul; ++i) {           val *= 2;         }         int tot = 0;         for (int i = 0; i < n; ++i) {           int cur = a[i];           while (cur > 0 && !(val % cur == 0 && isp2[val / cur])) {             cur /= 2;             ++tot;           }           if (cur > 0) {             tot += isp2[val / cur] - 1;           } else {             tot = 1e9;             break;           }         }         ans = min(ans, tot);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   inline int read() {     int s = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     do {       s = s * 10 + c -  0 ;     } while ((c = getchar()) >=  0  && c <=  9 );     return s;   }   int n, l, r, ql, qr;   long long ans;   int main() {     for (n = read(), l = r = read(); n--;) {       ql = read(), qr = read();       if (ql <= l && r <= qr) continue;       if (qr < l)         ans += l - qr, r = l, l = qr;       else if (r < ql)         ans += ql - r, l = r, r = ql;       else         l = ql > l ? ql : l, r = qr < r ? qr : r;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, a, b, v;     cin >> k >> a >> b >> v;     int x = (a + v - 1) / v;     int t, y;     t = b / (k - 1);     y = t * k;     while (y > x) {       b--;       t = b / (k - 1);       y = t * k;     }     int c;     c = b % (k - 1) + 1;     int m;     if (x > c + y)       m = x - (c + y);     else       m = 0;     if (y < x)       cout << m + t + 1;     else       cout << m + t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5, mum = 1e9 + 7;   int Pow(int A, long long B) {     int num = 1;     while (B) {       if (B & 1) num = 1LL * num * A % mum;       A = 1LL * A * A % mum;       B >>= 1;     }     return num;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m, k, r, c, ax, ay, bx, by;     cin >> n >> m >> k >> r >> c >> ax >> ay >> bx >> by;     cout << (ax == bx && ay == by ? Pow(k, 1LL * n * m)                                   : Pow(k, 1LL * n * m - 1LL * r * c))          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const int V = 1e5 + 25;   int arr[V];   map<int, int> mmap;   int main() {     int n;     cin >> n;     int mx = INT_MIN;     int mn = INT_MAX;     for (int i = 0; i < n; i++) {       cin >> arr[i];       mx = max(mx, arr[i]);       mn = min(mn, arr[i]);       mmap[arr[i]]++;     }     if (mx - mn < 2) {       cout << n << endl;       for (int i = 0; i < n; i++) {         cout << arr[i] <<    ;       }       cout << endl;       return 0;     }     int cnt = 0;     int a, b, c;     int p, q, r;     if (mmap.size() == 2) {       for (auto x : mmap) {         if (cnt == 0) p = x.first, a = x.second;         if (cnt == 1) r = x.first, c = x.second;         cnt++;       }       q = p + 1;       b = 0;     } else {       for (auto x : mmap) {         if (cnt == 0) p = x.first, a = x.second;         if (cnt == 1) q = x.first, b = x.second;         if (cnt == 2) r = x.first, c = x.second;         cnt++;       }     }     int b1 = b + 2 * min(a, c);     int a1 = a - min(a, c);     int c1 = c - min(a, c);     int b2 = b % 2;     int a2 = a + (b - b % 2) / 2;     int c2 = c + (b - b % 2) / 2;     int lhs = min(a1, a) + min(b1, b) + min(c1, c);     int rhs = min(a2, a) + min(b2, b) + min(c2, c);     if (lhs <= rhs) {       printf( %d n , lhs);       for (int i = 0; i < a1; i++) printf( %d  , p);       for (int i = 0; i < b1; i++) printf( %d  , q);       for (int i = 0; i < c1; i++) printf( %d  , r);     } else {       printf( %d n , rhs);       for (int i = 0; i < a2; i++) printf( %d  , p);       for (int i = 0; i < b2; i++) printf( %d  , q);       for (int i = 0; i < c2; i++) printf( %d  , r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = atan(1.0) * 4.0;   const long long int MOD = 1e9 + 7;   const long long int INF = 1e5;   const long double EPS = 0.0000001;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int a[1005], k;     a[0] = -1;     a[1] = 0;     for (int i = 2; i <= 1005; i++) {       a[i] = a[i - 1] + i - 1;     }     cin >> k;     if (k == 0) {       cout <<  a  << endl;       return 0;     }     char ch =  a ;     while (k > 0) {       int lb = lower_bound(a, a + 1005, k) - a;       if (a[lb] != k) lb--;       for (int i = 1; i <= lb; i++) cout << ch;       k -= a[lb];       ch++;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   int n, k, q;   int pref[200005];   int main() {     cin >> n >> k >> q;     int maxRight = 0;     for (int i = 0; i < n; ++i) {       int left, right;       cin >> left >> right;       maxRight = max(maxRight, right);       ++pref[left], --pref[right + 1];     }     for (int i = 1; i <= maxRight; ++i) {       pref[i] += pref[i - 1];     }     for (int i = 0; i <= 200001; ++i) {       pref[i] = (int)(pref[i] >= k);       pref[i] += pref[i - 1];     }     while (q--) {       int a, b;       cin >> a >> b;       cout << pref[b] - pref[a - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       bool prev = false;       for (int i = 0; true; i++) {         int change = 0;         if (i & 1) {           for (int j = 1; j < n - 1; j++) {             if (arr[j] > arr[j + 1]) {               swap(arr[j], arr[j + 1]);               change++;             }             j++;           }         } else {           for (int j = 0; j < n - 2; j++) {             if (arr[j] > arr[j + 1]) {               swap(arr[j], arr[j + 1]);               change++;             }             j++;           }         }         if (!change) {           if (prev) {             cout << i - 1 <<   n ;             break;           }           prev = true;         } else {           prev = false;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d;   long long f(long long k) { return (d * b * k - 2 * a) * (k + 1) / -2; }   int main() {     int t;     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       if (a > b * c) {         cout <<  -1 n ;         continue;       }       double k = a * 1.0 / (d * b) - 0.5;       cout << max(f(k), f(k + 1)) <<   n ;     }   }


#include <bits/stdc++.h>   int main(void) {     char a[100001];     long long current, jump[100001], n, i;     int flag = 1, visited[100001];     memset(visited, 0, sizeof(visited));     scanf( %lld , &n);     if (n == 1) {       printf( FINITE );       return 0;     }     scanf( %s , a);     for (i = 1; i <= n; i++) scanf( %lld , &jump[i]);     current = 1;     i = 1;     while (flag == 1) {       visited[current] = 1;       if (a[current - 1] ==  > ) {         current = current + jump[current];       } else {         current = current - jump[current];       }       if (current < 1 || current > n) {         flag = 0;         break;       }       if (visited[current] == 1) {         break;       }     }     if (flag == 0) {       printf( FINITE );     } else {       printf( INFINITE );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr1[26], arr2[26][26];   signed main() {     string s;     cin >> s;     long long n = s.length();     for (long long i = 0; i < n; i++) {       long long ct = s[i] -  a ;       for (long long j = 0; j < 26; j++) {         arr2[j][ct] += arr1[j];       }       arr1[ct]++;     }     long long ans = 0;     for (long long i = 0; i < 26; i++) ans = max(ans, arr1[i]);     for (long long i = 0; i < 26; i++) {       for (long long j = 0; j < 26; j++) {         ans = max(ans, arr2[i][j]);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     for (i = 1; i <= n; i++) {       if (i % 4 == 1 || i % 4 == 2)         cout <<  a ;       else         cout <<  b ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int m, n;   int main() {     int n;     string vic1, vic2, tmp1, tmp2;     cin >> vic1 >> vic2;     cin >> n;     cout << vic1 <<     << vic2 << endl;     for (int i = 0; i < n; ++i) {       cin >> tmp1 >> tmp2;       if (vic1 == tmp1)         vic1 = tmp2;       else         vic2 = tmp2;       cout << vic1 <<     << vic2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[6700][3000];   char c[3000];   int vis[2000];   vector<int> ans;   int len;   void shift(int x, int k) {     int num = 0;     for (int i = len - 1; i > len - 1 - x; i--) {       ch[k][num++] = ch[k - 1][i];     }     for (int i = 0; i < len - x; i++) {       ch[k][num++] = ch[k - 1][i];     }     ch[k][num] =   0 ;   }   int main() {     scanf( %d , &len);     scanf( %s , ch[0]);     while (ch[0][0] ==     || ch[0][0] ==   n  || ch[0][0] ==   r )       scanf( %s , ch[0]);     scanf( %s , c);     while (c[0] ==     || c[0] ==   n  || c[0] ==   r ) scanf( %s , c);     if (strlen(c) != strlen(ch[0])) {       printf( -1 );       return 0;     }     for (int i = 0; i < len; i++) {       vis[ch[0][i]]++;       vis[c[i]]--;     }     for (int i =  a ; i <=  z ; i++) {       if (vis[i] != 0) {         printf( -1 );         return 0;       }     }     int num = 1;     for (int i = 1; i <= len; i++) {       for (int j = 0; j <= len - i; j++) {         if (c[i - 1] == ch[num - 1][j]) {           ans.push_back(len - j - 1);           ans.push_back(1);           ans.push_back(len - 1);           shift(len - j - 1, num++);           shift(1, num++);           shift(len - 1, num++);           break;         }       }     }     printf( %d n , num - 1);     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   char str[10];   bool check(int x, int y) {     sprintf(str,  %02d:%02d , x, y);     return (str[0] == str[4] && str[1] == str[3]);   }   int main() {     int i, j, n, m;     scanf( %d:%d , &n, &m);     for (i = n; i < 24; ++i) {       for (j = 0; j < 60; ++j) {         if (i == n && j <= m) continue;         if (check(i, j)) {           printf( %s , str);           return 0;         }       }     }     cout <<  00:00  << endl;     return 0;   }