#include <bits/stdc++.h>   using namespace std;   const int maxn = 510000;   char s[maxn];   int n, maxtime;   int house;   bool ok(int need) {     int time = 0, candy = need, total = house;     int p = 0, q = 0;     int i;     for (i = 0; i < n; i++) {       p += (s[i] ==  H );       q += (s[i] ==  S );       if (p == total && (q + need) >= house) break;     }     if (!(p == total && (q + need) >= house)) return 0;     if (2 * (i + 1) - 1 <= maxtime) return 1;     for (int i = 0; i < n; i++) {       if (!total) return time <= maxtime;       if (++time > maxtime) return 0;       if (s[i] ==  S ) {         candy++;       } else if (s[i] ==  H ) {         if (candy) {           candy--;           total--;           continue;         }         int h2 = 0, k = 0, j;         for (j = i; j < n; j++) {           if (s[j] ==  H )             k++, h2++;           else if (s[j] ==  S )             k--, s[j] =  . ;           if (k == 0) break;         }         if (k) return 0;         time += 2 * (j - i);         time--;         candy += h2;         i--;       }     }     return time <= maxtime;   }   char str[maxn];   int main() {     while (scanf( %d%d , &n, &maxtime) != EOF) {       scanf( %s , str);       house = 0;       for (int i = 0; i < n; i++) {         house += (str[i] ==  H );       }       int l = 0, r = n;       int ans = -1;       while (l <= r) {         int m = (l + r) >> 1;         memcpy(s, str, sizeof s);         if (ok(m)) {           r = m - 1;           ans = m;         } else           l = m + 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a[200], b[200];     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int j;     for (int i = 0; i < n; i++) {       for (j = 1; j < n; j++) {         if ((a[i] - b[0] + m) % m != (a[(j + i) % n] - b[j] + m) % m) break;       }       if (j == n) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   struct business {     int num;     int dif;   };   bool compare(business x, business y) { return (x.dif < y.dif); }   int main() {     int n;     int x;     cin >> n;     vector<business> A(n + 1);     for (int i = 1; i <= n; i++) {       cin >> x;       A[i].num = i;       A[i].dif = x;     }     sort(A.begin(), A.end(), compare);     int triple = 0, p1 = 0, p2 = 0;     for (int i = 1; i < n; i++) {       if (A[i].dif == A[i + 1].dif)         if (p1 == 0) {           p1 = i;           if (i <= n - 2)             if (A[i + 1].dif == A[i + 2].dif) {               triple = i;               break;             }         } else {           p2 = i;           if (i <= n - 2)             if (A[i + 1].dif == A[i + 2].dif) triple = i;           break;         }     }     if ((triple == 0) && (p2 == 0))       cout <<  NO n ;     else {       cout <<  YES n ;       if (triple != 0) {         for (int i = 1; i <= n; i++) cout << A[i].num <<    ;         cout << endl;         for (int i = 1; i <= n; i++) {           if (i == triple) {             cout << A[i].num <<     << A[i + 2].num <<     << A[i + 1].num <<    ;             i += 2;           } else             cout << A[i].num <<    ;         }         cout << endl;         for (int i = 1; i <= n; i++) {           if (i == triple) {             cout << A[i + 2].num <<     << A[i + 1].num <<     << A[i].num <<    ;             i += 2;           } else             cout << A[i].num <<    ;         }         cout << endl;       } else {         for (int i = 1; i <= n; i++) cout << A[i].num <<    ;         cout << endl;         for (int i = 1; i <= n; i++) {           if (i == p1) {             cout << A[i + 1].num <<     << A[i].num <<    ;             i++;           } else             cout << A[i].num <<    ;         }         cout << endl;         for (int i = 1; i <= n; i++) {           if (i == p2) {             cout << A[i + 1].num <<     << A[i].num <<    ;             i++;           } else             cout << A[i].num <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     string s;     cin >> n;     cin >> s;     vector<long long> cnts(60, 0);     long long k = 0;     for (long long i = 0; i < n; i++) {       if (cnts[s[i] - 65] == 0) k++;       cnts[s[i] - 65]++;     }     for (long long i = 0; i < 60; i++) cnts[i] = 0;     long long l = 0;     long long r = -1;     long long res = 100001;     long long cnt = 0;     while (r < n) {       if (cnt < k) {         r++;         if (r == n) break;         cnts[s[r] - 65]++;         if (cnts[s[r] - 65] == 1) cnt++;       } else if (cnt == k) {         res = min(res, r - l + 1);         cnts[s[l] - 65]--;         if (cnts[s[l] - 65] == 0) cnt--;         l++;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string Scale, left, right, rest_elements;     int Slash;     cin >> Scale;     Slash = Scale.find( | );     left = Scale.substr(0, Slash);     right = Scale.substr(Slash + 1, Scale.size());     cin >> rest_elements;     for (auto i : rest_elements)       if (left.size() <= right.size())         left += i;       else         right += i;     cout << (left.size() == right.size() ? left +  |  + right :  Impossible )          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 50050;   vector<int> e[MAX];   vector<int> ee[MAX];   int c[MAX][555];   int vis[MAX];   int n, k;   void solve(int indx) {     c[indx][0] = 1;     vis[indx] = 1;     for (int i = 0; i < e[indx].size(); i++) {       if (vis[e[indx][i]] == 1) continue;       int cindx = e[indx][i];       ee[indx].push_back(cindx);       solve(cindx);       for (int j = 0; j <= k; j++) {         if (c[cindx][j] == 0) break;         c[indx][j + 1] += c[cindx][j];       }     }   }   long long solve1() {     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long ret = 0;       for (int j = 0; j < ee[i].size(); j++) {         for (int K = 1; K < k; K++) {           long long first = 0, second = 0;           first = c[ee[i][j]][K - 1];           second = c[i][k - K] - c[ee[i][j]][k - K - 1];           ret += (first * second);         }       }       ans += ret / 2;       ans += c[i][k];     }     return ans;   }   int main() {     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     solve(1);     cout << solve1() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007ll;   vector<int> adj[100005];   vector<pair<int, int> > grop[100005];   int now;   int weig[100005];   int bu[100005];   int flag[100005];   pair<int, int> dfs(int u) {     if (flag[u]) return make_pair(0, 0);     flag[u] = 1;     pair<int, int> res = make_pair(0, 0);     for (int i = 0; i < adj[u].size(); i++) {       pair<int, int> tem = dfs(adj[u][i]);       res.first += tem.first;       res.second += tem.second;     }     res.first += weig[u];     res.second += bu[u];     grop[now].push_back(make_pair(weig[u], bu[u]));     return res;   }   long long dp[100005];   int main() {     int n, m, w;     scanf( %d %d %d , &n, &m, &w);     for (int i = 1; i <= n; i++) scanf( %d , &weig[i]);     for (int i = 1; i <= n; i++) scanf( %d , &bu[i]);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       if (flag[i]) continue;       now++;       pair<int, int> tem = dfs(i);       grop[now].push_back(tem);     }     for (int i = 1; i <= now; i++) {       for (int j = w; j > 0; j--) {         for (int k = 0; k < grop[i].size(); k++) {           if (grop[i][k].first > j) continue;           dp[j] = max(dp[j], grop[i][k].second + dp[j - grop[i][k].first]);         }       }     }     long long res = 0;     for (int i = 0; i <= w; i++) res = max(res, dp[i]);     printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char ch = getchar();     bool f = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   void writep(long long x) {     write(x);     putchar(   );   }   const int N = 100005;   int n, S[N], a[N], top;   char s[N];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = (int)(1); i <= (int)(n); i++) {       if (s[i] ==  + )         a[i] = 1;       else         a[i] = 0;     }     for (int i = (int)(1); i <= (int)(n); i++) {       S[++top] = a[i];       if (top > 1 && S[top - 1] == a[i]) top -= 2;     }     if (top)       puts( No );     else       puts( Yes );   }


#include <bits/stdc++.h>   using namespace std;   struct MCMF {     using F = int;     const static F INF = 0x3f3f3f3f;     struct Edge {       int v, bro;       F cap, cost;       Edge() {}       Edge(int _v, int _bro, F _cap, F _cost)           : v(_v), bro(_bro), cap(_cap), cost(_cost) {}     };     vector<Edge> e;     vector<int> pos, pre;     vector<F> dis;     vector<bool> trk;     int n, s, t, m;     MCMF(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {       pos.assign(n, -1);       pre.resize(n);       dis.resize(n);       trk.resize(n);       e.reserve(4e5);     }     void add(int u, int v, F cap = INF, F cost = 0) {       assert(u < n && v < n);       e.emplace_back(v, pos[u], cap, cost);       pos[u] = m++;       e.emplace_back(u, pos[v], 0, -cost);       pos[v] = m++;     }     bool spfa() {       queue<int> q;       fill(pre.begin(), pre.end(), -1);       fill(dis.begin(), dis.end(), INF);       fill(trk.begin(), trk.end(), false);       dis[s] = 0;       trk[s] = true;       q.push(s);       while (!q.empty()) {         int u = q.front();         q.pop();         trk[u] = false;         for (int i = pos[u]; i != -1; i = e[i].bro) {           int v = e[i].v;           if (e[i].cap > 0 && dis[v] > dis[u] + e[i].cost) {             dis[v] = dis[u] + e[i].cost;             pre[v] = i;             if (!trk[v]) {               trk[v] = true;               q.push(v);             }           }         }       }       return pre[t] != -1;     }     pair<F, F> mcmf() {       F flow = 0, cost = 0;       while (spfa()) {         F f = INF;         for (int i = pre[t]; i != -1; i = pre[e[i ^ 1].v]) f = min(f, e[i].cap);         for (int i = pre[t]; i != -1; i = pre[e[i ^ 1].v]) {           e[i].cap -= f;           e[i ^ 1].cap += f;           cost += e[i].cost * f;         }         flow += f;       }       return {flow, cost};     }   };   void solve() {     int n1, n2, m, r, b;     cin >> n1 >> n2 >> m >> r >> b;     string s1, s2;     cin >> s1 >> s2;     int L = n1 + n2, R = L + 1;     int S = R + 1, T = S + 1;     MCMF g(T + 1, S, T);     vector<int> deg(S), demand(S);     for (int _ = 0; _ < m; _++) {       int x, y;       cin >> x >> y;       x--;       y--;       y += n1;       deg[x]++;       deg[y]++;       demand[x]++;       demand[y]--;       g.add(x, y, 1, r);       g.add(y, x, 1, b);     }     auto gg = []() {       cout << -1;       exit(0);     };     for (int i = 0; i < n1; i++) {       if (s1[i] !=  U  && deg[i] == 0) gg();       if (s1[i] ==  R ) {         g.add(L, i, deg[i] - 1);         demand[i] -= deg[i] + 1;         demand[L] += deg[i] + 1;       } else if (s1[i] ==  B ) {         g.add(L, i, deg[i] - 1);       } else {         g.add(L, i, deg[i] << 1);       }     }     for (int i = 0; i < n2; i++) {       int k = i + n1;       if (s2[i] !=  U  && deg[k] == 0) gg();       if (s2[i] ==  B ) {         g.add(k, R, deg[k] - 1);       } else if (s2[i] ==  R ) {         g.add(k, R, deg[k] - 1);         demand[k] += deg[k] + 1;         demand[R] -= deg[k] + 1;       } else {         g.add(k, R, deg[k] << 1);       }     }     g.add(R, L);     int sum = 0;     for (int i = 0; i < S; i++) {       if (demand[i] > 0) {         sum += demand[i];         g.add(i, T, demand[i]);       }       if (demand[i] < 0) {         g.add(S, i, -demand[i]);       }     }     int flow, cost;     tie(flow, cost) = g.mcmf();     if (flow < sum) gg();     cout << cost <<   n ;     for (int i = 0; i < m; i++) {       if (g.e[i * 4 + 1].cap) {         cout <<  R ;       } else if (g.e[i * 4 + 3].cap) {         cout <<  B ;       } else {         cout <<  U ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     ;     int n;     bool allSame = true;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i > 0 and a[i] != a[i - 1]) allSame = false;     }     sort(a, a + n);     if (n == 1) {       cout <<  -1 ;       return 0;     }     if (allSame) {       cout <<  1 n  << a[0];       return 0;     }     if (n == 2) {       if ((a[0] + a[1]) % 2 != 0)         cout <<  2 n  << a[0] - (a[1] - a[0]) <<     << a[1] + (a[1] - a[0]);       else         cout <<  3 n               << a[0] - (a[1] - a[0]) <<     << (a[0] + a[1]) / 2 <<                  << a[1] + (a[1] - a[0]);       return 0;     }     if (n == 3) {       int d1 = a[1] - a[0], d2 = a[2] - a[1];       if (d1 == d2) {         cout <<  2 n  << a[0] - d1 <<     << a[2] + d1;         return 0;       } else if (d1 == 2 * d2) {         cout <<  1 n  << a[0] + d1 / 2;         return 0;       } else if (2 * d1 == d2) {         cout <<  1 n  << a[1] + d2 / 2;         return 0;       }     }     set<int> uniq;     multiset<int> freq;     for (int i = 1; i < n; i++) {       uniq.insert(a[i] - a[i - 1]);       freq.insert(a[i] - a[i - 1]);     }     if (uniq.size() == 1) {       cout <<  2 n  << a[0] - *uniq.begin() <<     << a[n - 1] + *uniq.begin();       return 0;     } else if (uniq.size() == 2) {       int d1 = *uniq.begin();       int f1 = freq.erase(d1);       uniq.erase(d1);       int d2 = *uniq.begin();       int f2 = freq.erase(d2);       int d = f1 > f2 ? d1 : d2;       if (f1 > 1 and f2 > 1) {         cout <<  0 ;         return 0;       }       if (d1 == 0 or d2 == 0) {         cout <<  0 ;         return 0;       }       for (int i = 1; i < n; i++) {         if (a[i] - a[i - 1] == 2 * d) {           cout <<  1 n  << a[i - 1] + d;           return 0;         }       }     }     cout <<  0 ;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, k;   int main() {     ios_base::sync_with_stdio(0);     cin >> t;     while (t--) {       cin >> n >> k;       if (!n && !k)         cout << 0 <<   n ;       else         cout << 1440 - n * 60 - k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     if (k < 25) {       cout << -1 << endl;     } else {       int r = 0, c = 0;       for (int i = 5; i <= sqrt(k); i++) {         if (k % i == 0) {           r = i;           c = k / i;           break;         }       }       if (r == 0 or c == 0) {         cout << -1 << endl;       } else {         char ch[] = { a ,  e ,  i ,  o ,  u };         string fr =   ;         for (int j = 0; j < r; j++) {           for (int i = 0; i < c; i++) {             fr += ch[(j + i) % 5];           }         }         cout << fr << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     int cnt = 0;     if (n >= 5) {       int x = n / 5;       cnt += x;       n -= x * 5;     }     if (n == 0)       cout << cnt;     else       cout << cnt + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s1, s2, s3, s4;     cin >> s1 >> s2 >> s3 >> s4;     unordered_set<int> s;     s.insert(s1);     s.insert(s2);     s.insert(s3);     s.insert(s4);     int si = s.size();     if (si == 4)       cout << 0;     else if (si == 3)       cout << 1;     else if (si == 2)       cout << 2;     else       cout << 3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sort_1(pair<int, int> &a, pair<int, int> &b) { return a.first < b.first; }   bool sort_2(pair<int, int> &a, pair<int, int> &b) { return a.first > b.first; }   int main() {     int n, cnt = 0;     scanf( %d , &n);     vector<vector<pair<int, int>>> a(1001);     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       a[x / 1000].push_back(make_pair(y, i + 1));     }     bool b = true;     for (int i = 0; i < 1001; ++i) {       if (b)         sort(a[i].begin(), a[i].end(), sort_1);       else         sort(a[i].begin(), a[i].end(), sort_2);       b = !b;     }     for (int i = 0; i < 1001; ++i) {       for (int j = 0; j < a[i].size(); ++j) printf( %d  , a[i][j].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int h, l;     std::cin >> h >> l;     cout << fixed << setprecision(10);     std::cout << (1.0 * l / (2.0 * h) * l - 1.0 * h / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   long long r, n;   vector<int> degp[1000005];   long long answ[1000005][21];   long long m = 1000000007;   long long powmod(long long x, long long po) {     if (po == 0) {       return 1;     }     long long res = powmod(x, po / 2);     res = (res * res) % m;     if (po % 2 == 1) {       res = (res * x) % m;     }     return res;   }   int main() {     for (int i = 2; i <= 1000000; i++) {       if (degp[i].empty()) {         long long t = i;         long long u = 1;         while (t <= 1000000) {           for (int j = 1; j <= 1000000 / t; j++) {             if (j % i != 0) {               degp[t * j].push_back(u);             }           }           u++;           t = t * (long long)i;         }       }     }     for (int i = 0; i <= 1000000; i++) {       answ[i][0] = 1;     }     for (int i = 1; i < 21; i++) {       answ[0][i] = 2;       for (int j = 1; j <= 1000000; j++) {         answ[j][i] = (answ[j - 1][i] + answ[j][i - 1]) % m;       }     }     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %I64d%I64d , &r, &n);       long long res = 1;       for (int k = 0; k < degp[n].size(); k++) {         res = (res * answ[r][degp[n][k]]) % m;       }       printf( %I64d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   struct no {     int x, y, r;   };   no A, B, b, a;   int dist(no u, no v) {     return (u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y);   }   bool contido(no v, no u) {     if (u.r < v.r) return 0;     if ((sqrt(dist(v, u)) + (double)((v.r)) - 1e-2 < (double)(u.r))) return 1;     return 0;   }   bool disjunto(no v, no u) {     if (sqrt(dist(u, v)) > (double)(v.r + u.r) - 1e-2) return 1;     return 0;   }   int main() {     cin >> a.x >> a.y >> a.r >> A.r;     A.x = a.x, A.y = a.y;     cin >> b.x >> b.y >> b.r >> B.r;     B.x = b.x, B.y = b.y;     if (B.r < A.r) {       swap(B, A);       swap(a, b);     }     int ans;     if (contido(A, B)) {       if (contido(A, b))         ans = 4;       else if (contido(a, b) || contido(b, a))         ans = 2;       else if (disjunto(b, A))         ans = 2;       else         ans = 1;     } else if (disjunto(A, B)) {       ans = 4;     } else {       if (contido(a, b) || contido(b, a))         ans = 1;       else {         ans = 0;         if (disjunto(a, B)) ans++;         if (disjunto(b, A)) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int k;   set<pair<string, int> > st;   pair<string, int> tmp;   int main() {     cin >> s >> k;     for (int i = 0; i < (int)s.length(); i++) {       string q =   ;       q += s[i];       st.insert(make_pair(q, i));     }     while (k > 1 && (int)st.size() > 0) {       tmp = *st.begin();       st.erase(st.begin());       if (tmp.second + 1 < (int)s.length()) {         tmp.second++;         tmp.first += s[tmp.second];         st.insert(tmp);       }       k--;     }     if ((int)st.size() > 0) {       tmp = *st.begin();       cout << tmp.first << endl;       return 0;     }     cout <<  No such line.  << endl;     return 0;   }


#include <bits/stdc++.h>   int n, q, maxn;   int a[200005];   std::vector<int> v[1901][105];   inline void merge(std::vector<int> &v1, std::vector<int> &v2) {     if (v1.size() < v2.size()) std::swap(v1, v2);     v1.insert(v1.end(), v2.begin(), v2.end());     v2.clear();   }   inline void assign(int i, int x, int y, int l, int r) {     static int vis[105] = {};     if ((i + 1) * maxn <= n) {       for (int j = 1; j <= 100; j++) {         for (int k : v[i][j]) vis[k] = j;         v[i][j].clear();         v[i][j].push_back(j);       }       for (int j = i * maxn; j < (i + 1) * maxn; j++) a[j] = vis[a[j]];     }     for (int j = l; j < r; j++)       if (a[j] == x) a[j] = y;   }   int main() {     scanf( %d , &n);     maxn = sqrt(n * log2(n)) + 1;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; (i + 1) * maxn <= n; i++)       for (int j = 1; j <= 100; j++) v[i][j].push_back(j);     for (scanf( %d , &q); q--;) {       int l, r, x, y, L, R;       scanf( %d%d%d%d , &l, &r, &x, &y);       if (x != y) {         l--;         L = l / maxn, R = r / maxn;         if (L != R) {           assign(L, x, y, l, (L + 1) * maxn);           for (int i = L + 1; i < R; i++) merge(v[i][y], v[i][x]);           assign(R, x, y, R * maxn, r);         } else           assign(L, x, y, l, r);       }     }     for (int i = 0; (i + 1) * maxn <= n; i++) assign(i, 0, 0, 0, 0);     for (int i = 0; i < n; i++) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const signed long long int LINF = LLONG_MAX;   const double EPS = 1e-9;   const int MOD = 1000000007;   const int MAXN = 100001;   const int ALPH = 26;   const int DALPH = 52;   struct Node {     int l, r, m;     int minValue;     Node *lson, *rson;     Node(const int &al, const int &ar)         : l(al),           r(ar),           m((al + ar) / 2),           minValue(-1),           lson(nullptr),           rson(nullptr) {       if (l == r) {         return;       }       lson = new Node(l, m);       rson = new Node(m + 1, r);     }     ~Node() {       if (lson) {         delete lson;         delete rson;       }     }     void set(const int &index, const int &value) {       if (l == r) {         minValue = value;         return;       }       if (index < m + 1) {         lson->set(index, value);       } else {         rson->set(index, value);       }       minValue = min(lson->minValue, rson->minValue);     }     int getMin(const int &al, const int &ar) {       if (ar < l || r < al) {         return INF;       }       if (al <= l && r <= ar) {         return minValue;       }       return min(lson->getMin(al, ar), rson->getMin(al, ar));     }   };   struct pt {     int x, y;     pt() {}     pt(const int &ax, const int &ay) : x(ax), y(ay) {}     void read() { scanf( %d %d , &x, &y); }   };   bool operator<(const pt &p1, const pt &p2) { return p1.x < p2.x; }   struct query {     int id;     pt p1, p2;     bool ans;     query() {}     query(const int &aId, const pt &aP1, const pt &aP2)         : id(aId), p1(aP1), p2(aP2), ans(false) {}   };   bool operator<(const query &q1, const query &q2) { return q1.p2.x < q2.p2.x; }   bool cmpid(const query &q1, const query &q2) { return q1.id < q2.id; }   int n, m, k, q;   vector<pt> rook;   vector<query> qList;   void solve() {     sort((rook).begin(), (rook).end());     sort((qList).begin(), (qList).end());     Node *tree = new Node(1, m);     int rptr = 0, qptr = 0;     while (qptr < q) {       while (rptr < k && rook[rptr].x <= qList[qptr].p2.x) {         tree->set(rook[rptr].y, rook[rptr].x);         ++rptr;       }       if (tree->getMin(qList[qptr].p1.y, qList[qptr].p2.y) >= qList[qptr].p1.x) {         qList[qptr].ans = true;       }       ++qptr;     }     delete tree;   }   int main() {     scanf( %d %d %d %d , &n, &m, &k, &q);     rook.resize(k);     for (int i = 0; i < k; ++i) {       rook[i].read();     }     qList.resize(q);     for (int i = 0; i < q; ++i) {       pt p1, p2;       p1.read();       p2.read();       qList[i] = query(i, p1, p2);     }     solve();     for (int i = 0; i < k; ++i) {       swap(rook[i].x, rook[i].y);     }     for (int i = 0; i < q; ++i) {       swap(qList[i].p1.x, qList[i].p1.y);       swap(qList[i].p2.x, qList[i].p2.y);     }     swap(n, m);     solve();     sort((qList).begin(), (qList).end(), cmpid);     for (int i = 0; i < q; ++i) {       if (qList[i].ans) {         puts( YES );       } else {         puts( NO );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int q, n, x;   void f() {     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int maxi = v.back();     for (int i = v.size() - 1; i > 0 && v[i] + v[i - 1] > maxi; i--)       for (int j = i - 1; j >= 0; j--)         if (v[i] % v[j] != 0) {           maxi = max(maxi, v[i] + v[j]);           break;         }     for (int i = v.size() - 1; i > 0 && v[i] + v[i - 1] + v[i - 2] > maxi; i--)       for (int j = i - 1; j > 0; j--)         if (v[i] % v[j] != 0)           for (int k = j - 1; k >= 0; k--)             if (v[i] % v[k] != 0 && v[j] % v[k] != 0) {               maxi = max(maxi, v[i] + v[j] + v[k]);               break;             }     cout << maxi << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> q;     for (int u = 0; u < q; u++) f();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, s;     cin >> a >> b >> s;     a < 0 ? a *= -1 : a *= 1;     b < 0 ? b *= -1 : b *= 1;     int l = min(a, b) * 2 + (max(a, b) - min(a, b));     cout << (l <= s ? l % 2 == s % 2 ?  YES  :  NO  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, x, ans;   long long findX(long long R) {     if (R < 0) return 0;     return (R * (R + 1)) / 2;   }   int main() {     scanf( %lld %lld , &n, &k);     x = 0;     for (int i = 1; i <= n - 1; i++) {       if (findX(i - 1) <= k) x = i;     }     if (findX(x - 1) + x < k) {       printf( Impossible n );       return 0;     }     k -= findX(x - 1);     n -= x;     if (x) {       for (int i = 1; i <= x; i++) {         printf( ( );         if (i == k) {           printf( () );           n--;         }       }       for (int i = 1; i <= x; i++) {         printf( ) );       }     }     while (n) {       printf( () );       n--;     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n, m, a, b, c, p[100010], cnt;   bool vis[100010], ed;   vector<pair<int, int> > V[100010];   int powmod(int x, int y) {     int res = 1, cro = x;     while (y) {       if (y % 2) res = 1ll * res * cro % mod;       cro = 1ll * cro * cro % mod;       y /= 2;     }     return res;   }   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < V[x].size(); i++) {       int y = V[x][i].first;       int z = V[x][i].second;       if (vis[y]) {         if (p[y] != p[x] ^ z) ed = 1;         continue;       } else {         p[y] = p[x] ^ z;         vis[y] = 1;         dfs(y);       }     }   }   int main() {     scanf( %d%d , &n, &m);     while (m--) {       scanf( %d%d%d , &a, &b, &c);       V[a].push_back(make_pair(b, c ^ 1));       V[b].push_back(make_pair(a, c ^ 1));     }     ed = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);         cnt++;       }     }     if (ed)       puts( 0 );     else       printf( %d , powmod(2, cnt - 1));   }


#include <bits/stdc++.h>   using namespace std;   int dp[10000];   int main() {     int N, M;     cin >> N >> M;     int T;     double D;     int ans = 0;     for (int i = 0; i < N; i++) {       cin >> T >> D;       dp[T - 1]++;       for (int j = 0; j < T - 1; j++) dp[T - 1] = max(dp[T - 1], dp[j] + 1);     }     for (int i = 0; i < M; i++) ans = max(ans, dp[i]);     cout << N - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n < 4)       printf( NO n );     else if (n % 2) {       printf( YES n );       printf( 1 + 5 = 6 n3 - 2 = 1 n4 * 6 = 24 n24 * 1 = 24 n );       for (int j = n; j > 6; j -= 2) {         printf( %d - %d = 1 n , j, j - 1);         printf( 24 * 1 = 24 n );       }     } else {       printf( YES n );       printf( 1 * 2 = 2 n2 * 3 = 6 n6 * 4 = 24 n );       for (int j = n; j > 5; j -= 2) {         printf( %d - %d = 1 n , j, j - 1);         printf( 24 * 1 = 24 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const double PI = acos(-1.0);   const double E = exp(1.0);   const int M = 200010;   long long a[M];   long long ans[M][2];   int main() {     int n, k, x;     cin >> n >> k >> x;     long long temp = 1;     while (k--) temp *= x;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ans[i][0] = (ans[i - 1][0] | a[i]);     }     long long mx = 0;     for (int i = n; i > 0; --i) {       mx = max(mx, ans[i + 1][1] | ans[i - 1][0] | (a[i] * temp));       ans[i][1] = ans[i + 1][1] | a[i];     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k;   vector<pair<long long, char>> aa;   void print(long long a, char c) {     a = min(a, k);     if (a != 0) {       aa.push_back({a, c});     }     k -= a;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m >> k;     if (k > 4 * n * m - 2 * n - 2 * m) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (long long i = 0; i < m - 1; i++) {       print(1,  R );       print(n - 1,  D );       print(n - 1,  U );     }     print(m - 1,  L );     for (long long i = 0; i < n - 1; i++) {       print(1,  D );       print(m - 1,  R );       print(m - 1,  L );     }     print(n - 1,  U );     cout << aa.size() <<   n ;     for (auto i : aa) {       cout << i.first <<     << i.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 10;   int arr[MAX];   int n;   vector<int> v[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; ++i) v[i].clear();       for (int i = 0; i < n; ++i) {         int x, y;         cin >> x >> y;         v[x].push_back(y);       }       long long ans = 0;       priority_queue<int, vector<int>, greater<int> > q;       for (int i = n - 1; i >= 0; --i) {         for (auto &j : v[i]) q.push(j);         while (q.size() > n - i) ans += q.top(), q.pop();       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i, a[n];     long long int c = 0, ans = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       c += a[i];     }     for (i = 1; i <= 5; i++) {       if ((c + i) % (n + 1) != 1) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 1e5 + 5;   int st1[16][N][17], st2[16][N][17];   int a[N], lg[N];   int n;   void make_st(int id) {     for (int j = 1; j <= 16; j++) {       for (int i = 1; i <= n - (1 << j) + 1; i++) {         st1[id][i][j] =             min(st1[id][i][j - 1], st1[id][i + (1 << (j - 1))][j - 1]);         st2[id][i][j] =             max(st2[id][i][j - 1], st2[id][i + (1 << (j - 1))][j - 1]);       }     }   }   int query1(int id, int l, int r) {     int k = lg[r - l + 1];     return min(st1[id][l][k], st1[id][r - (1 << k) + 1][k]);   }   int query2(int id, int l, int r) {     int k = lg[r - l + 1];     return max(st2[id][l][k], st2[id][r - (1 << k) + 1][k]);   }   int queryl(int base, int l, int r) {     int ans = query1(base, max(l, 1), min(r, n));     if (l <= 0) ans = max(-n + 1, min(ans, query1(base, l + n, n) - n));     if (r > n) ans = max(-n + 1, min(ans, query1(base, 1, r - n) + n));     return ans;   }   int queryr(int base, int l, int r) {     int ans = query2(base, max(l, 1), min(r, n));     if (l <= 0) ans = min(n * 2, max(ans, query2(base, l + n, n) - n));     if (r > n) ans = min(n * 2, max(ans, query2(base, 1, r - n) + n));     return ans;   }   int main() {     read(n);     if (n == 1) {       print(0,   n );       return 0;     }     lg[0] = -1;     for (int i = 1; i <= n; i++) {       read(a[i]);       lg[i] = lg[i >> 1] + 1;       st1[0][i][0] = i - a[i];       st2[0][i][0] = i + a[i];     }     make_st(0);     for (int base = 1; base <= 15; base++) {       for (int i = 1; i <= n; i++) {         int l = st1[base - 1][i][0], r = st2[base - 1][i][0];         st1[base][i][0] = queryl(base - 1, l, r);         st2[base][i][0] = queryr(base - 1, l, r);       }       make_st(base);     }     for (int i = 1; i <= n; i++) {       int l = i, r = i, ans = 0;       for (int j = 15; j >= 0; j--) {         int L = queryl(j, l, r), R = queryr(j, l, r);         if (R - L + 1 < n) l = L, r = R, ans |= (1 << j);       }       print(ans + 1, i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, c;   vector<int> locck[567567];   const int S = 1 << 20;   int tree[2 * S];   void loduj() {     cin >> n >> c;     int x, l;     for (int i = 0; i < n; ++i) {       cin >> l;       for (int j = 0; j < l; ++j) {         cin >> x;         locck[i].push_back(x);       }     }     for (int i = 1; i < 2 * S; ++i) {       tree[i] = 1;     }   }   void forbRec(int p, int q, int pp, int qq, int no) {     if (q < pp || qq < p) {       return;     }     if (p <= pp && qq <= q) {       tree[no] = 0;       return;     }     int ss = (pp + qq) / 2;     forbRec(p, q, pp, ss, 2 * no);     forbRec(p, q, ss + 1, qq, 2 * no + 1);   }   void forb(int p, int q) { forbRec(p, q, 0, S - 1, 1); }   bool isVal(int p) {     p += S;     while (p) {       if (!tree[p]) {         return 0;       }       p /= 2;     }     return 1;   }   void cons(int x, int y) {     if (x < y) {       forb(c - y + 1, c - x);     } else {       forb(0, c - x);       forb(c - y + 1, c - 1);     }   }   void cons(vector<int> &u, vector<int> &v) {     int d = 0;     while ((d < u.size()) && (d < v.size()) && u[d] == v[d]) {       ++d;     }     if (d == u.size()) {       return;     }     if (d == v.size()) {       forb(0, c - 1);       return;     }     cons(u[d], v[d]);   }   void makeInts() {     for (int i = 0; i < n - 1; ++i) cons(locck[i], locck[i + 1]);   }   int solve() {     for (int i = 0; i < c; ++i)       if (isVal(i)) return i;     return -1;   }   int main() {     ios_base::sync_with_stdio(0);     loduj();     makeInts();     cout << solve() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long MOD = 4207849484;   int main() {     int n, m, i, g, h, j;     char c;     scanf( %d%d , &n, &m);     vector<int> a(n + 1, 0), bl(n + 1, 0);     for (int(i) = 0; (i) < (m); ++(i)) {       getchar();       scanf( %c %d , &c, &g);       if (c ==  + ) {         if (bl[g]) {           puts( Already on );           continue;         }         h = g;         int b = 0;         for (j = 2; j * j <= h && b == 0; j++) {           if (h % j == 0) {             if (a[h / j] || a[j]) {               b = max(a[h / j], a[j]);               break;             }           }         }         b = max(b, a[g]);         if (b == 0) {           bl[g] = 1;           puts( Success );           h = g;           for (j = 2; j * j <= h; j++) {             if (h % j == 0) {               a[h / j] = a[j] = h;             }           }           a[h] = h;         } else {           printf( Conflict with %d n , b);         }       } else {         if (bl[g] == 0) {           puts( Already off );         } else {           bl[g] = 0;           h = g;           for (j = 2; j * j <= h; j++) {             if (h % j == 0) {               a[h / j] = a[j] = 0;             }           }           a[h] = 0;           puts( Success );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e18 + 9;   const long long MAXN = 1e6 + 7;   const long long MAXN1 = 5e2 + 7;   const long long MOD = 1e9 + 7;   const long long ST = 157;   const long long ST1 = 199;   const long double EPS = 1e-9;   const long long BLOCK = 138;   void solve();   signed main() {     srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 );     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }   void solve() {     int n;     cin >> n;     vector<pair<long long, int>> v;     for (int i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       v.emplace_back(l, -1);       v.emplace_back(r, 1);     }     sort(v.begin(), v.end());     vector<long long> ans(n + 1);     int b = -1;     for (int i = 1; i < 2 * n; i++) {       if (v[i].second == -1) {         if (v[i - 1].second == 1) {           ans[-b] += v[i].first - v[i - 1].first - 1;         } else {           ans[-b] += v[i].first - v[i - 1].first;         }       } else {         if (v[i].first != v[i - 1].first || v[i - 1].second == -1) {           if (v[i - 1].second == 1)             ans[-b] += v[i].first - v[i - 1].first;           else             ans[-b] += v[i].first - v[i - 1].first + 1;         }       }       b += v[i].second;     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     cin >> t;     while (t--) {       long long int p, q, x;       cin >> p >> q;       long long int b = 0;       set<long long int> pf;       long long int cq = q;       for (long long int i = 2; i * i <= cq; i++) {         while (cq % i == 0) {           pf.insert(i);           cq /= i;         }       }       if (cq > 1) pf.insert(cq);       for (long long int i : pf) {         long long int cp = p;         while (cp % q == 0) cp /= i;         b = max(b, cp);       }       cout << b << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double v, d, l, g, r;     cin >> l >> d >> v >> g >> r;     double t;     t = d / v;     double k = 0;     while (k <= t) {       k += g;       if (t < k) {         t += (l - d) / v;         cout << setprecision(8) << t;         exit(0);       }       k += r;       if (t < k) {         t += (k - t);         t += (l - d) / v;         cout << setprecision(8) << t;         exit(0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const double eps = 0.000000001;   double dist(double x, double y) { return x * x + y * y; }   double xx, yy, v, t, x, y, r;   int n;   vector<pair<double, int> > vt;   int main() {     scanf( %lf %lf %lf %lf %d , &xx, &yy, &v, &t, &n);     if (t == 0) {       for (int i = 0; i < n; ++i) {         scanf( %lf %lf %lf , &x, &y, &r);         if (dist(x - xx, y - yy) <= r * r) {           printf( 1.00000 );           return 0;         }       }       printf( 0.00 );       return 0;     }     v *= t;     for (int i = 0; i < n; ++i) {       scanf( %lf %lf %lf , &x, &y, &r);       x -= xx;       y -= yy;       double dd = dist(x, y);       double d = sqrt(dd);       if (dd < r * r + eps) {         printf( 1.0000 );         return 0;       }       if (d - eps > v + r) continue;       double ang, ang1, ang2;       ang = atan2(y, x);       if (ang < 0) ang += pi * 2;       if (dd - r * r < v * v + eps)         ang1 = asin(r / d);       else {         double tmp = 0.5 * (v * v - r * r + dd) / (d * v);         ang1 = acos(tmp);       }       ang2 = ang + ang1;       ang1 = ang - ang1;       if (ang1 < 0) {         vt.push_back(pair<double, int>(ang1 + pi * 2, 1));         vt.push_back(pair<double, int>(pi * 2, -1));         vt.push_back(pair<double, int>(0.0, 1));         vt.push_back(pair<double, int>(ang2, -1));       } else if (ang2 > pi * 2) {         vt.push_back(pair<double, int>(ang1, 1));         vt.push_back(pair<double, int>(pi * 2, -1));         vt.push_back(pair<double, int>(0.0, 1));         vt.push_back(pair<double, int>(ang2 - pi * 2, -1));       } else {         vt.push_back(pair<double, int>(ang1, 1));         vt.push_back(pair<double, int>(ang2, -1));       }     }     double tot = 0, beg = 0;     int cnt = 0;     sort(vt.begin(), vt.end());     for (int i = 0; i < (int)vt.size(); ++i) {       if (cnt > 0) tot += vt[i].first - beg;       cnt += vt[i].second;       beg = vt[i].first;     }     tot /= pi * 2;     printf( %.12lf , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nexto[120];   int ara[120];   int main() {     std::ios_base::sync_with_stdio(false);     ;     int n;     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> ara[i];     }     int tt = n;     for (int i = n - 1; i >= 0; i--) {       nexto[i] = tt;       if (ara[i] == 1) {         tt = i;       }     }     if (tt == n) {       cout << 0 <<   n ;       return 0;     }     nexto[n] = n;     long long shuru;     if (ara[0] == 1) {       shuru = 0;     } else {       shuru = nexto[0];     }     long long ans = 1;     for (;;) {       if (shuru >= n) {         break;       }       long long shesh = nexto[shuru];       if (shesh >= n) {         break;       }       ans *= (shesh - shuru);       shuru = shesh;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline void chmin(A &a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A &a, B b) {     if (a < b) a = b;   }   string S;   long long dp[3333333];   signed main() {     for (long long i = 0; i < 26; i++) S += (char)( a  + i);     for (long long i = 0; i < 26; i++) S += (char)( A  + i);     fill_n(dp, 1111111, INT_MAX);     dp[1] = 0;     for (long long i = 1; i < 1111111; i++) {       for (long long j = 1; j <= 2; j++) {         chmin(dp[i * j + 1], dp[i] + 1);       }     }     long long n;     cin >> n;     string s;     long long cur = 0;     while (n > 1) {       if ((n - 1) & 1) {         s += string(1, S[cur++]);         n--;       } else {         s += string(2, S[cur++]);         n = (n - 1) / 2;       }     }     for (long long i = 0; i < S.size(); i++) s += S[i];     cout << s <<     << S << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     int n;     long long l, first, second;     cin >> n >> l >> first >> second;     vector<long long> a(n);     map<long long, bool> flag;     for (int i = 0; i < int(n); i++) {       cin >> a[i];       flag[a[i]] = true;     }     bool fx = false, fy = false;     for (int i = n - 1; i >= 0; i--) {       if (flag.count(a[i] - first)) fx = true;       if (flag.count(a[i] - second)) fy = true;     }     if (!fx && !fy) {       long long diff = second - first;       for (int i = 0; i < n; i++) {         if (flag.count(a[i] - diff)) {           if (a[i] + first <= l) {             cout << 1 <<   n ;             cout << a[i] + first;             return 0;           }           if (a[i] - second >= 0) {             cout << 1 <<   n ;             cout << a[i] - second;             return 0;           }         }       }       long long add = first + second;       for (int i = 0; i < n; i++) {         if (flag.count(a[i] + add)) {           if (a[i] + first <= l) {             cout << 1 <<   n ;             cout << a[i] + first;             return 0;           }         }       }       cout << 2 <<   n ;       cout << first <<     << second;     } else if (!fx) {       cout << 1 <<   n ;       cout << first;     } else if (!fy) {       cout << 1 <<   n ;       cout << second;     } else       cout <<  0 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   inline bool Min(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool Max(T &a, T b) {     return a < b ? (a = b, true) : false;   }   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline ll nl() {     ll a;     scanf( %lld , &a);     return a;   }   inline double nd() {     double a;     scanf( %lf , &a);     return a;   }   inline void pi(int a) { printf( %d  , a); }   inline void pl(ll a) { printf( %lld  , a); }   inline void pd(double a) { printf( %.12lf  , a); }   const int N = 2e5 + 100;   vector<int> gp[N];   bool is_university[N];   int n, k;   int cnt[N];   ll ans = 0;   void dfs(int v, int p) {     cnt[v] = is_university[v];     for (int next : gp[v])       if (next != p)         dfs(next, v), cnt[v] += cnt[next],             ans += min(cnt[next], k + k - cnt[next]);   }   void solve() {     n = ni();     k = ni();     for (int i = 0; i < (int)(k + k); ++i) is_university[ni()] = true;     for (int i = 0; i < (int)(n - 1); ++i) {       int a = ni();       int b = ni();       gp[a].push_back(b);       gp[b].push_back(a);     }     dfs(1, 1);     pl(ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int a[n], b[n];     map<pair<int, int>, int> mpa, mpb;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0, j = n - 1; i < j; i++, j--) {       int x = a[i];       int y = a[j];       if (x > y) swap(x, y);       mpa[{x, y}]++;     }     for (int i = 0, j = n - 1; i < j; i++, j--) {       int x = b[i];       int y = b[j];       if (x > y) swap(x, y);       mpb[{x, y}]++;     }     bool ok = true;     for (auto it : mpa) {       if (it.second != mpb[{it.first.first, it.first.second}]) {         ok = false;         break;       }     }     if (n % 2) {       if (a[n / 2] != b[n / 2]) ok = false;     }     cout << (ok ?  YES n  :  NO n );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int isprime(long long p) {     int i;     double max = sqrt(p);     for (i = 2; i <= max; i++)       if (p % i == 0) break;     if (i > max && p != 1) return 1;     return 0;   }   long long gcd(long long a, long long b) {     long long i;     for (i = a < b ? a : b; i > 0; i--)       if ((a % i == 0) && (b % i == 0)) break;     return i;   }   int comp(const void *a, const void *b) { return (*(int *)a - *(int *)b); }   int issame(int *a, int *b, int l) {     qsort(a, l, sizeof(int), comp);     qsort(b, l, sizeof(int), comp);     int i;     for (i = 0; i < l; i++)       if (a[i] != b[i]) break;     if (i == l) return 1;     return 0;   }   void swap(int *a, int *b) {     int x = *a;     *a = *b;     *b = x;   }   int arrmax(int *a, int l) {     int i;     int max = a[0];     for (i = 1; i < l; i++)       if (a[i] > max) max = a[i];     return max;   }   int arrmin(int *a, int l) {     int i;     int min = a[0];     for (i = 1; i < l; i++)       if (a[i] < min) min = a[i];     return min;   }   long long fact(int a) {     long long p = 1;     while (a > 0) p *= a--;     return p;   }   int min(int a, int b) {     if (a > b) return b;     return a;   }   int max(int a, int b) {     if (a < b) return b;     return a;   }   void sieve(int *a, int n) {     n--;     long long i, j;     for (i = 2; i <= n; i++) a[i] = 0;     for (i = 2; i <= n; i++)       if (!a[i])         for (j = i * i; j <= n; j += i)           if (!a[j]) a[j]++;   }   int main(void) {     int t;     scanf( %d , &t);     while (t--) {       char b[100];       scanf( %s , b);       int l = strlen(b);       char c[l / 2 + 1];       int i;       for (i = 1; i < l; i += 2) c[i / 2 + 1] = b[i];       c[0] = b[0];       for (i = 0; i < l / 2 + 1; i++) printf( %c , c[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   int n, m;   int res;   map<int, int> lck;   map<int, int>::iterator it;   long long fac[100002], inv[100002];   long long dp[100002];   void Add(long long &x, long long y) {     x += y;     if (x >= 1000000007)       x -= 1000000007;     else if (x < 0)       x += 1000000007;   }   bool check(int x) {     while (x) {       if (x % 10 != 4 && x % 10 != 7) return 0;       x /= 10;     }     return 1;   }   void Init() {     fac[0] = fac[1] = 1;     inv[0] = inv[1] = 1;     for (int i = (2), i_end_ = (100002); i < i_end_; i++)       fac[i] = fac[i - 1] * i % 1000000007;     for (int i = (2), i_end_ = (100002); i < i_end_; i++)       inv[i] = (1000000007 - (1000000007 / i)) * inv[1000000007 % i] % 1000000007;     for (int i = (2), i_end_ = (100002); i < i_end_; i++)       inv[i] = inv[i] * inv[i - 1] % 1000000007;   }   long long C(int n, int m) {     if (n < 0 || m > n) return 0;     return fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;   }   int main() {     Init();     scanf( %d%d , &n, &m);     for (int i = (1), i_end_ = (n); i <= i_end_; i++) {       int x;       scanf( %d , &x);       if (check(x))         lck[x]++;       else         res++;     }     int tot = 0;     dp[0] = 1;     for (it = lck.begin(); it != lck.end(); it++) {       tot++;       for (int i = (min(tot, m)), i_end_ = (1); i >= i_end_; i--)         Add(dp[i], dp[i - 1] * it->second % 1000000007);     }     long long ans = 0;     for (int i = (0), i_end_ = (min(tot, m)); i <= i_end_; i++)       Add(ans, dp[i] * C(res, m - i) % 1000000007);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 9;   const long long N = 500500;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, k;       cin >> n >> k;       string s, t;       cin >> s;       vector<pair<long long, long long> > ans;       for (long long i = 1; i <= k - 1; i++) {         t +=  () ;       }       for (long long i = 1; i <= (n - (2 * k) + 2) / 2; i++) {         t +=  ( ;       }       for (long long i = 1; i <= (n - (2 * k) + 2) / 2; i++) {         t +=  ) ;       }       for (long long i = 0; i < n; i++) {         if (s[i] == t[i]) continue;         for (long long j = i + 1; j < n; j++) {           if (s[j] == t[i]) {             ans.push_back({i + 1, j + 1});             reverse(s.begin() + i, s.begin() + j + 1);             break;           }         }       }       cout << ans.size() <<   n ;       for (auto z : ans) {         cout << z.first <<     << z.second <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0, flag = 0;     int arr[100];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] != arr[i + 1]) {         flag = 1;       }     }     if (flag == 0) {       cout << ans << endl;       return 0;     }     for (int i = 0; i < n; i++) {       if (arr[i] == 0 && arr[i - 1] == 1 && arr[i + 1] == 1) {         arr[i + 1] = 0;         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 5, Mod = 998244353;   char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;   int ny;   inline char gc() {     return pp1 == pp2 &&                    (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)                ? EOF                : *pp1++;   }   inline int read() {     int x = 0;     for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)       if (nc == 45) ny = -1;     if (nc < 0) return nc;     for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;          x = (x << 3) + (x << 1) + (nc ^ 48))       ;     return x * ny;   }   int n, k, m, ans = 1, s[MAXN], Mn[MAXN], l[MAXN], r[MAXN], c[MAXN], f[MAXN],                q[MAXN], head, tail;   inline void add(int& x, int y) { x += y, x >= Mod ? x -= Mod : 0; }   inline void sub(int& x, int y) { x -= y, x < 0 ? x += Mod : 0; }   inline int Solve(int k) {     memset(s, 0, sizeof(s));     for (int i = 1; i <= n; i++) Mn[i] = n + 1;     for (int i = 1; i <= m; i++) {       if (c[i] >> k & 1)         s[l[i]]++, s[r[i] + 1]--;       else         Mn[l[i]] = min(Mn[l[i]], r[i]);     }     for (int i = 1; i <= n; i++) s[i] += s[i - 1];     memset(f, 0, sizeof(f)), f[n + 1] = 1, q[head = tail = 1] = n + 1;     int sum = 1;     for (int i = 1; i <= n; i++) {       int tmp = 0;       for (; q[tail] >= Mn[i] && head <= tail;            add(tmp, f[q[tail]]), f[q[tail]] = 0, tail--)         ;       for (f[Mn[i]] = tmp, q[++tail] = Mn[i]; q[head] < i && head <= tail;            sub(sum, f[q[head]]), head++)         ;       if (!s[i]) add(f[n + 1], sum), sum = 2 * sum % Mod;       (q[tail] != n + 1 ? q[++tail] = n + 1 : 0);     }     return f[n + 1];   }   int main() {     n = read(), k = read(), m = read();     for (int i = 1; i <= m; i++) l[i] = read(), r[i] = read(), c[i] = read();     for (int i = 0; i <= k - 1; i++) ans = 1ll * ans * Solve(i) % Mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 111111;   const double inf = 0.000001;   const int INF = ~0U >> 1;   const int mod = 1000000007;   int n, a[maxn], m;   int equal(double x, double y) {     if (x - y >= -inf && x - y <= inf)       return 0;     else if (x - y > inf)       return 1;     return -1;   }   int main() {     scanf( %d , &n), scanf( %d , &m);     if (m < n / 2 || (n == 1 && m))       printf( %d n , -1);     else if (n == 1 && m == 0)       printf( %d n , 1);     else {       int ans = m - n / 2 + 1;       printf( %d %d , ans, ans * 2);       ans *= 2;       for (int i = 2; i < n; i++) printf(  %d , (++ans));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   vector<vector<long long>> ft(12, vector<long long>(100005, 0));   void add(long long kk, long long ind, long long val) {     while (ind <= n) {       ft[kk][ind] += val;       ind += ind & -ind;     }   }   long long sum(long long kk, long long ind) {     long long res = 0;     while (ind > 0) {       res += ft[kk][ind];       ind -= ind & -ind;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     vector<long long> arr(n + 1);     for (int i = 1; i < n + 1; i++) cin >> arr[i];     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < 12; j++) {         if (j == 1)           add(1, arr[i], 1);         else {           long long val = sum(j - 1, arr[i] - 1);           add(j, arr[i], val);         }       }     }     cout << sum(k + 1, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, S = 0;   char x[2], s[MAXN];   int viv[MAXN];   bool use[MAXN];   int cqf() {     int l = -1, r = -1;     int ans = MAXN, sum = 0;     while (true) {       while (r <= n && sum < S) {         r++;         if (!viv[s[r]] && use[s[r]]) sum++;         viv[s[r]]++;       }       if (sum < S) break;       ans = min(ans, r - l + 1);       if (viv[s[l]] == 1 && use[s[l]]) sum--;       viv[s[l]]--;       l++;     }     return ans;   }   int main() {     memset(viv, 0, sizeof(viv));     memset(use, 0, sizeof(use));     scanf( %d , &n);     gets(x);     gets(s);     for (int i = 0; i < n; i++) {       if (use[s[i]] == false) S++;       use[s[i]] = true;     }     printf( %d n , cqf());     return 0;   }


#include <bits/stdc++.h>   int main() {     std::string input(  ), answer(  ), output(  );     getline(std::cin, input);     getline(std::cin, answer);     int count[10] = {0};     char minNonZero( A );     for (int k = 0; k < input.size(); k++) {       ++count[input[k] -  0 ];       if (input[k] >  0  && input[k] < minNonZero) {         minNonZero = input[k];       }     }     if (minNonZero ==  A ) {       output =  0 ;     } else {       --count[minNonZero -  0 ];       output += minNonZero;       for (int digit = 0; digit < 10; digit++) {         while (count[digit]--) {           output += ( 0  + digit);         }       }     }     if (answer == output) {       puts( OK );     } else {       puts( WRONG_ANSWER );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int S[N], E[N], T[N], C[N];   int t[N], W[N];   int main() {     int n, m;     scanf( %d %d , &n, &m);     int i;     for (i = 1; i <= n; i++) {       t[i] = 1006;       W[i] = -1;     }     for (i = 1; i <= m; i++) {       scanf( %d %d %d %d , &S[i], &E[i], &T[i], &C[i]);       for (int j = S[i]; j <= E[i]; j++) {         if (T[i] < t[j]) {           t[j] = T[i];           W[j] = i;         }       }     }     int sum = 0;     for (i = 1; i <= n; i++) {       if (W[i] != -1) {         sum += C[W[i]];       }     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long l[200001], r[200001];   struct data {     long long l, r, ans, num;     bool operator<(const data &p) const { return r > p.r; }   } a[300001];   priority_queue<data> q;   bool cmp(data p, data q) {     if (p.l == q.l) return p.num < q.num;     return p.l < q.l;   }   bool cmp2(data p, data q) { return p.num < q.num; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]);     for (int i = 1; i < n; i++) {       a[i].l = l[i + 1] - r[i];       a[i].r = r[i + 1] - l[i];       a[i].num = i;     }     for (int i = n; i <= m + n - 1; i++) {       long long x;       scanf( %lld , &x);       a[i].num = i;       a[i].l = x;     }     sort(a + 1, a + m + n, cmp);     for (int i = 1; i <= m + n - 1; i++) {       if (a[i].num < n) {         data now = a[i];         now.num = i;         q.push(now);         continue;       }       if (q.empty()) continue;       data now = q.top();       q.pop();       if (now.r < a[i].l) {         printf( No n );         return 0;       }       a[now.num].ans = a[i].num - n + 1;     }     if (!q.empty()) {       printf( No n );       return 0;     }     printf( Yes n );     sort(a + 1, a + n + m, cmp2);     for (int i = 1; i < n; i++) printf( %d  , a[i].ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     long k = min(d, min(c, b));     long m = min(a, d);     long cost = 0;     if (e > f) {       d = d - m;       cost = m * e + min(d, min(c, b)) * f;     } else {       d = d - k;       cost = k * f + min(a, d) * e;     }     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, L, K;   string s;   int cnt[26];   string res[1000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> L >> K;     cin >> s;     for (int i = 0; i < N * L; i++) cnt[s[i] -  a ]++;     int l = 0;     int t = 0;     while (l < K - 1 and t < 26) {       int st = cnt[t];       for (int j = 0, _t = cnt[t]; j < _t; j++) {         if (res[l + j % (K - l)].size() == L) {           l = K + 1;           break;         }         res[l + j % (K - l)] += (char)(t +  a );         cnt[t]--;       }       l += st % (K - l);       t++;     }     int lst = 25;     for (int i = 0; i < K - 1; i++) {       while (res[i].size() < L) {         while (cnt[lst] == 0) lst--;         res[i] += (char)(lst +  a );         cnt[lst]--;       }     }     int fst = 0;     for (int i = K - 1; i < N; i++) {       while (res[i].size() < L) {         while (cnt[fst] == 0) fst++;         res[i] += (char)(fst +  a );         cnt[fst]--;       }     }     sort(res, res + N);     for (int i = 0; i < N; i++) {       cout << res[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n > 2)       cout << n - 2 << endl;     else       cout <<  7  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int justgreater(long long int n) {     long long int i;     for (i = 1;; i++)       if (i * (i + 1) / 2 > n) break;     return i - 1;   }   int main() {     long long int m, n, a[100009] = {0}, sum = 0, cnt = 0;     cin >> m >> n;     long long int up = justgreater(m + n);     long long int tup = up;     for (; tup >= 1; tup--) {       if (sum + tup > m) continue;       sum += tup;       a[tup]++;     }     long long int cnt0 = 0, cnt1 = 0;     for (long long int i = 1; i <= up; i++)       if (a[i] == 1)         cnt0++;       else         cnt1++;     cout << cnt0 << endl;     for (long long int i = 1; i <= up; i++)       if (a[i] == 1) cout << i <<    ;     cout << endl;     cout << cnt1 << endl;     for (long long int i = 1; i <= up; i++)       if (a[i] == 0) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   long long n, maxl = 2e5;   long long montonic(vector<long long> &b) {     bool inc = true, dec = true;     long long n = (long long)b.size();     for (long long i = 1; i < n; ++i) {       if (b[i] <= b[i - 1]) {         inc = false;       }       if (b[i] >= b[i - 1]) {         dec = false;       }     }     if (inc == 1) {       return 1;     }     if (dec == 1) {       return 0;     } else       return -1;   }   void f(vector<long long> &a, vector<long long> &b) {     string ans =   ;     while (true) {       if (b == a) {         break;       } else {         vector<long long> c = b;         reverse(c.begin(), c.end());         if (c == a) {           ans +=  R ;           break;         }       }       long long m = montonic(b);       if (m == -1) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else {         if (m == 0) {           reverse(b.begin(), b.end());           ans +=  R ;         } else {           for (long long i = n - 1; i >= 1; --i) b[i] -= b[i - 1];           ans +=  P ;         }       }     }     if ((long long)ans.size() > maxl) {       cout <<  BIG  <<   n ;       long long cnt = 0;       for (long long i = 0; i < (long long)ans.size(); ++i)         if (ans[i] ==  P ) ++cnt;       cout << cnt <<   n ;     } else {       cout <<  SMALL  <<   n ;       cout << (long long)ans.size() <<   n ;       reverse(ans.begin(), ans.end());       cout << ans <<   n ;     }   }   void solve() {     cin >> n;     if (n == 1) {       long long a;       cin >> a;       long long b;       cin >> b;       if (b % a) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else {         long long op = b / a - 1;         if (op > maxl) {           cout <<  BIG  <<   n ;           cout << op <<   n ;         } else {           cout <<  SMALL  <<   n ;           cout << op <<   n ;         }       }     } else if (n == 2) {       vector<long long> a(n), b(n);       for (long long i = 0; i < n; ++i) cin >> a[i];       for (long long i = 0; i < n; ++i) cin >> b[i];       vector<long long> c = a;       vector<long long> d = b;       long long popr = 0;       sort(c.begin(), c.end());       sort(d.begin(), d.end());       long long op = 0;       while (d[0] != c[0]) {         if (d[0] == 0) {           cout <<  IMPOSSIBLE  <<   n ;           return;         }         op += d[1] / d[0];         d[1] %= d[0];         swap(d[0], d[1]);       }       if ((d[1] - c[1]) % c[0]) {         cout <<  IMPOSSIBLE  <<   n ;         return;       } else         op += (d[1] - c[1]) / c[0];       if (op > maxl) {         cout <<  BIG  <<   n ;         cout << op <<   n ;       } else         f(a, b);     } else {       vector<long long> a(n), b(n);       for (long long i = 0; i < n; ++i) cin >> a[i];       for (long long i = 0; i < n; ++i) cin >> b[i];       f(a, b);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long maxn = 1e6 + 10;   int a[4], b[10] = {0, 1, 2, 0, 2, 1, 0}, c[4];   int check(int w) {     int sum = 0;     for (int i = 0; i < 3; i++) c[i] = a[i];     for (int i = w; i < 7; i++) {       if (c[b[i]] == 0) break;       --c[b[i]], ++sum;     }     int weeks = min(c[0] / 3, min(c[1] / 2, c[2] / 2));     c[0] -= weeks * 3, c[1] -= weeks * 2, c[2] -= weeks * 2, sum += weeks * 7;     for (int i = 0; i < 7; i++) {       if (c[b[i]] == 0) break;       --c[b[i]], ++sum;     }     return sum;   }   int main() {     for (int i = 0; i < 3; i++) cin >> a[i];     if (a[0] == 1 && a[1] == 1 && a[2] == 2) {       cout <<  4  << endl;       return 0;     }     int ans = 0;     for (int i = 0; i < 7; i++) {       ans = max(ans, check(i));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long read() {     long long s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x +  0 );     else       write(x / 10), putchar(x % 10 +  0 );   }   void print(long long x, char c =   n ) {     write(x);     putchar(c);   }   long long a[N], n, q;   struct node {     long long sum, len, tag;     node() { tag = -1; }     void update(long long x) {       tag = x;       sum = len * x;     }   } t[N * 4];   node operator+(const node &a, const node &b) {     node ret;     ret.sum = a.sum + b.sum;     ret.len = a.len + b.len;     return ret;   }   void push_down(long long w) {     if (!~t[w].tag) return;     t[(w * 2)].update(t[w].tag);     t[(w * 2 + 1)].update(t[w].tag);     t[w].tag = -1;   }   void cover(long long w, long long l, long long r, long long ql, long long qr,              long long x) {     if (r < ql || qr < l) return;     if (ql <= l && r <= qr) return t[w].update(x);     if (l < r) push_down(w);     cover((w * 2), l, ((l + r) / 2), ql, qr, x);     cover((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr, x);     t[w] = t[(w * 2)] + t[(w * 2 + 1)];   }   long long query(long long w, long long l, long long r, long long ql,                   long long qr) {     if (r < ql || qr < l) return 0;     if (ql <= l && r <= qr) return t[w].sum;     if (l < r) push_down(w);     return query((w * 2), l, ((l + r) / 2), ql, qr) +            query((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr);   }   void build(long long w, long long l, long long r) {     if (l == r) {       t[w].len = 1;       t[w].sum = 0;       return;     }     build((w * 2), l, ((l + r) / 2));     build((w * 2 + 1), ((l + r) / 2) + 1, r);     t[w] = t[(w * 2)] + t[(w * 2 + 1)];   }   set<long long> d;   void insert(long long x) {     if (d.find(x) != d.end()) return;     auto r = d.lower_bound(x);     cover(1, 1, n, (*--r) + 1, x, n - x);     d.insert(x);   }   void erase(long long x) {     if (d.find(x) == d.end()) return;     auto p = d.find(x), l = p, r = p;     l--, r++;     cover(1, 1, n, (*l) + 1, x, n - (*r));     d.erase(p);   }   inline long long calc(long long l, long long r) {     return (l + r) * (r - l + 1) / 2;   }   signed main(signed bangumi, char *ss969[]) {     (void)bangumi, (void)ss969;     n = read(), q = read();     for (long long i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     d.insert(0), d.insert(n);     for (long long i = 1; i < n; i++)       if (a[i] > a[i + 1]) insert(i);     while (q--) {       long long opt = read(), x = read(), y = read();       if (opt == 1) {         a[x] = y;         if (x > 1) {           if (a[x - 1] <= a[x])             erase(x - 1);           else             insert(x - 1);         }         if (x < n) {           if (a[x] <= a[x + 1])             erase(x);           else             insert(x);         }       } else {         if (y == n) {           print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, y));           continue;         }         auto p = d.upper_bound(y);         long long tmp = max(*--p, x - 1);         print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, tmp) -               (y - tmp) * (n - y));       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int n;   bool M[1005][1005];   int q;   bool ans = 0;   void setMatrix() {     for (int i = 0; i < n; i++)       if (M[i][i]) ans = !ans;   }   void CallEdit() {     int i;     scanf( %d , &i);     ans = !ans;   }   void CallPuts() { printf( %d , ans); }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &M[i][j]);     setMatrix();     scanf( %d , &q);     while (q--) {       int flag;       scanf( %d , &flag);       switch (flag) {         case 1: {           CallEdit();           break;         }         case 2: {           CallEdit();           break;         }         case 3: {           CallPuts();           break;         }         default:           break;       }     }     printf(  n );     return;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000010;   int p[maxn];   int main() {     int i, j, st, a, n, maxi;     long long ans = 0;     scanf( %d%d , &a, &n);     maxi = (int)(sqrt(a + n - 1) + 1e-7);     for (i = 1; i <= maxi; i++) {       st = (int)(a / (i * i) + 1e-7) * i * i;       for (j = st; j <= a + n - 1; j += i * i) p[j] = i * i;     }     for (i = a; i <= a + n - 1; i++) ans += i / p[i];     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, m, c;     cin >> n >> m >> c;     for (int i = 1; i <= m; i++) {       int x, ans;       cin >> x;       if (x <= c / 2) {         for (int j = 1; j <= n; j++) {           if (x < a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       } else {         for (int j = n; j >= 1; j--) {           if (x > a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   using namespace std;   const long long INF = 1LL << 60;   const double PI = acos(-1);   using ll = long long;   using P = array<ll, 2>;   template <typename T>   istream& operator>>(istream& i, vector<T>& v) {     for (ll j = (0); j < (ll)(v.size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(vector<T>& v) {     stringstream s;     for (ll i = (0); i < (ll)(v.size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   ostream& operator<<(ostream& o, vector<T>& v) {     if (v.size()) o << join(v);     return o;   }   template <typename T>   string join(vector<vector<T>>& vv) {     string s =   n ;     for (ll i = (0); i < (ll)(vv.size()); ++i) s += join(vv[i]) +   n ;     return s;   }   template <typename T>   ostream& operator<<(ostream& o, vector<vector<T>>& vv) {     if (vv.size()) o << join(vv);     return o;   }   template <typename T1, typename T2>   istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& o, pair<T1, T2>& v) {     return o <<  (  << v.first <<  ,  << v.second <<  ) ;   }   template <typename T>   istream& operator>>(istream& i, array<T, 2>& v) {     i >> v[0] >> v[1];     return i;   }   template <typename T>   ostream& operator<<(ostream& o, array<T, 2>& v) {     return o <<  (  << v[0] <<  ,  << v[1] <<  ) ;     return o;   }   int dx[4]{0, 1, 0, -1};   int dy[4]{1, 0, -1, 0};   void init_init_init() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     std::cout << fixed << setprecision(10);   }   template <class T>   T up(T a, T b) {     assert(b);     return (a + b - 1) / b;   }   template <typename... A>   bool eq(A const&... a) {     auto t = {a...};     assert(t.size());     auto tar = *t.begin();     for (const auto& e : t)       if (tar != e) return false;     return true;   }   template <class T>   bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   bool chmax(T& a, initializer_list<T> l) {     return chmax(a, max(l));   }   template <class T>   bool chmin(T& a, initializer_list<T> l) {     return chmin(a, min(l));   }   int main(int argc, char** argv) {     init_init_init();     ll x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     ll x3, y3, x4, y4;     cin >> x3 >> y3 >> x4 >> y4;     ll x5, y5, x6, y6;     cin >> x5 >> y5 >> x6 >> y6;     x1 *= 2, x2 *= 2, x3 *= 2, x4 *= 2, x5 *= 2, x6 *= 2;     y1 *= 2, y2 *= 2, y3 *= 2, y4 *= 2, y5 *= 2, y6 *= 2;     bool is{false};     for (ll x = x1; x <= x2; x++) {       ll y = y1;       if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or             (x5 <= x and x <= x6 and y5 <= y and y <= y6))) {         is = true;       }       y = y2;       if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or             (x5 <= x and x <= x6 and y5 <= y and y <= y6))) {         is = true;       }     }     for (ll y = y1; y <= y2; ++y) {       ll x = x1;       if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or             (x5 <= x and x <= x6 and y5 <= y and y <= y6))) {         is = true;       }       x = x2;       if (!((x3 <= x and x <= x4 and y3 <= y and y <= y4) or             (x5 <= x and x <= x6 and y5 <= y and y <= y6))) {         is = true;       }     }     auto ok = is;     std::cout << (ok ?  YES  :  NO ) << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   struct T {     int id, v, c, l, r, sum, prev;     void read(int ii) {       id = ii;       scanf( %d%d%d%d , &v, &c, &l, &r);     }     int total() { return c + l + r; }   };   int n;   map<int, vector<T> > gr;   vector<int> ans;   int res;   map<int, pair<int, int> > d;   int main() {     scanf( %d , &n);     for (int i = 0, _n = (n); i < _n; i++) {       T x;       x.read(i);       gr[x.total()].push_back(x);     }     res = 0;     for (map<int, vector<T> >::iterator git = gr.begin(); git != gr.end();          ++git) {       vector<T>& a = git->second;       d.clear();       d[0] = pair<int, int>(0, -1);       int n = (int)(a).size();       for (int i = 0, _n = (n); i < _n; i++) {         map<int, pair<int, int> >::iterator it = d.find(a[i].l);         if (it == d.end()) continue;         a[i].prev = it->second.second;         int newcost = it->second.first + a[i].v;         map<int, pair<int, int> >::iterator it2 = d.find(a[i].l + a[i].c);         if (it2 == d.end() || it2->second.first < newcost) {           d[a[i].l + a[i].c] = pair<int, int>(newcost, i);         }       }       int total = git->first;       if (d.count(total) == 0) continue;       if (d[total].first <= res) continue;       res = d[total].first;       int last = d[total].second;       ans.clear();       for (; last != -1; last = a[last].prev) ans.push_back(a[last].id);       reverse((ans).begin(), (ans).end());     }     printf( %d n , (int)(ans).size());     for (int i = 0, _n = ((int)(ans).size()); i < _n; i++)       printf(  %d  + (i == 0), ans[i] + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string toString(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long toLong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T S(T a) {     return a * a;   }   template <typename T>   inline T gcd(T a, T b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   template <typename T>   inline unsigned long long bigmod(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return S(bigmod(a, b / 2, m)) % m;     else       return (a % m * bigmod(a, b - 1, m)) % m;   }   template <typename T>   inline vector<string> parse(T str) {     vector<string> res;     string s;     istringstream os(str);     while (os >> s) res.push_back(s);     return res;   }   template <typename T>   inline unsigned long long dist(T A, T B) {     unsigned long long res =         (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   template <typename T>   inline double cosAngle(T a, T b, T c) {     double res = a * a + b * b - c * c;     res = res / (2 * a * b);     res = acos(res);     return res;   }   template <typename T>   inline T power(T base, int po) {     T res = 1;     if (base == 0) return 0;     for (int i = (0); i < (po); i++) res *= base;     return res;   }   template <typename T>   inline bool isOn(T mask, T pos) {     return mask & (1 << pos);   }   template <typename T>   inline int Off(T mask, T pos) {     return mask ^ (1 << pos);   }   template <typename T>   inline int On(T mask, T pos) {     return mask | (1 << pos);   }   long long arr[10005];   vector<int> v[5000];   long long dp[2005][2005];   int Size[2005];   int N;   int main() {     int i, j, k;     int n, q;     long long x, y;     int ks, cas;     int kk;     cin >> n >> kk;     for (i = 1; i <= n; i++) {       for (j = 1; j <= i; j++) {         if (i % j == 0) {           v[i].push_back(j);         }       }     }     for (i = 0; i <= n; i++) {       Size[i] = v[i].size();     }     memset(dp, 0, sizeof dp);     for (i = 1; i <= n; i++) {       dp[1][i] = 1;     }     for (i = 2; i <= kk; i++) {       for (j = 1; j <= n; j++) {         for (k = 0; k < Size[j]; k++) {           dp[i][j] = (dp[i][j] + dp[i - 1][v[j][k]]) % 1000000007;         }       }     }     long long res = 0;     for (i = 1; i <= n; i++) {       res = (res + dp[kk][i]) % 1000000007;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(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;   }   int main() {     int n, m;     cin >> n >> m;     vector<long long> d(n), pref(n);     for (int i = 0; i < n; i++) cin >> d[i];     sort(d.begin(), d.end());     pref[0] = d[0];     for (int i = 1; i < n; i++) pref[i] = (pref[i - 1] + d[i]) % 998244353;     while (m--) {       int a, b;       cin >> a >> b;       int x = lower_bound(d.begin(), d.end(), b) - d.begin();       int big = n - x;       if (big < a) {         cout << 0 <<   n ;         continue;       }       long long big_total = (pref[n - 1] - (x > 0 ? pref[x - 1] : 0)) % 998244353;       (big_total += 998244353) %= 998244353;       long long ans = (big_total * (big - a)) % 998244353;       ans = (ans * bigmod(big, 998244353 - 2)) % 998244353;       long long tmp = ((x > 0 ? pref[x - 1] : 0) * (big + 1 - a)) % 998244353;       tmp = (tmp * bigmod(big + 1, 998244353 - 2)) % 998244353;       ans = (ans + tmp) % 998244353;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846264338327950288419716939937510,                     EPS = 1e-9;   const int MAX = 1 << 17;   struct prav {     long double a, b, c;   };   pair<int, int> sred;   long double Sq(long double x) { return x * x; }   long double Dist(pair<int, int> a, pair<int, int> b) {     return sqrt(Sq(a.first - b.first) + Sq(a.second - b.second));   }   long double DistPrav(prav p, pair<int, int> toc) {     return abs(p.a * toc.first + p.b * toc.second + p.c) /            sqrt((Sq(p.a) + Sq(p.b)));   }   prav Pravac(pair<int, int> a, pair<int, int> b) {     return prav{         (long double)b.second - a.second, (long double)a.first - b.first,         (long double)b.first * a.second - (long double)a.first * b.second};   }   pair<int, int> tocke[MAX];   int main() {     int n;     scanf( %d%d%d , &n, &sred.first, &sred.second);     for (int i = 0; i < n; i++) scanf( %d%d , &tocke[i].first, &tocke[i].second);     long double minn = 1e15, maxx = -1e15;     for (int i = 0; i < n; i++) {       long double dd = Dist(sred, tocke[i]);       minn = min(minn, dd);       maxx = max(maxx, dd);       int slj = (i + 1) % n;       if (Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[i], sred)) + EPS >               Sq(Dist(tocke[slj], sred)) &&           Sq(Dist(tocke[i], tocke[slj])) + Sq(Dist(tocke[slj], sred)) + EPS >               Sq(Dist(tocke[i], sred))) {         minn = min(minn, DistPrav(Pravac(tocke[i], tocke[slj]), sred));       }     }     printf( %.15lf n , (double)((Sq(maxx) - Sq(minn)) * PI));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int n;   vector<int> nailed;   struct evn {     int pos, type, num;   };   vector<evn> events;   bool comp(const evn& a, const evn& b) {     if (a.pos == b.pos && a.type == b.type) return a.num < b.num;     if (a.pos == b.pos) return a.type == 0;     return a.pos < b.pos;   }   int main() {     srand(chrono::steady_clock::now().time_since_epoch().count());     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     nailed.resize(n, 0);     int l, r;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n))) {       cin >> l >> r;       if (r < l) swap(l, r);       evn a, b;       a.pos = l;       a.num = i;       a.type = 0;       events.push_back(a);       b.pos = r;       b.num = i;       b.type = 1;       events.push_back(b);     }     sort(events.begin(), events.end(), comp);     queue<int> pinned;     vector<int> ans;     for (auto it : events) {       if (it.type) {         if (nailed[it.num] == 0) {           while (!pinned.empty()) {             int ind = pinned.front();             nailed[ind] = 1;             pinned.pop();           }           nailed[it.num] = 1;           ans.push_back(it.pos);         }       } else {         pinned.push(it.num);       }     }     cout << (int)(ans.size()) <<   n ;     if ((int)(ans.size()) > 0) {       for (auto it : ans) cout << it <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 5;   int n, k, v;   int a[maxn];   bool f[maxn][maxn];   pair<int, int> fr[maxn][maxn];   bool u[maxn][maxn];   bool vis[maxn];   struct ex {     int cnt, x, y;   };   vector<ex> ans;   vector<int> vec;   int read() {     int x;     scanf( %d , &x);     return x;   }   int main() {     int i, j;     int x, y;     n = read();     k = read();     v = read();     f[0][0] = true;     for (i = 1; i <= n; i++) {       a[i] = read();       for (j = 0; j < k; j++) {         f[i][j] = f[i - 1][j];         fr[i][j] = make_pair(i - 1, j);         u[i][j] = false;       }       for (j = 0; j < k; j++) {         if (f[i - 1][j]) {           if (!f[i][(j + a[i]) % k]) {             f[i][(j + a[i]) % k] = true;             fr[i][(j + a[i]) % k] = make_pair(i - 1, j);             u[i][(j + a[i]) % k] = true;           }         }       }     }     if (!f[n][v % k]) {       printf( NO n );       return 0;     }     pair<int, int> tmp = make_pair(n, v % k);     while (tmp.first) {       if (u[tmp.first][tmp.second]) {         vec.push_back(tmp.first);         vis[tmp.first] = true;       }       tmp = fr[tmp.first][tmp.second];     }     for (i = 1; i < vec.size(); i++) {       x = vec[i];       ans.push_back((ex){a[x] / k + 1, x, vec[0]});       a[vec[0]] += a[x];       a[x] = 0;     }     if (v % k) {       x = vec[0];       y = 1;       if (x == 1) {         y = 2;       }     } else {       x = 1;       y = 2;       ans.push_back((ex){a[x] / k + 1, x, y});       a[y] += a[x];       a[x] = 0;       vis[x] = true;     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         y = i;         break;       }     }     for (i = y + 1; i <= n; i++) {       if (!vis[i]) {         ans.push_back((ex){a[i] / k + 1, i, y});         a[y] += a[i];         a[i] = 0;       }     }     if (a[x] >= v) {       ans.push_back((ex){(a[x] - v) / k, x, y});     } else {       if (a[x] + a[y] / k * k < v) {         printf( NO n );         return 0;       } else {         ans.push_back((ex){(v - a[x]) / k, y, x});       }     }     printf( YES n );     for (ex t : ans) {       if (t.cnt >= 1) printf( %d %d %d n , t.cnt, t.x, t.y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buffer[10];   bool query(int x, int y) {     cout << x <<     << y << endl;     cout.flush();     cin >> buffer;     return (buffer[0] ==  w );   }   const int Y = 100;   bool get(int x) { return query(x, Y); }   void answer(int l, int r) {     cout << l <<     << (Y - 1) <<    ;     cout << r <<     << (Y + 1) <<   n ;   }   int main() {     int n;     cin >> n;     const bool init = get(0);     int l = 0, r = 1000 * 1000 * 1000;     for (int i = 1; i < n; i++) {       int m = (r - l) / 2 + l;       if (get(m) == init) {         l = m;       } else {         r = m;       }     }     answer(l, r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int T, n, m, ans;   char s[N], p[N];   int ne[N], len[N];   int main() {     scanf( %s , s + 1);     m = strlen(s + 1);     cin >> T;     while (T--) {       scanf( %s , p + 1);       n = strlen(p + 1);       if (n == 1) continue;       for (int i = 2, j = 0; i <= n; i++) {         while (j && p[i] != p[j + 1]) j = ne[j];         if (p[i] == p[j + 1]) j++;         ne[i] = j;       }       memset(len, 0, sizeof len);       for (int i = 1, j = 0; i <= m; i++) {         while (j && s[i] != p[j + 1]) j = ne[j];         if (s[i] == p[j + 1]) j++;         len[i] = max(len[i - 1], j);         if (j == n) j = ne[j];       }       memset(ne, 0, sizeof ne);       for (int i = 2, j = 0; i <= n; i++) {         while (j && p[n - i + 1] != p[n - j]) j = ne[j];         if (p[n - i + 1] == p[n - j]) j++;         ne[i] = j;       }       bool flag = false;       for (int i = 1, j = 0; i <= m; i++) {         while (j && s[m - i + 1] != p[n - j]) j = ne[j];         if (s[m - i + 1] == p[n - j]) j++;         if (j && len[m - i] && (j + len[m - i] >= n)) {           flag = true;           break;         }         if (j == n) j = ne[j];       }       if (flag) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min_dist[3005][3005];   vector<int> furthest_out[3005];   vector<pair<int, int> > X;   vector<pair<int, int> > furthest_in[3005];   vector<int> E[3005];   int n;   void bfs(int source) {     for (int j = 1; j <= n; j++) min_dist[source][j] = 1 << 30;     min_dist[source][source] = 0;     queue<int> Q;     Q.push(source);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       int d = min_dist[source][v];       for (int i = 0; i < E[v].size(); i++) {         int to = E[v][i];         if (min_dist[source][to] >= (1 << 30)) {           min_dist[source][to] = d + 1;           Q.push(to);         }       }     }     X.clear();     for (int i = 1; i <= n; i++) {       if (i == source) continue;       if (min_dist[source][i] >= (1 << 30)) continue;       X.push_back(make_pair(min_dist[source][i], i));       furthest_in[i].push_back(make_pair(min_dist[source][i], source));     }     sort(X.begin(), X.end());     reverse(X.begin(), X.end());     for (int i = 0; i < X.size() && i < 5; i++) {       furthest_out[source].push_back(X[i].second);     }   }   long long v[222222];   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     int m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       E[u].push_back(v);     }     for (int i = 1; i <= n; i++) bfs(i);     for (int i = 1; i <= n; i++) {       sort(furthest_in[i].begin(), furthest_in[i].end());       reverse(furthest_in[i].begin(), furthest_in[i].end());     }     long long ans = 0;     int x = -1, y = -1, z = -1, dd = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         if (min_dist[i][j] == (1 << 30)) {           continue;         }         for (int k = 0; k < furthest_in[i].size() && k < 6; k++) {           int a = furthest_in[i][k].second;           if (i == a || j == a) continue;           for (int p = 0; p < furthest_out[j].size() && p < 6; p++) {             int b = furthest_out[j][p];             if (a == b) continue;             if (i == b || j == b) continue;             long long cur = min_dist[a][i] + min_dist[i][j] + min_dist[j][b];             if (cur > ans) {               ans = cur;               x = i;               y = j;               z = a;               dd = b;             }           }         }       }     }     cout << z <<     << x <<     << y <<     << dd << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace myrand {   mt19937 mt(chrono::system_clock::now().time_since_epoch() /              chrono::microseconds(1));   long long Int(long long l, long long r) {     return uniform_int_distribution<long long>(l, r)(mt);   }   }  // namespace myrand   using namespace myrand;   auto ss = chrono::system_clock::now();   double remain_time() {     auto en = chrono::system_clock::now();     return (chrono::duration_cast<chrono::nanoseconds>(en - ss).count() * 1e-9);   }   long long cnt;   long long dp[3001][3001];   const long long mod = 998244353;   void solve(string s, string t) {     int n = s.size();     int m = t.size();     for (int i = 0; i <= n; i++) dp[i][i] = 1;     for (int len = 1; len <= n; len++)       for (int i = 0; i + len <= n; i++) {         int j = i + len;         if (i >= m || s[len - 1] == t[i]) dp[i][j] += dp[i + 1][j];         if (j > m || s[len - 1] == t[j - 1]) dp[i][j] += dp[i][j - 1];         dp[i][j] %= mod;       }     for (int j = m; j <= n; j++) cnt = (cnt + dp[0][j]) % mod;     cout << cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, t;     cin >> s;     cin >> t;     solve(s, t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int dp[300000];   int main() {     int r, g;     cin >> r >> g;     int h;     int low = 0, high = 1000;     while (low <= high) {       int mid = (low + high) / 2;       if (mid * (mid + 1) / 2 <= r + g)         h = mid, low = mid + 1;       else         high = mid - 1;     }     int all = h * (h + 1) / 2;     dp[0] = 1;     for (int i = 1; i <= h; i++) {       for (int j = r; j >= 0; j--) {         dp[j + i] += dp[j];         dp[j + i] %= mod;       }     }     int ans = 0;     for (int i = min(all, r); i >= max(0, all - g); --i) {       ans = (ans + dp[i]) % mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50, B = 1111;   const long double inf = 5e18;   const long double eps = 1e-12;   int n, q, a[N], b[N], f[N], blo[N], sq, num, ll[N], rr[N], dfn[N], dfm[N], clk,       idfn[N];   vector<int> v[N];   int read() {     int x = 0, c, f = 1;     while (!isdigit(c = getchar())) c ==  -  ? f = -1 : 0;     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return x * f;   }   void dfs(int x) {     dfn[x] = ++clk;     idfn[clk] = x;     for (int i = 0; i < v[x].size(); i++) dfs(v[x][i]);     dfm[x] = clk;   }   long double k(long long y, int x) {     return x ? 1.0 * y / x : y > 0 ? inf : -inf;   }   void cmax(long long &x, long long y) { y > x ? x = y : 0; }   bool cmp(int x, int y) { return b[idfn[x]] < b[idfn[y]]; }   struct node {     int a[N], b[N], t[N], st[B][B], tp[B];     long long y[N];     vector<int> v[B];     void build(int i) {       int *Q = st[i], &R = tp[i];       R = 0;       for (int j = 0; j < v[i].size(); j++) {         int x = v[i][j];         assert(!j || b[x] >= b[v[i][j - 1]]);         while (R > 1 && k(y[Q[R]] - y[Q[R - 1]], b[Q[R]] - b[Q[R - 1]]) -                                 k(y[x] - y[Q[R]], b[x] - b[Q[R]]) <                             eps)           R--;         Q[++R] = x;       }     }     void init() {       for (int i = 1; i <= num; i++) {         for (int j = ll[i]; j <= rr[i]; j++)           v[i].push_back(j), y[j] = 1ll * a[j] * b[j];         sort(v[i].begin(), v[i].end(), cmp);         build(i);       }     }     void change(int l, int r, int x) {       for (int i = l; i <= min(r, rr[blo[l]]); i++)         a[i] -= x, y[i] = 1ll * a[i] * b[i];       build(blo[l]);       if (blo[l] != blo[r]) {         for (int i = ll[blo[r]]; i <= r; i++) a[i] -= x, y[i] = 1ll * a[i] * b[i];         build(blo[r]);       }       for (int i = blo[l] + 1; i < blo[r]; i++) t[i] += x;     }     long long query(int l, int r) {       long long ret = 0;       for (int i = l; i <= min(r, rr[blo[l]]); i++)         cmax(ret, 1ll * (a[i] - t[blo[l]]) * b[i]);       if (blo[l] != blo[r])         for (int i = ll[blo[r]]; i <= r; i++)           cmax(ret, 1ll * (a[i] - t[blo[r]]) * b[i]);       for (int i = blo[l] + 1; i < blo[r]; i++) {         int *Q = st[i], &R = tp[i];         while (R > 1 &&                k(y[Q[R]] - y[Q[R - 1]], b[Q[R]] - b[Q[R - 1]]) < t[i] + eps)           R--;         cmax(ret, 1ll * (a[Q[R]] - t[i]) * b[Q[R]]);       }       return ret;     }   } F, G;   int main() {     scanf( %d%d , &n, &q);     sq = max((int)sqrt(n / 6), 1);     for (int i = 2; i <= n; i++) v[f[i] = read()].push_back(i);     dfs(1);     for (int i = 1; i <= n; i++) a[i] = read() + a[f[i]];     for (int i = 1; i <= n; i++) b[i] = read() + b[f[i]];     for (int i = 1; i <= n; i++) blo[i] = (i - 1) / sq + 1;     num = blo[n];     for (int i = 1; i <= num; i++) ll[i] = (i - 1) * sq + 1, rr[i] = i * sq;     rr[num] = n;     for (int i = 1; i <= n; i++)       F.a[i] = G.a[i] = -a[idfn[i]], F.b[i] = b[idfn[i]], G.b[i] = -b[idfn[i]];     F.init();     for (int i = 1; i <= n; i++) b[i] = -b[i];     G.init();     for (int i = 1, op, x, y; i <= q; i++) {       op = read();       x = read();       if (op == 1)         y = read(), F.change(dfn[x], dfm[x], y), G.change(dfn[x], dfm[x], y);       else         cout << max(F.query(dfn[x], dfm[x]), G.query(dfn[x], dfm[x])) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, A[100];     cin >> n;     int aux = 0, ans = 15;     while (n--) {       int t;       cin >> t;       if (t <= ans)         ans = t + 15;       else         break;     }     if (ans > 90) ans = 90;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   const long long INF = 1e9 + 7;   long long n, ans = INF;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     long long n = s.size();     for (long long mask = 1; mask < 1 << n; mask++) {       long long t = 0;       bool check = true;       for (long long i = 0; i < n; i++)         if (mask >> i & 1) {           t = t * 10 + s[i] -  0 ;           if (t == 0 && s[i] ==  0 ) check = false;         }       long long tt = sqrt(t);       if (tt * tt == t && tt != 0 && check)         ans = min(ans, n - __builtin_popcount(mask));     }     cout << (ans == INF ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000000000001, mod = 1000000007;   long long toi(string s) {     long long a;     istringstream in(s);     in >> a;     return a;   }   int main() {     string s;     cin >> s;     for (int i = 1; i < s.length(); i++)       if (s[i] == s[i - 1]) {         cout <<  Impossible ;         return 0;       }     int a, b;     for (int i = 0; i < s.length(); i++)       for (int j = i + 1; j < s.length(); j++)         if (s[i] == s[j]) {           a = i;           b = j;           break;         }     char arr[2][13];     int A = b - a - 1, B = 26 - A - 1;     arr[0][A / 2] = s[a];     int x = 0, y = A / 2;     int cnt = A;     int p = a + 1;     while (cnt) {       if (x == 0 && y > 0)         y--;       else if (x == 0 && y == 0)         x++;       else         y++;       arr[x][y] = s[p];       p++;       cnt--;     }     cnt = B;     x = 0;     y = A / 2;     p = (b + 1) % 27;     while (cnt) {       if (x == 0 && y < 12)         y++;       else if (x == 0 && y == 12)         x++;       else         y--;       arr[x][y] = s[p];       p++;       p %= 27;       cnt--;     }     for (int i = 0; i < 13; i++) cout << arr[0][i];     cout <<   n ;     for (int i = 0; i < 13; i++) cout << arr[1][i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       long long int n, i, arr[200005];       string s;       cin >> n;       cin >> s;       long long int ans = 0;       for (i = 0; i < n; i++) {         int p = s[i] - 48;         if (p % 2 == 0) {           ans += i + 1;         }       }       cout << ans << endl;     }     return 0;   }