#include <bits/stdc++.h>   using namespace std;   vector<int> v;   void dfs(int depth, bool state) {     if (depth == 0) return;     dfs(depth - 1, !state);     v.push_back(state);     dfs(depth - 1, state);   }   int main() {     int N;     cin >> N;     int D = 1;     while (1 << D <= N) D++;     dfs(D - 1, 1);     int n = v.size();     for (int i = 0; i < (int)v.size() - 1; i++) n += (v[i] == v[i + 1]);     cout << (n == N or n + 1 == N) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long inf = 1LL << 30;   const double eps = 1e-9;   const long long mod = 1e9 + 7;   const int N = 100100;   pair<int, pair<int, int>> a[N];   int seg[N << 2], lazy[N << 2];   ;   int ans[N];   int dp[N];   void push(int nd, int L, int R) {     if (lazy[nd] == 0) return;     seg[nd] = 0;     if (L != R) {       lazy[nd << 1] = 1;       lazy[nd << 1 | 1] = 1;     }     lazy[nd] = 0;   }   void update(int nd, int L, int R, int idx, int val) {     if (L == R) {       seg[nd] = val;       return;     }     int mid = (L + R) >> 1;     if (idx <= mid)       update(nd << 1, L, mid, idx, val);     else       update(nd << 1 | 1, mid + 1, R, idx, val);     seg[nd] = seg[nd << 1] + seg[nd << 1 | 1];   }   long long query(int nd, int L, int R, int from, int to) {     push(nd, L, R);     if (from <= L && R <= to) return seg[nd];     if (from > R || to < L) return 0;     int mid = (L + R) >> 1;     long long leftAns = query(nd << 1, L, mid, from, to);     long long rightAns = query(nd << 1 | 1, mid + 1, R, from, to);     return leftAns + rightAns;   }   void updateRange(int nd, int L, int R, int from, int to) {     push(nd, L, R);     if (R < from || L > to) return;     if (from <= L && R <= to) {       lazy[nd] = 1;       push(nd, L, R);       return;     }     int mid = (L + R) >> 1;     updateRange(nd << 1, L, mid, from, to);     updateRange(nd << 1 | 1, mid + 1, R, from, to);     seg[nd] = seg[nd << 1] + seg[nd << 1 | 1];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i].first, &a[i].second.first);       a[i].second.second = i;     }     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       int j = lower_bound(                   a, a + n,                   make_pair(a[i].first + a[i].second.first, make_pair(0, 0))) -               a - 1;       dp[i] = 1 + query(1, 1, n, i, j);       updateRange(1, 1, n, i + 1, j);       update(1, 1, n, i, dp[i]);       ans[a[i].second.second] = dp[i];     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2005;   int n, h, l, r, a[maxN];   int dp[maxN][maxN];   inline int getint() {     int num = 0, bj = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c == EOF) return EOF;       bj = (c ==  -  || bj == -1) ? -1 : 1, c = getchar();     }     while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar();     return num * bj;   }   void init() {     cin >> n >> h >> l >> r;     for (int i = 1; i <= n; ++i) {       a[i] = getint();     }   }   int cor(int x) { return (x % h + h) % h; }   void solve() {     memset(dp, -1, sizeof(dp));     int ans = -1;     (a[1] >= l && a[1] <= r)                     ? dp[1][a[1]] = 1,                                ans = max(ans, 1) : dp[1][a[1]] = 0,                                ans = max(ans, 0);     (a[1] - 1 >= l && a[1] - 1 <= r)         ? dp[1][a[1] - 1] = 1,                        ans = max(ans, 1) : dp[1][a[1] - 1] = 0, ans = max(ans, 0);     for (int i = 2; i <= n; ++i) {       for (int j = 0; j < h; ++j) {         if (dp[i - 1][cor(j - a[i])] == -1 && dp[i - 1][cor(j - a[i] + 1)] == -1)           continue;         dp[i][j] = max(dp[i - 1][cor(j - a[i])], dp[i - 1][cor(j - a[i] + 1)]);         if (j >= l && j <= r) dp[i][j]++;         ans = max(ans, dp[i][j]);       }     }     cout << ans << endl;   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> cnt(string s) {     int bal = 0, minBal = 0;     for (char c : s) {       if (c ==  ( )         bal++;       else         bal--;       minBal = min(minBal, bal);     }     return {bal, minBal};   }   int k[400400];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> bal(n), minBal(n);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       auto p = cnt(s);       bal[i] = p.first;       minBal[i] = p.second;       if (bal[i] >= 0 && minBal[i] >= 0) k[bal[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (bal[i] > 0) continue;       if (minBal[i] - bal[i] >= 0) ans += (long long)k[-bal[i]];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int INF = 0x3f3f3f3f;   const int mo = 1e9 + 7;   inline int ksm(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = 1ll * a * a % mo)       if (b & 1) ret = 1ll * ret * a % mo;     return ret;   }   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n = 4, m, f[N][21], dep[N];   struct node {     int u, v, mx;     bool operator<(const node &A) const { return mx < A.mx; }   } a;   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 20; i >= 0; i--)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; i--)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   int dist(int x, int y) {     int lca = LCA(x, y);     return dep[x] + dep[y] - 2 * dep[lca];   }   void add(int u) {     int x = n + 1, y = n + 2;     n += 2;     dep[x] = dep[y] = dep[u] + 1;     f[x][0] = f[y][0] = u;     for (int i = 1; i <= 20; i++) f[x][i] = f[y][i] = f[f[x][i - 1]][i - 1];     int xx = a.u, yy = a.v;     node b = (node){xx, x, dist(xx, x)}, c = (node){xx, y, dist(xx, y)};     node d = (node){yy, x, dist(yy, x)}, e = (node){yy, y, dist(yy, y)};     node f = (node){xx, yy, dist(xx, yy)};     if (a < b) a = b;     if (a < c) a = c;     if (a < d) a = d;     if (a < e) a = e;     if (a < f) a = f;   }   signed main() {     dep[1] = 1;     a.u = 2, a.v = 4, a.mx = 2;     dep[2] = dep[3] = dep[4] = 2;     f[1][0] = f[2][0] = f[3][0] = f[4][0] = 1;     m = read();     for (; m; m--) {       int u = read();       add(u);       printf( %d n , a.mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[200001];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d %d , &x, &y);       a[x].push_back(y);     }     set<pair<int, int> > S;     for (int i = 1; i <= n; i++) {       sort(a[i].begin(), a[i].end());       if (!a[i].empty()) {         S.insert(make_pair(a[i][a[i].size() - 1], i));       }     }     int q;     cin >> q;     while (q--) {       int k;       scanf( %d , &k);       vector<pair<int, int> > temp;       for (int i = 1; i <= k; i++) {         int x;         scanf( %d , &x);         if (a[x].size()) {           S.erase(make_pair(a[x][a[x].size() - 1], x));           temp.push_back(make_pair(a[x][a[x].size() - 1], x));         }       }       if (S.size() == 0) {         cout <<  0 0 n ;       } else if (S.size() == 1) {         set<pair<int, int> >::iterator it;         it = S.begin();         int x = it->second, y = it->first;         printf( %d %d n , x, a[x][0]);       } else {         set<pair<int, int> >::reverse_iterator it;         it = S.rbegin();         int u = it->second;         it++;         int x = it->second, y = it->first;         int ans = *upper_bound(a[u].begin(), a[u].end(), y);         printf( %d %d n , u, ans);       }       for (int i = 0; i < temp.size(); i++) {         S.insert(temp[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> c;   int main() {     int l1, l2, f, ans = 0;     string s1, s2;     cin >> s1 >> s2;     l1 = s1.length();     l2 = s2.length();     for (int i = 1; i <= min(l1, l2); i++)       if (l1 % i == 0 && l2 % i == 0) {         f = 0;         c.clear();         for (int j = 0; j < l1; j += i) c[s1.substr(j, i)]++;         if (c[s1.substr(0, i)] == l1 / i) f++;         c.clear();         for (int j = 0; j < l2; j += i) c[s2.substr(j, i)]++;         if (c[s1.substr(0, i)] == l2 / i) f++;         if (f == 2) ans++;       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const MAX = 1e5 + 41;   int n;   int q;   int s[MAX];   int m[MAX];   int r[MAX];   int const BLOCK = 441;   bool sp[MAX];   int lt[MAX];   int ltb[MAX];   vector<pair<int, int> > a[MAX];   vector<long long> prefsum[MAX];   vector<long long> prefspeed[MAX];   int const INF = 2e9 + 41;   void init() {     for (int i = 0, k = 0; i < n; i += BLOCK, k++) {       for (int j = 0; j <= BLOCK - 1; j++) {         if (i + j >= n) break;         int m = ::m[i + j];         int r = ::r[i + j];         if (r != 0) {           a[k].push_back(make_pair((m + r - 1) / r, i + j));         } else {           a[k].push_back(make_pair(INF, i + j));         }       }       sort(a[k].begin(), a[k].end());       long long sm = 0;       long long sr = 0;       for (int j = 0; j <= (int)a[k].size() - 1; j++) {         int m = ::m[a[k][j].second];         int r = ::r[a[k][j].second];         sm += m;         sr += r;         prefsum[k].push_back(sm);         prefspeed[k].push_back(sr);       }     }   }   long long queryblock(int id, int t) {     long long res = 0;     int p = (int)(lower_bound(a[id].begin(), a[id].end(),                               make_pair(t - ltb[id], INF)) -                   a[id].begin());     p--;     if (p >= 0) {       res += prefsum[id][p];     }     res += prefspeed[id].back() * (t - ltb[id]);     if (p >= 0) {       res -= prefspeed[id][p] * (t - ltb[id]);     }     ltb[id] = t;     return res;   }   long long bruteblock(int id, int l, int r, int t) {     if (l > r) return 0LL;     l -= BLOCK * id;     r -= BLOCK * id;     sp[id] = false;     int sh = id * BLOCK;     for (int i = 0; i <= (int)a[id].size() - 1; i++) {       lt[sh + i] = max(lt[sh + i], ltb[id]);     }     long long res = 0;     for (int i = l; i <= r; i++) {       long long add = min((long long)m[sh + i],                           (long long)::r[sh + i] * (t - lt[sh + i]) + s[sh + i]);       res += add;       lt[sh + i] = t;       s[sh + i] = 0;     }     return res;   }   int getblockright(int x) {     int res = (x / BLOCK + 1) * BLOCK - 1;     res = min(res, n - 1);     return res;   }   int getblockleft(int x) { return x / BLOCK * BLOCK; }   void solve() {     init();     scanf( %d , &q);     for (int o = 1; o <= q; o++) {       int t, l, r;       scanf( %d %d %d , &t, &l, &r);       l--;       r--;       long long res = 0;       int rl = min(r, getblockright(l));       res += bruteblock(l / BLOCK, l, rl, t);       l = rl + 1;       int lr = max(l, getblockleft(r));       res += bruteblock(r / BLOCK, lr, r, t);       r = lr;       while (l < r) {         if (sp[l / BLOCK]) {           res += queryblock(l / BLOCK, t);         } else {           res += bruteblock(l / BLOCK, l, l + BLOCK - 1, t);           sp[l / BLOCK] = 1;           ltb[l / BLOCK] = t;         }         l += BLOCK;       }       printf( %lld n , res);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n - 1; i++) {       scanf( %d %d %d , &s[i], &m[i], &r[i]);     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], pn = 11, sumid[500005], lazy2[500005];   long long sum[500005], sum2[500005], pw[15], lazy[500005];   set<int> st;   void getsum(int x) {     sum2[x] = sum[x] - *lower_bound(pw + 1, pw + pn + 1, sum[x]);   }   void pushup(int x) {     sum2[x] = max(sum2[x * 2], sum2[x * 2 + 1]);     sum[x] = max(sum[x * 2], sum[x * 2 + 1]);     if (sum2[x] == sum2[x * 2])       sumid[x] = sumid[x * 2];     else       sumid[x] = sumid[x * 2 + 1];   }   void col(int x, long long v) {     sum2[x] += v;     sum[x] += v;     lazy[x] += v;   }   void col2(int x) {     sum[x] = 1e17;     getsum(x);     lazy[x] = 0;     lazy2[x] = 1;   }   void pushdown(int x) {     if (lazy2[x]) {       col2(x * 2);       col2(x * 2 + 1);       lazy2[x] = 0;     }     if (lazy[x]) {       col(x * 2, lazy[x]);       col(x * 2 + 1, lazy[x]);       lazy[x] = 0;     }   }   void build(int x, int l, int r) {     if (l == r) {       sum[x] = a[l];       getsum(x);       sumid[x] = l;       return;     }     int mid = (l + r) / 2;     build(x * 2, l, mid);     build(x * 2 + 1, mid + 1, r);     pushup(x);   }   void modify(int x, int l, int r, int ql, int qr) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr) {       col2(x);       return;     }     pushdown(x);     int mid = (l + r) / 2;     modify(x * 2, l, mid, ql, qr);     modify(x * 2 + 1, mid + 1, r, ql, qr);     pushup(x);   }   void modifyp(int x, int l, int r, int qx, long long v) {     if (l > qx || r < qx) return;     if (l == r) {       sum[x] = v;       getsum(x);       return;     }     pushdown(x);     int mid = (l + r) / 2;     modifyp(x * 2, l, mid, qx, v);     modifyp(x * 2 + 1, mid + 1, r, qx, v);     pushup(x);   }   void modifya(int x, int l, int r, int ql, int qr, long long v) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr) {       col(x, v);       return;     }     pushdown(x);     int mid = (l + r) / 2;     modifya(x * 2, l, mid, ql, qr, v);     modifya(x * 2 + 1, mid + 1, r, ql, qr, v);     pushup(x);   }   long long query(int x, int l, int r, int qx) {     if (l > qx || r < qx) return 0;     if (l == r) return sum[x];     pushdown(x);     int mid = (l + r) / 2;     return query(x * 2, l, mid, qx) + query(x * 2 + 1, mid + 1, r, qx);   }   void querysum2(int x, int l, int r, int ql, int qr, long long &ans, int &id) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr) {       if (sum2[x] > ans) {         ans = sum2[x];         id = sumid[x];       }       return;     }     pushdown(x);     int mid = (l + r) / 2;     querysum2(x * 2, l, mid, ql, qr, ans, id);     querysum2(x * 2 + 1, mid + 1, r, ql, qr, ans, id);     pushup(x);   }   void check(int x) {     int u = *st.lower_bound(x);     if (u != x) {       st.insert(x);       modifyp(1, 1, n, x, query(1, 1, n, u));     }   }   void print(int x, int l, int r) {     printf( x=%d,l=%d,r=%d,sum=%lld,sum2=%lld n , x, l, r, sum[x], sum2[x]);     if (l == r) return;     pushdown(x);     int mid = (l + r) / 2;     print(x * 2, l, mid);     print(x * 2 + 1, mid + 1, r);   }   int main() {     pw[0] = 1;     for (int i = 1; i <= pn; i++) pw[i] = pw[i - 1] * 42;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, 1, n);     for (int i = 1; i <= n; i++) st.insert(i);     for (int i = 1; i <= m; i++) {       int op, l, r, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d , &x);         int u = *st.lower_bound(x);         printf( %lld n , query(1, 1, n, u));         continue;       }       scanf( %d%d%d , &l, &r, &x);       if (l - 1) check(l - 1);       check(r);       if (op == 2) {         modify(1, 1, n, l, r - 1);         modifyp(1, 1, n, r, x);         while (1) {           set<int>::iterator it;           it = st.lower_bound(l);           if (it == st.end() || *it >= r) break;           st.erase(it);         }       } else {         while (1) {           modifya(1, 1, n, l, r, x);           while (sum2[1] > 0) {             int u = sumid[1];             modifyp(1, 1, n, u, query(1, 1, n, u));           }           long long ans = -1e18;           int id = 0;           querysum2(1, 1, n, l, r, ans, id);           if (ans < 0) break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     if (x < 0) return -x;     return x;   }   template <class T>   T sqr(T a) {     return a * a;   }   const double pi = acos(-1.0);   const double eps = 1e-8;   int i, n, cnt;   char s1[110], s2[110];   void fun1() {     if (s1[i + 1] ==  0 ) {       s1[i + 1] =  X ;       cnt++;     } else if (s2[i + 1] ==  0 ) {       s2[i + 1] =  X ;       cnt++;     }   }   void fun2() {     if (s1[i + 1] ==  0  && s2[i + 1] ==  0 ) {       s1[i + 1] =  X ;       s2[i + 1] =  X ;       cnt++;     }   }   int main() {     while (2 == scanf( %s%s , &s1, s2)) {       cnt = 0;       n = strlen(s1);       for (i = 0; i < n - 1; i++) {         if (s1[i] ==  0  && s2[i] ==  0 ) fun1();         if (s1[i] ==  0  || s2[i] ==  0 ) fun2();       }       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int check(string s) {     int d = 0;     for (int i = 0; i < s.length(); i++)       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  o  || s[i] ==  u  || s[i] ==  i )         d++;     return d;   }   int main() {     string s1, s2, s3;     getline(cin, s1);     getline(cin, s2);     getline(cin, s3);     if (check(s1) == 5 && check(s2) == 7 && check(s3) == 5)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const int N = 55;   string s[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> s[i];     int sx, sy, ex, ey;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if (s[i][j] ==  S ) sx = i, sy = j;         if (s[i][j] ==  E ) ex = i, ey = j;       }     string w;     cin >> w;     string p =  ULDR ;     sort((p).begin(), (p).end());     map<char, int> dx = {{ D , -1}, { U , +1}};     map<char, int> dy = {{ L , -1}, { R , +1}};     int ans = 0;     do {       bool ok = true;       int x = sx, y = sy;       for (int i = 0; i < w.size(); ++i) {         if (x == ex && y == ey) break;         if (x < 0 || x >= n || y < 0 || y >= m || s[x][y] ==  # ) {           ok = false;           break;         }         x += dx[p[w[i] -  0 ]];         y += dy[p[w[i] -  0 ]];       }       if (ok && x == ex && y == ey) ++ans;     } while (next_permutation((p).begin(), (p).end()));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str1[200002], str2[200002];   const int K = 1024;   int aw[200002];   int bw[200002];   char bit[1 << 16];   short cnt[200002 / K + 1][200002];   int main() {     gets(str1);     gets(str2);     int l1 = strlen(str1), l2 = strlen(str2);     for (int i = 0; i < l1; ++i) {       unsigned int one = 1;       for (int j = 0; j < 16 && i + j < l1; ++j) {         if (str1[i + j] ==  1 ) aw[i] |= one;         one <<= 1;       }     }     for (int i = 0; i < l2; ++i) {       unsigned int one = 1;       for (int j = 0; j < 16 && i + j < l2; ++j) {         if (str2[i + j] ==  1 ) bw[i] |= one;         one <<= 1;       }     }     bit[0] = 0;     for (int i = 1; i < (1 << 16); ++i) {       bit[i] = (i & 1) + bit[i >> 1];     }     int IT = K >> 4;     for (int i = 0; i + K <= l1; i += K) {       int ind = i / K;       for (int j = 0; j + K <= l2; ++j) {         int p1 = i, p2 = j;         for (int t = 0; t < IT; ++t) {           cnt[ind][j] += bit[aw[p1] ^ bw[p2]];           p1 += 16;           p2 += 16;         }       }     }     int q, p1, p2, len;     scanf( %d , &q);     while (q--) {       scanf( %d%d%d , &p1, &p2, &len);       int ans = 0;       int pos = (p1 / K) * K, r = p1 + len - 1;       while (pos < p1) pos += K;       for (int i = p1; i < pos && i <= r; ++i) {         ans += str1[i] != str2[p2];         ++p2;       }       if (pos <= r) {         while (pos + K - 1 <= r) {           ans += cnt[pos / K][p2];           pos += K;           p2 += K;         }         for (int i = pos; i <= r; ++i) {           ans += str1[i] != str2[p2];           ++p2;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10086;   struct Node {     string name;     vector<Node *> son;   };   char str[MAXN];   int ans;   void build(Node *&root, int &pos) {     if (str[pos] == 0) {       root = NULL;       return;     }     string name =   ;     for (; str[pos] !=  .  && str[pos] !=  : ;) {       name += str[pos++];     }     root = new Node();     root->name = name;     if (str[pos] ==  : ) {       do {         pos++;         Node *son;         build(son, pos);         if (son != NULL) root->son.push_back(son);       } while (str[pos] !=  . );     }     pos++;   }   void dfs(Node *root, map<string, int> &mp) {     if (root == NULL) return;     mp[root->name]++;     for (vector<Node *>::iterator it = root->son.begin(); it != root->son.end();          it++) {       map<string, int> _mp;       dfs(*it, _mp);       ans += _mp[root->name];       for (map<string, int>::iterator mit = _mp.begin(); mit != _mp.end(); mit++)         mp[mit->first] += mit->second;     }   }   int main() {     while (~scanf( %s , str)) {       Node *root;       int pos = 0;       build(root, pos);       ans = 0;       map<string, int> mp;       dfs(root, mp);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100008;   int n, a[N];   vector<pair<int, int> > ans;   int main(void) {     int i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , a + i);     for (i = 1; i + 2 <= n; i++)       if (a[i]) {         k = 1;         for (j = 2; i + j <= n; j++)           if (a[i + j]) {             if (i + j + j <= n)               k = j;             else               k = 1;             break;           }         a[i] ^= 1;         a[i + k] ^= 1;         a[i + k + k] ^= 1;         ans.push_back(make_pair(i, k));       }     if (a[n - 1] == 0 && a[n] == 0)       ;     else if (a[n - 1] == 1 && a[n] == 0) {       if (n >= 8) {         ans.push_back(make_pair(n - 7, 1));         ans.push_back(make_pair(n - 7, 3));         ans.push_back(make_pair(n - 6, 1));       } else {         printf( NO );         return 0;       }     } else if (a[n - 1] == 0 && a[n] == 1) {       if (n >= 7) {         ans.push_back(make_pair(n - 6, 1));         ans.push_back(make_pair(n - 6, 3));         ans.push_back(make_pair(n - 5, 1));       } else {         printf( NO );         return 0;       }     } else {       if (n >= 8) {         ans.push_back(make_pair(n - 7, 1));         ans.push_back(make_pair(n - 7, 3));         ans.push_back(make_pair(n - 6, 1));         ans.push_back(make_pair(n - 6, 1));         ans.push_back(make_pair(n - 6, 3));         ans.push_back(make_pair(n - 5, 1));       } else {         printf( NO );         return 0;       }     }     printf( YES n%d n , (int)ans.size());     for (auto p : ans)       printf( %d %d %d n , p.first, p.first + p.second,              p.first + p.second + p.second);     return 0;   }


#include<bits/stdc++.h>   typedef long long ll;   using namespace std;   const int MAXN = 5005;   int tag[MAXN],s[MAXN];   ll dp[MAXN];   int main(){       ios::sync_with_stdio(false);       int t;cin>>t;       while(t--){           int n;cin>>n;           for(int i=1;i<=n;i++){               cin>>tag[i];           }           for(int i=1;i<=n;i++){               cin>>s[i];               dp[i]=0;           }           for(int i=2;i<=n;i++){               for(int j=i-1;j>=1;j--){                   if(tag[i]==tag[j]) continue;                   ll di=dp[i],dj=dp[j],add=abs(s[i]-s[j]);                   dp[i]=max(dp[i],dj+add);                   dp[j]=max(dp[j],di+add);               }           }           ll ans=0;           for(int i=1;i<=n;i++){               ans=max(ans,dp[i]);           }           cout<<ans<<  n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   template <typename T>   inline T Bigmod(T base, T power, T MOD) {     T ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int main() {     ios::sync_with_stdio(false);     int n, m;     while (cin >> n >> m) {       int a[n];       int b[m];       int max_a = 0, min_a = 110, min_b = 110;       for (int i = 0; i < n; i++) {         cin >> a[i];         max_a = max(max_a, a[i]);         min_a = min(min_a, a[i]);       }       for (int i = 0; i < m; i++) {         cin >> b[i];         min_b = min(min_b, b[i]);       }       if (max(2 * min_a, max_a) < min_b)         cout << max(2 * min_a, max_a) << endl;       else         cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const long long int P = 1000000007;   const double eps = 1e-6;   int val[N];   int deg[N];   vector<int> gr[N];   vector<long long int> mx(N);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     long long int ans = 0;     for (int i = 0; i < n; i++) {       cin >> val[i];       ans += val[i];     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       gr[u].push_back(v);       gr[v].push_back(u);       deg[u]++, deg[v]++;     }     int start;     cin >> start;     start--;     stack<int> st;     for (int i = 0; i < n; i++)       if (deg[i] == 1 && i != start) st.push(i);     long long int maxall = 0;     while (!st.empty()) {       int now = st.top();       st.pop();       deg[now]--;       ans -= val[now];       for (auto i : gr[now]) {         if (deg[i]) {           deg[i]--;           if (deg[i] == 1 && i != start) st.push(i);           mx[i] = max((long long int)mx[i],                       (long long int)mx[now] + (long long int)val[now]);           maxall = max(maxall, mx[i]);         }       }     }     cout << ans + maxall;     cerr <<   nTime elapsed :   << 1000 * clock() / CLOCKS_PER_SEC <<   ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000005;   struct node {     int l, r, sum, id;   } tr[200010 * 4];   void build(int l, int r, int x) {     tr[x].l = l, tr[x].r = r;     if (l == r) {       tr[x].sum = 0;       tr[x].id = l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, x << 1);     build(mid + 1, r, x << 1 | 1);     if (tr[x << 1].sum > tr[x << 1 | 1].sum)       tr[x].sum = tr[x << 1].sum, tr[x].id = tr[x << 1].id;     else       tr[x].sum = tr[x << 1 | 1].sum, tr[x].id = tr[x << 1 | 1].id;   }   pair<int, int> query(int L, int R, int x) {     int l = tr[x].l, r = tr[x].r;     if (L == tr[x].l && R == tr[x].r) {       return make_pair(tr[x].sum, tr[x].id);     }     int mid = (l + r) >> 1;     if (R <= mid)       return query(L, R, x << 1);     else if (L > mid)       return query(L, R, x << 1 | 1);     else {       pair<int, int> p = query(L, mid, x << 1), q = query(mid + 1, R, x << 1 | 1);       if (p.first > q.first)         return p;       else         return q;     }   }   void upd(int L, int R, int x, int val) {     int l = tr[x].l, r = tr[x].r;     if (L == l && R == r) {       tr[x].sum = val;       tr[x].id = l;       return;     }     int mid = (l + r) >> 1;     if (R <= mid)       upd(L, R, x << 1, val);     else       upd(L, R, x << 1 | 1, val);     if (tr[x << 1].sum > tr[x << 1 | 1].sum)       tr[x].sum = tr[x << 1].sum, tr[x].id = tr[x << 1].id;     else       tr[x].sum = tr[x << 1 | 1].sum, tr[x].id = tr[x << 1 | 1].id;   }   struct EDGE {     int v, next, val;   } edges[200010 * 2];   int head[200010], cnt;   void addedge(int u, int v, int val) {     edges[cnt].v = v;     edges[cnt].next = head[u];     edges[cnt].val = val;     head[u] = cnt++;     edges[cnt].v = u;     edges[cnt].next = head[v];     edges[cnt].val = val;     head[v] = cnt++;   }   int n, m;   int size[200010], fa[200010], dep[200010], son[200010];   void dfs1(int u, int pre, int depth) {     size[u] = 1;     son[u] = -1;     fa[u] = pre;     dep[u] = depth;     for (int i = head[u]; i != -1; i = edges[i].next) {       int x = edges[i].v;       if (x == pre) continue;       dfs1(x, u, depth + 1);       if (son[u] == -1 || size[son[u]] < size[x]) {         son[u] = x;       }       size[u] += size[x];     }   }   int top[200010], pos[200010], no = 1, re[200010];   void dfs2(int u, int tops) {     top[u] = tops;     pos[u] = no++;     if (son[u] == -1) {       return;     }     dfs2(son[u], tops);     for (int i = head[u]; i != -1; i = edges[i].next) {       int x = edges[i].v;       if (x == fa[u] || x == son[u]) continue;       dfs2(x, x);     }   }   void dfs3(int u, int fa) {     for (int i = head[u]; i != -1; i = edges[i].next) {       int x = edges[i].v;       if (x == fa) continue;       upd(pos[x], pos[x], 1, edges[i].val);       dfs3(x, u);     }   }   int sum[200010];   pair<int, int> qry(int x, int y) {     int f1 = top[x], f2 = top[y];     pair<int, int> res(0, -1), tmp;     while (f1 != f2) {       if (dep[f1] < dep[f2]) {         swap(f1, f2);         swap(x, y);       }       tmp = query(pos[f1], pos[x], 1);       if (tmp.first > res.first) res = tmp;       x = fa[f1];       f1 = top[x];     }     if (x == y) return res;     if (dep[x] < dep[y]) swap(x, y);     tmp = query(pos[son[y]], pos[x], 1);     if (tmp.first > res.first) res = tmp;     return res;   }   struct bian {     pair<int, int> z;     long long w, c;     int id;   } ed[200010];   bool cmp(bian a, bian b) {     if (a.w == b.w)       return a.c < b.c;     else       return a.w < b.w;   }   int pa[200010];   bool vis[200010];   int root(int x) {     if (pa[x] == -1)       return x;     else {       pa[x] = root(pa[x]);       return pa[x];     }   }   int main() {     int n, m, i, j;     long long s;     memset(head, -1, sizeof(head));     memset(pa, -1, sizeof(pa));     memset(vis, 0, sizeof(vis));     cnt = 0;     scanf( %d %d , &n, &m);     for (i = 1; i <= m; i++) scanf( %I64d , &ed[i].w), ed[i].id = i;     for (i = 1; i <= m; i++) scanf( %I64d , &ed[i].c);     for (i = 1; i <= m; i++) scanf( %d %d , &ed[i].z.first, &ed[i].z.second);     scanf( %I64d , &s);     sort(ed + 1, ed + m + 1, cmp);     int mn = INF, mnid = -1;     long long ans = 0, sm = 0;     for (i = 1; i <= m; i++) {       int u = ed[i].z.first, v = ed[i].z.second;       if (root(u) != root(v)) {         pa[root(u)] = root(v);         vis[i] = 1;         addedge(u, v, ed[i].w);         if (ed[i].c < mn) mn = ed[i].c, mnid = i;         ans += ed[i].w;       }     }     build(1, n, 1);     dfs1(1, 0, 1);     dfs2(1, 1);     dfs3(1, 0);     for (i = 1; i <= n; i++) re[pos[i]] = i;     int nw = -1, nwf = -1;     ans -= s / mn;     sm = ans + s / mn;     for (i = 1; i <= m; i++) {       if (vis[i]) continue;       pair<int, int> mx = qry(ed[i].z.first, ed[i].z.second);       if (sm - (long long)mx.first + ed[i].w - s / ed[i].c < ans) {         ans = sm - (long long)mx.first + ed[i].w - s / ed[i].c;         nw = i;         nwf = mx.second;       }     }     printf( %I64d n , ans);     if (nw == -1) {       for (i = 1; i <= m; i++) {         if (vis[i] && i != mnid) {           printf( %d %I64d n , ed[i].id, ed[i].w);         } else if (mnid == i && vis[i]) {           printf( %d %I64d n , ed[i].id, ed[i].w - s / ed[i].c);         }       }     } else {       for (i = 1; i <= m; i++) {         if (i == nw) {           printf( %d %I64d n , ed[i].id, ed[i].w - s / ed[i].c);         } else if (vis[i]) {           if (ed[i].z.first == re[nwf] && ed[i].z.second == fa[re[nwf]] ||               ed[i].z.second == re[nwf] && ed[i].z.first == fa[re[nwf]])             continue;           printf( %d %I64d n , ed[i].id, ed[i].w);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k;     long long int n, m, t;     long long int a, b;     scanf( %I64d%I64d%I64d , &n, &a, &b);     t = n / a + 1;     for (i = 0; i <= t; i++) {       m = i * a;       if ((n - m) % b == 0 && n - m >= 0) {         printf( YES n%I64d %I64d , i, (n - m) / b);         return 0;       }     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 9;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n, m;     cin >> n >> m;     vector<vector<long long>> v(n);     vector<vector<long long>> vr(n);     long long a, b;     for (int i = 0; i < m; ++i) {       cin >> a >> b;       a--;       b--;       v[a].push_back(b);       vr[b].push_back(a);     }     vector<long long> mr(n, 0);     long long ps;     cin >> ps;     vector<long long> p(ps);     for (int i = 0; i < ps; ++i) {       cin >> p[i];       p[i]--;     }     mr[p[ps - 1]] = 0;     queue<int> q;     q.push(p[ps - 1]);     vector<bool> used(n);     used[p[ps - 1]] = true;     while (!q.empty()) {       long long cur = q.front();       q.pop();       for (auto i : vr[cur]) {         if (!used[i]) {           used[i] = true;           mr[i] = mr[cur] + 1;           q.push(i);         }       }     }     long long mn = 0, mx = 0;     for (int i = 0; i < ps - 1; ++i) {       long long lg = 1000000000000;       set<long long> s;       for (auto j : v[p[i]]) {         if (mr[j] < lg) {           s.clear();           s.insert(j);           lg = mr[j];         } else if (mr[j] == lg) {           s.insert(j);         }       }       if (s.find(p[i + 1]) == s.end()) {         mn++;         mx++;       } else {         if (s.size() > 1) {           mx++;         }       }     }     cout << mn <<     << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 2e5 + 4;   int main() {     int n;     scanf( %d , &n);     long long b[n], c[n], sum = 0;     for (int i = 0; i < n; i++) scanf( %lld , &b[i]), sum += b[i];     for (int i = 0; i < n; i++) scanf( %lld , &c[i]), sum += c[i];     if (sum % 2 * n != 0) {       printf( %d , -1);       return 0;     }     sum /= 2 * n;     long long a[n];     for (int i = 0; i < n; i++) {       long long here = b[i] + c[i] - sum;       if (here >= 0 and here % n != 0) {         printf( %d , -1);         return 0;       }       a[i] = here / n;     }     vector<int> fa(31, 0);     for (int bit = 0; bit < 31; bit++) {       for (int i = 0; i < n; i++)         if (a[i] & (1LL << bit)) fa[bit]++;     }     for (int i = 0; i < n; i++) {       for (int bit = 0; bit < 31; bit++)         if (a[i] & (1LL << bit)) b[i] -= (1LL << bit) * fa[bit];       if (b[i] != 0) {         printf( %d , -1);         return 0;       }     }     for (int i = 0; i < n; i++) printf( %lld  , a[i]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(         Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations )   #pragma GCC target( avx )   inline int read_char() {     static char buf[1 << 16], *ptr = buf, *end_ptr = buf;     if (ptr == end_ptr) {       int len = fread(buf, 1, sizeof(buf), stdin);       if (len <= 0) return EOF;       ptr = buf;       end_ptr = buf + len;     }     return *ptr++;   }   inline int read_int() {     int ch;     bool sg = 0;     do {       ch = read_char();       if (ch ==  - ) sg = 1;     } while (ch <  0  || ch >  9 );     int x = ch -  0 ;     while (true) {       ch = read_char();       if (ch <  0  || ch >  9 ) break;       x = x * 10 + ch -  0 ;     }     return (sg ? -x : x);   }   float __attribute__((aligned(64))) a[100005];   int n, m, ans, t, l, r;   float x;   int main() {     n = read_int();     m = read_int();     for (int i = 1; i <= n; i++) a[i] = read_int();     for (int i = 1; i <= m; i++) {       t = read_int();       l = read_int();       r = read_int();       x = read_int();       if (t == 1) {         for (int j = l; j <= r; j++)           if (a[j] > x) a[j] -= x;       } else {         ans = 0;         for (int j = l; j <= r; j++) ans += (a[j] == x);         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   unsigned long long x[N], y[N], f[N];   int a[N], cnt[N];   queue<int> g[N];   mt19937_64 rng(time(0));   char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;   inline int rd() {     int x = 0, f = 1;     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (isdigit(ch))       x = x * 10 + (ch ^ 48),       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     return x * f;   }   namespace Hash {   const int hashmod = 999983;   int v[hashmod];   bool vis[hashmod];   unsigned long long h[hashmod];   int &get(unsigned long long S) {     int i = S % hashmod;     for (; vis[i] && h[i] != S; i = (i + 1) % hashmod)       ;     if (!vis[i]) vis[i] = 1, h[i] = S;     return v[i];   }   }  // namespace Hash   int main() {     int n = rd();     for (int i = 1; i <= n; ++i) {       a[i] = rd();       x[i] = rng();       y[i] = rng();     }     unsigned long long now = 0, ans = 0;     ++Hash::get(now);     int p = 0;     for (int i = 1; i <= n; ++i) {       if (g[a[i]].size() == 3) {         int t = g[a[i]].front();         g[a[i]].pop();         while (p < t) --Hash::get(f[p++]);       }       g[a[i]].push(i);       switch (++cnt[a[i]] % 3) {         case 1:           f[i] = now ^= x[a[i]];           break;         case 2:           f[i] = now ^= y[a[i]];           break;         case 0:           f[i] = now ^= x[a[i]] ^ y[a[i]];           break;       }       ans += Hash::get(now)++;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   void bubbleSort(long long int arr[], int n) {     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < n - i - 1; j++) {         if (arr[j] > arr[j + 1]) {           int swap = arr[j];           arr[j] = arr[j + 1];           arr[j + 1] = swap;         }       }     }   }   int main() {     int n, k, ans;     scanf( %d %d , &n, &k);     long long int arr[n];     for (int i = 0; i < n; i++) {       scanf( %lld , &arr[i]);       bubbleSort(arr, i + 1);       int j = i;       long long int sum = 0;       while (j > -1) {         sum += arr[j];         j -= 2;       }       if (sum <= k) {         ans = i + 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000;   const int mod = 1000 * 1000 + 3;   string com =  ><+-.,[] ;   int main() {     string s;     cin >> s;     int res = 0;     for (int i = 0; i < s.size(); i++)       res = (res << 4) % mod, res = (res + 8 + com.find(s[i])) % mod;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const signed long long INF = 1000000100;   const long double EPS = 1e-9;   const long double Pi = 2 * atanl(1.0);   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &V) {     os <<  [ ;     for (int(i) = (0); (i) < (int(V.size())); (i)++)       os << V[i] << ((i == int(V.size()) - 1) ?    :  , );     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &S) {     os <<  ( ;     for (T i : S) os << i << (i == *S.rbegin() ?    :  , );     return os <<  ) ;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const map<T, U> &M) {     os <<  { ;     for (pair<T, U> i : M) os << i << (i.X == M.rbegin()->X ?    :  , );     return os <<  } ;   }   inline bool is_zero(const long double &first) {     return first >= -EPS and first <= EPS;   }   inline int sign(const long double &first) {     if (first < -EPS)       return -1;     else if (first > EPS)       return 1;     else       return 0;   }   inline pair<long double, long double> operator+(       const pair<long double, long double> &a,       const pair<long double, long double> &b) {     return pair<long double, long double>(a.first + b.first, a.second + b.second);   }   inline pair<long double, long double> operator-(       const pair<long double, long double> &a,       const pair<long double, long double> &b) {     return pair<long double, long double>(a.first - b.first, a.second - b.second);   }   inline pair<long double, long double> operator*(       const pair<long double, long double> &a, long double t) {     return pair<long double, long double>(a.first * t, a.second * t);   }   inline pair<long double, long double> operator/(       const pair<long double, long double> &a, long double t) {     return pair<long double, long double>(a.first / t, a.second / t);   }   inline bool operator==(const pair<long double, long double> &a,                          const pair<long double, long double> &b) {     return is_zero(a.first - b.first) and is_zero(a.second - b.second);   }   inline bool operator!=(const pair<long double, long double> &a,                          const pair<long double, long double> &b) {     return !is_zero(a.first - b.first) or !is_zero(a.second - b.second);   }   pair<long double, long double> FAIL = make_pair(1e30, 1e30);   inline long double cp(const pair<long double, long double> &a,                         const pair<long double, long double> &b) {     return a.first * b.second - a.second * b.first;   }   inline long double dp(const pair<long double, long double> &a,                         const pair<long double, long double> &b) {     return a.first * b.first + a.second * b.second;   }   inline long double pieprzu(const pair<long double, long double> &a,                              const pair<long double, long double> &b) {     return sqrtl((b.first - a.first) * (b.first - a.first) +                  (b.second - a.second) * (b.second - a.second));   }   inline long double distance_point_line(       const pair<long double, long double> &p,       const pair<pair<long double, long double>, pair<long double, long double> >           &u) {     return cp(p - u.first, p - u.second) / pieprzu(u.first, u.second);   }   inline bool on_right(const pair<long double, long double> &a,                        const pair<long double, long double> &b,                        const pair<long double, long double> &c) {     return sign(cp(c - a, b - a)) == 1;   }   inline bool on_left(const pair<long double, long double> &a,                       const pair<long double, long double> &b,                       const pair<long double, long double> &c) {     return sign(cp(c - a, b - a)) == -1;   }   inline double polygon_area(const vector<pair<long double, long double> > &A) {     long double result = 0.0;     if (int(A.size()) <= 2) return 0;     for (int(i) = (2); (i) < (int(A.size())); (i)++)       result += cp(A[i] - A[0], A[i - 1] - A[0]);     return abs(result / 2);   }   inline pair<long double, long double> projection(       const pair<long double, long double> &p,       const pair<pair<long double, long double>, pair<long double, long double> >           &u) {     return u.first +            ((u.second - u.first) * (dp(p - u.first, u.second - u.first) /                                     dp(u.second - u.first, u.second - u.first)));   }   inline bool between(const pair<long double, long double> &a,                       const pair<long double, long double> &b,                       const pair<long double, long double> &c) {     return sign(min(b.first, c.first) - a.first) <= 0 and            sign(a.first - max(b.first, c.first)) <= 0 and            sign(min(b.second, c.second) - a.second) <= 0 and            sign(a.second - max(b.second, c.second)) <= 0;   }   inline bool on_segment(const pair<long double, long double> &p,                          const pair<pair<long double, long double>,                                     pair<long double, long double> > &u) {     return between(p, u.first, u.second) and pieprzu(p, projection(p, u)) < EPS;   }   inline long double distance_segment_point(       const pair<pair<long double, long double>, pair<long double, long double> >           &u,       const pair<long double, long double> &p) {     if (on_segment(projection(p, u), u))       return fabs(distance_point_line(p, u));     else       return min(pieprzu(u.first, p), pieprzu(u.second, p));   }   inline long double angle(const pair<long double, long double> &a,                            const pair<long double, long double> &o,                            const pair<long double, long double> &b) {     long double result = atan2l(a.first - o.first, a.second - o.second) -                          atan2l(b.first - o.first, b.second - o.second);     if (sign(result) == -1) result += 2 * Pi;     return result;   }   inline pair<long double, long double> point_reflection(       const pair<long double, long double> &s,       const pair<long double, long double> &p) {     return p + (s - p) * 2;   }   inline pair<long double, long double> axial_reflection(       const pair<long double, long double> &p,       const pair<pair<long double, long double>, pair<long double, long double> >           &u) {     return point_reflection(p, projection(p, u));   }   inline int triangle_inequality(long double &p, long double q, long double r) {     int a = sign(p + q - r);     int b = sign(p + r - q);     int c = sign(q + r - p);     if (a == -1 or b == -1 or c == -1) return -1;     if (a == 0 or b == 0 or c == 0) return 0;     return 1;   }   vector<pair<long double, long double> > convex_hull(       vector<pair<long double, long double> > A) {     if (int(A.size()) <= 1) return A;     sort(A.begin(), A.end());     vector<pair<long double, long double> > R{A[0], A[1]};     for (int(i) = (2); (i) < (int(A.size())); (i)++) {       while (int(R.size()) >= 2 and              !on_right(R[R.size() - 2], R[R.size() - 1], A[i]))         R.pop_back();       R.push_back(A[i]);     }     int u = int(A.size());     for (int(i) = (int(A.size()) - 2); (i) >= (0); (i)--) {       while (int(R.size()) > u and              !on_right(R[R.size() - 2], R[R.size() - 1], A[i]))         R.pop_back();       R.push_back(A[i]);     }     R.pop_back();     return move(R);   }   inline pair<long double, long double> rotate90_origin(       const pair<long double, long double> &p) {     return pair<long double, long double>(p.second, -p.first);   }   inline pair<long double, long double> rotate90(       const pair<long double, long double> &p,       const pair<long double, long double> &o) {     return o + rotate90_origin(p - o);   }   inline pair<long double, long double> rotate_origin(       const pair<long double, long double> &p, long double theta) {     theta = -theta;     long double s = sinl(theta);     long double c = cosl(theta);     return pair<long double, long double>(p.first * c - p.second * s,                                           p.first * s + p.second * c);   }   inline pair<long double, long double> rotate(       const pair<long double, long double> &p,       const pair<long double, long double> &o, long double theta) {     return o + rotate_origin(p - o, theta);   }   inline bool parallel(const pair<pair<long double, long double>,                                   pair<long double, long double> > &u,                        const pair<pair<long double, long double>,                                   pair<long double, long double> > &v) {     return is_zero(cp(u.second - u.first, v.second - v.first));   }   bool perpendicular(const pair<pair<long double, long double>,                                 pair<long double, long double> > &u,                      const pair<pair<long double, long double>,                                 pair<long double, long double> > &v) {     return is_zero(dp(u.second - u.first, v.second - v.first));   }   inline pair<pair<long double, long double>, pair<long double, long double> >   segment_bisector(const pair<pair<long double, long double>,                               pair<long double, long double> > &u) {     pair<long double, long double> p = (u.first + u.second) / 2;     return pair<pair<long double, long double>, pair<long double, long double> >(         p, rotate90(u.second, p));   }   inline pair<pair<long double, long double>, pair<long double, long double> >   angle_bisector(const pair<long double, long double> &a,                  const pair<long double, long double> &o,                  const pair<long double, long double> &b) {     return pair<pair<long double, long double>, pair<long double, long double> >(         o, rotate(b, o, angle(a, o, b) / 2));   }   inline pair<long double, long double> intersection_line_line(       const pair<pair<long double, long double>, pair<long double, long double> >           &u,       const pair<pair<long double, long double>, pair<long double, long double> >           &v) {     long double p = cp(u.second - v.first, u.second - u.first);     long double q = cp(v.second - v.first, u.second - u.first);     if (is_zero(q)) return FAIL;     return v.first + (v.second - v.first) * (p / q);   }   const pair<pair<long double, long double>, long double> CFAIL =       pair<pair<long double, long double>, long double>(FAIL, 0);   pair<pair<long double, long double>, long double> incircle(       const pair<long double, long double> &a,       const pair<long double, long double> &b,       const pair<long double, long double> &c) {     if (is_zero(cp(b - a, c - a))) return CFAIL;     pair<pair<long double, long double>, pair<long double, long double> > p =         segment_bisector(             pair<pair<long double, long double>, pair<long double, long double> >(                 a, b));     pair<pair<long double, long double>, pair<long double, long double> > q =         segment_bisector(             pair<pair<long double, long double>, pair<long double, long double> >(                 a, c));     pair<long double, long double> t = intersection_line_line(p, q);     return pair<pair<long double, long double>, long double>(t, pieprzu(t, a));   }   pair<long double, long double> intersection_segment_segment(       const pair<pair<long double, long double>, pair<long double, long double> >           &u,       const pair<pair<long double, long double>, pair<long double, long double> >           &v) {     pair<long double, long double> r = intersection_line_line(u, v);     if (on_segment(r, u) and on_segment(r, v))       return r;     else       return FAIL;   }   int main() {     int N, X, Y;     scanf( %d %d %d , &N, &X, &Y);     vector<pair<long double, long double> > P;     int max_a = 0;     int max_b = 0;     for (int(i) = (1); (i) <= (N); (i)++) {       int a, b;       scanf( %d %d , &a, &b);       max_a = max(max_a, a);       max_b = max(max_b, b);       P.emplace_back(a, b);     }     P.emplace_back(max_a, 0);     P.emplace_back(0, max_b);     P = convex_hull(P);     pair<long double, long double> n(X, Y);     pair<long double, long double> z;     for (int(i) = (1); (i) <= (1500000); (i)++) {       if (X * i > 1490490 or Y * i > 1490010) {         z = pair<long double, long double>(X * i, Y * i);         break;       }     }     pair<pair<long double, long double>, pair<long double, long double> > s(         pair<long double, long double>(0, 0), z);     long double result = INF;     for (int(i) = (0); (i) < (int(P.size())); (i)++) {       pair<long double, long double> a = P[i];       pair<long double, long double> b = P[(i + 1) % int(P.size())];       pair<pair<long double, long double>, pair<long double, long double> > t(a,                                                                               b);       pair<long double, long double> d = intersection_segment_segment(s, t);       if (d == FAIL) continue;       result = min(result, pieprzu(pair<long double, long double>(X, Y),                                    pair<long double, long double>(0, 0)) /                                pieprzu(d, pair<long double, long double>(0, 0)));     }     cout << fixed << result << endl;     return 0;   }


#include <bits/stdc++.h>   inline int Get() {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     int Num = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 )       Num = (Num << 3) + (Num << 1) + ch -  0 ;     return Num;   }   const int M = 3e3 + 5;   const int m = 3000;   int n, a[M][M], s[M][M], r[M][M], d[M][M];   int main() {     n = Get();     for (int i = 1; i <= n; ++i) {       int x0 = Get(), y0 = Get(), x1 = Get(), y1 = Get();       for (int x = x0 + 1; x <= x1; ++x)         for (int y = y0 + 1; y <= y1; ++y) a[x][y] = i;     }     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= m; ++j)         s[i][j] = (!a[i][j]) + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];     for (int i = m; ~i; --i)       for (int j = m; ~j; --j) {         r[i][j] = a[i][j + 1] == a[i + 1][j + 1] ? 0 : r[i][j + 1] + 1;         d[i][j] = a[i + 1][j] == a[i + 1][j + 1] ? 0 : d[i + 1][j] + 1;       }     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j)         for (int k = 1; k <= r[i][j] && k <= d[i][j] &&                         !(s[i + k][j + k] - s[i][j + k] - s[i + k][j] + s[i][j]);              ++k)           if (k <= r[i + k][j] && k <= d[i][j + k]) {             std ::vector<int> ans;             for (int x = i + 1; x <= i + k; ++x)               for (int y = j + 1; y <= j + k; ++y) ans.push_back(a[x][y]);             std ::sort(ans.begin(), ans.end()),                 ans.erase(std ::unique(ans.begin(), ans.end()), ans.end());             printf( YES %d n , ans.size());             for (int k = 0, sze = ans.size(); k < sze; ++k) printf( %d  , ans[k]);             putchar(  n );             return 0;           }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   int t1, t2, x1, x2, t0;   int main() {     scanf( %d %d %d %d %d , &t1, &t2, &x1, &x2, &t0);     long long k1 = t0 - t1, k2 = t2 - t0;     if (k1 == 0) {       printf( %d %d n , x1, t1 == t2 ? x2 : 0);     } else if (k2 == 0) {       printf( %d %d n , t1 == t2 ? x1 : 0, x2);     } else {       int y1 = 0, y2 = 0;       long long t;       double tt = 1e100;       for (int i = 0; i <= x1; i++) {         t = ((k1 * 1.0 / k2) * i);         if ((k1 * 1.0 / k2) * i - t > EPS) t++;         if (i == 0) t = x2;         if (t > x2) continue;         double tmp =             (((long long)(t1)*i + (long long)(t2)*t) * 1.0) / (i + t + 0.0);         if (tmp - tt < 0) {           y1 = i;           y2 = t;           tt = tmp;         } else if (abs(tmp - tt) <= EPS) {           if (i + t > y1 + y2) {             y1 = i;             y2 = t;           }         }       }       printf( %d %d n , y1, y2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   long long int power(long long int x, long long int y) {     long long int res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   void solve() {     long long int n;     cin >> n;     vector<string> v;     while (n--) {       string s;       cin >> s;       if (s ==  pwd ) {         cout <<  / ;         for (int i = 0; i < v.size(); i++) {           cout << v[i] <<  / ;         }         cout << endl;       } else {         string s;         cin >> s;         vector<string> temp;         string te;         if (s[0] ==  / ) v.clear();         for (int i = 0; i < s.length(); i++) {           if (s[i] !=  / )             te.push_back(s[i]);           else {             if (i != 0) {               temp.push_back(te);               te.clear();             }           }         }         temp.push_back(te);         ;         for (int i = 0; i < temp.size(); i++) {           if (temp[i] ==  .. ) {             v.pop_back();           } else             v.push_back(temp[i]);         }       }     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n1, n2, i, j, n, ma = 0, temp, c;     cin >> n1 >> n2;     if (n1 < n2) {       cout <<  2 ;     } else {       cout << n1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long int n, ans, i, j, k;     cin >> n;     if (n == 0) {       cout <<  1  << endl;       return 0;     }     ans = 2 * n * n;     ans = ans + ((n + 2) * (n + 1)) - 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200001];   int dis[200001];   int par[200001];   void addEdge(int u, int v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   void dfs(int src, int parent, int dist) {     dis[src] = dist;     par[src] = parent;     for (int child : adj[src]) {       if (child != parent) {         dfs(child, src, dist + 1);       }     }   }   int solve() {     int n;     cin >> n;     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       addEdge(u, v);     }     dfs(1, 0, 0);     set<pair<int, int> > st;     for (int i = 1; i <= n; i++) {       if (dis[i] > 2) {         st.insert({-dis[i], i});       }     }     int ans = 0;     while (!st.empty()) {       int rmv = (*st.begin()).second;       st.erase(st.begin());       rmv = par[rmv];       auto itr = st.find({-dis[rmv], rmv});       if (itr != st.end()) st.erase(itr);       for (int c : adj[rmv]) {         if (dis[c] > 2) {           itr = st.find({-dis[c], c});           if (itr != st.end()) st.erase(itr);         }       }       ans++;     }     return ans;   }   int main() { cout << solve() <<   n ; }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3 + 10;   vector<int> occ[maxn];   int dp[maxn][maxn], a[maxn];   void solve() {     int n;     cin >> n;     int ptr = 0;     for (int i = 1; i <= n; i++) {       cin >> a[++ptr];       if (ptr > 1 and a[ptr] == a[ptr - 1]) ptr--;     }     n = ptr;     for (int i = 1; i <= n; i++) occ[a[i]].push_back(i);     for (int len = 1; len <= n; len++) {       for (int l = 1; l + len - 1 <= n; l++) {         int r = l + len - 1;         if (len == 1) {           dp[l][r] = 0;           continue;         }         dp[l][r] = max(dp[l][r - 1], dp[l + 1][r]);         if (a[l] == a[r]) dp[l][r] = max(dp[l][r - 1], dp[l + 1][r]) + 1;         for (auto m : occ[a[l]])           if (l < m and m < r) dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);         for (auto m : occ[a[r]])           if (l < m and m < r) dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);       }     }     cout << n - 1 - dp[1][n] <<   n ;     for (int i = 1; i <= n; i++) occ[a[i]].clear();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dp[i][j] = 0;   }   int main() {     ios_base::sync_with_stdio(false);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int solve(int A, int B) {     int count = 0;     for (int i = 0; i < 32; i++) {       if (((A >> i) & 1) != ((B >> i) & 1)) {         count++;       }     }     return count;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     std::vector<int> arr(m + 1);     for (size_t i = 0; i < m + 1; i++) {       cin >> arr[i];     }     int count = 0;     for (size_t i = 0; i < m; i++) {       int ans;       ans = solve(arr[i], arr[m]);       if (ans <= k) {         count++;       }     }     std::cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2001];   int main() {     int n, b, s = 0, m, s1, i;     scanf( %d%d , &n, &b);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) {       if (i == n - 1)         s1 = b;       else {         m = *max_element(a + i, a + n);         s1 = (b / a[i]) * m + b % a[i];       }       if (s1 > s) s = s1;     }     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, sum, min = 1000000000;     cin >> n;     int k[n];     for (i = 0; i < n; i++) cin >> k[i];     for (i = 0; i < n; i++) {       sum = 0;       int m[k[i]];       for (j = 0; j < k[i]; j++) {         cin >> m[j];         sum = sum + 5 * m[j] + 15;       }       if (sum < min) min = sum;     }     cout << min;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void work(int n) {     map<int, int> v;     int ans = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           for (int x = 0; x <= n; x++) {             if (i + j + k + x == n) {               int tot = i + j * 5 + k * 10 + x * 50;               if (v[tot]) continue;               v[tot] = 1;               ans++;             }           }         }       }     }     cout << ans <<   n ;   }   int main() {     scanf( %d , &n);     if (n <= 20)       work(n);     else       cout << 1LL * 733 + 1LL * 49 * (n - 20);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k >= 2 * n) {       cout << 0;       return 0;     }     long long q = k / 2, z;     if (k <= n)       z = k - 1;     else       z = n;     if (k & 1) {       long long ans = min(q - 1, z - q - 1);       ans++;       cout << ans;     } else {       cout << min(q - 1, z - q);     }   }


#include <bits/stdc++.h>   using namespace std;   int u, v;   const int maxn = 5e3 + 10;   vector<long long> G[maxn];   bool visited[maxn];   long long dp[maxn];   vector<long long> vc[maxn];   bool mark[maxn];   long long n;   vector<long long> ans;   void dfs(int x) {     visited[x] = 1;     for (int i = 0; i != G[x].size(); i++) {       if (visited[G[x][i]] == 0) {         dfs(G[x][i]);         dp[x] += 1 + dp[G[x][i]];       }     }   }   void main_dfs(int x) {     visited[x] = 1;     memset(mark, 0, sizeof(mark));     for (int i = 0; i < G[x].size(); i++) {       if (visited[G[x][i]] == 0) {         int g = vc[x].size();         for (int j = 0; j < g; j++) {           if (vc[x][j] + dp[G[x][i]] + 1 != n - 1 &&               mark[vc[x][j] + dp[G[x][i]] + 1] == 0) {             vc[x].push_back(vc[x][j] + dp[G[x][i]] + 1);             mark[vc[x][j] + dp[G[x][i]] + 1] = 1;           }         }         if (dp[G[x][i]] + 1 != n - 1 && mark[dp[G[x][i]] + 1] == 0) {           vc[x].push_back(dp[G[x][i]] + 1);           mark[dp[G[x][i]] + 1] = 1;         }       } else {         int g = vc[x].size();         for (int j = 0; j < g; j++) {           if (mark[vc[x][j] + n - 1 - dp[x]] == 0)             if (vc[x][j] + n - 1 - dp[x] != 0 &&                 vc[x][j] + n - 1 - dp[x] != n - 1) {               vc[x].push_back(vc[x][j] + n - dp[x] - 1);               mark[vc[x][j] + n - dp[x] - 1] = 1;             }         }         if (mark[n - dp[x] - 1] == 0)           if (n - dp[x] - 1 != 0 && n - dp[x] - 1 != n - 1) {             vc[x].push_back(n - dp[x] - 1);             mark[n - dp[x] - 1] = 1;           }       }     }     for (int i = 0; i != G[x].size(); i++) {       if (visited[G[x][i]] == 0) main_dfs(G[x][i]);     }   }   bool mk[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i != n - 1; i++) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1);     fill(visited, visited + maxn, 0);     main_dfs(1);     for (int i = 1; i != n + 1; i++) {       for (int j = 0; j != vc[i].size(); j++) {         if (find(ans.begin(), ans.end(), vc[i][j]) == ans.end()) {           ans.push_back(vc[i][j]);           if (n - 1 - vc[i][j] != vc[i][j]) ans.push_back(n - 1 - vc[i][j]);         }       }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i != ans.size(); i++) {       cout << ans[i] <<     << n - 1 - ans[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, m, x, y, cost, i, j;     string s;     cin >> t;     while (t--) {       cost = 0;       cin >> n >> m >> x >> y;       y = min(y, 2 * x);       for (i = 0; i < n; i++) {         cin >> s;         for (j = 0; j < m; j++) {           if (s[j] ==  . ) {             if (j + 1 < m && s[j + 1] ==  . )               cost += y, j++;             else               cost += x;           }         }       }       cout << cost << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long test;     cin >> test;     while (test--) {       long long b, p, f, h, c;       cin >> b >> p >> f >> h >> c;       long long profit = 0;       if (h > c) {         if (b - 2 * p >= 0) {           profit += p * h;           b = b - 2 * p;           if (b - 2 * f >= 0) {             profit += f * c;           } else {             profit += c * (b / 2);           }         } else {           profit += h * (b / 2);         }       } else {         if (b - 2 * f >= 0) {           profit += f * c;           b = b - 2 * f;           if (b - 2 * p >= 0) {             profit += p * h;           } else {             profit += h * (b / 2);           }         } else {           profit += c * (b / 2);         }       }       cout << profit <<   n ;     }   }


#include <bits/stdc++.h>   int n, m;   long long k;   long long pow(int n) {     if (n == 0) return 1;     long long tmp = pow(n >> 1);     tmp = tmp * tmp % 1000000009ll;     if (n & 1) tmp = tmp * 2ll % 1000000009ll;     return tmp;   }   int main() {     scanf( %d%d%I64d , &n, &m, &k);     int t = n - m;     long long ans = 0;     if (m == 0) {       puts( 0 );       return 0;     }     if (n - t * k < k) {       ans = m;     } else {       int num = (n - t * k) / k;       ans = (pow(num + 1) - 2 + 1000000009ll) * k % 1000000009ll;       ans = (ans + (n - t * k) % k) % 1000000009ll;       ans = (ans + t * (k - 1)) % 1000000009ll;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > AdjList;   priority_queue<pair<int, pair<int, int> > > Edgelist;   int n, j, k, m, l, t, i;   string s, ss;   int a[1050][1050];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         scanf( %d , &a[i][j]);       }     }     for (i = 0; i < n; i++) {       t += a[i][i] * a[i][i];     }     scanf( %d , &k);     while (k--) {       scanf( %d , &n);       if (n == 3) {         printf( %d , t % 2);       } else {         scanf( %d , &m);         t++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000 + 5], nxt[100000 + 5], lst[100000 + 5], fi[100000 + 5];   int cnt, root[100000 + 5];   struct node {     int sum, ls, rs;   } t[100000 * 43 + 5];   int build(int l, int r) {     int id = ++cnt;     if (l == r) {       t[id].sum = fi[l];       return id;     }     int mid = (l + r) >> 1;     t[id].ls = build(l, mid);     t[id].rs = build(mid + 1, r);     t[id].sum = t[t[id].ls].sum + t[t[id].rs].sum;     return id;   }   void upd(int l, int r, int &x, int y, int p, int v) {     t[x = ++cnt] = t[y];     if (l == r) {       t[x].sum = v;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       upd(l, mid, t[x].ls, t[y].ls, p, v);     else       upd(mid + 1, r, t[x].rs, t[y].rs, p, v);     t[x].sum = t[t[x].ls].sum + t[t[x].rs].sum;   }   int bs(int l, int r, int x, int v) {     if (v >= t[x].sum) return r + 1;     if (l == r) return l;     int mid = (l + r) >> 1;     if (t[t[x].ls].sum <= v)       return bs(mid + 1, r, t[x].rs, v - t[t[x].ls].sum);     else       return bs(l, mid, t[x].ls, v);   }   int ans[100000 + 5];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) fi[i] = 1;     for (int i = n; i >= 1; i--)       nxt[i] = lst[a[i]], lst[a[i]] = i, fi[nxt[i]] = 0;     root[1] = build(1, n);     for (int i = 1; i <= n - 1; i++) {       int tmp = 0;       upd(1, n, tmp, root[i], i, 0);       if (nxt[i])         upd(1, n, root[i + 1], tmp, nxt[i], 1);       else         root[i + 1] = tmp;     }     for (int k = 1; k <= n; k++) {       int now = 1;       while (now <= n) {         ans[k]++;         now = bs(1, n, root[now], k);       }     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i],    n [i == n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   struct kuhn {     int n, m;     vector<vector<int>> g;     vector<int> vis, ma, mb;     kuhn(int n_, int m_) : n(n_), m(m_), g(n), vis(n + m), ma(n, -1), mb(m, -1) {}     void add(int a, int b) { g[a].push_back(b); }     bool dfs(int i) {       vis[i] = 1;       for (int j : g[i])         if (!vis[n + j]) {           vis[n + j] = 1;           if (mb[j] == -1 or dfs(mb[j])) {             ma[i] = j, mb[j] = i;             return true;           }         }       return false;     }     int matching() {       int ret = 0, aum = 1;       for (auto& i : g) shuffle(i.begin(), i.end(), rng);       while (aum) {         for (int j = 0; j < m; j++) vis[n + j] = 0;         aum = 0;         for (int i = 0; i < n; i++)           if (ma[i] == -1 and dfs(i)) ret++, aum = 1;       }       return ret;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<string> v(n);     for (auto& i : v) cin >> i;     vector<string> v2;     kuhn k((n - 1) * m, (m - 1) * n);     int vert = 0, qt = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (v[i][j] ==  # ) {           qt++;           if (i + 1 < n and v[i + 1][j] ==  # ) {             vert++;             if (j + 1 < m and v[i][j + 1] ==  # ) k.add(m * i + j, n * j + i);             if (j + 1 < m and v[i + 1][j + 1] ==  # )               k.add(m * i + j, n * j + i + 1);             if (j and v[i][j - 1] ==  # ) k.add(m * i + j, n * (j - 1) + i);             if (j and v[i + 1][j - 1] ==  # )               k.add(m * i + j, n * (j - 1) + i + 1);           }           if (j + 1 < m and v[i][j + 1] ==  # ) vert++;         }     cout << qt - (vert - k.matching()) <<   n ;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   ,  ;     __f(comma + 1, args...);   }   const int N = 2e5 + 10;   const int INF = 1e8;   int n;   vector<int> g[N];   vector<int> BFS(vector<int> v, int src) {     vector<int> dist = vector<int>(n, INF);     queue<int> q;     q.push(src);     dist[src] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto v : g[u])         if (dist[v] == INF) {           dist[v] = dist[u] + 1;           q.push(v);         }     }     return dist;   }   int main() {     ios::sync_with_stdio(0);     int i, j, k, m;     cin >> n >> m >> k;     vector<int> a(k);     for (i = 0; i < k; ++i) {       cin >> a[i];       a[i]--;     }     for (i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     vector<int> d1 = BFS(a, 0);     vector<int> d2 = BFS(a, n - 1);     vector<int> b = {0};     vector<int> D3 = BFS(b, n - 1);     int d3 = D3[0];     sort(a.begin(), a.end(),          [&](int x, int y) { return d1[x] - d2[x] < d1[y] - d2[y]; });     vector<int> suf(k);     suf[k - 1] = d2[a[k - 1]];     for (i = k - 2; i >= 0; --i) suf[i] = max(suf[i + 1], d2[a[i]]);     int mx = 0;     for (i = 0; i < k - 1; ++i) mx = max(d1[a[i]] + suf[i + 1] + 1, mx);     cout << min(d3, mx) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get(char *s) {     if (s[0] ==  8  && s[1] ==  < ) return 1;     if (s[0] ==  [  && s[1] ==  ] ) return 2;     if (s[0] ==  (  && s[1] ==  ) ) return 3;   }   int check(int a, int b) {     if (a == 1 && b == 2 || a == 2 && b == 3 || a == 3 && b == 1) return 1;     if (a == 2 && b == 1 || a == 3 && b == 2 || a == 1 && b == 3) return 2;     return 0;   }   int main() {     char a[100] = {0}, b[100] = {0};     scanf( %s , a);     scanf( %s , b);     int x = 0, y = 0;     for (int i = 0; i < strlen(a); i += 2) {       int t = check(get(a + i), get(b + i));       if (t == 1) x++;       if (t == 2) y++;     }     if (x == y)       printf( TIE );     else if (x < y)       printf( TEAM 2 WINS );     else       printf( TEAM 1 WINS );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int nn, i, j, k;     cin >> nn;     long long int a[nn];     for (i = 0; i < nn; i++) cin >> a[i];     sort(a, a + nn);     for (i = 0; i < nn; i++) {       for (j = i + 1; j < nn; j++) {         if (a[i] != -1 && a[j] != -1 && a[j] % a[i] == 0) a[j] = -1;       }     }     long long int sum = 0;     for (i = 0; i < nn; i++) {       if (a[i] != -1) sum++;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long ara[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long mx = 0;     for (long long i = 0; i < n; ++i) {       cin >> ara[i];       while (ara[i] % 2 == 0) ara[i] /= 2;       while (ara[i] % 3 == 0) ara[i] /= 3;     }     for (long long i = 1; i < n; ++i) {       if (ara[i] != ara[0]) return cout <<  No , 0;     }     cout <<  Yes ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 100005;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;       cin >> n;       vector<long long int> v;       cout << n <<    ;       i = n - 1;       while (i > 0) {         if (n % i == 0) {           cout << i <<    ;           n = i;           i = n - 1;         } else {           i--;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int i;       int a[n];       int even = 0, odd = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] % 2 == 0)           even++;         else           odd++;       }       if (even % 2 == 0 && odd % 2 == 0) {         cout <<  YES  << endl;         continue;       }       sort(a, a + n, less<int>());       for (i = 1; i < n; i++) {         int k = 1;         while (a[i - k] == 0 && (i - k) > 0) {           k++;         }         if (a[i] - a[i - k] == 1) {           a[i] = 0;           a[i - k] = 0;           even--;           odd--;           if (even % 2 == 0 && odd % 2 == 0) {             cout <<  YES  << endl;             break;           }         }       }       if (i == n) cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[100005];   long long ans = 0;   long long temp[100005];   bool is(int m, string s) {     set<char> ss;     map<char, int> mp;     for (int i = 0; i < m; i++) {       ss.insert(s[i]);       mp[s[i]]++;     }     if (ss.size() == ans) return true;     for (int i = 0; i <= s.length() - m - 1; i++) {       mp[s[i]]--;       if (mp[s[i]] == 0) ss.erase(s[i]);       ss.insert(s[i + m]);       mp[s[i + m]]++;       if (ss.size() == ans) {         return true;       }     }     return false;   }   int main() {     int n;     string s;     cin >> n >> s;     set<char> se;     for (char c : s) se.insert(c);     ans = se.size();     int l = 0;     int r = n + 1;     while (r - l > 1) {       int m = l + (r - l) / 2;       if (!is(m, s))         l = m;       else         r = m;     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int MOD = 1000000007;   int d, n;   int a[N];   int ord[N], rnk[N];   vector<int> v[N];   inline bool cmp(int x, int y) { return a[x] > a[y]; }   int ans = 0;   int sz[N];   inline void dfs(int x, int top) {     sz[x] = 1;     for (int i = 0; i < v[x].size(); i++) {       int next = v[x][i];       if (sz[next] || rnk[next] < rnk[top] || a[top] - a[next] > d) continue;       dfs(next, top);       sz[x] = (long long)sz[x] * (sz[next] + 1) % MOD;     }   }   int main() {     scanf( %d%d , &d, &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ord[i] = i;     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++) rnk[ord[i]] = i;     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       memset(sz, 0, sizeof(sz));       dfs(ord[i], ord[i]);       ans = (ans + sz[ord[i]]) % MOD;     }     printf( %d n , ans);     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 <typename 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 T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename 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 <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   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<int, int> p[50010];   int f[50010];   void go(int first) {     printf( ? %d n , first);     fflush(stdout);     gn(p[first].first, p[first].second);   }   void end(int first) {     printf( ! %d n , first);     exit(0);   }   int main() {     int n, id, first;     gn(n, id, first);     for (int i = 1; i <= n; i++) f[i] = i;     srand(time(0));     random_shuffle(f + 1, f + n + 1);     go(id);     if (p[id].first >= first) end(p[id].first);     int N = min(n, 1000);     for (int i = 1; i <= N; i++) {       go(f[i]);       int u = p[f[i]].first;       if (u < first && u > p[id].first) id = f[i];     }     while (1) {       if (!p[id].second) go(id);       if (p[id].first >= first) end(p[id].first);       if (p[id].second == -1) end(-1);       id = p[id].second;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   vector<pair<int, int>> g[N], ans[N];   long long dist[N];   priority_queue<pair<int, int>> pq;   bool vis[N];   void dijkstra(int s) {     fill(dist, dist + N, 1LL << 61);     memset(vis, false, sizeof(vis));     dist[s] = 0;     pq.push({0, s});     while (!pq.empty()) {       int u = pq.top().second;       pq.pop();       if (vis[u]) continue;       vis[u] = true;       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i].first, w = g[u][i].second;         if (dist[v] > dist[u] + w) {           dist[v] = dist[u] + w;           pq.push({-dist[v], v});         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     int x, y;     cin >> x >> y;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     for (int i = 1; i <= n; i++) {       long long ti, ci;       cin >> ti >> ci;       dijkstra(i);       for (int j = 1; j <= n; j++) {         if (dist[j] <= ti) {           ans[i].push_back({j, ci});         }       }     }     for (int i = 1; i <= n; i++) {       g[i] = ans[i];     }     dijkstra(x);     if (dist[y] == 1LL << 61)       cout << -1;     else       cout << dist[y];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int n, l[N], r[N], a[N], ans, c;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       cin >> n;       for (int i = 1; i <= n; ++i) l[i] = 0, r[i] = n;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         if (l[a[i]] == 0) l[a[i]] = i;         r[a[i]] = i;       }       sort(a + 1, a + n + 1);       ans = 1, c = 0;       int m = 1;       for (int i = 2; i <= n; ++i) {         if (a[i] == a[i - 1]) continue;         m++;         if (r[a[i - 1]] < l[a[i]])           c++;         else           c = 0;         ans = max(ans, c + 1);       }       cout << m - ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   class IntegerIterator {    public:     using value_type = T;     using difference_type = std::ptrdiff_t;     using pointer = T*;     using reference = T;     using iterator_category = std::input_iterator_tag;     explicit IntegerIterator(T value) : value(value) {}     IntegerIterator& operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator& operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) const { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {     using IteratorType = std::reverse_iterator<IntegerIterator<T>>;       public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IteratorType begin() const {       return IteratorType(IntegerIterator<T>(begin_));     }     IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     return ReversedIntegerRange<T>(from + 1, to);   }   namespace impl {   using Random = std::mt19937;   }   inline impl::Random& randomEngine() {     static std::random_device device;     static impl::Random engine(device());     return engine;   }   inline int randomInteger() {     std::uniform_int_distribution<int> d;     return d(randomEngine());   }   inline int randomInteger(int to) {     ;     std::uniform_int_distribution<int> d(0, to - 1);     return d(randomEngine());   }   inline int randomInteger(int from, int to) {     return from + randomInteger(to - from);   }   using int64 = int64_t;   using std::endl;   using std::make_pair;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::unique;   using std::vector;   class AShuffleHashing {    public:     static void solveSlow(std::stringstream& in, std::ostream& out) {}     static constexpr int kStressIterations = 0;     static void generateTest(std::ostringstream& in, std::ostringstream& ___) {       auto _____ = std::stringstream(in.str());       solveSlow(_____, ___);     }     static void solve(std::istream& in, std::ostream& out) {       auto solve = [](string p, string h) -> bool {         if (h.size() < p.size()) return false;         sort(p.begin(), p.end());         for (int start : range(h.size() - p.size() + 1)) {           string h_s =   ;           for (int i : range<int>(start, start + p.size())) {             assert(i >= 0 && i < h.size());             h_s.push_back(h[i]);           }           sort(h_s.begin(), h_s.end());           if (p == h_s) return true;         }         return false;       };       int tests;       in >> tests;       for (int test : range(tests)) {         string p, h;         in >> p >> h;         out << (solve(p, h) ?  YES  :  NO ) << endl;       }     }   };   int main() {     std::ios_base::sync_with_stdio(false);     AShuffleHashing solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(nullptr);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int G = 3;   const int MOD = 998244353;   const int N = (1 << 15) + 5;   int rev[N], w[N], inv_n;   int bigMod(int a, int e, int mod) {     if (e == -1) e = mod - 2;     int ret = 1;     while (e) {       if (e & 1) ret = (long long)ret * a % mod;       a = (long long)a * a % mod;       e >>= 1;     }     return ret;   }   void prepare(int &n) {     int sz = abs(31 - __builtin_clz(n));     int r = bigMod(G, (MOD - 1) / n, MOD);     inv_n = bigMod(n, MOD - 2, MOD), w[0] = w[n] = 1;     for (int i = 1; i < n; ++i) w[i] = (long long)w[i - 1] * r % MOD;     for (int i = 1; i < n; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (sz - 1));   }   void ntt(int *a, int n, int dir) {     for (int i = 1; i < n - 1; ++i) {       if (i < rev[i]) swap(a[i], a[rev[i]]);     }     for (int m = 2; m <= n; m <<= 1) {       for (int i = 0; i < n; i += m) {         for (int j = 0; j < (m >> 1); ++j) {           int &u = a[i + j], &v = a[i + j + (m >> 1)];           int t = (long long)v * w[dir ? n - n / m * j : n / m * j] % MOD;           v = u - t < 0 ? u - t + MOD : u - t;           u = u + t >= MOD ? u + t - MOD : u + t;         }       }     }     if (dir)       for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * inv_n % MOD;   }   int f_a[N], f_b[N];   vector<long long> multiply(vector<long long> a, vector<long long> b) {     int sz = 1, n = a.size(), m = b.size();     while (sz < n + m - 1) sz <<= 1;     prepare(sz);     for (int i = 0; i < sz; ++i) f_a[i] = i < n ? a[i] : 0;     for (int i = 0; i < sz; ++i) f_b[i] = i < m ? b[i] : 0;     ntt(f_a, sz, 0);     ntt(f_b, sz, 0);     for (int i = 0; i < sz; ++i) f_a[i] = (long long)f_a[i] * f_b[i] % MOD;     ntt(f_a, sz, 1);     return vector<long long>(f_a, f_a + n + m - 1);   }   int n, k, q;   long long a[N], b[N];   vector<long long> get(int lo, int hi) {     if (lo == hi) return {b[lo], 1};     int mid = lo + hi >> 1;     vector<long long> one = get(lo, mid);     vector<long long> two = get(mid + 1, hi);     return multiply(one, two);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) scanf( %lld , a + i);     cin >> q;     while (q--) {       long long cmd, x, l, r, p;       scanf( %lld %lld %lld %lld , &cmd, &x, &l, &r);       if (cmd == 1) {         for (int i = 1; i <= n; ++i) {           b[i] = a[i];           if (i == l) b[i] = r;         }       } else {         scanf( %lld , &p);         for (int i = 1; i <= n; ++i) {           b[i] = a[i];           if (l <= i and i <= r) b[i] += p;         }       }       for (int i = 1; i <= n; ++i) {         b[i] = x - b[i], b[i] %= MOD;         if (b[i] < 0) b[i] += MOD;       }       vector<long long> yo = get(1, n);       printf( %lld n , yo[n - k]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void use_cio() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   template <typename... Args>   void dbg(Args... args) {     ((cout << args <<    ), ...);     cout << endl;   }   int n;   int ask(int r1, int c1, int r2, int c2) {     string ans;     dbg( ? , r1, c1, r2, c2);     cout.flush();     cin >> ans;     return (ans ==  YES );   }   int main() {     cin >> n;     string l, r;     int sx = 1, sy = 1;     while (sx + sy < n + 1) {       if (sy + 1 <= n && ask(sx, sy + 1, n, n)) {         sy++;         l +=  R ;       } else {         sx++;         l +=  D ;       }     }     int ex = n, ey = n;     while (ex + ey > n + 1) {       if (ex && ask(1, 1, ex - 1, ey)) {         ex--;         r +=  D ;       } else {         ey--;         r +=  R ;       }     }     reverse(r.begin(), r.end());     dbg( ! , l + r);   }


#include <bits/stdc++.h>   using namespace std;   long long dp[15][1 << 15];   int n, m, q;   struct NodeLCA {     int a, b, c;   };   vector<pair<int, int> > path;   vector<NodeLCA> LCA;   void readData() {     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       path.push_back(make_pair(u, v));     }     for (int i = 0; i < q; i++) {       int u, v, w;       cin >> u >> v >> w;       u--;       v--;       w--;       LCA.push_back({u, v, w});     }   }   int check(int root, int mask1, int child, int mask2) {     for (int i = 0; i < path.size(); i++) {       if (!(mask1 & (1 << path[i].first)) || !(mask1 & (1 << path[i].second)))         continue;       if (((mask2 & (1 << path[i].first)) > 0) ==           ((mask2 & (1 << path[i].second)) > 0))         continue;       if (path[i].second == root) swap(path[i].first, path[i].second);       if ((path[i].first != root) || (path[i].second != child)) return 0;     }     for (int i = 0; i < LCA.size(); i++) {       if (!(mask1 & (1 << LCA[i].a)) || !(mask1 & (1 << LCA[i].b))) continue;       if (((mask2 & (1 << LCA[i].a)) > 0) == ((mask2 & (1 << LCA[i].b)) > 0))         continue;       if (LCA[i].c != root) return 0;     }     return 1;   }   void dynamicProgramming() {     int mask, submask;     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     for (mask = 1; mask < (1 << n); mask++)       for (int i = 0; i < n; i++)         if (mask & (1 << i)) {           int tmp = -1;           for (int t = 0; t < n; t++)             if (t != i && (mask & (1 << t))) tmp = t;           if (tmp == -1) continue;           for (submask = (mask - 1) & mask; submask > 0;                submask = (submask - 1) & mask)             if ((submask & (1 << tmp)) && !(submask & (1 << i)))               for (int child = 0; child < n; child++)                 if (submask & (1 << child)) {                   if (check(i, mask, child, submask))                     dp[i][mask] += dp[child][submask] * dp[i][mask - submask];                 }         }   }   void writeData() { cout << dp[0][(1 << n) - 1]; }   int main() {     readData();     for (int i = 0; i < LCA.size(); i++)       if (LCA[i].a == LCA[i].b && LCA[i].a != LCA[i].c) {         cout << 0;         return 0;       }     dynamicProgramming();     writeData();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, k, count = 0;     cin >> n >> m >> k;     long long int s = n * m;     long long int a[s], b[s];     for (long long int i = 0; i < s; i++) cin >> a[i];     sort(a, a + s);     for (long long int i = 0; i < s; i++) {       b[i] = abs(a[i] - a[s / 2]);       if (b[i] % k != 0) {         cout << -1;         return 0;       } else {         count += b[i] / k;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, k;   int arr[N];   int a, b;   vector<int> v[N];   int tmp[N];   int subtree1[N];   int subtree2[N];   int sum[N];   int bst1[N];   int bst2[N];   bool ret;   void dfs(int node, int parent) {     subtree1[node] = 1;     subtree2[node] = tmp[node];     for (int next : v[node]) {       if (next != parent) {         dfs(next, node);         subtree1[node] += subtree1[next];         subtree2[node] += subtree2[next];       }     }   }   void dfs1(int node, int parent) {     sum[node] = 0;     bst1[node] = 0;     bst2[node] = 0;     for (int next : v[node]) {       if (next != parent) {         dfs1(next, node);         if (subtree2[next] == subtree1[next]) {           sum[node] += subtree1[next];         } else {           if (sum[next] > bst1[node]) {             bst2[node] = bst1[node];             bst1[node] = sum[next];           } else if (sum[next] > bst2[node]) {             bst2[node] = sum[next];           }         }       }     }     if (tmp[node]) {       ++sum[node];       sum[node] += bst1[node];     } else {       sum[node] = 0;       bst1[node] = 0;       bst2[node] = 0;     }     ret |= (sum[node] >= k);   }   void dfs2(int node, int parent, int val) {     if (val == n - subtree1[node]) {       sum[node] += val;     } else {       sum[node] -= bst1[node];       if (val > bst1[node]) {         bst2[node] = bst1[node];         bst1[node] = val;       } else if (val > bst2[node]) {         bst2[node] = val;       }       sum[node] += bst1[node];     }     if (!tmp[node]) {       sum[node] = 0;       bst1[node] = 0;       bst2[node] = 0;     }     ret |= (sum[node] >= k);     for (int next : v[node]) {       if (next != parent) {         if (subtree1[next] == subtree2[next]) {           dfs2(next, node, sum[node] - subtree1[next]);         } else if (bst1[node] == sum[next]) {           dfs2(next, node, sum[node] - bst1[node] + bst2[node]);         } else {           dfs2(next, node, sum[node]);         }       }     }   }   bool check(int val) {     for (int i = 1; i <= n; ++i) {       tmp[i] = (arr[i] >= val);     }     ret = 0;     dfs(1, 0);     dfs1(1, 0);     if (ret) {       return 1;     }     dfs2(1, 0, 0);     return ret;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , arr + i);     }     for (int i = 1; i < n; ++i) {       scanf( %d %d , &a, &b);       v[a].emplace_back(b);       v[b].emplace_back(a);     }     int l = 1;     int r = 1e6 + 1;     while (l < r) {       int mid = l + r >> 1;       if (check(mid)) {         l = mid + 1;       } else {         r = mid;       }     }     printf( %d n , l - 1);   }


#include <bits/stdc++.h>   using namespace std;   struct Bus {     long long s, t;   };   bool cmp(Bus &a, Bus &b) { return a.t < b.t; }   long long n, m, it[4 * 111111], tmp = 1, l, r;   Bus bus[111111];   vector<long long> positions;   void update(int idx, int l, int r, int pos, long long val) {     if (pos < l || pos > r) return;     if (l == r) {       it[idx] = val;       return;     }     int m = (l + r) / 2;     update(2 * idx, l, m, pos, val);     update(2 * idx + 1, m + 1, r, pos, val);     it[idx] = (it[2 * idx] + it[2 * idx + 1]) % 1000000007;   }   long long get(int idx, int l, int r, int u, int v) {     if (v < l || r < u) return 0;     if (u <= l && r <= v) return it[idx];     int m = (l + r) / 2;     long long ret =         (get(2 * idx, l, m, u, v) + get(2 * idx + 1, m + 1, r, u, v)) %         1000000007;     return ret;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> bus[i].s >> bus[i].t;     sort(bus, bus + m, cmp);     positions.push_back(0);     for (int i = 0; i < m; i++)       if (bus[i].t != positions[positions.size() - 1])         positions.push_back(bus[i].t);     if (n != positions[positions.size() - 1]) positions.push_back(n);     update(1, 0, positions.size() - 1, 0, 1);     for (int i = 0; i < m; i++) {       l = lower_bound(positions.begin(), positions.end(), bus[i].s) -           positions.begin();       r = upper_bound(positions.begin(), positions.end(), bus[i].t) -           positions.begin() - 1;       tmp = get(1, 0, positions.size() - 1, l, r);       update(1, 0, positions.size() - 1, r, tmp);     }     cout << get(1, 0, positions.size() - 1, positions.size() - 1,                 positions.size() - 1);   }