#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int maxn = 505, maxm = 1005;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long powermod(long long a, long long b, long long c) {     a = a % c;     long long ans = 1;     while (b) {       if (b % 2) ans = (ans * a) % c;       b = b / 2;       a = (a * a) % c;     }     return ans;   }   long long a[100005];   long long sum[100005];   int main() {     {       long long n, m, i, j, k;       scanf( %lld , &n);       long long cnt = 0, cnt1 = 0;       for (i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         sum[a[i]]++;         if (sum[a[i]] % 2 == 0) cnt++;         if (sum[a[i]] % 4 == 0) cnt1++;       }       long long q, x;       char s[10];       scanf( %lld , &q);       while (q--) {         scanf( %s%lld , s, &x);         if (s[0] ==  + ) {           sum[x]++;           if (sum[x] % 2 == 0) cnt++;           if (sum[x] % 4 == 0) cnt1++;           if (cnt >= 4 && cnt1 >= 1)             printf( YES n );           else             printf( NO n );         } else {           sum[x]--;           if (sum[x] % 2 == 1) cnt--;           if (sum[x] % 4 == 3) cnt1--;           if (cnt >= 4 && cnt1 >= 1)             printf( YES n );           else             printf( NO n );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       bool sym = false;       for (int i = 0; i < n; i++) {         int a, b, c, d;         cin >> a >> b >> c >> d;         if (b == c) sym = true;       }       cout << (!(m & 1) && sym ?  YES  :  NO ) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   pair<long long, long long> p[maxn];   long long m[maxn][2], mm[maxn][2], ycords[maxn], xcords[maxn];   int n;   bool can(long long l) {     for (int i = 0; i < n; i++) {       if (i > 0 && p[i - 1].second == p[i].second) continue;       long long newY = p[i].second + l;       int ind = upper_bound(ycords, ycords + n, newY) - ycords;       int ind1 = lower_bound(ycords, ycords + n, p[i].second) - ycords - 1;       long long left =           min(ind1 < 0 ? INT_MAX : mm[ind1][0], ind < n ? m[ind][0] : INT_MAX);       long long right =           max(ind1 < 0 ? -INT_MAX : mm[ind1][1], ind < n ? m[ind][1] : -INT_MAX);       if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) {         return true;       }       newY = p[i].second - l;       ind = upper_bound(ycords, ycords + n, p[i].second) - ycords;       ind1 = lower_bound(ycords, ycords + n, newY) - ycords - 1;       left =           min(ind1 >= 0 ? mm[ind1][0] : INT_MAX, ind < n ? m[ind][0] : INT_MAX);       right =           max(ind1 >= 0 ? mm[ind1][1] : -INT_MAX, ind < n ? m[ind][1] : -INT_MAX);       if (right - left <= l || (left == INT_MAX && right == -INT_MAX)) {         return true;       }     }     return false;   }   int main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     pair<long long, long long> rot[n];     for (long long i = 0; i < n; i++) {       rot[i].first = p[i].first - p[i].second;       rot[i].second = p[i].second + p[i].first;       p[i] = rot[i];     }     sort(p, p + n,          [](pair<long long, long long> a, pair<long long, long long> b) {            swap(a.first, a.second);            swap(b.first, b.second);            return a < b;          });     for (int i = 0; i < n; i++) {       ycords[i] = p[i].second;     }     m[n - 1][0] = p[n - 1].first;     m[n - 1][1] = p[n - 1].first;     for (int i = n - 2; i >= 0; i--) {       m[i][0] = min(m[i + 1][0], p[i].first);       m[i][1] = max(m[i + 1][1], p[i].first);     }     mm[0][0] = p[0].first;     mm[0][1] = p[0].first;     for (int i = 1; i < n; i++) {       mm[i][0] = min(mm[i - 1][0], p[i].first);       mm[i][1] = max(mm[i - 1][1], p[i].first);     }     long long l = 0, r = 4 * (2e9 + 100);     while (l < r) {       long long mid = (l + r) / 2;       bool result = can(mid);       if (result) {         r = mid;       } else {         l = mid + 1;       }     }     cout << fixed << l / 2.f <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, m, p, k = 0;     cin >> a >> m;     p = a + m;     while (1) {       if ((k % 2) == 0) {         p = p - 2;         a--;         m--;         if (p == 1 || p == 0 || a == 0 || m == 0) {           cout <<  Akshat ;           break;         }       } else {         p = p - 2;         a--;         m--;         if (p == 1 || p == 0 || a == 0 || m == 0) {           cout <<  Malvika ;           break;         }       }       k++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool containsr(int x21, int y21, int x22, int y22, int x11, int y11, int x12,                  int y12) {     return x21 >= x11 && y21 >= y11 && x22 <= x12 && y22 <= y12;   }   int main() {     int n;     cin >> n;     int found = 0;     int x11 = -1, y11 = -1, x12 = -1, y12 = -1;     int bottom = 1;     int left = 1;     int top = n;     int right = n;     int l = bottom, r = top;     while (true) {       if (l > r) {         top = l;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << bottom <<     << right <<     << m << endl;       fflush(stdout);       int res;       cin >> res;       if (res >= 1) {         r = m - 1;       } else {         l = m + 1;       }     }     l = bottom, r = top;     while (true) {       if (l > r) {         bottom = r;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << m <<     << right <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (res >= 1) {         l = m + 1;       } else {         r = m - 1;       }     }     l = left, r = right;     while (true) {       if (l > r) {         right = l;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << bottom <<     << m <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (res >= 1) {         r = m - 1;       } else {         l = m + 1;       }     }     l = left, r = right;     while (true) {       if (l > r) {         left = r;         break;       }       int m = (r + l) / 2;       cout <<  ?   << m <<     << bottom <<     << right <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (res >= 1) {         l = m + 1;       } else {         r = m - 1;       }     }     x11 = left, y11 = bottom, x12 = right, y12 = top;     int x21 = -1, y21 = -1, x22 = -1, y22 = -1;     bottom = 1;     left = 1;     top = n;     right = n;     l = bottom, r = top;     while (true) {       if (l > r) {         top = l;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << bottom <<     << right <<     << m << endl;       fflush(stdout);       int res;       cin >> res;       if (containsr(x11, y11, x12, y12, left, bottom, right, m)) {         res--;       }       if (res >= 1) {         r = m - 1;       } else {         l = m + 1;       }     }     l = bottom, r = top;     while (true) {       if (l > r) {         bottom = r;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << m <<     << right <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (containsr(x11, y11, x12, y12, left, m, right, top)) {         res--;       }       if (res >= 1) {         l = m + 1;       } else {         r = m - 1;       }     }     l = left, r = right;     while (true) {       if (l > r) {         right = l;         break;       }       int m = (r + l) / 2;       cout <<  ?   << left <<     << bottom <<     << m <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (containsr(x11, y11, x12, y12, left, bottom, m, top)) {         res--;       }       if (res >= 1) {         r = m - 1;       } else {         l = m + 1;       }     }     l = left, r = right;     while (true) {       if (l > r) {         left = r;         break;       }       int m = (r + l) / 2;       cout <<  ?   << m <<     << bottom <<     << right <<     << top << endl;       fflush(stdout);       int res;       cin >> res;       if (containsr(x11, y11, x12, y12, m, bottom, right, top)) {         res--;       }       if (res >= 1) {         l = m + 1;       } else {         r = m - 1;       }     }     x21 = left, y21 = bottom, x22 = right, y22 = top;     cout <<  !   << x11 <<     << y11 <<     << x12 <<     << y12 <<     << x21          <<     << y21 <<     << x22 <<     << y22 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int f(string s1, string s2) {     int k = 0;     while (s2 != s1) {       s2 += s2[0];       s2 = s2.substr(1);       k++;       if (k > s2.length()) return 1000000;     }     return k;   }   int main() {     int n;     cin >> n;     vector<string> V(n);     for (int i = 0; i < n; i++) cin >> V[i];     int MIN = 1000000, ans;     for (int i = 0; i < n; i++) {       ans = 0;       for (int j = 0; j < n; j++)         if (j != i) ans += f(V[i], V[j]);       if (ans < MIN) MIN = ans;     }     if (MIN == 1000000)       cout << -1 << endl;     else       cout << MIN << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using graph = vector<vector<int>>;   const ll mod = 1e9 + 7;   const int MAX = 2e5;   int n;   map<pii, ll> memo;   int size[MAX];   void dfs1(int v, int prev, const graph& G, const vector<ll>& V) {     pii p(prev, v);     ll res = 0;     int cnt = 1;     for (auto to : G[v])       if (to != prev) {         dfs1(to, v, G, V);         pii q(v, to);         cnt += size[to];         res = (res - memo[q] + mod) % mod;       }     res = (res + cnt * V[v] % mod) % mod;     size[v] = cnt;     memo[p] = res;   }   void dfs2(int v, int prev, const graph& G, const vector<ll>& V) {     ll val = memo[pii(-1, v)];     for (auto to : G[v])       if (to != prev) {         ll x = memo[pii(v, to)];         ll c = size[to];         ll tmp = memo[pii(to, v)] = (val + x - V[v] * c % mod + mod) % mod;         memo[pii(-1, to)] = (x - tmp + mod + V[to] * (n - c) % mod) % mod;         dfs2(to, v, G, V);       }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     vector<ll> V(n);     for (int i = 0; i < n; i++) {       cin >> V[i];       V[i] = (V[i] + mod) % mod;     }     graph G(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     dfs1(0, -1, G, V);     dfs2(0, -1, G, V);     ll res = 0;     for (int i = 0; i < n; i++) {       res = (res + memo[pii(-1, i)]) % mod;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a, b;     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       a.push_back(tmp);     }     cin >> m;     for (int i = 0; i < m; i++) {       int tmp;       cin >> tmp;       b.push_back(tmp);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     int a3 = 0, b3 = 0;     for (int i = a.size() - 1; i >= 0; i--) {       int l = 0, r = m;       while (l < r) {         int mid = (l + r) / 2;         if (b[mid] >= a[i]) {           r = mid;         } else           l = mid + 1;       }       if ((n - i) - (m - l) >= (a3 - b3)) {         a3 = n - i;         b3 = m - l;       }     }     cout << a3 * 3 + (n - a3) * 2 <<  :  << b3 * 3 + (m - b3) * 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T b, T p, T M) {     long long ret = 1;     for (; p > 0; p >>= 1) {       if (p & 1) ret = (ret * b) % M;       b = (b * b) % M;     }     return (T)ret;   }   template <class T>   inline T lcm(T a, T b) {     return (a * b) / __gcd(a, b);   }   int dx4[] = {-1, 0, 1, 0};   int dy4[] = {0, 1, 0, -1};   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};   int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};   int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};   const double PI = acos(-1.0), EPS = 1e-7;   const long long INF = (long long)1e18 + 7;   const int N = 2e5 + 5, M = 1e9 + 7;   string s, t;   int ok[N];   char re[N];   void fun() {     ok[ A ]++;     re[ A ] =  A ;     ok[ b ]++;     re[ b ] =  d ;     ok[ d ]++;     re[ d ] =  b ;     ok[ H ]++;     re[ H ] =  H ;     ok[ I ]++;     re[ I ] =  I ;     ok[ M ]++;     re[ M ] =  M ;     ok[ O ]++;     re[ O ] =  O ;     ok[ o ]++;     re[ o ] =  o ;     ok[ p ]++;     re[ p ] =  q ;     ok[ q ]++;     re[ q ] =  p ;     ok[ T ]++;     re[ T ] =  T ;     ok[ U ]++;     re[ U ] =  U ;     ok[ V ]++;     re[ V ] =  V ;     ok[ v ]++;     re[ v ] =  v ;     ok[ W ]++;     re[ W ] =  W ;     ok[ w ]++;     re[ w ] =  w ;     ok[ X ]++;     re[ X ] =  X ;     ok[ x ]++;     re[ x ] =  x ;     ok[ Y ]++;     re[ Y ] =  Y ;   }   int main() {     fun();     cin >> s;     t = s;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); i++) {       if (ok[s[i]] && re[s[i]] == t[i])         ;       else {         puts( NIE );         return 0;       }     }     puts( TAK );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x, y;   int main() {     cin >> n >> k;     int l = 1, r = n, mid;     while (l <= r) {       if (l == r) {         x = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     l = 1, r = x - 1;     while (l <= r) {       if (l == r) {         y = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     if (y > 0) {       cout <<  1   << y <<     << x << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK ) {         cout <<  2   << x <<     << y << endl;         fflush(stdout);         return 0;       }     }     l = x + 1, r = n;     while (l <= r) {       if (l == r) {         y = l;         break;       }       mid = l + r >> 1;       cout <<  1   << mid <<     << mid + 1 << endl;       fflush(stdout);       string s;       cin >> s;       if (s ==  TAK )         r = mid;       else         l = mid + 1;     }     cout <<  2   << x <<     << y << endl;     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r;   bool check(int x, int y) { return 1ll * x * x + 3ll * y * y <= 4ll * r * r; }   int main(void) {     scanf( %d , &r);     int i = 1, j = 1;     long long ans = 1;     while (check(i, j + 2)) {       ans += 2;       j += 2;     }     do {       i += 3;       ++j;       while ((j > 0) && ((!check(i, j)) || (!check(i + 1, j - 1)))) j -= 2;       if (j > 0) ans += j * 2;     } while (j > 0);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110000;   const int B = 60;   int n, q, mc;   int aint[4 * N][B];   void update(int nod, int pozx, int pozy, int poz, int val) {     int i;     if (pozx == pozy) {       for (i = 0; i < B; ++i) {         aint[nod][i] = 1;         if (i % val == 0) aint[nod][i]++;       }       return;     }     int mid = (pozx + pozy) / 2;     if (mid >= poz)       update(2 * nod, pozx, mid, poz, val);     else       update(2 * nod + 1, mid + 1, pozy, poz, val);     for (i = 0; i < B; ++i)       aint[nod][i] =           aint[2 * nod][i] + aint[2 * nod + 1][(i + aint[2 * nod][i]) % B];   }   int query(int nod, int pozx, int pozy, int poz1, int poz2) {     if (poz1 <= pozx && pozy <= poz2) {       int rez = aint[nod][mc];       mc = (mc + aint[nod][mc]) % B;       return rez;     }     int mid = (pozx + pozy) / 2, rez = 0;     if (mid >= poz1) rez = query(2 * nod, pozx, mid, poz1, poz2);     if (mid < poz2) rez += query(2 * nod + 1, mid + 1, pozy, poz1, poz2);     return rez;   }   int main() {     int i;     cin >> n;     for (i = 1; i <= n; ++i) {       int x;       cin >> x;       update(1, 1, n, i, x);     }     cin >> q;     for (i = 1; i <= q; ++i) {       char a;       int p1, p2;       cin >> a >> p1 >> p2;       if (a ==  A ) {         mc = 0;         cout << query(1, 1, n, p1, p2 - 1) <<   n ;       } else         update(1, 1, n, p1, p2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t a[4][4] = {0};   int64_t b[4][4] = {0};   int64_t chk(int64_t aa, int64_t bb) {     if (aa == bb) return 0;     if (aa == 3 && bb == 2) return 1;     if (aa == 2 && bb == 1) return 1;     if (aa == 1 && bb == 3) return 1;     return 2;   }   int64_t ma[4][4] = {0};   signed main() {     int64_t k, A, B;     cin >> k >> A >> B;     for (int64_t i = 1; i <= 3; ++i) {       for (int64_t j = 1; j <= 3; ++j) cin >> a[i][j];     }     for (int64_t i = 1; i <= 3; ++i) {       for (int64_t j = 1; j <= 3; ++j) cin >> b[i][j];     }     if (k <= 100 * 1000) {       int64_t curr1 = A;       int64_t curr2 = B;       int64_t la = 0, lb = 0;       int64_t score1 = 0;       int64_t score2 = 0;       int64_t len = 0;       int64_t hey_a = -1, hey_b = -1;       for (int64_t t = 1; t <= k; ++t) {         if (chk(curr1, curr2) == 1)           score1++;         else if (chk(curr1, curr2) == 2)           score2++;         int64_t _c1 = curr1, _c2 = curr2;         curr1 = a[_c1][_c2];         curr2 = b[_c1][_c2];       }       cout << score1 <<     << score2 <<   n ;       return 0;     }     int64_t curr1 = A;     int64_t curr2 = B;     int64_t la = 0, lb = 0;     int64_t score1 = 0;     int64_t score2 = 0;     int64_t len = 0;     int64_t hey_a = -1, hey_b = -1;     for (int64_t t = 1; t <= k; ++t) {       if (ma[curr1][curr2] > 0) {         hey_a = curr1, hey_b = curr2;         len = t - ma[curr1][curr2];         break;       }       ma[curr1][curr2] = t;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];     }     int64_t tstart = -1;     int64_t cnt1 = 0;     curr1 = A, curr2 = B;     for (int64_t t = 1; t <= k; ++t) {       if (curr1 == hey_a && curr2 == hey_b) {         tstart = t;         break;       }       cnt1++;       if (chk(curr1, curr2) == 1)         la++;       else if (chk(curr1, curr2) == 2)         lb++;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];     }     for (int64_t t = tstart; t <= k; ++t) {       if (chk(curr1, curr2) == 1)         score1++;       else if (chk(curr1, curr2) == 2)         score2++;       int64_t _c1 = curr1, _c2 = curr2;       curr1 = a[_c1][_c2];       curr2 = b[_c1][_c2];       if (curr1 == hey_a && curr2 == hey_b) {         break;       }     }     if (len > 0 && (k - cnt1) / len > 0) {       score1 = ((k - cnt1) / len) * score1;       score2 = ((k - cnt1) / len) * score2;     }     score1 += la;     score2 += lb;     int64_t rem = 0;     if (len > 0) rem = (k - cnt1) % len;     if (rem > 0) {       curr1 = hey_a;       curr2 = hey_b;       while (rem--) {         if (chk(curr1, curr2) == 1)           score1++;         else if (chk(curr1, curr2) == 2)           score2++;         int64_t _c1 = curr1, _c2 = curr2;         curr1 = a[_c1][_c2];         curr2 = b[_c1][_c2];       }     }     cout << score1 <<     << score2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pow_mod(int a, long long k, int mod) {     if (k == 0) {       return 1;     }     int sub = pow_mod(a, k / 2, mod);     if (k % 2 == 0) {       return ((long long)sub * sub) % mod;     } else {       return (((long long)sub * sub) % mod * a) % mod;     }   }   int main() {     int h, i, j, l;     int t, n, m, k, q;     int r, c;     scanf( %d %d %d %d %d , &n, &m, &k, &r, &c);     int ax, ay, bx, by;     scanf( %d %d %d %d , &ax, &ay, &bx, &by);     long long count;     long long mod = 1e9 + 7;     if (ax == bx && ay == by) {       count = (long long)n * m;     } else {       count = (long long)n * m - (long long)r * c;     }     printf( %d n , pow_mod(k, count, mod));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   long long a[N], n, mx, cnt;   vector<int> v, e;   long long ans = 1;   long long pw(long long a, long long b) {     if (b == 0) return 1;     long long res = pw(a, b / 2);     res = res * res % mod;     if (b % 2) res = res * a % mod;     return res;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]), mx = max(mx, a[i]);     sort(a, a + n);     for (int i = 2; i <= mx; i++) {       v.clear();       e.clear();       for (int j = 1; j * j <= i; j++) {         if (i % j == 0) {           v.push_back(j);           if (j * j != i) e.push_back(i / j);         }       }       for (int j = (int)e.size() - 1; j >= 0; j--) v.push_back(e[j]);       int now = 0;       long long sum = 1, sum2 = 1;       for (int j = 1; j < (int)v.size(); j++) {         int to = lower_bound(a + now, a + n, v[j]) - a;         sum = sum * pw(j, to - now) % mod;         now = to;       }       sum = sum * pw((int)v.size(), n - now) % mod;       now = 0;       for (int j = 1; j < v.size() - 1; j++) {         int to = lower_bound(a + now, a + n, v[j]) - a;         sum2 = sum2 * pw(j, to - now) % mod;         now = to;       }       sum2 = sum2 * pw((int)v.size() - 1, n - now) % mod;       ans = (ans + sum) % mod;       ans = (ans + mod - sum2) % mod;     }     ans = (ans + mod) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> s;   int a[2000];   int main(int argc, char const *argv[]) {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         int sum = a[i] + a[j];         if (s.find(sum) == s.end())           s[sum] = 1;         else           s[sum]++;       }     }     int ans = 0;     for (auto i : s) {       ans = max(ans, i.second);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(const vector<int>& pearl) {     vector<pair<int, int>> ans;     ans.reserve(pearl.size());     set<int> app;     int l = 0;     for (int i = 0; i < pearl.size(); i++) {       int cur = pearl[i];       if (app.find(cur) != end(app)) {         ans.push_back(make_pair(l + 1, i + 1));         l = i + 1;         set<int>().swap(app);       } else         app.insert(cur);     }     if (l != pearl.size()) {       if (l == 0) {         printf( -1 n );         return;       }       ans[ans.size() - 1].second = pearl.size();     }     printf( %d n , ans.size());     for (const auto& a : ans) printf( %d %d n , a.first, a.second);   }   int main() {     int n;     scanf( %d , &n);     vector<int> pearl(n);     for (int i = 0; i < n; i++) scanf( %d , &pearl[i]);     solve(pearl);   }


#include <bits/stdc++.h>   const int MAXN = 5E5 + 10;   int n;   int a[MAXN << 1];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int t = i + 1 >> 1;       if (i & 1)         a[t] = a[n - t + 1] = i;       else         a[n + t] = a[n * 2 - t] = i;     }     a[2 * n] = n;     if (n & 1)       a[n + 1 >> 1] = n;     else       a[n + (n >> 1)] = n;     for (int i = 2 * n; i > 0; --i) printf( %d%c , a[i],   n  [i > 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double const pi = 3.1415926535897932384626433832795;   int const inf = (int)1e9;   long long const inf64 = (long long)2e18;   const string name =  d ;   vector<pair<int, int> > ans;   int n, d[21];   void rec(int n, int x, int y, int z, bool rev) {     if (n == 0) return;     int now = n - 1;     while (now >= 0 && d[now] == d[n - 1]) now--;     if (now == -1) {       if (rev)         for (int i = 0; i < (int)n; i++) ans.push_back(make_pair(x, y));       else {         for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(x, z));         ans.push_back(make_pair(x, y));         for (int i = 0; i < (int)n - 1; i++) ans.push_back(make_pair(z, y));       }       return;     }     if (now + 1 == n - 1) {       rec(now + 1, x, z, y, 1);       ans.push_back(make_pair(x, y));       rec(now + 1, z, y, x, 1);     } else {       if (!rev) {         rec(now + 1, x, y, z, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(x, z));         rec(now + 1, y, x, z, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(z, y));         rec(now + 1, x, y, z, 0);       } else {         rec(now + 1, x, z, y, 1);         for (int it = 0; it < (int)n - now - 1; it++)           ans.push_back(make_pair(x, y));         rec(now + 1, z, y, x, 1);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < (int)n; i++) cin >> d[i];     reverse(d, d + n);     rec(n, 0, 2, 1, 0);     cout << ans.size() << endl;     for (int i = 0; i < (int)ans.size(); i++)       printf( %d %d n , ans[i].first + 1, ans[i].second + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, r;   int main() {     cin >> n >> r;     int ans = 0, Max = -1, mark = false;     for (int i = 1; i <= r; i++) {       int t = i, b = r, num = 0, cnt = 0;       while (t > 0 && b > 0) {         bool flag = false;         if (b > t) {           int c = b / t - 1;           num += c;           b -= t * c;           if (b > t) {             b -= t;             num++;           }           flag = true;         } else {           if (t > b) {             int c = t / b - 1;             num += c;             t -= b * c;             if (t > b) {               t -= b;               num++;             }           }         }         cnt++;         if (t == b) {           num++;           t -= b;           cnt++;           if (b == r) cnt--;           if (cnt > Max && (max(b, t) == 1 && min(b, t) == 0) && num == n) {             if (!flag)               mark = true;             else               mark = false;             Max = cnt;             ans = i;           }         }       }     }     if (Max == -1) {       cout <<  IMPOSSIBLE  << endl;       return 0;     }     string s;     int t = ans, b = r;     if (mark) swap(b, t);     while (t > 0 && b > 0) {       if (t >= b) {         t -= b;         s +=  T ;       } else {         b -= t;         s +=  B ;       }     }     reverse(s.begin(), s.end());     cout << n - Max << endl << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6;   vector<int> g[MAXN], g1[MAXN];   int n, p, mp, m, all_n;   void add(int t1, int t2) {     g[t1 ^ 1].push_back(t2);     g1[t2].push_back(t1 ^ 1);     g[t2 ^ 1].push_back(t1);     g1[t1].push_back(t2 ^ 1);   }   vector<int> order;   bool vis[MAXN];   int comp[MAXN];   vector<int> res;   void dfs1(int u) {     vis[u] = 1;     for (auto v : g[u]) {       if (vis[v] == 1) continue;       dfs1(v);     }     order.push_back(u);   }   void dfs2(int u, int c) {     comp[u] = c;     for (auto v : g1[u]) {       if (comp[v] == 0) dfs2(v, c);     }   }   bool solveSAT() {     for (int i = 0; i <= all_n * 2 - 3; i++) {       if (vis[i] == 0) dfs1(i);     }     reverse(order.begin(), order.end());     int cnt = 1;     for (auto u : order) {       if (comp[u] == 0) dfs2(u, cnt++);     }     for (int i = 0; i < all_n - 1; i++) {       if (comp[2 * i] == comp[2 * i + 1]) {         return 0;       }       if (comp[2 * i] > comp[2 * i + 1]) {         res.push_back(i);       }     }     return 1;   }   int main() {     cin >> n >> p >> mp >> m;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       add(x * 2, y * 2);     }     all_n = mp + p;     for (int i = 0; i < p; i++) {       int l, r;       cin >> l >> r;       if (l != 1) {         add((l + p - 2) * 2, i * 2 + 1);       }       if (r != mp) {         add((r + p - 1) * 2 + 1, i * 2 + 1);       }     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       add(x * 2 + 1, y * 2 + 1);     }     for (int i = 2; i < mp; i++) {       add((i + p - 2) * 2, (i + p - 1) * 2 + 1);     }     if (!solveSAT()) {       cout <<  -1 n ;       return 0;     }     vector<int> st;     int k = 1;     for (auto t : res) {       if (t < p) {         st.push_back(t);       } else {         k = max(k, t - p + 2);       }     }     cout << st.size() <<     << k << endl;     for (int i = 0; i < st.size(); i++) cout << st[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const M = 2e5 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10,                   sq = 450;   long long a[M], cnt[M], t1, t2, t0, x1;   pair<long long, long long> good, ans;   bool check(long long ind, long long sum) {     if (sum - ind > x1) return 0;     long long res = t2 * ind + t1 * (sum - ind);     if (res >= sum * t0) return 1;     return 0;   }   int32_t main() {     long long x2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     bool flag = 0;     good = make_pair(-1, -1);     if (t1 > t2) swap(t1, t2), swap(x1, x2), flag = 1;     for (long long i = 1; i <= x1 + x2; i++) {       long long lo = 0, hi = min(x2, i);       if (!check(hi, i)) continue;       while (hi > lo + 1) {         long long mid = (lo + hi) / 2;         if (check(mid, i))           hi = mid;         else           lo = mid + 1;       }       long long best = hi;       if (check(lo, i)) best = lo;       long long res = best * t2 + t1 * (i - best);       if (good.first == -1 || (res * good.second <= good.first * i))         good = make_pair(res, i), ans = make_pair(best, i - best);     }     swap(ans.first, ans.second);     if (flag)       cout << ans.second <<     << ans.first;     else       cout << ans.first <<     << ans.second;   }


#include <bits/stdc++.h>   int pct(int x) { return __builtin_popcount(x); }   using namespace std;   char grid[101][101];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m;     char c;     cin >> n >> m >> c;     int row;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> grid[i][j];       }     }     set<char> s;     long long ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j] != c && grid[i][j] !=  . ) {           if (i + 1 < n && grid[i + 1][j] == c && s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (i - 1 >= 0 && grid[i - 1][j] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (j + 1 < m && grid[i][j + 1] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           } else if (j - 1 >= 0 && grid[i][j - 1] == c &&                      s.find(grid[i][j]) == s.end()) {             ans++;             s.insert(grid[i][j]);           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   const long long INF = 1e12;   int solve(long long x) {     int res = 0;     while (x) {       res += (x % 10);       x /= 10;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     long long n;     while (cin >> n) {       long long tmp = 0, b = 0;       while (1) {         tmp = tmp * 10 + 9;         if (tmp > n) break;         b = tmp;       }       cout << solve(b) + solve(n - b) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string lower(string s) {     for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);     return s;   }   vector<string> sep(string s, char c) {     string temp;     vector<string> res;     for (int i = 0; i < s.size(); i++) {       if (s[i] == c) {         if (temp !=   ) res.push_back(temp);         temp =   ;         continue;       }       temp = temp + s[i];     }     if (temp !=   ) res.push_back(temp);     return res;   }   template <class T>   T toint(string s) {     stringstream ss(s);     T ret;     ss >> ret;     return ret;   }   template <class T>   string tostr(T inp) {     string ret;     stringstream ss;     ss << inp;     ss >> ret;     return ret;   }   template <class T>   void D(T A[], int n) {     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }   template <class T>   void D(vector<T> A, int n = -1) {     if (n == -1) n = A.size();     for (int i = 0; i < n; i++) cout << A[i] <<    ;     cout << endl;   }   vector<int> edge[1001];   vector<int> cost[1001];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int> > lst;     for (int(i) = (0); (i) < (n); (i)++) {       int pq;       scanf( %d , &pq);       lst.push_back((make_pair(pq, i)));     }     sort(lst.rbegin(), lst.rend());     int m;     scanf( %d , &m);     for (int(i) = (0); (i) < (m); (i)++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       edge[b].push_back((a));       cost[b].push_back((c));     }     long long ans = 1000000000000LL;     for (int(i) = (0); (i) < (n); (i)++) {       long long total = 0;       bool tval = 1;       for (int(j) = (0); (j) < (n); (j)++) {         if (i == j) continue;         if (edge[j].size() == 0) {           tval = 0;           break;         }         long long chs = 1000000000000LL;         for (int(k) = (0); (k) < (edge[j].size()); (k)++)           chs = min(chs, (long long)cost[j][k]);         total += chs;       }       if (!tval) continue;       ans = min(ans, total);     }     if (ans == 1000000000000LL)       cout << -1 << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     bool F = 1;     for (int i = 2; (long long)i * i <= n; i++) {       if (n % i == 0) {         F = 0;         break;       }     }     bool F2 = 1;     for (int i = 2; (long long)i * i <= n - 2; i++) {       if ((n - 2) % i == 0) {         F2 = 0;         break;       }     }     printf( %d n , F ? 1 : n % 2 == 0 || F2 ? 2 : 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   vector<long long> adj[500050];   long long a[500050], b[500050];   set<long long> s;   void dfs(long long x, long long pr) {     for (long long i = 0; i < adj[x].size(); i++)       if (adj[x][i] != pr) a[adj[x][i]] = *s.begin(), s.erase(s.begin());     b[x] = *s.begin();     s.erase(s.begin());     for (long long j = adj[x].size() - 1; j >= 0; j--)       if (adj[x][j] != pr) dfs(adj[x][j], x);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, y;     cin >> n;     if (n == 1) {       cout <<  1 2 ;       return 0;     }     for (long long i = 2; i < 2 * n + 1; i++) s.insert(i);     for (long long i = 0; i < n - 1; i++)       cin >> x >> y, adj[x].push_back(y), adj[y].push_back(x);     a[1] = 1;     dfs(1, -1);     for (long long i = 1; i < n + 1; i++) cout << a[i] <<     << b[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<pair<long long, long long>, long long>> v;     long long n, k;     cin >> n >> k;     long long p[n], c[n], ans[n];     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       cin >> c[i];       ans[i] = c[i];     }     for (int i = 0; i < n; i++) {       v.push_back({{p[i], c[i]}, i});     }     sort(v.begin(), v.end());     multiset<long long, greater<long long>> s;     for (int i = 0; i < n; i++) {       pair<long long, long long> x = v[i].first;       long long in = v[i].second;       long long coin = x.second;       int cnt = 0;       for (auto e : s) {         if (cnt >= k) break;         ans[in] += e;         cnt++;       }       s.insert(coin);     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void debug_out(const char* name, Arg1&& arg1) {     cout << name <<   =   << arg1 <<   ]  <<   n ;   }   template <typename Arg1, typename... Args>   void debug_out(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   =   << arg1 <<  , ;     debug_out(comma + 1, args...);   }   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   const long long mod = 1e9 + 7;   const long long N = 3e5, M = N;   void Solve_main() {     long long n, m, k;     string s;     char won =  # ;     cin >> n >> s;     deque<long long> d, r;     for (long long i = (0); i < (n); ++i) {       if (s[i] ==  D ) {         d.push_back(i);       } else {         r.push_back(i);       }     }     while (!d.empty() && !r.empty()) {       if (d.front() < r.front()) {         r.pop_front();         long long temp = d.front() + n;         d.pop_front();         d.push_back(temp);       } else {         d.pop_front();         long long temp = r.front() + n;         r.pop_front();         r.push_back(temp);       }     }     if (!d.empty()) {       cout <<  D  <<   n ;     } else {       cout <<  R  <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     long long tc = 1;     for (long long i = 0; i < tc; i++) {       Solve_main();     }     cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   namespace Fread {   const int SIZE = 1 << 21;   char buf[SIZE], *S, *T;   inline char getchar() {     if (S == T) {       T = (S = buf) + fread(buf, 1, SIZE, stdin);       if (S == T) return EOF;     }     return *S++;   }   }  // namespace Fread   namespace Fwrite {   const int SIZE = 1 << 21;   char buf[SIZE], *S = buf, *T = buf + SIZE;   inline void flush() {     fwrite(buf, 1, S - buf, stdout);     S = buf;   }   inline void putchar(char c) {     *S++ = c;     if (S == T) flush();   }   struct NTR {     ~NTR() { flush(); }   } ztr;   }  // namespace Fwrite   namespace Fastio {   struct Reader {     template <typename T>     Reader& operator>>(T& x) {       char c = Fread ::getchar();       T f = 1;       while (c <  0  || c >  9 ) {         if (c ==  - ) f = -1;         c = Fread ::getchar();       }       x = 0;       while (c >=  0  && c <=  9 ) {         x = x * 10 + (c -  0 );         c = Fread ::getchar();       }       x *= f;       return *this;     }     Reader& operator>>(char& c) {       c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       return *this;     }     Reader& operator>>(char* str) {       int len = 0;       char c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       while (c !=   n  && c !=    ) {         str[len++] = c;         c = Fread ::getchar();       }       str[len] =   0 ;       return *this;     }     Reader() {}   } cin;   const char endl =   n ;   struct Writer {     template <typename T>     Writer& operator<<(T x) {       if (x == 0) {         Fwrite ::putchar( 0 );         return *this;       }       if (x < 0) {         Fwrite ::putchar( - );         x = -x;       }       static int sta[45];       int top = 0;       while (x) {         sta[++top] = x % 10;         x /= 10;       }       while (top) {         Fwrite ::putchar(sta[top] +  0 );         --top;       }       return *this;     }     Writer& operator<<(char c) {       Fwrite ::putchar(c);       return *this;     }     Writer& operator<<(char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer& operator<<(const char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer() {}   } cout;   }  // namespace Fastio   const int MAXN = 2e5;   int n;   void solve_case() {     Fastio ::cin >> n;     int ans = n;     for (int i = n - 1; i >= 1; --i) {       ans = (ans + i + 1) / 2;     }     Fastio ::cout << ans << Fastio ::endl;     ans = n;     for (int i = n - 1; i >= 1; --i) {       Fastio ::cout << ans <<     << i << Fastio ::endl;       ans = (ans + i + 1) / 2;     }   }   int main() {     int T;     Fastio ::cin >> T;     while (T--) {       solve_case();     }     return 0;   }


#include <stdio.h>   #include <sys/time.h>      #define N 100000   #define Q 100000   #define A 100000   #define B 2154 /* B = floor(Q^(2/3)) = floor(N^(2/3)) */   #define INF 0x3f3f3f3f      int min(int a, int b) { return a < b ? a : b; }      unsigned int X;      void srand_() {    struct timeval tv;       gettimeofday(&tv, NULL);    X = tv.tv_sec ^ tv.tv_usec;    if (X % 2 == 0)     X++;   }      int rand_() {    return (X *= 3) >> 1;   }      int tt[Q], ll[Q], rr[Q], kk[Q], ans[Q];      int compare(int h1, int h2) {    return h1 / B != h2 / B ? h1 / B - h2 / B : (ll[h1] / B != ll[h2] / B ? ll[h1] / B - ll[h2] / B : rr[h1] - rr[h2]);   }      void sort(int *hh, int l, int r) {    while (l < r) {     int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;        while (j < k) {      int c = compare(hh[j], h);         if (c == 0)       j++;      else if (c < 0) {       tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;       i++, j++;      } else {       k--;       tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;      }     }     sort(hh, l, i);     l = k;    }   }      int kk_[N + 1], prev[N + 1], next[N + 1];      void incr(int i) {    if (next[i] != i + 1) {     prev[i + 1] = i, next[i + 1] = next[i];     next[i] = i + 1;     if (next[i + 1] != -1)      prev[next[i + 1]] = i + 1;    }    kk_[i + 1]++;    if (--kk_[i] == 0) {     if (prev[i] != -1)      next[prev[i]] = next[i];     if (next[i] != -1)      prev[next[i]] = prev[i];    }   }      void decr(int i) {    if (prev[i] != i - 1) {     next[i - 1] = i, prev[i - 1] = prev[i];     prev[i] = i - 1;     if (prev[i - 1] != -1)      next[prev[i - 1]] = i - 1;    }    kk_[i - 1]++;    if (--kk_[i] == 0) {     if (prev[i] != -1)      next[prev[i]] = next[i];     if (next[i] != -1)      prev[next[i]] = prev[i];    }   }      int solve(int k) {    int ans, i, j;       ans = INF;    for (i = next[0], j = 0; i != -1; i = next[i]) {     while (next[j] != -1 && k > 0)      k -= kk_[j = next[j]];     if (k > 0)      break;     ans = min(ans, j - i);     k += kk_[i];    }    return ans == INF ? -1 : ans;   }      int main() {    static int aa[N], aa_[N], old[Q], new_[Q], hh[Q], cnt[A + 1];    int n, q, q_, h, h_, i, l, r;       srand_();    scanf( %d%d , &n, &q);    for (i = 0; i < n; i++)     scanf( %d , &aa[i]), aa_[i] = aa[i];    q_ = 0;    for (h = 0; h < q; h++) {     scanf( %d , &tt[h]);     if (tt[h] == 1) {      scanf( %d%d%d , &ll[h], &rr[h], &kk[h]), ll[h]--, rr[h]--;      hh[q_++] = h;     } else {      int a;         scanf( %d%d , &i, &a), i--;      ll[h] = rr[h] = i, old[h] = aa_[i], new_[h] = aa_[i] = a;     }    }    sort(hh, 0, q_);    kk_[0] = INF, prev[0] = next[0] = -1;    for (h_ = 0, h = 0, l = 0, r = -1; h_ < q_; h_++) {     int h1 = hh[h_], l1 = ll[h1], r1 = rr[h1];        while (h < h1) {      if (tt[h] == 2) {       i = ll[h];       if (l <= i && i <= r)        decr(cnt[aa[i]]--);       aa[i] = new_[h];       if (l <= i && i <= r)        incr(cnt[aa[i]]++);      }      h++;     }     while (h > h1) {      h--;      if (tt[h] == 2) {       i = ll[h];       if (l <= i && i <= r)        decr(cnt[aa[i]]--);       aa[i] = old[h];       if (l <= i && i <= r)        incr(cnt[aa[i]]++);      }     }     while (l > l1)      incr(cnt[aa[--l]]++);     while (r < r1)      incr(cnt[aa[++r]]++);     while (l < l1)      decr(cnt[aa[l++]]--);     while (r > r1)      decr(cnt[aa[r--]]--);     ans[h1] = solve(kk[h1]);    }    for (h = 0; h < q; h++)     if (tt[h] == 1)      printf( %d n , ans[h]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c0, c1, n;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lls[31];   long long comb(long long a, long long b) {     long long s = 1, x, g;     for (long long i = 0; ++i <= b; lls[i] = i)       ;     for (long long i = -1; ++i < b;) {       x = a + b - i;       for (long long j = 0; ++j <= b;) {         g = gcd(lls[j], x);         x /= g;         lls[j] /= g;       }       if (x > 2147483647 / s) return 2147483647;       s *= x;     }     return s;   }   bool check(long long x) {     long long tmp = x / c0 + x / c1 + 1;     if (tmp > n) return 1;     for (long long i = 0; ++i <= 26;) {       for (long long j = i - 1; (++j) * c0 + i * c1 <= x;)         if ((tmp += comb(j, i)) > n) return 1;       for (long long j = i; (++j) * c1 + i * c0 <= x;)         if ((tmp += comb(j, i)) > n) return 1;     }     return 0;   }   void work(long long x, long long &tmp, long long &ans) {     tmp = x / c0 + x / c1 + 1;     ans = ((x / c0) * (x / c0 + 1) * c0 + (x / c1) * (x / c1 + 1) * c1) >> 1;     long long c;     for (long long i = 1; i <= 26; ++i) {       for (long long j = i; j * c0 + i * c1 <= x; ++j) {         c = comb(j, i);         tmp += c;         ans += c * (j * c0 + i * c1);       }       for (long long j = i + 1; j * c1 + i * c0 <= x; ++j) {         c = comb(j, i);         tmp += c;         ans += c * (j * c1 + i * c0);       }     }   }   int main() {     scanf( %lld%lld%lld , &n, &c0, &c1);     --n, c0 > c1 && (swap(c0, c1), 1);     if (!c0) {       printf( %lld n , n * c1);       return 0;     }     long long l = 0, r = c1 * 26, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     long long c, s;     work(l - 1, c, s);     s += (n - c) * l + n * (c0 + c1);     printf( %lld n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 5;   int grid[maxn][maxn];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 0, x1, x2, y1, y2; i < n; i++) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       ans += (x2 - x1 + 1) * (y2 - y1 + 1);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const long long MAX = 2e9 + 7;   const long long mod = 1e9 + 7;   const long long maxn = 1e3 + 7;   int n;   string s[maxn];   set<string> ss;   int jude(string s) {     set<char> q;     int a = s.size();     for (int i = 0; i < s.size(); i++) q.insert(s[i]);     if (q.size() == a)       return 1;     else       return 0;   }   int main() {     cin >> n;     int k = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       sort(s[i].begin(), s[i].end());       s[i].erase(unique(s[i].begin(), s[i].end()), s[i].end());       int flag = 1;       if (jude(s[i])) ss.insert(s[i]);     }     cout << ss.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 300000;   struct Res {     int with, without, best;   };   int n;   vector<int> adj[MAXN];   Res dfs(int at, int par) {     int nch = ((int)(adj[at]).size()) - (par != -1 ? 1 : 0);     Res ret;     ret.with = 1;     ret.without = nch;     ret.best = 0;     int without1 = 0, without2 = 0;     int any1 = 0, any2 = 0;     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par) continue;       Res sub = dfs(to, at);       ret.with = max(ret.with, sub.without + 1);       ret.without = max(ret.without, max(sub.with, sub.without) + nch - 1);       ret.best = max(ret.best, sub.best);       int anyc = max(sub.with, sub.without);       if (anyc > any1)         any2 = any1, any1 = anyc;       else if (anyc > any2)         any2 = anyc;       int withoutc = sub.without;       if (withoutc > without1)         without2 = without1, without1 = withoutc;       else if (withoutc > without2)         without2 = withoutc;     }     ret.best = max(ret.best, max(ret.with, ret.without));     if (nch >= 2)       ret.best = max(ret.best, max(without1 + without2 + 1,                                    any1 + any2 + ((int)(adj[at]).size()) - 2));     return ret;   }   int solve() { return dfs(0, -1).best; }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       adj[a].push_back(b), adj[b].push_back(a);     }     printf( %d n , solve());   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     long long n;     int k, cnt = 0;     scanf( %lld %d , &n, &k);     for (int i = 0; i < 63; i++) {       if (n >> i & 1) {         mp[i] = 1;         ++cnt;       }     }     if (cnt > k) return puts( No ), 0;     puts( Yes );     int st, pre;     for (int i = 62; i >= -62; i--) {       if (mp[i] + cnt <= k) {         pre = i - 1;         mp[i - 1] += 2 * mp[i];         cnt += mp[i];         mp[i] = 0;       } else         break;     }     int x;     for (int i = -62; i < 62; i++) {       if (mp.count(i)) {         x = i;         break;       }     }     vector<int> v;     int res = k - cnt;     if (res > 0) {       --mp[x];       for (int i = 1; i <= res; i++) v.push_back(x - i);       v.push_back(x - res);     }     for (int i = -62; i < 62; i++)       for (int j = 0, y = mp[i]; j < y; j++) v.push_back(i);     sort(v.begin(), v.end(), greater<int>());     for (int i = 0; i < v.size(); i++)       printf( %d%c , v[i],    n [i == v.size() - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long x, b;   void run(int a) {     if (a < 10)       x += a;     else {       x += a - a % 10;       run(a / 10 + a % 10);     }   }   int main() {     cin >> t;     int s[10005];     for (int i = 0; i < t; i++) cin >> s[i];     for (int i = 0; i < t; i++) {       x = 0;       run(s[i]);       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   const int MOD = 1000000007;   const int N = 1E5 + 15;   const int maxn = 2e5 + 14;   const int INF = (1 << 30) - 1;   const int letter = 130;   const double pi = acos(-1.0);   const double eps = 1e-8;   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, q;   long long a[N], b[N];   long long L[N], R[N];   int s[N], top;   void solve(int l, int r) {     int cnt = 0;     for (int i = l; i < r; i++) b[++cnt] = a[i];     b[0] = INF;     b[cnt + 1] = INF;     s[top = 0] = 0;     for (int i = 1; i <= cnt + 1; i++) {       if (b[i] <= b[s[top]])         s[++top] = i;       else {         while (top >= 0 && b[s[top]] < b[i]) R[s[top]] = i - s[top], top--;         s[++top] = i;       }     }     s[top = 0] = cnt + 1;     for (int i = cnt; i >= 0; i--) {       if (b[i] < b[s[top]])         s[++top] = i;       else {         while (top >= 0 && b[s[top]] <= b[i]) L[s[top]] = s[top] - i, top--;         s[++top] = i;       }     }     long long ans = 0;     for (int i = 1; i <= cnt; i++) {       ans += L[i] * R[i] * b[i];     }     printf( %I64d n , ans);   }   int main() {     int x, y;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %I64d , a + i);     for (int i = 1; i < n; i++) a[i] = abs(a[i + 1] - a[i]);     while (q--) {       scanf( %d%d , &x, &y);       solve(x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, m = 0, k = 0, arr[101], seg[100001][3];     long long sum = 0;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) cin >> seg[i][0] >> seg[i][1] >> seg[i][2];     for (int i = 0; i < k; i++) cin >> arr[i];     for (int i = 0; i < k; i++) {       for (int j = 0; j < m; j++) {         if (arr[i] < seg[j][0] || arr[i] > seg[j][1]) continue;         sum += (arr[i] - seg[j][0]) + seg[j][2];       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t n, s, ans = -1, x, y;   int main() {     cin >> n >> s;     while (n--) {       cin >> x >> y;       if (x < s || (x == s && !y)) ans = max(ans, !y ? 0 : 100 - y);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long double x, y;     node(long double X = 0.0, long double Y = 0.0) { x = X, y = Y; }   } que[200005];   int n, k;   int t[200005], head, tail;   long double s[200005], a[200005], b[200005], f[2][200005];   long double K(node, node);   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , t + i);       s[i] = s[i - 1] + t[i];       a[i] = a[i - 1] + s[i] / t[i];       b[i] = b[i - 1] + 1.0 / t[i];     }     int now = 1, lst = 0;     for (int i = 1; i <= n; ++i) f[now][i] = 9999999999999999;     for (int p = 1; p <= k; ++p) {       swap(now, lst);       head = tail = 0;       que[tail++] = node(0, 0);       for (int i = 1; i <= n; ++i) {         while (head + 1 < tail)           if (K(que[head], que[head + 1]) < b[i])             ++head;           else             break;         f[now][i] = que[head].y - que[head].x * b[i] + a[i];         node tmp(s[i], f[lst][i] - a[i] + s[i] * b[i]);         while (head < tail - 1)           if (K(que[tail - 1], que[tail - 2]) > K(que[tail - 2], tmp))             --tail;           else             break;         que[tail++] = tmp;       }     }     printf( %.10lf , (double)f[now][n]);     return 0;   }   long double K(node x, node y) { return (x.y - y.y) / (x.x - y.x); }


#include <bits/stdc++.h>   using namespace std;   const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1};   const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6;   int Case = 1, cas = 0;   long long n, A[mx], Sum;   int main() {     ios_base ::sync_with_stdio(0), cin.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> A[i];       Sum += A[i];     }     if (Sum % 3)       cout << 0 << endl;     else {       long long Ans = 0, taken = 0, milse = 0;       long long target = Sum / 3;       for (int i = 1; i < n; i++) {         taken += A[i];         if (taken == target + target) Ans += milse;         if (taken == target) milse++;       }       cout << Ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, t, ma, sum = 0;     std::string s[1000];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < k; i++) {       cin >> t;       ma = 1;       map<char, int> m;       for (int j = 0; j < n; j++) m[s[j][i]]++;       for (map<char, int>::iterator it = m.begin(); it != m.end(); it++)         ma = max(ma, it->second);       sum += ma * t;     }     cout << sum;   }


#include <bits/stdc++.h>   #pragma optimise GCC(-O2)   using namespace std;   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   int rng(int lim) {     uniform_int_distribution<int> uid(0, lim - 1);     return uid(rang);   }   long long INF = LLONG_MAX;   const long long M = 1000000007;   long long powm(long long, long long);   long long foo(long long a) {     long long ct = 1;     long long tp = a;     while (tp > 0) {       tp -= ct;       ct++;     }     return ct;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     long long hr = 0;     long long mn = 0;     hr += 10 * (s[0] -  0 );     hr += (s[1] -  0 );     mn += 10 * (s[3] -  0 );     mn += (s[4] -  0 );     long long a;     cin >> a;     mn += a;     long long ex = mn / 60;     mn = mn % 60;     hr += ex;     hr %= 24;     if (hr > 9 && mn > 9) cout << hr <<  :  << mn;     if (hr > 9 && mn <= 9) cout << hr <<  :  <<  0  << mn;     if (hr <= 9 && mn > 9) cout <<  0  << hr <<  :  << mn;     if (hr <= 9 && mn <= 9) cout <<  0  << hr <<  :  <<  0  << mn;   }   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b >>= 1;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   using ld = double;   const int MAXN = 1e5 + 1;   vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN];   vector<int64> suf_sum[MAXN];   int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN],       diameter[MAXN];   void max_self(int &a, int b) { a = max(a, b); }   void dfs1(int u) {     comp_ind[u] = comp_cnt;     comp[comp_cnt].emplace_back(u);     for (int v : G[u])       if (!comp_ind[v]) {         p[v] = u;         dfs1(v);         if (dp1[u] <= dp1[v] + 1) {           dp2[u] = dp1[u];           dp1[u] = dp1[v] + 1;         } else           max_self(dp2[u], dp1[v] + 1);       }   }   void dfs2(int u, int dist) {     dp[u] = max(dp1[u], dist);     max_self(diameter[comp_cnt], dp[u]);     for (int v : G[u])       if (v != p[u]) {         if (dp1[u] == dp1[v] + 1)           dfs2(v, max(dp2[u], dist) + 1);         else           dfs2(v, max(dp1[u], dist) + 1);       }   }   ld solve(int x, int y) {     if (x == y) return -1;     if (comp[x].size() > comp[y].size()) swap(x, y);     int D = max(diameter[x], diameter[y]);     ld sum = 0;     for (int d = 0; d <= diameter[x]; ++d) {       int64 freq = suf_freq[x][d];       if (d < diameter[x]) freq -= suf_freq[x][d + 1];       if (freq == 0) continue;       int suf = max(0, min(D - d - 1, diameter[y]));       sum += freq * suf_sum[y][suf];       sum += freq * suf_freq[y][suf] * (d + 1);       int rest = comp[y].size() - suf_freq[y][suf];       sum += freq * rest * D;     }     return sum / ((ld)comp[x].size() * comp[y].size());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int N, M, Q;     cin >> N >> M >> Q;     for (int i = 0; i < M; ++i) {       int u, v;       cin >> u >> v;       G[u].emplace_back(v);       G[v].emplace_back(u);     }     for (int u = 1; u <= N; ++u)       if (!comp_ind[u]) {         ++comp_cnt;         dfs1(u);         dfs2(u, 0);         suf_sum[comp_cnt] = vector<int64>(diameter[comp_cnt] + 1);         suf_freq[comp_cnt] = vector<int>(diameter[comp_cnt] + 1);         for (int v : comp[comp_cnt]) {           suf_sum[comp_cnt][dp[v]] += dp[v];           ++suf_freq[comp_cnt][dp[v]];         }         for (int d = diameter[comp_cnt] - 1; d >= 0; --d) {           suf_sum[comp_cnt][d] += suf_sum[comp_cnt][d + 1];           suf_freq[comp_cnt][d] += suf_freq[comp_cnt][d + 1];         }       }     map<pair<int, int>, ld> sol;     cout << fixed << setprecision(8);     for (int q = 0; q < Q; ++q) {       int u, v;       cin >> u >> v;       u = comp_ind[u], v = comp_ind[v];       pair<int, int> p{u, v};       auto it = sol.find(p);       if (it != sol.end())         cout << it->second <<   n ;       else {         ld ans = solve(u, v);         sol[p] = sol[make_pair(v, u)] = ans;         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   template <class T>   inline void read(T& x, T& y) {     read(x);     read(y);   }   template <class T>   inline void read(T& x, T& y, T& z) {     read(x);     read(y);     read(z);   }   inline char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   const int D = 360360;   long long A, B, C;   int n, i, j, k, l, p;   int f[761000];   int dp(long long A, long long B) {     int i, j;     memset(f, 127, sizeof(f));     f[B - A] = 0;     for (i = B - A; i >= 1; i--) {       long long x = A + i;       f[i - 1] = min(f[i - 1], f[i] + 1);       for (j = 2; j <= k; j++)         if (x - (x % j) >= A)           f[x - (x % j) - A] = min(f[x - (x % j) - A], f[i] + 1);     }     return f[0];   }   int main() {     cin >> B >> A >> k;     long long t1 = (A - 1) / D, t2 = (B - 1) / D, ans, ci = dp(0, D);     if (t1 == t2)       ans = dp(A, B);     else       ans = dp(A, (t1 + 1) * D) + dp(t2 * D, B) + ci * (t2 - t1 - 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, x = 0, y = 0, p = 0, q = 0;       cin >> n;       bool ans = true;       for (int i = 1; i <= n; i++) {         cin >> p >> q;         if (p < x || q < y)           ans = false;         else if (q - y > p - x)           ans = false;         x = p;         y = q;       }       if (ans == true)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   struct point {     long long int x, y;   };   void bfs(long long int node, vector<long long int> adj[], vector<bool> &visit,            vector<long long int> &dis) {     queue<long long int> q;     visit[node] = true;     dis[node] = 0;     q.push(node);     while (!q.empty()) {       long long int s = q.front();       q.pop();       for (auto u : adj[s]) {         if (visit[u]) continue;         visit[u] = true;         dis[u] = dis[s] + 1;         q.push(u);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int tests;     cin >> tests;     for (long long int gg = 0; gg < tests; gg++) {       long long int n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       vector<long long int> adj[n + 1];       for (long long int i = 0; i < n - 1; i++) {         long long int x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       vector<bool> visit(n + 1, false);       vector<long long int> dis(n + 1, 0);       bfs(a, adj, visit, dis);       if (dis[b] <= da) {         cout <<  Alice n ;         continue;       }       if (db > 2 * da) {         long long int m1 = *max_element(dis.begin(), dis.end()), node1 = 0;         for (long long int i = 1; i < n + 1; i++) {           if (dis[i] == m1) {             node1 = i;             break;           }         }         visit.assign(n + 1, false);         dis.assign(n + 1, 0);         bfs(node1, adj, visit, dis);         long long int dia = *max_element(dis.begin(), dis.end());         if (dia > 2 * da) {           cout <<  Bob n ;         } else {           cout <<  Alice n ;         }       } else {         cout <<  Alice n ;       }     }   }


#include <bits/stdc++.h>   const int SIZE_N = (1000 + 10);   const int SIZE_M = (SIZE_N);   const int SIZE_K = (500000 + 10);   int n, m, k;   int mat[SIZE_N][SIZE_M];   int mx[SIZE_M], my[SIZE_N];   int main(void) {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &mat[i][j]);     for (int i = 1; i <= n; ++i) my[i] = i;     for (int i = 1; i <= m; ++i) mx[i] = i;     for (; k > 0; --k) {       char typ[10];       int a, b;       scanf( %s , typ);       scanf( %d%d , &a, &b);       if (typ[0] ==  c ) {         std::swap(mx[a], mx[b]);       } else if (typ[0] ==  r ) {         std::swap(my[a], my[b]);       } else if (typ[0] ==  g ) {         printf( %d n , mat[my[a]][mx[b]]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<int> adj[100005];   vector<int>::iterator it;   int con[100005];   bool visited[100005];   int bfs(int root) {     int j, i, u, v, mn = 10000000, temp;     queue<int> Q;     Q.push(root);     visited[root] = true;     while (!Q.empty()) {       u = Q.front();       Q.pop();       for (i = 0; i < adj[u].size(); i++) {         v = adj[u][i];         if (!visited[v]) {           Q.push(v);           visited[v] = true;         } else {           for (j = 0; j < adj[u].size(); j++) {             if (adj[u][j] != v) {               it = lower_bound(adj[v].begin(), adj[v].end(), adj[u][j]);               if (it != adj[v].end() && ((*it) == adj[u][j])) {                 temp = con[u] + con[v] + con[adj[u][j]] - 6;                 if (temp < mn) mn = temp;               }             }           }         }       }     }     return mn;   }   int main() {     int j, t, i, t1, t2, n, m, ans;     t = 1;     while (t--) {       scanf( %d , &n);       scanf( %d , &m);       memset(visited, 0, sizeof(visited));       for (i = 0; i < m; i++) {         scanf( %d%d , &t1, &t2);         adj[t1].push_back(t2);         adj[t2].push_back(t1);       }       for (i = 1; i <= n; i++) {         sort(adj[i].begin(), adj[i].end());       }       for (i = 1; i <= n; i++) {         con[i] = adj[i].size();       }       ans = 10000000;       for (i = 1; i <= n; i++) {         if (!visited[i]) {           t1 = bfs(i);           if (t1 < ans) ans = t1;         }       }       if (ans == 10000000)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int BIT[100005];   int v[100005], n, i, mayor, lol, cosaMenor = 1000005;   int contMayor, numMenor;   bool record[100005];   int buenos;   void add(int pos) {     while (pos > 0) {       BIT[pos]++;       pos -= pos & (-pos);     }   }   int query(int pos) {     int sum = 0;     while (pos <= n) {       sum += BIT[pos];       pos += pos & (-pos);     }     return sum;   }   int cont[100005];   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &v[i]);     for (i = 1; i <= n; i++) {       if (query(v[i]) == 1)         cont[mayor]++;       else {         if (query(v[i]) > 1) {           cosaMenor = min(cosaMenor, v[i]);         } else {           record[v[i]] = true;           buenos++;         }       }       add(v[i]);       mayor = max(mayor, v[i]);     }     for (i = 1; i <= n; i++) {       if (buenos + cont[i] - (record[i] ? 1 : 0) > contMayor) {         contMayor = buenos + cont[i] - (record[i] ? 1 : 0);         numMenor = i;       } else {         if (buenos + cont[i] - (record[i] ? 1 : 0) == contMayor)           numMenor = min(numMenor, i);       }     }     if (contMayor == 0)       printf( %d , cosaMenor > n ? 1 : cosaMenor);     else       printf( %d , numMenor);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int f[10];     for (int i = 0; i < 10; i++) {       f[i] = 0;     }     for (int i = 0; i < 6; i++) {       int tem;       cin >> tem;       f[tem]++;     }     int leg;     int flag = 0;     for (int i = 0; i < 10; i++) {       if (f[i] >= 4) {         flag = 1;         f[i] = f[i] - 4;         break;       }     }     if (flag == 0) {       cout <<  Alien n ;       return 0;     }     int h = 0, b = 0;     for (int i = 0; i < 10; i++) {       if (f[i] != 0) {         h = i;         f[i] = f[i] - 1;       }     }     for (int i = 0; i < 10; i++) {       if (f[i] != 0) {         b = i;       }     }     if (h == b) {       cout <<  Elephant n ;     } else {       cout <<  Bear n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(T a) {     return a * a;   };   template <typename T>   void dprint(T begin, T end) {     for (auto i = begin; i != end; i++) cerr << (*i) <<    ;     cerr <<   n ;   };   const int maxn = 500 + 5;   int n, step[maxn * 2];   string ans;   pair<int, int> loc[maxn * 2];   bool query(int r1, int c1, int r2, int c2) {     cout <<  ?   << r1 <<     << c1 <<     << r2 <<     << c2 << endl;     cout.flush();     cin >> ans;     return ans ==  YES ;   }   int main() {     scanf( %d , &n);     loc[0] = pair<int, int>(1, 1);     for (int i = 0; i < n - 1; i++) {       if (query(loc[i].first + 1, loc[i].second, n, n)) {         loc[i + 1] = pair<int, int>(loc[i].first + 1, loc[i].second);         step[i] = 0;         continue;       }       if (query(loc[i].first, loc[i].second + 1, n, n)) {         loc[i + 1] = pair<int, int>(loc[i].first, loc[i].second + 1);         step[i] = 1;         continue;       }     }     loc[2 * n - 2] = pair<int, int>(n, n);     for (int i = 2 * n - 2; i > n; i--) {       if (query(loc[i - n].first, loc[i - n].second, loc[i].first,                 loc[i].second - 1)) {         loc[i - 1] = pair<int, int>(loc[i].first, loc[i].second - 1);         step[i - 1] = 1;         continue;       }       if (query(loc[i - n].first, loc[i - n].second, loc[i].first - 1,                 loc[i].second)) {         loc[i - 1] = pair<int, int>(loc[i].first - 1, loc[i].second);         step[i - 1] = 0;         continue;       }     }     if (loc[n].first == loc[n - 1].first + 1)       step[n - 1] = 0;     else       step[n - 1] = 1;     cout <<  !  ;     for (int i = 0; i < 2 * n - 2; i++)       if (step[i] == 0)         cout <<  D ;       else         cout <<  R ;     cout << endl;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, t, u, v;     vector<long long> b;     vector<pair<long long, long long> > a;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &x, &t);       a.push_back(make_pair(x, t));     }     scanf( %d , &v);     a.push_back(make_pair(0, 0));     for (int i = 0; i < a.size(); ++i)       a[i] = make_pair(a[i].first + v * a[i].second,                        -(a[i].first - v * a[i].second));     sort(a.rbegin(), a.rend());     u = v = 0;     for (int i = 0; i < a.size(); ++i) {       x = -a[i].second;       t = upper_bound(b.begin(), b.end(), x) - b.begin();       if (t == b.size())         b.push_back(x);       else         b[t] = x;       if (a[i] == make_pair(0ll, 0ll))         u = max(u, t);       else         v = max(v, t + 1);     }     printf( %d %d n , u, v);     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1000000;   int N;   long long Ans;   std::vector<int> G[MAXN + 5];   long long Val[MAXN + 5];   int Size[MAXN + 5];   int Fa[MAXN + 5], Dep[MAXN + 5];   void Dfs(int u, int fa, int dep) {     Size[u] = 1;     Fa[u] = fa;     Dep[u] = dep;     for (int i = 0; i < int(G[u].size()); i++) {       int v = G[u][i];       if (v != fa) {         Dfs(v, u, dep + 1);         Size[u] += Size[v];         Val[u] += (long long)Size[v] * Size[v];       }     }     Val[u] += (long long)(N - Size[u]) * (N - Size[u]);     Ans -= Val[u];   }   int Pa[MAXN + 5], Num[MAXN + 5];   int Find(int u) { return Pa[u] == u ? u : Pa[u] = Find(Pa[u]); }   long long In1(int u) {     return (long long)(N - Num[u]) * (N - Num[u]) * Num[u] - Val[u] * Num[u];   }   long long In2(int u) {     return (long long)Num[u] * (Num[u] - 1) * 2 * (N - Num[u]);   }   long long In3(int u) {     return std::max((long long)Num[u] * (Num[u] - 1) * (Num[u] - 2), 0ll);   }   void Merge(int u, int v) {     Ans -= In1(u) + In2(u) + In3(u);     Ans -= In1(v) + In2(v) + In3(v);     Pa[v] = u, Num[u] += Num[v];     Val[u] += Val[v] - (long long)Size[v] * Size[v] -               (long long)(N - Size[v]) * (N - Size[v]);     Ans += In1(u) + In2(u) + In3(u);   }   int main() {     scanf( %d , &N);     for (int i = 1; i < N; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v), G[v].push_back(u);     }     Ans = (long long)N * (N - 1) * (N - 1);     Dfs(1, 0, 0);     printf( %lld n , Ans);     for (int i = 1; i <= N; i++) Pa[i] = i, Num[i] = 1;     int Q;     scanf( %d , &Q);     while (Q--) {       int u, v;       scanf( %d%d , &u, &v);       u = Find(u), v = Find(v);       while (u != v) {         if (Dep[u] < Dep[v]) std::swap(u, v);         int anc = Find(Fa[u]);         Merge(anc, u), u = anc;       }       printf( %lld n , Ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 998244353;   const double PI = acos(-1.0);   template <typename _T>   _T Fabs(_T x) {     return x < 0 ? -x : x;   }   template <typename _T>   void read(_T &x) {     _T f = 1;     x = 0;     char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while ( 0  <= s && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   int n, b[400005 * 2], totx, d[400005 * 2], toty, ans;   bool vis[400005];   set<int> st[400005 << 2];   int maxx[400005 << 2], minn[400005 << 2];   struct ming {     int ax, ay, bx, by;   } s[400005];   struct node {     int l, r, val;   };   vector<node> vec[400005];   void updata(int rt, bool fg) {     if (fg)       maxx[rt] = minn[rt] = 0;     else       maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]),       minn[rt] = min(minn[rt << 1], minn[rt << 1 | 1]);     if (!st[rt].empty()) {       int t = *st[rt].rbegin();       if (vis[t])         minn[rt] = max(minn[rt], t);       else         maxx[rt] = max(maxx[rt], t);     }     if (minn[rt] > maxx[rt]) maxx[rt] = 0;   }   void insert(int rt, int l, int r, int al, int ar, int aw) {     if (al <= l && r <= ar) {       if (aw > 0)         st[rt].insert(aw);       else         st[rt].erase(-aw);       updata(rt, l == r);       return;     }     int mid = l + r >> 1;     if (al <= mid) insert(rt << 1, l, mid, al, ar, aw);     if (ar > mid) insert(rt << 1 | 1, mid + 1, r, al, ar, aw);     updata(rt, 0);   }   signed main() {     read(n);     for (int i = 1; i <= n; i++)       read(s[i].ax), read(s[i].ay), read(s[i].bx), read(s[i].by);     for (int i = 1; i <= n; i++) b[++totx] = s[i].ax, b[++totx] = s[i].bx;     sort(b + 1, b + totx + 1);     totx = unique(b + 1, b + totx + 1) - b - 1;     for (int i = 1; i <= n; i++)       s[i].ax = lower_bound(b + 1, b + totx + 1, s[i].ax) - b,       s[i].bx = lower_bound(b + 1, b + totx + 1, s[i].bx) - b;     for (int i = 1; i <= n; i++) d[++toty] = s[i].ay, d[++toty] = s[i].by;     sort(d + 1, d + toty + 1);     toty = unique(d + 1, d + toty + 1) - d - 1;     for (int i = 1; i <= n; i++)       s[i].ay = lower_bound(d + 1, d + toty + 1, s[i].ay) - d,       s[i].by = lower_bound(d + 1, d + toty + 1, s[i].by) - d - 1;     for (int i = 1; i <= n; i++)       vec[s[i].ax].push_back((node){s[i].ay, s[i].by, i}),           vec[s[i].bx].push_back((node){s[i].ay, s[i].by, -i});     for (int i = 1; i <= totx; i++) {       int siz = vec[i].size();       for (int j = 0; j < siz; j++)         insert(1, 1, toty, vec[i][j].l, vec[i][j].r, vec[i][j].val);       while (maxx[1])         vis[maxx[1]] = 1, insert(1, 1, toty, s[maxx[1]].ay, s[maxx[1]].by, 0),         ans++;     }     printf( %d n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n, m;   int a[1 << 20];   int t[1 << 20];   void upd(int v, int val) {     v += 1 << n;     t[v] = val;     v /= 2;     bool cur = 0;     while (v > 0) {       if (cur == 0)         t[v] = t[2 * v] | t[2 * v + 1];       else         t[v] = t[2 * v] ^ t[2 * v + 1];       v /= 2;       cur ^= 1;     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < 1 << n; ++i) scanf( %d , &a[i]);     memset((t), (0), sizeof(t));     bool cur = 1;     for (int h = 1 << n; h > 0; h /= 2) {       for (int v = h; v < 2 * h; ++v)         if (h == 1 << n)           t[v] = a[v - h];         else           t[v] = cur == 0 ? t[2 * v] | t[2 * v + 1] : t[2 * v] ^ t[2 * v + 1];       cur ^= 1;     }     while (m--) {       int p, b;       scanf( %d %d , &p, &b);       upd(p - 1, b);       printf( %d n , t[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200];   map<int, int> Map;   int cnt[20];   int main() {     for (int i = 0; i <= 11; i++) Map[1 << i] = i;     int _;     for (scanf( %d , &_); _; _--) {       scanf( %d , &n);       for (int i = 0; i < 12; i++) cnt[i] = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         if (a[i] > 2048) continue;         cnt[Map[a[i]]]++;       }       for (int i = 0; i <= 10; i++) {         cnt[i + 1] += cnt[i] / 2;       }       if (cnt[11])         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   long long prime[16] = {2,  3,  5,  7,  11, 13, 17, 19,                          23, 29, 31, 37, 41, 43, 47, 53};   long long n, ans;   void DFS(int x, int limit, long long num, long long cnt) {     if (cnt > n) return;     if (cnt == n && num < ans) ans = num;     for (int i = 1; i <= limit; i++) {       if (ans / prime[x] < num) break;       num *= prime[x];       DFS(x + 1, i, num, cnt * (i + 1));     }   }   int main() {     scanf( %lld , &n);     ans = INF;     DFS(0, 64, 1, 1);     printf( %lld n , ans);   }


#include<bits/stdc++.h>           using namespace std;              #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);           #define ll long long int           #define max3(a,b,c) max(max((a),(b)),(c))           #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))           #define min3(a,b,c) min(min((a),(b)),(c))           #define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))           #define all(v) v.begin(),v.end()           #define rall(v) v.rbegin(),v.rend()           typedef pair<int,int> pii;           typedef pair<ll,ll> pll;           const long double PI = 3.14159265358979323846264338;           const long long INF = 1000000000000000000;           const long long INF1 = 1000000000;           const long long MOD = 1000000007;       //    int v[INF],m[INF];           ll fun(ll n){      int b=0;      while(n>0){          b+=n%10;          n/=10;      }      return b;    }           int main(){         ios         int t;         cin>>t;         while(t--){         ll n;         cin>>n;         if(n%2050==0){                 ll sum=n/2050;                 ll ans = fun(sum);                 cout<<ans<<endl;         }         else{             cout<<-1<<endl;         }                  }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     long long k1 = 0, k2 = 1023;     for (long long i = 0; i < n; i++) {       long long k;       char c;       cin >> c >> k;       if (c ==  | ) {         k1 |= k;         k2 |= k;       }       if (c ==  ^ ) {         k1 ^= k;         k2 ^= k;       }       if (c ==  & ) {         k1 &= k;         k2 &= k;       }     }     cout << 2 << endl;     cout <<  |   << (k1 ^ (k2 ^ 1023)) << endl <<  ^   << (k2 ^ 1023);     return 0;   }


#include <bits/stdc++.h>   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, n, m, k, cnt = 0, ans = 0, t = 1;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) cin >> a[i];     priority_queue<long long, vector<long long>, greater<long long> > pq;     for (i = 0; i < n; i++) {       if (!pq.empty() && pq.top() < a[i]) {         ans += (a[i] - pq.top());         pq.pop();         pq.push(a[i]);       }       pq.push(a[i]);     }     return cout << ans, 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename base_type, base_type _MOD>   struct IntMod {     static const int INVERSE_CACHE_SIZE = (1 << 20);     static base_type MOD;     static void set_mod(base_type new_mod) { MOD = new_mod; }     base_type n;     IntMod(long long d = 0) { n = (d >= 0 ? d % MOD : (d % MOD + MOD) % MOD); }     virtual ~IntMod() = default;     IntMod operator-() const { return build(n == 0 ? 0 : MOD - n); }     IntMod& operator+=(IntMod a) {       n = (n >= MOD - a.n ? n - MOD + a.n : n + a.n);       return *this;     }     IntMod& operator-=(IntMod a) {       n = (n >= a.n) ? n - a.n : n - a.n + MOD;       return *this;     }     IntMod& operator*=(IntMod a) {       *this = *this * a;       return *this;     }     IntMod& operator/=(IntMod a) {       *this = *this / a;       return *this;     }     static IntMod build(base_type n) {       IntMod L;       L.n = n;       return L;     }     static base_type inverse_cache[INVERSE_CACHE_SIZE];     static bool inverse_cache_ready;     friend IntMod inverse(IntMod n) { return build(inverse_internal(n.n)); }     static base_type inverse_internal(base_type n) {       if (!inverse_cache_ready) {         inverse_cache_ready = true;         inverse_cache[0] = 0;         inverse_cache[1] = 1;         for (int n = 2; n < INVERSE_CACHE_SIZE; ++n)           inverse_cache[n] =               (MOD -                (base_type)((long long)inverse_cache[MOD % n] * (MOD / n) % MOD));       }       return n < INVERSE_CACHE_SIZE                  ? inverse_cache[n]                  : MOD - (base_type)((long long)inverse_internal(MOD % n) *                                      (MOD / n) % MOD);     }     friend bool operator==(IntMod a, IntMod b) { return a.n == b.n; }     friend bool operator!=(IntMod a, IntMod b) { return a.n != b.n; }     friend IntMod operator+(IntMod a, IntMod b) {       return build(a.n >= MOD - b.n ? a.n - MOD + b.n : a.n + b.n);     }     friend IntMod operator-(IntMod a, IntMod b) {       return build(a.n >= b.n ? a.n - b.n : a.n - b.n + MOD);     }     friend IntMod operator*(IntMod a, IntMod b) {       return build(           static_cast<base_type>(static_cast<long long>(a.n) * b.n % MOD));     }     friend IntMod operator/(IntMod a, IntMod b) { return a * inverse(b); }     friend IntMod xpow(IntMod p, long long e) {       if (e <= 0) return IntMod(1);       IntMod L = IntMod(1);       while (e) {         if (e & 1) L *= p;         p *= p;         e >>= 1;       }       return L;     }     friend ostream& operator<<(ostream& os, const IntMod& p) {       os << p.n;       return os;     }     friend istream& operator>>(istream& is, IntMod& p) {       is >> p.n;       return is;     }   };   template <typename base_type, base_type _MOD>   base_type IntMod<base_type, _MOD>::inverse_cache[INVERSE_CACHE_SIZE];   template <typename base_type, base_type _MOD>   bool IntMod<base_type, _MOD>::inverse_cache_ready;   template <typename base_type, base_type _MOD>   base_type IntMod<base_type, _MOD>::MOD = _MOD;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os << p.first <<     << p.second << endl;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& vec) {     for (const auto& v : vec) os << v <<    ;     return os;   }   long long SQRT(long long x) {     long long ret = sqrt(x) + 5;     while (1) {       if (ret * ret <= x) break;       ret--;     }     return ret;   }   const int maxm = 1e5 + 5;   const int maxn = 2;   const long long MOD = 1e9 + 7;   using Int = IntMod<int, MOD>;   struct Matrix {     Int m[maxn][maxn];     bool empty() {       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++)           if (m[i][j] != (i == j)) return false;       return true;     }     void clear() {       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) m[i][j] = (i == j);     }     friend Matrix operator*(const Matrix& a, const Matrix& b) {       Matrix c;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) c.m[i][j] = 0;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++)           for (int k = 0; k < maxn; k++) c.m[i][j] += a.m[i][k] * b.m[k][j];       return c;     }     friend Matrix pow(Matrix a, long long n) {       Matrix res;       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) res.m[i][j] = (i == j);       while (n) {         if (n & 1) res = res * a;         n >>= 1;         a = a * a;       }       return res;     }   } bs4, E;   struct Vector {     Int m[maxn];     void clear() {       for (int i = 0; i < maxn; i++) m[i] = 0;     }     friend Vector operator*(const Vector& a, const Matrix& b) {       Vector c;       c.clear();       for (int i = 0; i < maxn; i++)         for (int j = 0; j < maxn; j++) c.m[i] += a.m[j] * b.m[i][j];       return c;     }     friend Vector operator+(const Vector& a, const Vector& b) {       Vector c;       for (int i = 0; i < maxn; i++) c.m[i] = a.m[i] + b.m[i];       return c;     }   } I;   Int calc(int idx) {     if (idx <= 1)       return 1;     else {       Matrix p = pow(bs4, idx - 2);       return p.m[1][0] + p.m[1][1];     }   }   struct node {     Vector val;     Matrix lazy;     int l, r;   } tree[maxm * 8];   void push_down(int root) {     if (!tree[root].lazy.empty()) {       tree[root * 2 + 1].val = tree[root * 2 + 1].val * tree[root].lazy;       tree[root * 2 + 2].val = tree[root * 2 + 2].val * tree[root].lazy;       tree[root * 2 + 1].lazy = tree[root * 2 + 1].lazy * tree[root].lazy;       tree[root * 2 + 2].lazy = tree[root * 2 + 2].lazy * tree[root].lazy;       tree[root].lazy.clear();     }   }   void push_up(int root) {     tree[root].val = tree[root * 2 + 1].val + tree[root * 2 + 2].val;   }   void build(int root, int l, int r) {     tree[root].l = l;     tree[root].r = r;     tree[root].lazy.clear();     if (l == r) {       int x;       scanf( %d , &x);       tree[root].val.m[0] = calc(x);       tree[root].val.m[1] = calc(x + 1);       return;     }     int mid = (l + r) / 2;     build(root * 2 + 1, l, mid);     build(root * 2 + 2, mid + 1, r);     push_up(root);   }   void change(int root, int l, int r, const Matrix& val) {     int op = tree[root].l;     int ed = tree[root].r;     if (op > ed) return;     push_down(root);     if (op == l && ed == r) {       tree[root].val = tree[root].val * val;       tree[root].lazy = tree[root].lazy * val;       return;     }     int mid = (op + ed) / 2;     if (r <= mid)       change(root * 2 + 1, l, r, val);     else if (l > mid)       change(root * 2 + 2, l, r, val);     else {       change(root * 2 + 1, l, mid, val);       change(root * 2 + 2, mid + 1, r, val);     }     push_up(root);   }   Vector sum(int root, int l, int r) {     int op = tree[root].l;     int ed = tree[root].r;     if (op > ed) return I;     push_down(root);     if (op == l && ed == r) return tree[root].val;     int mid = (op + ed) / 2;     if (r <= mid)       return sum(root * 2 + 1, l, r);     else if (l > mid)       return sum(root * 2 + 2, l, r);     return sum(root * 2 + 1, l, mid) + sum(root * 2 + 2, mid + 1, r);   }   int main() {     bs4.m[0][0] = 0;     bs4.m[0][1] = 1;     bs4.m[1][0] = 1;     bs4.m[1][1] = 1;     E.clear();     I.clear();     int n, q, op, l, r, val;     scanf( %d%d , &n, &q);     build(0, 1, n);     while (q--) {       scanf( %d%d%d , &op, &l, &r);       if (op == 1) {         scanf( %d , &val);         change(0, l, r, pow(bs4, val));       } else         printf( %d n , sum(0, l, r).m[0].n);     }     return 0;   }


#include <bits/stdc++.h>   bool pr[3001];   int prm[3001];   using namespace std;   void primes() {     int i, j;     for (i = 0; i < 3001; i++) pr[i] = true;     pr[0] = false;     pr[1] = false;     for (i = 2; i <= sqrt(3000); i++) {       if (pr[i]) {         for (j = i; i * j <= 3001; j += 1) {           pr[i * j] = false;         }       }     }   }   int main() {     primes();     int n, i, k = 0, j, ans = 0;     cin >> n;     for (i = 0; i < 3001; i++) {       if (pr[i]) prm[k++] = i;     }     for (j = 6; j <= n; j++) {       int ct = 0;       for (i = 0; prm[i] <= j; i++) {         if (i >= k) break;         if (j % prm[i] == 0) ct++;       }       if (ct == 2) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int chk[300004][3];   int visit[300004];   vector<int> vec[300004];   vector<pair<int, int>> vecp;   void dfs(int x) {     visit[x] = 1;     for (int i = 0; i < vec[x].size(); i++) {       if (visit[vec[x][i]] == 0) {         dfs(vec[x][i]);         chk[x][0] += chk[vec[x][i]][0];         chk[x][1] += chk[vec[x][i]][1];         chk[x][2] += chk[vec[x][i]][2];         vecp.push_back({chk[vec[x][i]][1], chk[vec[x][i]][2]});       }     }   }   int main() {     int a, b, c, d, e, m = 0;     cin >> a;     int r = 0, bl = 0;     for (int i = 1; i <= a; i++) {       cin >> b;       if (b == 1)         r++;       else if (b == 2)         bl++;       chk[i][b]++;     }     for (int i = 1; i < a; i++) {       cin >> b >> c;       vec[b].push_back(c);       vec[c].push_back(b);     }     dfs(1);     for (int i = 0; i < vecp.size(); i++) {       int red = vecp[i].first;       int blue = vecp[i].second;       int redo = r - red;       int blueo = bl - blue;       if (red >= 1 && blue == 0 && blueo >= 1 && redo == 0) {         m++;       } else if (red == 0 && blue >= 1 && blueo == 0 && redo >= 1) {         m++;       }     }     cout << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1011;   const long long INF = 5e16;   namespace IO {   inline long long read() {     long long x = 0;     bool f = 0;     char ch = getchar();     for (; !isdigit(ch); ch = getchar()) f ^= (ch ==  - );     for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 | 48);   }   inline void wrn(long long x) {     write(x);     putchar(   );   }   inline void wln(long long x) {     write(x);     putchar(  n );   }   inline void wlnn(long long x, long long y) {     wrn(x);     wln(y);   }   }  // namespace IO   using namespace IO;   namespace Cesare {   long long x, k, p;   double Ans = 0, f[N][N];   int main() {     x = read(), k = read(), p = read();     double Mul = p * 0.01, Add = 1.0 - Mul;     for (register int i = 0; i <= k; ++i)       for (register int j = x + i; !(j & 1); j >>= 1) ++f[0][i];     for (register int i = (1); i <= (k); ++i)       for (register int j = (0); j <= (k); ++j) {         if (j) f[i][j - 1] += f[i - 1][j] * Add;         if (k >= (j << 1)) f[i][j << 1] += (f[i - 1][j] + 1) * Mul;       }     return printf( %.12lf n , f[k][0]), 0;   }   }  // namespace Cesare   int main() { return Cesare::main(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, l, k, n, m, a, b, c, sum = 0;     cin >> l >> k;     a = l * 2;     b = l * 5;     c = l * 8;     sum = ((a / k) + (b / k) + (c / k));     if (a % k != 0) sum++;     if (b % k != 0) sum++;     if (c % k != 0) sum++;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h, w;   int get(int x, int y) {     if (!y) return x;     if (x == h) return h + y;     if (y == w) return h + w + (h - x);     return h + w + h + (w - y);   }   vector<pair<long long, long long> > get(int h, int w, int x, int a, int b) {     vector<pair<long long, long long> > ans;     if (a <= 0 && b <= 0) return ans;     if (a >= w && b >= w) return ans;     if (x >= h || x <= 0) return ans;     if (a > 0 && a < w && b > 0 && b < w) return ans;     int fl = 0;     if (a > b) swap(a, b), fl = 1;     if (a <= 0 && b >= w) {       ans.push_back(pair<long long, long long>(x, 0));       ans.push_back(pair<long long, long long>(x, w));     } else if (a > 0)       ans.push_back(pair<long long, long long>(x, w));     else       ans.push_back(pair<long long, long long>(x, 0));     if (fl) reverse(ans.begin(), ans.end());     return ans;   }   int x[120005], y[120005];   bool vis[120005];   vector<int> e[120005];   void add(int x, int y) {     e[x].push_back(y);     e[y].push_back(x);   }   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < e[x].size(); i++)       if (!vis[e[x][i]]) dfs(e[x][i]);   }   int main() {     int x1, x2, y1, y2;     scanf( %d%d%d%d , &x1, &y1, &x2, &y2);     swap(y1, y2);     x1 *= 2;     x2 *= 2;     y1 *= 2;     y2 *= 2;     h = x2 - x1, w = y2 - y1;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       x[i] *= 2;       y[i] *= 2;       x[i] -= x1;       y[i] -= y1;     }     int fl = 0;     for (int i = 0; i < n; i++)       if (x[i] < 0 || y[i] < 0 || x[i] > h || y[i] > w) {         rotate(x, x + i, x + n);         rotate(y, y + i, y + n);         fl = 1;         break;       }     if (!fl) return puts( 1 ), 0;     x[n] = x[0];     y[n] = y[0];     int cnt = 0;     vector<pair<long long, int> > vec;     for (int i = 0; i < n; i++)       if (x[i] == x[i + 1]) {         vector<pair<long long, long long> > tmp = get(h, w, x[i], y[i], y[i + 1]);         for (int j = 0; j < tmp.size(); j++)           vec.push_back(               pair<long long, int>(get(tmp[j].first, tmp[j].second), cnt++));       } else {         vector<pair<long long, long long> > tmp = get(w, h, y[i], x[i], x[i + 1]);         for (int j = 0; j < tmp.size(); j++)           vec.push_back(               pair<long long, int>(get(tmp[j].second, tmp[j].first), cnt++));       }     if (!vec.size()) {       int a = h / 2, b = w / 2;       double ang = 0;       for (int i = 0; i < n; i++)         ang += atan2((x[i] - a) * (y[i + 1] - b) - (y[i] - b) * (x[i + 1] - a),                      (x[i] - a) * (x[i + 1] - a) + (y[i] - b) * (y[i + 1] - b));       printf( %d , abs(ang) <= 1 ? 0 : 1);       return 0;     }     for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second);     sort(vec.begin(), vec.end());     for (int i = 0; i < vec.size(); i++)       if (vec[i].second == 0) {         rotate(vec.begin(), vec.begin() + i, vec.end());         break;       }     rotate(vec.begin(), vec.begin() + 1, vec.end());     for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second);     int ans = 0;     for (int i = 0; i < cnt; i++)       if (!vis[i]) dfs(i), ans++;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int sum[1000100];   int main() {     string a, b;     cin >> a >> b;     int cnt = 0;     for (int i = 0; i < b.size(); i++) {       if (b[i] ==  1 ) cnt++;     }     sum[0] = a[0] -  0 ;     for (int i = 1; i < a.size(); i++) {       sum[i] = sum[i - 1] + a[i] -  0 ;     }     int l = 0, r = b.size() - 1;     int ans = 0;     while (r < a.size()) {       if (cnt % 2 == 0 && (sum[r] - sum[l] + a[l] -  0 ) % 2 == 0) {         ans++;       } else if (cnt % 2 != 0 && (sum[r] - sum[l] + a[l] -  0 ) % 2 != 0) {         ans++;       }       l++;       r++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100010], b[100010];   int main(int argc, char *argv[]) {     int n;     long long t, Sum = 0;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &t);       Sum += t;     }     for (int i = 1; i <= n; ++i) scanf( %lld , &b[i]);     sort(b + 1, b + 1 + n);     if (Sum <= (b[n] + b[n - 1]))       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long infl = 0x3f3f3f3f3f3f3f3fLL;   const long long infi = 0x3f3f3f3f;   const long long mod = infl;   long long mygcd(long long a, long long b) {     if (b == 0) {       return a;     }     return mygcd(b, a % b);   }   long long mypow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   void solve() {     long long n, d;     cin >> n >> d;     vector<long long> pro(n);     for (long long i = 1; i < n - 1; i++) {       cin >> pro[i];     }     vector<vector<long long>> gr(n);     for (long long i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       gr[i] = {x, y};     }     auto isok = [&](long long x) {       vector<long long> best(n, -1);       best[0] = x;       queue<long long> q;       q.push(0);       while (q.size()) {         long long front = q.front();         q.pop();         for (long long i = 1; i < n; i++) {           if (i == front) {             continue;           }           long long need =               d * (abs(gr[front][0] - gr[i][0]) + abs(gr[front][1] - gr[i][1]));           if (need > best[front]) {             continue;           }           long long new_best = best[front] - need + pro[i];           if (new_best > best[i]) {             best[i] = new_best;             q.push(i);           }         }       }       if (best[n - 1] == -1) {         return false;       }       return true;     };     long long l = 0;     long long r = infi;     while (l < r) {       long long m = (l + r) / 2;       if (isok(m)) {         r = m;       } else {         l = m + 1;       }     }     cout << r <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(20);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double inf = 1.0 / 0.0;   const double pi = 2 * acos(0.0);   map<char, int> tab, tab1;   char x;   int main() {     tab1[ Q ] = 9;     tab[ q ] = 9;     tab1[ R ] = 5;     tab[ r ] = 5;     tab1[ B ] = 3;     tab[ b ] = 3;     tab1[ P ] = 1;     tab[ p ] = 1;     tab1[ N ] = 3;     tab[ n ] = 3;     tab1[ K ] = 0;     tab[ k ] = 0;     ios_base::sync_with_stdio(false);     int b = 0, w = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         x = getchar();         if (tab.count(x) != 0) {           b += tab[x];         } else if (tab1.count(x) != 0) {           w += tab1[x];         }       }       getchar();     }     if (b > w)       cout <<  Black n ;     else if (w > b)       cout <<  White n ;     else       cout <<  Draw n ;     return 0;   }