#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, INF = 1e9 + 7;   int n, a[N];   bool used[N];   int main() {     int q;     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n * 2; i++) {         cin >> a[i];         used[i] = 0;       }       vector<pair<int, int> > vec;       for (int i = 1; i <= n * 2; i++) {         if (used[i]) continue;         for (int j = i + 1; j <= n * 2; j++) {           if ((a[i] + a[j]) % 2 == 0) {             used[j] = 1;             used[i] = 1;             vec.push_back({i, j});             break;           }         }       }       bool cond = 1;       for (int i = 1; i <= n * 2; i++) {         if (!used[i]) {           cond = 0;         }       }       for (int i = 0; i < vec.size() - cond; i++) {         cout << vec[i].first <<     << vec[i].second << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q, m;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     cin >> q;     while (q--) {       cin >> m;       cout << upper_bound(a, a + n, m) - a << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int a, b;   int k;   int main() {     cin >> a >> b;     if (b > a) {       cout <<  -1 n ;       return 0;     }     if (a == b) {       cout << a << endl;       return 0;     }     k = a / b;     if (k & 1) k++;     double ans = (a + b) * 1.0 / k;     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cas = 1, T;   int n, a[10010], b[10010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     int l = 1, r = (n + 1) / 2 + 1;     for (int i = 1; i <= n; i++) {       if (i % 2 == 1)         printf( %d  , a[l++]);       else         printf( %d  , a[r++]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }   int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }   int mul(int a, int b) { return 1ll * a * b % Mod; }   void Add(int &a, int b) { a = add(a, b); }   void Dec(int &a, int b) { a = dec(a, b); }   void Mul(int &a, int b) { a = mul(a, b); }   const int N = 1e5 + 50;   int n, a[N], pr[N], sf[N];   map<int, int> bin;   struct lll {     int a, b, c, bc, ac;   };   lll operator+(const lll &x, const lll &y) {     return (lll){add(x.a, y.a), add(x.b, y.b), add(x.c, y.c), add(x.bc, y.bc),                  add(x.ac, y.ac)};   }   namespace SGT {   const int N = ::N << 2;   lll t[N];   int tb[N];   int tc[N];   int tbc[N];   int len[N];   void up(int x) { t[x] = t[x << 1] + t[x << 1 | 1]; }   void build(int x, int l, int r) {     len[x] = r - l + 1;     if (l == r) return t[x].a = l - 1, void();     build(x << 1, l, ((l + r) >> 1));     build(x << 1 | 1, ((l + r) >> 1) + 1, r);     up(x);   }   void B(int x, int v) {     Add(tb[x], v);     Add(t[x].b, mul(len[x], v));     Add(t[x].bc, mul(v, t[x].c));     Add(tbc[x], mul(v, tc[x]));   }   void C(int x, int v) {     Add(tc[x], v);     Add(t[x].c, mul(len[x], v));     Add(t[x].bc, mul(v, t[x].b));     Add(tbc[x], mul(v, tb[x]));     Add(t[x].ac, mul(v, t[x].a));   }   void BC(int x, int v) {     Add(t[x].bc, v);     Add(tbc[x], v);   }   void down(int x) {     if (tb[x]) B(x << 1, tb[x]), B(x << 1 | 1, tb[x]), tb[x] = 0;     if (tc[x]) C(x << 1, tc[x]), C(x << 1 | 1, tc[x]), tc[x] = 0;     if (tbc[x]) BC(x << 1, tbc[x]), BC(x << 1 | 1, tbc[x]), tbc[x] = 0;   }   void mdfb(int x, int l, int r, int L, int R, int v) {     if (L <= l && r <= R) return B(x, v);     down(x);     if (L <= ((l + r) >> 1)) mdfb(x << 1, l, ((l + r) >> 1), L, R, v);     if (R > ((l + r) >> 1)) mdfb(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, v);     up(x);   }   void mdfc(int x, int l, int r, int L, int R, int v) {     if (L <= l && r <= R) return C(x, v);     down(x);     if (L <= ((l + r) >> 1)) mdfc(x << 1, l, ((l + r) >> 1), L, R, v);     if (R > ((l + r) >> 1)) mdfc(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R, v);     up(x);   }   lll ask(int x, int l, int r, int L, int R) {     if (L > R) return (lll){0};     if (L <= l && r <= R) return t[x];     down(x);     if (R <= ((l + r) >> 1)) return ask(x << 1, l, ((l + r) >> 1), L, R);     if (L > ((l + r) >> 1)) return ask(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R);     return ask(x << 1, l, ((l + r) >> 1), L, R) +            ask(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R);   }   }  // namespace SGT   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       pr[i] = bin[a[i]];       bin[a[i]] = i;     }     bin.clear();     for (int i = n; i; i--) {       sf[i] = bin[a[i]];       bin[a[i]] = i;       if (!sf[i]) sf[i] = n + 1;     }     SGT ::build(1, 1, n);     static int s1[N], s2[N];     int t1 = 0, t2 = 0, mx = 0, ans = 0;     for (int i = 1; i <= n; i++) {       mx = max(mx, pr[i]);       while (t1 && pr[s1[t1]] <= pr[i]) {         int h = dec(pr[i], pr[s1[t1]]);         SGT ::mdfb(1, 1, n, s1[t1 - 1] + 1, s1[t1], h);         --t1;       }       while (t2 && sf[s2[t2]] >= sf[i]) {         int h = dec(sf[i], sf[s2[t2]]);         SGT ::mdfc(1, 1, n, s2[t2 - 1] + 1, s2[t2], h);         --t2;       }       s1[++t1] = i, s2[++t2] = i;       SGT ::mdfb(1, 1, n, i, i, pr[i]);       SGT ::mdfc(1, 1, n, i, i, sf[i]);       lll z = SGT ::ask(1, 1, n, mx + 1, i);       Dec(ans, z.bc);       Dec(ans, mul(i + 1, z.a));       Add(ans, mul(i + 1, z.b));       Add(ans, z.ac);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void showvec(vector<long long> &arr);   inline void solve() {     long long n;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<long long> arr(200005);     long long t = 1;     cin >> t;     while (t--) {       long long n;       cin >> n;       fill(arr.begin(), arr.end(), -1);       long long ans = INT_MAX;       for (long long i = 0; i < n; i++) {         long long ele;         cin >> ele;         if (arr[ele] != -1) {           ans = min(ans, i - arr[ele] + 1);         }         arr[ele] = i;       }       cout << (ans == INT_MAX ? -1 : ans);       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long int i, l, n, m, t;     cin >> n >> m;     long int a[m + 1];     for (i = 0; i < m; i++) cin >> a[i];     sort(a, a + m);     bool flag = true;     if (a[0] == 1) flag = false;     if (a[m - 1] == n) flag = false;     for (i = 0; i < m - 2; i++)       if (a[i] == a[i + 1] - 1 && a[i + 1] + 1 == a[i + 2]) flag = false;     if (!flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct my {     int num;     int dmg;   } dmg[10010];   int mx, reg, rg[10010], n;   int flag[10010];   vector<pair<int, int> > v;   bool operator<(my a, my b) {     if (a.dmg > b.dmg) return 1;     return 0;   }   int main() {     cin >> n >> mx >> reg;     for (int i = 0; i < n; i++) {       cin >> rg[i] >> dmg[i].dmg;       dmg[i].num = i;     }     int time = 0, inds, kols = 0, fl = 0;     int total_dmg = 0, cur = mx;     sort(dmg, dmg + n);     while (1) {       cur += (reg - total_dmg);       if (cur > mx) cur = mx;       if (cur <= 0) {         cout <<  YES n ;         cout << time <<     << kols <<   n ;         for (int i = 0; i < (int)v.size(); i++)           cout << v[i].first <<     << v[i].second <<   n ;         return 0;       }       inds = -1;       for (int i = 0; i < n; i++) {         if (!flag[i]) {           if (cur * 100 <= rg[dmg[i].num] * mx) {             inds = i;             break;           }         }       }       if (inds != -1) {         total_dmg += dmg[inds].dmg;         flag[inds] = 1;         kols++;         v.push_back(make_pair(time, dmg[inds].num + 1));       } else {         if (reg >= total_dmg) {           cout <<  NO n ;           return 0;         }       }       time++;     }     return 0;   }


#include <bits/stdc++.h>   bool isvowel(char s) {     if (s ==  a  || s ==  A  || s ==  e  || s ==  E  || s ==  i  || s ==  I  ||         s ==  o  || s ==  O  || s ==  u  || s ==  U )       return true;     else       return false;   }   long long fact(long long n) {     long long mul = 1;     for (long long i = 1; i <= n; i++) mul = mul * i;     return mul;   }   long long gcd(long long a, long long b) {     return b == 0 ? a : gcd(b % 1000000007, (a % b) % 1000000007);   }   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1)       cout <<  -1             <<   n ;     else {       for (int i = 1; i <= n; i += 2) {         cout << i + 1 <<     << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 mt_rand(       chrono::high_resolution_clock::now().time_since_epoch().count());   const int INF = 2e9;   const long long ML = 4e18;   long long Pow(long long x, int p) {     long long res = 1;     while (p) {       if (p & 1) res = (res * x) % 998244353;       x = (x * x) % 998244353;       p >>= 1;     }     return res;   }   void solve() {     int n, q;     cin >> n >> q;     vector<int> ax(n);     for (int i = (0); i < (n); ++i) cin >> ax[i];     sort((ax).begin(), (ax).end());     vector<long long> sum(n + 1, 0);     for (int i = (1); i < (n + 1); ++i) {       sum[i] = sum[i - 1] + ax[i - 1];       sum[i] %= 998244353;     }     long long inv = Pow(n, 998244353 - 2);     for (int i = (0); i < (q); ++i) {       int a, b;       cin >> a >> b;       int p = lower_bound((ax).begin(), (ax).end(), b) - ax.begin();       int big = n - p, small = p;       if (big < a) {         cout << 0 << endl;         continue;       } else {         long long bs = (sum[n] - sum[p] + 998244353) % 998244353, sm = sum[p];         long long ans =             bs * (big - a) % 998244353 * Pow(big, 998244353 - 2) % 998244353;         ans = (ans + sm * (big + 1 - a) % 998244353 *                          Pow(big + 1, 998244353 - 2) % 998244353) %               998244353;         cout << ans << endl;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   const long long MOD = 1e9 + 7;   const long long MAXN = 1e6 + 1;   using namespace std;   long long readInt() {     bool minus1 = false;     long long result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus1 = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = result * 10 + (ch -  0 );     }     if (minus1)       return -result;     else       return result;   }   const int N = 3333;   int dx[] = {+1, -1, 0, 0};   int dy[] = {0, 0, +1, -1};   string dirs =  UDRL ;   int directiony[N];   int directionx[N];   long long curx = 5000000001LL, cury = 5000000001LL;   vector<long long> xler;   vector<long long> yler;   void add() {     xler.push_back(curx);     xler.push_back(curx - 1);     xler.push_back(curx + 1);     yler.push_back(cury);     yler.push_back(cury - 1);     yler.push_back(cury + 1);   }   int used[N][N];   int H, W;   void dfs(int x, int y) {     used[x][y] = 2;     for (int i = 0; i < 4; i++) {       int tmpx = x + dx[i];       int tmpy = y + dy[i];       if ((0 <= tmpx && tmpx < H) && (0 <= tmpy && tmpy < W) &&           used[tmpx][tmpy] == 0) {         dfs(tmpx, tmpy);       }     }   }   int main() {     int n = readInt();     add();     for (int i = 0; i < n; i++) {       char x;       int y;       cin >> x >> y;       for (int j = 0; j < 4; j++) {         if (dirs[j] == x) {           directionx[i] = dx[j] * y;           directiony[i] = dy[j] * y;           curx += directionx[i];           cury += directiony[i];           add();         }       }     }     sort(xler.begin(), xler.end());     sort(yler.begin(), yler.end());     xler.resize(unique(xler.begin(), xler.end()) - xler.begin());     yler.resize(unique(yler.begin(), yler.end()) - yler.begin());     H = xler.size();     W = yler.size();     curx = 5000000001LL;     cury = 5000000001LL;     long long compx = lower_bound(xler.begin(), xler.end(), curx) - xler.begin();     long long compy = lower_bound(yler.begin(), yler.end(), cury) - yler.begin();     for (int i = 0; i < n; i++) {       long long tmpx = curx + directionx[i];       long long tmpy = cury + directiony[i];       long long tmpcompx =           lower_bound((xler).begin(), (xler).end(), tmpx) - xler.begin();       long long tmpcompy =           lower_bound((yler).begin(), (yler).end(), tmpy) - yler.begin();       for (int j = min(tmpcompx, compx); j <= max(tmpcompx, compx); j++) {         for (int k = min(tmpcompy, compy); k <= max(tmpcompy, compy); k++) {           used[j][k] = 1;         }       }       curx = tmpx;       cury = tmpy;       compx = tmpcompx;       compy = tmpcompy;     }     dfs(0, 0);     long long res = 0;     for (int i = 0; i < H; i++) {       for (int j = 0; j < W; j++) {         if (used[i][j] != 2) {           res += (xler[i + 1] - xler[i]) * (yler[j + 1] - yler[j]);         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   const long long MAX_N = 3e5 + 10;   const long long MOD = 1e9 + 9;   using namespace std;   vector<int> g1[MAX_N];   vector<int> g[MAX_N];   vector<int> current;   int p[MAX_N];   int mark[MAX_N];   int d[MAX_N];   int h[MAX_N];   int n, m, k;   void rt(int v) {     mark[v]++;     for (auto x : g1[v]) {       if (!mark[x]) {         p[x] = v;         h[x] = h[v] + 1;         g[x].push_back(v);         g[v].push_back(x);         rt(x);       }     }   }   void solve() {     cout <<  CYCLES n ;     int ct = 0;     for (int i = 2; i <= n; ++i) {       int v = i;       if (g[v].size() > 1) continue;       ct++;       pair<int, int> pr;       int res = 1e9;       vector<pair<int, int>> vc;       for (auto x : g1[v]) {         if (x == p[v]) continue;         if ((h[v] - h[x]) % 3 != 2 and h[v] - h[x] + 1 < res) {           res = h[v] - h[x] + 1;           pr.second = v;           pr.first = x;         }         vc.push_back({h[x], x});       }       sort(vc.begin(), vc.end());       for (int i = 0; i < vc.size() - 1; ++i) {         int len = vc[i + 1].first - vc[i].first + 2;         if (len % 3 and res > len) {           res = len;           pr = {vc[i].second, vc[i + 1].second};         }       }       int now = pr.second;       cout << res <<   n ;       if (pr.second != v) cout << v <<   n ;       while (1) {         cout << now <<    ;         if (now == pr.first) break;         now = p[now];       }       cout <<   n ;       if (ct == k) exit(0);     }     exit(0);   }   void dfs(int v, int f) {     for (auto x : g[v]) {       if (x != f) {         d[x] = d[v] + 1;         dfs(x, v);       }     }   }   void sfd(int v, int f, int dest) {     current.push_back(v);     if (v == dest) {       cout << current.size() <<   n ;       for (auto x : current) cout << x <<    ;       exit(0);     }     for (auto x : g[v]) {       if (x != f) sfd(x, v, dest);     }     current.pop_back();   }   int main() {     cin >> n >> m >> k;     if (n == 1) return cout <<  PATH n1 n1 , 0;     if (n == 2) return cout <<  PATH n2 n1 2 , 0;     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &v, &u);       g1[u].push_back(v);       g1[v].push_back(u);     }     rt(1);     int now = 0, v = 1;     for (int i = 1; i <= n; ++i) {       if (h[i] > now) {         now = h[i];         v = i;       }     }     dfs(v, 0);     now = 0;     int best = 0;     for (int i = 1; i <= n; ++i) {       if (d[i] > now) {         now = d[i];         best = i;       }     }     if (n / (double)k <= now) {       cout <<  PATH n ;       sfd(v, 0, best);     } else       solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 100005;   int a[N * 2], ans[N];   stack<int> s;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= 2 * n; i++) {       char op;       scanf(  %c , &op);       if (op ==  + ) {         a[i] = -1;       } else {         scanf( %d , &a[i]);       }     }     int t = n;     for (int i = 2 * n; i >= 1; i--) {       if (a[i] == -1) {         if (s.empty()) return puts( NO ), 0;         ans[t--] = s.top();         s.pop();       } else {         if (!s.empty() && a[i] > s.top()) return puts( NO ), 0;         s.push(a[i]);       }     }     puts( YES );     for (int i = 1; i <= n; i++) printf( %d%c , ans[i],    n [i == n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e5 + 10;   int n, m;   int main() {     scanf( %d%d , &n, &m);     long long sum1 = 0, sum2 = 0;     int t = n - n / 2;     for (int i = 1; i <= n; i++) {       sum1 += i - 1;       sum2 += abs(t - i);     }     int x, d;     long long sum3 = 0;     long long z1 = 0;     long long z2 = 0;     while (m--) {       scanf( %d%d , &x, &d);       sum3 += x;       if (d < 0)         z1 += d * sum2;       else         z2 += d * sum1;     }     double ans = sum3;     ans += 1.0 * (z1 + z2) / n;     printf( %.12f , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   int w[55];   int n;   int num_teams(int s) {     map<int, int> cnt;     for (int i = 0; i < n; ++i) {       ++cnt[w[i]];     }     int teams = 0;     for (int i = 0; i < n; ++i) {       int wt = w[i];       if (cnt[wt] == 0) continue;       if (wt >= s) continue;       if (cnt[s - wt] == 0) continue;       if (wt == (s - wt) && cnt[wt] < 2) continue;       --cnt[wt];       --cnt[s - wt];       ++teams;     }     return teams;   }   void solve() {     int max_teams = 0;     for (int s = 2; s <= 100; ++s) {       max_teams = max(max_teams, num_teams(s));     }     cout << max_teams <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> w[i];       }       solve();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 5;   const long long mod = 1e9 + 7;   const int inf = 0x7fffffff;   int a[maxn];   int main() {     int t;     cin >> t;     while (t--) {       int r, g, b, w;       cin >> r >> g >> b >> w;       int f = 0;       if (r % 2 == 1) f++;       if (g % 2 == 1) f++;       if (b % 2 == 1) f++;       if (w % 2 == 1) f++;       if (f <= 1)         cout <<  Yes  <<   n ;       else {         if (r && g && b) r--, g--, b--, w += 3;         f = 0;         if (r % 2 == 1) f++;         if (g % 2 == 1) f++;         if (b % 2 == 1) f++;         if (w % 2 == 1) f++;         if (f <= 1)           cout <<  Yes  <<   n ;         else           cout <<  No  <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, sum = 0, maxi, mini, start, end;     ;     cin >> a >> b >> n;     mini = min(a, b);     maxi = max(a, b);     if (n <= min(a, b)) {       cout << n + 1;     } else {       if (mini + maxi >= n) {         int k = n - maxi;         if (k < 0) {           k = 0;         }         sum = mini - k + 1;       }       cout << sum;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     v.push_back(1);     long long x, i, xx = 10, c = 2, cc = 0;     while (1) {       i = 1;       cc = c - 1;       xx = 0;       while (i <= c) {         xx = xx + pow(2, cc);         cc++;         i++;       }       c++;       if (xx <= 100000) {         v.push_back(xx);       } else {         break;       }     }     int sz = v.size();     long long nn;     cin >> nn;     for (int ii = sz - 1; ii >= 0; ii--) {       if (v[ii] <= nn && nn % v[ii] == 0) {         cout << v[ii] << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   const int d = 998244353;   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<vector<long long int>> t(n + 1);     vector<long long int> init(k + 1, 0);     for (int i = 0; i <= n; i++) {       t[i] = init;     }     t[1][0] = m;     t[1][1] = 0;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= min(i - 1, k); j++) {         if (j >= 1) {           t[i][j] = (t[i - 1][j] + (m - 1) * t[i - 1][j - 1]) % d;         }         if (j == 0) {           t[i][0] = m;         }       }     }     cout << t[n][k];     return 0;   }


#include <bits/stdc++.h>   static const int MAXLEN = 1e6 + 12;   int len = 0;   char s[MAXLEN];   char *tokens[MAXLEN];   int token_ct = 0;   int max_depth = 0;   std::vector<char *> nested[MAXLEN];   int parse_comment_recursive(int start_token, int level) {     if (max_depth < level) max_depth = level;     nested[level].push_back(tokens[start_token++]);     int children = strtol(tokens[start_token++], NULL, 10);     while (children--) {       start_token = parse_comment_recursive(start_token, level + 1);     }     return start_token;   }   int main() {     while ((s[len] = getchar()) !=   n  && s[len] != EOF) ++len;     s[len] =   0 ;     tokens[token_ct++] = s;     for (int i = 0; i < len; ++i)       if (s[i] ==  , ) {         tokens[token_ct++] = s + i + 1;         s[i] =   0 ;       }     int parsed_tokens = 0;     while (parsed_tokens < token_ct)       parsed_tokens = parse_comment_recursive(parsed_tokens, 0);     printf( %d n , max_depth + 1);     for (int i = 0; i <= max_depth; ++i) {       for (std::vector<char *>::iterator j = nested[i].begin();            j != nested[i].end(); ++j) {         fputs(*j, stdout);         putchar(   );       }       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 0;   int n, k, x;   string s;   vector<int> v;   int main() {     int a, b, c, d, e, f;     int cnt = 0;     scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f);     if (a == d) cnt++;     if (b == e) cnt++;     if (c == f) cnt++;     if (cnt >= 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   char s[100100];   int n, ans = 1, tmp;   int main() {     scanf( %d %s , &n, s);     for (int i = 1; i < n; i++)       if (s[i] != s[i - 1])         ans++;       else         tmp++;     if (tmp) ans++;     if (tmp > 1) ans++;     printf( %d n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n;   int keep[201];   int tt[201];   int first[201];   int main() {     while (cin >> n) {       n *= 2;       int sum = 0, n1 = 0, n2 = 0, s1 = 0, s2 = 0;       memset(keep, 0, sizeof(keep));       memset(first, 0, sizeof(first));       for (int i = 0; i < n; i++) {         int a;         cin >> a;         keep[a]++;         tt[i] = a;       }       for (int i = 10; i < 100; i++) {         if (keep[i] > 1) {           s1++;           s2++;           if (n1 > n2)             n1 += keep[i] / 2, n2 += (keep[i] - keep[i] / 2), first[i] = 2;           else             n2 += keep[i] / 2, n1 += (keep[i] - keep[i] / 2), first[i] = 1;         } else if (keep[i] == 1)           sum++;       }       int turn = 1;       if (s1 > s2) {         turn = 2;         s1 += sum / 2;         s2 += (sum - sum / 2);       } else {         turn = 2;         s2 += sum / 2;         s1 += (sum - sum / 2);       }       cout << s1 * s2 << endl;       for (int i = 0; i < n; i++) {         if (keep[tt[i]] > 1) {           cout << first[tt[i]];           first[tt[i]] = (first[tt[i]] == 2 ? 1 : 2);         } else if (keep[tt[i]] == 1) {           cout << turn;           turn = (turn == 2 ? 1 : 2);         }         if (i < n - 1)           cout <<    ;         else           cout << endl;       }     }   }


#include <bits/stdc++.h>   template <typename T>   struct ScanfSpecifier {};   template <>   struct ScanfSpecifier<char*> {     static constexpr const char* value =  %s ;   };   template <>   struct ScanfSpecifier<int> {     static constexpr const char* value =  %d ;   };   template <>   struct ScanfSpecifier<double> {     static constexpr const char* value =  %lf ;   };   template <>   struct ScanfSpecifier<float> {     static constexpr const char* value =  %f ;   };   template <>   struct ScanfSpecifier<char> {     static constexpr const char* value =  %c ;   };   template <>   struct ScanfSpecifier<const char*> {     static constexpr const char* value =  %s ;   };   template <>   struct ScanfSpecifier<unsigned long> {     static constexpr const char* value =  %lu ;   };   template <>   struct ScanfSpecifier<unsigned int> {     static constexpr const char* value =  %u ;   };   template <>   struct ScanfSpecifier<long long int> {     static constexpr const char* value =  %lld ;   };   template <typename T>   int RD(T& arg) {     return std::scanf(ScanfSpecifier<T>::value, &arg);   }   template <int S>   int RD(char (&arg)[S]) {     return std::scanf( %s , arg);   }   int RD(char* arg) { return std::scanf( %s , arg); }   template <>   int RD<char>(char& arg) {     return std::scanf(  %c , &arg);   }   template <typename T, typename... Args>   int RD(T& arg1, Args&... args) {     return RD(arg1) + RD(args...);   }   template <typename T>   T RD() {     T ret;     RD(ret);     return ret;   }   template <typename It>   void RDV(It begin, It end) {     while (begin != end) RD(*begin++);   }   template <typename C>   void RDV(C& c) {     RDV(std::begin(c), std::end(c));   }   template <typename T>   void WT(T arg) {     std::printf(ScanfSpecifier<T>::value, arg);   }   template <typename T, typename U>   void WT(std::pair<T, U> arg) {     std::printf( ( );     WT(arg.first);     std::printf( ,  );     WT(arg.second);     std::printf( ) );   }   template <typename... Args>   void WT(Args... args) {     int alc = 0;     int dummy[] = {((alc++ ? std::printf(   ) : 0), WT(args), 0)...};   }   template <typename... Args>   void WTL(Args... args) {     WT(args...);     std::printf(  n );   }   template <typename It>   void WTV(It begin, It end) {     int alc = 0;     while (begin != end) (alc++ ? std::printf(   ) : 0), WT(*begin++);   }   template <typename C>   void WTV(const C& c) {     WTV(std::begin(c), std::end(c));   }   template <typename It>   void WTVL(It begin, It end) {     WTV(begin, end);     std::printf(  n );   }   template <typename C>   void WTVL(const C& c) {     WTVL(std::begin(c), std::end(c));   }   struct Range {     struct It {       int num, step;       int operator*() { return num; }       void operator++() { num += step; }       bool operator!=(const It& other) { return num != other.num; }     };     Range(int ee) : b(0), e(ee) {}     Range(int bb, int ee) : b(bb), e(ee) {}     It begin() { return {b, (b < e ? 1 : -1)}; }     It end() { return {e, 0}; }     int b, e;   };   template <typename T>   inline T& UMAX(T& x, T y) {     if (x < y) x = y;     return x;   }   template <typename T>   inline T& UMIN(T& x, T y) {     if (y < x) x = y;     return x;   }   template <typename T, typename... Args>   struct ArithmiticPromotion {     typedef decltype(T() + typename ArithmiticPromotion<Args...>::type()) type;   };   template <typename T, typename U>   struct ArithmiticPromotion<T, U> {     typedef decltype(T() + U()) type;   };   template <typename T>   struct ArithmiticPromotion<T, T> {};   template <typename T>   struct ArithmiticPromotion<T> {};   template <typename T, typename U>   typename ArithmiticPromotion<T, U>::T MAX(T a, U b) {     return a < b ? b : a;   }   template <typename T, typename... Args>   typename ArithmiticPromotion<T, Args...>::T MAX(T a, Args... args) {     return MAX(a, MAX(args...));   }   template <typename T, typename U>   typename ArithmiticPromotion<T, U>::T MIN(T a, U b) {     return a < b ? a : b;   }   template <typename T, typename... Args>   typename ArithmiticPromotion<T, Args...>::T MIN(T a, Args... args) {     return MIN(a, MIN(args...));   }   using RG = Range;   using namespace std;   char L[32], R[32];   void pad(char* s) {     int l = strlen(s);     reverse(s, s + l);     for (int i : RG(l, 19)) s[i] =  0 ;     reverse(s, s + 19);     for (int i : RG(19)) s[i] -=  0 ;   }   long long int ans;   int num[10];   void dfs(int pos, int r, int total) {     if (pos < 10) {       for (int i = 0; i <= r; i++) {         num[pos] = i;         dfs(pos + 1, r - i, total + i);       }     } else {       {         bool check = true;         int use = 0;         bool b = false;         int tmp[10] = {};         int mn = 1;         for (int i = 0; i < 19; i++) {           while (mn < 10 && tmp[mn] == num[mn]) mn++;           if (!b) {             for (int d = L[i] + 1; d < R[i]; d++)               if ((!d || tmp[d] + 1 <= num[d]) && use + 19 - i - !d >= total) {                 ans++;                 return;               }           } else if (R[i]) {             if (use + 19 - i - 1 >= total ||                 (mn < R[i] && use + 19 - i >= total)) {               ans++;               return;             }           }           if (R[i]) {             ++use;             if (++tmp[R[i]] > num[R[i]]) {               check = false;               break;             }           }           if (L[i] < R[i]) b = true;         }         if (check && use == total) {           ans++;           return;         }       }       {         bool check = true;         int use = 0;         bool b = false;         int tmp[10] = {};         int mx = 9;         for (int i = 0; i < 19; i++) {           while (mx > 0 && tmp[mx] == num[mx]) mx--;           if (!b) {             for (int d = L[i] + 1; d < R[i]; d++)               if (tmp[d] + 1 <= num[d] && use + 19 - i - !d >= total) {                 ans++;                 return;               }           } else {             if (mx > L[i] && use + 19 - i >= total) {               ans++;               return;             }           }           if (L[i]) {             ++use;             if (++tmp[L[i]] > num[L[i]]) {               check = false;               break;             }           }           if (L[i] < R[i]) b = true;         }         if (check && use == total) {           ans++;           return;         }       }     }   }   int main() {     RD(L, R);     pad(L), pad(R);     dfs(1, 18, 0);     WTL(ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   char second[N];   long long x, y, xx, yy;   int n;   bool check(long long days) {     long long px = x, py = y;     for (int i = 0; i < n; i++) {       long long mult = days / n;       if (i < (days % n)) mult++;       if (second[i] ==  U ) py += mult;       if (second[i] ==  D ) py -= mult;       if (second[i] ==  L ) px -= mult;       if (second[i] ==  R ) px += mult;     }     long long d = abs(xx - px) + abs(yy - py);     return d <= days;   }   int main() {     scanf( %lld%lld%lld%lld , &x, &y, &xx, &yy);     scanf( %d , &n);     scanf( %s , second);     long long lo = 0, hi = 1e18, ans = -1;     if (!check(hi)) {       cout << -1 << endl;       return 0;     }     while (hi - lo > 1) {       long long mid = (lo + hi) / 2;       if (check(mid)) {         ans = mid;         hi = mid;       } else {         lo = mid;       }     }     cout << hi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x, y;     cin >> n;     vector<pair<long long, long long>> a, b;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       a.push_back(make_pair(x, y));     }     for (long long i = 0; i < n; i++) {       cin >> x >> y;       b.push_back(make_pair(x, y));     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     cout << a[0].first + b[n - 1].first <<     << a[0].second + b[n - 1].second;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int a[1024], f[10010];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, l = INT_MAX, r = INT_MIN, cnt = 0, src, dst;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       ++f[a[i]];     }     for (int i = 0; i < 10001; ++i) {       if (f[i]) ++cnt;       if (cnt > 3) {         cout <<  Unrecoverable configuration. ;         return 0;       }     }     if (cnt == 1) {       cout <<  Exemplary pages. ;       return 0;     }     for (int i = 0; i < n; ++i) {       if (l > a[i]) {         l = a[i];         src = i + 1;       }       if (r < a[i]) {         r = a[i];         dst = i + 1;       }     }     int dif = r - l;     if (dif % 2) {       cout <<  Unrecoverable configuration. ;       return 0;     }     dif /= 2;     if (n == 2) {       cout << dif <<   ml. from cup #  << src <<   to cup #  << dst <<  . n ;       return 0;     }     for (int i = 0; i < n; ++i) {       if (i != src - 1 && i != dst - 1) {         if (l + dif != a[i] || r - dif != a[i]) {           cout <<  Unrecoverable configuration. ;           return 0;         }       }     }     cout << dif <<   ml. from cup #  << src <<   to cup #  << dst <<  . n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   const int N = 500005;   long long c[N];   map<long long, vector<pair<int, int>>> ed;   struct DSU {     vector<int> p, r;     int n;     int components;     DSU(int _) : n(_), components(_) {       p.resize(n + 1);       r.resize(n + 1);       for (int i = 0; i <= _; ++i) p[i] = i, r[i] = 0;     }     int parent(int i) { return p[i] = (p[i] == i) ? i : parent(p[i]); }     void merge(int x, int y) {       x = parent(x);       y = parent(y);       if (x == y) return;       if (r[x] > r[y])         p[y] = x;       else         p[x] = y;       if (r[x] == r[y]) ++r[y];       --components;     }   };   int _runtimeTerror_() {     long long ans = 0;     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> c[i];     ans += power(2, n, M) * ((1LL << k) % M) % M;     for (int i = 1; i <= m; ++i) {       int x, y;       cin >> x >> y;       ed[c[x] ^ c[y]].push_back({x, y});     }     DSU dsu(n);     for (auto &j : ed) {       int cnt = 0;       for (auto &k : j.second)         dsu.p[k.first] = k.first, dsu.p[k.second] = k.second;       dsu.components = n;       for (auto &k : j.second) {         dsu.merge(k.first, k.second);       }       ans -= power(2, n, M);       ans %= M;       ans += power(2, dsu.components, M);       ans = (ans + M) % M;     }     cout << ans <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 5;   int di[] = {1, 1, -1, -1};   int dj[] = {1, -1, 1, -1};   long long n, k;   long long solv() {     long long st = 0, ed = k, ans;     while (st <= ed) {       long long x = (k * (k + 1)) / 2;       long long mid = (st + ed) / 2;       long long xx = k - mid;       x -= ((xx * (xx + 1)) / 2) + mid - 1;       if (x < n)         st = mid + 1;       else if (x >= n)         ans = mid, ed = mid - 1;       else         return mid;     }     return ans;   }   int main() {     cin >> n >> k;     if ((k * (k + 1)) / 2 - k + 1 < n) return cout << -1, 0;     cout << solv();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2) {       cout <<  black  << endl;     } else {       cout <<  white             <<   n1 2 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int t, n, x[N], y[N];   long long a[N], val[N];   int main() {     cin >> t;     while (t--) {       scanf( %d , &n);       long long sum = 0;       for (int i = 1; i <= n; ++i) {         scanf( %lld , a + i);         sum += a[i];       }       if (sum % n) {         puts( -1 );         continue;       }       sum /= n;       int m = 0;       for (int i = 2; i <= n; ++i) {         long long req = a[i] % i;         if (req) {           req = i - req, ++m;           x[m] = 1, y[m] = i, val[m] = req;           a[1] -= req, a[i] += req;         }         ++m;         x[m] = i, y[m] = 1, val[m] = a[i] / i;         a[1] += a[i], a[i] = 0;       }       for (int i = 2; i <= n; ++i) {         ++m;         x[m] = 1, y[m] = i, val[m] = sum;         a[1] -= sum, a[i] += sum;       }       printf( %d n , m);       for (int i = 1; i <= m; ++i) printf( %d %d %lld n , x[i], y[i], val[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, i, x, y, best, w, cw, rt, a[200200];   vector<int> g[200200];   bool all;   void dfs(int i, int p, int cur, int dst) {     if (dst > best) {       best = dst;       cw = cur;       w = i;     }     for (int j : g[i])       if (j != p) {         dfs(j, i, ((a[j] == 0) ? cur : a[j]),             (dst + int(a[j] != 0 && a[j] != cur)));       }   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       all = true;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);         if (a[i] != 0) {           all = false;           rt = i;         }         g[i].clear();       }       for (i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         g[x].push_back(y);         g[y].push_back(x);       }       if (all) {         puts( 1 );         continue;       }       best = 0;       w = rt;       cw = a[rt];       dfs(rt, 0, a[rt], 0);       best = 0;       dfs(w, 0, cw, 0);       printf( %d n , (best + 3) / 2);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int64_t l;     int64_t p, q;     double x, w;     std::cin >> l;     std::cin >> p >> q;     w = (q + p);     x = l * p / w;     std::cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[105];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     a[n] = a[0];     int k;     int minn = 10005;     for (int i = 1; i <= n; i++) {       if (abs(a[i] - a[i - 1]) < minn) {         minn = abs(a[i] - a[i - 1]);         k = i;       }     }     if (k >= n) {       cout << 1 <<     << k << endl;     } else {       cout << k + 1 <<     << k << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int n, x, y, b, a[3];   int main() {     long long int x, y;     cin >> x >> y;     long long int a = 0;     while (true) {       if (a % 2 == 0) {         if (x >= 2 && y >= 2) {           x -= 2;           y -= 2;         } else {           if (x >= 1 && y >= 12) {             x--;             y -= 12;           } else {             if (x >= 0 && y >= 22) {               y -= 22;             } else {               break;             }           }         }       } else {         if (x >= 0 && y >= 22) {           y -= 22;         } else {           if (x >= 1 && y >= 12) {             x--;             y -= 12;           } else {             if (x >= 2 && y >= 2) {               x -= 2;               y -= 2;             } else {               break;             }           }         }       }       a++;     }     if (a % 2 == 1) {       cout <<  Ciel ;       return 0;     }     cout <<  Hanako ;   }


#include <bits/stdc++.h>   using namespace std;   inline int ci() {     register char ch;     int f = 1;     while (!isdigit(ch = getchar())) f = ch ==  -  ? -1 : 1;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (x * 10) + (ch ^  0 );     return f * x;   }   enum { N = 100024 };   int a[N];   int main() {     int n = ci();     for (register int i = (1); i <= (n); i++) a[i] = ci();     sort(a + 1, a + n + 1);     long long a1 = 0, a2 = 0;     int m = n / 2;     for (register int i = (1); i <= (m); i++) a1 += a[i];     for (register int i = (m + 1); i <= (n); i++) a2 += a[i];     printf( %I64d , a1 * a1 + a2 * a2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Dish {     int ind;     int cost;     int cnt;   };   int n;   bool dishComp(Dish a, Dish b) {     if (a.cost == b.cost) {       return a.ind < b.ind;     }     return a.cost < b.cost;   }   int main() {     int m, a, c;     cin >> n >> m;     vector<Dish> dishes;     for (int i = 0; i < n; i++) {       cin >> a;       Dish dish;       dish.ind = i + 1;       dish.cnt = a;       dishes.push_back(dish);     }     int has[n + 1];     for (int i = 0; i < n; i++) {       cin >> c;       dishes[i].cost = c;     }     sort(dishes.begin(), dishes.end(), dishComp);     for (int i = 0; i < n; i++) {       has[dishes[i].ind] = i;     }     int t, d, btindex, cnti;     long long int sm;     int saveIndex = 0;     for (int i = 0; i < m; i++) {       cin >> t >> d;       btindex = has[t];       if (dishes[btindex].cnt >= d) {         sm = (long long int)dishes[btindex].cost * d;         dishes[btindex].cnt = dishes[btindex].cnt - d;       } else {         sm = (long long int)dishes[btindex].cost * dishes[btindex].cnt;         d = d - dishes[btindex].cnt;         dishes[btindex].cnt = 0;         cnti = 0;         while (saveIndex < n) {           if (dishes[saveIndex].cnt < d) {             d = d - dishes[saveIndex].cnt;             sm = sm +                  (long long int)dishes[saveIndex].cost * dishes[saveIndex].cnt;             dishes[saveIndex].cnt = 0;           } else {             sm = sm + (long long int)dishes[saveIndex].cost * d;             dishes[saveIndex].cnt = dishes[saveIndex].cnt - d;             cnti = 1;             break;           }           saveIndex++;         }         if (cnti == 0) sm = 0;       }       cout << sm <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 9;   int seg[MAX * 4][2], n, k, a, b, q, ar[MAX];   void upd(int x, int s = 0, int e = n, int id = 0) {     if (e - s == 1) {       seg[id][0] = min(ar[s], a), seg[id][1] = min(ar[s], b);       return;     }     int mid = s + e >> 1;     if (x < mid)       upd(x, s, mid, id * 2 + 1);     else       upd(x, mid, e, id * 2 + 2);     seg[id][0] = seg[id * 2 + 1][0] + seg[id * 2 + 2][0];     seg[id][1] = seg[id * 2 + 1][1] + seg[id * 2 + 2][1];   }   pair<int, int> gt(int l, int r, int s = 0, int e = n, int id = 0) {     pair<int, int> ret = {0, 0};     if (r <= s || e <= l) return ret;     if (l <= s && e <= r) return {seg[id][0], seg[id][1]};     int mid = s + e >> 1;     pair<int, int> le = gt(l, r, s, mid, id * 2 + 1),                    ri = gt(l, r, mid, e, id * 2 + 2);     ret = {le.first + ri.first, le.second + ri.second};     return ret;   }   int main() {     cin >> n >> k >> a >> b >> q, n++;     while (q--) {       int t, d, a;       cin >> t >> d;       if (t == 1)         cin >> a, ar[d] += a, upd(d);       else         cout << gt(0, d).second + gt(d + k, n).first <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     int n;     scanf( %d , &n);     vector<int> a;     int r2 = 0;     int ans;     int prev = 0;     long long res = 0;     int pr2 = 0;     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       if (i == 0) {         prev = tmp;         continue;       }       if (tmp < prev) {         res += prev - tmp;       }       prev = tmp;     }     printf( %I64d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Interval {     int start, end;   };   bool compare(Interval i1, Interval i2) { return (i1.start < i2.start); }   vector<long long int> factors;   void Divisors(long long int n) {     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           factors.push_back(i);         else {           factors.push_back(i);           factors.push_back(n / i);         }       }     }   }   long long int coun[100005] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k, m, t;     cin >> n >> k >> m >> t;     while (t--) {       long long int task, in;       cin >> task >> in;       if (task == 0) {         if (in < k) {           k = k - in;           n = n - in;         } else {           n = in;         }         cout << n <<     << k << endl;       } else {         if (in <= k) {           k = k + 1;           n = n + 1;         } else {           k = k;           n = n + 1;         }         cout << n <<     << k << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   const int N = 254;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   int n, t, K;   int a[N], d[N];   long long A[N], D[N], lim[N];   long long f[N][N][2], g[N][N][2];   inline void down(long long &x, const long long y) { x > y ? x = y : 0; }   inline long long max(const long long x, const long long y) {     return x < y ? y : x;   }   int main() {     int i, j, k, r;     long long times, time2, rem, need;     scanf( %d%d%d , &n, &t, &K);     for (i = 1; i <= n; ++i) scanf( %d%d%lld , a + i, d + i, lim + i);     ++n, a[n] = d[n] = INT_MAX, lim[n] = INF;     for (i = 1; i <= n; ++i) A[i] = A[i - 1] + a[i], D[i] = D[i - 1] + d[i];     memset(f, 63, sizeof f), memset(g, 63, sizeof g);     memset(f, 0, sizeof *f), memset(g, 0, sizeof *g);     for (i = 1; i <= n; ++i)       for (j = 0; j <= t; ++j)         for (k = 0; k < 2; ++k) {           if ((long long)k * a[i] + (long long)j * d[i] <= lim[i] &&               f[i - 1][j][k] < INF) {             down(f[i][j][k], f[i - 1][j][k]),                 times = (k * A[i - 1] + j * D[i - 1] + K - 1) / K;             if (times * K <= k * A[i] + j * D[i]) down(g[i][j][k], times);           }           for (r = 0; r < j; ++r)             if ((times = g[i][r][k]) < INF) {               rem = k * A[i] + r * D[i] - K * times, assert(rem >= 0);               need =                   (max(0, rem + (long long)(j - r) * d[i] - lim[i]) + K - 1) / K;               if (need * K <= rem && f[i - 1][j - r][0] < INF) {                 down(f[i][j][k], times + need + f[i - 1][j - r][0]);                 time2 = ((j - r) * D[i - 1] + K - 1) / K;                 if (time2 * K <= (j - r) * D[i] + (rem - need * K))                   down(g[i][j][k], times + need + time2);               }             }         }     printf( %lld n , f[n][t][1]);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2e7 + 10;   const int mod = 998244853;   int n, m, qwq[maxn + 5], ifac[maxn + 5], f[maxn + 5];   void zzh_NB(int &x, int y) { (x += y) >= mod && (x -= mod); }   int add(int x) { return x >= mod ? x - mod : x; }   int readINT() {     int xx = 0, ch = getchar(), f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) xx = xx * 10 + ch -  0 , ch = getchar();     return xx * f;   }   int kehaixing(int x) { return x < 0 ? x + mod : x; }   int quick_pp(int x, int k) {     int ans = 1;     for (; k > 0; k >>= 1, x = 1LL * x * x % mod) {       if ((k & 1) == 1) ans = 1LL * ans * x % mod;     }     return ans;   }   int inv(int x) { return quick_pp(x, mod - 2); }   void init(int n) {     qwq[0] = 1;     for (int i = 1; i <= n; i++) qwq[i] = 1LL * qwq[i - 1] * i % mod;     ifac[n] = inv(qwq[n]);     for (int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % mod;   }   int wssb(int n, int m) {     if (n < m) return 0;     return 1LL * qwq[n] * ifac[m] % mod * ifac[n - m] % mod;   }   int ans = 0;   inline void duru() {     n = readINT(), m = readINT();     init(n + m);     for (int i = 0; i <= n; i++) {       f[i] = (i <= n - m ? wssb(n + m, n) : wssb(n + m, n - i));     }     for (int i = 0; i <= n; i++) {       zzh_NB(ans, 1LL * i * kehaixing(f[i] - f[i + 1]) % mod);     }     printf( %d n , ans);   }   int main() {     duru();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     long long int ans = 0;     vector<string> v;     string temp =   ;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  .  && v.size() != 0) {         for (int i = 0; i < v.size(); i++) {           if (temp == v[i]) ++ans;         }         if (temp ==   ) v.pop_back();         temp =   ;         continue;       }       if (s[i] ==  : ) {         for (int i = 0; i < v.size(); i++) {           if (temp == v[i]) ++ans;         }         v.push_back(temp);         temp =   ;         continue;       }       if (s[i] !=  , ) temp += s[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:256000000 )   template <class T>   T sqr(T a) {     return a * a;   }   double a, d, s;   int n;   void init() { cin >> a >> d >> n; }   void solve() {     double x = 0, y = 0;     int dx[4] = {1, 0, -1, 0};     int dy[4] = {0, 1, 0, -1};     int t = d / (4 * a);     d = d - t * (4 * a);     int q = 0;     for (int i = 0; i < n; ++i) {       double t = d;       if (!q) {         if (a - x - t < 1e-5) {           t -= a - x;           x = a;           q++;         }       } else if (q == 1) {         if (a - y - t < 1e-5) {           t -= a - y;           y = a;           q++;         }       } else if (q == 2) {         if (x - t < 1e-5) {           t -= x;           x = 0;           q++;         }       } else {         if (y - t < 1e-5) {           t -= y;           y = 0;           q = 0;         }       }       while (t - a > 1e-5) {         x += dx[q] * a;         y += dy[q] * a;         q++;         if (q == 4) q = 0;         t -= a;       }       x += dx[q] * t;       y += dy[q] * t;       printf( %0.4f %0.4f  n , x, y);     }   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<char> line;   bool isPossible(int gLoc, int k);   int main() {     int n, k;     cin >> n;     cin >> k;     char curr;     int grasshopperLocation;     for (int i = 0; i < n; i++) {       cin >> curr;       line.push_back(curr);       if (curr ==  G ) grasshopperLocation = i;     }     if (isPossible(grasshopperLocation, k))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }   bool isPossible(int gLoc, int k) {     for (int j = gLoc; j < line.size(); j += k) {       if (line[j] ==  T )         return true;       else if (line[j] ==  # )         break;     }     for (int j = gLoc; j >= 0; j -= k) {       if (line[j] ==  T )         return true;       else if (line[j] ==  # )         break;     }     return false;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x += _y;     return _x >= _mod ? _x - _mod : _x;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x -= _y;     return _x < 0 ? _x + _mod : _x;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x *= _y;     return _x >= _mod ? _x % _mod : _x;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1LL;     long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = mul(_ret, _a, _mod);     return _ret;   }   long long mymul(long long _a, long long _x, long long _mod) {     if (_x == 0) return 0LL;     long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = add(_ret, _a, _mod);     return _ret;   }   inline bool equal(double _x, double _y) {     return _x > _y - 1e-9 && _x < _y + 1e-9;   }   void sleep(double sec = 1021) {     clock_t s = clock();     while (clock() - s < CLOCKS_PER_SEC * sec)       ;   }   int __ = 1, _cs;   void build() {}   int n;   vector<int> vx[100001], vy[100001];   void init() {     n = getint();     for (int i = 0, x, y; i < n; i++) {       x = getint();       y = getint();       vx[x].push_back(y);       vy[y].push_back(x);     }     for (int i = 0; i < 100001; i++) {       sort(vx[i].begin(), vx[i].end());       sort(vy[i].begin(), vy[i].end());     }   }   int ans;   vector<int> cand[100001];   void solve() {     for (int x = 0; x < 100001; x++)       for (int y : vx[x]) {         size_t xptr = upper_bound(vx[x].begin(), vx[x].end(), y) - vx[x].begin();         size_t yptr = upper_bound(vy[y].begin(), vy[y].end(), x) - vy[y].begin();         while (xptr < vx[x].size() and yptr < vy[y].size()) {           if (vx[x][xptr] - y == vy[y][yptr] - x) {             if (not vx[vy[y][yptr]].empty())               cand[vy[y][yptr]].push_back(vx[x][xptr]);             xptr++;             yptr++;           } else if (vx[x][xptr] - y < vy[y][yptr] - x)             xptr =                 lower_bound(vx[x].begin(), vx[x].end(), y + (vy[y][yptr] - x)) -                 vx[x].begin();           else             yptr =                 lower_bound(vy[y].begin(), vy[y].end(), x + (vx[x][xptr] - y)) -                 vy[y].begin();         }       }     for (int x = 0; x < 100001; x++) {       sort(cand[x].begin(), cand[x].end());       size_t ptr = 0;       for (int y : cand[x]) {         while (ptr < vx[x].size() and vx[x][ptr] < y) ptr++;         if (ptr == vx[x].size()) break;         ans += (vx[x][ptr] == y);       }     }     cout << ans << endl;   }   int main() {     build();     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize ( O2,unroll-loops )   //#pragma GCC optimize( no-stack-protector,fast-math )   //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )      using namespace std;   typedef long long ll;   typedef long double ld;   typedef pair<int, int> pii;   typedef pair<pii, int> piii;   typedef pair<ll, ll> pll;   #define debug(x) cerr<<#x<< = <<(x)<<endl;   #define debugp(x) cerr<<#x<< = { <<(x.first)<< ,  <<(x.second)<< } <<endl;   #define debug2(x, y) cerr<< { <<#x<< ,  <<#y<< } = { <<(x)<< ,  <<(y)<< } <<endl;   #define debugv(v) {cerr<<#v<<  :  ;for (auto x:v) cerr<<x<<   ;cerr<<endl;}   #define all(x) x.begin(), x.end()   #define pb push_back   #define kill(x) return cout<<x<<  n , 0;      const int inf=1000000010;   const ll INF=1000000000000001000LL;   const int mod=1000000007;   const int MAXN=200010, LOG=18, SGM=26;      ll out, ans;   int n, m, k, u, v, x, y, t, a, b;   map<vector<int>, vector<string>> fuck;   int TR[MAXN][SGM], ts;   int par[LOG][MAXN];   int inc[MAXN], dest[MAXN];   vector<int> vec[MAXN];   string S[MAXN];      inline int Lcp(string &x, string &y){    int res=0;    while (res<m && x[res]==y[res]) res++;    return res;   }   int Count(vector<int> &vec, int l, int r){ // [l...r)    return lower_bound(all(vec), r)-lower_bound(all(vec), l);   }   int GetPar(int v, int k){    for (int i=0; (1<<i)<=k; i++) if (k&(1<<i)) v=par[i][v];    return v;   }   ll Solve(){    if (m==1) return 1ll*n*(n-1)/2;    sort(S, S+n);    ll res=0;/*    if (n<=2000){     for (int i=0; i<n; i++) for (int j=i+1; j<n; j++){      int l=Lcp(S[i], S[j]), r=m-1;      if (l==m){       res++;       continue ;      }      while (r && S[i][r]==S[j][r]) r--;      int ok=1;      while (l<r){       ok&=(S[i][l]<=S[i][l+1]);       l++;      }      res+=ok;     }     return res;    }*/    ts=0;    memset(TR[0], 0, sizeof(TR[0]));    vec[0].clear();    for (int i=0; i<n; i++){     vec[0].pb(i);     int v=0;     for (int j=m-1; ~j; j--){      int c=S[i][j]- a ;      if (!TR[v][c]){       TR[v][c]=++ts;       par[0][ts]=v;       vec[ts].clear();       memset(TR[ts], 0, sizeof(TR[ts]));      }      v=TR[v][c];      vec[v].pb(i);     }     dest[i]=v;    }    for (int i=1; i<=ts; i++) sort(all(vec[i]));    for (int j=1; j<LOG; ++j) for (int i=1; i<=ts; i++) par[j][i]=par[j-1][par[j-1][i]];    for (int i=0; i<n; i++){     inc[m-1]=m-1;     for (int j=m-2; ~j; j--){      if (S[i][j]<=S[i][j+1]) inc[j]=inc[j+1];      else inc[j]=j;     }     int l=i+1;     for (int lcp=m-1; ~lcp; lcp--){      int dwn=l-1, up=n;      while (up-dwn>1){       int mid=(dwn+up)>>1;       int tmp=Lcp(S[i], S[mid]);       if (tmp<lcp) up=mid;       else dwn=mid;      }      int r=up;      if (l==r) continue ;   //   debug2(inc[lcp], GetPar(dest[i], inc[lcp]))      res+=Count(vec[GetPar(dest[i], inc[lcp]+1)], l, r);         //   cerr<<S[i]<<   <<lcp<<     <<l<<   <<r<<  n ;   //   debug(res)   //   cerr<<  n ;            l=r;     }    }    return res;   }      int main(){    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);    //freopen( input.txt ,  r , stdin);    //freopen( output.txt ,  w , stdout);    cin>>n;    for (int i=0; i<n; i++){     cin>>S[i];     vector<int> shit(26, 0);     for (char ch:S[i]) shit[ch- a ]++;     fuck[shit].pb(S[i]);    }    m=S[0].size();    out=1337ll*n*(n-1)/2;    for (auto p:fuck){     n=0;     for (string s:p.second) S[n++]=s;     out-=1337ll*n*(n-1)/2;     out+=2ll*n*(n-1)/2;     ans+=Solve();    }    debug(ans)    cout<<out-ans<<  n ;        return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s[400000];   int bl[400000], S[400000], sz, n, m;   void dfs(int x, int y) {     bl[x] = y;     ++sz;     for (int z : s[x])       if (z != 1 && !bl[z]) dfs(z, y);   }   void dft(int x) {     S[x] = sz;     for (int y : s[x])       if (y != 1 && !S[y]) dft(y);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       s[x].insert(y);       s[y].insert(x);     }     if (s[1].count(n)) return printf( 1 n1 %d n , n), 0;     for (int x : s[1])       if (s[x].count(n)) return printf( 2 n1 %d %d n , x, n), 0;     for (int x : s[1])       for (int y : s[x])         if (s[y].count(n)) return printf( 3 n1 %d %d %d n , x, y, n), 0;     for (int x : s[1])       for (int y : s[x])         if (y != 1 && !s[1].count(y))           return printf( 4 n1 %d %d 1 %d n , x, y, n), 0;     if (!s[1].size()) return puts( -1 ), 0;     for (int x : s[1])       if (!bl[x]) {         sz = 0;         dfs(x, x);         dft(x);       }     int mn = n + 10, mid = 0;     for (int x : s[1])       if (S[x] != s[x].size()) {         if (s[x].size() < mn) {           mn = s[x].size();           mid = x;         }       }     if (mid) {       puts( 5 );       for (int y : s[mid])         if (y != 1)           for (int z : s[y])             if (z != 1 && z != mid && !s[mid].count(z))               return printf( 1 %d %d %d %d %d n , mid, y, z, mid, n), 0;     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 19;   const long long mx1 = 262150;   long long s[mx];   long long n, m, k;   long long extra[mx][mx];   long long dp[mx][mx1];   long long solve(long long prev, long long bitmask, long long m) {     if (m == 0) return 0;     if (dp[prev][bitmask] != -1) return dp[prev][bitmask];     long long ans = INT_MIN;     for (long long j = 0; j < mx; j++) {       if (bitmask & (1 << j))         ans = max(ans, extra[prev][j + 1] + s[j + 1] +                            solve(j + 1, bitmask ^ (1 << j), m - 1));     }     return dp[prev][bitmask] = ans;   }   signed main() {     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) cin >> s[i];     long long a, b, c;     memset(extra, 0, sizeof(extra));     for (long long i = 0; i < k; i++) {       cin >> a >> b >> c;       extra[a][b] = c;     }     long long bitmask = (1 << n) - 1;     long long prev = 0;     memset(dp, -1, sizeof(dp));     cout << solve(prev, bitmask, m) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long LINF = 1e17;   const double DINF = numeric_limits<double>::max();   const int ITER = 300;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const int MAXN = 1e5 + 10;   int n;   vector<int> g[MAXN];   int B[MAXN];   int dp[MAXN][2];   void mod(int v) {     for (int i = 0; i < 2; i++) dp[v][i] %= MOD;   }   void dfs(int v) {     dp[v][0] = 1 - B[v];     dp[v][1] = B[v];     for (int u : g[v]) {       int old[2];       old[0] = dp[v][0];       old[1] = dp[v][1];       dp[v][0] = dp[v][1] = 0;       dfs(u);       dp[v][0] += (1ll * old[0] * dp[u][1]) % MOD;       dp[v][1] += (1ll * old[1] * dp[u][1]) % MOD;       mod(v);       dp[v][1] += (1ll * old[1] * dp[u][0]) % MOD;       mod(v);       dp[v][1] += (1ll * old[0] * dp[u][1]) % MOD;       mod(v);       dp[v][0] += (1ll * old[0] * dp[u][0]) % MOD;       mod(v);     }   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       int p;       cin >> p;       g[p].push_back(i);     }     for (int i = 0; i < n; i++) {       cin >> B[i];     }     dfs(0);     cout << dp[0][1] << endl;   }   int main() {     cout << setprecision(12) << fixed;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N;     int x = 0;     int res = 0;     if (N == 1) {       printf( 1 n );       printf( 1 n );       return 0;     }     for (int i = 1; i <= N; i++) {       x += i;       if (x > N) {         res = i - 1;         break;       }     }     printf( %d n , res);     for (int i = 1; i < res; i++) {       printf( %d  , i);       N -= i;     }     printf( %d n , N);   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   template <class T>   bool get_max(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   bool get_min(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   int k;   int num[26];   string s;   int main() {     cin >> k;     cin >> s;     memset(num, 0, sizeof(num));     for (int i = 0; i < s.size(); i++) num[s[i] -  a ]++;     int flag = 1;     for (int i = 0; i < 26; i++)       if (num[i] % k != 0) {         flag = 0;       }     if (flag == 0)       puts( -1 );     else {       string ans;       for (int i = 0; i < k; i++)         for (int j = 0; j < 26; j++)           for (int g = 0; g < num[j] / k; g++) {             ans = ans + char(j +  a );           }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sav, mn = 1e9;   struct point {     long long x, y, uz;   } p[2005];   string s;   int det(point A, point B, point C) {     if (A.x * B.y + A.y * C.x + B.x * C.y - A.x * C.y - A.y * B.x - B.y * C.x < 0)       return -1;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;       if (p[i].y < mn) {         mn = p[i].y;         sav = i;       }     }     cin >> s;     p[sav].uz = 1;     cout << sav <<    ;     for (int i = 0; i < s.size(); i++) {       int crt = 1, j, sgn;       while (p[crt].uz) crt++;       j = crt + 1;       if (s[i] ==  R )         sgn = 1;       else         sgn = -1;       while (j <= n) {         while (j <= n && p[j].uz) j++;         if (j > n) break;         if (det(p[sav], p[crt], p[j]) == sgn) crt = j;         j++;       }       sav = crt;       p[crt].uz = 1;       cout << sav <<    ;     }     for (int i = 1; i <= n; i++)       if (!p[i].uz) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     vector<string> v, vec;     for (long long i = 1; i <= n; i++) {       string s;       cin >> s;       v.push_back(s);     }     for (long long i = 1; i <= m; i++) {       string s;       cin >> s;       vec.push_back(s);     }     long long q;     cin >> q;     while (q--) {       long long a;       cin >> a;       long long u = a % v.size();       cout << v[(u - 1 + v.size()) % v.size()];       u = a % vec.size();       cout << vec[(u - 1 + vec.size()) % vec.size()];       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void z_func(const string &s, vector<int> &z) {     int L = 0, R = 0;     int n = s.length();     z.resize(n);     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   int main() {     string str;     cin >> str;     vector<int> z;     z_func(str, z);     int maxz = 0, res = 0;     int n = (int)str.length();     for (int i = 0; i < (int)str.length(); i++) {       if (z[i] == n - i) {         if (maxz >= z[i]) res = max(res, z[i]);       }       maxz = max(maxz, z[i]);     }     if (res == 0)       cout <<  Just a legend  << endl;     else       cout << str.substr(0, res) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ll n, a, b;     cin >> n >> a >> b;     ll tot = 6 * n;     ll ans = 1e18;     if (a * b >= tot) {       cout << a * b <<   n  << a <<     << b <<   n ;     } else {       bool swp = false;       if (a > b) {         swp = true;         swap(a, b);       }       ll na = a, nb = b;       for (ll i = 1; i * i <= tot; i++) {         ll j = tot / i;         if (i * j < tot) j++;         if (i >= a && j >= b) {           if (i * j >= tot && i * j <= ans) {             ans = i * j;             na = i;             nb = j;           }         }       }       if (swp) swap(na, nb);       cout << na * nb <<   n  << na <<     << nb <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   char buf[1 << 23], *p1 = buf, *p2 = buf;   template <typename T>   inline void read(T &x) {     x = 0;     register char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (!(ch >= 48 && ch <= 57))       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     while ((ch >= 48 && ch <= 57)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   }  // namespace IO   using namespace IO;   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   struct ALTXDY {     int tp, t, x, y, id;     bool operator<(ALTXDY const &a) const {       return x == a.x ? tp < a.tp : x < a.x;     }   };   ALTXDY q[N << 1];   int n, m, k, tot, rt, bus[N], ans[N], c[N << 1], dat[N << 2], ls[N << 2],       rs[N << 2];   void update(int &i, int l, int r, int x, int k) {     if (!i) i = ++tot;     if (bus[dat[i]] < bus[k]) dat[i] = k;     if (l == r) return;     int mid = (l + r) >> 1;     if (x <= mid)       update(ls[i], l, mid, x, k);     else       update(rs[i], mid + 1, r, x, k);   }   int query(int i, int l, int r, int x, int y, int val) {     if (l == r) return dat[i];     int mid = (l + r) >> 1, t = -1;     if (x <= mid && ls[i] && bus[dat[ls[i]]] >= val)       t = query(ls[i], l, mid, x, y, val);     if (t == -1 && y >= mid + 1 && rs[i] && bus[dat[rs[i]]] >= val)       t = query(rs[i], mid + 1, r, x, y, val);     return t;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) {       int s, f, t;       read(s, f, t);       q[i] = (ALTXDY){0, t, s, f, i};       c[++k] = t;       bus[i] = f;     }     for (int i = 1; i <= m; i++) {       int b, l, r;       read(l, r, b);       q[i + n] = (ALTXDY){1, b, l, r, i};       c[++k] = b;     }     sort(c + 1, c + 1 + k);     k = unique(c + 1, c + 1 + k) - c - 1;     for (int i = 1; i <= n + m; i++)       q[i].t = lower_bound(c + 1, c + 1 + k, q[i].t) - c;     sort(q + 1, q + 1 + n + m);     for (int i = 1; i <= n + m; i++)       if (q[i].tp == 0)         update(rt, 1, k, q[i].t, q[i].id);       else         ans[q[i].id] = query(rt, 1, k, q[i].t, k, q[i].y);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   double am, vm2, d, tant, ti, vm, t, s, daux, tfin;   int main() {     scanf( %d %lf %lf , &n, &am, &d);     tant = 0;     for (i = 0; i < n; i++) {       scanf( %lf %lf , &ti, &vm);       t = (vm / am);       s = 0.5 * (vm * vm / am);       daux = d - s;       if (daux < 0) {         vm2 = sqrt(2 * d * am);         tfin = vm2 / am;         tfin += ti;       } else {         tfin = daux / vm;         tfin += (ti + t);       }       if (tfin > tant) {         tant = tfin;       }       printf( %.10lf n , tant);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   const int L = (1 << 20) + 1;   char buf[L], *S, *T, c;   char getchar() {     if (__builtin_expect(S == T, 0)) {       T = (S = buf) + fread(buf, 1, L, stdin);       return (S == T ? EOF : *S++);     }     return *S++;   }   int inp() {     int x = 0, f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   unsigned inpu() {     unsigned x = 0;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       ;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x;   }   long long inp_ll() {     long long x = 0;     int f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   char B[25], *outs = B + 20, *outr = B + 20;   template <class T>   inline void print(register T a, register char x = 0) {     if (x) *--outs = x, x = 0;     if (!a)       *--outs =  0 ;     else       while (a) *--outs = (a % 10) + 48, a /= 10;     if (x) *--outs = x;     fwrite(outs, outr - outs, 1, stdout);     outs = outr;   }   };  // namespace io   using io ::inp;   using io ::inp_ll;   using io ::inpu;   using io ::print;   using i32 = int;   using i64 = long long;   using u8 = unsigned char;   using u32 = unsigned;   using u64 = unsigned long long;   using f64 = double;   using f80 = long double;   long long power(long long a, long long b, long long p) {     if (!b) return 1;     long long t = power(a, b / 2, p);     t = t * t % p;     if (b & 1) t = t * a % p;     return t;   }   template <class T>   inline void freshmin(T &a, const T &b) {     if (a > b) a = b;   }   template <class T>   inline void freshmax(T &a, const T &b) {     if (a < b) a = b;   }   const int MAXN = 510;   const int MAXP = 10000000;   const u64 MOD = 1000000007;   const f80 MI = f80(1) / MOD;   const long long INF = 10000000000000000LL;   const long long inf = 5000000000000LL;   int n;   struct node {     long long a, b, k;     void init() { scanf( %lld%lld%lld , &a, &b, &k); }     bool operator<(const node &A) const { return b > A.b; }   } p[MAXN];   long long F[MAXN][MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) p[i].init();     sort(p + 1, p + n + 1);     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= i; ++j) {         F[i][j] = F[i - 1][j] + max(p[i].a - p[i].b * p[i].k, 0LL);         if (j) freshmax(F[i][j], F[i - 1][j - 1] + p[i].a - p[i].b * (j - 1));       }     cout << *max_element(F[n], F[n] + n + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 5;   long long gcd(long long n, long long m) {     if (n == 0)       return m;     else       return gcd(m % n, n);   }   long long a[105], b[105];   vector<pair<long long, long long> > v1, v2;   long long dp[103][60000];   long long go(long long pos, long long r) {     if (r < 0) return -MOD;     if (pos == v2.size()) {       return 0;     }     long long &ans = dp[pos][r];     if (ans != -1) return ans;     ans = go(pos + 1, r);     if (r >= a[v2[pos].second]) {       ans = max(ans, go(pos + 1, r + b[v2[pos].second]) + 1);     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, r;     cin >> n >> r;     for (long long i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (b[i] >= 0) {         v1.push_back({a[i], b[i]});       } else {         v2.push_back({-(a[i] + b[i]), i});       }     }     memset(dp, -1, sizeof(dp));     if (v1.size() > 0) {       sort(v1.begin(), v1.end());       long long ans = 0;       for (long long i = 0; i < v1.size(); i++) {         if (r >= v1[i].first) {           r += v1[i].second;           ans++;         }       }       if (v2.size() == 0) {         cout << ans << endl;         return 0;       }       sort(v2.begin(), v2.end());       long long k = go(0, r);       cout << ans + k << endl;     } else {       sort(v2.begin(), v2.end());       cout << go(0, r) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   long long f[N][2], down[N], g[N], h[N], a[N];   vector<int> e[N];   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   inline void DFS(int u, int par) {     f[u][0] = f[u][1] = down[u] = g[u] = a[u];     for (unsigned i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == par) continue;       DFS(v, u);       chkmax(f[u][0], f[v][0]);       chkmax(f[u][0], f[u][1] + f[v][1]);       chkmax(f[u][0], down[u] + g[v]);       chkmax(f[u][0], down[v] + g[u]);       chkmax(f[u][1], f[v][1]);       chkmax(f[u][1], down[u] + down[v]);       chkmax(g[u], g[v] + a[u]);       chkmax(g[u], down[u] + f[v][1]);       chkmax(g[u], down[v] + a[u] + h[u]);       chkmax(h[u], f[v][1]);       chkmax(down[u], a[u] + down[v]);     }   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i < n; ++i) {       int u, v;       read(u);       read(v);       e[u].push_back(v);       e[v].push_back(u);     }     DFS(1, 0);     printf( %lld n , f[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, i, j, k, l, x, y;   int a[200010];   struct node {     int i;   };   bool operator<(node x, node y) { return a[x.i] < a[y.i]; }   multiset<node> S;   multiset<node>::iterator p, p2;   int li[200010];   vector<pair<int, int> > v;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) S.insert((node){i});     while (!S.empty()) {       if (a[(*S.begin()).i] == 0) {         S.erase(S.begin());         continue;       }       p = --S.end();       x = (*p).i;       S.erase(p);       for (li[0] = 0; a[x]; a[x]--)         if (S.empty())           return puts( No ), 0;         else {           p2 = --S.end();           y = (*p2).i;           S.erase(p2);           li[++li[0]] = y;           a[y]--;           v.push_back(make_pair(x, y));         }       for (; li[0]; li[0]--) S.insert((node){li[li[0]]});     }     if (S.empty()) {       printf( Yes n );       printf( %d n , s / 2);       for (int k = 0; k < v.size(); k++)         printf( %d %d n , v[k].first, v[k].second);     } else       printf( No n );     scanf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int read() {     char ch =    ;     int x = 0;     bool flag = false;     while (!isdigit(ch)) {       if (ch ==  - ) flag = true;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return flag ? -x : x;   }   struct heap {     vector<pair<int, int> > v;     int loc[N];     heap() {       v.push_back(make_pair(-1, -1));       memset(loc, -1, sizeof loc);     }     void push(pair<int, int> p) {       int cur;       cur = v.size();       loc[p.second] = cur;       v.push_back(p);       while (v[cur] < v[cur >> 1]) {         swap(v[cur], v[cur >> 1]);         swap(loc[v[cur].second], loc[v[cur >> 1].second]);         cur >>= 1;       }     }     void pop() {       if (empty()) return;       swap(v[1], v.back());       loc[v[1].second] = 1;       loc[v.back().second] = -1;       v.pop_back();       int cur = 1;       while ((cur << 1) < v.size()) {         if ((cur << 1) + 1 == v.size()) {           if (v[cur] > v[cur << 1])             swap(v[cur], v[cur << 1]),                 swap(loc[v[cur].second], loc[v[cur << 1].second]);           break;         }         if (v[cur] < min(v[cur << 1], v[(cur << 1) + 1])) break;         if (v[cur << 1] < v[(cur << 1) + 1]) {           swap(v[cur], v[cur << 1]);           swap(loc[v[cur].second], loc[v[cur << 1].second]);           cur <<= 1;         } else {           swap(v[cur], v[(cur << 1) + 1]);           swap(loc[v[cur].second], loc[v[(cur << 1) + 1].second]);           cur = (cur << 1) + 1;         }       }     }     pair<int, int> top() { return v[1]; }     bool empty() { return v.size() == 1; }   };   int n, m;   vector<int> bad[N];   vector<pair<int, int> > v[N];   int d[N];   heap pq;   int main() {     n = read(), m = read();     for (int i = 0; i < m; i++) {       int a = read(), b = read(), c = read();       --a, --b;       v[a].push_back(make_pair(b, c));       v[b].push_back(make_pair(a, c));     }     for (int i = 0; i < n; i++) {       int num = read();       while (num--) {         bad[i].push_back(read());       }     }     for (int i = 0; i < n; i++) d[i] = 0x3f3f3f3f;     d[0] = 0;     pq.push(make_pair(0, 0));     while (!pq.empty()) {       pair<int, int> tp = pq.top();       pq.pop();       int t = tp.first;       int cur = tp.second;       if (t != d[cur]) continue;       int j = 0;       while (j < bad[cur].size() && bad[cur][j] < t) j++;       while (j < bad[cur].size() && bad[cur][j] == t) t++, j++;       for (int i = 0; i < v[cur].size(); i++) {         int to = v[cur][i].first, cost = v[cur][i].second;         if (t + cost < d[to]) {           d[to] = t + cost;           pq.push(make_pair(d[to], to));         }       }     }     if (d[n - 1] >= 0x3f3f3f3f)       puts( -1 );     else       cout << d[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int atoi(string s) {     int sol = 0, st = 1;     for (int i = 0; i < int(s.size()); i++) {       sol += (s[i] - 48) * st;       st *= 10;     }     return sol;   }   int main() {     string a, b;     cin >> a >> b;     reverse(a.begin(), a.end());     cout << atoi(a) + atoi(b) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 1001005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   int p[N], prime[N], phi[N], top, T, X, P, K, pp[N];   long long l, r, mid, ans;   void init_prime(int N) {     top = 0, phi[1] = 1;     for (int i = 2; i <= N; ++i) {       if (!p[i]) prime[++top] = i, phi[i] = i - 1;       for (int j = 1; j <= top; ++j) {         if ((long long)i * prime[j] > N) break;         p[i * prime[j]] = 1;         if (i % prime[j] == 0) {           phi[i * prime[j]] = phi[i] * prime[j];           break;         }         phi[i * prime[j]] = phi[i] * phi[prime[j]];       }     }   }   void init(int x) {     pp[0] = 0;     for (int i = 1; i <= top && (long long)prime[i] * prime[i] <= x; i++)       if (x % prime[i] == 0) {         pp[++pp[0]] = prime[i];         while (x % prime[i] == 0) x /= prime[i];         if (x == 1) return;         if (!p[x]) {           pp[++pp[0]] = x;           return;         }       }     if (x > 1) pp[++pp[0]] = x;   }   void dfs(int k, int op, long long s, long long n, long long &ans) {     if (k > pp[0]) {       ans += n / s * op;       return;     }     dfs(k + 1, op, s, n, ans);     if (s * pp[k] <= n) dfs(k + 1, -op, s * pp[k], n, ans);   }   long long Count(long long x) {     long long ans = 0;     dfs(1, 1, 1, x % P, ans);     return x / P * phi[P] + ans;   }   int main() {     scanf( %d , &T);     init_prime(N - 5);     while (T--) {       scanf( %d%d%d , &X, &P, &K), init(P);       K += Count(X), l = 1, r = 1e8;       while (l <= r) {         mid = (l + r) >> 1;         if (Count(mid) >= K)           ans = mid, r = mid - 1;         else           l = mid + 1;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(long long x, long long y) { return x > y; }   int main() {     long long n;     cin >> n;     string S;     cin >> S;     vector<long long> C;     for (long long i = 0; i < n; i++) {       long long x = S[i] -  0 ;       if (x == 0 || x == 1)         continue;       else if (x == 2)         C.push_back(2);       else if (x == 3)         C.push_back(3);       else if (x == 4)         C.push_back(2), C.push_back(2), C.push_back(3);       else if (x == 5)         C.push_back(5);       else if (x == 6)         C.push_back(5), C.push_back(3);       else if (x == 7)         C.push_back(7);       else if (x == 8)         C.push_back(7), C.push_back(2), C.push_back(2), C.push_back(2);       else if (x == 9)         C.push_back(7), C.push_back(3), C.push_back(3), C.push_back(2);     }     sort(C.begin(), C.end(), cmp);     for (auto it : C) cout << it;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     char c = getchar();     while (c <  0  ||  9  < c) c = getchar();     while ( 0  <= c && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return x;   }   int p[200000 + 5];   int tp, stk[200000 + 5];   int U[200000 + 5], V[200000 + 5];   map<pair<int, int>, bool> Map;   int main() {     int n = read(), m = read();     for (int i = 1; i <= m; i++) {       U[i] = read(), V[i] = read();       Map[make_pair(U[i], V[i])] = 1;       Map[make_pair(V[i], U[i])] = 1;     }     for (int i = 1; i <= n; i++) p[i] = i;     for (int t = 100; t >= 0; t--) {       random_shuffle(p + 1, p + n + 1);       p[n + 1] = p[1];       tp = 0;       for (int i = 1; i <= n && tp < m; i++)         if (!Map.count(make_pair(p[i], p[i + 1]))) stk[++tp] = i;       if (tp == m) {         for (int i = 1; i <= m; i++) printf( %d %d n , p[stk[i]], p[stk[i] + 1]);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   #pragma GCC optimize  -O3    long long INF = (long long)1e20;   int iINF = (int)1e20;   long long mod = 1e9 + 7;   long long mult(long long a, long long b) {     if (a == 0) return 0;     if (a == 1) return (b % mod);     if (a % 2) {       long long kek = mult(a / 2, b) % mod;       kek *= 2;       kek %= mod;       kek += b;       kek %= mod;       return kek;     } else {       long long kek = mult(a / 2, b) % mod;       kek *= 2;       kek %= mod;       return kek;     }   }   long long f(long long r) {     long long odd = 0, even = 0;     long long now = 1;     bool chet = false;     while (r > 0) {       long long num = min(r, now);       if (chet)         even += num;       else         odd += num;       r -= now;       now *= 2;       chet = !chet;     }     return (mult(odd, odd) + mult(even, even) + even) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long l, r;     cin >> l >> r;     cout << (f(r) - f(l - 1) + mod) % mod;   }


#include <bits/stdc++.h>   int in[301];   int c[301];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , in + i);     for (i = 1; i <= n; i++) scanf( %d , c + i);     for (i = 1; i <= n; i++) {       for (j = 2; j * j <= in[i]; j++) {         if (in[i] % j == 0) {           while (in[i] % j == 0) in[i] /= j;           in[i] *= j;         }       }     }     std::map<int, int> dp, dt;     dp[0] = 0;     for (i = 1; i <= n; i++) {       for (auto t : dp) {         int xx = gcd(t.first, in[i]);         int xy = t.second + c[i];         if (dp.count(xx) == 0 || dp[xx] > xy) {           if (dt.count(xx) == 0 || dt[xx] > xy) dt[xx] = xy;         }       }       for (auto t : dt) {         dp[t.first] = t.second;       }       dt.clear();     }     if (dp.count(1) == 0)       printf( -1 );     else       printf( %d , dp[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int n = 0;     bool f = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       n = (n << 1) + (n << 3) + (c ^ 48);       c = getchar();     }     return f ? -n : n;   }   int r, c, n, t, x, y, ans, res;   bool m[101][101];   int main() {     r = read(), c = read(), n = read(), t = read();     for (int i = 1; i <= n; i++) {       x = read(), y = read();       m[x][y] = 1;     }     for (int i = 1; i <= r; i++)       for (int j = 1; j <= c; j++)         for (int k = i; k <= r; k++)           for (int h = j; h <= c; h++) {             res = 0;             for (int a = i; a <= k; a++)               for (int b = j; b <= h; b++)                 if (m[a][b]) res++;             if (res >= t) ans++;           }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool umax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   long long POW(long long a, long long p, long long M) {     if (!p) return 1LL;     long long T = POW(a, p / 2, M);     T = T * T % M;     if (p & 1) T = T * (a % M) % M;     return T;   }   long long SQRT(long long a) {     long long b = (long long)sqrtl(((double)a) + 0.5);     while (b * b < a) ++b;     while (b * b > a) --b;     return (b * b == a) ? b : -1;   }   const long long MOD = 1e9 + 7;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long n, m;     cin >> n >> m;     if (n == 1) {       cout << 0 << endl;       return 0;     }     vector<vector<long long>> guess(n + 1);     long long f = 0;     long long N = 2e5;     long long fq[4 * N];     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[N + i] = 1;     for (long long i = 1; i <= n; i++) {       long long mx = min(n, i + m + 1);       f += 2 * (mx - i + 1) - 1;     }     long long st;     for (long long i = 1; i <= m; i++) {       long long a;       cin >> a;       guess[a].push_back(i);     }     for (long long i = 1; i <= n; i++) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i - ss; k >= i - guess[i][j - 1]; --k) {             long long org = min(n, k + m + 1);             long long wt = min(n, k + m - (guess[i][j - 1] + (k - i) + 1) + 1);             f -= fq[N + k] * (org - wt);             ct += fq[N + k];             fq[N + k] = 0;           }           fq[N + i - guess[i][j - 1] - 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     memset(fq, 0, sizeof(fq));     for (long long i = 1; i <= n; i++) fq[i] = 1;     for (long long i = n; i >= 1; i--) {       if (guess[i].empty()) continue;       long long ss = guess[i][0];       for (long long j = 1; j <= guess[i].size(); ++j) {         if (j < guess[i].size() && guess[i][j] == guess[i][j - 1] + 1)           continue;         else {           long long ct = 0;           for (long long k = i + ss; k <= i + guess[i][j - 1]; ++k) {             long long org = max(1LL, k - m - 1);             long long wt = max(1LL, k - m + (guess[i][j - 1] - (k - i) + 1) - 1);             f -= fq[k] * (wt - org);             ct += fq[k];             fq[k] = 0;           }           fq[i + guess[i][j - 1] + 1] += ct;           if (j < guess[i].size()) ss = guess[i][j];         }       }     }     cout << f << endl;     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   inline bool check2(long long x, long long y3) {     return (x * x + y3 * y3 * 3 <= n * n);   }   inline bool check(long long x, long long y3) {     return check2(x - 2, y3) & check2(x - 1, y3 - 1) & check2(x + 1, y3 - 1) &            check2(x + 2, y3) & check2(x + 1, y3 + 1) & check2(x - 1, y3 + 1);   }   long long calc(long long x, long long d) {     long long l = 0, r = 3e6;     while (l < r) {       long long mid = (l + r + 1) / 2;       long long y3 = d + mid * 2;       if (check(x, y3))         l = mid;       else         r = mid - 1;     }     long long ret = r * 2;     if (d == 0 && check(x, 0)) ret += 1;     if (d == 1 && check(x, d)) ret += 2;     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     n *= 2;     long long s = 0;     int x = 3, d = 1;     while (true) {       long long t = calc(x, d);       if (t == 0) break;       s += t;       x += 3, d ^= 1;     }     s *= 2;     s += calc(0, 0);     cout << s << endl;   }


#include <bits/stdc++.h>   inline int getint() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register int x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   const long long mod = 1e9 + 7;   const int N = 150001, M = 150002, K = 100001;   void exgcd(const long long &a, const long long &b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   inline long long inv(const long long &x) {     long long tmp, ret;     exgcd(x, mod, ret, tmp);     return (ret + mod) % mod;   }   long long f[2][M];   long long p[M], q[M];   long long fact[K], tcaf[K];   int k;   inline long long calc(const int &x) {     return fact[k] * tcaf[k - x] % mod * tcaf[x] % mod * p[x] % mod * q[k - x] %            mod;   }   signed main() {     int n = getint(), m = getint();     long long a = getint(), b = getint();     k = getint();     fact[0] = 1;     for (register int i = 1; i <= k; i++) {       fact[i] = fact[i - 1] * i % mod;     }     tcaf[k] = inv(fact[k]);     for (register int i = k - 1; ~i; i--) {       tcaf[i] = tcaf[i + 1] * (i + 1) % mod;     }     p[0] = q[0] = 1;     p[1] = a * inv(b) % mod;     q[1] = (b - a) * inv(b) % mod;     for (register int i = 2; i <= k; i++) {       p[i] = p[i - 1] * p[1] % mod;       q[i] = q[i - 1] * q[1] % mod;     }     f[0][m] = 1;     for (register int i = 1; i <= n; i++) {       long long s1 = 0, s2 = 0;       for (register int j = 0; j <= m; j++) {         f[i & 1][j] = (s1 * (f[!(i & 1)][m] - f[!(i & 1)][m - j]) - s2) % mod *                       calc(m - j) % mod;         s1 = (s1 + calc(j)) % mod;         s2 = (s2 + f[!(i & 1)][j] * calc(j)) % mod;       }       for (register int j = 1; j <= m; j++) {         f[i & 1][j] = (f[i & 1][j] + f[i & 1][j - 1]) % mod;       }     }     printf( %I64d n , (f[n & 1][m] + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, t = 1;     register char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = -1, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return x * t;   }   struct Line {     int v, next;   };   struct Link {     Line e[444444 << 1];     int h[444444], cnt;     void Add(int u, int v) {       e[++cnt] = (Line){v, h[u]};       h[u] = cnt++;       e[++cnt] = (Line){u, h[v]};       h[v] = cnt++;     }   } Gr, Tr;   multiset<int> MS[444444];   int W[444444];   int n, m, Q, Tot;   struct Graph {     int dfn[444444], low[444444], S[444444], tim, top;     void Tarjan(int u) {       dfn[u] = low[u] = ++tim;       S[++top] = u;       for (int i = Gr.h[u]; i; i = Gr.e[i].next) {         int v = Gr.e[i].v;         if (!dfn[v]) {           Tarjan(v);           low[u] = min(low[u], low[v]);           if (low[v] >= dfn[u]) {             Tr.Add(++Tot, u);             int x;             do {               x = S[top--];               Tr.Add(Tot, x);             } while (v != x);           }         } else           low[u] = min(low[u], dfn[v]);       }     }   } G;   struct SegMentTree {     int t[444444 << 2];     void Modify(int now, int l, int r, int p, int w) {       if (l == r) {         t[now] = w;         return;       }       int mid = (l + r) >> 1;       if (p <= mid)         Modify((now << 1), l, mid, p, w);       else         Modify((now << 1 | 1), mid + 1, r, p, w);       t[now] = min(t[(now << 1)], t[(now << 1 | 1)]);     }     int Query(int now, int l, int r, int L, int R) {       if (L <= l && r <= R) return t[now];       int ret = 1e9, mid = (l + r) >> 1;       if (L <= mid) ret = min(ret, Query((now << 1), l, mid, L, R));       if (R > mid) ret = min(ret, Query((now << 1 | 1), mid + 1, r, L, R));       return ret;     }   } SMT;   int fa[444444], tim, dfn[444444], low[444444];   int size[444444], hson[444444], top[444444], dep[444444];   void dfs1(int u, int ff) {     fa[u] = ff;     dep[u] = dep[ff] + 1;     size[u] = 1;     if (u <= n && ff) MS[ff].insert(W[u]);     for (int i = Tr.h[u]; i; i = Tr.e[i].next) {       int v = Tr.e[i].v;       if (v == ff) continue;       dfs1(v, u);       size[u] += size[v];       if (size[v] > size[hson[u]]) hson[u] = v;     }   }   void dfs2(int u, int tp) {     top[u] = tp;     dfn[u] = ++tim;     low[tim] = u;     if (hson[u]) dfs2(hson[u], tp);     for (int i = Tr.h[u]; i; i = Tr.e[i].next)       if (Tr.e[i].v != fa[u] && Tr.e[i].v != hson[u]) dfs2(Tr.e[i].v, Tr.e[i].v);   }   int Query(int u, int v) {     int ret = 1e9;     while (top[u] ^ top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       ret = min(ret, SMT.Query(1, 1, Tot, dfn[top[u]], dfn[u]));       u = fa[top[u]];     }     if (dep[u] > dep[v]) swap(u, v);     ret = min(ret, SMT.Query(1, 1, Tot, dfn[u], dfn[v]));     if (u <= n)       return ret;     else       return min(ret, W[fa[u]]);   }   void Modify(int u, int w) {     if (fa[u]) {       MS[fa[u]].erase(MS[fa[u]].find(W[u]));       MS[fa[u]].insert(w);       SMT.Modify(1, 1, Tot, dfn[fa[u]], *MS[fa[u]].begin());     }     W[u] = w;     SMT.Modify(1, 1, Tot, dfn[u], w);   }   int main() {     Tot = n = read();     m = read();     Q = read();     W[0] = 1e9;     for (int i = 1; i <= n; ++i) W[i] = read();     for (int i = 1; i <= m; ++i) Gr.Add(read(), read());     G.Tarjan(1);     dfs1(1, 0);     dfs2(1, 1);     for (int i = 1; i <= n; ++i) SMT.Modify(1, 1, Tot, dfn[i], W[i]);     for (int i = n + 1; i <= Tot; ++i)       SMT.Modify(1, 1, Tot, dfn[i], *MS[i].begin());     char ch[2];     while (Q--) {       scanf( %s , ch);       int a = read(), b = read();       if (ch[0] ==  C )         Modify(a, b);       else         printf( %d n , Query(a, b));     }     return 0;   }