#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   int n, m;   vector<int> len;   vector<pair<int, int> > pos;   deque<int> ans;   vector<bool> vis;   int find(int x) {     for (int i = 0; i < (int)len.size(); ++i) {       if (len[i] == x and !vis[i]) return i;     }     return -1;   }   int main() {     cin >> n >> m;     pos = vector<pair<int, int> >(n);     len = vector<int>(m);     for (int i = 0; i < n; ++i) cin >> pos[i].first >> pos[i].second;     for (int i = 0; i < m; ++i) cin >> len[i];     if (n % 2) {       cout <<  NO n ;       return 0;     }     bool good = 0;     vis = vector<bool>(m, 0);     ans = deque<int>();     for (int i = 0; i < n; i += 2) {       int prev = (i + n - 1) % n;       int dist1 = (int)hypot(pos[prev].first - pos[i].first,                              pos[prev].second - pos[i].second);       int dist2 = (int)hypot(pos[i + 1].first - pos[i].first,                              pos[i + 1].second - pos[i].second);       int idx = find(dist1 + dist2);       if (idx != -1) {         vis[idx] = 1;         ans.push_back(idx);       } else         goto no;     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       if (i % 2 == 1)         cout << -1 <<    ;       else {         cout << ans.front() + 1 <<    ;         ans.pop_front();       }     }     cout << endl;     return 0;   no:;     vis = vector<bool>(m, 0);     ans = deque<int>();     for (int i = 1; i < n; i += 2) {       int nxt = (i + n + 1) % n;       int dist1 = (int)hypot(pos[i - 1].first - pos[i].first,                              pos[i - 1].second - pos[i].second);       int dist2 = (int)hypot(pos[nxt].first - pos[i].first,                              pos[nxt].second - pos[i].second);       int idx = find(dist1 + dist2);       if (idx != -1) {         vis[idx] = 1;         ans.push_back(idx);       } else {         good = 0;         goto noo;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       if (i % 2 == 0)         cout << -1 <<    ;       else {         cout << ans.front() + 1 <<    ;         ans.pop_front();       }     }     cout << endl;     return 0;   noo:;     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     std::cin >> n;     if (n > 1) {       std::cout << 2 * (n - 1);     } else {       std::cout << 1;     };     std::cout <<     << 2 << std::endl << 1 <<     << 2;     return NULL;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, i, j, sum, k;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       sum += a;       j += 1 - 2 * a;       if (j < 0) j = 0;       if (k < j) k = j;     }     if (!k) {       cout << sum - 1;     } else {       cout << sum + k;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int a, b, c;       cin >> a >> b >> c;       int ans = (int)1e9;       int A = -1, B = -1, C = -1;       for (int cA = 1; cA <= 2 * a; cA++) {         for (int cB = cA; cB <= 2 * b; cB += cA) {           for (int i = 0; i < 2; i++) {             int cC = cB * (c / cB) + i * cB;             int res = abs(cA - a) + abs(cB - b) + abs(cC - c);             if (ans > res) {               ans = res;               A = cA;               B = cB;               C = cC;             }           }         }       }       cout << ans <<   n  << A <<     << B <<     << C <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5;   long long ans[N];   struct person {     int t, s, f, num;     void read() { scanf( %d%d%d , &t, &s, &f); }     bool operator<(const person &b) const { return t < b.t; }   } a[N];   int n, m, X, D, sl, sr;   long long T;   multiset<pair<long long, int> > s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) a[i].num = i, a[i].read();     sort(a + 1, a + n + 1);     T = 0;     X = 1;     D = 0;     int i = 1;     while (i <= n || !s.empty()) {       multiset<pair<long long, int> >::iterator tmp;       if (D == 1)         tmp = s.lower_bound(pair<long long, int>(X, -N));       else if (D == -1) {         tmp = s.upper_bound(pair<long long, int>(X, +N));         if (tmp == s.begin())           tmp = s.end();         else           --tmp;       } else         tmp = s.end();       if (i > n || tmp != s.end() && (tmp->first - X) * D <= a[i].t - T) {         T += (tmp->first - X) * D;         int tx = X;         X = tmp->first;         if (X < tx) {           multiset<pair<long long, int> >::iterator               beg = s.lower_bound(pair<long long, int>(X, -N)),               end = s.lower_bound(pair<long long, int>(X, +N));           for (; beg != end; beg++) sl--, sr++;         }         if (tmp->second > 0) {           s.insert(pair<long long, int>(a[tmp->second].f, -tmp->second));           if (a[tmp->second].f >= X)             sr++;           else             sl++;         } else {           ans[a[-tmp->second].num] = T;         }         if (tmp->first >= X)           sr--;         else           sl--;         s.erase(tmp);       } else {         X += (a[i].t - T) * D;         T = a[i].t;         s.insert(pair<long long, int>(a[i].s, i));         if (a[i].s >= X)           sr++;         else           sl++;         i++;       }       if (sr == 0 && sl == 0)         D = 0;       else if (sr >= sl)         D = 1;       else         D = -1;     }     for (int i = 1; i <= n; i++) printf( %I64d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c;   int main() {     cin >> a >> b >> c;     int ans = 0;     for (int i = 0; i <= c; i += a) {       if ((c - i) % b == 0) ans++;     }     if (ans == 0)       cout <<  No ;     else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 2;   const double eps = 1e-6;   const int MAX = 100001;   int CA[MAX];   int CB[MAX];   int main() {     int N;     cin >> N;     int ans = N + 1;     if (N == 1 || N == 2) {       cout << 0 << endl;       return 0;     }     vector<int> A(N);     vector<int> B(N);     map<int, int> MA;     map<int, int> MB;     int half = N / 2;     if (N % 2) half += 1;     for (int i = 0; i < N; ++i) {       int a, b;       cin >> a >> b;       if (a != b) {         MB[b] = MB[b] + 1;       }       MA[a] = MA[a] + 1;       if (MA[a] >= half) {         cout << 0 << endl;         return 0;       }       if (MB[b] >= half) {         ans = min(ans, MB[b]);       }     }     for (map<int, int>::iterator itr = MA.begin(); itr != MA.end(); ++itr) {       if (itr->second + MB[itr->first] >= half) {         ans = min(ans, half - itr->second);       }     }     if (ans == N + 1) {       cout << -1 << endl;     } else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 7;   int n, m, comp[N], y, spre[N];   bool vis[N];   vector<int> g[N], ig[N], ord, rep[N];   set<int> sgn[N];   void dfs1(int a) {     vis[a] = 1;     for (auto &b : g[a]) {       if (!vis[b]) {         dfs1(b);       }     }     ord.push_back(a);   }   void dfs2(int a) {     rep[y].push_back(a);     comp[a] = y;     for (auto &b : ig[a]) {       if (!comp[b]) {         dfs2(b);       }     }   }   int este(int i, int j) {     cout <<  ?   << i <<     << j << endl;     int r;     cin >> r;     return r;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       ig[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs1(i);       }     }     reverse(ord.begin(), ord.end());     for (auto &i : ord) {       if (comp[i] == 0) {         y++;         dfs2(i);       }     }     for (int i = 1; i <= n; i++)       for (auto &j : g[i])         if (comp[i] != comp[j]) sgn[comp[i]].insert(comp[j]);     n = y;     for (int i = 1; i <= n; i++) {       g[i].clear();       for (auto &j : sgn[i]) {         g[i].push_back(j);         spre[j]++;       }     }     vector<int> stk;     for (int i = 1; i <= n; i++) {       if (!spre[i]) stk.push_back(i);     }     int ret = stk[0];     while ((int)stk.size() > 1) {       int now = stk.back();       while ((int)rep[now].size() > 0 && (int)rep[ret].size() > 0) {         int x = rep[now].back(), y = rep[ret].back();         if (este(x, y))           rep[ret].pop_back();         else           rep[now].pop_back();       }       if (rep[ret].empty()) {         swap(stk.back(), stk[0]);         swap(ret, now);       }       stk.pop_back();       for (auto &j : g[now]) {         spre[j]--;         assert(spre[j] >= 0);         if (!spre[j]) {           stk.push_back(j);         }       }     }     cout <<  !   << rep[ret].back() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool func(int x) {     int cnt = 0;     while (x != 0) {       x = x / 10;       cnt++;     }     if (cnt == 1)       return true;     else if (cnt == 2)       return false;     else if (cnt == 0)       return true;   }   int main() {     int h1, h2, m1, m2;     int h, m, temp;     char ch;     cin >> h1;     cin >> ch;     cin >> m1;     cin >> h2;     cin >> ch;     cin >> m2;     int dh, dm, t;     dh = h2 - h1;     dm = m2 - m1;     if (dm == 0) {       float g = (double)dh / 2;       g *= 60;       if (g >= 60) {         int ho = g / 60;         int mi = (long long)g % 60;         h = h1 + ho;         m = mi + m1;       } else {         m = m1 + g;         if (m >= 60) {           h = h1 + (m / 60);           m = m % 60;         } else           h = h1;       }     } else if (dh == 0) {       h = h1;       m = m1 + dm / 2;     } else {       if (dm < 0) {         --dh;         t = dh + (60 - m1) + m2;       } else {         dh;         t = dh * 60 + (m2 - m1);       }       t = t / 2;       if (t + m1 >= 60) {         int u = h1 + t / 60;         int left = t % 60;         if (m1 + left >= 60) {           ++u;           m = (left - (60 - m1));         } else           m = m1 + left;         h = u;       } else {         h = h1;         m = m1 + t;       }     }     if (func(h) == true && func(m) == true) {       cout <<  0  << h <<  :  <<  0  << m << endl;     } else if (func(h) && !func(m)) {       cout <<  0  << h <<  :  << m << endl;     } else if (!func(h) && func(m)) {       cout << h <<  :  <<  0  << m << endl;     } else       cout << h <<  :  << m << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:40000000 )   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.0);   const int mod = 1000000007;   const int MAXN = 200 * 200;   int a[111];   int n;   int main() {     cin >> n;     bool p = 1;     for (int(i) = (0); (i) < (n); ++(i)) {       int x;       cin >> x;       a[x]++;       if (x == 25) continue;       if (x == 50) {         a[25]--;         if (a[25] < 0) p = 0;       }       if (x == 100) {         if (a[50] && a[25]) {           a[50]--;           a[25]--;         } else {           a[25] -= 3;           if (a[25] < 0) p = 0;         }       }     }     if (p)       cout <<  YES  << endl;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Append(const string& w, string& a) {     a += w;     a +=  , ;   }   bool IsNumber(const string& w) {     for (char c : w) {       if (!isdigit(c)) return false;     }     return !w.empty() && (w ==  0  || w[0] !=  0 );   }   void Process(const string& s, int start, int end, string& a, string& b) {     assert(end - start + 1 >= 0);     const string w = s.substr(start, end - start + 1);     if (IsNumber(w)) {       Append(w, a);     } else {       Append(w, b);     }   }   void Output(string& s) {     if (s.empty())       cout <<  - n ;     else       cout <<     << s.substr(0, s.size() - 1) <<    n ;   }   int main() {     string s;     cin >> s;     s +=  , ;     string a, b;     int start = 0;     for (int i = 0; i < (int)s.size(); ++i) {       if (s[i] ==  ;  || s[i] ==  , ) {         Process(s, start, i - 1, a, b);         start = i + 1;       }     }     Output(a);     Output(b);   }


#include <bits/stdc++.h>   using namespace std;   long long f(long long x) {     int num = 0;     for (int i = 1; 1ll * i * i <= x; i++) {       if (x % i) continue;       num++;       if (1ll * i * i != x) num++;     }     return num;   }   long long solve(vector<int> v) {     int n = v.size();     long long num = 1ll * v[0] * v[n - 1];     for (int i = 1; i < n / 2 + (n % 2); i++) {       long long cur = 1ll * v[i] * v[n - i - 1];       if (cur != num) return -1;     }     if (f(num) != n + 2) return -1;     return num;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.begin(), a.end());       cout << solve(a) << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1000005;   using namespace std;   long long n, k, sum, q, res, m, val, ans;   long long x, y;   double p;   long long xx[] = {1, 0, -1, 0};   long long yy[] = {0, 1, 0, -1};   void solve(long long no) {     cin >> n;     long long res = 0;     vector<long long> v[64];     for (int i = 0; i < n; i++) {       cin >> x;       res ^= x;       for (int j = 0; j < 64; j++)         if (x & (1LL << j)) v[j].push_back(i);     }     if (res == 0) {       cout <<  DRAW n ;       return;     }     vector<long long> v1;     for (int j = 63; j >= 0; j--) {       if (v[j].size() % 4 == 1) {         cout <<  WIN n ;         return;       } else if (v[j].size() % 4 == 3) {         if ((n - v[j].size()) % 2)           cout <<  WIN n ;         else           cout <<  LOSE n ;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     for (long long i = 1; i <= t; i++) solve(i);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int sz = n + m - 2;     int mid = sz / 2;     int x;     vector<pair<int, int>> a(mid + 1, {0, 0});     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> x;         int id = i + j;         if (id > mid) {           id = sz - id;         }         if (x == 0) {           a[id].first++;         } else {           a[id].second++;         }       }     }     int ans = 0;     int ma = a.size();     if (sz % 2 == 0) {       ma--;     }     for (int i = 0; i < ma; i++) {       ans += min(a[i].first, a[i].second);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, last;   int f[6005][6005];   inline void dfs(int x, int y, int o) {     f[x][y] += o;     int O = f[x][y];     f[x][y] %= 4;     if (O < 4) return;     dfs(x, y + 1, O / 4);     dfs(x, y - 1, O / 4);     dfs(x + 1, y, O / 4);     dfs(x - 1, y, O / 4);   }   int main() {     scanf( %d%d , &n, &t);     dfs(2500, 2500, n);     for (int i = 1; i <= t; i++) {       int x, y;       scanf( %d%d , &x, &y);       x += 2500, y += 2500;       if (x > 5000 || y > 5000 || x < 0 || y < 0) {         printf( 0 n );         continue;       }       printf( %d n , f[x][y]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void chkmin(T &x, T y) {     x = x > y ? y : x;   }   template <typename T>   void update(T &x, T y, T mod) {     x = x + y > mod ? x + y - mod : x + y;   }   template <typename T>   void multi(T &x, T y, T mod) {     x = 1ll * x * y % mod;   }   const int INF = (1ll << 30);   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 0;     } while (ch >  9  || ch <  0 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     x = f ? x : -x;   }   template <typename T>   void write(T x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1e5 + 7;   struct Segment_Tree {     int l, r, sum, rem, mul, fac[20];   } t[N << 2];   int n, m, mod, cnt, tot, phi, a[N], P[N], tmp[N], prime[N];   bool vis[N];   inline int calc(int x) {     for (int i = 1; i <= tot; i++) {       tmp[i] = 0;       while (x % P[i] == 0) {         x /= P[i];         tmp[i]++;       }     }     return x;   }   inline int qpow(int a, int b) {     long long ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ret % mod;   }   inline void mul(int p, int mul, int rem, int *tmp) {     multi(t[p].rem, rem, mod);     for (int i = 1; i <= tot; i++) t[p].fac[i] += tmp[i];     multi(t[p].sum, mul, mod);     multi(t[p].mul, mul, mod);   }   inline void divide(int p, int y, int *tmp) {     multi(t[p].rem, qpow(y, phi - 1), mod);     int tp = t[p].rem;     for (int i = 1; i <= tot; i++) {       t[p].fac[i] -= tmp[i];       multi(tp, qpow(P[i], t[p].fac[i]), mod);     }     t[p].sum = tp % mod;   }   inline void pushdown(int p) {     if (t[p].mul != 1 || t[p].rem != 1) {       mul((p << 1), t[p].mul, t[p].rem, t[p].fac);       mul((p << 1 | 1), t[p].mul, t[p].rem, t[p].fac);       t[p].mul = t[p].rem = 1;       for (int i = 1; i <= tot; i++) t[p].fac[i] = 0;     }   }   inline void build(int p, int l, int r) {     t[p].l = l;     t[p].r = r;     t[p].mul = t[p].rem = 1;     if (l == r) {       t[p].sum = a[l] % mod;       t[p].rem = calc(a[l]);       for (int i = 1; i <= tot; i++) t[p].fac[i] = tmp[i];       return;     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     build((p << 1), l, mid);     build((p << 1 | 1), mid + 1, r);     t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod;   }   inline void multi(int p, int l, int r, int x, int k, int *tmp) {     if (l <= t[p].l && t[p].r <= r) {       mul(p, k, x, tmp);       return;     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     if (l <= mid) multi((p << 1), l, r, x, k, tmp);     if (r > mid) multi((p << 1 | 1), l, r, x, k, tmp);     t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod;   }   inline void divide(int p, int x, int y, int *tmp) {     if (t[p].l == t[p].r) {       divide(p, y, tmp);       return;     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     if (x <= mid)       divide((p << 1), x, y, tmp);     else       divide((p << 1 | 1), x, y, tmp);     t[p].sum = (t[(p << 1)].sum + t[(p << 1 | 1)].sum) % mod;   }   inline int query(int p, int l, int r) {     if (l <= t[p].l && t[p].r <= r) return t[p].sum;     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1, ans = 0;     if (l <= mid) update(ans, query((p << 1), l, r), mod);     if (r > mid) update(ans, query((p << 1 | 1), l, r), mod);     return ans;   }   inline void init(int NN) {     for (int i = 2; i <= NN; i++) {       if (!vis[i]) {         prime[++cnt] = i;       }       for (int j = 1; j <= cnt && prime[j] * i <= NN; j++) {         vis[i * prime[j]] = true;         if (i % prime[j] == 0) break;       }     }   }   inline int getphi(int x) {     int ans = x;     for (int i = 1; i <= cnt && prime[i] * prime[i] <= x; i++) {       if (x % prime[i] == 0) {         ans = 1ll * ans * (prime[i] - 1) / prime[i];         while (x % prime[i] == 0) x /= prime[i];       }     }     if (x != 1) ans = 1ll * ans * (x - 1) / x;     return ans;   }   inline void divide(int x) {     for (int i = 1; i <= cnt && prime[i] * prime[i] <= x; i++) {       if (x % prime[i] == 0) {         while (x % prime[i] == 0) x /= prime[i];         P[++tot] = prime[i];       }     }     if (x != 1) P[++tot] = x;   }   int main() {     read(n);     read(mod);     init(1e5);     divide(mod);     phi = getphi(mod);     for (int i = 1; i <= n; i++) read(a[i]);     build(1, 1, n);     read(m);     for (int i = 1, opt, l, r, x; i <= m; i++) {       read(opt);       if (opt == 1) {         read(l);         read(r);         read(x);         multi(1, l, r, calc(x), x, tmp);       }       if (opt == 2) {         read(l);         read(x);         divide(1, l, calc(x), tmp);       }       if (opt == 3) {         read(l);         read(r);         printf( %d n , query(1, l, r) % mod);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, h[15], side = 0, dsh[15], cent = 52;   vector<int> sshot, cshot;   void recur(int now, int tot) {     if (now == n - 1) {       int ok = 1;       for (int i = 1; i < n - 1; i++)         if (dsh[i] * a + dsh[i - 1] * b + dsh[i + 1] * b <= h[i]) {           ok = 0;           break;         }       if (ok == 1 && tot < cent) {         cent = tot;         cshot.clear();         for (int i = 1; i < n - 1; i++)           for (int j = 0; j < dsh[i]; j++) cshot.push_back(i);       }       return;     }     if (tot >= cent) return;     for (int i = 0; i <= 8; i++) {       dsh[now] = i;       recur(now + 1, tot + i);     }   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     while (h[0] >= 0) {       h[0] -= b;       h[2] -= b;       h[1] -= a;       side++;       sshot.push_back(1);     }     while (h[n - 1] >= 0) {       h[n - 1] -= b;       h[n - 3] -= b;       h[n - 2] -= a;       side++;       sshot.push_back(n - 2);     }     memset(dsh, 0, sizeof(dsh));     recur(1, 0);     printf( %d n , cent + side);     printf( %d , sshot[0] + 1);     for (int i = 1; i < sshot.size(); i++) printf(  %d , sshot[i] + 1);     for (int i = 0; i < cshot.size(); i++) printf(  %d , cshot[i] + 1);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     vector<int> u(n);     for (long long i = 0; i < n; i++) cin >> u[i];     ;     sort((v).begin(), (v).end());     sort((u).begin(), (u).end());     bool turn = 0;     long long a = 0LL, b = 0LL;     while (!v.empty() || !u.empty()) {       if (!turn) {         if (v.back() >= u.back()) {           if (!v.empty()) {             a += v.back();             v.pop_back();           } else if (!u.empty()) {             u.pop_back();           } else {             break;           }         } else {           if (!u.empty()) {             u.pop_back();           } else if (!v.empty()) {             a += v.back();             v.pop_back();           } else {             break;           }         }         turn = 1;       } else {         if (u.back() >= v.back()) {           if (!u.empty()) {             b += u.back();             u.pop_back();           } else if (!v.empty()) {             v.pop_back();           } else {             break;           }         } else {           if (!v.empty()) {             v.pop_back();           } else if (!u.empty()) {             b += u.back();             u.pop_back();           } else {             break;           }         }         turn = 0;       }     }     cout << a - b << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     int l = (n - 1) / m;     if ((n - 1) % m == 0)       printf( %d n , 2 * l);     else       printf( %d n , 2 * l + 1 + ((n - 1) % m >= 2));     int need = (n - 1) % m;     for (int i = 2; i <= n;) {       int maxn = min(n, i + l - 1 + (need-- > 0));       printf( %d %d n , 1, i);       int j = i;       while (j++ < maxn) printf( %d %d n , j - 1, j);       i = maxn + 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   const int N = (int)2e5 + 5;   const int maxN = (int)1e6 + 6;   const long long Mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long Inf = (long long)1e18;   struct lowest_common_ancestor {     const static int N = 1e5 + 5;     const static int k = 17;     int par[N][k + 1], lev[N];     vector<vector<int>> g, city;     vector<int> ID[N][k + 1];     lowest_common_ancestor() {       for (int i = 0; i < N; ++i) {         for (int j = 0; j <= k; ++j) par[i][j] = 0;         lev[i] = 0;       }     }     vector<int> merge(vector<int> &a, vector<int> &b) {       vector<int> tmp;       auto i = a.begin(), j = b.begin();       for (int k = 1; k <= min(10, (int)a.size() + (int)b.size()); ++k) {         if (i != a.end() and j != b.end()) {           if (*i < *j)             tmp.push_back(*i), ++i;           else             tmp.push_back(*j), ++j;         } else if (i != a.end())           tmp.push_back(*i), ++i;         else           tmp.push_back(*j), ++j;       }       return tmp;     }     void build(int s, int p = 0) {       lev[s] = 1 + lev[p];       par[s][0] = p;       ID[s][0].assign(city[p].begin(), city[p].end());       for (int i = 1; i <= k; ++i) {         par[s][i] = par[par[s][i - 1]][i - 1];         ID[s][i] = merge(ID[s][i - 1], ID[par[s][i - 1]][i - 1]);       }       for (int i : g[s])         if (i != p) build(i, s);     }     void getLCA(int a, int b, int num) {       if (lev[a] < lev[b]) swap(a, b);       vector<int> res(city[a].begin(), city[a].end());       int d = lev[a] - lev[b];       int t = b;       for (int i = k; i >= 0; --i) {         if ((d >> i) & 1) {           res = merge(res, ID[a][i]);           a = par[a][i];         }       }       if (a == b) {         printf( %d , min((int)res.size(), num));         for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]);         cout <<   n ;         return;       }       for (int i = k; i >= 0; --i) {         if (par[a][i] != par[b][i]) {           res = merge(res, ID[a][i]);           res = merge(res, ID[b][i]);           b = par[b][i];           a = par[a][i];         }       }       res = merge(res, city[par[a][0]]);       res = merge(res, city[t]);       printf( %d , min((int)res.size(), num));       for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]);       cout <<   n ;       return;     }     void solve() {       int n = Int(), m = Int(), q = Int();       g.resize(n + 1);       city.resize(n + 1);       for (int i = 1; i < n; ++i) {         int x = Int(), y = Int();         g[x].emplace_back(y);         g[y].emplace_back(x);       }       for (int i = 1; i <= m; ++i) {         int c = Int();         city[c].emplace_back(i);       }       for (int i = 1; i <= n; ++i) {         sort(city[i].begin(), city[i].end());         while ((int)city[i].size() > 10) city[i].pop_back();       }       build(1);       while (q--) {         int l = Int(), r = Int(), t = Int();         getLCA(l, r, t);       }     }   };   lowest_common_ancestor lca;   int main() {     int test = 1, tc = 0;     while (test--) {       lca.solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const int inf = 0x3f3f3f3f;   int A[maxn];   int n, k;   void solve(int l, int r) {     if (l + 1 == r || !k) return;     int mid = (l + r) >> 1;     k -= 2;     swap(A[mid], A[mid - 1]);     solve(l, mid);     solve(mid, r);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) A[i] = i + 1;     k--;     if (k & 1) {       puts( -1 );       return 0;     }     solve(0, n);     if (k)       puts( -1 );     else {       for (int i = 0; i < n; i++) printf( %d  , A[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Imx = 2147483647;   const long long Lbig = 2e18;   const int mod = 1e9 + 7;   struct fastio {     char s[100000];     int it, len;     fastio() { it = len = 0; }     inline char get() {       if (it < len) return s[it++];       it = 0;       len = fread(s, 1, 100000, stdin);       if (len == 0)         return EOF;       else         return s[it++];     }     bool notend() {       char c = get();       while (c ==     || c ==   n ) c = get();       if (it > 0) it--;       return c != EOF;     }   } _buff;   inline long long getnum() {     long long r = 0;     bool ng = 0;     char c;     c = _buff.get();     while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get();     if (c ==  - ) ng = 1, c = _buff.get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get();     return ng ? -r : r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline char getreal() {     char c = _buff.get();     while (c ==     || c ==   n ) c = _buff.get();     return c;   }   int n;   int ask(int x, int y) {     printf( ? %d %d n , x, y);     fflush(stdout);     int ans;     scanf( %d , &ans);     return ans;   }   int a[5011], b[5011];   int A[5011], B[5011];   bool hs[5011];   int tans[5011];   bool check() {     memset(hs, 0, sizeof(hs));     for (int i = 0; i < n; i++) {       if (A[i] < 0 || A[i] >= n || hs[A[i]]) return false;       hs[A[i]] = 1;     }     memset(hs, 0, sizeof(hs));     for (int i = 0; i < n; i++) {       if (B[i] < 0 || B[i] >= n || hs[B[i]]) return false;       hs[B[i]] = 1;     }     for (int i = 0; i < n; i++) {       if (A[B[i]] != i) return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       a[i] = ask(i, 0);     }     for (int i = 0; i < n; i++) {       b[i] = ask(0, i);     }     int cnt = 0;     for (int i = 0; i < n; i++) {       A[0] = i;       B[0] = A[0] ^ a[0];       for (int j = 1; j < n; j++) {         A[j] = A[0] ^ a[0] ^ a[j];         B[j] = B[0] ^ b[0] ^ b[j];       }       if (check()) {         cnt++;         for (int j = 0; j < n; j++) tans[j] = A[j];       }     }     printf( ! n );     printf( %d n , cnt);     for (int i = 0; i < n; i++) printf( %d%c , tans[i], i + 1 < n ?     :   n );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   const long long M = 1e9 + 7;   const long long inf = 1e18 + 5;   vector<int> prefix_function(string &s) {     int n = s.size();     vector<int> pre(n);     int pos = 0;     pre[0] = 0;     for (int i = 1; i < n; i++) {       while (pos and s[pos] != s[i]) pos = pre[pos - 1];       if (s[pos] == s[i]) pos++;       pre[i] = pos;     }     return pre;   }   int main() {     string s, t;     cin >> t >> s;     int n = s.size();     vector<int> pre = prefix_function(s);     int a[n][26];     for (int i = 0; i < n; i++) {       for (int c = 0; c < 26; c++) {         if (i and s[i] !=  a  + c)           a[i][c] = a[pre[i - 1]][c];         else           a[i][c] = i + (s[i] ==  a  + c);       }     }     int tz = t.size();     int dp[tz + 1][n];     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < tz; i++) {       for (int j = 0; j < n; j++) {         if (dp[i][j] != -1) {           if (t[i] ==  ? ) {             for (int ch = 0; ch < 26; ch++) {               int val = a[j][ch];               if (val == n)                 dp[i + 1][pre[n - 1]] = max(dp[i + 1][n - 1], dp[i][j] + 1);               else                 dp[i + 1][val] = max(dp[i + 1][val], dp[i][j]);             }           } else {             int val = a[j][t[i] -  a ];             if (val == n)               dp[i + 1][pre[n - 1]] = max(dp[i + 1][n - 1], dp[i][j] + 1);             else               dp[i + 1][val] = max(dp[i + 1][val], dp[i][j]);           }         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) ans = max(ans, dp[tz][i]);     printf( %d  , ans);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = 1000001000;   const long long INFLL = INF * 1LL * INF;   const int mod = 1000 * 1000 * 1000 + 7;   const int mod9 = 1000 * 1000 * 1000 + 9;   const int modr = 99990001;   const long double PI = 3.1415926535897932385;   template <class T>   void zero(T val, T& first) {     first = val;   }   template <class T, class... Targs>   void zero(T val, T& first, Targs&... Fargs) {     first = val;     zero(val, Fargs...);   }   template <class T, class T2>   std::istream& operator>>(std::istream& is, pair<T, T2>& p) {     return is >> p.first >> p.second;   }   template <class T>   std::istream& readN(T& first, int n, int st = 0) {     for (int i = st, iend = (st + n - 1); i <= iend; i++) cin >> first[i];     return cin;   }   template <class T>   std::istream& readS(set<T>& first, int n) {     T second = *first.rbegin();     for (int i = 0, iend = (n - 1); i <= iend; i++) {       cin >> second;       first.insert(second);     }     return cin;   }   template <class T>   std::istream& read(T& first) {     return cin >> first;   }   template <class T, class... Targs>   std::istream& read(T& first, Targs&... Fargs) {     return read(first), read(Fargs...);   }   template <class T, class T2>   std::ostream& operator<<(std::ostream& os, pair<T, T2> p) {     return os << p.first <<     << p.second;   }   template <class T>   std::ostream& operator<<(std::ostream& os, vector<T> v) {     bool f = true;     for (auto second : v) {       if (!f) os <<    ;       os << second;       f = false;     }     return os;   }   template <class T>   std::ostream& operator<<(std::ostream& os, set<T> v) {     bool f = true;     for (auto second : v) {       if (!f) os <<    ;       os << second;       f = false;     }     return os;   }   template <class T>   std::ostream& operator<<(std::ostream& os, multiset<T> v) {     bool f = true;     for (auto second : v) {       if (!f) os <<    ;       os << second;       f = false;     }     return os;   }   template <class T, class T2>   std::ostream& operator<<(std::ostream& os, map<T, T2> v) {     bool f = true;     for (pair<T, T2> second : v) {       if (!f) os <<    ;       os << second.first <<  =>  << second.second;       f = false;     }     return os;   }   template <class T>   std::ostream& outV(T first, char del =    ) {     bool f = true;     for (auto second : first) {       if (!f) cout << del;       cout << second;       f = false;     }     return cout;   }   template <class T>   std::ostream& outN(T first, int n = -1, int st = 0) {     for (int i = st, iend = (n == -1 ? (int)first.size() - 1 : st + n - 1);          i <= iend; i++) {       cout << first[i];       if (i < iend) cout <<    ;     }     return cout;   }   template <class T>   std::ostream& outAN(T first, int n = -1, int st = 0) {     for (int i = st, iend = (n - 1); i <= iend; i++) {       cout << first[i];       if (i < iend) cout <<    ;     }     return cout;   }   template <class T>   std::ostream& outA2(T first, int n, int m) {     for (int i = 0, iend = (n - 1); i <= iend; i++) {       for (int j = 0, jend = (m - 1); j <= jend; j++)         cout << first[i][j] << (j == m - 1 ?   n  :    );     }     return cout;   }   template <class T>   std::ostream& out(T first) {     return cout << first;   }   template <class T, class... Targs>   std::ostream& out(T first, Targs... Fargs) {     return out(first) <<    , out(Fargs...);   }   template <typename T>   void srt(T& a, int st, int fn, bool isArr) {     sort(a + st, a + fn + 1);   }   template <class T>   void srt(T& a, int st = 0, int fn = 0) {     sort(a.begin() + st, fn ? a.begin() + fn + 1 : a.end());   }   template <typename T>   T rev_num(T a) {     T r = 0;     for (; a; a /= 10) r = r * 10 + a % 10;     return r;   }   template <typename T>   void rev(T& a, int st, int fn, bool isArr) {     reverse(a + st, a + fn + 1);   }   template <class T>   void rev(T& a, int st = 0, int fn = 0) {     reverse(a.begin() + st, fn ? a.begin() + fn + 1 : a.end());   }   long long sqr(long long a) { return a * a; };   long long sqr(int a) { return a * 1LL * a; };   long double sqr(long double a) { return a * a; };   long long phi(int n) {     int res = n;     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) {         while (n % i == 0) n /= i;         res -= res / i;       }     if (n > 1) res -= res / n;     return res;   }   long long bpm(long long a, long long n = -2, long long m = mod) {     n = n < 0 ? n + m : n;     long long r = 1;     while (n) {       if (n & 1) r = (r * a) % m;       a = (a * a) % m;       n >>= 1;     }     return r;   }   unsigned long long gcd(unsigned long long a, unsigned long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   vector<int> ero_p, ero_l;   void ero(int n) {     ero_l.resize(n + 1);     ero_l[0] = -1;     for (int i = 2, iend = (n); i <= iend; i++)       if (!ero_l[i]) {         ero_p.push_back(i);         ero_l[i] = i;         for (long long j = i * 1LL * i; j <= n; j += i) {           ero_l[j] = i;         }       }   }   long long gcd_cb(long long a, long long b, long long& first,                    long long& second) {     if (!b) {       first = 1;       second = 0;       return a;     }     long long x1, y1, g;     g = gcd_cb(b, a % b, x1, y1);     first = y1;     second = x1 - a / b * y1;     return g;   }   vector<long long> fact;   void fact_prec(int n = 20) {     fact.resize(n + 1);     fact[0] = 1;     for (int i = 1, iend = (n); i <= iend; i++) {       fact[i] = fact[i - 1] * i;     }   }   vector<long double> factd;   void fact_precd(int n = 146) {     factd.resize(n + 1);     factd[0] = 1;     for (int i = 1, iend = (n); i <= iend; i++) {       factd[i] = factd[i - 1] * i;     }   }   string str(long long a) {     string r =   ;     for (; a; a /= 10) r += a % 10 +  0 ;     rev(r);     return r;   }   const int N = 200005;   void solution() {     long long n, first, second;     read(n, first, second);     string s;     read(s);     int pv = -1;     long long res = 0;     for (int i = 0, iend = (n - 1); i <= iend; i++) {       if (s[i] ==  0 ) {         if (pv + 1 < i && pv != -1) {           res += min(first, second);         }         pv = i;       }     }     res += pv == -1 ? 0LL : second;     out(res) <<   n ;   }   int main() {     ios::sync_with_stdio(false);     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 1e5 + 10;   string a;   int main() {     int n;     while (~scanf( %d , &n)) {       map<string, int> q;       q.clear();       int num = 0;       for (int i = 0; i < n; i++) {         cin >> a;         q[a]++;         num = max(num, q[a]);       }       printf( %d n , num);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i;     cin >> n;     if (n == 1 || n == 2) {       cout <<  No ;     } else {       cout <<  Yes             <<   n ;       cout << 1 <<    ;       cout << n <<   n ;       cout << n - 1 <<    ;       for (i = 0; i < n - 1; i++) {         cout << i + 1 <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n;   string bs[50];   long long component[1000];   long long combo[1001][1001];   long long pseudopart[1001];   bool visited[1000];   int main() {     cin >> m >> n;     for (int i = 0; i < n; i++) cin >> bs[i];     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++) {         component[i] *= 2LL;         component[i] += (long long)((int)bs[j][i] - (int) 0 );       }     combo[0][0] = 1;     for (int i = 1; i < 1001; i++)       for (int j = 0; j <= i; j++) {         if (j == 0 || j == i)           combo[i][j] = 1;         else           combo[i][j] = combo[i - 1][j] + combo[i - 1][j - 1];         combo[i][j] %= 1000000007;       }     pseudopart[0] = 1;     pseudopart[1] = 1;     for (int i = 2; i <= m; i++) {       for (int j = 0; j < i; j++) {         pseudopart[i] += combo[i - 1][j] * pseudopart[i - 1 - j];         pseudopart[i] %= 1000000007;       }     }     long long ans = 1;     for (int i = 0; i < m; i++) {       if (visited[i]) continue;       long long temp = 0;       for (int j = 0; j < m; j++)         if (component[j] == component[i]) {           visited[j] = true;           temp++;         }       ans *= pseudopart[temp];       ans %= 1000000007;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 1e5 + 5;   const int MAX = 314000000;   int n, m;   int dis[maxn], tot[maxn], sum[maxn], dp[maxn];   vector<int> have[maxn];   queue<int> q;   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   class Edge {    public:     int from, l, dia, cur;     vector<int> mons;   } ed[maxn];   int main() {     scanf( %d%d , &m, &n);     for (int i = (1); i <= (n); ++i) dis[i] = INF;     for (int i = (0); i < (m); ++i) {       scanf( %d%d , &ed[i].from, &ed[i].l);       for (int j = (0); j < (ed[i].l); ++j) {         int v;         scanf( %d , &v);         if (!~v) {           ++ed[i].dia;           continue;         }         ed[i].mons.push_back(v);         have[v].push_back(i);       }       if (!ed[i].mons.size()) {         dis[ed[i].from] = min(dis[ed[i].from], ed[i].dia);       }     }     for (int i = (1); i <= (n); ++i)       if (dis[i] != INF) pq.push(make_pair(dis[i], i));     for (; !pq.empty(); pq.pop()) {       int u = pq.top().second, d = pq.top().first;       if (d != dis[u]) continue;       for (int i = (0); i < (have[u].size()); ++i) {         int id = have[u][i];         ++ed[id].cur;         if (ed[id].cur == ed[id].mons.size()) {           int v = ed[id].from;           int w = ed[id].dia;           for (int j = (0); j < (ed[id].mons.size()); ++j) {             w += dis[ed[id].mons[j]];             w = min(w, MAX);           }           if (w < dis[v]) {             dis[v] = w;             pq.push(make_pair(dis[v], v));           }         }       }     }     for (int i = (0); i < (m); ++i) {       bool ok = true;       ed[i].cur = 0;       for (int j = (0); j < (ed[i].mons.size()); ++j)         ok &= (dis[ed[i].mons[j]] != INF);       if (ok) ++tot[ed[i].from];     }     for (int i = (1); i <= (n); ++i)       if (dis[i] != INF && !tot[i]) q.push(i);     for (int i = (0); i < (m); ++i) {       if (!ed[i].mons.size() && dis[ed[i].from] != INF) {         int w = ed[i].dia;         for (int j = (0); j < (ed[i].mons.size()); ++j) {           w += dis[ed[i].mons[j]];           w = min(w, MAX);         }         dp[ed[i].from] = max(dp[ed[i].from], w);         --tot[ed[i].from];         if (!tot[ed[i].from]) {           q.push(ed[i].from);         }       }     }     for (; !q.empty(); q.pop()) {       int u = q.front();       for (int i = (0); i < (have[u].size()); ++i) {         int id = have[u][i];         int v = ed[id].from;         if (dis[v] != INF) {           sum[id] += dp[u];           sum[id] = min(sum[id], MAX);           ++ed[id].cur;           if (ed[id].cur == ed[id].mons.size()) {             dp[v] = max(dp[v], min(MAX, sum[id] + ed[id].dia));             --tot[v];             if (!tot[v]) q.push(v);           }         }       }     }     for (int i = (1); i <= (n); ++i) {       if (dis[i] == INF) {         puts( -1 -1 );       } else {         printf( %d  , dis[i]);         if (!tot[i])           printf( %d , dp[i]);         else           printf( -2 );         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   using namespace std;   struct E {     int k, c;     E() {}     E(int _k, int _c) : k(_k), c(_c) {}   } es[4200010];   struct Flow {     int n, m, dis[500010];     int qq[500010], qr, ql;     vector<int> e[500010];     void init(int _n) {       n = _n;       m = 0;       for (int i = 0; i < n; i++) e[i] = vector<int>();     }     void add_edge(int a, int b, int c) {       e[a].push_back(m);       es[m] = E(b, c);       m++;       e[b].push_back(m);       es[m] = E(a, 0);       m++;     }     bool BFS() {       memset(dis, -1, n * sizeof(int));       ql = qr = 0;       qq[qr++] = 0;       dis[0] = 0;       while (ql != qr && dis[n - 1] == -1) {         int p = qq[ql++];         for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end();              it++) {           E ee = es[*it];           if (ee.c == 0 || dis[ee.k] != -1) continue;           dis[ee.k] = dis[p] + 1;           qq[qr++] = ee.k;         }       }       return dis[n - 1] != -1;     }     long long go(int p, long long c) {       if (p == n - 1) return c;       long long ret = 0, tmp;       for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end();            it++) {         E &ee = es[*it];         if (ee.c == 0 || dis[p] + 1 != dis[ee.k]) continue;         tmp = go(ee.k, min(c - ret, (long long)ee.c));         ret += tmp;         ee.c -= tmp;         es[(*it) ^ 1].c += tmp;         if (ret == c) break;       }       if (ret == 0) dis[p] = -1;       return ret;     }     long long maxflow() {       long long ret = 0;       while (BFS()) ret += go(0, 1LL << 60);       return ret;     }   } flow;   vector<int> cc[301][301], cn[301];   int need_id, an[301], xx[301], yy[301];   pair<int, int> need[1000001];   int to[301];   bool used[301];   bool match(pair<int, int> X, pair<int, int> Y) {     if (X.first != Y.first && Y.first != -1) return 0;     if (X.second != Y.second && Y.second != -1) return 0;     return 1;   }   void go(int ma_id, int ma_hi, int n) {     if (ma_id != 1 && ((int)(cc[ma_id][0]).size()) == 0) return;     vector<pair<int, int> > qq;     int oo = need_id;     for (int i = ma_hi; i >= 0; i--) {       if (((int)(cc[ma_id][i]).size()) == 0) {         need[++need_id] = make_pair(ma_id, i);         cc[ma_id][i].push_back(-need_id);         qq.push_back(make_pair(ma_id, i));       }     }     if (need_id > n) {       for (int i = 0; i < (((int)(qq).size())); ++i)         cc[qq[i].first][qq[i].second].pop_back();       need_id = oo;       return;     }     flow.init(need_id + n + 2);     for (int i = (1); i < (n + 1); ++i)       flow.add_edge(need_id + i, need_id + n + 1, 1);     for (int i = (1); i < (need_id + 1); ++i) {       flow.add_edge(0, i, 1);       for (int j = (1); j < (n + 1); ++j) {         if (used[j]) continue;         if (match(need[i], make_pair(yy[j], xx[j])))           flow.add_edge(i, need_id + j, 1);       }     }     if (flow.maxflow() != need_id) {       need_id = oo;       return;     }     for (int i = 0; i < flow.m; i += 2) {       if (es[i].k > need_id && es[i + 1].k <= need_id && es[i].c == 0) {         used[es[i].k - need_id] = 1;         to[es[i + 1].k] = es[i].k - need_id;       }     }     for (int i = (1); i < (n + 1); ++i) {       for (int j = 0; j < (n); ++j) {         for (int k = 0; k < (((int)(cc[i][j]).size())); ++k) {           if (cc[i][j][k] < 0) cc[i][j][k] = to[-cc[i][j][k]];         }       }     }     for (int i = (1); i < (n + 1); ++i) {       if (!used[i]) {         used[i] = 1;         if (xx[i] == -1 && yy[i] == -1)           cc[1][0].push_back(i);         else if (yy[i] != -1)           cc[yy[i]][1].push_back(i);         else if (xx[i] != -1) {           if (xx[i] == 0)             cc[1][0].push_back(i);           else             cc[ma_id][xx[i]].push_back(i);         }       }     }     for (int i = (1); i < (n + 1); ++i) {       for (int j = 0; j < (((int)(cc[i][0]).size())); ++j) {         if (j % i == 0)           an[cc[i][0][j]] = cc[i][0][j + i - 1];         else           an[cc[i][0][j]] = cc[i][0][j - 1];       }       for (int j = (1); j < (n); ++j) {         for (int k = 0; k < (((int)(cc[i][j]).size())); ++k)           an[cc[i][j][k]] = cc[i][j - 1][0];       }     }     for (int i = (1); i < (n + 1); ++i) printf( %d%c , an[i],    n [i == n]);     exit(0);   }   int main() {     int(n);     scanf( %d , &n);     int ma_hi = -1;     for (int i = (1); i < (n + 1); ++i) {       char s1[20], s2[20];       scanf( %s , (s1));       scanf( %s , (s2));       int x = -1, y = -1;       if (s1[0] !=  ? ) x = atoi(s1);       if (s2[0] !=  ? ) y = atoi(s2);       if (x != -1 && y != -1) {         cc[y][x].push_back(i);         used[i] = 1;       } else if (y != -1)         cn[y].push_back(i);       xx[i] = x;       yy[i] = y;       ma_hi = max(ma_hi, x);     }     int mi = 10000, ma_id = 1;     for (int i = (1); i < (n + 1); ++i) {       int hi = n - 1;       while (hi >= 0 && ((int)(cc[i][hi]).size()) == 0) hi--;       while (hi >= 0) {         if (!((int)(cc[i][hi]).size())) {           need[++need_id] = make_pair(i, hi);           cc[i][hi].push_back(-need_id);         }         hi--;       }       if (((int)(cn[i]).size()) && ((int)(cc[i][0]).size()) == 0) {         need[++need_id] = make_pair(i, 0);         cc[i][0].push_back(-need_id);       }       while (((int)(cc[i][0]).size()) % i) {         need[++need_id] = make_pair(i, 0);         cc[i][0].push_back(-need_id);       }     }     for (int ker = 1; ker <= n; ker++) {       go(ker, ma_hi, n);     }     return 0 * puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename T, typename U, typename V>   ostream& operator<<(ostream& os, const tuple<T, U, V>& t) {     os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ) ;     return os;   }   template <typename T, typename U, typename V, typename W>   ostream& operator<<(ostream& os, const tuple<T, U, V, W>& t) {     os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ,         << get<3>(t) <<  ) ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const unordered_set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const deque<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   void debug_out() { cerr <<   n ; }   template <class Head, class... Tail>   void debug_out(Head&& head, Tail&&... tail) {     cerr << head;     if (sizeof...(Tail) > 0) cerr <<  ,  ;     debug_out(move(tail)...);   }   template <typename T>   T gcd(T x, T y) {     return y != 0 ? gcd(y, x % y) : x;   }   template <typename T>   T lcm(T x, T y) {     return x / gcd(x, y) * y;   }   template <class T1, class T2>   inline bool chmin(T1& a, T2 b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T1, class T2>   inline bool chmax(T1& a, T2 b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int INF = 1e9;   const long long IINF = 1e18;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char dir[4] = { D ,  R ,  U ,  L };   const long long MOD = 1000000007;   vector<bool> binary_conversion(const string& s) {     using u64 = uint64_t;     vector<u64> num(s.size() / 9 + 10, 0);     for (size_t i = 0; i < s.size(); i += 9) {       const string t = s.substr(i, 9);       u64 add = 0, mul = 1;       for (const auto c : t) {         add = add * 10 + (c -  0 );         mul *= 10;       }       for (auto& d : num) {         d = d * mul + add;         add = d >> 32;         d -= add << 32;       }     }     vector<bool> res(num.size() * 32);     for (size_t i = 0; i < num.size(); i++) {       for (size_t j = 0; j < 32; j++) {         res[i * 32 + j] = num[i] >> j & 1;       }     }     while (!res.empty() && !res.back()) res.pop_back();     return res;   };   namespace n91 {   using usize = std::size_t;   using u64 = std::uint64_t;   std::vector<bool> stob(std::string s) {     std::vector<u64> num(s.size() / 9 + 10, 0);     for (usize i = 0; i < s.size(); i += 9) {       const std::string t = s.substr(i, 9);       u64 mul = 1;       u64 add = 0;       for (const auto c : t) {         add = add * 10 + (c -  0 );         mul *= 10;       }       for (auto& d : num) {         d = d * mul + add;         add = d >> 32;         d -= add << 32;       }     }     std::vector<bool> res(num.size() * 32);     for (usize i = 0; i < num.size(); ++i) {       for (usize j = 0; j < 32; ++j) {         res[i * 32 + j] = num[i] >> j & 1;       }     }     while (!res.empty() && !res.back()) {       res.pop_back();     }     return res;   }   }  // namespace n91   const int MAX = 2048;   using u64 = uint64_t;   using BS = bitset<2 * MAX>;   BS calc(const string& s) {     BS res;     vector<bool> v = binary_conversion(s);     for (int i = 0; i < v.size(); i++) {       if (v[i]) {         res.set(i, 1);       }     }     return res;   }   vector<BS> bases;   vector<int> idx(MAX, -1);   vector<int> solve(BS b, int x) {     for (int i = MAX - 1; i >= 0; i--) {       if (!b[i]) continue;       if (~idx[i])         b ^= bases[idx[i]];       else {         b.set(MAX + x, 1);         idx[i] = bases.size();         bases.emplace_back(b);         return {};       }     }     vector<int> res;     for (int i = 0; i < MAX; i++) {       if (b[MAX + i]) {         res.emplace_back(i);       }     }     return res;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int m;     cin >> m;     for (int i = 0; i < m; i++) {       string S;       cin >> S;       vector<int> ans = solve(calc(S), i);       cout << ans.size();       for (int x : ans) cout <<     << x;       cout <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define pb push_back   #define fi first   #define se second   #define pii pair<int,int>       void solve() {       int n, m;       cin>>n>>m;       vector<int> a(n), b(n), c(m), vis(n, 1);       int cnt = 0;       for(int i=0;i<n;i++) cin>>a[i];       for(int i=0;i<n;i++) {           cin>>b[i];           if(a[i] != b[i]) {               vis[i] = 0;               cnt++;           }                      }       vector<vector<int>> arr(n);       for(int i=0;i<m;i++) {           cin>>c[i];           arr[c[i] - 1].pb(i);       }       if(cnt > m) {           cout<< NO ;           return ;       }       vector<int> ans(m, -1);       for(int i=0;i<n;i++) {           if(a[i] != b[i]) {               if(arr[b[i] - 1].empty()) {                   cout<< NO ;                   return ;               }               else {                   ans[arr[b[i] - 1].back()] = i;                   arr[b[i] - 1].pop_back();                }           }       }       for(int i=0;i<n;i++) {           if(a[i] == b[i]) {               if(!arr[b[i] - 1].empty())  {                   ans[arr[b[i] - 1].back()] = i;                   arr[b[i] - 1].pop_back();                }           }       }       int last = ans[m-1];       for(int i=m-2;i>=0;i--) {           if(last != -1) {               if(ans[i] == -1) {                   ans[i] = last;               }                else last = ans[i];           }           else last = ans[i];       }       for(int i=0;i<m;i++) {           if(ans[i] == -1) {               cout<< NO ;               return ;           }       }       cout<< YES <<  n ;       for(int i=0;i<m;i++) cout<<ans[i] + 1<<   ;    }      int main() {       int t = 1;       cin>>t;       while(t--) {           solve();           cout<<  n ;       }       return 0;   }


#include  list    #include <iostream>   #include <utility>   #include <vector>   #include  fstream    #include <fstream>   #include <map>   #include  algorithm    #include <iomanip>   #include  cmath    #include  set    #include <climits>   #include  queue    #include  complex       #define all(x) (x).begin(), (x).end()   #define ll long long   using namespace std;   long long mod = 1e9 + 7;   void solve() {       int n, k;       cin >> n >> k;       long long res = 1;       for (int i = 0; i < k; ++i) {           res *= n;           res %= mod;       }       cout << res << endl;   }   signed main() {       int n;       cin >> n;       while (n--) solve();      }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6 + 200, RANGE = 1e6 + 20;   const long long INF = 0x3f3f3f3f3f3f3f3f;   int n, m, p;   long long pre_min[MAX_N], nodes[MAX_N << 2], tag[MAX_N << 2];   pair<int, int> ai[MAX_N], bi[MAX_N];   struct tup {     int x, y, z;     bool operator<(const tup &rhs) const {       return x < rhs.x || (x == rhs.x && y < rhs.y);     }   } tups[MAX_N];   void pushdown(int p) {     if (tag[p] != 0) {       tag[(p << 1)] += tag[p], tag[((p << 1) | 1)] += tag[p];       nodes[(p << 1)] += tag[p], nodes[((p << 1) | 1)] += tag[p];       tag[p] = 0;     }   }   void pushup(int p) { nodes[p] = max(nodes[(p << 1)], nodes[((p << 1) | 1)]); }   void update(int ql, int qr, int l, int r, int p, long long val) {     if (ql <= l && r <= qr) return (void)(nodes[p] += val, tag[p] += val);     pushdown(p);     if (ql <= ((l + r) >> 1)) update(ql, qr, l, ((l + r) >> 1), (p << 1), val);     if (((l + r) >> 1) < qr)       update(ql, qr, ((l + r) >> 1) + 1, r, ((p << 1) | 1), val);     pushup(p);   }   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %d%d , &ai[i].first, &ai[i].second);     for (int i = 1; i <= m; i++) scanf( %d%d , &bi[i].first, &bi[i].second);     for (int i = 1; i <= p; i++)       scanf( %d%d%d , &tups[i].x, &tups[i].y, &tups[i].z), tups[i].y++,           tups[i].x++;     sort(ai + 1, ai + 1 + n), sort(bi + 1, bi + 1 + m),         sort(tups + 1, tups + 1 + p);     pre_min[m + 1] = INF;     for (int i = m; i >= 1; i--)       pre_min[i] = min(pre_min[i + 1], 1LL * bi[i].second);     int last_pos = 1;     for (int i = 1; i <= m; i++)       update(last_pos, bi[i].first, 1, RANGE, 1, -pre_min[i]),           last_pos = bi[i].first + 1;     update(last_pos, RANGE, 1, RANGE, 1, -INF);     long long ans = -INF;     for (int i = 1, ptr = 1; i <= n; i++) {       int pos = ai[i].first, cost = ai[i].second;       while (ptr <= p && tups[ptr].x <= pos)         update(tups[ptr].y, RANGE, 1, RANGE, 1, tups[ptr].z), ptr++;       ans = max(ans, nodes[1] - cost);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #include <unordered_map>   #include <cctype>   #include <string.h>      #define PB push_back   #define EB emplace_back    #define MP make_pair   #define endl   n    #define ll long long   #define ull unsigned long long   #define STR string   #define VEC vector<int>   #define IOS {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}   #define loop(i,a,b,c) for(ll i=a;i<b;i+=c)   #define MOD (int)1000000007   #define sp       #define pii pair<int,int>         using namespace std;   using namespace std::chrono;      /* Debugging */   template <typename T>   void printarr(T *A, int n){     for (int i = 0; i < n; i++)     {       cout<<A[i]<<   ;     }     cout<<endl;     }   template <typename T>   void arrinit(T *A, int n, T data){     for (int i = 0; i < n; i++)     {       A[i] = data;     }        }   template <typename T>   void takeinput(T *A, int n){     for(int i=0;i<n;i++){       cin>>A[i];     }   }   template <typename T>   void printcont(T A){     for(auto a: A){       cout<<a+1<<   ;     }     cout<<endl;   }   template <typename T>   T binpowmod(T a, T b, T p){     if(b==0) return 1;     if(b==1) return a;     if(b%2==0) return ((binpowmod(a,b/2,p)%p)*(binpowmod(a,b/2,p)%p))%p;     return ((a%p)*(binpowmod(a,b-1,p)%p))%p;   }   // template <typename T>   // T gcd(T a,T b){   //   if(a==0) return b;   //   if(b==0) return a;   //   if(a>b) return gcd(b,a%b);   //   return gcd(b%a,a); 1 2 3 4  => 1 2    // }      void solve (){     int n;     cin>>n;     int k = n;     vector <pii> steps{};     if(n<=8){       for (int i = 3; i < n; i++)       {           steps.PB({i,i+1});       }       while(n!=1){           steps.PB({k,2});           if(n%2==1) n = n/2 + 1;           else n/=2;       }       }     else{       for (int i = 3; i < n; i++)       {           if(i!=8)steps.PB({i,i+1});       }       while(n!=1){           steps.PB({k,8});           if(n%8!=0) n = n/8 + 1;           else n = n/8;       }       steps.PB({8,2});       steps.PB({8,2});       steps.PB({8,2});     }     cout<<steps.size()<<endl;     for (int i = 0; i < steps.size(); i++)     {         cout<<steps[i].first<<   <<steps[i].second<<endl;     }             }      int main(){       auto start = high_resolution_clock::now();        IOS       // freopen( input.txt , r ,stdin);       // freopen( output.txt , w ,stdout);       // freopen( output.txt , w ,stderr);       ll t;       cin>>t;         while(t--){         solve();       }       auto stop = high_resolution_clock::now();        auto duration = duration_cast<milliseconds>(stop - start);        // cout << Time taken :  <<duration.count() <<  milliseconds n ;       return 0;   }


#include <bits/stdc++.h>   int main() {     long long n;     scanf( %lld , &n);     if (n <= 1) {       printf( -1 );     } else {       printf( %lld %lld %lld , n, n + 1, n * (n + 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class T {    private:     long node[262145];     long low[262145];     long high[262145];     void update(long n);     long amount(long a, long b, long n, long n_a, long n_b);     long firstUp(long k, long n, long n_a, long n_b);     long firstDown(long k, long n, long n_a, long n_b);       public:     long amount(long a, long b);     long firstUp(long k);     long firstDown(long k);     void pop(long n);     void push(long n);     long size();     T();   } WaitTree, DestTree;   T::T() {     for (long i = 0; i < 262145; i++) {       low[i] = 1000000000;       high[i] = -1000000000;     }   }   long T::size() { return node[1]; }   long T::amount(long a, long b, long n, long n_a, long n_b) {     if (a > n_b || b < n_a) return 0;     if (n_a >= a && n_b <= b) return node[n];     return amount(a, b, 2 * n, n_a, (n_a + n_b) / 2) +            amount(a, b, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b);   }   long T::firstDown(long k, long n, long n_a, long n_b) {     if (node[n] == 0 || n_a > k) return -1000000000;     if (n > 131071) return n - 131071;     if (n_b > k) {       long a = firstDown(k, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b);       if (a > 0) return a;       return firstDown(k, 2 * n, n_a, (n_a + n_b) / 2);     } else       return high[n];   }   long T::firstUp(long k, long n, long n_a, long n_b) {     if (node[n] == 0 || n_b < k) return 1000000000;     if (n > 131071) return n - 131071;     if (n_a < k) {       long a = firstUp(k, 2 * n, n_a, (n_a + n_b) / 2);       if (a < 1000000000) return a;       return firstUp(k, 2 * n + 1, (n_a + n_b) / 2 + 1, n_b);     } else       return low[n];   }   long T::firstUp(long k) { return firstUp(k, 1, 1, 131071 + 1); }   long T::firstDown(long k) { return firstDown(k, 1, 1, 131071 + 1); }   long T::amount(long a, long b) { return amount(a, b, 1, 1, 131071 + 1); }   void T::update(long n) {     n /= 2;     while (n > 0) {       low[n] = (low[2 * n + 1] < low[2 * n] ? low[2 * n + 1] : low[2 * n]);       high[n] = (high[2 * n] > high[2 * n + 1] ? high[2 * n] : high[2 * n + 1]);       node[n] = node[2 * n] + node[2 * n + 1];       n /= 2;     }   }   void T::pop(long n) {     node[131071 + n]--;     if (node[131071 + n] == 0) {       low[131071 + n] = 1000000000;       high[131071 + n] = -1000000000;     }     update(131071 + n);   }   void T::push(long n) {     high[131071 + n] = n;     low[131071 + n] = n;     node[131071 + n]++;     update(131071 + n);   }   struct A {     long id;     long time, wait, dest;   };   bool operator<(const A &a, const A &b) { return a.time < b.time; }   vector<A> P(100005);   class X {    public:     long id, floor;     X(long _id, long _floor);   };   X::X(long _id, long _floor) {     id = _id;     floor = _floor;   }   vector<X> Waiting[100005];   vector<X> Dest[100005];   long long Arrive[100005];   long Arrived;   long N, M;   void in() {     scanf( %ld %ld , &N, &M);     for (long i = 0; i < N; i++) {       scanf( %ld %ld %ld , &P[i].time, &P[i].wait, &P[i].dest);       P[i].id = i;     }     sort(P.begin(), P.begin() + N);   }   void processEvent(long f, long long t, long &nextP) {     X x(0, 0);     while (P[nextP].time == t && nextP < N) {       Waiting[P[nextP].wait].push_back(X(P[nextP].id, P[nextP].dest));       WaitTree.push(P[nextP].wait);       nextP++;     }     while (Waiting[f].size() > 0) {       x = Waiting[f].back();       Dest[x.floor].push_back(X(x.id, x.floor));       WaitTree.pop(f);       DestTree.push(x.floor);       Waiting[f].pop_back();     }     while (Dest[f].size() > 0) {       x = Dest[f].back();       Arrive[x.id] = t;       Arrived++;       DestTree.pop(f);       Dest[f].pop_back();     }   }   void solve() {     const int UP = 1;     const int DOWN = 2;     int dir;     long nextMove;     long nextP = 0;     long p_up, p_down;     long f = 1;     long long t = 0;     while (Arrived < N) {       processEvent(f, t, nextP);       p_up = p_down = 0;       p_up += WaitTree.amount(f, 131071 + 1);       p_up += DestTree.amount(f, 131071 + 1);       p_down += WaitTree.amount(1, f);       p_down += DestTree.amount(1, f);       if (p_up >= p_down)         dir = UP;       else         dir = DOWN;       if (dir == UP) {         nextMove = 1000000000;         nextMove = (nextMove < WaitTree.firstUp(f) - f ? nextMove                                                        : WaitTree.firstUp(f) - f);         nextMove = (nextMove < DestTree.firstUp(f) - f ? nextMove                                                        : DestTree.firstUp(f) - f);         if (nextP < N)           nextMove =               (nextMove < P[nextP].time - t ? nextMove : P[nextP].time - t);         t += nextMove;         if (DestTree.size() > 0 || WaitTree.size() > 0) {           f += nextMove;         }       }       if (dir == DOWN) {         nextMove = 1000000000;         nextMove =             (nextMove < f - WaitTree.firstDown(f) ? nextMove                                                   : f - WaitTree.firstDown(f));         nextMove =             (nextMove < f - DestTree.firstDown(f) ? nextMove                                                   : f - DestTree.firstDown(f));         if (nextP < N)           nextMove =               (nextMove < P[nextP].time - t ? nextMove : P[nextP].time - t);         t += nextMove;         if (DestTree.size() > 0 || WaitTree.size() > 0) {           f -= nextMove;         }       }     }   }   void out() {     for (long i = 0; i < N; i++) printf( %I64d n , Arrive[i]);   }   int main() {     in();     solve();     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T a) {     return ((a < 0) ? -a : a);   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   const int INF = (int)1E9 + 7;   const long double EPS = 1E-10;   const long double PI = 3.1415926535897932384626433832795;   int n;   vector<long double> a;   bool check(const vector<long double>& a) {     if (int((a).size()) <= 1) return true;     if (fabs(a[0]) < EPS) {       for (int i = 0; i < int(int((a).size())); ++i)         if (fabs(a[i]) > EPS) return false;       return true;     }     long double b = a[1] / a[0], cur = a[0];     for (int i = 0; i < int(int((a).size())); ++i) {       if (fabs(a[i] - cur) > EPS) return false;       cur *= b;     }     return true;   }   vector<int> getz(const vector<long double>& a) {     vector<int> z(int((a).size()));     int l = 0, r = -1;     for (int i = int(1); i < int(int((a).size())); ++i) {       z[i] = i > r ? 0 : min(z[i - l], r - i + 1);       while (i + z[i] < int((a).size()) && fabs(a[z[i]] - a[i + z[i]]) < EPS)         z[i]++;       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   int main() {     cin >> n;     a.resize(n);     for (int i = 0; i < int(n); ++i) {       int x;       scanf( %d , &x);       a[i] = x;     }     if (check(a)) {       puts( 0 );       exit(0);     }     for (int i = 0; i < int(2); ++i) {       vector<long double> b = a;       b.erase(b.begin() + i);       if (check(b)) {         puts( 1 );         exit(0);       }     }     vector<long double> ok(n - 1, 0);     if (fabs(a[0]) > EPS) {       long double d = a[1] / a[0];       ok[0] = a[0], ok[1] = a[1];       for (int i = int(2); i < int(int((ok).size())); ++i) ok[i] = ok[i - 1] * d;     }     vector<long double> t1 = ok;     t1.insert(t1.end(), (a).begin(), (a).end());     vector<int> z1 = getz(t1);     reverse((ok).begin(), (ok).end());     reverse((a).begin(), (a).end());     ok.insert(ok.end(), (a).begin(), (a).end());     vector<int> z2 = getz(ok);     if (z1[n - 1] + z2[n - 1] >= n - 1)       puts( 1 );     else       puts( 2 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   const double PI = acos(-1);   const double eps = (1e-9);   const long long int INF = (1e18);   const int M = (1e9) + 7;   const int N = 2050;   const int K = 5250;   int dp[N][N];   int n, m, k;   vector<pair<int, int> > fire;   int saare[2][N];   int val[2][N];   int last[2][N];   int sz[2];   void compress(int ind, int n) {     vector<pair<int, int> > tp(n);     int i, j, r;     for (i = 0; i < n; i++) tp[i].first = saare[ind][i], tp[i].second = i;     sort(tp.begin(), tp.end());     i = 0, r = 1, j = 0;     while (i < n) {       while (j < n && tp[i].first == tp[j].first)         saare[ind][tp[j].second] = r, j++;       val[ind][r++] = tp[i].first;       if (j < n && tp[i].first + 1 < tp[j].first)         val[ind][r] = tp[i].first + 1, last[ind][r] = tp[j].first - 1, r++;       i = j;     }     sz[ind] = r;     return;   }   int build() {     int i, j, x, y, a, b;     for (i = 0; i < sz[0]; ++i) {       for (j = 0; j < sz[1]; ++j) dp[i][j] = 0;     }     for (i = 0; i < k; ++i) {       x = saare[0][i], y = saare[1][i];       a = saare[0][i + k], b = saare[1][i + k];       dp[x][y] += 1;       dp[x][b + 1] -= 1;       dp[a + 1][y] -= 1;       dp[a + 1][b + 1] += 1;     }     for (i = 1; i < sz[0]; ++i) {       for (j = 1; j < sz[1]; ++j)         dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);     }     x = n + 1, a = 0;     y = m + 1, b = 0;     for (i = 1; i < sz[0]; ++i) {       for (j = 1; j < sz[1]; ++j) {         if (dp[i][j] == 0) {           x = min(x, val[0][i]);           a = max(a, val[0][i]);           a = max(a, last[0][i]);           y = min(y, val[1][j]);           b = max(b, val[1][j]);           b = max(b, last[1][j]);         }       }     }     int z = max(0, max(a - x, b - y));     return z;   }   int check(int t) {     vector<pair<int, int> > point(2 * k);     int i, x, y, a, b;     for (i = 0; i < k; ++i) {       tie(x, y) = fire[i];       a = max(x - t, 1), b = max(y - t, 1);       point[i] = {a, b};       a = min(x + t, n), b = min(y + t, m);       point[i + k] = {a, b};     }     for (i = 0; i < 2 * k; ++i) tie(saare[0][i], saare[1][i]) = point[i];     int s = 2 * k;     saare[0][s] = 1, saare[1][s] = 1, s++;     saare[0][s] = n, saare[1][s] = m, s++;     compress(0, s);     compress(1, s);     {       string _s =  t ;       replace(_s.begin(), _s.end(),  , ,    );       stringstream _ss(_s);       istream_iterator<string> _it(_ss);       err(_it, t);     };     int z = build();     return (z <= 2 * t);   }   void solve() {     scanf( %d%d%d , &n, &m, &k);     fire.resize(k);     int i;     for (i = 0; i < k; ++i) scanf( %d%d , &fire[i].first, &fire[i].second);     int mid, l = 0, r = (max(n, m) / 2);     while (l < r) {       mid = ((l + r) >> 1);       if (check(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , l);   }   int main() {     int t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<string> str;   const string di =  .. ;   char ss[500];   int main() {     int ti;     scanf( %d , &ti);     for (int i = 0; i < ti; i++) {       scanf( %s , ss);       if (ss[0] ==  p ) {         printf( / );         for (int i = 0; i < str.size(); i++) printf( %s/ , str[i].c_str());         printf(  n );       } else {         scanf( %s , ss);         if (ss[0] ==  / ) str.clear();         char *tmp = strtok(ss,  / );         while (tmp != NULL) {           if (di == tmp)             str.pop_back();           else             str.push_back(tmp);           tmp = strtok(NULL,  / );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 100000000;   const long long MAXN = 2e6 + 20;   struct edge {     long long from, to, cost;   };   int main() {     long long i, j, k, t1, t2, t3, n, m, t;     std::ios::sync_with_stdio(0);     cin >> n >> k;     cout << (k + n - 1) / n <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, a[5002], b, c, d;     cin >> n;     cout <<  ?  <<     << 1 <<     << 2 << endl;     fflush(stdout);     cin >> b;     cout <<  ?  <<     << 2 <<     << 3 << endl;     fflush(stdout);     cin >> c;     cout <<  ?  <<     << 1 <<     << 3 << endl;     fflush(stdout);     cin >> d;     a[1] = (b + d - c) / 2;     a[2] = b - a[1];     a[3] = d - a[1];     for (i = 4; i <= n; i++) {       cout <<  ?  <<     << 1 <<     << i << endl;       fflush(stdout);       cin >> b;       a[i] = b - a[1];     }     cout <<  !  <<    ;     for (i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   const int hashnum = 3;   long long base[] = {233, 23, 97};   long long mod[] = {122420729, 1000000007, 1000000009};   int sum[maxn];   char s[maxn];   long long power[hashnum][maxn];   int n;   struct node {     long long hv[hashnum];     int pref, suf, len;   };   node zer;   inline void init() {     zer.pref = zer.suf = zer.len = 0;     for (int i = (0); i < (hashnum); ++i) zer.hv[i] = 0;     for (int i = (0); i < (hashnum); ++i) {       power[i][0] = 1;       for (int j = (1); j < (maxn); ++j)         power[i][j] = power[i][j - 1] * base[i] % mod[i];     }   }   node merge(node& a, node& b) {     node c = zer;     if (a.len == 0 && b.len == 0)       c.suf = c.pref = a.pref + b.pref;     else if (a.len == 0)       c = b, c.pref += a.pref;     else if (b.len == 0)       c = a, c.suf += b.pref;     else {       c.len = a.len + b.len + (a.suf + b.pref) % 2;       c.pref = a.pref;       c.suf = b.suf;       for (int i = (0); i < (hashnum); ++i) {         if ((a.suf + b.pref) % 2 == 1) {           c.hv[i] = a.hv[i] * power[i][b.len + 1] % mod[i];           (c.hv[i] += 2 * power[i][b.len] % mod[i]) %= mod[i];           (c.hv[i] += b.hv[i]) %= mod[i];         } else {           c.hv[i] = a.hv[i] * power[i][b.len] % mod[i];           (c.hv[i] += b.hv[i]) %= mod[i];         }       }     }     return c;   }   struct segtree {     node t[maxn << 2];     int n, ql, qr;     node ans;     void init(int n) { this->n = n; }     void maintain(int o) { t[o] = merge(t[o << 1], t[o << 1 | 1]); }     void build(int l, int r, int o) {       t[o] = zer;       if (l == r) {         if (s[l] ==  0 ) {           t[o].len++;           for (int i = (0); i < (hashnum); ++i) t[o].hv[i] = 1;         } else           t[o].suf = t[o].pref = 1;         return;       }       int mid = l + r >> 1;       build(l, mid, o << 1), build(mid + 1, r, o << 1 | 1);       maintain(o);     }     void query(int l, int r, int o) {       if (ql <= l && qr >= r)         ans = merge(ans, t[o]);       else {         int mid = l + r >> 1;         if (ql <= mid) query(l, mid, o << 1);         if (qr > mid) query(mid + 1, r, o << 1 | 1);       }     }     node Query(int l, int r) {       ans = zer;       ql = l, qr = r;       query(1, n, 1);       return ans;     }   };   segtree tree;   bool judge(node& a, node& b) {     if (a.suf % 2 != b.suf % 2 || a.pref % 2 != b.pref % 2 || a.len != b.len)       return false;     for (int i = (0); i < (hashnum); ++i)       if (a.hv[i] != b.hv[i]) return false;     return true;   }   int main(void) {     scanf( %d%s , &n, s + 1);     init();     tree.init(n);     tree.build(1, n, 1);     for (int i = (1); i <= (n); ++i) {       sum[i] = sum[i - 1];       if (s[i] ==  1 ) sum[i]++;     }     int q;     scanf( %d , &(q));     for (; q--;) {       int l1, l2, r1, r2, len;       scanf( %d%d%d , &l1, &l2, &len);       r1 = l1 + len - 1;       r2 = l2 + len - 1;       if (sum[r2] - sum[l2 - 1] != sum[r1] - sum[l1 - 1]) {         puts( No );         continue;       }       node x = tree.Query(l1, r1);       node y = tree.Query(l2, r2);       if (judge(x, y))         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Notlucky(int x) {     for (int i = x; i != 0; i /= 10) {       if (i % 10 == 8 || i % 10 == -8) return false;     }     return true;   }   int main() {     int a, b;     cin >> a;     b = a + 1;     while (Notlucky(b)) {       b++;     }     cout << b - a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   mt19937_64 rnd;   const int N = 2e5 + 5;   void tc() {     int n;     cin >> n;     vector<int> v;     int p = 1;     while (n) {       if (n % 10) {         v.push_back(n % 10 * p);       }       n /= 10;       p *= 10;     }     cout << int((v).size()) <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) tc();     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC target( avx,avx2 )   using namespace std;   using LF = double;   using LL = long long;   using basis = complex<LF>;   const LF PI = acos(-1.0l);   const int N = 125005;   vector<int> rev;   vector<basis> omega;   inline void calc_rev(int n, int log_n) {     omega.assign(n, 0);     rev.assign(n, 0);     for (int i = 0; i < n; i++) {       rev[i] = 0;       for (int j = 0; j < log_n; j++) {         if ((i >> j) & 1) rev[i] |= 1 << (log_n - j - 1);       }     }   }   inline void fft(vector<basis> &A, int n, bool invert) {     for (int i = 0; i < n; i++) {       if (i < rev[i]) swap(A[i], A[rev[i]]);     }     for (int len = 2; len <= n; len <<= 1) {       LF ang = 2 * PI / len * (invert ? -1 : +1);       int half = (len >> 1);       basis curomega(cos(ang), sin(ang));       omega[0] = basis(1, 0);       for (int i = 1; i < half; i++) omega[i] = omega[i - 1] * curomega;       for (int i = 0; i < n; i += len) {         basis t;         int pu = i, pv = i + half, pu_end = i + half, pw = 0;         for (; pu != pu_end; pu++, pv++, pw++) {           t = A[pv] * omega[pw];           A[pv] = A[pu] - t;           A[pu] += t;         }       }     }     if (invert)       for (int i = 0; i < n; i++) A[i] /= n;   }   inline void multiply(int n, vector<basis> &A, vector<basis> &B,                        vector<int> &C) {     fft(A, n, false);     fft(B, n, false);     for (int i = 0; i < n; i++) A[i] *= B[i];     fft(A, n, true);     for (int i = 0; i < n; i++) {       C[i] = (int)(A[i].real() + 0.5);     }   }   inline void solve(int n, vector<int> &coefficients_of_A,                     vector<int> &coefficients_of_B, vector<int> &result) {     vector<basis> A(n), B(n);     for (int i = 0; i < n; i++) {       A[i] = coefficients_of_A[i];       B[i] = 0;     }     for (int i = 0; i < n; i++) {       B[i] = coefficients_of_B[i];     }     vector<int> C(n);     multiply(n, A, B, C);     for (int i = 0; i < n; i++) {       int add = C[i];       result[i] += add;     }   }   inline void do_FFT(vector<int> &A, vector<int> &B, vector<int> &result) {     int n = 1, bits = 0;     while (n < 2 * A.size() || n < 2 * B.size()) {       n <<= 1, bits++;     }     result.assign(n, 0);     calc_rev(n, bits);     vector<int> tempA(A.begin(), A.end());     vector<int> tempB(B.begin(), B.end());     tempA.resize(n);     tempB.resize(n);     solve(n, tempA, tempB, result);   }   int n, m;   string S, T;   vector<int> indexes[6][2];   vector<int> graph[N][6];   int visited[6];   int dfs(int u, int v) {     int ans = 1;     visited[v] = 1;     for (auto k : graph[u][v]) {       if (!visited[k]) ans += dfs(u, k);     }     return ans;   }   int work(int curr_position) {     int ans = 0;     memset(visited, 0, sizeof(visited));     for (int i = 0; i < 6; i++) {       if (!visited[i]) ans += dfs(curr_position, i) - 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> S >> T;     int i, j;     n = S.size();     m = T.size();     for (i = 0; i <= n - 1; i++) {       indexes[S[i] -  a ][0].push_back(i);     }     for (j = 0; j <= m - 1; j++) {       indexes[T[j] -  a ][1].push_back(j);     }     for (i = 0; i <= 5; i++) {       for (j = 0; j <= 5; j++) {         if (i == j) continue;         vector<int> polynomial1(n + 1, 0), polynomial2(m, 0);         for (int x : indexes[i][0]) polynomial1[x] = 1;         for (int x : indexes[j][1]) polynomial2[m - 1 - x] = 1;         vector<int> res;         do_FFT(polynomial1, polynomial2, res);         for (int k = 0; k < n - m + 1; k++) {           if (res[m - 1 + k]) {             graph[k][i].push_back(j);             graph[k][j].push_back(i);           }         }       }     }     for (i = 0; i <= n - m; i++) {       cout << work(i) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > a[60];   int c[60], d[60], e[60];   int main() {     int i, j, k, m, n;     double w;     while (scanf( %d%lf%d , &n, &w, &m) != EOF) {       for (i = 0; i < n; i++) d[i] = m;       memset(c, 0, sizeof(c));       k = 0;       int f = 0;       for (i = 0; i < m; i++) a[i].clear();       for (i = 0; i < n; i++) {         int cnt = 0;         while (d[i] > 0) {           if (d[i] >= n - c[k]) {             a[k].push_back(make_pair(i, n - c[k]));             d[i] -= n - c[k];             c[k] = n;             k++;           } else {             a[k].push_back(make_pair(i, d[i]));             c[k] += d[i];             d[i] = 0;           }           cnt++;         }         if (cnt > 2) f = 1;       }       if (f) {         puts( NO );         continue;       }       puts( YES );       for (i = 0; i < m; i++) {         for (j = 0; j < a[i].size(); j++) {           printf( %d %.10lf%c , a[i][j].first + 1, a[i][j].second * w / m,                  j < a[i].size() - 1 ?     :   n );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long N, i, j, k, a, b;   long long gcd(long long a, long long b) {     long long t;     while (b > 0) {       t = b;       b = a % b;       a = t;     }     return a;   }   long long lcm(long long a, long long b, long long c) {     long long d = a * b / gcd(a, b);     return c * d / gcd(c, d);   }   int main() {     scanf( %I64d , &N);     for (i = max(1ll, N - 100); i <= N; i++) {       for (j = i; j <= N; j++) {         for (k = j; k <= N; k++) {           b = lcm(i, j, k);           if (b > a) a = b;         }       }     }     printf( %I64d n , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int INF = 0x3f3f3f3f;   int vis[105];   int main() {     string s;     cin >> s;     int len = s.size();     int ans = 0;     for (int i = 0; i < len - 1; i++) {       if (s[i] ==  V  && s[i + 1] ==  K ) ans++;     }     for (int i = 0; i < len; i++) {       char ch = s[i];       s[i] =  V ;       int temp = 0;       for (int j = 0; j < len - 1; j++) {         if (s[j] ==  V  && s[j + 1] ==  K ) temp++;       }       s[i] = ch;       ans = max(ans, temp);     }     for (int i = 0; i < len; i++) {       char ch = s[i];       s[i] =  K ;       int temp = 0;       for (int j = 0; j < len - 1; j++) {         if (s[j] ==  V  && s[j + 1] ==  K ) temp++;       }       s[i] = ch;       ans = max(ans, temp);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, q, a[13][110005], id;   bitset<4100> s[110005];   inline int read() {     int ret = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (isdigit(ch)) {       ret = (ret << 3) + (ret << 1) + (ch ^ 48);       ch = getchar();     }     return ret * ff;   }   signed main() {     m = read(), n = read(), q = read();     id = n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) a[i][j] = read();       for (int j = 0; j < (1 << n); j++)         if (j & (1 << (i - 1))) s[i][j] = 1;     }     for (int que = 1; que <= q; que++) {       int opt = read(), x = read(), y = read();       if (opt == 1) {         s[++id] = s[x] & s[y];         continue;       }       if (opt == 2) {         s[++id] = s[x] | s[y];         continue;       }       if (opt == 3) {         vector<pair<int, int> > v;         for (int i = 1; i <= n; i++) v.push_back(make_pair(a[i][y], i));         sort(v.begin(), v.end());         int sum = 0;         for (int i = 0; i < n; i++) {           sum |= (1 << (v[i].second - 1));           if (s[x][sum]) {             printf( %d n , v[i].first);             break;           }         }         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(vector<long long int> &a, int n) {     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];   }   bool fine = 0;   void solve() {     int x, y, z;     cin >> x >> y >> z;     vector<int> a(x), b(y), c(z);     for (int i = 0; i < x; i++) cin >> a[i];     for (int i = 0; i < y; i++) cin >> b[i];     for (int i = 0; i < z; i++) cin >> c[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     reverse(a.begin(), a.end());     reverse(c.begin(), c.end());     reverse(b.begin(), b.end());     long long int ans = 0;     long long int dp[x + 1][y + 1][z + 1];     memset(dp, 0, sizeof(dp));     for (int i = 0; i < x + 1; i++) {       for (int j = 0; j < y + 1; j++) {         for (int k = 0; k < z + 1; k++) {           if ((i + j + k) < 2 || (i + j + k) & 1) continue;           if (i && j)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j - 1][k] + a[i - 1] * b[j - 1]);           if (i && k)             dp[i][j][k] =                 max(dp[i][j][k], dp[i - 1][j][k - 1] + a[i - 1] * c[k - 1]);           if (k && j)             dp[i][j][k] =                 max(dp[i][j][k], dp[i][j - 1][k - 1] + b[j - 1] * c[k - 1]);           ans = max(dp[i][j][k], ans);         }       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     if (fine) {       int t;       cin >> t;       while (t--) {         solve();       }     } else       solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5 + 10;   struct node {     int l, r, id;     friend bool operator<(node A, node B) {       return A.r == B.r ? A.l < B.l : A.r < B.r;     }   };   node a[N];   bool add[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ll n, m;     ;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i].l >> a[i].r;       a[i].id = i;     }     sort(a + 1, a + 1 + n);     multiset<int> b;     for (int i = 0; i < m; ++i) b.insert(0);     for (int i = 1; i <= n; ++i) {       auto p = b.lower_bound(a[i].l);       if (p != b.begin()) {         add[a[i].id] = 1;         --p;         b.erase(p);         b.insert(a[i].r);       }     }     vector<int> ans;     for (int i = 1; i <= n; ++i)       if (!add[i]) ans.emplace_back(i);     cout << ans.size() << endl;     for (auto i : ans) cout << i <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e3 + 100;   const long long inf = 0x3f3f3f3f;   const long long iinf = 1 << 30;   const long long linf = 2e18;   const long long mod = 998244353;   const double eps = 1e-7;   template <class T = long long>   T chmin(T &a, T b) {     return a = min(a, b);   }   template <class T = long long>   T chmax(T &a, T b) {     return a = max(a, b);   }   template <class T = long long>   inline void red(T &x) {     x -= mod, x += x >> 31 & mod;   }   template <class T = long long>   T read() {     T f = 1, a = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       a = (a << 3) + (a << 1) + ch -  0 ;       ch = getchar();     }     return a * f;   }   long long n, m, ans;   char s[maxn], t[maxn];   long long f[maxn][maxn];   signed main() {     scanf( %s %s , s + 1, t + 1);     long long n = strlen(s + 1), m = strlen(t + 1);     for (long long i = (1); i <= (n); ++i) f[i][i] = 2 * (i > m || s[1] == t[i]);     for (long long i = (2); i <= (n); ++i)       for (long long l = (1); l <= (n - i + 1); ++l) {         long long r = l + i - 1;         if (l > m || s[i] == t[l]) red(f[l][r] += f[l + 1][r]);         if (r > m || s[i] == t[r]) red(f[l][r] += f[l][r - 1]);       }     for (long long i = (m); i <= (n); ++i) red(ans += f[1][i]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -funroll-loops )   #pragma GCC target( avx,sse4 )   using namespace std;   const int P = 1e9 + 7, i2 = P / 2 + 1, i6 = P / 6 + 1, N = 1e6 + 5;   long long n, m;   int r, f1[N], f2[N], f3[N];   int main() {     scanf( %lld , &n);     long long g1 = (n + 1) % P, g3 = (long long)g1 * g1 % P * g1 % P;     while ((long long)m * m <= n) m++;     m--;     for (register int i = 1, _lim_ = m; i <= _lim_; i++) {       long long v1 = (long long)i * i % P, v2 = (long long)v1 * v1 % P,                 v3 = (long long)v1 * v2 % P;       f1[i] = (f1[i - 1] + v1) % P;       f2[i] = (f2[i - 1] + v2) % P;       f3[i] = (f3[i - 1] + v3) % P;     }     for (register int x = 0, _lim_ = m; x <= _lim_; x++) {       long long s = 0, v1 = (long long)x * x % P, v2 = (long long)v1 * v1 % P,                 v3 = (long long)v1 * v2 % P;       while ((long long)x * x + (long long)m * m > n) m--;       s = ((g3 + g1 * (3 * v1 - 3 * v2 - 1) + v1 - v2 * 3 + v3 * 2) % P *                (m + 1) % P +            (3 * g1 + 1 - (3 * g1 + 3) * v1 * 2 + v2 * 6) % P * f1[m] % P +            3 * (v1 * 2 - g1 - 1) * f2[m] + 2 * f3[m]) %           P;       s = (s * 2 - g3 + g1 - v1 * (3 * g1 + 1) + v2 * (3 * g1 + 3) - v3 * 2) % P;       r = (r + s * (1 << (x > 0))) % P;     }     r = (long long)r * i6 % P;     if (r < 0) r += P;     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, co[200010], to[200010];   int cnt = 0;   int dfn[200010], low[200010];   int scc_cnt;   int sccno[200010];   int nt[200010], va[200010];   stack<int> S;   void dfs(int u) {     dfn[u] = low[u] = ++cnt;     S.push(u);     int v = to[u];     if (dfn[v] == 0) {       dfs(v);       low[u] = min(low[u], low[v]);     } else if (!sccno[v]) {       low[u] = min(low[u], dfn[v]);     }     int MMM = 0x3f3f3f3f;     if (low[u] == dfn[u]) {       ++scc_cnt;       while (true) {         int x = S.top();         S.pop();         sccno[x] = scc_cnt;         MMM = min(MMM, co[x]);         if (x == u) {           break;         }       }       va[scc_cnt] = MMM;     }   }   int num[200010];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> co[i];     for (int i = 1; i <= n; i++) cin >> to[i];     memset(dfn, 0, sizeof(dfn));     cnt = scc_cnt = 0;     for (int i = 1; i <= n; ++i) {       if (!dfn[i]) {         dfs(i);       }     }     for (int u = 1; u <= n; ++u) {       int v = to[u];       if (sccno[u] != sccno[v]) {         nt[sccno[u]] = sccno[v];         num[sccno[u]]++;       }     }     queue<int> q;     int ans = 0;     for (int i = 1; i <= scc_cnt; i++) {       if (num[i] == 0) {         ans += va[i];       }     }     cout << ans << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   char s[N], t[N];   int n, m;   int ch[N][26];   int lps[N];   void calcLps() {     memset(lps, 0, sizeof(lps));     int i = 1;     int len = 0;     lps[0] = 0;     while (i < m) {       if (t[i + 1] == t[len + 1]) {         len++;         lps[i] = len;         i++;       } else {         if (len == 0) {           lps[i] = 0;           i++;         } else {           len = lps[len - 1];         }       }     }   }   int main() {     scanf( %s , s + 1);     scanf( %s , t + 1);     n = strlen(s + 1), m = strlen(t + 1);     for (int i = 1; i <= m; i++) ch[i - 1][t[i] -  a ] = i;     calcLps();     for (int i = 1; i <= m; i++) {       for (int j = 0; j < 26; j++) {         if (!ch[i][j]) {           ch[i][j] = ch[lps[i - 1]][j];         }       }     }     vector<vector<int> > dp(n + 1, vector<int>(m + 1, -1));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= m; j++) {         if (dp[i][j] == -1) continue;         if (s[i + 1] ==  ? ) {           for (int c = 0; c < 26; c++) {             dp[i + 1][ch[j][c]] =                 max(dp[i + 1][ch[j][c]], dp[i][j] + (ch[j][c] == m));           }         } else {           int c = s[i + 1] -  a ;           dp[i + 1][ch[j][c]] =               max(dp[i + 1][ch[j][c]], dp[i][j] + (ch[j][c] == m));         }       }     }     int ans = 0;     for (int i = 0; i <= m; i++) {       ans = max(ans, dp[n][i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 107;   int n, k;   int f[N][N];   int main() {     int i, j, tmp;     bool ok = 0;     cin >> k;     f[1][2] = f[2][1] = 1;     tmp = 0;     for (i = 3; i <= 100; i++) {       f[1][i] = f[i][1] = 1;       for (j = 2; j < i; j++) {         if (tmp + j - 1 > k) break;         tmp += j - 1;         f[i][j] = f[j][i] = 1;         if (tmp == k) {           ok = 1;           break;         }       }       if (ok) break;     }     cout << i << endl;     k = i;     for (i = 1; i <= k; i++) {       for (j = 1; j < k; j++) {         cout << f[i][j];       }       cout << f[i][k] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100500;   int n, m;   int a[30];   string s, t;   char ans[5500];   void po_poryadky(int x) {     for (int i = x; i < n; i++) {       for (int j = 0; j < 30; j++)         if (a[j]) {           ans[i] = (char)( a  + j);           a[j]--;           break;         }     }   }   void ubiraem(int x) {     for (int i = x; i >= 0; i--) {       int num = ans[i] -  a ;       a[num]++;       for (int j = num + 1; j < 30; j++)         if (a[j]) {           ans[i] = (char)( a  + j);           a[j]--;           po_poryadky(i + 1);           return;         }     }     cout << -1;     exit(0);   }   void v_roven() {     for (int i = 0; i < m; i++) {       int num = t[i] -  a ;       if (a[num] != 0) {         ans[i] = t[i];         a[num]--;         continue;       }       for (int j = num + 1; j < 30; j++)         if (a[j]) {           a[j]--;           ans[i] = (char)( a  + j);           po_poryadky(i + 1);           return;         }       ubiraem(i - 1);       return;     }     if (n == m)       ubiraem(m - 1);     else       po_poryadky(m);   }   int main() {     cin >> s >> t;     n = s.size();     m = t.size();     for (int i = 0; i < n; i++) a[(int)(s[i] -  a )]++;     v_roven();     ans[n] =   0 ;     cout << ans;     return 0;   }