#include <bits/stdc++.h>   using namespace std;   template <class _Tp>   _Tp gcd(_Tp a, _Tp b) {     return (b == 0) ? (a) : (gcd(b, a % b));   }   const long long Inf = 1000000000000000000ll;   const int inf = 1000000000;   char buf[1 << 25], *p1 = buf, *p2 = buf;   inline int getc() {     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 25, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0, f = 0;     char c = getc();     while (!isdigit(c)) (c ==  - ) && (f = 1), c = getc();     while (isdigit(c)) x = x * 10 + (c & 15), c = getc();     return f ? -x : x;   }   const int N = 200005;   const int Lg = 19;   int dfn[N], fa[N][Lg], dep[N], siz[N];   int sum[N * 4], t[N * 4], cnt;   vector<int> e[N];   map<int, int> added[N];   void dfs(int u, int f) {     dfn[u] = ++cnt;     fa[u][0] = f;     dep[u] = dep[f] + 1;     siz[u] = 1;     for (int i = 0; i < e[u].size(); ++i) {       int to = e[u][i];       if (to == f) continue;       dfs(to, u);       siz[u] += siz[to];     }   }   void pushup(int o, int len) {     if (t[o])       sum[o] = len;     else if (len == 1)       sum[o] = 0;     else       sum[o] = sum[o << 1] + sum[o << 1 | 1];   }   void update(int o, int l, int r, int L, int R, int val) {     if (L <= l && r <= R) {       t[o] += val;       pushup(o, r - l + 1);       return;     }     int mid = l + r >> 1;     if (L <= mid) update(o << 1, l, mid, L, R, val);     if (R > mid) update(o << 1 | 1, mid + 1, r, L, R, val);     pushup(o, r - l + 1);   }   int n, q;   int main() {     n = read();     q = read();     for (int i = 1; i < n; ++i) {       int x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1, 0);     for (int w = 1; w < Lg; ++w)       for (int i = 1; i <= n; ++i) fa[i][w] = fa[fa[i][w - 1]][w - 1];     while (q--) {       int u = read(), v = read(), k;       if (dfn[u] > dfn[v]) swap(u, v);       if (added[u][v])         added[u][v] = 0, k = -1;       else         added[u][v] = 1, k = 1;       if (dfn[u] + siz[u] - 1 >= dfn[v] + siz[v] - 1) {         int x = v;         for (int w = Lg - 1; ~w; --w)           if (dep[fa[x][w]] > dep[u]) x = fa[x][w];         update(1, 1, n, dfn[x], dfn[v] - 1, k);         update(1, 1, n, dfn[v] + siz[v], dfn[x] + siz[x] - 1, k);       } else {         update(1, 1, n, 1, dfn[u] - 1, k);         update(1, 1, n, dfn[u] + siz[u], dfn[v] - 1, k);         update(1, 1, n, dfn[v] + siz[v], n, k);       }       printf( %d n , n - sum[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int lim = (int)sqrt(n);     int val;     for (int i = 1; i <= lim; i++) {       if (n % i == 0) val = i;     }     cout << val <<     << n / val <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i;     cin >> n;     for (i = 3; n / i >= 1; i = i * 3)       if (n % i != 0) break;     cout << n / i + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-13;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     int k = n / m;     vector<int> v(n);     vector<vector<int>> d(m);     for (int i = 0; i < (int)(n); ++i) {       cin >> v[i];       d[v[i] % m].push_back(i);     }     long long ans = 0;     vector<pair<int, int>> free;     for (int i = 0; i < (int)(2 * m); ++i) {       int cur = i % m;       while (d[cur].size() > k) {         free.push_back(make_pair(d[cur].back(), i));         d[cur].pop_back();       }       while (d[cur].size() < k && !free.empty()) {         d[cur].push_back(free.back().first);         v[free.back().first] += i - free.back().second;         ans += i - free.back().second;         free.pop_back();       }     }     cout << ans <<   n ;     for (auto x : v) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { cin >> x; }   void _R(int64_t &x) { cin >> x; }   void _R(double &x) { cin >> x; }   void _R(long double &x) { cin >> x; }   void _R(char &x) { cin >> x; }   void _R(char *x) { cin >> x; }   void _R(string &x) { cin >> x; }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { cout << x; }   void _W(const int64_t &x) { cout << x; }   void _W(const double &x) { cout << fixed << setprecision(8) << x; }   void _W(const long double &x) { cout << fixed << setprecision(16) << x; }   void _W(const char &x) { cout << x; }   void _W(const char *x) { cout << x; }   void _W(const string &x) { cout << x; }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     cout <<    ;     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) cout <<    ;   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     cout << (sizeof...(tail) ?     :   n );     W(tail...);   }   int n, k;   vector<int> a;   bool ok_even(int x) {     int cnt = 0;     for (int i = (0); i < (n); i++) {       if ((cnt & 1)) {         if (a[i] <= x) cnt++;       } else {         cnt++;       }       if (cnt >= k) return true;     }     return false;   }   bool ok_odd(int x) {     int cnt = 0;     for (int i = (0); i < (n); i++) {       if ((!(cnt & 1))) {         if (a[i] <= x) cnt++;       } else {         cnt++;       }       if (cnt >= k) return true;     }     return false;   }   bool ok(int x) {     if (ok_even(x)) {       return true;     } else if (ok_odd(x)) {       return true;     }     return false;   }   void solve() {     R(n, k);     a.resize(n);     for (int i = (0); i < (n); i++) {       R(a[i]);     }     int l = 0, r = 1e9 + 10;     while (r - l > 1) {       int mid = (r + l) / 2;       if (ok(mid)) {         r = mid;       } else {         l = mid;       }     }     W(r);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int testcase = 1; testcase <= t; testcase++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7, maxn = (int)1e5 + 5;   int a[maxn], d[maxn];   int mpow(int A, int N) {     int ret = 1;     while (N) {       if (N & 1) ret = (ret * 1ll * A) % mod;       A = (A * 1ll * A) % mod;       N >>= 1;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.clear();     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int ans = 0;     for (int i = maxn - 1; i > 0; i--) {       int sz = 0;       for (int j = 1; j * j <= i; j++) {         if (i % j) continue;         if (j != i) d[sz++] = j;         if (j != 1 && j * j != i) d[sz++] = i / j;       }       sort(d, d + sz);       int lim = lower_bound(a, a + n, i) - a;       int cur = (mpow(sz + 1, n - lim) - mpow(sz, n - lim) + mod) % mod;       for (int j = sz - 1; j >= 0; j--) {         int idx = lower_bound(a, a + lim, d[j]) - a;         cur = (cur * 1ll * mpow(j + 1, lim - idx)) % mod;         lim = idx;       }       ans = (ans + cur) % mod;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   int cnt[1009];   int vec[1009];   vector<int> ans;   int main() {     int a, b, c, d, e, i, j, k, l, n, m, x, y, t, p;     scanf( %d , &t);     for (p = 1; p <= t; p++) {       scanf( %d , &n);       s.clear();       ans.clear();       for (i = 0; i <= n; i++) {         s.insert(i);         cnt[i] = 0;       }       for (i = 1; i <= n; i++) {         scanf( %d , &vec[i]);         s.erase(vec[i]);         cnt[vec[i]]++;       }       c = 0;       for (i = 2; i <= n; i++) {         if (vec[i] < vec[i - 1]) {           c = 1;           break;         }       }       if (c) {         while (c) {           auto it = s.begin();           a = *it;           i = a;           if (i == 0) {             i = 1;             for (j = 2; j <= n; j++) {               if (vec[j] < vec[j - 1]) {                 if (vec[j] != j) {                   i = j;                 } else {                   i = j - 1;                 }                 break;               }             }           }           s.erase(it);           ans.push_back(i);           cnt[a]++;           cnt[vec[i]]--;           if (cnt[vec[i]] == 0) {             s.insert(vec[i]);           }           vec[i] = a;           c = 0;           for (i = 2; i <= n; i++) {             if (vec[i] < vec[i - 1]) {               c = 1;               break;             }           }         }       }       l = ans.size();       printf( %d n , l);       for (i = 0; i < l; i++) {         printf( %d  , ans[i]);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   struct abc {     int p, q, idx;   };   bool compareTwoStudents(abc a, abc b) {     if (a.p != b.p) return a.p < b.p;     return (a.q < b.q);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s, s1, s2;     int a, b, c, x, y, z, p, q, u, v, idx;     int i, j, k, m, n, t, flag = 0, count = 0;     cin >> q;     while (q--) {       cin >> n;       cin >> s;       if (s.length() == 2) {         if (s[1] <= s[0]) {           cout <<  NO n ;         } else {           cout <<  YES n2 n ;           for (i = 0; i < s.length(); i++) {             cout << s[i];             if (i == 0) cout <<    ;           }           cout <<   n ;         }       } else {         cout <<  YES n2 n ;         for (i = 0; i < s.length(); i++) {           cout << s[i];           if (i == 0) cout <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d, e, i;     scanf( %d %d %d %d %d , &a, &b, &c, &d, &e);     int arr[e];     if (a == 1 || b == 1 || c == 1 || d == 1)       printf( %d n , e);     else {       for (i = 1; i <= e; i++) {         if (i % a == 0)           arr[i - 1] = 1;         else if (i % b == 0)           arr[i - 1] = 1;         else if (i % c == 0)           arr[i - 1] = 1;         else if (i % d == 0)           arr[i - 1] = 1;         else           arr[i - 1] = 0;       }       int count = 0;       for (i = 0; i < e; i++) {         if (arr[i] == 1) count++;       }       printf( %d n , count);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 107;   const long long mod = 1e9 + 7;   const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};   const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};   const long double pi = acos(-1.0);   const int B = (int)sqrt(N);   int d[16 / 2][2 * 4];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string lada1, lada2, korol, black;     cin >> lada1 >> lada2 >> korol >> black;     int l1x = lada1[0] -  a , l1y = lada1[1] -  1 ;     int l2x = lada2[0] -  a , l2y = lada2[1] -  1 ;     int kx = korol[0] -  a , ky = korol[1] -  1 ;     int bx = black[0] -  a , by = black[1] -  1 ;     d[kx][ky] = 2;     for (int i = 0; i < 4; ++i) {       int x = l1x + rx[i], y = l1y + ry[i];       while (x > -1 && y > -1 && x < 16 / 2 && y < 2 * 4 && d[x][y] != 2) {         d[x][y] = 1;         x += rx[i], y += ry[i];       }     }     for (int i = 0; i < 4; ++i) {       int x = l2x + rx[i], y = l2y + ry[i];       while (x > -1 && y > -1 && x < 16 / 2 && y < 2 * 4 && d[x][y] != 2) {         d[x][y] = 1;         x += rx[i], y += ry[i];       }     }     for (int i = max(0, kx - 1); i < min(8, kx + 2); ++i)       for (int j = max(0, ky - 1); j < min(8, ky + 2); ++j) d[i][j] = 1;     for (int i = max(0, bx - 1); i < min(8, bx + 2); ++i)       for (int j = max(0, by - 1); j < min(8, by + 2); ++j)         if (!d[i][j]) {           cout <<  OTHER  <<   n ;           return 0;         }     cout <<  CHECKMATE  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 30;   int num[MAX], x[MAX];   char s[1000 + 10];   int main() {     int n;     while (cin >> s >> n) {       int m = n;       string a;       memset(num, 0, sizeof num);       int len = strlen(s), sum = 0;       for (int i = 0; i < len; ++i) {         if (!num[s[i] -  a ]) ++sum;         ++num[s[i] -  a ];       }       if (sum > n)         cout <<  -1 ;       else {         for (int i = 0; i < 26; ++i) {           if (num[i]) {             a += (i +  a );             --m;           }           x[i] = 1;         }         while (m) {           int j = 0;           for (int i = 0; i < 26; ++i) {             if ((num[i] - 1) / x[i] + 1 > (num[j] - 1) / x[j] + 1) j = i;           }           a += (j +  a );           ++x[j];           --m;         }         int j = 0;         for (int i = 0; i < 26; ++i) {           if ((num[i] - 1) / x[i] + 1 > (num[j] - 1) / x[j] + 1) j = i;         }         cout << (num[j] - 1) / x[j] + 1 << endl;         cout << a;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print_ret(const std::vector<long long>& ret) {     long long r = 0;     for (typeof((ret).end()) it = (ret).begin(); it != (ret).end(); ++it)       r ^= *it;     cout << r << endl;     cout << ret.size() << endl;     for (typeof((ret).end()) it = (ret).begin(); it != (ret).end(); ++it)       cout << *it <<    ;     cout << endl;   }   int main(int argc, const char* argv[]) {     long long l, r, k;     std::vector<long long> ret;     cin >> l >> r >> k;     if (k == 1) {       ret.push_back(l);     } else if (k == 2) {     k2:       if (r - l >= 2) {         ret.push_back(l + 1);         if (l & 1)           ret.push_back(l + 2);         else           ret.push_back(l);       } else {         ret.push_back(l);         if ((l ^ (l + 1)) < l) ret.push_back(l + 1);       }     } else if (k == 3) {       long long t = l;       while (t & (t - 1)) t &= (t - 1);       t |= (t << 1);       if (t <= r) {         ret.push_back(l);         ret.push_back(t);         ret.push_back(l ^ t);       } else {         goto k2;       }     } else {       for (long long t = l; t <= r; t++) {         if (!(t & 3)) {           if (t + 3 <= r) {             ret.push_back(t);             ret.push_back(t + 1);             ret.push_back(t + 2);             ret.push_back(t + 3);             print_ret(ret);             return 0;           }           break;         }       }       std::vector<long long> vals;       for (long long t = l; t <= r; t++) vals.push_back(t);       long long bestval = l;       long long bestmask = 1;       for (int mask = 1; mask < (1 << vals.size()); mask++) {         long long cur = 0;         for (int i = 0; i < vals.size(); i++) {           if (mask & (1 << i)) cur ^= vals[i];         }         if (cur < bestval) {           bestval = cur;           bestmask = mask;         }       }       for (int i = 0; i < vals.size(); i++) {         if (bestmask & (1 << i)) ret.push_back(vals[i]);       }     }     print_ret(ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<pair<int, int> > &v) {     for (int i = 0; i < v.size(); i++) cout << v[i].second <<    ;     cout << endl;   }   int main() {     int n;     cin >> n;     vector<pair<int, int> > input;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       input.push_back(make_pair(x, i + 1));     }     sort(input.begin(), input.end());     vector<pair<int, int> > swaps;     for (int i = 1; i < n && swaps.size() < 2; i++) {       if (input[i - 1].first == input[i].first) {         swaps.push_back(make_pair(i - 1, i));       }     }     if (swaps.size() < 2) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     print(input);     swap(input[swaps[0].first], input[swaps[0].second]);     print(input);     swap(input[swaps[1].first], input[swaps[1].second]);     print(input);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200000;   struct el {     int l, r, id;   } a[MAX_N], b[MAX_N];   long k[MAX_N];   class compare {    public:     bool operator()(el a, el b) { return a.r < b.r; }   };   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].l >> a[i].r;       a[i].id = i;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> b[i].l >> b[i].r >> k[i];       b[i].id = i;     }     compare cmp;     sort(a, a + n, cmp);     sort(b, b + m, cmp);     int uk = 0;     vector<int> ans(n);     multimap<int, int> mp;     for (int i = 0; i < m; i++) {       while (uk < n && a[uk].r <= b[i].r)         mp.insert(make_pair(a[uk].l, a[uk].id)), uk++;       map<int, int>::iterator it;       for (it = mp.lower_bound(b[i].l); it != mp.end() && k[b[i].id];            it = mp.lower_bound(b[i].l)) {         ans[it->second] = b[i].id + 1;         k[b[i].id]--;         mp.erase(it);       }     }     if (mp.empty() && uk == n) {       cout <<  YES n ;       copy(ans.begin(), ans.end(), ostream_iterator<int>(cout,    ));     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int a[18] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0};   long long n;   int main() {     cin >> n;     if (n == 0) {       cout << 1 << endl;       return 0;     }     int res = 0;     while (n != 0) {       int m = n % 16;       n /= 16;       res += a[m];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     cout << (n + 1) / 36 <<     << ((n + 1) / 3) % 12;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int l = 0;     int r = 0;     vector<int> a(3);     vector<int> b(3);     for (int i = 0; i < 3; i++) {       a[i] = (int)(s[i] -  0 );       b[i] = (int)(s[i + 3] -  0 );       l += a[i];       r += b[i];     }     if (l == r) {       cout <<  0 ;       return 0;     }     int dif = abs(l - r);     if (l > r) {       sort(a.rbegin(), a.rend());       sort(b.begin(), b.end());       if (a[0] >= dif || (9 - b[0]) >= dif) {         cout <<  1 ;         return 0;       }       int mx = max({a[0] + (9 - b[0]), a[0] + a[1], 18 - b[0] - b[1]});       if (mx >= dif) {         cout <<  2 ;         return 0;       }     } else {       sort(a.begin(), a.end());       sort(b.rbegin(), b.rend());       if (b[0] >= dif || (9 - a[0]) >= dif) {         cout <<  1 ;         return 0;       }       int mx = max({b[0] + (9 - a[0]), b[0] + b[1], 18 - a[0] - a[1]});       if (mx >= dif) {         cout <<  2 ;         return 0;       }     }     cout <<  3 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1100000;   const int M = 21;   vector<int> adj[N];   int par[N][M];   int vis[N];   void dfs(int u, int p) {     par[u][0] = p;     for (int v : adj[u]) {       if (v == p) continue;       dfs(v, u);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(n, 0);     for (int i = 1; i < M; i++)       for (int j = 1; j <= n; j++) par[j][i] = par[par[j][i - 1]][i - 1];     vis[n] = 1;     int rest = n - k - 1;     for (int i = n - 1; i >= 0; i--) {       if (vis[i]) continue;       int now = i;       int cnt = 0;       for (int j = M - 1; j >= 0; j--) {         int cur = par[now][j];         if (cur == 0 || vis[cur]) continue;         cnt += 1 << j;         now = cur;       }       if (cnt + 1 > rest) continue;       rest -= cnt + 1;       vis[i] = 1;       now = i;       for (int times = 0; times < cnt; times++) {         now = par[now][0];         vis[now] = 1;       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   int bt(int x) { return 31 - __builtin_clz(x); }   int bt(long long x) { return 63 - __builtin_clzll(x); }   int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }   long long cdiv(long long a, long long b) {     return a / b + !(a < 0 || a % b == 0);   }   int nxt_C(int x) {     int c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   long long nxt_C(long long x) {     long long c = x & -x, r = x + c;     return (((r ^ x) >> 2) / c) | r;   }   vector<int> get_bits(int mask) {     vector<int> bb;     while (mask) {       int b = bt(mask);       bb.push_back(b);       mask ^= (1 << b);     }     reverse(bb.begin(), bb.end());     return bb;   }   int get_mask(vector<int> v) {     int mask = 0;     for (int x : v) {       mask ^= (1 << x);     }     return mask;   }   template <typename T>   void uniq(vector<T> &v) {     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());   }   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long l, long long r) {     uniform_int_distribution<long long> uid(l, r);     return uid(rng);   }   void sc() {}   template <typename Head, typename... Tail>   void sc(Head &H, Tail &...T) {     cin >> H;     sc(T...);   }   const int mod = 1e9 + 7;   int pwr(int a, long long b) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * 1LL * a) % mod;       a = (a * 1LL * a) % mod;       b >>= 1;     }     return ans;   }   const int N = 2e5 + 5;   int a[N];   int dp[N][2];   int n, k;   bool f(int x) {     dp[0][0] = 0;     dp[0][1] = 0;     for (int i = 1; i <= n; i++) {       dp[i][0] = dp[i][1] = 0;     }     for (int i = 0; i <= n - 1; i++) {       for (int j = 0; j <= 1; j++) {         dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);         if (a[i + 1] > x && !j) continue;         dp[i + 1][j ^ 1] = max(dp[i + 1][j ^ 1], dp[i][j] + 1);       }     }     return max(dp[n][0], dp[n][1]) >= k;   }   void solve() {     sc(n, k);     for (int i = 1; i <= n; i++) {       sc(a[i]);     }     int l = 0, r = 1e9 + 5;     while (r - l > 1) {       int m = (l + r) >> 1;       if (f(m))         r = m;       else         l = m;     }     cout << r;   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int tt = 1; tt <= t; tt++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     while (cin >> n >> a >> b >> c) {       int s = a + b + c;       double ans = (1.0 * n / s);       if (a == 0 && b == 0 && c == 0)         printf( %.1lf %.1lf %.1lf n , 0.0, 0.0, 0.0);       else         printf( %.16f %.16f %.16f n , ans * a, ans * b, ans * c);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, dp, q, c, b;   string ans =   ;   void update(int &x) {     if (x == 0)       x = 1;     else       x = 0;   }   int main() {     scanf( %d , &n);     int a[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) scanf( %d , &a[i][j]);     }     for (int i = 0; i < n; i++) dp = (dp + a[i][i]) % 2;     scanf( %d , &q);     while (q--) {       scanf( %d , &b);       if (b == 3) {         printf( %d , dp);       } else {         scanf( %d , &c);         update(dp);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string DIRECTION =  NEWS ;   string s[2];   int n, a[2][1000100], pre[1000100];   void calcPre(int p[]) {     int i = 0, j = -1;     pre[0] = -1;     while (i < n) {       while (j >= 0 && p[i] != p[j]) j = pre[j];       i++;       j++;       pre[i] = (j >= n || p[i] != p[j] ? j : pre[j]);     }   }   int suffixMatch(int s[], int p[]) {     int i = 0, j = 0;     while (i < n) {       while (j >= 0 && s[i] != p[j]) j = pre[j];       i++;       j++;     }     return j;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s[0] >> s[1];     n--;     for (int z = 0; z < 2; z++)       for (int i = 0; i < n; i++)         for (int j = 0; j < 4; j++)           if (s[z][i] == DIRECTION[j]) a[z][i] = j;     reverse(a[0], a[0] + n);     for (int i = 0; i < n; i++) a[0][i] = 3 - a[0][i];     calcPre(a[0]);     cout << (suffixMatch(a[1], a[0]) ?  NO  :  YES ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int nsz = 3e5;   int n;   long long k, mod, a[nsz + 5], b[nsz + 5], ans;   map<long long, int> mp;   long long inline qpow(long long a, int p) {     long long res = 1;     for (; p; p >>= 1) {       if (p & 1) {         res *= a;         res %= mod;       }       a *= a;       a %= mod;     }     return res % mod;   }   long long inline modify(long long a) {     a %= mod;     return a < 0 ? a + mod : a;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> mod >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       ++mp[modify(qpow(a[i], 4) - k * a[i] % mod)];     }     for (__typeof(mp.begin()) it = mp.begin(); it != mp.end(); ++it) {       ans += it->second * (it->second - 1) / 2;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     int fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   struct Po {     long long x, y, t;   } po[200010], b[200010], c[200010];   struct shj {     long long t, x, zh;   } a[200010];   int n, l;   string an, no;   bool vi[2000010][2];   bool c1(const shj &a, const shj &b) { return a.t < b.t; }   bool c2(const Po &a, const Po &b) { return a.t < b.t; }   void check(long long x) {     for (int i = 1; i <= n; i++) {       long long no = b[i].t / l;       c[i] = b[i];       c[i].x -= x * no;       c[i].t %= l;     }     sort(c + 1, c + n + 1, c2);     c[n + 1].t = l;     c[n + 1].x = x;     no =   ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= c[i + 1].t - c[i].t - c[i + 1].x + c[i].x; j++)         no +=  0 ;       for (int j = 1; j <= c[i + 1].x - c[i].x; j++) no +=  1 ;     }     if (an ==   )       an = no;     else if (no < an)       an = no;   }   int main() {     read(n);     read(l);     for (int i = 1; i <= n; i++) {       read(po[i].t);       read(po[i].x);       read(po[i].y);     }     po[++n] = (Po){0, 0, 0};     for (int i = 1; i <= n; i++) {       a[i].t = po[i].t % l;       a[i].x = po[i].x + po[i].y + po[i].t;       b[i].x = (po[i].x + po[i].y + po[i].t) / 2;       b[i].t = po[i].t;       if (a[i].x % 2 == 1 || a[i].x < 0) {         puts( NO );         return 0;       } else         a[i].x /= 2;       a[i].zh = po[i].t / l;     }     a[n + 1] = (shj){l, 0, -1};     sort(a + 1, a + n + 2, c1);     long long nl = 0, nr = l;     for (int i = 1; i <= n; i++) {       long long x = a[i + 1].t - a[i].t, y = a[i + 1].zh - a[i].zh,                 z = a[i + 1].x - a[i].x;       if (y > 0) {         if ((z - x) % y == 0)           nl = max(nl, (z - x) / y);         else           nl = max(nl, (z - x) / y + 1);         nr = min(nr, z / y);       }       if (y < 0) {         z = -z;         y = -y;         if (z % y == 0)           nl = max(nl, z / y);         else           nl = max(nl, z / y + 1);         nr = min(nr, (z + x) / y);       }     }     if (nl > nr) {       puts( NO );       return 0;     }     an =   ;     check(nl);     check(nr);     for (int i = 1; i <= l; i++) vi[i][0] = an[i - 1] -  0 ;     for (int i = 1; i <= n; i++) {       a[i].t = po[i].t % l;       a[i].x = po[i].y - po[i].x + po[i].t;       b[i].x = (po[i].y - po[i].x + po[i].t) / 2;       b[i].t = po[i].t;       if (a[i].x % 2 == 1 || a[i].x < 0) {         puts( NO );         return 0;       } else         a[i].x /= 2;       a[i].zh = po[i].t / l;     }     a[n + 1] = (shj){l, 0, -1};     sort(a + 1, a + n + 2, c1);     nl = 0, nr = l;     for (int i = 1; i <= n; i++) {       long long x = a[i + 1].t - a[i].t, y = a[i + 1].zh - a[i].zh,                 z = a[i + 1].x - a[i].x;       if (y > 0) {         if ((z - x) % y == 0)           nl = max(nl, (z - x) / y);         else           nl = max(nl, (z - x) / y + 1);         nr = min(nr, z / y);       }       if (y < 0) {         z = -z;         y = -y;         if (z % y == 0)           nl = max(nl, z / y);         else           nl = max(nl, z / y + 1);         nr = min(nr, (z + x) / y);       }     }     if (nl > nr) {       puts( NO );       return 0;     }     an =   ;     check(nl);     check(nr);     for (int i = 1; i <= l; i++) vi[i][1] = an[i - 1] -  0 ;     for (int i = 1; i <= l; i++) printf( %c ,  DLRU [2 * vi[i][0] + vi[i][1]]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 255;   int cnt;   int n, a, b, k, f;   map<string, int> M;   map<pair<int, int>, int> Edge;   int main() {     scanf( %d %d %d %d %d , &n, &a, &b, &k, &f);     int last = 0;     int res = 0;     for (int i = 1; i <= n; ++i) {       string aa, bb;       cin >> aa >> bb;       if (!M.count(aa)) M[aa] = ++cnt;       if (!M.count(bb)) M[bb] = ++cnt;       int x = M[aa], y = M[bb];       Edge[{min(x, y), max(x, y)}] += last == x ? b : a;       res += last == x ? b : a;       last = y;     }     priority_queue<int> Q;     for (auto v : Edge) Q.push(v.second);     while (!Q.empty() && k > 0) {       int xd = Q.top();       Q.pop();       if (xd <= f) break;       --k;       res += f - xd;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1;   int n, sol, counter;   bool mark[20];   void check(long long x) {     if (x > n) return;     if (x != 0) sol++;     for (int i = 0; i <= 9; i++) {       if (mark[i]) {         if (i != 0 || (i == 0 && x != 0)) check(x * 10 + i);       } else {         if (counter < 2) {           counter++;           mark[i] = true;           if (i != 0 || (i == 0 && x != 0)) check(x * 10 + i);           mark[i] = false;           counter--;         }       }     }   }   int main() {     scanf( %d , &n);     sol = 0;     counter = 0;     for (int i = 0; i <= 9; i++) mark[i] = false;     long long x = 0;     check(x);     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using ii = pair<int, int>;   using ld = long double;   const int N = 5e5;   bool flip[N], still[N];   int par[N], asdjashsgggg[N], x[N];   int find(int v, bool& b) {     b = flip[v];     while (par[v] != v) {       v = par[v];       b ^= flip[v];     }     return v;   }   tuple<int, int, bool, bool> merge(int u, int v) {     bool bu, bv;     u = find(u, bu);     v = find(v, bv);     if (u == v) {       if (bu == bv)         throw true;       else         throw false;     } else {       int from = u, to = v;       bool flipped = bu == bv, delta = 0;       if (asdjashsgggg[u] == asdjashsgggg[v])         delta = 1;       else if (asdjashsgggg[to] < asdjashsgggg[from])         swap(from, to);       par[from] = to;       flip[from] ^= flipped;       asdjashsgggg[to] += delta;       return {from, to, flipped, delta};     }   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> x[i];       x[i]--;     }     iota(par, par + n, 0);     fill(still, still + k, true);     vector<ii> e;     while (m--) {       int u, v;       cin >> u >> v;       u--, v--;       if (x[u] == x[v] && still[x[u]]) {         try {           merge(u, v);         } catch (bool oc) {           if (oc) still[x[u]] = false;         }       }       e.emplace_back(u, v);     }     int cnt = accumulate(still, still + k, 0);     sort(e.begin(), e.end(), [&](ii a, ii b) {       a = minmax(x[a.first], x[a.second]);       b = minmax(x[b.first], x[b.second]);       return a < b;     });     ii pre = {-1, -1};     stack<tuple<int, int, bool, bool>> s;     bool bad = false;     long long ans = (long long)cnt * (cnt - 1) >> 1;     for (auto [u, v] : e) {       ii cur = minmax(x[u], x[v]);       if (cur.first == cur.second || !still[cur.first] || !still[cur.second])         continue;       if (pre < cur) {         while (!s.empty()) {           auto [from, to, flipped, delta] = s.top();           s.pop();           par[from] = from;           flip[from] ^= flipped;           asdjashsgggg[to] -= delta;         }         pre = cur;         ans -= bad;         bad = false;       }       if (bad) continue;       try {         s.push(merge(u, v));       } catch (bool oc) {         if (oc) bad = true;       }     }     ans -= bad;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dfn[200002], low[200002], tot, head[200002], num, f[200002];   int p[20][200002];   int deep[200002], n, m, q, st[200002], top, dep[200002];   bool vis[200002];   inline long long rd() {     long long x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f ? -x : x;   }   struct edge {     int n, to;   } e[200002];   inline void add(int u, int v) {     e[++tot].n = head[u];     e[tot].to = v;     head[u] = tot;   }   vector<int> vec[200002];   void tarjan(int u, int fa) {     dfn[u] = low[u] = ++dfn[0];     st[++top] = u;     vis[u] = 1;     for (vector<int>::iterator it = vec[u].begin(); it != vec[u].end(); ++it) {       int v = *it;       if (v == fa) continue;       if (!dfn[v]) {         tarjan(v, u);         low[u] = min(low[u], low[v]);         if (low[v] == dfn[u]) {           ++num;           add(u, num);           int x = 0;           while (x != v) {             x = st[top];             add(num, x);             vis[x] = 0;             top--;           }         }         if (low[v] > dfn[u]) {           add(u, v);           vis[st[top]] = 0;           top--;         }       } else if (vis[v])         low[u] = min(low[u], dfn[v]);     }   }   void dfs(int u, int fa) {     for (int i = 1; (1 << i) <= deep[u]; ++i) p[i][u] = p[i - 1][p[i - 1][u]];     for (int i = head[u]; i; i = e[i].n)       if (e[i].to != fa) {         int v = e[i].to;         f[v] = u;         deep[v] = deep[u] + 1;         p[0][v] = u;         dep[v] = dep[u] + (v > n);         dfs(v, u);       }   }   inline int getlca(int u, int v) {     if (deep[u] < deep[v]) swap(u, v);     for (int i = 19; i >= 0; --i)       if (deep[u] - (1 << i) >= deep[v]) u = p[i][u];     if (u == v) return u;     for (int i = 19; i >= 0; --i)       if (p[i][u] != p[i][v]) u = p[i][u], v = p[i][v];     return p[0][u];   }   inline int dist(int u, int v) {     int lca = getlca(u, v);     return deep[u] + deep[v] - 2 * deep[lca] -            (dep[u] + dep[v] - dep[lca] - dep[f[lca]]);   }   int main() {     n = rd();     m = rd();     q = rd();     int u, v;     for (int i = 1; i <= m; ++i) {       u = rd();       v = rd();       vec[u].push_back(v);       vec[v].push_back(u);     }     num = n;     tarjan(1, 0);     dfs(1, 0);     while (q--) {       u = rd();       v = rd();       printf( %d n , dist(u, v));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt_list, pos[20200], pa[20100], len[20100], fs[20100], pc[20100],       ls[20100], cnt_ls, tmp[20100], cnt, n, num_q;   struct pp {     int id;     char ch;   };   vector<pp> adj[20201];   pp now;   void dfs(int id, int pr) {     int i, j, s, p, q, ip;     pos[id] = cnt_list++;     pa[pos[id]] = pr;     for (i = 0; i < adj[id].size(); i++) {       ip = adj[id][i].id;       if (pos[ip] >= 0) continue;       pc[cnt_list] = adj[id][i].ch -  a ;       dfs(ip, pos[id]);     }   }   int main() {     int id1, id2, i, j, s, p, q, x, y, fg;     char ch;     scanf( %d%d , &n, &num_q);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &id1, &id2);       ch = getchar();       while (ch <  a  || ch >  z ) ch = getchar();       id1--;       id2--;       now.id = id2;       now.ch = ch;       adj[id1].push_back(now);       now.id = id1;       now.ch = ch;       adj[id2].push_back(now);     }     memset(pos, -1, sizeof(pos));     dfs(0, -1);     while (num_q--) {       scanf( %d%d , &x, &y);       x--;       y--;       x = pos[x];       y = pos[y];       int u, v;       u = x;       v = y;       cnt_ls = cnt = 0;       while (u != v) {         if (u > v) {           ls[cnt_ls++] = pc[u];           u = pa[u];         } else {           tmp[cnt++] = pc[v];           v = pa[v];         }       }       while (cnt > 0) ls[cnt_ls++] = tmp[--cnt];       for (i = 0; i < n; i++) len[i] = -1;       u = x;       fs[u] = len[u] = 0;       int ans = 0;       while (u != 0) {         len[pa[u]] = len[u] + 1;         if (fs[u] == 0) {           if (len[u] < cnt_ls) {             if (ls[len[u]] > pc[u])               fs[pa[u]] = -1;             else if (ls[len[u]] < pc[u])               fs[pa[u]] = 1;             else               fs[pa[u]] = 0;           } else             fs[pa[u]] = 1;         } else           fs[pa[u]] = fs[u];         if (fs[pa[u]] < 0 || (fs[pa[u]] == 0 && len[pa[u]] != cnt_ls)) ans++;         u = pa[u];       }       for (i = 1; i < n; i++) {         if (len[pa[i]] >= 0 && len[i] < 0) {           len[i] = len[pa[i]] + 1;           if (fs[pa[i]] == 0) {             if (len[pa[i]] < cnt_ls) {               if (ls[len[pa[i]]] > pc[i])                 fs[i] = -1;               else if (ls[len[pa[i]]] < pc[i])                 fs[i] = 1;               else                 fs[i] = 0;             } else               fs[i] = 1;           } else             fs[i] = fs[pa[i]];           if (fs[i] < 0 || (fs[i] == 0 && len[i] != cnt_ls)) ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   #pragma GCC optimize( -ffloat-store )   using namespace std;   const auto start_time = std::chrono::high_resolution_clock::now();   void aryanc403() {}   const long long int INF = 0xFFFFFFFFFFFFFFFL;   long long int seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline long long int rnd(long long int l = 0, long long int r = INF) {     return uniform_int_distribution<long long int>(l, r)(rng);   }   class CMP {    public:     bool operator()(pair<long long int, long long int> a,                     pair<long long int, long long int> b) {       return !(a.first < b.first || (a.first == b.first && a.second <= b.second));     }   };   void add(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt == m.end())       m.insert({x, cnt});     else       jt->second += cnt;   }   void del(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt->second <= cnt)       m.erase(jt);     else       jt->second -= cnt;   }   bool cmp(const pair<long long int, long long int> &a,            const pair<long long int, long long int> &b) {     return a.first < b.first || (a.first == b.first && a.second < b.second);   }   const long long int mod = 1000000007L;   const long long int L = 38;   long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y;   long long int m;   string s;   vector<long long int> a;   vector<pair<long long int, pair<long long int, long long int>>> hashes,       prefHash;   long long int getHash() {     long long int a = 0;     for (long long int i = 0; i < L; ++i) a = a * 3 + rnd(0, 2);     return a;   }   void getVec(vector<long long int> &a, long long int n) {     for (long long int i = 0; i < L; ++i) {       a.push_back(n % 3);       n /= 3;     }   }   long long int getXOR(const long long int &a1, const long long int &b1) {     vector<long long int> a, b;     getVec(a, a1);     reverse(begin(a), end(a));     getVec(b, b1);     reverse(begin(b), end(b));     long long int ans = 0;     for (long long int i = 0; i < L; ++i) ans = ans * 3 + ((a[i] + b[i]) % 3);     return ans;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       cin >> n;       hashes.resize(n + 1);       for (auto &v : hashes) {         v.first = getHash();         v.second.first = getHash();         v.second.second = getHash();       }       a.clear();       a.reserve(n + 1);       prefHash.resize(n + 1);       a.push_back(0);       prefHash[0] = hashes[0];       for (i = (1); i <= (n); ++i) {         cin >> in;         a.push_back(in);         prefHash[i].first = getXOR(prefHash[i - 1].first, hashes[in].first);         prefHash[i].second.first =             getXOR(prefHash[i - 1].second.first, hashes[in].second.first);         prefHash[i].second.second =             getXOR(prefHash[i - 1].second.second, hashes[in].second.second);       }       vector<long long int> freq(n + 1, 0);       map<pair<long long int, pair<long long int, long long int>>, long long int>           hval;       long long int l = 0;       long long int ans = 0;       hval[prefHash[0]]++;       for (long long int i = 1; i <= n; ++i) {         freq[a[i]]++;         while (l < i && freq[a[i]] > 3) {           hval[prefHash[l]]--;           l++;           freq[a[l]]--;         }         ans += hval[prefHash[i]];         hval[prefHash[i]]++;       }       cout << ans <<   n ;     }     aryanc403();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const string nl =   n ;   long long n, k, hld = 0, sum, hld1 = 0;   vector<long long> a;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cin >> n >> k;     a.resize(n);     for (auto& i : a) {       cin >> i;     }     for (long long i = 0; i < n; ++i) {       sum += a[i];       hld = max(hld, sum);       hld1 = min(hld1, sum);     }     cout << max(0LL, k - (hld - hld1 - 1)) << nl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, i;     cin >> t;     for (i = 1; i <= t; i++) {       cin >> n;       if (n % 4 == 0)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int ms = 200200;   const int eps =  z  -  a  + 1;   void print(int x) {     for (int i = 0; i < eps; i++) {       std::cout << ((x & (1 << i)) ? 1 : 0);     }     std::cout <<   n ;   }   char t[200200];   std::string str[200200];   int main() {     int n;     std::cin >> n;     int isnt = 0;     int know = (1 << eps) - 1;     int ans = 0;     for (int i = 0; i < n; i++) {       std::cin >> t[i] >> str[i];     }     for (int i = 0; i < n; i++) {       int tot = (~isnt & know);       bool hmm = tot - (tot & -tot) == 0;       int mask = 0;       for (auto a : str[i]) {         mask |= 1 << (a -  a );       }       if (t[i] ==  ! ) {         if (hmm) {           ans++;         }         know &= mask;       } else if (t[i] ==  . ) {         isnt |= mask;       } else {         if (hmm && (1 << (str[i][0] -  a )) != tot) {           ans++;         }         if (!hmm && str[i][0] != str[n - 1][0]) {           isnt |= 1 << (str[i][0] -  a );         }       }     }     std::cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   int N, M;   int a[110];   int b[110];   int sum[110];   int num[110][30];   char ans[110];   void solve(int n) {     string temp;     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     memset(sum, 0, sizeof(sum));     cout <<  ? 1   << n << endl;     cout.flush();     for (int i = n * (n + 1) / 2; i > 0; i--) {       cin >> temp;       for (int j = 0; j < temp.size(); j++) {         a[temp.size()] += temp[j] -  a ;       }     }     cout <<  ? 1   << n - 1 << endl;     cout.flush();     for (int i = n * (n - 1) / 2; i > 0; i--) {       cin >> temp;       for (int j = 0; j < temp.size(); j++) {         b[temp.size()] += temp[j] -  a ;       }     }     for (int i = 1; i <= n; i++) {       sum[i] = a[i] - b[i];       ans[n - i] = sum[i] - sum[i - 1] +  a ;     }   }   int main() {     string temp;     int limit;     int now;     while (~scanf( %d , &N)) {       if (N <= 3) {         char c;         for (int i = 1; i <= N; i++) {           cout <<  ?   << i <<     << i << endl;           cout.flush();           cin >> c;           ans[i - 1] = c;         }       } else {         memset(num, 0, sizeof(num));         limit = (N + 1) >> 1;         solve(limit);         cout <<  ?   << 1 <<     << N << endl;         cout.flush();         for (int i = N * (N + 1) / 2; i > 0; i--) {           cin >> temp;           for (int j = 0; j < temp.size(); j++) {             num[temp.size()][temp[j] -  a ]++;           }         }         for (int i = N; i >= limit; i--) {           for (int j = 1; j <= min(N - i + 1, limit); j++) {             now = j;             num[i][ans[j - 1] -  a ] -= now;           }           for (int j = now + 1; j <= limit; j++) {             num[i][ans[j - 1] -  a ] -= now;           }         }         for (int i = N; i > limit; i--) {           for (int j = 0; j < 30; j++) {             if (num[i][j] / (N - i + 1) * (N - i + 2) != num[i - 1][j]) {               ans[i - 1] = j +  a ;               for (int k = i - 1; k >= limit; k--) {                 num[k][j] -= N - i + 1;               }               break;             }           }         }       }       ans[N] =   0 ;       printf( ! %s n , ans);       cout.flush();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   vector<string> getWords(string s) {     string cur =   ;     vector<string> vec;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==    ) {         vec.push_back(cur);         cur =   ;       } else         cur += s[i];     }     vec.push_back(cur);     return vec;   }   int dist[213456], sz[213456];   vector<vector<int> > vec;   void dfs(int n, int p) {     sz[n] = 1;     for (auto x : vec[n]) {       if (x != p) {         dist[x] = dist[n] + 1;         dfs(x, n);         sz[n] += sz[x];       }     }   }   int main() {     int n, k;     cin >> n >> k;     vec.resize(n + 1);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       vec[u].push_back(v);       vec[v].push_back(u);     }     dfs(1, 0);     vector<long long> vec1;     for (int i = 2; i <= n; i++) {       int val = dist[i] - (sz[i] - 1);       vec1.push_back(val);     }     sort(vec1.begin(), vec1.end());     reverse(vec1.begin(), vec1.end());     long long ans = 0;     for (int i = 0; i < k; i++) ans += vec1[i];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, r, c;   vector<string> grip;   int main() {     grip.clear();     cin >> r >> c >> n >> k;     string ful =   ;     for (int i = 0; i < c; i++) ful +=  . ;     for (int i = 0; i < r; i++) grip.push_back(ful);     for (int i = 0; i < n; i++) {       int y, x;       cin >> y >> x;       y--, x--;       grip[y][x] =  # ;     }     int ans = 0;     for (int il = 0; il < r; il++) {       for (int ir = il; ir < r; ir++) {         for (int jl = 0; jl < c; jl++) {           for (int jr = jl; jr < c; jr++) {             int con = 0;             for (int p = il; p <= ir; p++) {               for (int q = jl; q <= jr; q++)                 if (grip[p][q] ==  # ) con++;             }             if (con >= k) ans++;           }         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int h[N], nex[N << 1], to[N << 1], tot, dis[N];   void add(int x, int y) {     to[++tot] = y;     nex[tot] = h[x];     h[x] = tot;   }   int fa[N][30], dep[N], lg[N];   void dfs(int u, int fath, int d) {     dis[u] = d;     fa[u][0] = fath;     dep[u] = dep[fath] + 1;     for (int i = 1; i <= lg[dep[u]]; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];     for (int j = h[u]; j; j = nex[j])       if (to[j] != fath) dfs(to[j], u, d + 1);   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     while (dep[x] > dep[y]) x = fa[x][lg[dep[x] - dep[y]] - 1];     if (x == y) return x;     for (int i = lg[dep[x] - 1]; i >= 0; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     for (int i = 1; i <= n; i++) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);     dfs(1, 0, 0);     int q;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int x, y, a, b, k;       scanf( %d%d%d%d%d , &x, &y, &a, &b, &k);       int lcab = lca(a, b);       int d1 = dis[a] + dis[b] - 2 * dis[lcab];       if (k >= d1 && (k % 2) == (d1 % 2)) {         printf( Yes n );         continue;       }       int lcax = lca(a, x);       int lcay = lca(a, y);       int lcby = lca(b, y);       int lcbx = lca(b, x);       int d2 = dis[x] + dis[a] - 2 * dis[lcax];       int d3 = dis[a] + dis[y] - 2 * dis[lcay];       int d4 = dis[b] + dis[y] - 2 * dis[lcby];       int d5 = dis[b] + dis[x] - 2 * dis[lcbx];       if (k >= (d2 + 1 + d4) && (k % 2) == ((d2 + 1 + d4) % 2)) {         printf( Yes n );       } else if (k >= (d3 + 1 + d5) && (k % 2) == ((d3 + 1 + d5) % 2)) {         printf( Yes n );       } else {         printf( No n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const long long M = 1000000007;   long long a;   int main() {     scanf( %I64d , &a);     a %= 360;     a += 360;     long long ans = 0, mx = -1;     for (int i = 0; i < 4; i++) {       if (mx < abs((a + i * 270) % 360 - 180)) {         mx = abs((a + i * 270) % 360 - 180);         ans = i;       }     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int pos[100005];   pair<int, int> tree[100005];   bool func(pair<int, int> x, pair<int, int> y) { return (x.first) < (y.first); }   int main() {     int n;     for (int i = 1; i < 100005; i++) {       pos[i] = 2e9 + 1000;     }     pos[0] = -2e9;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &tree[i].first, &tree[i].second);     }     sort(tree, tree + n, func);     int mx = 0, g;     for (int i = 0; i < n; i++) {       if (i != 0 && tree[i].first - tree[i].second <= tree[i - 1].first) {       } else {         g = lower_bound(pos, pos + n, tree[i].first - tree[i].second) - pos;         pos[g] = min(pos[g], tree[i].first);         mx = max(mx, g);       }       if (i != n - 1 && tree[i].first + tree[i].second >= tree[i + 1].first) {       } else {         g = lower_bound(pos, pos + n, tree[i].first) - pos;         pos[g] = min(pos[g], tree[i].first + tree[i].second);         mx = max(mx, g);       }     }     printf( %d , mx);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<char> s(n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     vector<char> t(n);     for (int i = 0; i < n; i++) {       cin >> t[i];     }     vector<int> ans;     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) {         continue;       } else {         char target = t[i];         for (int j = n - 2; j >= i; j--) {           if (s[j + 1] == target) {             swap(s[j], s[j + 1]);             ans.push_back(j + 1);           }         }         if (s[i] != t[i]) {           cout << -1;           return 0;         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200], n, c = 0;     double sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sort(a, a + n);     while (double(sum / n) < 4.5) {       sum += (5 - a[c]);       c++;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buffer[2000020], *p1, *p2;   template <class T>   void read(T& x) {     char ch = ((p1 == p2 &&                 (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                    ? EOF                    : *p1++);     x = 0;     bool f = 1;     while (!( 0  <= ch && ch <=  9 ) && ch !=  - )       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                 ? EOF                 : *p1++);     if (ch ==  - )       f = 0,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                 ? EOF                 : *p1++);     while ( 0  <= ch && ch <=  9 )       x = (x << 1) + (x << 3) + ch -  0 ,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                 ? EOF                 : *p1++);     x = (f) ? x : -x;   }   int _num[20];   template <class T>   void write(T x) {     if (!x) {       putchar( 0 ), putchar(  n );       return;     }     if (x < 0) putchar( - ), x = -x;     int c = 0;     while (x) _num[++c] = x % 10, x /= 10;     while (c) putchar( 0  + _num[c--]);     putchar(  n );   }   int bc[128];   int masks[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};   int a[2020], res[2020];   int n, k;   bool vis[2020][2020], dp[2020][2020];   bool DP(int pos, int rest) {     if (pos > n) return rest == 0;     if (vis[pos][rest]) return dp[pos][rest];     vis[pos][rest] = 1;     bool& ans = dp[pos][rest];     ans = false;     for (register int i = 9; i >= 0; i--) {       if ((a[pos] | masks[i]) != masks[i]) continue;       if (rest < bc[masks[i] ^ a[pos]]) continue;       if (DP(pos + 1, rest - bc[masks[i] ^ a[pos]])) {         res[pos] = i;         return ans = true;       }     }     return ans;   }   int main() {     bc[0] = 0;     for (register int i = 1; i <= 127; i++) bc[i] = bc[i >> 1] + (i & 1);     read(n), read(k);     for (register int i = 1; i <= n; i++) {       char ch =           ((p1 == p2 &&             (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                ? EOF                : *p1++);       while (ch !=  0  && ch !=  1 )         ch = ((p1 == p2 &&                (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                   ? EOF                   : *p1++);       while (ch ==  0  || ch ==  1 )         a[i] = (a[i] << 1) + ch -  0 ,         ch = ((p1 == p2 &&                (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))                   ? EOF                   : *p1++);     }     if (!DP(1, k))       printf( -1 );     else       for (register int i = 1; i <= n; i++) printf( %d , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100010;   int n, parent[maxN], child[maxN];   long long f[maxN], g[maxN], res;   struct ioi {     int v, w;   };   vector<ioi> adj[maxN];   void dfs(int u) {     child[u] = 1;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i].v;       if (parent[u] == v) continue;       parent[v] = u;       dfs(v);       child[u] = child[u] + child[v];       f[u] += ((adj[u][i].w) ? child[v] : f[v]);     }   }   void dfs_g(int u) {     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i].v;       if (parent[u] == v) continue;       int tmp = ((adj[u][i].w) ? child[v] : f[v]);       g[v] = (adj[u][i].w) ? (n - child[v]) : (f[u] + g[u] - tmp);       dfs_g(v);     }   }   bool check(int x) {     while (x) {       if (((x % 10) != 4) && ((x % 10) != 7)) return false;       x /= 10;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n - 1; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       w = check(w);       ioi tmp;       tmp.v = v;       tmp.w = w;       adj[u].push_back(tmp);       tmp.v = u;       tmp.w = w;       adj[v].push_back(tmp);     }     dfs(1);     dfs_g(1);     for (int i = 1; i <= n; ++i) res += ((f[i] + g[i]) * (f[i] + g[i] - 1));     cout << res;     fclose(stdin);     fclose(stdout);   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar();     return ans;   }   inline long long L_read() {     long long ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar();     return ans;   }   int dx[5] = {0, -1, 1, 0, 0};   int dy[5] = {0, 0, 0, -1, 1};   struct cz {     long long Time;     bool Initial;   };   cz state[1050][1050];   bool mp[1050][1050];   long long p;   string s;   struct pos {     int x;     int y;   };   pos ww;   inline bool check(int x, int y, int n, int m) {     for (int i = 1; i <= 4; i++) {       int nowx = x + dx[i], nowy = y + dy[i];       if (nowx >= 1 && nowx <= n && nowy >= 1 && nowy <= m)         if (mp[nowx][nowy] == mp[x][y]) return true;     }     return false;   }   int n, m, k, x, y;   bool vis[1050][1050];   queue<pos> qwq;   inline void bfs() {     while (!qwq.empty()) {       int nowx = qwq.front().x;       int nowy = qwq.front().y;       qwq.pop();       for (int i = 1; i <= 4; i++) {         if (nowx + dx[i] >= 1 && nowx + dx[i] <= n && nowy + dy[i] >= 1 &&             nowy + dy[i] <= m) {           if (!vis[nowx + dx[i]][nowy + dy[i]]) {             vis[nowx + dx[i]][nowy + dy[i]] = 1;             state[nowx + dx[i]][nowy + dy[i]].Time = state[nowx][nowy].Time + 1;             ww.x = nowx + dx[i];             ww.y = nowy + dy[i];             qwq.push(ww);           }         }       }     }   }   int Odd(long long i) { return (i & 1) != 0; }   int main() {     bool ff = 0;     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  1 ) state[i][j + 1].Initial = 1, mp[i][j + 1] = 1;       }     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (check(i, j, n, m)) {           ww.x = i, ww.y = j;           vis[i][j] = 1;           qwq.push(ww);           ff = 1;         }     if (!ff) {       for (int i = 1; i <= k; i++) {         x = read(), y = read(), p = L_read();         cout << mp[x][y] <<   n ;       }       return 0;     }     bfs();     for (int i = 1; i <= k; i++) {       x = read(), y = read();       p = L_read();       if (p <= state[x][y].Time) {         cout << state[x][y].Initial <<   n ;         continue;       }       if (!Odd(p - state[x][y].Time))         cout << state[x][y].Initial <<   n ;       else {         if (state[x][y].Initial == 0)           cout << 1 <<   n ;         else           cout <<  0 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static const long long L = 233333;     static char sxd[L], *sss = sxd, *ttt = sxd;     if (sss == ttt) {       ttt = (sss = sxd) + fread(sxd, 1, L, stdin);       if (sss == ttt) {         return EOF;       }     }     return *sss++;   }   inline char readalpha() {     char c = gc();     for (; !isalpha(c); c = gc())       ;     return c;   }   inline char readchar() {     char c = gc();     for (; c ==    ; c = gc())       ;     return c;   }   template <class T>   inline bool read(T& x) {     bool flg = false;     char c = gc();     x = 0;     for (; !isdigit(c); c = gc()) {       if (c ==  - ) {         flg = true;       } else if (c == EOF) {         return false;       }     }     for (; isdigit(c); c = gc()) {       x = (x << 1) + (x << 3) + (c ^ 48);     }     if (flg) {       x = -x;     }     return true;   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10) {       putchar(x | 48);       return;     }     write(x / 10);     putchar((x % 10) | 48);   }   const int maxn = 20;   const int maxl = 1000005;   int n;   int f[1 << maxn];   int g[1 << maxn];   char s[maxl];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; ++i) {       int now = i, nowzt = 0;       while (now) {         if (nowzt & (1 << (s[now] -  a ))) {           break;         }         nowzt |= (1 << (s[now] -  a ));         now--;         f[nowzt] = i - now;       }     }     int ans = 0;     for (int i = 0; i < 1 << 20; ++i) {       g[i] = f[i];     }     for (int i = 0; i < 1 << 20; ++i) {       for (int j = 0; j < 20; ++j) {         g[i | (1 << j)] = max(g[i], g[i | (1 << j)]);       }     }     for (int i = 0; i < 1 << 20; ++i) {       ans = max(ans, f[i] + g[((1 << 20) - 1) ^ i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, sum = 0;     cin >> n >> m;     vector<int> v;     for (int i = 0; i < n; i++) {       int ff;       cin >> ff;       v.push_back(ff);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       if (x == 1) {         int l, k;         cin >> l >> k;         v[l - 1] = k - sum;       }       if (x == 2) {         int y;         cin >> y;         { sum += y; }       }       if (x == 3) {         int ans;         cin >> ans;         cout << v[ans - 1] + sum << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> used;   int main() {     int n, k;     scanf( %d %d , &n, &k);     int a[n];     long long ans = 0;     int p = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       used[a[i]]++;       if (used[a[i]] == k) {         ans += (long long)(n - i);         while (1) {           used[a[p]]--;           if (a[p++] == a[i]) break;           ans += (long long)(n - i);         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 9, inf = 0x3f3f3f3f;   void Chkmax(int &x, int y) {     if (y > x) x = y;   }   int n, ans, mx, root;   int a[maxn], sum[maxn];   void Solve(int v) {     static int b[maxn], last[maxn << 1];     for (int i = 1; i <= n; ++i) {       if (a[i] == root) {         b[i] = 1;       } else if (a[i] == v) {         b[i] = -1;       } else         b[i] = 0;     }     int V(n);     for (int i = 0; i <= 2 * n; ++i) last[i] = inf;     last[V] = 0;     int nw(0);     for (int i = 1; i <= n; ++i) {       nw += b[i];       if (last[nw + V] <= i) {         Chkmax(ans, i - last[nw + V]);       } else         last[nw + V] = i;     }   }   int main() {     scanf( %d , &n);     mx = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       sum[a[i]]++;       Chkmax(mx, a[i]);     }     root = 0;     for (int i = 1; i <= mx; ++i) {       if (sum[i] > sum[root]) {         root = i;       }     }     for (int i = 1; i <= mx; ++i)       if (i ^ root) {         Solve(i);       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       vector<pair<int, int> > v;       for (int i = 0; i < n; i++) {         int k, l;         cin >> k >> l;         v.push_back(make_pair(k, l));       }       int j = 0, ma = -1, b = 0;       for (int i = 0; i < n; i++) {         b = max(b, v[i].first);         if ((v[i].first - v[i].second) > ma) {           ma = max(v[i].first - v[i].second, ma);           j = v[i].first;         } else if ((v[i].first - v[i].second) == ma) {           if (v[i].first > j) {             j = v[i].first;           }         }       }       if (b >= x) {         cout <<  1  << endl;       } else if (ma > 0) {         if ((x - b) % ma == 0) {           cout << (x - b) / ma + 1 << endl;         } else {           cout << (x - b) / ma + 2 << endl;         }       } else {         cout <<  -1  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int add[N << 6], num[N << 6], lazy[N << 6], ls[N << 6], rs[N << 6], total;   int init() {     num[total] = add[total] = lazy[total] = 0;     ls[total] = rs[total] = -1;     return total++;   }   void down(int l, int r, int o) {     if (ls[o] == -1) ls[o] = init();     if (rs[o] == -1) rs[o] = init();     int ll = ls[o], rr = rs[o];     add[ll] += add[o];     add[rr] += add[o] + num[o] * ((l + r) / 2 + 1 - l);     num[ll] += num[o];     num[rr] += num[o];     lazy[ll] += lazy[o];     lazy[rr] += lazy[o];     num[o] = add[o] = lazy[o] = 0;   }   int L, R, V, op;   void update(int l, int r, int o) {     if (L <= l && r <= R) {       if (op == 0) {         lazy[o] += V;       } else {         add[o] += l - L + 1;         num[o]++;       }       return;     }     down(l, r, o);     int ll = ls[o], rr = rs[o];     if (L <= (l + r) / 2) update(l, (l + r) / 2, ll);     if (R > (l + r) / 2) update((l + r) / 2 + 1, r, rr);   }   int query(int l, int r, int o, int x) {     if (l == r) {       return add[o] + lazy[o];     }     down(l, r, o);     int ll = ls[o], rr = rs[o];     if (x <= (l + r) / 2)       return query(l, (l + r) / 2, ll, x);     else       return query((l + r) / 2 + 1, r, rr, x);   }   struct Node {     int l, t, fg;     Node() {}     Node(int l, int t, int fg) : l(l), t(t), fg(fg) {}     bool operator<(const Node& th) const {       if (l != th.l) return l < th.l;       if (fg != th.fg) return fg > th.fg;       return t < th.t;     }   } node[N * 2];   int ll[N * 4], rr[N * 4], tt[N * 4];   multiset<int> st;   int main() {     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       int tot = 0;       for (int i = 0; i < m; i++) {         int l, r, t;         scanf( %d%d%d , &l, &r, &t);         r--;         node[tot++] = Node(l, t, 1);         node[tot++] = Node(r, t, -1);       }       sort(node, node + tot);       int cnt = 0, pre;       st.clear();       for (int i = 0; i < tot; i++) {         int l = node[i].l, t = node[i].t, fg = node[i].fg;         if (st.size() == 0) {           pre = l;           st.insert(t);           continue;         }         if (l > pre) {           ll[cnt] = pre;           rr[cnt] = l - 1;           tt[cnt] = *st.begin();           cnt++;           pre = l;         }         if (fg == -1) {           if (pre == l) {             ll[cnt] = pre;             rr[cnt] = l;             tt[cnt] = *st.begin();             cnt++;             pre = l + 1;           }           st.erase(st.lower_bound(t));         } else {           st.insert(t);         }       }       int ed = 1e9;       total = 0;       init();       for (int i = 0; i < cnt; i++) {         int l = ll[i], r = rr[i], t = tt[i];         op = 0;         V = r - l + 1;         L = max(0, t - l + 1), R = ed;         if (L <= R) update(0, ed, 0);         L = t - r, R = t - l;         op = 1;         if (R >= 0) update(0, ed, 0);       }       for (int i = 0; i < n; i++) {         int a;         scanf( %d , &a);         printf( %d n , query(0, ed, 0, a));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 1000000 + 5;   const int maxn = 6400 + 5;   struct Edge {     int to, next;   } edges[maxm];   int indices[maxn];   int deg[maxn];   char ans[maxm];   int an;   int over;   inline int Trans_index(char* s) { return (s[0] -  0 ) * 80 + (s[1] -  0 ); }   void DFS(int x) {     while (indices[x] != -1) {       int y = edges[indices[x]].to;       indices[x] = edges[indices[x]].next;       DFS(y);     }     ans[an++] = x / 80 +  0 ;   }   int main() {     int n;     scanf( %d n , &n);     memset(indices, 0xff, sizeof(indices));     int start;     for (int i = 0; i < n; i++) {       char line[5];       gets(line);       int x = start = Trans_index(line);       edges[i].to = Trans_index(line + 1);       ;       edges[i].next = indices[x];       indices[x] = i;       deg[edges[i].to]++;       deg[x]--;     }     int cnt_err = 0;     over = -1;     for (int i = 0; i < maxn; i++) {       if (deg[i] == 0)         continue;       else if (deg[i] < 0)         start = i, cnt_err -= deg[i];       else         over = i, cnt_err += deg[i];     }     if (cnt_err != 0 && cnt_err != 2) {       puts( NO );       return 0;     }     DFS(start);     for (int i = 0; i < maxn; i++) {       if (indices[i] != -1) {         printf( NO );         return 0;       }     }     puts( YES );     reverse(ans, ans + an);     if (cnt_err == 0) over = start;     ans[an++] =  0  + over % 80;     ans[an++] =   0 ;     puts(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000050;   int a[N];   int main() {     int n, k;     cin >> n >> k;     if (n == 1 && k == 10)       cout <<  -1  << endl;     else {       if (k == 10) {         cout <<  1 ;         for (int i = 1; i < n; i++) cout <<  0 ;         cout << endl;       } else {         for (int i = 0; i < n; i++) cout << k;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long dad = 1e6;   int n, m, l = 1, r;   long long k;   long long d[dad], a[dad], b[dad], res, ans[dad], dem[dad];   struct yasu {     int id, l, r;   } p[dad], c[dad];   bool cmp(yasu u, yasu v) {     return (u.l / 300 < v.l / 300 || (u.l / 300 == v.l / 300 && u.r < v.r));   }   void update(int u, long long gt1, long long gt2, long long gt3) {     res += dem[c[u].l] * gt2;     res += dem[c[u].r] * gt3;     dem[c[u].id] += gt1;   }   int getint() {     int ww = 0;     char cc = getchar();     while (cc >  9  || cc <  0 ) cc = getchar();     while (cc >=  0  && cc <=  9 ) {       ww = ww * 10 + cc -  0 ;       cc = getchar();     }     return ww;   }   long long getll() {     long long ww = 0;     char cc = getchar();     while (cc >  9  || cc <  0 ) cc = getchar();     while (cc >=  0  && cc <=  9 ) {       ww = ww * 10 + cc -  0 ;       cc = getchar();     }     return ww;   }   void input() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; ++i) {       d[i] = getll();       d[i] = d[i] == 1 ? 1 : -1;     }     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       a[i] = a[i - 1] + a[i] * d[i];     }     for (int i = 0; i <= n; ++i) {       b[++*b] = a[i];       b[++*b] = a[i] + k;       b[++*b] = a[i] - k;     }     sort(b + 1, b + *b + 1);     *b = unique(b + 1, b + *b + 1) - b - 1;     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &p[i].l, &p[i].r);       --p[i].l;       p[i].id = i;     }     for (int i = 0; i <= n; ++i) {       c[i].id = lower_bound(b + 1, b + *b + 1, a[i]) - b;       c[i].l = lower_bound(b + 1, b + *b + 1, a[i] - k) - b;       c[i].r = lower_bound(b + 1, b + *b + 1, a[i] + k) - b;     }     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= m; ++i) {       int l1 = p[i].l;       int r1 = p[i].r;       while (l < l1) {         --dem[c[l].id];         res -= dem[c[l].r];         ++l;       }       while (l > l1) {         --l;         res += dem[c[l].r];         ++dem[c[l].id];       }       while (r < r1) {         ++r;         res += dem[c[r].l];         ++dem[c[r].id];       }       while (r > r1) {         --dem[c[r].id];         res -= dem[c[r].l];         --r;       }       ans[p[i].id] = res;     }     for (int i = 1; i <= m; ++i) printf( %lld n , ans[i]);   }   void output() {}   int main() {     input();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = unsigned long long;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int k;     cin >> k;     int n = (1 << k);     vector<vector<ll> > a(n, vector<ll>(n, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     int t;     cin >> t;     vector<pair<int, int> > shape(t);     for (int i = 0; i < t; i++) cin >> shape[i].first >> shape[i].second;     for (int r = 0; r < k; r++) {       vector<vector<ll> > b(n, vector<ll>(n, 0));       for (int c = 0; c < t; c++) {         for (int i = 0; i < (1 << k); i++) {           for (int j = 0; j < (1 << k); j++) {             b[(i + shape[c].first) & ((1 << k) - 1)]              [(j + shape[c].second) & ((1 << k) - 1)] ^= a[i][j];           }         }       }       a = b;       for (int c = 0; c < t; c++) {         shape[c].first = (shape[c].first * 2) % n;         shape[c].second = (shape[c].second * 2) % n;       }     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j]) ans++;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int xinc[] = {0, 0, 1, -1};   const int yinc[] = {1, -1, 0, 0};   const long double PI = acos(-1.0);   int n, k;   void solve() {     cin >> n >> k;     int d = n - k;     if (k == 1) {       cout << 1;       for (int i = 0; i < n - 1; i++) cout << 0;       cout <<   n ;       return;     }     d /= 2;     string p =  1 ;     for (int i = 0; i < d; i++) p +=  0 ;     int z = p.size();     for (int i = 0; i < n; i++) cout << p[i % z];     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct info {     double val;     string a;   };   vector<info> t;   int n, x, y, hcnt, sumh;   double aa;   long long res = 0;   bool cmp(const info &u, const info &v) { return u.val > v.val; }   int main() {     string a;     cin >> n;     for (int i = 0; i < n; i++) {       x = y = 0;       cin >> a;       for (int j = 0; a[j]; j++)         if (a[j] ==  s )           x++;         else if (a[j] ==  h )           y++;       sumh += y;       if (y == 0)         aa = 2e9;       else         aa = (double)x / y;       t.push_back({aa, a});     }     sort(t.begin(), t.end(), cmp);     int Size = t.size();     for (int i = 0; i < Size; i++) {       int sSize = t[i].a.size();       for (int j = 0; j < sSize; j++) {         if (t[i].a[j] ==  h )           sumh--;         else if (t[i].a[j] ==  s )           res += sumh;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300000;   const int MAX_E2 = 1 << 20;   const long double PI = acosl(-1.0);   struct Elm {     long double x, y, th;     Elm() : x(0.0), y(0.0), th(0.0) {}     Elm(long double _x, long double _y, long double _th)         : x(_x), y(_y), th(_th) {}     Elm &extend(int l) {       x += l * cosl(th), y += l * sinl(th);       return *this;     }     Elm &rot(long double dth) {       long double c = cosl(dth), s = sinl(dth);       long double x0 = c * x - s * y;       long double y0 = s * x + c * y;       x = x0, y = y0;       th += dth;       return *this;     }     Elm operator+(const Elm &e) const {       long double c = cosl(th), s = sinl(th);       long double x0 = c * e.x - s * e.y;       long double y0 = s * e.x + c * e.y;       return Elm(x + x0, y + y0, th + e.th);     }   };   template <typename T, const int MAX_E2>   struct SegTree {     int e2;     T nodes[MAX_E2], defv;     SegTree() {}     void init(int n, T _defv) {       defv = _defv;       for (e2 = 1; e2 < n; e2 <<= 1)         ;       fill(nodes, nodes + MAX_E2, defv);     }     T &get(int i) { return nodes[e2 - 1 + i]; }     void seti(int i, T v) { get(i) = v; }     void setall() {       for (int j = e2 - 2; j >= 0; j--)         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];     }     void set(int i, T v) {       int j = e2 - 1 + i;       nodes[j] = v;       while (j > 0) {         j = (j - 1) / 2;         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];       }     }   };   SegTree<Elm, MAX_E2> st;   int main() {     int n, m;     scanf( %d%d , &n, &m);     st.init(n, Elm(0.0, 0.0, 0.0));     for (int i = 0; i < n; i++) st.seti(i, Elm(1.0, 0.0, 0.0));     st.setall();     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       y--;       Elm e = st.get(y);       if (x == 1)         e.extend(z);       else         e.rot(-PI * z / 180);       st.set(y, e);       Elm r = st.nodes[0];       printf( %.10Lf %.10Lf n , r.x, r.y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     cout << arr[(n - 1) / 2];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   map<long long, int> cnt;   bool vis[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long a[n];     memset(vis, 0, sizeof(vis));     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       while (1) {         auto it = cnt.find(x);         if (it == cnt.end()) {           cnt[x] = i;           break;         } else {           vis[cnt[x]] = true;           cnt.erase(it);           x *= 2LL;         }       }       a[i] = x;     }     vector<long long> vec;     for (int i = 0; i < n; i++) {       if (vis[i]) continue;       vec.push_back(a[i]);     }     cout << vec.size() << endl;     for (long long x : vec) cout << x <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000 * 1000 * 1000 + 7;   long long n, m;   map<long long, long long> mp;   long long get(long long x) {     if (x < 0) return 0;     if (mp.find(x) != mp.end()) return mp[x];     long long y = x / 2, z = x - x / 2;     mp[x] += get(y) * get(z);     mp[x] %= mod;     for (int i = 1; i < m; i++) {       mp[x] += get(y - i) * get(z - m + i);       mp[x] %= mod;     }     return mp[x];   }   int main() {     cin >> n >> m;     mp[0] = 1;     mp[1] = 1;     long long ans = get(n);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 19;   double pw2[8 * N];   struct mynum {     double v;     int sh;     mynum(double _v, int _sh) {       v = _v;       sh = _sh;     }     mynum() {}     mynum shift(int x) { return mynum(v, sh + x); }     friend mynum operator+(mynum a, mynum b) {       if (a.sh < b.sh) swap(a, b);       if (b.v == 0) return a;       if (a.v == 0) return b;       b.v *= pw2[b.sh - a.sh + 4 * N];       return mynum(a.v + b.v, a.sh);     }   };   struct tree {     int sh[2 * N];     mynum T[2 * N];     void push(int v) {       if (v >= N) {         T[v].sh += sh[v];         sh[v] = 0;       } else {         sh[2 * v] += sh[v];         sh[2 * v + 1] += sh[v];         T[v].sh += sh[v];         sh[v] = 0;       }     }     mynum get(int l, int r, int L = 1, int R = N, int v = 1) {       if (r < L || l > R)         return mynum(0, 0);       else if (l <= L && R <= r)         return T[v].shift(sh[v]);       else {         push(v);         return get(l, r, L, (L + R) / 2, 2 * v) +                get(l, r, (L + R) / 2 + 1, R, 2 * v + 1);       }     }     inline int getsh(int x) {       int L = 1, R = N, v = 1;       while (v < N) {         push(v);         if ((L + R) / 2 >= x)           v = 2 * v, R = (L + R) / 2;         else           v = 2 * v + 1, L = (L + R) / 2 + 1;       }       return sh[v] + T[v].sh;     }     void ch(int l, int r, int x, int L = 1, int R = N, int v = 1) {       if (r < L || l > R)         return;       else if (l <= L && R <= r)         sh[v] += x;       else {         push(v);         ch(l, r, x, L, (L + R) / 2, 2 * v);         ch(l, r, x, (L + R) / 2 + 1, R, 2 * v + 1);         T[v] = T[2 * v].shift(sh[2 * v]) + T[2 * v + 1].shift(sh[2 * v + 1]);       }     }     tree() {}     void init() {       for (int i = N; i < 2 * N; i++) sh[i] = 0, T[i] = mynum(1, 0);       for (int i = N - 1; i > 0; i--) sh[i] = 0, T[i] = T[2 * i] + T[2 * i + 1];     }   };   tree TL, TR;   int main() {     pw2[4 * N] = 1;     for (int i = 1; i < 4 * N - 10; i++)       pw2[4 * N + i] = pw2[4 * N + i - 1] * 2.0,                   pw2[4 * N - i] = pw2[4 * N - i + 1] / 2.0;     int n;     scanf( %d , &n);     vector<pair<int, int> > V;     TL.init();     TR.init();     for (int i = 1; i <= n; i++) {       int t;       scanf( %d , &t);       V.push_back(make_pair(-t, i));     }     sort(V.begin(), V.end());     double ans = 0;     for (int i = 0; i < V.size(); i++) {       int v = -V[i].first;       int p = V[i].second;       mynum a = TL.get(1, p);       int sa = TL.getsh(p);       mynum b = TR.get(p, n);       int sb = TR.getsh(p);       a = a.shift(-sa);       b = b.shift(-sb);       assert(a.v == a.v);       assert(b.v == b.v);       assert(v == v);       int tp = a.sh + b.sh;       double res = v * a.v * b.v * pw2[4 * N + tp];       assert(pw2[4 * N + tp] == pw2[4 * N + tp]);       assert(res == res);       ans += res;       TL.ch(1, p, -1);       TR.ch(p, n, -1);     }     ans /= 2 * (double)n * (double)n;     printf( %.10lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long MN = 505, MOD = 1000 * 1000 * 1000 + 7;   long long a[MN], dp[MN][MN];   int32_t main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i], dp[i + 1][i + 1] = 1;     for (long long s = 1; s < n; s++)       for (long long l = 1; l <= n - s; l++) {         long long r = l + s;         dp[l][r] = dp[l + 1][r];         for (long long i = l + 1; i < r; i++)           if (a[i] > a[l]) (dp[l][r] += dp[l + 1][i] * dp[i][r] % MOD) %= MOD;       }     cout << dp[1][n];   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long a, sum;   } t, tt;   vector<node> vec[300005];   long long cost[300005], in[300005], dp[300005][2], vis[300005];   queue<node> que;   int main(void) {     long long i, j, n, m, a, b, c;     long long ans;     scanf( %lld , &n);     ans = 0;     for (i = 1; i <= n; i++) {       scanf( %lld , &cost[i]);       ans = max(ans, cost[i]);     }     for (i = 1; i < n; i++) {       scanf( %lld %lld %lld , &a, &b, &c);       in[a]++;       in[b]++;       t.sum = c;       t.a = b;       vec[a].push_back(t);       t.a = a;       vec[b].push_back(t);     }     for (i = 1; i <= n; i++) {       if (in[i] == 1) {         t.a = i;         t.sum = cost[i];         que.push(t);         in[i]--;       }     }     while (que.size()) {       t = que.front();       ans = max(ans, t.sum);       vis[t.a] = 1;       que.pop();       for (auto x : vec[t.a]) {         if (vis[x.a] == 1) {           continue;         } else {           if (dp[x.a][0] < t.sum - x.sum) {             dp[x.a][1] = dp[x.a][0];             dp[x.a][0] = t.sum - x.sum;           } else if (dp[x.a][1] < t.sum - x.sum) {             dp[x.a][1] = t.sum - x.sum;           }           ans = max(ans, dp[x.a][0] + dp[x.a][1] + cost[x.a]);           in[x.a]--;           if (in[x.a] == 1) {             tt.a = x.a;             tt.sum = dp[x.a][0] + cost[x.a];             que.push(tt);           }         }       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 9;   long long n, k;   long long a[N];   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr <<   ;     cin >> n >> k;     for (int i = 0; i < (n); i++) cin >> a[i], a[i]--;     sort(a, a + n, greater<long long>());     long long i = 0;     while (i < n) ans += a[i] * 2, i += k;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     for (cin >> (t); (t)--;) {       int n, d;       cin >> n >> d;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       int ans = a[0];       for (int i = 1; i < n; i++) {         int q = min(d / i, a[i]);         ans += q;         if (q == d / i)           break;         else           d -= a[i] * i;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using ppi = pair<int, pii>;   using vpi = vector<pii>;   const int kMod = 1e9 + 7;   struct ModInt {     long long n;     ModInt(long long n = 0) : n(n % kMod) {}     ModInt operator+(const ModInt& oth) { return n + oth.n; }     ModInt operator-(const ModInt& oth) { return n - oth.n; }     ModInt operator*(const ModInt& oth) { return n * oth.n; }     long long get() { return n < 0 ? n + kMod : n; }   };   using vi = vector<ModInt>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll R, G, val = 0, n = 0;     cin >> R >> G;     while (val <= R + G) val += ++n;     n--;     cerr << (int)(1000 * ((double)clock()) / CLOCKS_PER_SEC) << endl;     vector<ll> dp(R + 1, 0);     dp[0] = 1;     ll ans = 0;     for (int i = 1; i <= n; i++) {       vector<ll> newdp(R + 1, 0);       int tmp = (1LL * i * (i + 1)) / 2;       for (int r = 0; r <= R; r++) {         int g = tmp - r;         if (r >= i) newdp[r] = dp[r - i];         if (g <= G) newdp[r] = (newdp[r] + dp[r]) % kMod;       }       dp.swap(newdp);     }     for (int r = 0; r <= R; r++) ans = (ans + dp[r]) % kMod;     cerr << (int)(1000 * ((double)clock()) / CLOCKS_PER_SEC) << endl;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, ans;     cin >> s;     ans =   ;     for (int i = 0; i < s.size(); i++) {       ans = ans + s[i];       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||           s[i] ==  u  || s[i] ==  y ) {         for (int j = i; j < s.size(); j++) {           if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  ||               s[j] ==  u  || s[j] ==  y ) {             i = j;           } else {             break;           }         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007, maxn = 110;   int n, k, mat[maxn], fact[maxn], dp[maxn][maxn * maxn], stup[maxn][maxn];   long long m;   int pot(int a, long long b) {     if (!b) {       return 1;     }     if (b == 1) {       return a;     }     int rek, ost;     rek = pot(a, b >> 1);     ost = pot(a, b & 1);     return ((((long long)rek * rek) % mod) * (long long)ost) % mod;   }   int rek(int cur, int ost) {     if (!ost) {       return dp[cur][ost] = 1;     }     if (cur >= n || ost < 0) {       return 0;     }     if (dp[cur][ost] != -1) {       return dp[cur][ost];     }     dp[cur][ost] = 0;     for (int i = 0; i <= min(n, ost); i++) {       dp[cur][ost] += ((long long)stup[cur][i] * rek(cur + 1, ost - i)) % mod;       if (dp[cur][ost] >= mod) {         dp[cur][ost] -= mod;       }     }     return dp[cur][ost];   }   int main(void) {     scanf( %d , &n);     cin >> m;     scanf( %d , &k);     fact[0] = 1;     for (int i = 1; i <= n; i++) {       fact[i] = ((long long)fact[i - 1] * i) % mod;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= n; j++) {         stup[i][j] =             pot(((long long)fact[n] *                  pot(((long long)fact[j] * fact[n - j]) % mod, mod - 2)) %                     mod,                 (m - i - 1) / n + 1);       }     }     memset(dp, -1, sizeof dp);     printf( %d n , rek(0, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void read(Tp& x) {     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   int buf[22];   template <typename Tp>   inline void write(Tp x) {     int p = 0;     if (x < 0) {       putchar( - );       x = -x;     }     if (x == 0)       buf[++p] = 0;     else       while (x) {         buf[++p] = x % 10;         x /= 10;       }     for (int i = p; i; i--) putchar( 0  + buf[i]);   }   int m, b;   int main() {     scanf( %d%d , &m, &b);     long long int ans = 0;     for (int y = 0; y <= b; y++) {       int x = m * (b - y);       ans = max(ans, 1ll * (1 + x) * (1 + y) * (x + y) / 2);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       T t = bigmod(p, e / 2, M);       return (t * t) % M;     }     return (bigmod(p, e - 1, M) * p) % M;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T multimod(T a, T b, T m) {     T ans = 0ll;     a %= m, b %= m;     while (b) {       if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m);       b >>= 1ll;       a = (m - a) > a ? a + a : a + a - m;     }     return (T)ans;   }   long long dp[102][2688];   char str[102];   long long solve(long long a, long long b) {     if (a < b) swap(a, b);     if (a == 0ll || b == 0ll) return false;     if (!solve(b, a % b)) return true;     long long x = a / b;     return (x % (b + 1) % 2 == 0);   }   int main() {     int i, j, x, y, k;     int u, v, m, q, t, n, w;     memset(dp, -1ll, sizeof dp);     scanf( %d , &t);     while (t--) {       long long a, b;       cin >> a >> b;       if (solve(a, b))         cout <<  First  << endl;       else         cout <<  Second  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int unibit[60] = {0};   long long a[200005];   long long unia[200005] = {0};   int main() {     int n, k, x;     cin >> n >> k >> x;     long long orr = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       orr |= a[i];       long long b = a[i];       for (int j = 0; b > 0; j++) {         if (b % 2 == 1) {           if (unibit[j] == 0)             unibit[j] = i;           else             unibit[j] = -1;         }         b /= 2;       }     }     long long pow = 1;     for (int i = 0; i < 35; i++) {       if (unibit[i] > 0) {         int j = unibit[i];         unia[j] += pow;       }       pow *= 2;     }     long long ans = 0;     long long xx = 1;     for (int i = 0; i < k; i++) xx *= (long long)x;     for (int i = 1; i <= n; i++) {       long long or2 = orr;       or2 ^= unia[i];       a[i] *= xx;       or2 |= a[i];       if (ans < or2) ans = or2;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[105][105], s[105], res[105], letter, letter2, help[105];   int i, j, k, N, lens, lena[105];   int main() {     scanf( %d , &N);     gets(a[103]);     for (i = 0; i < N; i++) {       gets(a[i]);       lena[i] = strlen(a[i]);       for (j = 0; j < lena[i]; j++)         if (a[i][j] >=  a  && a[i][j] <=  z ) a[i][j] -= 32;     }     gets(s);     lens = strlen(s);     for (i = 0; i < lens; i++) {       if (s[i] >=  a  && s[i] <=  z )         help[i] = s[i] - 32;       else         help[i] = s[i];     }     scanf( %c , &letter);     if (letter >=  A  && letter <=  Z )       letter2 = letter + 32;     else       letter2 = letter - 32;     if (letter < letter2) swap(letter, letter2);     for (i = 0; i < lens; i++) {       for (j = 0; j < N; j++) {         if (memcmp(help + i, a[j], lena[j]) == 0) {           for (k = i; k < i + lena[j]; k++) {             if (s[k] != letter && s[k] != letter2) {               if (s[k] >=  a  && s[k] <=  z )                 res[k] = letter;               else                 res[k] = letter2;             } else {               if (s[k] >=  a  && s[k] <=  z )                 res[k] = letter ==  a  ?  b  :  a ;               else                 res[k] = letter2 ==  A  ?  B  :  A ;             }           }         }       }     }     for (i = 0; i < lens; i++)       if (res[i] == 0) res[i] = s[i];     puts(res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 998244353;   void add(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> x(n), y(n), s(n);     for (int i = 0; i < (int)(n); i++) cin >> x[i] >> y[i] >> s[i];     vector<int> cost(n + 1);     for (int i = 0; i < (int)(n); i++) {       int j = lower_bound((x).begin(), (x).end(), y[i]) - x.begin();       cost[i + 1] = (x[i] - y[i]) % MOD;       add(cost[i + 1], cost[i]);       add(cost[i + 1], MOD - cost[j]);       add(cost[i + 1], cost[i]);     }     for (int i = (int)(n)-1; i >= ((int)0); i--) add(cost[i + 1], MOD - cost[i]);     int ans = (x.back() + 1) % MOD;     for (int i = 0; i < (int)(n); i++)       if (s[i]) add(ans, cost[i + 1]);     cout << ans % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool checkbitt(long long int num, int pos);   long long int setbitt(long long int num, long long int pos);   long long int resetbitt(long long int num, int pos);   const long long int mod = 1e9 + 7;   const long long int N = 1e6 + 10;   long long int count(long long int x) {     x--;     return (x * (x + 1)) / 2;   }   int solve() {     int n;     cin >> n;     pair<int, int> arr[n];     map<int, int> a;     map<int, int> b;     map<pair<int, int>, int> c;     long long int bad = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i].first >> arr[i].second;       a[arr[i].first]++;       b[arr[i].second]++;       c[arr[i]]++;       bad += c[arr[i]] - 1;     }     long long int res = 0;     for (auto x : a) {       res += count(x.second);     }     for (auto x : b) {       res += count(x.second);     }     cout << res - bad << endl;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int cs = 1;     int cn = 1;     while (cs--) {       solve();     }   }   bool checkbitt(long long int num, int pos) { return (num >> pos) & 1; }   long long int setbitt(long long int num, long long int pos) {     return (1 << pos) | num;   }   long long int resetbitt(long long int num, int pos) {     if (!checkbitt(num, pos))       return num;     else       return (1 << pos) ^ num;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   const int N = 2e5 + 5;   const double pi = acos(-1);   int t;   int main() {     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       if (n % m == 0)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans = 1e9;   vector<vector<int> > cnt(65);   vector<set<int> > ed;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     ed.resize(n + 1);     bool tw = false;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       int d = 0;       while (a && !(tw)) {         if (a & 1) {           for (int k : cnt[d]) {             if (ed[k].find(i) == ed[k].end()) {               ed[k].insert(i);               ed[i].insert(k);             }           }           cnt[d].push_back(i);           if (cnt[d].size() > 2) tw = true;         }         a >>= 1, d++;       }     }     if (tw) {       cout << 3 <<   n ;       return 0;     }     for (int j = 0; j < 64; j++) {       unordered_set<int> vis;       if (cnt[j].size() == 2) {         queue<pair<int, int> > q;         for (int k : ed[cnt[j][0]])           if (k != cnt[j][1]) q.push(make_pair(k, 1));         vis.insert(cnt[j][0]);         while (!q.empty()) {           pair<int, int> cur = q.front();           q.pop();           if (vis.find(cur.first) != vis.end()) continue;           vis.insert(cur.first);           if (cur.first == cnt[j][1]) {             ans = min(ans, cur.second);             break;           }           for (int k : ed[cur.first]) q.push(make_pair(k, cur.second + 1));         }       }     }     if (ans == 1e9)       cout << -1 <<   n ;     else       cout << ans + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF64 = 1e18 + 1337;   const int INF32 = 1e9 + 228;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, s;     cin >> n >> s;     vector<long long> a(n);     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum < s) {       cout << -1;       return 0;     }     sort(a.begin(), a.end(), greater<int>());     for (int i = 0; i < n - 1; i++) s -= (a[i] - a[n - 1]);     while (s > 0 && a[n - 1] > 0) {       s -= n;       a[n - 1]--;     }     cout << a[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<long long, long long> P, d[100000];   double rm, rM;   int main() {     scanf( %d%I64d%I64d , &n, &P.first, &P.second);     for (int i = 0; i < n; i++) {       pair<long long, long long> Q;       scanf( %I64d%I64d , &Q.first, &Q.second);       double t = (P.first - Q.first) * (P.first - Q.first) +                  (P.second - Q.second) * (P.second - Q.second);       if (i == 0)         rm = rM = t;       else {         if (rm > t) rm = t;         if (rM < t) rM = t;       }       d[i] = Q;     }     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       pair<long long, long long> Q =           make_pair(d[j].first - d[i].first, d[j].second - d[i].second);       double t =           Q.first * (P.first - d[i].first) + Q.second * (P.second - d[i].second);       t /= (Q.first * Q.first + Q.second * Q.second);       if (0 <= t && t <= 1) {         long long a = d[j].second - d[i].second;         long long b = -(d[j].first - d[i].first);         long long c = -(a * d[i].first + b * d[i].second);         double t = (a * P.first + b * P.second + c);         t = t * t / (a * a + b * b);         if (t < rm) rm = t;       }     }     double r = rM - rm;     printf( %.9f n , r * 3.1415926535897932384626433832795);     return 0;   }