#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300;   char s[MAXN];   int n;   void solve() {     int maxv = 0, x = 0, y = 0, sum = 0, f = 0;     s[n++] =  _ ;     s[n] = 0;     for (int i = 0; i < n; ++i) {       if (!f) {         if (s[i] ==  _ ) {           x = 0;         } else if (s[i] !=  ( ) {           x++;           maxv = max(maxv, x);         } else {           f = 1;           x = 0;         }       } else {         if (s[i] ==  _ ) {           if (y) sum++;           y = 0;         } else if (s[i] !=  ) ) {           y++;         } else {           if (y) sum++;           f = 0, y = 0;         }       }     }     printf( %d %d n , maxv, sum);   }   int main() {     while (~scanf( %d%s , &n, s)) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, num, maxs = INT_MIN, mins = INT_MAX, mins2 = INT_MAX;     cin >> n >> m;     vector<int> v1;     vector<int> v2;     for (int i = 0; i < n; i++) {       cin >> num;       v1.push_back(num);       maxs = max(maxs, num);       mins2 = min(mins2, num);     }     for (int i = 0; i < m; i++) {       cin >> num;       v2.push_back(num);       if (num <= maxs) {         cout <<  -1 ;         return 0;       }       mins = min(mins, num);     }     for (int i = 0; i < n; i++) {       if (2 * v1[i] <= maxs) {         cout << maxs;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (2 * mins2 <= mins - 1) {         cout << 2 * mins2;         return 0;       }       if (2 * v1[i] <= mins - 1) {         cout << mins - 1;         return 0;       }     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r = 0, m = 0;     string s;     cin >> n;     while (!cin.eof()) {       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (int(s[i]) > 64 && int(s[i]) < 91) {           r++;         }       }       if (r > m) {         m = r;       }       r = 0;     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 212345, OFFSET = 3;   struct BITree {     long long a[MAXN];     void clear() { memset(a, 0, sizeof(a)); }     int lowbit(int i) { return (i & -i); }     long long sum(int i) {       long long ret = 0;       for (i += OFFSET; i > 0; i -= lowbit(i)) ret += a[i];       return ret;     }     void add(int i, long long d) {       for (i += OFFSET; i < MAXN; i += lowbit(i)) a[i] += d;     }   } cnt, sum;   int h[MAXN];   vector<pair<int, long long> > qq;   vector<int> H;   int find(int h) { return lower_bound(H.begin(), H.end(), h) - H.begin(); }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < int(n); i++) scanf( %d , h + i);     qq.resize(q);     H = vector<int>(h, h + n);     for (int i = 0; i < int(q); i++) {       int t;       scanf( %d , &t);       if (t == 1) {         int p, x;         scanf( %d%d , &p, &x);         qq[i].first = p - 1;         qq[i].second = x;         H.push_back(x);       } else {         long long v;         scanf( %I64d , &v);         qq[i].first = -1;         qq[i].second = v;       }     }     sort(H.begin(), H.end());     H.resize(unique(H.begin(), H.end()) - H.begin());     cnt.clear();     sum.clear();     for (int i = 0; i < int(n); i++) {       h[i] = find(h[i]);       cnt.add(h[i], 1);       sum.add(h[i], H[h[i]]);     }     for (int i = 0; i < int(q); i++) {       if (~qq[i].first) {         int j = qq[i].first;         cnt.add(h[j], -1);         sum.add(h[j], -H[h[j]]);         h[j] = find(qq[i].second);         cnt.add(h[j], 1);         sum.add(h[j], H[h[j]]);       } else {         long long v = qq[i].second;         int l = 0, r = H.size() - 1;         while (l < r) {           int m = (l + r + 1) / 2;           int tot = cnt.sum(m);           long long vol = sum.sum(m);           if (H[m] * (long long)tot - vol < v)             l = m;           else             r = m - 1;         }         int tot = cnt.sum(l);         long long vol = sum.sum(l);         printf( %.10f n ,                H[l] + (v - (H[l] * (long long)tot - vol)) / (double)tot);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     long long sum = 0;     for (long long i = 0; i < m; i++) {       if (a[i] <= 0) sum += a[i];     }     if (sum <= 0) {       cout << abs(sum);     } else {       cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   bool g[MAXN][MAXN];   bool mh[MAXN], mv[MAXN];   bool use[MAXN];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a][b] = true;       mv[a] = true;       mh[b] = true;     }     int ans = 0;     for (int i = 1; i < n - 1; i++) ans += !mh[i] + !mv[i];     if (n % 2 && !mh[n / 2] && !mv[n / 2]) ans--;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long int> > v, dp;   long long int ans, k;   void dfs(long long int u, long long int par) {     long long int i;     dp[u][0] = 1;     for (auto it : v[u]) {       if (it == par) continue;       dfs(it, u);       for (i = 1; i <= k; i++) ans += dp[it][i - 1] * dp[u][k - i];       for (i = 1; i <= k; i++) dp[u][i] += dp[it][i - 1];     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, i, x, y;       cin >> n >> k;       v.resize(n + 1);       dp.resize(n + 1, vector<long long int>(k + 1));       ans = 0;       for (i = 1; i < n; i++) {         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);       }       dfs(1, 0);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e4 + 1;   int n, m, x[N], y[N], freq[N], q[N], vis[N], match[N], T, ans[N];   vector<int> g[N];   bool get(int u) {     vis[u] = T;     for (auto i : g[u]) {       if (match[i] != -1 && vis[match[i]] == T) continue;       if (match[i] == -1 || get(match[i])) {         match[i] = u;         return 1;       }     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     if (!m) return puts( 0 ), 0;     memset(match, -1, sizeof match);     for (int i = 0; i < m; i++)       scanf( %d %d , x + i, y + i), x[i], y[i], freq[x[i]]++, freq[y[i]]++;     int id = n + 1;     for (int i = 0; i < m; i++) {       g[x[i]].push_back(id);       g[y[i]].push_back(id++);     }     int can = 0;     queue<int> q;     for (int i = 1; i <= n; i++) q.push(i);     while (q.size()) {       int x = q.front();       q.pop();       if (freq[x]) {         freq[x]--;         T++;         if (get(x)) q.push(x), ans[x]++;       }     }     for (int i = 1; i <= n; i++) can = max(can, ans[i]);     printf( %d n , can);     for (int i = 0; i < m; i++)       if (match[i + n + 1] == y[i])         printf( %d %d n , y[i], x[i]);       else         printf( %d %d n , x[i], y[i]);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int kMod = 998244353;   int inv(int b) {     int e = kMod - 2;     int r = 1;     while (e) {       if (e % 2) r = 1LL * r * b % kMod;       b = 1LL * b * b % kMod;       e /= 2;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k, c;     cin >> n >> k >> c;     vector<int> a(n), mx(n, 0);     int all = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       for (int j = 0; j <= k; ++j) {         mx[i] = max(mx[i], (a[i] ^ (a[i] - j)));       }       all ^= a[i];     }     vector<int> order(n);     iota(order.begin(), order.end(), 0);     sort(order.begin(), order.end(), [&](int a, int b) { return mx[a] < mx[b]; });     vector<vector<int>> comb(2 * k + 1, vector<int>(2 * k + 1, 0));     for (int i = 0; i <= 2 * k; ++i) {       comb[i][0] = comb[i][i] = 1;       for (int j = 1; j < i; ++j) {         comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % kMod;       }     }     vector<vector<long long>> dp(k + 1, vector<long long>(1 << c, 0));     dp[0][0] = 1;     int lim = 1;     for (auto it : order) {       for (int j = k; j >= 0; --j) {         for (int i = 1; i + j <= k; ++i) {           int val = (a[it] ^ (a[it] - i)) / 2;           for (int x = 0; x < lim; ++x)             dp[i + j][x ^ val] += comb[i + j][j] * dp[j][x];         }       }       for (int j = 0; j <= k; ++j) {         int val = (a[it] ^ (a[it] - j)) / 2;         while (lim <= val) lim *= 2;       }       for (int j = 0; j <= k; ++j)         for (int x = 0; x < lim; ++x) dp[j][x] %= kMod;     }     int sub = 1, invn = inv(n);     for (int i = 0; i < k; ++i) sub = 1LL * sub * invn % kMod;     for (int i = 0; i < (1 << c); ++i) {       int par = (k + all + i) % 2;       if (par)         cout << 0 <<    ;       else         cout << (dp[k][(i ^ all) / 2] * sub) % kMod <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n], odd = 0, even = 0;     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       if (arr[i] % 2)         odd++;       else         even++;     }     sort(arr, arr + n);     reverse(arr, arr + n);     long long ans = 0;     bool b = odd % 2;     for (int i = 0; i < n; i++) {       if (!b) {         ans += arr[i];       } else {         if (arr[i] % 2 && odd > 1) {           ans += arr[i];           odd--;         } else if (arr[i] % 2 == 0) {           ans += arr[i];         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(NULL);     int m, n;     cin >> m >> n;     set<int> v[m];     for (int i = 0; i < m; i++) {       int s;       cin >> s;       for (int j = 0; j < s; j++) {         int x;         cin >> x;         v[i].insert(x);       }     }     for (int i = 0; i < m; i++) {       for (int j = i + 1; j < m; j++) {         int cnt = 0;         for (auto it : v[i]) {           if (v[j].find(it) != v[j].end()) {             cnt = 1;             break;           }         }         if (cnt == 0) {           cout <<  impossible ;           exit(0);         }       }     }     cout <<  possible ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     Point() {}     Point(long long x0, long long y0) : x(x0), y(y0) {}     void in() { scanf( %I64d %I64d , &x, &y); }     long long operator*(Point pt) { return x * pt.y - y * pt.x; }     Point operator-(Point pt) { return Point(x - pt.x, y - pt.y); }     Point operator+(Point pt) { return Point(x + pt.x, y + pt.y); }   } p[1000010];   int n;   long long solve(Point o) {     long long ans = 0;     int i, j;     i = j = 1;     while (i <= n) {       while (i == j || (p[j + 1] - p[i]) * (o - p[i]) >= 0) j++;       ans += (long long)(j - i) * (j - i - 1) / 2;       i++;     }     return ans;   }   bool In_Polygon(Point o) {     for (int i = 1; i <= n; i++)       if ((p[i + 1] - p[i]) * (o - p[i]) <= 0) return false;     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) p[i].in();     for (int i = n + 1; i <= n + n; i++) p[i] = p[i - n];     reverse(p + 1, p + n + n + 1);     int cas;     scanf( %d , &cas);     for (int cc = 1; cc <= cas; cc++) {       Point o;       o.in();       if (!In_Polygon(o))         cout << 0 << endl;       else         cout << (long long)n * (n - 1) * (n - 2) / 6 - solve(o) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> L[200005], W[200005];   vector<pair<long long, int> > path;   int a[200005], add[200005], rmv[200005];   int res[200005];   void DFS(int u, long long dis) {     int v, w, rem1 = 0, rem2 = 0;     path.push_back(make_pair(dis, u));     for (int i = 0; i < L[u].size(); i++) {       v = L[u][i];       w = W[u][i];       DFS(v, dis + W[u][i]);       rem1 += add[v];       rem2 += rmv[v];     }     int pos = lower_bound(path.begin(), path.end(), make_pair(dis - a[u], -1)) -               path.begin();     if (pos != path.size() && path[pos].first >= dis - a[u]) {       v = path[pos].second;       rmv[v]--;       add[u]++;     }     path.pop_back();     res[u] = rem1 + rem2;     add[u] += rem1;     rmv[u] += rem2;   }   int main() {     int n, u, v, w;     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n - 1; i++) {       u = i;       scanf( %d%d , &v, &w);       v--;       L[v].push_back(u);       W[v].push_back(w);     }     DFS(0, 0);     for (int i = 0; i < n; i++) {       if (i) printf(   );       printf( %d , res[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   long long getint() {     long long summ = 0, f = 1;     char ch;     for (ch = getchar(); !isdigit(ch) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) {       f = -1;       ch = getchar();     }     for (; isdigit(ch); ch = getchar())       summ = (summ << 3) + (summ << 1) + ch - 48;     return summ * f;   }   long long n, m, a[200005], ans, k, s[200004];   priority_queue<long long> q;   signed main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = n; i; i--) {       if (a[i] < 0)         q.push(a[i]);       else {         while (!q.empty() && a[i] >= 0) {           a[i] += q.top();           q.pop();         }         if (a[i] < 0) q.push(a[i]);       }     }     long long tot = 0;     while (!q.empty()) {       s[++tot] = q.top();       q.pop();     }     for (long long i = 1; i <= tot; i++) {       s[i] = -s[i] + s[i - 1];     }     for (long long i = 1, x; i <= m; i++) {       x = getint();       cout << tot + 1 - (upper_bound(s + 1, s + 1 + tot, x) - s) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   struct edge {     long long to;     long long cost;   };   vector<edge> mp[maxn];   long long dis[maxn];   long long vis[maxn];   long long dis1[maxn];   long long a[maxn];   long long b[maxn];   long long N, M, k;   long long cot[maxn];   bool SPFA(long long s, long long N) {     memset(vis, 0, sizeof(vis));     memset(cot, 0, sizeof(cot));     for (int i = 0; i <= N; i++) {       dis[i] = 1000000000000000000;       ;     }     priority_queue<long long> q;     dis[s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.top();       q.pop();       vis[u] = 0;       for (int v = 0; v < mp[u].size(); v++) {         int to = mp[u][v].to;         if (dis[u] + mp[u][v].cost < dis[to]) {           dis[to] = dis[u] + mp[u][v].cost;           if (!vis[to]) {             vis[to] = 1;             q.push(to);           }         } else if (dis[to] == dis[u] + mp[u][v].cost) {           cot[to]++;         }       }     }     return true;   }   int main() {     long long u, v, cost;     scanf( %lld %lld %lld , &N, &M, &k);     memset(mp, 0, sizeof(mp));     for (int i = 0; i < M; i++) {       scanf( %lld%lld%lld , &u, &v, &cost);       edge te;       te.to = v;       te.cost = cost;       mp[u].push_back(te);       te.to = u;       te.cost = cost;       mp[v].push_back(te);     }     long long sum = 0;     for (int i = 0; i < k; i++) {       scanf( %lld %lld , &a[i], &b[i]);       edge te;       te.to = a[i];       te.cost = b[i];       mp[1].push_back(te);       te.to = 1;       te.cost = b[i];       mp[a[i]].push_back(te);     }     SPFA(1, N);     for (int i = 0; i < k; i++) {       if (dis[a[i]] < b[i]) {         sum++;       } else if ((dis[a[i]] == b[i])) {         if (cot[a[i]] >= 1) {           sum++;           cot[a[i]]--;         }       }     }     printf( %lld n , sum);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   int main() {     std::ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n, 0);     int ind = 0, length = n + 1;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       if (length > r - l + 1) {         length = r - l + 1;         ind = l - 1;       }     }     for (int i = ind, j = 0; i < n; i++, j++) {       a[i] = j % length;     }     for (int i = ind - 1, j = length - 1; i >= 0;          i--, j = (j - 1 + length) % length)       a[i] = j;     cout << length << endl;     for (auto k : a) cout << k <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, z = 0;     cin >> n;     char *colours = new char[50];     for (int x = 0; x < n; x++) {       cin >> colours[x];     }     for (int i = 0; i < n - 1; i++) {       if (colours[i] == colours[i + 1]) {         z++;       }     }     delete[] colours;     cout << z;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000100;   const int INF = (1 << 29);   const double EPS = 0.000000001;   const double Pi = acos(-1.0);   int n;   long long x[maxn];   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) scanf( %I64d , &x[i]);       sort(x + 1, x + n + 1);       long long ans = 1e12;       for (int i = 1; i + n / 2 <= n; i++) {         long long a = x[i], b = x[i + n / 2];         ans = min(ans, b - a);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 0.000000000000001;   int n, k;   double P[21];   bool eq(long double a, long double b) {     if (abs(a - b) < 0.000000000000001) return true;     return false;   }   bool memo[1 << 21];   long double dp[1 << 21];   long double doit(int msk) {     if (msk == 0) return 1;     if (memo[msk] == true) {       return dp[msk];     }     int i, j;     long double ret = 0, sm = 0;     for (i = 0; i < n; i++) {       if (msk & (1 << i)) {         sm += P[i];       }     }     for (i = 0; i < n; i++) {       if (msk & (1 << i)) {         ret += P[i] * doit(msk ^ ((1 << i))) / (1 - (sm - P[i]));       }     }     memo[msk] = true;     return dp[msk] = ret;   }   long double ans[21];   int main() {     scanf( %d%d , &n, &k);     int i, j, nz = 0;     for (i = 0; i < n; i++) {       scanf( %lf , &P[i]);       if (!eq(P[i], 0)) nz++;       ans[i] = 0;     }     for (i = 0; i < (1 << n); i++) {       if (__builtin_popcount(i) == min(k, nz)) {         int f = 1;         for (j = 0; j < n; j++) {           if (i & (1 << j))             if (eq(0, P[j])) {               f = 0;               break;             }         }         if (!f) continue;         long double x = doit(i);         for (j = 0; j < n; j++) {           if (i & (1 << j)) {             ans[j] += x;           }         }       }     }     for (i = 0; i < n; i++) {       printf( %.15lf  , (double)ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   template <class T1, class T2, class T3>   inline void gn(T1 &x1, T2 &x2, T3 &x3) {     gn(x1, x2), gn(x3);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = (long long)a * a % m)       if (b & 1) ans = (long long)ans * a % m;     return ans;   }   pair<pair<int, int>, int> p[200010];   int first[200010], t[200010], nn;   vector<int> pos[200010], B[200010];   void update(int id, int u, int v) {     for (; u < B[id].size(); u += u & -u) B[id][u] += v;   }   int calc(int id, int u, int ans = 0) {     for (; u; u -= u & -u) ans += B[id][u];     return ans;   }   int main() {     int n;     gn(n);     for (int i = 0; i < n; i++) {       gn(p[i].first.first, p[i].first.second, p[i].second);       first[i] = p[i].second;       t[i] = p[i].first.second;     }     sort(t, t + n);     sort(first, first + n);     nn = unique(first, first + n) - first;     for (int i = 0; i < n; i++) {       p[i].first.second = upper_bound(t, t + n, p[i].first.second) - t;       p[i].second = lower_bound(first, first + nn, p[i].second) - first;       pos[p[i].second].push_back(p[i].first.second);     }     for (int i = 0; i < nn; i++) {       sort(pos[i].begin(), pos[i].end());       B[i].resize(pos[i].size() + 1);     }     for (int i = 0; i < n; i++) {       int a = p[i].first.first, u = p[i].second;       int t = upper_bound(pos[u].begin(), pos[u].end(), p[i].first.second) -               pos[u].begin();       if (a == 1)         update(u, t, 1);       else if (a == 2)         update(u, t, -1);       else         println(calc(u, t));     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     int n;     cin >> n;     set<string> st;     while (n--) {       string s, ss;       cin >> s;       for (int i = s.size() - 1; i >= 0; i--) {         if (s[i] ==  u ) {           ss +=  oo ;         } else if (s[i] ==  h ) {           ss +=  h ;           while (i > 0 && s[i - 1] ==  k ) {             i--;           }         } else {           ss += s[i];         }       }       reverse(ss.begin(), ss.end());       st.insert(ss);     }     cout << st.size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cnt, ans, i, j, temp, flag;   string s, heavy =  heavy , metal =  metal ;   int main() {     cin >> s;     for (i = 0; i < s.length(); i++) {       temp = i;       flag = 0;       for (j = 0; j < 5; j++) {         if (s[temp] == heavy[j])           ++temp;         else           break;       }       if (j == 5) flag = 1, ++cnt;       if (flag) {         i = temp - 2;         continue;       }       temp = i;       for (j = 0; j < 5; j++) {         if (s[temp] == metal[j])           ++temp;         else           break;       }       if (j == 5) flag = 1, ans += cnt;       if (flag) {         i = temp - 2;         continue;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   map<long long int, map<long long int, bool> > my;   int main() {     long long int n;     cin >> n;     my[1][n] = 1;     if (n % 2 == 0) {       cout <<  white  << endl;       cout << 1 <<     << 2 << endl;     } else       cout <<  black  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 5e2 + 10;   int a[N][N];   int b[N][N];   int c[N][N];   int minv[N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     memset((minv), (0x3f), sizeof(minv));     for (int i = 1; i <= n; i++) {       scanf( %*s );       for (int j = 1; j <= m; j++) {         cin >> a[i][j] >> b[i][j] >> c[i][j];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         vector<int> v;         for (int o = 1; o <= m; o++) {           for (int t = 0; t < c[i][o]; t++)             v.push_back(max(0, b[j][o] - a[i][o]));         }         sort(v.rbegin(), v.rend());         int sum = 0;         for (int o = 0; o < k && o < v.size(); o++) sum += v[o];         ans = max(ans, sum);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int INF = 1e9 + 1;   const int MOD = 1e9 + 7;   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i += 1) cin >> a[i];     ;     sort(a.begin(), a.end());     vector<int> ans;     for (int i = 0; i < n; i += 1) {       for (int j = 0; j < 31; j += 1) {         int pv = a[i] - (1 << j);         int nx = a[i] + (1 << j);         bool pv_find = binary_search(a.begin(), a.end(), pv);         bool nx_find = binary_search(a.begin(), a.end(), nx);         if (pv_find && nx_find) {           ans = {pv, a[i], nx};           break;         } else if (pv_find)           ans = {pv, a[i]};         else if (nx_find)           ans = {a[i], nx};       }       if ((int)ans.size() == 3) break;     }     if (ans.empty()) ans.push_back(a[0]);     cout << (int)ans.size() <<   n ;     for (int i = 0; i < (int)ans.size(); i += 1) cout << ans[i] <<    ;     ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int graph[101][101];   int dp[101][101][26];   int dfs(int x, int y, int curr, int n) {     if (dp[x][y][curr] != -1) {       return dp[x][y][curr];     }     for (int i = 0; i < n; i++) {       if (graph[x][i] >= curr) {         if (!dfs(y, i, graph[x][i], n)) {           dp[x][y][curr] = 1;           return 1;         }       }     }     dp[x][y][curr] = 0;     return 0;   }   int main(void) {     memset(dp, -1, sizeof(dp));     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         graph[i][j] = -1;       }     }     for (int i = 0; i < m; i++) {       int a, b;       char c;       cin >> a >> b >> c;       a--;       b--;       graph[a][b] = c -  a ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (dfs(i, j, 0, n)) {           cout <<  A ;         } else {           cout <<  B ;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, f[1001], l[1001];     bool rated = false;     cin >> n;     for (i = 0; i < n; i++) {       cin >> f[i] >> l[i];       if (f[i] != l[i]) {         rated = true;         cout <<  rated  << endl;         return 0;       }     }     if (!rated) {       for (i = 1; i < n; i++) {         if (l[i] > l[i - 1]) {           cout <<  unrated  << endl;           return 0;         }       }     }     cout <<  maybe  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 800005;   int n, m, q, sa[N], sb[N], s[N];   set<int> a[N], b[N];   void modify(int x, int l, int r, int k, int val, int id) {     if (l == r) {       if (id)         sa[x] = val;       else         sb[x] = val;       s[x] = (sa[x] <= -sb[x]);       return;     }     int mid = (l + r) >> 1;     if (k <= mid)       modify(x << 1, l, mid, k, val, id);     else       modify(x << 1 | 1, mid + 1, r, k, val, id);     sa[x] = min(sa[x << 1], sa[x << 1 | 1]);     sb[x] = min(sb[x << 1], sb[x << 1 | 1]);     s[x] = s[x << 1] || s[x << 1 | 1] || sa[x << 1] <= -sb[x << 1 | 1];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) a[i].insert(0x3f3f3f3f), b[i].insert(0);     memset(sa, 0x3f, sizeof(sa));     while (q--) {       int x, y, id;       scanf( %d%d , &x, &y);       id = x & 1, x = (x + 1) / 2, y = (y + 1) / 2;       if (id) {         if (a[x].find(y) != a[x].end())           a[x].erase(y);         else           a[x].insert(y);         modify(1, 1, n, x, *a[x].begin(), 1);         if (s[1])           printf( NO n );         else           printf( YES n );       } else {         if (b[x].find(-y) != b[x].end())           b[x].erase(-y);         else           b[x].insert(-y);         modify(1, 1, n, x, *b[x].begin(), 0);         if (s[1])           printf( NO n );         else           printf( YES n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int soch(int a) {     if (a == 3) return 1;     return soch(a - 1) * a / (a - 3);   }   int main() {     int n, num, i, j, k, raz, dob, num1, dob1, sum = 0, flag = 0, flag1 = 0;     bool graf[105][105];     bool graf1[6][6];     vector<pair<int, int>> ver;     vector<int> v;     vector<int> v1;     vector<int> v2;     cin >> k;     for (i = 1; i <= 100; i++)       for (j = 1; j <= 100; j++) graf[i][j] = 0;     for (i = 3; i <= 100; i++) {       v2.push_back(soch(i));       if (soch(i) > k) break;     }     num = i - 1;     raz = k - soch(num);     v.push_back(0);     v.push_back(1);     for (i = 3; i <= num; i++) v.push_back(soch(i + 1) - soch(i));     for (i = 0; i < v.size(); i++)       if (v[i] > raz) {         dob = i - 1;         break;       };     raz -= v[dob];     dob++;     k = raz;     if (k) {       flag1 = 1;       for (i = 3; i <= 100; i++)         if (soch(i) > k) break;       num1 = i - 1;       raz = k - soch(num1);       for (i = 0; i < v.size(); i++)         if (v[i] > raz) {           dob1 = i - 1;           break;         };       raz -= v[dob1];       dob1++;       k = raz;     }     if (k == 3) {       flag = 1;       v1.push_back(5);       for (i = 1; i <= 5; i++)         for (j = 1; j <= 5; j++)           if (i != j)             graf1[i][j] = 1;           else             graf1[i][j] = 0;       graf1[1][3] = graf1[3][1] = graf1[1][4] = graf1[4][1] = graf1[4][3] =           graf1[3][4] = 0;     }     if (!flag)       for (i = v2.size() - 1; k > 0; i--)         while (v2[i] <= k) {           k -= v2[i];           v1.push_back(i + 3);         }     for (i = 0; i < v1.size(); i++) sum += v1[i];     if (!flag1) num1 = dob1 = 0;     n = num + num1 + sum + 1 + flag1;     cout << n << endl;     for (i = 1; i <= num; i++)       for (j = 1; j <= num; j++)         if (i != j) graf[i][j] = 1;     for (j = 1; j <= dob; j++) graf[num + 1][j] = graf[j][num + 1] = 1;     if (flag1) {       for (i = num + 2; i <= num + num1 + 1; i++)         for (j = num + 2; j <= num + num1 + 1; j++)           if (i != j) graf[i][j] = 1;       for (j = num + 2; j <= dob1 + num + 1; j++)         graf[num + num1 + 2][j] = graf[j][num + num1 + 2] = 1;       num = num + num1 + 1;     }     if (!flag) {       raz = 2;       for (k = 0; k < v1.size(); k++) {         for (i = num + raz; i <= num + raz + v1[k] - 1; i++)           for (j = num + raz; j <= num + raz + v1[k] - 1; j++)             if (i != j) graf[i][j] = 1;         raz += v1[k];       }     } else {       for (i = 0; i < 5; i++)         for (j = 0; j < 5; j++)           graf[num + 2 + i][num + 2 + j] = graf1[i + 1][j + 1];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) cout << graf[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 2147483647;   const int MOD = 1000000007;   const long long INF64 = 9223372036854775807;   const long double EPS = 1e-7;   using namespace std;   vector<int> a;   int getDist(int fr, int to) {     int l = fr, r = to, mid = (a[to] + a[fr]) / 2;     while (l < r - 1) {       int m = (l + r) / 2;       if (a[m] < mid)         l = m;       else         r = m;     }     int l1 = fr, r1 = to, mid1 = (a[to] + a[fr]) / 2 + (a[to] + a[fr]) % 2;     while (l1 < r1 - 1) {       int m = (l1 + r1) / 2;       if (a[m] < mid1)         l1 = m;       else         r1 = m;     }     return min(         min(max(a[l] - a[fr], a[to] - a[l]), max(a[r] - a[fr], a[to] - a[r])),         min(max(a[l1] - a[fr], a[to] - a[l1]),             max(a[r1] - a[fr], a[to] - a[r1])));   }   int main() {     int n, k;     char t;     scanf( %d%d n , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %c , &t);       if (t ==  0 ) a.push_back(i);     }     int ans = INF;     for (int i = 0; i < (int)a.size() - k; i++) ans = min(ans, getDist(i, i + k));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long base = 17LL;   const long long MOD = 998244353LL;   const int MAXN = 1e5 + 10;   struct Node {     long long v;     long long tagv;     long long len;   } st[MAXN << 2];   long long a[MAXN];   inline long long fp(long long x, long long y) {     long long ret = 1LL;     while (y) {       if (y & 1) ret = ret * x % MOD;       x = x * x % MOD;       y >>= 1;     }     return ret;   }   long long inv = fp(base - 1, MOD - 2);   long long basep[MAXN];   Node operator+(const Node& a, const Node& b) {     Node ret;     ret.len = a.len + b.len;     ret.tagv = -1;     ret.v = (a.v * basep[b.len] % MOD + b.v) % MOD;     return ret;   }   void init() {     basep[0] = 1LL;     for (int i = 1; i < MAXN; i++) basep[i] = basep[i - 1] * base % MOD;   }   void setv(int o, long long v) {     st[o].v = (basep[st[o].len] - 1 + MOD) % MOD * v % MOD * inv % MOD;     st[o].tagv = v;   }   void pushup(int o) { st[o] = st[o << 1] + st[o << 1 | 1]; }   void pushdown(int o) {     if (st[o].tagv != -1) {       setv(o << 1, st[o].tagv);       setv(o << 1 | 1, st[o].tagv);       st[o].tagv = -1;     }   }   void build(int o, int l, int r) {     st[o].tagv = -1;     st[o].len = r - l + 1;     if (l == r) {       setv(o, a[l]);       return;     }     int m = l + r >> 1;     build(o << 1, l, m);     build(o << 1 | 1, m + 1, r);     pushup(o);   }   void update(int o, int l, int r, int L, int R, long long v) {     if (L <= l && r <= R) {       setv(o, v);       return;     }     pushdown(o);     int m = l + r >> 1;     if (L <= m) update(o << 1, l, m, L, R, v);     if (m < R) update(o << 1 | 1, m + 1, r, L, R, v);     pushup(o);   }   Node query(int o, int l, int r, int L, int R) {     if (L <= l && r <= R) return st[o];     pushdown(o);     int m = l + r >> 1;     if (R <= m) return query(o << 1, l, m, L, R);     if (m < L) return query(o << 1 | 1, m + 1, r, L, R);     return query(o << 1, l, m, L, R) + query(o << 1 | 1, m + 1, r, L, R);   }   char s[MAXN];   int main() {     init();     int n, m, k;     int x, l, r, y;     scanf( %d%d%d , &n, &m, &k);     scanf( %s , s);     for (int i = 1; i <= n; i++) a[i] = s[i - 1] -  0 ;     build(1, 1, n);     for (int i = 1; i <= m + k; i++) {       scanf( %d%d%d%d , &x, &l, &r, &y);       if (x == 1) {         update(1, 1, n, l, r, 1LL * (y));       } else {         if (y == (r - l + 1)) {           puts( YES );           continue;         }         if (query(1, 1, n, l + y, r).v == query(1, 1, n, l, r - y).v)           puts( YES );         else           puts( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool deb = false;   int i;   const int N = 100011;   int g[N];   int ans1[N], ans2[N];   int main() {     int i, j, n, k;     scanf( %d , &n), scanf( %d , &k);     int a, b, c, d;     scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d);     if (k < n + 1 || n == 4) {       printf( %d n , -1);       return 0;     }     g[1] = a;     g[2] = c;     g[n] = b, g[n - 1] = d;     j = 3;     for (i = 1; i < n + 1; ++i) {       if (i == a || i == b || i == c || i == d) continue;       if (g[j] == 0) g[j] = i, j++;     }     for (i = 1; i < n + 1; ++i) printf( %d  , g[i]);     printf(  n );     printf( %d  , g[2]), printf( %d  , g[1]);     for (i = 3; i < n - 1; ++i) {       printf( %d  , g[i]);     }     printf( %d  , g[n]), printf( %d n , g[n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   long cmpduong(string s1, string s2) {     long len1 = s1.size();     long len2 = s2.size();     if (len1 < len2) return 2;     if (len1 == len2) {       if (s1 > s2)         return 1;       else         return 2;     }     if (len1 > len2) return 1;   }   long cmp_am(string s1, string s2) {     long len1 = s1.size();     long len2 = s2.size();     if (len1 < len2) return 1;     if (len1 == len2) {       if (s1 >= s2)         return 2;       else         return 1;     }     if (len1 > len2) return 2;   }   long check(string s) {     string tam =  -  + s;     if (s[0] ==  - ) {       if (cmp_am(s,  -128 ) == 1) return 1;       if (cmp_am(s,  -32768 ) == 1) return 2;       if (cmp_am(s,  -2147483648 ) == 1) return 3;       if (cmp_am(s,  -9223372036854775808 ) == 1) return 4;       return 5;     } else {       if (cmpduong(s,  127 ) == 2) return 1;       if (cmpduong(s,  32767 ) == 2) return 2;       if (cmpduong(s,  2147483647 ) == 2) return 3;       if (cmpduong(s,  9223372036854775807 ) == 2) return 4;       return 5;     }   }   int main() {     cin >> s;     if (check(s) == 1) cout <<  byte  << endl;     if (check(s) == 2) cout <<  short  << endl;     if (check(s) == 3) cout <<  int  << endl;     if (check(s) == 4) cout <<  long  << endl;     if (check(s) == 5) cout <<  BigInteger  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sum[400006] = {0};   long long Min[400006] = {0};   long long Max[400006] = {0};   void solve() {     long long n;     cin >> n;     long long k;     cin >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     for (long long i = 0; i <= 2 * k + 3; i++) Min[i] = Max[i] = sum[i] = 0;     for (long long i = 0; i < n / 2; i++) {       Max[max(v[i], v[n - i - 1])]++;       Min[min(v[i], v[n - i - 1])]++;       sum[v[i] + v[n - i - 1]]++;     }     for (long long i = 1; i <= k; i++) {       Min[i] += Min[i - 1];       Max[i] += Max[i - 1];     }     long long ans = 2000000000000000005;     long long c;     for (long long i = 2; i <= k + 1; i++) {       c = Min[i - 1];       if (c <= n / 2) ans = min(ans, c + 2 * ((n / 2) - c) - sum[i]);     }     for (long long i = k + 1; i <= 2 * k; i++) {       if (i - k - 1 >= 0) c = Max[i - k - 1];       if (c <= n / 2) ans = min(ans, c * 2 + (n / 2 - c) - sum[i]);     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int ans[100010];   int a[100010], b[100010];   int c[100010], d[100010], cnt[100010];   set<pair<int, int> > s;   int x[100010 * 4], nx;   vector<int> A[100010 * 4], B[100010 * 4];   bool solve() {     for (int i = 0; i < N; i++) {       x[nx++] = a[i];       x[nx++] = b[i];     }     for (int i = 0; i < M; i++) {       x[nx++] = c[i];       x[nx++] = d[i];     }     sort(x, x + nx);     nx = unique(x, x + nx) - x;     for (int i = 0; i < M; i++) {       c[i] = lower_bound(x, x + nx, c[i]) - x;       d[i] = lower_bound(x, x + nx, d[i]) - x;       A[c[i]].push_back(-(i + 1));       B[d[i]].push_back(-(i + 1));     }     for (int i = 0; i < N; i++) {       a[i] = lower_bound(x, x + nx, a[i]) - x;       b[i] = lower_bound(x, x + nx, b[i]) - x;       A[a[i]].push_back(i + 1);     }     memset(ans, -1, sizeof(ans));     for (int i = 0; i < nx; i++) {       int n;       n = A[i].size();       for (int j = 0; j < n; j++) {         if (A[i][j] > 0) {           int k = A[i][j] - 1;           set<pair<int, int> >::iterator it =               s.lower_bound(pair<int, int>(b[k], -1));           if (it == s.end()) return false;           int u = it->second;           ans[k] = u + 1;           cnt[u]--;           if (!cnt[u]) s.erase(it);         } else {           int k = -A[i][j] - 1;           s.insert(pair<int, int>(d[k], k));         }       }       n = B[i].size();       for (int j = 0; j < n; j++) {         int k = -B[i][j] - 1;         s.erase(pair<int, int>(d[k], k));       }     }     return true;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d%d , &a[i], &b[i]);     scanf( %d , &M);     for (int i = 0; i < M; i++) scanf( %d%d%d , &c[i], &d[i], &cnt[i]);     if (solve()) {       puts( YES );       for (int i = 0; i < N; i++) printf( %d  , ans[i]);       puts(  );     } else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, n1 = 0, n2 = 0, ar = 0, curr = 0, current;     cin >> n;     vector<int> a(n);     for (i = 0; i < n; i++) cin >> a[i];     current = a[0];     for (i = 0; i < n; i++) {       if (curr == 0 && a[i] == current)         n1++;       else if (a[i] != current)         curr++, n2++;       if ((curr > 0 && a[i] == current) || i == n - 1) {         current = a[i - 1];         if (n1 == n2)           ar = max(n1 + n2, ar);         else           ar = max((2 * min(n1, n2)), ar);         n1 = n2, n2 = 1;       }     }     cout << ar << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     vector<int> d(n);     for (int(i) = 0; (i) < (n); (i)++) {       cin >> d[i];     }     sort((d).begin(), (d).end());     if (d[b] != d[b - 1]) {       cout << d[b] - d[b - 1] << endl;     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205000;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   vector<string> w, a, b;   string s1, s2;   bool check(string& s) {     if (s.size() == 0) return 0;     if (s[0] ==  0 ) return s.size() == 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] >  9  || s[i] <  0 ) return 0;     }     return 1;   }   signed main() {     cin >> s1;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  ,  || s1[i] ==  ; ) {         w.push_back(s2);         s2 =   ;       } else {         s2 += s1[i];       }       if (i == s1.size() - 1) w.push_back(s2);     }     for (int i = 0; i < w.size(); i++) {       if (check(w[i])) {         a.push_back(w[i]);       } else         b.push_back(w[i]);     }     if (a.size() == 0) {       cout <<  -  << endl;     } else {       cout <<    ;       for (int i = 0; i < a.size(); i++) {         cout << a[i];         if (i != a.size() - 1) cout <<  , ;       }       cout <<    n ;     }     if (b.size() == 0) {       cout <<  -  << endl;     } else {       cout <<    ;       for (int i = 0; i < b.size(); i++) {         cout << b[i];         if (i != b.size() - 1) cout <<  , ;       }       cout <<    n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e5 + 5;   int n, I;   int a[MAXN], num[MAXN];   int read() {     int s = 1, x = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) s = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * s;   }   int main() {     n = read(), I = read();     int maxk = 8 * I / n, maxK = pow(2, maxk);     if (maxk >= 20) {       cout <<  0 n ;       return 0;     }     for (int i = 1; i <= n; ++i) a[i] = read();     sort(a + 1, a + n + 1);     int cnt = 1;     num[cnt] = 1;     for (int i = 2; i <= n; ++i) {       if (a[i] == a[i - 1])         num[cnt]++;       else         num[++cnt] = num[cnt - 1] + 1;     }     if (cnt <= maxK) {       cout <<  0 n ;       return 0;     }     int max_con = -1;     for (int i = maxK; i <= cnt; ++i) {       int tmp = num[i] - num[i - maxK];       max_con = max(max_con, tmp);     }     cout << n - max_con << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, x, y, x1, y1;     cin >> n >> a >> b;     if (max(n - a, n - b) < max(a - 1, b - 1))       cout <<  black n ;     else       cout <<  white n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int a[MAXN], deg[MAXN];   set<pair<int, int> > s;   int main() {     int n, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> deg[i] >> a[i];       if (deg[i]) s.insert(make_pair(deg[i], i));       sum += deg[i];     }     cout << sum / 2 << endl;     while (s.size()) {       pair<int, int> x = *s.begin();       s.erase(x);       int t = a[x.second];       cout << x.second <<     << t << endl;       s.erase(make_pair(deg[t], t));       deg[t]--;       a[t] ^= x.second;       if (deg[t]) s.insert(make_pair(deg[t], t));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[6], ans[100001];   pair<int, int> arr[100001];   bool given[100001];   string tshirt[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };   int match(string s) {     for (int i = 0; i < 6; i++) {       if (tshirt[i] == s) return i;     }   }   void convert(int ind, string s) {     string tmp;     bool flag = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  , ) {         flag = 1;         arr[ind].first = match(tmp);         tmp.clear();       } else         tmp.push_back(s[i]);     }     if (flag) {       arr[ind].second = match(tmp);       if (arr[ind].first > arr[ind].second) swap(arr[ind].first, arr[ind].second);     } else {       arr[ind].first = match(tmp);       arr[ind].second = -1;     }     return;   }   bool cal_ans(int n) {     for (int i = 0; i < n; i++) {       if (arr[i].second == -1) {         if (cnt[arr[i].first] == 0) return false;         ans[i] = arr[i].first;         cnt[arr[i].first]--;         given[i] = 1;       }     }     for (int j = 0; j < 5; j++) {       for (int i = 0; i < n; i++) {         if (given[i] == 0 and arr[i].first == j) {           if (cnt[arr[i].first]) {             cnt[arr[i].first]--;             ans[i] = j;           } else {             if (cnt[arr[i].second]) {               cnt[arr[i].second]--;               ans[i] = arr[i].second;             } else               return false;           }           given[i] = 1;         }       }     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     for (int i = 0; i < 6; i++) cin >> cnt[i];     int n;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       convert(i, s);     }     if (cal_ans(n)) {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         cout << tshirt[ans[i]] << endl;       }     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   set<pair<int, int> > s;   set<pair<pair<int, int>, int> > vis;   char dir[10];   int sx, sy, h, w, d, tar;   inline void update(int& a, int b) {     if (b < a) a = b;   }   int main() {     scanf( %d%d%d%d%s , &h, &w, &sx, &sy, dir);     tar = ((h + w) * 2 - 4) >> 1;     if (dir[0] ==  U  && dir[1] ==  L )       d = 3;     else if (dir[0] ==  U  && dir[1] ==  R )       d = 2;     else if (dir[0] ==  D  && dir[1] ==  L )       d = 1;     else       d = 0;     --tar;     s.insert(make_pair(sx, sy));     vis.insert(make_pair(make_pair(sx, sy), d));     long long ans = 1;     pair<int, int> p1;     pair<pair<int, int>, int> p2;     while (tar > 0) {       if ((D[d][0] == 1 && sx == h) || (D[d][0] == -1 && sx == 1)) d ^= 2;       if ((D[d][1] == 1 && sy == w) || (D[d][1] == -1 && sy == 1)) d ^= 1;       int g = 0x3f3f3f3f;       if (D[d][0] == 1)         update(g, h - sx);       else         update(g, sx - 1);       if (D[d][1] == 1)         update(g, w - sy);       else         update(g, sy - 1);       ans += g;       sx += D[d][0] * g;       sy += D[d][1] * g;       p1 = make_pair(sx, sy);       if (s.find(p1) == s.end()) {         --tar;         s.insert(p1);       }       p2 = make_pair(p1, d);       if (vis.find(p2) != vis.end()) {         printf( -1 n );         return 0;       } else         vis.insert(p2);     }     printf(          %I64d            n ,         ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[100009];   int main() {     int n;     while (cin >> n) {       for (int i = 0; i < n; ++i) cin >> num[i];       long long sum = n;       long long count = 1;       for (int i = 1; i < n; ++i) {         if (num[i] == num[i - 1])           count++;         else {           sum += ((count - 1) * (count)) / 2;           count = 1;         }       }       if (count != 0) sum += ((count - 1) * (count)) / 2;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 11;   int n, l;   int main() {     scanf( %d , &n);     while (n) {       int a = n % 10;       int b = n % 100;       int c = n % 1000;       if (a == 1)         n /= 10;       else if (b == 14)         n /= 10;       else if (c == 144)         n /= 100;       l++;       if (l > 1000) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> MP1, MP2;   map<int, int>::iterator it;   const int N = 300100;   const long long INF = 3000 * 1000 * 1000LL;   vector<int> v;   int a[N];   long long ps[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, l, r;     long long ans = -INF;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (!MP1.count(a[i])) MP1[a[i]] = i;       MP2[a[i]] = i;       ps[i] += ps[i - 1];       if (a[i] > 0) ps[i] += a[i];     }     for (it = MP1.begin(); it != MP1.end(); it++) {       if (MP2[it->first] != it->second) {         long long t = ps[MP2[it->first]] - ps[it->second] + it->first;         if (it->first < 0) t += it->first;         if (t > ans) {           ans = t;           l = it->second;           r = MP2[it->first];         }       }     }     for (int i = 1; i <= n; i++)       if ((i != l && i != r && a[i] < 0) || (i < l || i > r)) v.push_back(i);     cout << ans <<     << v.size() << endl;     for (int u : v) cout << u <<    ;     cout << endl;     return 0;   }


#include <algorithm>     #include <iostream>     #include <sstream>     #include <string>     #include <vector>     #include <queue>     #include <set>     #include <map>     #include <cstdio>     #include <cstdlib>     #include <cctype>     #include <cmath>     #include <cstring>   #include <list>     #include <cassert>   #include <climits>   #include <bitset>   #include <chrono>   #include <random>   using namespace std;      #define PB push_back     #define MP make_pair     #define SZ(v) ((int)(v).size())     #define FOR(i,a,b) for(int i=(a);i<(b);++i)     #define REP(i,n) FOR(i,0,n)     #define FORE(i,a,b) for(int i=(a);i<=(b);++i)     #define REPE(i,n) FORE(i,0,n)     #define FORSZ(i,a,v) FOR(i,a,SZ(v))     #define REPSZ(i,v) REP(i,SZ(v))     std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());   typedef long long ll;   ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }      const int MAXN = 5000;   const int MAXC = 20;      int n, num, den;   char s[MAXN + 1];   vector<char> ans;      int mp[26];   char c[MAXC]; int nc;   int a[MAXN];      int fst[MAXC], lst[MAXC], cnt[MAXC];      bool ok[1 << MAXC];   bool can[1 << MAXC];      void solve() {    nc = 0; REP(i, 26) mp[i] = -1;    REP(i, n) { int x = s[i] -  a ; if (mp[x] == -1) c[nc] =  a  + x, mp[x] = nc, nc++; a[i] = mp[x]; }       REP(i, nc) fst[i] = INT_MAX, lst[i] = INT_MIN, cnt[i] = 0;    REP(i, n) fst[a[i]] = min(fst[a[i]], i), lst[a[i]] = max(lst[a[i]], i), ++cnt[a[i]];       //printf( c: ); REP(i, nc) printf(  %c , c[i]); puts(  );    FOR(mask, 1, 1 << nc) {      int maskfst = INT_MAX, masklst = INT_MIN, maskcnt = 0;     REP(i, nc) if (mask&(1 << i)) maskfst = min(maskfst, fst[i]), masklst = max(masklst, lst[i]), maskcnt += cnt[i];     ok[mask] = num*(masklst - maskfst + 1) <= maskcnt*den;     //printf( %s[%x] [%d..%d] cnt=%d n , ok[mask] ?  ok  :  fail , mask, maskfst, masklst, maskcnt);    }    can[0] = true;    FOR(mask, 1, 1 << nc) {     can[mask] = false;     if (ok[mask]) REP(i, nc) if ((mask&(1 << i)) != 0 && can[mask ^ (1 << i)]) {      can[mask] = true;     }     REP(i, nc) {      int lmask = mask&((2 << i) - 1), rmask = mask^lmask;      if (can[lmask] && can[rmask]) can[mask] = true;     }    }       ans.clear();    REP(i, nc) if (can[(1 << nc) - 1 - (1 << i)]) ans.PB(c[i]);    sort(ans.begin(), ans.end());   }      void run() {    scanf( %d%d%d , &n, &num, &den);    scanf( %s , s); assert(strlen(s) == n);    solve();    printf( %d , SZ(ans)); REPSZ(i, ans) printf(  %c , ans[i]); puts(  );   }      int main() {    //int ncase; scanf( %d , &ncase); FORE(i, 1, ncase)    run();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int cnt = 0, cnt1 = 0;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  - )         cnt++;       else         cnt1++;     }     if (cnt1 == 0) {       cout <<  YES ;       return 0;     }     if (cnt % cnt1 == 0)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, rt;   int p[20][N], sz[N];   bool vis[N];   int dep[N], yr[N];   int cur = 1, pos[N], chainhd[N], chain[N], rpos[N];   int L[100 * N], R[100 * N], t[100 * N], root[N], nxt = 1, num;   int query[N], a[N], b[N], k[N], y[N];   vector<int> g[N];   void build(int id, int x, int y) {     if (x == y) {       return;     }     L[id] = nxt++;     R[id] = nxt++;     int mid = (x + y) >> 1;     build(L[id], x, mid);     build(R[id], mid + 1, y);   }   int update(int id, int x, int y, int l) {     if (l < x or l > y) return id;     int ID = nxt++;     if (x == y) {       t[ID] = t[id] + 1;       return ID;     }     int mid = (x + y) >> 1;     L[ID] = update(L[id], x, mid, l);     R[ID] = update(R[id], mid + 1, y, l);     t[ID] = t[L[ID]] + t[R[ID]];     return ID;   }   void dfs(int x) {     vis[x] = 1;     sz[x] = 1;     for (auto it : g[x]) {       if (!vis[it]) {         dep[it] = dep[x] + 1;         dfs(it);         sz[x] += sz[it];       }     }   }   void per_dfs(int x) {     vis[x] = 1;     root[x] = update(root[p[0][x]], 1, m, yr[x]);     for (auto it : g[x]) {       if (!vis[it]) {         per_dfs(it);       }     }   }   int lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     int diff = dep[u] - dep[v];     for (int i = 0; i < 18; i++) {       if ((diff >> i) & 1) u = p[i][u];     }     if (u == v) return u;     for (int i = 17; i > -1; i--) {       if (p[i][u] != p[i][v]) {         u = p[i][u];         v = p[i][v];       }     }     return p[0][u];   }   void HLD(int x) {     if (chainhd[num] == 0) chainhd[num] = x;     pos[x] = cur;     rpos[cur] = x;     cur++;     chain[x] = num;     int mx = 0, hv = -1;     for (auto it : g[x]) {       if (it != p[0][x]) {         if (sz[it] >= mx) {           mx = sz[it];           hv = it;         }       }     }     if (hv == -1) return;     HLD(hv);     for (auto it : g[x]) {       if (it != hv and it != p[0][x]) {         num++;         HLD(it);       }     }   }   int per_query(int id, int x, int y, int l, int r) {     if (l > y or r < x) return 0;     if (l <= x and r >= y) return t[id];     int mid = (x + y) >> 1;     int ans = per_query(L[id], x, mid, l, r) + per_query(R[id], mid + 1, y, l, r);     return ans;   }   int search(int u, int l, int r, int k, int y, int i) {     if (k == 1 and (yr[u] <= y or yr[u] >= i)) return u;     while (l < r) {       int mid = (l + r) >> 1;       int node = rpos[mid];       int x = per_query(root[u], 1, m, y + 1, i) -               per_query(root[node], 1, m, y + 1, i);       x = dep[u] - dep[node] - x;       if (yr[node] <= y or yr[node] >= i) x++;       if (x >= k) {         l = mid + 1;       } else {         r = mid;       }     }     return rpos[l - 1];   }   int query_hld(int u, int v, int k, int y, int i) {     u = p[0][u];     int a = chain[u], b = chain[v];     while (a != b) {       int hd = chainhd[a];       int x = per_query(root[u], 1, m, y + 1, i) -               per_query(root[hd], 1, m, y + 1, i);       if (yr[hd] >= y + 1 and yr[hd] < i) x++;       x = dep[u] - dep[hd] + 1 - x;       if (x >= k) {         int l = pos[hd], r = pos[u];         return search(u, l, r, k, y, i);       } else {         k -= x;         u = p[0][hd];         a = chain[u];       }     }     if (u == v) {       return -1;     }     int l = pos[v] + 1, r = pos[u];     return search(u, l, r, k, y, i);   }   int count(int u, int v, int y, int i) {     u = p[0][u];     if (dep[u] <= dep[v]) return 0;     int ans =         per_query(root[u], 1, m, y + 1, i) - per_query(root[v], 1, m, y + 1, i);     ans = dep[u] - dep[v] - ans;     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[0][i]);       if (p[0][i] == 0) {         rt = i;         continue;       }       g[p[0][i]].push_back(i);     }     for (int i = 1; i < 18; i++) {       for (int j = 1; j <= n; j++) {         if (p[i - 1][j] > 0) p[i][j] = p[i - 1][p[i - 1][j]];       }     }     dep[rt] = 1;     dfs(rt);     HLD(rt);     scanf( %d , &m);     build(nxt++, 1, m);     int ty;     for (int i = 1; i <= m; i++) {       scanf( %d , &ty);       if (ty == 1) {         scanf( %d , &ty);         yr[ty] = i;         query[i] = 0;       } else {         query[i] = 1;         scanf( %d%d%d%d , a + i, b + i, k + i, y + i);       }     }     memset(vis, 0, sizeof(vis));     root[0] = 1;     pos[0] = 0;     chain[0] = 0;     per_dfs(rt);     for (int i = 1; i <= m; i++) {       if (query[i]) {         int l = lca(a[i], b[i]);         if (a[i] == l) {           int x = count(b[i], l, y[i], i);           int ans;           if (x >= k[i]) {             ans = query_hld(b[i], l, x - k[i] + 1, y[i], i);           } else {             ans = -1;           }           printf( %d n , ans);         } else if (b[i] == l) {           int x = count(a[i], l, y[i], i);           int ans;           if (x >= k[i]) {             ans = query_hld(a[i], l, k[i], y[i], i);           } else {             ans = -1;           }           printf( %d n , ans);         } else {           int x = count(a[i], l, y[i], i);           int ans;           if (x >= k[i]) {             ans = query_hld(a[i], l, k[i], y[i], i);           } else {             k[i] -= x;             if (yr[l] <= y[i] or yr[l] >= i) k[i]--;             if (k[i] == 0)               ans = l;             else {               x = count(b[i], l, y[i], i);               if (x >= k[i])                 ans = query_hld(b[i], l, x - k[i] + 1, y[i], i);               else                 ans = -1;             }           }           printf( %d n , ans);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline void init() {}   string lines[1001];   int main() {     string s;     int n = 0;     int mx = 0;     while (getline(cin, lines[n])) {       mx = std::max<int>(mx, lines[n].length());       n++;     }     cout << string(mx + 2,  * ) << endl;     int sw = 0;     for (int i = 0; i < n; i++) {       cout <<  * ;       int len = lines[i].length();       if (len % 2 != mx % 2) {         if (sw) {           lines[i] =     + lines[i];         } else {           lines[i] +=    ;         }         sw = !sw;       }       int d = mx - len;       if (d) cout << string(d / 2,    );       cout << lines[i];       if (d) cout << string(d / 2,    );       cout <<  * n ;     }     cout << string(mx + 2,  * ) << endl;     return 0;   }


#include <bits/stdc++.h>   struct M {     int p, b;   };   struct F {     const int p, i;     int r;     int c;     F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {}     int t() { return r - p; }   };   void solve(std::vector<F> &fs, std::vector<M> &ms) {     std::multimap<int, int> ms_landed;     std::map<int, F *> fs_active;     {       std::vector<F *> fs_sort;       fs_sort.reserve(fs.size());       for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]);       std::sort(fs_sort.begin(), fs_sort.end(),                 [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; });       fs_active.insert({fs_sort[0]->p, fs_sort[0]});       int curr = fs_sort[0]->r;       for (int i = 1; i < fs_sort.size(); i++) {         F &f = *fs_sort[i];         if (f.r > curr) {           int l = std::max(curr + 1, f.p);           curr = f.r;           fs_active.insert({l, &f});         }       }     }     auto update = [&](F &f, std::map<int, F *>::iterator &f_it, const int &b) {       f.c++;       f.r += b;       while (f_it != fs_active.end()) {         int l_succ = f_it->first;         F &f_succ = *f_it->second;         if (f.r < f_succ.r) {           if (f.r >= l_succ) {             f_it = fs_active.insert(fs_active.erase(f_it), {f.r + 1, &f_succ});           }           break;         }         f_it = fs_active.erase(f_it);       }     };     for (const M &m : ms) {       auto f_it = --fs_active.upper_bound(m.p);       if (f_it == fs_active.end()) continue;       int l = f_it->first;       F &f = *f_it->second;       if (l <= m.p && m.p <= f.r) {         update(f, ++f_it, m.b);         auto m_succ = ms_landed.lower_bound(l);         while (m_succ != ms_landed.end()) {           M m{m_succ->first, m_succ->second};           if (l <= m.p && m.p <= f.r) {             update(f, f_it, m.b);             m_succ = ms_landed.erase(m_succ);           } else {             break;           }         }       } else {         ms_landed.insert({m.p, m.b});       }     }     for (F &f : fs) {       printf( %d %d n , f.c, f.t());     }   }   int main() {     int n;     int m;     scanf( %d%d , &n, &m);     std::vector<F> fs;     fs.reserve(n);     std::vector<M> ms;     ms.reserve(m);     for (int i = 0; i < n; i++) {       int p, t;       scanf( %d%d , &p, &t);       fs.push_back({p, t, i});     }     for (int i = 0; i < m; i++) {       int p, b;       scanf( %d%d , &p, &b);       ms.push_back({p, b});     }     solve(fs, ms);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long edgestory;   long long last;   struct UnionFind {     vector<int> f;     vector<bool> special;     void init(int n) {       f.clear();       f.insert(f.begin(), n, -1);       special.clear();       special.insert(special.begin(), n, false);       edgestory = 0;     }     int comp(int x) { return (f[x] == -1 ? x : f[x] = comp(f[x])); }     bool sp(int x) { return special[comp(x)]; }     bool join1(int i, int j) {       if (i == j) return true;       edgestory++;       bool con = comp(i) == comp(j);       if (!con) {         bool spv = sp(i) || sp(j);         if (sp(i) && sp(j)) last = edgestory;         f[comp(i)] = comp(j);         special[comp(i)] = spv;       }       return con;     }     pair<int, int> join2(int i, int j) {       if (i == j) return {0, 0};       edgestory++;       if (edgestory == last) return {i, j};       bool con = comp(i) == comp(j);       if (!con) {         f[comp(i)] = comp(j);       }       return {0, 0};     }   } uf;   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     long long n, m, k;     cin >> n >> m >> k;     vector<long long> special(k);     for (auto &x : special) cin >> x;     vector<tuple<long long, long long, long long>> edges(m);     for (auto &x : edges) {       long long u, v, w;       cin >> u >> v >> w;       x = make_tuple(w, u - 1, v - 1);     }     sort(edges.begin(), edges.end());     uf.init(n);     for (auto &x : special) uf.special[x - 1] = true;     for (auto &[w, u, v] : edges) uf.join1(u, v);     long long lastw = 0;     uf.init(n);     for (auto &[w, u, v] : edges) {       lastw = w;       if (uf.join2(u, v) != make_pair(0, 0)) break;     }     for (int i = 0; i < k; i++) cout <<     + !i << lastw;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   long long a[200005], b[200005], t[200005];   long long c(long long l, long long r, long long* a) {     if (l == r - 1) return 0;     long long ans = 0, m = (l + r + 1) / 2, k = l, ct = 0;     ans += c(l, m, a) + c(m, r, a);     for (long long i = l, j = m; i < m || j < r;) {       if (j >= r || (i < m && a[i] <= a[j])) {         t[k++] = a[i++];         ct++;       } else {         t[k++] = a[j++];         ans += m - l - ct;       }     }     for (long long i = l; i < r; i++) a[i] = t[i];     return ans;   }   bool solve() {     long long n;     string s, t;     cin >> n >> s >> t;     string ss = s, tt = t;     sort((ss).begin(), (ss).end()), sort((tt).begin(), (tt).end());     if (ss != tt) {       return false;     }     for (long long i = 0; i < n - 1; i++) {       if (ss[i] == ss[i + 1]) {         return true;       }     }     for (long long i = 0; i < n; i++) {       a[i] = lower_bound((ss).begin(), (ss).end(), s[i]) - ss.begin();       b[i] = lower_bound((ss).begin(), (ss).end(), t[i]) - ss.begin();     }     long long c1 = c(0, n, a), c2 = c(0, n, b);     return (c1 & 1) == (c2 & 1);   }   signed main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     ;     long long q;     cin >> q;     while (q--) {       if (solve())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t, n, m, i, j, k;     cin >> n >> k;     vector<ll> v;     i = 0;     if (n % 2 == 1) {       v.push_back(1);       n -= 1;       i++;     }     if (n > 0) {       j = log2(n);       m = pow(2, j);       while (n > 0) {         if (m <= n) {           n -= m;           v.push_back(m);           i++;         } else {           j--;           m = pow(2, j);         }       }     }     ll x = 0, y;     if (i <= k && n == 0) {       for (j = 0; j < v.size(); j++) {         if (i == k) break;         m = v[j];         if (m == 1) continue;         v.erase(v.begin() + j);         j--;         while (m != 1) {           m /= 2;           v.push_back(m);           i++;           if (i == k) break;         }         v.push_back(m);       }       if (i == k) {         sort(v.begin(), v.end());         cout <<  YES               <<   n ;         for (i = 0; i < v.size(); i++) cout << v[i] <<    ;       } else         cout <<  NO ;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long V;     cin >> V;     while (V--) {       double a[250];       for (long long i = 0; i < 250; i++) cin >> a[i];       double exp = 0;       for (long long i = 0; i < 250; i++) exp += a[i];       exp /= 250;       double var = 0;       for (long long i = 0; i < 250; i++) var += (a[i] - exp) * (a[i] - exp);       var /= 250;       double k = exp / var;       double err = 0.60;       if (1.0 - err <= k && k <= 1.0 + err)         cout <<  poisson  << endl;       else         cout <<  uniform  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> G[100000];   int a[100000];   int b[100000];   int c[100000];   void dfs(int v) {     b[v]++;     c[v] = 1;     for (int i = 0; i < (int)(G[v].size()); i++) {       int w = G[v][i];       if (++b[w] == a[w]) dfs(w);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < (int)(m); i++) {       int a, b;       cin >> a >> b;       --a, --b;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < (int)(n); i++) cin >> a[i];     for (int i = 0; i < (int)(n); i++) {       if (a[i] == b[i]) dfs(i);     }     cout << accumulate(c, c + n, 0) << endl;     for (int i = 0; i < (int)(n); i++)       if (c[i]) cout << i + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long sum = 0;       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       sort(a, a + n);       reverse(a, a + n);       if (n == 1) {         cout <<  T n ;         continue;       }       if (n == 2) {         if (a[0] == a[1]) {           cout <<  HL n ;           continue;         } else {           cout <<  T n ;           continue;         }       }       if (a[0] > sum - a[0]) {         cout <<  T n ;         continue;       }       if (sum % 2 == 0) {         cout <<  HL n ;         continue;       } else {         cout <<  T n ;         continue;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846264338327950288419716939937510;   const double E = 2.7182818284590452353602874713526624977572470936999596;   const double eps = 0.000000001;   const int MOD = 998244353;   inline int max(int u, int v) { return u > v ? u : v; }   inline int min(int u, int v) { return u < v ? u : v; }   inline int gcd(int u, int v) { return v ? gcd(v, u % v) : u; }   template <typename T>   inline void read(T& u) {     char id;     u = 0;     bool flag = 0;     id = getchar();     while (id >  9  || id <  0 ) {       if (id ==  - ) flag = 1;       id = getchar();     }     while ((id <=  9  && id >=  0 )) {       u = u * 10 + id -  0 ;       id = getchar();     }     if (flag) u *= -1;   }   template <typename T>   inline void read(T& u, T& v) {     read(u);     read(v);   }   template <typename T>   inline void read(T& u, T& v, T& tmp) {     read(u);     read(v);     read(tmp);   }   long long n, m, a[1500][1500], r, c, len, f[2250000];   struct node {     long long x, y, v;   } str[2250000];   bool cmp(node x, node y) { return x.v < y.v; }   long long power(long long a, long long n) {     a %= MOD;     long long res = 1;     while (n) {       if (n & 1) res = 1LL * res * a % MOD;       a = 1LL * a * a % MOD;       n >>= 1;     }     return res;   }   long long inv(long long x) { return power(x, MOD - 2) % MOD; }   long long cnt, a1, a2, b1, b2, sum;   void solve(int p) {     f[p] = (sum +             (1LL * str[p].x * str[p].x % MOD * cnt % MOD + a2 -              2LL * str[p].x % MOD * a1 % MOD) +             (1LL * str[p].y * str[p].y % MOD * cnt % MOD + b2 -              2LL * str[p].y % MOD * b1 % MOD)) %            MOD;     f[p] = (1LL * f[p] + MOD) % MOD;     f[p] = 1LL * f[p] * inv(cnt) % MOD;   }   inline void add(int p) {     cnt++;     sum += f[p];     a1 += str[p].x;     a2 += 1LL * str[p].x * str[p].x % MOD;     b1 += str[p].y;     b2 += 1LL * str[p].y * str[p].y % MOD;     a1 %= MOD;     b1 %= MOD;     a2 %= MOD;     b2 %= MOD;     sum %= MOD;   }   int main() {     read(n, m);     for (int i = (1); (i) <= (n); (i)++)       for (int j = (1); (j) <= (m); (j)++) read(a[i][j]);     for (int i = (1); (i) <= (n); (i)++)       for (int j = (1); (j) <= (m); (j)++) str[++len] = (node){i, j, a[i][j]};     sort(str + 1, str + len + 1, cmp);     for (int i = (1); (i) <= (len); (i)++) {       int j;       for (j = i; j <= len; j++)         if (str[j].v != str[i].v) break;       for (int k = (i); (k) <= (j - 1); (k)++) solve(k);       for (int k = (i); (k) <= (j - 1); (k)++) add(k);       i = j - 1;     }     long long r, c;     read(r, c);     long long res = 0;     for (int i = (1); (i) <= (len); (i)++)       if (str[i].x == r && str[i].y == c) res = f[i];     res %= MOD;     res = (res + MOD) % MOD;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const greater<int> gt;   int A[100000];   int main() {     cout << fixed << setprecision(11);     long long n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < n; ++i) cin >> A[i];     sort(A, A + n, gt);     double mx = 0, rx = 0;     for (int i = 0; i < n; ++i) {       rx += A[i];       if (n - i < m + 2) {         mx = max(mx, (min(m - n + i + 1, (i + 1) * k) + rx) / (i + 1));       }     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 5;   int n, deg[N], a[N];   bool ed[N][N];   void change(int u) {     for (int v = 0; v < n; v++) {       deg[u] -= ed[u][v], deg[u] += ed[u][v] ^= true;       deg[v] -= ed[v][u], deg[v] += ed[v][u] ^= true;     }   }   bool check() {     copy(deg, deg + n, a);     sort(a, a + n, greater<int>());     for (int i = 1, sum = a[0]; i < n; sum += a[i++])       if (sum == i * (i - 1) / 2 + i * (n - i)) return false;     return true;   }   int main() {     cin >> n;     for (int u = 0; u < n; u++)       for (int v = 0; v < n; v++) {         char c;         cin >> c;         deg[u] += ed[u][v] = c -  0 ;       }     if (check()) return cout <<  0 1 , 0;     int ted = 0;     for (int u = 0; u < n; change(u++)) change(u), ted += check();     if (ted) return cout <<  1   << ted, 0;     if (n == 6) return cout <<  2 18 , 0;     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long mod = 1e9 + 7;   vector<long long> v;   long long n, s;   bool check(long long x) {     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += (v[i] - x);     }     return sum >= s;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n;     cin >> s;     long long z;     long long sum = 0;     for (long long i = 0; i < n; i++) cin >> z, v.push_back(z), sum += z;     if (sum < s) {       cout <<  -1 ;       return 0;     }     sort(v.begin(), v.end());     long long l = 0;     long long r = v[0];     while (r > l + 1) {       long long m = (l + r) / 2;       if (check(m)) {         l = m;       } else {         r = m;       }     }     if (!check(r))       cout << l <<   n ;     else       cout << r;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 20;   const int inf = 2e9;   int n, q;   int h[maxn], v[maxn];   pair<pair<int, int>, int> b[maxn];   vector<int> hull[maxn];   long double inter(int id1, int id2) {     if (v[id1] == v[id2]) return -1;     return (long double)(h[id1] - h[id2]) / (v[id2] - v[id1]);   }   long double H(int idx, long double t) { return h[idx] + t * v[idx]; }   void update(int node, int x) {     while (hull[node].size() > 1) {       int sz = hull[node].size();       int id1 = hull[node][sz - 1];       int id2 = hull[node][sz - 2];       long double t = inter(id1, id2);       if (v[id1] == v[x] or H(x, t) >= H(id1, t))         hull[node].pop_back();       else         break;     }     if (hull[node].size() == 1 and h[*hull[node].begin()] < h[x])       hull[node].pop_back();     hull[node].push_back(x);   }   void add(int node, int l, int r, int idx) {     if (idx < l or r <= idx) return;     update(node, idx);     if (r - l < 2) return;     int mid = (l + r) / 2;     add((node + node + 0), l, mid, idx);     add((node + node + 1), mid, r, idx);   }   pair<long double, int> find(int node, int t) {     int l = 0, r = hull[node].size();     for (; r - l > 1;) {       int mid = (l + r) / 2;       if (inter(hull[node][mid], hull[node][mid - 1]) <= t)         l = mid;       else         r = mid;     }     return make_pair(H(hull[node][l], t), hull[node][l]);   }   pair<long double, int> ans(int node, int l, int r, int s, int e, int t) {     if (e <= l or r <= s) return make_pair(-inf, n);     if (s <= l and r <= e) return find(node, t);     int mid = (l + r) / 2;     return max(ans((node + node + 0), l, mid, s, e, t),                ans((node + node + 1), mid, r, s, e, t));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> h[i] >> v[i];       b[i].first.second = h[i];       b[i].first.first = v[i];       b[i].second = i;     }     h[n] = -1;     v[n] = 0;     sort(b, b + n);     for (int i = 0; i < n; i++) add(1, 0, n, b[i].second);     for (int l, r, t; q--;) {       cin >> l >> r >> t;       l--, r--;       cout << ans(1, 0, n, l, r + 1, t).second + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, num;     cin >> n >> k;     num = (n) * (n - 1) / 2;     if (num <= k)       cout <<  no solution  << endl;     else       for (int i = 1; i <= n; i++) cout << 1 <<     << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000009;   const int MOD = 1000000007;   double probMayor(pair<int, int> x, int bid) {     if (bid < x.first) {       return 1.0;     }     if (bid > x.second) {       return 0.0;     }     return double(x.second - bid) / (x.second - x.first + 1);   }   double probMenor(pair<int, int> x, int bid) {     if (bid < x.first) {       return 0.0;     }     if (bid > x.second) {       return 1.0;     }     return double(bid - x.first) / (x.second - x.first + 1);   }   double go(vector<pair<int, int> > v, int idx, int bid, int cnt) {     if (idx >= v.size()) {       if (cnt <= 0) {         return 1;       }       return 0;     }     double res = 0.0;     if (bid >= v[idx].first && bid <= v[idx].second) {       res += go(v, idx + 1, bid, cnt - 1) *              (1.0 / (v[idx].second - v[idx].first + 1));     }     res += go(v, idx + 1, bid, cnt) * probMenor(v[idx], bid);     return res;   }   int main() {     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       v.push_back(make_pair(l, r));     }     double res = 0.0;     for (int i = 0; i < n; i++) {       pair<int, int> p = v[i];       v.erase(v.begin() + i);       for (int j = 1; j <= 10000; j++) {         res += probMayor(p, j) * j * go(v, 0, j, 1);       }       v.insert(v.begin() + i, p);     }     for (int j = 1; j <= 10000; j++) {       res += j * go(v, 0, j, 2);     }     printf( %.10f n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 305, MOD = 1e4 + 7;   char s[N];   int n, m, ndc, f[N][N][N];   int getf(int cnt, int l, int r) {     if (cnt < 0) return 0;     if (~f[cnt][l][r]) return f[cnt][l][r];     if (l == 1 && r == m) return f[cnt][l][r] = !cnt;     int ret = 0;     if (l > 1 && r < m && s[l - 1] == s[r + 1])       ret = (ret + getf(cnt, l - 1, r + 1)) % MOD;     if (l > 1 && s[l - 1] != s[r]) ret = (ret + getf(cnt - 1, l - 1, r)) % MOD;     if (r < m && s[l] != s[r + 1]) ret = (ret + getf(cnt - 1, l, r + 1)) % MOD;     return f[cnt][l][r] = ret;   }   struct matrix {     int sq[N][N];     matrix() { memset(sq, 0, sizeof(sq)); }     matrix operator*(const matrix &a) const {       matrix ret;       for (int i = 1; i <= ndc; i++)         for (int j = i; j <= ndc; j++)           for (int k = i; k <= j; k++)             ret.sq[i][j] = (ret.sq[i][j] + 1ll * sq[i][k] * a.sq[k][j]) % MOD;       return ret;     }   } trs, one;   inline matrix qpow(matrix x, int y) {     matrix ret = one;     while (y) {       if (y & 1) ret = ret * x;       x = x * x;       y >>= 1;     }     return ret;   }   int idr[N], idg[N], cntc[N];   int main() {     int i, j, k, ans = 0;     scanf( %s%d , s + 1, &n);     m = strlen(s + 1);     idr[0] = ++ndc;     for (i = 1; i < m; i++) {       int rem = (m - i + 1) / 2;       if ((m - i + 1) / 2 != (m - i) / 2 + 1) idg[(m - i) / 2 + 1] = ++ndc;       idr[i] = ++ndc;     }     if (!idg[1]) idg[1] = ++ndc;     idg[0] = ++ndc;     for (i = 0; i < m; i++) {       if (i) trs.sq[idr[i]][idr[i]] = 24;       if (i < m - 1) trs.sq[idr[i]][idr[i + 1]] = 1;     }     for (i = (m + 1) / 2; i > 0; i--) {       trs.sq[idg[i]][idg[i]] = 25;       trs.sq[idg[i]][idg[i - 1]] = 1;     }     for (i = 1; i <= ndc; i++) one.sq[i][i] = 1;     memset(f, -1, sizeof(f));     for (i = 0; i < m; i++) {       for (j = 1; j <= m; j++) {         cntc[i] = (cntc[i] + getf(i, j, j)) % MOD;         if (j < m && s[j] == s[j + 1])           cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;       }     }     for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];     trs.sq[ndc][ndc] = 26;     ans = (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc];     if (!((n + m) & 1)) {       printf( %d , ans);       return 0;     }     memset(f, -1, sizeof(f));     memset(cntc, 0, sizeof(cntc));     for (i = 0; i < m; i++)       for (j = 1; j < m; j++)         if (s[j] == s[j + 1]) cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;     for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];     trs.sq[ndc][ndc] = 0;     ans = (ans - (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc] + MOD) % MOD;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       char ch;       string str;       cin >> str;       int n1 = 0, n2 = 0;       int ct = 0;       for (int i = 0; i < n; i++) {         if (str[i] ==  ( ) {           if (n2 > 0) {             if (n2 > n1) {               n2 = 0;               n1 = 0;             } else {               n1 -= n2;               n2 = 0;             }           }           n1++;         } else {           n2++;           if (n2 > n1) ct++;         }       }       cout << ct << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   double E = 2.71828182846;   double PI = 3.1415926535897932384626433832795;   double EPS = 1e-9;   const int ROOT = 444;   const int MAXN = 300100;   const int ROOTN = 555;   int n;   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   void solve() {     cin >> n;     for (int i = 0; i <= n; i += 1234567) {       for (int j = i; j <= n; j += 123456) {         if ((n - j) % 1234 == 0) {           cout <<  YES ;           return;         }       }     }     cout <<  NO ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(1313);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int X = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar();     return X * w;   }   const int N = 100 + 10;   inline int id(int x, int y) {     if (x & 1)       return (x - 1) * 10 + y;     else       return (x - 1) * 10 + 11 - y;   }   int to[N];   double dp[N];   int main() {     for (register int i = 1; i <= 10; ++i)       for (register int j = 1; j <= 10; ++j) to[id(i, j)] = id(i - read(), j);     for (register int i = 2; i <= 6; ++i) {       for (register int j = 1; j < i; ++j) dp[i] += dp[j] / 6;       dp[i] = (dp[i] + 1) / (i - 1) * 6;     }     for (register int i = 7; i <= 100; ++i) {       for (register int j = 1; j <= 6; ++j)         dp[i] += min(dp[i - j], dp[to[i - j]]);       dp[i] = dp[i] / 6 + 1;     }     printf( %.10lf n , dp[100]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 200005;   int ans, cnt0, cnt1, lth, pos1[MX], pos0[MX], pre[MX], nxt[MX];   char s[MX];   bool vis[MX];   int main() {     scanf( %s , s + 1);     lth = strlen(s + 1);     for (int i = 1; i <= lth; i++) {       if (s[i] ==  0 )         pos0[++cnt0] = i;       else         pos1[++cnt1] = i;       if (cnt1 > cnt0) return puts( -1 ), 0;     }     cnt0 = cnt1 = 0;     for (int i = lth; i; i--) {       if (s[i] ==  0 )         cnt0++;       else         cnt1++;       if (cnt1 > cnt0) return puts( -1 ), 0;     }     printf( %d n , cnt0 - cnt1);     for (int i = 1; i <= cnt1; i++)       pre[pos1[i]] = pos0[i], nxt[pos0[i]] = pos1[i];     for (int i = cnt1, j = cnt0; i; i--, j--)       nxt[pos1[i]] = pos0[j], pre[pos0[j]] = pos1[i];     for (int i = 1; i <= lth; i++)       if (!vis[i]) {         int cnt = 0;         for (int j = i; j; j = nxt[j]) cnt++, vis[j] = 1;         printf( %d  , cnt);         for (int j = i; j; j = nxt[j]) printf( %d  , j);         putchar(  n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   void solve() {     long long int n, m;     cin >> n >> m;     vector<long long int> v(m);     for (auto &it : v) cin >> it;     ;     vector<long long int> suf(m);     long long int s = 0;     for (long long int i = m - 1; i >= 0; i--) {       if (i + v[i] - 1 > n - 1) {         cout << -1 <<   n ;         return;       }       s += v[i];       suf[i] = s;     }     if (s < n) {       cout << -1 <<   n ;       return;     }     long long int j = 0;     long long int start = 0, prev = -1;     vector<long long int> ans;     for (long long int i = 0; i < m; i++) {       cout << max(n - suf[i] + 1, i + 1) <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) solve();     return 0;   }


#include<fstream>   #include<iostream>   #include<sstream>   #include<iomanip>   #include<string>   #include<vector>   #include<list>   #include<set>   #include<map>   #include<queue>   #include<algorithm>   #include<functional>   #include<numeric>   #include<bitset>   #include<cassert>   #include<array>   #include  string.h    #include  math.h    using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   #define mp make_pair      #ifndef BLAH   #define fin cin   #define fout cout   #endif      namespace   {      }      int main()   {    ios::sync_with_stdio(0);   #ifdef BLAH    ifstream fin( test.in );    ofstream fout( test.out );   #endif       int zzz; fin >> zzz;    for (int zz = 1; zz <= zzz; ++zz)    {     int n, m; fin >> n >> m;     string s, ss;     fin >> s;     s =  0  + s +  0 ;        for (int t = 0; t < m; ++t)     {      ss = s;      for (int i = 1; i <= n; ++i)      {       if (s[i - 1] != s[i + 1])        ss[i] =  1 ;      }      if (s == ss) break;      swap(s, ss);     }        fout << s.substr(1, n) << endl;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long modExponentiate(unsigned long long a, unsigned long long b) {     if (b == 0) return 1;     unsigned long long ans = a;     unsigned long long t = 1;     while (b > 1) {       if (b % 2 == 0) {         ans = (ans * ans) % (1000000007);         a = (a * a) % 1000000007;         b = b / 2;       } else {         t = (t * a) % 1000000007;         b = b - 1;       }     }     return (t * ans) % 1000000007;   }   int noofz(int a) {     int no = 0;     while (a > 0) {       if ((a % 2) == 1) no++;       a = a / 2;     }     return (6 - no);   }   int main() {     map<char, int> m;     for (int i = 0; i < 10; i++) m[(char)( 0  + i)] = noofz(i);     for (int i = 10; i < 36; i++) m[(char)( A  + i - 10)] = noofz(i);     for (int i = 36; i < 62; i++) m[(char)( a  + i - 36)] = noofz(i);     m[ - ] = noofz(62);     m[ _ ] = noofz(63);     char str[100001];     cin >> str;     long long ans = 1LL;     long long anslog = 0LL;     for (int i = 0; i < strlen(str); i++) {       anslog = anslog + m[str[i]];     }     ans = modExponentiate(3, anslog);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int steps, count, i, n;     char str[500];     char pc;     scanf( %s , str);     steps = count = 0;     n = strlen(str);     if (n == 0) {       printf( 0 n );       return 0;     }     pc = str[0];     count = 1;     for (i = 1; i < n; i++) {       if (count == 5) {         count = 1;         steps++;         pc = str[i];         continue;       }       if (pc == str[i])         count++;       else {         count = 1;         steps++;         pc = str[i];       }     }     if (count > 0) steps++;     printf( %d n , steps);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e9;   const long long MOD = 1e9 + 7;   mt19937 azino(777);   int ask(int a, int b, int c) {     cout <<  ?   << a <<     << b <<     << c << endl;     int x;     cin >> x;     return x;   }   void answer(vector<int>& ans) {     cout <<  !   << ans.size() <<    ;     for (auto& it : ans) cout << it <<    ;     cout << endl;     return;   }   vector<int> pp(int pos0, int pos1, int pos, int type) {     vector<int> p(3, -1);     if (type == 0) {       int c1 = ask(pos1, pos, pos + 1);       int c2 = ask(pos1, pos, pos + 2);       if (c1 == c2) {         if (c1 == 0) p[0] = p[1] = p[2] = 0;         if (c1 == 1) p[0] = 1, p[1] = p[2] = 0;       } else {         if (c1 == 0) p[0] = p[1] = 0;         if (c2 == 0) p[0] = p[2] = 0;         for (auto& i : p)           if (i == -1) i = 1;       }     } else {       int c1 = ask(pos0, pos, pos + 1);       int c2 = ask(pos0, pos, pos + 2);       if (c1 == c2 && c1 == 1)         p[0] = p[1] = p[2] = 1;       else if (c1 == c2 && c1 == 0)         p[0] = 0, p[1] = p[2] = 1;       else {         if (c1 == 1) p[0] = p[1] = 1;         if (c2 == 1) p[0] = p[2] = 1;         for (auto& i : p)           if (i == -1) i = 0;       }     }     return p;   }   void solve() {     int n;     cin >> n;     vector<int> z(n);     int pos0 = 0, pos1 = 0;     for (int i = 0; i < n; i += 3) {       z[i] = ask(i + 1, i + 2, i + 3);       if (z[i])         pos1 = i;       else         pos0 = i;     }     vector<int> p0(3, -1), p1(3, -1);     int c1 = ask(pos1 + 1, pos1 + 2, pos0 + 1);     int c2 = ask(pos1 + 1, pos1 + 2, pos0 + 2);     int poss0 = -1, poss1 = -1;     if (c1 == c2) {       if (c1 == 0)         p0[0] = p0[1] = 0;       else         p1[0] = p1[1] = 1;     } else {       p0[0] = c1, p0[1] = c2;       if (c1 == 0)         poss0 = pos0 + 1;       else         poss1 = pos0 + 1;       if (c2 == 0)         poss0 = pos0 + 2;       else         poss1 = pos0 + 2;     }     if (p0[0] == -1) {       c1 = ask(pos1 + 1, pos0 + 1, pos0 + 2);       c2 = ask(pos1 + 1, pos0 + 1, pos0 + 3);       if (c1 == c2 && c1 == 0)         p0[0] = p0[1] = p0[2] = 0;       else if (c1 == c2 && c1 == 1)         p0[0] = 1, p0[1] = p0[2] = 0;       else {         if (c1 == 0) p0[0] = p0[1] = 0;         if (c2 == 0) p0[0] = p0[2] = 0;         for (auto& i : p0)           if (i == -1) i = 1;       }       for (int i = 0; i < 3; ++i)         if (p0[i] == 0)           poss0 = pos0 + 1 + i;         else           poss1 = pos0 + 1 + i;       c1 = ask(poss0, pos1 + 1, pos1 + 2);       c2 = ask(poss0, pos1 + 1, pos1 + 3);       if (c1 == c2) {         if (c1 == 1) p1[0] = p1[1] = p1[2] = 1;         if (c1 == 0) p1[0] = 0, p1[1] = p1[2] = 1;       } else {         if (c1 == 1) p1[0] = p1[1] = 1;         if (c2 == 1) p1[0] = p1[2] = 1;         for (auto& i : p1)           if (i == -1) i = 0;       }       for (int i = 0; i < 3; ++i)         if (p1[i] == 0)           poss0 = pos1 + 1 + i;         else           poss1 = pos1 + 1 + i;     } else {       if (poss0 != -1) {         for (int i = 0; i < 3; ++i) p1[i] = ask(poss1, poss0, pos1 + 1 + i);         p0[2] = ask(poss1, poss0, pos0 + 3);       } else {         c1 = ask(pos0 + 1, pos1 + 1, pos1 + 2);         c2 = ask(pos0 + 1, pos1 + 1, pos1 + 3);         if (c1 == c2 && c1 == 1)           p1[0] = p1[1] = p1[2] = 1;         else if (c1 == c2 && c1 == 0)           p1[0] = 0, p1[1] = p1[2] = 1;         else {           if (c1 == 1) p1[0] = p1[1] = 1;           if (c2 == 1) p1[0] = p1[2] = 1;           for (auto& i : p1)             if (i == -1) i = 0;         }         for (int i = 0; i < 3; ++i)           if (p1[i] == 0)             poss0 = pos1 + 1 + i;           else             poss1 = pos1 + 1 + i;         c1 = ask(poss1, pos0 + 1, pos0 + 2);         c2 = ask(poss1, pos0 + 1, pos0 + 3);         if (c1 == c2) {           if (c1 == 0) p0[0] = p0[1] = p0[2] = 0;           if (c1 == 1) p0[0] = 1, p0[1] = p0[2] = 0;         } else {           if (c1 == 0) p0[0] = p0[1] = 0;           if (c2 == 0) p0[0] = p0[2] = 0;           for (auto& i : p0)             if (i == -1) i = 1;         }         for (int i = 0; i < 3; ++i)           if (p0[i] == 0)             poss0 = pos0 + 1 + i;           else             poss1 = pos0 + 1 + i;       }     }     vector<int> ans;     for (int i = 0; i < 3; ++i)       if (p0[i] == 0) ans.emplace_back(pos0 + i + 1);     for (int i = 0; i < 3; ++i)       if (p1[i] == 0) ans.emplace_back(pos1 + i + 1);     for (int i = 0; i < n; i += 3) {       if (i == pos0 || i == pos1) continue;       auto it = pp(poss0, poss1, i + 1, z[i]);       for (int j = 0; j < 3; ++j)         if (it[j] == 0) ans.emplace_back(i + 1 + j);     }     answer(ans);   }   signed main() {     cout << fixed << setprecision(15);     int t;     cin >> t;     while (t-- > 0) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     long long int lift = abs(x - z) * t2 + 3 * t3 + abs(x - y) * t2,                   walk = abs(x - y) * t1;     if (lift <= walk)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T;   char s[2000];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %s , s + 1);       int l = strlen(s + 1);       if (s[l] ==  o  && s[l - 1] ==  p )         printf( FILIPINO n );       else if (s[l] ==  u  && s[l - 1] ==  s  && s[l - 2] ==  e  &&                    s[l - 3] ==  d  ||                s[l] ==  u  && s[l - 1] ==  s  && s[l - 2] ==  a  &&                    s[l - 3] ==  m )         printf( JAPANESE n );       else         printf( KOREAN n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int a[maxn], b[maxn];   int n, m;   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 0; i < n; i++) scanf( %d , a + i);       for (int i = 0; i < m; i++) scanf( %d , b + i);       int dis, ans = 0;       for (int i = 0; i < n; i++) {         int tmp = lower_bound(b, b + m, a[i]) - b;         if (tmp == 0)           dis = b[0] - a[i];         else if (tmp == m)           dis = a[i] - b[m - 1];         else           dis = min(b[tmp] - a[i], a[i] - b[tmp - 1]);         ans = max(ans, dis);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   const int mod = 1e9 + 7;   inline int cal(int x, int y) {     int l = 0, r = 1e9;     while (l < r) {       int mid = l + r + 1 >> 1;       if (3ll * mid + y <= x)         l = mid;       else         r = mid - 1;     }     if (y > x) return 0;     return l + 1;   }   int main() {     int n, l, r;     while (~scanf( %d%d%d , &n, &l, &r)) {       int cnt[5] = {0}, dp[2][5] = {0}, t = 0;       for (int i = 0; i < 3; i++) {         cnt[i] = cal(r, i) - cal(l - 1, i);       }       dp[0][0] = 1;       for (int i = 1; i <= n; i++) {         t ^= 1;         for (int j = 0; j < 3; j++) {           dp[t][j] = 0;           for (int k = 0; k < 3; k++) {             dp[t][j] += 1ll * cnt[k] * dp[t ^ 1][(j - k + 3) % 3] % mod;             if (dp[t][j] >= mod) dp[t][j] -= mod;           }         }       }       printf( %d n , dp[t][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   const double Exp = 1e-9;   int sgn(double x) {     if (fabs(x) < Exp) return 0;     return x > 0 ? 1 : -1;   }   struct Point {     double x, y;     Point(double x = 0, double y = 0) : x(x), y(y) {}     friend Point operator+(const Point &a, const Point &b) {       return Point(a.x + b.x, a.y + b.y);     }     friend Point operator-(const Point &a, const Point &b) {       return Point(a.x - b.x, a.y - b.y);     }     friend Point operator*(const Point &a, double b) {       return Point(a.x * b, a.y * b);     }     friend Point operator/(const Point &a, double b) {       return Point(a.x / b, a.y / b);     }     Point rotate(double del) {       return Point(x * cos(del) - y * sin(del), x * sin(del) + y * cos(del));     }   } s, t, island[40];   vector<Point> vec;   double Dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }   double Cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }   double Length(const Point &a) { return sqrt(Dot(a, a)); }   struct Line {     Point p, v;     Line(Point p, Point v) : p(p), v(v) {}     Point get_point(double t) { return p + v * t; }   };   Point get_line_intersection(const Line &l1, const Line &l2) {     Point a = l1.p, b = l1.p + l1.v;     Point c = l2.p, d = l2.p + l2.v;     double u = Cross(d - a, c - a), v = Cross(c - b, d - b);     double t = u / (u + v);     return a + (b - a) * t;   }   int if_point_on_line(const Point &p, const Point &st, const Point &ed) {     return sgn(Cross(p - st, ed - st)) == 0;   }   int if_point_on_ray(const Point &p, const Point &st, const Point &ed) {     if (sgn(Cross(p - st, ed - st)) != 0) return 0;     if (sgn(Dot(p - st, ed - st)) < 0) return 0;     return 1;   }   int if_point_on_segment(const Point &p, const Point &st, const Point &ed) {     return if_point_on_ray(p, st, ed) && if_point_on_ray(p, ed, st);   }   int main() {     cin >> s.x >> s.y >> t.x >> t.y;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> island[i].x >> island[i].y;     }     double sum = 0;     int flag = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       int l = i, r = i + 1;       r %= n;       sum += Length(island[r] - island[l]);     }     for (int i = 0; i < n; i++) {       int l = i, r = i + 1;       r %= n;       if (flag == 1 && cnt < 2) vec.push_back(island[l]);       Point now;       if (sgn(Cross(s - t, island[r] - island[l])) != 0) {         now = get_line_intersection(Line(s, t - s),                                     Line(island[r], island[l] - island[r]));         if (if_point_on_segment(now, island[l], island[r])) {           if ((vec.size() > 0 && sgn(Length(vec[vec.size() - 1] - now)) != 0) ||               vec.size() == 0) {             if (if_point_on_segment(now, s, t)) {               cnt++;               flag = 1;               vec.push_back(now);               if (cnt == 2) break;             }           }         }       } else if (if_point_on_line(island[l], s, t)) {         flag = 2;         break;       }     }     if (flag == 2 || cnt == 0) {       double ans = Length(s - t);       printf( %.9lf n , ans);       return 0;     }     double edge_len = 0;     for (int i = 1; i < vec.size(); i++) {       edge_len += Length(vec[i] - vec[i - 1]);     }     edge_len = min(edge_len, sum - edge_len);     double s_len = min(Length(s - vec[0]), Length(s - vec[vec.size() - 1]));     double t_len = min(Length(t - vec[0]), Length(t - vec[vec.size() - 1]));     double ans1 = edge_len + s_len + t_len;     double rest_len = Length(s - t);     rest_len -= s_len + t_len;     double ans2 = s_len + t_len + 2 * rest_len;     double ans = min(ans1, ans2);     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, h;     cin >> s;     h = s;     sort(h.begin(), h.end());     if (s != h) {       cout <<  NO ;       return 0;     }     int a = 0, b = 0, c = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  a ) {         a++;       } else if (s[i] ==  b ) {         b++;       } else {         c++;       }     }     if (a != 0 && b != 0 && (a == c || b == c)) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }