#include <bits/stdc++.h>   using namespace std;   int n;   int cnt[3], seen[3];   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     int m = n / 3;     for (int i = 0; i < n; i++) {       cnt[s[i] -  0 ]++;     }     for (int i = 0; i < n; i++) {       if (cnt[s[i] -  0 ] > m) {         for (long long j = 0; j < 3; j++) {           if (cnt[j] < m) {             if (j > s[i] -  0  && seen[s[i] -  0 ] < m) break;             cnt[j]++;             cnt[s[i] -  0 ]--;             s[i] = j +  0 ;           }         }       }       seen[s[i] -  0 ]++;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k, z;     cin >> n >> k >> z;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = 0;     for (int i = 0; i <= z; i++) {       int kol = k - 2 * i;       if (kol < 0) {         continue;       }       int tren = 0;       int maxa = 0;       for (int j = 0; j < kol + 1; j++) {         tren += a[j];         if (j < n - 1) {           maxa = max(a[j] + a[j + 1], maxa);         }       }       tren += i * maxa;       ans = max(ans, tren);     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {     unsigned long long ans;     long long n;     scanf( %I64d , &n);     ans = n * 3;     ans *= (n + 1);     cout << ++ans <<   n ;   }   int main() {     FILE* input = stdin;     FILE* output = stdout;     while (!feof(input)) {       run();       break;     }     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 t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) {         cin >> arr[i];       }       long long b[n];       if (n % 2 == 0) {         for (long long i = 0; i < n - 1; i = i + 2) {           b[i] = arr[i + 1];           b[i + 1] = -1 * arr[i];         }         for (long long i = 0; i < n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       } else {         for (long long i = 3; i < n - 1; i = i + 2) {           b[i] = arr[i + 1];           b[i + 1] = -1 * arr[i];         }         if (arr[0] + arr[1] != 0) {           cout << -arr[2] <<     << -arr[2] <<     << arr[0] + arr[1] <<    ;         } else if (arr[1] + arr[2] != 0) {           cout << arr[1] + arr[2] <<     << -arr[0] <<     << -arr[0] <<    ;         } else {           cout << -arr[1] <<     << arr[0] + arr[2] <<     << -arr[1] <<    ;         }         for (long long i = 3; i < n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};   const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};   void run() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v(m);     vector<int> id;     for (auto &it : v) {       cin >> it.first >> it.second;       id.push_back(it.first);     }     sort(id.rbegin(), id.rend());     vector<long long> sum(1, 0);     for (auto &it : id) sum.push_back(it + sum.back());     long long mx = sum[min(n, m)];     for (auto &it : v) {       int tmp_n = n;       int j = upper_bound(id.begin(), id.end(), it.second, greater<int>()) -               id.begin();       long long cur = 0;       if (it.first < it.second) {         cur += it.first;         tmp_n--;       }       j = min(j, tmp_n);       cur += sum[j];       tmp_n -= j;       cur += 1LL * tmp_n * it.second;       mx = max(mx, cur);     }     cout << mx <<   n ;   }   int main() {     run();     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio;     cin.tie(NULL);     long long i, j, n, t, k, m;     cin >> t;     while (t--) {       cin >> n >> k;       vector<long long> s(n);       for (long long i = 0; i < n; i++) {         cin >> s[i];       }       map<long long, queue<long long>> m;       for (long long i = 0; i < n; i++) {         m[s[i]].push(i);       }       vector<long long> res(n + 1, 0);       long long ans = 0;       long long count = 0;       long long col = 1;       vector<long long> v;       for (auto i : m) {         if (i.second.size() >= k) {           long long kk = k;           col = 1;           while (!i.second.empty() && kk > 0) {             res[i.second.front()] = col;             col++;             kk--;             i.second.pop();           }         } else {           while (!i.second.empty()) {             v.push_back(i.second.front());             i.second.pop();           }         }       }       if (v.size() >= k) {         long long sz = v.size();         long long st = sz / k;         st = st * k;         long long col = 1;         for (long long i = 0; i < st; i++) {           res[v[i]] = col;           col++;           if (col == k + 1) {             col = 1;           }         }       }       for (long long i = 0; i < n; i++) {         cout << res[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       char s[n + 1];       scanf( %s , s + 1);       int a[100] = {0}, b[100] = {0};       int aa = 0, bb = 0;       for (int i = 1; i <= n; i++) {         if (s[i] ==  a ) {           aa++;           b[i] = b[i - 1];           a[i] = a[i - 1] + 1;         } else {           bb++;           a[i] = a[i - 1];           b[i] = b[i - 1] + 1;         }       }       int flag = 1;       if (aa == 0 || bb == 0) {         printf( -1 -1 n );         continue;       } else {         for (int i = 1; i <= n; i++) {           if (flag == 1)             for (int j = n; j >= i; j--) {               if (a[j] - a[i - 1] == b[j] - b[i - 1]) {                 printf( %d %d n , i, j);                 flag = 0;                 break;               }             }           else             break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, u, r, i;   bool flag = false;   long long max_score = 0;   vector<long long> a, b, k, p;   inline long long score(vector<long long> a) {     long long s = 0;     for (i = (0); i < (n); ++i) {       s += a[i] * k[i];     }     return s;   }   vector<long long> permute(const vector<long long> &a) {     vector<long long> temp(a.size());     for (i = (0); i < (n); ++i) {       temp[i] = a[p[i] - 1] + r;     }     return temp;   }   void recurse(vector<long long> a, long long remain) {     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);     remain--;     for (i = (0); i < (n); ++i) {       a[i] = a[i] ^ b[i];     }     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);   }   int main(int argc, char *argv[]) {     cin >> n >> u >> r;     a = vector<long long>(n);     b = vector<long long>(n);     p = vector<long long>(n);     k = vector<long long>(n);     for (i = (0); i < (n); ++i) {       cin >> a[i];     }     for (i = (0); i < (n); ++i) {       cin >> b[i];     }     for (i = (0); i < (n); ++i) {       cin >> k[i];     }     for (i = (0); i < (n); ++i) {       cin >> p[i];     }     recurse(a, u);     cout << max_score << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, s, d;   bool f(char x) {     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) return true;     if (x >=  0  && x <=  9 ) {       int p = x -  0 ;       if (p % 2 == 1) return true;     }     return false;   }   int main() {     string s;     cin >> s;     int d = 0;     for (int i = 0; i < s.length(); i++) {       if (f(s[i])) d++;     }     cout << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   const long long maxn = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 10;   vector<long long> g[maxn];   long long deg[maxn];   long long a[maxn];   bool mark[maxn];   long long rem;   vector<long long> path, V;   inline void dfs(long long node) {     mark[node] = true;     rem--;     path.push_back(node);     for (auto u : g[node]) {       if (mark[u]) {         cout << 0 << endl;         exit(0);       }       dfs(u);     }   }   long long dp[maxn];   int32_t main() {     long long n = in(), q = in(), t = in();     rem = n;     for (long long i = 0; i < n; i++) a[i] = in();     for (long long i = 0; i < q; i++) {       long long from = in() - 1, to = in() - 1;       g[from].push_back(to);       deg[to]++;     }     V.push_back(0);     dp[0] = 1;     for (long long i = 0; i < n; i++) {       if (!mark[i] && !deg[i]) {         path.clear();         dfs(i);         long long prefsum = 0;         for (auto v : path) {           prefsum += a[v];           V.push_back(prefsum);           if (v - path.back()) t -= prefsum;         }       }     }     if (rem) return cout << 0 << endl, 0;     if (t < 0) return cout << 0 << endl, 0;     for (long long i = 1; i < V.size(); i++) {       for (long long pre = 0; pre + V[i] < maxn; pre++)         (dp[pre + V[i]] += dp[pre]) %= mod;     }     cout << dp[t] << endl;   }


#include <bits/stdc++.h>   using namespace std;   void er() {     cout <<  NO  << endl;     exit(0);   }   int main() {     int n;     cin >> n;     int a[n + 1];     int o = 0;     int um = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] != 0) o++;       um = um + a[i];     }     if (o < 1) er();     if (um != 0) {       cout <<  YES  << endl;       cout << 1 << endl;       cout << 1 <<     << n << endl;       return 0;     }     cout <<  YES  << endl;     cout << 2 << endl;     for (int i = 1; i <= n; i++) {       if (a[i] != 0) {         cout << 1 <<     << i << endl;         cout << i + 1 <<     << n << endl;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long double e = 1e-2;   int k;   long double R, r, l;   long double x, y, xl, yl, xr, yr;   long double a, b, c, S;   long double COS[12], SIN[12];   bool check(long double x, long double y) {     long double s = 0;     for (int i = 0; i < 12; i += 2)       s = max(s, ((x + COS[i]) * (x + COS[i])) + ((y + SIN[i]) * (y + SIN[i])));     return s <= l + r;   }   bool end(long double x, long double y) {     long double s = 1e+60;     for (int i = 0; i < 12; i += 2)       s = min(s, ((x + COS[i]) * (x + COS[i])) + ((y + SIN[i]) * (y + SIN[i])));     return s > S;   }   int main() {     R = 1;     r = sqrt(((R) * (R)) - ((0.5) * (0.5)));     for (int i = 0; i < 12; i++) {       COS[i] = cos(((i * 30) * M_PI / 180));       SIN[i] = sin(((i * 30) * M_PI / 180));     }     scanf( %d , &k);     l = k;     l *= l;     S = k + 3;     S *= S;     x = (k + 2) / 3 * 3 * COS[2];     y = (k + 2) / 3 * 3 * SIN[2];     xl = xr = x;     yl = yr = y;     long long ans = 0;     do {       long double s;       s = y * xr - x * yr;       while (s > 0 && abs(s) > e && !check(xr, yr)) {         xr += 2 * r * COS[5];         yr += 2 * r * SIN[5];         s = y * xr - x * yr;       }       while (check(xr, yr)) {         xr -= 2 * r * COS[5];         yr -= 2 * r * SIN[5];       }       s = y * xl - x * yl;       while (s < 0 && abs(s) > e && !check(xl, yl)) {         xl += 2 * r * COS[11];         yl += 2 * r * SIN[11];         s = y * xl - x * yl;       }       while (check(xl, yl)) {         xl -= 2 * r * COS[11];         yl -= 2 * r * SIN[11];       }       long double L = sqrt(((xl - xr) * (xl - xr)) + ((yl - yr) * (yl - yr)));       ans += max((long long)((L + r) / (2 * r)) - 1, 0LL);       xl += 2 * r * COS[7];       yl += 2 * r * SIN[7];       xr += 2 * r * COS[9];       yr += 2 * r * SIN[9];     } while (!end(xr, yr) || !end(xl, yl));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     string s[n];     long long flg = 1;     long long ar[n];     for (long long i = 0; i < n; i++) {       cin >> s[i];       long long flag = 0;       long long pos = -1;       for (long long j = 0; j < n; j++) {         if (s[i][j] ==  . ) {           flag = 1;           pos = j;           break;         }       }       if (flag == 0) {         flg = 0;       }       ar[i] = pos;     }     if (!flg) {       flg = 1;       long long ar[n];       for (long long i = 0; i < n; i++) {         long long flag = 0;         long long pos = -1;         for (long long j = 0; j < n; j++) {           if (s[j][i] ==  . ) {             flag = 1;             pos = j;             break;           }         }         if (flag == 0) {           flg = 0;           break;         }         ar[i] = pos;       }       if (!flg)         cout << -1;       else {         for (long long i = 0; i < n; i++) {           cout << ar[i] + 1 <<     << i + 1 <<   n ;         }       }       return 0;     } else {       for (long long i = 0; i < n; i++) {         cout << i + 1 <<     << ar[i] + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     long long int a[s.size()];     vector<long long int> v;     for (long long int i = 0; i < s.size(); i++) {       if (i == 0) {         vector<long long int> tp(8, 0);         long long int j = 0;         long long int k = s[i];         while (k) {           tp[j] = (k >> 0) & 1;           k = k >> 1;           j++;         }         long long int ans = 0;         reverse(tp.begin(), tp.end());         for (long long int l = 0; l < 8; l++) {           ans = ans + tp[l] * pow(2, l);         }         v.push_back(ans);         a[i] = 256 - ans;         continue;       }       vector<long long int> tp(8, 0);       long long int j = 0;       long long int k = s[i];       while (k) {         tp[j] = (k >> 0) & 1;         k = k >> 1;         j++;       }       long long int ans = 0;       reverse(tp.begin(), tp.end());       for (long long int l = 0; l < 8; l++) {         ans = ans + tp[l] * pow(2, l);       }       a[i] = (v[i - 1] - ans + 256) % 256;       v.push_back(ans);     }     for (long long int i = 0; i < s.size(); i++) cout << a[i] <<   n  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 400005;   template <typename T>   void cmin(T &x, const T &y) {     if (y < x) x = y;   }   template <typename T>   void cmax(T &x, const T &y) {     if (y > x) x = y;   }   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   int fst[MX], nxt[MX], v[MX], lnum;   int ida[MX], idb[MX], on_path[MX];   int n;   void addeg(int nu, int nv) {     nxt[++lnum] = fst[nu];     fst[nu] = lnum;     v[lnum] = nv;   }   void input() {     read(n);     for (int i = 1; i <= n; i++) read(ida[i]);     for (int i = 1; i <= n; i++) read(idb[i]);     for (int i = 1; i < n; i++) {       int a, b;       read(a), read(b);       addeg(a, b);       addeg(b, a);     }   }   int dep[MX], fa[MX], usd_mov;   void dfs1(int x, int f, int tar) {     dep[x] = dep[f] + 1, fa[x] = f;     if (x == tar) {       int tmp = x;       on_path[x] = 1;       while (fa[tmp])         swap(ida[tmp], ida[fa[tmp]]), tmp = fa[tmp], on_path[tmp] = 1, usd_mov++;     }     for (int i = fst[x]; i; i = nxt[i]) {       int y = v[i];       if (v[i] != f) dfs1(v[i], x, tar);     }   }   void fuck_out(char *s) {     cerr << s << endl;     puts( -1 );     exit(0);   }   int posa[MX], posb[MX], on_cyc[MX];   void work() {     int frm = 0, tar = 0;     for (int i = 1; i <= n; i++)       if (!ida[i]) frm = i;     for (int i = 1; i <= n; i++)       if (!idb[i]) tar = i;     dfs1(tar, 0, frm);     for (int i = 1; i <= n; i++) posa[ida[i]] = i, posb[idb[i]] = i;     for (int i = 1; i <= n; i++)       if (ida[i] != idb[i]) on_cyc[i] = 1;     int bot1 = 0, bot2 = 0;     static int vis[MX];     vector<int> cyc;     for (int i = 1; i <= n; i++)       if (on_cyc[i] && dep[i] > dep[bot1]) bot1 = i;     for (int x = bot1; on_cyc[x]; x = fa[x]) cyc.push_back(x), vis[x] = 1;     reverse(cyc.begin(), cyc.end());     if (!bot1) {       printf( %d %d n , 0, usd_mov);       return;     }     for (int i = 1; i <= n; i++)       if (on_cyc[i] && dep[i] > dep[bot2] && !vis[i]) bot2 = i;     for (int x = bot2; on_cyc[x]; x = fa[x]) cyc.push_back(x), vis[x] = -1;     int top1 = *cyc.begin(), top2 = *cyc.rbegin(), entry = fa[top1];     if (bot2 && fa[top1] != fa[top2]) fuck_out( unconnected loop! );     for (int i = 1; i <= n; i++)       if (on_cyc[i] && !vis[i]) fuck_out( not a single loop! );     int step = 0, revs = 0;     for (int i = 0; i < cyc.size(); i++)       if (idb[cyc[i]] == ida[cyc[0]]) step = i;     for (int i = 0; i < cyc.size(); i++)       if (idb[cyc[(i + step) % cyc.size()]] != ida[cyc[i]])         fuck_out( can t rearrange loop! );     for (int x = frm; x; x = fa[x]) revs += vis[x];     long long way1 = usd_mov + 1ll * step * (cyc.size() + 1);     long long way2 = usd_mov + 1ll * (cyc.size() - step) * (cyc.size() + 1);     if (revs > 0)       way2 -= revs * 2;     else       way1 += revs * 2;     long long ans = min(way1, way2);     int adda = 0, addb = 0;     if (bot1 && bot2)       adda = bot1, addb = bot2;     else       adda = bot1, addb = entry;     for (int x = entry; !on_path[x]; x = fa[x]) ans += 2;     if (adda > addb) swap(adda, addb);     printf( %d %d %lld n , adda, addb, ans);   }   int main() {     input();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     long long m_min = 1ll << 62;     long long ans = 0;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       ans += x;       if (x % 2 == 1) m_min = min(m_min, x);     }     if (ans % 2 == 1) ans -= m_min;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 5;   long long int power(long long int base, long long int exp) {     long long int res = 1;     while (exp) {       if (exp % 2) res *= base;       base *= base;       res %= mod;       base %= mod;       exp /= 2;     }     return res;   }   long long int n, m, k, l[maxn], r[maxn], dp[350][350], adj[350][350], c[maxn];   long long int go(long long int idx, long long int k) {     if (k <= 0) return 0;     if (idx >= n + 1) return 1e16;     long long int &ret = dp[idx][k];     if (ret != -1) return ret;     ret = go(idx + 1, k);     for (long long int i = idx; i <= min(idx + k, n); i++) {       ret = min(ret, go(i + 1, k - (i - idx + 1)) + adj[idx][i]);     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> k;     for (long long int i = 1; i <= n; i++)       for (long long int j = i; j <= n; j++) adj[i][j] = 1e15;     for (long long int i = 1; i <= m; i++) {       cin >> l[i] >> r[i] >> c[i];       adj[l[i]][r[i]] = min(adj[l[i]][r[i]], c[i]);     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         if (i < j) break;         for (long long int k = j; k <= n; k++) {           adj[j][k] = min(adj[j][k], adj[j][i] + adj[i][k]);         }       }     }     memset(dp, -1, sizeof(dp));     long long int ans = go(1, k);     if (ans > 1e12) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> A;       if (i == n) {         while (A--) cout <<  PLR ;         return 0;       }       while (A--) {         cout <<  PRL ;       }       cout <<  R ;     }   }


#include <bits/stdc++.h>   const int inf = int(1e9);   const int mod = inf + 7;   const double PI = acos(-1.0);   using namespace std;   const int N = 1e5 + 155;   void solve() {     int n, k, s = 0;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       s += x;     }     for (int ans = 0;; ans++) {       int a = 2 * (s + ans * k);       int b = (2 * k - 1) * (ans + n);       if (a >= b) {         cout << ans;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int ans = 0;     while ((a >= 1 && b > 1) || (a > 1 && b >= 1)) {       if (a < b) {         ans++;         a--;         b -= 2;       } else {         ans++;         a -= 2;         b--;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int L[7], R[7];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> L[i] >> R[i];     }     long double cases = 0;     long double sum = 0;     for (int p = 1; p <= 10000; ++p) {       for (int mask = 3; mask < 1 << n; ++mask) {         bool ok = true;         long double cnt = 1;         for (int j = 1; j <= n; ++j)           if (!((mask >> (j - 1)) & 1)) {             if (L[j] < p) {               cnt *= min(p - 1, R[j]) - L[j] + 1;             } else {               ok = false;             }           }         if (!ok) continue;         vector<pair<bool, int>> ranges;         for (int j = 1; j <= n; ++j)           if ((mask >> (j - 1)) & 1) {             if (p <= R[j]) {               ranges.push_back(make_pair(L[j] <= p, R[j] - max(p + 1, L[j]) + 1));             } else {               ok = false;             }           }         if (!ok) continue;         long double cnt2 = 0;         for (int j = 0; j < int(ranges.size()); ++j) {           bool ok = true;           for (int k = 0; k < int(ranges.size()); ++k)             if (k != j)               if (!ranges[k].first) ok = false;           if (ok) {             cnt2 += ranges[j].second;           }         }         int b = 0;         for (int tmp = mask; tmp; tmp &= tmp - 1) ++b;         if (b < 2) continue;         bool add = true;         for (int j = 0; j < int(ranges.size()); ++j) {           add &= ranges[j].first;         }         cnt *= (cnt2 + add);         cases += cnt;         sum += cnt * p;       }     }     cout << fixed << setprecision(15) << 1.0 * sum / cases;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sub;     int grp;     cin >> n >> sub;     if (n == sub)       grp = 0;     else if (sub == 0 || sub == 1)       grp = 1;     else if (sub >= n - n / 2)       grp = n - sub;     else       grp = sub;     cout << grp << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Bp, typename Ep, typename Mp>   inline Mp __powMod(Bp a, Ep b, const Mp &m) {     a %= m;     Mp res = 1;     while (b > 0) {       if (b & 1) {         res = ((long long)res * a) % m;       }       a = ((long long)a * a) % m;       b >>= 1;     }     return res % m;   }   const int MOD = 1e9 + 7;   template <typename Tp>   inline Tp inv(const Tp &x) {     return __powMod(x, MOD - 2, MOD);   }   const int N = 100000 + 5;   int m;   int dp[N];   vector<int> prime;   int mu[N];   bool notPrime[N];   inline void init() {     mu[1] = 1;     for (int i = 2; i < N; ++i) {       if (!notPrime[i]) {         mu[i] = -1;         prime.emplace_back(i);       }       for (const auto &p : prime) {         if (i * p >= N) {           break;         }         notPrime[i * p] = true;         if (i % p == 0) {           mu[i * p] = 0;           break;         } else {           mu[i * p] = -mu[i];         }       }     }   }   int main() {     init();     scanf( %d , &m);     int ans = 1;     for (int i = 2, t; i <= m; ++i) {       if (mu[i] != 0) {         t = m / i;         ans = (ans - (long long)mu[i] * t * inv(m - t) % MOD + MOD) % MOD;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   double pd[40][40][300];   int n, K;   int r[40];   int go(int a, int i, int j) {     if (a < i || a > j) return a;     return j - (a - i);   }   double solve(int a, int b, int k) {     if (k == 0) return b < a;     double& ret = pd[a][b][k];     if (ret > -0.5) return ret;     ret = 0;     double mul = 1. / ((double)((n * (n + 1)) / 2));     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) {         int aa = go(a, i, j);         int bb = go(b, i, j);         ret += mul * solve(aa, bb, k - 1);       }     return ret;   }   int main() {     cin >> n >> K;     memset(pd, -1, sizeof pd);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       r[x] = i;     }     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         ans += solve(r[i], r[j], K);       }     printf( %.15f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244353;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     long long n, k;     cin >> n >> k;     long long m = 0;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     for (long long i = n; i > n - k; i--) {       m += i;     }     vector<long long> ind;     for (long long i = 0; i < n; i++) {       if (v[i] > n - k) ind.push_back(i);     }     long long x = 1;     for (long long i = 1; i < ind.size(); i++) {       x *= ind[i] - ind[i - 1];       x %= MOD;     }     cout << m <<     << x;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   int nxt[100001];   char s[100001], t[100001];   int temp[100001];   int l, r;   bool check(int u) {     for (int i = 0; i < m; ++i) {       if (s[u + i] != t[i]) return 0;     }     return 1;   }   void pre_do() {     for (int i = 1; i <= n - m + 1; i++) {       temp[i] += check(i);     }   }   void putin() {     cin >> n >> m >> q;     scanf( %s%s , s + 1, t);   }   int main() {     putin();     pre_do();     for (int i = 1; i <= n; i++) {       temp[i] += temp[i - 1];     }     for (int i = 1; i <= q; i++) {       cin >> l >> r;       if (r - l + 1 < m)         cout << 0 << endl;       else         cout << temp[r - m + 1] - temp[l - 1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e4 + 5;   const int SQRN = 210;   const int BSZ = 256;   vector<int> g[MAXN];   int v[MAXN], lvl[MAXN], pai[MAXN];   int jump[MAXN], best[MAXN][SQRN];   int trie[BSZ * 20 + 5][2];   int n, q, cnt_trie = 1;   void predfs(int cur, int p) {     for (auto viz : g[cur]) {       if (viz == p) continue;       lvl[viz] = lvl[cur] + 1;       pai[viz] = cur;       predfs(viz, cur);     }   }   void build(int cur, int k, int root) {     if (k >= BSZ) return;     jump[root] = cur;     int val = v[cur] ^ k;     int tcur = 1;     for (int i = 16; i >= 0; i--) {       bool viz = val & (1 << i);       if (!trie[tcur][viz]) trie[tcur][viz] = ++cnt_trie;       tcur = trie[tcur][viz];     }     if (pai[cur] == cur) return;     build(pai[cur], k + 1, root);   }   int find_best(int mask) {     int cur = 1;     int resp = 0;     for (int i = 16; i >= 0; i--) {       bool want = 1 ^ ((bool)(mask & (1 << i)));       if (trie[cur][want])         cur = trie[cur][want], resp += (1 << i);       else         cur = trie[cur][!want];     }     return resp;   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= n - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     pai[1] = 1;     predfs(1, 1);     for (int i = 1; i <= n; i++) {       build(i, 0, i);       for (int k = 0; k * BSZ <= n; k++) best[i][k] = find_best(k * BSZ);       memset(trie, 0, sizeof(trie));       cnt_trie = 1;     }     while (q--) {       int a, b;       scanf( %d %d , &a, &b);       int w = 0;       int respf = 0;       while (lvl[jump[b]] > lvl[a]) {         respf = max(respf, best[b][w]);         b = pai[jump[b]];         w++;       }       int dist = w * BSZ;       while (b != a) {         respf = max(respf, v[b] ^ dist);         b = pai[b];         dist++;       }       respf = max(respf, v[a] ^ dist);       printf( %d n , respf);     }   }


#include <bits/stdc++.h>   using namespace std;   namespace std {   bool operator<(const complex<double> &lhs, const complex<double> &rhs) {     if (real(lhs) == real(rhs)) {       return imag(lhs) < imag(rhs);     } else {       return real(lhs) < real(rhs);     }   }   }  // namespace std   ostream &operator<<(ostream &os, const complex<double> &p) {     return os <<  (  << p.real() <<  ,  << p.imag() <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &vec) {     os <<  [ ;     for (const auto &v : vec) {       os << v <<  , ;     }     os <<  ] ;     return os;   }   complex<double> counter_clock_wise(complex<double> p, double rad) {     double a = abs(p);     return polar(a, arg(p) + rad);   }   const double EPS = 1e-7;   const double PI = 3.141592653589793;   double dot(complex<double> a, complex<double> b) { return real(conj(a) * b); }   double point_distance(complex<double> a, complex<double> b) {     return abs(a - b);   }   bool is_square(vector<complex<double> > ps) {     sort(ps.begin(), ps.end());     vector<double> dist;     for (long long i = 0; i < 4; i++) {       for (long long j = i + 1; j < 4; j++) {         if (abs(ps[i] - ps[j]) < EPS) return false;         dist.push_back(abs(ps[i] - ps[j]));       }     }     sort(dist.begin(), dist.end());     for (long long i = 0; i < 4; i++) {       if (abs(dist[0] - dist[i]) > EPS) return false;     }     for (long long i = 4; i < 6; i++) {       if (abs(sqrt(2) * dist[1] - dist[i]) > EPS) return false;     }     return true;   }   const long long INF = 100000000;   long long solve(vector<long long> y, vector<long long> x, vector<long long> b,                   vector<long long> a) {     long long ret = INF;     ;     ;     for (long long i = 0; i < static_cast<long long>(4); i++) {       for (long long j = 0; j < static_cast<long long>(4); j++) {         for (long long k = 0; k < static_cast<long long>(4); k++) {           for (long long l = 0; l < static_cast<long long>(4); l++) {             vector<long long> cur = {i, j, k, l};             vector<complex<double> > ps;             for (long long m = 0; m < static_cast<long long>(4); m++) {               complex<double> p(x[m], y[m]);               p -= complex<double>(a[m], b[m]);               p = counter_clock_wise(p, (PI / 2) * cur[m]);               p += complex<double>(a[m], b[m]);               ps.push_back(p);             }             sort(ps.begin(), ps.end());             if (is_square(ps)) {               ;               ;               ret = min(ret, i + j + k + l);             }           }         }       }     }     if (ret == INF) return -1;     return ret;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       vector<long long> y(4), x(4), b(4), a(4);       for (long long j = 0; j < 4; j++) {         cin >> x[j] >> y[j] >> a[j] >> b[j];       }       long long ret = solve(y, x, b, a);       cout << ret << endl;     }     return 0;   }


#include <bits/stdc++.h>   namespace IO {   char gc() { return getchar(); }   template <typename Tp>   bool get1(Tp &x) {     bool neg = 0;     char c = gc();     while (c != EOF && (c <  0  || c >  9 ) && c !=  - ) c = gc();     if (c ==  - ) c = gc(), neg = 1;     if (c == EOF) return false;     x = 0;     for (; c >=  0  && c <=  9 ; c = gc()) x = x * 10 + c -  0 ;     if (neg) x = -x;     return true;   }   template <typename Tp>   void printendl(Tp x) {     if (x < 0) putchar( - ), x = -x;     static short a[40], sz;     sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);     puts(  );   }   }  // namespace IO   using IO::get1;   using IO::printendl;   const int inf = 0x3f3f3f3f;   const long long Linf = 1ll << 61;   const int maxn = 111;   int n, q1, q2, a[maxn], b[maxn], c[maxn], ans[maxn];   int d[maxn];   void getv(int id) {     for (int i = 1; i <= n; i++) a[id] += d[i] * (d[i] - 1) * (d[i] - 2) / 6;     for (int i = 1; i <= n - 2; i++) b[id] += d[i] * d[i + 1] * d[i + 2];   }   int main() {     get1(n);     get1(a[0]) && get1(b[0]);     for (int i = 1; i <= n; i++) {       c[i] = (i < n ? i : 1);       printf( + %d n , c[i]);       fflush(stdout);       get1(a[i]) && get1(b[i]);     }     for (int i = n; i >= 1; i--) {       a[i] -= a[i - 1];       b[i] -= b[i - 1];     }     memset(ans, -1, sizeof(ans));     ans[1] = (a[n] - a[1]);     for (int i = 2; i < n; i++)       if (a[i]) {         ans[i] = 0;         while (ans[i] * (ans[i] - 1) / 2 < a[i]) ans[i]++;       }     if (ans[3] == -1) ans[3] = (b[2] > 0);     if (ans[2] == -1) ans[2] = b[n] / (ans[3] + 1) - 1;     for (int i = 3; i < n - 1; i++) {       b[i] -= (ans[i - 1] + 1) * (ans[i - 2] + 1);       if (ans[i + 1] == -1) ans[i + 1] = (b[i] > 0);     }     ans[n] = (b[n - 1] - (ans[n - 2] + 1) * (ans[n - 3] + 1)) / (ans[n - 2] + 1);     printf( ! );     for (int i = 1; i <= n; i++) printf(  %d , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     if (x < y) swap(x, y);     while (y > 0) {       T f = x % y;       x = y;       y = f;     }     return x;   }   const int maxn = 200005;   int n;   int a[maxn];   int dp[maxn];   vector<int> adj[maxn];   void dfs(int u, int p, set<int> gcd0, set<int> gcd1) {     dp[u] = *gcd0.rbegin();     if (!gcd1.empty()) {       dp[u] = max(dp[u], *gcd1.rbegin());     }     for (int v : adj[u]) {       if (v != p) {         set<int> g0;         set<int> g1 = gcd0;         for (auto x : gcd0) g0.insert(gcd(x, a[v]));         for (auto x : gcd1) g1.insert(gcd(x, a[v]));         dfs(v, u, g0, g1);       }     }   }   int main(int argc, char *argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     {       for (int i = 1; i <= n; i++) cin >> a[i], dp[i] = i;       for (int i = 1; i < n; i++) {         int x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       set<int> gcd0;       set<int> gcd1;       gcd0.insert(a[1]);       gcd1.insert(0);       dfs(1, 0, gcd0, gcd1);       for (int i = 1; i <= n; i++) {         cout << dp[i] << (i == n ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   int v[N], md[N];   vector<int> freq[N];   int lm[N], rm[N];   int cs[N];   int val(int x, int l, int r) {     if (l > r || l < 0) return 0;     return upper_bound(freq[x].begin(), freq[x].end(), r) -            lower_bound(freq[x].begin(), freq[x].end(), l);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     freq[0].push_back(0);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i]);       md[i] = v[i] % k;       cs[i] += v[i] % k;       cs[i] += cs[i - 1];       cs[i] %= k;       freq[cs[i]].push_back(i);     }     stack<pair<int, int> > s;     for (int i = n; i > 0; i--) {       while (s.size() && s.top().first < v[i]) {         s.pop();       }       if (s.size()) {         rm[i] = s.top().second - 1;       } else         rm[i] = n;       s.push(make_pair(v[i], i));     }     while (!s.empty()) {       s.pop();     }     for (int i = 1; i <= n; i++) {       while (s.size() && s.top().first <= v[i]) {         s.pop();       }       if (s.size()) {         lm[i] = s.top().second + 1;       } else         lm[i] = 1;       s.push(make_pair(v[i], i));     }     long long ans = 0;     int l, r, al, ar;     int x, d;     for (int i = 1; i <= n; i++) {       if (lm[i] == rm[i]) continue;       if (abs(lm[i] - i) + 1 < abs(i - rm[i]) + 1) {         l = lm[i] - 1, r = i - 2;         al = i + 1, ar = rm[i];         d = md[i];       } else {         d = -md[i];         l = i + 1, r = rm[i];         al = lm[i] - 1, ar = i - 2;       }       for (int j = l; j <= r; j++) {         x = cs[j] + d + k;         x %= k;         ans += val(x, al, ar);       }       ans += val(cs[i - 1], lm[i] - 1, i - 2);       ans += val(cs[i], i + 1, rm[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int u[1005];   int v[1005];   int main() {     int n, k, i;     cin >> n >> k;     int a, b, c, d;     int t;     cin >> a >> b >> c >> d;     if (n == 4) {       cout <<  -1  << endl;     } else if (k < n + 1) {       cout <<  -1  << endl;     } else {       cout << a <<    ;       cout << c <<    ;       for (i = 1; i <= n; i++) {         if (i == a || i == b || i == c || i == d) {           continue;         }         cout << i <<    ;       }       cout << d <<    ;       cout << b << endl;       cout << c <<    ;       cout << a <<    ;       for (i = 1; i <= n; i++) {         if (i == a || i == b || i == c || i == d) {           continue;         }         cout << i <<    ;       }       cout << b <<    ;       cout << d << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long M = 1e9 + 7;   const long long H = 1e5 + 7;   const long long B = 1e4 + 7;   const long long A = 1e6 + 7;   set<long long> o;   map<long long, long long> mp, pm;   map<char, long long> hs;   vector<long long> v, vc, oreder1, inoreder, posoreder, ve, vv, vd;   deque<char> p, pe;   deque<string> ts, ss, stoi, rs;   deque<double> sd, ds;   string g, s, w, h, s1;   double l;   char z, u =  a ;   bool re, rt;   deque<int> e;   map<pair<long long, long long>, long long> aw, wa;   long long cnt, ans, TT, n, a, b, c, q, m, t, d, temp, mx = 0, mn = 0, rem, sum,                                                         tt = 1e32;   long long used[N];   int main() {     ios_base::sync_with_stdio(0);     srand(time(NULL));     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a >> b;       cnt = 0;       for (long long i = 0; i < a; i++) {         cin >> l;         cnt += l;       }       if (cnt == b) cout <<  YES  << endl;       if (cnt != b) cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[225][1 << 16];   int dx[4] = {0, -1, 0, 1};   int dy[4] = {1, 0, -1, 0};   int tran[4] = {2, 3, 0, 1};   string s[15];   bool visit[15][15][1 << 16];   int n, m, length, backx, backy, startbody, status;   struct snake {     int x, y, body;   } start;   bool in(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }   bool collision(int x, int y, snake sn) {     int body = sn.body;     int xx = sn.x;     int yy = sn.y;     for (int i = 1; i < length - 1; i++) {       xx += dx[tran[body & 3]];       yy += dy[tran[body & 3]];       body >>= 2;       if (x == xx && y == yy) return true;     }     return false;   }   int BFS() {     queue<pair<snake, int>> Q;     Q.push({start, 0});     visit[start.x][start.y][start.body] = 1;     while (!Q.empty()) {       snake nowsnake = Q.front().first;       int nowstep = Q.front().second;       if (s[nowsnake.x][nowsnake.y] ==  @ ) return nowstep;       Q.pop();       for (int i = 0; i < 4; i++) {         int nextx = nowsnake.x + dx[i];         int nexty = nowsnake.y + dy[i];         if (in(nextx, nexty) && s[nextx][nexty] !=  #  &&             !collision(nextx, nexty, nowsnake)) {           snake nextsnake;           nextsnake.x = nextx;           nextsnake.y = nexty;           nextsnake.body = ((nowsnake.body << 2) & startbody) | i;           if (!visit[nextsnake.x][nextsnake.y][nextsnake.body]) {             visit[nextsnake.x][nextsnake.y][nextsnake.body] = true;             Q.push({nextsnake, nowstep + 1});           }         }       }     }     return -1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     length = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] !=  #  && s[i][j] !=  @  && s[i][j] !=  . ) {           if (s[i][j] ==  1 ) {             start.x = i;             start.y = j;           }           if (s[i][j] -  0  > length) {             backx = i;             backy = j;             length = s[i][j] -  0 ;           }         }       }     }     startbody = (1 << ((length - 1) * 2)) - 1;     status = 0;     while (s[backx][backy] !=  1 ) {       for (int i = 0; i < 4; i++) {         int newbackx = backx + dx[i];         int newbacky = backy + dy[i];         if (in(newbackx, newbacky) &&             s[newbackx][newbacky] + 1 == s[backx][backy]) {           status <<= 2;           status |= i;           backx = newbackx;           backy = newbacky;           break;         }       }     }     start.body = status;     cout << BFS() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 1e5 + 10, mod = 1e9 + 7, inf = 2e9;   struct re {     int to, va;     bool co;   };   re nel;   int n, anch = 1, anzn = 1, cuq, si[sz], sq, cu, lg, rg, add;   vector<re> sv[sz];   vector<pair<int, pair<int, int> > > pa[sz];   pair<int, int> dot[2][sz * 8];   pair<int, int> recalc(pair<int, int> l, pair<int, int> r) {     pair<int, int> re;     re.first = (1ll * l.first * r.first) % mod;     re.second = l.second + r.second;     return re;   }   void build(int nu, int l, int r) {     dot[cu][nu].first = 1, dot[cu][nu].second = 0;     if (l < r) {       int mid = (l + r) / 2;       build(nu * 2, l, mid);       build(nu * 2 + 1, mid + 1, r);     }   }   void cha(int nu, int l, int r) {     if (l == r) {       dot[cu][nu].first = (1ll * dot[cu][nu].first * add) % mod,       dot[cu][nu].second++;     } else {       int mid = (l + r) / 2;       if (lg <= mid)         cha(nu * 2, l, mid);       else         cha(nu * 2 + 1, mid + 1, r);       dot[cu][nu] = recalc(dot[cu][nu * 2], dot[cu][nu * 2 + 1]);     }   }   pair<int, int> que(int nu, int l, int r) {     if (l >= lg and r <= rg)       return dot[cu][nu];     else if (l > rg or r < lg)       return make_pair(1, 0);     else {       int mid = (l + r) / 2;       return recalc(que(nu * 2, l, mid), que(nu * 2 + 1, mid + 1, r));     }   }   int pow(int x, int y) {     if (y == 0)       return 1;     else if (y % 2 == 1)       return (1ll * pow(x, y - 1) * x) % mod;     else {       int t = pow(x, y / 2);       return (1ll * t * t) % mod;     }   }   void siz(int v, int pr) {     si[v] = 1;     for (int a = 0; a < sv[v].size(); a++) {       int ne = sv[v][a].to;       if (ne != pr) {         siz(ne, v);         si[v] += si[ne];       }     }   }   int find_ce(int v, int pr) {     for (int a = 0; a < sv[v].size(); a++) {       int ne = sv[v][a].to;       if (ne != pr and si[ne] > cuq / 2) return find_ce(ne, v);     }     if (pr != -1) si[pr] = cuq - si[v];     return v;   }   void dfs2(int v, int pr, int rq, int bq, int le) {     pa[sq].push_back(make_pair(le, make_pair(rq, bq)));     for (int a = 0; a < sv[v].size(); a++) {       int ne = sv[v][a].to, r = 0, b = 0, nle = sv[v][a].va;       if (sv[v][a].co == 0)         r++;       else         b++;       if (ne != pr) dfs2(ne, v, rq + r, bq + b, (1ll * le * nle) % mod);     }   }   void dfs(int v, int q) {     cuq = q;     siz(v, -1);     int ce = find_ce(v, -1);     sq = 1;     pa[0].push_back(make_pair(1, make_pair(0, 0)));     for (int a = 0; a < sv[ce].size(); a++) {       int ne = sv[ce][a].to, rq = 0, bq = 0, le = sv[ce][a].va;       if (sv[ce][a].co == 0)         rq = 1;       else         bq = 1;       dfs2(ne, ce, rq, bq, le), sq++;     }     q++;     cu = 0, build(1, 0, q * 2);     cu = 1, build(1, 0, q * 2);     for (int a = 0; a < sq; a++) {       for (int b = 0; b < pa[a].size(); b++) {         int le = pa[a][b].first, rq = pa[a][b].second.first,             bq = pa[a][b].second.second;         cu = 0, lg = 0, rg = -(bq - rq * 2) + q;         int qq;         pair<int, int> ans = que(1, 0, q * 2);         qq = ans.second, anch = (1ll * anch * ans.first) % mod;         cu = 1, lg = 0, rg = -(bq * 2 - rq) - 1 + q;         ans = que(1, 0, q * 2);         qq -= ans.second, anzn = (1ll * anzn * ans.first) % mod;         anch = (1ll * anch * pow(le, qq)) % mod;       }       for (int b = 0; b < pa[a].size(); b++) {         int le = pa[a][b].first, rq = pa[a][b].second.first,             bq = pa[a][b].second.second;         cu = 0, lg = (bq - rq * 2) + q, add = le;         cha(1, 0, q * 2);         cu = 1, lg = (bq * 2 - rq) + q, add = le;         cha(1, 0, q * 2);       }       pa[a].clear();     }     while (sv[ce].size() > 0) {       int ne = sv[ce].back().to;       for (int b = 0; b < sv[ne].size(); b++)         if (sv[ne][b].to == ce) sv[ne].erase(sv[ne].begin() + b);       sv[ce].pop_back();       dfs(ne, si[ne]);     }   }   int main() {     cin >> n;     for (int a = 0; a < n - 1; a++) {       int u, v, va, co;       scanf( %d%d%d%d , &u, &v, &va, &co);       u--, v--;       nel.to = v, nel.va = va, nel.co = co;       sv[u].push_back(nel);       nel.to = u, sv[v].push_back(nel);     }     dfs(0, n);     int ans = (1ll * anch * pow(anzn, mod - 2)) % mod;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N], n, i, k, j, c, p, b[N], m, r, t, check, mr;   struct tree {     int data = 0;     int rank = 1;   } * ROOT[N], *f[N];   vector<int> leafs;   void push(tree*& node, int number) {     tree* child = new tree();     child->data = number;     child->rank = node->rank + 1;     f[number] = child;     if (leafs.size()) {       for (int it = leafs.size() - 1; it >= 0; it--) {         if (leafs[it] == node->data) {           leafs.erase(leafs.begin() + it);           break;         }       }     }     leafs.push_back(number);     c = max(c, child->rank);   };   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       if (a[i] > m) {         j++;         ROOT[j] = new tree();         ROOT[j]->data = a[i];         m = a[i];         if (leafs.size()) leafs.clear();         continue;       }       if (a[i] > a[i - 1]) {         if (!leafs.size()) {           push(ROOT[j], a[i]);           continue;         } else {           r = 0;           mr = 0;           check = 0;           for (int it = leafs.size() - 1; it >= 0; it--) {             if (f[leafs[it]]->rank < r) leafs.erase(leafs.begin() + it);             if (mr <= f[leafs[it]]->rank) {               if (leafs[it] < a[i]) {                 if (f[leafs[it]]->rank > r) {                   r = f[leafs[it]]->rank;                   t = leafs[it];                   check = 1;                 }               }             }             mr = max(mr, f[leafs[it]]->rank);           }           if (check)             push(f[t], a[i]);           else             push(ROOT[j], a[i]);         }       } else {         c = max(c, 1);       }     }     if (c)       cout << c;     else       cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long OO = (long long)1e15;   const double EPS = 1e-11;   vector<vector<pair<long long, int> > > adj;   vector<vector<long long> > ar;   vector<vector<long long> > dep;   long long nxt(int node, long long time) {     int idx =         lower_bound(ar[node].begin(), ar[node].end(), time) - ar[node].begin();     if (idx >= (int)ar[node].size() || ar[node][idx] != time) return 0;     return dep[node][idx] - time;   }   long long dij(int src, int d, int len) {     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     long long cst = nxt(src, 0);     q.push(make_pair((cst), (src)));     vector<long long> dest(len, OO);     dest[src] = q.top().first;     while (!q.empty()) {       int n = q.top().second;       long long c = q.top().first;       q.pop();       if (c != dest[n]) continue;       if (n == d) return c;       for (int i = 0; i < (int)adj[n].size(); ++i) {         int tn = adj[n][i].second;         long long tc = adj[n][i].first;         long long nc = c + tc + ((tn == d) ? 0 : nxt(tn, c + tc));         if (nc < dest[tn]) {           dest[tn] = nc;           q.push(make_pair((dest[tn]), (tn)));         }       }     }     return -1;   }   int main() {     int n, m, a, b, k;     cin >> n >> m;     adj.clear();     adj.resize(n);     long long c;     for (int i = 0; i < m; ++i) {       cin >> a >> b >> c;       a--, b--;       adj[a].push_back(make_pair((c), (b)));       swap(a, b);       adj[a].push_back(make_pair((c), (b)));     }     ar.clear();     dep.clear();     ar.resize(n);     dep.resize(n);     for (int i = 0; i < n; ++i) {       cin >> k;       if (k == 0) continue;       ar[i].resize(k);       dep[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> ar[i][j];       }       dep[i][k - 1] = ar[i][k - 1] + 1;       for (int j = k - 2; j >= 0; --j) {         if (ar[i][j] + 1 != ar[i][j + 1])           dep[i][j] = ar[i][j] + 1;         else           dep[i][j] = dep[i][j + 1];       }     }     cout << dij(0, n - 1, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   const long long N = 1e6 + 7;   long long a[N];   long long n;   long long res = 0;   long long par[N];   long long sz[N];   long long findpar(long long v) {     if (par[v] == v) return v;     return par[v] = findpar(par[v]);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       par[i] = i;       sz[i] = 1;     }     vector<pair<long long, pair<long long, long long> > > vec;     for (long long i = 1; i < n; i++) {       long long v, u;       cin >> v >> u;       vec.push_back({max(a[v], a[u]), {v, u}});     }     sort(vec.begin(), vec.end());     for (auto pr : vec) {       long long x = pr.first;       long long v = findpar(pr.second.first);       long long u = findpar(pr.second.second);       res += sz[v] * sz[u] * x;       par[v] = u;       sz[u] += sz[v];     }     for (long long i = 0; i < vec.size(); i++)       vec[i].first = -1 * (min(a[vec[i].second.first], a[vec[i].second.second]));     sort(vec.begin(), vec.end());     for (long long i = 1; i <= n; i++) {       par[i] = i;       sz[i] = 1;     }     for (auto pr : vec) {       long long x = pr.first;       long long v = findpar(pr.second.first);       long long u = findpar(pr.second.second);       res += sz[v] * sz[u] * x;       par[v] = u;       sz[u] += sz[v];     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int mod = 1e9 + 7;   const int inf = 1 << 30;   const int maxn = 505;   int n, m, k;   int cuantas[maxn], tomar[maxn][maxn], dp[maxn][maxn];   vector<int> pos[maxn];   int solve(int i, int f) {     if (f > k) return inf;     if (i > n) return 0;     int& res = dp[i][f];     if (res != -1) return res;     res = inf;     for (int j = 0; j <= cuantas[i]; j++) {       int faltar = cuantas[i] - j;       if (f + faltar <= k) {         res = min(res, solve(i + 1, f + faltar) + tomar[i][j]);       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  0 ) continue;         pos[i].push_back(j);       }       cuantas[i] = (int)pos[i].size();     }     for (int i = 1; i <= n; i++) {       for (int tam = 1; tam <= cuantas[i]; tam++) {         tomar[i][tam] = inf;         for (int j = 0; j < cuantas[i]; j++) {           if (j + tam - 1 >= cuantas[i]) break;           tomar[i][tam] = min(tomar[i][tam], pos[i][j + tam - 1] - pos[i][j] + 1);         }       }     }     memset(dp, -1, sizeof(dp));     cout << solve(1, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, j, k, l, n;     cout.precision(10);     {       cin >> n >> k;       if (n <= k / 2)         cout <<  YES               <<   n ;       else {         cout <<  NO               <<   n ;         return 0;       }       for (i = 0; i < n - 1; i++) {         cout <<  1  ;       }       cout << k - (n - 1) <<   n ;       cout << k / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long n, a = 1, b = 1, mod = 1000000007, pp = 1000000005;   unsigned long long fp(unsigned long long n, unsigned long long p) {     if (p == 0) return 1;     if (p == 1) return n;     unsigned long long res;     res = fp(n, p / 2) % mod;     res = (res * res) % mod;     if (p % 2) res = (res * n) % mod;     return res % mod;   }   long long solve(long long n, long long m) {     unsigned long long a = 1, b = 1, res;     for (int i = 1; i <= m; i++) {       a *= n;       a %= mod;       n--;       b *= i;       b %= mod;     }     res = (a * fp(b, pp) % mod) % mod;     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     ios_base::sync_with_stdio(0);     ;     cin >> n;     unsigned long long ans = solve(2 * n, n);     cout << (ans % mod - n) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isrange(int second, int first, int n, int m) {     if (0 <= second && second < n && 0 <= first && first < m) return true;     return false;   }   int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},       ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};   const int MAX = 101010;   long long int a[6], arr[MAX];   vector<pair<long long int, int> > v;   vector<int> tmp;   int num[MAX], start = 1;   long long int seg[MAX * 4];   multiset<long long int> s[MAX];   long long int getn(int l, int r) {     l += start;     r += start;     long long int ans = 0;     while (l <= r) {       if (l % 2) {         ans = max(ans, seg[l]);         l++;       }       if ((r % 2) == 0) {         ans = max(ans, seg[r]);         r--;       }       l /= 2;       r /= 2;     }     return ans;   }   void upd(int first, long long int second) {     first += start;     seg[first] = second;     for (int e = (first / 2); e >= 1; e /= 2)       seg[e] = max(seg[e * 2], seg[e * 2 + 1]);   }   void del(int first) {     long long int second = *s[first].begin();     s[first].erase(s[first].lower_bound(second));     second = *s[first].begin();     upd(first, second);   }   int main(void) {     while (start < MAX) start *= 2;     for (int e = 0; e < 6; e++) scanf( %lld , &a[e]);     int n;     scanf( %d , &n);     for (int e = 0; e < n; e++) {       long long int r;       scanf( %lld , &r);       for (int p = 0; p < 6; p++) {         v.push_back(make_pair(r - a[p], e));         s[e].insert(r - a[p]);       }     }     if (n == 1) return !printf( 0 );     for (int e = 0; e < n; e++) {       long long int first = *s[e].begin();       upd(e, first);     }     sort(v.begin(), v.end());     memset(num, 0, sizeof(num));     long long int ans = 1e18, lx = 0;     for (int e = 0; e < (int)v.size(); e++) {       if (lx != v[e].first) {         bool suc = false;         for (int p = 0; p < (int)tmp.size(); p++) {           num[tmp[p]]++;           if (num[tmp[p]] == 6) {             suc = true;             break;           }           del(tmp[p]);         }         if (suc) break;         tmp.clear();       }       long long int vv = 0;       if (0 <= v[e].second - 1) vv = max(vv, getn(0, v[e].second - 1));       if (v[e].second + 1 < n) vv = max(vv, getn(v[e].second + 1, n - 1));       ans = min(ans, vv - v[e].first);       tmp.push_back(v[e].second);       lx = v[e].first;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int len = 0, x, pre;     long long ans = 0LL;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (i != 0) {         if (pre == x) {           len++;         } else {           ans += 1LL * (len + 1) * len / 2;           len = 1;         }       } else         len = 1;       pre = x;     }     ans += 1LL * (len + 1) * len / 2;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dfs(int u, int p[], bool mark[]) {     mark[u] = true;     if (mark[p[u]]) return;     dfs(p[u], p, mark);   }   int main() {     int result = 0, cycle = 0;     int n;     cin >> n;     int p[n + 1], b[n + 1], f = 0;     bool mark[n + 1];     for (int i = 1; i <= n; i++) {       cin >> p[i];       mark[i] = false;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       f += b[i];     }     if (f % 2 == 0) result++;     for (int i = 1; i <= n; i++) {       if (!mark[i]) {         dfs(i, p, mark);         cycle++;       }     }     if (cycle > 1) result += cycle;     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-15;   const long double pi = acos(-1);   const long long oo = 1 << 30;   const long long loo = 1ll << 62;   const long long mods = 1e9 + 7;   const long long MAXN = 100005;   const long long INF = 0x7fffffff;   inline long long read() {     long long f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   double mx[MAXN], mn[MAXN], smx[MAXN], smn[MAXN], sp[MAXN], sq[MAXN];   signed main() {     long long n = read();     for (long long i = 1; i <= n; i++) scanf( %lf , &mx[i]);     for (long long i = 1; i <= n; i++) scanf( %lf , &mn[i]);     for (long long i = 1; i <= n; i++) smx[i] = smx[i - 1] + mx[i];     for (long long i = n; i >= 1; i--) smn[i] = smn[i + 1] + mn[i];     for (long long i = 1; i <= n; i++) {       double pl = 1 + smx[i] - smn[i + 1], mul = smx[i],              mi = sqrt(pl * pl - mul * 4 + eps);       sp[i] = (pl + mi) * 0.5, sq[i] = (pl - mi) * 0.5;     }     for (long long i = 1; i <= n; i++) printf( %.10lf  , sp[i] - sp[i - 1]);     puts(  );     for (long long i = 1; i <= n; i++) printf( %.10lf  , sq[i] - sq[i - 1]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first > b.first;   }   int main() {     string s;     int n, m;     cin >> n >> m;     cin >> s;     char ara[m + 1], ara1[m + 1];     for (int i = 0; i < m; i++) {       char x, y;       cin >> x >> y;       ara[i] = x;       ara1[i] = y;     }     char str[27], str1[27];     int j = 0;     for (char ch =  a ; ch <=  z ; ch++) {       char ch1;       ch1 = ch;       int f = 0;       for (int i = 0; i < m; i++) {         if (ara[i] == ch1) {           str[j] = ara1[i];           ch1 = ara1[i];           f = 1;         } else if (ara1[i] == ch1) {           str[j] = ara[i];           ch1 = ara[i];           f = 1;         }       }       if (f == 1) {         str1[j] = ch;         j++;       }       f = 0;     }     str[j] =   0 ;     str1[j] =   0 ;     string st = (string)str;     string st1 = (string)str1;     int l1 = st1.size();     for (int j = 0; j < n; j++) {       for (int i = 0; i < l1; i++) {         if (s[j] == st1[i]) {           s[j] = st[i];           break;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int x[100000], y[100000], xx[100000], yy[100000];   int ord[100000];   vector<int> inds;   inline bool cmpx(const int &lhs, const int &rhs) { return x[lhs] < x[rhs]; }   inline bool cmpy(const int &lhs, const int &rhs) { return y[lhs] < y[rhs]; }   vector<int> xs, ys;   void sortUnique(vector<int> &inds) {     sort(inds.begin(), inds.end());     inds.erase(unique(inds.begin(), inds.end()), inds.end());   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < (int)(n); ++i)       scanf( %d%d%d%d , x + i, y + i, xx + i, yy + i), x[i] += xx[i],           y[i] += yy[i];     for (int i = 0; i < (int)(n); ++i) ord[i] = i;     sort(ord, ord + n, cmpx);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[i]);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[n - 1 - i]);     for (int i = 0; i < (int)(n); ++i) ord[i] = i;     sort(ord, ord + n, cmpy);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[i]);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[n - 1 - i]);     sortUnique(inds);     for (int ind : inds) xs.push_back(x[ind]), ys.push_back(y[ind]);     sortUnique(xs);     sortUnique(ys);     int xsz = (int)xs.size();     int ysz = (int)ys.size();     long long ans = 2e18;     for (int i = 0; i < (int)(xsz); ++i)       for (int j = i; j < xsz; ++j) {         int cnt = j - i + 1;         if (xsz - cnt > k) continue;         int xbeg = xs[i], xed = xs[j];         for (int ii = 0; ii < (int)(ysz); ++ii)           for (int jj = ii; jj < ysz; ++jj) {             cnt = jj - ii + 1;             if (ysz - cnt > k) continue;             int ybeg = ys[ii], yed = ys[jj];             int bad = 0;             for (int ind : inds)               if (x[ind] < xbeg || x[ind] > xed || y[ind] < ybeg ||                   y[ind] > yed) {                 ++bad;               }             if (bad <= k) {               long long dx = ((long long)xed - xbeg + 1) / 2;               long long dy = ((long long)yed - ybeg + 1) / 2;               if (dx <= 0) dx = 1;               if (dy <= 0) dy = 1;               ans = min(ans, (long long)dx * dy);             }           }       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     int n, k;     cin >> n >> k;     cout << k * (6 * (n - 1) + 5) << endl;     for (int i = 1; i <= n; i++) {       printf( %d %d %d %d n , k * (6 * (i - 1) + 1), k * (6 * (i - 1) + 2),              k * (6 * (i - 1) + 3), k * (6 * (i - 1) + 5));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long MOD = 1e9 + 7;   const int MAXN = 705;   const int bignumlen = 17;   const int Blen = 8;   const long long base = 100000000;   struct bignum {     int len;     long long data[bignumlen];     long long &operator[](int x) { return (data[x]); }     const long long &operator[](int x) const { return (data[x]); }     bignum() {       memset(data, 0, sizeof(data));       len = 0;     }     void clear() {       for (int i = len; i >= 1; --i) data[i] = 0;       len = 0;     }     int check(const bignum &a, const bignum &b) {       if (a.len > b.len) return (0);       if (b.len > a.len) return (1);       for (int i = a.len; i >= 1; --i) {         if (a.data[i] < b.data[i]) return (1);         if (b.data[i] < a.data[i]) return (0);       }       return 2;     }     bool operator<(const bignum &b) { return (check(*this, b) == 1); }     bool operator>(const bignum &b) { return (check(*this, b) == 0); }     bool operator<=(const bignum &b) { return (check(*this, b) >= 1); }     bool operator>=(const bignum &b) { return (check(*this, b) % 2 == 0); }     bool operator!=(const bignum &b) { return (check(*this, b) != 2); }     bool operator==(const bignum &b) { return (check(*this, b) == 2); }     bignum operator=(const bignum &x) {       for (int i = x.len + 1; i <= len; ++i) data[i] = 0;       for (int i = 1; i <= x.len; ++i) data[i] = x.data[i];       len = x.len;       return *this;     }     bignum operator=(long long x) {       for (int i = len; i >= 0; --i) data[i] = 0;       len = 0;       while (x) {         data[++len] = x % base;         x /= base;       }       return *this;     }     bignum(long long x) {       memset(data, 0, sizeof(data));       len = 0;       (*this) = x;     }     bignum operator*(const bignum &b) {       int i, j;       bignum tmp;       for (i = 1; i <= len; ++i)         if (data[i] != 0)           for (j = 1; j <= b.len; ++j)             if (b.data[j] != 0) {               tmp.data[i + j - 1] += data[i] * b.data[j];               tmp.data[i + j] += tmp.data[i + j - 1] / base;               tmp.data[i + j - 1] %= base;             }       tmp.len = len + b.len - 1;       while (tmp.data[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator*(long long x) {       int i;       bignum tmp;       for (i = 1; i <= len; ++i) tmp[i] = data[i] * x;       tmp.len = len;       for (i = 1; i <= len; ++i) {         tmp[i + 1] += tmp[i] / base, tmp[i] %= base;         if (tmp[i + 1] && i + 1 > tmp.len) tmp.len++;       }       return tmp;     }     bignum operator/(long long x) {       int i;       bignum tmp;       long long y = 0;       for (i = len; i >= 1; --i) {         y = y * base + data[i];         tmp[i] = y / x;         y %= x;       }       tmp.len = len;       while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;       return tmp;     }     bignum operator/(const bignum &b) {       if (b.len <= 1 && b[1] == 0) {         printf( error! ?0?! );         for (;;)           ;       }       int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;       long long x = data[len], y = b[b.len];       while (x) x /= 10, l1++;       while (y) y /= 10, l2++;       bignum tmp, chu, B;       chu = *this;       B = b;       for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;       for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;       for (i = l1 - l2; i >= 0; --i) {         x = 0;         while (chu >= B) chu -= B, x++;         tmp[i / Blen + 1] = tmp[i / Blen + 1] * 10 + x;         B /= 10;       }       tmp.len = (l1 - l2) / Blen + 1;       while (tmp.len >= 1 && !tmp[tmp.len]) tmp.len--;       return tmp;     }     bignum operator+(const bignum &b) {       bignum tmp;       int i, l = max(len, b.len);       for (i = 1; i <= l; ++i) tmp[i] = data[i] + b[i];       for (i = 1; i <= l; ++i) tmp[i + 1] += tmp[i] / base, tmp[i] %= base;       tmp.len = l;       if (tmp[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator+(long long x) {       bignum tmp;       tmp = *this;       tmp[1] += x;       for (int i = 1; i <= len && tmp[i] >= base; ++i)         tmp[i + 1] += tmp[i] / base, tmp[i] %= base;       while (tmp[tmp.len + 1]) tmp.len++;       return tmp;     }     bignum operator-(const bignum &b) {       int i;       bignum tmp;       for (i = 1; i <= len; ++i) tmp.data[i] = data[i] - b.data[i];       for (i = 1; i <= len; ++i) {         if (tmp[i] < 0) tmp.data[i] += base, tmp.data[i + 1]--;       }       tmp.len = len;       while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;       return tmp;     }     bignum operator-(long long x) {       bignum tmp;       tmp = *this;       tmp[1] -= x;       for (int i = 1; i <= len && tmp[i] < 0; ++i) {         tmp[i + 1] += (tmp[i] + 1) / base - 1;         tmp[i] = (tmp[i] + 1) % base + base - 1;       }       while (!tmp[tmp.len] && tmp.len > 1) tmp.len--;       return tmp;     }     long long operator%(long long x) {       int i;       long long y = 0;       for (i = len; i >= 1; --i) y = (y * base + data[i]) % x;       return y;     }     bignum operator%(const bignum &b) {       if (b.len <= 1 && b[1] == 0) {         printf( error! ?0 mod! );         for (;;)           ;       }       int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;       long long x = data[len], y = b[b.len];       while (x) x /= 10, l1++;       while (y) y /= 10, l2++;       bignum chu, B;       chu = *this;       B = b;       for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;       for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;       for (i = l1 - l2; i >= 0; --i) {         while (chu >= B) chu -= B;         B /= 10;       }       return chu;     }     bignum operator+=(const bignum &b) { return *this = (*this + b); }     bignum operator*=(const bignum &b) { return *this = (*this * b); }     bignum operator-=(const bignum &b) { return *this = (*this - b); }     bignum operator/=(const bignum &b) { return *this = (*this / b); }     bignum operator%=(const bignum &b) { return *this = (*this % b); }     bignum operator*=(long long x) { return (*this = (*this * x)); }     bignum operator+=(long long x) { return (*this = (*this + x)); }     bignum operator-=(long long x) { return (*this = (*this - x)); }     bignum operator/=(long long x) { return (*this = (*this / x)); }     void read() {       char c[bignumlen * Blen + 10];       scanf( %s , c + 1);       int l = strlen(c + 1);       (*this).clear();       long long x;       for (int i = 1; i <= (l - 1) / Blen + 1; ++i) {         x = 0;         for (int j = l - Blen * i + 1; j <= l - Blen * i + Blen; ++j)           if (j >= 1) x = x * 10 + c[j] - 48;         data[++len] = x;       }     }     void write() {       printf( %I64d , data[len]);       for (int i = len - 1; i >= 1; --i) printf( %0*I64d , Blen, data[i]);     }   };   int n;   vector<bignum> DP[MAXN];   vector<int> v[MAXN];   int sz[MAXN];   int dfs(int now, int p) {     DP[now].push_back(0);     DP[now].push_back(1);     sz[now] = 1;     for (int ea = 0; ea < v[now].size(); ea++) {       int sek = v[now][ea];       if (sek == p) continue;       sz[now] += dfs(sek, now);       vector<bignum> ans(MAXN);       for (int j = 0; j < MAXN; j++) ans[j] = -1;       for (int i = 1; i <= DP[now].size() - 1; i++) {         for (int j = 1; j <= DP[sek].size() - 1; j++) {           bignum tmp = DP[now][i] / i * DP[sek][j] / j * (i + j);           if (tmp > ans[i + j]) ans[i + j] = tmp;           tmp = DP[now][i] * DP[sek][j];           if (tmp > ans[i]) ans[i] = tmp;         }       }       ans[0] = 0;       DP[now].clear();       for (int j = 0; j < MAXN; j++) {         if (ans[j] == -1) break;         DP[now].push_back(ans[j]);       }     }     return sz[now];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(0, -1);     bignum res = DP[0][1];     for (int i = 2; i <= DP[0].size() - 1; i++)       if (DP[0][i] > res) res = DP[0][i];     res.write();   }


#include <bits/stdc++.h>   using namespace std;   class fenwickTree {    public:     int* tree;     int size;     int prefixSum(int index) {       index++;       int ret = 0;       while (index > 0) {         ret += tree[index];         index -= (index & -index);       }       return ret;     }     void update(int index, int delta) {       index++;       while (index <= size) {         tree[index] += delta;         index += (index & -index);       }     }     int rangeSum(int left, int right) {       return prefixSum(right) - prefixSum(left - 1);     }     fenwickTree(int n) {       size = n;       tree = new int[size + 1];       memset(tree, 0, sizeof(int) * (size + 1));     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       fenwickTree tree(n + 1);       int cts[n + 1];       memset(cts, 0, sizeof cts);       long long invert = 0;       bool ok = false;       for (int i = 0; i < n; i++) {         int w;         cin >> w;         cts[w]++;         if (cts[w] == 2) ok = true;         tree.update(w, 1);         invert += tree.rangeSum(w + 1, n);       }       if (invert & 1 && !ok)         cout <<  NO n ;       else         cout <<  YES n ;     }   }


#include <bits/stdc++.h>   template <class p, class q>   void umin(p& a, const q& b) {     if (a > b) a = b;   }   template <class p, class q>   void umax(p& a, const q& b) {     if (a < b) a = b;   }   using ll = long long;   using VI = std::vector<int>;   using VLL = std::vector<ll>;   using namespace std;   using namespace std::chrono;   int n;   int const N = 1e5 + 3;   ll const P = 1e9 + 7;   int a[N];   int l[N];   int prime[N];   int phi[N];   int mult[N];   int ppower[N];   ll ans;   void sieve() {     int p = 2;     prime[1] = 0;     phi[1] = 1;     while (p < N) {       ppower[p] = 1;       if (prime[p]) {         int cp = p;         while (cp % prime[p] == 0) {           cp /= prime[p];           mult[p]++;           ppower[p] *= prime[p];         }         phi[p] = (mult[p] >= 2) ? prime[p] * phi[p / prime[p]]                                 : (prime[p] - 1) * phi[p / prime[p]];         p++;         continue;       }       prime[p] = p;       ppower[p] = p;       mult[p] = 1;       phi[p] = p - 1;       for (ll i = 1LL * p * p; i < N; i += p) {         if (!prime[i]) prime[i] = p;       }       p++;     }   }   void write_divisors(int r, VI& output) {     if (r == 1)       output = {1};     else {       VI partial;       write_divisors(r / ppower[r], partial);       int prw = 1;       for (int i = (0); i <= (mult[r]); i++) {         for (const auto& u : partial) {           output.push_back(prw * u);         }         prw *= prime[r];       }     }   }   VI divisors[N];   void uzup() {     for (int i = (1); i <= (N - 1); i++) write_divisors(i, divisors[i]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = (1); i <= (n); i++) cin >> a[i];     sieve();     uzup();     for (int j = (1); j <= (n); j++) {       VI monitor;       for (int k = j; k <= n; k += j) {         for (const auto& u : divisors[a[k]]) {           monitor.push_back(u);           ans = (ans + 1LL * phi[u] * phi[j] * (2 * l[u] + 1)) % P;           l[u]++;         }       }       for (int i = (((int)((monitor).size())) - 1); i >= (0); i--) {         l[monitor[i]]--;         monitor.pop_back();       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   long long qpow(long long a, long long b) {     if (b == -1) return 0;     long long res = 1;     while (b) {       if (b & 1) res = res * a % 998244353;       a = a * a % 998244353;       b >>= 1;     }     return res;   }   long long n;   long long a[1000005], ans;   signed main() {     read(n);     for (long long i = 1; i <= n; ++i) read(a[i]);     for (long long i = 1; i <= n; ++i) {       ans += a[i] * qpow(2, n - i) % 998244353;       ans %= 998244353;       ans += a[i] * qpow(2, n - i - 1) % 998244353 * (n - i) % 998244353;       ans %= 998244353;     }     writeln(ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int input, max = 0, temp1, temp2;     scanf( %d , &input);     for (int i = 1; i <= input; i++) {       if (input % i == 0) {         temp1 = input / i;         temp2 = i;         if (temp1 <= temp2) {           break;         }       }     }     printf( %d %d n , temp1, temp2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxSize = 1 << 16;   map<string, int> t;   int a[maxSize];   vector<string> s;   vector<vector<int> > v;   int main() {     int n, k;     scanf( %d%d , &n, &k);     v.resize(n);     s.resize(n);     for (int i = 0; i < n; i++) {       cin >> s[i];       t[s[i]] = i;     }     for (int i = 0; i < k; i++) {       string s1, s2;       cin >> s1 >> s2;       int x, y;       x = t[s1], y = t[s2];       v[x].push_back(y);       v[y].push_back(x);     }     int res = 0, ans = 0;     for (int i = 0; i < maxSize; i++) {       int cnt = 0;       for (int j = 0; j < n; j++)         if (i & (1 << j)) cnt++;       for (int j = 0; j < n; j++)         if (i & (1 << j))           for (int x = 0; x < v[j].size(); x++)             if (i & (1 << v[j][x])) {               cnt = 0;               break;             }       if (cnt > ans) res = i, ans = cnt;     }     printf( %d n , ans);     set<string> st;     for (int i = 0; i < n; i++)       if (res & (1 << i)) st.insert(s[i]);     for (auto e : st) cout << e << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200500;   int n;   pair<int, int> a[MAXN];   int b[MAXN];   int s[MAXN];   int FindMax(int j) {     int ret = 0;     for (; j >= 0; (j &= (j + 1))--) {       ret = max(ret, s[j]);     }     return ret;   }   void Update(int j, int x) {     for (; j < n; j |= (j + 1)) {       s[j] = max(s[j], x);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a[i].first, &a[i].second);       b[i] = a[i].first + a[i].second;     }     sort(a, a + n);     sort(b, b + n);     int res = 1;     for (int i = 0; i < n; ++i) {       int p = lower_bound(b, b + n, a[i].first - a[i].second + 1) - b - 1;       int curVal = FindMax(p) + 1;       Update(lower_bound(b, b + n, a[i].first + a[i].second) - b, curVal);       res = max(res, curVal);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   int n;   vector<pair<int, int> > v;   long long DP[3001][3001];   long long solve(int idx, int lst) {     if (idx == n) return 0;     long long &ret = DP[idx][lst];     if (ret != -1) return ret;     ret = (1LL << 59);     ret = min(ret, solve(idx + 1, lst) + v[idx].first - v[lst].first);     ret = min(ret, solve(idx + 1, idx) + v[idx].second);     return ret;   }   int main() {     scanf( %d , &n);     int a, b;     for (int i = 0; i < n; ++i) {       scanf( %d %d , &a, &b);       v.push_back(pair<int, int>(a, b));     }     memset(DP, -1, sizeof(DP));     sort(v.begin(), v.end());     cout << solve(1, 0) + 1LL * v[0].second;   }


#include <bits/stdc++.h>   using namespace std;   int row[1010];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     memset(row, 0x3f3f3f3f, sizeof row);     long long ans = 0;     for (int i = (0); i < (n); ++i) {       int r, c;       scanf( %d %d , &r, &c);       row[r] = min(c, row[r]);     }     for (int i = 1; i <= m; ++i) ans += ((row[i] == 0x3f3f3f3f) ? 0 : row[i]);     printf( %lld n , min(ans, (long long)k));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 2e5 + 5;   int dist[N];   vector<int> open[N], close[N];   int n, k;   bool done[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (auto i = 0; i < (long long)(n); i++) {       int l, r;       cin >> l >> r;       open[l].push_back(i);       close[r + 1].push_back(i);       dist[i] = r + 1;     }     set<int> pool;     set<pair<int, int> > dist_idx;     vector<int> res;     for (auto i = 1; i < (long long)(N); i++) {       for (auto j : close[i]) {         if (done[j]) continue;         pool.erase(j);         dist_idx.erase({dist[j], j});       }       for (auto j : open[i]) {         pool.insert(j);         dist_idx.insert({dist[j], j});       }       while (((int)((pool).size())) > k) {         auto it = dist_idx.end();         it--;         int idx = (*it).second;         res.push_back(idx + 1);         dist_idx.erase(it);         pool.erase(idx);         done[idx] = true;       }     }     cout << ((int)((res).size())) <<   n ;     for (auto i : res) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[50][50], n, m;   bool can(int k) {     int total = 0;     for (int i = 0; i < m; i++)       if (a[k][i] != i + 1) total++;     if (total <= 2) return 1;     return 0;   }   bool ok() {     for (int i = 1; i <= n; i++)       if (!can(i)) return 0;     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     if (ok()) {       printf( YES n );       return 0;     }     for (int i = 0; i < m - 1; i++)       for (int j = i + 1; j < m; j++) {         for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);         if (ok()) {           printf( YES n );           return 0;         }         for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);       }     printf( NO n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   ostream& operator<<(std::ostream& os, const std::map<T1, T2>& v) {     os <<  [ ;     for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();          ++ii)       os << ii->first <<  :  << ii->second <<    ;     return os <<  ] ;   }   template <class Cntnr>   ostream& c_out(std::ostream& os, const Cntnr& v) {     os <<  [ ;     for (typename Cntnr::const_iterator ii = v.begin(); ii != v.end(); ++ii)       os << *ii <<    ;     os <<   ] ;     return os;   }   template <typename T>   ostream& operator<<(ostream& o, const vector<T>& c) {     return c_out(o, c);   }   template <typename T>   ostream& operator<<(ostream& o, const list<T>& c) {     return c_out(o, c);   }   template <typename T>   ostream& operator<<(ostream& o, const set<T>& c) {     return c_out(o, c);   }   int main() {     int n, a, b;     scanf( %d , &n);     scanf( %d , &a);     scanf( %d , &b);     for (int i = (0); i < (int)(n); i++) {       long long w;       cin >> w;       cout << w - ((((w * a) / b) * b + a - 1) / a) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int com[] = {1, 4, 6, 8, 9};     long long int t;     cin >> t;     while (t--) {       int64_t k;       cin >> k;       string n;       cin >> n;       map<int, int> m;       for (int i = 0; i < n.size(); i++) {         m[n[i] -  0 ]++;       }       int flag = 1;       for (auto it : m) {         if (it.first == 1 || it.first == 4 || it.first == 6 || it.first == 8 ||             it.first == 9) {           flag = 0;           cout << 1 << endl << it.first << endl;           break;         }       }       if (flag) {         for (auto it : m) {           if (it.second > 1) {             cout << 2 << endl << it.first << it.first << endl;             flag = 0;             break;           }         }         if (n ==  32  || n ==  35 ) {           flag = 0;           cout << 2 << endl << n << endl;         }       }       if (flag) {         stack<int> s;         string temp =   ;         for (int i = 0; i < n.size(); i++) {           if (n[i] !=  3 ) {             temp += n[i];           }           if (temp.size() == 2) {             break;           }         }         cout << 2 << endl << temp << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   double DP[2][2510][2510];   double X[2510], Y[2510];   double dis(int a, int b) {     return sqrt((X[a] - X[b]) * (X[a] - X[b]) + (Y[a] - Y[b]) * (Y[a] - Y[b]));   }   int main() {     ios::sync_with_stdio(false);     memset(DP, 0, sizeof(DP));     int N;     cin >> N;     for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];     for (int i = 2; i <= N; i++) {       for (int s = 0; s < N; s++) {         int e = s + i - 2;         e %= N;         int t;         t = (s - 1 + N) % N;         DP[0][t][e] = max(DP[0][t][e], DP[0][s][e] + dis(s, t));         t = (e + 1) % N;         DP[1][s][t] = max(DP[1][s][t], DP[0][s][e] + dis(s, t));         t = (s - 1 + N) % N;         DP[0][t][e] = max(DP[0][t][e], DP[1][s][e] + dis(e, t));         t = (e + 1) % N;         DP[1][s][t] = max(DP[1][s][t], DP[1][s][e] + dis(e, t));       }     }     double res = 0;     for (int i = 0; i < N; i++) {       int j = (i - 1 + N) % N;       res = max(res, DP[0][i][j]);       res = max(res, DP[1][i][j]);     }     cout.precision(20);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class X, class Y>   void minimize(X &x, const Y &y) {     if (x > y) x = y;   }   template <class X, class Y>   void maximize(X &x, const Y &y) {     if (x < y) x = y;   }   template <class T>   T Abs(const T &x) {     return (x < 0 ? -x : x);   }   const int mod = (int)1e9 + 7;   int cntWay[500500 * 2], sumWay[500500 * 2];   int frac[500500], finv[500500];   int inverse(int x) {     int res = 1;     int mul = x;     int k = mod - 2;     while (k > 0) {       if (k & 1) res = 1LL * res * mul % mod;       mul = 1LL * mul * mul % mod;       k >>= 1;     }     return (res);   }   void precalc(void) {     frac[0] = finv[0] = 1;     for (int i = (1), _b = (500500 - 1); i <= _b; i = i + 1)       frac[i] = 1LL * frac[i - 1] * i % mod;     for (int i = (1), _b = (500500 - 1); i <= _b; i = i + 1)       finv[i] = inverse(frac[i]);   }   int comb(int k, int n) {     if (k > n) return (0);     return (1LL * frac[n] * finv[k] % mod * finv[n - k] % mod);   }   int countWay(int number, int sum, int absLim, int numBig) {     sum -= numBig * absLim;     sum += (number - numBig) * (absLim + 1);     return (comb(number - 1, sum - 1));   }   int countWay(int number, int sum, int absLim) {     int res = 0;     for (int numBig = 0, _n = (number + 1); numBig < _n; numBig = numBig + 1) {       int numSet = comb(numBig, number);       int numWay = countWay(number, sum, absLim, numBig);       if (numBig % 2 == 0)         res = (res + 1LL * numSet * numWay) % mod;       else         res = (res - 1LL * numSet * numWay % mod + mod) % mod;     }     return (res);   }   void process(void) {     int a, b, range, n;     cin >> a >> b >> range >> n;     for (int i = (-range * n), _b = (range * n); i <= _b; i = i + 1)       cntWay[i + 500500] = countWay(n, i, range);     for (int i = (range * n), _a = (-range * n); i >= _a; i = i - 1)       sumWay[i + 500500] = (sumWay[i + 1 + 500500] + cntWay[i + 500500]) % mod;     int res = 0;     for (int i = (-range * n), _b = (range * n); i <= _b; i = i + 1) {       int reqScore = b + i + 1 - a;       if (reqScore > range * n) continue;       maximize(reqScore, -range * n);       int numWayB = cntWay[i + 500500];       int numWayA = sumWay[reqScore + 500500];       res = (res + 1LL * numWayA * numWayB) % mod;     }     printf( %d n , res);   }   int main(void) {     precalc();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x7f7f7f7f7f7f7f7f;   struct sta {     int s;     long long k, val;   } p[105];   int n, m;   long long b, f[(1 << 20) + 5];   bool cmp(sta a, sta b) { return a.k < b.k; }   void init() {     memset(f, -1, sizeof f);     scanf( %d%d , &n, &m);     cin >> b;     int t, a;     for (int i = 0; i < n; i++) {       scanf( %lld%lld%d , &p[i].val, &p[i].k, &t);       p[i].s = 0;       for (int j = 0; j < t; j++) {         scanf( %d , &a);         p[i].s |= (1 << (a - 1));       }     }     sort(p, p + n, cmp);   }   long long solve() {     f[0] = 0;     int t = (1 << m) - 1;     long long ans = inf;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= t; j++) {         if (f[j] == -1) continue;         int u = p[i].s | j;         if (f[u] == -1)           f[u] = p[i].val + f[j];         else           f[u] = min(f[u], p[i].val + f[j]);       }       if (f[t] != -1) ans = min(ans, f[t] + p[i].k * b);     }     return ans == inf ? -1 : ans;   }   int main() {     init();     long long res = solve();     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       cout << a + b + c - 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool bo[1005][1005];   double ans[1005][1005];   double f(int n, int m) {     if (m == 0) return 1;     if (bo[n][m]) return ans[n][m];     if (n == 0) {       return 1.0 / (m + 1);     }     double a = 1.0, b = 1 - f(m, n - 1);     double c = 1.0 * m / (m + 1) * (1 - f(m - 1, n)), d = 1.0 / (m + 1) + c;     double p = (d - c) / (a - c + d - b);     bo[n][m] = true;     return ans[n][m] = p * a + (1 - p) * c;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     double x = f(n, m);     printf( %.10f %.10f , x, 1 - x);   }


#include <bits/stdc++.h>   using namespace std;   long long n, w, a[1123], d, mx, mn;   int main() {     cin >> n >> w;     for (int i = 0; i < n; ++i) {       cin >> a[i];       d += a[i];       mx = max(d, mx);       mn = min(d, mn);     }     cout << max(w + 1 - mx + mn, 0ll);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 * 2 + 10;   int n, len, h;   struct node {     int flag, mx, l, r;   } t[MAXN << 2];   int a[MAXN], b[MAXN];   int L[MAXN];   void push_down(int k) {     if (t[k].flag) {       t[k << 1].flag += t[k].flag;       t[k << 1 | 1].flag += t[k].flag;       t[k << 1].mx += t[k].flag;       t[k << 1 | 1].mx += t[k].flag;       t[k].flag = 0;     }   }   void push_up(int k) { t[k].mx = min(t[k << 1].mx, t[k << 1 | 1].mx); }   void build(int l, int r, int k) {     t[k].l = l;     t[k].r = r;     t[k].flag = 0;     if (t[k].l == t[k].r) {       t[k].mx = -t[k].l;       return;     }     int mid = t[k].l + t[k].r >> 1;     build(l, mid, k << 1);     build(mid + 1, r, k << 1 | 1);     push_up(k);   }   void update(int l, int r, int val, int k) {     if (l <= t[k].l && t[k].r <= r) {       t[k].mx += val;       t[k].flag += val;       return;     }     push_down(k);     int mid = t[k].l + t[k].r >> 1;     if (l <= mid) update(l, r, val, k << 1);     if (r > mid) update(l, r, val, k << 1 | 1);     push_up(k);   }   int main() {     scanf( %d%d%d , &n, &len, &h);     for (int i = 1; i <= len; i++) scanf( %d , b + i);     sort(b + 1, b + len + 1);     build(1, len, 1);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       int ll = 1, rr = len, ans = -1;       while (ll <= rr) {         int mid = ll + rr >> 1;         if (b[mid] + a[i] >= h) {           ans = mid;           rr = mid - 1;         } else           ll = mid + 1;       }       L[i] = ans;     }     int res = 0;     for (int i = 1; i <= n; i++) {       if (L[i] != -1) update(L[i], len, 1, 1);       if (i >= len) {         if (t[1].mx >= 0) res++;         if (L[i - len + 1] != -1) update(L[i - len + 1], len, -1, 1);       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[1000000 + 1];   const int mod = 1e9 + 7;   vector<int> v;   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int mx = a[n - 1];     deque<int> dq;     int i = n - 1;     for (i = n - 1; i >= 0; i--) {       if (a[i] == mx) {         dq.push_back(a[i]);       } else         break;     }     bool turn = true;     for (i; i >= 0; i--) {       if (turn == true) {         dq.push_back(a[i]);         turn = false;       } else {         dq.push_front(a[i]);         turn = true;       }     }     for (auto i : dq) cout << i <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 1e5 + 7;   const double eps = 0.00000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   int cnt[6];   int a[6], b[6];   int i, j, k;   int sum;   int num(int m, int n) {     if (m * 2 > n) return 1;     if (m * 4 > n) return 2;     if (m * 8 > n) return 3;     if (m * 16 > n) return 4;     if (m * 32 > n) return 5;     return 6;   }   int n, m;   bool judge(int x) {     int sum = 0, i;     for (i = 1; i <= 5; i++) {       if (a[i] == 0 || a[i] > b[i])         sum += num(cnt[i], n + x) * (a[i] - b[i]);       else         sum += num(cnt[i] + x, n + x) * (a[i] - b[i]);     }     return sum > 0;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= 5; i++) {       scanf( %d , &k);       if (k != -1)         cnt[i]++, a[i] = 250 - k;       else         a[i] = 0;     }     for (i = 1; i <= 5; i++) {       scanf( %d , &k);       if (k != -1)         cnt[i]++, b[i] = 250 - k;       else         b[i] = 0;     }     for (j = 0; j < n - 2; j++)       for (i = 1; i <= 5; i++) {         scanf( %d , &k);         if (k != -1) cnt[i]++;       }     for (i = 0; i <= 10000; i++)       if (judge(i)) {         printf( %d , i);         return 0;       }     puts( -1 );   }