#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1050;   const long long mod = 1e9 + 7;   int l, r, n, id = 1;   int a[N];   bool vis[N];   char ans[N][N];   void work(int now, int i) {     bool flag = true;     while (!vis[i]) {       vis[i] = 1;       if (flag) {         if (a[i] > i)           ans[id][i] = ans[id][a[i]] =  / ;         else {           ans[id][i] = ans[id][r] =  / ;           ++id;           ans[id][r] = ans[id][a[i]] =     ;           flag = 0;         }       } else {         if (a[i] < i)           ans[id][i] = ans[id][a[i]] =     ;         else {           ans[id][i] = ans[id][now] =     ;           ++id;           ans[id][now] = ans[id][a[i]] =  / ;           flag = 1;         }       }       i = a[i];     }   }   int main() {     cin >> n;     l = inf, r = 0;     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       if (a[i] != i) l = min(l, i), r = max(r, i);     }     if (l == inf) {       printf( %d n , n);       for (int i = 1; i <= n; ++i, puts(  ))         for (int j = 1; j <= n; ++j) printf( . );       return 0;     }     int pre = 1, nxt = a[r];     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) ans[i][j] =  . ;     for (int i = l; i <= r; ++i)       if (a[i] == r) pre = i;     a[pre] = a[r];     a[r] = r;     for (int i = l; i < r; ++i) {       if (a[i] == i || vis[i]) continue;       work(i, i);       id++;     }     ans[id][nxt] = ans[id][r] =  / ;     cout << n - 1 << endl;     for (int i = n; i >= 1; --i) {       printf( %s n , ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void solve() {     long long w, h;     cin >> w >> h;     int l1;     cin >> l1;     vector<long long> row1(l1);     for (int i = 0; i < l1; i++) {       cin >> row1[i];     }     int l2;     cin >> l2;     vector<long long> row2(l2);     for (int i = 0; i < l2; i++) {       cin >> row2[i];     }     sort(row1.begin(), row1.end());     sort(row2.begin(), row2.end());     long long gap = max(row1[l1 - 1] - row1[0], row2[l2 - 1] - row2[0]);     int h1;     cin >> h1;     vector<long long> col1(h1);     for (int i = 0; i < h1; i++) {       cin >> col1[i];     }     int h2;     cin >> h2;     vector<long long> col2(h2);     for (int i = 0; i < h2; i++) {       cin >> col2[i];     }     sort(col1.begin(), col1.end());     sort(col2.begin(), col2.end());     long long gap2 = max(col1[h1 - 1] - col1[0], col2[h2 - 1] - col2[0]);     long long area = max(h * gap, w * gap2);     cout << area <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 3;   bool dp[30][(1 << 14)][30];   int cnt[(1 << 14)], deg[(1 << 14)];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a;     int c = 0;     bool fail = 0;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 2) fail = 1;       if (x == 1)         c++;       else         a.push_back(x);     }     if (n == 1) {       if (c == 1) return cout <<  YES n , 0;       return cout <<  NO n , 0;     }     sort(a.begin(), a.end());     if (c < (n + 1) / 2 or fail) return cout <<  NO n , 0;     int m = n - c;     for (int mask = 0; mask < (1 << m); mask++) {       for (int i = 0; i < m; i++) {         if (mask & (1 << i)) {           deg[mask] = deg[mask ^ (1 << i)] + a[i];           cnt[mask] = cnt[mask ^ (1 << i)] + 1;         }       }     }     dp[0][0][c] = 1;     for (int i = 0; i < m; i++) {       for (int mask = 0; mask < (1 << i); mask++) {         for (int j = 0; j <= c; j++) {           if (dp[i][mask][j] == 0) continue;           for (int submask = mask; submask; submask = (submask - 1) & mask) {             if (deg[submask] > a[i] - 1 or deg[submask] + j < a[i] - 1) continue;             int t = a[i] - 1 - deg[submask];             if (cnt[submask] + t > 1)               dp[i + 1][(mask ^ submask) | (1 << i)][j - t] = 1;           }           if (j >= a[i] - 1) dp[i + 1][mask | (1 << i)][j - a[i] + 1] = 1;         }       }     }     cout << (dp[m][(1 << (m - 1))][0] == 1 ?  YES n  :  NO n );   }


#include <bits/stdc++.h>   using namespace std;   bool maxl(long long a, long long b) { return a > b; }   bool minl(long long a, long long b) { return a < b; }   bool cmp(int a, int b) { return a > b; }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int main() {     int a[105], ji = 0, ou = 0, i, j, n, ans = 0;     n = read();     for (i = 0; i < n; i++) {       a[i] = read();       if (a[i] % 2 == 0) {         ou++;       } else {         ji++;       }       ans += a[i];     }     sort(a, a + n);     if (ans % 2 == 1) {       cout << ans << endl;     } else {       if (ji >= 1) {         for (i = 0; i < n; i++)           if (a[i] % 2 == 1) {             ans -= a[i];             break;           }         cout << ans << endl;       } else {         cout << 0 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 2005;   int n, m, d;   string p, q;   int a[N], b[N];   int dp[N][N][2][2];   int calc(int id, int rem, int aflag, int bflag) {     if (id == n) {       return (rem == 0);     }     int& ans = dp[id][rem][aflag][bflag];     if (ans != -1) {       return ans;     }     ans = 0;     if (aflag && bflag) {       for (int x = 0; x < 10; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, 1, 1)) % M;       }     } else if (aflag && bflag == 0) {       for (int x = 0; x < b[id] + 1; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, 1, x != b[id])) % M;       }     } else if (aflag == 0 && bflag) {       for (int x = a[id]; x < 10; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans = (ans + calc(id + 1, (10 * rem + x) % m, x != a[id], 1)) % M;       }     } else {       for (int x = a[id]; x < b[id] + 1; x++) {         if ((id % 2 && x != d) || (id % 2 == 0 && x == d)) {           continue;         }         ans =             (ans + calc(id + 1, (10 * rem + x) % m, x != a[id], x != b[id])) % M;       }     }     return ans;   }   void solve() {     memset(dp, -1, sizeof(dp));     cin >> m >> d >> p >> q;     n = (int)((p).size());     for (int i = 0; i < n; i++) {       a[i] = p[i] -  0 ;       b[i] = q[i] -  0 ;     }     cout << calc(0, 0, 0, 0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   string a[N];   int r[N], c[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 0; i <= n; i++) r[i] = 0;       for (int j = 0; j <= m; j++) c[j] = 0;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (a[i][j] ==  . ) r[i]++, c[j]++;       int ans = 1e9 + 7;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           int cur = r[i] + c[j];           if (a[i][j] ==  . ) cur--;           ans = min(ans, cur);         }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, ans, mas[2000000], j;   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> mas[i];       while (m < mas[i] - mas[j]) j++;       if (i > j + 1) ans += (i - j - 1) * (i - j) / 2;     }     cout << ans;   }


#include <bits/stdc++.h>   long int pos[100001] = {0}, neg[100001] = {0};   int main() {     long int n, count = 0, i;     scanf( %ld , &n);     long int arr[n];     for (i = 0; i < n; i++) {       scanf( %ld , arr + i);       if (arr[i] > 0)         pos[arr[i]]++;       else if (arr[i] < 0)         neg[-arr[i]]++;     }     for (i = 0; i < 100001; i++) {       if (pos[i] > 0) count++;       if (neg[i] > 0) count++;     }     printf( %ld , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<pair<int, int>> dec;     vector<pair<int, int>> inc;     dec.push_back({1e7, 0});     inc.push_back({-1e7, 0});     for (int i = 0; i < n; i++) {       if (a[i] >= dec[dec.size() - 1].first and           a[i] <= inc[inc.size() - 1].first) {         cout <<  NO ;         return 0;       } else if (a[i] < dec[dec.size() - 1].first and                  a[i] <= inc[inc.size() - 1].first) {         dec.push_back({a[i], i});       } else if (a[i] >= dec[dec.size() - 1].first and                  a[i] > inc[inc.size() - 1].first) {         inc.push_back({a[i], i});       } else {         if (i < n - 1) {           if (a[i] > a[i + 1]) {             dec.push_back({a[i], i});           } else {             inc.push_back({a[i], i});           }         } else {           inc.push_back({a[i], i});         }       }     }     cout <<  YES n ;     vector<int> ans(n, 1);     for (int i = 1; i < inc.size(); i++) {       ans[inc[i].second] = 0;     }     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, j, a;   int c[11];   int main() {     cin >> n >> m >> k;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= m; ++j) {         char x;         cin >> x;         c[j] += (x ==  Y );       }     }     for (i = 1; i <= m; ++i) a += (c[i] >= k);     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int t2[2], t[2];   vector<int> type;   int main() {     cin >> s;     int n = s.length();     int c = 1;     while (c < n && s[c] == s[0]) c++;     if (c == n) {       cout <<  0 n ;       return 0;     }     int prev = 0;     for (int i = 1; i < n; i++) {       int ind = (c + i) % n;       if (s[(prev + c) % n] != s[ind]) {         if (i - prev <= 1)           type.push_back(0);         else           type.push_back(1);         prev = i;       }     }     if (n - prev <= 1)       type.push_back(0);     else       type.push_back(1);     c = 1;     while (c < type.size() && type[c] == type[0]) c++;     c %= n;     int ans = 0;     prev = 0;     for (int i = 1; i < type.size(); i++) {       int ind = (c + i) % type.size();       if (type[ind] != type[(prev + c) % type.size()]) {         if (type[(prev + c) % type.size()] == 0)           ans += (i - prev) / 2;         else           ans += i - prev;         prev = i;       }     }     if (type[(prev + c) % type.size()] == 0)       ans += (type.size() - prev) / 2;     else       ans += type.size() - prev;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void even() {     puts( YES );     printf( %d * %d = %d n , 1, 2, 2);     printf( %d * %d = %d n , 2, 3, 6);     printf( %d * %d = %d n , 6, 4, 24);     for (int i = 5; i + 1 <= n; i += 2) {       printf( %d - %d = 1 n , i + 1, i);       printf( 1 * 24 = 24 n );     }   }   void odd() {     puts( YES );     printf( 5 - 1 = 4 n );     printf( 4 - 2 = 2 n );     printf( 4 * 2 = 8 n );     printf( 8 * 3 = 24 n );     for (int i = 6; i + 1 <= n; i += 2) {       printf( %d - %d = 1 n , i + 1, i);       printf( 1 * 24 = 24 n );     }   }   int main() {     cin >> n;     if (n < 4) {       puts( NO );       return 0;     }     if (n % 2 == 0)       even();     else       odd();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mx[4005], need[4005];   int n, l[4005], r[4005], a[4005];   bool inter(int i, int j) {     if (l[i] >= l[j] && l[i] <= r[j]) return 1;     if (r[i] >= l[j] && r[i] <= r[j]) return 1;     if (l[j] >= l[i] && l[j] <= r[i]) return 1;     if (r[j] >= r[i] && r[j] <= r[i]) return 1;     return 0;   }   bool check(int d) {     int i, j, p, s;     r[0] = (1 << 30);     for (i = 1; i <= n; i++) need[i] = 0, mx[i] = n;     need[n] = n;     for (i = 1; i <= n; i++) {       for (j = i, s = 0; j <= n; j++)         if ((s += need[j]) > j - i + 1) return false;       for (j = i, s = 0; j <= n; j++)         if ((s += need[j]) == j - i + 1) break;       s = j;       for (j = 1, p = 0; j <= n; j++)         if (mx[j] > 0 && mx[j] <= s && r[j] < r[p]) p = j;       need[mx[p]]--, mx[p] = -1;       for (j = 1; j <= n; j++)         if (inter(p, j) && i + d < mx[j]) {           need[i + d]++, need[mx[j]]--;           mx[j] = i + d;         }       a[i] = p;     }     return 1;   }   int main() {     int i, ll, rr, mid;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d %d , &l[i], &r[i]);     ll = 0, rr = n - 1;     while (rr - ll > 1) {       mid = (ll + rr) >> 1;       if (check(mid))         rr = mid;       else         ll = mid;     }     check(rr);     for (i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   int n;   struct edge {     int ne, to;     edge(int N = 0, int T = 0) : ne(N), to(T) {}   } e[MAXN << 1];   int fir[MAXN], num = 0;   inline void join(int a, int b) {     e[++num] = edge(fir[a], b);     fir[a] = num;   }   int pa[MAXN][MAXN], siz[MAXN][MAXN];   void pre(int u, int fa, const int rt) {     siz[rt][u] = 1;     pa[rt][u] = fa;     for (int i = fir[u]; i; i = e[i].ne) {       int v = e[i].to;       if (v == fa) continue;       pre(v, u, rt);       siz[rt][u] += siz[rt][v];     }   }   long long f[MAXN][MAXN];   long long dfs(int u, int v) {     if (u == v) return 0ll;     if (f[u][v]) return f[u][v];     return f[u][v] = max(dfs(u, pa[u][v]), dfs(pa[v][u], v)) +                      1ll * siz[v][u] * siz[u][v];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       join(u, v);       join(v, u);     }     for (int i = 1; i <= n; i++) pre(i, 0, i);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) ans = max(ans, dfs(i, j));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793238463;   vector<vector<int> > g;   int parent[1009];   void dfs(int u, int prev) {     parent[u] = prev;     for (int v : g[u])       if (v != prev) dfs(v, u);   }   bool fme[1009], fhim[1009];   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       g = vector<vector<int> >(n + 9);       for (int i = 0; i < (n - 1); i++) {         int u, v;         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);       }       int k1;       cin >> k1;       vector<int> me(k1);       memset((fme), (0), sizeof(fme));       for (int i = 0; i < (k1); i++) cin >> me[i], fme[me[i]] = 1;       int k2;       cin >> k2;       vector<int> him(k2);       memset((fhim), (0), sizeof(fhim));       for (int i = 0; i < (k2); i++) cin >> him[i], fhim[him[i]] = 1;       int root = me[0];       memset((parent), (0), sizeof(parent));       dfs(root, -1);       cout <<  B   << him[0] << endl;       int u;       cin >> u;       while (u != -1 && !fme[u]) u = parent[u];       if (u == -1)         cout <<  C -1  << endl;       else {         cout <<  A   << u << endl;         int v;         cin >> v;         if (fhim[v])           cout <<  C   << u << endl;         else           cout <<  C -1  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int INF = 0x3f3f3f3f;   int m, n, c[N], cnt[N];   vector<int> g[N];   int bit[N];   void add(int x, int t) {     for (; x <= n; x += x & -x) bit[x] += t;   }   int ask(int x) {     int ret = 0;     for (; x > 0; x -= x & -x) ret += bit[x];     return ret;   }   struct Que {     int p, c, ret;   } q[N];   vector<int> geet[N];   int st[N], ed[N], clk, sz[N], son[N], mat[N];   void predfs(int u, int f) {     st[u] = ++clk, mat[clk] = u, son[u] = -1, sz[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f) continue;       predfs(v, u);       sz[u] += sz[v];       if (son[u] == -1 || sz[v] > sz[son[u]]) son[u] = v;     }     ed[u] = clk;   }   void dfs(int u, int f, bool keep) {     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f || v == son[u]) continue;       dfs(v, u, 0);     }     if (son[u] != -1) dfs(son[u], u, 1);     ++cnt[c[u]];     if (cnt[c[u]] - 1 > 0) add(cnt[c[u]] - 1, -1);     add(cnt[c[u]], 1);     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i];       if (v == f || v == son[u]) continue;       for (int j = st[v]; j <= ed[v]; ++j) {         ++cnt[c[mat[j]]];         if (cnt[c[mat[j]]] - 1 > 0) add(cnt[c[mat[j]]] - 1, -1);         add(cnt[c[mat[j]]], 1);       }     }     for (int i = 0; i < (int)geet[u].size(); ++i) {       int id = geet[u][i];       q[id].ret = ask(n) - ask(min(n, q[id].p - 1));     }     if (!keep) {       for (int i = st[u]; i <= ed[u]; ++i) {         add(cnt[c[mat[i]]], -1);         --cnt[c[mat[i]]];         if (cnt[c[mat[i]]]) add(cnt[c[mat[i]]], 1);       }     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &c[i]);       }       for (int i = 0; i < N; ++i) g[i].clear(), geet[i].clear();       memset(bit, 0, sizeof(bit));       memset(cnt, 0, sizeof(cnt));       clk = 0;       for (int i = 1; i < n; ++i) {         int u, v;         scanf( %d%d , &u, &v);         g[u].push_back(v);         g[v].push_back(u);       }       predfs(1, 0);       for (int i = 1; i <= m; ++i) {         int u;         scanf( %d%d , &u, &q[i].p);         geet[u].push_back(i);       }       dfs(1, 0, 1);       for (int i = 1; i <= m; ++i) {         printf( %d n , q[i].ret);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:1024000000,1024000000 )   const long double pi = acosl(-1.);   int T;   const long long mod = 258280327;   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   long long quickfind(long long x, long long y) {     long long result = 1;     while (y) {       if (y & 1) result = result * x % mod;       y >>= 1;       x = x * x % mod;     }     return result;   }   using namespace std;   int dfn[33333];   int cnt[33333];   struct master {     int x, y, z;     master(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}   };   int n;   int size[33333];   vector<master> cd[33333];   vector<int> ans;   int q[11111111] = {0};   int h = 5000000, t = 5000000 - 1;   void solve() {     for (int i = 1; i <= n; i++) q[++t] = i, size[i] = 4;     while (h <= t) {       int x = q[h++];       if ((int)cd[x].size() == 0) continue;       int y = cd[x][(int)cd[x].size() - 1].x;       int z = cd[x][(int)cd[x].size() - 1].y;       size[x]--, size[y]++, size[z]++;       if (size[y] > 9 || size[z] > 9) {         size[x]++;         size[y]--;         size[z]--;         q[++t] = x;         continue;       }       ans.push_back(cd[x][(int)cd[x].size() - 1].z);       cd[x].pop_back();       q[++t] = x;     }   }   int main() {     srand(time(NULL));     scanf( %d , &n);     for (int i = 1; i <= n << 2; i++) {       int a, b, c;       scanf( %d , &a);       scanf( %d , &b);       scanf( %d , &c);       cd[a].push_back(master(b, c, i));     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 16; j++) {         int x = rand() % 4;         int y = rand() % 4;         swap(cd[i][x], cd[i][y]);       }     }     solve();     if ((int)ans.size() == n * 4) {       printf( YES n );       printf( %d , ans[0]);       for (int i = 1; i <= (int)ans.size() - 1; i++) printf(  %d , ans[i]);       puts(  );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int d[N], head[N], tot;   int to[N * N], nex[N * N], vis[N * N];   vector<pair<int, int> > ans;   void init() {     tot = 0;     memset(d, 0, sizeof(d));     memset(head, -1, sizeof(head));     ans.clear();   }   void add(int u, int v, int w) {     d[v]++;     to[tot] = v;     nex[tot] = head[u];     vis[tot] = w;     head[u] = tot++;   }   void dfs(int x) {     for (int& i = head[x]; ~i;) {       if (vis[i] == 1) {         i = nex[i];         continue;       }       if (vis[i] == 0) ans.push_back(make_pair(x, to[i]));       vis[i] = vis[i ^ 1] = 1;       dfs(to[i]);     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       init();       int n, m, u, v;       scanf( %d%d , &n, &m);       for (int i = 0; i < m; i++) {         scanf( %d%d , &u, &v);         add(u, v, 0);         add(v, u, 0);       }       vector<int> tmp;       int ret = n;       for (int i = 1; i <= n; i++)         if (d[i] & 1) tmp.push_back(i), ret--;       for (int i = 0; i < tmp.size(); i += 2) {         add(tmp[i], tmp[i + 1], -1);         add(tmp[i + 1], tmp[i], -1);       }       for (int i = 1; i <= n; i++) dfs(i);       printf( %d n , ret);       for (int i = 0; i < ans.size(); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[(int)2e5][2];   int main() {     cin >> n;     if (n == 3) {       cout <<  1 2 3  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];       a[i][0]--;       a[i][1]--;     }     int next = 0;     for (int i = 0; i < n; i++) {       cout << (next + 1) <<    ;       int b = a[next][0];       int c = a[next][1];       if (a[b][0] == c || a[b][1] == c) {         next = b;       } else {         next = c;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 998244353;   struct mat {     long long a[2][2];   };   mat mul(mat a, mat b) {     mat c;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         c.a[i][j] = 0;         for (int k = 0; k < 2; k++) c.a[i][j] += a.a[i][k] * b.a[k][j];         c.a[i][j] %= N;       }     }     return c;   }   mat make_mat(long long x, long long y) {     mat ret;     ret.a[0][0] = x;     ret.a[1][0] = y;     ret.a[0][1] = 1;     ret.a[1][1] = 0;     return ret;   }   mat val[2000005];   void pushup(int x) { val[x] = mul(val[(x << 1)], val[((x << 1) | 1)]); }   void modify(int x, int l, int r, int pos, mat v) {     if (l == r) {       val[x] = v;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid) modify((x << 1), l, mid, pos, v);     if (pos > mid) modify(((x << 1) | 1), mid + 1, r, pos, v);     pushup(x);   }   int n, m, x, y, d[500005];   string s;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     cin >> s;     reverse(s.begin(), s.end());     s =     + s;     for (int i = 1; i <= n; i++) {       d[i] = s[i] -  0 ;       modify(1, 1, n, i,              make_mat(d[i] + 1, (i == 1 ? 0 : (d[i] == 1) * (9 - d[i - 1]))));     }     while (m--) {       cin >> x >> y;       x = n - x + 1;       d[x] = y;       modify(1, 1, n, x,              make_mat(d[x] + 1, (x == 1 ? 0 : (d[x] == 1) * (9 - d[x - 1]))));       if (x < n)         modify(1, 1, n, x + 1,                make_mat(d[x + 1] + 1, (d[x + 1] == 1) * (9 - d[x])));       cout << val[1].a[0][0] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 4e18;   const int MAX_LOG = 21;   const int MAX_N = (1 << 17);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, a, b, c, d;     cin >> n >> k >> a >> b >> c >> d;     if (n < 5 || k < n + 1) {       cout << -1 << endl;     } else {       int arr[n];       arr[0] = a, arr[n - 1] = b, arr[1] = c, arr[n - 2] = d;       vector<bool> taken(n + 1);       taken[a] = taken[b] = taken[c] = taken[d] = true;       int id = 1;       for (int i = 2; i < n - 2; i++) {         while (taken[id]) {           id++;         }         arr[i] = id;         taken[id] = true;       }       for (int i = 0; i < n; i++) {         cout << arr[i] <<    ;       }       cout << endl;       vector<int> v;       v.push_back(c);       v.push_back(a);       v.push_back(arr[2]);       for (int i = 3; i <= n - 3; i++) {         v.push_back(arr[i]);       }       v.push_back(b);       v.push_back(d);       for (int x : v) {         cout << x <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     long long m, n, k;     while (tt--) {       cin >> n >> k;       vector<int> vec(n);       for (long long i = 0; i < n; i++) {         cin >> vec[i];       };       sort(vec.begin(), vec.end());       set<int> s;       for (long long i = 0; i < n; i++) {         s.insert(vec[i]);       }       if (s.size() != n) {         cout << 0 << endl;       } else {         for (long long i = 0; i < n; i++) {           int no = vec[i] & k;           if (no == vec[i])             ;           if (no == vec[i] and               binary_search(vec.begin() + i + 1, vec.end(), no)) {             cout << 1 << endl;             return 0;           } else if (no != vec[i] and binary_search(vec.begin(), vec.end(), no)) {             cout << 1 << endl;             return 0;           }         }         s.clear();         for (long long i = 0; i < n; i++) {           s.insert(vec[i] & k);         }         if (s.size() != n)           cout << 2 << endl;         else           cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005], res = 1e9, A, B, x[100005], kq[100005], kq1[100005], dem = 0,                     e[100005];   void no(int val) {     if (a[n] >= 0 || a[n - 1] >= 0 || res <= val) return;     res = val;     for (int i = 2; i <= n - 1; i++) kq[i] = x[i];     return;   }   void xuli(int i, int val) {     if (val >= res) return;     if (i == 2 || i == n - 1 || 1 == 1) {       for (int j = 0; j <= 16; j++) {         bool ok = true;         x[i] = j;         a[i - 1] -= B * j;         a[i] -= A * j;         a[i + 1] -= B * j;         if (a[i - 1] >= 0) ok = false;         if (ok == true) {           if (i == n - 1)             no(val + j);           else             xuli(i + 1, val + j);         }         a[i - 1] += B * j;         a[i] += A * j;         a[i + 1] += B * j;       }     } else {       int tg = max(e[i] / A + 1, max(e[i - 1] / B + 1, e[i + 1] / B + 1));       for (int j = 0; j <= tg; j++) {         bool ok = true;         x[i] = j;         a[i - 1] -= B * j;         a[i] -= A * j;         a[i + 1] -= B * j;         if (a[i - 1] >= 0) ok = false;         if (ok == true) {           if (i == n - 1)             no(val + j);           else             xuli(i + 1, val + j);         }         a[i - 1] += B * j;         a[i] += A * j;         a[i + 1] += B * j;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> A >> B;     for (int i = 1; i <= n; i++) cin >> a[i], e[i] = a[i];     xuli(2, 0);     cout << res <<   n ;     for (int i = 2; i <= n - 1; i++)       for (int j = 1; j <= kq[i]; j++) kq1[++dem] = i;     for (int i = 1; i <= dem; i++) cout << kq1[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int l, r;     cin >> l >> r;     vector<long long int> v, ans;     long long int x = 1;     while (x <= r) {       v.push_back(x);       x *= 2;     }     x = 1;     while (x <= r) {       for (auto i : v) {         long long int y = x * i;         if (y > r) break;         ans.push_back(y);       }       x *= 3;     }     sort(ans.begin(), ans.end());     long long int n = 0;     for (auto i : ans) {       if (i >= l && i <= r) n++;     }     cout << n;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   int main(void) {     int n;     stack<int> s;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = n; i >= 1; i--) {       if (s.empty()) {         s.push(a[i]);         b[i] = 0;         continue;       }       if (a[i] < s.top()) {         s.push(a[i]);         b[a[i]] = 0;       } else if (a[i] > s.top()) {         int temp = max(1, b[s.top()]);         s.pop();         while (!s.empty() && a[i] > s.top()) {           temp = max(temp + 1, b[s.top()]);           s.pop();         }         b[a[i]] = temp;         s.push(a[i]);       }     }     int k = 0;     for (int i = 1; i <= n; i++) k = max(k, b[i]);     printf( %d n , k);   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int u, v;   };   node p[200010];   int du[200010], n, m;   int _first[200010], _next[200010], _to[200010], cnt;   int add(int a, int b) {     _next[++cnt] = _first[a];     _first[a] = cnt;     _to[cnt] = b;     du[b]++;   }   bool check(int x) {     cnt = 0;     bool ok = 1;     int now;     for (int i = 1; i <= n; i++) du[i] = 0, _first[i] = 0;     for (int i = 1; i <= x; i++) add(p[i].u, p[i].v);     for (int i = 1; i <= n; i++) {       if (!ok && !du[i]) return false;       if (!du[i]) now = i, ok = 0;     }     if (ok) return false;     while (_first[now]) {       ok = 1;       for (int i = _first[now]; i; i = _next[i]) {         du[_to[i]]--;         if (!ok && !du[_to[i]]) return false;         if (!du[_to[i]]) now = _to[i], ok = 0;       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &p[i].u, &p[i].v);       if (p[i].u == 0 || p[i].v == 0) return 0;     }     int l = 1, r = m, ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     long long int i, j;     string s;     cin >> s;     long long int arr[400], brr[400];     for (i = 1; i <= 300; i++) {       arr[i] = i;       brr[i] = i;     }     while (m--) {       char a, b;       cin >> a >> b;       long long int ind1 = brr[a];       long long int ind2 = brr[b];       arr[ind1] = b;       arr[ind2] = a;       brr[b] = ind1;       brr[a] = ind2;     }     for (i = 0; i < (long long int)s.size(); i++) {       s[i] = (char)arr[s[i]];     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   vector<long long> p;   int ho, mi, se;   void fix_time() {     if (se > 59) mi += se / 60, se = se % 60;     if (se < 0) se += 60, mi--;     if (mi > 59) ho += mi / 60, mi = mi % 60;     if (mi < 0) mi += 60, ho--;     if (ho < 0) ho += 24;     if (ho > 24) ho -= 24;   }   long long my_pow(int x, int y) {     long long num = 1;     for (long long i = x; y > 0; i = (i * i), y >>= 1)       if (y & 1) num = (num * i);     return num;   }   bool prime[1000001], prime2[1000001];   void sieve() {     for (int i = 2; i <= 1000000; i += 2) prime[i] = false, prime[i - 1] = true;     prime[2] = true;     for (int i = 3; i * i <= 1000000; i += 2)       if (prime[i])         for (int j = i * i; j <= 1000000; j += 2 * i) prime[j] = false;   }   vector<int> vv;   int cnt = 0;   void pfact(long long x) {     if (x % 2 == 0) {       p.push_back(2);       while (x % 2 == 0) x /= 2, cnt++;       vv.push_back(cnt);     }     for (long long i = 3; i * i <= x; i += 2)       if (x % i == 0) {         cnt = 0;         p.push_back(i);         while (x % i == 0) x /= i, cnt++;         vv.push_back(cnt);       }     if (x > 1) p.push_back(x), cnt++, vv.push_back(1);   }   int gcd(int a, int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   int m, x, n, y, z, k, mx, one, gd, x2, y2, two, mn = 1e9, mid, l, r, pos,                                                   a[500003], b[500003], c[500000];   string s2;   vector<int> v, v2[100003];   long long sum, ans, num;   char ch;   map<string, int> mp1;   set<int> myset;   string s, s1;   int tmp;   bool yes, lft, rt;   multiset<string> lfts[100001], rts[100001];   int t, sum2, y3, z3;   bool used;   int main() {     ios_base::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n;       bool res[n];       memset(res, 0, n);       vector<pair<pair<int, int>, int> > myvec;       for (int i = 0; i < n; i++) {         cin >> x >> y;         myvec.push_back({{y, x}, i});       }       sort(myvec.begin(), myvec.end());       int ind = myvec[0].second;       int beg = myvec[0].first.second;       int en = myvec[0].first.first;       res[ind] = true;       vector<int> shits;       for (int i = 1; i < n; i++) {         m = i;         int f = myvec[i].first.first;         int se = myvec[i].first.second;         ind = myvec[i].second;         if (en >= se) {           if (beg > se) beg = se;           en = f;           shits.push_back(ind);           for (int j = 0; j < shits.size(); j++) res[shits[j]] = true;           shits.clear();         } else           shits.push_back(ind);       }       yes = false;       for (int i = 0; i < n; i++)         if (!res[i]) yes = true;       if (yes)         for (int i = 0; i < n; i++)           if (res[i])             cout <<  1  ;           else             cout <<  2  ;       else         cout << -1;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v, d, id;     long long cnt;     bool operator<(const struct Edge& rhs) const { return d < rhs.d; }   } edg[100001];   int vert[100001];   long long sz[100001];   int find(int i) {     if (vert[i] == i) return i;     return vert[i] = find(vert[i]);   }   void Union(int x, int y) {     int xset = find(x);     int yset = find(y);     if (xset != yset) {       vert[xset] = yset;       long long total = sz[xset] + sz[yset];       sz[xset] = sz[yset] = total;     }   }   int n;   int tmp_id[100001];   vector<pair<int, int> > gr[100001];   long long total_size[100001];   bool vis[100001];   long long ans[100001];   long long dfs_cnt(int cur, int id) {     vis[cur] = true;     tmp_id[cur] = id;     long long res = sz[cur];     for (int i = 0; i < gr[cur].size(); i++) {       int nxt = gr[cur][i].first;       if (vis[nxt]) continue;       res += dfs_cnt(nxt, id);     }     return res;   }   long long dfs(int cur) {     vis[cur] = true;     long long res = sz[cur];     for (int i = 0; i < gr[cur].size(); i++) {       int nxt = gr[cur][i].first, edg_id = gr[cur][i].second;       if (vis[nxt]) continue;       long long sub_size = dfs(nxt);       ans[edg_id] += sub_size * (total_size[tmp_id[cur]] - sub_size) * 2;       res += sub_size;     }     return res;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v, d;       cin >> u >> v >> d;       struct Edge tmp = {u, v, d, i + 1, 0};       edg[i] = tmp;     }     for (int i = 1; i <= n; i++) {       vert[i] = i;       sz[i] = 1;     }     sort(edg, edg + n - 1);     int st = 0;     for (int i = 0; i < n - 1; i++) {       if (i == n - 1 || edg[i + 1].d != edg[i].d) {         vector<int> cln;         cln.clear();         for (int j = st; j <= i; j++) {           int u = edg[j].u, v = edg[j].v, id = edg[j].id;           int cmp1 = find(u), cmp2 = find(v);           vis[cmp1] = false;           vis[cmp2] = false;           gr[cmp1].push_back(make_pair(cmp2, id));           gr[cmp2].push_back(make_pair(cmp1, id));           cln.push_back(cmp1);           cln.push_back(cmp2);         }         int id = 0;         for (int j = 0; j < cln.size(); j++) {           if (vis[cln[j]]) continue;           total_size[id] = dfs_cnt(cln[j], id);           id++;         }         for (int j = 0; j < cln.size(); j++) {           vis[cln[j]] = false;         }         for (int j = 0; j < cln.size(); j++) {           if (vis[cln[j]]) continue;           dfs(cln[j]);         }         for (int j = 0; j < cln.size(); j++) {           vis[cln[j]] = false;           gr[cln[j]].clear();         }         for (int j = st; j <= i; j++) {           int u = edg[j].u, v = edg[j].v;           int cmp1 = find(u), cmp2 = find(v);           Union(cmp1, cmp2);         }         st = i + 1;       }     }     long long mx = -1;     for (int i = 1; i <= n - 1; i++) {       mx = max(mx, ans[i]);     }     vector<int> buff;     for (int i = 1; i <= n - 1; i++) {       if (ans[i] == mx) buff.push_back(i);     }     cout << mx <<     << buff.size() << endl;     for (int i = 0; i < buff.size(); i++) {       cout << buff[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   bitset<16 * 2002> dp[1 << 16];   int n, k;   int a[16];   int weight[16];   int calc(int &x) {     int c = 0;     while (x % k == 0) x /= k, c++;     return c;   }   int _calc(int x) {     int c = 0;     while (x % k == 0) x /= k, c++;     return c;   }   void dfs(int s, int x) {     if (__builtin_popcount(s) == 1) return;     int y = x, z = x;     while (y < 16 * 2002) {       if (dp[s][y]) z = y;       y = y * k;     }     if (z != x) {       for (int i = 0; i < n; i++)         if ((1 << i) & s) weight[i] += _calc(z / x);       dfs(s, z);     } else {       for (int i = 0; i < n; i++)         if ((1 << i) & s and x >= a[i] and dp[s ^ (1 << i)][x - a[i]]) {           dfs(s ^ (1 << i), x - a[i]);           break;         }     }   }   signed main() {     dp[0][0] = 1;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < (1 << n); i++) {       for (int j = 0; j < n; j++)         if (i & (1 << j)) dp[i] |= (dp[i - (1 << j)] << a[j]);       for (int j = 16 * 2000 / k; j >= 0; j--)         if (dp[i][j * k]) dp[i][j] = 1;     }     if (!dp[(1 << n) - 1][1]) return puts( NO ) * 0;     puts( YES );     dfs((1 << n) - 1, 1);     int cnt = n - 1;     while (cnt--) {       int f1 = -1, f2 = -1;       for (int i = 0; i < n; i++) {         if (f1 == -1 or weight[i] > weight[f1])           f2 = f1, f1 = i;         else if (f2 == -1 or weight[i] > weight[f2])           f2 = i;       }       printf( %d %d n , a[f1], a[f2]);       a[f1] += a[f2];       weight[f2] = -1e9;       weight[f1] -= calc(a[f1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 5];       for (int i = 0; i < n; i++) cin >> a[i];       int ans = 1;       for (int i = 1; i <= 26; i++) {         int x = 1;         while (true) {           int count = 0;           int j, k;           for (j = 0; j < n; j++) {             if (a[j] == i) count++;             if (count == x) break;           }           int count1 = 0;           for (k = n - 1; k >= 0; k--) {             if (a[k] == i) count1++;             if (count1 == x) break;           }           if (j == n || k == -1) break;           if (j >= k) break;           vector<int> freq;           for (int l = 0; l <= 27; l++) freq.push_back(0);           for (int l = j + 1; l < k; l++) freq[a[l]]++;           int y = 0;           for (int l = 0; l <= 26; l++) y = max(y, freq[l]);           ans = max(ans, 2 * x + y);           x++;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1000000 + 10;   long long d[maxn];   long long ans = 0;   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long v, u;       cin >> v >> u;       d[u]++;       d[v]++;     }     for (long long i = 1; i <= n; i++) ans += d[i] * (n - 1 - d[i]);     cout << (n * (n - 1) * (n - 2)) / 6 - (ans / 2) << endl;     return 0;   }


#include <bits/stdc++.h>   int n;   char S[300000];   struct edge {     int to, nxt;   } E[500000];   int H[500000], tot;   inline void add_edge(int a, int b) { E[++tot] = (edge){b, H[a]}, H[a] = tot; }   struct SegmentTree {     struct node {       node *L, *R;       node() { L = R = NULL; }     };     node *root;     void insert(node *&now, int l, int r, int k) {       if (!now) now = new node;       if (l == r) return;       int mdl = (l + r) >> 1;       if (k <= mdl)         insert(now->L, l, mdl, k);       else         insert(now->R, mdl + 1, r, k);     }     bool query(node *now, int l, int r, int L, int R) {       if (l > R || r < L || !now) return false;       if (L <= l && r <= R) return true;       int mdl = (l + r) >> 1;       return query(now->L, l, mdl, L, R) | query(now->R, mdl + 1, r, L, R);     }     SegmentTree() { root = NULL; }   };   SegmentTree::node *merge(SegmentTree::node *&A, SegmentTree::node *&B) {     if (!(A && B)) return A ? A : B;     SegmentTree::node *nw = new SegmentTree::node;     nw->L = merge(A->L, B->L), nw->R = merge(A->R, B->R);     return nw;   }   struct SAM {     struct node {       int son[26], len, link, R;       SegmentTree S;       node() {         memset(son, 0xff, sizeof(int) * 26);         len = link = R = 0;       }     } T[500000];     int tot, lst;     void insert(char C) {       C -=  a ;       int q = ++tot, p = lst;       T[q].len = T[p].len + 1,       T[q].S.insert(T[q].S.root, 1, n, T[q].R = T[q].len);       lst = q;       while (~p && !~T[p].son[C]) T[p].son[C] = q, p = T[p].link;       if (!~p) return;       int np = T[p].son[C];       if (T[p].len + 1 == T[np].len)         T[q].link = np;       else {         int nq = ++tot;         memcpy(T[nq].son, T[np].son, sizeof(int) * 26);         T[nq].link = T[np].link;         T[nq].len = T[p].len + 1;         T[np].link = T[q].link = nq;         while (~p && T[p].son[C] == np) T[p].son[C] = nq, p = T[p].link;       }     }     SAM() { tot = lst = 0, T[0].link = -1; }   } G;   void pre(int now) {     for (int i = H[now]; i; i = E[i].nxt) {       pre(E[i].to);       G.T[now].R = std::max(G.T[now].R, G.T[E[i].to].R);       G.T[now].S.root = merge(G.T[now].S.root, G.T[E[i].to].S.root);     }   }   int Ans;   void solve(int now, int ans, int top) {     Ans = std::max(Ans, ans);     for (int i = H[now]; i; i = E[i].nxt) {       if (G.T[top].S.query(G.T[top].S.root, 1, n,                            G.T[E[i].to].R - G.T[E[i].to].len + G.T[top].len,                            G.T[E[i].to].R - 1))         solve(E[i].to, ans + 1, E[i].to);       else         solve(E[i].to, ans, top);     }   }   int main() {     scanf( %d%s , &n, S + 1);     if (n == 1) return puts( 1 ), 0;     for (int i = 1; i <= n; i++) G.insert(S[i]);     for (int i = 1; i <= G.tot; i++) add_edge(G.T[i].link, i);     pre(0), solve(0, 0, 0);     printf( %d n , Ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 45;   int a[maxn], b[maxn];   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   int N;   struct Martix {     long long arr[maxn][maxn];     void init() { memset(arr, 0x3f, sizeof(arr)); }     void to() {       this->init();       for (int i = 0; i < N; i++) {         arr[i][i] = 0;       }     }     void out() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           long long v = arr[i][j] == INFF ? -1 : arr[i][j];           cout << v <<    ;         }         cout << endl;       }       puts( -- );     }   };   Martix operator*(const Martix& a, const Martix& b) {     Martix ret;     ret.init();     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         for (int k = 0; k < N; k++) {           ret.arr[i][j] = min(ret.arr[i][j], a.arr[i][k] + b.arr[k][j]);         }       }     }     return ret;   }   long long dp[maxn][maxn][maxn];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]);     memset(dp, 0x3f, sizeof(dp));     N = n + 1;     for (int i = 0; i < N; i++) {       dp[i][i][0] = 0;     }     for (int k = 1; k <= n; k++) {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           if (j - 1 >= 0)             dp[i][j][k] = min(dp[i][j][k], dp[i][j - 1][k - 1] + a[k - 1]);           if (j + 1 < N)             dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k - 1] + b[k - 1]);         }       }     }     Martix x;     x.init();     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         x.arr[i][j] = dp[i][j][n];       }     }     Martix ret;     ret.to();     while (m) {       if (m & 1) ret = ret * x;       x = x * x;       m >>= 1;     }     printf( %I64d n , ret.arr[0][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7LL;   const int MAXN = 212345;   int vis[MAXN];   vector<int> g[MAXN];   long long dfs(int u) {     vis[u] = 1;     long long r = 1;     for (int v : g[u])       if (!vis[v]) r += dfs(v);     return r;   }   long long fexp(long long b, long long e) {     if (b == 1 || e == 0) return 1;     if (b == 0) return 0;     long long resp = fexp(b, e / 2);     resp = ((resp % MOD) * (resp % MOD)) % MOD;     if (e & 1) resp = ((resp % MOD) * (b % MOD)) % MOD;     return resp % MOD;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 0, u, v, w; i < n - 1; ++i) {       cin >> u >> v >> w;       if (!w) {         g[u].push_back(v);         g[v].push_back(u);       }     }     long long r = fexp(n, k);     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         r = (r % MOD - fexp(dfs(i), k) % MOD) % MOD;         if (r < 0) r += MOD;         r %= MOD;       }     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exponent, long long mod) {     long long ans = 1;     while (exponent) {       if (exponent & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       exponent /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   const int upperlimit = 71;   const int mod = 998244353;   long long fact[upperlimit];   long long invfact[upperlimit];   vector<long long> pdv;   void func(long long n) {     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) pdv.push_back(i);       while (n % i == 0) n /= i;     }     if (n > 1) pdv.push_back(n);   }   int pw(long long n, long long i) {     int ans = 0;     while (n % i == 0) {       ans++;       n /= i;     }     return ans;   }   int main() {     fact[0] = 1;     invfact[0] = 1;     for (int i = 1; i < upperlimit; i++) {       fact[i] = fact[i - 1];       fact[i] *= i;       fact[i] %= mod;       invfact[i] = powmod(fact[i], mod - 2, mod);     }     long long d, u, v;     int q;     long long temp = 1;     int lol = 0;     scanf( %lld , &d);     func(d);     scanf( %d , &q);     while (q--) {       scanf( %lld , &u);       scanf( %lld , &v);       long long gc = gcd(u, v);       temp = 1;       lol = 0;       for (int i = 0; i < pdv.size(); i++) {         int gg = abs(pw(gc, pdv[i]) - pw(u, pdv[i]));         temp *= invfact[gg];         temp %= mod;         lol += gg;       }       temp *= fact[lol];       temp %= mod;       lol = 0;       for (int i = 0; i < pdv.size(); i++) {         int gg = abs(pw(gc, pdv[i]) - pw(v, pdv[i]));         temp *= invfact[gg];         temp %= mod;         lol += gg;       }       temp *= fact[lol];       temp %= mod;       printf( %lld n , temp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[2513][2513];   bitset<2513> big[2513];   vector<int> comp;   vector<pair<int, int> > need[2513 * 2513];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         if (i == j && a[i][j] != 0) return printf( NOT MAGIC n ), 0;         if (i > j && a[i][j] != a[j][i]) return printf( NOT MAGIC n ), 0;         comp.push_back(a[i][j]);       }     sort(comp.begin(), comp.end());     comp.erase(unique(comp.begin(), comp.end()), comp.end());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         need[lower_bound(comp.begin(), comp.end(), a[i][j]) - comp.begin()]             .push_back(make_pair(i, j));       }     for (int i = 0; i < n * n; i++) {       auto& v = need[i];       for (auto& p : v) {         if ((big[p.first] & big[p.second]).any()) return printf( NOT MAGIC n ), 0;       }       for (auto& p : v) big[p.first][p.second] = 1;     }     printf( MAGIC n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(int n) {     string x =   ;     if (n >= 5) {       x +=  -O| ;       n -= 5;     } else {       x +=  O-| ;     }     while (n--) {       x +=  O ;     }     x +=  - ;     while (x.size() < 8) x +=  O ;     cout << x << endl;   }   int main() {     int n;     cin >> n;     if (n == 0) cout <<  O-|-OOOO ;     while (n) {       print(n % 10);       n /= 10;     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<vector<long long>> in(n);     vector<long long> deg(n);     long long a, b;     for (long long i = 0; i < m; ++i) {       cin >> a >> b;       --a;       --b;       if (a > b) {         swap(a, b);       }       ++deg[a];       ++deg[b];       in[a].push_back(b);     }     long long answ = 0;     for (long long i = 0; i < n; ++i) {       answ += ((deg[i] - in[i].size()) * in[i].size());     }     cout << answ <<   n ;     long long q;     cin >> q;     long long x;     for (long long i = 0; i < q; ++i) {       cin >> x;       --x;       answ -= ((deg[x] - in[x].size()) * in[x].size());       for (long long c : in[x]) {         answ -= ((deg[c] - in[c].size()) * in[c].size());         in[c].push_back(x);         answ += ((deg[c] - in[c].size()) * in[c].size());       }       in[x].clear();       cout << answ <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cou = 0, ans = 0, mx = INT_MIN, mn = INT_MAX, sum = 0, modu = 1e9 + 7;   vector<vector<int>> from, to;   vector<bool> visited(1e3, false);   void dfs(int t) {     visited[t] = true;     for (int c = 0; c < from[t].size(); c++) {       if (!visited[from[t][c]]) dfs(from[t][c]);     }   }   void d(int t) {     dfs(t);     for (int z = 0; z < to[t].size(); z++) {       if (!visited[to[t][z]]) d(to[t][z]);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     vector<pair<int, int>> v(t);     for (long long i = 0; i < t; i++) cin >> v[i].first >> v[i].second;     sort(v.begin(), v.end());     if (t < 3) {       cout <<  YES ;       return 0;     }     int n1 = v[0].second, n2 = v[1].second;     for (int x = 2; x < t; x++) {       if (n1 >= v[x].first && n2 >= v[x].first) {         cout <<  NO ;         return 0;       } else {         if (n1 < n2)           n1 = v[x].second;         else           n2 = v[x].second;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[2048][2048];   int flagr[2048], flagc[2048];   int n, ans = 0;   void print() {     cout << endl;     cout <<  ==========  << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) cout << a[i][j];       cout << endl;     }     cout << endl;   }   void solve() {     for (int i = 0; i < n; i++) {       for (int j = n - 1; j > i; j--) {         if ((a[i][j] -  0  + flagr[i] + flagc[j]) & 1) {           a[i][j] =  0 ;           flagc[j]++, flagr[i]++, ans++;         }         a[i][j] =  0 ;       }     }     for (int i = 0; i < n; i++) {       a[i][i] = (a[i][i] -  0  + flagr[i] + flagc[i]) % 2 + 48;     }     memset(flagr, 0, sizeof(flagr));     memset(flagc, 0, sizeof(flagc));     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < i; j++) {         if ((a[i][j] -  0  + flagr[i] + flagc[j]) & 1) {           flagc[j]++, flagr[i]++, ans++;         }         a[i][j] =  0 ;       }     }     for (int i = 0; i < n; i++)       if ((a[i][i] -  0  + flagr[i] + flagc[i]) % 2) ans++;   }   int main() {     int i, j, k, l;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , a[i]);     }     solve();     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y;   string h;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> h >> x >> y;       if (x >= 2400 and y > x) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d;   vector<int> e[100000 + 5], lst[100000 + 5];   int dfn[100000 + 5], low[100000 + 5], cnt, tot, sta[100000 + 5], ptr,       scc[100000 + 5], cycle[100000 + 5];   char open[100000 + 5][55];   void tarjan(int now) {     dfn[now] = low[now] = ++cnt;     sta[++ptr] = now;     for (auto v : e[now]) {       if (!dfn[v]) {         tarjan(v);         low[now] = min(low[now], low[v]);       } else if (!scc[v])         low[now] = min(low[now], dfn[v]);     }     if (low[now] == dfn[now]) {       tot++;       while (sta[ptr] != now) scc[sta[ptr--]] = tot;       scc[sta[ptr--]] = tot;     }     return;   }   int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }   int _gcd[55];   bool can[100000 + 5][55];   int off[100000 + 5];   pair<int, int> q[100000 * 50 + 5];   void bfs(int s, int id) {     int rear = 0;     q[rear].first = s;     q[rear].second = 0;     can[s][0] = 1;     for (int front = 0; front <= rear; front++) {       int now = q[front].first;       int day = q[front].second;       int nd = (day + 1) % d;       for (auto v : e[now])         if (scc[v] == id) {           if (can[v][nd] == 0) {             can[v][nd] = 1;             rear++;             q[rear].first = v;             q[rear].second = nd;           }         }     }     cycle[id] = d;     for (int i = 1; i <= d - 1; i++)       if (can[s][i]) {         cycle[id] = i;         break;       }     assert(d % cycle[id] == 0);   }   int dp[100000 + 5][55], dpscc[100000 + 5][55];   void upd(int &x, int y) {     if (y > x) x = y;   }   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);     }     for (int i = 1; i <= n; i++) scanf( %s , open[i]);     for (int i = 1; i <= n; i++)       if (!dfn[i]) tarjan(i);     for (int i = 1; i <= n; i++) lst[scc[i]].push_back(i);     for (int i = 1; i <= tot; i++) bfs(lst[i][0], i);     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= d - 1; j++)         if (can[i][j]) {           off[i] = j;           break;         }     }     memset(dp, -1, sizeof dp);     memset(dpscc, -1, sizeof dpscc);     int ans = 0;     dpscc[scc[1]][0] = 0;     for (int id = tot; id >= 1; id--) {       int c = cycle[id];       int cnt[55] = {};       for (auto now : lst[id]) {         bool tmp[55] = {};         for (int i = 0; i <= d - 1; i++)           if (open[now][i] ==  1 ) tmp[(i - off[now] + c) % c] = 1;         for (int i = 0; i <= d - 1; i++) cnt[i] += tmp[i];       }       for (auto now : lst[id]) {         for (int i = 0; i <= d - 1; i++)           if (dpscc[id][(i - off[now] + c) % c] >= 0)             dp[now][i] =                 dpscc[id][(i - off[now] + c) % c] + cnt[(i - off[now] + c) % c];         for (int i = 0; i <= d - 1; i++) ans = max(ans, dp[now][i]);       }       for (auto now : lst[id])         for (auto v : e[now])           if (scc[v] != id) {             int nid = scc[v];             for (int i = 0; i <= d - 1; i++)               upd(dpscc[nid][(i + 1 - off[v] + cycle[nid]) % cycle[nid]],                   dp[now][i]);           }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   string s;   int n;   int main() {     cin >> s;     n = s.length();     for (int i = 1; i < n - 1; i++) {       if (s[i - 1] ==  .  || s[i] ==  .  || s[i + 1] ==  . ) continue;       int c1 = s[i - 1] -  A  + 1;       int c2 = s[i] -  A  + 1;       int c3 = s[i + 1] -  A  + 1;       int t = 0;       if (c1 != c2 && c1 != c3) t++;       if (c2 != c1 && c2 != c3) t++;       if (c3 != c1 && c3 != c2) t++;       if (t == 3) {         cout <<  Yes ;         return 0;       }     }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932384626433832795;   const double EPS = 1e-9;   const int MAX_NUMBER = 25 * 1000 * 1000;   const int ROOT = 10000;   bool isPrime[MAX_NUMBER];   int primesAmount;   bool canMult(int a, int b) {     if (b == 0) {       return true;     }     return a <= MAX_NUMBER / b;   }   void precalc() {     int op = 0;     memset(isPrime, true, sizeof(isPrime));     isPrime[0] = isPrime[1] = false;     primesAmount = 0;     double t = clock();     for (int i = 2; i < MAX_NUMBER; ++i) {       ++op;       if (isPrime[i]) {         ++primesAmount;         if (i < ROOT) {           for (int j = i * i; j < MAX_NUMBER; j += i) {             ++op;             isPrime[j] = false;           }         }       }     }     cerr <<  op   << op << endl;     cerr <<  amount primes   << primesAmount << endl;     t = clock() - t;     t /= CLOCKS_PER_SEC;     cerr <<  precalc time is   << t << endl;   }   int solve(int x, const vector<int>& a) {     if (x == 2) {       return 0;     }     vector<bool> haveNumber(MAX_NUMBER, false);     for (int i = 0; i < a.size(); ++i) {       if (a[i] < MAX_NUMBER) {         haveNumber[a[i]] = true;       }     }     if (haveNumber[1]) {       return 1;     }     int primesToX = 0;     for (int i = 2; i <= x - 1; ++i) {       if (isPrime[i]) {         ++primesToX;         if (!haveNumber[i]) {           return -1;         }       }     }     return primesToX;   }   int main() {     precalc();     int n, x;     while (cin >> n >> x) {       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       int res = solve(x, a);       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5, mod = 1e9 + 7;   struct pt {     long long x, y;     inline void in() { scanf( %lld%lld , &x, &y); }     inline long long operator*(const pt& rhs) const {       return x * rhs.y - rhs.x * y;     }     inline pt operator+(const pt& rhs) const {       return (pt){x + rhs.x, y + rhs.y};     }     inline pt operator-(const pt& rhs) const {       return (pt){x - rhs.x, y - rhs.y};     }     inline void mo() {       x %= mod;       y %= mod;     }   } a[N], s2[N];   int n, i, j, ans, s1[N];   long long s0[N], z, tot;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) a[i].in(), s2[i] = s2[i - 1] + a[i], s2[i].mo();     for (i = 2; i <= n; i++)       z = a[i - 1] * a[i], s0[i] = s0[i - 1] + z,       s1[i] = (s1[i - 1] + s0[i]) % mod;     tot = abs(s0[n + 1] = s0[n] + a[n] * a[1]);     for (i = 3, j = 1; i <= n; i++) {       for (; j < i - 1 && abs(s0[i] - s0[j] + a[i] * a[j]) > tot / 2.0; j++)         ;       ans = (ans + s0[i] % mod * (i - 1 - j) - (s1[i - 2] - s1[j - 1]) +              a[i] * (s2[i - 2] - s2[j - 1])) %             mod;       ans = (ans + s1[j - 1] + s2[j - 1] * a[i] +              (s0[n + 1] - s0[i]) % mod * (j - 1)) %             mod;     }     ans = ((tot % mod * (mod + 1 >> 2) % mod * n % mod * (n - 3) % mod + ans) %                mod +            mod) *           2 % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300 + 10;   const int MAXM = 1e5 + 10;   const int MOD = 1e9 + 7;   int T, n, q, t, a[MAXN], dp[MAXN][MAXM], deg[MAXN], cnt[MAXN];   vector<int> g[MAXN];   bool visited[MAXN];   void dfs(int v, int x) {     visited[v] = true;     cnt[v] = 0;     for (auto u : g[v]) {       if (!visited[u]) {         dfs(u, x + a[v]);         cnt[v] = cnt[u] + 1;       }     }     t -= a[v] * cnt[v];     a[v] += x;     if (t < 0) {       cout << 0 <<   n ;       exit(0);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     T = 1;     while (T--) {       cin >> n >> q >> t;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       for (int i = 1; i <= q; i++) {         int u, v;         cin >> u >> v;         g[u].push_back(v);         deg[v]++;       }       for (int i = 1; i <= n; i++) {         if (!deg[i]) {           dfs(i, 0);         }       }       for (int i = 1; i <= n; i++) {         if (!visited[i]) {           cout << 0 <<   n ;           return 0;         }       }       for (int i = 1; i <= n; i++) {         dp[i][0] = 1;         for (int j = 1; j <= t; j++) {           dp[i][j] = dp[i - 1][j];           if (a[i] <= j) {             dp[i][j] = (dp[i][j] + dp[i][j - a[i]]) % MOD;           }         }       }       cout << dp[n][t] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline char smax(A &a, const B &b) {     return a < b ? a = b, 1 : 0;   }   template <typename A, typename B>   inline char smin(A &a, const B &b) {     return b < a ? a = b, 1 : 0;   }   template <typename I>   inline void read(I &x) {     int f = 0, c;     while (!isdigit(c = getchar())) c ==  -  ? f = 1 : 0;     x = c & 15;     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);     f ? x = -x : 0;   }   const int N = 1e5 + 7;   const int LOG = 36;   const double eps = 1e-13;   int n, nl;   long long t;   double M;   int a[N], b[N], q[N];   double p[N];   inline int dcmp(const double &x) {     return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);   }   struct Line {     double k, b;     inline bool operator<(const Line &a) const {       return dcmp(k - a.k) < 0 || (dcmp(k - a.k) == 0 && b < a.b);     }   } l[N];   inline double crs(const Line &l1, const Line &l2) {     return (l2.b - l1.b) / (l1.k - l2.k);   }   struct Matrix {     double a[3][3];     inline Matrix() { memset(a, 0, sizeof(a)); }     inline Matrix(const double &x) {       memset(a, 0, sizeof(a));       a[0][0] = a[1][1] = a[2][2] = x;     }     inline void print() {       for (int i = 0; i < 3; ++i) {         for (int j = 0; j < 3; ++j) fprintf(stderr,  %.13lf  , a[i][j]);         puts(  );       }     }     inline Matrix operator*(const Matrix &b) {       Matrix c;       c.a[0][0] = a[0][0] * b.a[0][0] + a[0][1] * b.a[1][0] + a[0][2] * b.a[2][0];       c.a[0][1] = a[0][0] * b.a[0][1] + a[0][1] * b.a[1][1] + a[0][2] * b.a[2][1];       c.a[0][2] = a[0][0] * b.a[0][2] + a[0][1] * b.a[1][2] + a[0][2] * b.a[2][2];       c.a[1][0] = a[1][0] * b.a[0][0] + a[1][1] * b.a[1][0] + a[1][2] * b.a[2][0];       c.a[1][1] = a[1][0] * b.a[0][1] + a[1][1] * b.a[1][1] + a[1][2] * b.a[2][1];       c.a[1][2] = a[1][0] * b.a[0][2] + a[1][1] * b.a[1][2] + a[1][2] * b.a[2][2];       c.a[2][0] = a[2][0] * b.a[0][0] + a[2][1] * b.a[1][0] + a[2][2] * b.a[2][0];       c.a[2][1] = a[2][0] * b.a[0][1] + a[2][1] * b.a[1][1] + a[2][2] * b.a[2][1];       c.a[2][2] = a[2][0] * b.a[0][2] + a[2][1] * b.a[1][2] + a[2][2] * b.a[2][2];       return c;     }   } f[LOG];   inline void ycl() {     for (int i = 1; i <= n; ++i)       smax(M, p[i] * b[i]), l[i] = (Line){p[i], p[i] * a[i]};     sort(l + 1, l + n + 1);     for (int i = 1; i <= n; ++i)       if (dcmp(l[i].k - l[nl].k))         l[++nl] = l[i];       else         l[nl] = l[i];     n = nl, nl = 1;     q[1] = 1;     for (int i = 2; i <= n; ++i) {       while (nl > 1 &&              dcmp(crs(l[q[nl - 1]], l[i]) - crs(l[q[nl - 1]], l[q[nl]])) <= 0)         --nl;       q[++nl] = i;     }     for (int i = 1; i <= nl; ++i) l[i] = l[q[i]];     n = nl;   }   inline void work() {     ycl();     double dp = 0;     long long tt = 0;     for (int i = 1; i <= n && tt < t; ++i) {       double stp;       if (i < n)         stp = crs(l[i], l[i + 1]);       else         stp = 1e20;       if (tt < t && dcmp(tt * M - dp - stp) >= 0) continue;       Matrix A, B;       A.a[0][0] = dp, A.a[1][0] = tt, A.a[2][0] = 1;       B.a[0][0] = 1 - l[i].k, B.a[0][1] = l[i].k * M, B.a[0][2] = l[i].b;       B.a[1][1] = 1, B.a[1][2] = 1;       B.a[2][2] = 1;       f[0] = B;       for (int i = 1; i < LOG; ++i) f[i] = f[i - 1] * f[i - 1];       for (int i = LOG - 1; ~i; --i)         if (tt + (1ll << i) < t) {           Matrix C = f[i] * A;           if (dcmp(C.a[1][0] * M - C.a[0][0] - stp) < 0) A = C, tt += 1ll << i;         }       A = f[0] * A, ++tt;       dp = A.a[0][0];     }     printf( %.13lf n , dp);   }   inline void init() {     read(n), read(t);     for (int i = 1; i <= n; ++i) read(a[i]), read(b[i]), scanf( %lf , &p[i]);   }   int main() {     init();     work();     fclose(stdin), fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 123;   using LL = long long;   using PLL = pair<LL, LL>;   PLL lr[maxn], a[maxn];   LL ans[maxn];   deque<pair<LL, PLL>> itv;   priority_queue<PLL, vector<PLL>, greater<PLL>> Q;   LL n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> lr[i].first >> lr[i].second;     sort(lr, lr + n);     for (int i = 0; i < n - 1; ++i)       itv.emplace_back(lr[i + 1].first - lr[i].second,                        make_pair(lr[i + 1].second - lr[i].first, i));     sort(itv.begin(), itv.end());     for (int i = 0; i < m; ++i) {       LL t;       cin >> t;       a[i] = {t, i + 1};     }     sort(a, a + m);     bool flag(true);     for (int i = 0; i < m; ++i) {       while (!itv.empty() && itv[0].first <= a[i].first) {         Q.push(itv[0].second);         itv.pop_front();       }       LL r, id;       if (Q.empty()) continue;       tie(r, id) = Q.top();       Q.pop();       if (r < a[i].first) {         flag = false;         break;       }       ans[id] = a[i].second;     }     if (itv.empty() && flag) {       cout <<  Yes  << endl;       cout << ans[0];       for (int i = 1; i < n - 1; ++i) cout <<     << ans[i];       cout << endl;     } else       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     char arr[4][4];     int i, j;     std::map<int, int> map;     for (i = 0; i < 4; i++) {       for (j = 0; j < 4; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  . ) {           continue;         } else {           map[arr[i][j]]++;         }       }     }     for (i = 0; i < 4; i++) {       for (j = 0; j < 4; j++) {         if (map[arr[i][j]] > 2 * k) {           cout <<  NO ;           exit(0);         }       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   //#include <bits/extc++.h>   #define ll long long   #define endl   n    #define pb push_back   #define ms(v,x) memset(v,x,sizeof(v))   #define ff first   #define ss second   #define td(v) v.begin(),v.end()   #define rep(i,a,n) for (int i=(a);i<(n);i++)   #define per(i,a,n) for (int i=(n-1);i>=a;i--)   #define trav(a, x) for(auto& a : x)   #define re(v) {for(auto &_re : v) cin >> _re;}   #define pr(v) {for(auto _pr : v) cout << _pr <<    ; cout << endl;}   #define sz(x) (int)(x).size()   #define all(x) x.begin(), x.end()   #define pii pair<int,int>   #define pll pair<ll,ll>   #define vi vector<int>   #define vl vector<ll>   #define eb emplace_back   using namespace std;   using vvi = vector<vi>;   using vvl = vector<vl>;   const ll M = 1e9 + 7;   //const ll M = 998244353;   //const ll M = 1e6;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   ll binpow(ll a, ll b){    ll res = (a!=0);    while(b > 0){     if(b&1) res = res * a % M;     a = a * a % M;     b>>=1;    }    return res;   }   //#define double long double   //#define int long long   //#define tiii tuple<int,int,int>   //#define uint unsigned int   void solve(){    int n;    cin >> n;    vi a(n), c(n + 1);     re(a);    for(int i=0;i<n;i++){     int j = i;     while(j+1 < n && a[j + 1] == a[i]){      j++;     }     c[a[i]]++;     i = j;    }    int ans = n + 1;    for(int i=0;i<n;i++){     ans = min(ans, c[a[i]] + 1 - (a[i] == a[0]) - (a[i] == a.back()));    }    cout << ans << endl;   }   int32_t main(){     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);     //freopen( .in ,  r , stdin);    //freopen( .out ,  w , stdout);    int t = 1;    cin >> t;    while(t--){     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, s, a[101], b[101], x, y, i;     double c, d, e, f, g = 10000000, h, k = -1;     cin >> n >> m >> s;     for (i = 1; i <= n; i++) cin >> a[i];     cin >> x >> y;     for (i = 2; i <= n; i++) {       c = double(a[i]) / double(m);       d = (x - a[i]) * (x - a[i]);       e = y * y;       f = double(sqrt(d + e));       f /= s;       c += f;       if (c < g || (c == g && d < k)) {         k = d;         g = c;         h = i;       }     }     cout << h;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int val;     int num;   } c[100010];   bool cmp(node a, node b) { return a.val < b.val; }   int main() {     int n, d, a, b, u, v, res = 0;     scanf( %d%d%d%d , &n, &d, &a, &b);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &u, &v);       c[i].val = u * a + v * b;       c[i].num = i;     }     sort(c + 1, c + 1 + n, cmp);     int i;     for (i = 1; i <= n; i++) {       if (d - c[i].val < 0) {         res = i - 1;         break;       }       d = d - c[i].val;     }     if (i == n + 1) res = n;     printf( %d n , res);     for (int i = 1; i <= res; i++) printf( %d  , c[i].num);     return 0;   }


#include<bits/stdc++.h>   #define R register   #define I inline   #define ll long long   #define ull unsigned long long   #define LL __int128   #define db double   using namespace std;   #define pii pair<int,int>   #define mp(x,y) make_pair(x,y)   #define piii pair<pair<int,int>,int>   #define mp3(x,y,z) make_pair(make_pair(x,y),z)   #define fi first.first   #define se first.second   #define th second   #define putint(x) printf( %d n ,x)   #define putll(x) printf( %lld n ,x)   #define putull(x) printf( %llu n ,x)   #define lowbit(x) ((x)&(-(x)))   #define inf (0x7fffffff)   #define INF (1e18)   #define eps (1e-8)   I int read()   {    char ch=getchar();    int res=0,flag=1;    while(ch< 0 ||ch> 9 )    {     if(ch== - )      flag=-1;     ch=getchar();    }    while(ch>= 0 &&ch<= 9 )    {     res=res*10+ch- 0 ;     ch=getchar();    }    return res*flag;   }   int a,b,k;   int main()   {    a=read();    b=read();    k=read();    if(b==1)    {     if(k==0)     {      puts( YES );      cout<< 1 ;      for(R int i=1;i<=a;++i)       cout<< 0 ;      puts(  );      cout<< 1 ;      for(R int i=1;i<=a;++i)       cout<< 0 ;      puts(  );      return 0;     }     else     {      puts( NO );      return 0;     }    }    if(a==0)    {     if(k==0)     {      puts( YES );      for(R int i=1;i<=b;++i)       cout<< 1 ;      puts(  );      for(R int i=1;i<=b;++i)       cout<< 1 ;      puts(  );     }     else      puts( NO );     return 0;    }    if(k<a+b-1)    {     puts( YES );     int pos1=a+b,pos2=a+b-k,cnt=0;     for(R int i=1;i<=a+b;++i)     {      if(i==pos2)       cout<<1,++cnt;      else if(cnt<b-(i<pos2))       cout<<1,++cnt;      else       cout<<0;     }     puts(  );     cnt=0;     for(R int i=1;i<=a+b;++i)     {      if(i==pos2&&pos1!=pos2)      {       cout<<0;       continue;      }      if(i==pos1)       cout<<1,++cnt;      else if(cnt<b-1)       cout<<1,++cnt;      else       cout<<0;     }     puts(  );    }    else     puts( NO );       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1ll << 62;   struct Query {     long long n;     int id;     Query(long long _n = 0, int _id = 0) : n(_n), id(_id) {}     inline bool operator<(const Query& rhs) const { return n > rhs.n; }   } qry[100010];   long long ans[100010];   vector<pair<long long, int> > dic[65];   inline long long qpow(long long base, int pw) {     long long res = 1;     while (pw) {       if (pw & 1) {         if (res < inf / base)           res = res * base;         else           return inf;       }       if (pw > 1) {         if (base < inf / base)           base = base * base;         else           return inf;       }       pw >>= 1;     }     return res;   }   inline long long get_sqrt(long long x) {     long long l = 1, r = 1000000001ll;     while (r - l > 1) {       long long mid = (l + r) >> 1;       if (mid * mid <= x)         l = mid;       else         r = mid;     }     return l;   }   bool notPrime[65];   int mu[65];   vector<int> prime;   void linear_sieve() {     notPrime[0] = notPrime[1] = true;     for (int i = 2; i <= 60; i++) {       if (!notPrime[i]) {         prime.push_back(i);         mu[i] = -1;       }       for (int j = 0; j < (int)prime.size() && i * prime[j] <= 60; j++) {         int d = i * prime[j];         notPrime[d] = true;         mu[d] = -mu[i];         if (i % prime[j] == 0) {           mu[d] = 0;           break;         }       }     }   }   int main() {     int T;     long long n;     scanf( %d , &T);     for (int i = 1; i <= T; i++) {       scanf( %lld , &n);       qry[i] = Query(n, i);     }     sort(qry + 1, qry + 1 + T);     for (int i = 3; i <= 60; i++) {       long long v;       for (int j = 2; (v = qpow(j, i)) <= 1000000000000000000ll; j++)         dic[i].push_back(pair<long long, int>(v, j));     }     linear_sieve();     for (int i = 1; i <= T; i++) {       n = qry[i].n;       long long& res = ans[qry[i].id];       res = n - 1 + (get_sqrt(n) - 1) * mu[2];       for (int i = 3; i <= 60; i++) {         while (!dic[i].empty() && dic[i].back().first > n) dic[i].pop_back();         if (dic[i].empty()) break;         res += (dic[i].back().second - 1) * mu[i];       }     }     for (int i = 1; i <= T; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, bool> tz;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int cnk(long long n, long long k, long long mod) {     long long result = 1;     int lal = 0;     for (int lol = n; lal < k; lal++, lol--) {       result *= lol;       result %= mod;     }     return result;   }   const long long mod = 1e9 + 7;   vector<long long> graph[100000];   vector<long long> vec;   vector<long long> vec1[1001];   vector<long long> vec2[1001];   long long mas[100][100];   vector<long long> nap[4];   bool masi[100000];   long long mas1[100];   long long mas2[100];   string s;   bool comp(long long a, long long b) { return a > b; }   int main() {     long long a, b, c, d;     long long k = 0;     double p;     cin >> a;     long long mini = 1e9;     for (long long lol = 0; lol < a; lol++) {       scanf( %i , &k);       mini = min(mini, k);     }     cin >> a;     for (long long lol = 0; lol < a; lol++) {       scanf( %i , &k);       vec.push_back(k);     }     long long res = 0;     std::sort(vec.begin(), vec.end(), comp);     for (long long bom = 0; bom < vec.size(); bom++) {       if (bom % (mini + 2) < mini) {         res += vec[bom];       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5005];   int vals[5005];   int n;   long long d[2][5005];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       vals[i] = a[i];     }     sort(vals, vals + n);     memset(d, 0, sizeof(d));     int cur = 0, nw = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         d[nw][j] = d[cur][j] + abs(a[i] - vals[j]);         if (j > 0) {           d[nw][j] = min(d[nw][j], d[nw][j - 1]);         }       }       swap(cur, nw);     }     long long res = d[cur][0];     for (int i = 0; i < n; i++) {       res = min(res, d[cur][i]);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> A;   int F(int q, int w, int pr) {     if (w - q <= 2) return w - q;     int s = q;     int g = 0;     int ans = 2;     while (s < w) {       int f = s;       int st = 1;       while (st <= (A[s] - pr)) st <<= 1;       st = pr + (st >> 1);       while (f < w && (A[f] & st) == st) f++;       ans = max(ans, F(s, f, st) + g + ((f == w) ? 0 : 1));       s = f;       g++;     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     A.resize(n);     for (int i = 0; i < n; i++) scanf( %d , &A[i]);     sort(A.begin(), A.end());     reverse(A.begin(), A.end());     printf( %d n , n - F(0, n, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acosl(-1);   void solve() {     long long n, s, t;     cin >> n >> s >> t;     if (n == s + t) {       cout << max(s, t) + 1 <<   n ;     } else {       if (2 * n == s + t) {         cout << 1 <<   n ;       } else {         if (s > t) {           swap(s, t);         }         long long same = t - (n - s);         cout << max(n - s, s - same) + 1 <<   n ;       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     cin >> tt;     while (tt--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 10;   const int MOD = 1e9 + 7;   long long bit[maxn], n, k;   long long sum(int i) {     long long s = 0;     while (i > 0) {       s += bit[i];       s %= MOD;       i -= i & -i;     }     return s;   }   void add(int i, long long x) {     while (i <= n) {       bit[i] += x;       bit[i] %= MOD;       i += i & -i;     }   }   long long dp[maxn];   long long a[maxn];   long long quick_mod(long long a, long long b) {     long long ans = 1;     a %= MOD;     while (b) {       if (b & 1) {         ans = ans * a % MOD;         b--;       }       b >>= 1;       a = a * a % MOD;     }     return ans;   }   long long C(long long n, long long m) {     if (m > n) return 0;     long long ans = 1;     for (int i = 1; i <= m; i++) {       long long a = (n + i - m) % MOD;       long long b = i % MOD;       ans = ans * (a * quick_mod(b, MOD - 2) % MOD) % MOD;     }     return ans;   }   long long Lucas(long long n, long long m) {     if (m == 0) return 1;     return C(n % MOD, m % MOD) * Lucas(n / MOD, m / MOD) % MOD;   }   long long combine[maxn];   void init_combine() {     for (int i = 1; i <= n; i++) combine[i] = Lucas(k + i - 1, i);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     dp[1] = a[1];     init_combine();     for (int i = 2; i <= n; i++) {       dp[i] = a[i];       for (int j = 1; j <= i - 1; j++) {         dp[i] += (combine[j] * a[i - j]) % MOD;         dp[i] %= MOD;       }     }     for (int i = 1; i <= n; i++) cout << dp[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     cin >> n >> x >> y;     vector<char> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long j = 0, p = 0;     while (j < n) {       while (a[j] == 48 && j < n) {         j++;       }       p++;       while (a[j] == 49 && j < n) {         j++;       }     }     if (a[0] == 49) {       p--;     }     if (p == 0) {       cout <<  0  << endl;       return 0;     }     cout << (p - 1) * min(x, y) + y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, x, y, z;   int f[100005];   int main() {     scanf( %d%d , &n, &m);     for (; m; --m) {       scanf( %d%d%d , &x, &y, &z);       k = 7;       k -= f[x];       k -= f[y];       k -= f[z];       if (!f[x]) f[x] = k & -k, k -= k & -k;       if (!f[y]) f[y] = k & -k, k -= k & -k;       if (!f[z]) f[z] = k & -k, k -= k & -k;     }     for (i = 1; i <= n; ++i) {       if (f[i] == 1)         printf( 1 );       else if (f[i] == 2)         printf( 2 );       else         printf( 3 );       if (i == n)         printf(  n );       else         printf(   );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const int mod = 1e9 + 9;   int Case = 1, n, m;   char ss[maxn][maxn];   int dr[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};   int vis[maxn][maxn][5][5];   struct node {     int x, y, d, cnt;     node(int x = 0, int y = 0, int d = 0, int cnt = 0) {       this->x = x;       this->y = y;       this->d = d;       this->cnt = cnt;     }   } s;   void bfs() {     queue<node> A;     for (int i = 0; i < 4; i++) {       int nx = s.x + dr[i][0];       int ny = s.y + dr[i][1];       if (nx >= 0 && nx < n && ny >= 0 && ny < m && ss[nx][ny] !=  * ) {         vis[nx][ny][i][2] = 1;         A.push(node(nx, ny, i, 2));       }     }     while (!A.empty()) {       node temp = A.front();       A.pop();       if (ss[temp.x][temp.y] ==  T ) {         printf( YES n );         return;       }       for (int i = 0; i < 4; i++) {         int nx = temp.x + dr[i][0];         int ny = temp.y + dr[i][1];         if (nx >= 0 && nx < n && ny >= 0 && ny < m && ss[nx][ny] !=  * ) {           if (temp.d != i) {             if (temp.cnt <= 0) continue;             if (!vis[nx][ny][i][temp.cnt - 1]) {               vis[nx][ny][i][temp.cnt - 1] = 1;               A.push(node(nx, ny, i, temp.cnt - 1));             }           } else {             if (!vis[nx][ny][i][temp.cnt]) {               vis[nx][ny][i][temp.cnt] = 1;               A.push(node(nx, ny, i, temp.cnt));             }           }         }       }     }     printf( NO n );   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , ss[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ss[i][j] ==  S ) s.x = i, s.y = j;       }     }     bfs();   }   int main() {     ios::sync_with_stdio(false);     while (Case--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * flag;   }   int n;   int s[109];   int main() {     n = read();     for (int i = (1), i_end_ = (n); i <= i_end_; ++i) {       char c = getchar();       if (c ==  U ) s[i] = 1;       if (c ==  R ) s[i] = 2;     }     int ans = 0, i = 1;     while (i <= n) {       if (s[i] == 1)         if (s[i + 1] == 2)           ++ans, i = i + 2;         else           i++;       else if (s[i] == 2)         if (s[i + 1] == 1)           ++ans, i = i + 2;         else           i++;     }     printf( %d n , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int base = 31337;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int logo = 20;   const int off = 1 << logo;   const int treesiz = off << 1;   int n;   int niz[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , niz + i);       niz[i] *= 2;     }     int sum = 0;     for (int i = 0; i < n; i++) sum += niz[i];     if (sum >= 9 * n)       printf( 0 );     else {       sort(niz, niz + n);       for (int i = 0; i < n; i++) {         sum += 10 - niz[i];         if (sum >= 9 * n) {           printf( %d n , i + 1);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, m;   vector<long long> g[N];   vector<long long> rg[N];   vector<long long> vs;   bool used[N];   int cmp[N], cmpsize[N];   void add_edge(int from, int to) {     g[from].push_back(to);     rg[to].push_back(from);   }   void dfs(int v) {     used[v] = 1;     for (int i = 0; i < (((int)(g[v]).size())); i++) {       if (!used[g[v][i]]) dfs(g[v][i]);     }     vs.push_back(v);   }   void rdfs(int v, int k) {     used[v] = 1;     cmp[v] = k;     for (int i = 0; i < (((int)(rg[v]).size())); i++) {       if (!used[rg[v][i]]) rdfs(rg[v][i], k);     }   }   int scc() {     memset(used, 0, sizeof(used));     vs.clear();     for (int v = 0; v < (n); v++) {       if (!used[v]) dfs(v);     }     memset(used, 0, sizeof(used));     int k = 0;     for (int i = ((int)(vs).size()) - 1; i >= 0; i--) {       if (!used[vs[i]]) rdfs(vs[i], k++);     }     return k;   }   int dfs2(int v) {     used[v] = 1;     int res = cmpsize[cmp[v]] == 1;     for (int i = 0; i < (((int)(g[v]).size())); i++)       if (!used[g[v][i]]) {         res &= dfs2(g[v][i]);       }     for (int i = 0; i < (((int)(rg[v]).size())); i++)       if (!used[rg[v][i]]) {         res &= dfs2(rg[v][i]);       }     return res;   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < (m); i++) {       int a, b;       cin >> a >> b;       add_edge(a - 1, b - 1);     }     scc();     memset(cmpsize, 0, sizeof(cmpsize));     for (int i = 0; i < (n); i++) {       cmpsize[cmp[i]]++;     }     memset(used, 0, sizeof(used));     int ans = n;     for (int i = 0; i < (n); i++)       if (!used[i]) {         ans -= dfs2(i);       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.size();     int a = 0, b = 0, c = 0;     for (int i = 0; i < n; ++i) {       a += (s[i] ==  a );       b += (s[i] ==  b );       c += (s[i] ==  c );     }     if (a == 0 || b == 0 || c == 0) {       cout <<  NO n ;       return 0;     }     if (c != a && c != b) {       cout <<  NO n ;       return 0;     }     int lasta = -1, lastb = -1, lastc = -1;     for (int i = 0; i < n; ++i) {       if (s[i] ==  a ) lasta = max(lasta, i);       if (s[i] ==  b ) lastb = max(lastb, i);       if (s[i] ==  c ) lastc = max(lastc, i);     }     if (!(lasta < lastb && lastb < lastc)) {       cout <<  NO n ;       return 0;     }     for (int i = 0; i <= lasta; ++i) {       if (s[i] !=  a ) {         cout <<  NO n ;         return 0;       }     }     for (int i = lasta + 1; i <= lastb; ++i) {       if (s[i] !=  b ) {         cout <<  NO n ;         return 0;       }     }     for (int i = lastb + 1; i <= lastc; ++i) {       if (s[i] !=  c ) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int t, n, lenn;   long long int last(long long int x) {     long long int tr = x;     lenn = 0;     while (x > 0) {       tr = x % 10;       x /= 10;       ++lenn;     }     return tr;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     long long int x, lllll;     while (t--) {       cin >> n;       lllll = last(n);       if (lenn == 1) {         x = 1;       } else if (lenn == 2) {         x = 3;       } else if (lenn == 3) {         x = 6;       } else {         x = 10;       }       cout << x + 10 * (lllll - 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   template <typename T>   using V = vector<T>;   template <typename T, typename S>   using P = pair<T, S>;   template <class T>   using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;   using LD = long double;   template <typename T, typename S>   void check(T& a, S& b) {     if (a >= b) {       a %= b;     }   }   template <typename T>   T gcd(T u, T v) {     if (u == v) return u;     if (u == 0) return v;     if (v == 0) return u;     if (~u & 1) {       if (v & 1)         return gcd(u >> 1, v);       else         return gcd(u >> 1, v >> 1) << 1;     }     if (~v & 1) return gcd(u, v >> 1);     if (u > v) return gcd((u - v) >> 1, v);     return gcd((v - u) >> 1, u);   }   LL mulmod(LL a, LL b, LL m) {     check(a, m);     check(b, m);     LL q = (LL)(((LD)a * (LD)b) / (LD)m);     LL r = a * b - q * m;     if (r > m) r %= m;     if (r < 0) r += m;     return r;   }   template <typename T, typename S>   T expo(T e, S n) {     T x = 1, p = e;     while (n) {       if (n & 1) x = x * p;       p = p * p;       n >>= 1;     }     return x;   }   template <typename T>   T powerL(T e, T n, T m) {     T x = 1, p = e;     while (n) {       if (n & 1) x = mulmod(x, p, m);       p = mulmod(p, p, m);       n >>= 1;     }     return x;   }   const int N = 200010;   const LL mod = (LL)1e9 + 7;   LL f[N], inv[N];   void pre() {     f[0] = inv[0] = f[1] = inv[1] = 1;     for (LL i = 2; i < N; i++) {       f[i] = mulmod(f[i - 1], i, mod);       inv[i] = powerL(f[i], mod - 2, mod);     }     return;   }   LL ncr(LL n, LL r) {     LL ans = mulmod(f[n], inv[n - r], mod);     return mulmod(ans, inv[r], mod);   }   LL solve(V<LL>& a) {     LL n = (LL)a.size();     LL x = (n >> 1) - 1;     V<LL> co;     for (LL i = 0; i < (LL)(x / 2) + 1; i++) {       LL t = ncr(x, i);       co.push_back(t);       co.push_back(t);     }     if ((LL)co.size() * 2 > n) co.pop_back();     auto temp = co;     reverse(temp.begin(), temp.end());     for (LL& i : temp) co.push_back(i);     if (n % 4 == 0) {       for (LL i = 1; i < n; i += 2) co[i] = -co[i];     }     LL ans = 0;     for (LL i = 0; i < (LL)n; i++) {       LL t = mulmod(a[i], co[i], mod);       ans = (ans + t);       ans %= mod;       ans = (ans + mod) % mod;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cerr.tie(NULL);     ;     pre();     LL n;     cin >> n;     V<LL> a(n);     for (LL i = 0; i < (LL)n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << a[0] <<   n ;       return 0;     }     if (n & 1) {       V<LL> t;       for (LL i = 0; i < (LL)n - 1; i++) {         t.push_back(a[i] + (2 * (!(i & 1)) - 1) * a[i + 1]);       }       a = t;     }     cout << solve(a) <<   n ;     cerr <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms           <<   n ;     return 0;   }


#include <bits/stdc++.h>   int a[100 + 10];   int main() {     int n, m, min_, max_;     scanf( %d %d %d %d , &n, &m, &min_, &max_);     int i, j, t = 0;     for (i = 0; i < m; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < m; i++) {       for (j = i + 1; j < m; j++) {         if (a[j] < a[i]) {           t = a[i];           a[i] = a[j];           a[j] = t;         }       }     }     if (a[0] < min_ || a[m - 1] > max_)       printf( Incorrect n );     else if (a[0] == min_ && a[m - 1] == max_)       printf( Correct n );     else if (a[0] != min_ && a[m - 1] != max_) {       if (n - m >= 2)         printf( Correct n );       else         printf( Incorrect n );     } else {       if (n - m >= 1)         printf( Correct n );       else         printf( Incorrect n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[101];   long long arr[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     long long sum1 = sum;     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       for (long long j = 1; j <= arr[i]; j++) {         if (arr[i] % j == 0) {           long long sum2 = sum + arr[0] * (j - 1) + arr[i] / j - arr[i];           sum1 = min(sum2, sum1);         }       }     }     cout << sum1;     return 0;   }


/** try <3 **/   #include<bits/stdc++.h>      using namespace std;      #define task  sol    #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #define pb push_back   #define mp make_pair   #define zs(v) ((int)(v).size())   #define BIT(x, i) (((x) >> (i)) & 1)   #define CNTBIT __builtin_popcountll   #define ALL(v) (v).begin(),(v).end()   #define endl   n       typedef long double ld;   typedef long long ll;   typedef pair<int, int> pii;      const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};   const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};      const ll mod=998244353 ; /// 998244353   const int base=311;   const int N=2e5+5;      int n,k;   int a[N],pos[N];   ll gt[N];      ll binpow(ll n, ll k)   {       if(k==0) return 1;       ll t=binpow(n,k/2);       t=t*t%mod;       if(k&1) t=t*n%mod;       return t;   }   int C(int k, int n)   {       if(k>n) return 0;       return gt[n]*binpow(gt[k]*gt[n-k]%mod,mod-2)%mod;   }   void add(int &a, int b)   {       a+=b;       if(a>=mod) a-=mod;   }   void gogo()   {       cin>>n>>k;       for(int i=1;i<=n;++i)       {           cin>>a[i];           a[i]++;           pos[a[i]]=i;       }       gt[0]=1;       for(int i=1;i<=N-5;++i) gt[i]=gt[i-1]*i%mod;       int cnt=1;       for(int i=1;i<n;++i)       {   //        cout<<a[i]<<   <<a[i+1]<<   <<pos[a[i]+1]<<   <<pos[a[i+1]+1]<<  n ;           if(pos[a[i]+1]>pos[a[i+1]+1])           {               cnt++;           }       }   //    cout<<cnt<<endl;       int ans=0;       for(int i=cnt;i<=min(n,k);++i)       {           /// choose i-cnt such that it will not be equal           add(ans,(ll)C(i,k)*C(i-cnt,n-cnt)%mod);       }       cout<<ans;   }   int main()   {       ios_base::sync_with_stdio(0); cin.tie(0);       if(fopen(task .inp ,  r ))       {           freopen(task .inp ,  r , stdin);           freopen(task .out ,  w , stdout);       }       gogo();   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   const int INF = 1e8;   const int N = 2e5 + 2;   int n, m, k;   vector<int> G[N];   int a[N];   bool sp[N];   int distN[N], dist1[N];   int suf[N];   bool cmp(int& v, int& u) { return dist1[v] < dist1[u]; }   void bfsN() {     for (int i = 0; i < n; i++) distN[i] = INF;     distN[n - 1] = 0;     queue<pair<int, int>> q;     q.push({0, n - 1});     while (!q.empty()) {       int v = q.front().second;       int d = q.front().first;       q.pop();       for (auto u : G[v]) {         if (distN[u] > d + 1) {           distN[u] = d + 1;           q.push({distN[u], u});         }       }     }   }   void bfs1() {     for (int i = 0; i < n; i++) dist1[i] = INF;     dist1[0] = 0;     queue<pair<int, int>> q;     q.push({0, 0});     while (!q.empty()) {       int v = q.front().second;       ;       int d = q.front().first;       q.pop();       for (auto u : G[v]) {         if (dist1[u] > d + 1) {           dist1[u] = d + 1;           q.push({dist1[u], u});         }       }     }   }   int getAns() {     int ans = 0;     for (int i = k - 2; i >= 0; i--) ans = max(ans, dist1[a[i]] + 1 + suf[i + 1]);     return min(ans, distN[0]);   }   signed main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> a[i], a[i]--;       sp[a[i]] = true;     }     for (int i = 0; i < m; i++) {       int v, u;       cin >> v >> u, v--, u--;       G[v].push_back(u);       G[u].push_back(v);     }     bfsN();     bfs1();     sort(a, a + k, cmp);     suf[k - 1] = distN[a[k - 1]];     for (int i = k - 2; i >= 0; i--) suf[i] = max(suf[i + 1], distN[a[i]]);     cout << getAns() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2222;   const int INF = 0x3f3f3f3f;   int n, m, k, s;   int mat[2][N][9], cp[9][9];   void tomin(int &a, int b) {     if (a > b) a = b;   }   void tomax(int &a, int b) {     if (a < b) a = b;   }   void work() {     for (int i = 0; i < m; i++)       for (int j = 0; j < k; j++) {         for (int r = i; r < m; r++)           for (int p = 0; p < k; p++) {             tomax(cp[j][p], abs(r - i) + mat[1][i][j] - mat[0][r][p]);             tomax(cp[j][p], abs(r - i) + mat[1][r][p] - mat[0][i][j]);             tomax(cp[p][j], cp[j][p]);           }       }     int d, ans = 0;     scanf( %d , &d);     d--;     for (int i = 1; i < s; i++) {       int x;       scanf( %d , &x);       x--;       tomax(ans, cp[d][x]);       d = x;     }     printf( %d n , ans);   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &s);     memset(mat[0], INF, sizeof(mat[0]));     memset(mat[1], -1, sizeof(mat[1]));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int d;         scanf( %d , &d);         d--;         tomin(mat[0][j][d], i);         tomax(mat[1][j][d], i);       }     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[4];     for (int i = 0; i < 4; i++) cin >> arr[i];     sort(arr, arr + 4);     long long w, x, y, z;     w = arr[0];     x = arr[1];     y = arr[2];     long long a, b, c, d;     b = (w - x + y) / 2;     a = w - b;     c = x - a;     cout << a <<     << b <<     << c;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int a[10000];   int n, m, mn, mn1;   multiset<int> s;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       s.insert(a[i]);     }     int q = *s.rbegin() + m;     while (m--) {       int t = *s.begin();       s.erase(s.begin());       s.insert(t + 1);     }     cout << *s.rbegin() <<     << q;     return 0;   }