#include <bits/stdc++.h>   using namespace std;   inline void PAUSE() {     char tmp;     cin >> tmp;   }   char s[102];   int main() {     int n, k;     int f = 0;     scanf( %d %d , &n, &k);     if (n == k) f = 1;     cin >> s;     if (n >= 2 * k)       for (int i = k - 1; i >= 1; i--) {         cout <<  LEFT  << endl;       }     else       for (int i = k + 1; i <= n; i++) {         cout <<  RIGHT  << endl;         f = 1;       }     if (f == 0)       for (int i = 1; i <= n; i++) {         cout <<  PRINT   << s[i - 1] << endl;         if (i != n) cout <<  RIGHT  << endl;       }     else       for (int i = n; i >= 1; i--) {         cout <<  PRINT   << s[i - 1] << endl;         if (i != 1) cout <<  LEFT  << endl;       }     PAUSE();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6 + 5;   int ends_here[MAX];   int qs, qe;   struct data {     int child[26];     int score;     bool leaf;     int suf;     int ends;   };   data arr[MAX];   int que[MAX];   int cur;   struct aho_corasick {     int root;     int size;     void init() { root = (++cur); }     void insert(string s, int ind) {       int node = root;       for (int i = 0; i < s.length(); i++) {         int c = s[i] -  a ;         if (!arr[node].child[c]) {           arr[node].child[c] = (++cur);         }         node = arr[node].child[c];       }       ++size;       arr[node].leaf = 1;       arr[node].ends = ind;     }     int find(int node, int c) {       while (node != root) {         if (arr[node].child[c]) {           return arr[node].child[c];         }         node = arr[node].suf;       }       if (arr[root].child[c]) {         return arr[root].child[c];       } else {         return root;       }     }     void prepare() {       qs = 0;       qe = 0;       que[qe++] = root;       arr[root].suf = root;       while (qs < qe) {         int node = que[qs++];         for (int i = 0; i < 26; i++) {           if (arr[node].child[i]) {             int nxt = arr[node].child[i];             if (node != root) {               arr[nxt].suf = find(arr[node].suf, i);             } else {               arr[nxt].suf = root;             }             arr[nxt].score = arr[arr[nxt].suf].score + arr[nxt].leaf;             que[qe++] = nxt;           }         }       }     }     long long query(string s) {       int node = root;       long long ans = 0;       for (int i = 0; i < s.length(); i++) {         int c = s[i] -  a ;         node = find(node, c);         ans += arr[node].score;       }       return ans;     }     void dfs(int s1, int s2) {       arr[s1].leaf |= arr[s2].leaf;       for (int i = 0; i < 26; i++) {         if (!arr[s2].child[i]) {           continue;         }         if (!arr[s1].child[i]) {           arr[s1].child[i] = arr[s2].child[i];           continue;         }         dfs(arr[s1].child[i], arr[s2].child[i]);       }     }     void merge(aho_corasick other) {       dfs(root, other.root);       size += other.size;     }   };   int n, k;   set<int> pos;   vector<int> hlp;   void check(int ind) {     int f = 0;     for (int i = ind;; i += k) {       if (ends_here[i + k - 1] == 0) {         f = 1;         break;       }       if (pos.find(ends_here[i + k - 1]) != pos.end()) {         f = 1;         break;       }       pos.insert(ends_here[i + k - 1]);       hlp.push_back(ends_here[i + k - 1]);       if (pos.size() == n) {         break;       }     }     if (f == 0) {       printf( YES n );       for (auto x : hlp) {         printf( %d  , x);       }       exit(0);     } else {       pos.clear();       hlp.clear();     }   }   string str[100005];   int main() {     aho_corasick a;     a.init();     scanf( %d %d , &n, &k);     string s;     cin >> s;     s = s + s;     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       cin >> str[i];       a.insert(str[i], i);     }     a.prepare();     int st = a.root;     for (int i = 0; i < s.length(); i++) {       int c = s[i] -  a ;       st = a.find(st, c);       if (arr[st].score > 0) {         ends_here[i] = arr[st].ends;       }     }     for (int i = 0; i < k; i++) {       check(i);     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     while (c < 48) c ==  -  && (f = -1), c = getchar();     while (c > 47) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   const int MAXN = 100005;   std::vector<long long> adj;   long long n, ans;   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int main(int argc, char const *argv[]) {     n = read();     for (int i = 1; i <= n; ++i) adj.push_back(read());     sort(adj.rbegin(), adj.rend());     long long mx[5] = {1, *adj.begin(), 1, 1, 1};     ans = 0;     if (adj.size() > 1) mx[2] = adj[1];     if (adj.size() > 2) mx[3] = adj[2];     for (long long i : adj)       if (i % 2 != mx[1] % 2) mx[4] = max(mx[4], i);     for (int i = 1; i <= 4; ++i)       for (long long x : adj) ans = max(ans, lcm(mx[i], x));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2E5 + 10;   long long jc[15];   int main() {     jc[0] = 1;     for (int i = 1; i <= 14; ++i) jc[i] = jc[i - 1] * i;     int n, m;     cin >> n >> m;     int z = max(n - 13, 1);     long long ad = 0, p = jc[n - z + 1];     while (m--) {       int k;       cin >> k;       if (k == 1) {         int l, r;         cin >> l >> r;         if (r < z)           cout << (l + r) * 1ll * (r - l + 1) / 2 << endl;         else {           long long ans = (z - 1) * (r - max(l, z) + 1), da = ad;           if (l < z) ans += (l + z - 1) * 1ll * (z - l) / 2;           bool b[15] = {0};           for (int i = z; i <= r; ++i) {             long long t = da / jc[n - i];             int j = 1;             da -= t * jc[n - i];             for (; t || b[j]; ++j)               if (!b[j]) --t;             b[j] = 1;             if (i >= l) ans += j;           }           cout << ans << endl;         }       } else {         int t;         cin >> t;         ad = (ad + t) % p;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Q;   long long sum[105];   multiset<long long> s;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> Q;     while (Q--) {       char op;       long long f;       cin >> op >> f;       if (op ==  + ) {         long long i = 0;         while ((1 << (i + 1)) <= f) i++;         sum[i] += f;         s.insert(f);       } else {         long long i = 0;         while ((1 << (i + 1)) <= f) i++;         sum[i] -= f;         s.erase(s.find(f));       }       long long t = s.size();       long long k = 0;       long long ant = 0;       for (long long i = 0; i <= 30; i++) {         ant += sum[i];         auto it = s.lower_bound((1 << i));         if (it == s.end()) continue;         if ((1 << (i + 1)) <= *it) continue;         if (*it > 2 * (ant - sum[i])) k++;       }       cout << t - k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b[205];   int a[205];   int main() {     int n, m, k;     int x;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d , &x);       a[i] = x;     }     int sum = 0;     int mm = m;     while (n--) {       mm = m;       while (mm--) {         scanf( %d , &x);         int sb;         for (int j = 1; j <= k; j++) {           if (x == a[j]) {             sb = j;           }         }         sum += sb;         b[1] = a[sb];         int count = 2;         for (int j = 1; j <= k; j++) {           if (j != sb) {             b[count++] = a[j];           }         }         for (int j = 1; j <= k; j++) {           a[j] = b[j];         }       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char dir;     cin >> dir;     string m;     cin >> m;     string kboard =  qwertyuiopasdfghjkl;zxcvbnm,./ ;     if (dir ==  R ) {       for (int i = 0; i < m.length(); i++) {         int index = kboard.find(m[i]);         cout << kboard[index - 1];       }       cout << endl;     } else {       for (int i = 0; i < m.length(); i++) {         int index = kboard.find(m[i]);         cout << kboard[index + 1];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 1e5 + 5;   vector<int> g[N];   vector<pair<int, int> > ans;   int maxx;   void dfs(int x, int fa, int t) {     int siz = g[x].size();     int tmp = t;     ans.push_back(make_pair(x, t));     for (int i = 0; i <= siz - 1; i++) {       int v = g[x][i];       if (v == fa) continue;       if (t == maxx) t = maxx - siz, ans.push_back(make_pair(x, t));       dfs(v, x, ++t);       ans.push_back(make_pair(x, t));     }     if (t >= tmp && x - 1) ans.push_back(make_pair(x, tmp - 1));   }   int main() {     int n, x, y;     scanf( %d , &n);     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++) maxx = max(maxx, (int)g[i].size());     dfs(1, 1, 0);     int num = (int)ans.size();     printf( %d n , num);     for (int i = 0; i <= num - 1; i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void chkmin(T &x, T y) {     if (x > y) x = y;   }   int q, n, f, inv[100100], fac[100100], p[6];   void Euclid(int a, int b, int &x, int &y) {     if (!a)       x = 0, y = 1;     else {       int q = b / a, r = b % a;       Euclid(r, a, y, x);       x -= q * y;     }   }   int cal(int n, int m) {     if (m > n) return 0;     return 1ll * fac[n - 1] * inv[m - 1] % 1000000007 * inv[n - m] % 1000000007;   }   int main() {     fac[0] = 1;     for (int i = 1; i < 100100; i++) fac[i] = 1ll * fac[i - 1] * i % 1000000007;     int x, y;     Euclid(fac[100100 - 1], 1000000007, x, y);     inv[100100 - 1] = x;     for (int i = 100100 - 1; i > 0; i--)       inv[i - 1] = 1ll * inv[i] * i % 1000000007;     scanf( %d , &q);     while (q--) {       scanf( %d %d , &n, &f);       x = 0, y = n;       for (int i = 2; i <= sqrt(y); i++) {         if (y % i) continue;         p[x++] = i;         while (y % i == 0) y /= i;       }       if (y > 1) p[x++] = y;       y = 0;       for (int i = 0; i < (1 << x); i++) {         int tmp = n, cnt = 0;         for (int j = 0; j < x; j++)           if (i & (1 << j)) cnt++, tmp /= p[j];         if (cnt & 1)           y = (y - cal(tmp, f) + 1000000007) % 1000000007;         else           y = (y + cal(tmp, f)) % 1000000007;       }       printf( %d n , y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     set<int> v;     int a;     for (int i = 0; i < n; ++i) {       cin >> a;       v.insert(a);     }     v.erase(0);     cout << v.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long mod = 1e9 + 7;   const long long N = 300050;   long long m, fact[N];   void pre() {     fact[0] = 1;     for (long long i = 1; i < N; i++) {       fact[i] = (fact[i - 1] * i) % m;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long test = 1;     while (test--) {       long long n;       cin >> n >> m;       pre();       long long ans = 0;       for (long long i = 1; i <= n; i++) {         long long x = fact[n - i + 1] * (n - i + 1) % m;         x = (x * fact[i]) % m;         ans = (ans + x) % m;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tab[300000];   vector<int> numbers;   int main() {     int n;     cin >> n;     numbers.resize(n + 10);     vector<int> unused;     for (int i = 1; i <= n; i++) {       cin >> numbers[i];       if (numbers[i] > n || numbers[i] < 1) {         unused.push_back(i);       } else if (tab[numbers[i]] == 0) {         tab[numbers[i]] = i;       } else {         unused.push_back(i);       }     }     for (int i = 1; i <= n; i++) {       if (tab[i] == 0) {         tab[i] = unused.back();         unused.pop_back();       }     }     for (int i = 1; i <= n; i++) {       numbers[tab[i]] = i;     }     for (int i = 1; i <= n; i++) {       cout << numbers[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 998244353;   long double eps = 1e-12;   long long int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};   long long int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};   long long int n, res = 0, k = 0, h, ans = 0, m;   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int x, long long int y) {     return (x * y) / gcd(x, y);   }   long long int pot(long long int a, long long int b) {     long long int r = 1;     while (b) {       if (b % 2) r = (r * a) % mod;       a = (a * a) % mod;       b /= 2;     }     return r % mod;   }   void pr(long long int a[], long long int n) {     for (long long int i = 1; i <= n; i++) cout << a[i] <<   n ;     cout <<   n ;   }   void read(long long int a[], long long int n) {     for (long long int i = 1; i <= n; i++) cin >> a[i];   }   void yes() { cout <<  Yes n ; }   void no() { cout <<  No n ; }   vector<long long int> v[300015];   void add_edge(long long int x, long long int y) {     v[x].push_back(y);     v[y].push_back(x);   }   string s2, ch =   , s, s1 =   , t;   vector<pair<string, long long int> > vs;   vector<pair<pair<long long int, long long int>, long long int> > vvv, vvv2;   vector<pair<long long int, long long int> > vv, vv2;   long long int a[300015], b[300015] = {0};   long long int bit[300015];   void update(long long int x, long long int val) {     for (; x <= n; x += x & -x) bit[x] += val;   }   long long int query(long long int x) {     long long int sum = 0;     for (; x > 0; x -= x & -x) {       sum += bit[x];     }     return sum;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int i = 0, x = 0, z = 0, y = 0, j = 0, q, mx = 0, mm, idx = 0,                   ok = 0, l = 0, r, negatif = 0, positif = 0;     set<pair<long long int, long long int> >::iterator itw, ith;     multiset<long long int>::iterator it;     multiset<long long int> mst, mst2;     cin >> n;     read(a, n);     for (i = 1; i <= (long long int)(n); i++) {       vv.push_back({a[i], -i});     }     sort(vv.rbegin(), vv.rend());     for (i = 0; i < vv.size(); i++) vv[i].second = abs(vv[i].second);     cin >> q;     for (i = 1; i <= (long long int)(q); i++) {       long long int k, pos;       cin >> k >> pos;       vvv.push_back({{k, pos}, i});     }     sort(vvv.begin(), vvv.end());     j = 0;     for (i = 0; i < vvv.size(); i++) {       long long int k = vvv[i].first.first;       long long int pos = vvv[i].first.second;       long long int qidx = vvv[i].second;       while (j < k) {         long long int val = vv[j].first;         long long int idx = vv[j].second;         update(idx, 1);         j++;       }       l = 1;       r = n;       res = 0;       while (l <= r) {         long long int mid = (l + r) / 2;         long long int sum = query(mid);         if (sum < pos) {           res = mid;           l = mid + 1;         } else {           r = mid - 1;         }       }       res++;       b[qidx] = a[res];     }     pr(b, q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 1e5 + 42, mod = 1e9 + 7;   int n, inp[nmax];   vector<int> seen[nmax], dvd[nmax];   int phi[nmax];   int cnt[nmax];   long long sum_gcd(vector<int> cur) {     long long alone = 0;     for (auto w : cur) alone = (alone + w) % mod;     long long together = 0;     for (auto p : cur) {       for (auto q : dvd[p]) {         together = (together + 1LL * phi[q] * cnt[q]) % mod;         cnt[q]++;       }     }     for (auto p : cur) {       for (auto q : dvd[p]) cnt[q] = 0;     }     long long ret = (alone + together * 2) % mod;     return ret;   }   int main() {     scanf( %i , &n);     for (int i = 1; i <= n; i++) scanf( %i , &inp[i]);     for (int i = 1; i < nmax; i++) phi[i] = i;     for (int i = 2; i < nmax; i++)       if (phi[i] == i) {         for (int j = i; j < nmax; j = j + i) phi[j] = phi[j] / i * (i - 1);       }     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j = j + i) seen[i].push_back(inp[j]);     }     for (int i = 1; i < nmax; i++) {       for (int j = i; j < nmax; j = j + i) dvd[j].push_back(i);     }     long long outp = 0;     for (int i = 1; i <= n; i++)       outp = (outp + 1LL * phi[i] * sum_gcd(seen[i])) % mod;     printf( %lld n , outp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void cal(long long number, long long x, long long s) {     long long d = number ^ x;     long long temp = 2 * number - (s + d);     if (temp % 2 == 0) {       cout << 3 << endl;       cout << d <<     << temp / 2 <<     << temp / 2 << endl;     }     if (temp % 2 == 1) {       number -= 1;       d = number ^ x;       temp = 2 * number - (s + d);       cout << 3 << endl;       cout << d <<     << temp / 2 <<     << temp / 2 << endl;     }   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     long long s = 0, x = 0, number = 0;     for (long long i = 0; i < 57; i++) {       number = number | 1LL << i;     }     for (long long i = 0; i < n; i++) {       cin >> a[i];       s = s + a[i];       x = x ^ a[i];     }     cal(number, x, s);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int kor = 1e7;   int main() {     long long n, rad, v;     cin >> n >> rad >> v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       long long d = r - l;       int ma = 0;       while (d < kor) {         d *= 10;         rad *= 10;         ma++;       }       long long mnv = 0;       long long mxv = d;       while (mnv != mxv) {         long long cv = (mnv + mxv) / 2;         double cd = cv + rad * sin((double)cv / rad);         if (cd < (d / 2)) {           mnv = cv + 1;           continue;         }         mxv = cv;       }       long long ev = mnv;       mnv = 0;       mxv = d;       while (mnv != mxv) {         long long cv = (mnv + mxv) / 2;         double cd = cv - rad * sin((double)cv / rad);         if (cd < (d / 2)) {           mnv = cv + 1;           continue;         }         mxv = cv;       }       long long bv = min(ev, mnv);       bv *= 2;       double t = (double)bv / v;       while (ma > 0) {         t /= 10;         rad /= 10;         ma--;       }       cout << setprecision(20) << t << endl;     }     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, v[5005];   int ans(int st, int dr, int lvl) {     if (st > dr) return 0;     int mini = 1000000001;     int minipoz;     for (int i = st; i <= dr; i++) {       if (v[i] <= lvl) {         return ans(st, i - 1, lvl) + ans(i + 1, dr, lvl);       }       if (v[i] < mini) {         mini = v[i];         minipoz = i;       }     }     return min(dr - st + 1, mini - lvl + ans(st, minipoz - 1, mini) +                                 ans(minipoz + 1, dr, mini));   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> v[i];     cout << ans(1, n, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a, b, e;   char s[5];   long long ans;   int c;   int main() {     int n, f;     scanf( %d , &n);     while (n--) {       scanf( %s %d , &s, &f);       if (s[0] ==  0  && s[1] ==  1 )         a.push_back(f);       else if (s[0] ==  1  && s[1] ==  0 )         b.push_back(f);       else if (s[0] ==  0  && s[1] ==  0 )         e.push_back(f);       else {         c++;         ans += f;       }     }     int temp = c + 2 * min((int)a.size(), (int)b.size());     c += min((int)a.size(), (int)b.size());     if (!a.empty()) sort(a.rbegin(), a.rend());     if (!b.empty()) sort(b.rbegin(), b.rend());     for (int i = 0; i < min((int)a.size(), (int)b.size()); ++i) {       ans += a[i];       ans += b[i];     }     if (a.size() > b.size()) {       for (int i = min(a.size(), b.size()); i < a.size(); ++i) e.push_back(a[i]);     } else if (b.size() > a.size()) {       for (int i = min(a.size(), b.size()); i < b.size(); ++i) e.push_back(b[i]);     }     if (!e.empty()) sort(e.rbegin(), e.rend());     for (int i = 0; i < e.size(); ++i) {       if (((temp + 2) / 2) <= c) {         ans += e[i];         temp++;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     int m;     scanf( %I64d %d , &n, &m);     std::vector<long long int> v(n, 0);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x - 1]++;       v[y - 1]++;     }     long long int res = 0;     for (int i = 0; i < n; i++) {       res -= v[i] * (n - 1 - v[i]);     }     res /= 2;     res += (n * (n - 1) * (n - 2)) / 6;     printf( %I64d , res);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> z, q;   long long w, p = 10, l = 60;   long long mul(long long x, long long y) {     long long z = 0;     for (; y; y >>= 1, x = x * 2 % p)       if (y & 1) z = (z + x) % p;     return z;   }   pair<long long, long long> F(long long x) {     if (x == 0) return pair<long long, long long>(0, 1);     if (x & 1) {       pair<long long, long long> u = F(x - 1);       return pair<long long, long long>(u.second, (u.first + u.second) % p);     } else {       pair<long long, long long> u = F(x / 2);       return pair<long long, long long>(           mul(u.first, 2 * u.second + p - u.first),           (mul(u.first, u.first) + mul(u.second, u.second)) % p);     }   }   int main() {     cin >> w;     for (int i = 0; i < l; i++)       if (F(i).first == w % p) z.push_back(i);     for (int i = 0; i < 12; i++) {       p *= 10;       q.clear();       for (long long j : z)         for (int k = 0; k < 10; k++)           if (F(j + k * l).first == w % p) q.push_back(j + k * l);       z.swap(q);       l *= 10;     }     if (!z.size())       puts( -1 );     else       cout << *min_element(z.begin(), z.end());   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   string to_string(string s) { return     + s +    ; }   string to_string(char s) { return string(1, s); }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A>   string to_string(A);   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool f = 1;     string r =  { ;     for (const auto &x : v) {       if (!f) r +=  ,  ;       f = 0;       r += to_string(x);     }     return r +  } ;   }   void debug_out() { cout << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cout <<     << to_string(H);     debug_out(T...);   }   const int N = 1e5 + 10;   int n, k;   vector<pair<int, int>> g[N];   vector<pair<long long, long long>> A1[N];   pair<long long, long long> f(int u, int p) {     auto &a1 = A1[u];     for (auto it : g[u])       if (it.first != p) {         int v = it.first, c = it.second;         auto now = f(v, u);         a1.emplace_back(now.first + c, max(now.first, now.second) + c);       }     sort((a1).begin(), (a1).end());     reverse((a1).begin(), (a1).end());     pair<long long, long long> ans(0, 0);     for (auto i = (0); i <= (min(int(a1.size()), k - 1) - 1); ++i) {       ans.first += a1[i].first;       ans.second += a1[i].first;     }     long long cur = ans.second;     for (auto i = (0); i <= (int(a1.size()) - 1); ++i) {       if (i <= k - 2) {         ans.second =             max(ans.second, cur - a1[i].first + a1[i].second +                                 (k - 1 < int(a1.size()) ? a1[k - 1].first : 0));       } else {         ans.second = max(ans.second, cur + a1[i].second);       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (auto i = (1); i <= (n - 1); ++i) {       int x, y, c;       cin >> x >> y >> c;       g[x].emplace_back(y, c);       g[y].emplace_back(x, c);     }     pair<int, int> ans = f(0, -1);     cout << max(ans.first, ans.second) <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int N;   int arr[51][51];   bool checkSum(int num, int row, int col) {     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         if (arr[row][i] + (long long int)arr[j][col] == num) {           return true;         }       }     }     return false;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         scanf( %d , &arr[i][j]);       }     }     bool flag = true;     for (int i = 0; i < N && flag; i++) {       for (int j = 0; j < N && flag; j++) {         if (arr[i][j] != 1) {           flag = checkSum(arr[i][j], i, j);         }       }     }     if (flag) {       printf( Yes n );     } else {       printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<char, int> &a, pair<char, int> &b) { return a.second < b.second; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s[3];     int i;     bool imp = false;     unordered_map<char, int> m;     vector<pair<char, int>> v;     for (i = 0; i < 3; i++) {       cin >> s[i];     }     for (i = 0; i < 3; i++) {       if (s[i][1] ==  > ) {         m[s[i][0]]++;         m[s[i][2]]--;       } else {         m[s[i][0]]--;         m[s[i][2]]++;       }     }     for (auto it = m.begin(); it != m.end(); it++) {       v.push_back(make_pair(it->first, it->second));     }     if (v[0].second == v[1].second || v[1].second == v[2].second ||         v[0].second == v[2].second) {       imp = true;     }     if (imp) {       cout <<  Impossible n ;     } else {       sort(v.begin(), v.end(), cmp);       for (i = 0; i < v.size(); i++) {         cout << v[i].first;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _dbg(string) { cout << endl; }   template <class H, class... T>   void _dbg(string s, H h, T... t) {     int l = s.find( , );     cout << s.substr(0, l) <<   =   << h <<  ,  ;     _dbg(s.substr(l + 1), t...);   }   template <class T, class U>   ostream &operator<<(ostream &o, const pair<T, U> &p) {     o <<  (  << p.first <<  ,  << p.second <<  ) ;     return o;   }   template <class T>   ostream &operator<<(ostream &o, const vector<T> &v) {     o <<  [ ;     for (T t : v) {       o << t <<  , ;     }     o <<  ] ;     return o;   }   class UnionFind {    public:     vector<int> par, rank;     UnionFind(int sz) : par(sz, -1), rank(sz, 0) {}     int find(int x) {       if (par[x] < 0)         return x;       else         return par[x] = find(par[x]);     }     void unite(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (rank[x] < rank[y]) {         par[y] += par[x];         par[x] = y;       } else {         par[x] += par[y];         par[y] = x;         if (rank[x] == rank[y]) rank[x]++;       }     }     inline bool same(int x, int y) { return find(x) == find(y); }     inline int size(int x) { return -par[find(x)]; }   };   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = (int)(0); i < (int)(n); i++) scanf( %d , &v[i]);     for (int i = (int)(0); i < (int)(n); i++) v[i]--;     UnionFind uf(n + 1);     vector<bool> appeared(n + 1, false);     appeared[n] = true;     cout <<  1  ;     for (int i = (int)(0); i < (int)(n); i++) {       if (v[i] > 0 && appeared[v[i] - 1]) uf.unite(v[i] - 1, v[i]);       if (appeared[v[i] + 1]) uf.unite(v[i], v[i] + 1);       appeared[v[i]] = true;       int sz = uf.size(n) - 1;       printf( %d%c , (i + 2) - sz,    n [i == n - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     double s, f, r, v;     int n;     scanf( %d%lf%lf , &n, &r, &v);     while (n--) {       scanf( %lf%lf , &s, &f);       double ans = 0, d = f - s;       int cnt = (int)floor(d / (2 * pi * r));       ans += cnt * 2 * pi * r / v;       d -= cnt * (2 * pi * r);       d /= 2;       double L = 0, R = d;       for (int _i = 0; _i < 60; _i++) {         double mid = (L + R) / 2;         if (mid + sin(mid / r) * r > d)           R = mid;         else           L = mid;       }       ans += 2 * L / v;       printf( %f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long d1[] = {0, 2, 3, 1};   long long fn1(long long start, long long pos, long long len) {     long long zzz = len / 4;     if (len == 1) return start;     for (long long i = 0; i < 4; i++) {       long long l = i * zzz;       long long r = l + (zzz - 1);       if (l <= pos && pos <= r) return fn1(start + d1[i] * zzz, pos - l, zzz);     }     return -1;   }   long long d2[] = {0, 3, 1, 2};   long long fn2(long long start, long long pos, long long len) {     long long zzz = len / 4;     if (len == 1) return start;     for (long long i = 0; i < 4; i++) {       long long l = i * zzz;       long long r = l + (zzz - 1);       if (l <= pos && pos <= r) return fn2(start + d2[i] * zzz, pos - l, zzz);     }     return -1;   }   long long solve() {     long long n;     cin >> n;     n--;     long long row = n / 3;     long long col = n % 3;     if (col == 0) {       long long pos = row;       long long temp = 1;       long long start = 1;       while (true) {         if (pos - temp >= 0) {           pos -= temp;           temp *= 4;           start *= 4;           continue;         }         break;       }       cout << start + pos <<   n ;     }     if (col == 1) {       long long pos = row;       long long temp = 1;       long long start = 2;       while (true) {         if (pos - temp >= 0) {           pos -= temp;           temp *= 4;           start *= 4;           continue;         }         break;       }       cout << fn1(start, pos, temp) <<   n ;     }     if (col == 2) {       long long pos = row;       long long temp = 1;       long long start = 3;       while (true) {         if (pos - temp >= 0) {           pos -= temp;           temp *= 4;           start *= 4;           continue;         }         break;       }       cout << fn2(start, pos, temp) <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t-- != 0) {       long long stat = solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> g[100009], df;   long long n, v[100009];   long long used[100009], x, sum, plu[100009], minu[100009], br;   void dfs(int node) {     used[node] = 1;     long long mxpl = 0, mxmi = 0;     for (int i = 0; i < g[node].size(); i++) {       if (used[g[node][i]] == 0) {         dfs(g[node][i]);         mxpl = max(mxpl, plu[g[node][i]]);         mxmi = max(mxmi, minu[g[node][i]]);       }     }     if (v[node] + mxpl > mxmi) {       plu[node] = mxpl;       minu[node] = mxpl + v[node];     } else {       minu[node] = mxmi;       plu[node] = minu[node] - v[node];     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     dfs(1);     for (int i = 1; i <= n; i++) {     }     sum = minu[1] + plu[1];     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long num[100500];   long long d1[15], d2[15];   int main() {     long long n;     long long ans = 0;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &num[i]);     }     for (int i = 1; i <= n; i++) {       long long digit = 0;       long long a = num[i];       long long di = 1;       while (a) {         d1[++digit] = a % 10;         a /= 10;       }       for (int k = 1; k <= digit; k++) {         ans += d1[k] * di + d1[k] * di * 10;         di *= 100;         di = di % 998244353;         ans = ans % 998244353;       }     }     ans *= n;     ans = ans % 998244353;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   int cur = 0;   string get_next() {     string ans =   ;     if (cur >= 26) {       ans =  B ;     } else {       ans =  A ;     }     ans += (char)( a  + cur % 26);     cur++;     return ans;   }   int main() {     int n, k;     cin >> n >> k;     vector<bool> used(n - k + 1);     for (int i = 0; i < n - k + 1; i++) {       string s;       cin >> s;       if (s ==  NO ) {         used[i] = true;       }     }     vector<string> ans(n);     for (int i = 0; i < n; i++) {       if (i >= k - 1 && used[i - k + 1]) {         ans[i] = ans[i - k + 1];       } else {         ans[i] = get_next();       }     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   long long ans, add[400009], sum[400009];   set<pair<int, pair<int, int> > > segm;   int mod(int x) {     if (x < 0) return -x;     return x;   }   void split(int nod, int l1, int l2) {     if (add[nod] == 0) return;     int f1 = nod << 1, f2 = (nod << 1) + 1;     sum[f1] += 1LL * add[nod] * l1, sum[f2] += 1LL * add[nod] * l2;     add[f1] += add[nod], add[f2] += add[nod];     add[nod] = 0;   }   void U(int nod, int st, int dr, int x, int y, int val) {     if (x <= st && dr <= y) {       add[nod] += val;       sum[nod] += 1LL * val * (dr - st + 1);       return;     }     int mij = (st + dr) >> 1;     split(nod, mij - st + 1, dr - mij);     if (x <= mij) U(nod << 1, st, mij, x, y, val);     if (y > mij) U((nod << 1) + 1, mij + 1, dr, x, y, val);     sum[nod] = sum[nod << 1] + sum[(nod << 1) + 1];   }   void Q(int nod, int st, int dr, int x, int y) {     if (x <= st && dr <= y) {       ans += sum[nod];       return;     }     int mij = (st + dr) >> 1;     split(nod, mij - st + 1, dr - mij);     if (x <= mij) Q(nod << 1, st, mij, x, y);     if (y > mij) Q((nod << 1) + 1, mij + 1, dr, x, y);   }   void Update(int L, int R, int val) {     set<pair<int, pair<int, int> > >::iterator it = segm.lower_bound(                                                    make_pair(L, make_pair(0, 0))),                                                it2;     if (it->second.first < L) {       int A = it->second.first, B = it->first, C = it->second.second;       if (B > R) {         U(1, 1, N, L, R, mod(val - C));         segm.erase(it);         segm.insert(make_pair(L - 1, make_pair(A, C)));         segm.insert(make_pair(B, make_pair(R + 1, C)));         segm.insert(make_pair(R, make_pair(L, val)));         return;       }       U(1, 1, N, L, B, mod(val - C));       segm.erase(it);       segm.insert(make_pair(L - 1, make_pair(A, C)));       it = segm.lower_bound(make_pair(L, make_pair(0, 0)));     }     while (1) {       if (it == segm.end()) break;       if (it->second.first > R) break;       if (it->first > R) {         int A = it->second.first, B = it->first, C = it->second.second;         U(1, 1, N, A, R, mod(val - C));         segm.erase(it);         segm.insert(make_pair(B, make_pair(R + 1, C)));         break;       }       it2 = it, it2++;       U(1, 1, N, it->second.first, it->first, mod(val - it->second.second));       segm.erase(it);       it = it2;     }     segm.insert(make_pair(R, make_pair(L, val)));   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= N; i++) segm.insert(make_pair(i, make_pair(i, i)));     while (M--) {       int tip, a, b, c;       scanf( %d , &tip);       if (tip == 1) {         scanf( %d %d %d , &a, &b, &c);         Update(a, b, c);       } else {         scanf( %d %d , &a, &b), ans = 0LL;         Q(1, 1, N, a, b);         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> q;   const int maxn = 360;   int main() {     int t, n;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       int num = 360 / (180 - n);       int ans = 0;       if (num * (180 - n) != 360) num++;       for (int i = num; i <= 360; i++) {         if ((n * i) % 180 != 0) continue;         ans = i;         if (ans != 0) break;       }       if (ans == 0)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double INF = 1e12, EPS = 1e-9;   const int B = 2000;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};   int h, w, q;   int qs[100000][4];   char in[100010][12], dir[256];   int dp[100010 * 12], vis[100010][12];   inline int to(int y, int x) {     int &res = dp[y * 12 + x];     if (res != -1) return res;     if (y == 0 || x == 0 || x == w + 1) return res = y * 12 + x;     res = -2;     int d = dir[in[y][x]];     return res = to(y + dy[d], x + dx[d]);   }   int main() {     dir[ < ] = 1;     dir[ ^ ] = 0;     dir[ > ] = 3;     scanf( %d%d%d , &h, &w, &q);     for (int i = 0; i < (int)h; i++) scanf( %s , in[i + 1] + 1);     for (int i = 0; i < (int)q; i++) {       char c, d;       int y, x;       scanf(  %c%d%d , &c, &y, &x);       qs[i][0] = c ==  A ;       qs[i][1] = y;       qs[i][2] = x;       if (c ==  C ) {         scanf(  %c , &d);         qs[i][3] = d;       }     }     memset(vis, -1, sizeof(vis));     for (int it = 0; it < (int)q; it++) {       if (it % B == 0) {         memset(dp, -1, sizeof(dp));         for (int i = it; i < it + B && i < q; i++)           if (qs[i][0] == 0) {             int y = qs[i][1], x = qs[i][2];             dp[y * 12 + x] = y * 12 + x;           }       }       int y = qs[it][1], x = qs[it][2];       if (!qs[it][0]) {         in[y][x] = (char)qs[it][3];         continue;       }       while (1) {         if (x == 0 || x == w + 1 || y == 0) {           printf( %d %d n , y, x);           break;         }         if (vis[y][x] == it) {           puts( -1 -1 );           break;         }         vis[y][x] = it;         int ny = to(y, x), nx;         if (ny < 0) {           puts( -1 -1 );           break;         }         nx = ny % 12;         ny /= 12;         if (nx == 0 || nx == w + 1 || ny == 0) {           printf( %d %d n , ny, nx);           break;         }         int d = dir[in[ny][nx]];         y = ny + dy[d];         x = nx + dx[d];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 350;   const long long PHI = (long long)998244352;   const long long INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long MOD = (long long)998244353;   const long long OVER_FLOW = 0x7fffffff;   const long long LOVER_FLOW = 0x7fffffffffffffff;   long long n;   struct op {     long long x1, y1, x2, y2;   };   long long vis[MAXN][MAXN];   vector<op> res;   string str;   void add(long long x1, long long y1, long long x2, long long y2) {     res.push_back((op){x1, y1, x2, y2});     vis[x2][y2]++;   }   void move(long long x1, long long y1, bool x) {     if (x) {       if (x1 != 1) {         add(x1, y1, 1, y1);       } else {         add(x1, y1, 1, y1 == 1 ? 2 : 1);       }     } else {       if (x1 != 2) {         add(x1, y1, 2, y1);       } else {         add(x1, y1, 2, y1 == 1 ? 2 : 1);       }     }   }   int main() {     ios::sync_with_stdio(false);     long long m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cin >> str;         for (long long k = str.size() - 1; k >= 0; k--) {           move(i, j, str[k] ==  1 );         }       }     }     for (long long i = 1; i <= 2; i++) {       for (long long j = 2; j <= m; j++) {         while (vis[i][j]) {           add(i, j, i, 1);           vis[i][j]--;         }       }     }     long long cnt = res.size();     memset(vis, 0, sizeof vis);     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         cin >> str;         for (auto k : str) {           move(i, j, k ==  1 );         }       }     }     for (long long i = 1; i <= 2; i++) {       for (long long j = 2; j <= m; j++) {         while (vis[i][j]) {           add(i, j, i, 1);           vis[i][j]--;         }       }     }     cout << res.size() <<   n ;     for (long long i = 0; i < cnt; i++) {       cout << res[i].x1 <<     << res[i].y1 <<     << res[i].x2 <<                << res[i].y2 <<   n ;     }     for (long long i = res.size() - 1; i >= cnt; i--) {       cout << res[i].x2 <<     << res[i].y2 <<     << res[i].x1 <<                << res[i].y1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   long long k, L, R, a[2222222], b[2222222], ans, sum[2222222];   int n, r;   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   bool check(long long x) {     long long ans = 0, now = 0;     memset(b, 0, sizeof(b));     for (int i = 1; i <= n; i++) {       now += b[i];       if (a[i] + now < x)         ans += x - a[i] - now, b[i + 2 * r + 1] -= x - a[i] - now,             now += x - a[i] - now;       if (ans > k) return 0;     }     return 1;   }   int main() {     scanf( %d%d%lld , &n, &r, &k);     L = 2e18;     for (int i = 1; i <= n; i++)       scanf( %lld , &sum[i]), L = min(L, sum[i]), sum[i] += sum[i - 1];     for (int i = 1; i <= n; i++)       a[i] = sum[min(i + r, n)] - sum[max(0, i - r - 1)];     R = 1e20;     while (L <= R) {       long long mid = L + R >> 1;       if (check(mid))         L = mid + 1, ans = mid;       else         R = mid - 1;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<long long> a(n);     vector<int> nx(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     map<long long, int> mp;     long long sig = 0;     for (int i = 0; i < 3 * n; i++) {       int ri = (i % n);       nx[mp[sig]] = ri;       mp[sig] = ri;       sig += a[ri];     }     int res = n;     for (int i = 0; i < n; i++) {       int len = 1, p = nx[i];       if (p == -1) {         continue;       }       nx[i] = -1;       while (p != i) {         len++;         int np = nx[p];         nx[p] = -1;         p = np;       }       res = min(n - len, res);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, t;     cin >> n >> t;     long long int A[n];     for (long long int i = 0; i < n; i++) {       cin >> A[i];     }     long long int cnt = 0;     long long int sum = 0;     long long int i = 0;     long long int j = 0;     for (i = 0; i < n; i++) {       sum += A[i];       if (sum <= t) {         cnt++;       } else {         sum -= A[j];         j++;       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int nnext[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }   int main() {     int n, m, k, idx, x, y, now, have, array[350][350];     cin >> n >> m >> k, x = y = 1, idx = now = have = 0;     vector<vector<pair<int, int> > > ans(k);     while (k) {       if (k == 1) {         if (y > m)           x++, y = m, now = 1;         else if (!y)           x++, y = 1, now = 0;         ans[idx].push_back(make_pair(x, y)), have++;         if (have == n * m) break;         if (!now)           y++;         else           y--;         continue;       } else {         ans[idx].push_back(make_pair(x, y)), have++;         if (!now)           y++;         else           y--;         if (y > m)           x++, y = m, now = 1;         else if (!y)           x++, y = 1, now = 0;       }       if (ans[idx].size() == 2) idx++, k--;     }     for (int i = 0; i < int(ans.size()); i++) {       cout << ans[i].size() <<    ;       for (int j = 0; j < int(ans[i].size()); j++)         cout << ans[i][j].first <<     << ans[i][j].second <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long BINF = 9e18, LINF = 2e9, mod = 998244353, P = 179,                   Q = 1791791791;   const long long MAXN = 1e4 + 7;   long long a[MAXN], b[MAXN], c[MAXN];   vector<pair<long long, long long>> g[MAXN];   bool cmp(vector<pair<long long, long long>> &a,            vector<pair<long long, long long>> &b) {     return a.size() < b.size();   }   struct way {     long long a, b, c;   };   vector<way> ways;   long long h[MAXN];   long long c1[MAXN], c2[MAXN];   long long f[MAXN];   long long tin[MAXN], tout[MAXN];   long long par[MAXN];   long long timer = 0;   void dfs(long long v, long long p = -1, long long pc = -1) {     par[v] = p;     h[v] = (p == -1 ? 0 : h[p] + 1);     tin[v] = timer++;     if (g[v].size() == 1 && p != -1) {       long long u, c;       for (pair<long long, long long> e : g[v])         if (e.first != p) u = e.first, c = e.second;       if (pc != c) {         cout <<  NO ;         exit(0);       }       dfs(u, p, pc);       return;     }     for (pair<long long, long long> e : g[v]) {       if (e.first == p) continue;       dfs(e.first, v, e.second);       if (c1[v] == -1)         c1[v] = f[e.first];       else if (c2[v] == -1)         c2[v] = f[e.first];       f[v] = f[e.first];     }     tout[v] = timer++;     if (p != -1) ways.push_back(way{p, v, pc});     if (g[v].size() == 0) f[v] = c1[v] = c2[v] = v;   }   void dfsd(long long v, long long p = -1) {     long long ps = -1;     for (long long i = 0; i < g[v].size(); ++i) {       if (g[v][i].first == p)         ps = i;       else         dfsd(g[v][i].first, v);     }     if (ps != -1) g[v].erase(g[v].begin() + ps);   }   vector<way> answ;   void add(long long a, long long b, long long c) {     if (a == b) return;     answ.push_back({a, b, c});   }   long long lca(long long a, long long b) {     if (h[a] < h[b]) swap(a, b);     while (h[a] > h[b]) a = par[a];     while (a != b) a = par[a], b = par[b];     return a;   }   long long dist(long long a, long long b) {     return h[a] + h[b] - 2 * h[lca(a, b)];   }   void solve() {     long long n;     cin >> n;     fill(c1, c1 + n, -1);     fill(c2, c2 + n, -1);     for (long long i = 0; i < n - 1; ++i) {       cin >> a[i] >> b[i] >> c[i];       --a[i];       --b[i];       g[a[i]].push_back({b[i], c[i]});       g[b[i]].push_back({a[i], c[i]});     }     long long root = min_element(g, g + n, cmp) - g;     dfsd(root, -1);     dfs(root);     for (way w : ways) {       if (h[w.a] > h[w.b]) swap(w.a, w.b);       long long lul = c1[w.a];       if (dist(lul, w.b) != dist(lul, w.a) + dist(w.a, w.b)) lul = c2[w.a];       if (lul == -1) lul = root;       add(c1[w.b], c2[w.b], -(w.c / 2));       add(root, lul, -(w.c / 2));       add(root, c1[w.b], w.c / 2);       add(lul, c2[w.b], w.c / 2);     }     cout <<  YES n ;     cout << answ.size() <<   n ;     for (way w : answ) cout << w.a + 1 <<     << w.b + 1 <<     << w.c <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cout.precision(40);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 202000;   int n, m;   struct edge {     int u, v, w;   } edges[maxn];   int pre[maxn];   vector<edge> vec;   int found(int x) {     int rx = x;     while (pre[rx] != rx) rx = pre[rx];     while (pre[x] != rx) {       int tmp = pre[x];       pre[x] = rx;       x = tmp;     }     return rx;   }   int cmp(edge alpha, edge beta) { return alpha.w < beta.w; }   void read() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &edges[i].u, &edges[i].v, &edges[i].w);     sort(edges + 1, edges + m + 1, cmp);   }   void work() {     int ans = 0;     for (int i = 1; i <= n; i++) pre[i] = i;     for (int i = 1; i <= m;) {       int j = i;       vec.clear();       while (edges[i].w == edges[j].w) {         if (found(edges[j].u) == found(edges[j].v)) {           j++;           continue;         }         vec.push_back(edges[j]);         j++;       }       for (int k = 0; k < vec.size(); k++) {         if (found(vec[k].u) == found(vec[k].v))           ans++;         else           pre[found(vec[k].u)] = found(vec[k].v);       }       i = j;     }     printf( %d n , ans);   }   int main() {     read();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 18) + 100;   const int maxnode = maxn << 2;   int n, ai[maxn + 5];   int ls[maxnode + 5], rs[maxnode + 5];   int re[maxnode + 5], sp[maxnode + 5];   long long sum[maxnode + 5];   void Build(int x, int l, int r) {     re[x] = sp[x] = 0;     ls[x] = x << 1, rs[x] = x << 1 | 1;     if (l == r) {       sum[x] = ai[l];       return;     }     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     Build(lson, l, mid);     Build(rson, mid + 1, r);     sum[x] = sum[lson] + sum[rson];   }   void Replace(int d, int x, int l, int r, int p, int v) {     if (l == r) {       sum[x] = v;       return;     }     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     if (re[x] >> d & 1) {       re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)),           re[rson] ^= (1 << (d + 1));     }     if (sp[x] >> d & 1) {       sp[x] ^= (1 << d), swap(lson, rson);     }     re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0;     sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0;     if (p <= mid)       Replace(d + 1, lson, l, mid, p, v);     else       Replace(d + 1, rson, mid + 1, r, p, v);     sum[x] = sum[lson] + sum[rson];   }   long long Sum(int d, int x, int l, int r, int ll, int rr) {     if (ll <= l && r <= rr) return sum[x];     int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1;     long long res = 0;     if (re[x] >> d & 1) {       re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)),           re[rson] ^= (1 << (d + 1));     }     if (sp[x] >> d & 1) {       sp[x] ^= (1 << d), swap(lson, rson);     }     re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0;     sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0;     if (ll <= mid) res += Sum(d + 1, lson, l, mid, ll, rr);     if (mid < rr) res += Sum(d + 1, rson, mid + 1, r, ll, rr);     return res;   }   int main() {     int _;     scanf( %d%d , &n, &_);     int pn = n;     n = (1 << n);     for (int i = 1; i <= n; ++i) scanf( %d , ai + i);     Build(1, 1, n);     while (_--) {       int o, x, k, l, r;       scanf( %d , &o);       if (o == 1) {         scanf( %d%d , &x, &k);         Replace(0, 1, 1, n, x, k);       } else if (o == 2) {         scanf( %d , &k);         k = pn - k;         re[1] ^= (1 << k);       } else if (o == 3) {         scanf( %d , &k);         k = pn - 1 - k;         sp[1] ^= (1 << k);       } else {         scanf( %d%d , &l, &r);         long long ans = Sum(0, 1, 1, n, l, r);         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct deal {     long num_person;     long num_shoue;     vector<deal> *d;       public:     deal(long _p, long _s, vector<deal> *_d) {       num_person = _p;       num_shoue = _s;       d = _d;     }     deal(long _p, long _s) {       num_person = _p;       num_shoue = _s;       d = NULL;     }   };   long n, m;   vector<vector<long long>> d1;   map<long, vector<long long>> people;   map<long, vector<long>> num_people;   map<long, long long> shoes;   map<long, long> num_shoes;   long long max(long long a, long long b) { return a > b ? a : b; }   int main() {     scanf( %d , &n);     shoes = map<long, long long>();     num_shoes = map<long, long>();     long size, money;     for (long i = 0; i < n; i++) {       scanf( %d%d , &money, &size);       shoes[size] = money;       num_shoes[size] = i;     }     scanf( %d , &m);     people = map<long, vector<long long>>();     for (long i = 0; i < m; i++) {       scanf( %d%d , &money, &size);       if (!people.count(size)) {         people[size] = vector<long long>(2, 0);         num_people[size] = vector<long>(2, -1);       }       if (people[size][0] < money) {         people[size][1] = people[size][0];         num_people[size][1] = num_people[size][0];         people[size][0] = money;         num_people[size][0] = i;       } else if (people[size][1] < money) {         people[size][1] = money;         num_people[size][1] = i;       }     }     map<long, vector<long long>>::iterator i = people.begin();     long money2;     size = -10;     d1 = vector<vector<long long>>(m, vector<long long>(2, 0));     long k = 0;     vector<deal> *p10 = new vector<deal>();     vector<deal> *p11 = new vector<deal>();     vector<deal> *pp10;     vector<deal> *pp11;     long size10 = 0;     long size11 = 0;     long psize10;     long psize11;     long prev_size;     for (i = people.begin(); i != people.end(); i++) {       psize10 = size10;       psize11 = size11;       pp10 = p10;       pp11 = p11;       p10 = new vector<deal>();       p10->reserve(3);       p11 = new vector<deal>();       p11->reserve(3);       prev_size = size;       size = i->first;       money = i->second[0];       money2 = i->second[1];       if (prev_size + 1 < size) {         p10->push_back(deal(-1, -1, pp11));         p11->push_back(deal(-1, -1, pp11));         size10 = psize11;         size11 = psize11;         if (shoes[size] > 0 && shoes[size] <= money) {           d1[k][0] = shoes[size];           p10->push_back(deal(num_people[size][0], num_shoes[size]));           size10++;         } else           d1[k][0] = 0;         d1[k][1] = 0;         if (shoes[size] > 0 && shoes[size + 1] > 0) {           long cost, cost2;           bool p = 0;           if (shoes[size] > shoes[size + 1]) {             cost = shoes[size];             cost2 = shoes[size + 1];             p = 0;           } else {             cost = shoes[size + 1];             cost2 = shoes[size];             p = 1;           }           if (money >= cost) {             d1[k][1] += cost;             if (!p) {               p11->push_back(deal(num_people[size][0], num_shoes[size]));               size11++;             } else {               p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));               size11++;             }             if (money2 >= cost2) {               d1[k][1] += cost2;               if (!p) {                 p11->push_back(deal(num_people[size][1], num_shoes[size + 1]));                 size11++;               } else {                 p11->push_back(deal(num_people[size][1], num_shoes[size]));                 size11++;               }             }           } else {             if (money >= cost2) {               d1[k][1] += cost2;               if (!p) {                 p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));                 size11++;               } else {                 p11->push_back(deal(num_people[size][0], num_shoes[size]));                 size11++;               }             }           }         } else {           if (shoes[size] > 0 && shoes[size] <= money) {             d1[k][1] = shoes[size];             p11->push_back(deal(num_people[size][0], num_shoes[size]));             size11++;           }           if (shoes[size + 1] > 0 && shoes[size + 1] <= money) {             d1[k][1] = shoes[size + 1];             p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));             size11++;           }         }         if (k != 0) {           d1[k][0] += d1[k - 1][1];           d1[k][1] += d1[k - 1][1];         }       } else {         long cost = 0;         if (shoes[size] > 0 && shoes[size] <= money) cost = shoes[size];         d1[k][0] = max(d1[k - 1][0] + cost, d1[k - 1][1]);         if (d1[k - 1][0] + cost > d1[k - 1][1]) {           p10->push_back(deal(-1, -1, pp10));           if (cost) {             p10->push_back(deal(num_people[size][0], num_shoes[size]));             size10++;           }         } else {           p10->push_back(deal(-1, -1, pp11));         }         cost = 0;         long cost2 = 0;         if (shoes[size] > 0 && shoes[size + 1] > 0) {           if (shoes[size] > shoes[size + 1]) {             if (shoes[size] <= money) {               cost = shoes[size];               if (shoes[size + 1] <= money2) cost2 = shoes[size + 1];             } else {               if (shoes[size + 1] <= money) {                 cost2 = shoes[size + 1];               }             }           } else {             if (shoes[size + 1] <= money) {               cost2 = shoes[size + 1];               if (shoes[size] <= money2) cost = shoes[size];             } else {               if (shoes[size] <= money) {                 cost = shoes[size];               }             }           }         } else {           if (shoes[size] > 0 && shoes[size] <= money) cost = shoes[size];           if (shoes[size + 1] > 0 && shoes[size + 1] <= money)             cost2 = shoes[size + 1];         }         long cost3 = 0;         if (shoes[size + 1] > 0 && shoes[size + 1] <= money)           cost3 = shoes[size + 1];         d1[k][1] = 0;         d1[k][1] = max(d1[k - 1][0] + cost + cost2, d1[k - 1][1] + cost3);         if (d1[k - 1][0] + cost + cost2 > d1[k - 1][1] + cost3) {           p11->push_back(deal(-1, -1, pp10));           if (cost != 0 && cost2 != 0) {             if (cost > cost2) {               p11->push_back(deal(num_people[size][0], num_shoes[size]));               p11->push_back(deal(num_people[size][1], num_shoes[size + 1]));               size11++;               size11++;             } else {               p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));               p11->push_back(deal(num_people[size][1], num_shoes[size]));               size11++;               size11++;             }           } else {             if (cost) {               p11->push_back(deal(num_people[size][0], num_shoes[size]));               size11++;             }             if (cost2) {               p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));               size11++;             }           }         } else {           p11->push_back(deal(-1, -1, pp11));           if (cost3) {             p11->push_back(deal(num_people[size][0], num_shoes[size + 1]));             size11++;           }         }       }       k++;     }     printf( %I64d n , d1[k - 1][1]);     printf( %d n , size11);     vector<deal> *p;     p = p11;     while ((*p).size() != 0) {       for (int j = 1; j < (*p).size(); j++) {         if ((*p)[j].num_person + 1 < 0) break;         printf( %d %d n , (*p)[j].num_person + 1, (*p)[j].num_shoue + 1);       }       p = (*p)[0].d;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; }   inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; }   struct matrix {     double x[128][128];     double *operator[](int a) { return x[a]; }     void clear() { memset(x, 0, sizeof(x)); }     void reset() {       clear();       for (int i = 0; i < 128; ++i) x[i][i] = 1;     }   } p, a, ans;   matrix operator*(matrix &a, matrix &b) {     p.clear();     for (int i = 0; i < 128; i++)       for (int j = 0; j < 128; j++)         for (int k = 0; k < 128; k++) p[i][j] += a[i][k] * b[k][j];     return p;   }   int n, x;   double pos[128];   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i <= x; ++i) scanf( %lf , &pos[i]);     a.clear();     for (int i = 0; i < 128; ++i)       for (int j = 0; j < 128; ++j) a[i][j] = pos[i ^ j];     ans.reset();     for (; n; n >>= 1, a = a * a)       if (n & 1) ans = ans * a;     printf( %.10f n , 1.0 - double(ans[0][0]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n, value;     char str[200];     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> str;       if (strcmp(str,  add ) == 0) {         cin >> value;         v.insert(lower_bound(v.begin(), v.end(), value), value);       } else if (strcmp(str,  del ) == 0) {         cin >> value;         v.erase(lower_bound(v.begin(), v.end(), value));       } else if (strcmp(str,  sum ) == 0) {         long long sum = 0;         for (int j = 2; j < v.size(); j += 5) {           sum += v[j];         }         cout << sum << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while ((~c && c <  0 ) || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   int X[] = {-1, 0, 1, 0};   int Y[] = {0, 1, 0, -1};   int main() {     int n;     read(n);     int win = 2;     for (int i = 1; i <= n; i++) {       int a;       read(a);       if (a % 2 == 0) {         win = (win == 2) ? 1 : 2;       }       printf( %d n , win);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   set<pair<long long, long long> > st;   int resp[maxn];   struct island {     long long ini, fim;   } isl[maxn];   struct event {     long long type, val, ini;     event() { type = 0, val = 0, ini = 0; }     event(long long a, long long b, long long c) {       type = a;       val = b;       ini = c;     }   } e[2 * maxn];   bool cmp(event a, event b) {     if (a.ini == b.ini && a.type == b.type) return a.val < b.val;     if (a.ini == b.ini) return a.type < b.type;     return a.ini < b.ini;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     long long al, bl;     int siz = 0;     for (int i = 0; i < n; i++) {       long long a, b;       scanf( %I64d %I64d , &a, &b);       if (i != 0) {         isl[i - 1].fim = b - al;         isl[i - 1].ini = a - bl;         int atual = i - 1;         e[siz++] = event(1, atual, isl[i - 1].ini);       }       al = a;       bl = b;     }     for (int i = 0; i < m; i++) {       long long q;       scanf( %I64d , &q);       e[siz++] = event(2, i, q);     }     sort(e, e + siz, cmp);     for (int i = 0; i < siz; i++) {       if (e[i].type == 1) {         st.insert(make_pair(isl[e[i].val].fim, e[i].val));       } else {         set<pair<long long, long long> >::iterator it =             st.lower_bound(make_pair(e[i].ini, -1LL));         if (it != st.end()) {           resp[it->second] = e[i].val;           st.erase(it);         }       }     }     int ok = 1;     if (!st.empty()) ok = 0;     if (ok) {       puts( Yes );       for (int i = 0; i < n - 1; i++) {         printf( %d  , resp[i] + 1);       }       printf(  n );     } else {       puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[10000], i, sum = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int maxv = a[0];     int minv = a[0];     for (i = 1; i < n; ++i) {       if (maxv < a[i]) {         maxv = a[i];         sum++;       } else if (minv > a[i]) {         minv = a[i];         sum++;       }     }     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int s[505][505];   int main() {     scanf( %d%d , &n, &m);     char c = getchar();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         c = getchar();         if (c ==  S )           s[i][j] = 0;         else if (c ==  W )           s[i][j] = 1;         else           s[i][j] = 2;       }       getchar();     }     bool f = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] == 1) {           if (i > 1 && s[i - 1][j] == 0) f = 1;           if (j > 1 && s[i][j - 1] == 0) f = 1;           if (i < n && s[i + 1][j] == 0) f = 1;           if (j < m && s[i][j + 1] == 0) f = 1;         }       }     }     if (f) {       printf( No n );       return 0;     }     printf( Yes n );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] == 0) {           printf( S );         } else if (s[i][j] == 1)           printf( W );         else           printf( D );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, j, c = 0, p, q, f = 0;     scanf( %d , &n);     scanf( %d , &p);     int a[p];     for (i = 0; i < p; i++) scanf( %d , &a[i]);     scanf( %d , &q);     int b[q];     for (i = 0; i < q; i++) scanf( %d , &b[i]);     for (i = 1; i <= n; i++) {       f = 0;       for (j = 0; j < p; j++) {         if (a[j] == i) {           c++;           f++;         }       }       if (f == 0) {         for (j = 0; j < q; j++) {           if (b[j] == i) {             c++;           }         }       }     }     if (n == c)       printf( I become the guy. n );     else       printf( Oh, my keyboard! n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000018;   char str[2][510000], text[1010000];   int n, ans[1010000], num_node, fail[1010000], nxt[1010000], len[1010000],       to[1010000][26], path[1010000], pa[1010000];   int dl[1010000], last, save[1010000], ie[1010000];   void init() {     num_node = 2;     fail[0] = 1;     len[1] = -1;     len[0] = 0;     nxt[0] = 1;     last = 0;   }   int get_fail(int id, int pos) {     while (pos - len[id] - 1 < 1 || text[pos - len[id] - 1] != text[pos])       id = fail[id];     return id;   }   void add_letter(int pos) {     int cur = get_fail(last, pos);     if (!to[cur][text[pos] -  a ]) {       len[num_node] = len[cur] + 2;       fail[num_node] = to[get_fail(fail[cur], pos)][text[pos] -  a ];       dl[num_node] = len[num_node] - len[fail[num_node]];       if (dl[num_node] == dl[fail[num_node]])         nxt[num_node] = nxt[fail[num_node]];       else         nxt[num_node] = fail[num_node];       to[cur][text[pos] -  a ] = num_node++;     }     last = to[cur][text[pos] -  a ];   }   int main() {     scanf( %s%s , str[0], str[1]);     n = strlen(str[0]);     int i, j, s, p, q;     for (i = 0; i < n; i++) {       text[2 * i] = str[0][i];       text[2 * i + 1] = str[1][i];     }     n *= 2;     for (i = n - 1; i >= 0; i--) text[i + 1] = text[i];     init();     for (i = 1; i <= n; i++) {       add_letter(i);       ans[i] = inf;       for (j = last; len[j] > 0; j = nxt[j]) {         save[j] = ans[i - len[nxt[j]] - dl[j]];         path[j] = i - len[nxt[j]] - dl[j];         if (dl[j] == dl[fail[j]]) {           if (save[j] > save[fail[j]]) {             save[j] = save[fail[j]];             path[j] = path[fail[j]];           }         }         if (!(i & 1)) {           if (ans[i] > save[j] + 1) {             ans[i] = save[j] + 1;             pa[i] = path[j];           }         }       }       if (!(i & 1) && text[i] == text[i - 1]) {         if (ans[i] > ans[i - 2]) {           ans[i] = ans[i - 2];           pa[i] = i - 2;         }       }     }     if (ans[n] == inf)       puts( -1 );     else {       printf( %d n , ans[n]);       int id = n;       while (id > 0) {         if (pa[id] + 2 != id) printf( %d %d n , pa[id] / 2 + 1, id / 2);         id = pa[id];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double INF = 1e6;   const double PI = atan2(0, -1);   const int maxn = 550;   inline int sgn(double x) {     if (fabs(x) < EPS) return 0;     return x < 0 ? -1 : 1;   }   inline int iseq(double x, double y) { return sgn(x - y) == 0; }   struct Point {     double x, y;     Point(double x = 0, double y = 0) : x(x), y(y) {}     double Angle() { return atan2(y, x); }   };   inline Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }   inline Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }   inline Point operator*(double x, Point A) { return Point(x * A.x, x * A.y); }   inline double operator*(Point A, Point B) { return A.x * B.x + A.y * B.y; }   inline double operator%(Point A, Point B) { return A.x * B.y - A.y * B.x; }   inline double Length2(Point A) { return A * A; }   inline double Length(Point A) { return sqrt(A * A); }   inline double Distance2(Point A, Point B) { return Length2(A - B); }   inline double Distance(Point A, Point B) { return Length(A - B); }   inline bool operator==(Point A, Point B) { return iseq(Distance(A, B), 0); }   inline bool operator<(Point A, Point B) {     return iseq(A.x, B.x) ? sgn(A.y - B.y) == -1 : sgn(A.x - B.x) == -1;   }   struct Line {     Point P, Q;     Line() {}     Line(Point A, Point B) {       P = A;       Q = B;     }     Point Direction() { return Q - P; }   };   inline int IsOnLine(Point P, Line l) { return sgn((l.P - P) % (l.Q - P)) == 0; }   inline int IsOnSegment(Point P, Line l) {     if (P == l.P || P == l.Q) return 1;     return sgn((l.P - P) % (l.Q - P)) == 0 && sgn((l.P - P) * (l.Q - P)) <= 0;   }   inline bool IsSegmentOverlap(Line A, Line B) {     if (iseq(A.Direction() % B.Direction(), 0))       return IsOnSegment(A.P, B) + IsOnSegment(A.Q, B) + IsOnSegment(B.P, A) +                  IsOnSegment(B.Q, A) >=              2;     else       return false;   }   inline bool IsSegmentIntersected(Line A, Line B) {     if (IsOnSegment(A.P, B) || IsOnSegment(A.Q, B)) return true;     if (IsOnSegment(B.P, A) || IsOnSegment(B.Q, A)) return true;     int sgn1 = sgn((A.P - B.P) % B.Direction()),         sgn2 = sgn((A.Q - B.P) % B.Direction());     int sgn3 = sgn((B.P - A.P) % A.Direction()),         sgn4 = sgn((B.Q - A.P) % A.Direction());     return sgn1 * sgn2 == -1 && sgn3 * sgn4 == -1;   }   inline Point getLineIntersection(Line A, Line B) {     Point v = A.Direction(), w = B.Direction();     Point u = B.P - A.P;     return A.P + ((w % u) / (w % v)) * v;   }   int n;   vector<Point> Rect[maxn];   double area1, area2;   inline double getPolygonArea(const vector<Point> &A) {     double ans = 0;     for (auto j = 1u; j + 1 < A.size(); ++j)       ans += (A[j] - A[0]) % (A[j] - A[0]) * 0.5;     return ans;   }   inline bool IsInPolygon(Point P, const vector<Point> &A) {     double area1 = getPolygonArea(A), area2 = 0.0;     for (auto j = 0u; j + 1 < A.size(); ++j)       area2 += (A[j] - P) % (A[j + 1] - P) * 0.5;     return iseq(area1, area2);   }   inline bool IsPolygonOverlap(vector<Point> P[], int i, int j) {     int sgn = 1;     for (auto k = 0u; k < P[i].size(); ++k)       if (!IsInPolygon(P[i][k], P[j])) {         sgn = 0;         break;       }     if (!sgn) return false;     if (iseq(getPolygonArea(P[i]), getPolygonArea(P[j]))) return i < j;     return true;   }   struct info {     Point P;     double ang;     int delta;     info() {}     info(Point x, double y, int z) {       P = x;       ang = y;       delta = z;     }   };   inline int operator<(const info &A, const info &B) {     if (iseq(A.ang, B.ang))       return A.delta > B.delta;     else       return A.ang < B.ang;   }   inline double getPosition(Point P, Line l) {     return ((P - l.P) * l.Direction()) / (l.Direction() * l.Direction());     return (P.x - l.P.x) / (l.Q.x - l.P.x);   }   double ans[maxn];   double getAreaUnion(vector<Point> P[], int n, double *ans) {     for (int i = 1; i <= n; ++i) ans[i] = 0.0;     static vector<pair<double, int>> PointList;     double aans = 0;     for (int i = 1; i <= n; ++i)       for (auto j = 0u; j + 1 < P[i].size(); ++j) {         Line A(P[i][j], P[i][j + 1]);         PointList.clear();         for (int k = 1; k <= n; ++k)           if (i != k)             for (auto w = 0u; w + 1 < P[k].size(); ++w) {               Line B(P[k][w], P[k][w + 1]);               int p1 = sgn((B.P - A.P) % A.Direction());               int p2 = sgn((B.Q - A.P) % A.Direction());               if (!p1 && !p2) {                 if (i < k && sgn(A.Direction() * B.Direction()) == 1) {                   PointList.push_back(                       make_pair(min(1.0, max(getPosition(B.P, A), 0.0)), -1));                   PointList.push_back(                       make_pair(min(1.0, max(getPosition(B.Q, A), 0.0)), 1));                 }               } else {                 Point tp = getLineIntersection(A, B);                 if (p1 >= 0 && p2 < 0)                   PointList.push_back(                       make_pair(min(1.0, max(getPosition(tp, A), 0.0)), -1));                 if (p1 < 0 && p2 >= 0)                   PointList.push_back(                       make_pair(min(1.0, max(getPosition(tp, A), 0.0)), 1));               }             }         PointList.push_back(make_pair(0.0, 1));         PointList.push_back(make_pair(1.0, -1));         sort(PointList.begin(), PointList.end());         double S0 = A.P % A.Q * 0.5;         double lst = 0;         int now = 0;         for (auto l = 0u, r = 0u; l < PointList.size();) {           ans[now] += S0 * (PointList[l].first - lst);           lst = PointList[l].first;           for (r = l + 1; r < PointList.size() && iseq(PointList[r].first, lst);                ++r)             ;           for (auto w = l; w < r; ++w) now += PointList[w].second;           l = r;         }       }     return ans[1];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= 4; ++j) {         Point P;         scanf( %lf%lf , &P.x, &P.y);         Rect[i].push_back(P);       }       if (sgn((Rect[i][1] - Rect[i][0]) % (Rect[i][2] - Rect[i][0])) == -1)         reverse(Rect[i].begin(), Rect[i].end());       area1 += (Rect[i][1] - Rect[i][0]) % (Rect[i][3] - Rect[i][0]);       Rect[i].push_back(Rect[i][0]);     }     area2 = getAreaUnion(Rect, n, ans);     printf( %.10lf n , area1 / area2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     if (arr[n - 1] == 1) {       arr[n - 1] = 2;     } else {       arr[n - 1] = 1;     }     sort(arr.begin(), arr.end());     for (long long i = 0; i < n; i++) {       cout << arr[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     if (y == 0) return 1;     if (y & 1) return (x * power(x, y - 1)) % 1000000007;     long long int t = power(x, y / 2);     return (t * t) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     set<int> arr[26];     int n = (int)s.size();     for (int i = 0; i < n; i++) arr[s[i] -  a ].insert(i);     string mk =  Mike n ;     string ann =  Ann n ;     bool found = false;     for (int i = 0; i < n; i++) {       found = false;       for (int j = 0; j < s[i] -  a ; j++) {         auto itr = arr[j].lower_bound(0);         if (itr != arr[j].end() && *itr < i) {           found = true;           break;         }       }       if (true == found)         cout << ann;       else         cout << mk;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1000010;   const int inf = 0x3f3f3f3f;   using namespace std;   int n, m;   int c[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       c[a]++;       c[b]++;     }     if (n < 3) return puts( 0 ), 0;     long long ret = 0;     for (int i = 1; i <= n; i++) ret += 1ll * c[i] * (n - 1 - c[i]);     ret /= 2;     cout << (1ll * n * (n - 1) * (n - 2) / 6 - ret) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using dd = double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   ll INFLL = (ll)2e18, MOD = 1e9 + 7;   const int INF = 0x6f6f6f6f;   vector<vector<ll>> adj;   vector<int> vis;   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},       dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   inline ll mexp(ll x, ll n, ll m) {     ll res = 1;     while (n) {       if (n & 1) res = (res * x) % m;       n >>= 1;       x = ((x % m) * (x % m)) % m;     }     return res;   }   inline bool ispow2(ll x) { return x && (!(x & (x - 1))); }   inline ll gcd(ll x, ll y) {     pll p{x, y};     while (p.second) p = {p.second, p.first % p.second};     return p.first;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     cerr << fixed;     cout << setprecision(10);     cerr << setprecision(3);     mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());     int n;     cin >> n;     vector<int> seq(n + 1);     map<int, int> m;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       m[t] = i + 1;     }     int ct = 1;     for (auto& e : m) seq[e.second] = ct++;     m.clear();     vector<ll> tree(n + 1, 0);     auto sum = [&](int pos) {       ll ret = 0;       while (pos) {         ret += tree[pos];         pos -= pos & -pos;       }       return ret;     };     auto upd = [&](int pos, ll val) {       while (pos <= n) {         tree[pos] += val;         pos += pos & -pos;       }     };     ll ans = 0;     for (int i = 1; i <= n; ++i) {       ll gr = sum(n) - sum(seq[i]);       ll le = seq[i] - 1 - sum(seq[i] - 1);       ans += gr * le;       upd(seq[i], 1);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, int> > H[1000007];   long long n, val[1000005], ans, cnt[1000005];   int S[1000005];   int m, up[1000005], p[1000005], len, b[1000005], mp[1000005];   void prepare() {     int i, j;     b[1] = 1;     for (i = 2; i < 1000005; i++) {       if (!b[i]) p[++len] = i;       for (j = 1; j <= len; j++) {         if (1LL * i * p[j] >= 1000005) break;         b[1LL * i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }     for (i = 1; i < 1000005; i++) S[i] = S[i - 1] + (!b[i]);     for (i = 1; i <= len; i++) mp[p[i]] = i;     for (i = 1000005 - 1; i >= 1; i--) mp[i] = mp[i] ? mp[i] : mp[i + 1];   }   int SQRT(long long n) {     int p = (int)(sqrt(n));     while (1LL * p * p <= n) p++;     return p;   }   long long find(long long x, int t) {     int i, u = x % 1000007, p;     for (i = 0; i < H[u].size(); i++)       if (H[u][i].first == x) break;     p = H[u][i].second;     return t > up[p] ? cnt[p] + up[p] - t : cnt[p];   }   long long Pi(int t) { return cnt[t] + up[t] - 1; }   void update(int t) {     long long i, x = val[t], l = n / (x + 1) + 1, r = n / x;     r = min(r, (long long)(sqrt(n)));     for (i = l; i <= r; i++)       if (!b[i]) ans += Pi(t) - S[i];   }   int main() {     long long i, j = 1, q = 1;     long long x = 0;     cin >> n;     prepare(), m = 1;     for (i = 1; 1LL * p[i] * p[i] * p[i] <= n; i++) ans++;     for (i = 1; i <= n; i = n / (val[m++]) + 1) val[m] = n / i;     m--, sort(val + 1, val + m + 1);     for (i = 1; i <= m; i++)       H[val[i] % 1000007].push_back(pair<long long, int>(val[i], i));     for (i = 1; i <= m; i++) up[i] = mp[SQRT(val[i])];     for (i = 1; i <= up[m]; i++) {       for (j = m; j >= q; j--) {         if (i != 1) {           x = find(val[j] / p[i - 1], i - 1);           cnt[j] = cnt[j] - x - 1;         } else           cnt[j] = val[j] - 1;       }       while (q <= m && i == up[q]) update(q++);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n, i, j, k, l, m, arr[100010], arr1[100010], x, y;     double a, b, c, d, p, t;     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     reverse(arr, arr + n);     arr1[0] = arr[0];     for (i = 1; i < n; i++) arr1[i] = arr1[i - 1] + arr[i];     m = 9999999999;     for (i = 0; i < n - 1; i++)       m = min(abs(abs(arr1[n - 1] - arr1[i]) - arr1[i]) + 1, m);     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   int in() {     int n;     scanf( %d , &n);     return n;   }   long long Lin() {     long long n;     scanf( %lld , &n);     return n;   }   double Din() {     double n;     scanf( %lf , &n);     return n;   }   const long long inf = (long long)1e17;   const long long mod = (long long)1e9 + 7;   const int N = 5e5 + 5;   struct trie {     trie* node[2];     int cnt;     trie() {       node[0] = node[1] = NULL;       cnt = 0;     }   };   void add(trie* root, long long x, bool ck) {     for (int i = 1; i <= 18; i++) {       int p = (x % 2 == 1);       x /= 10;       if (root->node[p] == NULL) root->node[p] = new trie;       root = root->node[p];     }     ck ? root->cnt++ : root->cnt--;   }   int query(trie* root, string s) {     reverse(s.begin(), s.end());     while (s.size() < 18) s.push_back( 0 );     for (int i = 0; i < 18; i++) {       int p = s[i] -  0 ;       if (root->node[p] == NULL) return 0;       root = root->node[p];     }     return root->cnt;   }   int solve() {     int q = in();     trie* root = new trie;     while (q--) {       string ck;       long long x;       cin >> ck;       if (ck ==  + ) {         x = Lin();         add(root, x, true);       } else if (ck ==  - ) {         x = Lin();         add(root, x, false);       } else {         string s;         cin >> s;         printf( %d n , query(root, s));       }     }     return 0;   }   int main() {     int test = 1, tc = 0;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int i = n / 2 - 1, j = n / 2;     sort(arr, arr + n);     int x = 0;     int ans[n];     if (n % 2) ans[0] = arr[n / 2], x++, j++;     for (; i >= 0 && j < n; i--, j++) {       ans[x++] = arr[i];       ans[x++] = arr[j];     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   void test_case() {     int n;     cin >> n;     cout << fixed << setprecision(10) << (1 / tan(PI / (2 * n))) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tc;     cin >> tc;     for (int tt = 1; tt <= tc; ++tt) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   struct node {     char a;     struct node *left;     struct node *right;   };   int main() {     int t, len;     char ch[205];     struct node *p, *q, *r[26];     scanf( %d , &t);     getchar();     while (t--) {       int flag = 0;       scanf( %s , ch);       len = strlen(ch);       for (int i = 0; i < 26; i++) r[i] = NULL;       for (int i = 0; i < len; i++) {         if (r[ch[i] -  a ] == NULL) {           p = (struct node *)malloc(sizeof(struct node));           p->a = ch[i];           p->left = NULL;           p->right = NULL;           r[ch[i] -  a ] = p;           if (i > 0) {             if (r[ch[i - 1] -  a ]->left == NULL) {               r[ch[i - 1] -  a ]->left = p;               p->right = r[ch[i - 1] -  a ];             } else if (r[ch[i - 1] -  a ]->right == NULL) {               r[ch[i - 1] -  a ]->right = p;               p->left = r[ch[i - 1] -  a ];             } else {               printf( NO n );               flag = 1;               break;             }           }         } else {           if (r[ch[i] -  a ]->left != r[ch[i - 1] -  a ] &&               r[ch[i] -  a ]->right != r[ch[i - 1] -  a ]) {             printf( NO n );             flag = 1;             break;           }         }       }       if (flag == 1) continue;       printf( YES n );       for (int i = 0; i < 26; i++) {         if (r[i] != NULL) {           q = r[i];           while (q->left != NULL) q = q->left;           while (q != NULL) {             printf( %c , q->a);             q = q->right;           }           break;         }       }       for (int i = 0; i < 26; i++)         if (r[i] == NULL) printf( %c , i +  a );       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(2e6);   int n;   bool used[N + 7];   int main() {     cin >> n;     for (int i = 2; i * i <= N; ++i) {       if (!used[i]) {         for (int z = i * i; z <= N; z = z + i) used[z] = true;       }     }     int cnt = 0;     for (int i = 2; i <= N; ++i)       if (!used[i]) {         printf( %d  , i);         ++cnt;         if (cnt == n) return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const M = 2e5 + 10, M2 = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long tmp = 1;     for (long long i = 1;; i++) {       if (tmp - 1 >= n) return cout << i - 1, 0;       tmp *= 2;     }   }


#include<bits/stdc++.h>   using namespace std;   #define pi acos(-1)   #define printfl   printf( %f n ,f)   #define printd   printf( %lf n ,d)   #define printi   printf( %d n ,p)   #define printl   printf( %ld n ,l)   #define printll   printf( %lld n ,ll)   #define case cout<< Case  <<TEST<< :     #define forcase   for(int TEST=1;TEST<=test;TEST++)   #define max3(a,b,c) max((a,b),c)   #define min3(a,b,c) min((a,b),c)   #define newl printf(  n )   #define printd1d2 printf( %lf %lf n ,d1, d2)   #define ll long long int   void solve()   {       ll n,q;cin>>n>>q;       string s;cin>>s;       map <ll,ll> mp;       ll indx=1;       for (ll i = 1; i <=26; i++)           {               mp[i-1]=i;                          }      ll sum[n+1];      sum[0]=0;      ll l=1;      for (ll i = 0; i < s.size(); i++)          {              sum[l]=sum[l-1]+mp[s[i]- a ];              l++;          }               for (ll i = 0; i < q; i++)          {              ll c,d;cin>>c>>d;              cout<<sum[d]-sum[c-1]<<endl;          }        // cout<<sum[13]<<endl;                      }   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     int test;    // cin>>test;     //forcase     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod_factorial[100005];   long long mod_inv_factorial[100005];   long long binpow(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) {         res = (res * a);       }       a = (a * a);       b >>= 1;     }     return res;   }   long long binpowmod(long long a, long long b, long long p) {     long long res = 1LL;     while (b) {       if (b & 1) {         res = (res * 1LL * a) % 1000000007;       }       a = (a * 1LL * a) % 1000000007;       b >>= 1;     }     return res;   }   long long mod_inverse(long long a) {     return binpowmod(a, 1000000007 - 2, 1000000007);   }   void precomputefact() {     mod_factorial[0] = 1;     for (int i = 1; i <= 1e5; i++) {       mod_factorial[i] = (i * 1LL * mod_factorial[i - 1]) % 1000000007;     }     mod_inv_factorial[0] = 1;     for (int i = 1; i <= 1e5; i++) {       mod_inv_factorial[i] =           ((mod_inv_factorial[i - 1]) * 1LL * mod_inverse(i)) % 1000000007;     }   }   long long modbinomial(long long n, long long k, long long p) {     long long ans = mod_factorial[n] * mod_inv_factorial[n - k] % 1000000007 *                     mod_inv_factorial[k] % 1000000007;     return ans;   }   void solve() {     int n;     cin >> n;     vector<pair<int, int>> temp;     function<bool(pair<int, int>, pair<int, int>)> comp = [](pair<int, int> a,                                                              pair<int, int> b) {       if (a.first < b.first) {         return true;       } else if (a.first == b.first) {         if (a.second > b.second) {           return true;         }       }       return false;     };     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       temp.push_back(make_pair(l, r));     }     sort(temp.begin(), temp.end(), comp);     for (int i = 0; i < temp.size(); i++) {       int f = temp[i].first;       int s = temp[i].second;       if (f == s) {         cout << f <<     << s <<     << f <<   n ;       } else {         if (f == temp[i + 1].first) {           cout << f <<     << s <<     << temp[i + 1].second + 1 <<   n ;         } else if (s == temp[i + 1].second) {           cout << f <<     << s <<     << temp[i + 1].first - 1 <<   n ;         }       }     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long testcase;     cin >> testcase;     while (testcase--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool discount_flag = true;     int num_of_session;     cin >> num_of_session;     vector<int> num_of_teams(200001);     for (int i = 0; i < num_of_session; i++) cin >> num_of_teams[i];     for (int i = 0; i < num_of_session; i++)       if (num_of_teams[i] % 2 == 1)         if (i != num_of_session - 1 and num_of_teams[i + 1] > 0) {           num_of_teams[i + 1] -= 1;           num_of_teams[i] = 0;         } else if (num_of_teams[i + 1] == 0)           discount_flag = false;         else if (i == num_of_session)           discount_flag = false;     if (discount_flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fact(vector<int> x, long long t) {     if (t == 1) return 1;     vector<long long> num(x.begin(), x.end());     stringstream s;     string tmp;     s << t;     s >> tmp;     int count = 0;     for (int i = 0; i < num.size(); i++) {       stringstream ss;       string temp;       ss << num[i];       ss >> temp;       bool flag = false;       for (int j = 0; j < temp.size(); j++) {         for (int k = 0; k < tmp.size(); k++)           if (temp[j] == tmp[k]) {             count++;             flag = true;             break;           }         if (flag) break;       }     }     return count;   }   int main() {     long long n;     cin >> n;     long long t = n;     vector<int> factors;     long long i;     factors.push_back(1);     for (i = 2; i < sqrt(n); i++) {       if (n % i == 0) {         factors.push_back(n / i);         factors.push_back(i);       }     }     if (i * i == n) {       factors.push_back(i);     }     factors.push_back(n);     cout << fact(factors, t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void optimise() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int mod = 998244353;   long long int inf = 1e18 + 6;   void normalize(long long int &a) { a = (a + mod) % mod; }   long long int modmul(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a * b) % mod;   }   long long int modadd(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a + b) % mod;   }   long long int modsub(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a - b + mod) % mod;   }   long long int me(long long int x, long long int n) {     x %= mod;     if (n == 0) return 1;     long long int u = me(x, n / 2) % mod;     u = (u * u) % mod;     if (n % 2) u = (u * x) % mod;     return u;   }   long long int me1(long long int x, long long int n) {     if (n == 0) return 1;     long long int u = me1(x, n / 2);     u = u * u;     if (n % 2) u = u * x;     return u;   }   inline long long int modInv(long long int a) { return me(a, mod - 2); }   inline long long int modDiv(long long int a, long long int b) {     return modmul(a, modInv(b));   }   long long int __gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return __gcd(b, a % b);   }   const long long int N = 1e6 + 1;   vector<long long int> G[N];   void solve() {     long long int n;     cin >> n;     long long int a[n + 1];     long long int sum[n + 1];     sum[0] = 0;     for (long long int i = 1; i <= n; ++i) {       cin >> a[i];       sum[i] = sum[i - 1] + a[i];     }     map<long long int, vector<pair<long long int, long long int> > > m;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j + i - 1 <= n; j++) {         long long int sum1 = sum[i + j - 1] - sum[j - 1];         m[sum1].push_back({j + i - 1, j});       }     }     long long int max1 = 0;     long long int ans = -1;     for (auto i = m.begin(); i != m.end(); i++) {       sort(m[i->first].begin(), m[i->first].end());       long long int j1 = 0;       long long int r = 0;       long long int sum1 = i->first;       for (auto j = m[sum1].begin(); j != m[sum1].end(); j++) {         if (j->second > r) {           j1++;           r = j->first;         }       }       if (j1 > max1) {         ans = sum1;         max1 = j1;       }     }     cout << max1 <<   n ;     long long int r = 0;     for (auto k1 = m[ans].begin(); k1 != m[ans].end(); k1++) {       if (k1->second > r) {         cout << k1->second <<     << k1->first <<   n ;         r = k1->first;       }     }   }   signed main() {     optimise();     long long int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     long long int a[n + 2];     vector<long long int> pre(n + 2);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];     }     int left = 1;     int num = -1, occur = -1;     for (int i = 1; i <= n; i++) {       while ((a[i] * (i - left + 1) - (pre[i] - pre[left - 1])) > k) left++;       if (occur < (i - left + 1)) {         occur = i - left + 1;         num = a[i];       }     }     cout << occur <<     << num << endl;   }


#include <bits/stdc++.h>   int main() {     int t, a, b, i, temp;     scanf( %d , &t);     for (i = 1; i <= t; i++) {       scanf( %d %d , &a, &b);       if (b > a) {         temp = a;         a = b;         b = temp;       }       while ((a * a) < 2 * a * b) {         a++;       }       printf( %d n , a * a);     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[222222], b[222222], c[222222], d[222222];   set<long long> st;   set<long long>::iterator it;   map<long long, long long> sp2;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, k, x, s, i;     cin >> n >> m >> k;     cin >> x >> s;     for (i = 1; i <= m; i++) {       cin >> a[i];     }     for (i = 1; i <= m; i++) {       cin >> b[i];     }     for (i = 1; i <= k; i++) {       cin >> c[i];     }     for (i = 1; i <= k; i++) {       cin >> d[i];       st.insert(d[i]);       sp2[d[i]] = c[i];     }     long long ans = n * x;     long long rem;     long long temp;     for (i = 1; i <= m; i++) {       if (b[i] <= s) {         temp = 0;         rem = s - b[i];         it = st.upper_bound(rem);         if (it != st.begin()) {           it--;           temp += sp2[*it];         }         if (temp >= n)           ans = 0;         else           ans = min(ans, (n - temp) * a[i]);       }     }     temp = 0;     it = st.upper_bound(s);     if (it != st.begin()) {       it--;       temp += sp2[*it];     }     if (temp >= n)       ans = 0;     else       ans = min(ans, (n - temp) * x);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF32 = 0x3f3f3f3f;   const double EPS = 1.0e-8;   const double PI = acos(-1.0);   struct Point {     double x, y;     Point(double _x = 0, double _y = 0) {       x = _x;       y = _y;     }     friend Point operator+(const Point &a, const Point &b) {       return Point(a.x + b.x, a.y + b.y);     }     friend Point operator-(const Point &a, const Point &b) {       return Point(a.x - b.x, a.y - b.y);     }     friend double operator^(const Point &a, const Point &b) {       return a.x * b.y - a.y * b.x;     }     friend bool operator==(const Point &a, const Point &b) {       return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS;     }   };   struct V {     Point start, end;     V(Point _start = Point(0, 0), Point _end = Point(0, 0)) {       start = _start;       end = _end;     }   };   Point Basic;   set<Point> Set;   double Distance(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   bool operator<(Point a, Point b) {     a = a - Basic;     b = b - Basic;     double Ang1 = atan2(a.y, a.x), Ang2 = atan2(b.y, b.x);     double Len1 = Distance(a, Point(0.0, 0.0)),            Len2 = Distance(b, Point(0.0, 0.0));     if (fabs(Ang1 - Ang2) < EPS) return Len1 < Len2;     return Ang1 < Ang2;   }   set<Point>::iterator Pre(set<Point>::iterator it) {     if (it == Set.begin()) it = Set.end();     return --it;   }   set<Point>::iterator Nxt(set<Point>::iterator it) {     ++it;     return it == Set.end() ? Set.begin() : it;   }   int Query(Point p) {     set<Point>::iterator it = Set.lower_bound(p);     if (it == Set.end()) it = Set.begin();     return ((p - *(Pre(it))) ^ (*(it) - *(Pre(it)))) < EPS;   }   void Insert(Point p) {     if (Query(p)) return;     Set.insert(p);     set<Point>::iterator it = Nxt(Set.find(p));     while (Set.size() > 3 && ((p - *(Nxt(it))) ^ (*(it) - *(Nxt(it)))) < EPS) {       Set.erase(it);       it = Nxt(Set.find(p));     }     it = Pre(Set.find(p));     while (Set.size() > 3 && ((p - *(it)) ^ (*(it) - *(Pre(it)))) > -EPS) {       Set.erase(it);       it = Pre(Set.find(p));     }   }   int main() {     int q;     scanf( %d , &q);     Basic = Point(0, 0);     int oper;     Point a, str[5];     for (int i = 1; i <= 3; ++i) {       scanf( %d%lf%lf , &oper, &str[i].x, &str[i].y);       Basic = Basic + str[i];     }     Basic.x /= 3.0;     Basic.y /= 3.0;     q -= 3;     for (int i = 1; i <= 3; ++i) {       Set.insert(str[i]);     }     while (q--) {       scanf( %d%lf%lf , &oper, &a.x, &a.y);       if (oper == 1) {         Insert(a);       } else {         if (Query(a))           printf( YES n );         else           printf( NO n );       }     }   }