#include <bits/stdc++.h>   long long mod(long long x) {     if (x < 0) return -x;     return x;   }   long long expo(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y % 2 == 1) res = (res * x);       y = y >> 1;       x = x * x;     }     return res;   }   using namespace std;   const int MAXN = 500005;   vector<long long> v;   long long a[1000000], b[1000000];   int main() {     ios_base::sync_with_stdio(false);     long long n, t, m, k, x, y;     cin >> n;     string s;     cin >> s;     x = 0;     y = 0;     t = 0;     if (n % 2 != 0) {       cout <<  :( ;       return 0;     }     for (long long i = 0; i < n; i++) {       if (s[i] ==  ) ) {         y++;       }       if (s[i] ==  ( ) {         x++;       }     }     k = n / 2 - x;     for (long long i = 0; i < n; i++) {       if (s[i] ==  ? ) {         s[i] =  ( ;         k--;       }       if (k <= 0) break;     }     k = n / 2 - y;     for (long long i = 0; i < n; i++) {       if (s[i] ==  ? ) {         s[i] =  ) ;         k--;       }       if (k <= 0) break;     }     t = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  ) ) {         t--;       }       if (s[i] ==  ( ) {         t++;       }       if (t <= 0 && i != n - 1) {         cout <<  :( ;         return 0;       }       if (t < 0) {         cout <<  :( ;         return 0;       }     }     if (t != 0) {       cout <<  :( ;       return 0;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {0, 0, -1, 1};   const int dy[4] = {-1, 1, 0, 0};   int main() {     int i, j, k, n;     long int mx, mn, sm = 0;     int t;     cin >> t;     while (t--) {       int f = 0;       cin >> n;       vector<pair<int, int>> v(n);       for (i = 0; i < n; i++) {         int a, b;         cin >> a >> b;         v[i] = (make_pair(a, b));       }       if (v[0].first < v[0].second) f = 1;       for (i = 1; i < n; i++) {         int x = v[i].first - v[i - 1].first;         int y = v[i].second - v[i - 1].second;         if (x < 0 || y < 0 || (v[i].first < v[i].second) ||             (v[i - 1].first < v[i - 1].second) || y > x) {           f = 1;           break;         }       }       if (f)         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int maxm = 100005;   typedef int arr[maxn];   arr head, dfn, low, col, st;   int top, depth, color, tot, cnt;   pair<int, int> e[maxm * 2], bridge[maxn];   int euler[maxn * 2], d[maxn * 2][30], pos;   void add(int x, int y) {     e[tot] = make_pair(head[x], y);     head[x] = tot++;   }   void tarjan(int u, int f) {     dfn[u] = low[u] = ++depth;     st[++top] = u;     for (int i = head[u]; i != -1; i = e[i].first) {       int v = e[i].second;       if (v == f) continue;       if (!dfn[v]) {         tarjan(v, u);         low[u] = min(low[v], low[u]);       } else         low[u] = min(low[u], dfn[v]);       if (low[v] > dfn[u]) bridge[cnt++] = make_pair(u, v);     }     if (dfn[u] == low[u]) {       int x;       color++;       do {         col[x = st[top--]] = color;       } while (x != u);     }   }   void dfs(int u, int f) {     euler[++pos] = u;     low[u] = pos;     for (int i = head[u]; i != -1; i = e[i].first) {       int v = e[i].second;       if (v == f) continue;       dfn[v] = dfn[u] + 1;       dfs(v, u);       euler[++pos] = u;     }   }   void RMQ_init() {     for (int i = 1; i <= pos; i++) d[i][0] = i;     for (int j = 1; (1 << j) <= pos; j++) {       for (int i = 1; i + j - 1 <= pos; i++) {         if (dfn[euler[d[i][j - 1]]] < dfn[euler[d[i + (1 << (j - 1))][j - 1]]]) {           d[i][j] = d[i][j - 1];         } else           d[i][j] = d[i + (1 << (j - 1))][j - 1];       }     }   }   int RMQ(int L, int R) {     int k = 0;     if (L > R) swap(L, R);     while ((1 << (k + 1)) <= R - L + 1) k++;     return dfn[euler[d[L][k]]] < dfn[euler[d[R - (1 << k) + 1][k]]]                ? d[L][k]                : d[R - (1 << k) + 1][k];   }   int main() {     for (int n, m; scanf( %d%d , &n, &m) != EOF;) {       depth = color = tot = top = cnt = 0;       for (int i = 1; i <= n; i++) {         head[i] = -1, dfn[i] = 0;       }       for (int i = 1, x, y; i <= m; i++) {         scanf( %d%d , &x, &y);         add(x, y);         add(y, x);       }       tarjan(1, -1);       tot = 0;       for (int i = 0; i <= color; i++) {         head[i] = -1;         dfn[i] = 0;       }       for (int i = 0; i < cnt; i++) {         add(col[bridge[i].first], col[bridge[i].second]);         add(col[bridge[i].second], col[bridge[i].first]);       }       pos = 0;       dfn[1] = 0;       dfs(1, 0);       RMQ_init();       int Q;       scanf( %d , &Q);       for (int i = 1, x, y; i <= Q; i++) {         scanf( %d%d , &x, &y);         int ance = RMQ(low[col[x]], low[col[y]]);         ance = euler[ance];         printf( %d n , dfn[col[x]] + dfn[col[y]] - 2 * dfn[ance]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int zuo = 0, you = 0;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       zuo += x;       you += y;     }     printf( %d n , min(n - zuo, zuo) + min(n - you, you));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxk = 20;   const int maxn = 3e5 + 17;   int N, Q;   int sub[maxn], ans[maxn];   vector<int> graph[maxn];   set<pair<int, int> > DFS(int u) {     sub[u] = 1;     set<pair<int, int> > cur;     for (int v : graph[u]) {       set<pair<int, int> > next = DFS(v);       if (next.size() >= cur.size()) swap(cur, next);       for (auto x : next) cur.insert(x);       sub[u] += sub[v];     }     cur.insert({sub[u], u});     ans[u] = cur.lower_bound({sub[u] + 1 >> 1, 0})->second;     return cur;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> Q;     for (int i = 2; i <= N; i++) {       int x;       cin >> x;       graph[x].push_back(i);     }     DFS(1);     while (Q--) {       int x;       cin >> x;       cout << ans[x] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     int ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void rt(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       rt(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   const int maxn = 130;   int N;   double a[maxn][maxn], b[maxn][maxn], c[maxn][maxn], p[maxn];   void pow(int x) {     if (x == 1) {       for (int i = 0; i <= (int)N; i++)         for (int j = 0; j <= (int)N; j++) c[i][j] = a[i][j];       return;     }     pow(x >> 1);     memset(b, 0, sizeof b);     for (int k = 0; k <= (int)N; k++)       for (int i = 0; i <= (int)N; i++)         for (int j = 0; j <= (int)N; j++) b[i][j] += c[i][k] * c[k][j];     if (x & 1) {       memset(c, 0, sizeof c);       for (int k = 0; k <= (int)N; k++)         for (int i = 0; i <= (int)N; i++)           for (int j = 0; j <= (int)N; j++) c[i][j] += b[i][k] * a[k][j];     } else       memcpy(c, b, sizeof c);   }   int n, x;   int main() {     n = rd(), x = rd();     for (int i = 0; i <= (int)x; i++) scanf( %lf , &p[i]);     for (N = 1; N <= x; N <<= 1)       ;     N--;     for (int i = 0; i <= (int)N; i++)       for (int j = 0; j <= (int)x; j++) a[i][i ^ j] = p[j];     pow(n);     double ans = 0;     printf( %.8lf n , 1 - c[0][0]);   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   const long long inf = 1e18;   long long i, j, k, m, n, qq, t, it, ma = -inf, mi = inf, x, y, col,                                       md = 998244353;   string cmp(string second) {     vector<long long> p(second.size(), 0);     for (i = 1; i < second.size(); i++) {       j = p[i - 1];       while (j > 0 && second[i] != second[j]) j = p[j - 1];       if (second[i] == second[j]) j++;       p[i] = j;     }     return second.substr(0, j);   }   int32_t main() {     cin >> qq;     while (qq--) {       string second;       cin >> second;       n = second.size();       k = 0;       while (n - 1 - k >= 0 && k < n / 2 && second[k] == second[n - 1 - k]) k++;       if (k == (n + 1) / 2) {         cout << second <<   n ;         continue;       }       for (i = 0; i < k; i++) cout << second[i];       string t = second.substr(k, max(0ll, n - k - k));       string rt = t;       reverse(rt.begin(), rt.end());       string ans1 = cmp(t +  %  + rt);       string ans2 = cmp(rt +  %  + t);       if (ans1.size() > ans2.size())         cout << ans1;       else         cout << ans2;       for (i = k - 1; i > -1; i--) cout << second[i];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int rc = 0, uc = 0, c = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  R )         rc++;       else         uc++;       if (rc == uc && s[i] == s[i + 1]) c++;     }     cout << c <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI =       3.141592653589793238462643383279502884197169399375105820974944;   long long dist(long long a, long long b, long long c, long long d) {     return abs(a - c) + abs(b - d);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = 1000000000;     for (long long i = c - 1; i <= c + 1; i++) {       for (long long j = d - 1; j <= d + 1; j++) {         if (i != c or j != d) {           ans = min(ans, dist(a, b, i, j));         }       }     }     cout << 2 * ans + 8 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, tb[100], w1, w2, l = 1;   int main() {     scanf( %d , &n);     for (int i = 0; i < n / 2; i++) scanf( %d , &tb[i]);     sort(tb, tb + n / 2);     for (int i = 0; i < n / 2; i++) {       w1 += abs(tb[i] - l);       l += 2;     }     l = 2;     for (int i = 0; i < n / 2; i++) {       w2 += abs(tb[i] - l);       l += 2;     }     printf( %d , min(w1, w2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infl = 1LL << 60;   mt19937 rnd(time(0));   inline int myrand(int l, int r) { return rnd() % (r - l + 1) + l; }   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 , c = getchar();     }     return x * f;   }   const int maxn = 3e5 + 10;   vector<int> linker[maxn];   int n, m, q[maxn], dis[maxn], pre[maxn];   bool mark[maxn], vis[maxn];   vector<int> v;   void dfs(int x) {     vis[x] = 1, v.push_back(x);     for (int cur : linker[x])       if (!vis[cur]) dfs(cur);   }   void print() {     vector<int> ans(0);     int x = n;     while (x) ans.push_back(x), x = pre[x];     reverse(ans.begin(), ans.end());     for (int cur : ans) printf( %d  , cur);     puts(  );   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read();       linker[u].push_back(v);       linker[v].push_back(u);     }     int head = 1, tail = 0;     memset(dis, 0x3f, sizeof dis);     q[++tail] = 1, dis[1] = 0;     while (head <= tail) {       int x = q[head++];       for (int cur : linker[x])         if (dis[cur] == inf) dis[cur] = dis[x] + 1, q[++tail] = cur, pre[cur] = x;     }     if (dis[n] <= 4) return printf( %d n , dis[n]), print(), 0;     for (int cur : linker[1]) mark[cur] = 1;     mark[1] = 1;     for (int cur : linker[1]) {       for (int to : linker[cur])         if (!mark[to]) {           printf( %d n%d %d %d %d %d n , 4, 1, cur, to, 1, n);           return 0;         }     }     vis[1] = 1;     for (int x : linker[1])       if (!vis[x]) {         dfs(x);         for (int y : v) {           if (mark[y] && linker[y].size() - 1 < v.size() - 1) {             printf( %d n , min(dis[n], 5));             if (dis[n] < 5)               print();             else {               memset(mark, 0, sizeof mark);               for (int cur : linker[y]) mark[cur] = 1;               mark[y] = 1;               for (int cur : linker[y])                 if (cur != 1)                   for (int foo : linker[cur])                     if (!mark[foo]) {                       printf( %d %d %d %d %d %d n , 1, y, cur, foo, y, n);                       return 0;                     }             }             return 0;           }         }         v.clear();       }     if (dis[n] == inf)       return puts( -1 ), 0;     else {       printf( %d n , dis[n]);       print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double v = 1.41421356237;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       long long int x1, y1, z1, x2, y2, z2;       cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;       long long int m, sum = 0;       m = min(z1, y2);       sum += (2 * m);       m = min(x1, z2);       x1 -= m;       z2 -= m;       m = min(y1, x2);       y1 -= m;       x2 -= m;       sum -= (2 * min(y1, z2));       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50005;   const unsigned long long MOD = 1e8 + 7;   const unsigned long long MAX = 1e15;   int X[N], Y[N], T[N], K[N];   int n;   double P[N], dp[N], ans = 0;   bool cmp(int a, int b) { return T[a] < T[b]; }   double dist(int i, int j) {     double ans = sqrt((X[K[i]] - X[K[j]]) * (X[K[i]] - X[K[j]]) +                       (Y[K[i]] - Y[K[j]]) * (Y[K[i]] - Y[K[j]]));     return ans;   }   void work() {     for (int i = 1; i <= n; i++) {       dp[i] = P[K[i]];       for (int j = 1; j < i; j++)         if (dist(i, j) + T[K[j]] <= T[K[i]]) dp[i] = max(dp[j] + P[K[i]], dp[i]);       ans = max(ans, dp[i]);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%lf , &X[i], &Y[i], &T[i], &P[i]);       K[i] = i;     }     sort(K + 1, K + n + 1, cmp);     work();     printf( %.7f n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int n, t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> t;     while (t--) {       cin >> n;       long long int a[n], x = 0;       vector<long long int> ans;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (i == 0) {           ans.push_back(a[i]);           continue;         }         long long int last = ans[ans.size() - 1];         if ((a[i] > 0 && last < 0) || (last > 0 && a[i] < 0))           ans.push_back(a[i]);         else {           ans[ans.size() - 1] = max(last, a[i]);         }       }       long long int sum = 0;       for (int i = 0; i < ans.size(); i++) {         sum += ans[i];       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool bin(unsigned long long a, unsigned long long b) { return a > b; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     long inp;     queue<long> seg;     map<long, long> cnt;     set<long> once;     for (int y = 0; y < k; y++) {       scanf( %ld , &inp);       seg.push(inp);       cnt[inp]++;       if (cnt[inp] == 1)         once.insert(inp);       else if (cnt[inp] > 1)         once.erase(inp);     }     if (!once.empty())       printf( %ld n , (*once.rbegin()));     else       puts( Nothing );     for (int y = 0; y < n - k; y++) {       if (cnt[seg.front()] == 1) {         once.erase(seg.front());         cnt.erase(seg.front());       } else         cnt[seg.front()]--;       if (cnt[seg.front()] == 1) once.insert(seg.front());       seg.pop();       scanf( %ld , &inp);       seg.push(inp);       cnt[inp]++;       if (cnt[inp] == 1)         once.insert(inp);       else         once.erase(inp);       if (!once.empty())         printf( %ld n , (*once.rbegin()));       else         puts( Nothing );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, in[200005], a[200005], sta[200005], top, now, root, ans, flag;   bool vis[200005], mark[200005];   int read() {     int x, f = 1;     char ch;     while (!(isdigit(ch = getchar()))) ch ==  -  ? f = -1 : f;     x = ch - 48;     while ((isdigit(ch = getchar()))) x = x * 10 + ch - 48;     return f * x;   }   void Topology() {     while (now < top) {       now++;       int tmp = sta[now];       vis[tmp] = 1;       in[a[tmp]]--;       if (!in[a[tmp]]) sta[++top] = a[tmp];     }   }   void dfs(int u) {     vis[u] = 1;     if (!vis[a[u]]) dfs(a[u]);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       in[a[i]]++;       if (a[i] == i) {         flag = 1;         root = i;       }     }     for (int i = 1; i <= n; i++)       if (!in[i]) sta[++top] = i;     Topology();     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         if (!root) root = i;         ans++;         dfs(a[i]);         a[i] = root;         mark[i] = 1;       }     }     printf( %d n , ans - flag);     for (int i = 1; i <= n; i++) {       if (mark[i]) a[i] = root;       printf( %d  , a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int u[5005][10005];   int n, m, a[5005], b[5005] = {1}, c[5005] = {1}, d[5005] = {1}, e[5005];   int expmod(int a, int b, int mod) {     int res = 1;     for (; b; b >>= 1) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;     }     return res;   }   int dunc(int k, int e) {     if (k + e > n) return 0;     return 1ll * c[k + e - 1] * d[k - 1] % mod;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++)       scanf( %d , &a[i]), b[i] = expmod(a[i], mod - 2, mod);     for (int i = 1; i < n; i++) c[i] = 1ll * c[i - 1] * a[i] % mod;     for (int i = 1; i < n; i++) d[i] = 1ll * d[i - 1] * b[i] % mod;     int m = 2 * n - 2;     for (int i = 2; i <= n; i++) {       u[i][1] = 1;       for (int j = 2; j <= m; j++) {         u[i][j] = (u[i - 1][j - 1] +                    1ll * dunc(i - 1, j - 1) * (a[i - 1] - 1) % mod * b[i - 1]) %                   mod;       }     }     int ans;     for (int i = 1; i <= m; i++) {       ans = 0;       for (int j = 1; j <= n; j++) {         ans = (ans + 1ll * c[j - 1] * (u[j][i] + dunc(j, i))) % mod;       }       if (ans & 1)         printf( %d n , ans + mod >> 1);       else         printf( %d n , ans >> 1);     }   }


#include <bits/stdc++.h>   #include <sys/types.h>   #include <stdio.h>   #include <unistd.h>   #define _USE_MATH_DEFINES   #define ll long long int   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif   using namespace std;   //mp.reserve(1024);   //mp.max_load_factor(0.25);   void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}       template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   vector<ll> v(200001);   ll dp[200001];   ll cal(ll x, ll n){    if(x>=n)     return 0;    ll now = v[x];    if(dp[x]!=-1)     return dp[x];    ll val = now;    if(x+v[x]<n){     val += cal(x+v[x], n);    }    dp[x] = val;    return dp[x];       }   int main()   {    ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       //freopen( input.txt ,  r , stdin);       //freopen( output1.txt ,  w , stdout);    ll t;    cin>>t;    while(t--){     ll n, ans = INT_MIN;     cin>>n;     memset(dp, -1, sizeof dp);     for(ll i=0;i<n;i++){      cin>>v[i];     }     for(ll i=0;i<n;i++){      ans = max(ans ,cal(i, n));     }     cout<<ans<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err() { cout <<   n ; }   template <class T, class... Ts>   void err(const T& arg, const Ts&... args) {     cout << arg <<    ;     err(args...);   }   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   void run() {     int n = read();     long long sum = 0;     long long ans = 0;     while (n--) {       int a = read();       sum += a;       ans = ((ans) < (sum) ? (ans) : (sum));     }     cout << -ans <<   n ;   }   int main() {     int _T = read();     while (_T--) run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (3e5) + 10, mod = 1e9 + 7;   int n, a[maxn];   map<int, int> mark;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     int num = 0;     for (int i = 0; i < n; i++) {       if (a[i] > num) return cout << i + 1 << endl, 0;       if (a[i] == num) num++;     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[200005];   int main() {     string str;     cin >> str;     f[0] = 1;     for (int i = 1; i < str.length(); i++) {       if (str[i] == str[i - 1])         f[i] = f[i - 1] + 1;       else         f[i] = 1;     }     int last = 0, plast = 0;     cout << str[0];     for (int i = 1; i < str.length(); i++) {       if (f[i] == 1) {         cout << str[i];         plast = last;         last = i;       }       if (f[i] == 2 && f[plast] == 1) {         cout << str[i];         plast = last;         last = i;       }     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);   }   int main() {     FastIO();     int N;     int A[200][200];     cin >> N;     int Count = 0;     int Cars[1000] = {0};     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         cin >> A[i][j];         if (A[i][j] == 0) {           if (Cars[i + 1] == 0) Cars[i + 1] = 100;           if (Cars[j + 1] == 0) Cars[j + 1] = 100;         } else if (A[i][j] == 1) {           Cars[i + 1] = -100;         } else if (A[i][j] == 2)           Cars[j + 1] = -100;         else if (A[i][j] == 3) {           Cars[i + 1] = -100;           Cars[j + 1] = -100;         }       }     }     for (int i = 1; i <= N; i++) {       if (Cars[i] != -100) {         Count++;       }     }     cout << Count << endl;     for (int i = 1; i <= N; i++) {       if (Cars[i] != -100) cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int main() {     fastio();     long long int n;     cin >> n;     long long int ans = 0;     long long int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (long long int i = 0; i < n; i += 2) {       long long int sum = 0;       for (long long int j = i + 1; j < n; j += 2) {         long long int x = a[j] - sum;         if (x < 0) {         } else {           ans += min(a[i], x);           if (sum) ans++;         }         sum -= a[j];         if (sum < 0) {           if (abs(sum) > a[i])             break;           else {             a[i] += sum;             sum = 0;           }         }         if (j + 1 < n) sum += a[j + 1];       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = (ans * a) % 1000000007;       }       a = (a * a) % 1000000007;       b >>= 1;     }     return ans;   }   bool prime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long i = 0;     long long x = 1;     bool b = true;     vector<long long> v;     while (i < n) {       if (a[i] == x) {         v.push_back(2001 + i);         b = false;         x++;         i++;       } else         i++;     }     cout << v.size() << endl;     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 998244353;   long long int hmaxii = 0;   vector<long long int> values[2 * 100000 + 1];   long long int MAXN = 2 * 100000 + 1;   long long int spf[2 * 100000 + 1];   long long int diff, x, y, z;   long long int flag = 1;   long long int price[1001][1001];   long long int dp[2000][2000];   long long int ans = 0;   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int power(long long int a, long long int b) {     if (b == 0) {       return 1;     }     long long int temp = power(a, b / 2);     temp = temp * temp;   }   void solution() {     int n;     cin >> n;     int arr[n + 1];     int brr[n + 1];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       arr[x] = i;     }     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       brr[x] = i;     }     int answer = 0;     map<int, int> values;     for (int i = 1; i <= n; i++) {       values[(brr[i] - arr[i] + n) % n]++;       answer = max(answer, values[(brr[i] - arr[i] + n) % n]);     }     cout << answer << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       solution();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     while (cin >> n >> s) {       int ans = s;       for (int i = 0; i < n; ++i) {         int f, t;         cin >> f >> t;         if (ans < f + t) {           ans = f + t;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 4e18;   const long double pai = acos(-1);   int n, q, ans;   set<pair<pair<int, int>, int> > s;   int main() {     scanf( %d%d , &n, &q);     ans = n;     s.insert({{1, n}, 1});     while (q--) {       int l, r, x;       scanf( %d%d%d , &l, &r, &x), x--;       auto it = s.lower_bound({{l, -1}, -1});       if (it == s.end() || it->first.first > l) it--;       vector<pair<pair<int, int>, int> > add;       while (it != s.end()) {         int L = it->first.first, R = it->first.second, old = it->second;         if (L < l) add.push_back({{L, l - 1}, old});         if (R > r) add.push_back({{r + 1, R}, old});         it = s.erase(it);         ans -= (R - L + 1) * old;         if (it == s.end() || it->first.first > r) break;       }       for (auto u : add) {         int L = u.first.first, R = u.first.second, old = u.second;         ans += (R - L + 1) * old;         s.insert(u);       }       s.insert({{l, r}, x});       ans += (r - l + 1) * x;       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, l;     int ans[101];     int s = 0;     cin >> n >> d >> l;     for (int i = 0; i < n; ++i) {       ans[i] = (i & 1) ? -1 : 1;       s += ans[i];     }     bool sw = false;     while (true) {       if (s == d) break;       sw = false;       if (s < d) {         for (int i = 0; i < n; ++i) {           if (ans[i] < l and ans[i] > 0) {             ans[i]++;             s++;             sw = true;             break;           }         }       } else if (s > d) {         for (int i = 0; i < n; ++i) {           if (ans[i] < 0 and ans[i] > -l) {             ans[i]--;             s--;             sw = true;             break;           }         }       }       if (!sw) return cout << -1, 0;     }     for (int i = 0; i < n; ++i) cout << abs(ans[i]) <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fp(long long b, long long p) {     long long res = 1;     while (p) {       if (p % 2) res = (res * b) % 1000000007;       b = (b * b) % 1000000007;       p /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     if (k == -1 && n % 2 != m % 2)       return cout << 0, 0;     else       cout << fp(fp(2, (n - 1)), (m - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   char b_[N], n_[N];   long long mod, b, n;   int prime[N];   inline void get_phi() {     int x = mod;     int sx = sqrt(mod);     for (int i = 2; i <= sx; ++i) {       if (x == 1) break;       if (x % i) continue;       while (x % i == 0) x /= i;       prime[++prime[0]] = i;     }     if (!prime[0] || x != 1) prime[++prime[0]] = x;   }   inline long long gcd(long long a, long long b) {     return (b == 0 ? a : gcd(b, a % b));   }   inline long long power(long long a, long long p) {     long long ans = 1, base = a;     while (p) {       if (p & 1ll) (ans = ans * base) %= mod;       (base = base * base) %= mod;       p >>= 1ll;     }     return ans;   }   int main() {     scanf( %s%s , b_ + 1, n_ + 1);     scanf( %lld , &mod);     int len = strlen(b_ + 1);     b = 0ll;     for (register int i = 1; i <= len; ++i) {       (b = b * 10ll + b_[i] -  0 ) %= mod;     }     long long ans = (b - 1ll + mod) % mod;     get_phi();     long long phi = mod;     for (register int i = 1; i <= prime[0]; ++i)       phi = phi / prime[i] * (prime[i] - 1);     long long gcd_ = gcd(mod, b);     len = strlen(n_ + 1);     n = 0ll;     bool bigger = 0;     for (register int i = 1; i <= len; ++i) {       n = n * 10ll + n_[i] -  0 ;       if (n > phi) {         bigger = 1;         n %= phi;       }     }     if (gcd_ != 1)       (ans *= power(b, (n - 1 + phi) % phi + (bigger ? phi : 0ll)) % mod) %= mod;     else       (ans *= power(b, (n - 1 + phi) % phi) % mod) %= mod;     printf( %lld n , ((ans % mod) == 0 ? mod : ans % mod));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n, greater<int>());     deque<int> d;     d.push_front(arr[0]);     int i;     for (i = 1; i < n; i++) {       if (arr[i] != arr[0]) break;     }     while (i < n) {       int a = arr[i];       d.push_back(a);       if (arr[i] == arr[i + 1]) d.push_front(a);       for (; i < n; i++) {         if (arr[i] != a) break;       }     }     cout << d.size() << endl;     while (d.size() > 0) {       cout << d.front() <<    ;       d.pop_front();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxc = 22;   const int maxn = (int)5e5;   int tin[maxn], tout[maxn], _t = 0, ver[maxn], n;   vector<int> g[maxn];   int deep[maxn], maxh[1 << maxc];   unsigned mask[maxn];   int sz[maxn], ans[maxn];   unsigned char s[maxn];   int dfs_size(int v, unsigned m) {     mask[v] = m;     sz[v] = 1;     ver[tin[v] = _t++] = v;     for (auto u : g[v]) {       deep[u] = 1 + deep[v];       sz[v] += dfs_size(u, m ^ (1U << s[u]));     }     tout[v] = _t;     return sz[v];   }   const int INF = (int)1e9;   int calc(int u, int v) {     int res = maxh[mask[u]] + deep[u] - 2 * deep[v];     for (int i = 0; i < maxc; ++i) {       int m = mask[u] ^ (1U << i);       res = max(res, maxh[m] + deep[u] - 2 * deep[v]);     }     return res;   }   void dfs(int v, bool flag) {     int heavy = -1;     for (auto u : g[v])       if (heavy == -1 || sz[heavy] < sz[u]) heavy = u;     for (auto u : g[v])       if (heavy != u) {         dfs(u, 0);         ans[v] = max(ans[v], ans[u]);       }     if (heavy != -1) {       dfs(heavy, 1);       ans[v] = max(ans[v], ans[heavy]);     }     for (auto u : g[v])       if (u != heavy) {         for (int t = tin[u]; t < tout[u]; ++t)           ans[v] = max(ans[v], calc(ver[t], v));         for (int t = tin[u]; t < tout[u]; ++t)           maxh[mask[ver[t]]] = max(maxh[mask[ver[t]]], deep[ver[t]]);       }     ans[v] = max(ans[v], calc(v, v));     maxh[mask[v]] = max(maxh[mask[v]], deep[v]);     if (!flag)       for (int t = tin[v]; t < tout[v]; ++t) maxh[mask[ver[t]]] = -INF;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; ++i) {       int v;       cin >> v >> s[i];       g[v - 1].push_back(i);       s[i] -=  a ;     }     dfs_size(0, 0);     fill(maxh, maxh + (1 << maxc), -INF);     dfs(0, 1);     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   bool isSubSequence(string str1, string str2, int m, int n) {     if (m == 0) return true;     if (n == 0) return false;     if (str1[m - 1] == str2[n - 1])       return isSubSequence(str1, str2, m - 1, n - 1);     return isSubSequence(str1, str2, m, n - 1);   }   int main() {     fast();     long long int t = 1;     cin >> t;     while (t--) {       long long int n, p, k;       cin >> n >> p >> k;       vector<long long int> v;       long long int i, x;       for (i = 0; i < n; i++) {         cin >> x;         v.push_back(x);       }       sort(v.begin(), v.end());       long long int ans = 0;       long long int left = p;       vector<long long int> possible;       if (v[0] > left) {         cout << 0 << endl;       } else if (v[0] == left) {         if (n >= 2 && v[0] == v[1]) {           cout << 2 << endl;         } else {           cout << 1 << endl;         }       } else {         ans = 1;         left -= v[0];         vector<long long int> temp;         for (i = 2; i < n; i += 2) {           temp.push_back(v[i]);         }         if (temp.size() == 0) {           if (p >= v[1]) {             cout << 2 << endl;             continue;           } else {             cout << 1 << endl;             continue;           }         } else {           if (v[n - 1] == temp[temp.size() - 1]) {             for (i = 0; i < temp.size(); i++) {               if (left >= temp[i]) {                 left -= temp[i];                 ans += 2;               }             }             possible.push_back(ans);           } else {             for (i = 0; i < temp.size(); i++) {               if (left >= temp[i]) {                 left -= temp[i];                 ans += 2;               }             }             if (left >= v[n - 1]) {               ans += 1;             }             possible.push_back(ans);           }         }         ans = 0;         left = p;         for (i = 1; i < n; i += 2) {           if (left >= v[i]) {             ans += 2;             left -= v[i];           }         }         possible.push_back(ans);         sort(possible.begin(), possible.end());         cout << possible[possible.size() - 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int input() {     int res = 0;     char c =    ;     while (c <  0  && c !=  - ) c = getchar();     while (c >=  0 ) res = res * 10 + (c -  0 ), c = getchar();     return res;   }   const int N = 1e5 + 1;   string to_str(int x) {     string res;     while (x) res +=  0  + x % 10, x /= 10;     reverse(res.begin(), res.end());     return res;   }   string rc(string s) {     int i = 0, x = 0, y = 0;     for (; i < s.size(); ++i)       if (s[i] >=  0  && s[i] <=  9 )         break;       else         y = y * 26 + s[i] -  A  + 1;     for (; i < s.size(); ++i) x = x * 10 + (s[i] -  0 );     return { R  + to_str(x) +  C  + to_str(y)};   }   string aa(string s) {     int i = 1, x = 0, y = 0;     for (; s[i] !=  C ; ++i) x = x * 10 + (s[i] -  0 );     for (++i; i < s.size(); ++i) y = y * 10 + (s[i] -  0 );     string r;     while (y) r +=  A  + (y - 1) % 26, y = (y - 1) / 26;     reverse(r.begin(), r.end());     return r + to_str(x);   }   int main() {     for (int i = input(); i; --i) {       string s;       cin >> s;       bool f = false, RC = false;       for (auto i : s) {         if (i >=  A  && i <=  Z  && f)           RC = true;         else if (i >=  0  && i <=  9 )           f = true;       }       if (RC)         cout << aa(s) << endl;       else         cout << rc(s) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int T, n;   char Ls[400000 + 5], ps[400000 + 5];   long long ans;   long long read() {     long long x = 0, F = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) F = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * F;   }   struct AC_automaton {     int tr[400000 + 5][26], cnt;     int C_end[400000 + 5], fail[400000 + 5], Ans[400000 + 5], lst[400000 + 5];     void Clear() {       cnt = 0;       fail[0] = 0;       memset(tr[0], 0, sizeof(tr[0]));       memset(Ans, 0, sizeof(Ans));     }     void Insert(char *s, int id) {       int p = 0, len = strlen(s);       for (int i = 0; i < len; i++) {         int num = s[i] -  a ;         if (!tr[p][num]) {           tr[p][num] = ++cnt;           C_end[cnt] = 0;           memset(tr[cnt], 0, sizeof(tr[cnt]));           fail[cnt] = 0;         }         p = tr[p][num];       }       C_end[p]++;     }     void Build() {       queue<int> Q;       for (int i = 0; i < 26; i++)         if (tr[0][i]) Q.push(tr[0][i]);       while (!Q.empty()) {         int k = Q.front();         Q.pop();         for (int i = 0; i < 26; i++)           if (tr[k][i]) {             int nxt = tr[k][i];             fail[nxt] = tr[fail[k]][i];             Q.push(nxt);             lst[nxt] = C_end[fail[nxt]] ? fail[nxt] : lst[fail[nxt]];           } else             tr[k][i] = tr[fail[k]][i];       }     }     void Query(char *s) {       int p = 0;       int len = strlen(s);       for (int i = 0; i < len; i++) {         if (s[i] <  a  || s[i] >  z ) {           p = 0;           continue;         }         p = tr[p][s[i] -  a ];         for (int j = p; j; j = lst[j]) Ans[i] += C_end[j];       }     }   } ac, ac2;   int main() {     ac.Clear();     ac2.Clear();     scanf( %s , Ls);     n = read();     int L;     for (int i = 1; i <= n; i++) {       scanf( %s , ps);       ac.Insert(ps, i);       L = strlen(ps);       reverse(ps, ps + L);       ac2.Insert(ps, i);     }     int len = strlen(Ls);     ac.Build(), ac2.Build();     ac.Query(Ls);     reverse(Ls, Ls + len);     ac2.Query(Ls);     for (int i = 0; i < len - 1; i++)       ans += 1LL * ac.Ans[i] * ac2.Ans[len - i - 2];     printf( %lld , ans);   }


#include <bits/stdc++.h>   const int maxn = 5205;   using namespace std;   int n, a[maxn][maxn], m;   int cnt, sum[maxn][maxn], x[maxn];   bool check(int x) {     int now;     for (int i = x; i <= n; i += x) {       for (int j = x; j <= n; j += x) {         now = sum[i][j] - sum[i - x][j] - sum[i][j - x] + sum[i - x][j - x];         if (now == 0 || now == x * x)           continue;         else           return 0;       }     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n / 4; j++) {         scanf( %1x , &m);         cnt = 0;         while (m) {           a[i][j * 4 - cnt++] = (m % 2);           m >>= 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];       }     }     cnt = 0;     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         x[++cnt] = i;       }     }     for (int k = cnt; k >= 1; k--) {       if (check(x[k])) {         printf( %d n , x[k]);         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000 + 100;   int nex[maxN];   int st[maxN];   int en[maxN];   vector<int> c[maxN];   int ind;   void dfs(int s) {     st[s] = ind++;     for (auto x : c[s]) dfs(x);     en[s] = ind;   }   int main() {     int n, m;     string s;     cin >> n >> m;     cin >> s;     int curr = 0;     c[curr].push_back(1);     for (int i = 1; i < ((int)(s).size()); i++) {       while (curr && s[i] != s[curr]) curr = nex[curr];       if (s[curr] == s[i]) curr++;       nex[i + 1] = curr;       c[curr].push_back(i + 1);     }     dfs(0);     int len = 0;     if (m != 0) {       int last;       cin >> last;       last--;       len = ((int)(s).size());       int p = ((int)(s).size());       for (int i = 1; i < m; i++) {         int num;         cin >> num;         num--;         len += ((int)(s).size());         len -= max(0, last + p - num);         if (last + p - num > 0) {           int lfix = last + p - num;           if (!(st[lfix] <= st[p] && st[p] < en[lfix])) {             cout << 0 << endl;             return 0;           }         }         last = num;       }     } else       len = 0;     long long ans = 1;     int mod = 1e9 + 7;     len = n - len;     for (int i = 0; i < len; i++) ans = ans * 26LL % mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const vector<int> mods = {998244353, 1000000007, 1000000009};   const long long inf = 3e18;   const double pi = acos(-1.0);   const double eps = 0.0000001;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class... K>   using umap = unordered_map<K...>;   template <class... K>   using uset = unordered_set<K...>;   int n, m, k;   int u, v, w;   const int N = 200100;   const int P = 400000;   umap<int, vector<pair<int, int> > > g;   long long pw[N][3];   long long fc[10][10][3];   vector<long long> goal;   long long comb[15];   long long res;   void build() {     for (int j = (0); j < (3); ++j) pw[0][j] = 1;     for (int i = (1); i < (n + 10); ++i)       for (int j = (0); j < (3); ++j) {         pw[i][j] = (pw[i - 1][j] * 13) % mods[j];       }     goal.resize(3);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (3); ++j) {         goal[j] = (goal[j] + pw[i][j]) % mods[j];       }   }   void inc() {     long long car = 1;     for (int i = (1); i < (10); ++i) {       long long nxc = (comb[i] + car) / i;       comb[i] = (comb[i] + car) % i;       car = nxc;     }   }   bool alz() {     for (int i = (1); i < (k + 1); ++i) {       if (comb[i]) return 0;     }     return 1;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.precision(13);     cin >> n >> m >> k;     build();     for (int i = (0); i < (m); ++i) {       cin >> u >> v >> w;       u--;       v--;       g[u].push_back({w, v});     }     for (int i = (0); i < (n); ++i) sort(begin(g[i]), end(g[i]));     for (int i = (0); i < (n); ++i) {       long long sg = ((int)(g[i]).size());       for (int j = (0); j < (sg); ++j)         for (int k = (0); k < (3); ++k) {           fc[sg][j][k] = (fc[sg][j][k] + pw[g[i][j].second][k]) % mods[k];         }     }     res = 0;     for (int i = (0); i < (P); ++i) {       vector<long long> cur(3);       for (int i = (0); i < (k); ++i)         for (int j = (0); j < (3); ++j) {           cur[j] = (cur[j] + fc[i + 1][comb[i + 1]][j]) % mods[j];         }       if (cur == goal) res++;       inc();       if (alz()) break;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   string s;   bool dp[1010][1010];   bool dfs(int i, int j) {     if (i == N && abs(j) == K) return true;     if (i != N && abs(j) == K) return false;     if (i == N && abs(j) != K) return false;     if (dp[i][j] == 1) return false;     dp[i][j] = 1;     if (s[i] ==  W ) return dfs(i + 1, j + 1);     if (s[i] ==  L ) return dfs(i + 1, j - 1);     if (s[i] ==  D ) return dfs(i + 1, j);     if (dfs(i + 1, j + 1) == true) {       s[i] =  W ;       return 1;     }     if (dfs(i + 1, j) == true) {       s[i] =  D ;       return 1;     }     if (dfs(i + 1, j - 1) == true) {       s[i] =  L ;       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin >> N >> K;     cin >> s;     if (dfs(0, 0) == true)       cout << s << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj;   vector<int> a, b, t;   vector<int> dep, sz;   void dfs(int v, int p) {     dep[v] = dep[p] + 1;     for (auto c : adj[v]) {       if (c != p) {         dfs(c, v);         sz[v] += sz[c];       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int k;       cin >> k;       a.resize(2 * k - 1);       b.resize(2 * k - 1);       t.resize(2 * k - 1);       adj.assign(2 * k + 1, vector<int>());       for (int i = 0; i < 2 * k - 1; ++i) {         cin >> a[i] >> b[i] >> t[i];         adj[a[i]].push_back(b[i]);         adj[b[i]].push_back(a[i]);       }       dep.assign(2 * k + 1, 0);       sz.assign(2 * k + 1, 1);       dfs(1, 0);       long long solMx = 0, solMn = 0;       for (int i = 0; i < 2 * k - 1; ++i) {         if (dep[a[i]] > dep[b[i]]) {           swap(a[i], b[i]);         }         solMx += (long long)min(sz[b[i]], 2 * k - sz[b[i]]) * t[i];         solMn += sz[b[i]] % 2 * t[i];       }       cout << solMn <<     << solMx <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 5e5 + 10;   bool bio[MAXN];   int n;   int a[MAXN], b[MAXN], aa[MAXN], bb[MAXN];   int deg[1 << 20];   map<pair<int, int>, vector<int>> id;   vector<pair<int, int>> e[1 << 20];   stack<int> path;   bool euler(int x, bool print) {     for (int i = 0; i < n; ++i) {       bio[i] = false;       a[i] = aa[i] & ((1 << x) - 1);       b[i] = bb[i] & ((1 << x) - 1);       deg[a[i]] = deg[b[i]] = 0;       e[a[i]].clear();       e[b[i]].clear();     }     for (int i = 0; i < n; ++i) {       deg[a[i]]++;       deg[b[i]]++;       e[a[i]].emplace_back(b[i], i);       if (a[i] != b[i]) e[b[i]].emplace_back(a[i], i);     }     for (int i = 0; i < n; ++i)       if (deg[a[i]] % 2 || deg[b[i]] % 2) return false;     vector<int> ret;     int node = a[0];     path.push(node);     while (!path.empty()) {       int nxt = -1;       while (!e[node].empty() && bio[e[node].rbegin()->second])         e[node].pop_back();       if (!e[node].empty()) {         path.push(node);         nxt = e[node].rbegin()->first;         bio[e[node].rbegin()->second] = true;         e[node].pop_back();         node = nxt;       } else {         ret.push_back(node);         node = path.top();         path.pop();       }     }     if (!print) return ret.size() == n + 1;     if (ret.size() == n + 1) {       printf( %d n , x);       for (int i = 0; i < n; ++i) {         int aa = a[i] & ((1 << x) - 1);         int bb = b[i] & ((1 << x) - 1);         id[{aa, bb}].push_back(i);       }       for (int i = ret.size() - 2; i >= 0; --i) {         int a = ret[i + 1], b = ret[i];         if (id.find({a, b}) != id.end() && id[{a, b}].size() != 0) {           int x = *id[{a, b}].rbegin();           id[{a, b}].pop_back();           printf( %d %d  , 2 * x + 1, 2 * x + 2);         } else {           int x = *id[{b, a}].rbegin();           id[{b, a}].pop_back();           printf( %d %d  , 2 * x + 2, 2 * x + 1);         }       }       printf(  n );       exit(0);     }   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &aa[i], &bb[i]);     }     int lo = 0, hi = 20;     while (lo < hi) {       int mid = (lo + hi) / 2 + 1;       if (euler(mid, false))         lo = mid;       else         hi = mid - 1;     }     euler(lo, true);     return 0;   }


#include <bits/stdc++.h>   using std::max;   using std::min;   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3f;   __inline__ __attribute__((always_inline)) unsigned int rnd() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     f && (x = -x);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? min(a, args...) : min(b, args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? max(b, args...) : max(a, args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 100005;   const int MAXN = 10000005;   bool pr[MAXN];   int _p[MAXN >> 3], _pos;   int md[MAXN];   void sieve() {     for (int i = 2; i < MAXN; ++i) {       if (!pr[i]) {         _p[++_pos] = i;         md[i] = i;       }       for (int j = 1; j <= _pos && i * _p[j] < MAXN; ++j) {         pr[i * _p[j]] = true;         md[i * _p[j]] = _p[j];         if (!(i % _p[j])) break;       }     }   }   std::vector<int> p[N], d[N];   int c[MAXN], cnt[1 << 8], mul[1 << 8];   int calc(int id) {     int siz = ((int)p[id].size()), ans = 0;     for (int i = 0; i < siz; ++i) mul[1 << i] = p[id][i];     for (int i = 1; i < 1 << siz; ++i) {       cnt[i] = cnt[i >> 1] + (i & 1);       mul[i] = mul[i ^ ((i) & (-(i)))] * mul[((i) & (-(i)))];       if (cnt[i] & 1)         ans += c[mul[i]];       else         ans -= c[mul[i]];     }     return ans;   }   int a[N];   int _val[11], _cnt[11], pos, cur_id;   void dfs(int dep, int val) {     if (dep == pos + 1) {       d[cur_id].push_back(val);       return;     }     for (int i = 0; i <= _cnt[dep]; ++i) {       dfs(dep + 1, val);       if (i < _cnt[dep]) val *= _val[dep];     }   }   bool ban[N], vis[N];   int deg[N];   int f(int mid) {     while (ban[mid]) --mid;     if (!mid) return false;     int qwq = 0;     for (int i = 1; i <= mid; ++i)       if (!ban[i]) {         ++qwq;         for (auto it : d[i]) ++c[it];       }     int ans = 0;     for (int i = 1; i <= mid; ++i)       if (!ban[i] && calc(i) != qwq) ++ans;     for (int i = 1; i <= mid; ++i)       if (!ban[i])         for (auto it : d[i]) --c[it];     return ans;   }   std::vector<int> getnodes(int mid) {     while (ban[mid]) --mid;     std::vector<int> nd;     int qwq = 0;     for (int i = 1; i <= mid; ++i)       if (!ban[i]) {         ++qwq;         for (auto it : d[i]) ++c[it];       }     for (int i = 1; i <= mid; ++i)       if (!ban[i] && calc(i) != qwq) nd.push_back(i);     for (int i = 1; i <= mid; ++i)       if (!ban[i])         for (auto it : d[i]) --c[it];     return nd;   }   int main() {     mul[0] = 1;     sieve();     int n, k;     read(n, k);     for (int i = 1; i <= n; ++i) {       read(a[i]);       ++c[a[i]];       int cur = a[i], last = 0;       pos = 0;       while (cur > 1) {         if (md[cur] != last)           p[i].push_back(md[cur]), _val[++pos] = md[cur], _cnt[pos] = 1;         else           ++_cnt[pos];         last = md[cur];         cur /= last;       }       cur_id = i;       dfs(1, 1);     }     for (int j = 1; j <= _pos; ++j)       for (int i = (MAXN - 1) / _p[j]; i >= 1; --i) c[i] += c[i * _p[j]];     std::vector<int> nd;     for (int i = 1; i <= n; ++i) {       if ((deg[i] = calc(i)) <= n - 2) {         nd.push_back(i);         for (int j = 1; j <= n && ((int)nd.size()) < 3; ++j)           if (i != j && gcd(a[i], a[j]) == 1) nd.push_back(j);         break;       }     }     if (nd.empty()) {       std::vector<int> clique, rest;       for (int i = 1; i <= n; ++i)         if (deg[i] == n)           clique.push_back(i);         else           rest.push_back(i);       if (((int)clique.size()) > k) clique.resize(k);       for (int i = 1; i <= n && ((int)clique.size()) < k; ++i) {         if (!vis[i] && deg[i] == n - 1) {           clique.push_back(i);           for (auto it : rest)             if (gcd(a[it], a[i]) == 1) vis[it] = true;         }       }       for (auto it : clique) printf( %d  , it);       printf(  n );       return 0;     }     assert(((int)nd.size()) == 3);     if (k == 3) {       for (auto it : nd) printf( %d  , it);       printf(  n );       return 0;     }     for (auto it : nd) ban[it] = true;     for (auto id : nd)       for (auto it : d[id]) --c[it];     std::vector<int> clique;     for (int i = 1; i <= n; ++i)       if (!ban[i] && ((deg[i] = calc(i)) == n - 3)) clique.push_back(i);     if (((int)clique.size()) >= k) {       clique.resize(k);       for (auto it : clique) printf( %d  , it);       printf(  n );       return 0;     }     memset(c, 0, sizeof(c));     int l = 1, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (f(mid) + 3 >= k)         r = mid;       else         l = mid + 1;     }     std::vector<int> v1 = getnodes(l - 1);     std::vector<int> v2 = getnodes(l);     assert(f(l - 1) == ((int)v1.size()));     assert(f(l) == ((int)v2.size()));     assert(((int)v1.size()) + 3 < k);     assert(((int)v2.size()) + 3 >= k);     std::sort(v1.begin(), v1.end());     std::vector<int> qwq;     for (auto it : v2) {       auto _ = std::lower_bound(v1.begin(), v1.end(), it);       if (_ == v1.end() || *_ != it) qwq.push_back(it);     }     std::sort(qwq.begin(), qwq.end());     assert(((int)v1.size()) + ((int)qwq.size()) == ((int)v2.size()));     if (((int)v1.size()) + 3 + 1 == k && ((int)qwq.size()) != 1)       v1.push_back(nd[0]), v1.push_back(nd[1]);     else       v1.push_back(nd[0]), v1.push_back(nd[1]), v1.push_back(nd[2]);     while (((int)v1.size()) < k) {       v1.push_back(qwq.back());       qwq.pop_back();     }     assert(((int)v1.size()) == k);     for (auto it : v1) printf( %d  , it);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 500005;   const int MOD = 1e9 + 7;   int i, n, m, k, rs, x, y;   long long val[N];   map<int, int> p;   map<long long, vector<pair<int, int>>> M;   int Pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = ((long long)ans * a) % MOD, --b;       a = ((long long)a * a) % MOD;       b /= 2;     }     return ans;   }   int pfind(int x) {     if (!p.count(x)) return p[x] = x;     if (p[x] == x) return p[x] = x;     return p[x] = pfind(p[x]);   }   void punite(int x, int y) {     if (rand() & 1)       p[pfind(x)] = pfind(y);     else       p[pfind(y)] = pfind(x);   }   int main() {     scanf( %d %d %d , &n, &m, &k);     rs = Pow(2, n + k);     for (i = 1; i <= n; ++i) scanf( %lld , val + i);     while (m--) {       scanf( %d %d , &x, &y);       M[val[x] ^ val[y]].push_back(make_pair(x, y));     }     for (auto it : M) {       vector<pair<int, int>> v = it.second;       x = n;       p.clear();       for (auto it : v)         if (pfind(it.first) != pfind(it.second)) {           punite(it.first, it.second);           --x;         }       rs -= Pow(2, n);       rs += Pow(2, x);       if (rs < 0)         rs += MOD;       else         rs %= MOD;     }     printf( %d n , rs);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int arr = 9e5 + 10;   signed main() {     long long a, b;     cin >> a >> b;     a = min(a, b);     long long ans = 1;     for (long long i = 1; i <= a; i++) ans *= i;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, a[maxn], b[maxn], v[maxn];   unordered_map<int, int> mp;   void dfs(int x, int l, int r) {     if (v[x] <= r && v[x] >= l) mp[v[x]] = 1;     if (a[x] != -1) {       if (l < v[x]) dfs(a[x], l, min(v[x] - 1, r));     }     if (b[x] != -1) {       if (r > v[x]) dfs(b[x], max(l, v[x] + 1), r);     }   }   bool f[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i] >> a[i] >> b[i];       if (a[i] != -1) f[a[i]] = 1;       if (b[i] != -1) f[b[i]] = 1;     }     int root = 1;     for (int i = 1; i <= n; i++)       if (!f[i]) root = i;     dfs(root, 0, 1000000000);     int ret = 0;     for (int i = 1; i <= n; i++)       if (mp.find(v[i]) != mp.end()) ret++;     cout << n - ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   const int mod = 1e9 + 7;   int n, m, t, q;   vector<int> G[N];   map<int, int> M;   set<int> S;   int a[N], in[N], iinn[N], vis[N];   long long sum;   void topsort(int id) {     int cnt = 0;     while (1) {       for (int i = (1); i <= (n); i++) {         if (iinn[i] == 0 && vis[i] == 0 && a[i] == id) {           cnt++;           vis[i] = 1;           sum++;           int len = G[i].size();           for (int j = (0); j <= (len - 1); j++) {             iinn[G[i][j]]--;           }           i = 0;         }       }       if (cnt == n) break;       id = (id % 3) + 1;       sum++;     }   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n); i++) {       int len, num;       scanf( %d , &len);       for (int j = (1); j <= (len); j++) {         scanf( %d , &num);         G[num].push_back(i);         in[i]++;         iinn[i]++;       }     }     long long ans = 1ll << 62;     sum = 0;     topsort(1);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(2);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(3);     ans = min(ans, sum);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int len;     string s;     cin >> len;     cin >> s;     vector<char> vect;     while (len != 0) {       if (len % 2 == 1) {         vect.push_back(s[0]);       } else {         vect.insert(vect.begin(), s[0]);       }       s.erase(0, 1);       len = s.length();     }     for (int i = 0; i < vect.size(); i++) {       cout << vect[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, d;     vector<pair<int, int>> v;     vector<int> ans;     set<pair<int, int>> st;     scanf( %d %d %d , &n, &m, &d);     ans.resize(n);     for (int i = 0; i < n; ++i) {       int t;       scanf( %d , &t);       v.push_back(make_pair(t, i));     }     sort(v.begin(), v.end());     st.insert(make_pair(v[0].first + d + 1, 1));     ans[v[0].second] = 1;     for (int i = 1; i < v.size(); ++i) {       int minute = v[i].first;       int id = v[i].second;       auto it = st.begin();       int cur_min_available_minute = it->first;       int day = it->second;       if (cur_min_available_minute <= m && minute >= cur_min_available_minute) {         st.erase(it);         st.insert(make_pair(minute + d + 1, day));         ans[id] = day;       } else {         st.insert(make_pair(minute + d + 1, st.size() + 1));         ans[id] = st.size();       }     }     printf( %d n , (int)st.size());     for (int i = 0; i < n; ++i) {       printf( %d  , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double V = e * 3.14159265358979 * (d / 2) * (d / 2);     if (v <= V) {       cout <<  NO ;     } else {       double S = 3.14159265358979 * (d / 2) * (d / 2) * h;       cout <<  YES  << endl << fixed << setprecision(12) << S / (v - V);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(false);     int n;     cin >> n;     vector<int> nums(n);     map<int, int> counts;     for (int i = 0; i < n; i++) {       cin >> nums[i];       counts[nums[i]]++;     }     map<int, int> last;     int k = 0, previous;     for (auto it = counts.begin(); it != counts.end(); it++) {       if (k++ > 0) {         if (previous < it->second) {           cout << -1 << endl;           return 0;         }       }       if (k != it->first) {         cout << -1 << endl;         return 0;       }       previous = it->second;       last[it->first] = 1;     }     int total = 0;     vector<int> ans(n);     for (int i = 0; i < n; i++) {       ans[i] = last[nums[i]]++;       total = max(ans[i], total);     }     cout << total << endl;     for (int i = 0; i < n; i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, ans = 0, cnt = 0;     cin >> n;     vector<long long> a(n), pref(n + 1);     for (auto& i : a) cin >> i;     pref[0] = a[0];     for (int i = 1; i < n; ++i) pref[i] += pref[i - 1] + a[i];     if (pref[n - 1] % 3 || n < 3) return cout << 0, 0;     long long s = pref[n - 1] / 3;     for (int i = 0; i < n - 1; ++i) {       if (pref[i] == 2 * s) ans += cnt;       if (pref[i] == s) ++cnt;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[100001];   long long int d[100001];   long long int n;   long long int max(long long int x, long long int y) {     if (x > y) return x;     return y;   }   int main() {     cin >> n;     long long int i;     long long int x;     for (i = 0; i < n; ++i) {       cin >> x;       a[x]++;     }     d[0] = 0;     d[1] = a[1];     for (i = 2; i <= 100001; ++i) {       d[i] = max(d[i - 1], d[i - 2] + a[i] * i);     }     cout << d[100001] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, m, x, c, count, nr, OK, suma, k, level, val, y[100], z;   void inmultire_y(long long nr) {     int i = 0;     int j = 0;     int Max = 0;     for (; i < 100; i++) y[i] = 0;     long long x2 = nr;     int n = 0;     while (x2) {       n++;       x2 /= 10;     }     x2 = nr;     for (i = 1; i <= n; i++) {       long long x1 = nr;       for (j = 1; j <= n; j++) {         y[i + j - 1] += (x2 % 10) * (x1 % 10);         Max = max(Max, i + j - 1);         if (y[i + j - 1] >= 10) {           Max = max(Max, i + j);           y[i + j] += y[i + j - 1] / 10;           y[i + j - 1] = y[i + j - 1] % 10;         }         x1 /= 10;       }       x2 /= 10;     }     y[0] = Max;   }   long long impartire_y(long long X) {     long long i;     unsigned long R = 0;     for (i = y[0]; i; i--) {       y[i] = (R = 10 * R + y[i]) / X;       R %= X;     }     while (!y[y[0]] && y[0] > 1) y[0]--;     long long r = 0;     for (i = 100; i > 0; i--) {       if (y[i]) {         for (long long j = i; j > 0; j--) {           r = r * 10 + y[j];         }         break;       }     }     return r;   }   int main() {     cin >> n;     val = 2;     for (level = 2; level <= n + 1; level++) {       x = level * (level - 1);       while (1) {         inmultire_y(x);         z = impartire_y(level - 1);         z = z - val / (level - 1);         break;       }       val = x;       cout << z <<   n ;     }     return 0;   }


#include <algorithm>   #include <array>   #include <cassert>   #include <chrono>   #include <cmath>   #include <cstring>   #include <functional>   #include <iomanip>   #include <iostream>   #include <map>   #include <numeric>   #include <queue>   #include <random>   #include <set>   #include <vector>   using namespace std;      template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os <<  (  << p.first <<  ,   << p.second <<  ) ; }   template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os <<  { ; string sep; for (const T &x : v) os << sep << x, sep =  ,  ; return os <<  } ; }      void dbg_out() { cerr << endl; }   template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr <<     << H; dbg_out(T...); }      #ifdef NEAL_DEBUG   #define dbg(...) cerr <<  (  << #__VA_ARGS__ <<  ): , dbg_out(__VA_ARGS__)   #else   #define dbg(...)   #endif         const int INF = int(1e9) + 5;      int main() {       ios::sync_with_stdio(false);   #ifndef NEAL_DEBUG       cin.tie(nullptr);   #endif          int N, A, B;       string str;       cin >> N >> A >> B >> str;       vector<int> S(N);       vector<int> char_to_index(128, -1);       string chars;       int C = 0;          for (int i = 0; i < N; i++) {           char ch = str[i];              if (char_to_index[ch] < 0) {               char_to_index[ch] = C++;               chars += ch;           }              S[i] = char_to_index[ch];       }          dbg(chars);          vector<int> char_start(C, INF);       vector<int> char_end(C, -INF);       vector<int> occur(C, 0);          for (int i = 0; i < N; i++) {           char_start[S[i]] = min(char_start[S[i]], i);           char_end[S[i]] = max(char_end[S[i]], i + 1);           occur[S[i]]++;       }          vector<bool> succeeds(1 << C, false);          for (int mask = 1; mask < 1 << C; mask++) {           int start = INF, end = -INF, count = 0;              for (int c = 0; c < C; c++)               if (mask >> c & 1) {                   start = min(start, char_start[c]);                   end = max(end, char_end[c]);                   count += occur[c];               }              succeeds[mask] = count * B >= (end - start) * A;              if (succeeds[mask])               dbg(mask,  succeeds );       }          vector<int> dp(1 << C, 0);          for (int c = 0; c < C; c++)           dp[1 << c] = 1 << c;          for (int mask = 0; mask < 1 << C; mask++) {           for (int split = 0; split < C; split++) {               int lower = mask & ((1 << split) - 1);               int upper = mask & -(1 << split);               assert((lower | upper) == mask && (lower & upper) == 0);                  if (succeeds[lower] && dp[lower] != 0) dp[mask] |= dp[upper];               if (succeeds[upper] && dp[upper] != 0) dp[mask] |= dp[lower];           }              for (int single = 0; single < C; single++)               if (mask >> single & 1) {                   int without = mask & ~(1 << single);                      if (succeeds[without] && dp[without] != 0)                       dp[mask] |= 1 << single;               }              dbg(mask, dp[mask]);       }          int answer = dp[(1 << C) - 1];       cout << __builtin_popcount(answer);       string sorted;          for (int c = 0; c < C; c++)           if (answer >> c & 1)               sorted += chars[c];          sort(sorted.begin(), sorted.end());          for (auto &ch : sorted)           cout <<     << ch;          cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, d, x, y, r;     int i, n;     scanf( %lf%lf%d , &a, &d, &n);     for (i = 1; i <= n; i++) {       r = fmod(i * d, 4 * a);       if (r <= a)         x = r, y = 0;       else if (r <= 2 * a)         x = a, y = r - a;       else if (r <= 3 * a)         x = a - (r - 2 * a), y = a;       else         x = 0, y = a - (r - 3 * a);       printf( %.10f %.10f n , x, y);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool cap = false, low = false, num = false;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  a  && s[i] <=  z )         low = true;       else if (s[i] >=  A  && s[i] <=  Z )         cap = true;       else if (s[i] >=  0  && s[i] <=  9 )         num = true;     }     if (s.size() >= 5 && cap && low && num)       cout <<  Correct  << endl;     else       cout <<  Too weak  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   long long int vis[N];   vector<vector<int> > v;   int dfs(int t) {     vis[t] = 1;     for (int i = 0; i < v[t].size(); i++) {       if (vis[v[t][t]] == 0) {         dfs(v[t][i]);       }     }     return 0;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   int main() {     long long int n, m;     cin >> n >> m;     while (1) {       if (n == 0 or m == 0) break;       if (n >= 2 * m)         n = n % (2 * m);       else if (m >= 2 * n)         m = m % (2 * n);       else         break;     }     cout << n <<     << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int T, N, M1, M2, s, e;     long long X;     for (cin >> T; T--;) {       M1 = M2 = 0x7fffffff;       s = 0;       e = 1e9;       for (cin >> N >> X; N--;) {         int d, h;         cin >> d >> h;         M1 = min(M1, -d);         M2 = min(M2, h - d);       }       if (X + M1 <= 0) {         cout <<  1 n ;         continue;       }       while (s <= e) {         int m = (s + e) >> 1;         if (X + 1LL * m * M2 + M1 <= 0)           e = m - 1;         else           s = m + 1;       }       if (s > 1e9)         cout <<  -1 n ;       else         cout << s + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum(int n) {     int c = 0;     while (n > 0) {       c += n % 10;       n /= 10;     }     return c;   }   void showarr(int arr[], int n) {     for (int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   int arr[8001], f[8001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int i, j, t;     cin >> t;     while (t--) {       int s, k, n, q, m = 0;       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> arr[i];         f[i + 1] = 0;       }       int ans = 0, cnt = 0;       for (i = 0; i < n; i++) {         cnt = arr[i];         for (j = i + 1; j < n; j++) {           cnt += arr[j];           if (cnt > n) break;           f[cnt] = 1;         }       }       for (i = 0; i < n; i++) {         if (f[arr[i]]) ans++;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int QuickPow(int x, int y) {     int Res = 1, Temp = x;     while (y) {       if (y & 1) Res = Res * Temp % 1000000007;       Temp = Temp * Temp % 1000000007;       y /= 2;     }     return Res;   }   inline void Swap(int &x, int &y) {     int Temp = x;     x = y;     y = Temp;   }   inline int Max(int x, int y) { return x > y ? x : y; }   inline int Min(int x, int y) { return x < y ? x : y; }   inline void read(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   struct node {     int v, Index;     node() {}     node(int V, int INDEX) {       v = V;       Index = INDEX;     }   };   stack<int> S;   vector<node> G[400005];   int Dfn[400005], Low[400005], Bel[400005], Cnt, Col, Size[400005], Maxx, Root;   bool InStack[400005];   void Tarjan(int x, int Pre) {     Dfn[x] = Low[x] = ++Cnt;     S.push(x);     InStack[x] = 1;     int l = G[x].size();     for (register int i = 0; i < l; ++i) {       int to = G[x][i].v;       if (to == Pre) continue;       if (!Dfn[to]) {         Tarjan(to, x);         Low[x] = Min(Low[x], Low[to]);       } else if (InStack[to])         Low[x] = Min(Low[x], Dfn[to]);     }     if (Dfn[x] == Low[x]) {       Col++;       int u;       do {         Size[Col]++;         u = S.top();         S.pop();         InStack[u] = 0;         Bel[u] = Col;       } while (u != x);       if (Size[Col] > Maxx) Maxx = Size[Col], Root = x;     }   }   bool Pan[400005];   int From[400005 * 2], To[400005 * 2];   void Dfs(int x) {     Pan[x] = 1;     int l = G[x].size();     for (register int i = 0; i < l; ++i) {       int to = G[x][i].v, Id = G[x][i].Index;       if (Pan[to]) {         From[Id] = x, To[Id] = to;         continue;       }       if (Low[to] != Low[x])         From[Id] = to, To[Id] = x;       else         From[Id] = x, To[Id] = to;       Dfs(to);     }   }   int main() {     int n, m;     read(n);     read(m);     for (register int i = 1; i <= m; ++i) {       int u, v;       read(u);       read(v);       G[u].push_back(node(v, i));       G[v].push_back(node(u, i));     }     for (register int i = 1; i <= n; ++i)       if (!Dfn[i]) Tarjan(i, i);     printf( %d n , Maxx);     Dfs(Root);     for (register int i = 1; i <= m; ++i) printf( %d %d n , From[i], To[i]);     return 0;   }


#include <bits/stdc++.h>   struct compare {     bool operator()(const int& l, const int& r) { return l > r; }   };   using namespace std;   priority_queue<int, vector<int>, compare> pq;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (k % 3 && n % 3 == 0) {         cout <<  Bob n ;       } else if (k % 3 == 0) {         n %= (k + 1);         if (n % 3 == 0 && n != k) {           cout <<  Bob n ;         } else {           cout <<  Alice n ;         }       } else {         cout <<  Alice n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long double pi = 2.0 * acos(0.0);   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   long long int N;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a, b, c, i, j, k, first, r, x, y, z;     long long int n, m, p, q, t;     long long int A[1000005];     long long int B[1000005];     first = 0;     r = 0;     cin >> n;     k = (n) / 2;     cout << k <<   n ;     for (i = 0; i < k - 1; i++) cout <<  2  ;     cout << (2 + (n % 2));     return 0;   }


#include<bits/stdc++.h>      #define ll long long   #define rep(A,B,C) for(A=B;A<C;++A)   #define pii pair<int,int>   #define pll pair<ll,ll>      #define fi first   #define se second   #define all(A) A.begin(),A.end()      using namespace std;      /////////////////////////////////////////////////////   #define vv vector   #define Nmx 303030   #define lNmx 20      ll N,M;   vv<pll> uvv[Nmx + 3];   pll xyv[Nmx + 3];   ll dblp[Nmx + 3][lNmx + 3];   ll dps[Nmx + 3];   ll mked[Nmx + 3], mkcm[Nmx + 3];   vv<pll> cmv[Nmx + 3];   ll an[Nmx + 3];   ll i, j, k;         ll dfs1(ll a,ll p,ll d){              dblp[a][0] = p;       dps[a] = d;       ll i = 0, pi = 0;       ll c = 0;       c += mked[a] - mkcm[a];       rep(i,0,uvv[a].size()){           ll b = uvv[a][i].fi;           if(b==p){               pi = i;               continue;           }           ll rb= dfs1(b, a, d + 1);           //printf( %lld,%lld,%lld n , a, b, rb);           uvv[a][i].se = rb;           c += rb;           //assert(false);       }       an[a] = c;       uvv[a][pi].se = c - mkcm[a];       //printf( %lld,%lld,%lld,%lld n , a, p, d,uvv[1][0].se);       return uvv[a][pi].se;   }      void dblinit(){       ll i, j;       rep(j,0,lNmx)           rep(i,0,N+1)               dblp[i][j + 1] = dblp[dblp[i][j]][j];   }      pll lcap(ll a,ll b){       if(a==b)           return {-1, -1};       if(dps[a]<dps[b])           swap(a, b);       ll i = lNmx;       while(dps[a]-dps[b]>1){           if((1<<i)<=dps[a]-dps[b]-1)               a = dblp[a][i];           --i;       }       if(dps[a]>dps[b]){           if(dblp[a][0]==b)               return {a, -1};           a = dblp[a][0];       }       i = lNmx;       while(i>=0){           if(dblp[a][i]!=dblp[b][i]){               a = dblp[a][i];               b = dblp[b][i];           }           --i;       }       if(a>b)           swap(a, b);       return {a, b};   }      ll calc(ll a){       ll i;       map<ll, ll> mp;       rep(i,0,uvv[a].size()){           mp[uvv[a][i].fi] = i;       }       ll ans = 0;       map<pll, ll> mp2;       rep(i,0,cmv[a].size()){                      ll aa = --an[a];           ll p1 = cmv[a][i].fi, p2 = cmv[a][i].se;           //printf( %lld:%lld,%lld,%lld,%lld  ,a, i,p1,p2, an[a]);           if(p1!=-1){               ll I = mp[p1];               aa -= --uvv[a][I].se;               //printf( a%lld, , uvv[a][I].se);           }           if(p2!=-1){               ll I = mp[p2];               aa -= --uvv[a][I].se;               //printf( b%lld, , uvv[a][I].se);           }           if(p1!=-1&&p2!=-1){               //printf( c%lld, , mp2[cmv[a][i]]);               aa += mp2[cmv[a][i]]++;           }           //printf(  n );           ans += aa;       }       return ans;   }         void solve(){       dfs1(1, 0, 1);       dblinit();              //assert(false);       rep(i,0,M){           pll xy = xyv[i];           if(xy.fi>xy.se)               swap(xy.fi, xy.se);           ++mked[xy.fi];           ++mked[xy.se];           //printf( ccc%lld,%lld, n , xy.fi, xy.se);           if(xy.fi==xy.se){               cmv[xy.fi].push_back({-1, -1});               ++mkcm[xy.fi];               continue;           }           pll cmp = lcap(xy.fi, xy.se);           //printf( ddd%lld,%lld,%lld n , cmp.fi, cmp.se,dblp[cmp.fi][0]);                      ll cm = dblp[cmp.fi][0];           cmv[cm].push_back(cmp);           ++mkcm[cm];       }              dfs1(1, 0, 1);       /*rep(i,0,N+1){           printf(  n%lld-%lld: n , i, an[i]);           rep(j,0,uvv[i].size()){               printf( %lld,%lld n , uvv[i][j].fi, uvv[i][j].se);           }       }*/       ll ans=0;       rep(i,0,N+1){           ll a = calc(i);           //printf( %lld,%lld n , i, a);           ans += a;       }          printf( %lld n , ans);   }            int main(){       scanf( %lld , &N);              rep(i,1,N){           ll u, v;           scanf( %lld%lld , &u, &v);           uvv[u].push_back({v, 0});           uvv[v].push_back({u, 0});       }       uvv[1].push_back({0, 0});       scanf( %lld , &M);       rep(i,0,M){           ll u, v;           scanf( %lld%lld , &u, &v);           xyv[i] = {u, v};       }       solve();          return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int sz[100005], answer[100005];   long long ans = 0;   vector<int> spis;   void clears(int v, int pr) {     sz[v] = 1;     int pos = -1;     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       if (u == pr)         pos = i;       else {         clears(u, v);         sz[v] += sz[u];       }     }     if (pos != -1) {       swap(g[v][pos], g[v].back());       g[v].pop_back();     }     return;   }   void dfs(int v, int len) {     ans += (long long)2 * len;     spis.push_back(v);     for (int i = 0; i < (int)g[v].size(); i++) {       int u = g[v][i];       dfs(u, len + 1);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v), g[v].push_back(u);     }     clears(1, -1);     int cen = 1;     while (true) {       int mx = -1;       for (int i = 0; i < (int)g[cen].size(); i++) {         int u = g[cen][i];         if (2 * sz[u] > sz[cen]) mx = i;       }       if (mx == -1) break;       int newcen = g[cen][mx];       swap(g[cen][mx], g[cen].back());       g[cen].pop_back();       g[newcen].push_back(cen);       sz[cen] -= sz[newcen];       sz[newcen] += sz[cen];       cen = newcen;     }     dfs(cen, 0);     cout << ans <<   n ;     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++)         answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i];     } else {       for (int i = 1; i < n / 2; i++)         answer[spis[i]] = spis[i + n / 2], answer[spis[i + n / 2]] = spis[i];       answer[spis[0]] = spis[n / 2], answer[spis[n / 2]] = spis[n - 1],       answer[spis[n - 1]] = spis[0];     }     for (int i = 1; i <= n; i++) cout << answer[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int main() {     int mas[100000];     cin >> n;     for (int i = 0; i < (n); i++) {       scanf( %d , &mas[i]);       if (i < n / 2)         mas[i] -= i;       else         mas[i] -= n - i - 1;     }     sort(mas, mas + n);     int l = 0;     int ans = 0;     for (int i = 1; i <= n; i++)       if (mas[i] != mas[l] || i == n) {         if (mas[l] >= 1) ans = max(ans, i - l);         l = i;       }     cout << n - ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, s;     cin >> n >> s;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long l = 0, r = n, total = 0;     while (l < r) {       long long mid = (l + r) / 2;       long long cost[n];       for (int i = 0; i < n; i++) {         cost[i] = a[i] + mid * (i + 1);       }       sort(cost, cost + n);       total = 0;       for (int i = 0; i < mid; i++) {         total += cost[i];       }       if (s < total) {         r = mid;       } else {         l = mid;       }       if (r - l == 1) {         int cost[n];         mid = r;         for (int i = 0; i < n; i++) {           cost[i] = a[i] + mid * (i + 1);         }         sort(cost, cost + n);         total = 0;         for (int i = 0; i < mid; i++) {           total += cost[i];         }         if (s >= total) {           l = r;         } else {           mid = l;           for (int i = 0; i < n; i++) {             cost[i] = a[i] + mid * (i + 1);           }           sort(cost, cost + n);           total = 0;           for (int i = 0; i < mid; i++) {             total += cost[i];           }         }         break;       }     }     cout << l <<     << total <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define endl   n       using namespace std;      typedef long long lld;      void solve(){       int n;       cin>>n;       vector<lld> a(n+1), b(n+1), p(n+2,0);       for(int i=1;i<=n;i++){           cin>>a[i];       }       for(int i=1;i<=n;i++){           cin>>b[i];           p[i]=a[i]*b[i]+p[i-1];       }       lld ans=p[n];       for(int i=1;i<=n;i++){           lld curr=a[i]*b[i];           for(int l=i-1, r=i+1; l>=1 && r<=n; l--, r++){               curr+=a[r]*b[l]+a[l]*b[r];               ans=max(ans,curr+p[l-1]+p[n]-p[r]);           }           curr=0;           for(int l=i, r=i+1; l>=1 && r<=n; l--, r++){               curr+=a[r]*b[l]+a[l]*b[r];               ans=max(ans,curr+p[l-1]+p[n]-p[r]);           }       }       cout<<ans<<endl;   }      int32_t main(){       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (a > (b * c)) {         cout << (-1) << endl;         continue;       }       long long k = (a / (d * b));       cout << (a * (k + 1)) - (d * b * k * (k + 1) / 2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const double INF = 2e50;   double sqr(double a) { return a * a; }   int get_ch(double x, double y) {     if (x <= 0 && y <= 0) return 1;     if (x <= 0 && y >= 0) return 4;     if (x >= 0 && y <= 0) return 2;     return 3;   }   struct pt {     double x, y;     pt(double x, double y) : x(x), y(y) {}     pt() {}     void read() { cin >> x >> y; }     double d() { return sqrt(sqr(x) + sqr(y)); }     pt operator-(pt ot) { return pt(x - ot.x, y - ot.y); }     bool operator==(pt ot) { return x == ot.x && y == ot.y; }     double operator*(const pt ot) const { return (x * ot.y - y * ot.x); }     bool operator<(const pt f) const {       int a = get_ch(x, y);       int b = get_ch(f.x, f.y);       return (a < b || (a == b && (*this) * f >= 0));     }   };   inline double get_an(pt f, pt s) {     return acos((f.x * s.x + f.y * s.y) / f.d() / s.d());   }   inline double vec_m(pt f, pt s) { return (f.x * s.y - f.y * s.x); }   double with_a[501][501], with_b[501][501];   int main() {     int n, m;     cin >> n >> m;     if (!m) {       cout << n * (n - 1) * (n - 2) / 6;       return 0;     }     vector<pt> f(n), s(m);     for (int i = 0; i < n; i++) {       f[i].read();     }     for (int i = 0; i < m; i++) {       s[i].read();     }     double ans = 0;     for (int i = 0; i < n; i++) {       vector<pair<pt, pair<int, int> > > ev(n + m - 1 - i);       int sz = 0;       for (int j = i + 1; j < n; j++) {         if (j == i) continue;         ev[sz++] = make_pair(f[j] - f[i], make_pair(0, j));       }       for (int j = 0; j < m; j++) {         ev[sz++] = make_pair(s[j] - f[i], make_pair(1, j));       }       sort(ev.begin(), ev.end());       for (int j = 0; j < (int)ev.size(); j++) {         pt maxi = pt(INF, INF);         int id = ev[j].second.second;         if (ev[j].second.first) continue;         for (int k = (j + 1) % (int)ev.size();; k = (k + 1) % (int)ev.size()) {           if (k == j) break;           int type = ev[k].second.first;           int to_id = ev[k].second.second;           pt temp = (type ? s[to_id] : f[to_id]);           double to_an = vec_m(f[id] - f[i], temp - f[i]);           if (to_an < 0) break;           if (type) {             if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - f[id]) > 0) {               maxi = temp;             }           } else {             if (maxi == pt(INF, INF) || vec_m(maxi - f[id], temp - maxi) > 0) {               ans++;             }           }         }       }     }     cout << fixed << setprecision(0) << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   string st;   int l, memo[1000009][2];   int get(int pos, int carry) {     if (pos < 0) return carry;     int &ret = memo[pos][carry];     if (ret != -1) return ret;     ret = 9999999;     if (carry == 0) {       if (st[pos] ==  0 )         return ret = get(pos - 1, 0);       else {         int ra = get(pos - 1, carry) + 1;         int rb = get(pos - 1, 1 - carry) + 1;         ret = min(ra, rb);         return ret;       }     } else {       if (st[pos] ==  1 )         return ret = get(pos - 1, carry);       else {         int ra = get(pos - 1, 0) + 1;         int rb = get(pos - 1, 1) + 1;         ret = min(ra, rb);         return ret;       }     }   }   int print_path(int pos, int carry) {     if (pos < 0) {       if (carry) printf( +2^%d n , l - pos - 1);       return 0;     }     if (carry == 0) {       if (st[pos] ==  0 )         return print_path(pos - 1, 0);       else {         int ra = get(pos - 1, carry) + 1;         if (ra == memo[pos][carry]) {           printf( +2^%d n , l - pos - 1);           return print_path(pos - 1, carry);         } else {           printf( -2^%d n , l - pos - 1);           return print_path(pos - 1, 1 - carry);         }       }     } else {       if (st[pos] ==  1 )         return print_path(pos - 1, carry);       else {         int ra = get(pos - 1, 0) + 1;         if (ra == memo[pos][carry]) {           printf( +2^%d n , l - pos - 1);           return print_path(pos - 1, 0);         } else {           printf( -2^%d n , l - pos - 1);           return print_path(pos - 1, 1);         }       }     }   }   int main() {     while (cin >> st) {       memset(memo, -1, sizeof memo);       ;       l = st.size();       cout << get(l - 1, 0) << endl;       print_path(l - 1, 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   signed main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long x = gcd(c, d);       c /= x;       d /= x;       if (c == 0 && a != 0) {         cout << -1 <<   n ;         continue;       }       if (c == 0 && a == 0) {         cout <<  0 n ;         continue;       }       if (c == d && a != b) {         cout << -1 <<   n ;         continue;       }       if (c == d && a == b) {         cout <<  0 n ;         continue;       }       long long l = (a + c - 1) / c - 1;       long long r = (long long)2e18 / d;       while (r - l > 1) {         long long m = (r + l) / 2;         if (m * d >= b + m * c - a) {           r = m;         } else {           l = m;         }       }       cout << r * d - b <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n = 0, a = 0;     cin >> n >> a;     long long int ar[n];     long long int i = 0;     for (i = 0; i < n; i++) cin >> ar[i];     long long int pos = a - 1;     if (n == 1) {       if (ar[0] == 1)         cout <<  1  << endl;       else         cout <<  0  << endl;     } else if (n == 2) {       if ((ar[0] == 1) && (ar[1] == 1))         cout <<  2  << endl;       else if ((ar[0] == 1) || (ar[1] == 1))         cout <<  1  << endl;       else         cout <<  0  << endl;     } else {       long long int low = pos - 1;       long long int high = pos + 1;       long long int ans = 0;       if (ar[pos] == 1) ans++;       while ((low >= 0) || (high < n)) {         long long int l1 = ar[low];         long long int l2 = ar[high];         if ((low >= 0) && (high < n) && (l1 == 1) && (l2 == 1))           ans += 2;         else if ((low >= 0) && (high >= n) && (l1 == 1))           ans++;         else if ((low < 0) && (high < n) && (l2 == 1))           ans++;         else           ans = ans;         low--;         high++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[100][100];   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n * n; i++) {       scanf( %d%d , &a, &b);       if (!arr[a][b]) {         printf( %d  , i + 1);         for (int y = 0; y <= n; y++) {           arr[a][y] = 1;           arr[y][b] = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename A, typename B = A>   using pr = pair<A, B>;   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cout << fixed << setprecision(10);     int sy, a, b;     cin >> sy >> a >> b;     sy = -sy;     int n;     cin >> n;     vector<pr<int>> segs(n);     for (auto &[x, y] : segs) cin >> y >> x;     sort((segs).begin(), (segs).end());     vector<ll> pref(n + 1);     for (int i = 0; i < n; i++)       pref[i + 1] = pref[i] + segs[i].first - segs[i].second;     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       auto get = [&](int k) { return (k - x) * double(y) / (sy + y); };       double x1 = x + get(a);       double x2 = x + get(b);       auto find = [&](double x) {         return int(upper_bound((segs).begin(), (segs).end(),                                pr<int>{ceil(x + 1e-6), -1}) -                    segs.begin());       };       int i1 = find(x1);       int i2 = find(x2);       double sum = 0;       if (i2 != i1) {         sum += pref[i2] - pref[i1 + 1];         if (i1 != -1)           sum +=               min<double>(segs[i1].first - segs[i1].second, segs[i1].first - x1);         if (i2 != n) sum += max<double>(0, x2 - segs[i2].second);       } else {         int i = i2;         if (i != -1 && i != n)           sum += max<double>(0, min<double>(segs[i].first, x2) -                                     max<double>(segs[i].second, x1));       }       cout << sum * (sy + y) / y <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int limit = 3000000;   const int tope = 100000;   int absolut(int x) {     if (x < 0) return -x;     return x;   }   void die() {     cout << -1 << endl;     exit(0);   }   int n;   int a[limit];   int b[limit];   int add[limit];   long long int nsol;   vector<pair<int, int> > vsol;   void fix(int pos) {     while (int(vsol.size()) < tope and add[pos] > 0 and a[pos] < 9 and            a[pos + 1] < 9) {       a[pos]++;       a[pos + 1]++;       add[pos]--;       vsol.push_back(pair<int, int>(pos, 1));     }     while (int(vsol.size()) < tope and add[pos] < 0 and a[pos] > 0 and            a[pos + 1] > 0) {       a[pos]--;       a[pos + 1]--;       add[pos]++;       vsol.push_back(pair<int, int>(pos, -1));     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       a[i] = c -  0 ;     }     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       b[i] = c -  0 ;     }     for (int i = 1; i < n; i++) {       add[i] = b[i] - (a[i] + add[i - 1]);       nsol += absolut(add[i]);     }     if (a[n] + add[n - 1] != b[n]) die();     while (int(vsol.size()) < nsol and int(vsol.size()) < tope) {       for (int pos = 1; pos < n and int(vsol.size()) < tope; pos++) fix(pos);       for (int pos = n - 1; pos >= 1 and int(vsol.size()) < tope; pos--) fix(pos);     }     cout << nsol << endl;     for (int i = 0; i < int(vsol.size()) and i < tope; i++)       cout << vsol[i].first <<     << vsol[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > q;   int tar[100005];   int n, k, add;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> tar[i];     long long ans = 0;     cin >> add;     int tmp;     for (int i = 1; i <= n; i++) {       cin >> tmp;       q.push(tmp);       while (k < tar[i]) {         if (q.empty()) {           cout << -1 << endl;           return 0;         }         k += add;         ans += q.top();         q.pop();       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int tu(int val) { return (1 << val); }   bool iset(int mask, int id) {     if ((mask & tu(id)) != 0) return true;     return false;   }   void doset(int &mask, int id) { mask |= tu(id); }   void dounset(int &mask, int id) { mask = mask & (~tu(id)); }   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   const long long LM = 1e18;   long long N, K;   vector<long long> pms, PA, push_back, temp;   void proc(vector<long long> &ans, const vector<long long> &now) {     ans.clear();     ans.push_back(1);     int l = now.size();     for (int(x) = (0); (x) < (l); (x)++) {       long double p = now[x];       int la = ans.size();       temp.clear();       for (int(i) = (0); (i) < (la); (i)++) {         long double v = p * ans[i];         while (v <= LM) {           temp.push_back(v);           v *= p;         }       }       la = temp.size();       for (int(i) = (0); (i) < (la); (i)++) ans.push_back(temp[i]);     }     sort(ans.begin(), ans.end());     int la = ans.size();     for (int(i) = (1); (i) < (la); (i)++) assert(ans[i] != ans[i - 1]);   }   long long count(long long val) {     int la = PA.size();     int lb = push_back.size();     int ia = 0;     int ib = lb - 1;     long long ret = 0;     while (ia < la && ib >= 0) {       unsigned long long va = PA[ia] * push_back[ib];       if (va > val)         ib--;       else {         ret += ib + 1;         ia++;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     while (cin >> N) {       vector<long long> pa, pb;       pms.clear();       pms.resize(N);       for (int(i) = (0); (i) < (N); (i)++) cin >> pms[i];       sort(pms.begin(), pms.end());       cin >> K;       for (int(i) = (0); (i) < (N); (i)++) {         if ((i % 2) == 0)           pa.push_back(pms[i]);         else           pb.push_back(pms[i]);       }       proc(PA, pa);       proc(push_back, pb);       long long ans = -1;       long long lo = 1;       long long hi = LM;       while (true) {         if (hi - lo < 5) {           for (long long x = lo; x <= hi; x++) {             long long k = count(x);             if (k == K) {               ans = x;               break;             }           }           break;         }         long long m = (lo + hi) / 2;         long long k = count(m);         if (k >= K)           hi = m;         else           lo = m;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ans_t =  YES ;   string ans_f =  NO ;   void judge(int n) {     if (n < 6 + 10 + 14 + 1) {       cout << ans_f << endl;     } else {       cout << ans_t << endl;       int tmp = n - 6 - 10 - 14;       if (tmp == 6 || tmp == 10 || tmp == 14) {         cout <<  6 10   << 14 + 1 <<     << tmp - 1 << endl;       } else {         cout <<  6 10 14   << tmp << endl;       }     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       judge(n);     }     return 0;   }