#include <bits/stdc++.h>   using namespace std;   int n;   const int N = 50;   const int M = 10000000;   const int MOD = 1e9 + 7;   string st[N];   int fa[N], lst[N], tot, cnt[N], ss[N];   int V[N], col[N], res;   int get_f(int t) {     if (fa[t] == t)       return t;     else       return get_f(fa[t]);   }   int ID[M], F[M], G[M];   int tmpA[M], tmpB[M], tmpC[M];   void FWT(int A[], int n) {     for (int i = 2; i <= n; i <<= 1)       for (int j = 0; j < n; j += i)         for (int k = j; k < (j + (i >> 1)); ++k)           A[k + (i >> 1)] = (A[k + (i >> 1)] + A[k]) % MOD;   }   void IFWT(int A[], int n) {     for (int i = 2; i <= n; i <<= 1)       for (int j = 0; j < n; j += i)         for (int k = j; k < (j + (i >> 1)); ++k)           A[k + (i >> 1)] = (A[k + (i >> 1)] - A[k] + MOD) % MOD;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> st[i];     for (int i = 0; i < n; ++i) fa[i] = i;     for (int i = 0; i < n; ++i)       for (int j = 0; j < i; ++j)         if (st[i][j] ==  A ) fa[get_f(i)] = get_f(j);     for (int i = 0; i < n; ++i) cnt[get_f(i)]++;     tot = 0;     for (int i = 0; i < n; ++i)       if (fa[i] == i) {         if (cnt[i] == 1)           res++;         else           lst[i] = tot++;       }     for (int i = 0; i < n; ++i)       if (cnt[i] != 1)         for (int j = 0; j < i; ++j)           if (cnt[j] != 1)             if (st[i][j] ==  X ) {               int u = lst[get_f(i)], v = lst[get_f(j)];               if (u == v) {                 puts( -1 );                 exit(0);               }               if (u > v) swap(u, v);               V[u] |= 1 << v;               V[v] |= 1 << u;             }     for (int i = 0; i < tot; ++i) ID[1 << i] = i;     F[0] = 1;     for (int i = 1; i < (1 << tot); ++i) {       int x = i & (-i);       if (F[i ^ x] && !(V[ID[x]] & (i ^ x))) F[i] = 1;     }     G[0] = 1;     FWT(F, 1 << tot);     FWT(G, 1 << tot);     for (int i = 0;; ++i) {       int v = 0;       for (int j = 0; j < (1 << tot); ++j)         if (__builtin_popcount(((1 << tot) - 1) ^ j) & 1)           v = (v + MOD - G[j]) % MOD;         else           v = (v + G[j]) % MOD;       if (v) {         cout << i - 1 + n;         return 0;       }       for (int j = 0; j < (1 << tot); ++j) G[j] = 1ll * F[j] * G[j] % MOD;     }   }


#include <bits/stdc++.h>   using namespace std;   long long sol(long long a, long long b, long long h, long long w, int n,                 vector<long long> v) {     int p = 0;     long long th = h, tw = w;     for (; p < n; ++p) {       if (th < a)         th *= v[p];       else if (tw < b)         tw *= v[p];       else         break;     }     n = p;     v.resize(p);     auto solve = [&]() {       if (h >= a && w >= b) return true;       if (n < 20) {         for (int i = 0; i < 1 << n; ++i) {           th = h, tw = w;           for (int j = 0; j < n; ++j) {             if (i >> j & 1) {               if (th < a) th *= v[j];             } else {               if (tw < b) tw *= v[j];             }           }           if (th >= a && tw >= b) return true;         }         return false;       }       int m1 = n / 2, m2 = n - m1;       vector<pair<long long, long long>> x;       for (int i = 0; i < 1 << m1; ++i) {         th = 1, tw = 1;         for (int j = 0; j < m1; ++j) {           if (i >> j & 1) {             if (th * h < a) th *= v[j];           } else {             if (tw * w < b) tw *= v[j];           }         }         x.push_back({min(th, a), min(tw, b)});       }       sort(x.begin(), x.end());       vector<long long> mx(x.size());       for (int i = x.size() - 1; i >= 0; --i) {         mx[i] = x[i].second;         if (i + 1 < x.size()) mx[i] = max(mx[i], mx[i + 1]);       }       for (int i = 0; i < 1 << m2; ++i) {         th = 1, tw = 1;         for (int j = 0; j < m2; ++j) {           if (i >> j & 1) {             if (th * h < a) th *= v[m1 + j];           } else {             if (tw * w < b) tw *= v[m1 + j];           }         }         long long val = (a + h * th - 1) / (h * th);         auto it = lower_bound(x.begin(), x.end(), make_pair(val, 0LL));         if (it != x.end()) {           if (mx[it - x.begin()] * min(tw, b) * w >= b) return true;         }       }       return false;     };     int l = 0, r = p;     while (l < r) {       n = (l + r) >> 1;       if (solve())         r = n;       else         l = n + 1;     }     n = l;     if (solve()) return n;     return 1 << 30;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     long long a, b, h, w, n;     cin >> a >> b >> h >> w >> n;     vector<long long> v(n);     for (auto &i : v) cin >> i;     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     int ans = min(sol(a, b, h, w, n, v), sol(b, a, h, w, n, v));     if (ans == 1 << 30) ans = -1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   class event {    public:     long long t;     int id, type;     event() {}     event(long long a, int b, int c) {       t = a;       id = b;       type = c;     }     bool operator<(const event& other) const {       if (t != other.t) return other.t < t;       if (type != other.type) return other.type < type;       return other.id < id;     }   };   int n, p;   long long A[MAXN];   priority_queue<event> pq;   set<int> hold, qu;   long long last;   int main() {     scanf( %d %d , &n, &p);     for (int i = 1; i <= n; i++) {       scanf( %lld , &A[i]);       pq.push(event(A[i], i, 2));     }     while (!pq.empty()) {       event top = pq.top();       pq.pop();       if (top.type == 2) {         if (qu.empty()) {           qu.insert(top.id);           pq.push(event(top.t + p, top.id, 1));           last = top.t + p;         } else if (*qu.begin() > top.id) {           qu.insert(top.id);           pq.push(event(last + p, top.id, 1));           last = last + p;         } else {           hold.insert(top.id);         }       } else {         A[top.id] = top.t;         qu.erase(top.id);         set<int>::iterator lb = hold.lower_bound(top.id);         if (lb != hold.end()) {           pq.push(event(top.t, *lb, 2));           hold.erase(lb);         }       }     }     for (int i = 1; i <= n; i++) printf( %lld  , A[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int MAXN = 1e5 + 10;   int n, k;   int ans;   int data[MAXN];   int has[MAXN];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &data[i]);       ++has[data[i] % 10];       ans += data[i] / 10;     }     for (int i = 1; i < 10; ++i) {       int s = min(has[10 - i], k / i);       k -= i * s;       ans += s;       if (s != has[10 - i]) break;     }     ans += min(10 * n - ans, k / 10);     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n <<   n ;     for (int i = 0; i < n; i++) {       cout << 1 <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long sum1[maxn];   long long sum2[maxn];   long long a[maxn];   long long pos[maxn];   int n;   long long lowbit(long long x) { return x & -x; }   void add(long long *sum, long long x, long long v) {     while (x <= n) {       sum[x] += v;       x += lowbit(x);     }   }   long long query(long long *sum, long long x) {     long long res = 0;     while (x > 0) {       res += sum[x];       x -= lowbit(x);     }     return res;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       pos[a[i]] = i;     }     long long ans1 = 0;     for (int i = 1; i <= n; i++) {       ans1 += i - 1 - query(sum1, pos[i]);       add(sum1, pos[i], 1);       add(sum2, pos[i], pos[i]);       int mid, l = 1, r = n;       while (l <= r) {         mid = (l + r) >> 1;         if (query(sum1, mid) * 2 <= i)           l = mid + 1;         else           r = mid - 1;       }       long long ans2 = 0;       long long cnt = query(sum1, mid);       long long sum = query(sum2, mid);       ans2 += mid * cnt - sum - cnt * (cnt - 1) / 2;       cnt = i - cnt;       sum = query(sum2, n) - sum;       ans2 += sum - cnt * (mid + 1) - cnt * (cnt - 1) / 2;       cout << ans1 + ans2 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     int h[100000], max[100001];     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> h[i];     }     max[n] = h[n - 1] - 1;     for (int i = n - 1; i >= 0; --i) {       if (h[i] > max[i + 1])         max[i] = h[i];       else         max[i] = max[i + 1];     }     for (int i = 0; i < n; ++i) {       if (max[i + 1] >= h[i])         cout << max[i + 1] - h[i] + 1 <<    ;       else         cout << 0 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int const N = 1100;   int n, m, ans, ans1;   int map[N][N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) map[i][j] = -1;     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       for (int j = 1; j <= x; ++j)         if (map[i][j] != 0)           map[i][j] = 1;         else {           printf( %d n , 0);           return 0;         }       if (map[i][x + 1] == 1) {         printf( %d n , 0);         return 0;       }       map[i][x + 1] = 0;     }     for (int i = 1; i <= m; ++i) {       int x;       scanf( %d , &x);       for (int j = 1; j <= x; ++j)         if (map[j][i] != 0)           map[j][i] = 1;         else {           printf( %d n , 0);           return 0;         }       if (map[x + 1][i] == 1) {         printf( %d n , 0);         return 0;       }       map[x + 1][i] = 0;     }     ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (map[i][j] == -1) ans++;     ans1 = 1;     for (int i = 1; i <= ans; ++i) ans1 = (ans1 * 2) % 1000000007;     printf( %d n , ans1);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60000000 )   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = 3.1415926535897932384626433832795;   template <class T>   T sqr(T x) {     return x * x;   }   int n, m;   long long w[300300];   long long t[300300];   vector<pair<pair<int, int>, int> > Q;   long long ans[300300];   int main() {     memset(w, 0, sizeof(w));     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       int x;       scanf( %d , &x);       w[i] = x;     }     scanf( %d , &m);     Q.resize(m);     for (int i = 0; i < (int)(m); i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       Q[i] = make_pair(make_pair(b, a), i);     }     sort(Q.begin(), Q.end());     int cur = 0;     for (int i = 0; i < (int)(Q.size()); i++) {       int a = Q[i].first.second;       int b = Q[i].first.first;       int num = Q[i].second;       if (b > 1000) {         ans[num] = 0;         while (a < n) {           ans[num] += w[a];           a += b;         }       } else {         if (b > cur) {           cur = b;           memset(t, 0, sizeof(t));           for (int i = n - 1; i >= 0; i--) {             t[i] = w[i];             if (i + cur < n) t[i] += t[i + cur];           }         }         if (a < n)           ans[num] = t[a];         else           ans[num] = 0;       }     }     for (int i = 0; i < (int)(m); i++) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Size = 1e5;   long long n, m;   bool onField(long long x, long long y) {     return (x <= n && x >= 1) && (y <= m && y >= 1);   }   int main() {     long long x, y, dx, dy, k;     long long ans = 0;     cin >> n >> m;     cin >> x >> y;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> dx >> dy;       for (long long cof = 1100000000; cof; cof /= 2)         while (onField(x + (cof * dx), y + (cof * dy))) {           x += (cof * dx);           y += (cof * dy);           ans += cof;         }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, k, ans = INT_MIN;       cin >> n >> k;       long long A[n];       for (int i = 0; i < n; i++) cin >> A[i];       for (long long j = n - 1; ~j; j--) {         for (long long i = j - 1; ~i; i--) {           if (ans >= (i + 1) * (j + 1)) break;           ans = max(ans, (i + 1) * (j + 1) - (k * (A[i] | A[j])));         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n = 0;     cin >> n;     string s;     cin >> s;     int pos = 0;     vector<int> v(n);     int flag = 1;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < n; i++) {       if (s[pos] ==  > ) {         pos += v[pos];       } else {         pos -= v[pos];       }       if (pos < 0 || pos > n - 1) {         cout <<  FINITE ;         flag = 0;         break;       }     }     if (flag == 1) {       cout <<  INFINITE ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[300001];   int arr[300001];   int dp[300001];   int maxi = -(int)1e10, max_pos;   bool flag = false;   void dfs(int beta, int baap) {     if (flag) return;     if (arr[beta] == maxi)       dp[beta] = 0;     else       dp[beta] = -(int)1e10;     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs(pota, beta);       if (dp[pota] != -(int)1e10) {         if (dp[beta] == -(int)1e10)           dp[beta] = 1 + dp[pota];         else {           int dist = 1 + dp[beta] + dp[pota];           if (dist > 2) flag = true;           dp[beta] = max(dp[beta], 1 + dp[pota]);         }       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       if (arr[i] > maxi) {         maxi = arr[i];         max_pos = i;       }     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     int max_count = 0, max_cnt = 0;     for (int i = 1; i <= n; i++) {       if (arr[i] == maxi) max_count++;       if (arr[i] == maxi - 1) max_cnt++;     }     if (max_count == 1) {       for (int i = 0; i < g[max_pos].size(); i++) {         int j = g[max_pos][i];         if (arr[j] == maxi - 1) max_cnt--;       }       if (max_cnt)         printf( %d n , maxi + 1);       else         printf( %d n , maxi);     } else {       dfs(1, 0);       if (flag)         printf( %d n , maxi + 2);       else         printf( %d n , maxi + 1);     }     return 0;   }


#include <bits/stdc++.h>   const int INF = INT_MAX;   using namespace std;   const int N = 3e5 + 10;   int arr[N];   int main() {     ios_base::sync_with_stdio(false);     stringstream ss;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     map<int, bool> ma;     vector<pair<int, int> > ans;     int i = 0, j;     int start, end;     bool flag = false;     while (i < n) {       j = i;       start = i;       ma.clear();       while (j < n) {         if (ma.find(arr[j]) == ma.end()) {           ma[arr[j]] = true;         } else {           break;         }         j++;       }       if (j < n) {         end = j;         ans.push_back(make_pair(start, end));       } else {         if (ans.size() > 0) {           ans[ans.size() - 1].second = n - 1;         } else {           flag = true;         }         break;       }       i = j + 1;     }     if (flag)       ss <<  -1 n ;     else {       ss << ans.size() <<   n ;       for (int k = 0, end = ans.size(); k < end; k++) {         ss << (ans[k].first + 1) <<     << (ans[k].second + 1) <<   n ;       }     }     cout << ss.str() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   int t;   void solve() {     int n, res = 0, j = 0;     string s;     cin >> n >> s;     map<int, int> m;     for (int i = 0; i <= n; i++) {       if (s[i] ==  x ) {         m[j]++;       } else {         j++;       }     }     for (auto i : m) {       res += max(0, i.second - 2);     }     cout << res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (0) {       cin >> t;       while (t--) solve();     } else {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   long long arr[100010], dpArr[100010], dpQuery[100010];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     for (long long i = (1); i < (n + 1); ++i) cin >> arr[i];     pair<pair<long long, long long>, long long> q[m + 1];     for (long long i = (1); i < (m + 1); ++i)       cin >> q[i].first.first >> q[i].first.second >> q[i].second;     for (long long i = 0; i < (k); ++i) {       long long x, y;       cin >> x >> y;       ++dpQuery[x];       --dpQuery[y + 1];     }     long long sum = 0LL;     for (long long i = (1); i < (m + 1); ++i) {       sum += dpQuery[i];       dpArr[q[i].first.first] += (sum * q[i].second);       dpArr[q[i].first.second + 1] -= (sum * q[i].second);     }     sum = 0LL;     for (long long i = (1); i < (n + 1); ++i) {       sum += dpArr[i];       cout << (sum + arr[i]) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, z, flag = 0;   vector<long long> sum(200005), mx(200005, INT_MIN);   vector<int> adj[200005 + 1];   vector<int> pl(200005 + 1);   map<int, int> vis;   void dfs(int a) {     vis[a] = 1;     for (int i = 0; i < adj[a].size(); i++) {       if (vis[adj[a][i]] == 0) {         dfs(adj[a][i]);         sum[a] += sum[adj[a][i]];         mx[a] = max(mx[a], mx[adj[a][i]]);       }     }     sum[a] += pl[a];     mx[a] = max(mx[a], sum[a]);     return;   }   map<int, int> mp;   long long ans = INT_MIN;   void dfs2(int x) {     mp[x] = 1;     long long k = 0;     priority_queue<long long> q;     for (int i = 0; i < adj[x].size(); i++) {       if (mp[adj[x][i]] == 0) q.push(mx[adj[x][i]]);     }     long long s = q.size();     int j = 2;     while (j > 0 && q.size()) {       k += q.top();       q.pop();       j--;     }     if (s > 1) ans = max(ans, k);     for (int i = 0; i < adj[x].size(); i++) {       if (mp[adj[x][i]] == 0) dfs2(adj[x][i]);     }   }   int main() {     int t;     t = 1;     for (int r = 0; r < t; r++) {       cin >> n;       long long i;       for (i = 1; i <= n; i++) cin >> pl[i];       for (i = 0; i < n - 1; i++) {         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       dfs(1);       dfs2(1);       if (ans == INT_MIN)         cout <<  Impossible n ;       else         cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int n, m, i, j, k, l, a, b, sz[2], v1[2][5005];   string s;   bool used[5005];   int main() {     ios_base ::sync_with_stdio();     cin.tie(0);     cin >> s;     n = s.size();     if (n == 1) {       cout << s;       return 0;     }     int pw = 1;     while (pw * 2 <= n) pw *= 2, k++;     a = 0;     b = 1;     v1[a][0] = 0;     sz[a] = 1;     for (l = 0; l < n - (1 << k) + 1; l++) {       char res =  z ;       int v, mask;       for (i = 0; i < sz[a]; i++) {         int v = v1[a][i], mask = ((1 << k) - 1) ^ (v - l);         used[v] = 0;         for (j = mask; j > 0; j = mask & (j - 1)) res = min(res, s[v + j]);         res = min(res, s[v]);       }       for (i = 0; i < sz[a]; i++) {         int v = v1[a][i], mask = ((1 << k) - 1) ^ (v - l);         for (j = mask; j >= 0; j = mask & (j - 1)) {           if (!used[v + j + 1] && s[v + j] == res)             v1[b][sz[b]++] = v + j + 1, used[v + j + 1] = true;           if (j == 0) break;         }       }       cout << res;       sz[a] = 0;       b = a;       a ^= 1;     }     return 0;   }


#include <bits/stdc++.h>   const int MAXQ = 5e5 + 5;   using namespace std;   struct edge {     int v, next;   } ed[MAXQ * 4];   int head[MAXQ * 2];   int topE;   void addE(int u, int v) {     ed[++topE].v = v;     ed[topE].next = head[u];     head[u] = topE;     return;   }   int dep[MAXQ * 2];   int fa[MAXQ * 2][25];   int Q;   int ans;   int topN;   int lca(int x, int y) {     int res = 0;     if (dep[x] < dep[y]) {       swap(x, y);     }     res += dep[x] - dep[y];     while (dep[x] != dep[y]) {       x = fa[x][int(log2(dep[x] - dep[y]))];     }     for (int i = int(log2(dep[x])); i >= 0; --i) {       if (fa[x][i] != fa[y][i]) {         res += dep[x] - dep[fa[x][i]];         res += dep[y] - dep[fa[y][i]];         x = fa[x][i];         y = fa[y][i];       }     }     if (x == y) {       return res;     }     x = fa[x][0];     y = fa[y][0];     res += 2;     return res;   }   void insertNode(int u, int v) {     fa[u][0] = v;     dep[u] = dep[v] + 1;     for (int i = 1; i <= int(log2(dep[u])); ++i) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];     }     return;   }   int da, db;   int main() {     scanf( %d , &Q);     topN = 4;     dep[2] = dep[3] = dep[4] = 1;     fa[2][0] = fa[3][0] = fa[4][0] = 1;     da = 2;     db = 3;     ans = 2;     for (int i = 1; i <= Q; ++i) {       int v;       scanf( %d , &v);       insertNode(++topN, v);       insertNode(++topN, v);       if (lca(da, topN) > ans) {         ans = lca(da, topN);         db = topN;       } else if (lca(db, topN) > ans) {         ans = lca(db, topN);         da = topN;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char m[1000000];   int main() {     int t, i, j;     string s;     cin >> t;     cin >> s;     int l = s.length();     for (i = 0; i < l; i++) m[i] = s[i];     for (i = 1; i < t; i++) {       cin >> s;       for (j = 0; j < l; j++) {         if (m[j] ==  ? ) m[j] = s[j];         if (m[j] != s[j] && s[j] !=  ? ) m[j] =  ! ;       }     }     for (i = 0; i < l; i++) {       if (m[i] ==  ? )         cout <<  x ;       else if (m[i] ==  ! )         cout <<  ? ;       else         cout << m[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lb = 1000;   void azmuth(long long n = 12) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(n) << fixed;   }   void solve() {     long long n;     string s;     cin >> n >> s;     vector<long long> ans(n);     ans[0] = 1;     for (long long i = 0; i < n - 1; i++) {       if (s[i] ==  = ) {         ans[i + 1] = ans[i];         continue;       }       if (s[i] ==  L ) {         ans[i + 1] = 1;         continue;       }       ans[i + 1] = 1 + ans[i];     }     for (long long i = n - 2; i >= 0; i--) {       if (s[i] ==  L ) {         ans[i] = max(ans[i], ans[i + 1] + 1);       } else if (s[i] ==  R ) {         ans[i] = min(ans[i], ans[i + 1] - 1);       } else         ans[i] = ans[i + 1];     }     for (auto a : ans) cout << a <<    ;     cout <<   n ;     ;   }   int32_t main() {     azmuth();     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, class F = function<T(const T&, const T&)>>   class SparseTable {    public:     int n;     vector<vector<T>> sp;     F func;     SparseTable(const vector<T>& a, const F& f) : func(f) {       n = static_cast<int>(a.size());       int max_log = 32 - __builtin_clz(n);       sp.resize(max_log);       sp[0] = a;       for (int j = 1; j < max_log; ++j) {         sp[j].resize(n - (1 << j) + 1);         for (int i = 0; i <= n - (1 << j); ++i) {           sp[j][i] = func(sp[j - 1][i], sp[j - 1][i + (1 << (j - 1))]);         }       }     }     T get(int l, int r) const {       int lg = 32 - __builtin_clz(r - l + 1) - 1;       return func(sp[lg][l], sp[lg][r - (1 << lg) + 1]);     }   };   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1), nxt(n + 1), prv(n + 1), cum(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       cum[i] = cum[i - 1] + a[i];     }     for (int i = n; i >= 1; i--) {       nxt[i] = i + 1;       while (nxt[i] <= n && a[nxt[i]] <= a[i]) nxt[i] = nxt[nxt[i]];     }     for (int i = 1; i <= n; i++) {       prv[i] = i - 1;       while (prv[i] >= 1 && a[prv[i]] <= a[i]) prv[i] = prv[prv[i]];     }     SparseTable<int> mn_sp(cum, [&](int i, int j) { return min(i, j); });     SparseTable<int> mx_sp(cum, [&](int i, int j) { return max(i, j); });     int ans = 0;     for (int i = 1; i <= n; i++) {       int l = prv[i] + 1, r = nxt[i] - 1;       ans = max(ans, mx_sp.get(i, r) - mn_sp.get(l - 1, i - 1) - a[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int treas[310][310];   long long dp[310][310];   long long d[310][310];   vector<pair<int, int> > G[110000];   vector<pair<long long, pair<int, int> > > lst;   queue<pair<long long, pair<int, int> > > bfs;   int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};   long long n, m;   long long Dist(int x1, int y1, int x2, int y2) {     return abs(x1 - x2) + abs(y1 - y2);   }   int main() {     ios_base::sync_with_stdio(0);     int p, fx, fy;     cin >> n >> m >> p;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> treas[i][j];         G[treas[i][j]].push_back({i, j});         if (treas[i][j] == p) fx = i, fy = j;         if (treas[i][j] == 1) dp[i][j] = i + j;       }     for (int i = 2; i <= p; i++) {       long long cur_size = G[i].size();       long long prev_size = G[i - 1].size();       if (cur_size * prev_size <= n * m) {         for (int j = 0; j < cur_size; j++) {           int cur_x = G[i][j].first;           int cur_y = G[i][j].second;           dp[cur_x][cur_y] = 1e9;           for (int k = 0; k < prev_size; k++) {             int prev_x = G[i - 1][k].first;             int prev_y = G[i - 1][k].second;             dp[cur_x][cur_y] =                 min(dp[cur_x][cur_y],                     dp[prev_x][prev_y] + Dist(cur_x, cur_y, prev_x, prev_y));           }         }       } else {         lst.clear();         for (int j = 0; j < n; j++)           for (int k = 0; k < n; k++) d[j][k] = -1;         for (int j = 0; j < prev_size; j++) {           int prev_x = G[i - 1][j].first;           int prev_y = G[i - 1][j].second;           lst.push_back({dp[prev_x][prev_y], {prev_x, prev_y}});         }         sort(lst.begin(), lst.end());         int ptr = 1;         bfs.push(lst[0]);         d[lst[0].second.first][lst[0].second.second] = lst[0].first;         while (!bfs.empty()) {           int x = bfs.front().second.first;           int y = bfs.front().second.second;           long long val = bfs.front().first;           bfs.pop();           while (ptr < lst.size() && lst[ptr].first <= val) bfs.push(lst[ptr++]);           int X, Y;           for (int k = 0; k < 4; k++) {             X = x + dir[k][0];             Y = y + dir[k][1];             if (X >= 0 && X <= n && Y >= 0 && Y < m && d[X][Y] == -1) {               d[X][Y] = val + 1;               bfs.push({val + 1, {X, Y}});             }           }         }         for (int j = 0; j < cur_size; j++) {           int x = G[i][j].first;           int y = G[i][j].second;           dp[x][y] = d[x][y];         }       }     }     cout << dp[fx][fy] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, i, j, sum = 0, k;     cin >> x >> y;     for (i = 1; i <= x; i++) {       j = i % 5;       k = y + j;       sum = sum + (k / 5);     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)2e9;   const long long md = 1000000007;   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<int, int> > v(n);     for (int i = 0; i < (int)n; i++) {       cin >> v[i].first >> v[i].second;     }     sort((v).begin(), (v).end(), [&](pair<int, int>& a, pair<int, int>& b) {       return abs(a.first) + abs(a.second) < abs(b.first) + abs(b.second);     });     vector<string> out;     for (pair<int, int>& p : v) {       int first = p.first, second = p.second;       if (first) {         out.emplace_back( 1   + to_string(abs(first)) +     +                          (first > 0 ?  R  :  L ));       }       if (second) {         out.emplace_back( 1   + to_string(abs(second)) +     +                          (second > 0 ?  U  :  D ));       }       out.emplace_back(to_string(2));       if (second) {         out.emplace_back( 1   + to_string(abs(second)) +     +                          (second < 0 ?  U  :  D ));       }       if (first) {         out.emplace_back( 1   + to_string(abs(first)) +     +                          (first < 0 ?  R  :  L ));       }       out.emplace_back(to_string(3));     }     cout << (int)(out.size()) <<   n ;     for (string& s : out) cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void yes() {     cout <<  YES           <<   n ;     return;   }   void no() {     cout <<  NO           <<   n ;     return;   }   template <typename T>   void p(T a) {     cout << a <<    ;     return;   }   template <typename T>   void pnl(T a) {     cout << a <<   n ;     return;   }   const int ten4 = 1e4;   const int ten5 = 1e5;   const int ten6 = 1e6;   const int ten7 = 1e7;   const int ten9 = 1e9;   const int mod = 1e9 + 7;   struct pair_hash {     inline std::size_t operator()(const std::pair<int, int>& v) const {       return v.first * 31 + v.second;     }   };   long long bin_to_integer(string strin) {     long long r = 1, sum = 0;     for (long long i = strin.length() - 1; i >= 0; i--) {       if (strin[i] ==  1 ) sum += r;       r *= 2;     }     return sum;   }   string to_binary(int n) {     string strng;     while (n > 0) {       if (n & 1)         strng +=  1 ;       else         strng +=  0 ;       n >>= 1;     }     reverse(strng.begin(), strng.end());     return strng;   }   int compare(const void* a, const void* b) {     const long long* x = (long long*)a;     const long long* y = (long long*)b;     if (*x > *y)       return 1;     else if (*x < *y)       return -1;     return 0;   }   int power(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res = (res * 1LL * a) % mod;       n /= 2;       a = (a * 1LL * a) % mod;     }     return res;   }   const int Nc = 200001;   int F[Nc];   bool Fcomputed = false;   int nCr(int n, int r) {     if (!Fcomputed) {       F[0] = 1, Fcomputed = true;       for (int i = 1; i < Nc; i++) F[i] = (F[i - 1] * 1LL * i) % mod;     }     if (n < r) return 0;     int res = F[n];     res = res * 1LL * power(F[r], mod - 2) % mod;     res = res * 1LL * power(F[n - r], mod - 2) % mod;     return res;   }   struct unionfind {     vector<int> p;     unionfind(int N) { p = vector<int>(N, -1); }     int root(int x) {       if (p[x] < 0) {         return x;       } else {         p[x] = root(p[x]);         return p[x];       }     }     bool same(int x, int y) { return root(x) == root(y); }     void unite(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (p[x] < p[y]) {           swap(x, y);         }         p[y] += p[x];         p[x] = y;       }     }   };   void testcase(int test) {     int n;     cin >> n;     int arr[n], cnt = 0;     for (int i = 0; i < (n); i++) cin >> arr[i];     if (n % 2 == 0) return yes();     for (int i = 0; i < (n - 1); i++) {       if (arr[i] >= arr[i + 1]) return yes();     }     no();     return;   }   int main() {     ios_base::sync_with_stdio(false);     ;     int test = 1, z = 1;     cin >> test;     while (z <= test) {       testcase(z);       z++;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2,avx )   #pragma GCC optimize( unroll-loops )   using namespace std;   string YES[2] = { NO ,  YES };   string Yes[2] = { No ,  Yes };   string yes[2] = { no ,  yes };   template <class T>   using pq = priority_queue<T>;   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   int scan() { return getchar(); }   void scan(int &a) { cin >> a; }   void scan(long long &a) { cin >> a; }   void scan(char &a) { cin >> a; }   void scan(double &a) { cin >> a; }   void scan(string &a) { cin >> a; }   template <class T, class S>   void scan(pair<T, S> &p) {     scan(p.first), scan(p.second);   }   template <class T>   void scan(vector<T> &);   template <class T>   void scan(vector<T> &a) {     for (auto &i : a) scan(i);   }   template <class T>   void scan(T &a) {     cin >> a;   }   void IN() {}   template <class Head, class... Tail>   void IN(Head &head, Tail &...tail) {     scan(head);     IN(tail...);   }   template <class T, class S>   inline bool chmax(T &a, S b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T, class S>   inline bool chmin(T &a, S b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   vector<int> iota(int n) {     vector<int> a(n);     iota(begin(a), end(a), 0);     return a;   }   template <typename T>   vector<int> iota(vector<T> &a, bool greater = false) {     vector<int> res(a.size());     iota(begin(res), end(res), 0);     sort(begin(res), end(res), [&](int i, int j) {       if (greater) return a[i] > a[j];       return a[i] < a[j];     });     return res;   }   vector<pair<long long, long long>> factor(long long x) {     vector<pair<long long, long long>> ans;     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) {         ans.push_back({i, 1});         while ((x /= i) % i == 0) ans.back().second++;       }     if (x != 1) ans.push_back({x, 1});     return ans;   }   template <class T>   vector<T> divisor(T x) {     vector<T> ans;     for (T i = 1; i * i <= x; i++)       if (x % i == 0) {         ans.push_back(i);         if (i * i != x) ans.push_back(x / i);       }     return ans;   }   template <typename T>   void zip(vector<T> &x) {     vector<T> y = x;     sort(begin(y), end(y));     for (int i = 0; i < x.size(); ++i) {       x[i] = distance((y).begin(), lower_bound(begin(y), end(y), (x[i])));     }   }   int popcount(long long x) { return __builtin_popcountll(x); }   struct Setup_io {     Setup_io() {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       cout << fixed << setprecision(15);     }   } setup_io;   int in() {     int x;     cin >> x;     return x;   }   long long lin() {     unsigned long long x;     cin >> x;     return x;   }   template <typename T>   struct edge {     int from, to;     T cost;     int id;     edge(int to, T cost) : from(-1), to(to), cost(cost) {}     edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}     edge(int from, int to, T cost, int id)         : from(from), to(to), cost(cost), id(id) {}     edge &operator=(const int &x) {       to = x;       return *this;     }     operator int() const { return to; }   };   template <typename T>   using Edges = vector<edge<T>>;   using Tree = vector<vector<int>>;   using Graph = vector<vector<int>>;   template <class T>   using Wgraph = vector<vector<edge<T>>>;   Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {     Tree res(n);     if (m == -1) m = n - 1;     while (m--) {       int a, b;       cin >> a >> b;       a -= margin, b -= margin;       res[a].emplace_back(b);       if (!directed) res[b].emplace_back(a);     }     return move(res);   }   template <class T>   Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {     Wgraph<T> res(n);     if (m == -1) m = n - 1;     while (m--) {       int a, b;       T c;       cin >> a >> b >> c;       a -= margin, b -= margin;       res[a].emplace_back(b, c);       if (!directed) res[b].emplace_back(a, c);     }     return move(res);   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto &e : v) cout << e <<    ;     cout << endl;     return os;   }   template <class T, class S>   ostream &operator<<(ostream &os, const pair<T, S> &p) {     cout <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <class S, class T>   string to_string(pair<S, T> p) {     return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ;   }   template <class A>   string to_string(A v) {     if (v.empty()) return  {} ;     string ret =  { ;     for (auto &x : v) ret += to_string(x) +  , ;     ret.back() =  } ;     return ret;   }   void dump() { cerr << endl; }   template <class Head, class... Tail>   void dump(Head head, Tail... tail) {     cerr << to_string(head) <<    ;     dump(tail...);   }   template <typename T>   static constexpr T inf = numeric_limits<T>::max() / 2;   int main() {     int n, k;     IN(n, k);     int ans = 0;     while (k--) {       int m;       IN(m);       vector<int> a(m);       IN(a);       if (a[0] == 1) {         int c = 0;         while (c < m and a[c] == c + 1) c++;         ans += m - c;         ans += m - c;       } else         ans += m * 2 - 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   long long p, q, b;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool ok() {     long long m = gcd(p, q);     q /= m;     m = b;     while (q != 1) {       m = gcd(q, m);       q /= m;       if (m == 1) break;     }     if (q == 1) return true;     return false;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %I64d%I64d%I64d , &p, &q, &b);       if (!p || ok())         printf( Finite n );       else         printf( Infinite n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <class T>   bool cmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   struct starter {     high_resolution_clock::time_point t1, t2;     starter() {       ios::sync_with_stdio(0);       cin.tie(0);       t1 = high_resolution_clock::now();     }     ~starter() {       t2 = high_resolution_clock::now();       duration<double> time_span = duration_cast<duration<double>>(t2 - t1);       cerr <<  It took   << time_span.count() <<   seconds. ;     }   } starter_;   const int64_t MOD = 998244353;   struct mi {     using ll = long long;     ll v;     explicit operator ll() const { return v; }     mi() { v = 0; }     mi(ll _v) {       v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;       if (v < 0) v += MOD;     }     friend bool operator==(const mi& a, const mi& b) { return a.v == b.v; }     friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }     friend bool operator<(const mi& a, const mi& b) { return a.v < b.v; }     mi& operator+=(const mi& m) {       if ((v += m.v) >= MOD) v -= MOD;       return *this;     }     mi& operator-=(const mi& m) {       if ((v -= m.v) < 0) v += MOD;       return *this;     }     mi& operator*=(const mi& m) {       v = v * m.v % MOD;       return *this;     }     mi& operator/=(const mi& m) { return (*this) *= inv(m); }     friend mi pow(mi a, ll p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi& a) {       assert(a.v != 0);       return pow(a, MOD - 2);     }     mi operator-() const { return mi(-v); }     mi& operator++() { return *this += 1; }     mi& operator--() { return *this -= 1; }     mi operator++(int32_t) {       mi temp;       temp.v = v++;       return temp;     }     mi operator--(int32_t) {       mi temp;       temp.v = v--;       return temp;     }     friend mi operator+(mi a, const mi& b) { return a += b; }     friend mi operator-(mi a, const mi& b) { return a -= b; }     friend mi operator*(mi a, const mi& b) { return a *= b; }     friend mi operator/(mi a, const mi& b) { return a /= b; }     friend ostream& operator<<(ostream& os, const mi& m) {       os << m.v;       return os;     }     friend istream& operator>>(istream& is, mi& m) {       ll x;       is >> x;       m.v = x;       return is;     }   };   struct BIT {     int64_t N;     vector<int64_t> bit;     void init(int64_t n) {       N = n;       bit.assign(n + 1, 0);     }     void update(int64_t idx, int64_t val) {       while (idx <= N) {         bit[idx] += val;         idx += idx & -idx;       }     }     void updateMax(int64_t idx, int64_t val) {       while (idx <= N) {         bit[idx] = max(bit[idx], val);         idx += idx & -idx;       }     }     int64_t pref(int64_t idx) {       int64_t ans = 0;       while (idx > 0) {         ans += bit[idx];         idx -= idx & -idx;       }       return ans;     }     int64_t rsum(int64_t l, int64_t r) { return pref(r) - pref(l - 1); }     int64_t prefMax(int64_t idx) {       int64_t ans = -2e9;       while (idx > 0) {         ans = max(ans, bit[idx]);         idx -= idx & -idx;       }       return ans;     }   } T;   const int64_t inf = 1e18;   const int64_t N = 2e5 + 5;   int64_t n, p[N], have[N];   int64_t unknown, cnt_unknown[N];   int32_t main() {     cin >> n;     for (int64_t i = (1); i <= (n); ++i) {       cin >> p[i];       if (~p[i]) {         have[p[i]] = 1;       } else {         unknown++;         cnt_unknown[i] = 1;       }     }     for (int64_t i = (1); i <= (n); ++i) {       cnt_unknown[i] += cnt_unknown[i - 1];       have[i] += have[i - 1];     }     mi ans = mi(unknown) * (unknown - 1) / 2;     ans /= 2;     auto get_poss = [&](int64_t L, int64_t R) {       if (L > R) return int64_t(0);       return (R - L + 1) - (have[R] - have[L - 1]);     };     if (unknown)       for (int64_t i = (1); i <= (n); ++i) {         if (p[i] == -1) continue;         int64_t tot = cnt_unknown[i - 1];         int64_t poss = get_poss(p[i] + 1, n);         ans += mi(tot) * poss / unknown;       }     if (unknown)       for (int64_t i = n; i; --i) {         if (p[i] == -1) continue;         int64_t tot = cnt_unknown[n] - cnt_unknown[i - 1];         int64_t poss = unknown - get_poss(p[i] + 1, n);         ans += mi(tot) * poss / unknown;       }     T.init(n);     for (int64_t i = (1); i <= (n); ++i) {       if (~p[i]) {         ans += T.rsum(p[i] + 1, n);         T.update(p[i], 1);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   char ibuf[(1 << 20)], *iS, *iT, obuf[(1 << 20)],       *oS = obuf, *oT = oS + (1 << 20) - 1, c, qu[55];   int f, qr;   inline void flush(void) {     return fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void();   }   inline char getch(void) {     return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20), stdin),                         (iS == iT ? EOF : *iS++))                      : *iS++);   }   inline void putch(char x) {     *oS++ = x;     if (oS == oT) flush();     return;   }   string getstr(void) {     string s =   ;     char c = getch();     while (c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF)       c = getch();     while (!(c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF))       s.push_back(c), c = getch();     return s;   }   void putstr(string str, int begin = 0, int end = -1) {     if (end == -1) end = str.size();     for (register int i = begin; i < end; i++) putch(str[i]);     return;   }   template <typename T>   inline T read() {     register T x = 0;     for (f = 1, c = getch(); c <  0  || c >  9 ; c = getch())       if (c ==  - ) f = -1;     for (x = 0; c <=  9  && c >=  0 ; c = getch()) x = x * 10 + (c & 15);     return x * f;   }   template <typename T>   inline void write(const T& t) {     register T x = t;     if (!x) putch( 0 );     if (x < 0) putch( - ), x = -x;     while (x) qu[++qr] = x % 10 +  0 , x /= 10;     while (qr) putch(qu[qr--]);     return;   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_flusher_;   }  // namespace io   using io::getch;   using io::getstr;   using io::putch;   using io::putstr;   using io::read;   using io::write;   struct LCA {     int lca, x, y;   };   long long f[13][(1 << 13)];   int n, m, q;   vector<pair<int, int> > edges;   vector<LCA> lca;   long long F(int p, int S) {     if (~f[p][S]) return f[p][S];     S ^= 1 << p;     int sp = 0;     while (!(S >> sp & 1)) sp++;     f[p][S ^ (1 << p)] = 0;     for (register int i = S; i; i = (i - 1) & S) {       if (!(i >> sp & 1)) continue;       bool pass = false;       for (vector<LCA>::iterator j = lca.begin(); j != lca.end(); j++)         if (j->lca == p && (i >> j->x & 1) && (i >> j->y & 1)) pass = true;       if (pass) continue;       for (vector<LCA>::iterator j = lca.begin(); j != lca.end(); j++)         if ((i >> j->lca & 1) && (!(i >> j->x & 1) || !(i >> j->y & 1)))           pass = true;       if (pass) continue;       for (vector<pair<int, int> >::iterator j = edges.begin(); j != edges.end();            j++)         if (j->first != p && j->second != p &&             ((i >> j->first & 1) ^ (i >> j->second & 1)))           pass = true;       if (pass) continue;       bool choose = false;       int ppp = 0;       for (vector<pair<int, int> >::iterator j = edges.begin(); j != edges.end();            j++)         if (j->first == p && (i >> j->second & 1))           choose ? pass = true : (choose = true, ppp = j->second);         else if (j->second == p && (i >> j->first & 1))           choose ? pass = true : (choose = true, ppp = j->first);       if (pass) continue;       if (choose)         f[p][S ^ (1 << p)] += F(ppp, i) * F(p, S ^ i ^ (1 << p));       else         for (register int j = 0; j < n; j++)           if (i >> j & 1) f[p][S ^ (1 << p)] += F(j, i) * F(p, S ^ i ^ (1 << p));     }     return f[p][S ^ (1 << p)];   }   int main() {     memset(f, -1, sizeof(f));     n = read<int>(), m = read<int>(), q = read<int>();     while (m--)       edges.push_back((pair<int, int>){read<int>() - 1, read<int>() - 1});     while (q--) {       int a = read<int>() - 1, b = read<int>() - 1, c = read<int>() - 1;       lca.push_back((LCA){c, a, b});     }     for (register int i = 0; i < n; i++) f[i][1 << i] = 1;     write(F(0, (1 << n) - 1)), putch(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ar[n];     long long br[n];     for (auto x = 0; x < n; x++) {       cin >> ar[x];       br[x] = ar[x];     }     sort(br, br + n);     long long m;     cin >> m;     while (m--) {       long long pos, k;       set<long long> s;       cin >> k >> pos;       long long bound = br[n - k];       vector<long long> q;       for (int x = 0; x < n; x++) {         if (bound <= ar[x]) {           q.push_back(ar[x]);         }       }       long long sub = q.size() - k;       for (int x = q.size() - 1; x >= 0 && sub != 0; x--) {         if (bound == q[x]) {           q[x] = -1;           sub--;         }         if (sub == 0) {           break;         }       }       for (int x = 0; x < q.size(); x++) {         if (q[x] == -1) {           continue;         }         pos--;         if (pos == 0) cout << q[x] << endl;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long pow(long long a, int b) {     if (b == 0) return 1;     long long base = pow(a, b >> 1);     base = base * base;     if (b & 1) base = base * a;     return base;   }   long long f(long long n) {     if (n == 1) return 1;     map<long long, int> factors;     long long n_ = n;     for (long long i = 2; i * i <= n_; i++) {       while (n % i == 0) {         factors[i]++;         n /= i;       }     }     if (n > 1) factors[n]++;     long long ans = 1;     for (pair<long long, int> p : factors) {       ans *= pow(p.first, p.second) - pow(p.first, p.second - 1);     }     return ans;   }   int main() {     scanf(  %lld %lld , &n, &k);     for (int i = 0; i < (k + 1) / 2; i++) {       n = f(n);       if (n == 1) break;     }     printf( %lld n , n % 1000000007);     return 0;   }


#include <bits/stdc++.h>   int A[100020] = {0};   int main() {     int n, i, dis1, dis2 = 0, dis = 0, min;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &A[i]);       if (min > A[i] || i == 1) min = A[i];     }     for (i = 1; i <= n; i++)       if (A[i] == min) {         if (dis2 == 0) dis2 = i;         dis1 = dis2;         dis2 = i;         if (dis > dis2 - dis1 || dis == 0) dis = dis2 - dis1;       }     printf( %d , dis);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, t;     cin >> s;     cin >> t;     int sc[26] = {0}, tc[26] = {0};     for (int i = 0; i < n; i++) {       sc[s[i] -  a ]++;       tc[t[i] -  a ]++;     }     int flag = 1;     for (int i = 0; i < 26; i++) {       if (sc[i] == tc[i])         continue;       else {         cout << -1 << endl;         flag = 0;         break;       }     }     if (flag == 1) {       int k = 0, change[100005];       for (int i = 0; i < n; i++)         if (s[i] == t[i])           continue;         else           for (int j = i + 1; j < n; j++)             if (s[j] == t[i]) {               while (j > i) {                 char temp = s[j];                 s[j] = s[j - 1];                 s[j - 1] = temp;                 change[k++] = j;                 j--;               }               break;             }       cout << k << endl;       for (int i = 0; i < k; i++) cout << change[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int dblcmp(double x) {     if (abs(x) < 1e-8) return 0;     return (x > 0) ? 1 : -1;   }   inline double sqr(double x) { return x * x; }   const double pi = acos(-1.0);   struct point {     double x, y;     point() {}     point(double _x, double _y) : x(_x), y(_y){};     void input() { scanf( %lf%lf , &x, &y); }     void output() { printf( %.2f %.2f n , x, y); }     bool operator==(point a) const {       return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0;     }     bool operator<(point a) const {       return dblcmp(a.x - x) == 0 ? dblcmp(y - a.y) < 0 : x < a.x;     }     double len() { return hypot(x, y); }     double len2() { return x * x + y * y; }     double distance(point p) { return hypot(x - p.x, y - p.y); }     point add(point p) { return point(x + p.x, y + p.y); }     point sub(point p) { return point(x - p.x, y - p.y); }     point mul(double b) { return point(x * b, y * b); }     point div(double b) { return point(x / b, y / b); }     double dot(point p) { return x * p.x + y * p.y; }     double det(point p) { return x * p.y - y * p.x; }     double rad(point a, point b) {       point p = *this;       return fabs(atan2(fabs(a.sub(p).det(b.sub(p))), a.sub(p).dot(b.sub(p))));     }     point trunc(double r) {       double l = len();       if (!dblcmp(l)) return *this;       r /= l;       return point(x * r, y * r);     }     point rotleft() { return point(-y, x); }     point rotright() { return point(y, -x); }     point rotate(point p, double angle) {       point v = this->sub(p);       double c = cos(angle), s = sin(angle);       return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);     }   };   struct line {     point a, b;     line() {}     line(point _a, point _b) {       a = _a;       b = _b;     }     bool operator==(line v) { return (a == v.a) && (b == v.b); }     line(point p, double angle) {       a = p;       if (dblcmp(angle - pi / 2) == 0) {         b = a.add(point(0, 1));       } else {         b = a.add(point(1, tan(angle)));       }     }     line(double _a, double _b, double _c) {       if (dblcmp(_a) == 0) {         a = point(0, -_c / _b);         b = point(1, -_c / _b);       } else if (dblcmp(_b) == 0) {         a = point(-_c / _a, 0);         b = point(-_c / _a, 1);       } else {         a = point(0, -_c / _b);         b = point(1, (-_c - _a) / _b);       }     }     void input() {       a.input();       b.input();     }     void adjust() {       if (b < a) swap(a, b);     }     double length() { return a.distance(b); }     double angle() {       double k = atan2(b.y - a.y, b.x - a.x);       if (dblcmp(k) < 0) k += pi;       if (dblcmp(k - pi) == 0) k -= pi;       return k;     }     int relation(point p) {       int c = dblcmp(p.sub(a).det(b.sub(a)));       if (c < 0) return 1;       if (c > 0) return 2;       return 3;     }     bool pointonseg(point p) {       return dblcmp(p.sub(a).det(b.sub(a))) == 0 &&              dblcmp(p.sub(a).dot(p.sub(b))) <= 0;     }     bool parallel(line v) { return dblcmp(b.sub(a).det(v.b.sub(v.a))) == 0; }     int segcrossseg(line v) {       int d1 = dblcmp(b.sub(a).det(v.a.sub(a)));       int d2 = dblcmp(b.sub(a).det(v.b.sub(a)));       int d3 = dblcmp(v.b.sub(v.a).det(a.sub(v.a)));       int d4 = dblcmp(v.b.sub(v.a).det(b.sub(v.a)));       if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2;       return (d1 == 0 && dblcmp(v.a.sub(a).dot(v.a.sub(b))) <= 0 ||               d2 == 0 && dblcmp(v.b.sub(a).dot(v.b.sub(b))) <= 0 ||               d3 == 0 && dblcmp(a.sub(v.a).dot(a.sub(v.b))) <= 0 ||               d4 == 0 && dblcmp(b.sub(v.a).dot(b.sub(v.b))) <= 0);     }     int linecrossseg(line v) {       int d1 = dblcmp(b.sub(a).det(v.a.sub(a)));       int d2 = dblcmp(b.sub(a).det(v.b.sub(a)));       if ((d1 ^ d2) == -2) return 2;       return (d1 == 0 || d2 == 0);     }     int linecrossline(line v) {       if ((*this).parallel(v)) {         return v.relation(a) == 3;       }       return 2;     }     point crosspoint(line v) {       double a1 = v.b.sub(v.a).det(a.sub(v.a));       double a2 = v.b.sub(v.a).det(b.sub(v.a));       return point((a.x * a2 - b.x * a1) / (a2 - a1),                    (a.y * a2 - b.y * a1) / (a2 - a1));     }     double dispointtoline(point p) {       return fabs(p.sub(a).det(b.sub(a))) / length();     }     double dispointtoseg(point p) {       if (dblcmp(p.sub(b).dot(a.sub(b))) < 0 ||           dblcmp(p.sub(a).dot(b.sub(a))) < 0) {         return min(p.distance(a), p.distance(b));       }       return dispointtoline(p);     }     point lineprog(point p) {       return a.add(b.sub(a).mul(b.sub(a).dot(p.sub(a)) / b.sub(a).len2()));     }     point symmetrypoint(point p) {       point q = lineprog(p);       return point(2 * q.x - p.x, 2 * q.y - p.y);     }   };   int N;   line bas[110];   point ret[110];   int main() {     scanf( %d , &N);     if (N < 5) {       puts( No solution );       return 0;     }     double minOO = 249.66 / tan(acos(-1.0) / N);     double maxOO = 250.33 / tan(acos(-1.0) / N);     int i;     srand(23333);     for (i = 1; i <= N; i++) {       int factor = rand();       double len = (maxOO * factor + minOO * (32768 - factor)) / 32768;       bas[i] = line(point(0, 0),                     point(len * cos(2 * pi / N * i), len * sin(2 * pi / N * i)));       bas[i].a = bas[i].a.rotate(bas[i].b, pi / 2);     }     for (i = 1; i <= N; i++) {       ret[i] = bas[i].crosspoint(bas[i % N + 1]);       printf( %.6f %.6f n , ret[i].x, ret[i].y);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   bool check(long long mid) {     long long sum = (mid + k - 1) * (k - mid) / 2;     return (sum >= n - 1);   }   int main() {     scanf( %I64d%I64d , &n, &k);     if (n == 1) {       printf( 0 );       return 0;     }     long long l = 1, r = k - 1, mid;     while (l < r) {       mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     if ((l + k - 1) * (k - l) / 2 >= n - 1)       printf( %I64d , k - l);     else       printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, a = 0, b = 0;     cin >> n;     string str;     cin >> str;     for (int i = 0; i < n - 1; i++) {       if (str[i] ==  S  && str[i + 1] ==  F )         a++;       else if (str[i] ==  F  && str[i + 1] ==  S )         b++;     }     if (a > b)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans;   int main() {     int i, j, k;     scanf( %d , &n);     for (i = k = 0; i < n; i++) {       scanf( %d , &j);       if (j == 0 && k == 0)         continue;       else if (j == 0 && k == 2)         k = 1;       else if (j == 0 && k == 1)         k = 0;       else if (j == 1 && k == 1)         k = 2, ans += 2;       else if (j == 1)         ans++, k = 2;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E5 + 10;   const int INF = 1E9 + 10;   int n;   int a[MAXN][4];   int d[MAXN];   int dis[MAXN], pre[MAXN];   vector<int> lst[MAXN];   int val[MAXN << 2];   int choose(int l, int r) {     return a[lst[l].back()][1] < a[lst[r].back()][1] ? l : r;   }   void build(int u, int l, int r) {     if (l + 1 == r) {       val[u] = l;       return;     }     int m = l + r >> 1;     build(u << 1, l, m);     build(u << 1 | 1, m, r);     val[u] = choose(val[u << 1], val[u << 1 | 1]);   }   int query(int u, int l, int r, int c) {     if (r <= c) return val[u];     int m = l + r >> 1, ret = query(u << 1, l, m, c);     if (m < c) ret = choose(ret, query(u << 1 | 1, m, r, c));     return ret;   }   void update(int u, int l, int r, int c) {     if (l + 1 == r) return;     int m = l + r >> 1;     if (c < m)       update(u << 1, l, m, c);     else       update(u << 1 | 1, m, r, c);     val[u] = choose(val[u << 1], val[u << 1 | 1]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3]);       d[i] = a[i][0];     }     sort(d, d + n);     int m = unique(d, d + n) - d;     for (int i = 0; i < n; ++i)       lst[lower_bound(d, d + m, a[i][0]) - d].push_back(i);     a[n][1] = INF;     a[n][2] = a[n][3] = 0;     for (int i = 0; i < m; ++i) {       lst[i].push_back(n);       sort(lst[i].begin(), lst[i].end(),            [](const int &l, const int &r) { return a[l][1] > a[r][1]; });     }     build(1, 0, m);     queue<int> Q;     dis[n] = 0;     for (int i = 0; i <= n; ++i) pre[i] = -1;     Q.push(n);     while (!Q.empty() && !~pre[n - 1]) {       int u = Q.front();       Q.pop();       int v, r = upper_bound(d, d + m, a[u][2]) - d;       while (r && a[lst[v = query(1, 0, m, r)].back()][1] <= a[u][3]) {         dis[lst[v].back()] = dis[u] + 1;         pre[lst[v].back()] = u;         Q.push(lst[v].back());         lst[v].pop_back();         update(1, 0, m, v);       }     }     if (~pre[n - 1]) {       printf( %d n , dis[n - 1]);       vector<int> ans;       for (int p = n - 1; p < n; p = pre[p]) ans.push_back(p + 1);       for (int i = ans.size() - 1; i >= 0; --i)         printf( %d%c , ans[i],   n  [!!i]);     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[105][105];   string sa[105], sb[105];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> sa[i];     }     sort(sa + 1, sa + n + 1);     for (int i = 1; i <= n; ++i) {       cin >> sb[i];     }     sort(sb + 1, sb + n + 1);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         f[i][j] = max(f[i - 1][j], f[i][j - 1]);         if (sa[i] == sb[j]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);       }     }     cout << n - f[n][n];   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   using ll = long long;   using ld = long double;   using pt = complex<ld>;   constexpr ld EPS = 1e-9;   ld cross(pt a, pt b) { return imag(conj(a) * b); }   ld cross(pt p, pt a, pt b) { return cross(a - p, b - p); }   int orientation(pt a, pt b, pt c) {     ld orien = cross(b - a, c - a);     return (orien > EPS) - (orien < -EPS);   }   bool lineSegmentIntersection(pt a, pt b, pt c, pt d) {     if (orientation(a, b, c) == 0 && orientation(a, b, d) == 0) {       ld dist = abs(a - b);       return (abs(a - c) <= dist && abs(b - c) <= dist) ||              (abs(a - d) <= dist && abs(b - d) <= dist);     }     return orientation(a, b, c) * orientation(a, b, d) <= 0 &&            orientation(c, d, a) * orientation(c, d, b) <= 0;   }   struct seg {     pt a, b;     ll id;     bool operator<(const seg& o) const {       if (real(a) < real(o.a)) {         ld s = cross(a, b, o.a);         return (s > EPS || (abs(s) <= EPS && imag(a) < imag(o.a)));       } else if (real(a) > real(o.a)) {         ld s = cross(o.a, o.b, a);         return (s < EPS || (abs(s) <= EPS && imag(a) < imag(o.a)));       }       return imag(a) < imag(o.a);     }   };   struct event {     pt p;     ll id, type;     bool operator<(const event& o) const {       if (real(p) != real(o.p)) return real(p) < real(o.p);       if (type != o.type) return type > o.type;       return imag(p) < imag(o.p);     }   };   bool lessPs(const pt& a, const pt& b) {     if (real(a) != real(b)) return real(a) < real(b);     return imag(a) < imag(b);   }   bool intersect(const seg& a, const seg& b) {     return lineSegmentIntersection(a.a, a.b, b.a, b.b);   }   pair<int, int> intersect(const vector<seg>& s) {     ll n = (ll)(s).size();     vector<event> e;     e.reserve(2 * n);     for (ll i = 0; i < n; i++) {       e.push_back({s[i].a, i, 1});       e.push_back({s[i].b, i, -1});     }     sort(begin(e), end(e));     set<seg> q;     for (ll i = 0; i < n * 2; i++) {       ll id = e[i].id;       if (e[i].type == 1) {         auto it = q.lower_bound(s[id]);         if (it != q.end() && intersect(*it, s[id])) return {it->id, s[id].id};         if (it != q.begin() && intersect(*prev(it), s[id]))           return {it->id, s[id].id};         q.insert(s[id]);       } else {         auto it = q.lower_bound(s[id]), next = it, prev = it;         if (it != q.begin() && it != --q.end()) {           ++next, --prev;           if (intersect(*next, *prev)) return {next->id, prev->id};         }         q.erase(it);       }     }     return {-1, -1};   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll n;     cin >> n;     vector<pt> p(n), d(n);     for (ll i = 0; i < n; i++) {       ll x, y, dx, dy, s;       cin >> x >> y >> dx >> dy >> s;       p[i] = {(ld)x, (ld)y};       d[i] = {(ld)dx, (ld)dy};       d[i] /= abs(d[i]);       d[i] *= s;     }     ld l = 0;     ld r = 1e10 + 10;     vector<seg> segs(n);     for (ll i = 0; i < 100; i++) {       ld mid = (l + r) / 2;       for (ll j = 0; j < n; j++) {         segs[j] = {p[j], p[j] + mid * d[j], j};         if (lessPs(segs[j].b, segs[j].a)) swap(segs[j].b, segs[j].a);       }       if (intersect(segs).first >= 0) {         r = mid;       } else {         l = mid;       }     }     if (r > 1e10) {       cout <<  No show :(  << endl;     } else {       cout << fixed << setprecision(10) << l << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int len, link;     int nxt[26];     long long val;   };   struct Automaton {     int sz, last;     Node s[200100 * 10];     void init() {       sz = last = 0;       s[0].len = 0;       s[0].link = -1;       s[0].val = 0;       memset(s[0].nxt, 0, sizeof(s[0].nxt));       ++sz;     }     void extend(int c, int cost) {       int cur, p;       if (s[last].nxt[c]) {         cur = s[last].nxt[c];         if (s[cur].len == s[last].len + 1) {           s[cur].val += cost;           last = cur;           return;         }         int clone = sz++;         s[clone] = s[cur];         s[clone].len = s[last].len + 1;         s[clone].val = cost;         s[cur].link = clone;         for (p = last; p != -1 && s[p].nxt[c] == cur; p = s[p].link)           s[p].nxt[c] = clone;         last = clone;         return;       }       cur = sz++;       s[cur].len = s[last].len + 1;       s[cur].val = cost;       for (p = last; p != -1 && !s[p].nxt[c]; p = s[p].link) s[p].nxt[c] = cur;       if (p == -1)         s[cur].link = 0;       else {         int q = s[p].nxt[c];         if (s[p].len + 1 == s[q].len)           s[cur].link = q;         else {           int clone = sz++;           s[clone].len = s[p].len + 1;           memcpy(s[clone].nxt, s[q].nxt, sizeof(s[q].nxt));           s[clone].link = s[q].link;           s[clone].val = 0;           for (; p != -1 && s[p].nxt[c] == q; p = s[p].link) s[p].nxt[c] = clone;           s[q].link = s[cur].link = clone;         }       }       last = cur;     }     int cnt[10 * 200100], st[10 * 200100];     long long solve(int len) {       int i, j;       for (j = 0; j <= len; j++) cnt[j] = 0;       for (j = 0; j < sz; j++) cnt[s[j].len]++;       for (j = 1; j <= len; j++) cnt[j] += cnt[j - 1];       for (j = 0; j < sz; j++) st[cnt[s[j].len]--] = j;       long long ret = 0;       for (i = sz; i >= 1; i--) {         int x = st[i];         if (ret < s[x].val * s[x].len) ret = s[x].val * s[x].len;         int p = s[x].link;         if (p != -1) s[p].val += s[x].val;       }       return ret;     }   } sam;   string str[200100];   int c[200100];   int main() {     int N, i, len = 0;     scanf( %d , &N);     for (i = (0); i < (N); i++) cin >> str[i];     for (i = (0); i < (N); i++) scanf( %d , &c[i]);     sam.init();     for (i = (0); i < (N); i++) {       sam.last = 0;       for (int j = 0; j < str[i].length(); j++) {         sam.extend(str[i][j] -  a , c[i]);       }       if (len < str[i].length()) len = str[i].length();     }     long long ans = sam.solve(len);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   long double ang, ca, PI = acos(-1);   int main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n;       ang = 2 * PI / (2 * n);       ca = 0.5 / tan(ang / 2);       cout << fixed << setprecision(10) << 2 * ca <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int h, m, s, t1, t2;     cin >> h >> m >> s >> t1 >> t2;     h %= 12;     t1 %= 12;     t2 %= 12;     m /= 5;     s /= 5;     if (t1 > t2) swap(t1, t2);     if (((h >= t1 && h < t2) + (m >= t1 && m < t2) + (s >= t1 && s < t2)) % 3 ==         0) {       cout <<  YES ;     } else       cout <<  NO ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int key(int x);   int main() {     int t;     cin >> t;     int str[t];     for (int u = 0; u < t; u++) {       str[u] = key(u);     }     for (int u = 0; u < t; u++) cout << str[u] <<   n ;     return 0;   }   int key(int x) {     int n, k, d, mini = 1000, m = 0;     cin >> n >> k >> d;     int arr[n], c = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int j = 0; j < n - d + 1; j++) {       for (int a = 0; a < d; a++) {         m = 0;         for (int b = 0; b <= a; b++) {           if (arr[j + a] == arr[j + b])             m++;           else             continue;         }         if (m <= 1) c++;       }       mini = min(mini, c);       c = 0;     }     return mini;   }


#include <bits/stdc++.h>   int allocator_pos = 0;   char allocator_memory[(int)1e5];   inline void *operator new(size_t n) {     char *res = allocator_memory + allocator_pos;     allocator_pos += n;     assert(allocator_pos <= (int)1e5);     return (void *)res;   }   inline void operator delete(void *) noexcept {}   template <class T = int>   inline T readInt();   inline double readDouble();   inline int readUInt();   inline int readChar();   inline void readWord(char *s);   inline bool readLine(char *s);   inline bool isEof();   inline int getChar();   inline int peekChar();   inline bool seekEof();   inline void skipBlanks();   template <class T>   inline void writeInt(T x, char end = 0, int len = -1);   inline void writeChar(int x);   inline void writeWord(const char *s);   inline void writeDouble(double x, int len = 0);   inline void flush();   static struct buffer_flusher_t {     ~buffer_flusher_t() { flush(); }   } buffer_flusher;   static const int buf_size = 4096;   static unsigned char buf[buf_size];   static int buf_len = 0, buf_pos = 0;   inline bool isEof() {     if (buf_pos == buf_len) {       buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);       if (buf_pos == buf_len) return 1;     }     return 0;   }   inline int getChar() { return isEof() ? -1 : buf[buf_pos++]; }   inline int peekChar() { return isEof() ? -1 : buf[buf_pos]; }   inline bool seekEof() {     int c;     while ((c = peekChar()) != -1 && c <= 32) buf_pos++;     return c == -1;   }   inline void skipBlanks() {     while (!isEof() && buf[buf_pos] <= 32U) buf_pos++;   }   inline int readChar() {     int c = getChar();     while (c != -1 && c <= 32) c = getChar();     return c;   }   inline int readUInt() {     int c = readChar(), x = 0;     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return x;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - )       s = -1, c = getChar();     else if (c ==  + )       c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   inline double readDouble() {     int s = 1, c = readChar();     double x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     if (c ==  . ) {       c = getChar();       double coef = 1;       while ( 0  <= c && c <=  9 ) x += (c -  0 ) * (coef *= 1e-1), c = getChar();     }     return s == 1 ? x : -x;   }   inline void readWord(char *s) {     int c = readChar();     while (c > 32) *s++ = c, c = getChar();     *s = 0;   }   inline bool readLine(char *s) {     int c = getChar();     while (c !=   n  && c != -1) *s++ = c, c = getChar();     *s = 0;     return c != -1;   }   static int write_buf_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_buf_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;     write_buf[write_buf_pos++] = x;   }   inline void flush() {     if (write_buf_pos) {       fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;       fflush(stdout);     }   }   template <class T>   inline void writeInt(T x, char end, int output_len) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n < output_len) s[n++] =  0 ;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   inline void writeDouble(double x, int output_len) {     if (x < 0) writeChar( - ), x = -x;     int t = (int)x;     writeInt(t), x -= t;     writeChar( . );     for (int i = output_len - 1; i > 0; i--) {       x *= 10;       t = std::min(9, (int)x);       writeChar( 0  + t), x -= t;     }     x *= 10;     t = std::min(9, (int)(x + 0.5));     writeChar( 0  + t);   }   #pragma GCC optimaze( O3,unroll-loops )   #pragma GCC target( sse4,sse3,sse2,sse )   using namespace std;   int a[20005], b[20005], n, m, p;   int dp1[3][20005], dp2[3][20005];   int f(int x, int y) {     int r = a[x] + b[y];     if (r < p)       return r;     else       return r - p;   }   void get_ans(int x1, int y1, int x2, int y2) {     if (x1 == x2) {       for (int i = y1; i < y2; i++) writeChar( S );       return;     }     if (y1 == y2) {       for (int i = x1; i < x2; i++) writeChar( C );       return;     }     int mid = (x1 + y1 + x2 + y2) / 2;     dp1[0][x2] = f(n - x2, m - y2);     int x = 0, y = 0, i1, i2;     for (i1 = x2 + y2, i2 = x1 + y1; i1 > mid && i2 < mid; i1--, i2++) {       for (int j = max(x1, i1 - y2); j <= min(x2, i1 - y1); j++) {         int z = i1 - j;         if (j != x1)           dp1[x ^ 1][j - 1] =               max(dp1[x ^ 1][j - 1], dp1[x][j] + f(n - j + 1, m - z));         if (z != y1)           dp1[x ^ 1][j] = max(dp1[x ^ 1][j], dp1[x][j] + f(n - j, m - z + 1));         dp1[x][j] = 0;       }       x ^= 1;       for (int j = max(x1, i2 - y2); j <= min(x2, i2 - y1); j++) {         int z = i2 - j;         if (j != x2)           dp2[y ^ 1][j + 1] = max(dp2[y ^ 1][j + 1], dp2[y][j] + f(n - j, m - z));         if (z != y2)           dp2[y ^ 1][j] = max(dp2[y ^ 1][j], dp2[y][j] + f(n - j, m - z));         dp2[y][j] = 0;       }       y ^= 1;     }     if (i1 > mid) {       for (int j = max(x1, i1 - y2); j <= min(x2, i1 - y1); j++) {         int z = i1 - j;         if (j != x1)           dp1[x ^ 1][j - 1] =               max(dp1[x ^ 1][j - 1], dp1[x][j] + f(n - j + 1, m - z));         if (z != y1)           dp1[x ^ 1][j] = max(dp1[x ^ 1][j], dp1[x][j] + f(n - j, m - z + 1));         dp1[x][j] = 0;       }       x ^= 1;     }     if (i2 < mid) {       for (int j = max(x1, i2 - y2); j <= min(x2, i2 - y1); j++) {         int z = i2 - j;         if (j != x2)           dp2[y ^ 1][j + 1] = max(dp2[y ^ 1][j + 1], dp2[y][j] + f(n - j, m - z));         if (z != y2)           dp2[y ^ 1][j] = max(dp2[y ^ 1][j], dp2[y][j] + f(n - j, m - z));         dp2[y][j] = 0;       }       y ^= 1;     }     int posx = -1, tek = -1;     for (int i = max(x1, mid - y2); i <= min(x2, mid - y1); i++) {       if (tek < dp1[x][i] + dp2[y][i]) posx = i, tek = dp1[x][i] + dp2[y][i];       dp1[x][i] = 0, dp2[y][i] = 0;     }     if (x1 == 1 && y1 == 1 && x2 == n && y2 == m) {       writeInt(tek);       writeChar(  n );     }     get_ans(posx, mid - posx, x2, y2);     get_ans(x1, y1, posx, mid - posx);     return;   }   int main() {     n = readInt();     m = readInt();     p = readInt();     for (int i = 0; i < n; i++) {       a[i] = readInt();       a[i] %= p;     }     for (int i = 0; i < m; i++) {       b[i] = readInt();       b[i] %= p;     }     if (n == 1) {       int ans = 0;       for (int i = 0; i < m; i++) ans += f(0, i);       writeInt(ans);       writeChar(  n );       for (int i = 1; i < m; i++) writeChar( S );       exit(0);     }     if (m == 1) {       int ans = 0;       for (int i = 0; i < n; i++) ans += f(i, 0);       writeInt(ans);       writeChar(  n );       for (int i = 1; i < n; i++) writeChar( C );       exit(0);     }     get_ans(1, 1, n, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200];     int t, n, x;     for (int i = 0; i <= 100; i++) a[i] = 0;     for (int i = 0; i <= 100; i++)       for (int j = 0; j <= 100; j++) {         t = 3 * i + 7 * j;         if (t > 100) break;         a[t] = 1;       }     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (a[x] == 0) cout <<  NO  << endl;       if (a[x] == 1) cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   inline t read(t &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0) {       putchar( - ), write(-x);     } else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int N = 1e5 + 5, M = 1e4 + 5, NM = N * 4 + M, TR = NM << 2;   int n, m, pt[NM], pn;   double p[TR], ans;   struct tree {     int x, h, l, r;   } a[N];   struct mushroom {     int x, v;   } b[M];   void build(int x, int l, int r) {     p[x] = 1;     if (l == r) return;     int mid = l + r >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   void up(int x, int l, int r, int L, int R, double v) {     if (L <= l && r <= R) {       p[x] *= v;       return;     }     int mid = l + r >> 1;     if (L <= mid) up(x << 1, l, mid, L, R, v);     if (R > mid) up(x << 1 | 1, mid + 1, r, L, R, v);   }   double que(int x, int l, int r, int pos) {     if (l == r) return p[x];     int mid = l + r >> 1;     if (pos <= mid) return p[x] * que(x << 1, l, mid, pos);     return p[x] * que(x << 1 | 1, mid + 1, r, pos);   }   signed main() {     read(n);     read(m);     for (int i = 1; i <= n; i++) {       read(a[i].x);       read(a[i].h);       read(a[i].l);       read(a[i].r);       pt[++pn] = a[i].x - a[i].h;       pt[++pn] = a[i].x - 1;       pt[++pn] = a[i].x + 1;       pt[++pn] = a[i].x + a[i].h;     }     for (int i = 1; i <= m; i++) {       read(b[i].x);       read(b[i].v);       pt[++pn] = b[i].x;     }     sort(pt + 1, pt + 1 + pn);     pn = unique(pt + 1, pt + 1 + pn) - pt - 1;     build(1, 1, pn);     for (int i = 1; i <= n; i++) {       up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x - a[i].h) - pt,          lower_bound(pt + 1, pt + 1 + pn, a[i].x - 1) - pt, 1.0 - 0.01 * a[i].l);       up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x + 1) - pt,          lower_bound(pt + 1, pt + 1 + pn, a[i].x + a[i].h) - pt,          1.0 - 0.01 * a[i].r);     }     for (int i = 1; i <= m; i++)       ans +=           que(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, b[i].x) - pt) * b[i].v;     printf( %.10lf , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 3e5 + 10;   const long long MAXE = 3e5 + 10;   const long long INF = 2e18 + 3;   long long n, m, k, ec;   long long from[2 * MAXE], to[2 * MAXE], prv[2 * MAXE], w[2 * MAXE], head[MAXN],       sec[2 * MAXE];   long long comp[MAXN], d[MAXN], ss[MAXN];   bool portal[MAXN], mark[MAXN];   set<pair<long long, long long>> st;   long long ans = 0;   void add_edge(long long u, long long v, long long c) {     from[ec] = u, to[ec] = v, w[ec] = c, prv[ec] = head[u];     head[u] = ec++;   }   long long get_min() {     pair<long long, long long> fr = *st.begin();     st.erase(st.begin());     return fr.second;   }   void update(long long v) {     mark[v] = 1;     for (long long e = head[v]; e != -1; e = prv[e]) {       long long u = to[e], c = w[e];       if (!mark[u] && d[u] > w[e] + d[v]) {         st.erase({d[u], u});         d[u] = d[v] + w[e];         st.insert({d[u], u});         ss[u] = ss[v];       }     }   }   void dijk() {     fill(d, d + MAXN, INF);     memset(ss, -1, sizeof(ss));     for (long long i = 0; i < n; i++)       if (portal[i]) mark[i] = 1, d[i] = 0, ss[i] = i;     for (long long i = 0; i < n; i++)       if (portal[i]) update(i);     while (st.size()) update(get_min());   }   bool cmp(long long e1, long long e2) {     if (w[e1] != w[e2]) return w[e1] < w[e2];     return e1 < e2;   }   long long get_comp(long long v) {     if (comp[v] == v) return v;     return comp[v] = get_comp(comp[v]);   }   void merge(long long e) {     if (get_comp(ss[to[e]]) == get_comp(ss[from[e]])) return;     ans += w[e];     comp[get_comp(ss[to[e]])] = get_comp(ss[from[e]]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     memset(head, -1, sizeof(head));     while (m--) {       long long a, b, c;       cin >> a >> b >> c;       a--, b--;       add_edge(a, b, c);       add_edge(b, a, c);     }     cin >> k;     while (k--) {       long long temp;       cin >> temp, temp--, portal[temp] = 1;     }     dijk();     ans = d[0];     iota(comp, comp + n, 0);     iota(sec, sec + ec, 0);     for (int i = 0; i < ec; i++) w[i] += d[from[i]] + d[to[i]];     sort(sec, sec + ec, cmp);     for (long long e = 0; e < ec; e++) merge(sec[e]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool hs(int mask, int i) { return mask & (1 << i); }   int dp[300000];   void dfs2(vector<int> &adj, int i, int &c) {     c++;     dp[i] = 3;     int u = adj[i];     if (dp[u] == 3) {       return;     }     dfs2(adj, u, c);   }   void dfs(vector<int> &adj, int i, int &c) {     dp[i] = 2;     int u = adj[i];     if (dp[u] == 0) {       dfs(adj, u, c);     } else if (dp[u] == 2) {       dfs2(adj, i, c);     }     dp[i] = 1;   }   int main() {     int n, t;     cin >> n;     t = n;     long long m = 1000000007;     vector<int> adj;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       a--;       adj.push_back(a);     }     memset(dp, 0, sizeof(dp));     long long ans = 1, k = 1;     vector<long long> v(200005);     for (int i = 0; i < v.size(); i++) {       v[i] = k;       k = k * 2ll;       k = k % m;     }     for (int i = 0; i < n; i++) {       int c = 0;       if (dp[i] == 0) {         dfs(adj, i, c);         t = t - c;         if (c > 1) {           ans = ans * (v[c] - 2ll);           ans = ans % m;         }       }     }     ans = ans * v[t];     ans = ans % m;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int MAXN = 100005;   const long long MOD = 1000000007;   void base() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   pair<int, int> arr[100005];   int occ[100005];   int main() {     base();     int n, k, temp, need = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> temp;       arr[i].second = temp;       occ[temp]++;     }     for (int i = 0; i < n; i++) {       cin >> temp;       arr[i].first = temp;     }     for (int i = 1; i <= k; i++) {       if (occ[i] == 0) need++;     }     sort(arr, arr + n);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (occ[arr[i].second] > 1 && need > 0) {         occ[arr[i].second]--;         need--;         ans += (long long)arr[i].first;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, x = 1, y = 1;     cin >> n;     while (n--) {       cin >> s;       if (s ==  ULDR )         x++, y++;       else if (s ==  UR  || s ==  DL )         x++;       else         y++;     }     cout << 1LL * x * y << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int x, y;   int main() {     scanf( %d%d , &x, &y);     int ans = 0, d = 1, xx = 0, yy = 0;     while (true) {       if (yy == y && xx <= x && xx + d >= x) break;       ans++;       xx += d;       if (xx == x && yy <= y && yy + d >= y) break;       ans++;       yy += d;       d++;       if (yy == y && xx - d <= x && xx >= x) break;       ans++;       xx -= d;       if (xx == x && yy - d <= y && yy >= y) break;       ans++;       yy -= d;       d++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     int s = 0, o = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) o = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) s *= 10, s += c -  0 ;     return s * o;   }   const int maxn = 30005;   int gem[maxn];   int a[maxn];   int dp[maxn][601], all, len, n, x;   inline void up(int &a, int b) {     if (a < b) a = b;   }   int main(int argc, char const *argv[]) {     n = getint(), len = getint();     for (int i = 0; i < n; i++) {       x = getint();       gem[x]++;       all = max(all, x);     }     int r = 0;     dp[len][0 + 300] = gem[len] + 1;     for (int i = 0; i <= all; ++i)       for (int j = -300; j < 300; ++j)         if (dp[i][j + 300]) {           r = max(r, dp[i][j + 300] - 1);           if (len + j > 0 && i + len + j - 1 <= all)             up(dp[i + len + j - 1][j - 1 + 300],                dp[i][j + 300] + gem[i + len + j - 1]);           if (i + len + j <= all)             up(dp[i + len + j][j + 300], dp[i][j + 300] + gem[i + len + j]);           if (i + len + j + 1 <= all)             up(dp[i + len + j + 1][j + 1 + 300],                dp[i][j + 300] + gem[i + len + j + 1]);         }     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T f = 0, x = 0;     char c = getchar();     while (!isdigit(c)) f = c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return f ? -x : x;   }   namespace run {   inline char getc() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   const int N = 2e5 + 9;   int head[N], nex[N], to[N], cnt, deg[N];   inline void add(int u, int v) {     deg[v]++, nex[++cnt] = head[u], head[u] = cnt, to[cnt] = v;   }   int n, m, bel[N], tot, dfn[N], num, dwn[N];   inline void dfs(int u) {     dfn[u] = ++num;     for (int i = head[u]; i; i = nex[i]) dfs(to[i]);     dwn[u] = num;   }   struct node {     int x, l, r, v;     explicit node() {}     node(int _x, int _l, int _r, int _v) : x(_x), l(_l), r(_r), v(_v) {}     inline bool operator<(const node &A) const { return x < A.x; }   } q[N << 1];   namespace Seg {   int sum[N << 2], num[N << 2];   inline void pushup(int k, int l, int r) {     if (l == r) return num[k] = sum[k] > 0, void();     if (sum[k])       num[k] = r - l + 1;     else       num[k] = num[(k << 1)] + num[(k << 1 | 1)];   }   inline void modify(int k, int l, int r, int _l, int _r, int v) {     if (_l <= l && r <= _r) return sum[k] += v, pushup(k, l, r);     if (_l <= ((l + r) >> 1)) modify((k << 1), l, ((l + r) >> 1), _l, _r, v);     if (_r > ((l + r) >> 1))       modify((k << 1 | 1), ((l + r) >> 1) + 1, r, _l, _r, v);     pushup(k, l, r);   }   }  // namespace Seg   inline int id(int x, int y) { return (x - 1) * m + y; }   int main() {     n = read<int>(), m = read<int>();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         char c = getc();         if (c ==  D ) {           bel[id(i - 1, j)] = id(i, j), bel[id(i, j)] = id(i - 1, j);           if (i > 2) add(id(i - 2, j), id(i, j));           if (i + 1 <= n) add(id(i + 1, j), id(i - 1, j));         }         if (c ==  R ) {           bel[id(i, j - 1)] = id(i, j), bel[id(i, j)] = id(i, j - 1);           if (j > 2) add(id(i, j - 2), id(i, j));           if (j + 1 <= m) add(id(i, j + 1), id(i, j - 1));         }       }     for (int i = 1; i <= n * m; i++)       if (!deg[i]) dfs(i);     for (int i = 1; i <= n * m; i++) {       int l = dfn[bel[i]], r = dwn[bel[i]];       q[++tot] = node(dfn[i], l, r, 1), q[++tot] = node(dwn[i] + 1, l, r, -1);     }     sort(q + 1, q + tot + 1);     long long ans = 0;     for (int i = 1, j, las = 0; i <= tot; i = j + 1) {       j = i;       while (j + 1 <= tot && q[j + 1].x == q[i].x) j++;       ans += 1LL * (q[i].x - las) * Seg::num[1], las = q[i].x;       for (int k = i; k <= j; k++)         Seg::modify(1, 1, n * m, q[k].l, q[k].r, q[k].v);     }     printf( %lld n , ans >> 1);     return 0;   }   }  // namespace run   int main() { return run::main(); }


#include <bits/stdc++.h>   using namespace std;   int ans1 = 0, ans2 = 0, ans3 = 0, a[100];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i % 3 == 1) ans1 += a[i];       if (i % 3 == 2) ans2 += a[i];       if (i % 3 == 0) ans3 += a[i];     }     if (ans1 >= ans2 && ans1 >= ans3) {       cout <<  chest  << endl;       return 0;     }     if (ans2 >= ans1 && ans2 >= ans3) {       cout <<  biceps  << endl;       return 0;     }     if (ans3 >= ans1 && ans3 >= ans2) {       cout <<  back  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline const int getint() {     int r = 0, k = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) k = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ;     return k * r;   }   const int N = 1e5 + 10;   char s[N];   int n;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     int sum = 0, x = 0, y = 0, z = 0, need = 0;     for (int i = (1); i <= (n); ++i)       if (s[i] ==  ( )         ++x;       else if (s[i] ==  ) )         ++y;       else         ++z;     need = x - y - (z - 1);     if (need <= 0 && z) {       puts( -1 );       return 0;     }     int now = z;     for (int i = (n); i >= (1); --i) {       if (s[i] ==  ( )         ++sum;       else if (s[i] ==  ) )         --sum;       else {         if (now == z) {           sum -= need;         } else {           sum--;         }         --now;       }       if (sum > 0) {         puts( -1 );         return 0;       }     }     if (sum != 0) {       puts( -1 );       return 0;     }     now = 0;     for (int i = (1); i <= (n); ++i) {       if (s[i] ==  # ) {         ++now;         if (now == z)           printf( %d n , need);         else           puts( 1 );       }     }     return 0;   }


#include<bits/stdc++.h>   #define inf 0x3f3f3f   using namespace std;   typedef long long ll;   const int maxn = 3e5+5;   const int mod = 1e9+7;   int a[maxn],b[maxn];   int main()   {    int T;    cin>>T;    while(T--){     int n;     cin>>n;     for(int i=1;i<=n;i++) cin>>a[i];     for(int j=1;j<=n;j++) cin>>b[j];     int cnt1=0,cnt2=0;     vector<int> v1,v2;     for(int i=1;i<=n;i++){      if(a[i]>b[i]){       cnt1+=a[i]-b[i];        for(int j=0;j<a[i]-b[i];j++) v1.push_back(i);      }      else{       cnt2+=b[i]-a[i];       for(int j=0;j<b[i]-a[i];j++) v2.push_back(i);      }     }     if(cnt1!=cnt2){      cout<< -1 n ;      continue;     }     cout<<v1.size()<<  n ;     for(int i=0;i<v1.size();i++){      cout<<v1[i]<<   <<v2[i]<<  n ;     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, m, z, ck = 0;     cin >> n >> m >> z;     for (i = 1; i <= z; i++) {       if (n * i > z)         break;       else if ((n * i) % m == 0) {         ck++;       }     }     cout << ck << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1700;   int n, m, tim, res[N * N], num[N * N], a[N][N], s[N][N], id[N][N];   bool ray[N][N];   bool check(int x, int y) {     return s[x + 3][y + 3] - s[x - 4][y + 3] - s[x + 3][y - 4] +                s[x - 4][y - 4] <=            15;   }   void dfs1(int x, int y) {     if (id[x][y] || !a[x][y]) return;     id[x][y] = *res;     dfs1(x - 1, y);     dfs1(x + 1, y);     dfs1(x, y - 1);     dfs1(x, y + 1);   }   void dfs2(int x, int y) {     if (!a[x][y] || ray[x][y]) return;     if (!check(x, y)) {       if (num[id[x][y]] != tim) {         num[id[x][y]] = tim;         res[id[x][y]]++;       }       return;     }     ray[x][y] = true;     dfs2(x - 1, y);     dfs2(x + 1, y);     dfs2(x, y - 1);     dfs2(x, y + 1);   }   int main() {     scanf( %d%d , &n, &m);     n += 5;     m += 5;     for (int i = 6; i <= n; i++)       for (int j = 6; j <= m; j++) scanf( %d , &a[i][j]);     n += 5;     m += 5;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && !id[i][j]) {           ++*res;           dfs1(i, j);         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && !ray[i][j] && check(i, j)) {           ++tim;           dfs2(i, j);         }     sort(res + 1, res + *res + 1);     printf( %d n , *res);     for (int i = 1; i <= *res; i++) printf( %d  , res[i]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void join(vector<T>& arr, string sep) {     bool first = true;     for (auto t : arr) {       if (first) {         first = false;         cout << t;       } else {         cout << sep << t;       }     }     cout <<   n ;   }   struct Euler {     vector<vector<pair<long long, long long>>> g;     long long n;     vector<long long> path;     long long edge_count;     Euler(long long n) : n(n) {       g.resize(n);       edge_count = 0;     }     void addEdge(long long u, long long v) {       long long w = edge_count++;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     bool compute() {       int first = 0;       while (first < n && g[first].empty()) first++;       if (first == n) return true;       long long v1 = -1, v2 = -1;       for (long long u = 0; u < (long long)(n); ++u) {         if (g[u].size() & 1) {           return false;         }       }       if (v1 != -1) {         assert(v2 != -1);       }       vector<long long> visited(edge_count);       vector<long long> s = {first};       while (!s.empty()) {         long long u = s.back();         long long v;         while (true) {           if (g[u].empty()) {             v = -1;             path.push_back(u);             s.pop_back();             break;           }           long long v = g[u].back().first;           long long w = g[u].back().second;           g[u].pop_back();           if (visited[w]) {             continue;           }           visited[w] = true;           s.push_back(v);           break;         }       }       if (v1 != -1) {         for (long long i = 0; i < (long long)(path.size() - 1); ++i) {           if ((path[i] == v1 && path[i + 1] == v2) ||               (path[i] == v2 && path[i + 1] == v1)) {             vector<long long> res;             for (long long j = (long long)(i + 1); j < (long long)(path.size());                  ++j) {               res.push_back(path[j]);             }             for (long long j = (long long)(1); j < (long long)(i + 1); ++j) {               res.push_back(path[j]);             }             path = res;             break;           }         }       }       for (long long u = 0; u < (long long)(n); ++u) {         if (!g[u].empty()) {           return false;         }       }       return true;     }   };   long long getPref(long long c, long long i) { return ((1 << i) - 1) & c; }   struct PairHash {     int operator()(const pair<long long, long long>& pp) const {       const int p = 31;       const int m = 1e9 + 9;       long long l = pp.first;       long long r = (pp.second * p) % m;       return (l + r) % m;     }   };   void solve() {     long long n;     cin >> n;     vector<pair<long long, long long>> colors(n);     for (long long i = 0; i < (long long)(n); ++i) {       long long a, b;       cin >> a >> b;       colors[i] = {a, b};     }     vector<long long> res;     for (long long i = (long long)(1); i < (long long)(2 * n + 1); ++i) {       res.push_back(i);     }     long long lowest = 0;     long long l = 1;     long long r = 20;     while (l <= r) {       long long i = l + (r - l) / 2;       unordered_map<pair<long long, long long>,                     vector<pair<long long, long long>>, PairHash>           nodes2Idx;       Euler e(1 << i);       for (long long j = 0; j < (long long)(n); ++j) {         long long pref1 = getPref(colors[j].first, i);         long long pref2 = getPref(colors[j].second, i);         long long idx1 = 2 * j + 1;         long long idx2 = 2 * j + 2;         if (pref1 > pref2) {           swap(pref1, pref2);           swap(idx1, idx2);         }         nodes2Idx[{pref1, pref2}].push_back({idx1, idx2});         e.addEdge(pref1, pref2);       }       if (!e.compute()) {         r = i - 1;         continue;       }       l = i + 1;       lowest = i;       assert(e.path.size() == n + 1);       for (long long j = 0; j < (long long)(n); ++j) {         long long pref1 = e.path[j];         long long pref2 = e.path[j + 1];         bool swaped = false;         if (pref1 > pref2) {           swap(pref1, pref2);           swaped = true;         }         auto it = nodes2Idx.find({pref1, pref2});         pair<long long, long long> idxPair = it->second.back();         it->second.pop_back();         long long idx1 = idxPair.first;         long long idx2 = idxPair.second;         if (swaped) swap(idx1, idx2);         res[2 * j] = idx1;         res[2 * j + 1] = idx2;       }     }     cout << lowest <<   n ;     join(res,    );   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[111000], s, ans[111000];   int main() {     cin >> n >> k;     for (register int i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     if (s % k != 0) {       cout <<  No ;       return 0;     }     int t = s / k;     int cnt = 0;     for (register int i = 1; i <= n;) {       int sum = 0, tmp = 0;       while (sum < t) {         sum += a[i];         i++;         tmp++;       }       if (sum != t) {         cout <<  No ;         return 0;       }       ans[++cnt] = tmp;     }     cout <<  Yes  << endl;     for (register int i = 1; i <= cnt; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w[100001];   int main() {     map<string, int> mp;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> w[i];     }     sort(w, w + n);     string s;     for (int i = 0; i < m; i++) {       cin >> s;       mp[s]++;     }     int a[101], k = 0;     for (map<string, int>::iterator i = mp.begin(); i != mp.end(); i++) {       a[k++] = (*i).second;     }     sort(a, a + k);     long long s1 = 0, p = 0;     for (int i = 0; i < k; i++) {       s1 += a[k - i - 1] * w[i];       p += a[k - i - 1] * w[n - i - 1];     }     cout << s1 <<     << p;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 2e6 + 10;   const int Mod = 1e9 + 7;   const int MAX = 2e18;   int main() {     long long int x, j = 0, mx = 0, mx2 = 0, cnt = 0;     bool f = 0, f2 = 0, f3 = 0;     string s;     cin >> x >> s;     long long int ar[x + 5];     memset(ar, 0, sizeof(ar));     ;     for (int i = 0; i < x; i++) {       if (s[i] ==  G ) {         ar[j]++;         f2 = 1;         cnt++;         if (f == 1) {           f3 = 1;         }       } else {         f = 1;         if (i != x - 1) {           j++;         }       }     }     if (f == 0) {       cout << x << endl;       ;       return 0;     }     if (f2 == 0) {       cout << 0 << endl;       ;       return 0;     }     if (f3 == 0) {       cout << cnt << endl;       ;       return 0;     }     for (int i = 0; i < j + 1; i++) {       if (ar[i + 1] == 0) {         mx2 = max(mx2, ar[i]);         ar[i] = 0;         i++;         continue;       }       mx2 = max(mx2, ar[i]);       ar[i] = ar[i] + ar[i + 1];       mx = max(mx, ar[i]);     }     if (mx2 > mx) {       if (mx2 < cnt) {         cout << mx2 + 1 << endl;         ;       } else {         cout << mx2 << endl;         ;       }     } else if (cnt > mx) {       cout << mx + 1 << endl;       ;     } else {       cout << mx << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     if (n <= 30)       cout <<  NO n ;     else {       cout <<  YES n ;       long long d = n - 30;       long long a = 6, b = 10, c = 14;       if (d == 6 || d == 10 || d == 14)         cout <<  6 10 15   << d - 1 << endl;       else         cout <<  6 10 14   << d << endl;     }   }   signed main() {     long long t;     cin >> t;     while (t--) solve();     return 0;   }