#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long long N = (long long)2e6 + 222;   const long long INF = (long long)1e18;   const double eps = (double)1e-6;   long long n, m, l, r, used[N];   vector<long long> g[N];   set<long long> s;   long long cnt = 0;   void dfs(long long x) {     used[x] = 1;     s.erase(x);     cnt++;     long long pr = 0;     for (auto to : g[x]) {       while (s.upper_bound(pr) != s.end() && (*s.upper_bound(pr)) < to) {         long long k = (*s.upper_bound(pr));         if (!used[k]) dfs(k);       }       pr = to;     }   }   void solve() {     cin >> n >> m;     for (long long i = 1; i <= m; ++i) {       cin >> l >> r;       g[l].push_back(r);       g[r].push_back(l);     }     for (long long i = 1; i <= n; ++i) s.insert(i);     long long ans = 0;     for (long long i = 1; i <= n; ++i) sort(g[i].begin(), g[i].end());     for (long long i = 1; i <= n; ++i) g[i].push_back(n + 1);     for (long long i = 1; i <= n; ++i) {       if (!used[i]) {         ans++;         dfs(i);       }     }     cout << ans - 1;   }   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;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n <= 3 || n == 5 || n == 7 || n == 11) {         cout <<  -1               <<   n ;       } else {         if (n % 2 == 0) {           cout << n / 4 <<   n ;         } else {           cout << n / 4 - 1 <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[300000][2], fa[300000], sz[300000], top[300000], d[300000],       prf[300000], f1[300000], q1[300000], q2[300000];   vector<int> g[300000], b[300000];   map<int, map<int, int> > f2[300000];   long long ans;   void dfs1(int u) {     d[u] = d[fa[u]] + 1;     sz[u] = 1;     for (int v : g[u])       if (v != fa[u]) {         fa[v] = u;         dfs1(v);         sz[u] += sz[v];       }   }   void dfs2(int u) {     if (!top[u]) top[u] = u;     b[top[u]].push_back(u);     int t = 0;     for (int v : g[u])       if (v != fa[u] && sz[v] > sz[t]) t = v;     if (!t) return;     prf[u] = t;     top[t] = top[u];     dfs2(t);     for (int v : g[u])       if (v != fa[u] && v != t) dfs2(v);   }   int lca(int x, int y) {     for (; top[x] != top[y]; x = fa[top[x]])       if (d[top[x]] < d[top[y]]) swap(x, y);     return d[x] < d[y] ? x : y;   }   int go(int x, int k) {     int len = d[x] - d[top[x]];     if (len < k) return go(fa[top[x]], k - len - 1);     return b[top[x]][len - k];   }   int add1(int x, int y) {     int len = d[x] - d[y];     if (len < k) return x;     int z = go(x, len - k + 1);     ++f1[x];     --f1[z];     return z;   }   void add2(int u1, int u2, int v1, int v2) {     if (top[u1] > top[v1]) swap(u1, v1), swap(u2, v2);     if (d[u1] > d[u2]) swap(u1, u2);     ++f2[top[u1]][top[v1]][d[u1]];     --f2[top[u1]][top[v1]][d[u2] + 1];   }   void add(int x, int y) {     int z = lca(x, y);     x = add1(x, z);     y = add1(y, z);     int u = x, v = y;     int n1 = 0, n2 = 0;     for (; top[u] != top[z]; u = fa[top[u]]) q1[++n1] = u;     for (; top[v] != top[z]; v = fa[top[v]]) q2[++n2] = v;     if (u != z) q1[++n1] = u;     if (v != z) q2[++n2] = v;     for (int i1 = 1, i2 = n2; i1 <= n1; ++i1) {       int u1 = q1[i1], u2 = top[u1];       if (d[u2] <= d[z]) u2 = prf[z];       for (; i2; --i2) {         int v1 = q2[i2], v2 = top[v1];         if (d[v2] <= d[z]) v2 = prf[z];         if (d[u1] + d[v1] - d[z] * 2 < k) continue;         int len = d[u1] + d[v1] - d[z] * 2;         int w1 = go(v1, len - k), w2 = 0;         len = d[u2] + d[v1] - d[z] * 2;         if (len >= k) {           w2 = go(v1, len - k);           add2(u1, u2, w1, w2);           break;         }         len = d[u1] + d[v1] - d[z] * 2;         w2 = go(u1, len - k);         add2(u1, w2, w1, v1);         u1 = fa[w2];       }     }   }   long long C(long long x) { return x * (x - 1) / 2; }   void dfs3(int u, int t) {     for (int v : g[u])       if (v != fa[u]) {         dfs3(v, t);         f1[u] += f1[v];       }     ans += C(f1[u]) * t;   }   void calc(int t) {     for (int i = 1; i <= n; ++i) {       for (auto j : f2[i]) {         long long sum = 0, lst = 0;         for (auto k : j.second) {           ans += (k.first - lst) * C(sum) * t;           lst = k.first;           sum += k.second;         }       }       f2[i].clear();     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , a[i] + 0, a[i] + 1);       add(a[i][0], a[i][1]);     }     dfs3(1, 1);     calc(1);     memset(f1, 0, sizeof f1);     ++k;     for (int i = 1; i <= m; ++i) add(a[i][0], a[i][1]);     dfs3(1, -1);     calc(-1);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[300005];   map<int, int> mp;   vector<int> opt;   int main() {     int n, lst = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       if (mp[arr[i]] && mp[arr[i]] > lst) {         mp[arr[i]] = 0;         opt.push_back(++lst);         opt.push_back(i);         lst = i;       } else {         mp[arr[i]] = i;       }     }     int l = opt.size();     if (l / 2 == 0) {       printf( -1 n );       return 0;     }     printf( %d n , l / 2);     opt[l - 1] = n;     for (int i = 0; i < l; i++) {       printf( %d  , opt[i++]);       printf( %d n , opt[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double EPS = 1e-9;   const long long INF = 1e18 + 2007;   const double PI = 3.1415926535897932384626433832795;   const long long N = 200005;   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   signed main() {     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     long long g = 0;     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       g = gcd(g, a);     }     set<long long> ans;     for (long long i = 0; i < k; i++) {       ans.insert((g * i) % k);     }     cout << ans.size() << endl;     for (auto x : ans) {       cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, z, x = 10, k = 0, year = 0, l = 0, f = 0;     string s;     cin >> n;     while (n--) {       cin >> s;       x = 10;       f = 0;       year = 0;       k = s.length() - 4;       for (i = 1; i < k; i++) {         f += x;         x *= 10;       }       for (i = 4; i < s.length(); i++) {         year = year * 10 + 10 * (s[i] - 48);       }       year /= 10;       while (year < 1989 + f) {         year += x;       }       cout << year << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long f = 1, x = 0;     char ss = getchar();     while (ss <  0  || ss >  9 ) {       if (ss ==  - ) f = -1;       ss = getchar();     }     while (ss >=  0  && ss <=  9 ) {       x = x * 10 + ss -  0 ;       ss = getchar();     }     return f * x;   }   long long seed, vmax;   long long rnd() {     long long res = seed;     seed = (seed * 7 + 13) % 1000000007;     return res;   }   const int maxn = 100010;   int n, m;   long long a[maxn];   struct node {     int ll, rr;     mutable long long val;     bool operator<(const node& tt) const { return ll < tt.ll; }   };   set<node> st;   long long qpow(long long a, long long k, long long p) {     long long res = 1;     a %= p;     while (k > 0) {       if (k & 1) res = (res * a) % p;       a = (a * a) % p;       k >>= 1;     }     return res;   }   set<node>::iterator split(int pos) {     set<node>::iterator it = st.lower_bound(node{pos});     if (it != st.end() && it->ll == pos) return it;     --it;     int ll = it->ll, rr = it->rr;     long long val = it->val;     st.erase(it);     st.insert(node{ll, pos - 1, val});     return st.insert(node{pos, rr, val}).first;   }   void assign(int ll, int rr, long long val) {     set<node>::iterator itr = split(rr + 1), itl = split(ll);     st.erase(itl, itr);     st.insert(node{ll, rr, val});   }   void add(int ll, int rr, long long val) {     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl) itl->val += val;   }   long long kth(int ll, int rr, int k) {     vector<pair<long long, int> > vec;     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl)       vec.push_back(pair<long long, int>(itl->val, itl->rr - itl->ll + 1));     sort(vec.begin(), vec.end());     for (vector<pair<long long, int> >::iterator it = vec.begin();          it != vec.end(); ++it) {       k -= it->second;       if (k <= 0) return it->first;     }     return -1;   }   long long qsum(int ll, int rr, long long x, long long y) {     long long res = 0;     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl)       res += (qpow(itl->val, x, y) * ((itl->rr - itl->ll + 1) % y)) % y, res %= y;     return res;   }   int main() {     n = read();     m = read();     seed = read();     vmax = read();     for (int i = 1; i <= n; ++i) {       a[i] = (rnd() % vmax) + 1;       st.insert(node{i, i, a[i]});     }     for (int i = 1; i <= m; ++i) {       int op = (rnd() % 4) + 1;       int ll = (rnd() % n) + 1, rr = (rnd() % n) + 1;       long long x, y;       if (ll > rr) swap(ll, rr);       if (op == 3)         x = (rnd() % (rr - ll + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (op == 4) y = (rnd() % vmax) + 1;       if (op == 1)         add(ll, rr, x);       else if (op == 2)         assign(ll, rr, x);       else if (op == 3)         printf( %lld n , kth(ll, rr, x));       else if (op == 4)         printf( %lld n , qsum(ll, rr, x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fw[100005], s[100005], t[100005];   bool r[100005], v[100005];   int res = 0;   void dfs(int i) {     v[i] = true;     if (v[fw[i]]) {       t[res] = i;     } else {       dfs(fw[i]);     }   }   int main() {     int n = 0;     ios::sync_with_stdio(false);     memset(fw, 0, sizeof(fw));     memset(r, true, sizeof(r));     memset(v, false, sizeof(v));     cin >> n;     int num = 0;     for (int i = 1; i <= n; ++i) {       cin >> fw[i];       r[fw[i]] = false;     }     for (int i = 1; i <= n; ++i) {       if (r[i] && !v[i]) {         ++res;         s[res] = i;         dfs(i);       }     }     int cur = res;     for (int i = 1; i <= n; ++i) {       if (!v[i]) {         ++res;         s[res] = i;         dfs(i);       }     }     if (cur == 0 && res == 1) {       cout << 0 << endl;     } else {       cout << res << endl;       for (int i = 1; i <= res; ++i) {         cout << t[i] <<     << s[i % res + 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class F, class T>   T convert(F input, int width = 0, int prec = -1) {     stringstream A;     T res;     if (prec > -1) A << fixed << setprecision(prec);     A << setw(width) << setfill( 0 ) << input;     A >> res;     return res;   }   int main() {     string nm;     cin >> nm;     int ln = nm.length() - 1;     int dt = find((nm).begin(), (nm).end(),  . ) - nm.begin();     if (nm[dt - 1] !=  9  && nm[dt + 1] <  5 ) {       cout << nm.substr(0, dt);       return 0;     }     if (nm[dt - 1] !=  9  && nm[dt + 1] >=  5 ) {       string res = nm.substr(0, dt);       res[int((res).size()) - 1] = res[int((res).size()) - 1] + 1;       cout << res;       return 0;     }     cout <<  GOTO Vasilisa. ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string board[8];   int main() {     for (int i = 0; i < 8; ++i) cin >> board[i];     const char* s =  WB ;     for (int i = 0; i < 8; ++i) {       int c = board[i][0] ==  B ;       for (int j = 1; j < 8; ++j) {         if (board[i][j] != s[(c + j) % 2]) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   const int ms = 101;   long long memo[ms][ms], memo2[ms][ms][ms];   long long a[ms];   std::string str;   long long dp(int l, int r);   long long dp2(int l, int r, int x) {     if (r - l <= 0) return 0;     long long &ans = memo2[l][r][x];     if (ans != -1) return ans;     ans = dp(l + 1, r) + a[x];     for (int i = l + 1; i < r; i++) {       if (str[i] == str[l]) {         ans = std::max(ans, dp(l + 1, i) + dp2(i, r, x + 1));       }     }     return ans;   }   long long dp(int l, int r) {     if (r - l <= 0)       return 0;     else if (r - l == 1)       return a[1];     long long &ans = memo[l][r];     if (ans != -1) return ans;     ans = 0;     for (int m = l; m < r; m++) {       ans = std::max(ans, dp2(m, r, 1) + dp(l, m));     }     return ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n;     std::cin >> n >> str;     for (int i = 0; i < n; i++) {       std::cin >> a[i + 1];     }     memset(memo, -1, sizeof memo);     memset(memo2, -1, sizeof memo2);     std::cout << dp(0, n) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, x, b[110000];   void modify(int x, int y) {     for (; x <= n; x += x & -x) b[x] = ((b[x]) > (y) ? (b[x]) : (y));   }   int get(int x) {     int ans = 0;     for (; x; x -= x & -x) ans = ((ans) > (b[x]) ? (ans) : (b[x]));     return ans;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &x);       modify(x, get(x) + 1);     }     printf( %d n , get(n));   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, arr[200001], arr2[200001], e, f, g, mn = 1e9, ans, sum, ct, t,                                                       ct2, mx, sum2;   bool kk;   int main() {     cin >> a;     for (int i = 0; i < a; i++) {       cin >> arr[i];       sum += arr[i];     }     for (int i = 0; i < a; i++) {       sum2 += arr[i];       if (sum % 2) {         if (sum2 >= sum / 2 + 1) {           cout << i + 1;           return 0;         }       } else {         if (sum2 >= sum / 2) {           cout << i + 1;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[5], y[5];   int matr[5005][5005];   inline void err() {     for (int i = 0; i <= 5000; ++i)       for (int j = 0; j <= 5000; ++j) matr[i][j] = -1;   }   inline void fil(int i, int j, int ii, int jj, int val) {     for (int a = i; a <= ii; ++a)       for (int b = j; b <= jj; ++b) matr[a][b] = val;   }   int main() {     ios ::sync_with_stdio(false);     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int S = a * b + c * d + e * f;     int rad = (int)sqrt((double)S);     if (rad * rad != S) {       cout << -1;       exit(0);     }     x[0] = a;     y[0] = b;     x[1] = c;     y[1] = d;     x[2] = e;     y[2] = f;     int lim = 1 << 3;     lim--;     for (int i = 0; i <= lim; ++i) {       for (int j = 0; j <= 3; ++j)         if (i & (1 << j)) swap(x[j], y[j]);       err();       for (int masca = 0; masca <= lim; ++masca) {         if (__builtin_popcount(masca) < 2) continue;         int xx1 = 0;         int m = 0;         m ^= 1;         m ^= 2;         m ^= 4;         int ymax = 0;         int ymin = 1 << 30;         int tx = 0;         int ty = 0;         for (int j = 0; j <= 2; ++j)           if (masca & (1 << j)) {             xx1 += x[j];             m ^= (1 << j);             ymax = max(ymax, y[j]);             ymin = min(ymin, y[j]);           } else {             tx = x[j];             ty = y[j];           }         if (ty != ymax - ymin and ty != rad - ymax) continue;         if (xx1 == rad) {           err();           int lastx = 1;           int lasty = 1;           for (int j = 0; j <= 3; ++j)             if (masca & (1 << j)) {               fil(lastx, lasty, lastx + x[j] - 1, lasty + y[j] - 1, j);               lastx = lastx + x[j];               lasty = 1;             }           int muie = -1;           while (m) {             ++muie;             m >>= 1;           }           cout << rad <<   n ;           for (int i = 1; i <= rad; ++i) {             for (int j = 1; j <= rad; ++j) {               if (matr[i][j] == -1) matr[i][j] = muie;               cout << (char)(matr[i][j] +  A );             }             cout <<   n ;           }           exit(0);         }       }       for (int j = 0; j <= 3; ++j)         if (i & (1 << j)) swap(x[j], y[j]);     }     cout << -1;     exit(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n[101];   vector<int> cost;   int main() {     int N, B;     cin >> N >> B;     int o, e;     o = e = 0;     for (int i = 0; i < N; i++) {       cin >> n[i];     }     for (int i = 0; i < N; i++) {       if (n[i] % 2)         o++;       else         e++;       if (o == e) {         if (i < N - 1) {           cost.push_back(abs(n[i] - n[i + 1]));         }       }     }     if (o != e) {       cout << 0 << endl;     } else {       sort(cost.begin(), cost.end());       int i = 1, tot = 0;       for (; i <= cost.size(); i++) {         tot += cost[i - 1];         if (tot > B) break;       }       cout << i - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int root, n;   vector<int> mp[200605];   int Dfs(int u, int from) {     set<int> s;     for (int i = 0; i < mp[u].size(); i++) {       int v = mp[u][i];       if (v == from) continue;       int tmp = Dfs(v, u);       if (tmp == -1) return -1;       s.insert(tmp + 1);     }     if (s.size() == 0) return 0;     if (s.size() == 1) return *s.begin();     if (s.size() == 2) {       if (from == -1) {         int sum = 0;         for (set<int>::iterator it = s.begin(); it != s.end(); it++) {           sum += *it;         }         return sum;       } else {         root = u;         return -1;       }     }     return -1;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) mp[i].clear();       for (int i = 1; i <= n - 1; i++) {         int x, y;         scanf( %d%d , &x, &y);         mp[x].push_back(y);         mp[y].push_back(x);       }       root = 1;       int ans = Dfs(root, -1);       if (ans == -1 && root != 1) ans = Dfs(root, -1);       while (ans % 2 == 0) ans /= 2;       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m, long long p) {     long long r = 1;     n = n % p;     while (m > 0) {       if (m % 2) r = (r * n) % p;       n = (n * n) % p;       m = m / 2;     }     return r % p;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long> z_function(string s) {     long long n = (long long)s.length();     vector<long long> z(n);     for (long long i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     long long a[n], b[m];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     long long j = 0;     for (long long i = 0; i < n; i++) {       if (a[i] <= b[j]) {         ans++;         j++;       }       if (j == m) break;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 14050;   template <class t>   inline void read(t &s) {     s = 0;     register int f = 1;     register char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     s *= f;     return;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0) putchar( - ), x = -x;     int buf[21], top = 0;     while (x) buf[++top] = x % 10, x /= 10;     if (!top) buf[++top] = 0;     while (top) putchar(buf[top--] ^  0 );     return;   }   inline void setIn(string s) {     freopen(s.c_str(),  r , stdin);     return;   }   inline void setOut(string s) {     freopen(s.c_str(),  w , stdout);     return;   }   inline void setIO(string s =   ) {     setIn(s +  .in );     setOut(s +  .out );     return;   }   template <class t>   inline bool checkmin(t &x, t y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   template <class t>   inline bool checkmax(t &x, t y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   inline int lowbit(int x) { return x & (-x); }   int s[2][MaxN], m[2];   int n;   bool vis[2][MaxN], win[2][MaxN];   int cnt[2][MaxN];   inline void dfs(int k, int u) {     if (!win[k][u])       for (int i = 1; i <= m[k ^ 1]; ++i) {         register int nxt = (u - s[k ^ 1][i] - 1 + n) % n + 1;         if (!vis[k ^ 1][nxt])           win[k ^ 1][nxt] = vis[k ^ 1][nxt] = true, dfs(k ^ 1, nxt);       }     else       for (int i = 1; i <= m[k ^ 1]; ++i) {         register int nxt = (u - s[k ^ 1][i] - 1 + n) % n + 1;         if (!vis[k ^ 1][nxt] && ++cnt[k ^ 1][nxt] >= m[k ^ 1])           vis[k ^ 1][nxt] = true, dfs(k ^ 1, nxt);       }     return;   }   signed main(void) {     read(n);     read(m[0]);     for (int i = 1; i <= m[0]; ++i) read(s[0][i]);     read(m[1]);     for (int i = 1; i <= m[1]; ++i) read(s[1][i]);     vis[0][1] = vis[1][1] = true;     dfs(1, 1);     dfs(0, 1);     for (int i = 0; i < 2; ++i, puts(  ))       for (int j = 2; j <= n; ++j)         printf( %s  , (vis[i][j] ? (win[i][j] ?  Win  :  Lose ) :  Loop ));     return 0;   }


/*    Solution by:-     --------------Sannidhay Vashal    ----------------NIT SRINAGAR       */   #include<iostream>   #include<vector>   #include<algorithm>   #include<stack>   #include<queue>   #include<map>   #include<math.h>   #include<climits>   #include<set>   #include<cstring>   #include<unordered_map>   #include <cstdlib>    #include<cmath>       #define fio ios_base::sync_with_stdio(false);cin.tie(NULL)   #define ll            long long int   #define ull           unsigned long long int   #define cinll(x)      ll x;cin>>x;   #define cini(x)       int x;cin>>x;   #define cins(x)       string x;cin>>x;   #define vect(x)       vector<ll> x;   #define vect1(x)      vector<ll> x;x.push_back(0);   #define pb(x)         push_back(x)   #define mp(x,y)       make_pair(x,y)   #define MAX           1e18   #define MIN           -1000000007   #define MOD           1000000007      using namespace std;      bool compare(pair<ll,ll> a,pair<ll,ll> b){     return a.second<b.second;   }      int main(){     cinll(t);     while(t--){       cinll(n);       vector<ll> arr;       unordered_map<ll,ll> mapit;       vector<pair<ll,ll>> ans;       for(ll i=0;i<n;i++) {         cinll(x);         arr.pb(x);         mapit[x]++;       }       ll anss = -1;       for(ll i=0;i<n;i++){         if(mapit[arr[i]]==1) ans.pb(mp(i+1,arr[i]));       }       sort(ans.begin(),ans.end(),compare);       if(ans.size()>=1) anss = ans[0].first;       cout<<anss<<  n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans, n, m, a, r, c, sum, sums[1000002], sumsR[1000002],       sumsC[1000002], sumsR2[1000002], sumsC2[1000002];   const long long p = 998244353;   struct el {     long long x, r, c;   };   bool operator<(el x, el y) { return x.x < y.x; }   el arr[1000002];   long long modu(long long am, long long bm) {     long long ansm = am, p2 = p - 2, h = bm;     while (p2 > 0) {       if ((p2 & 1) != 0) ansm = (ansm * h) % p;       h = (h * h) % p;       p2 /= 2;     }     return ansm;   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= n * m; i++) {       cin >> a;       arr[i].x = a;       arr[i].r = (i - 1) / m + 1;       arr[i].c = (i - 1) % m + 1;     }     cin >> r >> c;     sort(arr + 1, arr + n * m + 1);     sums[1] = 0;     sumsR[1] = arr[1].r % p;     sumsC[1] = arr[1].c % p;     sumsR2[1] = (arr[1].r * arr[1].r) % p;     sumsC2[1] = (arr[1].c * arr[1].c) % p;     a = 0;     for (int i = 2; i <= n * m; i++) {       if (arr[i].x != arr[i - 1].x) a = i - 1;       sum = 0;       sum += sums[a] % p;       sum %= p;       sum += (a * arr[i].r * arr[i].r) % p;       sum %= p;       sum += (a * arr[i].c * arr[i].c) % p;       sum %= p;       sum += (sumsR2[a]) % p;       sum %= p;       sum += (sumsC2[a]) % p;       sum %= p;       sum -= (2 * arr[i].r * sumsR[a]) % p;       sum %= p;       if (sum < 0) sum += p;       sum -= (2 * arr[i].c * sumsC[a]) % p;       sum %= p;       if (sum < 0) sum += p;       sum = modu(sum, a);       if (arr[i].r == r && arr[i].c == c) {         ans = sum;         break;       }       sumsR[i] = (sumsR[i - 1] + arr[i].r) % p;       sumsC[i] = (sumsC[i - 1] + arr[i].c) % p;       sumsR2[i] = (sumsR2[i - 1] + arr[i].r * arr[i].r) % p;       sumsC2[i] = (sumsC2[i - 1] + arr[i].c * arr[i].c) % p;       sums[i] = (sums[i - 1] + sum);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NM = 1000005;   const int Mod = 1000000007;   int N, m, n, p26 = 0, pi[NM], i, x, y, b[NM];   char a[NM];   bool kmp[NM];   long long put(long long a, int b) {     if (!b) return 1;     if (b & 1) return a * put(a * a % Mod, b >> 1) % Mod;     return put(a * a % Mod, b >> 1);   }   void KMP() {     int i, k = 0;     pi[1] = 0;     for (i = 2; i <= n; ++i) {       while (k && a[i] != a[k + 1]) k = pi[k];       if (a[i] == a[k + 1]) ++k;       pi[i] = k;     }     while (k) {       kmp[k] = 1;       k = pi[k];     }   }   int main() {     scanf( %d %d n , &N, &m);     gets(a + 1);     n = strlen(a + 1);     KMP();     if (!m) {       printf( %I64d n , put(26LL, N));       return 0;     }     for (i = 1; i <= m; ++i) scanf( %d , &b[i]);     p26 += b[1] - 1;     for (i = 1; i < m; ++i) {       x = b[i] + n - 1;       y = b[i + 1];       if (x < y)         p26 += y - x - 1;       else if (!kmp[x - y + 1]) {         printf( 0 n );         return 0;       }     }     p26 += N;     p26 -= b[i] + n - 1;     printf( %I64d n , put(26LL, p26));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   char s[N];   int cost(char a, char b) { return min(abs(b - a), 26 - abs(b - a)); }   int main() {     int ans = 1e9;     int n;     cin >> n;     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       int j = i + 1, k = j + 1, t = k + 1;       if (t > n) continue;       ans = min(ans, cost(s[i],  A ) + cost(s[j],  C ) + cost(s[k],  T ) +                          cost(s[t],  G ));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int m, h, t, n, i, j, k;   int a[200000], q[200000];   long long sum[200000], ans;   long long pas[200000];   long long get(int i, int j) { return sum[j] - sum[i] + a[i]; }   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (i = 0; i < m; i++) cin >> q[i];     sort(a, a + n);     sum[0] = a[0];     for (i = 1; i < n; i++) {       sum[i] = sum[i - 1];       sum[i] += a[i];     }     for (i = 1; i <= 100000; i++) {       ans = 0;       long long num = 0;       long long freespace = i;       for (j = n - 2; j >= 0;) {         if (freespace > n * 10) freespace = n * 10;         num++;         long long l = j - freespace + 1;         if (l < 0) l = 0;         ans += num * get(l, j);         j = j - freespace;         freespace = freespace * i;       }       pas[i] = ans;     }     for (i = 0; i < m; i++) cout << pas[q[i]] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target(         sse,sse2,sse3,sse4,fma4,ssse3,popcnt,abm,aes,pclmul,cld,inline-all-stringops )   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   static unsigned rnd() {     static int second = 124612741;     second ^= second << 13;     second ^= second >> 17;     return second ^= second << 5;   }   inline int fpow(int a, int st, int mod) {     int ans = 1;     while (st) {       if (st % 2) ans = (long long)ans * a % mod;       a = (long long)a * a % mod;       st /= 2;     }     return ans;   }   int invmod(int first, int second) {     int a = 1, b = 0, k;     for (; second; swap(first, second), swap(a, b)) {       k = first / second;       first -= second * k;       a -= b * k;     }     return a + max(b, 0);   }   inline int calcBits(int a) { return __builtin_popcount(a); }   struct Hash {     Hash() : x1(0), x2(0) {}     Hash(const int& x1, const int& x2) : x1(x1), x2(x2) {}     int x1, x2;     static int mod1, mod2;     static int p1, p2;     static int invp1, invp2;     static bool initCalled;     static const Hash ONE, ZERO, INVALID;     static Hash UNIT, INV_UNIT;     static bool prime(int a) {       if (a == 1) return 0;       for (int i = 2; i * i <= a; ++i) {         if (a % i == 0) return false;       }       return true;     }     static int pickModHelper(int start, int bad) {       int mn = 1000000000, best = -1;       for (int _n(start + 1000), i(start); i <= _n; i++) {         if (i == bad || !prime(i)) continue;         int cur = calcBits(i);         if (cur < mn) {           mn = cur;           best = i;         }       }       return best;     }     static void init() {       if (initCalled) return;       initCalled = true;       mod1 = 1 << 30;       while (!prime(mod1)) ++mod1;       mod2 = pickModHelper((1 << 29) + rnd() % 1000000, mod1);       invp1 = invmod(p1, mod1);       invp2 = invmod(p2, mod2);       INV_UNIT = Hash(invp1, invp2);     }     inline Hash& operator+=(const Hash& other) {       x1 += other.x1;       if (x1 >= Hash::mod1) x1 -= Hash::mod1;       x2 += other.x2;       if (x2 >= Hash::mod2) x2 -= Hash::mod2;       return *this;     }     inline Hash& operator-=(const Hash& other) {       x1 -= other.x1;       if (x1 < 0) x1 += Hash::mod1;       x2 -= other.x2;       if (x2 < 0) x2 += Hash::mod2;       return *this;     }     inline Hash& operator*=(const Hash& other) {       x1 = (long long)x1 * other.x1 % Hash::mod1;       x2 = (long long)x2 * other.x2 % Hash::mod2;       return *this;     }     inline Hash& operator*=(const int& other) {       x1 = (long long)x1 * other % Hash::mod1;       x2 = (long long)x2 * other % Hash::mod2;       return *this;     }     inline Hash& operator^=(const int& power) {       int st = power;       Hash ans(1, 1);       while (st) {         if (st % 2) ans *= *this;         x1 = (long long)x1 * x1 % Hash::mod1;         x2 = (long long)x2 * x2 % Hash::mod2;         st /= 2;       }       return *this;     }     inline bool operator==(const Hash& other) const {       return x1 == other.x1 && x2 == other.x2;     }   };   bool Hash::initCalled = false;   int Hash::mod1 = 0;   int Hash::mod2 = 0;   int Hash::p1 = 23561;   int Hash::p2 = 10000019;   int Hash::invp1 = -1;   int Hash::invp2 = -1;   const Hash Hash::ONE(1, 1);   const Hash Hash::ZERO(0, 0);   const Hash Hash::INVALID(-1, -1);   Hash Hash::UNIT(Hash::p1, Hash::p2);   Hash Hash::INV_UNIT(-1, -1);   inline Hash operator+(const Hash& a, const Hash& b) {     Hash ans(a.x1 + b.x1, a.x2 + b.x2);     if (ans.x1 >= Hash::mod1) ans.x1 -= Hash::mod1;     if (ans.x2 >= Hash::mod2) ans.x2 -= Hash::mod2;     return ans;   }   inline Hash operator-(const Hash& a, const Hash& b) {     Hash ans(a.x1 - b.x1, a.x2 - b.x2);     if (ans.x1 < 0) ans.x1 += Hash::mod1;     if (ans.x2 < 0) ans.x2 += Hash::mod2;     return ans;   }   inline Hash operator*(const Hash& a, const Hash& b) {     return Hash((long long)a.x1 * b.x1 % Hash::mod1,                 (long long)a.x2 * b.x2 % Hash::mod2);   }   inline Hash operator*(const Hash& a, const int& b) {     return Hash((long long)a.x1 * b % Hash::mod1,                 (long long)a.x2 * b % Hash::mod2);   }   inline Hash operator^(const Hash& a, const int& power) {     int st = power;     Hash ans(1, 1), cur(a);     while (st) {       if (st % 2) ans *= cur;       cur *= cur;       st /= 2;     }     return ans;   }   inline Hash fpow(const Hash& a, const int& power) { return a ^ power; }   inline Hash invmod(const Hash& a) {     return Hash(invmod(a.x1, Hash::mod1), invmod(a.x2, Hash::mod2));   }   template <class H>   struct HashString : public string {     HashString() : string() { precalc(0); }     HashString(const HashString& other) : string(other) { precalc(size()); }     HashString(HashString&& other)         : hh(std::move(other.hh)), string(std::move(other)) {       precalc(size());     }     HashString(const string& other) : string(other) {       precalc(size());       build();     }     HashString(string&& other) : string(std::move(other)) {       precalc(size());       build();     }     HashString(const char* other) : string(other) {       precalc(size());       build();     }     inline void clear() {       hh.clear();       string::clear();     }     inline static H getPow(int p) {       if (p < haveN) {         return pp[p];       } else {         return fpow(H::UNIT, p);       }     }     inline static H getInvPow(size_t p) {       if (p < invpp.size()) {         return invpp[p];       } else {         return fpow(H::INV_UNIT, p);       }     }     inline H getInvRegister(const H& p) const {       if (p == register_) {         return registerValue_;       } else {         register_ = p;         return registerValue_ = invmod(p);       }     }     static void precalc(int N = 0) {       Hash::init();       if (haveN >= N) return;       pp.resize(N);       invpp.resize(N);       if (!haveN) {         pp[0] = H::ONE;         invpp[0] = H::ONE;         haveN = 1;       }       for (int i = haveN; i < N; ++i) {         pp[i] = pp[i - 1] * H::UNIT;         invpp[i] = invpp[i - 1] * H::INV_UNIT;       }       haveN = N;     }     inline void build() {       int curSize = size();       if (haveN <= curSize) {         precalc(curSize);       }       for (int i = hh.size(); i < curSize; ++i) {         H pr = i ? hh.back() : H::ZERO;         hh.push_back(pr + getPow(i) * (*this)[i]);       }     }     inline H getHash(int pos, int len) const {       if (len <= 0) return H::ZERO;       const int S = size();       if (pos + len - 1 < S) {         H ans = hh[pos + len - 1];         if (pos) {           ans -= hh[pos - 1];           ans *= getInvPow(pos);         }         return ans;       } else {         H head = hh.back();         if (pos) {           head -= hh[pos - 1];           head *= getInvPow(pos);         }         int full = -1, en = -1;         H mid = H::ZERO;         int midlen = 0;         if (len <= S) {           en = pos + len - 1 - S;           H tail = hh[en];           full = 0;           return head + tail * getPow(S - pos);         } else {           en = (pos + len - 1) % S;           H tail = hh[en];           full = (len - (S - pos) - (en + 1)) / S;           mid = hh.back() * (H::ONE - getInvPow(full * S)) *                 getInvRegister(H::ONE - getInvPow(S));           return head + mid * getPow(S - pos) + tail * getPow(len - (en + 1));         }       }     }     inline HashString& operator+=(const char& ch) {       string::operator+=(ch);       build();       return *this;     }     inline HashString& operator+=(const HashString& other) {       string::operator+=(other);       build();       return *this;     }     inline bool operator==(const HashString& other) const {       return hh.back() == other.hh.back();     }     inline bool operator<(const HashString& other) const {       int s1 = size();       int s2 = other.size();       const int S = min(s1, s2);       int l = 0, r = S + 1;       while (r - l > 1) {         int xx = (r + l) / 2;         if (getHash(0, xx) == other.getHash(0, xx))           l = xx;         else           r = xx;       }       char c1 = 0, c2 = 0;       if (l < s1) c1 = (*this)[l];       if (l < s2) c2 = other[l];       return c1 < c2;     }     inline bool operator<=(const HashString& other) const {       return (*this == other) || (*this < other);     }     inline bool operator>(const HashString& other) const {       return !(*this == other) && !(*this < other);     }     inline bool operator>=(const HashString& other) const {       return !(*this < other);     }     inline bool operator!=(const HashString& other) const {       return !(*this == other);     }     inline void reserve(int N) {       hh.reserve(N);       string::reserve(N);     }     vector<H> hh;     static vector<H> pp, invpp;       private:     mutable H register_, registerValue_;     static int haveN;   };   template <>   int HashString<Hash>::haveN = 0;   template <>   vector<Hash> HashString<Hash>::pp = vector<Hash>();   template <>   vector<Hash> HashString<Hash>::invpp = vector<Hash>();   template <class H, bool cyclic = true>   struct HashStringPiece {     explicit HashStringPiece(const HashString<H>& s, int pos, int len)         : s(s), pos(pos), len(len), hash(H::INVALID) {}     inline H getHash() const {       if (hash == H::INVALID) hash = s.getHash(pos, len);       return hash;     }     inline H getPartialHash(int needLen) const { return s.getHash(pos, needLen); }     inline char getChar(int i) const {       i += pos;       const int S = s.size();       if (i < S) return s[i];       if (!cyclic) return 0;       i -= S;       if (i < S) return s[i];       return s[i % S];     }     const HashString<H>& s;     const int pos, len;     mutable H hash;   };   template <class H, class T>   char getHSPRangeChar(T beg, T en, int pos) {     for (T it = beg; it != en; ++it) {       if (pos < it->len) {         return it->getChar(pos);       }       pos -= it->len;     }     return 0;   }   template <class H, class T>   H getHSPRangeHash(T beg, T en, int len) {     H ans = H::ZERO;     int cur = 0;     for (T it = beg; it != en; ++it) {       if (len >= it->len) {         ans += it->getHash() * it->s.getPow(cur);         cur += it->len;         len -= it->len;       } else {         ans += it->getPartialHash(len) * it->s.getPow(cur);         break;       }     }     return ans;   }   int TB, IT;   template <class H, class T>   inline int compareHSPRanges(T beg1, T en1, int len1, T beg2, T en2, int len2) {     if (beg1 == en1 && beg2 == en2) return 0;     if (beg1 == en1) return -1;     if (beg2 == en2) return 1;     int l = 0, r = min(len1, len2) + 1;     while (r - l > 1) {       int xx = (r + l) / 2;       auto h1 = getHSPRangeHash<H, T>(beg1, en1, xx);       auto h2 = getHSPRangeHash<H, T>(beg2, en2, xx);       if (h1 == h2)         l = xx;       else         r = xx;     }     char c1 = getHSPRangeChar<H, T>(beg1, en1, l);     char c2 = getHSPRangeChar<H, T>(beg2, en2, l);     if (c1 < c2)       return -1;     else if (c1 == c2)       return 0;     else       return 1;   }   template <class H, class T>   inline int compareHSPRanges(T beg1, T en1, T beg2, T en2) {     int len1 = 0;     for (T it = beg1; it != en1; ++it) {       len1 += it->len;     }     int len2 = 0;     for (T it = beg2; it != en2; ++it) {       len2 += it->len;     }     return compareHSPRanges<H, T>(beg1, en1, len1, beg2, en2, len2);   }   int a, b, c, d, n, m, k;   char str[1000002];   int bal[2000002];   HashString<Hash> s;   inline string build(pair<pair<int, int>, int> a) {     string ans =   ;     for (int _n((a.first.first) - 1), i(0); i <= _n; i++) ans +=  ( ;     for (int _n((n)-1), i(0); i <= _n; i++) {       int cur = a.second + i;       if (cur >= n) cur -= n;       ans += str[cur];     }     for (int _n((a.first.second) - 1), i(0); i <= _n; i++) ans +=  ) ;     return ans;   }   HashString<Hash> op, cl;   inline bool better(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b,                      const HashString<Hash>& s) {     HashStringPiece<Hash> A[3] = {HashStringPiece<Hash>(op, 0, a.first.first),                                   HashStringPiece<Hash>(s, a.second, n),                                   HashStringPiece<Hash>(cl, 0, a.first.second)};     HashStringPiece<Hash> B[3] = {HashStringPiece<Hash>(op, 0, b.first.first),                                   HashStringPiece<Hash>(s, b.second, n),                                   HashStringPiece<Hash>(cl, 0, b.first.second)};     int t = compareHSPRanges<Hash>(A, A + 3, B, B + 3);     if (t == -1)       return 1;     else       return 0;   }   int main() {     gets(str);     n = (int)strlen(str);     HashString<Hash> s(str);     HashString<Hash>::precalc(2 * n + 1);     op.reserve(n + 1);     cl.reserve(n + 1);     for (int _n((n)-1), i(0); i <= _n; i++) {       op +=  ( ;       cl +=  ) ;     }     c = 0;     for (int _n((n)-1), i(0); i <= _n; i++) {       if (str[i] ==  ( )         ++c;       else         --c;     }     bal[0] = 0;     for (int _n((2 * n) - 1), i(0); i <= _n; i++) {       if (i) bal[i] = bal[i - 1];       int cur = i;       if (i >= n) cur = i - n;       if (str[cur] ==  ( )         ++bal[i];       else         --bal[i];     }     int blen = 1000000000;     pair<pair<int, int>, int> best = make_pair(make_pair(0, 0), 0);     stack<pair<int, int> > s1, s2;     for (int _n((n)-1), i(0); i <= _n; i++) {       int new_element = bal[i];       int minima = s1.empty() ? new_element : min(new_element, s1.top().second);       s1.push(make_pair(new_element, minima));     }     for (int _n((n)-1), cyc(0); cyc <= _n; cyc++) {       int current_minimum = -1000000000;       if (s1.empty() || s2.empty())         current_minimum = s1.empty() ? s2.top().second : s1.top().second;       else         current_minimum = min(s1.top().second, s2.top().second);       int p = 0;       if (cyc) p = bal[cyc - 1];       int mn = current_minimum - p;       int beg = max(0, -mn);       int en = c + beg;       int len = beg + en + n;       if (len < blen ||           (len == blen && better(make_pair(make_pair(beg, en), cyc), best, s))) {         blen = len;         best = make_pair(make_pair(beg, en), cyc);       }       if (s2.empty()) {         while (!s1.empty()) {           int element = s1.top().first;           s1.pop();           int minima = s2.empty() ? element : min(element, s2.top().second);           s2.push(make_pair(element, minima));         }       }       s2.pop();       int new_element = bal[cyc + n];       int minima = s1.empty() ? new_element : min(new_element, s1.top().second);       s1.push(make_pair(new_element, minima));     }     string ans = build(best);     printf( %s n , ans.c_str());   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long cc = getc(stdin);     for (; cc <  0  || cc >  9 ;) cc = getc(stdin);     long long ret = 0;     for (; cc >=  0  && cc <=  9 ;) {       ret = ret * 10 + cc -  0 ;       cc = getc(stdin);     }     return ret;   }   long long power(long long num, long long g) {     if (g == 0) return 1;     if (g % 2 == 1)       return (num * power((num * num) % 998244353, g / 2)) % 998244353;     return power((num * num) % 998244353, g / 2);   }   int parent[100005];   int siz[100005];   int find(int index) {     if (parent[index] == index) return index;     return parent[index] = find(parent[index]);   }   vector<pair<int, int> > vec[100005];   int b[100005][18], c[100005][18];   int timer, intime[100005], outtime[100005], level[100005];   void dfs(int index, int par, int lev) {     level[index] = lev;     timer++;     intime[index] = timer;     parent[index] = par;     for (long long i = 0; i < vec[index].size(); i++) {       if (vec[index][i].first == par) continue;       c[vec[index][i].first][0] = vec[index][i].second;       dfs(vec[index][i].first, index, lev + 1);     }     timer++;     outtime[index] = timer;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     pair<pair<int, int>, pair<int, int> > pa[m];     vector<pair<int, int> > vec1;     for (long long i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       pa[i] = make_pair(make_pair(w, i), make_pair(u, v));     }     sort(pa, pa + m);     for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;     for (long long i = 0; i < m; i++) {       int u = pa[i].second.first;       int v = pa[i].second.second;       int w = pa[i].first.first;       int g = find(u);       int h = find(v);       if (g == h) continue;       if (siz[g] > siz[h])         siz[g] += siz[h], parent[h] = g;       else         siz[h] += siz[g], parent[g] = h;       vec[u].push_back(make_pair(v, w));       vec[v].push_back(make_pair(u, w));     }     timer = 0;     dfs(1, 1, 1);     for (long long i = 0; i < n; i++) {       b[i + 1][0] = parent[i + 1];     }     for (int i = 1; i <= 17; i++) {       for (int j = 1; j <= n; j++) {         b[j][i] = b[b[j][i - 1]][i - 1];         c[j][i] = max(c[j][i - 1], c[b[j][i - 1]][i - 1]);       }     }     for (long long i = 0; i < n; i++) parent[i + 1] = i + 1, siz[i + 1] = 1;     for (long long i = 0; i < m; i++) {       int u = pa[i].second.first;       int v = pa[i].second.second;       int w = pa[i].first.first;       int xyz = pa[i].first.second;       int g = find(u);       int h = find(v);       if (g == h) {         int g = 1 << 17;         int ans = 0;         int h = u;         for (int j = 17; j >= 0; j--) {           int d = b[h][j];           if (intime[d] <= intime[v] && outtime[d] >= outtime[v]) {             continue;           }           ans = max(ans, c[h][j]);           h = d;         }         while (intime[h] > intime[v] || outtime[h] < outtime[v]) {           ans = max(ans, c[h][0]);           h = b[h][0];         }         h = v;         for (int j = 17; j >= 0; j--) {           int d = b[h][j];           if (intime[d] <= intime[u] && outtime[d] >= outtime[u]) {             continue;           }           ans = max(ans, c[h][j]);           h = d;         }         while (intime[h] > intime[u] || outtime[h] < outtime[u]) {           ans = max(ans, c[h][0]);           h = b[h][0];         }         vec1.push_back(make_pair(xyz, ans));         continue;       }       if (siz[g] > siz[h])         siz[g] += siz[h], parent[h] = g;       else         siz[h] += siz[g], parent[g] = h;       vec[u].push_back(make_pair(v, w));       vec[v].push_back(make_pair(u, w));     }     sort(vec1.begin(), vec1.end());     for (long long i = 0; i < vec1.size(); i++) cout << vec1[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string st;   long n, k, ans, calc;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     cin >> st;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  # )         ++calc;       else {         ans = max(ans, calc);         calc = 0;       }     }     if (ans >= k)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5005;   struct Point {     double x, y, z;   };   double dist(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +                 (a.z - b.z) * (a.z - b.z));   }   Point p[MAXN];   double dis[MAXN];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) scanf( %lf%lf%lf , &p[i].x, &p[i].y, &p[i].z);       for (int i = 1; i < n; i++) dis[i] = dist(p[0], p[i]);       double ta = 100000.0;       for (int i = 1; i < n - 1; i++) {         for (int j = i + 1; j < n; j++) {           double tmp = dist(p[j], p[i]);           double td;           if (dis[i] > dis[j])             td = (tmp - dis[i] + dis[j]) / 2 + dis[i];           else             td = (tmp - dis[j] + dis[i]) / 2 + dis[j];           if (ta > td) ta = td;         }       }       printf( %.6lf n , ta);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510;   bool dp[N][N];   int n, k;   int a[N], b[N];   int main() {     cin >> n >> k;     long long sum1 = 0, sum2 = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       sum1 += a[i];       sum2 += b[i];     }     ans = sum1 / k + sum2 / k;     if (sum1 % k + sum2 % k < k) {       printf( %lld n , ans);       return 0;     } else {       bool flag = false;       dp[0][0] = true;       for (int i = 1; i <= n; i++)         for (int j = 0; j < k; j++)           if (dp[i - 1][j]) {             dp[i][j] = true;             for (int x = 1; x < k; x++) {               if (a[i] >= x && b[i] >= k - x) dp[i][(j + x) % k] = true;             }           }       for (int i = 0; i <= sum1 % k; i++)         if (dp[n][i] && sum2 % k + i >= k) {           flag = true;           break;         }       if (flag)         printf( %lld n , ans + 1);       else         printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     getline(cin, s);     getline(cin, t);     int x = -1, y = -1;     for (int i = 0, j = 0; j < t.length(); j++) {       i += s[i] == t[j];       if (i == s.length()) {         x = j;         break;       }     }     for (int i = s.length() - 1, j = t.length() - 1; j >= 0; j--) {       i -= s[i] == t[j];       if (i == -1) {         y = j;         break;       }     }     if (x != -1 && y != -1 && x < y) {       printf( %d , y - x);     } else {       printf( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   char mapp[110][110];   int main() {     cin.sync_with_stdio(false);     int n, m;     int ans, cnt;     int x1, x2, y1, y2;     while (cin >> n >> m) {       ans = 0;       x1 = 0x3f3f3f3f, x2 = -1, y1 = 0x3f3f3f3f, y2 = -1;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> mapp[i][j];           if (mapp[i][j] ==  B ) {             x1 = min(x1, i);             y1 = min(y1, j);             x2 = max(x2, i);             y2 = max(y2, j);             ans++;           }         }       }       if (x1 == 0x3f3f3f3f) {         cout << 1 << endl;       } else {         cnt = max(x2 - x1, y2 - y1) + 1;         if (cnt > n || cnt > m) {           cout << -1 << endl;           continue;         }         cout << cnt * cnt - ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int maxN = -1;   vector<string> str;   bool ok = false;   int main() {     string s;     while (getline(cin, s)) {       maxN = max(maxN, (int)s.size());       str.push_back(s);     }     for (int i = 0; i < maxN + 2; i++) cout <<  * ;     cout << endl;     int n = str.size();     for (int i = 0; i < n; i++) {       cout <<  * ;       int ni = str[i].size();       int align = maxN - ni;       int space = align / 2;       if (align % 2 != 0) {         if (ok == false) {         } else           space++;       }       for (int j = 0; j < space; j++) cout <<    ;       cout << str[i];       if (align % 2 != 0) {         if (ok == true)           space--;         else if (ok == false)           space++;       }       for (int j = 0; j < space; j++) cout <<    ;       cout <<  * ;       cout << endl;       if (align % 2) ok = !ok;     }     for (int i = 0; i < maxN + 2; i++) cout <<  * ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   long long n, a[300005], l[300005], r[300005];   bool vis[300005];   void work() {     n = read();     for (register long long i = (1); i <= (n); ++i) a[i] = read(), vis[i] = 0;     long long all = 0, now = 0, mx = 0;     for (register long long i = (1); i <= (n); ++i) {       if (!vis[a[i]]) vis[a[i]] = 1, l[a[i]] = i, ++all;       r[a[i]] = i;     }     long long lst = -1;     for (register long long i = (1); i <= (n); ++i)       if (vis[i]) {         if (!now)           now = mx = 1, lst = i;         else {           if (l[i] > r[lst])             now++;           else             now = 1;           lst = i;           mx = max(mx, now);         }       }     cout << all - mx << endl;   }   signed main() {     long long T = read();     while (T--) work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   long double pi = 3.1415926535897932384626433832795;   long long mod = 1e9 + 7;   const int N = 1e6 + 10;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   vector<vector<long long> > e(int n) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < n; j++) {         if (i == j)           v.push_back(1);         else           v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > zero(int n, int m) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < m; j++) {         v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > operator^(vector<vector<long long> > b,                                        vector<vector<long long> > a) {     int n = b.size(), m = a[0].size(), K = a.size();     vector<vector<long long> > c = zero(n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < K; k++) {           c[i][j] += b[i][k] * a[k][j];           c[i][j] %= mod;         }       }     }     return c;   }   vector<vector<long long> > bin_pow(vector<vector<long long> > a, long long pw) {     int n = a.size();     vector<vector<long long> > res = e(n);     while (pw) {       if (pw & 1ll) res = res ^ a;       a = a ^ a;       pw >>= 1;     }     return res;   }   long long n, k;   int main() {     cin >> n >> k;     vector<vector<long long> > ans = zero(1, 16);     ans[0][0] = 1;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       b = min(b, k);       long long pw = b - a;       vector<vector<long long> > m = zero(c + 1, c + 1);       ans[0].resize(c + 1);       for (int i = 0; i <= c; i++) {         for (int j = -1; j <= +1; j++) {           int ni = i + j;           if (ni < 0 || ni > c) continue;           m[i][ni] = 1;         }       }       m = bin_pow(m, pw);       ans = ans ^ m;     }     cout << ans[0][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> scores;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       scores.push_back(temp);     }     int max = scores[0];     int min = scores[0];     int count = 0;     for (int s : scores) {       if (s > max) {         max = s;         count++;       }       if (s < min) {         min = s;         count++;       }     }     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int inf2 = inf * inf;   priority_queue<long long int, vector<long long int>, greater<long long int>>       mnheap;   long long int gcd(long long int x, long long int y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int is_prime(long long int x) {     if (x < 2) return 0;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   inline long long int modpw(long long int x, long long int y, long long int z) {     long long int res = 1;     x = x % z;     while (y) {       if (y & 1) res = (res * x) % z;       x = (x * x) % z;       y /= 2;     }     return res;   }   inline long long int modinv(long long int x, long long int z) {     return modpw(x, z - 2, z);   }   long long int lcm(long long int x, long long int y) {     return (x * y) / gcd(x, y);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       long long int x;       vector<long long int> vv;       for (int i = 0; i < n; i++) {         cin >> x;         vv.push_back(x);       }       if (n == 1) {         cout << 1 <<     << 1 << endl;         cout << -vv[0] << endl;         cout << 1 <<     << 1 << endl;         cout << 0 << endl;         cout << 1 <<     << 1 << endl;         cout << 0 << endl;         return 0;       }       cout << 1 <<     << n - 1 << endl;       for (int i = 0; i < n - 1; i++) {         cout << vv[i] * (n - 1) <<    ;       }       cout << endl;       cout << n <<     << n << endl;       cout << vv[n - 1] * (n - 1) << endl;       cout << 1 <<     << n << endl;       for (int i = 0; i < n; i++) {         cout << -1 * vv[i] * n <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100000 + 10;   int pos[MAX], s[MAX];   int main() {     int n, a;     while (cin >> n) {       memset(pos, 0, sizeof pos);       memset(s, -1, sizeof s);       for (int i = 1; i <= n; ++i) {         cin >> a;         if (s[a] == -1)           s[a] = 0;         else if (s[a] == 0)           s[a] = i - pos[a];         else if (s[a] > 0 && i - pos[a] != s[a])           s[a] = -2;         pos[a] = i;       }       int sum = 0;       for (int i = 1; i < MAX; ++i)         if (s[i] >= 0) ++sum;       cout << sum << endl;       for (int i = 1; i < MAX; ++i) {         if (s[i] >= 0) cout << i <<     << s[i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = -1;   int n;   int main() {     int t;     scanf( %d , &t);     for (int cs = (0); cs < (int)(t); cs++) {       scanf( %d , &n);       printf( %d %d n , n - 1, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 1e9;   struct Node {     int cnt;     int xy, yx;     int minx, miny;     int maxx, maxy;     Node() : cnt(0), xy(-INF), yx(-INF), minx(INF), miny(INF), maxx(0), maxy(0) {}     Node(int x, int y)         : cnt(1), xy(x - y), yx(y - x), minx(x), miny(y), maxx(x), maxy(y) {}   };   struct SegmentTree {     int n;     vector<Node> tree;     vector<int> toaddx;     SegmentTree(int n) : n(n), tree(4 * n), toaddx(4 * n) {}     Node combine(Node a, Node b) {       Node c;       c.cnt = a.cnt + b.cnt;       c.xy = max(a.xy, b.xy);       c.yx = max(a.yx, b.yx);       c.maxx = max(a.maxx, b.maxx);       c.maxy = max(a.maxy, b.maxy);       c.minx = min(a.minx, b.minx);       c.miny = min(a.miny, b.miny);       return c;     }     Node getval(int l, int r) { return getval(l, r, 1, 0, n - 1); }     Node getval(int l, int r, int tv, int tl, int tr) {       if (l <= tl && tr <= r) {         return tree[tv];       }       if (tr < l || r < tl) {         return Node();       }       int tm = (tl + tr) / 2;       return combine(getval(l, r, 2 * tv, tl, tm),                      getval(l, r, 2 * tv + 1, tm + 1, tr));     }     void change_cnt(int x, int y, int sign) {       change_cnt(x, y, sign, 1, 0, n - 1);     }     bool change_cnt(int x, int y, int sign, int tv, int tl, int tr) {       if (tl == tr) {         if (sign == +1) {           tree[tv] = combine(tree[tv], Node(x, y));           return true;         } else if (sign == -1 && --tree[tv].cnt == 0) {           tree[tv] = Node();           return true;         }         return false;       } else {         int tm = (tl + tr) / 2;         bool changed;         if (y <= tm) {           changed = change_cnt(x, y, sign, 2 * tv, tl, tm);         } else {           changed = change_cnt(x, y, sign, 2 * tv + 1, tm + 1, tr);         }         if (changed) {           tree[tv] = combine(tree[2 * tv], tree[2 * tv + 1]);         }         return changed;       }     }   };   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     while (cin >> n) {       vector<pair<int, int>> bn(n);       int miny = INF, maxy = -INF;       for (int i = 0; i < n; ++i) {         string s;         cin >> s;         for (auto c : s) {           if (c ==  B )             ++bn[i].first;           else             ++bn[i].second;         }         miny = min(miny, bn[i].second);         maxy = max(maxy, bn[i].second);       }       sort(bn.begin(), bn.end());       SegmentTree left(maxy + 1), right(maxy + 1);       for (auto [x, y] : bn) {         right.change_cnt(x, y, +1);       }       auto check = [&](int x, int y, bool return_true_answer) {         auto q1 = right.getval(y, maxy);         auto q2 = left.getval(y, maxy);         auto q3 = left.getval(miny, y);         auto q4 = right.getval(miny, y);         int q2res = q2.cnt ? x - y + q2.yx : 0;         int q4res = q4.cnt ? y - x + q4.xy : 0;         int q1res = q1.cnt ? max(q1.maxx - x, q1.maxy - y) : 0;         int q3res = q3.cnt ? max(x - q3.minx, y - q3.miny) : 0;         int top = max(q1res, q2res);         int bot = max(q3res, q4res);         if (return_true_answer) {           return max(bot, top);         }         int res = bot - top;         return res;       };       tuple<int, int, int> res(INF, -1, -1);       for (int x = bn[0].first, idx = 0; x <= bn[n - 1].first; ++x) {         while (idx < n && x == bn[idx].first) {           right.change_cnt(bn[idx].first, bn[idx].second, -1);           left.change_cnt(bn[idx].first, bn[idx].second, +1);           ++idx;         }         int L = (x == 0 ? max(miny, 1) : miny);         int R = maxy;         while (R - L > 1) {           int mid = (L + R) / 2;           int f = check(x, mid, false);           if (f <= 0) {             L = mid;           } else {             R = mid;           }         }         tuple<int, int, int> cur(check(x, L, true), x, L);         for (int i = L + 1; i <= R; ++i) {           cur = min(cur, {check(x, i, true), x, i});         }         res = min(res, cur);       }       auto [val, bb, nn] = res;       cout << val <<   n ;       cout << string(bb,  B ) << string(nn,  N ) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct DirectedEulerPath {     int n;     vector<vector<int> > g;     vector<int> path;     void init(int _n) {       n = _n;       g = vector<vector<int> >(n + 1, vector<int>());       path.clear();     }     void add_edge(int u, int v) { g[u].push_back(v); }     void dfs(int u) {       while (g[u].size()) {         int v = g[u].back();         g[u].pop_back();         dfs(v);       }       path.push_back(u);     }     bool getPath() {       int ctEdges = 0;       vector<int> outDeg, inDeg;       outDeg = inDeg = vector<int>(n + 1, 0);       for (int i = 1; i <= n; i++) {         ctEdges += g[i].size();         outDeg[i] += g[i].size();         for (auto &u : g[i]) inDeg[u]++;       }       int ctMiddle = 0, src = 1;       for (int i = 1; i <= n; i++) {         if (abs(inDeg[i] - outDeg[i]) > 1) return 0;         if (inDeg[i] == outDeg[i]) ctMiddle++;         if (outDeg[i] > inDeg[i]) src = i;       }       if (ctMiddle != n && ctMiddle + 2 != n) return 0;       dfs(src);       reverse(path.begin(), path.end());       return (path.size() == ctEdges + 1);     }   } ep;   string arr[(int)5e5], rev[(int)5e5];   map<string, int> comp;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int x = 0; x < n; x++) {       cin >> arr[x];       comp[arr[x].substr(0, 2)];       comp[arr[x].substr(1, 2)];     }     int cnt = 1;     for (auto x : comp) {       comp[x.first] = cnt;       rev[cnt++] = x.first;     }     ep.init(cnt);     for (int x = 0; x < n; x++)       ep.add_edge(comp[arr[x].substr(0, 2)], comp[arr[x].substr(1, 2)]);     bool ok = ep.getPath();     if (!ok) return 0 * printf( NO n );     cout <<  YES n ;     string ans = rev[ep.path[0]];     for (int x = 1; x < (int)ep.path.size(); x++) ans += rev[ep.path[x]].back();     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   long long n, k, a;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     a = n / (2 * (k + 1));     cout << a <<     << a * k <<     << n - a * (k + 1);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   int n;   pair<int, int> e[200005];   int deg[200005];   vector<int> Adj[200005];   void solve();   int main() { solve(); }   void solve() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       e[i] = {u, v};       Adj[u].push_back(v);       Adj[v].push_back(u);     }     for (int i = 1; i <= n - 1; i++) {       int u = e[i].first, v = e[i].second;       int c = 0, d = 0;       if (Adj[u].size() - 1 == 1) {         cout <<  NO ;         return;       }       if (Adj[v].size() - 1 == 1) {         cout <<  NO ;         return;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, m;   int long long dp[maxn];   vector<pair<int long long, int long long>> veci[maxn];   set<pair<int long long, int long long>> st;   bool mark[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     fill_n(dp, maxn, 1e18);     while (m--) {       int long long a, b, c;       cin >> a >> b >> c;       veci[a].push_back({b, c});       veci[b].push_back({a, c});     }     for (int i = 1; i <= n; i++) {       int long long a;       cin >> a;       st.insert({a, i});     }     while (st.size() > 0) {       auto x = *st.begin();       st.erase(x);       if (mark[x.second]) continue;       dp[x.second] = x.first;       mark[x.second] = 1;       for (auto y : veci[x.second])         st.insert({dp[x.second] + (2 * y.second), y.first});     }     for (int i = 1; i <= n; i++) cout << dp[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   const int N = 2 * 1e5 + 10;   const long long MOD = 1e9;   const long double eps = 1e-12;   int n, m;   long long fib[N], fib_sum[N], g0[4 * N], g1[4 * N], lazy[4 * N];   void precalc() {     fib[0] = fib[1] = 1;     for (int i = 2; i < N; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;     for (int i = 0; i < N; i++) fib_sum[i + 1] = (fib_sum[i] + fib[i]) % MOD;   }   long long get_gib(int i, int x) {     if (x == 0) return g0[i];     if (x == 1) return g1[i];     long long res = 0;     res = g0[i] * fib[x - 2] + g1[i] * fib[x - 1];     res %= MOD;     return res;   }   void pull(int i, int l, int r) {     int m = (l + r) / 2, cl = i * 2 + 0, cr = i * 2 + 1;     g0[i] = g0[cl] + get_gib(cr, m - l);     g0[i] %= MOD;     g1[i] = g1[cl] + get_gib(cr, m - l + 1);     g1[i] %= MOD;   }   void upd(int id, int len, int add) {     g0[id] += add * fib_sum[len];     g0[id] %= MOD;     g1[id] += add * fib_sum[len + 1] - add;     g1[id] %= MOD;   }   void push(int idx, int l, int r) {     if (lazy[idx] <= 0) return;     int a = lazy[idx], cl = idx * 2 + 0, cr = idx * 2 + 1, m = (l + r) / 2;     upd(cl, m - l, a);     upd(cr, r - m, a);     lazy[cl] += a;     lazy[cr] += a;   }   void turn(int pos, int val, int l = 0, int r = n, int idx = 1) {     if (pos < l || r <= pos) return;     if (r - l < 2) {       g0[idx] = val, g1[idx] = val;       return;     }     push(idx, l, r);     int m = (l + r) / 2;     turn(pos, val, l, m, idx * 2 + 0);     turn(pos, val, m, r, idx * 2 + 1);     pull(idx, l, r);   }   void inc(int ql, int qr, int val, int l = 0, int r = n, int idx = 1) {     if (qr <= l || r <= ql) return;     if (ql <= l && r <= qr) {       upd(idx, r - l, val);       lazy[idx] += val;       return;     }     push(idx, l, r);     int m = (l + r) / 2;     inc(ql, qr, l, m, idx * 2 + 0);     inc(ql, qr, m, r, idx * 2 + 1);     pull(idx, l, r);   }   long long get(int ql, int qr, int l = 0, int r = n, int idx = 1) {     if (qr <= l || r <= ql) return 0;     if (ql <= l && r <= qr) {       return get_gib(idx, l - ql);     }     push(idx, l, r);     long long res = 0;     int m = (l + r) / 2;     res += get(ql, qr, l, m, idx * 2 + 0);     res += get(ql, qr, m, r, idx * 2 + 1);     return res % MOD;   }   int main() {     precalc();     n = in();     m = in();     for (int i = 0; i < n; i++) {       int a = in();       turn(i, a);     }     for (int i = 0; i < m; i++) {       int t = in();       if (t == 1) {         int x = in(), v = in();         x--;         turn(x, v);       } else if (t == 2) {         int l = in(), r = in();         l--;         long long res = (get(l, r) + MOD) % MOD;         printf( %I64d n , res);       } else {         int l = in(), r = in(), d = in();         l--;         inc(l, r, d);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string s[] = {        Washington ,  Adams ,      Jefferson ,  Madison ,     Monroe ,        Adams ,       Jackson ,    Van Buren ,  Harrison ,    Tyler ,        Polk ,        Taylor ,     Fillmore ,   Pierce ,      Buchanan ,        Lincoln ,     Johnson ,    Grant ,      Hayes ,       Garfield ,        Arthur ,      Cleveland ,  Harrison ,   Cleveland ,   McKinley ,        Roosevelt ,   Taft ,       Wilson ,     Harding ,     Coolidge ,        Hoover ,      Roosevelt ,  Truman ,     Eisenhower ,  Kennedy ,        Johnson ,     Nixon ,      Ford ,       Carter ,      Reagan ,        Bush ,        Clinton };   int main() {     int a;     cin >> a;     cout << s[a - 1] << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     vector<char> a(str.begin(), str.end());     cin >> str;     vector<char> b(str.begin(), str.end());     int res = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] >=  a ) a[i] += - a  +  A ;       if (b[i] >=  a ) b[i] += - a  +  A ;       if (a[i] > b[i]) {         res = 1;         break;       } else if (a[i] < b[i]) {         res = -1;         break;       }     }     printf( %d n , res);   }


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


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int NN = 1 << 20;   int qpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = (long long)ret * a % mod;       a = (long long)a * a % mod;       b >>= 1;     }     return ret;   }   namespace NTT {   const int g = 3;   int x[NN << 2], y[NN << 2], wn[NN << 2];   void init() {     for (int i = 0; i <= 20; i++) wn[i] = qpow(g, (mod - 1) / (1 << i));   }   void brc(int *F, int len) {     int j = len / 2;     for (int i = 1; i <= len - 2; i++) {       if (i < j) swap(F[i], F[j]);       int k = len / 2;       while (j >= k) j -= k, k >>= 1;       if (j < k) j += k;     }   }   void NTT(int *F, int len, int t) {     int id = 0;     brc(F, len);     for (int h = 2; h <= len; h <<= 1) {       id++;       for (int j = 0; j < len; j += h) {         int E = 1;         for (int k = j; k < j + h / 2; k++) {           int u = F[k], v = (long long)E * F[k + h / 2] % mod;           F[k] = (u + v) % mod, F[k + h / 2] = ((u - v) % mod + mod) % mod;           E = (long long)E * wn[id] % mod;         }       }     }     if (t == -1) {       for (int i = 1; i <= len / 2 - 1; i++) swap(F[i], F[len - i]);       long long inv = qpow(len, mod - 2);       for (int i = 0; i <= len - 1; i++) F[i] = (long long)F[i] % mod * inv % mod;     }   }   }  // namespace NTT   int a[NN], n, k;   int main() {     NTT::init();     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       a[x] = 1;     }     NTT::NTT(a, 1 << 20, 1);     for (int i = 0; i < (1 << 20); i++) a[i] = qpow(a[i], n / 2);     NTT::NTT(a, 1 << 20, -1);     int ans = 0;     for (int i = 0; i <= 9 * n / 2; i++) ans = (ans + 1ll * a[i] * a[i]) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       map<int, int> m;       vector<int> v;       for (int i = 0; i < 4 * n; i++) {         int x;         cin >> x;         m[x]++;         if (m[x] % 2) v.push_back(x);       }       int flag = 1;       for (auto i : m) {         if (i.second % 2 == 1) {           flag = 0;           break;         }       }       if (!flag) {         cout <<  NO  << endl;         continue;       }       sort(v.begin(), v.end());       int area = v[0] * v[v.size() - 1];       for (int i = 1; i < v.size() / 2; i++) {         if (v[i] * v[v.size() - 1 - i] != area) {           flag = 0;           break;         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MXN = 1e6 + 7;   const double EPS = 1e-9;   const double PI = acos(-1);   long long a[MXN], cnt[MXN], n;   long long dp1[MXN], dp2[MXN], pref[MXN];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1, greater<int>());     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         cnt[a[i] - a[j]]++;       }     }     for (int i = 1; i <= 5500; i++)       for (int j = 1; j <= 5500; j++) dp2[i + j] += cnt[i] * cnt[j];     long double ans = 0;     long long sum = 0;     for (int i = 1; i <= 30000; i++) {       ans += sum * cnt[i];       sum += dp2[i];     }     long long x = (n * (n - 1ll)) / 2;     ans /= x;     ans /= x;     ans /= x;     cout << fixed << setprecision(10) << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int a1[2][6] = {{1, 3, 4, 5, 2, 6}, {3, 2, 6, 4, 1, 5}};   int i, j, k, n, m;   int a[10], f[10];   char p[10];   string s;   set<string> yao, laji;   void sou(string a, int ty) {     if (laji.count(a)) return;     int i, j;     if (ty) laji.insert(a);     for (i = 0; i <= 1; i++) {       string b;       for (j = 0; j <= 5; j++) b += a[a1[i][j] - 1];       sou(b, 1);     }   }   void dfs(int x, string a) {     if (x > 6) {       if (!laji.count(a)) {         yao.insert(a);         sou(a, 0);       }       return;     }     int i;     for (i = 1; i <= 6; i++)       if (!f[i]) {         f[i] = 1;         dfs(x + 1, a + p[i]);         f[i] = 0;       }   }   int main() {     scanf( %s , p + 1);     dfs(1, s);     printf( %d n , yao.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, l;   int main() {     cin >> n >> m >> k >> l;     long long x = m * ((k + l) / m + ((k + l) % m == 0 ? 0 : 1));     if (x <= n)       cout << x / m << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   const int inf = 0x3f3f3f3f;   struct node {     int val, r, d;   } cells[maxn * maxn];   int n, m, q;   inline int getIndex(int x, int y) { return x * (m + 1) + y; }   void solve() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         cells[getIndex(i, j)].r = getIndex(i, j + 1);         cells[getIndex(i, j)].d = getIndex(i + 1, j);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &cells[getIndex(i, j)].val);       }     }     while (q--) {       int a, b, c, d, h, w;       scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &h, &w);       int pos1 = getIndex(a - 1, 0), pos2 = getIndex(c - 1, 0);       for (int i = 1; i <= b - 1; i++) pos1 = cells[pos1].r;       for (int i = 1; i <= d - 1; i++) pos2 = cells[pos2].r;       int tmp1 = pos1, tmp2 = pos2;       for (int i = 1; i <= h; i++) {         tmp1 = cells[tmp1].d;         tmp2 = cells[tmp2].d;         swap(cells[tmp1].r, cells[tmp2].r);       }       for (int i = 1; i <= w; i++) {         tmp1 = cells[tmp1].r;         tmp2 = cells[tmp2].r;         swap(cells[tmp1].d, cells[tmp2].d);       }       tmp1 = pos1, tmp2 = pos2;       for (int i = 1; i <= w; i++) {         tmp1 = cells[tmp1].r;         tmp2 = cells[tmp2].r;         swap(cells[tmp1].d, cells[tmp2].d);       }       for (int i = 1; i <= h; i++) {         tmp1 = cells[tmp1].d;         tmp2 = cells[tmp2].d;         swap(cells[tmp1].r, cells[tmp2].r);       }     }     for (int i = 1; i <= n; i++) {       int tmp = getIndex(i, 0);       for (int j = 1; j <= m; j++) {         tmp = cells[tmp].r;         printf( %d  , cells[tmp].val);       }       puts(  );     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200100], b[200100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       b[x] = i;     }     int mx = 0;     for (int i = 1; i <= n; i++) {       a[i] = b[a[i]];       if (a[i - 1] < a[i])         mx++;       else         break;     }     cout << n - mx;   }


#include <bits/stdc++.h>   int main() {     double n, r;     std::cin >> n >> r;     double ang = 180 / n;     ang = 3.1415926536 * ang / 180.0;     double R = sin(ang) / (1 - sin(ang)) * r;     printf( %0.7lf n , R);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long inf = 1LL << 30;   const double eps = 1e-9;   const long long mod = 1e9 + 7;   const int Alpha = 28;   const int MAXLEN = 1e5 + 5;   class SuffixAutomata {    public:     struct state {       int len, link;       int next[Alpha];       state() {         len = link = 0;         memset(next, -1, sizeof(next));       }     };     long long mem[2 * MAXLEN];     int sz = 1, last = 0;     vector<state> st;     vector<int> terminal;     void Init(int len) {       st.clear();       terminal.clear();       st.resize(2 * len);       terminal.resize(2 * len);       sz = 1;       last = 0;       st[0].len = 0;       st[0].link = -1;       memset(mem, -1, sizeof(mem));     }     void extend(char ccc) {       int c = ccc -  a ;       int cur = sz++;       st[cur].len = st[last].len + 1;       int p = last;       while (p != -1 && st[p].next[c] == -1) {         st[p].next[c] = cur;         p = st[p].link;       }       if (p == -1) {         st[cur].link = 0;       } else {         int q = st[p].next[c];         if (st[p].len + 1 == st[q].len) {           st[cur].link = q;         } else {           int clone = sz++;           st[clone].len = st[p].len + 1;           for (int j = 0; j < Alpha; j++) st[clone].next[j] = st[q].next[j];           st[clone].link = st[q].link;           while (p != -1 && st[p].next[c] == q) {             st[p].next[c] = clone;             p = st[p].link;           }           st[q].link = st[cur].link = clone;         }       }       last = cur;     }     void getTerminal() {       int p = last;       while (p > 0) terminal[p] = 1, p = st[p].link;     }     void build(string s) {       Init(s.size());       for (auto x : s) extend(x);       getTerminal();     }     long long dp(int x) {       long long &ret = mem[x];       if (ret != -1) return ret;       ret = terminal[x];       for (int i = 0; i < Alpha; i++) {         if (st[x].next[i] == -1) continue;         ret += dp(st[x].next[i]);       }       return ret;     }     void solve(string s) {       build(s);       long long ans = 0;       for (int nd = 1; nd < sz; nd++) {         long long all_string = st[nd].len - st[st[nd].link].len;         long long frq = dp(nd);         ans += (frq * frq * all_string);       }       printf( %lld n , ans);     }   };   char a[100100];   int main() {     int t;     scanf( %d , &t);     while (t--) {       SuffixAutomata SA;       scanf( %s , &a);       SA.solve(a);     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     string s[] = {          Washington ,  Adams ,      Jefferson ,  Madison ,     Monroe ,          Adams ,       Jackson ,    Van Buren ,  Harrison ,    Tyler ,          Polk ,        Taylor ,     Fillmore ,   Pierce ,      Buchanan ,          Lincoln ,     Johnson ,    Grant ,      Hayes ,       Garfield ,          Arthur ,      Cleveland ,  Harrison ,   Cleveland ,   McKinley ,          Roosevelt ,   Taft ,       Wilson ,     Harding ,     Coolidge ,          Hoover ,      Roosevelt ,  Truman ,     Eisenhower ,  Kennedy ,          Johnson ,     Nixon ,      Ford ,       Carter ,      Reagan };     int a;     std::cin >> a;     std::cout << s[a - 1];   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = (1LL << 60);   const double pi = acos(-1);   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   inline void pcas(int ca) { printf( Case %d:  , ca); }   const int maxn = 1e5 + 10;   int n, x;   char ch[5];   vector<int> v;   int main() {     scanf( %d , &n);     while (n--) {       scanf( %s , ch);       if (ch[0] ==  s ) {         int sz = v.size();         long long ans = 0;         for (int i = 2; i < sz; i += 5) {           ans += v[i];         }         printf( %lld n , ans);       } else {         if (ch[0] ==  a ) {           scanf( %d , &x);           v.insert(lower_bound(v.begin(), v.end(), x), x);         } else {           scanf( %d , &x);           v.erase(lower_bound(v.begin(), v.end(), x));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, l;     cin >> n >> i >> j >> k >> l;     int man = (abs(k - i) + abs(l - j));     if (i == n && k == 0 || k == n && i == 0)       cout << min(man + 2 * min(n - j, n - l), man + 2 * min(j, l));     else if (j == n && l == 0 || l == n && j == 0)       cout << min(man + 2 * min(n - k, n - i), man + 2 * min(k, i));     else       cout << man;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, l;   const long long mod = 998244353;   long long qpow(long long a, long long n) {     long long ret = 1;     while (n > 0) {       if (n & 1) ret = ret * a % mod;       a = a * a % mod;       n >>= 1;     }     return ret;   }   const int maxn = 4005;   long long f[maxn][maxn][2];   int main() {     while (cin >> n >> k >> l) {       memset(f, 0, sizeof(f));       f[0][0][0] = 1;       for (int i = 1; i <= 2 * n + 1; i++) {         for (int j = 0; j <= n; j++) {           for (int x = 0; x < 2; x++) {             if (f[i - 1][j][x]) {               if (j) {                 f[i][j - 1][x] = (f[i][j - 1][x] + f[i - 1][j][x] * j) % mod;               }               if (j >= k && !x) {                 f[i][j][1] = (f[i][j][1] + f[i - 1][j][x]) % mod;               }               if (i + j - 1 < 2 * n + x) {                 f[i][j + 1][x] = (f[i][j + 1][x] + f[i - 1][j][x]) % mod;               }             }           }         }       }       long long fac = 1;       for (int i = n + 1; i <= 2 * n + 1; i++) {         fac = fac * i % mod;       }       long long ans = f[2 * n + 1][0][1];       ans = ans * qpow(fac, mod - 2) % mod;       ans = ans * qpow(2, n) % mod;       ans = ans * l % mod;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   class matrix {    public:     int row, col;     std::vector<std::vector<int>> num;     matrix(int row, int col, int defaultValue = 0) {       this->num =           std::vector<std::vector<int>>(row, std::vector<int>(col, defaultValue));       this->row = row;       this->col = col;     }     matrix(std::vector<std::vector<int>> num) {       this->num = num;       this->row = this->num.size();       this->col = this->num[0].size();     }     matrix operator*(matrix &another) {       if (this->col != another.row) {         printf( Wrong size: %d*%d X %d*%d n , this->row, this->col, another.row,                another.col);         throw  Wrong size ;       }       matrix newone(this->row, another.col);       for (int r = 0; r < newone.row; r++) {         for (int c = 0; c < newone.col; c++) {           for (int k = 0; k < this->col; k++) {             newone.num[r][c] +=                 1ll * this->num[r][k] * another.num[k][c] % (mod - 1);             newone.num[r][c] %= mod - 1;           }         }       }       return newone;     }     matrix operator^(long long x) {       if (x == 0) {         printf( Not implemented yet. n );         throw  Not implemented ;       } else if (x == 1) {         return *this;       } else {         matrix halfpower = (*this) ^ (x / 2);         if (x % 2 == 0)           return halfpower * halfpower;         else           return halfpower * halfpower * (*this);       }     }   };   std::vector<int> primeDecomposition(int x) {     std::vector<int> answer;     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) {         answer.push_back(i);         while (x % i == 0) x /= i;       }     }     if (x > 1) answer.push_back(x);     return answer;   }   int power(int a, long long b) {     if (b == 0) return 1;     int half = power(a, b / 2);     if (b % 2 == 0)       return 1ll * half * half % mod;     else       return 1ll * half * half % mod * a % mod;   }   int main() {     long long n;     int f[4], c, answer(1);     scanf( %lld%d%d%d%d , &n, &f[1], &f[2], &f[3], &c);     matrix baseMatrix({{1, 1, 1}, {1, 0, 0}, {0, 1, 0}});     baseMatrix = baseMatrix ^ (n - 3);     std::set<int> primeSet;     for (int t : primeDecomposition(c)) primeSet.insert(t);     for (int i = 1; i <= 3; i++)       for (int t : primeDecomposition(f[i])) primeSet.insert(t);     for (int t : primeSet) {       matrix countMatrix(3, 1);       for (int i = 0; i < 3; i++) {         for (int k = f[i + 1]; k % t == 0; k /= t)           countMatrix.num[3 - i - 1][0]++;         for (int k = c; k % t == 0; k /= t)           countMatrix.num[3 - i - 1][0] += i + 1;       }       countMatrix = baseMatrix * countMatrix;       answer = 1ll * answer * power(t, countMatrix.num[0][0]) % mod;     }     answer = 1ll * answer * power(power(c, mod - 2), n) % mod;     printf( %d n , answer);     return 0;   }


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


#include <bits/stdc++.h>   typedef struct S {     unsigned val, ki, ka, min, max;     long long unsigned sum;     struct S *lc, *rc;   } v;   v *alloc(unsigned ki, unsigned ka, unsigned val) {     v *x;     x = (v *)malloc(sizeof(v));     x->val = val;     x->min = val;     x->max = val;     x->ki = ki;     x->ka = ka;     x->sum = (ka - ki + 1) * (long long unsigned)val;     x->lc = x->rc = NULL;     return x;   }   long long unsigned que(v *x, unsigned lo, unsigned hi) {     if (hi < x->ki || lo > x->ka) return 0;     if (lo <= x->ki && hi >= x->ka) return x->sum;     unsigned ll, rr;     if (x->val) {       ll = lo < x->ki ? x->ki : lo;       rr = hi > x->ka ? x->ka : hi;       if (rr < ll) return 0;       return (rr - ll + 1) * (long long unsigned)x->val;     }     long long unsigned a = que(x->lc, lo, hi) + que(x->rc, lo, hi);     return a;   }   void set(v *x, unsigned lo, unsigned hi, unsigned val) {     if (hi < x->ki || lo > x->ka || x->min >= val) {       return;     }     if (lo <= x->ki && hi >= x->ka && x->max <= val) {       x->val = x->min = x->max = val;       x->sum = val * (long long unsigned)(x->ka - x->ki + 1);       return;     }     unsigned m;     if (x->val) {       if (val <= x->val) return;       m = (x->ki + x->ka) >> 1;       if (!x->lc)         x->lc = alloc(x->ki, m, x->val);       else {         x->lc->val = x->lc->min = x->lc->max = x->val;         x->lc->sum = (m - x->ki + 1) * (long long unsigned)x->val;       }       if (!x->rc)         x->rc = alloc(m + 1, x->ka, x->val);       else {         x->rc->val = x->rc->min = x->rc->max = x->val;         x->rc->sum = (x->ka - m) * (long long unsigned)x->val;       }       x->val = 0;     }     set(x->lc, lo, hi, val);     set(x->rc, lo, hi, val);     if (x->lc->val && x->lc->val == x->rc->val) {       x->val = x->lc->val;       x->sum = x->val * (long long unsigned)(x->ka - x->ki + 1);     } else       x->sum = x->lc->sum + x->rc->sum;     x->min = x->lc->min;     x->max = x->rc->max;     return;   }   v *p;   unsigned A[222222], F[222222], G[222222];   int main() {     unsigned n, h, i, j, k, x;     long long unsigned r;     scanf( %u , &n);     p = alloc(0, n, 1);     for (i = 0; ++i <= n; A[i] = x) {       scanf( %u , &x);       h = 0;       for (j = 1; j * j <= x; ++j)         if (x % j == 0) {           if (!F[j])             F[j] = i;           else if (h < j)             h = j;           if (j != (k = x / j)) {             if (!F[k])               F[k] = i;             else if (h < k)               h = k;           }         }       set(p, i, n - 1, h);     }     r = que(p, 2, n - 1);     for (i = n; i > 1; --i) {       x = A[i];       h = 0;       for (j = 1; j * j <= x; ++j)         if (x % j == 0) {           if (!G[j])             G[j] = i;           else if (h < j)             h = j;           if (j != (k = x / j)) {             if (!G[k])               G[k] = i;             else if (h < k)               h = k;           }         }       set(p, 0, i - 1, h);       for (x = A[i], j = 1; j * j <= x; ++j)         if (x % j == 0) {           if (F[j] && F[j] < i) set(p, F[j], i - 1, j);           if (F[k = x / j] && F[k] < i) set(p, F[k], i - 1, k);         }       r += que(p, i == n ? 1 : 0, i - 2);     }     printf( %I64u n , r);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   const int mod = 1e9 + 7;   const int N = 100 + 5;   const int M = 10;   int n, a[M], C[N][N], dp[M][N];   int f(int cur, int n) {     if (cur == M) return !n;     int &r = dp[cur][n];     if (r != -1) return r;     r = 0;     for (int i = a[cur]; i <= n; i++)       r = (r + (long long)f(cur + 1, n - i) * C[n][i] % mod) % mod;     return r;   }   int main() {     ios ::sync_with_stdio(0);     memset(dp, -1, sizeof(dp));     C[0][0] = 1;     for (int i = 1; i <= N - 1; i++) {       C[i][0] = 1;       for (int j = 1; j <= N - 1; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;     }     cin >> n;     for (int i = 0; i <= 9; i++) cin >> a[i];     int st = a[0];     int ans = 0;     for (int i = 1; i <= n; i++) {       a[0] = st;       memset(dp, -1, sizeof(dp));       ans += f(0, i);       if (a[0]) a[0]--;       memset(dp, -1, sizeof(dp));       ans -= f(0, i - 1);       ans = (ans % mod + mod) % mod;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9999999999999999;   const double PI = acos(-1);   long long A[100];   int main() {     ios::sync_with_stdio(false);     long long a, b, c;     cin >> a >> b >> c;     A[0] = a;     A[1] = b;     for (long long i = 2; i < 50; i++) {       A[i] = A[i - 1] + A[i - 2];     }     cout << A[c];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b;     cin >> a >> b;     int s[6] = {a, b, b - a, -a, -b, a - b};     int n;     cin >> n;     cout << (s[(n - 1) % 6] % (long long)1000000007 + (long long)1000000007) %                 (long long)1000000007          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, i;     cin >> n;     long long mx = -1, mn = 1e18;     for (i = 0; i < n; i++) {       cin >> a[i];       mn = min(mn, a[i]);       mx = max(mx, a[i]);     }     long long cnt = 0;     if (n < 3)       cout << 0 << endl;     else {       for (i = 0; i < n; i++) {         if (a[i] > mn && a[i] < mx) cnt++;       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int Gcd(unsigned long long int a, unsigned long long int b) {     if (b == 0)       return a;     else       return Gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     unsigned long long int l, r, gcd, lcm;     cin >> l >> r >> gcd >> lcm;     unsigned long long int ans = lcm / gcd;     unsigned long long int sq = sqrt(ans);     unsigned long long int cnt = 0;     if (lcm % gcd != 0) {       cout << 0 << endl;       return 0;     }     for (unsigned long long int i = 1; i <= sq; i++) {       if (ans % i == 0) {         if ((ans / i) * gcd >= l and (ans / i) * gcd <= r and i * gcd >= l and             i * gcd <= r) {           unsigned long long int check = Gcd(ans / i, i);           if (check != 1) continue;           ++cnt;           if (ans != i * i) ++cnt;         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      using ll = long long;      void solve()   {       int n;       int q;       cin >> n >> q;          string s;       cin >> s;          vector<array<int, 26>> pref(n + 1);       pref[0].fill(0);       for (int i = 0; i < n; i++)       {           for (int c = 0; c < 26; c++)               pref[i + 1][c] = pref[i][c] + (c == s[i] -  a );       }          for (int z = 0; z < q; z++)       {           int l, r;           cin >> l >> r;              int add = 0;           for (int c = 0; c < 26; c++)               add += (pref[r][c] - pref[l - 1][c]) * (c + 1);              cout << add <<   n ;       }   }      int main()   {       ios_base::sync_with_stdio(false), cin.tie(NULL);          solve();          return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const long long xx = 2e5;   vector<long long> g1[xx + 10];   vector<long long> g2[xx + 10];   long long v[xx + 10];   long long p1[xx], p2[xx];   void make_first(long long h) {     long long node = 1;     for (long long i = 1; i < h + 1; i++) {       if (v[i - 1] == 1) {         long long root = node;         for (long long j = 0; j < v[i]; j++) {           ++node;           g1[root].push_back(node);         }       } else {         long long r2 = node;         long long r1 = node - 1;         ++node;         g1[r1].push_back(node);         for (long long j = 0; j < v[i] - 1; j++) {           ++node;           g1[r2].push_back(node);         }       }     }   }   long long mx_node = 0;   void make_second(long long h) {     long long node = 1;     for (long long i = 1; i < h + 1; i++) {       long long root = node;       for (long long j = 0; j < v[i]; j++) {         ++node;         g2[root].push_back(node);         mx_node = max(mx_node, node);       }     }   }   void dfs1(long long r, long long p) {     for (auto i : g2[r]) {       if (i != p) {         p1[i] = r;         dfs1(i, r);       }     }   }   void dfs2(long long r, long long p) {     for (auto i : g1[r]) {       if (i != p) {         p2[i] = r;         dfs2(i, r);       }     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long h;     cin >> h;     for (long long i = 0; i < h + 1; i++) {       cin >> v[i];     }     bool per = true;     if (h >= 2) {       for (long long i = 2; i < h + 1; i++) {         if (v[i] > 1 && v[i - 1] > 1) {           per = false;           break;         }       }     }     if (per) {       cout <<  perfect  <<   n ;       return 0;     }     make_first(h);     make_second(h);     dfs1(1, -1);     dfs2(1, -1);     cout <<  ambiguous  <<   n ;     for (long long i = 1; i <= mx_node; i++) cout << p1[i] <<    ;     cout <<   n ;     for (long long i = 1; i <= mx_node; i++) cout << p2[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   typedef vector<int> vt;   int a[110000];   int n;   void solve() {     vt v;     vt::iterator it;     for (int i = 0; i < n; i++) {       it = upper_bound(v.begin(), v.end(), a[i]);       if (it == v.end())         v.push_back(a[i]);       else         *it = a[i];     }     cout << v.size() << endl;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1;     s2 =  hello ;     int i = 0, j = 0, count = 0;     int l = s1.length();     while (l) {       if (s1[i] != s2[j]) i++;       if (s1[i] == s2[j]) {         i++;         j++;         count++;       }       l--;     }     if (count > 4)       cout <<  YES ;     else       cout <<  NO ;   }