#include <bits/stdc++.h>   using namespace std;   int q;   unsigned long long a, b, c;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> a >> b >> c;       unsigned long long sum = a + b + c;       cout << sum / 2 <<   n ;       sum = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(15);     srand(42u);     unsigned int n;     unsigned int m;     cin >> n >> m;     cout << (min(n, m) & 1 ?  Akshat  :  Malvika ) << endl;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   int adder[1234567], pre[1234567];   int main() {     std::ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     int i, l, r;     l = 0;     r = 0;     string s;     cin >> s;     for (i = 1; i < n; i++) {       if (r < i) {         l = i;         r = i;         while (r < n && s[r] == s[r - l]) r++;         pre[i] = r - l;         r--;         continue;       }       if (r - i + 1 > pre[i - l]) {         pre[i] = pre[i - l];       } else {         l = i;         while (r < n && s[r] == s[r - l]) r++;         pre[i] = r - l;         r--;       }     }     long long haha, haha1, endp;     for (i = 1; i < n; i++) {       haha = k * i;       haha1 = (k + 1) * i;       endp = i + pre[i];       if (haha > endp) continue;       haha1 = min(haha1, n);       haha1 = min(haha1, endp);       adder[haha]++;       adder[haha1 + 1]--;     }     if (k == 1) {       adder[n]++;     }     for (i = 1; i <= n; i++) {       adder[i] += adder[i - 1];       if (adder[i])         cout << 1;       else         cout << 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE *stm;   const double PI = 22.0 / 7.0;   const long long MXN = 1e5 + 1;   const long long MNN = 1e3 + 1;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   bool srt(string a, string b) { return a.size() > b.size(); }   int gcd(int a, int b) {     if (b == 0)       return a;     else       gcd(b, a % b);   }   int lcm(int a, int b) { return (b / gcd(a, b)) * a; }   int main() {     string first;     cin >> first;     int n = first.size();     int ctr = 0;     int j = 0;     while (first[j] ==  a  and j < n) {       ctr++;       j++;     }     if (ctr == n) {       first[n - 1] =  z ;     } else if (first[0] !=  a ) {       for (int i = 0; i < n and first[i] !=  a ; i++) first[i] = first[i] - 1;     } else if (first[0] ==  a ) {       int i = 0;       while (first[i] ==  a ) {         i++;       }       for (; i < n and first[i] !=  a ; i++) first[i] = first[i] - 1;     }     cout << first << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 100010;   const int M = 25;   long long dp[M][N];   int cnt[N], a[N];   long long cost, left, right;   void move(int nleft, int nright) {     while (nleft < left) cost += cnt[a[--left]]++;     while (nright > right) cost += cnt[a[++right]]++;     while (nleft > left) cost -= --cnt[a[left++]];     while (nright < right) cost -= --cnt[a[right--]];   }   void solve(int type, int l, int r, int opl, int opr) {     if (l > r) return;     long long mincost = LLONG_MAX;     int mid = l + r >> 1, sit;     for (int i = opl, sz = std::min(opr, mid - 1); i <= sz; ++i) {       move(i + 1, mid);       long long x = dp[type - 1][i] + cost;       if (x < mincost) {         mincost = x;         sit = i;       }     }     dp[type][mid] = mincost;     solve(type, l, mid - 1, opl, sit);     solve(type, mid + 1, r, sit, opr);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     left = 1, right = 0;     move(1, n);     memset(dp[0], 0x3f, sizeof(dp[0]));     dp[0][0] = 0;     for (int i = 1; i <= k; ++i) {       solve(i, 1, n, 0, n);     }     return printf( %I64d n , dp[k][n]), 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   string name;   string hostname;   string res;   int is_good(char c) {     if (c -  a  >= 0 && c -  a  < 26) return 1;     if (c -  A  >= 0 && c -  A  < 26) return 1;     if (c -  0  >= 0 && c -  0  < 10) return 1;     if (c ==  _ ) return 1;     return 0;   }   int main() {     cin >> s;     int tk = 0;     int cl1 = 0;     int cl2 = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  @ ) {         if (tk != 0) {           printf( NO n );           return 0;         }         tk = 1;         cl1++;         continue;       }       if (s[i] ==  / ) {         cl2++;         if (tk != 1) {           printf( NO n );           return 0;         }         tk = 2;         continue;       }       if (tk == 0) name += s[i];       if (tk == 1) hostname += s[i];       if (tk == 2) res += s[i];     }     if (res ==    && cl2 != 0) {       printf( NO n );       return 0;     }     if (name ==    || hostname ==   ) {       printf( NO n );       return 0;     }     if (name.length() > 16 || hostname.length() > 32 || res.length() > 16) {       printf( NO n );       return 0;     }     for (int i = 0; i < name.length(); i++)       if (!is_good(name[i])) {         printf( NO n );         return 0;       }     for (int i = 0; i < res.length(); i++)       if (!is_good(res[i])) {         printf( NO n );         return 0;       }     int tl = 0;     for (int i = 0; i < hostname.length(); i++)       if (hostname[i] ==  . ) {         if (tl > 16 || tl == 0) {           printf( NO n );           return 0;         }         tl = 0;         continue;       } else if (!is_good(hostname[i])) {         printf( NO n );         return 0;       } else         tl++;     if (tl > 16 || tl == 0) {       printf( NO n );       return 0;     }     if (cl1 > 1 || cl2 > 1) {       printf( NO n );       return 0;     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   int main() {     int i, j;     int n, pare[maxn], mark[maxn];     while (scanf( %d , &n) != EOF) {       memset(pare, 0, sizeof(pare));       memset(mark, 0, sizeof(mark));       for (i = 2; i <= n; i++) {         scanf( %d , &pare[i]);         mark[pare[i]] = 1;       }       for (i = n; i >= 2; i--)         if (mark[i] == 0) {           mark[pare[i]]++;         }       for (i = 1; i <= n; i++) {         if (mark[i] != 0 && mark[i] < 4) break;       }       if (i == (n + 1))         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int k;     cin >> k;     k += 2000;     cout << 2000 <<   n ;     cout << -1 <<    ;     for (int i = 0; i < 1999; i++) {       if (k > 1000000) {         cout << 1000000 <<    ;         k -= 1000000;       } else {         cout << k <<    ;         k = 0;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n), b(n);     for (long long &i : a) cin >> i;     for (long long &i : b) cin >> i;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (long long &i : a) cout << i <<    ;     cout << endl;     for (long long &i : b) cout << i <<    ;     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     long long n = 1;     cin >> n;     while (n--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   namespace A {   int ch[10001000][2], fail[10001000], end[10001000], cnt;   inline int insert(char *s, int id, int *dis) {     int len = strlen(s), rt = 0;     for (int i = 0; i < len; ++i) {       int d = s[i] -  a ;       if (!ch[rt][d]) ch[rt][d] = ++cnt;       rt = ch[rt][d];     }     if (end[rt]) dis[end[rt]] = 1;     end[rt] = id;     return len;   }   void getfail(int dis[1600][1600]) {     queue<int> q;     if (ch[0][0]) q.push(ch[0][0]);     if (ch[0][1]) q.push(ch[0][1]);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int k = 0; k <= 1; ++k) {         if (!ch[u][k])           ch[u][k] = ch[fail[u]][k];         else {           fail[ch[u][k]] = ch[fail[u]][k];           if (end[fail[ch[u][k]]]) {             if (end[ch[u][k]])               dis[end[ch[u][k]]][end[fail[ch[u][k]]]] = 1;             else               end[ch[u][k]] = end[fail[ch[u][k]]];           }           q.push(ch[u][k]);         }       }     }   }   void match(char *s, int len, int *dis) {     int rt = 0;     for (int i = 0; i < len; ++i) {       rt = ch[rt][s[i] -  a ];       if (end[rt]) dis[end[rt]] = 1;     }   }   };  // namespace A   int n, st[1600], dis[1600][1600];   char s[10001000];   namespace D {   int S, T, tot = 1, fir[1600], nxt[1600 * 1600], to[1600 * 1600],             val[1600 * 1600], dep[1600], cur[1600];   queue<int> q;   inline void addE(int u, int v, int w) {     nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v, val[tot] = w;     nxt[++tot] = fir[v], fir[v] = tot, to[tot] = u, val[tot] = 0;   }   inline bool bfs() {     memset(dep, -1, sizeof dep);     memcpy(cur, fir, sizeof fir);     q.push(S), dep[S] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = fir[u], v; i; i = nxt[i]) {         v = to[i];         if ((~dep[v]) || !val[i]) continue;         dep[v] = dep[u] + 1, q.push(v);       }     }     return (~dep[T]);   }   int dfs(int u, int now) {     if (u == T || !now) return now;     int res = 0;     for (int &i = cur[u], v; i; i = nxt[i]) {       v = to[i];       if (dep[v] != dep[u] + 1 || !val[i]) continue;       int tmp = dfs(v, min(now, val[i]));       if (!tmp) continue;       res += tmp, now -= tmp, val[i] -= tmp, val[i ^ 1] += tmp;       if (!now) break;     }     return res;   }   inline int dinic() {     int res = 0, tmp;     while (bfs())       while ((tmp = dfs(S, INF))) res += tmp;     return res;   }   int mat[1600];   bool vis[1600];   void match(int u) {     if (vis[u]) return;     vis[u] = 1;     for (int i = fir[u]; i; i = nxt[i])       if (!vis[to[i]] && to[i] <= 2 * n) vis[to[i]] = 1, match(mat[to[i]]);   }   void write() {     for (int u = 1; u <= n; ++u)       for (int i = fir[u]; i && !mat[u]; i = nxt[i])         if (!val[i] && to[i] <= 2 * n) mat[mat[u] = to[i]] = u;     for (int u = 1; u <= n; ++u)       if (!mat[u]) match(u);     for (int i = 1; i <= n; ++i) {       if (vis[i] && !vis[i + n]) printf( %d%c , i,    n [i == n]);     }   }   }  // namespace D   using D::addE;   using D::dinic;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %s , s + st[i]);       st[i + 1] = A::insert(s + st[i], i, dis[i]) + st[i];     }     A::getfail(dis);     for (int i = 1; i <= n; ++i) A::match(s + st[i], st[i + 1] - st[i], dis[i]);     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j)           if (dis[i][k] && dis[k][j]) dis[i][j] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (dis[i][j]) D::S = 2 * n + 1, D::T = D::S + 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (dis[i][j] && i != j) addE(i, j + n, 1);     for (int i = 1; i <= n; ++i) addE(D::S, i, 1), addE(i + n, D::T, 1);     int res = dinic();     res = n - res;     cout << res << endl;     D::write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, t, cnt = 0, flag, cs = 1;     pair<int, int> A[110];     scanf( %d %d , &j, &k);     for (i = 0; i < j; i++) {       scanf( %d , &A[i].first);       A[i].second = i + 1;     }     sort(A, A + j);     vector<int> v;     int sum = 0;     for (i = 0; i < j; i++) {       sum += A[i].first;       if (sum > k) break;       cnt++;       v.push_back(A[i].second);     }     cout << cnt << endl;     if (cnt == 0) return 0;     for (i = 0; i <= cnt - 2; i++) cout << v[i] <<    ;     cout << v[i] << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     using namespace std;     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string b, b1, b2, e, e1, e2;     cin >> b1 >> b2 >> e1 >> e2;     swap(b2[0], b2[1]);     swap(e2[0], e2[1]);     b = b1 + b2;     e = e1 + e2;     b.erase(b.find( X ), 1);     e.erase(e.find( X ), 1);     if ((b + b).find(e) != string::npos) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef pair<int, int> pll;      #define all(x)                      (x).begin(),(x).end()   #define X                           first   #define Y                           second   #define sep                               #define endl                          n    #define debug(x)                    cerr << #x <<  :   <<  x << endl;      const ll MAXN = 1e6 + 10;   const ll INF = 8e18;   const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;   const ll LOG = 20;      int n, m, P[MAXN], H[MAXN], t_0, par[MAXN][LOG];    vector<int> adj[MAXN];   vector<pll> adj2[MAXN];   vector<pair<int, pll>> edges, mst_edges;   set<int> un_vis;   ll ans;   bool w_0[MAXN][LOG];   set<pll> used;      int Find(int v) {    if (v == P[v]) return v;    return P[v] = Find(P[v]);   }      inline bool Union(int v, int u, int w) {    int pu = u, pv = v;    v = Find(v), u = Find(u);    if (v == u) return false;    P[v] = u;    ans += w;    used.insert({pv, pu});    used.insert({pu, pv});       if (w == 0) t_0++;    mst_edges.push_back({w, {pu, pv}});    return true;   }      void dfs(int v) {    un_vis.erase(v);        int lst = 0;    while (true) {     auto it = un_vis.upper_bound(lst);     if (it == un_vis.end()) break;     lst = *it;     if (binary_search(all(adj[v]), lst)) continue; //        Union(v, lst, 0);     dfs(lst);    }   }      void dfs2(int v, int p, int w) {    par[v][0] = p;    w_0[v][0] = (w == 0);       for (pll e : adj2[v]) {     int u = e.X, w = e.Y;     if (u == p) continue;     H[u] = H[v] + 1;     dfs2(u, v, w);    }   }      pair<int, bool> kth_par(int v, int k) {    bool b = false;    for (int i = LOG - 1; i >= 0; i--)     if (k & (1 << i))      b |= w_0[v][i], v = par[v][i];    return {v, b};   }      bool LCA(int u, int v) {    if (H[v] < H[u]) swap(v, u);    pair<int, bool> p = kth_par(v, H[v] - H[u]);    v = p.X;    bool b = p.Y;    if (v == u) return b;       for (int i = LOG - 1; i >= 0; i--) {     if (par[v][i] != par[u][i]) {      b |= w_0[v][i];      b |= w_0[u][i];      v = par[v][i];      u = par[u][i];     }    }        b |= w_0[v][0];    b |= w_0[u][0];    return b;         }      int main() {    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    cin >> n >> m;    int x = 0;       for (int i = 0; i < m; i++) {     int u, v, w;     cin >> u >> v >> w;     x ^= w;     edges.push_back({w, {u, v}});     adj[v].push_back(u);     adj[u].push_back(v);    }       for (int i = 1; i <= n; i++) {     sort(all(adj[i]));     un_vis.insert(i);     P[i] = i;     }        while (!un_vis.empty()) dfs(*un_vis.begin());       sort(all(edges));    for (auto e : edges) Union(e.Y.X, e.Y.Y, e.X);     for (auto e : mst_edges) {     adj2[e.Y.X].push_back({e.Y.Y, e.X});     adj2[e.Y.Y].push_back({e.Y.X, e.X});    }       dfs2(1, 0, 1);    for (int i = 1; i < LOG; i++) {     for (int v = 1; v <= n; v++) {      par[v][i] = par[par[v][i - 1]][i - 1];      w_0[v][i] = w_0[v][i - 1] | w_0[par[v][i - 1]][i - 1];     }    }       ll tot = 1ll * n * (n - 1) / 2 - m;    if (tot == t_0) {     for (pair<int, pll> et : edges) {      pll e = et.Y;      if (used.find(e) != used.end()) continue;      bool b = LCA(e.X, e.Y);      if (b) return cout << min(ans + et.X, ans + x) << endl, 0;     }          cout << ans + x << endl;     return 0;     }        cout << ans << endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   map<char, int> u;   int main() {     cin >> s >> s;     for (auto x : s) ++u[x];     if (u.size() == 1) return puts( Yes ), 0;     for (auto& x : u)       if (x.second >= 2) return puts( Yes ), 0;     puts( No );   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, k;   int A[25], B[2];   int fact[25];   int mod(long long int a) { return (a % MOD + MOD) % MOD; }   int poww(int pw) {     if (pw == 0) return 1;     return 3 * poww(pw - 1);   }   int result = 0;   int precompute(int U1) {     int ret = 0;     int el = (n + 1) / 2, fl = n - el;     int EL = (1 << el), FL = (1 << fl);     map<pair<int, int>, int> store;     int cnt, sum;     for (int i = 0; i < FL; i++) {       sum = cnt = 0;       for (int bit = 0; bit < fl; bit++) {         if (i & (1 << bit)) sum += A[el + bit], cnt++;         if (sum > MOD) sum = MOD;       }       if (sum != MOD) store[pair<int, int>(sum, cnt)]++;     }     for (int i = 0; i < EL; i++) {       sum = cnt = 0;       for (int bit = 0; bit < el; bit++) {         if (i & (1 << bit)) sum += A[bit], cnt++;         if (sum > MOD) sum = MOD;       }       if (sum > U1) continue;       for (int x = 0; x < fl + 1; x++) {         pair<int, int> t = pair<int, int>(U1 - sum, x);         if (store.count(t)) {           int ff = mod((long long int)store[t] * fact[x + cnt]);           ff = mod((long long int)ff * fact[n - x - cnt]);           ret = mod(ret + ff);         }       }     }     result = mod(result - ret);     return result;   }   int pc2(int U1, int U2) {     int el = (n - 1) / 2, fl = n - el;     int EL = poww(el), FL = poww(fl);     precompute(U1);     precompute(U2);     if (U1 > U2) swap(U1, U2);     U2 = U2 - U1;     map<pair<pair<int, int>, int>, int> store;     int sum1, sum2, ret = 0;     int c1, c2;     for (int i = 0; i < FL; i++) {       sum1 = sum2 = c1 = c2 = 0;       int t = i;       for (int bit = 0; bit < fl; bit++) {         if (t % 3 == 1) sum1 += A[el + bit], c1++;         if (t % 3 == 2) sum2 += A[el + bit], c2++;         t /= 3;         if (sum1 > MOD) sum1 = MOD;         if (sum2 > MOD) sum2 = MOD;       }       if (sum1 != MOD && sum2 != MOD)         store[pair<pair<int, int>, int>(pair<int, int>(sum1, sum2),                                         (c1 << 8) | c2)]++;     }     for (int i = 0; i < EL; i++) {       sum1 = sum2 = c1 = c2 = 0;       int t = i;       for (int bit = 0; bit < el; bit++) {         if (t % 3 == 1) sum1 += A[bit], c1++;         if (t % 3 == 2) sum2 += A[bit], c2++;         if (sum1 > MOD) sum1 = MOD;         if (sum2 > MOD) sum2 = MOD;         t /= 3;       }       if (sum1 > U1 || sum2 > U2) continue;       for (int x = 0; x < fl + 1; x++) {         for (int y = 0; y + x <= fl; y++) {           if (x + y > fl) continue;           pair<pair<int, int>, int> t = pair<pair<int, int>, int>(               pair<int, int>(U1 - sum1, U2 - sum2), (x << 8) | y);           if (store.count(t)) {             int ff = store[t];             ff = mod((long long int)ff * fact[c1 + x]);             ff = mod((long long int)ff * fact[c2 + y]);             ff = mod((long long int)ff * fact[n - c1 - x - c2 - y]);             ret = mod((long long int)ret + ff);           }         }       }     }     result = mod((long long int)result + ret);     return ret;   }   int main() {     B[0] = B[1] = -1;     fact[0] = 1;     for (int i = 1; i < 25; i++) fact[i] = ((long long int)fact[i - 1] * i) % MOD;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     cin >> k;     for (int i = 0; i < k; i++) cin >> B[i];     result = fact[n];     if (k == 1)       precompute(B[0]);     else if (k == 2) {       pc2(B[0], B[1]);     }     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     ;     long long int T, N, X;     cin >> T;     while (T--) {       cin >> N >> X;       vector<bool> Pl(100100);       for (long long int i = 0, P; i < N; i++) {         cin >> P;         Pl[P - 1] = true;       }       for (long long int i = 0; i < 100100; i++) {         if (!Pl[i] && X > 0) {           Pl[i] = true;           X--;         }       }       long long int Counter = 0;       for (long long int i = 0; i < 100100; i++) {         if (Pl[i])           Counter++;         else           break;       }       cout << Counter << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > second;   int arr[(int)(1e5) + 30];   int main() {     int n, m;     int u, v;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v;       second.insert(make_pair(u, v));       second.insert(make_pair(v, u));     }     for (int i = 0; i < n; i++) arr[i] = i + 1;     int limit = 1000;     while (limit--) {       random_shuffle(arr, arr + n);       arr[n] = arr[0];       for (int i = 0; i < m; i++) {         if (second.find(make_pair(arr[i], arr[i + 1])) != second.end()) goto re;       }       for (int i = 0; i < m; i++) cout << arr[i] <<     << arr[i + 1] << endl;       return 0;     re:;     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> v[100005];   int a[100008];   int b[100005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i].first);       v[i].second = i;     }     sort(v, v + n);     int val = 0;     int qt = (n + 2) / 3;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (i < qt) {         int idx = v[i].second;         a[idx] = i;         b[idx] = v[i].first - i;       } else if (i < 2 * qt) {         int idx = v[i].second;         b[idx] = i;         a[idx] = v[i].first - i;       } else {         int idx = v[i].second;         b[idx] = n - 1 - i;         a[idx] = v[i].first - b[idx];       }     }     puts( YES );     for (int i = 0; i < n; i++) {       printf( %d  , a[i]);     }     puts(  );     for (int i = 0; i < n; i++) {       printf( %d  , b[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m, m2;     char c;     scanf( %d %c %d , &h, &c, &m);     scanf( %d , &m2);     m2 += m;     int h2 = (int)(m2 / 60);     h2 += h;     h2 %= 24;     m2 = m2 % 60;     if (h2 >= 0 && h2 <= 9) printf( 0 );     printf( %d: , h2);     if (m2 >= 0 && m2 <= 9) printf( 0 );     printf( %d n , m2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const long long N = 1e6 + 5;   void no() { cout <<  0 0 0  << endl; }   void cpc() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(NULL);   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     long long j = n / 2 - 1;     while (j >= 4 && v[j] <= v[j + 1]) j--;     if (j < 4) {       no();       return;     }     deque<long long> va;     va.push_front(j);     j--;     while (j >= 0) {       if (v[j] > v[j + 1]) va.push_front(j);       j--;     }     va.push_front(-1);     if (va.size() < 4) {       no();       return;     }     long long a, b, c, d;     a = va[0];     b = va[1];     c = -1;     d = va[va.size() - 1];     long long dis = b - a;     for (long long i = 0; i < n; i++) {       if ((va[i] - b) > dis) {         c = va[i];         break;       }     }     if (c == -1 || (d - c) <= dis) {       no();       return;     }     cout << b - a <<     << c - b <<     << d - c <<     << endl;   }   int32_t main() {     cpc();     long long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10, N = 2e4 + 10;   const int n = 1e5;   long long ans, s[M];   int gcd(int x, int y) {     int i = 0, j = 0;     if (x == 0) return y;     if (y == 0) return x;     for (; 0 == (x & 1); i++) x >>= 1;     for (; 0 == (y & 1); j++) y >>= 1;     if (i > j) i = j;     while (1) {       if (x < y) x ^= y, y ^= x, x ^= y;       if (0 == (x -= y)) return y << i;       while (0 == (x & 1)) x >>= 1;     }   }   int T, A, B, C;   int prime[N], cc[M], cnt;   bool vis[M];   void init() {     s[1] = 1;     for (int i = 2; i <= n; i++) {       if (!vis[i]) {         prime[++cnt] = i;         s[i] = 2;         cc[i] = 1;       }       for (int j = 1, v; j <= cnt && i * prime[j] <= n; j++) {         v = i * prime[j];         vis[v] = 1;         if (!(i % prime[j])) {           s[v] = s[i] / (cc[i] + 1) * (cc[i] + 2);           cc[v] = cc[i] + 1;           break;         }         s[v] = s[i] * s[prime[j]];         cc[v] = 1;       }     }   }   long long all(int a, int b, int c) { return s[a] * s[b] * s[c]; }   long long S(long long a) { return (a * (a - 1ll)) / 2ll; }   long long S2(long long a) { return (a * (a - 1ll) * (a - 2ll)) / 6ll * 4ll; }   long long calc1(int ab, int c) { return S(s[ab]) * s[c]; }   long long calc2(int a, int bc) { return s[a] * S(s[bc]); }   long long calc3(int abc) { return S(s[abc]) * 2ll + S2(s[abc]); }   long long calc4(int ab, int abc) { return (s[ab] - s[abc]) * S(s[abc]); }   long long calc5(int ab, int bc, int ac, int abc) {     return (s[ab] - s[abc]) * (s[bc] - s[abc]) * (s[ac] - s[abc]);   }   int ab, bc, ac, abc;   long long solve() {     return all(A, B, C) - calc1(ab, C) - calc2(A, bc) - calc2(B, ac) +            calc4(ab, abc) + calc4(bc, abc) + calc4(ac, abc) -            calc5(ab, bc, ac, abc) + calc3(abc);   }   int main() {     init();     for (scanf( %d , &T); T--;) {       scanf( %d%d%d , &A, &B, &C);       ab = gcd(A, B), bc = gcd(B, C), ac = gcd(A, C);       abc = gcd(A, bc);       printf( %I64d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s;   char ch;   string ss =   , str =   ;   long long a[200003], b[200003];   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0;     stack<long long> st;     cin >> ss;     n = ss.length();     long long dp[n + 2];     memset(dp, 0, sizeof(dp));     for (i = 0; i < n; i++) {       if (ss[i] ==  ( ) {         st.push(i);         continue;       }       if (st.empty()) continue;       long long lft = st.top();       st.pop();       if (lft)         dp[i] = dp[lft - 1] + i - lft + 1;       else         dp[i] = i - lft + 1;       mx = max(mx, dp[i]);     }     for (i = 0; i < n; i++)       if (dp[i] == mx) ct++;     if (!mx) return cout <<  0 1 , 0;     cout << mx <<     << ct;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200100];   deque<int> Q;   bool cnt[10001000];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]] = true;     sort(a, a + n);     int Min = a[0], Max = a[n - 1], Ans = 0;     for (int i = Min; i <= 1e7; i++) {       if (Q.size() && Q.front() < i - m) Q.pop_front();       if (i >= Min + m - 1)         while (Q.size() >= k) Q.pop_back(), Ans++;       if (cnt[i]) Q.push_back(i);     }     cout << Ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1003];   const int mod = 1000000007;   int comb[1005][1005], i, j;   int main() {     int lim = 1002;     for (i = 1; i <= lim; i++) comb[i][i] = comb[i][0] = 1;     for (i = 2; i <= lim; i++)       for (j = 1; j < i; j++) {         long long aux = comb[i - 1][j] + comb[i - 1][j - 1];         aux %= mod;         comb[i][j] = aux;       }     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     long long ans = 1;     long long nr = a[1];     for (i = 2; i <= n; i++) {       int en = a[i] - 1;       ans = (1LL * ans * comb[en + nr][en]) % mod;       nr += a[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[5000010], ch;   int a[5000010];   int dc[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};   int sd = 24 * 60 * 60;   int main() {     int n, m, top = 1;     int YY, MM, DD, hh, mm, ss;     scanf( %d%d , &n, &m);     getchar();     a[0] = 0xc0c0c0c0;     while (gets(buf)) {       sscanf(buf,  %d%c%d%c%d%c%d%c%d%c%d , &YY, &ch, &MM, &ch, &DD, &ch, &hh,              &ch, &mm, &ch, &ss);       int t = (dc[MM] + DD - 1) * sd + hh * 60 * 60 + mm * 60 + ss;       a[top++] = t;       t -= n - 1;       int l = 0, r = top - 1;       while (l < r - 1) {         int mid = l + r >> 1;         if (a[mid] < t)           l = mid;         else           r = mid;       }       if (top - r >= m) {         buf[19] = 0;         printf( %s n , buf);         return 0;       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long y = 2; y <= 10005; y++) {       for (long long z = y + 1; z <= 10005; z++) {         if (2 * y * z - n * y - n * z <= 0) continue;         long long x = (n * y * z) / (2 * y * z - n * y - n * z);         if ((n * y * z) % (2 * y * z - n * y - n * z) == 0 && x <= 1000000000 &&             x != y && x != z && y != z) {           cout << x <<     << y <<     << z <<   n ;           return 0;         }       }     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, ans;   string s;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  U ) y++;       if (s[i] ==  D ) y--;       if (s[i] ==  L ) x--;       if (s[i] ==  R ) x++;     }     if (y < 0) y *= (-1);     if (x < 0) x *= (-1);     ans = n - x - y;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v, id;     node(int _id) {       id = _id;       cin >> v;     }     bool operator<(const node& from) const { return v > from.v; }   };   vector<node> Q;   bool IN[200005];   int l[200005];   int r[200005];   int pt = 1, mx = 1;   void update(int x) {     IN[x] = 1;     if (IN[x - 1]) l[x] = l[x - 1];     if (IN[x + 1]) r[x] = r[x + 1];     r[l[x]] = r[x];     l[r[x]] = l[x];     mx = max(mx, r[x] - l[x] + 1);   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) Q.push_back(node(i));     for (int i = 1; i <= n; i++) l[i] = r[i] = i;     sort(Q.begin(), Q.end());     int pt = 1;     for (int i = 0; i < n; i++) {       while (i < n and Q[i + 1].v == Q[i].v) update(Q[i++].id);       update(Q[i].id);       for (; pt <= mx; pt++) cout << Q[i].v <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int n;   int main() {     int i;     long long ans, sumx, sumy, x, y;     scanf( %d , &n);     ans = sumx = sumy = 0;     for (i = 0; i < n; i++) {       scanf( %I64d%I64d , &x, &y);       ans += (long long)x * x * n + y * y * n;       sumx += x;       sumy += y;     }     printf( %I64d , ans - sumx * sumx - sumy * sumy);   }


#include <bits/stdc++.h>   using namespace std;   int dp[1000000], arr[1000000];   int main() {     int fi = 1, se = 1;     int n;     cin >> n;     int last = 20;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       arr[i] = x;       if (i == 1) {         cout << 20 <<   n ;         dp[i] = 20;         continue;       }       while (arr[fi] + 90 <= arr[i]) fi++;       while (arr[se] + 1440 <= arr[i]) se++;       dp[i] = 20 + dp[i - 1];       dp[i] = min(dp[i], dp[fi - 1] + 50);       dp[i] = min(dp[i], dp[se - 1] + 120);       cout << dp[i] - last <<   n ;       last = dp[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fr[300005], v[300005];   int main() {     int n, i, x, sol = 0, pos1, pos2, cate = 0;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> v[i];       x = v[i];       ++fr[x];       if (fr[x] == 1) ++cate;       if (cate == 1 && fr[x] == 1) pos1 = i;       if (cate == 2 && fr[x] == 1) sol = max(sol, i - pos1), pos2 = i;       if (cate >= 2) {         if (v[pos1] == v[i])           sol = max(sol, i - pos2);         else           sol = max(sol, i - pos1);       }     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, k;       scanf( %d %d , &n, &k);       int div = n / k;       int mod = n % k;       for (int i = 0; i < k; i++) {         for (int j = 1; j <= div; j++) {           printf( %c , ( a  + i));         }         if (mod) {           printf( %c , ( a  + i));           mod--;         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   void err() { std::cout << std::endl; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   using namespace std;   const int mod = 998244353;   const int inf = 1 << 30;   const int maxn = 200000 + 5;   const int maxq = 3000 + 5;   long long qpow(long long x, long long n) {     long long r = 1;     while (n > 0) {       if (n & 1) r = r * x % mod;       n >>= 1;       x = x * x % mod;     }     return r;   }   long long inv(int x) { return qpow(x, mod - 2); }   void add(long long& x, long long y) {     x += y;     if (x >= mod) x -= mod;   }   int n, m, a[maxn], w[maxn];   long long f[maxq][maxq];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     int sa = 0, sb = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , w + i);       if (a[i])         sa += w[i];       else         sb += w[i];     }     f[0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         int a = sa + j, b = sb - (i - j);         long long fm = inv(a + b);         add(f[i + 1][j + 1], f[i][j] * a % mod * fm % mod);         add(f[i + 1][j], f[i][j] * b % mod * fm % mod);       }     }     long long ea = 0, eb = 0;     for (int i = 0; i <= m; i++) {       ;       add(ea, f[m][i] * (sa + i) % mod);       add(eb, f[m][i] * (sb - (m - i)) % mod);     };     long long iva = inv(sa), ivb = inv(sb);     for (int i = 1; i <= n; i++) {       if (a[i]) {         printf( %lld n , 1ll * w[i] * iva % mod * ea % mod);       } else {         printf( %lld n , 1ll * w[i] * ivb % mod * eb % mod);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double a[(1000000)], x[(1000000)];   long double b[(1000000)], y[(1000000)];   int n, A, B;   long double ans;   const long double inf = 3e9;   bool check(double t) {     int k = B;     long double cnt = inf * inf;     for (int i = A; i > 0; i--) {       while (k && y[k] >= x[i]) {         cnt = min(cnt, y[k] + t * b[k]);         k--;       }       if (x[i] + t * a[i] >= cnt) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       double P, V;       scanf( %lf%lf , &P, &V);       if (V < 0.) {         B++;         y[B] = P;         b[B] = V;       } else {         A++;         x[A] = P;         a[A] = V;       }     }     double l = 0., r = inf;     ans = -1;     for (int T = 0; T < 100; T++) {       double mid = (l + r) / 2.;       if (check(mid)) {         ans = mid;         r = mid;       } else         l = mid;     }     if (ans < 0.)       puts( -1 );     else {       cout.precision(10);       cout << fixed;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int n, a[maxn];   long long k;   long long f[maxn];   int main() {     scanf( %d %I64d , &n, &k);     f[0] = f[1] = 1;     for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2];     for (int i = 1; i <= n;) {       if (f[n - i] >= k) {         a[i] = i;         i++;       } else {         k -= f[n - i];         a[i] = i + 1;         a[i + 1] = i;         i += 2;       }     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }


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


#include <bits/stdc++.h>   using namespace std;   bool marked[100000 + 2];   vector<int> prime;   int ase[100000 + 2], num[100000 + 2];   bool isPrime(int n) {     if (n < 2) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     return marked[n] == false;   }   void sieve(int n) {     for (int i = 3; i * i <= n; i += 2) {       if (marked[i] == false) {         for (int j = i * i; j <= n; j += i + i) {           marked[j] = true;         }       }     }     prime.push_back(2);     for (int i = 3; i <= n; i += 2) {       if (!marked[i]) {         prime.push_back(i);       }     }   }   vector<pair<int, int> > ans;   void correct(int x) {     if (num[x] == x) {       return;     }     int j = ase[x];     int k = j - *(upper_bound(prime.begin(), prime.end(), j - x + 1) - 1) + 1;     int a;     a = num[j], num[j] = num[k], num[k] = a;     ase[num[k]] = k, ase[num[j]] = j;     ans.push_back(pair<int, int>(k, j));     correct(x);   }   int main(int argc, char** argv) {     sieve(100000);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       ase[num[i]] = i;     }     getchar();     for (int i = 1; i <= n; i++) {       correct(i);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int calc(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       n /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     long long x = calc(2, n);     cout << x * (x + 1) / 2 % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2 * 1e9;   const double EPS = 1e-9;   const int MaxN = 100000 + 5;   const int MaxM = 2 * 100000 + 5;   int N, M, S, L, Dist[MaxN];   typedef struct Node {     int idx;     Node(void) {}     Node(int _idx) { idx = _idx; }     inline bool operator<(const Node &NewNode) const {       return Dist[idx] > Dist[NewNode.idx];     }   };   typedef struct Edge {     int idx, Weight;     Edge(void) {}     Edge(int _idx, int _Weight) {       idx = _idx;       Weight = _Weight;     }   };   vector<Edge> E[MaxM];   inline void Dijkstra(int Start) {     for (int i = 0; i < N; i++) Dist[i] = INF;     priority_queue<Node> PQ;     PQ.push(Node(Start));     Dist[Start] = 0;     while (!PQ.empty()) {       Node CurrNode = PQ.top();       PQ.pop();       for (vector<Edge>::iterator it = E[CurrNode.idx].begin();            it != E[CurrNode.idx].end(); it++) {         Node NextNode = Node((*it).idx);         int Weight = (*it).Weight;         if (Dist[CurrNode.idx] + Weight < Dist[NextNode.idx]) {           Dist[NextNode.idx] = Dist[CurrNode.idx] + Weight;           PQ.push(NextNode);         }       }     }   }   vector<pair<pair<int, int>, int> > Edges;   int main(void) {     scanf( %d %d %d , &N, &M, &S);     S--;     for (int i = 0; i < M; i++) {       int idx, idy, Weight;       scanf( %d %d %d , &idx, &idy, &Weight);       idx--;       idy--;       E[idx].push_back(Edge(idy, Weight));       E[idy].push_back(Edge(idx, Weight));       Edges.push_back(make_pair(make_pair(idx, idy), Weight));     }     scanf( %d , &L);     Dijkstra(S);     int Sol = 0;     for (int i = 0; i < N; i++)       if (Dist[i] == L) Sol++;     for (int i = 0; i < M; i++) {       int idx = Edges[i].first.first, idy = Edges[i].first.second,           Weight = Edges[i].second;       int Pos1 = -1, Pos2 = -1;       if ((Dist[idx] < L) && (L < Dist[idx] + Weight) &&           (L <= Dist[idy] + Dist[idx] + Weight - L))         Pos1 = L - Dist[idx];       if ((Dist[idy] < L) && (L < Dist[idy] + Weight) &&           (L <= Dist[idx] + Dist[idy] + Weight - L))         Pos2 = Dist[idy] + Weight - L;       if (Pos1 >= 0) Sol++;       if ((Pos2 >= 0) && (Pos2 != Pos1)) Sol++;     }     printf( %d n , Sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<char> s;     char a[100005];     s.insert( A );     s.insert( H );     s.insert( I );     s.insert( M );     s.insert( O );     s.insert( T );     s.insert( U );     s.insert( V );     s.insert( W );     s.insert( X );     s.insert( Y );     scanf( %s , &a);     int n = strlen(a);     for (int i = 0; i < n; i++) {       if (s.find(a[i]) == s.end() || a[i] != a[n - 1 - i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long power(long long a, long long b) {     long long x = 1;     a = a % 1000000007ULL;     while (b) {       if (b & 1) x = (x * a) % 1000000007ULL;       a = (a * a) % 1000000007ULL;       b >>= 1;     }     return x;   }   inline long long inv(long long a) { return power(a, 1000000007ULL - 2); }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   const int N = 1e5 + 5;   string s;   vector<int> v[12];   int n;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) {       v[s[i] -  0 ].push_back(i);     }     if (n < 2) {       cout <<  -1 n ;       return 0;     }     if (n == 2) {       if (v[0].size() > 0 && v[5].size() > 0) {         if (s[0] ==  5 )           cout <<  0 n ;         else           cout <<  1 n ;         return 0;       }       if (v[2].size() > 0 && v[5].size() > 0) {         if (s[0] ==  2 )           cout <<  0 n ;         else           cout <<  1 n ;         return 0;       }       if (v[7].size() > 0 && v[5].size() > 0) {         if (s[0] ==  7 )           cout <<  0 n ;         else           cout <<  1 n ;         return 0;       }       cout <<  -1 n ;       return 0;     }     int ans = 10000;     if (v[0].size() > 1) {       int x = v[0].size();       ans = min(ans, abs(n - 1 - v[0][x - 1]) + abs(n - 2 - v[0][x - 2]));     }     if (v[2].size() > 0 && v[5].size() > 0) {       int x = v[2].size();       int y = v[5].size();       x = v[2][x - 1];       y = v[5][y - 1];       if (n != 3 || v[0].size() == 0) {         int tmp = 0;         string sss = s;         for (int i = y; i < n - 1; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 1] =  5 ;         for (int j = n - 2; j > -1; j--) {           if (sss[j] ==  2 ) {             x = j;             break;           }         }         for (int i = x; i < n - 2; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 2] =  2 ;         if (sss[0] ==  0 ) {           for (int j = 0; j < n; j++) {             if (sss[j] ==  0 ) tmp++;           }         }         ans = min(tmp, ans);       }     }     if (v[7].size() > 0 && v[5].size() > 0) {       int x = v[7].size();       int y = v[5].size();       x = v[7][x - 1];       y = v[5][y - 1];       if (n != 3 || v[0].size() == 0) {         int tmp = 0;         string sss = s;         for (int i = y; i < n - 1; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 1] =  5 ;         for (int j = n - 2; j > -1; j--) {           if (sss[j] ==  7 ) {             x = j;             break;           }         }         for (int i = x; i < n - 2; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 2] =  7 ;         if (sss[0] ==  0 ) {           for (int j = 0; j < n; j++) {             if (sss[j] ==  0 ) tmp++;           }         }         ans = min(tmp, ans);       }     }     if (v[5].size() > 0 && v[0].size() > 0) {       int x = v[5].size();       int y = v[0].size();       x = v[5][x - 1];       y = v[0][y - 1];       if (n != 3 || v[0].size() == 1) {         int tmp = 0;         string sss = s;         for (int i = y; i < n - 1; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 1] =  0 ;         for (int j = n - 2; j > -1; j--) {           if (sss[j] ==  5 ) {             x = j;             break;           }         }         for (int i = x; i < n - 2; i++) {           sss[i] = sss[i + 1];           tmp++;         }         sss[n - 2] =  5 ;         if (sss[0] ==  0 ) {           for (int j = 0; j < n; j++) {             if (sss[j] ==  0 ) tmp++;           }         }         ans = min(tmp, ans);       }     }     if (ans == 10000) {       cout <<  -1 n ;       return 0;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[400050];   int ran[400050];   int find_set(int a) { return p[a] == a ? a : (p[a] = find_set(p[a])); }   int unite(int a, int b) {     int x = find_set(a);     int y = find_set(b);     if (x == y) return -1;     if (ran[x] < ran[y]) {       p[x] = y;     } else {       p[y] = x;       if (ran[x] == ran[y]) ran[x]++;     }     return 0;   }   pair<int, pair<int, int> > ed[400050];   int viz[200050];   int main() {     int n, m;     int s, t, ds, dt;     int di = 0, dii = 0;     int tes = 0;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       ed[i] = make_pair(0, make_pair(a, b));     }     scanf( %d %d %d %d , &s, &t, &ds, &dt);     for (int i = 0; i < m; i++) {       if ((ed[i].second.first == s && ed[i].second.second == t) ||           (ed[i].second.second == s && ed[i].second.first == t)) {         ed[i] = make_pair(2, make_pair(ed[i].second.first, ed[i].second.second));       } else if (ed[i].second.first == s || ed[i].second.second == s) {         ed[i] = make_pair(1, make_pair(ed[i].second.first, ed[i].second.second));         viz[ed[i].second.first] |= 1;         viz[ed[i].second.second] |= 1;       } else if (ed[i].second.first == t || ed[i].second.second == t) {         ed[i] = make_pair(1, make_pair(ed[i].second.first, ed[i].second.second));         viz[ed[i].second.first] |= 2;         viz[ed[i].second.second] |= 2;       }     }     sort(ed, ed + m);     for (int i = 0; i <= n; i++) {       p[i] = i;       ran[i] = 1;     }     int i;     for (i = 0; i < m; i++) {       if (ed[i].first) break;       if (find_set(ed[i].second.first) != find_set(ed[i].second.second)) {         tes++;         unite(ed[i].second.first, ed[i].second.second);         ed[i] = make_pair(-1, make_pair(ed[i].second.first, ed[i].second.second));       }     }     for (int j = i; j < m; j++) {       int q = (ed[j].second.first == s || ed[j].second.first == t)                   ? ed[j].second.second                   : ed[j].second.first;       if (ed[j].first == 2) break;       if (viz[q] == 3) continue;       if (find_set(ed[j].second.first) != find_set(ed[j].second.second)) {         if (ed[j].second.first == s || ed[j].second.second == s) {           if (di == ds) continue;           di++;         }         if (ed[j].second.first == t || ed[j].second.second == t) {           if (dii == dt) continue;           dii++;         }         tes++;         unite(ed[j].second.first, ed[j].second.second);         ed[j] = make_pair(-1, make_pair(ed[j].second.first, ed[j].second.second));       }     }     for (int j = i; j < m; j++) {       if (find_set(ed[j].second.first) != find_set(ed[j].second.second)) {         if (ed[j].second.first == s || ed[j].second.second == s) {           if (di == ds) continue;           di++;         }         if (ed[j].second.first == t || ed[j].second.second == t) {           if (dii == dt) continue;           dii++;         }         tes++;         unite(ed[j].second.first, ed[j].second.second);         ed[j] = make_pair(-1, make_pair(ed[j].second.first, ed[j].second.second));       }     }     if (tes != n - 1) {       printf( No n );     } else {       printf( Yes n );       for (int i = 0; i < m; i++) {         if (ed[i].first == -1)           printf( %d %d n , ed[i].second.first, ed[i].second.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t = 1, T;   void print2d(vector<vector<long long>> &v) {     for (long long i = 0; i < v.size(); i++) {       for (long long x : v[i]) {         cout << x <<    ;       }       cout <<   n ;     }   }   void print(vector<long long> &a) {     for (long long x : a) {       cout << x <<    ;     }     cout <<   n ;     return;   }   long long fun(long long x, long long y) { return x * x + y * y; }   void solve() {     long long n;     cin >> n;     vector<long long> a(n, 0);     vector<long long> freq(n + 1, 0);     long long x;     for (long long i = 0; i < n; i++) {       cin >> a[i];       freq[a[i]]++;     }     set<long long> v;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         v.insert(a[i] + a[j]);       }     }     long long ans = 0;     for (long long sum : v) {       long long i, j;       if (sum & 1) {         i = sum / 2;         j = i + 1;       } else         i = j = sum / 2;       long long rep = 0;       while (i >= 1 && j <= n) {         if (i == j) {           rep += freq[i] / 2;           i--;           j++;         } else {           rep += min(freq[i], freq[j]);           i--;           j++;         }       }       ans = max(ans, rep);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     T = t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int battle(std::string player1, std::string player2) {     if (player1 == player2) {       return 0;     }     if (player1 ==  rock ) {       if (player2 ==  scissors ) {         return 1;       } else {         return -1;       }     }     if (player1 ==  paper ) {       if (player2 ==  rock ) {         return 1;       } else {         return -1;       }     }     if (player1 ==  scissors ) {       if (player2 ==  paper ) {         return 1;       } else {         return -1;       }     }   }   int main(int argc, char const *argv[]) {     std::string fyodor, matroskin, sharic;     std::cin >> fyodor >> matroskin >> sharic;     std::string winner =  ? ;     if (battle(fyodor, matroskin) == 1) {       if (battle(fyodor, sharic) == 1) {         winner =  F ;       }     } else if (battle(fyodor, matroskin) == -1) {       if (battle(matroskin, sharic) == 1) {         winner =  M ;       }     } else {       if (battle(sharic, fyodor) == 1) {         winner =  S ;       }     }     std::cout << winner <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   void io() {}   long long fast_exp(long long base, int exp, int m) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) {         res = (res * base) % m;       }       base = (base * base) % m;       exp /= 2;     }     return res % m;   }   long long arr[200005];   long long val[200005];   long long siz[200005];   map<long long, long long> mp;   long long ans, cnt, tmp;   long long vis[200005];   vector<long long> adj[200005];   long long dp[2001][2001];   long long n, m, k;   int main() {     io();     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 0;     cin >> arr[0] >> arr[1] >> arr[2];     sort(arr, arr + 3);     if (arr[2] - arr[1] - arr[0] < 0) {       cout << 0 <<   n ;       return 0;     }     cout << arr[2] - arr[1] - arr[0] + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a, b;   vector<int> undiradj[100001];   vector<int> diradj[100001];   vector<int> dirjda[100001];   stack<int> s;   bool vis[100001];   vector<int> scc[100001];   bool isinscc[100001];   bool hascycle;   void dfs(int node) {     if (!vis[node]) {       vis[node] = true;       for (int i = 0; i < diradj[node].size(); i++) {         dfs(diradj[node][i]);       }       s.push(node);     }   }   void sfd(int node, int con) {     if (!vis[node]) {       vis[node] = true;       scc[con].push_back(node);       for (int i = 0; i < dirjda[node].size(); i++) {         sfd(dirjda[node][i], con);       }     }   }   int undirdfs(int node) {     if (!vis[node]) {       if (isinscc[node]) hascycle = true;       int cnt = 0;       vis[node] = true;       for (int i = 0; i < undiradj[node].size(); i++) {         cnt += undirdfs(undiradj[node][i]);       }       cnt++;       return cnt;     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       undiradj[a].push_back(b);       undiradj[b].push_back(a);       diradj[a].push_back(b);       dirjda[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);       }     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     int cc = 0;     while (!s.empty()) {       int curnode = s.top();       s.pop();       if (!vis[curnode]) {         sfd(curnode, cc);         if (scc[cc].size() > 1) {           for (int i = 0; i < scc[cc].size(); i++) {             isinscc[scc[cc][i]] = true;           }         }         cc++;       }     }     for (int i = 1; i <= n; i++) {       vis[i] = false;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         hascycle = false;         int v = undirdfs(i);         if (hascycle)           ans += v;         else           ans += (v - 1);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s =   ;     int r = 1;     while (s.size() < 1050) {       int k = r;       string t =   ;       while (k > 0) {         t = char((k % 10) +  0 ) + t;         k = k / 10;       }       s = s + t, r++;     }     cout << s[n - 1];     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     if (n == 1 || m == 1)       cout << max(n, m);     else if (m == 2 && n % 4)       cout << n + 2 - (n & 1);     else if (n == 2 && m % 4)       cout << m + 2 - (m & 1);     else       cout << (n * m) - ((n * m) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 998244353;   long long binpow(long long a, long long p) {     return p ? binpow(a * a % mod, p >> 1) * (p & 1 ? a : 1) % mod : 1;   }   long long bininv(long long a) { return binpow(a, mod - 2); }   set<int> solved;   map<long long, vector<long long> > mp;   vector<vector<long long> > C;   int k, kk;   long long m, invm;   long long fact[35000];   long long ifact[35000];   struct FFT {     int n;     vector<long long> w;     vector<long long> inv;     void set(int _n = (1 << 14)) {       n = _n;       inv.resize(n);       inv[0] = 0;       for (int i = 1, j = 0; i < n; i++) {         int bit = (n >> 1);         while (bit & j) {           j ^= bit;           bit >>= 1;         }         j ^= bit;         inv[i] = j;       }       w.resize(n);       long long step = binpow(3, (mod - 1) / n);       w[0] = 1;       for (int i = 1; i < n; i++) {         w[i] = w[i - 1] * step % mod;       }     }     void fft(vector<long long>& a) {       for (int i = 0; i < n; i++) {         if (i < inv[i]) {           swap(a[i], a[inv[i]]);         }       }       for (int len = 2; len <= n; len <<= 1) {         for (int i = 0; i < n; i += len) {           int i1 = i, i2 = i + (len >> 1);           int wind = 0, wstep = (n / len);           for (; i2 < i + len; i1++, i2++, wind += wstep) {             long long x = a[i1], y = a[i2] * w[wind] % mod;             a[i1] = (x + y) % mod;             a[i2] = (x - y + mod) % mod;           }         }       }     }     void ifft(vector<long long>& a) {       fft(a);       reverse(a.begin() + 1, a.end());       long long invn = binpow(n, mod - 2);       for (int i = 0; i < n; i++) {         a[i] = (a[i] * invn) % mod;       }     }     void do_calculation(vector<long long> a, vector<long long> b,                         vector<long long>& to) {       fft(a);       fft(b);       for (int i = 0; i < n; i++) {         to[i] = a[i] * b[i] % mod;       }       ifft(to);       for (int i = k + 1; i < n; i++) {         to[i] = 0;       }     }   } fft;   void prec() {     fact[0] = ifact[0] = 1;     for (int i = 1; i < 35000; i++) {       fact[i] = fact[i - 1] * i % mod;       ifact[i] = binpow(fact[i], mod - 2);     }   }   void calc(long long n) {     if (solved.count(n)) return;     if (n == 1) {       vector<long long> tmp(k + 1, invm);       tmp[0] = 1;       for (int i = 0; i < k + 1; i++) {         tmp[i] = tmp[i] * ifact[i] % mod;       }       while (tmp.size() < kk) {         tmp.push_back(0);       }       mp[1] = tmp;     } else if (n & 1) {       calc(n - 1);       mp[n] = vector<long long>(kk, 0);       fft.do_calculation(mp[1], mp[n - 1], mp[n]);       mp[n][0] = 1;     } else {       calc(n / 2);       mp[n] = vector<long long>(kk, 0);       fft.do_calculation(mp[n / 2], mp[n / 2], mp[n]);       mp[n][0] = 1;     }     solved.insert(n);   }   void solve(int test_ind) {     int st = clock();     prec();     long long n;     cin >> n >> m >> k;     kk = 1;     while (kk < k) {       kk <<= 1;     }     kk <<= 1;     fft.set(kk);     invm = bininv(m);     calc(n);     cout << mp[n][k] * fact[k] % mod << endl;   }   int main() {     int t = 1;     for (int i = 0; i < t; i++) {       solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long dsum(unsigned long long n) {     unsigned long long res = 0;     while (n) {       res += n % 10;       n /= 10;     }     return res;   }   int main() {     unsigned long long n, s;     cin >> n >> s;     unsigned long long dif = n - dsum(n);     if (dif < s)       cout << 0 << endl;     else {       unsigned long long l = 1, h = n;       while (h - l > 0) {         unsigned long long mid = l + (h - l) / 2;         unsigned long long x = dsum(mid);         dif = mid - x;         if (dif < s) {           l = mid + 1;         } else           h = mid;       }       if (n - dsum(l) >= s) l--;       cout << n - l << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   long long _gcd(long long x, long long y) { return (!y ? x : _gcd(y, x % y)); }   long long _lcm(long long x, long long y) { return x / _gcd(x, y) * y; }   int main() {     std::ios_base::sync_with_stdio(0);     long long n;     string s;     cin >> n >> s;     long long a = 0, b = 0, ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ) )         a++;       else         b++;     }     if (n % 2 || a != b) return cout << -1 <<   n , 0;     a = 0, b = 0;     int inx1 = 0, inx2 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ( ) {         a++;         inx1 = i;       } else {         b++;         inx2 = i;       }       if (a == b) {         if (inx2 < inx1) ans += a * 2;         a = 0;         b = 0;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   int main() {     char x[101], y[101], z[101];     int len;     scanf( %s%s , x, y);     len = strlen(x);     for (int i = 0; i < len; i++) {       z[i] = y[i];     }     int flag = 1;     for (int i = 0; i < len; i++) {       if (y[i] > x[i]) {         flag = 0;         printf( -1 n );         break;       }     }     if (flag == 1) printf( %s , y);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool cmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   const int _ = 2e5 + 55, __ = 5e5 + 55;   int N;   long long a[_], b[_];   char ans[__];   int n, cnt;   bool check() {     for (int i(1), I(N); i <= I; ++i)       if (b[i] <= 0) return 0;     return 1;   }   bool up() {     for (int i(1), I(N - 1); i <= I; ++i)       if (b[i + 1] <= b[i]) return 0;     return 1;   }   bool down() {     for (int i(1), I(N - 1); i <= I; ++i)       if (b[i] <= b[i + 1]) return 0;     return 1;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> N;     for (int i(1), I(N); i <= I; ++i) cin >> a[i];     for (int i(1), I(N); i <= I; ++i) cin >> b[i];     if (N == 1) return printf(a[1] == b[1] ?  SMALL n0 n  :  IMPOSSIBLE n ), 0;     if (N == 2) {       long long x(b[1]), y(b[2]), s(0);       while (x && y) {         if (y == a[1]) swap(x, y);         if (x == a[1] && y >= a[2] && (y - a[2]) % x == 0) {           s += (y - a[2]) / x, y = a[2];           break;         }         if (y == a[2]) swap(x, y);         if (x == a[2] && y >= a[1] && (y - a[1]) % x == 0) {           s += (y - a[1]) / x, y = a[1], swap(x, y);           break;         }         if (x > y) swap(x, y);         s += y / x, y %= x;       }       if (x != a[1] || y != a[2])         return printf( IMPOSSIBLE n ), 0;       else if (s > 2e5)         return printf( BIG n%lld n , s), 0;     }     while (check()) {       int flg = 1;       for (int i(1), I(N); i <= I; ++i)         if (a[i] != b[i]) {           flg = 0;           break;         }       if (!flg) {         flg = 2;         for (int i(1), I(N); i <= I; ++i)           if (a[i] != b[N - i + 1]) {             flg = 0;             break;           }       }       if (flg) {         if (flg == 2 && cnt <= 2e5) ans[++n] =  R ;         if (cnt <= 2e5) {           printf( SMALL n%d n , n);           for (int i(n), I(1); i >= I; --i) putchar(ans[i]);           putchar(  n );         } else           printf( BIG n%d n , cnt);         return 0;       } else if (up()) {         ++cnt;         if (cnt <= 2e5) ans[++n] =  P ;         for (int i(N), I(2); i >= I; --i) b[i] -= b[i - 1];       } else if (down()) {         ++cnt;         if (cnt <= 2e5) ans[++n] =  R , ans[++n] =  P ;         reverse(b + 1, b + N + 1);         for (int i(N), I(2); i >= I; --i) b[i] -= b[i - 1];       } else         break;     }     printf( IMPOSSIBLE n );     return 0;   }


#include <bits/stdc++.h>   template <typename T>   class IntegerIterator       : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {    public:     explicit IntegerIterator(int value) : value(value) {}     IntegerIterator& operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator& operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) {}     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {    public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) {}     std::reverse_iterator<IntegerIterator<T>> begin() const {       return std::reverse_iterator<IntegerIterator<T>>(           IntegerIterator<T>(begin_));     }     std::reverse_iterator<IntegerIterator<T>> end() const {       return std::reverse_iterator<IntegerIterator<T>>(IntegerIterator<T>(end_));     }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     ;     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     ;     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     ;     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     ;     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     ;     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     ;     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     ;     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     ;     return ReversedIntegerRange<T>(from + 1, to);   }   template <typename R>   void sort(R& range) {     std::sort(range.begin(), range.end());   }   template <typename R, typename Comp>   void sort(R& range, Comp comp) {     std::sort(range.begin(), range.end(), comp);   }   template <typename R>   void reverse(R& range) {     std::reverse(range.begin(), range.end());   }   template <typename R, typename T>   auto lower_bound(const R& range, const T& value) -> decltype(range.begin()) {     return std::lower_bound(range.begin(), range.end(), value);   }   template <typename R, typename T, typename Comp>   auto lower_bound(const R& range, const T& value, Comp comp)       -> decltype(range.begin()) {     return std::lower_bound(range.begin(), range.end(), value, comp);   }   template <typename R, typename T>   auto upper_bound(const R& range, const T& value) -> decltype(range.begin()) {     return std::upper_bound(range.begin(), range.end(), value);   }   template <typename R, typename T, typename Comp>   auto upper_bound(const R& range, const T& value, Comp comp)       -> decltype(range.begin()) {     return std::upper_bound(range.begin(), range.end(), value, comp);   }   template <typename R>   auto min_element(const R& range) -> decltype(range.begin()) {     return std::min_element(range.begin(), range.end());   }   template <typename R>   auto max_element(const R& range) -> decltype(range.begin()) {     return std::max_element(range.begin(), range.end());   }   template <typename R>   bool next_permutation(R& range) {     return std::next_permutation(range.begin(), range.end());   }   template <typename T>   void unique(std::vector<T>& range) {     range.erase(std::unique(range.begin(), range.end()), range.end());   }   template <typename R>   R sorted(R range) {     sort(range);     return range;   }   template <typename R, typename Comp>   R sorted(R range, Comp comp) {     sort(range, comp);     return range;   }   template <typename R>   R reversed(R range) {     reverse(range);     return range;   }   template <typename T>   T gcd(T a, T b) {     while (b) {       T tmp = a % b;       a = b;       b = tmp;     }     return a;   }   using namespace std;   class TaskC {    public:     void solve(std::istream& in, std::ostream& out) {       int n;       in >> n;       vector<int> v(n);       for (int i : range(26)) {         in >> v[i];       }       auto x = solve(v);       out << x.first <<   n  << x.second;     }     pair<int, string> solve(vector<int> v) {       int cntOdd = 0;       char odd;       for (int i : range(v.size())) {         if (v[i] % 2 == 1) {           ++cntOdd;           odd =  a  + i;         }       }       if (cntOdd > 1) {         return {0, go(v)};       }       if (cntOdd == 1) {         int g = 0;         for (int i : range(v.size())) {           g = gcd(g, v[i]);         }         auto r = go(v, 2 * g);         r = r + odd + reversed(r);         string res;         for (int i = 0; i < g; ++i) {           res += r;         }         return {g, res};       }       int g = 0;       for (int i : range(v.size())) {         g = gcd(g, v[i]);       }       assert(g % 2 == 0);       string r = go(v, g);       r = r + reversed(r);       string res;       for (int i = 0; i < g / 2; ++i) {         res += r;       }       return {g, res};     }     string go(vector<int> v, int del = 1) {       string res;       for (int i : range(v.size())) {         res += string(v[i] / del, char( a  + i));       }       return res;     }   };   int main() {     std::ios_base::sync_with_stdio(false);     TaskC solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(0);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }


#include <iostream>   #include <cstdio>      using namespace std;      #define MAXN 200005      int t, n;   int a[MAXN];   int pre[MAXN], suf[MAXN];   bool pre_ok[MAXN], suf_ok[MAXN];   bool ans;   int main()   {       //freopen( CF#696D.in ,  r , stdin);       scanf( %d , &t);       while(t --)       {           ans = true;           scanf( %d , &n);           pre_ok[0] = suf_ok[n + 1] = true;           suf[n + 1] = 0;           for(int i = 1;i <= n;i ++) scanf( %d , a + i);              for(int i = 1;i < n;i ++)           {               pre[i] = a[i] - pre[i - 1];               pre_ok[i] = pre_ok[i - 1];               if(pre[i] < 0) {                   pre[i] = 0;                   pre_ok[i] = ans = false;               }           }           if(a[n] != pre[n - 1]) pre_ok[n] = ans = false;           for(int i = n;i > 1;i --)           {               suf[i] = a[i] - suf[i + 1];               suf_ok[i] = suf_ok[i + 1];               if(suf[i] < 0) {                   suf[i] = 0;                   suf_ok[i] = ans = false;               }           }           if(a[1] != suf[2]) suf_ok[1] = ans = false;           for(int i = 1;i < n;i ++)           {               if(pre_ok[i - 1] && suf_ok[i + 2] && a[i + 1] - pre[i - 1] >= 0 && a[i] - suf[i + 2] == a[i + 1] - pre[i - 1]) ans = true;           }           if(ans) printf( YES n );           else printf( NO n );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c, v, m, l, a, i = 1, x;     cin >> c >> v >> m >> a >> l;     x = v;     while (x < c) x += min(v + i * a - l, m - l), i++;     cout << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1005;   int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};   string toBinary(int x) {     string ret =   ;     while (x) {       ret = (x & 1 ?  1  :  0 ) + ret;       x >>= 1;     }     while (((int)(ret).size()) < 8) {       ret =  0  + ret;     }     return ret;   }   int toDec(string x) {     int ret = 0, val = 1;     for (int i = 7; i >= 0; --i) {       if (x[i] ==  1 ) ret += val;       val <<= 1;     }     return ret;   }   string second;   vector<int> s1;   int main() {     getline(cin, second);     s1.push_back(0);     for (int i = 0; i < (((int)(second).size()) - 1); ++i) {       string temp = toBinary(second[i]);       reverse(temp.begin(), temp.end());       s1.push_back(toDec(temp));     }     for (int i = 0; i < (((int)(second).size())); ++i) {       string temp = toBinary(second[i]);       reverse(temp.begin(), temp.end());       int res = toDec(temp);       printf( %d n , (s1[i] - res + 256) & 255);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5010;   int dp[maxn][maxn], sa[maxn], sb[maxn];   char a[maxn], b[maxn];   void gao(char *p, char *q, int n, int m) {     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (p[i] == q[j]) dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);   }   int main() {     scanf( %s%s , a + 1, b + 1);     int n = strlen(a + 1), m = strlen(b + 1);     gao(a, a, n, n);     for (int i = 1; i <= n; ++i) sa[i] = 1;     for (int i = 1; i <= m; ++i) sb[i] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (i != j) sa[i] = max(sa[i], dp[i][j] + 1);     gao(b, b, m, m);     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= m; ++j)         if (i != j) sb[i] = max(sb[i], dp[i][j] + 1);     gao(a, b, n, m);     int ans = -1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (dp[i][j] >= sa[i] && dp[i][j] >= sb[j])           if (max(sa[i], sb[j]) != 0 && (ans < 0 || ans > max(sa[i], sb[j])))             ans = max(sa[i], sb[j]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, V[171];   void cauta(int p) {     vector<pair<int, int> > Queries;     int res, st = 2, dr = n;     for (int m = dr; m >= st; --m) {       cout <<  ?  ;       for (int i = 1; i <= n; ++i) {         if (i != p)           cout <<  1  ;         else           cout << n - m + 2 <<    ;       }       cout <<   n ;       cout.flush();       cin >> res;       if (res == 0) {         V[p] = m;       } else {         if (V[res]) {           V[p] = V[res] - 1 + m - n;         } else if (res != p)           Queries.push_back({res, n - m + 1});       }     }     if (!V[p]) V[p] = 1;     for (auto it : Queries) V[it.first] = it.second + V[p];   }   int gaseste(int dif) {     cout <<  ?  ;     for (int i = 1; i < n; ++i) {       if (dif > 0)         cout <<  1  ;       else         cout << -dif + 1 <<    ;     }     if (dif > 0)       cout << dif + 1 <<   n ;     else       cout <<  1 n ;     cout.flush();     int rep = 0;     cin >> rep;     return rep;   }   void solve() {     cin >> n;     int v, st = 0, dr = 0;     for (int i = -n + 1; i < n; ++i) {       if (!i) continue;       v = gaseste(i);       V[v] = i;       if (!v) {         if (i > 0 && !dr) dr = i;       }       if (v && i < 0 && !st) st = -i;     }     V[n] = st + 1;     for (int i = 1; i < n; ++i) V[i] += V[n];     cout <<  !  ;     for (int i = 1; i <= n; ++i) {       cout << V[i] <<    ;       V[i] = 0;     }     cout <<   n ;     cout.flush();   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int te = 1;     while (te--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 7;   const int maxa = 1e5 + 7;   int dp[maxn][maxn];   int num[maxn], n;   int get_ans() {     memset(dp, 0, sizeof(dp));     int max_mod[7], max_num[maxa];     memset(max_mod, 0, sizeof(max_mod));     memset(max_num, 0, sizeof(max_num));     int ans = 0;     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= n; ++j) {         if (i == j) continue;         if (j < i) {           dp[i][j] = dp[j][i];           max_mod[num[j] % 7] = max(max_mod[num[j] % 7], dp[i][j]);           if (j != 0) max_num[num[j]] = max(max_num[num[j]], dp[i][j]);         } else {           dp[i][j] = dp[i][0] + 1;           dp[i][j] = max(max_mod[num[j] % 7] + 1, dp[i][j]);           dp[i][j] = max(max_num[num[j] + 1] + 1, dp[i][j]);           dp[i][j] = max(max_num[num[j] - 1] + 1, dp[i][j]);           max_mod[num[j] % 7] = max(max_mod[num[j] % 7], dp[i][j]);           max_num[num[j]] = max(max_num[num[j]], dp[i][j]);         }         if (i != 0 && j != 0) ans = max(ans, dp[i][j]);       }       memset(max_mod, 0, sizeof(max_mod));       for (int j = 1; j <= n; ++j) {         max_num[num[j]] = 0;       }     }     return ans;   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; ++i) {         scanf( %d , num + i);       }       int ans = get_ans();       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(fast - math)   using namespace std;   long long powmod(long long a, long long b, long long mod) {     if (b == 0 || a == 1) {       if (mod == 1)         return 0;       else         return 1;     }     if (b % 2 == 0) {       long long k = powmod(a, b / 2, mod);       return (k * k) % mod;     } else {       long long k = powmod(a, b / 2, mod);       return ((k * k) % mod * a) % mod;     }   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b)       return gcd(a % b, b);     else       return gcd(b % a, a);   }   int prime(int p) {     for (int i = 2; i * i <= p; i++) {       if (p % i == 0 && i < p) return i;     }     return 1;   }   long long sqr(long long i) { return i * i; }   void r(long long &a) { cin >> a; }   void r(long double &a) { cin >> a; }   void r(long long &a, long long &b) { cin >> a >> b; }   void r(long double &a, long double &b) { cin >> a >> b; }   void r(long long &a, long long &b, long long &c) { cin >> a >> b >> c; }   void r(long double &a, long double &b, long double &c) { cin >> a >> b >> c; }   void r(long long &a, long long &b, long long &c, long long &d) {     cin >> a >> b >> c >> d;   }   void r(long double &a, long double &b, long double &c, long double &d) {     cin >> a >> b >> c >> d;   }   void r(long long &a, long long &b, long long &c, long long &d, long long &e) {     cin >> a >> b >> c >> d >> e;   }   void r(long double &a, long double &b, long double &c, long double &d,          long double &e) {     cin >> a >> b >> c >> d >> e;   }   void r(long long &a, long long &b, long long &c, long long &d, long long &e,          long long &f) {     cin >> a >> b >> c >> d >> e >> f;   }   void r(long double &a, long double &b, long double &c, long double &d,          long double &e, long double &f) {     cin >> a >> b >> c >> d >> e >> f;   }   void r(vector<long long> &a) {     for (long long i = 0; i < a.size(); i++) r(a[i]);   }   void r(vector<vector<long long>> &a) {     for (long long i = 0; i < a.size(); i++) r(a[i]);   }   void w(long long a) { cout << a <<   n ; }   void w(int a) { cout << a <<   n ; }   void w(long double a) { cout << a <<   n ; }   void w(char a) { cout << a; }   void w(long long a, long long b) { cout << a <<     << b <<   n ; }   void w(long double a, long double b) { cout << a <<     << b <<   n ; }   void w(long long a, long long b, long long c) {     cout << a <<     << b <<     << c <<   n ;   }   void w(long double a, long double b, long double c) {     cout << a <<     << b <<     << c <<   n ;   }   void w(long long a, long long b, long long c, long long d) {     cout << a <<     << b <<     << c <<     << d <<   n ;   }   void w(long double a, long double b, long double c, long double d) {     cout << a <<     << b <<     << c <<     << d <<   n ;   }   void w(vector<long long> a) {     for (long long i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   void w(vector<vector<long long>> a) {     for (long long i = 0; i < a.size(); i++) w(a[i]);     cout <<   n ;   }   void r(pair<long long, long long> &a) { cin >> a.first >> a.second; }   void w(pair<long long, long long> a) {     cout << a.first <<     << a.second <<   n ;   }   void r(vector<pair<long long, long long>> &a) {     for (long long i = 0; i < a.size(); i++) r(a[i]);   }   void w(vector<pair<long long, long long>> a) {     for (long long i = 0; i < a.size(); i++) w(a[i]);     cout <<   n ;   }   void r(string &a) { cin >> a; }   void r(char &a) { cin >> a; }   void w(string a) { cout << a <<   n ; }   void sort(vector<long long> &a) { sort(a.begin(), a.end()); }   void sort(vector<pair<long long, long long>> &a) { sort(a.begin(), a.end()); }   void rev(vector<long long> &a) { reverse(a.begin(), a.end()); }   void rev(vector<pair<long long, long long>> &a) { reverse(a.begin(), a.end()); }   void rev(string &a) { reverse(a.begin(), a.end()); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   void solve(int ppppppppp = 1) {     long long n, k;     r(n, k);     long long pow1 = 1;     for (long long i = 0; i < k; i++) pow1 *= 10;     w(lcm(pow1, n));     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tututu;     tututu = 1;     for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1073741824;   const int M = INF;   const double RRR = 180.0 / PI;   vector<vector<pair<int, int> > > g;   vector<int> used;   void dfs(int v, int l, int r) {     used[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       if (g[v][i].second >= l && g[v][i].second <= r) {         continue;       }       int to = g[v][i].first;       if (!used[to]) {         dfs(to, l, r);       }     }   }   int main() {     double TIME_START = clock();     int n, m;     cin >> n >> m;     used.resize(n);     g.resize(n);     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       g[a].push_back(make_pair(b, i));       g[b].push_back(make_pair(a, i));     }     int k;     cin >> k;     int l, r;     for (int i = 0; i < k; i++) {       cin >> l >> r;       l--;       r--;       int col = 0;       used.assign(n, 0);       for (int i = 0; i < n; i++) {         if (!used[i]) {           col++;           dfs(i, l, r);         }       }       cout << col << endl;     }     fprintf(stderr,   n n%.15lf n n ,             (double)(clock() - TIME_START) / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   #pragma g++ opitmize(3)   #pragma g++ opitmize(2)   #pragma g++ opitmize( fast )   #pragma g++ opitmize( inline )   using namespace std;   int n, m, head[400010], k = -1, vis[400010], h[400010], tot = 1;   long long a[400010], f[400010], f1;   struct node {     int to, nt, fg;   } edge[1000010];   inline void add(int u, int v, int fg) {     edge[++k].nt = head[u];     head[u] = k;     edge[k].to = v;     edge[k].fg = fg;   }   inline long long fr_dfs(int u, int fa) {     long long tmp = 0, t = 0;     vis[u] = 1;     for (register int i = head[u]; ~i; i = edge[i].nt) {       int v = edge[i].to;       if (v == fa) continue;       if (vis[v]) continue;       tmp = fr_dfs(v, u);       t += tmp;       f[(i / 2) + 1] += tmp * edge[i ^ 1].fg;     }     if (a[u] < 0) {       long long hhd = a[u];       a[u] = 0;       return t + hhd;     }     return t;   }   inline void sc_dfs(int u, int fa, long long &flow) {     if (a[u] > 0) {       flow += a[u];       a[u] = 0;     }     vis[u] = 1;     for (register int i = head[u]; ~i; i = edge[i].nt) {       int v = edge[i].to;       if (v == fa || vis[v]) continue;       f[(i / 2) + 1] += (flow * edge[i].fg);       sc_dfs(v, u, flow);       f[(i / 2) + 1] += (flow * edge[i ^ 1].fg);     }   }   int main() {     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (register int i = 1; i <= n; i++) scanf( %lld , &a[i]), f1 += a[i];     int u, v;     scanf( %d , &m);     for (register int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       add(u, v, -1);       add(v, u, 1);     }     if (f1 != 0) {       printf( Impossible n );       return 0;     }     memset(vis, 0, sizeof(vis));     a[1] += fr_dfs(1, 0);     h[1] = 1;     for (register int i = 1; i <= n; i++) {       if (!vis[i]) {         a[i] += fr_dfs(i, 0);         h[++tot] = i;       }     }     memset(vis, 0, sizeof(vis));     for (register int i = 1; i <= tot; i++) {       sc_dfs(h[i], 0, a[h[i]]);     }     for (register int i = 1; i <= n; i++) {       if (a[i]) {         printf( Impossible n );         return 0;       }     }     printf( Possible n );     for (register int i = 1; i <= m; i++) printf( %lld n , f[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   int n, k;   int v[MAXN], c[MAXN], a[MAXN];   double f[MAXN];   int rv[MAXN][20], rc[MAXN][20];   inline int GetV(int l, int r) {     int x = log2(r - l + 1);     return max(rv[l][x], rv[r + 1 - (1 << x)][x]);   }   inline int GetC(int l, int r) {     int x = log2(r - l + 1);     return min(rc[l][x], rc[r + 1 - (1 << x)][x]);   }   inline int Cal(int pos) {     if (100 * v[pos] > c[pos]) return c[pos];     int left = pos, right = n, t;     while (left <= right) {       int mid = (left + right) >> 1;       if (GetV(pos, mid) * 100 <= GetC(pos, mid)) {         t = mid;         left = mid + 1;       } else         right = mid - 1;     }     int ans = GetV(pos, t) * 100;     if (t < n) ans = max(ans, GetC(pos, t + 1));     return ans;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &v[i]);     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);     for (int i = 1; i <= n; ++i) rv[i][0] = v[i], rc[i][0] = c[i];     int lgn = log2(n);     for (int j = 1; j <= lgn; ++j) {       int last = n + 1 - (1 << j);       for (int i = 1; i <= last; ++i) {         rv[i][j] = max(rv[i][j - 1], rv[i + (1 << (j - 1))][j - 1]);         rc[i][j] = min(rc[i][j - 1], rc[i + (1 << (j - 1))][j - 1]);       }     }     for (int i = 1; i <= n; ++i) a[i] = Cal(i);     f[0] = 1.0 * k / (n - k + 1);     for (int i = 1; i <= n - k + 1; ++i)       f[i] = f[i - 1] * (n - i - k + 2) / (n - i + 1);     sort(a + 1, a + n + 1);     double ans = 0;     for (int i = 1; i <= n - k + 1; ++i) ans += a[i] * f[i];     cout << fixed << setprecision(9) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30);   int dp[110][700][40], g[35][35];   string s;   int solve(int p, int k, int q) {     if (p < 0 && k >= 0) return 0;     if (p < 0 || k < 0) return -inf;     if (dp[p][k][q] != -1) return dp[p][k][q];     char ch = q +  a ;     int ans = -inf;     for (char curr =  a ; curr <=  z ; curr++) {       int dk = 0;       if (curr != s[p]) dk++;       int x = solve(p - 1, k - dk, curr -  a );       if (x == -inf) continue;       ans = max(ans, x + g[curr -  a ][q]);     }     return dp[p][k][q] = ans;   }   int main() {     fill(&dp[0][0][0], &dp[0][0][0] + 110 * 700 * 40, -1);     int k;     cin >> s >> k;     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string tmp;       char c1, c2;       int w;       cin >> c1 >> c2 >> w;       g[c1 -  a ][c2 -  a ] = w;     }     cout << solve(s.size() - 1, k, 30);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     vector<pair<int, int>> t(N), b(N);     for (int i = 0; i < N; i++)       cin >> b[i].first >> b[i].second >> t[i].first >> t[i].second;     multiset<int> tm[2], bm[2];     for (int i = 0; i < N; i++) {       tm[0].insert(t[i].first);       tm[1].insert(t[i].second);       bm[0].insert(-b[i].first);       bm[1].insert(-b[i].second);     }     for (int i = 0; i < N; i++) {       tm[0].erase(tm[0].find(t[i].first));       tm[1].erase(tm[1].find(t[i].second));       bm[0].erase(bm[0].find(-b[i].first));       bm[1].erase(bm[1].find(-b[i].second));       pair<int, int> tp = make_pair(*tm[0].begin(), *tm[1].begin());       pair<int, int> bp = make_pair(-*bm[0].begin(), -*bm[1].begin());       if (tp.first >= bp.first && tp.second >= bp.second) {         cout << tp.first <<     << tp.second << endl;         return 0;       }       tm[0].insert(t[i].first);       tm[1].insert(t[i].second);       bm[0].insert(-b[i].first);       bm[1].insert(-b[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long INF = 1e18;   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long nCr(long long n, long long r) {     long long res = 1;     if (n < r) return -1;     r = min(r, n - r);     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long nPr(long long n, long long r) {     long long res = 1;     if (n < r) return -1;     for (long long i = 0; i < r; i++) res *= (n - i);     return res;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     sort(b.begin(), b.end());     long long ans = INF;     for (long long i = 0; i < n; i++) {       long long x = (b[i] - a[0] + m) % m;       vector<long long> v(n);       for (long long j = 0; j < n; j++) v[j] = (a[j] + x) % m;       sort(v.begin(), v.end());       if (v == b) ans = min(ans, x);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 4;   long long fac[N], infac[N];   long long me(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return res;   }   long long mi(long long n) { return me(n, mod - 2); }   void factorial() {     fac[0] = 1;     for (long long i = 1; i < N; i++) fac[i] = (i * fac[i - 1]) % mod;     infac[N - 1] = mi(fac[N - 1]);     for (long long i = N - 1; i > 0; i--) infac[i - 1] = (i * infac[i]) % mod;   }   long long ncr(long long n, long long r) {     if (n < r) return 0;     long long res = fac[n];     res = (res * infac[r]) % mod;     res = (res * infac[n - r]) % mod;     return res;   }   int main() {     factorial();     long long n, m;     scanf( %lld , &n);     scanf( %lld , &m);     long long ans = me(m, n);     for (long long s = 1; s <= n; s++) {       long long val = me(m, s), temp = me(m - 1, n - s);       val = (val * temp) % mod;       val = (val * ncr(n, s - 1));       ans = (ans + val) % mod;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int maxn = 1e6 + 10;   struct Edge {     int to, nxt;     long long cost;     Edge() {}     Edge(int to, int nxt, long long cost) : to(to), nxt(nxt), cost(cost) {}   } edge[maxn << 1];   int head[maxn], tot;   long long dp[maxn];   void Init(int n) {     tot = 0;     for (int i = 1; i <= n; ++i) head[i] = -1;   }   void addedge(int u, int v, long long cost) {     edge[tot] = Edge(v, head[u], cost);     head[u] = tot++;     edge[tot] = Edge(u, head[v], cost);     head[v] = tot++;   }   int n;   long long val[maxn];   long long ans;   void DFS(int u, int pre) {     dp[u] = val[u];     long long max1 = 0, max2 = 0;     for (int i = head[u]; ~i; i = edge[i].nxt) {       int v = edge[i].to;       long long cost = edge[i].cost;       if (v == pre) continue;       DFS(v, u);       long long tmp = dp[v] - cost;       if (tmp > max1) swap(max1, tmp);       max2 = max(tmp, max2);       dp[u] = max(dp[u], dp[v] - cost + val[u]);     }     ans = max(ans, max(dp[u], max1 + max2 + val[u]));   }   void RUN() {     while (~scanf( %d , &n)) {       Init(n);       for (int i = 1; i <= n; ++i) scanf( %lld , val + i);       long long w;       for (int i = 1, u, v; i < n; ++i) {         scanf( %d %d %lld , &u, &v, &w);         addedge(u, v, w);       }       ans = 0;       DFS(1, -1);       printf( %lld n , ans);     }   }   int main() {     RUN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << 2 * n * n - 2 * n + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400000 + 1000;   struct node {     int l, r, dir;     long long w;   } temp;   vector<node> v;   long long vis[N];   bool cmp(node a, node b) {     if (a.l == b.l) return a.dir < b.dir;     return a.l < b.l;   }   int main() {     int n, x, i, l, w, r, time;     long long ans;     memset(vis, 0, sizeof(vis));     ans = 1e11;     scanf( %d%d , &n, &x);     for (i = 0; i < n; i++) {       scanf( %d%d%d , &l, &r, &w);       temp.w = w;       temp.l = l;       temp.r = r;       temp.dir = -1;       v.push_back(temp);       temp.l = r;       temp.r = l;       temp.dir = 1;       v.push_back(temp);     }     sort(v.begin(), v.end(), cmp);     for (i = 0; i < v.size(); i++) {       time = abs(v[i].r - v[i].l) + 1;       if (time >= x) continue;       if (v[i].dir == -1) {         if (vis[x - time] != 0) ans = min(ans, vis[x - time] + v[i].w);       } else {         if (!vis[time])           vis[time] = v[i].w;         else           vis[time] = min(vis[time], v[i].w);       }     }     if (ans == 1e11)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, k, u, v, c[200005] = {}, d[200005] = {}, z = 0;     vector<int> g[200005] = {};     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 0; i < m; i++)       cin >> u >> v, g[u].push_back(v), g[v].push_back(u);     for (int i = 1; i <= n; i++) {       if (d[i]) continue;       d[i] = 1;       queue<int> q;       vector<int> w = {i};       q.push(i);       while (!q.empty()) {         int x = q.front();         q.pop();         for (int j = 0; j < g[x].size(); j++) {           if (!d[g[x][j]]) d[g[x][j]] = 1, q.push(g[x][j]), w.push_back(g[x][j]);         }       }       unordered_map<int, int> p;       int o = 0;       for (int j = 0; j < w.size(); j++) p[c[w[j]]]++, o = max(o, p[c[w[j]]]);       z += w.size() - o;     }     cout << z;   }


#include <bits/stdc++.h>   using namespace std;   int p = 0, cnt = 0, cplus, cminus, val[10005], Child[10005];   pair<int, int> F[10005][105], FF[105];   string s;   vector<int> g[10005];   void DFS(int u) {     while (p < s.size()) {       p++;       if (s[p - 1] ==  ( ) {         g[u].push_back(++cnt);         DFS(cnt);       } else if ( 0  <= s[p - 1] && s[p - 1] <=  9 ) {         val[++cnt] = s[p - 1] -  0 ;         g[u].push_back(cnt);       } else if (s[p - 1] ==  ) )         break;     }   }   void FinalDFS(int u, int root) {     for (int i = 0; i <= 100; i++) F[u][i] = pair<int, int>(1e9, -1e9);     if (g[u].size() == 0) {       F[u][0] = pair<int, int>(val[u], val[u]);       return;     }     for (int i = 0; i < g[u].size(); i++)       if (g[u][i] != root) FinalDFS(g[u][i], u);     for (int i = 0; i <= 100; i++) F[u][i] = F[g[u][0]][i];     for (int i = 1; i < g[u].size(); i++) {       int v = g[u][i];       for (int j = 0; j <= 100; j++) FF[j] = pair<int, int>(1e9, -1e9);       for (int j = 0; j <= 100; j++)         for (int jj = 0; jj <= j; jj++) {           if (jj < j) {             if (cplus <= 100) {               FF[j].first =                   min(FF[j].first, F[u][j - jj - 1].first + F[v][jj].first);               FF[j].second =                   max(FF[j].second, F[u][j - jj - 1].second + F[v][jj].second);             } else {               FF[j].first =                   min(FF[j].first, F[u][j - jj - 1].first - F[v][jj].second);               FF[j].second =                   max(FF[j].second, F[u][j - jj - 1].second - F[v][jj].first);             }           }           if (cplus <= 100) {             FF[j].first = min(FF[j].first, F[u][j - jj].first - F[v][jj].second);             FF[j].second =                 max(FF[j].second, F[u][j - jj].second - F[v][jj].first);           } else {             FF[j].first = min(FF[j].first, F[u][j - jj].first + F[v][jj].first);             FF[j].second =                 max(FF[j].second, F[u][j - jj].second + F[v][jj].second);           }         }       for (int j = 0; j <= 100; j++) F[u][j] = FF[j];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> s >> cplus >> cminus;     DFS(0);     FinalDFS(1, 1);     if (cplus <= 100)       cout << F[1][cplus].second;     else       cout << F[1][cminus].second;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   vector<pair<char, int> > v;   map<int, int> mp1, mp2;   int arr[105][105];   int main() {     int x, y, z, n = 0, m = 0, c = 0, lo = 2, mn = 1e9, mx = 0;     char ch;     cin >> x >> y;     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         cin >> arr[i][j];       }     }     if (y > x) {       for (int i = 0; i < x; i++) {         for (int j = 0; j < y; j++) {           mn = min(mn, arr[i][j]);         }         if (mn != 0) {           for (int k = 0; k < y; k++) {             arr[i][k] -= mn;           }           while (mn--) {             v.push_back(make_pair( r , i + 1));           }         }         mn = 1e9;       }       mn = 1e9;       for (int i = 0; i < y; i++) {         mn = 1e9;         for (int j = 0; j < x; j++) {           mn = min(mn, arr[j][i]);         }         if (mn != 0) {           for (int k = 0; k < x; k++) {             arr[k][i] -= mn;           }           while (mn--) {             v.push_back(make_pair( c , i + 1));           }         }         mn = 1e9;       }     } else {       mn = 1e9;       for (int i = 0; i < y; i++) {         mn = 1e9;         for (int j = 0; j < x; j++) {           mn = min(mn, arr[j][i]);         }         if (mn != 0) {           for (int k = 0; k < x; k++) {             arr[k][i] -= mn;           }           while (mn--) {             v.push_back(make_pair( c , i + 1));           }         }         mn = 1e9;       }       for (int i = 0; i < x; i++) {         for (int j = 0; j < y; j++) {           mn = min(mn, arr[i][j]);         }         if (mn != 0) {           for (int k = 0; k < y; k++) {             arr[i][k] -= mn;           }           while (mn--) {             v.push_back(make_pair( r , i + 1));           }         }         mn = 1e9;       }     }     bool f = 0;     for (int i = 0; i < x; i++) {       for (int j = 0; j < y; j++) {         if (arr[i][j] != 0) {           f = 1;           i = x;           break;         }       }     }     if (f == 1) {       cout << -1 << endl;     } else {       cout << v.size() << endl;       for (int i = 0; i < v.size(); i++) {         if (v[i].first ==  r ) {           cout <<  row  ;         } else {           cout <<  col  ;         }         cout << v[i].second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[400001], b[400001];   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     unsigned n;     cin >> n;     for (unsigned i = 1; i <= n / 2; ++i) cin >> b[i];     a[1] = 0;     a[n] = b[1];     for (unsigned i = 2; i <= n / 2; ++i) {       if (b[i] - a[i - 1] <= a[n - i + 2]) {         a[i] = a[i - 1];         a[n - i + 1] = b[i] - a[i];       } else {         a[n - i + 1] = a[n - i + 2];         a[i] = b[i] - a[n - i + 1];       }     }     for (unsigned i = 1; i <= n; ++i) cout << a[i] <<    ;     return 0;   }