#include <bits/stdc++.h>   using namespace std;   int n, m, ha1[50][50], ha2[50][50], ans1[50][50], ans2[50][50], x = 0, flag = 0;   int main() {     memset(ha1, 0, sizeof(ha1));     memset(ha2, 0, sizeof(ha2));     memset(ans1, 0, sizeof(ans1));     memset(ans2, 0, sizeof(ans2));     cin >> n >> m;     for (int i = 1, xx, yy; i <= n; ++i) {       cin >> xx >> yy;       ha1[xx][yy] = 1;       ha1[yy][xx] = 1;     }     for (int i = 1, xx, yy; i <= m; ++i) {       cin >> xx >> yy;       ha2[xx][yy] = 1;       ha2[yy][xx] = 1;     }     for (int i = 1; i <= 9; ++i)       for (int j = 1; j <= 9; ++j) {         if (i == j) continue;         for (int k = 1; k <= 9; ++k) {           if (k == i || k == j) continue;           if (ha1[i][j] == ha2[i][k] && ha1[i][j]) {             ++ans1[i][j];             ++ans2[i][k];             x = i;           }         }       }     for (int i = 1; i <= 9; ++i)       for (int j = 1; j <= 9; ++j)         if (ans1[i][j]) {           flag++;           break;         }     if (flag == 1) {       cout << x << endl;       return 0;     }     x = 0;     for (int i = 1; i <= 9; ++i)       for (int j = 1; j <= 9; ++j) {         if (i == j) continue;         if ((ans1[i][j] && ans1[j][i]) || (ans2[i][j] && ans2[j][i])) x = -1;       }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int parent[100000], Size[100000];   void init(int n) {     for (int i = 0; i < n; i++) {       parent[i] = i;       Size[i] = 1;     }   }   int Find(int u) {     if (u != parent[u]) parent[u] = Find(parent[u]);     return parent[u];   }   void Union(int u, int v) {     u = Find(u);     v = Find(v);     if (u != v) {       if (Size[u] < Size[v]) swap(u, v);       parent[v] = u;       Size[u] += Size[v];     }   }   int qa[100000], qb[100000], big[100000], table[450][100000] = {};   bool visited[100000] = {}, match[100000] = {};   vector<int> bigVertices, temp[100000], appear[100000];   vector<vector<int>> comp;   vector<pair<int, int>> edges[100000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       a--, b--, c--;       edges[c].emplace_back(a, b);     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> qa[i] >> qb[i];       qa[i]--, qb[i]--;     }     init(n);     for (int c = 0; c < m; c++) {       for (auto e : edges[c]) Union(e.first, e.second);       for (auto e : edges[c]) {         if (!visited[e.first]) {           temp[Find(e.first)].push_back(e.first);           visited[e.first] = true;         }         if (!visited[e.second]) {           temp[Find(e.second)].push_back(e.second);           visited[e.second] = true;         }       }       for (auto e : edges[c]) {         if (!temp[e.first].empty()) {           comp.push_back(temp[e.first]);           temp[e.first].clear();         }         if (!temp[e.second].empty()) {           comp.push_back(temp[e.second]);           temp[e.second].clear();         }         visited[e.first] = visited[e.second] = false;         parent[e.first] = e.first, parent[e.second] = e.second;         Size[e.first] = Size[e.second] = 1;       }     }     for (int i = 0; i < comp.size(); i++)       for (int j = 0; j < comp[i].size(); j++) appear[comp[i][j]].push_back(i);     for (int i = 0; i < n; i++) {       if (appear[i].size() > 450) {         big[i] = bigVertices.size();         bigVertices.push_back(i);       } else         big[i] = -1;     }     for (int i = 0; i < bigVertices.size(); i++)       for (int c : appear[bigVertices[i]])         for (int j : comp[c]) table[i][j]++;     for (int i = 0; i < q; i++) {       int a = qa[i], b = qb[i];       if (big[a] == -1) swap(a, b);       if (big[a] != -1)         cout << table[big[a]][b] <<   n ;       else {         int ret = 0;         for (int c : appear[a]) match[c] = true;         for (int c : appear[b]) ret += match[c];         for (int c : appear[a]) match[c] = false;         cout << ret <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int lp[N + 1];   vector<int> pr;   int i, j, p1, p2, x0, x1, x2, ans;   int main() {     for (i = 2; i <= N; i++) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; j++)         lp[i * pr[j]] = pr[j];     }     cin >> x2;     for (i = pr.size() - 1; i >= 0; i--)       if (x2 % pr[i] == 0) break;     if (x2 == pr[i]) {       cout << x2 << endl;       return 0;     }     p2 = pr[i];     ans = x2 - p2 + 1;     for (j = 0; j < pr.size() && pr[j] <= x2; j++) {       p1 = pr[j];       x1 = ((x2 - p2) / p1 + 1) * p1;       if (x1 > x2) continue;       if (x1 == p1)         x0 = p1;       else         x0 = x1 - p1 + 1;       if (x0 >= 3) ans = min(ans, x0);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 2100000;   const long long N = 210000;   struct node {     long long inx;     long long a, b;     long long m;     long long lt, rt;   };   vector<node> odd_nodes[M];   vector<node> even_nodes[M];   bool cmp(node a, node b) {     if (a.lt == b.lt)       return a.rt > b.rt;     else       return a.lt < b.lt;   }   long long lt_ans[N], rt_ans[N];   set<long long> op;   int main() {     ios::sync_with_stdio(false);     long long tt;     cin >> tt;     while (tt--) {       op.clear();       long long m, n;       cin >> n;       long long a, b;       for (long long i = 0; i < n; i++) {         cin >> a >> b >> m;         long long mn = max(0ll, a - m);         long long tb = b - (m - (a - mn));         long long mx = max(0ll, b - m);         long long ta = a - (m - (b - mx));         long long v = a + b - m;         op.insert(v);         odd_nodes[v].push_back({i, a, b, m, mn - tb, ta - mx});       }       long long ans = 0;       for (auto &u : op) {         auto &p = odd_nodes[u];         if (p.empty()) continue;         sort(p.begin(), p.end(), cmp);         long long st = 0, ed = 1e9;         for (long long i = 0; i < p.size(); i++) {           if (p[i].lt > ed) {             for (long long j = st; j < i; j++) {               long long t = (p[j].a - p[j].b + p[j].m - ed) / 2;               lt_ans[p[j].inx] = t;               rt_ans[p[j].inx] = p[j].m - t;             }             ans++;             ed = p[i].rt;             st = i;           } else {             ed = min(ed, p[i].rt);           }         }         ans++;         for (long long j = st; j < p.size(); j++) {           long long t = (p[j].a - p[j].b + p[j].m - ed) / 2;           lt_ans[p[j].inx] = t;           rt_ans[p[j].inx] = p[j].m - t;         }         p.clear();       }       cout << ans << endl;       for (long long i = 0; i < n; i++)         cout << lt_ans[i] <<     << rt_ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     vector<string> N(a), M(b);     for (auto& i : N) cin >> i;     for (auto& i : M) cin >> i;     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       cout << N[(n - 1) % a] << M[(n - 1) % b] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       s.insert(t);     }     int a, b;     cin >> a >> b;     int res = 0;     while (a > b) {       int mx = 1;       set<int> toerase;       for (set<int>::reverse_iterator it = s.rbegin(); it != s.rend(); ++it) {         int curr = a % *it;         if (a - curr >= b) {           if (curr > mx) mx = curr;         } else {           toerase.insert(*it);         }         if (mx >= *it) break;       }       for (set<int>::iterator it = toerase.begin(); it != toerase.end(); ++it) {         s.erase(*it);       }       a -= mx;       res++;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long LINF = 1LL << 60;   const double inf = 1e15;   long long mod = 1e9 + 7;   char READ_DATA;   int SIGNAL_INPUT;   template <typename Type>   inline Type ru(Type &v) {     SIGNAL_INPUT = 1;     while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 )       if (READ_DATA ==  - )         SIGNAL_INPUT = -1;       else if (READ_DATA == EOF)         return EOF;     v = READ_DATA -  0 ;     while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 )       v = v * 10 + READ_DATA -  0 ;     v *= SIGNAL_INPUT;     return v;   }   inline long long modru(long long &v) {     long long p = 0;     SIGNAL_INPUT = 1;     while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 )       if (READ_DATA ==  - )         SIGNAL_INPUT = -1;       else if (READ_DATA == EOF)         return EOF;     p = v = READ_DATA -  0 ;     while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 ) {       v = (v * 10 + READ_DATA -  0 ) % mod;       p = (p * 10 + READ_DATA -  0 ) % (mod - 1);     }     v *= SIGNAL_INPUT;     return p;   }   template <typename A, typename B>   inline char ru(A &x, B &y) {     if (ru(x) == EOF) return EOF;     ru(y);     return 2;   }   template <typename A, typename B, typename C>   inline char ru(A &x, B &y, C &z) {     if (ru(x) == EOF) return EOF;     ru(y);     ru(z);     return 3;   }   template <typename A, typename B, typename C, typename D>   inline char ru(A &x, B &y, C &z, D &w) {     if (ru(x) == EOF) return EOF;     ru(y);     ru(z);     ru(w);     return 4;   }   struct Edge {     int u, v, next;     long long w, cap, flow;     Edge(int _u = 0, int _v = 0, int nxt = -1, long long _w = 1,          long long _cap = 0) {       u = _u;       v = _v;       w = _w;       cap = _cap;       flow = 0;       next = nxt;     }     int operator<(const Edge &b) const { return w < b.w; }   };   const int maxn = 2e6 + 3, N = 2e7, SZ = 21;   double eps = 1e-7, pi = acos(-1.0);   long long seed = 131, smod = (1LL << 32) - 267;   long long a, b, p, n;   long long sp(long long a, long long b, long long mod) {     long long ans = 1, x = a;     while (b) {       if (b & 1) (ans *= x) %= mod;       (x *= x) %= mod;       b >>= 1;     }     return ans;   }   long long c[maxn];   long long ans1, ans2;   int main() {     cin >> a >> b >> p >> n;     c[0] = 1;     for (register int j = 1; j < p; ++j) c[j] = c[j - 1] * a % p;     for (register int j = 1; j < p; ++j) {       long long y = c[j * (p - 2) % (p - 1)] * b % p;       long long t = (j - y + p) % p;       if (t * (p - 1) + j > n) continue;       long long u = ((n - j) / (p - 1) - t) / p;       ans2 += (u + 1);     }     cout << ans2;   }


#include <bits/stdc++.h>   using namespace std;   void change(char &x) {     if (x ==  B )       x =  W ;     else       x =  B ;   }   int main() {     string s;     int n;     cin >> n;     cin >> s;     int w = 0, b = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  B )         b++;       else         w++;     }     if (b % 2 != 0 && w % 2 != 0) {       cout << -1;       return 0;     }     string c = s;     vector<int> vec1, vec2;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  B ) {         vec1.push_back(i + 1);         if (s[i] ==  B ) change(s[i]);         change(s[i + 1]);       }     }     if (s[n - 1] ==  W ) {       cout << vec1.size() << endl;       for (int i = 0; i < vec1.size(); i++) cout << vec1[i] <<    ;       return 0;     }     for (int i = 0; i < n - 1; i++) {       if (c[i] ==  W ) {         vec2.push_back(i + 1);         change(c[i]);         change(c[i + 1]);       }     }     if (s[n - 1] ==  B ) {       cout << vec2.size() << endl;       for (int i = 0; i < vec2.size(); i++) cout << vec2[i] <<    ;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   inline int chkmax(T &x, const T2 &y) {     return x < y ? x = y, 1 : 0;   }   template <class T, class T2>   inline int chkmin(T &x, const T2 &y) {     return x > y ? x = y, 1 : 0;   }   const int MAXN = (1 << 20);   int n, m;   int64_t g[MAXN], b[MAXN];   void read() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < m; i++) cin >> g[i];   }   void solve() {     sort(b, b + n);     sort(g, g + m);     if (b[n - 1] > g[0]) {       cout << -1 <<   n ;       return;     }     int64_t answer = 0;     for (int i = 0; i < n; i++) answer += b[i] * 1ll * m;     for (int i = m - 1; i >= 0; i--) answer += g[i];     if (b[n - 1] == g[0])       answer -= m * 1ll * b[n - 1];     else {       answer -= (m - 1) * 1ll * b[n - 1];       answer -= b[n - 2];     }     cout << answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     long long sum = 0, z = 0, s = 0, m = 0, mm = 0;     cin >> n;     vector<long long> a(n);     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < (n - 1); i++) {       if (i % 2 == 0)         sum = sum + abs(a[i + 1] - a[i]);       else         sum = max(z, sum - abs(a[i + 1] - a[i]));       m = max(m, sum);     }     for (i = 1; i < (n - 1); i++) {       if (i % 2 == 1)         s = s + abs(a[i + 1] - a[i]);       else         s = max(z, s - abs(a[i + 1] - a[i]));       m = max(s, m);     }     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100];     cin >> n;     int i, loce, loco, even = 0, odd = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) {         even++;         loce = i;       }       if (a[i] % 2 == 1) {         odd++;         loco = i;       }     }     if (odd > even) {       cout << loce + 1;     } else {       cout << loco + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mInv[41];   long long fact[41];   long long factInv[41];   map<long, long> mymap;   long long heights[5];   long long segTree[3];   long nums[5005];   long g[5005];   vector<long> primes;   vector<long> badPrimes;   long funcVal[1000006];   long long N;   set<string> dictionary;   set<string>::iterator it;   pair<set<string>::iterator, bool> ret;   long long gcd(long long a, long long b) {     if (b == 0) return a;     if (a % b == 0) return b;     return gcd(b, a % b);   }   long long getmoduloInv(long long n) {     if (n == 1) return 1;     if (mInv[n] > 0) return mInv[n];     long long m = (-1 * 1000000007) / n;     m += 1000000007;     m *= getmoduloInv(1000000007 % n);     mInv[n] = (m % 1000000007);     return mInv[n];   }   vector<long> get_primes(unsigned long maxN) {     char *sieve;     sieve = new char[maxN / 8 + 1];     long m = (maxN / 8) + 1;     for (long long i = 0; i < m; i++) sieve[i] = 255;     for (unsigned long x = 2; x <= maxN; x++)       if (sieve[x / 8] & (0x01 << (x % 8))) {         primes.push_back(x);         for (unsigned long j = 2 * x; j <= maxN; j += x)           sieve[j / 8] &= ~(0x01 << (j % 8));       }     delete[] sieve;     return primes;   }   long long getPow(long long b, long long p) {     if (b < 2 || p == 1) return b;     if (p == 0) return 1;     long long val = getPow(b, p / 2);     val *= val;     val %= 1000000007;     if (p % 2 == 1) {       val *= b;       val %= 1000000007;     }     return val;   }   void buildSegTree(long node, long b, long e) {     if (b == e)       segTree[node] = b;     else {       long mid = (b + e) / 2;       buildSegTree(node * 2, b, mid);       buildSegTree(1 + node * 2, mid + 1, e);       if (heights[segTree[node * 2]] <= heights[segTree[1 + node * 2]])         segTree[node] = segTree[node * 2];       else         segTree[node] = segTree[1 + node * 2];     }   }   long long getMin(long node, long segBeg, long segEnd, long qBeg, long qEnd) {     if (segEnd < qBeg || segBeg > qEnd) return N + 1;     if (segBeg >= qBeg && segEnd <= qEnd) return segTree[node];     long mid = (segBeg + segEnd) / 2;     long fh = getMin(node * 2, segBeg, mid, qBeg, qEnd);     long sh = getMin(1 + node * 2, mid + 1, segEnd, qBeg, qEnd);     if (heights[sh] < heights[fh]) return sh;     return fh;   }   string genMinString(long long val) {     long len = val / 9, firstDigit = val % 9;     string s =   ;     if (firstDigit > 0) {       char ch =  0  + firstDigit;       s = ch + s;     }     for (long i = 0; i < len; i++) s = s +  9 ;     return s;   }   long maxBuild;   vector<long> mult(vector<long> A, vector<long> B) {     long len1 = A.size(), len2 = B.size();     vector<long> C;     for (long i = 0; i < len1; i++) {       long carry = 0;       for (long j = 0; j < len2; j++) {         long pos = i + j;         long val = carry + (A[i] * B[j]);         carry = val / 10;         val = val % 10;         if (pos >= C.size()) {           C.push_back(val);         } else {           C[pos] += val;           carry = C[pos] / 10;           C[pos] = C[pos] % 10;         }       }       if (carry > 0) C.push_back(carry);     }     return C;   }   vector<long> getVal(long power) {     vector<long> C;     C.push_back(5);     if (power == 1) return C;     vector<long> B = getVal(power / 2);     B = mult(B, B);     if (power % 2 == 1) B = mult(B, C);     return B;   }   long getZeros(long fives) {     long ans = 0;     while (fives > 0) {       ans += fives;       fives /= 5;     }     return ans;   }   long long getPow(long zeros) {     long val = ((zeros * 4) / 5) - 1;     while (getZeros(val) < zeros) val++;     if (getZeros(val) == zeros) return val;     return -1;   }   long long rowVal[5050], colVal[5050];   long long rowAlter[5050], colAlter[5050];   int main(void) {     long long test_cases = 1, l, r, seed = 1, maxVal;     vector<string> originalStrings;     long long curNum;     long long m, n, k;     long long ans = 0;     for (long T = 0; T < test_cases; T++) {       cin >> n >> m >> k;       long rv, cv, av;       memset(rowVal, 0, sizeof(rowVal));       memset(colVal, 0, sizeof(colVal));       memset(rowAlter, -1, sizeof(rowAlter));       memset(colAlter, -1, sizeof(colAlter));       for (long i = 0; i < k; i++) {         scanf( %ld , &av);         scanf( %ld , &rv);         rv--;         scanf( %ld , &cv);         if (av == 1) {           rowVal[rv] = cv;           rowAlter[rv] = i;         } else {           colVal[rv] = cv;           colAlter[rv] = i;         }       }       for (long i = 0; i < n; i++) {         for (long j = 0; j < m; j++) {           if (rowAlter[i] > colAlter[j])             printf( %ld  , rowVal[i]);           else             printf( %ld  , colVal[j]);         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int an[333333];   int bit[333333];   void upd(int x, int v) {     for (int i = x; i <= n; i += (i & -i)) {       bit[i] += v;     }   }   int get(int x) {     int an = 0;     for (int i = x; i > 0; i -= (i & -i)) an += bit[i];     return an;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) upd(i, 1);     while (m--) {       int from, to, win;       scanf( %d%d%d , &from, &to, &win);       int add = get(to);       int dec = get(from - 1);       while (add > dec) {         int ll = from, rr = to;         while (ll <= rr) {           int mid = (ll + rr) / 2;           if (get(mid) == dec)             ll = mid + 1;           else             rr = mid - 1;         }         an[ll] = win;         upd(ll, -1);         --add;       }       an[win] = 0;       upd(win, 1);     }     for (int i = 1; i <= n; ++i) printf( %d  , an[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 5;   const int mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int a[n + 5], mx = 0;     long long sum = 0;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i], mx = max(mx, a[i]);     sum -= mx;     cout << (mx - sum + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int prev = arr[0], best = -1, num, left = 0;     for (int i = 0; i < n; i++) {       k -= (0LL + i - left) * (arr[i] - prev);       while (k < 0) {         k += arr[i] - arr[left++];       }       if (best < i - left + 1) {         best = i - left + 1;         num = arr[i];       }       prev = arr[i];     }     cout << best <<     << num << endl;     return 0;   }


#include <bits/stdc++.h>   int g[1010][1010];   int main() {     int n, k, ans, i, j;     while (~scanf( %d%d , &n, &k)) {       ans = 0;       memset(g, 0, sizeof(g));       for (i = 0; i < n; i++)         for (j = i + 1; j <= i + k; j++) g[i][j % n] = 1, ans++;       int flag = 1;       for (i = 0; i < n; i++)         for (j = 0; j < n; j++)           if (g[i][j] && g[j][i]) flag = 0;       if (flag) {         printf( %d n , ans);         for (i = 0; i < n; i++)           for (j = 0; j < n; j++)             if (g[i][j]) printf( %d %d n , i + 1, j + 1);       } else         puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   struct node {     int a, b, w;   } p[200005];   int fa[200005];   bool d[200005];   bool cmp(node x, node y) { return x.w > y.w; }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     int n, m, ans = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &p[i].a, &p[i].b, &p[i].w);     }     std::sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= n; i++) {       fa[i] = i;       d[i] = true;     }     for (int i = 1; i <= m; i++) {       int x = find(p[i].a);       int y = find(p[i].b);       if (x != y && (d[x] || d[y])) {         fa[y] = x;         ans += p[i].w;         d[x] = d[x] & d[y];       } else if (x == y && d[x]) {         d[x] = false;         ans += p[i].w;       }     }     printf( %d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define ll long long int   using namespace std;      int t;      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       int n;       cin >> n;       int sum=0;       int odd=-1;       vector<int> a(n);       for (int q=0;q<n;q++){           int x;           cin>>x;           a[q]=x;           sum+=x;           if (odd==-1 && x%2==1){               odd=q;           }       }       if (sum%2==1){           cout<<0<<  n ;       }else{           int s=sum/2;           bool dp[n+1][s+1];           for (int i=0;i<=n;i++){               dp[i][0]=true;           }           for (int j=1;j<=s;j++){               dp[0][j]=false;           }           for (int i=1;i<=n;i++){               for (int j=1;j<=s;j++){                   if (dp[i-1][j]==true){                       dp[i][j]=true;                   }else{                       if (a[i-1]>j){                           dp[i][j]=false;                       }else{                           dp[i][j]=dp[i-1][j-a[i-1]];                       }                   }               }           }           if (dp[n][s]==false){               cout<<0<<  n ;           }else{               if (odd!=-1){                   cout<<1<<  n ;                   cout<<odd+1<<  n ;               }else{                   int idx=-1;                   int mn=33;                   for (int i=0;i<n;i++){                       if (mn > __builtin_ctz(a[i])){                           mn=__builtin_ctz(a[i]);                           idx=i;                       }                   }                   cout<<1<<  n ;                   cout<<idx+1<<  n ;               }           }       }          }


#include <bits/stdc++.h>   using namespace std;   int pre[100010];   char f[100010];   int a[100010];   int ans[100010];   int main() {     int n, m, i, c, cnt = 0;     scanf( %d , &n);     scanf( %d , &m);     for (i = 0; i < n; ++i) {       scanf( %c , &f[i]);       scanf( %c , &f[i]);       scanf( %d , &a[i]);       --a[i];       if (f[i] ==  + ) {         pre[a[i]]++;         pre[a[i] + 1]--;       } else {         if (a[i]) {           pre[0]++;           pre[a[i]]--;         }         pre[a[i] + 1]++;       }     }     if (pre[0] == m) {       ans[0] = 1;       cnt++;     } else {       ans[0] = 0;     }     for (i = 1; i < n; ++i) {       pre[i] = pre[i - 1] + pre[i];       if (pre[i] == m) {         ans[i] = 1;         cnt++;       } else {         ans[i] = 0;       }     }     if (cnt > 1)       for (i = 0; i < n; ++i)         if (ans[i] == 1) ans[i] = -1;     for (i = 0; i < n; ++i) {       if (f[i] ==  + ) {         if (ans[a[i]] == 1)           printf( Truth n );         else if (ans[a[i]] == 0)           printf( Lie n );         else           printf( Not defined n );       } else {         if (ans[a[i]] == 0)           printf( Truth n );         else if (ans[a[i]] == 1)           printf( Lie n );         else           printf( Not defined n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int vis[500500];   int a[500500];   int b[500500];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int j = 0; j < n; j++) cin >> b[j];     int ans = 0;     int j = 0;     for (int i = 0; i < n; i++) {       if (vis[a[i]]) continue;       while (j < n && b[j] != a[i]) {         vis[b[j]] = 1;         ans++;         j++;       }       if (j < n && a[i] == b[j]) j++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, u, r;   long long ans = -1e18;   long long a[35], b[35], k[35], p[35];   void calc(long long aa[]) {     long long mx = 0;     for (int i = 1; i <= n; i++) mx += aa[i] * k[i];     ans = (ans > mx ? ans : mx);   }   void dfs(long long depth, long long aa[]) {     if (depth == u) {       calc(aa);       return;     }     long long t1[35], t2[35];     for (int i = 1; i <= n; i++) t1[i] = aa[i] ^ b[i];     if ((u - depth) % 2)       calc(t1);     else       calc(aa);     for (int i = 1; i <= n; i++) t2[i] = aa[p[i]] + r;     dfs(depth + 1, t2);     if (depth <= u - 2) {       for (int i = 1; i <= n; i++) t2[i] = t1[p[i]] + r;       dfs(depth + 2, t2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> u >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) cin >> p[i];     dfs(0, a);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, q;     cin >> n >> q;     vector<int> res(n + 1, 0);     vector<vector<int>> adjacenyList(n + 1);     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adjacenyList[u].emplace_back(v);       adjacenyList[v].emplace_back(u);     }     function<void(int, int)> DFS = [&](int u, int val) {       res[u] = val;       for (int v : adjacenyList[u]) {         if (res[v]) continue;         DFS(v, min(v, val));       }     };     int c = 0, l = 0;     int t, x;     cin >> t >> x;     x = (x + l) % n + 1;     c = x;     DFS(x, x);     while (--q) {       cin >> t >> x;       x = (x + l) % n + 1;       if (t & 1) {         c = min(c, res[x]);       } else {         l = min(c, res[x]);         cout << l <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int arr[205];   int u[100005], v[100005], f[100005];   int lvl[205], ptr[205];   bool vis[205];   vector<int> graph[205];   vector<int> cgraph[205];   vector<vector<int>> vec;   void addedge(int a, int b, int k) {     u[K] = a;     v[K] = b;     u[K ^ 1] = b;     v[K ^ 1] = a;     f[K] = k;     graph[a].push_back(K);     graph[b].push_back(K ^ 1);     K += 2;   }   bool bfs() {     queue<int> qu;     qu.push(0);     fill(lvl, lvl + N + 2, 0);     lvl[0] = 1;     while (qu.size()) {       int n = qu.front();       qu.pop();       for (int e : graph[n]) {         if (f[e] && !lvl[v[e]]) {           lvl[v[e]] = lvl[u[e]] + 1;           qu.push(v[e]);         }       }     }     return lvl[N + 1];   }   int dfs(int n, int p) {     if (n == N + 1 || !p) {       return p;     }     for (int &i = ptr[n]; i < graph[n].size(); i++) {       int e = graph[n][i];       if (f[e] && lvl[v[e]] > lvl[n]) {         int k = dfs(v[e], min(f[e], p));         if (!k) {           continue;         }         f[e] -= k;         f[e ^ 1] += k;         return k;       }     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> arr[i];       if (arr[i] % 2 == 1) {         addedge(0, i, 2);       } else {         addedge(i, N + 1, 2);       }     }     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (arr[i] % 2 == 1 && arr[j] % 2 == 0) {           bool isp = 1;           for (int k = 2; k <= sqrt(arr[i] + arr[j]); k++) {             if ((arr[i] + arr[j]) % k == 0) {               isp = 0;               break;             }           }           if (isp) {             addedge(i, j, 1);           }         }       }     }     int ans = 0;     while (1) {       if (!bfs()) {         break;       }       fill(ptr, ptr + 2 + N, 0);       int p;       while ((p = dfs(0, INT_MAX / 2))) {         ans += p;       }     }     if (ans != N) {       cout <<  Impossible n ;       return 0;     }     for (int e = 1; e < K; e += 2) {       if (f[e] && u[e] != 0 && v[e] != 0 && u[e] != N + 1 && v[e] != N + 1) {         cgraph[v[e]].push_back(u[e]);         cgraph[u[e]].push_back(v[e]);       }     }     for (int n = 1; n <= N; n++) {       if (!vis[n]) {         int c = n;         vector<int> temp;         while (!vis[c]) {           temp.push_back(c);           vis[c] = 1;           for (int e : cgraph[c]) {             if (!vis[e]) {               c = e;             }           }         }         vec.push_back(temp);       }     }     cout << vec.size() <<   n ;     for (auto k : vec) {       cout << k.size() <<    ;       for (int n : k) {         cout << n <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     scanf( %d%d , &n, &k);     if (k >= (n * (n - 1)) / 2)       puts( no solution );     else {       for (int i = 0, t = 1; t <= n; t++) printf( %d %d n , i, t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > a;   vector<int> color;   int n, m;   long long ans = 0;   void brut(int v) {     if (v == n) {       set<pair<int, int> > q;       vector<bool> find(n, false);       for (int i = 0; i < n; ++i) {         for (int j : a[i]) {           if (j < i) continue;           if (color[i] == -1 && color[j] == -1) continue;           if (color[i] == -1 || color[j] == -1) continue;           pair<int, int> temp = {color[i], color[j]};           if (temp.second < temp.first) swap(temp.first, temp.second);           if (q.find(temp) != q.end()) continue;           find[i] = find[j] = true;           q.insert(temp);           break;         }       }       for (int i = 0; i < n; ++i) {         for (int j : a[i]) {           if (j < i) continue;           if (color[i] == -1 && color[j] == -1) continue;           if (color[i] == -1 || color[j] == -1) continue;           pair<int, int> temp = {color[i], color[j]};           if (temp.second < temp.first) swap(temp.first, temp.second);           if (q.find(temp) != q.end()) continue;           find[i] = find[j] = true;           q.insert(temp);         }       }       for (int i = 0; i < n; ++i)         if (color[i] != -1 && !find[i]) return;       ans = max(ans, (long long)q.size());       return;     }     for (int i = -1; i < 6; ++i) {       color[v] = i;       brut(v + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     a.resize(n);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       a[x].push_back(y);       a[y].push_back(x);     }     color.resize(n);     brut(0);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long n, x, y, z, ans;   long long a[N], b[N], par[N], sz[N];   long long get(long long x) {     if (par[x] == x) return x;     return par[x] = get(par[x]);   }   void merge(long long x, long long y) {     long long root_a = get(x);     long long root_b = get(y);     if (root_a == root_b) {       return;     }     if (sz[root_a] < sz[root_b]) {       par[root_a] = par[root_b];       sz[root_b] += sz[root_a];     } else {       par[root_b] = par[root_a];       sz[root_a] += sz[root_b];     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       long long n;       for (long long i = 0; i < N; i++) {         par[i] = i;         sz[i] = 1;       }       cin >> n;       for (long long i = 1; i < n + 1; i++) cin >> a[i];       for (long long i = 1; i < n + 1; i++) cin >> b[i];       for (long long i = 1; i < n + 1; i++) {         long long left = i - b[i];         long long right = i + b[i];         long long p1 = get(i);         if (left >= 1) {           long long p2 = get(left);           if (p1 != p2) merge(p1, p2);         }         if (right <= n) {           long long p2 = get(right);           if (p1 != p2) merge(p1, p2);         }       }       long long f = 0;       for (long long i = 1; i < n + 1; i++) {         long long p1 = get(i);         long long p2 = get(a[i]);         if (p1 != p2) f = 1;       }       if (f)         cout <<  NO n ;       else         cout <<  YES n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   template <typename Tp>   inline void read(Tp &x) {     static char c;     static bool neg;     x = 0, c = getchar(), neg = false;     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = true;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (neg) {       x = -x;     }   }   const int N = 100000 + 5;   int n, w, q;   int a[N], b[N];   int mn[N], mx[N], ans[N];   inline void checkMax(int &x, const int &y) {     if (x < y) {       x = y;     }   }   inline void checkMin(int &x, const int &y) {     if (x > y) {       x = y;     }   }   int main() {     read(n), read(w), read(q);     for (int i = 0; i < n; ++i) {       read(a[i]);     }     for (int i = 0, x; i < q; ++i) {       read(x);       b[i] = w - x;     }     fill(mn, mn + q, a[0]);     fill(mx, mx + q, a[0]);     for (int j = 1; j < n; ++j) {       for (int i = 0; i < q; ++i) {         checkMax(mx[i], a[j]);         checkMin(mn[i], a[j]);         if (mx[i] - mn[i] > b[i]) {           ++ans[i];           mn[i] = mx[i] = a[j];         }       }     }     for (int i = 0; i < q; ++i) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline void priv(vector<int> a) {     for (int i = 0; i < ((int)(a).size()); ++i)       printf( %d%c , a[i], i == (int)(a).size() - 1 ?   n  :    );   }   template <typename T>   istream& operator>>(istream& i, vector<T>& v) {     for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(vector<T>& v) {     stringstream s;     for (int i = 0; i < ((int)(v).size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   ostream& operator<<(ostream& o, vector<T>& v) {     if ((int)(v).size()) o << join(v);     return o;   }   template <typename T1, typename T2>   istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& o, pair<T1, T2>& v) {     return o << v.first <<  ,  << v.second;   }   const int MX = 100005, INF = 1001001001;   const long long int LINF = 1e18;   const double eps = 1e-10;   int main() {     int n;     scanf( %d , &n);     vector<int> x;     long long int sum = 0;     for (int i = 0; i < (n); ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       if (a <= d && b <= c) continue;       long long int s = a + b, t = c + d;       if (s <= t) {         if (a <= d)           sum += c - b;         else           sum += a - d;       } else {         sum += a + c;         x.push_back(s);         x.push_back(t);       }     }     sort(x.begin(), x.end());     reverse(x.begin(), x.end());     for (int i = 0; i < ((int)(x).size()); ++i) {       if (i & 1) sum -= x[i];     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long n, count = 0;       cin >> n;       long long a[100005];       for (int i = 0; i < n; i++) cin >> a[i];       if (n == 1)         cout <<  1  << endl;       else {         for (int i = 0; i < n; i++) {           for (int j = i + 1; j < n; j++) {             if ((a[i] - a[j]) == 1 || (a[i] - a[j] == -1)) count++;           }         }         if (count > 0)           cout <<  2  << endl;         else           cout <<  1  << endl;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;      #define ll long long int   #define pll pair<ll, ll>   #define vl vector<ll>   #define pb push_back   #define pp pop_back   #define f(i, a, b) for (ll i = a; i < b; ++i)   #define rev(i, a, b) for (ll i = a; i >= b; --i)   #define print(x) cout << x << endl   #define endl   n    #define F first   #define S second   #define setbits(x) __builtin_popcountll(x)   #define zerobits(x) __builtin_ctzll(x)   #define to(n) to_string(n)   #define low(v, n) lower_bound(v.begin(), v.end(), n) - v.begin()   #define upp(v, n) upper_bound(v.begin(), v.end(), n) - v.begin()   #define mod 998244353   #define mex 100005      ll power(ll x, ll y)   {       if (y == 0)       {           return 1;       }       if (y % 2 == 0)       {           return power((x % mod) * (x % mod), y / 2) % mod;       }       else       {           return ((x % mod) * power((x % mod) * (x % mod), y / 2) % mod);       }   }      ll modinverse(ll a, ll m)   {       return power(a, m - 2);   }      ll ncr(ll n, ll r)   {       ll k = min(r, n - r);       ll result = 1;       ll divide = 1;          f(i, 1, k + 1)       {           result = ((result % mod) * ((n + 1 - i) % mod)) % mod;           divide = ((divide % mod) * (i % mod)) % mod;       }          result = (result * modinverse(divide, mod)) % mod;       return result;   }      int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);          ll t;       cin >> t;       while (t--)       {           ll n;           cin >> n;           string s;           cin >> s;              ll p = 0;           ll q = 0;           ll i = 0;           while (i < n)           {               if (s[i] ==  0 )               {                   p++;                   ++i;               }               else if (s[i] ==  1  && i + 1 < n && s[i + 1] ==  1 )               {                   q++;                   i += 2;               }               else               {                   ++i;               }           }              print(ncr(p + q, p));       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int N, M;   long long f(int a, int b) {     long long res = 1;     for (int i = 1; i <= a; i++) {       int ii = i;       while (b > 0 && ii % 2 == 0) {         ii /= 2;         b--;       }       res = (res * ii) % M;     }     return res;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       v.push_back(make_pair(x, i + 1));     }     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       v.push_back(make_pair(x, i + 1));     }     scanf( %d , &M);     sort(v.begin(), v.end());     long long res = 1;     int cnt = 0;     int b = 0;     for (int i = 0; i < N * 2; i++) {       if (i > 0 && v[i].first != v[i - 1].first) {         res = (res * f(cnt, b)) % M;         cnt = 1;         b = 0;       } else {         if (i != 0 && v[i] == v[i - 1]) b++;         cnt++;       }     }     res = (res * f(cnt, b)) % M;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d  %d , &a, &b);     int diff, same, total;     total = a + b;     if (a > b) {       diff = b;     } else {       diff = a;     }     same = (total - (2 * diff)) / 2;     printf( %d  %d n , diff, same);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 40005;   const int M = 1005;   const int Q = 1000000007;   const int P = 10000019;   int n, m, q, tot;   int v[N], w[N], Ask[N], f[N], id[N];   int g[M], dp[N * 4];   vector<int> T[N * 4];   void Build(int s, int x, int y, int l, int r, int k) {     if (l <= x && y <= r) {       T[s].push_back(k);       return;     }     int Mid = (x + y) / 2;     int t = s + s;     if (l <= Mid) Build(t, x, Mid, l, r, k);     if (Mid < r) Build(t + 1, Mid + 1, y, l, r, k);   }   void Make(int s, int x, int y) {     if (x == y) {       dp[s] = Ask[x];       return;     }     int Mid = (x + y) / 2;     int t = s + s;     Make(t, x, Mid);     Make(t + 1, Mid + 1, y);     dp[s] = dp[t] | dp[t + 1];   }   void Add(int dp[M], int y, int x) {     for (int i = m; i >= x; i--) dp[i] = max(dp[i], dp[i - x] + y);   }   void print() {     int Ans = 0;     for (int i = m; i; i--) Ans = (1LL * P * Ans + g[i]) % Q;     printf( %d n , Ans);   }   void Work(int s, int x, int y) {     if (!dp[s]) return;     int Mid = (x + y) / 2;     int tmp[N];     for (int i = 0; i <= m; i++) tmp[i] = g[i];     for (int j = 0; j < T[s].size(); j++) Add(g, v[T[s][j]], w[T[s][j]]);     if (x == y) {       print();       for (int i = 0; i <= m; i++) g[i] = tmp[i];       return;     }     int t = s + s;     Work(t, x, Mid);     Work(t + 1, Mid + 1, y);     for (int i = 0; i <= m; i++) g[i] = tmp[i];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &v[i], &w[i]);       f[i] = 1;       id[i] = i;     }     scanf( %d , &q);     tot = n;     for (int i = 1; i <= q; i++) {       int x;       scanf( %d , &x);       if (x == 1) {         tot++;         scanf( %d%d , &v[tot], &w[tot]);         f[tot] = 1;         id[tot] = n + i;       } else if (x == 2) {         int y;         scanf( %d , &y);         Build(1, 1, n + q, id[y], n + i, y);         f[y] = 0;       } else if (x == 3) {         Ask[n + i] = 1;       }     }     for (int i = 1; i <= n; i++)       if (f[i]) Add(g, v[i], w[i]);     for (int i = n + 1; i <= tot; i++)       if (f[i]) Build(1, 1, n + q, id[i], n + q, i);     Make(1, 1, n + q);     Work(1, 1, n + q);     return 0;   }


#include <bits/stdc++.h>   class Scanner {    private:     static const int BUFFER_SIZE = 1 << 18;     char buff[BUFFER_SIZE];     char *buffPos, *buffLim;     FILE* file;       public:     Scanner(FILE* file) {       this->file = file;       buffLim = buff + fread(buff, 1, BUFFER_SIZE, file);       buffPos = buff;     }       private:     inline void flushBuff() {       buffLim = buff + fread(buff, 1, BUFFER_SIZE, file);       if (buffLim == buff) {         *buffLim++ =   n ;       }       buffPos = buff;     }     inline bool isWS(char t) { return t <=    ; }     inline bool isDig(char t) { return t >=  0  && t <=  9 ; }     inline void nextPos() {       buffPos++;       if (buffPos == buffLim) {         flushBuff();       }     }       public:     inline char getchar() {       char ch = *buffPos;       nextPos();       return ch;     }     inline void next(char* s) {       while (isWS(*buffPos)) {         nextPos();       }       while (!isWS(*buffPos)) {         *s = *buffPos;         s++;         nextPos();       }       *s =   0 ;     }     inline void nextLine(char* s) {       while (*buffPos !=   n ) {         nextPos();       }       if (*buffPos ==   n ) {         nextPos();       }       while (*buffPos !=   n ) {         *s++ = *buffPos;         nextPos();       }       *s =   0 ;     }     inline int nextInt() {       while (!isDig(*buffPos) && *buffPos !=  - ) {         nextPos();       }       int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       int res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos();       }       return res * sign;     }     inline long long nextLong() {       while (!isDig(*buffPos) && *buffPos !=  - ) {         nextPos();       }       long long sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       long long res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos();       }       return res * sign;     }     inline int n() {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       int res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = res * 10 + (*buffPos -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nl() {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = res * 10 + (*buffPos -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nlm(const int MOD) {       while (*buffPos <  0  || *buffPos >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (*buffPos >=  0  && *buffPos <=  9 ) {         res = (res * 10 + (*buffPos -  0 )) % MOD;         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline double nextDouble() {       while (isWS(*buffPos)) {         nextPos();       }       int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1;       double res = 0;       while (isDig(*buffPos)) {         res = res * 10 + *buffPos -  0 ;         nextPos();       }       if (*buffPos ==  . ) {         nextPos();         double ep = 1;         while (isDig(*buffPos)) {           ep *= 0.1;           res += ep * (*buffPos -  0 );           nextPos();         }       }       return sign * res;     }     inline char nextChar() {       while (isWS(*buffPos)) nextPos();       char res = *buffPos;       nextPos();       return res;     }     ~Scanner() { fclose(file); }   };   Scanner sc(stdin);   template <class __TyFirst, class __TySecond>   std::ostream& operator<<(std::ostream& out,                            const std::pair<__TyFirst, __TySecond>& o);   static std::string cout_list_sep =    ;   template <       class IterateType, typename = decltype(std::declval<IterateType>().begin()),       typename = decltype(std::declval<IterateType>().end()),       typename = typename std::enable_if<std::is_convertible<           typename std::iterator_traits<               typename IterateType::iterator>::iterator_category,           std::input_iterator_tag>::value>::type,       typename = typename std::enable_if<!std::is_base_of<           std::string, typename std::decay<IterateType>::type>::value>::type,       typename value_type = typename IterateType::value_type>   std::ostream& operator<<(std::ostream& out, const IterateType& a) {     for (const auto& i : a) out << i << cout_list_sep;     return out;   }   template <class __TyFirst, class __TySecond>   std::ostream& operator<<(std::ostream& out,                            const std::pair<__TyFirst, __TySecond>& o) {     out <<  (  << o.first <<  ,  << o.second <<  ) ;     return out;   }   template <typename _ForwardIterator>   void logArray(_ForwardIterator, _ForwardIterator, const char* = 0) {}   namespace Temps {   template <typename _IntType>   class RangeInt {     static_assert(std::is_integral<_IntType>::value,                    RangeInt object must have integral value type );       public:     class iterator : public std::iterator<std::input_iterator_tag, _IntType,                                           _IntType, const _IntType*, _IntType> {       _IntType val, step;         public:       using typename std::iterator<std::input_iterator_tag, _IntType, _IntType,                                    const _IntType*, _IntType>::reference;       explicit constexpr iterator(int val, int step) noexcept           : val(val), step(step) {}       constexpr iterator& operator++() noexcept {         val += step;         return *this;       }       constexpr iterator operator++(int) noexcept {         iterator ret = *this;         val += step;         return ret;       }       constexpr bool operator==(const iterator& rhs) const noexcept {         return val == rhs.val;       }       constexpr bool operator!=(const iterator& rhs) const noexcept {         return val != rhs.val;       }       constexpr reference operator*() const { return val; }     };     const _IntType _begin, _step, _end;     explicit constexpr RangeInt(const _IntType end) noexcept         : _begin(0), _step(1), _end(end > 0 ? end : 0) {}     explicit constexpr RangeInt(const _IntType begin, const _IntType end) noexcept         : _begin(begin), _step(1), _end(end > begin ? end : begin) {}     explicit constexpr RangeInt(const _IntType begin, const _IntType end,                                 const _IntType step)         : _begin(begin),           _step(step),           _end(((step > 0 && end <= begin) || (step < 0 && end >= begin))                    ? begin                    : (step > 0                           ? begin + (end - begin + step - 1) / step * step                           : begin + (begin - end - step - 1) / (-step) * step)) {}     constexpr iterator begin() const noexcept { return iterator(_begin, _step); }     constexpr iterator end() const noexcept { return iterator(_end, _step); }     constexpr _IntType size() const noexcept { return (_end - _begin) / _step; }   };   template <class IntType, typename = typename std::enable_if<                                std::is_integral<IntType>::value>::type>   inline constexpr RangeInt<IntType> range(IntType arg1) {     return RangeInt<IntType>(arg1);   }   template <class IntType, typename = typename std::enable_if<                                std::is_integral<IntType>::value>::type>   inline constexpr RangeInt<IntType> range(IntType arg1, IntType arg2) {     return RangeInt<IntType>(arg1, arg2);   }   template <class IntType, typename = typename std::enable_if<                                std::is_integral<IntType>::value>::type>   inline constexpr RangeInt<IntType> range(IntType arg1, IntType arg2,                                            IntType arg3) {     return RangeInt<IntType>(arg1, arg2, arg3);   }   }  // namespace Temps   using Temps::range;   namespace Temps {   template <class T>   inline bool checkMin(T& a, T b) {     return (b < a ? a = b, 1 : 0);   }   template <class T>   inline bool checkMax(T& a, T b) {     return (a < b ? a = b, 1 : 0);   }   template <class IntType, typename = typename std::enable_if<                                std::is_integral<IntType>::value>::type>   IntType gcd(const IntType a, const IntType b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class ForwardIterator, class OutputIterator>   void dissociate(ForwardIterator __begin, ForwardIterator __end,                   OutputIterator __dest) {     std::vector<typename std::iterator_traits<ForwardIterator>::_IntType> values(         __begin, __end);     std::sort(values.begin(), values.end());     std::unique(values.begin(), values.end());     while (__begin != __end) {       *__dest =           static_cast<typename std::iterator_traits<OutputIterator>::_IntType>(               std::distance(                   values.begin(),                   std::lower_bound(values.begin(), values.end(), *__begin)));       __dest++;       __begin++;     }   }   }  // namespace Temps   using Temps::checkMax;   using Temps::checkMin;   namespace Temps {   template <class Type>   class Vector {     static_assert(std::is_trivial<Type>::value,                    Temps::Vector can only be used for trival types );       public:     typedef Type& reference;     typedef const Type& const_reference;     class iterator : public std::iterator<std::random_access_iterator_tag, Type> {      public:       friend class Vector;       using typename std::iterator<std::random_access_iterator_tag,                                    Type>::difference_type;       using           typename std::iterator<std::random_access_iterator_tag, Type>::pointer;       using typename std::iterator<std::random_access_iterator_tag,                                    Type>::reference;         private:       pointer ptr;       iterator(pointer ptr) : ptr(ptr) {}         public:       bool operator==(const iterator rhs) const { return ptr == rhs.ptr; }       bool operator!=(const iterator rhs) const { return ptr != rhs.ptr; }       bool operator<(const iterator rhs) const { return ptr < rhs.ptr; }       bool operator<=(const iterator rhs) const { return ptr <= rhs.ptr; }       bool operator>(const iterator rhs) const { return ptr > rhs.ptr; }       bool operator>=(const iterator rhs) const { return ptr >= rhs.ptr; }       iterator operator++() { return iterator(++ptr); }       iterator operator++(int) { return iterator(ptr++); }       iterator operator--() { return iterator(--ptr); }       iterator operator--(int) { return iterator(ptr--); }       iterator operator+(const difference_type dif) const {         return iterator(ptr + dif);       }       iterator operator-(const difference_type dif) const {         return iterator(ptr - dif);       }       iterator operator+=(const difference_type dif) {         ptr += dif;         return *this;       }       iterator operator-=(const difference_type dif) {         ptr -= dif;         return *this;       }       difference_type operator-(const iterator& rhs) const {         return ptr - rhs.ptr;       }       operator pointer() { return ptr; }     };       protected:     Type* a = nullptr;     unsigned int _capacity = 0, _size = 0;     void __grow_capacity(unsigned int least_size) {       if (_capacity >= least_size) {         return;       }       if (_capacity == 0) {         _capacity = 1;       }       while (_capacity < least_size) {         _capacity = _capacity * 2;       }       a = static_cast<Type*>(realloc(a, sizeof(Type) * _capacity));     }       public:     Vector() = default;     explicit Vector(unsigned int size, const Type& initial_value = Type())         : _capacity(size), _size(size) {       a = static_cast<Type*>(malloc(sizeof(Type) * _capacity));       Type *__first = a, *const __last = a + _size;       while (__first != __last) {         *__first++ = initial_value;       }     }     Vector(const Vector& rhs) : _capacity(rhs._size), _size(rhs._size) {       a = static_cast<Type*>(malloc(sizeof(Type) * _capacity));       Type *__first = a, *__r_p = rhs.a, *const __last = a + _size;       while (__first != __last) {         *__first++ = *__r_p++;       }     }     Vector(Vector&& rhs) : _capacity(rhs._capacity), _size(rhs._size) {       a = rhs.a;       rhs.a = nullptr;     }     Vector(const std::initializer_list<Type>& list)         : _capacity(               static_cast<unsigned int>(std::distance(list.begin(), list.end()))),           _size(_capacity) {       a = static_cast<Type*>(malloc(sizeof(Type) * _capacity));       Type* p = a;       for (const auto& i : list) {         *p++ = i;       }     }     template <typename Container,               typename = decltype(std::declval<Container>().begin(),                                   std::declval<Container>().end())>     Vector(const Container& list)         : _capacity(               static_cast<unsigned int>(std::distance(list.begin(), list.end()))),           _size(_capacity) {       a = static_cast<Type*>(malloc(sizeof(Type) * _capacity));       Type* p = a;       for (const auto& i : list) {         *p++ = i;       }     }     template <         typename _InputIterator,         typename = typename std::enable_if<std::is_convertible<             typename std::iterator_traits<_InputIterator>::iterator_category,             std::input_iterator_tag>::value>::type>     explicit Vector(_InputIterator __first, _InputIterator __last) {       _size = _capacity =           static_cast<unsigned int>(std::distance(__first, __last));       a = static_cast<Type*>(malloc(sizeof(Type) * _capacity));       Type* p = a;       while (__first != __last) {         *p++ = *__first++;       }     }     inline bool empty() const { return _size == 0; }     inline unsigned int size() const { return _size; }     inline unsigned int capacity() const { return _capacity; }     void reserve(unsigned int __capacity) {       _capacity = __capacity;       if (_size > _capacity) {         _size = _capacity;       }       a = static_cast<Type*>(realloc(a, sizeof(Type) * _capacity));     }     void resize(unsigned int __size) {       if (_size > __size) {         _size = __size;         return;       }       __grow_capacity(__size);       Type *__un = a + _size, *const __ed = a + __size;       while (__un != __ed) {         *__un++ = Type();       }       _size = __size;     }     inline void clear() { resize(0); }     Vector& operator=(const Vector& rhs) {       __grow_capacity(rhs._size);       _size = rhs._size;       Type* __first = a;       const Type *const __last = a + _size, *__r_p = rhs.a;       while (__first != __last) {         *__first++ = *__r_p++;       }       return *this;     }     Vector& operator=(Vector&& rhs) {       _size = rhs._size;       _capacity = rhs._capacity;       free(a);       a = rhs.a;       rhs.a = nullptr;       return *this;     }     Type operator[](const unsigned int id) const { return a[id]; }     Type& operator[](const unsigned int id) { return a[id]; }     Type front() const { return a[0]; }     Type& front() { return a[0]; }     Type back() const { return a[_size - 1]; }     Type& back() { return a[_size - 1]; }     void pop_back() { _size--; }     Vector& push_back(const Type& b) {       __grow_capacity(_size + 1);       a[_size] = b;       _size++;       return *this;     }     Vector& push_back(const Vector& rhs) {       __grow_capacity(_size + rhs._size);       for (const auto& i : rhs) {         a[_size++] = i;       }       return *this;     }     Vector& push_back(const std::initializer_list<Type>& rhs) {       __grow_capacity(_size + rhs.size());       for (const auto& i : rhs) {         a[_size++] = i;       }       return *this;     }     inline iterator begin() const { return iterator(a); }     inline iterator end() const { return iterator(a + _size); }     ~Vector() { free(a); }   };   }  // namespace Temps   using Temps::Vector;   void preInit();   void init();   void solve();   int32_t main() {     preInit();     init();     solve();     return 0;   }   constexpr long long N = 100005;   struct dp_t {     long long ss = 0, sub_sr = 0, ss_sr = 0;     dp_t() = default;     dp_t(long long val) : ss(val), sub_sr(val), ss_sr(val) {}   };   std::vector<long long> e[N];   long long n, w[N], ans = 0;   void preInit() {}   void init() {     n = sc.n();     for (long long i = 1; i <= n; i++) w[i] = sc.n();     for (long long i = 1; i < n; i++) {       long long u = sc.n(), v = sc.n();       e[u].push_back(v);       e[v].push_back(u);     }   }   dp_t dp[N];   void dfs(long long u, long long f) {     dp[u] = dp_t(w[u]);     long long pre_v_sub_sr = 0;     for (long long v : e[u])       if (v != f) {         dfs(v, u);         const dp_t& dv = dp[v];         dp_t du;         du.ss = std::max(dp[u].ss, w[u] + dv.ss);         du.sub_sr = std::max({dp[u].sub_sr, dp[u].ss + dv.ss, dv.sub_sr});         du.ss_sr = std::max({dp[u].ss_sr, dp[u].ss + dv.sub_sr,                              pre_v_sub_sr + w[u] + dv.ss, dv.ss_sr + w[u]});         pre_v_sub_sr = std::max(pre_v_sub_sr, dv.sub_sr);         ans = std::max({ans, dp[u].sub_sr + dv.sub_sr, dp[u].ss_sr + dv.ss,                         dp[u].ss + dv.ss_sr});         dp[u] = du;       }   }   void solve() {     dfs(1, 0);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int d, n, x, ans;   int main() {     cin >> d;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> x;       ans += d - x;     }     cin >> x;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     using T = tuple<long long, long long, long long, long long>;     vector<long long> x(n), y(n), z(n);     for (long long i = (0); i < ((n)); ++i) cin >> x[i] >> y[i] >> z[i];     vector<long long> flag(n, 0);     vector<pair<long long, long long> > ans;     for (long long i = (0); i < ((n)); ++i) {       if (flag[i]) continue;       flag[i]++;       bool check = true;       long long X = (1LL << 60), Y, Z, id;       for (long long j = (0); j < ((n)); ++j) {         if (flag[j]) continue;         if (X == (1LL << 60)) {           X = x[j], Y = y[j], Z = z[j];           id = j;           continue;         }         if (((min(x[i], X)) <= (x[j]) && (x[j]) < (max(x[i], X) + 1)) &&             ((min(y[i], Y)) <= (y[j]) && (y[j]) < (max(y[i], Y) + 1)) &&             ((min(z[i], Z)) <= (z[j]) && (z[j]) < (max(z[i], Z) + 1))) {           X = x[j], Y = y[j], Z = z[j];           id = j;           continue;         }       }       flag[id]++;       ans.push_back(pair<long long, long long>(i + 1, id + 1));     }     for (long long i = (0); i < ((n / 2)); ++i)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {       int n, m;       cin >> n >> m;       int cnt = 0;       set <int> s;       while(n) {           s.insert(n % m);           cnt++;           n /= m;       }       if(s.size() == cnt) cout <<  YES n ;       else cout <<  NO n ;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1E9 + 7;   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   int n, k;   int il[2];   const long long mod = 1E9 + 7;   int best[2][55][55];   int ile[2][55][55];   int a, b;   int binom[55][55];   int main() {     ios_base::sync_with_stdio(false);     binom[0][0] = 1;     for (int i = (1); i <= (55 - 1); ++i) {       binom[i][0] = 1;       for (int j = (1); j <= (55 - 1); ++j) {         binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;       }     }     cin >> n >> k;     for (int i = (1); i <= (n); ++i) {       int x;       cin >> x;       if (x == 50)         il[0]++;       else         il[1]++;     }     for (int s = (0); s <= (1); ++s)       for (int i = (0); i <= (55 - 1); ++i)         for (int j = (0); j <= (55 - 1); ++j) best[s][i][j] = INF;     a = il[0];     b = il[1];     best[0][a][b] = 0;     ile[0][a][b] = 1;     for (int moves = (0); moves <= (55 * 55 * 10); ++moves) {       for (int s = (0); s <= (1); ++s)         for (int i = (0); i <= (a); ++i)           for (int j = (0); j <= (b); ++j) {             if (best[s][i][j] == moves) {               for (int ii = (0); ii <= (i); ++ii)                 for (int jj = (0); jj <= (j); ++jj)                   if (ii || jj) {                     if (ii * 50 + jj * 100 > k) break;                     int x = a - i;                     int y = b - j;                     x += ii;                     y += jj;                     long long il = (binom[i][ii] * (long long)binom[j][jj]) % mod;                     if (moves + 1 < best[1 - s][x][y]) {                       best[1 - s][x][y] = moves + 1;                       ile[1 - s][x][y] = (ile[s][i][j] * il) % mod;                     } else if (moves + 1 == best[1 - s][x][y]) {                       ile[1 - s][x][y] += (ile[s][i][j] * il) % mod;                       ile[1 - s][x][y] %= (int)mod;                     }                   }             }           }     }     if (best[1][a][b] == INF) best[1][a][b] = -1;     cout << best[1][a][b] << endl << ile[1][a][b] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1007;   int c[N], t[N];   bool cmp(int i, int j) { return c[i] > c[j]; }   int main() {     int n, k;     cin >> n >> k;     vector<int> v[3];     for (int i = 0; i < n; ++i) {       cin >> c[i] >> t[i];       v[t[i]].push_back(i);     }     sort((v[1]).begin(), (v[1]).end(), cmp);     int sz = (int)((v[1]).size()), uu = (int)((v[2]).size());     double sum = 0;     if (sz < k) {       for (int i = 0; i < sz; ++i) sum += (double)c[v[1][i]] / 2;       for (int i = 0; i < uu; ++i) sum += c[v[2][i]];       cout << fixed << setprecision(1) << sum <<   n ;       for (int i = 0; i < sz; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ;       for (int i = 0; i < k - sz - 1; ++i)         cout << 1 <<     << v[2][i] + 1 <<   n ;       cout << (n - (k - 1)) <<    ;       for (int i = k - sz - 1; i < n - sz; ++i) cout << v[2][i] + 1 <<    ;       cout <<   n ;     } else {       for (int i = 0; i < k - 1; ++i) sum += (double)c[v[1][i]] / 2;       int mini = 1000000000;       for (int i = k - 1; i < sz; ++i) {         sum += c[v[1][i]];         mini = min(mini, c[v[1][i]]);       }       for (int i = 0; i < uu; ++i) {         sum += c[v[2][i]];         mini = min(mini, c[v[2][i]]);       }       sum -= (double)mini / 2;       cout << fixed << setprecision(1) << sum <<   n ;       for (int i = 0; i < k - 1; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ;       cout << (n - (k - 1)) <<    ;       for (int i = k - 1; i < sz; ++i) cout << v[1][i] + 1 <<    ;       for (int i = 0; i < uu; ++i) cout << v[2][i] + 1 <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool is_vowel(const char c) {     for (const char vowel : { a ,  e ,  i ,  o ,  u })       if (c == vowel) return true;     return false;   }   bool is_block_ok(const array<char, 3> cs) {     for (const char c : cs)       if (is_vowel(c)) return true;     return cs[0] == cs[1] && cs[1] == cs[2];   }   int main() {     string s;     cin >> s;     const int n = int(s.length());     int start = 0;     for (int i = 0; i < n; i++) {       if (i >= start + 2 && !is_block_ok({s[i - 2], s[i - 1], s[i]})) {         cout <<    ;         start = i;       }       cout << s[i];     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     long long int k;     cin >> n >> k;     vector<pair<int, int> > a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a.begin(), a.end());     int ans = -1;     long long int l = 0, r = 2e9;     for (int i = 0; i < 60; i++) {       long long int m = l + (r - l) / 2;       int less = 0, right = 0, center = 0;       long long int money = 0;       vector<int> c;       for (auto &e : a) {         if (e.second < m) {           money += e.first;         } else if (e.first >= m) {           money += e.first;           right++;         } else if (e.first < m && m <= e.second) {           c.push_back(e.first);         }       }       int need = max(0, (n + 1) / 2 - right);       if (need > c.size()) {         r = m - 1;       } else {         for (int i = 0; i < c.size(); i++) {           if (i < c.size() - need)             money += c[i];           else             money += m;         }         if (money <= k) {           ans = m;           l = m + 1;         } else {           r = m - 1;         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   int n, m, c;   int A[1111];   int pref = 0, post = 0;   bool end() {     bool ans = true;     for (int(i) = 0; (i) < (n); (i)++)       if (A[i] == -1 || (i < n - 1 && A[i + 1] < A[i])) ans = false;     return ans;   }   int main() {     memset(A, -1, sizeof(A));     scanf( %d%d%d , &n, &m, &c);     int H = (c + 1) / 2;     for (int(i) = 0; (i) < (m); (i)++) {       int x;       scanf( %d , &x);       if (x <= H) {         int i = 0;         while (i < n && (A[i] <= x && A[i] != -1)) i++;         A[i] = x;         printf( %d n , i + 1);         fflush(stdout);         if (end()) return 0;       } else {         int i = n - 1;         while (i >= 0 && (A[i] >= x && A[i] != -1)) i--;         A[i] = x;         printf( %d n , i + 1);         fflush(stdout);         if (end()) return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N];   int main() {     ios::sync_with_stdio(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       if (n % 2 == 0) {         cout << n / 2 <<     << n / 2 << endl;       } else {         int lim = sqrt(n + 0.5), fg = 0;         for (int i = 3; i <= lim; ++i) {           if (n % i == 0) {             cout << (n / i) <<     << (n / i) * (i - 1) << endl;             fg = 1;             break;           }         }         if (!fg) {           cout << 1 <<     << n - 1 << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     string a;     cin >> a;     int n = 0, m = 0, first = 0, last = 0;     bool b = true;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  H ) n++;       if (a[i] ==  Q ) m++;     }     int sm = int(sqrt(m));     int i = 0;     i = a.size() - 1;     while ((i >= 0) && (a[i] ==  H )) {       last++;       i--;     };     last /= 2;     i = 0;     while ((i < a.size()) && (a[i] ==  H )) {       first++;       i++;     };     first /= 2;     if (m == 0)       cout <<  Yes ;     else {       if (!((sm * sm == m) && (n % (sm + 1) == 0)))         cout <<  No ;       else {         string middle =   ;         int counter = 0;         while (counter < sm) {           if (a[i] ==  Q ) counter++;           middle += a[i];           i++;         }         string str;         str = middle;         for (int i = 0; i < first; i++) {           str =  H  + str;         }         for (int i = 0; i < last; i++) {           str = str +  H ;         }         string out =   ;         for (int i = 0; i < str.size(); i++) {           if (str[i] ==  H )             out = out +  H ;           else             out += str;         };         if (out == a)           cout <<  Yes ;         else           cout <<  No ;       };     }     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000, MAX_M = 1000;   int N, M;   int a[MAX_N][MAX_M], mxx[MAX_N], mxy[MAX_M], cmpx[MAX_N][MAX_M],       cmpy[MAX_N][MAX_M];   vector<int> cmp;   int main() {     scanf( %d %d , &N, &M);     for (int i = (0); i < (N); i++)       for (int j = (0); j < (M); j++) {         scanf( %d , &a[i][j]);       }     for (int i = (0); i < (N); i++) {       cmp.clear();       for (int j = (0); j < (M); j++) {         cmp.push_back(a[i][j]);       }       sort(cmp.begin(), cmp.end());       cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());       mxx[i] = (int)cmp.size();       for (int j = (0); j < (M); j++) {         cmpx[i][j] =             lower_bound(cmp.begin(), cmp.end(), a[i][j]) - cmp.begin() + 1;       }     }     for (int i = (0); i < (M); i++) {       cmp.clear();       for (int j = (0); j < (N); j++) {         cmp.push_back(a[j][i]);       }       sort(cmp.begin(), cmp.end());       cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());       mxy[i] = (int)cmp.size();       for (int j = (0); j < (N); j++) {         cmpy[j][i] =             lower_bound(cmp.begin(), cmp.end(), a[j][i]) - cmp.begin() + 1;       }     }     for (int i = (0); i < (N); i++) {       for (int j = (0); j < (M); j++) {         if (j) printf(   );         int mx = max(cmpx[i][j], cmpy[i][j]);         printf( %d , mx + max(mxx[i] - cmpx[i][j], mxy[j] - cmpy[i][j]));       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, howMany[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     vector<pair<int, int> > beacons;     for (int i = 0; i < n; i++) {       int x, p;       cin >> x >> p;       beacons.push_back({x, p});     }     sort(beacons.begin(), beacons.end());     howMany[0] = 0;     auto it = beacons.begin();     for (int i = 1; i < n; i++) {       int now = beacons[i].first, power = beacons[i].second;       auto it =           lower_bound(beacons.begin(), beacons.end(), make_pair(now - power, -1));       int idx = it - beacons.begin();       if (idx == 0) {         howMany[i] = i;       } else {         howMany[i] = howMany[idx - 1] + (i - idx);       }     }     int ans = n;     for (int i = 0; i < n; i++) {       ans = min(ans, howMany[i] + (n - i - 1));     }     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 6;   int n, k, h[N];   long long p, m, t, a[N], b[N];   struct xd {     int z, i;     bool operator<(const xd &d) const { return z > d.z; }   } tmp, nw;   inline int read() {     int T = 0, F = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) F = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       T = (T << 3) + (T << 1) + (ch - 48), ch = getchar();     return F * T;   }   bool check(long long x) {     priority_queue<xd> q;     memset(b, 0, sizeof(b));     for (int i = 1; i <= n; ++i)       if (x - a[i] * m < h[i]) tmp.z = x / a[i], tmp.i = i, q.push(tmp);     for (int i = 1; i <= m && !q.empty(); ++i)       for (int j = 1; j <= k && !q.empty(); ++j) {         tmp = q.top(), q.pop();         if (tmp.z < i) return 0;         ++b[tmp.i];         if (x + b[tmp.i] * p - a[tmp.i] * m < h[tmp.i])           tmp.z = (x + b[tmp.i] * p) / a[tmp.i], q.push(tmp);       }     return q.empty();   }   long long ef(long long l, long long r) {     if (l == r) return l;     long long mid = l + r >> 1ll;     if (check(mid)) return ef(l, mid);     return ef(mid + 1, r);   }   int main() {     n = read(), m = read(), k = read(), p = read();     for (int i = 1; i <= n; ++i) h[i] = read(), a[i] = read();     printf( %lld n , ef(0, 5e12 + 1e9 + 1));     return 0;   }


#include <bits/stdc++.h>   int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; }   int main() {     int n, k;     scanf( %d%d , &n, &k);     int i;     if ((n == 1 && k == 1)) {       printf( -1 n );       return 0;     }     if (n == k) {       printf( -1 n );       return 0;     }     if ((n - k) % 2 != 0) {       printf( 1  );       for (i = 2; i <= ((n - k) - (n - k) % 2); i += 2) {         printf( %d %d  , i + 1, i);       }       for (i = n - k + 1; i <= n; i++) printf( %d  , i);     } else {       for (i = 1; i <= (n - k); i += 2) {         printf( %d %d  , i + 1, i);       }       for (i = n - k + 1; i <= n; i++) printf( %d  , i);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int print1() {     cout << -1 << endl;     return 0;   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > e(n);     int a, b;     for (int i = 0; i < m; ++i) {       cin >> a >> b;       a--;       b--;       e[a].push_back(b);       e[b].push_back(a);     }     vector<int> c(n, 0);     vector<int> cnt(3, 0);     cnt[0] = n;     for (auto &v : e[0]) {       c[v] = 2;       cnt[0]--;       cnt[2]++;     }     for (a = 0; a < n && c[a] == 0; ++a)       ;     if (a == n) return print1();     for (auto &v : e[a]) {       if (c[v] == 2) {         c[v] = 1;         cnt[1]++;         cnt[2]--;       }     }     for (int j = 0; j < 3; ++j)       if (cnt[j] == 0) return print1();     vector<int> loc(3, 0);     for (int i = 0; i < n; ++i) {       loc[0] = 0;       loc[1] = 0;       loc[2] = 0;       for (auto &v : e[i]) loc[c[v]]++;       if (loc[c[i]] != 0) return print1();       for (int j = 0; j < 3; ++j)         if (c[i] != j && loc[j] != cnt[j]) return print1();     }     for (int i = 0; i < n; ++i) cout << c[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   char a[maxn][maxn];   int vis[maxn][maxn];   int n, m;   inline void go(int x, int y) {     if (vis[x][y] == 1) return;     if (a[x][y] !=  # ) return;     vis[x][y] = 1;     go(x - 1, y);     go(x + 1, y);     go(x, y - 1);     go(x, y + 1);   }   inline bool check(int x, int y) {     a[x][y] =  . ;     int sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (a[i][j] ==  #  && vis[i][j] == 0) {           sum++;           go(i, j);         }     }     a[x][y] =  # ;     return sum > 1;   }   int main() {     cin >> n >> m;     int sum = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] ==  # ) sum++;       }     if (sum <= 2) {       cout <<  -1  << endl;       return 0;     }     int ans = 2;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  # )           if (check(i, j)) ans = 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_dp = 2e5 + 1;   int dp[101][max_dp];   int n, k;   int a[101], b[101];   int solve(int num, int bal) {     if (dp[num][bal] != -1) {       return dp[num][bal];     }     if (num == 0) {       if (bal == 1e5) {         return 0;       } else {         return -1e9;       }     }     int x = solve(num - 1, bal);     int y = a[num - 1] + solve(num - 1, bal + a[num - 1] - k * b[num - 1]);     dp[num][bal] = max(x, y);     return dp[num][bal];   }   int main() {     cin >> n >> k;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int ans = solve(n, 1e5);     if (ans > 0)       cout << ans << endl;     else       cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, v[1005], xi, yi;   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     int res = 0;     while (m--) {       scanf( %d %d , &xi, &yi);       xi--, yi--;       res += min(v[xi], v[yi]);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100][10000];   int d[100][10000];   int main() {     int n, m;     cin >> n >> m;     string str;     getline(cin, str);     for (int i = 0; i < n; i++) {       getline(cin, str);       for (int j = 0; j < str.size(); j++)         if (str[j] ==  1 )           A[i][j] = 1;         else           A[i][j] = 0;     }     for (int i = 0; i < n; i++) {       int prev = 1000001;       int prev2 = 100000;       for (int j = m - 1; j >= 0; j--)         if (A[i][j]) {           prev = -(m - j);           break;         }       if (prev == 1000001) {         cout << -1 << endl;         return 0;       }       bool first = true;       for (int j = 0; j < m; j++) {         if (A[i][j]) {           if (first) {             prev2 = j + 1 + m - 1;             first = false;           }           d[i][j] = 0;           prev = j;         } else           d[i][j] = j - prev;       }       for (int j = m - 1; j >= 0; j--) {         d[i][j] = min(d[i][j], prev2 - j);         if (A[i][j]) prev2 = j;       }     }     int mindall = 1000000;     for (int i = 0; i < m; i++) {       int mind = 0;       for (int j = 0; j < n; j++) {         mind += d[j][i];       }       mindall = min(mindall, mind);     }     cout << mindall << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, tt;     cin >> n >> tt;     vector<int> a(1 << n);     long long sum = 0;     for (int i = 0; i < (1 << n); i++) {       cin >> a[i];       sum += (long long)a[i];     }     cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ;     while (tt--) {       int x, y;       cin >> x >> y;       sum += y - a[x];       a[x] = y;       cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n >= 1 && n <= 10 || n >= 22 && n <= 25)       cout <<  0 ;     else if (n == 11)       cout <<  4 ;     else if (n == 20)       cout <<  15 ;     else       cout <<  4 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int l = 0, u = 0;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] > 90)         l++;       else         u++;     }     if (l >= u) {       transform(s.begin(), s.end(), s.begin(), ::tolower);       cout << s << endl;     } else {       transform(s.begin(), s.end(), s.begin(), ::toupper);       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int MN = 1e5 + 4;   int N, Q, ecnt, ch[MN], depth[MN], len[MN];   long long rt, bit1[MN], *bit2[MN];   std::vector<int> adj[MN];   inline void upd(long long *bit, int ind, int cap, long long val) {     for (; ind < cap; ind += ind & -ind) bit[ind] += val;   }   inline long long qry(long long *bit, int ind) {     long long res = 0;     for (; ind; ind -= ind & -ind) res += bit[ind];     return res;   }   void dfs1(int src, int p, int d, int b) {     ++ecnt;     ch[src] = b;     depth[src] = d++;     for (int i : adj[src]) {       if (i == p) continue;       dfs1(i, src, d, b);     }   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1, a, b; i < N; ++i) {       scanf( %d%d , &a, &b);       adj[a].emplace_back(b);       adj[b].emplace_back(a);     }     int cnt = 0;     for (int i : adj[1]) {       dfs1(i, 1, 1, ++cnt);       len[cnt] = ecnt + 1;       bit2[cnt] = (long long *)calloc(ecnt + 1, sizeof(long long));       ecnt = 0;     }     for (int i = 0, a, b, c, d; i < Q; ++i) {       scanf( %d , &a);       if (a) {         scanf( %d , &b);         if (b == 1)           printf( %lld n , rt);         else           printf( %lld n , qry(bit1, depth[b]) + qry(bit2[ch[b]], depth[b]));       } else {         scanf( %d%d%d , &b, &c, &d);         if (b == 1) {           upd(bit1, 1, MN, c);           upd(bit1, d + 1, MN, -c);           rt += c;         } else {           if (d < depth[b]) {             upd(bit2[ch[b]], depth[b] - d, len[ch[b]], c);             upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c);           } else {             upd(bit2[ch[b]], 1, len[ch[b]], c);             upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c);             if (depth[b] != d) {               upd(bit1, 1, MN, c);               upd(bit1, d - depth[b] + 1, MN, -c);               upd(bit2[ch[b]], 1, len[ch[b]], -c);               upd(bit2[ch[b]], d - depth[b] + 1, len[ch[b]], c);             }             rt += c;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     long long int res = 0;     for (long long int i = 1; i <= r; i *= 2) {       for (long long int j = 1; j <= r; j *= 3) {         if (i * j <= r && i * j >= l) {           res++;         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pos, l, r;     cin >> n >> pos >> l >> r;     int result;     if (l == 1 && r == n) {       result = 0;     } else if (l == 1) {       result = abs(pos - r) + 1;     } else if (r == n) {       result = abs(pos - l) + 1;     } else {       result = min(abs(pos - l), abs(pos - r)) + r - l + 2;     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[3123];   vector<vector<int> > vCiclos;   int dist[3123];   int vis[3123];   vector<int> v;   int ciclo[3123];   int tamanhoCiclo[3123];   int cnt = 1;   int n;   bool cycle[3123];   void dfs(int x, int pai) {     vis[x] = 1;     v.push_back(x);     for (int i = 0; i < graph[x].size(); ++i) {       int y = graph[x][i];       if (y == pai) continue;       if (vis[y] == 0) {         dfs(y, x);       } else if (vis[y] == 1) {         vector<int> aux;         for (int j = v.size() - 1;; --j) {           int vert = v[j];           ciclo[vert] = cnt;           aux.push_back(v[j]);           cycle[v[j]] = true;           if (vert == y) break;         }         cnt++;         vCiclos.push_back(aux);       }     }     vis[x] = 2;     v.pop_back();   }   void dfs2(int x, int pai, int k) {     dist[x] = k;     for (int i = 0; i < graph[x].size(); i++) {       int y = graph[x][i];       if (y == pai || cycle[y]) continue;       dfs2(y, x, k + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       graph[x].push_back(y);       graph[y].push_back(x);     }     dfs(1, 1);     for (int i = 0; i < vCiclos.size(); i++) {       for (int j = 0; j < vCiclos[i].size(); j++) {         int y = vCiclos[i][j];         dfs2(y, y, 0);       }     }     for (int i = 1; i <= n; i++) printf( %d  , dist[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, N = 200200, G = 3, Gi = 332748118;   long long power(long long base, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * base % mod;       base = base * base % mod;       b >>= 1;     }     return ret;   }   int limit, len, last = -1, pos[N];   long long G0[N], G1[N], G2[N], g[N], F0[N], F1[N], F2[N];   long long w[N];   void getlen(int n) {     limit = 1, len = 0;     while (limit < n) limit <<= 1, ++len;     w[0] = 1;     long long gg = power(G, (mod - 1) / limit);     for (int i = 1; i < limit; ++i) {       pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << (len - 1));       w[i] = w[i - 1] * gg % mod;     }   }   void ntt(long long *a, int n, int type) {     for (int i = 0; i < limit; ++i)       if (i < pos[i]) swap(a[i], a[pos[i]]);     for (int mid = 1; mid < limit; mid <<= 1)       for (int j = 0, r = mid << 1; j < limit; j += r)         for (int k = 0; k < mid; ++k) {           long long x = a[j + k], y = w[limit / r * k] * a[j + mid + k] % mod;           a[j + k] = (x + y) % mod;           a[j + mid + k] = (x - y + mod) % mod;         }     if (type == -1) {       reverse(a + 1, a + limit);       long long inv = power(limit, mod - 2);       for (int i = 0; i < limit; ++i) a[i] = inv * a[i] % mod;     }   }   long long f[N], h[N], tmp[N];   void calc(long long *a, int n, long long *b, int m, long long *c, int nm = -1) {     if (nm == -1) nm = n + m - 1;     getlen(nm);     for (int i = 0; i < n; ++i) f[i] = a[i];     for (int i = n; i < limit; ++i) f[i] = 0;     for (int i = 0; i < m; ++i) h[i] = b[i];     for (int i = m; i < limit; ++i) h[i] = 0;     ntt(f, nm, 1), ntt(h, nm, 1);     for (int i = 0; i < limit; ++i) f[i] = f[i] * h[i] % mod;     ntt(f, nm, -1);     for (int i = 0; i < nm; ++i) c[i] = f[i];   }   void CDQ(int l, int r) {     if (l == r) {       F0[l] = (F0[l] + G0[l]) % mod;       F1[l] = (F1[l] + G1[l]) % mod;       F2[l] = (F2[l] + G2[l]) % mod;       return;     }     int mid = (l + r) >> 1;     CDQ(l, mid);     calc(F0 + l, mid - l + 1, G0, r - l + 1, tmp + l, r - l + 1);     for (int i = mid + 1; i <= r; ++i) F0[i] = (F0[i] + tmp[i]) % mod;     calc(F0 + l, mid - l + 1, G1, r - l + 1, tmp + l, r - l + 1);     for (int i = mid + 1; i <= r; ++i) F1[i] = (F1[i] + tmp[i]) % mod;     calc(F1 + l, mid - l + 1, G1, r - l + 1, tmp + l, r - l + 1);     for (int i = mid + 1; i <= r; ++i) F0[i] = (F0[i] + tmp[i]) % mod;     for (int i = mid + 1; i <= r; ++i) F2[i] = (F2[i] + tmp[i]) % mod;     calc(F1 + l, mid - l + 1, G2, r - l + 1, tmp + l, r - l + 1);     for (int i = mid + 1; i <= r; ++i) F1[i] = (F1[i] + tmp[i]) % mod;     calc(F2 + l, mid - l + 1, G2, r - l + 1, tmp + l, r - l + 1);     for (int i = mid + 1; i <= r; ++i) F2[i] = (F2[i] + tmp[i]) % mod;     CDQ(mid + 1, r);   }   int n;   int main() {     scanf( %d , &n);     g[0] = g[2] = 1;     for (int i = 4; i <= n; ++i) g[i] = (g[i - 2] + g[i - 4]) % mod;     for (int i = 1; i <= n; ++i)       G0[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 1] % mod;     for (int i = 2; i <= n; ++i)       G1[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 2] % mod;     for (int i = 3; i <= n; ++i)       G2[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 3] % mod;     CDQ(1, n);     long long Ans = 1LL * n * (G0[n] + G2[n]) % mod;     for (int i = 2; i <= n - 2; ++i) {       Ans = (Ans + (G0[i] * F0[n - i] % mod + 2LL * G1[i] * F1[n - i] % mod +                     G2[i] * F2[n - i] % mod) *                        (long long)i % mod) %             mod;     }     printf( %lld n , (Ans % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string months[] = { January ,    February ,  March ,     April ,                         May ,        June ,      July ,      August ,                         September ,  October ,   November ,  December };     string s;     int n, a;     cin >> s >> n;     for (int i = 0; i < 12; i++) {       if (months[i].compare(s) == 0) {         a = i + n;         break;       }     }     while (a > 11) {       a = a - 12;     }     cout << months[a];   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 2e9 + 5;   const int MAXN = 100010;   int n;   long long a, r, m, h[MAXN];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> r >> m;     for (int i = 0; i < n; i++) {       cin >> h[i];     }     m = min(m, a + r);     sort(h, h + n, greater<long long>());     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += h[i];     }     long long lbound = (sum + n - 1) / n;     long long cur = (n * h[0] - sum) * a;     long long ans = 1e18;     long long run = 0;     for (int i = 0; i < n; i++) {       if (h[i] < lbound) break;       long long lo = lbound;       if (i + 1 < n) {         lo = max(lo, h[i + 1]);       }       ans = min(ans, cur + run);       long long delta = (i + 1) * m - n * a;       run += delta * (h[i] - lo);     }     ans = min(ans, cur + run);     reverse(h, h + n);     long long ubound = sum / n;     cur = (sum - n * h[0]) * r;     run = 0;     for (int i = 0; i < n; i++) {       if (h[i] > ubound) break;       long long hi = ubound;       if (i + 1 < n) {         hi = min(hi, h[i + 1]);       }       ans = min(ans, cur + run);       long long delta = (i + 1) * m - n * r;       run += delta * (hi - h[i]);       ;     }     ans = min(ans, cur + run);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const int N = 2e5 + 10;   const int MX = 1e9;   int n, t;   int ar[N], mn[N];   unordered_map<int, int> bit;   void upd(int x, int val) {     x++;     while (x <= t) {       bit[x] += val;       x += (x & (-x));     }   }   int ask(int x) {     x++;     int ret = 0;     while (x) {       ret += bit[x];       x -= (x & (-x));     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     t = min(t, n + MX + 10);     for (int i = 1; i <= n; i++) {       cin >> ar[i];       mn[i] = max(ar[i] - i, 0);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       upd(mn[i], 1);       int mul = t - i - 1;       if (mul >= 0) {         ans = max(ans, ask(mul));       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gets(string s) {     int sum = 0;     while ((s[0] ==  0 ) and (s.size() != 1)) s = s.substr(1, s.size() - 1);     for (int i = 0; i < s.size(); i++) sum += s[i] - 48;     return sum;   }   int main() {     string s, s1, m;     int kol;     cin >> s;     m = s;     kol = gets(s);     for (int i = 0; i < s.size(); i++) {       s1 = s;       int kol1 = 0;       if (s1[i] !=  0 ) s1[i]--;       for (int j = i + 1; j < s.size(); j++) s1[j] =  9 ;       kol1 = gets(s1);       while ((s1[0] ==  0 ) and (s1.size() != 1))         s1 = s1.substr(1, s1.size() - 1);       if ((kol1 > kol) or           ((kol == kol1) and            ((s1.size() > m.size()) or ((s1 > m) and (s1.size() == m.size()))))) {         m = s1;         kol = kol1;       }     }     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& a) {     for (T& ai : a) is >> ai;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> const& a) {     os <<  [  ;     for (const T& ai : a) os << ai <<    ;     return os <<  ] ;   }   template <typename T1, typename T2>   istream& operator>>(istream& is, pair<T1, T2>& a) {     return is >> a.first >> a.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& os, pair<T1, T2> const& a) {     return os <<  (  << a.first <<  ,   << a.second <<  ) ;   }   int f() {     int n;     cin >> n;     vector<int> a(n);     cin >> a;     vector<int> val(a);     sort((val).begin(), (val).end());     int m = unique((val).begin(), (val).end()) - val.begin();     val.resize(m);     map<int, int> idx;     for (int i = 0; i < m; ++i) idx[val[i]] = i;     vector<vector<int> > tiers(m);     for (int i = 0; i < n; ++i) tiers[idx[a[i]]].push_back(i);     int i = 0, j = 1, r = 0;     while (i < m) {       while (j < m && tiers[j - 1].back() < tiers[j].front()) ++j;       int s = 0, lb = tiers[i].front(), ub = tiers[j - 1].back();       for (int k = i; k < j; ++k) s += tiers[k].size();       if (i - 1 >= 0) {         for (int x : tiers[i - 1]) {           if (x < lb) ++s;         }       }       if (j < m) {         for (int x : tiers[j]) {           if (x > ub) ++s;         }       }       r = max(r, s);       i = j++;     }     for (int i = 0; i < m - 1; ++i) {       int j = 0, jz = tiers[i + 1].size();       int s = jz;       for (int lhs : tiers[i]) {         ++s;         while (j < jz && tiers[i + 1][j] <= lhs) {           ++j;           --s;         }         r = max(r, s);       }     }     return n - r;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) cout << f() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, a, b;     cin >> t;     while (t--) {       cin >> a >> b;       int f = 0;       long long area = a * a - b * b;       if ((a - b) != 1)         cout <<  NO ;       else {         area = a + b;         for (int i = 2; i <= sqrt(a + b); i++) {           if (area % i == 0) {             cout <<  NO ;             f = 1;             break;           }         }         if (f == 0) cout <<  YES ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long s(0), p, k;   int main() {     cin >> k >> p;     for (long long cz(1), i(0); i < k; ++i, ++cz) {       string str = to_string(cz);       string res(str);       reverse(begin(str), end(str));       res += str;       s += stoll(res) % p;     }     cout << s % p << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long xl, xr, yu, yd;   long long x, y;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (i == 0) {         xl = x;         xr = x;         yu = y;         yd = y;       } else {         if (x < xl) xl = x;         if (x > xr) xr = x;         if (y > yu) yu = y;         if (y < yd) yd = y;       }     }     long long ans = max(yu - yd, xr - xl);     cout << ans * ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int o, e, oC, eC, n, en;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> en;       if (en % 2 == 0) {         e = i;         eC++;       } else {         o = i;         oC++;       }     }     if (oC == 1)       cout << o;     else       cout << e;   }


#include <bits/stdc++.h>   using namespace std;   double px[1005], py[1005];   double tx, ty;   int sum;   int pnpoly(int nvert, double *vertx, double *verty, double testx,              double testy) {     int i, j, c = 0;     for (i = 0, j = nvert - 1; i < nvert; j = i++) {       if (((verty[i] > testy) != (verty[j] > testy)) &&           (testx <            (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) +                vertx[i]))         c = !c;     }     return c;   }   int main() {     ios::sync_with_stdio(false);     int n;     while (cin >> n) {       sum = 0;       memset(px, 0, sizeof(px));       memset(py, 0, sizeof(py));       for (int i = 0; i <= n; i++) {         cin >> px[i] >> py[i];       }       for (int i = 1; i < n; i++) {         if (px[i] - px[i - 1] == 0) {           tx = px[i];           ty = abs(py[i] - py[i - 1]) / (py[i] - py[i - 1]) * 0.1 + py[i];         } else if (py[i] - py[i - 1] == 0) {           ty = py[i];           tx = abs(px[i] - px[i - 1]) / (px[i] - px[i - 1]) * 0.1 + px[i];         }         if (pnpoly(n, px, py, tx, ty)) {           sum++;         }       }       cout << sum << endl;     }     return 0;   }