#include <bits/stdc++.h>   using namespace std;   const long long FASTIO = []() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     return 0;   }();   long long n;   vector<vector<long long>> ans;   long long ask(long long x1, long long y1, long long x2, long long y2) {     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;     cout.flush();     long long c;     cin >> c;     if (c == -1) {       while (1) {       }     }     return c;   }   void bfs(long long x, long long y) {     vector<vector<long long>> used(n + 5, vector<long long>(n + 5, true));     vector<long long> v1 = {2, 1, 0, 0, -1, -2};     vector<long long> v2 = {0, 1, 2, -2, -1, 0};     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         used[i][j] = false;       }     }     queue<pair<long long, long long>> q;     q.push({x, y});     used[x][y] = true;     while (!q.empty()) {       long long X = q.front().first;       long long Y = q.front().second;       q.pop();       for (long long i = 0; i < 6; i++) {         if (X + v1[i] > 0 && Y + v2[i] > 0 && !used[X + v1[i]][Y + v2[i]]) {           pair<long long, long long> a = {X, Y}, b = {X + v1[i], Y + v2[i]};           if (v1[i] < 0 || v2[i] < 0) {             swap(a, b);           }           if (b != pair<long long, long long>{n, n}) {             bool t = ask(a.first, a.second, b.first, b.second);             if (t) {               ans[X + v1[i]][Y + v2[i]] = ans[X][Y];             } else {               ans[X + v1[i]][Y + v2[i]] = !ans[X][Y];             }           }           used[X + v1[i]][Y + v2[i]] = true;           q.push({X + v1[i], Y + v2[i]});         }       }     }   }   signed main() {     cin >> n;     ans.resize(n + 10, vector<long long>(n + 10, -1));     ans[1][1] = 1;     ans[n][n] = 0;     bfs(1, 1);     long long p = 1;     while (ans[p][p] == ans[p + 2][p + 2]) {       ++p;     }     if (ask(p, p, p + 2, p + 1)) {       ans[p + 2][p + 1] = ans[p][p];       bfs(p + 2, p + 1);     } else if (ask(p + 1, p, p + 2, p + 2)) {       ans[p + 1][p] = ans[p + 2][p + 2];       bfs(p + 1, p);     } else {       if (ans[p + 2][p] == 1) {         ans[p + 2][p + 1] = 0;         bfs(p + 2, p + 1);       } else {         ans[p + 1][p] = 1;         bfs(p + 1, p);       }     }     cout <<  ! n ;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cout << ans[i][j];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l[2005], r[2005], t, k;     cin >> t;     while (t) {       int q = 0, next = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> l[i] >> r[i];         if (i == 0) {           next = l[i] + 1;           cout << l[i] <<    ;           continue;         }         if (r[i] < next) {           cout << 0 <<    ;         } else if (l[i] <= next) {           cout << next <<    ;           next++;         } else {           cout << l[i] <<    ;           next = l[i] + 1;         }       }       cout << endl;       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[500005], b[500005];   char s[500005];   int res = 1e9, xx, yy;   int calc2(int x, int y) {     if (x == 0 && y == 0) return 1000000000;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (x <= a[i] && y <= b[i])         ans = max(ans, max(a[i] - x, b[i] - y));       else if (x <= a[i] || y <= b[i])         ans = max(ans, abs(a[i] - x) + abs(b[i] - y));       else         ans = max(ans, max(x - a[i], y - b[i]));     }     if (ans < res) {       res = ans;       xx = x, yy = y;     }     return ans;   }   int calc1(int x) {     int l = 0, r = 500000;     if (x == 0) l = 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (calc2(x, mid) < calc2(x, mid + 1))         r = mid - 1;       else         l = mid + 1;     }     return min(calc2(x, l), calc2(x, r));   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       int x = (int)strlen(s + 1);       for (int j = 1; j <= x; j++) {         if (s[j] ==  N )           a[i]++;         else           b[i]++;       }     }     int l = 0, r = 500000;     while (l <= r) {       int mid = (l + r) >> 1;       int v1 = calc1(mid), v2 = calc1(mid + 1);       if (v1 < v2)         r = mid - 1;       else if (v1 > v2)         l = mid + 1;       else {         int v3 = calc1(mid + 2);         if (v1 < v3)           r = mid - 1;         else if (v1 > v3)           l = mid + 1;         else           break;       }     }     printf( %d n , res);     for (int i = 1; i <= xx; i++) putchar( N );     for (int i = 1; i <= yy; i++) putchar( B );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, num, l, r;     string str, res;     cin >> n;     l = 1e9;     l = l * (-2);     r = 1e9;     r = r * (2);     while (n--) {       cin >> str >> num >> res;       if (str ==  > ) {         if (res ==  Y )           l = max(l, num + 1);         else           r = min(r, num);       } else if (str ==  >= ) {         if (res ==  Y )           l = max(l, num);         else           r = min(r, num - 1);       } else if (str ==  < ) {         if (res ==  Y )           r = min(r, num - 1);         else           l = max(l, num);       } else {         if (res ==  Y )           r = min(r, num);         else           l = max(l, num + 1);       }     }     if (l > r)       cout <<  Impossible ;     else       cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<1005> b[1005];   int n, m;   bool ok2(int r, int c) {     if (r + 2 > n || c + 2 > n) return false;     for (int i = r; i < r + 3; i++)       for (int j = c; j < c + 3; j++) {         if (!b[i].test(j)) return false;       }     return true;   }   bool ok(int r, int c) {     if (n < 3) return false;     for (int i = r - 2; i <= r; i++) {       if (i <= 0) continue;       for (int j = c - 2; j <= c; j++) {         if (j <= 0) continue;         if (ok2(i, j)) return true;       }     }     return false;   }   int main() {     int r, c;     bool bOK = false;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &r, &c);       b[r].set(c);       if (ok(r, c)) {         bOK = true;         printf( %d n , i);         break;       }     }     if (!bOK) printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   vector<int> colors[100013];   unordered_map<int, vector<int> > adj[100013];   unordered_map<int, int> p[100013];   unordered_map<int, int> h[100013];   pair<int, int> visited[100013];   unordered_map<int, int> precalc[100013];   int BIG = 200;   int findSet(int x, int c) {     return p[x][c] == x ? x : p[x][c] = findSet(p[x][c], c);   }   void mergeSet(int a, int b, int c) {     int r1 = findSet(a, c), r2 = findSet(b, c);     if (r1 != r2) {       if (h[r1][c] < h[r2][c])         p[r1][c] = r2;       else if (h[r1][c] > h[r2][c])         p[r2][c] = r1;       else         p[r1][c] = r2, h[r2][c] += 1;     }   }   bool sameSet(int a, int b, int c) { return findSet(a, c) == findSet(b, c); }   void dfs(int x, int c, int start) {     visited[x] = make_pair(start + 1, c);     precalc[start][x] += 1;     for (int i = 0; i < adj[x][c].size(); i++)       if (visited[adj[x][c][i]] != make_pair(start + 1, c))         dfs(adj[x][c][i], c, start);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a -= 1;       b -= 1;       if (!p[a].count(c)) p[a][c] = a, h[a][c] = 0, colors[a].push_back(c);       if (!p[b].count(c)) p[b][c] = b, h[b][c] = 0, colors[b].push_back(c);       mergeSet(a, b, c);       adj[a][c].push_back(b);       adj[b][c].push_back(a);     }     for (int i = 0; i < n; i++)       if (colors[i].size() >= BIG)         for (int j = 0; j < colors[i].size(); j++) dfs(i, colors[i][j], i);     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int u, v;       scanf( %d%d , &u, &v);       u -= 1;       v -= 1;       if (colors[u].size() >= BIG)         printf( %d n , precalc[u][v]);       else if (colors[v].size() >= BIG)         printf( %d n , precalc[v][u]);       else {         int ans = 0;         if (colors[u].size() < colors[v].size()) {           for (int i = 0; i < colors[u].size(); i++)             if (p[v].count(colors[u][i]) && sameSet(u, v, colors[u][i])) ans += 1;         } else           for (int i = 0; i < colors[v].size(); i++)             if (p[u].count(colors[v][i]) && sameSet(u, v, colors[v][i])) ans += 1;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, a, b;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       cout << a + b << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];       }       long long b[n];       for (long long i = 0; i < n; i++) {         if (i % 2) {           if (a[i] >= 0)             b[i] = a[i];           else             b[i] = -a[i];         } else {           if (a[i] <= 0)             b[i] = a[i];           else             b[i] = -a[i];         }         cout << b[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j;     int a[110][110];     long long ans[150];     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++)         for (j = 1; j <= n; j++) scanf( %d , &a[i][j]);       memset(ans, 0, sizeof(ans));       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           if (i == j) continue;           if (a[i][j] == -1) continue;           ans[i] = ans[i] | a[i][j];         }       }       for (i = 1; i <= n; i++)         if (i == 1)           printf( %I64d , ans[i]);         else           printf(  %I64d , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, i, sum = 0, k, l = 10000000000;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a;       sum += a;       if (a % 2) l = min(l, a);     }     if (sum % 2 == 1) sum -= l;     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long q, t;   bool f(long long x) {     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin >> q;     while (q--) {       long long ans = 0;       cin >> t;       {         if (t == 2) {           cout << -1 << endl;           continue;         }         if (t == 9) {           cout << 1 << endl;           continue;         }         if (t % 2 == 1) {           t -= 9;           if (t < 4) {             cout << -1 << endl;             continue;           } else             ans++;         }         if (t % 4 == 0)           cout << t / 4 + ans << endl;         else if (t % 4 == 2)           cout << t / 4 + ans << endl;         else if (t % 6 == 0)           cout << t / 6 + ans << endl;         else if (t % 6 == 4)           cout << t / 6 + 1 + ans << endl;         else           cout << 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 200005;   int v[maxn], fa[maxn], ans[maxn], num[maxn];   int n, m;   int findset(int x) {     if (fa[x] != x) {       fa[x] = findset(fa[x]);     }     return fa[x];   }   void _union(int x, int y) {     int p = findset(x);     int q = findset(y);     if (p != q) {       fa[p] = q;     }   }   int main() {     int a, x, y;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i]);       num[i] = v[i];       fa[i] = i;     }     fa[n + 1] = n + 1;     scanf( %d , &m);     while (m--) {       scanf( %d , &a);       if (a == 1) {         scanf( %d%d , &x, &y);         while (y > 0) {           x = findset(x);           if (x == n + 1) break;           if (num[x] > y) {             ans[x] += y;             num[x] -= y;             y = 0;           } else {             y -= num[x];             ans[x] = v[x];             num[x] = 0;             _union(x, x + 1);           }         }       } else if (a == 2) {         scanf( %d , &x);         printf( %d n , ans[x]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s;     bool f = 0;     long last = -1, c = 0;     long ans = 0;     for (register int i = 0; i < s.length(); i++) {       if (s[i] ==  F ) {         if (last == -1) {           last = i;         } else {           last = max(i - c, (last == 0) ? 0 : last + 1);         }         ans = max(ans, last);         c++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ara[100005], i, j, k, ind, mx, sum, ans, ans1;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> ara[i];     }     for (i = 0; i < n; i++) {       if (ara[i] >= k) {         k = ara[i];         ind = i;       }     }     for (i = 0; i < n; i++) {       if (i != ind) {         sum += ara[i];       }     }     if (k >= sum)       ans = k - sum + 1;     else       ans = sum - k + 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(unsigned long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (unsigned long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int exp(long long int value, long long int power) {     long long int result = 1;     while (power > 0) {       if (power & 1LL) {         result *= value;         result %= 1000000007;       }       value *= value;       value %= 1000000007;       power /= 2LL;     }     return result;   }   long long int lcm(long long n1, long long n2) {     long long max = (n1 > n2) ? n1 : n2;     do {       if (max % n1 == 0 && max % n2 == 0) {         return max;       } else         ++max;     } while (true);   }   int isprime(long long n) {     if (n <= 3) return 1;     if (n % 2 == 0 || n % 3 == 0) return 0;     for (long long i = 5; i * i <= n; i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return 0;     }     return 1;   }   long long a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int f, cnt, len, p, q, r, t, i, j, k, l, n, m, x, y, z, b, c, s;     cin >> n;     n -= 10;     x = 0;     if (n == 1) x = 4;     if (n == 2) x = 4;     if (n == 3) x = 4;     if (n == 4) x = 4;     if (n == 5) x = 4;     if (n == 6) x = 4;     if (n == 7) x = 4;     if (n == 8) x = 4;     if (n == 9) x = 4;     if (n == 10) x = 15;     if (n == 11) x = 4;     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> m;   int main() {     int n, ans = 0;     string str;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> str;       m[str]++;       ans = max(ans, m[str]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct pos {     long long x, y;     bool operator<(const pos &p) const {       if (x != p.x) return x < p.x;       return y < p.y;     }   } A[200005], stk[200005];   bool check(pos a, pos b, pos c) {     return (c.y - a.y) * (b.x - c.x) <= (b.y - c.y) * (c.x - a.x);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       y -= x * x, A[i] = (pos){x, y};     }     sort(A + 1, A + n + 1);     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (i != n && A[i].x == A[i + 1].x) continue;       while (cnt > 1 && check(stk[cnt - 1], A[i], stk[cnt])) cnt--;       stk[++cnt] = A[i];     }     printf( %d n , cnt - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct fast_ios {     fast_ios() {       cin.tie(0);       ios::sync_with_stdio(false);       cout << fixed << setprecision(20);     };   } fast_ios_;   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (auto &x : v) is >> x;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, vector<T> &v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i];       if (i != v.size() - 1) cout << endl;     };     return os;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, pair<T1, T2> p) {     cout <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename T>   void Out(T x) {     cout << x << endl;   }   template <typename T1, typename T2>   void chOut(bool f, T1 y, T2 n) {     if (f)       Out(y);     else       Out(n);   }   using vec = vector<long long>;   using mat = vector<vec>;   using Pii = pair<long long, long long>;   using v_bool = vector<bool>;   using v_Pii = vector<Pii>;   long long dx[4] = {1, 0, -1, 0};   long long dy[4] = {0, 1, 0, -1};   const long long mod = 1000000007;   void imp() {     Out( Not unique );     exit(0);   }   signed main() {     long long n, m;     cin >> n >> m;     vector<string> s(n);     cin >> s;     queue<Pii> que;     long long S = 0;     for (long long i = (0); i < (n); i++)       for (long long j = (0); j < (m); j++)         if (s[i][j] ==  . ) {           S++;           long long cnt = 0;           for (long long k = (0); k < (4); k++) {             long long x = i + dx[k], y = j + dy[k];             if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) cnt++;           }           if (cnt == 1) que.push(Pii(i, j));         }     while (!que.empty()) {       long long i = que.front().first, j = que.front().second;       que.pop();       if (s[i][j] !=  . ) continue;       long long k0 = -1;       for (long long k = (0); k < (4); k++) {         long long x = i + dx[k], y = j + dy[k];         if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) {           k0 = k;           break;         }       }       if (k0 == -1) imp();       long long i2 = i + dx[k0], j2 = j + dy[k0];       if (k0 == 0)         s[i][j] =  ^ , s[i2][j2] =  v ;       else if (k0 == 1)         s[i][j] =  < , s[i2][j2] =  > ;       else if (k0 == 2)         s[i][j] =  v , s[i2][j2] =  ^ ;       else if (k0 == 3)         s[i][j] =  > , s[i2][j2] =  < ;       S -= 2;       for (long long k = (0); k < (4); k++) {         long long i3 = i2 + dx[k], j3 = j2 + dy[k];         if (i3 >= 0 && i3 < n && j3 >= 0 && j3 < m && s[i3][j3] ==  . ) {           long long cnt = 0;           for (long long k3 = (0); k3 < (4); k3++) {             long long x = i3 + dx[k3], y = j3 + dy[k3];             if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) cnt++;           }           if (cnt == 1) que.push(Pii(i3, j3));         }       }     }     if (S != 0)       imp();     else       Out(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b[101];   int main() {     int n, x;     cin >> n >> x;     int a[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]]++;     }     int t = 0;     for (int i = 0; i < x; i++) {       if (b[i] == 0) {         t++;       }     }     if (b[x] == 1) t++;     cout << t;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t;   int data[105][3];   bitset<50> mark;   set<pair<long long, long long> > ss;   struct Node {     pair<long long, long long> g;     void reset() { g.first = g.second = 0; }     void set(int x) {       if (x < 50)         g.first |= 1ll << x;       else         g.second |= 1ll << (x - 50);     }     void reset(int x) {       if (x < 50)         g.first &= (-1ll) ^ (1ll << x);       else         g.second |= (-1ll) ^ (1ll << (x - 50));     }     bool test(int x) {       if (x < 50)         return (g.first & (1ll << x));       else         return (g.second & (1ll << (x - 50)));     }     int key;     friend bool operator<(const Node &a, const Node &b) { return a.key > b.key; }   } tmp;   priority_queue<Node> que;   int main() {     scanf( %d%d%d , &n, &m, &t);     for (int i = 0; i < m; i++)       scanf( %d%d%d , &data[i][0], &data[i][1], &data[i][2]);     tmp.reset();     tmp.key = 0;     que.push(tmp);     int ans, tt = 0;     while (t--) {       if (que.empty()) {         ans = -1;         break;       }       tmp = que.top();       que.pop();       ans = tmp.key;       mark.reset();       for (int i = 0; i < m; i++)         if (tmp.test(i)) {           mark.set(data[i][0]), mark.set(data[i][1] + n);         }       for (int i = 0; i < m; i++)         if (!mark.test(data[i][0]) && !mark.test(data[i][1] + n)) {           tmp.set(i);           tmp.key += data[i][2];           if (ss.find(tmp.g) == ss.end()) {             ss.insert(tmp.g);             que.push(tmp);           }           tmp.key -= data[i][2];           tmp.reset(i);         }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int z = N * 32;   int n, a[N], f[N], rt;   int pool[z], tp, cnt, ch[z][2];   long long ans;   int fa(int x) {     if (x == f[x]) return x;     return f[x] = fa(f[x]);   }   void uni(int x, int y) {     x = fa(x), y = fa(y);     if (x == y) return;     f[x] = y;   }   int newnode() {     if (!tp) return ++cnt;     return pool[tp--];   }   void ins(int v) {     int no = rt, x;     for (register int i = 30; i >= 0; --i) {       if (v & (1 << i))         x = 1;       else         x = 0;       if (!ch[no][x]) ch[no][x] = newnode();       no = ch[no][x];     }   }   void clr(int x) {     if (ch[x][0]) clr(ch[x][0]);     if (ch[x][1]) clr(ch[x][1]);     pool[++tp] = x;     ch[x][0] = ch[x][1] = 0;   }   int find_min(int v) {     int no = rt, ans = 0, x;     for (register int i = 30; i >= 0; --i) {       if (v & (1 << i))         x = 1;       else         x = 0;       if (!ch[no][x])         ans = ans * 2 + 1, no = ch[no][x ^ 1];       else         ans = ans * 2, no = ch[no][x];     }     return ans;   }   void solve(vector<int> x, int d) {     int s = x.size();     if (s <= 1) return;     if (d == -1) {       int no = x[0];       for (register int i = 1; i < s; ++i) {         uni(no, x[i]);         no = x[i];       }       return;     }     vector<int> l, r;     int no;     for (register int i = 0; i < s; ++i) {       no = x[i];       if (a[no] & (1 << d))         l.push_back(no);       else         r.push_back(no);     }     solve(l, d - 1);     solve(r, d - 1);     int sl = l.size(), sr = r.size();     if (sl == 0 || sr == 0) return;     int q = (1 << d) - 1;     rt = newnode();     for (register int i = 0; i < sl; ++i) {       no = l[i];       ins(a[no] & q);     }     int f = a[l[0]] ^ a[r[0]];     for (register int i = 0; i < sr; ++i) {       no = r[i];       f = min(f, find_min(a[no] & q));     }     uni(l[0], r[0]);     clr(rt);     ans += f + (1 << d);   }   int main() {     scanf( %d , &n);     vector<int> c;     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       c.push_back(i);     }     solve(c, 29);     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, l;   int main() {     int i, n;     scanf( %d , &n);     getchar();     char ch[1000];     scanf( %s , ch);     for (i = 0; i < n; ++i) {       if (ch[i] ==  0 )         k++;       else         l++;     }     if (n % 2 == 1 || k != l) {       printf( 1 n%s n , ch);       return 0;     }     cout << 2 << endl;     for (i = 0; i < n; ++i) {       printf( %c , ch[i]);       if (ch[i] ==  0 )         k--;       else         l--;       if (k == 0 || l == 0) break;     }     i++;     cout <<    ;     for (int j = i; j < n; ++j) printf( %c , ch[j]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, A[300005], fix[300005], fix1[300005], B[300005], C[300005];   long long BITree[900005], BITree1[900005];   long long getSum(long long index) {     long long sum = 0;     index = index + 1;     while (index > 0) {       sum += BITree[index];       index -= index & (-index);     }     return sum;   }   void updateBIT(long long index, long long val) {     index = index + 1;     while (index <= n + 10) {       BITree[index] += val;       index += index & (-index);     }   }   long long getSum1(long long index) {     long long sum = 0;     index = index + 1;     while (index > 0) {       sum += BITree1[index];       index -= index & (-index);     }     return sum;   }   void updateBIT1(long long index, long long val) {     index = index + 1;     while (index <= m + 10) {       BITree1[index] += val;       index += index & (-index);     }   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       cin >> A[i];       if (fix[A[i]] == 0) updateBIT(A[i], 1);       fix[A[i]] = 1;       if (C[A[i]] != 0) {         C[A[i]] = max(C[A[i]], A[i] - fix1[A[i]] - 1 + 1);         C[A[i]] = max(C[A[i]], getSum1(i - 1) - getSum1(fix1[A[i]]) + 1);         updateBIT1(fix1[A[i]], -1);         updateBIT1(i, 1);       } else {         C[A[i]] = A[i] + getSum(n) - getSum(A[i]);         updateBIT1(i, 1);       }       fix1[A[i]] = i;     }     for (long long i = n; i >= 1; i--) {       B[i] = B[i + 1] + fix[i];     }     for (long long i = 1; i <= n; i++) {       if (fix[i] == 0) {         cout << i <<     << i + B[i];       } else {         cout << 1 <<     << max(C[i], getSum1(m) - getSum1(fix1[i]) + 1);       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inv = numeric_limits<int>::max();   const int minv = numeric_limits<int>::min();   const int max_n = 500010;   int n;   int a[max_n];   int b[max_n] = {0};   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     int c = 0;     for (int i = n - 2; i >= 0; --i) {       if (i > 0 and a[i - 1] != a[i] and a[i] != a[i + 1])         ++c;       else {         b[i + 1] = c;         c = 0;       }     }     int res = 0;     for (int i = 1; i <= n - 2; ++i)       if (b[i] > 0) {         res = max(res, (b[i] + 1) / 2);         if (b[i] & 1)           for (int j = i; j < i + b[i]; ++j) a[j] = a[i - 1];         else {           for (int j = i; j < i + b[i] / 2; ++j) a[j] = a[i - 1];           for (int j = i + b[i] / 2; j < i + b[i]; ++j) a[j] = a[i + b[i]];         }       }     printf( %d n , res);     for (int i = 0; i < n; ++i) printf( %d  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     long long from, to, w;     edge(int from, int to, long long w) : from(from), to(to), w(w) {}     bool operator<(const edge& e) const { return ((w > e.w)); }   };   void O_o() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   bool valid(long long i, long long j, long long n, long long m) {     return (i >= 0 && i < n && j >= 0 && j < m);   }   long long n, k, a, b;   vector<long long> vec;   bool ok(long long x) {     long long cnt = 999999999;     multimap<int, pair<int, int> > mm;     for (int i = x; i < n + 1; i++) {       cnt = x - vec[i] + vec[i - x];       if (cnt <= k) {         b = i, a = i - x + 1;         return 1;       }     }     return 0;   }   int main() {     O_o();     cin >> n >> k;     int arr[n + 5];     vec.push_back(0);     for (int i = 1; i <= int(n); i++) {       cin >> arr[i];       vec.push_back(arr[i] + vec.back());     }     long long second = 0, e = 1e9, ans = 2e9 + 7, x = 0, y = 0, i = 65;     while (second < e) {       long long mid = (second + e) >> 1;       if (ok(mid)) {         second = mid + 1;       } else         e = mid - 1;     }     second -= 3;     while (ok(second)) ++second;     second--;     ok(second);     cout << second << endl;     for (int i = 1; i <= int(n); i++) {       if (i >= a && i <= b)         cout <<  1  ;       else         cout << arr[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = (long long)(1e13) + 7LL;   long long osn = 137LL;   long long getHash(string &s) {     long long res = 0LL, curr = osn;     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 65 && s[i] <= 90) s[i] += 32;       if (s[i] ==  o ) s[i] =  0 ;       if (s[i] ==  l  || s[i] ==  i ) s[i] =  1 ;       res += curr * (long long)(s[i]);       curr *= osn;     }     return res;   }   int main() {     string s, t;     long long s_hash;     cin >> s;     s_hash = getHash(s);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (getHash(t) == s_hash) {         cout <<  No ;         return 0;       }     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   vector<int> circuit;   vector<int> e[MAXN];   void calc(int v) {     stack<int> s;     while (true) {       if (((int)e[v].size()) == 0) {         circuit.push_back(v);         if (!((int)s.size())) {           break;         }         v = s.top();         s.pop();       } else {         s.push(v);         int u = e[v].back();         e[v].pop_back();         v = u;       }     }   }   int a[MAXN];   int b[MAXN];   int c[MAXN];   vector<int> comp;   unordered_map<int, int> act;   unordered_map<long long, vector<int> > pos;   bool bio[MAXN];   void dfs(int v) {     if (bio[v]) return;     bio[v] = true;     for (auto w : e[v]) {       dfs(w);     }   }   vector<vector<int> > ans;   vector<vector<int> > sol;   int s;   void solve(vector<int> &start) {     int uk = 0;     for (auto x : start) {       calc(x);       uk += ((int)circuit.size()) - 1;       reverse(circuit.begin(), circuit.end());       ans.push_back(circuit);       circuit.clear();     }     if (uk > s) {       cout << -1;       exit(0);     }     for (auto v : ans) {       vector<int> nv;       for (int i = 0; i < ((int)v.size()) - 1; ++i) {         int x = v[i];         int y = v[i + 1];         assert(((int)pos[(long long)x * MAXN + y].size()) > 0);         nv.push_back(pos[(long long)x * MAXN + y].back());         pos[(long long)x * MAXN + y].pop_back();       }       sol.push_back(nv);     }   }   int main() {     int n;     cin >> n >> s;     for (int i = 0; i < n; ++i) {       cin >> a[i];       comp.push_back(a[i]);     }     sort(comp.begin(), comp.end());     comp.erase(unique(comp.begin(), comp.end()), comp.end());     for (int i = 0; i < ((int)comp.size()); ++i) {       act[comp[i]] = i;     }     for (int i = 0; i < n; ++i) {       a[i] = act[a[i]];       b[i] = a[i];     }     sort(b, b + n);     for (int i = 0; i < n; ++i) {       if (a[i] != b[i]) {         e[b[i]].push_back(a[i]);         pos[(long long)b[i] * MAXN + a[i]].push_back(i);       }     }     vector<int> start;     for (int i = 0; i < n; ++i) {       if (!bio[b[i]] && ((int)e[b[i]].size())) {         dfs(b[i]);         start.push_back(b[i]);       }     }     if (((int)start.size()) <= 2) {       solve(start);     } else {       int uk = 0;       for (auto x : start) {         calc(x);         uk += ((int)circuit.size()) - 1;         circuit.clear();       }       if (uk > s) {         cout << -1;         return 0;       }       for (int i = 0; i < n; ++i) {         e[i].clear();       }       for (int i = 0; i < n; ++i) {         if (a[i] != b[i]) {           e[b[i]].push_back(a[i]);         }       }       int can = s - uk;       can = min(((int)start.size()), can);       vector<int> out;       for (int i = 0; i < can; ++i) {         int x = start[((int)start.size()) - i - 1];         out.push_back(pos[(long long)x * MAXN + e[x].back()].back());       }       if (((int)out.size()) > 1) {         sol.push_back(out);       }       for (int i = 0; i < can - 1; ++i) start.pop_back();       for (int i = 0; i < n; ++i) {         c[i] = a[i];       }       for (int i = 0; i < n; ++i) e[i].clear();       for (int i = 0; i < n; ++i) {         if (a[i] != b[i]) {           pos[(long long)b[i] * MAXN + a[i]].pop_back();         }       }       for (int i = 0; i < ((int)out.size()); ++i) {         c[out[(i + 1) % ((int)out.size())]] = a[out[i]];       }       for (int i = 0; i < n; ++i) {         if (c[i] != b[i]) {           e[b[i]].push_back(c[i]);           pos[(long long)b[i] * MAXN + c[i]].push_back(i);         }       }       solve(start);     }     cout << ((int)sol.size()) << endl;     for (auto v : sol) {       cout << ((int)v.size()) <<   n ;       for (auto x : v) cout << x + 1 <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5050;   long long a[maxn];   long long c[maxn];   long long tag[maxn];   long long number[maxn];   int main() {     long long i, j, k, n, m;     while (scanf( %lld%lld , &n, &k) != EOF) {       memset(tag, 0, sizeof(tag));       for (i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         tag[a[i]]++;       }       for (i = 1; i <= 5000; i++) number[i] = 1;       bool flag = true;       for (i = 1; i <= 5000; i++)         if (tag[i] > k) {           flag = false;           break;         }       if (!flag)         printf( NO n );       else {         long long cnt = 1;         for (i = 1; i <= 5000; i++) {           for (j = 1; j <= 5000; j++)             if (a[j] == i) {               c[j] = cnt;               cnt++;               if (cnt > k) cnt = 1;             }         }         printf( YES n );         for (i = 1; i <= n; i++) printf( %lld  , c[i]);         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, piles[100000], q;     cin >> n;     cin >> q;     piles[0] = q;     for (int i = int(1); i < int(n); i++) {       cin >> q;       piles[i] = piles[i - 1] + q;     }     cin >> m;     for (int i = int(0); i < int(m); i++) {       cin >> q;       int ans = upper_bound(piles, piles + n, q) - piles;       if (ans > 0 && piles[ans - 1] == q) ans--;       ans++;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx )   using namespace std;   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& x : v) {       is >> x;     }     return is;   }   template <class T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& x : v) {       os << x <<    ;     }     return os;   }   const int N = (1 << 20) + 1;   vector<pair<int, int>> eulerWalk(vector<vector<pair<int, int>>>& gr, int nedges,                                    int src = 0) {     int n = ((int)(gr.size()));     static vector<int> D(N), its(N), eu(N);     D.clear(), D.resize(n);     its.clear(), its.resize(n);     eu.clear(), eu.resize(nedges);     static vector<pair<int, int>> s;     s = {make_pair(src, -1)};     static vector<pair<int, int>> ret;     ret.clear();     D[src]++;     while (!s.empty()) {       auto x = s.back();       int y, e, &it = its[x.first], end = ((int)(gr[x.first].size()));       if (it == end) {         ret.push_back(x);         s.pop_back();         continue;       }       tie(y, e) = gr[x.first][it++];       if (!eu[e]) {         D[x.first]--, D[y]++;         eu[e] = 1;         s.emplace_back(y, e);       }     }     for (int x : D)       if (x < 0 || ((int)(ret.size())) != nedges + 1) return {};     return {ret.rbegin(), ret.rend()};   }   vector<vector<pair<int, int>>> graph(N);   vector<pair<int, int>> cycle;   bool valid(int k, const vector<pair<int, int>>& pearls) {     graph.clear();     graph.resize((1 << k));     int src;     for (int i = 0; i < ((int)(pearls.size())); ++i) {       int u = (pearls[i].first & ((1 << k) - 1));       int v = (pearls[i].second & ((1 << k) - 1));       graph[u].emplace_back(v, i);       graph[v].emplace_back(u, i);       src = u;     }     cycle = eulerWalk(graph, pearls.size(), src);     return !cycle.empty() && cycle.back().first == src;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<pair<int, int>> pearls(n);     for (auto& p : pearls) {       cin >> p.first >> p.second;     }     int res = 20;     while (!valid(res, pearls)) {       --res;     }     cout << res <<   n ;     for (int i = 0; i < n; ++i) {       int u = (pearls[i].first & ((1 << res) - 1));       int v = (pearls[i].second & ((1 << res) - 1));       pearls[i] = make_pair(u, v);     }     for (int i = 1; i <= n; ++i) {       auto curr = cycle[i];       int prev_node = cycle[i - 1].first;       int curr_edge = curr.second;       if (pearls[curr_edge].first == prev_node &&           pearls[curr_edge].second == curr.first) {         cout << 2 * curr_edge + 1 <<     << 2 * curr_edge + 2 <<    ;       } else {         cout << 2 * curr_edge + 2 <<     << 2 * curr_edge + 1 <<    ;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   int n, m;   int A[1000 + 9][1000 + 9];   long long K, sum;   int mrk = 0, to;   int vis[1000 + 9][1000 + 9] = {0};   int di[] = {1, 0, -1, 0};   int dj[] = {0, 1, 0, -1};   set<int> usedAs[1000 + 9][1000 + 9];   bool valid(int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; }   bool flood(int i, int j) {     if (!valid(i, j) || vis[i][j] == mrk || A[i][j] < to) return false;     sum -= to;     vis[i][j] = mrk;     usedAs[i][j].insert(to);     if (sum == 0) return true;     for (int d = 0; d < 4; d++)       if (flood(i + di[d], j + dj[d])) return true;     return false;   }   int main() {     read_file();     while (scanf( %d %d n , &n, &m) != EOF) {       scanf( %lld , &K);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) scanf( %d , &A[i][j]), usedAs[i][j].clear();       bool done = false;       memset(vis, 0, sizeof vis);       for (int i = 0; i < n && !done; i++) {         for (int j = 0; j < m && !done; j++) {           if (K % A[i][j] == 0 && K / A[i][j] <= n * m) {             if (usedAs[i][j].count(A[i][j])) continue;             mrk++;             to = A[i][j];             sum = K;             if (flood(i, j)) done = true;           }         }       }       if (!done) {         printf( NO n );         continue;       }       printf( YES n );       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) A[i][j] = vis[i][j] == mrk ? to : 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) printf( %d%c , A[i][j],    n [j == m - 1]);     }   }


#include <bits/stdc++.h>   int a[100005];   inline int max(int x, int y) { return x > y ? x : y; }   int main() {     int ans = 0, n, Max, Min, Maxpos, Minpos;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int l = 1, r = 1;     while (r <= n && a[r] == a[1]) r++;     if (r == n + 1) return !printf( %d , n);     if (a[r] > a[1])       Max = a[r], Maxpos = r, Min = a[1], Minpos = r - 1;     else       Max = a[1], Maxpos = r - 1, Min = a[r], Minpos = r;     while (l <= r && r <= n) {       while (r < n && a[r + 1] >= Min && a[r + 1] <= Max) {         r++;         if (a[r] == Max)           Maxpos = r;         else           Minpos = r;       }       r++;       ans = max(ans, r - l);       if (r > n) break;       if (a[r] > Max) {         l = Minpos + 1;         Min = Max, Minpos = Maxpos;         Max = a[r], Maxpos = r;       }       if (a[r] < Min) {         l = Maxpos + 1;         Max = Min, Maxpos = Minpos;         Min = a[r], Minpos = r;       }     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, sol = 1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     if (n > m) swap(n, m);     if (((n % 10) + 1 <= 2 && n % 10 >= 1 && m % 10 >= 5) || (abs(n - m) > 10))       return cout << 0, 0;     else {       for (long long int i = n + 1; i <= m; i++) sol = (sol * (i % 10)) % 10;     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double EPS = 1e-8;   using namespace std;   int read() {     int d, f = 1;     char c;     while (!isdigit(c = getchar()))       if (c ==  - ) f = -1;     d = c ^  0 ;     while (isdigit(c = getchar())) d = (d * 10) + (c ^  0 );     return d * f;   }   void rekt() {     puts( YES );     exit(0);   }   int main() {     int n;     while (cin >> n) {       int x0 = read(), y0 = read();       pair<long long, char> dir[8];       for (int i = 0; i < 8; ++i) dir[i].first = 1000000000000000000ll;       for (int i = 0; i < n; ++i) {         char c[2];         scanf( %s , c);         int x = read(), y = read();         if (y == y0) {           if (x < x0 && x0 - x < dir[0].first)             dir[0].first = x0 - x, dir[0].second = c[0];           else if (x > x0 && x - x0 < dir[1].first)             dir[1].first = x - x0, dir[1].second = c[0];         } else if (x == x0) {           if (y < y0 && y0 - y < dir[2].first)             dir[2].first = y0 - y, dir[2].second = c[0];           else if (y > y0 && y - y0 < dir[3].first)             dir[3].first = y - y0, dir[3].second = c[0];         } else if (abs(x - x0) == abs(y - y0)) {           if (x < x0 && y < y0 && x0 - x < dir[4].first)             dir[4].first = x0 - x, dir[4].second = c[0];           else if (x > x0 && y < y0 && x - x0 < dir[5].first)             dir[5].first = x - x0, dir[5].second = c[0];           else if (x < x0 && y > y0 && x0 - x < dir[6].first)             dir[6].first = x0 - x, dir[6].second = c[0];           else if (x > x0 && y > y0 && x - x0 < dir[7].first)             dir[7].first = x - x0, dir[7].second = c[0];         }       }       for (int i = 0; i < 4; ++i)         if (dir[i].second ==  R  || dir[i].second ==  Q ) rekt();       for (int i = 4; i < 8; ++i)         if (dir[i].second ==  B  || dir[i].second ==  Q ) rekt();       puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   int n, m, a[205], b[205], res;   vector<int> v[205], tmp[205];   signed main() {     n = read(), m = read();     for (register int i = (1); i <= (n); ++i) a[i] = read();     for (register int i = (1); i <= (m); ++i) b[i] = read();     for (register int i = (1); i <= (n); ++i)       for (register int j = (1); j <= (m); ++j) v[i].push_back(j);     for (register int p = (9); p >= (0); --p) {       bool ok = 1;       for (register int i = (1); i <= (n); ++i) {         int x = a[i];         if (!(x >> p & 1)) continue;         tmp[i].clear();         for (int j = 0; j < v[i].size(); ++j) {           int y = b[v[i][j]];           if (!(y >> p & 1)) tmp[i].push_back(v[i][j]);         }         if (tmp[i].size() == 0) {           ok = 0;           break;         }       }       if (!ok)         res += (1 << p);       else         for (register int i = (1); i <= (n); ++i)           if (a[i] >> p & 1) v[i] = tmp[i];     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const int M = 1000000007;   int t;   int n, k;   string s;   int dp[1001][1002][2];   int get(int it, int d, bool complete, bool zero) {     if (it == 0) return complete;     if (zero && dp[it][d][complete] != -1) return dp[it][d][complete];     long long ret = 0;     int to = zero ? 9 : s[n - it] -  0 ;     for (int i = 0; i <= to; i++) {       bool nxtZero = zero || (i < to);       bool nxtComplete = complete || ((i == 4 || i == 7) && (d <= k));       int nxtD = min((i == 4 || i == 7) ? 1 : d + 1, 1001);       ret += get(it - 1, nxtD, nxtComplete, nxtZero);     }     ret %= M;     if (zero) dp[it][d][complete] = ret;     return ret;   }   bool correct() {     int prev = -1;     for (int i = 0, _n = (n); i < _n; ++i)       if (s[i] ==  4  || s[i] ==  7 ) {         if (prev != -1 && i - prev <= k) return true;         prev = i;       }     return false;   }   void solution() {     cin >> t >> k;     memset((dp), (-1), sizeof((dp)));     while (t--) {       cin >> s, n = (int)((s).size());       int ret = get(n, 1001, 0, 0);       ret -= correct();       cin >> s, n = (int)((s).size());       ret = get(n, 1001, 0, 0) - ret;       if (ret >= M) ret %= M;       if (ret < 0) ret += M;       cout << ret << endl;     }   }   int main() {     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int aray[100002];   int main() {     int i, j, k, a, b, x, n, y, p, q, len, mx = 0, s = 1;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &aray[i]);     }     p = 0;     q = 0;     s = 0;     for (i = 1; i < n; i++) {       a = aray[i] - aray[i - 1];       if (a) {         if (p == a) {           s = q;         }         q = i;         p = a;       }       len = i - s + 1;       if (len > mx) mx = len;     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[30010], n;   bool vis[30010];   void print(vector<int> v) {     for (int i = 0; i < v.size(); i++) printf( %d  , v[i]);     printf(  n );   }   bool check(vector<int> v) {     if (!v.size()) return false;     if (v.size() == 1 || v.size() == 2) return true;     int d = v[1] - v[0];     for (int i = 2; i < v.size(); i++)       if (v[i] - v[i - 1] != d) return false;     return true;   }   bool solve(int l, int r) {     vector<int> v1, v2;     for (int i = 1; i <= n; i++) vis[i] = 0;     int d = a[r] - a[l];     int last = -1, get = a[l];     for (int i = 1; i <= n; i++)       if (a[i] == get)         get += d, v1.push_back(a[i]), last = i;       else         vis[i] = 1;     for (int i = 1; i <= n; i++)       if (vis[i]) v2.push_back(a[i]);     if (check(v2)) {       print(v1), print(v2);       return true;     }     vis[last] = 1, v1.pop_back(), v2.clear();     for (int i = 1; i <= n; i++)       if (vis[i]) v2.push_back(a[i]);     if (check(v2)) {       print(v1), print(v2);       return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n == 2)       printf( %d n%d , a[1], a[2]);     else if (!solve(1, 2) && !solve(2, 3) && !solve(1, 3))       printf( No solution );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w;   long long ans;   double a[100010], b[100010];   struct node {     int f, x, v;     double a, b;   } sh[100010];   double m_abs(double x) {     if (x < 0)       return -x;     else       return x;   }   bool cmp(node x, node y) { return (x.a < y.a || (x.a == y.a && x.b > y.b)); }   void m_sort(int l, int r) {     if (l == r) return;     int mid;     mid = (l + r) / 2;     m_sort(l, mid);     m_sort(mid + 1, r);     int ll, rr, now;     now = 0;     ll = l;     rr = mid + 1;     while (ll <= mid && rr <= r) {       if (a[ll] < a[rr]) {         now++;         b[now] = a[ll];         ll++;       } else {         now++;         b[now] = a[rr];         rr++;         ans += (long long)mid - ll + 1;       }     }     for (int i = ll; i <= mid; i++) {       now++;       b[now] = a[i];     }     for (int i = rr; i <= r; i++) {       now++;       b[now] = a[i];     }     for (int i = 1; i <= now; i++) {       a[l + i - 1] = b[i];     }   }   int main() {     scanf( %d%d , &n, &w);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &sh[i].x, &sh[i].v);       if (sh[i].x > 0) sh[i].f = 1;     }     for (int i = 1; i <= n; i++) {       if (sh[i].f == 0) {         sh[i].a = m_abs((sh[i].x * 1.0) / ((sh[i].v + w) * 1.0));         sh[i].b = m_abs((sh[i].x * 1.0) / ((sh[i].v - w) * 1.0));       } else {         sh[i].b = m_abs((sh[i].x * 1.0) / ((sh[i].v - w) * 1.0));         sh[i].a = m_abs((sh[i].x * 1.0) / ((sh[i].v + w) * 1.0));       }     }     sort(sh + 1, sh + 1 + n, cmp);     for (int i = 1; i <= n; i++) a[i] = sh[i].b;     m_sort(1, n);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int nm = 100010;   const long long inf = 1000000000000000ll;   int n;   long long a[nm], b[nm];   pair<long long, int> dau[nm], cuoi[nm];   int main() {     scanf( %d , &n);     long long x1, x2;     scanf( %I64d%I64d , &x1, &x2);     for (int i = 1; i <= n; ++i) {       scanf( %I64d%I64d , &a[i], &b[i]);       dau[i] = make_pair(a[i] * x1 + b[i], i);       cuoi[i] = make_pair(a[i] * x2 + b[i], i);     }     sort(dau + 1, dau + n + 1);     sort(cuoi + 1, cuoi + n + 1);     int j = 0;     long long xxx = -inf;     for (int i = 1; i <= n; ++i) {       while (j + 1 < i && cuoi[j + 1].first < cuoi[i].first) {         j++;         xxx = max(xxx, a[cuoi[j].second] * x1 + b[cuoi[j].second]);       }       if (xxx > a[cuoi[i].second] * x1 + b[cuoi[i].second]) {         printf( YES n );         return 0;       }     }     printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   mt19937 gen(chrono::system_clock::now().time_since_epoch().count());   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   const int maxn = (int)3e5 + 10;   const int inf = (int)1e9 + 5;   const int mod = (int)1e9 + 7;   const long long llinf = (long long)1e18 + 5;   const long double pi = acos(-1.0);   int nxt[maxn * 30][2];   int f[maxn * 30];   int sz = 1;   int v[maxn], t[maxn];   void add(int x, int d) {     int v = 1;     for (int i = 29; i >= 0; --i) {       int b = (x >> i & 1);       if (nxt[v][b] == 0) nxt[v][b] = ++sz;       v = nxt[v][b];       f[v] += d;     }   }   int get(int x) {     int v = 1;     int res = 0;     for (int i = 29; i >= 0; --i) {       int b = (x >> i & 1);       if (f[nxt[v][b]] > 0) {         v = nxt[v][b];       } else {         res |= 1 << i;         v = nxt[v][b ^ 1];       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     for (int i = 1; i <= n; ++i) {       cin >> t[i];       add(t[i], 1);     }     for (int i = 1; i <= n; ++i) {       int z = get(v[i]);       cout << z <<    ;       add(z ^ v[i], -1);     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   bool inBound(int x) { return x >= 0 && x < 30001; }   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     std::cout.tie(0);     int n, d;     cin >> n >> d;     int mx = 30000;     vector<int> gems(mx + 1, 0);     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       gems[temp]++;     }     vector<vector<int> > dp;     dp.resize(mx + 1, vector<int>(500, 0));     for (int i = mx; i >= d; i--) {       for (int prev = 0; prev < 500; prev++) {         dp[i][prev] = gems[i];         int prevJump = d + prev - 250;         int nextPos = i + prevJump;         int choice1 =             (inBound(nextPos - 1) && prev - 1 >= 0 && (prevJump - 1) > 0)                 ? dp[nextPos - 1][prev - 1]                 : 0;         int choice2 =             (inBound(nextPos) && (prevJump) > 0) ? dp[nextPos][prev] : 0;         int choice3 =             (inBound(nextPos + 1) && prev + 1 < 500 && (prevJump + 1) > 0)                 ? dp[nextPos + 1][prev + 1]                 : 0;         dp[i][prev] += max(choice1, max(choice2, choice3));       }     }     cout << dp[d][250] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char s[555555];   int t[555555];   int n, a, b, T;   int getAns() {     for (int i = 0; i + 1 < n - 1 - i; i++) {       swap(t[i + 1], t[n - 1 - i]);     }     if (t[0] > T) {       return 0;     }     int ct = t[0];     int ans = 1;     for (int i = 1; i < n; i++) {       ct += a + t[i];       if (ct <= T) {         ans = i + 1;       }     }     if (ans == n) {       return ans;     }     long long wt = t[0];     int bi = n - 1;     while (wt + a + t[bi] <= T) {       wt += a + t[bi];       bi--;     }     ans = max(ans, n - bi);     for (int i = 1; i + 1 < n; i++) {       wt += 2 * a + t[i];       while (wt > T && bi + 1 < n) {         bi++;         wt -= a + t[bi];       }       if (wt > T) {         break;       }       ans = max(ans, i + n - bi);     }     return ans;   }   int main() {     scanf( %d , &n);     scanf( %d%d , &a, &b);     scanf( %d , &T);     scanf(  n%s , s);     for (int i = 0; i < n; i++) {       t[i] = 1;       if (s[i] ==  w ) {         t[i] += b;       }     }     cout << max(getAns(), getAns());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const int n_ = 3010;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   int n, dp[n_][3], a[n_][3];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int j = 0; j < 3; j++) {       for (int i = 0; i < n; i++) cin >> a[i][j];     }     dp[0][1] = -INF;     for (int i = 0; i < n; i++) {       dp[i + 1][1] = max(dp[i][0] + a[i][0], dp[i][1] + a[i][1]);       dp[i + 1][0] = max(dp[i][1] + a[i][2], dp[i][0] + a[i][1]);     }     cout << dp[n][1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dp[1005][2005];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= max(m, n); i++) {       for (int j = 0; j <= i; j++) {         if (j == 1) {           dp[i][j] = i;           continue;         }         dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];         dp[i][j] %= mod;       }     }     cout << 1LL * dp[n - 1][2 * k] * dp[m - 1][2 * k] % mod;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 8e6 + 7, mod = 998244353, root = 3;   long long x[N], n, m, i, j, ma, mb, inv, res, b[N], ans[N], L, R[N];   long long pow_mod(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = 1LL * x * res % mod;       x = 1LL * x * x % mod;       n >>= 1;     }     return res;   }   void ntt(long long* x, long long type) {     for (long long i = 0; i < n; ++i)       if (i < R[i]) swap(x[i], x[R[i]]);     for (long long i = 1; i < n; i <<= 1) {       long long wn = pow_mod(root, type == 1 ? (mod - 1) / (i << 1)                                              : (mod - 1 - (mod - 1) / (i << 1)));       for (long long p = i << 1, j = 0; j < n; j += p) {         long long w = 1;         for (long long k = 0; k < i; ++k, w = 1LL * wn * w % mod) {           long long l = x[j + k], r = 1LL * x[j + k + i] * w % mod;           x[j + k] = (l + r) % mod;           x[j + k + i] = (l - r + mod) % mod;         }       }     }   }   void fpow(long long sz) {     ntt(ans, 1);     ntt(x, 1);     while (sz) {       if (sz & 1) {         for (long long i = 0; i < n; i++) ans[i] = 1ll * ans[i] * x[i] % mod;       }       for (long long i = 0; i < n; i++) x[i] = 1ll * x[i] * x[i] % mod;       sz >>= 1;     }     ntt(ans, -1);   }   int32_t main() {     ans[0] = 1;     long long sz, k, tx;     cin >> sz >> k;     for (long long i = 1; i <= k; i++) {       scanf( %d , &tx);       x[tx] = 1;     }     for (m = 200000 * 9 + 7, n = 1; n <= m; n <<= 1) L++;     for (i = 0; i < n; ++i) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L - 1);     fpow(sz / 2);     long long cnt = 0;     inv = pow_mod(n, mod - 2);     for (long long i = 0; i < n; i++)       cnt =           (cnt + (ans[i] % mod * inv % mod) * (ans[i] % mod * inv % mod) % mod) %           mod;     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool readInteger(T& x) {     char c, r = 0, n = 0;     x = 0;     for (;;) {       c = getchar();       if ((c < 0) && (!r))         return (0);       else if ((c ==  - ) && (!r))         n = 1;       else if ((c >=  0 ) && (c <=  9 ))         x = x * 10 + c -  0 , r = 1;       else if (r)         break;     }     if (n) x = -x;     return (1);   }   template <typename T, T MOD>   struct ModInt {     T value;     ModInt() : value(0) {}     ModInt(T x) {       x %= MOD;       if (x < 0) x += MOD;       value = x;     }       private:     T __________________(T ___, T ____) {       if (!____) return ___;       return __________________(____, ___ % ____);     }     T _____________(T _, T __, T ____, T ___) {       T _____, ______, _______ = ____ - _;       assert(!(_______ % __________________(__, ___)));       for (_____ = ______ = 0; _____ - ______ != _______;) {         _____ = (_______ + ______ + __ - 1) / __ * __;         ______ = (_____ - _______ + ___ - 1) / ___ * ___;       }       return _____ + _;     }       public:     ModInt& operator+=(ModInt x) {       value += x.value;       if (value >= MOD) value -= MOD;       return *this;     }     ModInt& operator-=(ModInt x) {       value -= x.value;       if (value < 0) value += MOD;       return *this;     }     ModInt& operator*=(ModInt x) {       value *= x.value;       value %= MOD;       return *this;     }     ModInt& operator/=(ModInt x) {       x.invert();       return *this *= x;     }     ModInt operator+(ModInt x) const {       ModInt o = *this;       o += x;       return o;     }     ModInt operator-(ModInt x) const {       ModInt o = *this;       o -= x;       return o;     }     ModInt operator*(ModInt x) const {       ModInt o = *this;       o *= x;       return o;     }     ModInt operator/(ModInt x) const {       ModInt o = *this;       o /= x;       return o;     }     bool operator==(ModInt x) const { return value == x.value; }     bool operator!=(ModInt x) const { return !(*this == x); }     ModInt operator-() const { return ModInt(0) - *this; }     ModInt operator^(long long x) const {       ModInt ret = 1;       ModInt mul = *this;       while (x) {         if (x & 1) ret *= mul;         mul *= mul;         x >>= 1;       }       return ret;     }     ModInt& operator^=(long long x) { return *this = *this ^ x; }       private:     void invert() { *this ^= MOD - 2; }       public:     void answer() { std::cout << value << std::endl; }   };   const int MX = 2.1e5;   int N, K;   int ai[MX];   vector<int> E[MX];   vector<int> child[MX];   bool light[MX];   long long dp[MX][5];   const int NINF = -1e9;   void solve(int x) {     for (auto& o : (child[x])) solve(o);     long long useNow = NINF;     {       long long& ans = dp[x][4];       ans = NINF;       if (light[x]) {         {           long long sum = 1;           long long bestDelta = 0;           for (auto& o : (child[x])) {             sum += dp[o][3];             bestDelta = max(bestDelta, dp[o][4] - dp[o][3]);           }           sum += bestDelta;           ans = max(ans, sum);         }         {           long long sum = 1;           long long bestA = 0;           long long bestB = 0;           for (auto& o : (child[x])) {             long long v1 = max(0LL, dp[o][3]);             long long v2 = dp[o][2];             sum += v1;             long long delta = v2 - v1;             if (delta > bestA) {               bestB = bestA;               bestA = delta;             } else               bestB = max(bestB, delta);           }           useNow = sum + bestA + bestB;           ans = max(ans, useNow);         }       }     }     {       long long& ans = dp[x][3];       ans = NINF;       if (light[x]) {         long long sum = 1;         for (auto& o : (child[x])) sum += dp[o][3];         ans = max(ans, sum);       }     }     {       long long& ans = dp[x][2];       ans = NINF;       if (light[x]) {         long long sum = 1;         long long bestDelta = 0;         for (auto& o : (child[x])) {           long long v1 = max(0LL, dp[o][3]);           long long v2 = dp[o][2];           sum += v1;           bestDelta = max(bestDelta, v2 - v1);         }         sum += bestDelta;         ans = max(ans, sum);       }     }     {       long long& ans = dp[x][1];       ans = useNow;       for (auto& o : (child[x])) ans = max(ans, dp[o][1]);     }   }   int ROOT = 0;   bool ok(int threshold) {     for (int i = (0); i < int(N); i++) light[i] = ai[i] >= threshold;     if (light[ROOT]) return true;     solve(ROOT);     return dp[ROOT][1] >= K;   }   void init(int x, int par) {     for (auto& o : (E[x]))       if (o != par) {         child[x].push_back(o);         init(o, x);       }   }   int main() {     readInteger(N);     readInteger(K);     for (int i = (0); i < int(N); i++) readInteger(ai[i]);     for (int k = (0); k < int(N - 1); k++) {       int u, v;       readInteger(u);       readInteger(v);       --u, --v;       E[u].push_back(v);       E[v].push_back(u);     }     for (int i = (0); i < int(N); i++)       if (ai[i] < ai[ROOT]) ROOT = i;     init(ROOT, -1);     vector<int> vals(N);     for (int i = (0); i < int(N); i++) vals[i] = ai[i];     sort(vals.begin(), vals.end());     reverse(vals.begin(), vals.end());     int lo = K - 1;     int hi = N - 1;     while (lo != hi) {       int mid = (lo + hi) / 2;       if (ok(vals[mid]))         hi = mid;       else         lo = mid + 1;     }     printf( %d n , vals[lo]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k;     cin >> n;     cin >> k;     int array[n];     for (int i = 0; i < n; i++) {       cin >> array[i];     }     int e;     int s;     int a = 0;     for (int i = 0; i < k; i++) {       e = 0;       s = 0;       for (int j = 0; j < n; j++) {         if (array[j] == 1 && j % k != i) {           e++;         }         if (array[j] == -1 && j % k != i) {           s++;         }       }       if (abs(e - s) > a) {         a = abs(e - s);       }     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200 + 5;   int a[maxn], b[maxn];   int n, m, k, x;   int getloc(int x) {     for (int i = 1; i <= k; i++) {       if (a[i] == x) return i;     }   }   void update(int x) {     int pos = 0;     for (int i = 1; i <= k; i++) {       if (a[i] == x) pos = i;     }     b[1] = a[pos];     int t = 2;     for (int i = 1; i <= k; i++) {       if (i != pos) b[t++] = a[i];     }     for (int i = 1; i <= k; i++) {       a[i] = b[i];     }   }   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 1; i <= k; i++) scanf( %d , &a[i]);       int ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &x);           ans += getloc(x);           update(x);         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e6 + 3;   long long quickpow(long long a, long long x) {     long long ans = 1;     while (x) {       if (x & 1) ans = ans * a % mod;       x >>= 1;       a = a * a % mod;     }     return ans;   }   int main() {     long long n, k, x = 0, m = 0;     cin >> n >> k;     while ((1ll << x) < k) x++;     if (x > n) {       cout <<  1 1  << endl;       return 0;     }     for (long long i = 2; i < k; i <<= 1) m += (k - 1) / i;     long long p = quickpow(2, mod - 1 - m % (mod - 1));     long long ans = (quickpow(quickpow(2, n), k - 1) * p) % mod;     if (mod <= k - 1)       cout << ans <<     << ans << endl;     else {       long long ans1 = 1, ori = quickpow(2, n);       for (long long i = 1; i < k; i++) ans1 = (ans1 * (ori - i)) % mod;       ans1 = ans1 * p % mod;       cout << ((ans - ans1) % mod + mod) % mod <<     << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 * 1000 + 10;   pair<int, long double> song[maxn];   int n;   long double ans, sum;   inline bool cmp(const pair<int, long double> &a,                   const pair<int, long double> &b) {     return ((long double)1 - a.second) * b.second * b.first <            ((long double)1 - b.second) * a.second * a.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> song[i].first >> song[i].second;       song[i].second *= (long double)0.01;     }     sort(song, song + n, cmp);     for (int i = 0; i < n; i++) {       ans += song[i].first;       ans += ((long double)1 - song[i].second) * sum;       sum += song[i].second * (long double)song[i].first;     }     cout << setprecision(12) << fixed << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long, pair<long long, long long> > &a,                  const pair<long long, pair<long long, long long> > &b) {     return (a.second.first < b.second.first);   }   bool sortbyth(const pair<long long, pair<long long, long long> > &a,                 const pair<long long, pair<long long, long long> > &b) {     return (a.second.second < b.second.second);   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long max3(long long a, long long b, long long c) {     return max(max(a, b), c);   }   long long max4(long long a, long long b, long long c, long long d) {     return max(max(a, b), max(c, d));   }   long long min3(long long a, long long b, long long c) {     return min(min(a, b), c);   }   long long min4(long long a, long long b, long long c, long long d) {     return min(min(a, b), min(c, d));   }   long long po(long long x, long long n, long long mod = 998244353) {     if (n == 0) {       return 1;     }     long long m = po(x, n / 2, mod);     m *= m;     m %= mod;     if (n % 2) {       m *= x;       m %= mod;     }     return m;   }   long long n, m, x, y;   long long col[2][1005];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     clock_t startTime = clock();     cin >> n >> m >> x >> y;     char a[1005][1005];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (long long i = 0; i < m; i++) {       long long c = 0;       for (long long j = 0; j < n; j++) {         if (a[j][i] ==  # ) {           c++;         }       }       col[0][i] = c;       col[1][i] = n - c;     }     long long dp[2][2][1005] = {};     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 1005; j++) {         if (j >= x || j == 0) {           dp[1][i][j] = 0;         } else {           dp[1][i][j] = INT_MAX;         }       }     }     for (long long index = m - 1; index >= 0; index--) {       for (long long last = y - 1; last >= 0; last--) {         for (long long color = 0; color < 2; color++) {           if (last == y - 1) {             dp[0][color][last] = dp[1][1 ^ color][0] + col[color][index];           } else if (last < x - 1) {             dp[0][color][last] = dp[1][color][last + 1] + col[color][index];           } else {             dp[0][color][last] =                 min(dp[1][color][last + 1], dp[1][1 ^ color][0]) +                 col[color][index];           }         }       }       for (long long last = y - 1; last >= 0; last--) {         for (long long color = 0; color < 2; color++) {           dp[1][color][last] = dp[0][color][last];         }       }     }     cout << min(dp[0][0][0], dp[0][1][0]) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int sgn(long long v) { return v > 0 ? 1 : 0; }   int main(void) {     long long p, q, r, s;     cin >> p >> q >> r >> s;     int n;     int res = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       long long temp1 = (a * p + b * q + c);       long long temp2 = a * r + b * s + c;       res = (sgn(temp1) == sgn(temp2)) ? res : res + 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     long long ans = 0;     long long ca = 0, cab = 0, cabc = 0, slen = 1;     for (char c : s) {       if (c ==  a )         ca = (slen + ca) % mod;       else if (c ==  b )         cab = (ca + cab) % mod;       else if (c ==  c )         cabc = (cabc + cab) % mod;       else {         cabc = (3 * cabc + cab) % mod;         cab = (ca + 3 * cab) % mod;         ca = (slen + 3 * ca) % mod;         slen = (3 * slen) % mod;       }     }     cout << cabc <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = (1 << 7);   const int mod = 1e9 + 7;   long long dp[N][M];   struct node {     int v, s[8];   } a[N];   bool cmp(node b, node d) { return b.v > d.v; }   int n, p, k;   int main() {     scanf( %d%d%d , &n, &p, &k);     int st = 1 << p;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v);     for (int i = 1; i <= n; i++)       for (int j = 0; j < p; j++) scanf( %d , &a[i].s[j]);     sort(1 + a, 1 + a + n, cmp);     for (int i = 0; i <= n; i++)       for (int j = 1; j < st; j++) dp[i][j] = -1e18;     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < st; j++) {         for (int k = 0; k < p; k++)           if (j & (1 << k))             dp[i][j] = max(dp[i - 1][j - (1 << k)] + a[i].s[k], dp[i][j]);         int p = __builtin_popcount(j);         if ((i - 1) - p >= k)           dp[i][j] = max(dp[i][j], dp[i - 1][j]);         else           dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[i].v);       }     }     printf( %lld n , dp[n][st - 1]);   }


#include <bits/stdc++.h>   using namespace std;   const int logsize = 18;   int n, m, q, rt = 1, t, sc, vis[100005], dfn[100005], low[100005], sid[100005],                sz[100005], dep[100005], pr[100005][logsize], w[100005],                mod = 1e9 + 7;   stack<int> s;   vector<int> g[100005], ng[100005];   int inline read() {     int res = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       ;     for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar())       ;     return res;   }   void tarjan(int u, int p) {     dfn[u] = low[u] = ++t;     vis[u] = 1;     s.push(u);     for (int v : g[u]) {       if (v == p || vis[v] == 2) continue;       if (!vis[v]) {         tarjan(v, u);       }       low[u] = min(low[u], low[v]);     }     if (dfn[u] == low[u]) {       ++sc;       for (;;) {         int v = s.top();         s.pop();         vis[v] = 2;         sid[v] = sc;         ++sz[sc];         if (u == v) break;       }     }   }   void dfs(int u, int p) {     dep[u] = u == rt ? 0 : dep[p] + 1;     w[u] = u == rt ? sz[u] > 1 : w[p] + (sz[u] > 1);     pr[u][0] = p;     for (int v : ng[u]) {       if (v == p) continue;       dfs(v, u);     }   }   void inline init() {     dfs(rt, -1);     for (int i = 1; i <= logsize - 1; ++i) {       for (int u = 1; u <= sc; ++u) {         int p = pr[u][i - 1];         if (p == -1) {           pr[u][i] = -1;         } else {           pr[u][i] = pr[p][i - 1];         }       }     }   }   int inline lca(int u, int v) {     if (dep[u] > dep[v]) {       swap(u, v);     }     for (int i = 0; i < logsize; ++i) {       if ((dep[v] - dep[u]) >> i & 1) {         v = pr[v][i];       }     }     if (u == v) return u;     for (int i = logsize - 1; i >= 0; --i) {       if (pr[u][i] != pr[v][i]) {         u = pr[u][i];         v = pr[v][i];       }     }     return pr[u][0];   }   int qpow(long long a, int p) {     long long res = 1;     while (p) {       if (p & 1) {         res *= a;         res %= mod;       }       a *= a;       a %= mod;       p >>= 1;     }     return res % mod;   }   int main() {     ios_base::sync_with_stdio(0);     n = read();     m = read();     for (int i = 1; i <= m; ++i) {       int u = read(), v = read();       g[u].push_back(v);       g[v].push_back(u);     }     for (int u = 1; u <= n; ++u) {       if (!vis[u]) {         tarjan(u, -1);       }     }     for (int u = 1; u <= n; ++u) {       for (int v : g[u]) {         int su = sid[u], sv = sid[v];         if (su == sv) continue;         ng[su].push_back(sv);       }     }     init();     q = read();     for (int i = 1; i <= q; ++i) {       int u = read(), v = read(), su = sid[u], sv = sid[v], sp = lca(su, sv);       int d = w[su] + w[sv] - w[sp] * 2 + (sz[sp] > 1);       cout << qpow(2, d) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const long long int Mod = 998244353;   vector<int> adj[maxn];   long long int dp[maxn], pd[maxn], alone[maxn];   int n;   void dfs(int u, int p = -1) {     dp[u] = pd[u] = 0;     alone[u] = 1;     for (auto v : adj[u])       if (v ^ p) {         dfs(v, u);         dp[u] = ((dp[u] * (2 * dp[v] + alone[v]) % Mod) +                  ((alone[u] + pd[u]) * (alone[v] + pd[v]) % Mod)) %                 Mod;         pd[u] = (pd[u] * (dp[v] * 2 + alone[v]) + alone[u] * dp[v]) % Mod;         alone[u] = (alone[u] * (alone[v] + dp[v])) % Mod;       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int fi, se;       cin >> fi >> se;       fi--, se--;       adj[fi].push_back(se);       adj[se].push_back(fi);     }     dfs(0);     cout << (dp[0] + alone[0]) % Mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 11;   const int MAXN = 1e5 + 5;   const int LG = 20;   const int INF = 1e9;   using ll = long long int;   using ull = unsigned long long int;   const ll MOD2 = 998244353;   const ll MOD1 = 1e9 + 7LL;   vector<int> g[MAXN], cg[MAXN];   vector<int> cpar(MAXN);   vector<int> ans(MAXN);   int n, m;   struct CDMP {     vector<bool> dead;     vector<int> par;     int oneCentroid(int root) {       static vector<int> sub(MAXN);       function<void(int, int)> dfs = [&](int u, int p) {         sub[u] = 1;         for (int v : g[u]) {           if (v == p || dead[v]) continue;           dfs(v, u);           sub[u] += sub[v];         }       };       dfs(root, -1);       int N = sub[root];       function<int(int, int)> findcenter = [&](int u, int p) {         for (int v : g[u]) {           if (v == p || dead[v]) continue;           if (2 * sub[v] > N) return findcenter(v, u);         }         return u;       };       return findcenter(root, -1);     }     void traverse(int u, int p, int d = 0) {       par[u] = p;       for (int v : cg[u]) {         if (v != p) {           traverse(v, u, d + 1);         }       }     }     vector<int> &decomposeTree() {       par = vector<int>(MAXN, -1);       dead = vector<bool>(MAXN, false);       function<int(int)> rec = [&](int u) {         int c = oneCentroid(u);         dead[c] = true;         for (int v : g[c])           if (!dead[v]) {             int cv = rec(v);             cg[c].push_back(cv);             cg[cv].push_back(c);           }         return c;       };       int r = rec(1);       traverse(r, -1);       return par;     }   } cdmp;   struct computeLCA {     int level[MAXN];     int par[MAXN][LG];     int findlca(int u, int v) {       if (level[u] < level[v]) swap(u, v);       int lg = 0;       for (; (1 << lg) <= level[u]; ++lg)         ;       --lg;       for (int i = lg; i >= 0; --i)         if (level[u] - (1 << i) >= level[v]) u = par[u][i];       if (u == v) return u;       for (int i = lg; i >= 0; --i)         if (par[u][i] != -1 && par[u][i] != par[v][i])           u = par[u][i], v = par[v][i];       return par[u][0];     }     int dist(int u, int v) {       return level[u] + level[v] - 2 * level[findlca(u, v)];     }     void dfs(int u, int p) {       level[u] = 1 + level[p];       par[u][0] = p;       for (int v : g[u])         if (v != p) {           dfs(v, u);         }     }     void build() {       level[1] = 0;       for (int i = 0; i <= n; ++i)         for (int j = 0; j < LG; ++j) par[i][j] = -1;       dfs(1, 1);       for (int l = 1; l < LG; ++l)         for (int i = 1; i <= n; ++i)           if (par[i][l - 1] != -1) {             par[i][l] = par[par[i][l - 1]][l - 1];           }     }   } lca;   void update(int x) {     int node = x;     while (node > 0) {       ans[node] = min(ans[node], lca.dist(node, x));       node = cpar[node];     }   }   int query(int x) {     int node = x;     int ret = INF;     while (node > 0) {       ret = min(ret, lca.dist(node, x) + ans[node]);       node = cpar[node];     }     return ret;   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d , &u);       scanf( %d , &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 0; i <= n; ++i) ans[i] = INF;     cpar = cdmp.decomposeTree();     lca.build();     update(1);     while (m--) {       int t, x;       scanf( %d , &t);       scanf( %d , &x);       if (t == 1) {         update(x);       } else {         printf( %d , query(x));         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, j, temp, cnt = 0;       cin >> n;       string s;       cin >> s;       for (int i = 0; i < n; i++) {         temp = 0;         for (int j = 0; j < n - 1; j++) {           if (s[j] ==  A  && s[j + 1] ==  P ) {             s[j + 1] =  A ;             j++;             temp = 1;           }         }         if (temp == 1) {           cnt++;         } else           break;       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<vector<int> > g(n);       vector<int> deg(n);       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         --x;         --y;         g[x].push_back(y);         g[y].push_back(x);         deg[x]++;         deg[y]++;       }       for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end());       vector<bool> used(n), vis(n);       vector<int> q(n);       int top = 0;       vector<int> vert(k);       bool f = 0;       for (int i = 0; i < n; i++) {         used[i] = vis[i] = 0;         if (deg[i] < k) {           vis[i] = 1;           q[top++] = i;         }       }       for (int i = 0; i < top; i++) {         int u = q[i];         vis[u] = 0;         used[u] = 1;         if (deg[u] < k - 1) {           for (auto j : g[u]) {             if (!used[j]) --m;             deg[j]--;             if (!vis[j] and !used[j] and deg[j] < k) {               vis[j] = 1;               q[top++] = j;             }           }           continue;         } else if (deg[u] == k - 1) {           if ((long long)k * (k - 1) <= 2 * (long long)m) {             int r = 0;             for (auto p : g[u]) {               if (!used[p]) vert[r++] = p;             }             bool ff = 1;             for (int x = 0; x < r; x++) {               if (!ff) break;               for (int y = x + 1; y < r; y++) {                 int pp =                     lower_bound(g[vert[x]].begin(), g[vert[x]].end(), vert[y]) -                     g[vert[x]].begin();                 if (pp == g[vert[x]].size() or g[vert[x]][pp] != vert[y]) {                   ff = 0;                   break;                 }               }             }             if (ff) {               f = 1;               cout <<  2 n  << u + 1 <<    ;               for (int c = 0; c < r; c++) cout << vert[c] + 1 <<    ;               cout <<   n ;               break;             }           }         }         for (auto j : g[u]) {           deg[j]--;           if (!used[j]) --m;           if (!vis[j] and !used[j] and deg[j] < k) {             vis[j] = 1;             q[top++] = j;           }         }       }       if (f) continue;       vector<int> ff;       for (int i = 0; i < n; i++)         if (!used[i]) ff.push_back(i);       if (!ff.empty()) {         cout <<  1   << ff.size() <<   n ;         for (auto c : ff) {           c++;           cout << c <<    ;         }         cout <<   n ;       } else         cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, n, *a, t, j, flag;     long m;     scanf( %d , &n);     scanf( %ld , &m);     a = (int*)calloc(n, sizeof(int));     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++)       for (j = 0; j < n - i - 1; j++)         if (a[j + 1] > a[j]) {           t = a[j + 1];           a[j + 1] = a[j];           a[j] = t;         }     flag = 1;     for (i = 0; i < n && flag; i++) {       m = m - a[i];       if (m <= 0) flag = 0;     }     printf( %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int i32INF = 1 << 30;   const long long i64INF = 1LL << 60;   const double mINF = 1e100;   const double EPS = 1e-9;   int nextint() {     int a;     scanf( %d , &a);     return a;   }   int n;   vector<int> v;   int difs[23][23];   bool isGood[1 << 23];   bool solveIsGood(int mask) {     int id = n;     while ((mask & (1 << (id - 1))) == 0) id--;     for (int i = 0; i < n; i++)       if (mask & (1 << i) && mask & difs[id][i]) return true;     return false;   }   int dp[1 << 23];   int main() {     n = nextint();     v.resize(n);     for (int i = 0; i < n; i++) v[i] = nextint();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j)           for (int k = 0; k < n; k++)             if (v[i] - v[j] == v[k]) difs[i][j] |= (1 << k);     isGood[0] = 1;     for (int mask = 1; mask < (1 << (n - 1)); mask++)       isGood[mask] = solveIsGood(mask);     fill(dp, dp + (1 << n), 1024);     dp[1] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j < (1 << (i - 1)); j++) {         int jj = j | (1 << (i - 1));         if (isGood[jj]) {           int cr = dp[jj];           jj |= 1 << i;           dp[jj] = min(dp[jj], cr + 1);           for (int k = 0; k < i; k++)             if (jj & (1 << k))               dp[jj & (~(1 << k))] = min(dp[jj & (~(1 << k))], cr);         }       }     }     int res = 1024;     for (int mask = 0; mask < (1 << (n - 1)); mask++)       res = min(res, dp[mask | (1 << (n - 1))]);     if (res == 1024) res = -1;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, h, t, x, y;   vector<int> s[100100];   int a[100100], b[100100];   bool bj[100100][2];   void out(int u, int v) {     int su = s[u].size(), sv = s[v].size();     int same = 0, i = 0, j = 0;     while (i < su && j < sv) {       if (s[u][i] == s[v][j])         same++, bj[i][0] = 1, bj[j][1] = 1, i++, j++;       else if (s[u][i] > s[v][j])         j++;       else         i++;     }     printf( YES n%d %d n , u, v);     for (int i = 0; i < su; i++)       if (s[u][i] != v) {         if (!h) break;         if (!bj[i][0]) {           printf( %d  , s[u][i]);           h--;         }       }     for (int i = 0; i < su; i++)       if (s[u][i] != v) {         if (!h) break;         if (bj[i][0]) {           printf( %d  , s[u][i]);           h--;         }       }     puts(  );     for (int i = 0; i < sv; i++)       if (s[v][i] != u) {         if (!t) break;         if (!bj[i][1]) {           printf( %d  , s[v][i]);           t--;         }       }     for (int i = sv - 1; i >= 0; i--)       if (s[v][i] != u) {         if (!t) break;         if (bj[i][1]) {           printf( %d  , s[v][i]);           t--;         }       }     puts(  );   }   bool found(int u, int v) {     int su = s[u].size(), sv = s[v].size();     if (su - 1 < h || sv - 1 < t) return 0;     int same = 0, i = 0, j = 0;     while (i < su && j < sv) {       if (s[u][i] == s[v][j])         same++, i++, j++;       else if (s[u][i] > s[v][j])         j++;       else         i++;     }     if (su + sv - same - 2 >= h + t) {       out(u, v);       return 1;     }     return 0;   }   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);       a[i] = x, b[i] = y;     }     for (int i = 1; i <= n; i++) sort(s[i].begin(), s[i].end());     for (int i = 1; i <= m; i++) {       if (found(a[i], b[i])) return 0;       if (found(b[i], a[i])) return 0;     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> pr;   vector<bool> used(1000001, false);   vector<int> d(1000001, 0);   void sieve() {     for (long long i = 2; i <= 1000000; i++) {       for (long long k = i * i; k <= 1000000; k += i) used[k] = true;     }     for (int i = 2; i <= 1000000; i++)       if (!used[i]) pr.push_back(i);   }   int main() {     sieve();     d[1] = 1;     for (int i = 2; i <= 1000000; i++) {       d[i] = d[i - 1];       int k = lower_bound(pr.begin(), pr.end(), i) - pr.begin();       int k1 = upper_bound(pr.begin(), pr.end(), i) - pr.begin();       if (k1 - k > 0) {         d[i]++;         continue;       }       int x = sqrt(i);       if (x * x == i) {         k = lower_bound(pr.begin(), pr.end(), x) - pr.begin();         k1 = upper_bound(pr.begin(), pr.end(), x) - pr.begin();         if (k1 - k > 0) {           d[i]--;         }       }     }     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       printf( %d n , d[n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 4;   const int oo = 1e8 + 7;   int n, a[maxn], cc, p;   long long s[maxn];   int main() {     cin >> n;     a[1] = 1;     a[2] = 2 * n;     a[n + 1] = 2;     a[n + 2] = 2 * n - 1;     int cc = 3;     for (int i = 3; i <= (n); ++i) {       if (i % 2) {         a[i] = cc;         a[i + n] = cc + 1;         cc += 2;       } else {         a[i + n] = cc;         a[i] = cc + 1;         cc += 2;       }     }     long long k = 0;     for (int i = 1; i <= (2 * n); ++i) k += i;     for (int i = 2 * n + 1; i <= (4 * n); ++i) a[i] = a[i - 2 * n];     for (int i = 1; i <= (4 * n); ++i) s[i] = s[i - 1] + a[i];     k = k / 2;     k++;     for (int i = 1; i <= (3 * n); ++i) {       long long x = s[i + n - 1] - s[i - 1];       if (abs(x - k) > 1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (int i = 1; i <= (2 * n); ++i) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, c[N], k = 1e5;   char a[N], b[N];   void solve(int p, int coef) {     if (a[p - 1] + coef <  0  || a[p - 1] + coef >  9 ) {       solve(p - 1, -coef);     }     a[p - 1] += coef;     a[p] += coef;     printf( %d %d n , p - 1, coef);     if (!--k) {       exit(0);     }   }   int main() {     scanf( %d%s%s , &n, a + 1, b + 1);     copy(a + 1, a + 1 + n, c + 1);     long long answer = 0;     for (int i = 1; i < n; ++i) {       if (c[i] != b[i]) {         answer += abs(c[i] - (int)b[i]);         c[i + 1] += (int)b[i] - c[i];       }     }     if (c[n] != b[n]) {       return puts( -1 );     } else {       printf( %lld n , answer);       if (answer < k) {         k = answer;       }       for (int i = n; i; --i) {         for (; a[i] != b[i]; solve(i, a[i] < b[i] ? 1 : -1))           ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print_ans(int x1, int y1, int x2, int y2) {     long long int ans;     ans = (x1 - x2) * (y1 - y2);     if (ans < 0) ans = -ans;     cout << ans;     return;   }   int main() {     int n, x[4], y[4], i;     cin >> n;     if (n < 2)       cout <<  -1 ;     else {       for (i = 0; i < n; i++) cin >> x[i] >> y[i];       if (n == 2) {         if (x[0] == x[1] || y[0] == y[1])           cout <<  -1 ;         else           print_ans(x[0], y[0], x[1], y[1]);       } else {         if (x[0] != x[1] && y[0] != y[1])           print_ans(x[0], y[0], x[1], y[1]);         else if (x[1] != x[2] && y[1] != y[2])           print_ans(x[1], y[1], x[2], y[2]);         else           print_ans(x[0], y[0], x[2], y[2]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vv[2000][2000];   int main() {     int n;     string s;     cin >> s;     long long left[2000], right[2000];     for (int i = 0; i < s.length(); i++) {       vv[i][i] = true;     }     int sm = 1, cp = s.length() - 1;     for (; sm < s.length(); sm++) {       for (int i = sm, j = 0; i < s.length(); i++, j++) {         if (s[j] == s[j + sm] && (sm == 1 || vv[j + 1][j + sm - 1])) {           vv[j][j + sm] = true;         } else {           vv[j][j + sm] = false;         }       }     }     for (int i = 0; i < s.length(); i++) {       left[i] = 1;       right[i] = 1;       for (int j = 0; j < i; j++) {         if (vv[j][i]) left[i]++;         if (vv[s.length() - (i + 1)][s.length() - (j + 1)]) right[i]++;       }     }     long long res = 0, right_sum = 0;     for (int i = 0; i < s.length() - 1; i++) right_sum += right[i];     for (int i = 0; i < s.length() - 1; i++) {       res += left[i] * right_sum;       right_sum -= right[s.length() - (i + 2)];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long, pair<long long, long long>>> pq;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       bool flag = true, cond = true;       long long n, i, j, x, y, ind, k, m, mn = INT_MAX, p = 0, mx = 0, diff, y1,                                           count = 0;       cin >> n;       vector<long long> a(n), b(n);       for (i = 0; i < n; i++) {         cin >> a[i];       }       map<long long, long long> mp;       for (j = 0; j < n; j++) {         cin >> b[j];         mp[b[j]]++;       }       vector<long long> c;       map<long long, long long>::iterator it;       for (i = 0; i < n; i++) {         it = mp.lower_bound(n - a[i]);         if (it == mp.end()) {           it = mp.begin();           c.push_back((a[i] + it->first) % n);           if (it->second == 1)             mp.erase(it->first);           else             mp[it->first]--;         } else {           c.push_back((a[i] + it->first) % n);           if (it->second == 1)             mp.erase(it->first);           else             mp[it->first]--;         }       }       for (int iz = 0; iz < c.size(); iz++) {         cout << c[iz] <<    ;       }       cout <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[50005];   bool cmp(const string &a, const string &b) { return a + b < b + a; }   int main() {     int n, i;     cin >> n;     for (i = 0; i < n; i++) cin >> s[i];     sort(s, s + n, cmp);     string ans = accumulate(s, s + n, string());     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxs = 300 * 1000 + 5, Maxn = 300 * 1000 + 5;   int n, dp[Maxs];   string s, t;   long long ans;   vector<pair<int, string> > adj[Maxn];   void kmp() {     dp[0] = -1;     for (int i = 0; i < t.size(); i++) {       int pt = i;       while (dp[pt] != -1 && t[dp[pt]] != t[i]) pt = dp[pt];       dp[i + 1] = dp[pt] + 1;     }   }   double now;   void dfs(int v, int indt) {     for (auto u : adj[v]) {       int indt2 = indt;       for (int j = 0; j < u.second.size(); ++j) {         if (clock() - now == CLOCKS_PER_SEC * 0.990) {           cout << ans << endl;           exit(0);         }         if (indt2 == t.size()) ans++, indt2 = dp[indt2];         if (indt2 >= 0 && indt2 < t.size() && u.second[j] == t[indt2])           indt2++;         else if (indt2 != 0 && indt2 >= 0)           indt2 = dp[indt2], j--;       }       if (indt2 == t.size()) ans++, indt2 = dp[indt2];       dfs(u.first, indt2);     }   }   int main() {     now = clock();     cin >> n;     int par;     for (int i = 1; i < n; i++)       cin >> par >> s, par--, adj[par].push_back(make_pair(i, s));     cin >> s;     t = s;     kmp();     dfs(0, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int calc(long long n, long long k, long long a1, long long a2, long long a3) {     long long sum;     if (a2 < a3) {       swap(a2, a3);     }     if (a1 < a2) {       swap(a1, a2);     }     if (a2 < a3) {       swap(a2, a3);     }     if (a1 < 0 || a2 < 0 || a3 < 0) {       return 0;     }     sum = a1 - a2 + a1 - a3;     if (sum > n - k) {       return 0;     }     if ((n - k - sum) % 3 == 0) {       return 1;     }     return 0;   }   int task() {     long long i, n, k, d1, d2, a1, a2, a3;     cin >> n;     ;     cin >> k;     ;     cin >> d1;     ;     cin >> d2;     ;     a1 = k + 2 * d1 + d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 - d1;       a3 = a2 - d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k + 2 * d1 - d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 - d1;       a3 = a2 + d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k - 2 * d1 + d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 + d1;       a3 = a2 - d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     a1 = k - 2 * d1 - d2;     if (a1 % 3 == 0) {       a1 = a1 / 3;       a2 = a1 + d1;       a3 = a2 + d2;       if (calc(n, k, a1, a2, a3)) {         return 1;       }     }     return 0;   }   int main(int argc, char const *argv[]) {     int i, t;     string yes( yes );     string no( no );     cin >> t;     ;     for (i = 0; i < t; i++) {       if (task()) {         cout << yes << endl;         ;       } else {         cout << no << endl;         ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, f[1000010], mn, rt, ans;   int cnt, head[1000010], to[2000010], nxt[2000010];   void add(int x, int y) {     cnt++;     to[cnt] = y;     nxt[cnt] = head[x];     head[x] = cnt;   }   void dfs(int x, int fa, int now) {     f[x] = now;     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa) {         continue;       }       dfs(y, x, min(now, y));     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     q--;     scanf( %d , &rt);     scanf( %d , &rt);     rt = rt % n + 1;     mn = rt;     dfs(rt, 0, rt);     while (q--) {       int op, x;       scanf( %d%d , &op, &x);       x = (x + ans) % n + 1;       if (op == 1) {         mn = min(mn, f[x]);       } else {         ans = min(mn, f[x]);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, a, b;     cin >> n >> a >> b;     for (long long i = 0; i <= n; ++i) {       if (a * i > n) {         break;       }       long long cur = a * i;       if (n - cur >= 0 && (n - cur) % b == 0) {         cout <<  YES n ;         cout << i <<     << (n - cur) / b;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long r, g, b, k = 0;   long long a[4];   int main() {     cin >> t;     while (t--) {       cin >> a[1] >> a[2] >> a[3];       sort(a + 1, a + 1 + 3);       k = a[1] + a[2];       if (a[3] >= k)         cout << k << endl;       else {         k -= a[3];         r = min(a[1], k / 2) + a[3];         cout << r << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000 + 50;   vector<int> v[maxN];   int cnt;   bool mark[maxN];   void dfs(int s) {     mark[s] = 1;     cnt++;     for (int i = 0; i < v[s].size(); i++)       if (mark[v[s][i]] == 0) dfs(v[s][i]);   }   int main() {     int n, m, k, sum = 0, com = 0;     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (mark[i] == 0) {         com++;         cnt = 0;         dfs(i);         sum += min(k, cnt);       }     if (k == 1)       cout << max(0, com - 2) << endl;     else       cout << max(0, com - 1 - (sum / 2)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     int i;     cin >> x;     for (i = 0; x[i]; i++) {       if (i == 0 && x[i] == 57)         x[i] = x[i];       else if (x[i] >= 53)         x[i] = (57 - x[i]) + 48;       cout << x[i];     }     return 0;   }