#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2200, MAX_K = 2200, INDEX = 1;   int n, k, a[MAX_N + INDEX], books[MAX_K + INDEX];   int ans = 0;   bool isBook(int x) {     for (int i = 1; i <= k; i++) {       if (books[i] == x) {         return true;       }     }     return false;   }   int dist(int book, int x) {     for (int i = 1; x + i <= n; i++) {       if (a[x + i] == book) {         return i;       }     }     return n + 1;   }   int getBest(int x) {     int best = 1;     for (int i = 2; i <= k; i++) {       if (dist(books[i], x) > dist(books[best], x)) {         best = i;       }     }     return best;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (!isBook((a[i]))) {         books[getBest(i)] = a[i];         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     set<pair<string, int> > name, s;     int n;     cin >> n;     string a;     for (int i = 0; i < n; i++) {       cin >> a;       name.insert(make_pair(a, i + 1));       cin >> a;       name.insert(make_pair(a, i + 1));     }     int temp;     bool flag = true;     set<pair<string, int> >::iterator itr1 = name.begin();     for (int i = 0; i < n; i++) {       cin >> temp;       while ((*itr1).second != temp && itr1 != name.end()) itr1++;     }     if (itr1 != name.end())       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first < b.first) return true;     return false;   }   long long int const maxm = 1e6;   long long int const minm = -1e9;   void solve() {     int n;     cin >> n;     int next[n + 1][2];     for (int i = 1; i <= n; i++) cin >> next[i][0] >> next[i][1];     vector<int> ans;     ans.push_back(3);     while (ans.size() < n) {       int cur = ans.back();       if (next[next[cur][0]][0] == next[cur][1] ||           next[next[cur][0]][1] == next[cur][1]) {         ans.push_back(next[cur][0]);         ans.push_back(next[cur][1]);       } else {         ans.push_back(next[cur][1]);         ans.push_back(next[cur][0]);       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     std ::ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     string s;     cin >> s;     long long a[2] = {0};     for (long long i = 0; i < n; i++) a[s[i] - 48]++;     if (a[0] == a[1]) {       cout <<  2 n  << s[0] <<    ;       for (long long i = 1; i < n; i++) cout << s[i];     } else {       cout <<  1 n  << s;     }   }


#include <bits/stdc++.h>   using namespace std;   int const INF = 100 + (int)1e9;   long long const INFL = 100 + (long long)1e18;   long double const PI = 3.141592653589793238462643L;   mt19937 tw(960172);   bool is_prime(long long x) {     for (long long y = 2; y * y <= x; ++y)       if (x % y == 0) return 0;     return x > 1;   }   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   long long sqr(int a) { return (long long)a * a; }   template <class T>   T sqr(T const& a) {     return a * a;   }   long long gcd(long long a, long long b) {     while (b > 0) {       long long t = a % b;       a = b;       b = t;     }     return a;   }   void solve() {     int n, k;     cin >> n >> k;     if (n <= 3 || k == 1 || k > 3 || (n == 4 && k == 2)) {       cout << -1 <<   n ;       return;     }     vector<pair<int, int>> edges;     if (k == 2) {       for (int i = 1; i < n; ++i) edges.emplace_back(i, i + 1);     } else {       edges.emplace_back(1, 2);       edges.emplace_back(2, 3);       edges.emplace_back(3, 4);       for (int i = 5; i <= n; ++i) {         edges.emplace_back(i, 1);         edges.emplace_back(i, 3);         if (i > 5) {           edges.emplace_back(i, i - 1);           if (i > 6) edges.emplace_back(i, 5);         }       }     }     cout << edges.size() <<   n ;     for (auto e : edges) cout << e.first <<     << e.second <<   n ;   }   int main() {     cout << setprecision(15) << fixed;     int tcnt = 1;     for (int test = 1; test <= tcnt; ++test) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   char s[N], t[N], S[N];   int n, ch[N][26], fa[N];   int len[N], anc[N], dif[N], nd, la;   int ans[N], _ans[N], from[N];   void extend(int n) {     int c = S[n], p = la;     for (; S[n - len[p] - 1] != c; p = fa[p])       ;     if (!ch[p][c -  a ]) {       len[++nd] = len[p] + 2;       int q = fa[p];       for (; S[n - len[q] - 1] != c; q = fa[q])         ;       fa[nd] = ch[q][c -  a ];       ch[p][c -  a ] = nd;       dif[nd] = len[nd] - len[fa[nd]];       anc[nd] = (dif[nd] == dif[fa[nd]] ? anc[fa[nd]] : fa[nd]);     }     la = ch[p][c -  a ];   }   int main() {     scanf( %s%s , s + 1, t + 1);     n = strlen(s + 1);     for (int i = (int)(1); i <= (int)(n); i++)       S[i * 2 - 1] = s[i], S[i * 2] = t[i];     fa[0] = nd = 1;     len[1] = -1;     n *= 2;     for (int i = (int)(1); i <= (int)(n); i++) ans[i] = 1 << 30;     _ans[0] = 1;     for (int i = (int)(1); i <= (int)(n); i++) {       extend(i);       for (int p = la; p; p = anc[p]) {         _ans[p] = i - (len[anc[p]] + dif[p]);         if (dif[fa[p]] == dif[p])           if (ans[_ans[p]] > ans[_ans[fa[p]]]) _ans[p] = _ans[fa[p]];         if (!(i & 1) && ans[i] > ans[_ans[p]] + 1)           ans[i] = ans[_ans[p]] + 1, from[i] = _ans[p];       }       if (!(i & 1) && S[i - 1] == S[i] && ans[i] > ans[i - 2])         ans[i] = ans[i - 2], from[i] = i - 2;     }     if (ans[n] > 1e9) return puts( -1 ), 0;     printf( %d n , ans[n]);     for (int i = n; i; i = from[i])       if (i - from[i] > 2) printf( %d %d n , from[i] / 2 + 1, i / 2);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i, j, n, m, po1, po2, w1, w2, z1, z2, lr, pr, li, pi, tw, ti;     cin >> n;     if ((n / 2) % 2 == 1) {       cout <<  ! -1 ;       return 0;     }     po1 = 1;     po2 = n / 2 + 1;     cout <<  ?   << po1 << endl;     cin >> w1;     cout <<  ?   << po2 << endl;     cin >> w2;     lr = w1 - w2;     pr = -lr;     li = 1;     pi = n / 2 + 1;     if (pr == 0) {       cout <<  !   << li;       return 0;     }     for (i = 0; i < 29; i++) {       ti = (pi + li) / 2;       cout <<  ?   << ti << endl;       cin >> z1;       cout <<  ?   << ti + n / 2 << endl;       cin >> z2;       tw = z1 - z2;       if (tw == 0) {         cout <<  !   << ti;         return 0;       }       if (tw < 0) {         if (lr < 0) {           lr = tw;           li = ti;         } else {           pr = tw;           pi = ti;         }       } else {         if (lr > 0) {           lr = tw;           li = ti;         } else {           pr = tw;           pi = ti;         }       }     }   }


#include <bits/stdc++.h>   const long long oo = 0x7f7f7f7f7f7f7f7f;   using namespace std;   const long long maxn = 1e6 + 999;   long long n, m, k, visa[maxn], visb[maxn], b[maxn], tota, totb, totc, totd;   struct goods {     long long val, id;     friend bool operator<(goods x, goods y) { return x.val < y.val; }   } a[maxn], A[maxn], B[maxn], C[maxn];   long long tot, cnt[maxn << 2], ls[maxn << 2], rs[maxn << 2], root;   long long sumv[maxn << 2];   void insert(long long pos, long long val, long long l, long long r,               long long &rt) {     if (val == 0 || pos == 0) return;     if (!rt) rt = ++tot;     if (val > 0)       sumv[rt] += val, cnt[rt]++;     else       sumv[rt] += val, cnt[rt]--;     if (l == r) {       return;     }     long long mid = l + r >> 1;     if (pos <= mid)       insert(pos, val, l, mid, ls[rt]);     else       insert(pos, val, mid + 1, r, rs[rt]);   }   long long query(long long k, long long l, long long r, long long rt) {     if (!k) return 0;     if (l == r) {       return min(k, cnt[rt]) * b[l];     }     long long cntt = cnt[ls[rt]];     long long mid = l + r >> 1;     if (k <= cntt)       return query(k, l, mid, ls[rt]);     else       return sumv[ls[rt]] + query(k - cntt, mid + 1, r, rs[rt]);   }   signed main() {     scanf( %lld%lld%lld , &n, &m, &k);     for (long long i = 1; i <= n; i++)       scanf( %lld , &a[i].val), b[i] = a[i].val, a[i].id = i;     sort(b + 1, b + 1 + n);     for (long long i = 1; i <= n; i++)       a[i].val = lower_bound(b + 1, b + 1 + n, a[i].val) - b;     long long x;     scanf( %lld , &x);     for (long long i = 1; i <= x; i++) {       long long p;       scanf( %lld , &p);       visa[p] = 1;     }     scanf( %d , &x);     for (long long i = 1; i <= x; i++) {       long long p;       scanf( %d , &p);       visb[p] = 1;     }     for (long long i = 1; i <= n; i++) {       if (visa[i] && visb[i])         A[++tota] = a[i];       else if (visa[i] && !visb[i])         B[++totb] = a[i];       else if (visb[i] && !visa[i])         C[++totc] = a[i];       insert(a[i].val, b[a[i].val], 1, n, root), totd++;     }     long long ans = oo, tmp = 0;     long long now1 = min(k, min(totb, totc));     sort(A + 1, A + 1 + tota);     sort(B + 1, B + 1 + totb);     sort(C + 1, C + 1 + totc);     for (long long i = 1; i <= now1; i++)       tmp += b[B[i].val] + b[C[i].val],           insert(C[i].val, -b[C[i].val], 1, n, root),           insert(B[i].val, -b[B[i].val], 1, n, root), totd -= 2;     long long ls = 0;     for (long long r = 0; r <= tota; r++) {       if (r + now1 == k && m - (r + now1 * 2) >= 0 &&           m - (r + now1 * 2) <= totd) {         ans = min(ans, tmp + query(m - (r + now1 * 2), 1, n, root));       }       tmp += b[A[r + 1].val];       insert(A[r + 1].val, -b[A[r + 1].val], 1, n, root), totd--;       if (r + 1 + now1 > k && now1 > 0) {         tmp -= b[B[now1].val] + b[C[now1].val],             insert(C[now1].val, b[C[now1].val], 1, n, root),             insert(B[now1].val, b[B[now1].val], 1, n, root), totd += 2;         now1--;       }     }     if (ans == oo) ans = -1;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int b1[] = {0, 0, 1, -1};   int b2[] = {1, -1, 0, 0};   int d1[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int d2[] = {-1, 0, 1, -1, 1, -1, 0, 1};   string st;   const int mxn = 1e6;   struct tp {     int tt, cl, op;   } tree[4 * mxn];   void build_tree(int s, int e, int index) {     tp obj;     obj.tt = obj.cl = obj.op = 0;     if (s == e) {       obj.cl = (st[s] ==  ) );       obj.op = (st[s] ==  ( );       tree[index] = obj;       return;     }     int mid = (s + e) / 2;     build_tree(s, mid, 2 * index);     build_tree(mid + 1, e, 2 * index + 1);     int min_blnc = min(tree[2 * index].op, tree[2 * index + 1].cl);     obj.tt = tree[2 * index].tt + tree[2 * index + 1].tt + 2 * min_blnc;     obj.cl = tree[2 * index].cl + tree[2 * index + 1].cl - min_blnc;     obj.op = tree[2 * index].op + tree[2 * index + 1].op - min_blnc;     tree[index] = obj;     return;   }   tp query(int second, int se, int qs, int qe, int index) {     tp obj;     obj.tt = obj.cl = obj.op = 0;     if (second >= qs and se <= qe) {       return tree[index];     }     if (qe < second || qs > se) return obj;     int mid = (second + se) / 2;     tp tp1 = query(second, mid, qs, qe, 2 * index);     tp tp2 = query(mid + 1, se, qs, qe, 2 * index + 1);     int min_blnc = min(tp1.op, tp2.cl);     obj.tt = tp1.tt + tp2.tt + 2 * min_blnc;     obj.cl = tp1.cl + tp2.cl - min_blnc;     obj.op = tp1.op + tp2.op - min_blnc;     return obj;   }   void solve() {     cin >> st;     int n = st.length();     build_tree(0, n - 1, 1);     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       x--, y--;       tp res = query(0, n - 1, x, y, 1);       cout << res.tt << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long inf = 1e18, M = 1e9 + 7;   const long long int N = 1;   bool left_turn(pair<long long int, long long int> a,                  pair<long long int, long long int> b,                  pair<long long int, long long int> c) {     if (a.first == b.first) {       if (a.second < b.second)         return c.first < b.first;       else         return c.first > b.first;     } else if (a.second == b.second) {       if (a.first < b.first)         return c.second > b.second;       else         return c.second < b.second;     }   }   void solve() {     long long int n;     cin >> n;     vector<pair<long long int, long long int> > v(n + 1);     for (long long int i = 0; i < n + 1; ++i) cin >> v[i].first >> v[i].second;     long long int ans = 0;     for (long long int i = 1; i < n; ++i) {       if (left_turn(v[i - 1], v[i], v[i + 1])) ++ans;     }     cout << ans;   }   int32_t main() {     long long int t = 1;     for (long long int z = 1; z <= t; ++z) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long min(long long x, long long y) { return x < y ? x : y; }   inline long long max(long long x, long long y) { return x > y ? x : y; }   const int Maxn = 1e4 + 5;   int n, k, m, ans = -1;   int a[Maxn], b[105], c[30], dis[30][Maxn], f[2000005], pw[30];   bool inq[Maxn];   void SPFA(register int x, register int p) {     dis[p][x] = 0;     queue<int> q;     q.push(x);     while (!q.empty()) {       x = q.front();       q.pop();       inq[x] = false;       for (register int i = 1, nx; i <= m; i++) {         nx = x + b[i];         if (nx <= n + 1)           if (dis[p][x] + 1 < dis[p][nx]) {             dis[p][nx] = dis[p][x] + 1;             if (!inq[nx]) {               q.push(nx);               inq[nx] = true;             }           }         nx = x - b[i];         if (nx > 0)           if (dis[p][x] + 1 < dis[p][nx]) {             dis[p][nx] = dis[p][x] + 1;             if (!inq[nx]) {               q.push(nx);               inq[nx] = true;             }           }       }     }   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 25; i++) pw[i] = pw[i - 1] << 1;     memset(dis, 0x3f, sizeof(dis));     int pos, siz = 0;     cin >> n >> k >> m;     for (int i = 1; i <= k; i++) {       scanf( %d , &pos);       a[pos] = 1;     }     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     for (int i = 0; i <= n; i++)       if (a[i + 1] != a[i]) {         c[++siz] = i + 1;         SPFA(i + 1, siz);       }     n = siz;     memset(f, 0x3f, sizeof(f));     f[0] = 0;     int nx;     for (int i = 0; i < pw[n] - 3; i++)       for (int j = 1; j < n; j++)         for (int k = j + 1; k <= n; k++) {           if ((i & pw[j - 1]) || (i & pw[k - 1])) continue;           nx = i | pw[j - 1] | pw[k - 1];           f[nx] = min(f[nx], f[i] + dis[j][c[k]]);         }     if (f[pw[n] - 1] == 0x3f3f3f3f) f[pw[n] - 1] = -1;     cout << f[pw[n] - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cnt, prime[100], pcnt;   long long flg;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long search(long long a, long long b) {     if (!b) return 0;     long long d = gcd(a, b);     a /= d;     b /= d;     long long minn = 1ll << 60;     for (int i = 1; i <= cnt; i++)       if (a % prime[i] == 0) minn = min(minn, b % prime[i]);     if (minn == 1ll << 60) return b;     return minn + search(a, b - minn);   }   int main() {     long long a, b;     scanf( %I64d%I64d , &a, &b);     long long A = a;     for (long long i = 2; i * i <= A; i++) {       if (a % i == 0) {         while (a % i == 0) {           a /= i;         }         prime[++cnt] = i;       }     }     if (a > prime[cnt]) prime[++cnt] = a;     if (a == A) {       printf( %I64d , A > b ? b : b % A + (b - b % A) / A);       return 0;     }     long long ans = search(A, b);     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 1e9;   int a[N], maxv[N << 2], addv[N << 2];   int dmax[N][21];   int n, ans;   void maintain(int rt, int l, int r) {     maxv[rt] = 0;     if (l < r) maxv[rt] = max(maxv[rt << 1], maxv[rt << 1 | 1]);     maxv[rt] += addv[rt];   }   void update(int ql, int qr, int v, int rt, int l, int r) {     if (ql <= l && qr >= r)       addv[rt] += v;     else {       int mid = (l + r) >> 1;       if (ql <= mid) update(ql, qr, v, rt << 1, l, mid);       if (qr > mid) update(ql, qr, v, rt << 1 | 1, mid + 1, r);     }     maintain(rt, l, r);   }   void querymax(int ql, int qr, int rt, int l, int r, int add) {     if (ql <= l && qr >= r)       ans = max(ans, maxv[rt] + add);     else {       int mid = (l + r) >> 1;       if (ql <= mid) querymax(ql, qr, rt << 1, l, mid, add + addv[rt]);       if (qr > mid) querymax(ql, qr, rt << 1 | 1, mid + 1, r, add + addv[rt]);     }   }   void build() {     for (int i = 1; i <= n; i++) dmax[i][0] = a[i];     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i + (1 << j) - 1 <= n; i++) {         dmax[i][j] = max(dmax[i][j - 1], dmax[i + (1 << (j - 1))][j - 1]);       }     }   }   int query(int l, int r) {     int k = 0;     while ((1 << (k + 1)) <= r - l + 1) k++;     return max(dmax[l][k], dmax[r - (1 << k) + 1][k]);   }   int main() {     int k, num, l, r, mid;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build();     memset(maxv, 0, sizeof(maxv));     for (int i = 1; i <= n; i++) {       l = 0;       r = i;       while (r - l > 1) {         mid = (l + r) >> 1;         if (query(mid, r - 1) >= a[i])           l = mid;         else           r = mid;       }       update(r, i, 1, 1, 1, n);       if (i >= k) {         ans = 0;         querymax(i - k + 1, i, 1, 1, n, 0);         printf( %d  , ans);       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using std::max;   using std::min;   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3f;   __inline__ __attribute__((always_inline)) unsigned int rnd() {     static unsigned int seed = 416;     return seed += 0x71dad4bfu, seed ^= seed >> 5, seed += 0xc6f74d88u,            seed ^= seed << 17, seed += 0x25e6561u, seed ^= seed >> 13;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     f && (x = -x);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? min(a, args...) : min(b, args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? max(b, args...) : max(a, args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 65;   const int mod = 1000000007;   template <typename _Tp1, typename _Tp2>   __inline__ __attribute__((always_inline)) void add(_Tp1 &a, _Tp2 b) {     (a += b) >= mod && (a -= mod);   }   template <typename _Tp1, typename _Tp2>   __inline__ __attribute__((always_inline)) void sub(_Tp1 &a, _Tp2 b) {     (a -= b) < 0 && (a += mod);   }   int n, a[N], fa[N];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int dp[1 << 15][N], sum[1 << 15];   std::pair<int, int> solve(int ___) {     std::vector<int> nd;     for (int i = 1; i <= n; ++i)       if (find(i) == ___) nd.push_back(a[i]);     std::vector<int> A, B;     for (auto a : nd) {       int cnt = 0;       for (auto b : nd)         if (a != b && !(a % b)) ++cnt;       if (!cnt)         A.push_back(a);       else         B.push_back(a);     }     if (((int)B.size()) <= 1) return std::make_pair(0, 1);     memset(dp, 0, sizeof(dp));     memset(sum, 0, sizeof(sum));     for (auto &&it : B) {       int qwq = 0;       for (int i = 0; i < ((int)A.size()); ++i)         if (!(it % A[i])) qwq |= 1 << i;       it = qwq, ++sum[it];       ++dp[it][1];     }     for (int i = 0; i < ((int)A.size()); ++i)       for (int st = 0; st < 1 << ((int)A.size()); ++st)         if ((st >> i) & 1) sum[st] += sum[st ^ (1 << i)];     for (int st = 0; st < 1 << ((int)A.size()); ++st) {       for (int j = 1; j <= ((int)B.size()); ++j) {         if (!dp[st][j]) continue;         add(dp[st][j + 1], 1ll * dp[st][j] * (sum[st] - j) % mod);         for (auto it : B)           if ((it & st) && (st & it) != it) add(dp[st | it][j + 1], dp[st][j]);       }     }     return std::make_pair(((int)B.size()) - 1,                           dp[(1 << ((int)A.size())) - 1][((int)B.size())]);   }   int C[N][N];   int main() {     for (int i = 0; i < N; ++i)       for (int j = C[i][0] = 1; j <= i; ++j)         C[i][j] = C[i - 1][j - 1], add(C[i][j], C[i - 1][j]);     read(n);     for (int i = 1; i <= n; ++i) read(a[i]), fa[i] = i;     std::sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (!(a[i] % a[j])) fa[find(i)] = find(j);     long long ans = 1, res = 0;     for (int i = 1; i <= n; ++i) {       if (fa[i] == i) {         std::pair<int, int> tmp = solve(i);         res += tmp.first;         ans = ans * C[res][tmp.first] % mod * tmp.second % mod;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e7 + 7;   long long mn = (long long)(1e18 + 7), mx = -(long long)(1e18 + 7);   long long n, m, k, s, q, t;   long long a, b, c, d, e;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> a >> b >> c >> d;     for (int i = 0; i <= N; i++) {       if (i * c <= n) mx = max(mx, i * a + ((n - i * c) / d * b));       if (i * d <= n) mx = max(mx, i * b + ((n - i * d) / c * a));     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   template <class T>   int getbit(T s, int i) {     return (s >> 1) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   long long N;   long long modPow(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long tmp = modPow(a, b / 2);     if (b % 2 == 0) return ((tmp * tmp) % 1000000007LL);     return ((((tmp * tmp) % 1000000007LL) * a) % 1000000007LL);   }   void VarInput() { cin >> N; }   void ProSolve() {     long long ans = modPow(27, N) - modPow(7, N);     while (ans < 0) ans += 1000000007LL;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     VarInput();     ProSolve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300010;   int h[MAXN], v[MAXN];   int main() {     int n;     scanf(  %d , &n);     for (int i = 0; i < (n); ++i) {       scanf(  %d , &h[i]);     }     v[0] = 1;     v[n - 1] = 1;     for (int i = (1); i < (n - 1); ++i) {       v[i] = min(h[i], v[i - 1] + 1);     }     for (int i = n - 2; i >= 0; --i) {       v[i] = min(v[i], min(h[i], v[i + 1] + 1));     }     int ans = -1;     for (int i = 0; i < (n); ++i) ans = max(ans, v[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n;     while (~scanf( %I64d , &n)) {       long long m = sqrt(n);       long long m1 = sqrt(m);       long long i;       long long sum;       int flag = 0;       for (i = m + 1; i >= m + 1 - 100; i--) {         sum = 0;         long long b = i;         while (b) {           sum += b % 10;           b /= 10;         }         long long num = sum * i + i * i;         if (num == n) {           printf( %I64d n , i);           flag = 1;           break;         }       }       if (flag == 0) {         printf( -1 n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int bit[200005];   void update(long long int x) {     while (x < 200005) {       bit[x] += 1;       if (x == 0) break;       x += x & (-x);     }   }   long long int query(long long int x) {     long long int ans = 0;     while (x >= 0) {       ans += bit[x];       if (x == 0) break;       x -= x & (-x);     }     return ans;   }   int main() {     long long int n, t;     cin >> n >> t;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) {       cin >> v[i];       if (i) v[i] += v[i - 1];     }     vector<long long int> v2 = v;     sort(v.begin(), v.end());     long long int ans = 0;     for (long long int i = (n - 1); i >= 0; i--) {       int pos = lower_bound(v.begin(), v.end(), v2[i] + t) - v.begin();       ans += query(pos - 1);       update(lower_bound(v.begin(), v.end(), v2[i]) - v.begin());     }     ans += query(lower_bound(v.begin(), v.end(), t) - v.begin() - 1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int get(int a) {     int maxx = 0;     for (int i = 0; i < 21; i++)       if (a & (1 << i)) maxx = i;     int ans = (1 << (maxx + 1)) - 1;     return (ans ^ a);   }   int main() {     int n;     cin >> n;     vector<int> a(n + 1);     for (int i = n; i >= 0; i--) {       if (a[i] == 0) {         for (int j = 21; j >= 0; j--) {           int tmp = get(i);           if ((i ^ tmp) == i + tmp && a[tmp] == 0) {             a[tmp] = i;             a[i] = tmp;             break;           }         }       }     }     long long ans = 0;     for (int i = 0; i <= n; i++) ans += (a[i] ^ i);     cout << ans << endl;     for (int i = 0; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const int N = 4e5 + 10;   const int M = 1e6 + 10;   const long long mod = 1e9 + 7;   const double PI = acos(-1);   long long w[N];   int fa[N][21];   long long wi[N][21];   long long mx[N][21];   int Find(int x, int y) {     for (int i = 20; i >= 0; --i)       if (mx[x][i] < y) x = fa[x][i];     return x;   }   int dd[21];   int main() {     dd[0] = 1;     for (int i = 1; i <= 20; ++i) dd[i] = dd[i - 1] * 2;     int cnt = 1, last = 0;     w[0] = 1e16;     for (int i = 0; i <= 20; ++i) fa[0][i] = 0, wi[0][i] = 1e16, mx[0][i] = 1e16;     w[1] = 0, fa[1][0] = 0, wi[1][0] = 0;     for (int i = 1; i <= 20; ++i) fa[1][i] = 0, wi[1][i] = 1e16, mx[1][i] = 1e16;     int q, to, op;     long long x, y;     scanf( %d , &q);     while (q--) {       scanf( %d%I64d%I64d , &op, &x, &y);       x ^= last, y ^= last;       if (op == 1) {         w[++cnt] = y;         fa[cnt][0] = Find(x, y);         mx[cnt][0] = wi[cnt][0] = w[cnt];         for (int i = 1; i <= 20; ++i) {           to = fa[cnt][i - 1];           fa[cnt][i] = fa[to][i - 1];           mx[cnt][i] = max(mx[cnt][i - 1], mx[to][i - 1]);           wi[cnt][i] = wi[cnt][i - 1] + wi[to][i - 1];         }       } else {         last = 0;         for (int i = 20; i >= 0; --i) {           if (wi[x][i] <= y) {             last += dd[i];             y -= wi[x][i];             x = fa[x][i];           }         }         printf( %d n , last);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int prime = 999983;   const int INF = 0x7FFFFFFF;   const long long INFF = 0x7FFFFFFFFFFFFFFF;   const double pi = acos(-1.0);   const double inf = 1e18;   const double eps = 1e-6;   const long long mod = 1e9 + 7;   long long qpow(long long a, long long b) {     long long s = 1;     while (b > 0) {       if (b & 1) s = s * a % mod;       a = a * a % mod;       b >>= 1;     }     return s;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};   const int maxm = 2e7, maxn = 3e5 + 10;   int a[maxn];   int num[maxm][2];   int main(void) {     int n;     cin >> n;     long long ans = 0;     num[0][0] = 1;     for (int i = 1; i < n + 1; i++) {       scanf( %d , &a[i]);       a[i] ^= a[i - 1];       ans += num[a[i]][i % 2];       num[a[i]][i % 2]++;     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int ma = -1, mi = 1000000000000000;   inline long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   inline long long int lcm(long long int a, long long int b, long long int MOD) {     return a / gcd(a, b) * b % MOD;   }   long long int power(long long int x, unsigned int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, a[100000] = {0}, n, m, b[100009] = {0}, c = 0, d = 0,                            e[30] = {0}, x = 0;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 1; i++) {       if (a[i] + a[i + 1] < m) {         d = m - a[i] - a[i + 1];         a[i + 1] += d;         c += d;       }     }     cout << c << endl;     for (i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int AA[100010];   int BB[100010];   long long dp[100010];   int N;   vector<long long> M;   vector<long long> B;   bool bad(long long l1, long long l2, long long l3) {     long double XX1 = 1.00000 * (M[l1] - M[l2]) / (M[l1] - M[l3]);     long double XX2 = 1.00000 * (B[l2] - B[l1]) / (B[l3] - B[l1]);     return XX1 < XX2;   }   void add(long long m, long long b) {     M.push_back(m);     B.push_back(b);     while (M.size() >= 3 && bad(M.size() - 3, M.size() - 2, M.size() - 1)) {       M.erase(M.end() - 2);       B.erase(B.end() - 2);     }   }   int pointer;   long long query(long long x) {     if (pointer >= M.size()) pointer = M.size() - 1;     while (pointer < M.size() - 1 &&            M[pointer + 1] * x + B[pointer + 1] > M[pointer] * x + B[pointer])       pointer++;     return M[pointer] * x + B[pointer];   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> AA[i];     }     for (int i = 1; i <= N; i++) {       cin >> BB[i];     }     dp[1] = 0LL;     add(-BB[1], -dp[1]);     for (int i = 2; i <= N; i++) {       dp[i] = -1LL * query(AA[i]);       add(-BB[i], -dp[i]);     }     cout << dp[N] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int delta = (int)1e9 + 7;   int n, a[(int)3e5 + 20], b[(int)3e5 + 20], x, y, z, ans, h[(int)3e5 + 20];   vector<int> G[(int)3e5 + 20];   bool cmp(int u, int v) {     if (a[u] == a[v]) return u < v;     return a[u] > a[v];   }   bool ac1() {     for (int i = 0; i < G[b[1]].size(); ++i) h[G[b[1]][i]] = 1;     int w = 2;     while (a[b[w]] == a[b[1]] - 1 && w <= n) {       if (!h[b[w]]) return 1;       ++w;     }     return 0;   }   bool ac2() {     for (int i = 1; i <= n; ++i)       if (a[i] == z) ++y;     for (int i = 1; i <= n; ++i) {       if (a[i] == z)         x = 1;       else         x = 0;       for (int j = 0; j < G[i].size(); ++j)         if (a[G[i][j]] == z) ++x;       if (x == y) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i], b[i] = i;     for (int i = 1; i < n; ++i) {       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     sort(b + 1, b + n + 1, cmp);     z = ans = a[b[1]];     if (n == 1 || a[b[1]] - a[b[2]] > 1)       ;     else if (a[b[1]] == a[b[2]] + 1) {       if (ac1()) ++ans;     } else {       y = 0;       ans += ac2() + 1;     }     cout << ans;     return cout << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(long long first) {     return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   class DPowerTree {    public:     int N;     vector<vector<int>> E;     vector<long long> C;     vector<int> Omit;     vector<bool> Take;     vector<pair<long long, long long>> Ans;     pair<long long, long long> solve(int u, int p) {       if (E[u].size() == 1 && u != 0) {         return Ans[u] = {0, C[u]};       };       long long a = 0, b = 0;       for (int v : E[u]) {         if (v != p) {           auto s = solve(v, u);           a = min(a + s.second, b + s.first);           b += s.second;         }       }       return Ans[u] = {a, min(b, a + C[u])};     }     void collect(int u, int p, bool allPaths, vector<int>& Ret) {       long long diff = Ans[u].second - Ans[u].first;       if (allPaths && C[u] <= diff) Ret.push_back(u + 1);       int worst = -1;       int cnt = 0;       for (int v : E[u]) {         if (v != p) {           int myDiff = Ans[v].second - Ans[v].first;           if (myDiff > worst) {             worst = myDiff;             cnt = 0;           }           cnt += myDiff == worst;         }       }       for (int v : E[u]) {         if (v != p) {           int myDiff = Ans[v].second - Ans[v].first;           collect(v, u, myDiff < worst || cnt > 1 || (worst <= C[u] && allPaths),                   Ret);         }       }     }     void solve(istream& cin, ostream& cout) {       cin >> N;       C.resize(N);       cin >> C;       E.resize(N);       Ans.resize(N);       for (int i = 0; i < N - 1; ++i) {         int u, v;         cin >> u >> v;         --u;         --v;         E[u].push_back(v);         E[v].push_back(u);       }       auto s = solve(0, -1);       vector<int> X;       collect(0, -1, true, X);       sort(X.begin(), X.end());       cout << s.second <<     << X.size() << endl;       cout << X;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     DPowerTree solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int f[100010], n, a[100010];   const long long int inf = 2000000000000;   int main() {     long long int i, j, k;     scanf( %I64d , &n);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     f[0] = 0;     sort(a + 1, a + 1 + n);     for (i = 1; i <= n; i++) {       f[i] = f[i - 1] + 20;       long long int t;       t = lower_bound(a + 1, a + 1 + n, a[i] - 89) - a - 1;       f[i] = min(f[i], f[t] + 50);       t = lower_bound(a + 1, a + 1 + n, a[i] - 1439) - a - 1;       f[i] = min(f[i], f[t] + 120);       printf( %I64d n , f[i] - f[i - 1]);     }     return 0;   }


#include <bits/stdc++.h>   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   using namespace std;   const long long maxn = 1e5 + 7;   const double eps = 1e-10;   const long long mod = 1e9 + 7;   long long n;   long long totA = 0, totB = 0;   long long casA[maxn * 2], casB[maxn * 2];   long long tot = 0;   struct Node {     long long set, score;   };   Node node[maxn];   bool cmp(Node a, Node b) {     if (a.set < b.set) return 1;     if (a.set == b.set && a.score < b.score) return 1;     return 0;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i < 2 * maxn; i++)       casA[i] = casB[i] = 9223372036854775807;     bool flagA = 0, flagB = 0;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       if (x == 1)         casA[++totA] = i;       else         casB[++totB] = i;       if (i == n) {         if (x == 1)           flagA = 1;         else           flagB = 1;       }     }     for (long long i = n; i >= 1; i--) {       long long winA = 0, winB = 0, tarA = 0, tarB = 0;       long long now = 1;       bool flag = 1;       while (now <= n) {         if (casA[tarA + i] == 9223372036854775807 &&             casB[tarB + i] == 9223372036854775807) {           flag = 0;           break;         }         if (casA[tarA + i] < casB[tarB + i]) {           winA++;           tarA += i;           tarB = casA[tarA] - tarA;           now = casA[tarA] + 1;         } else {           winB++;           tarB += i;           tarA = casB[tarB] - tarB;           now = casB[tarB] + 1;         }       }       if (winA == winB) flag = 0;       if (winA > winB && flagB) flag = 0;       if (winA < winB && flagA) flag = 0;       if (flag) {         node[++tot].set = max(winA, winB);         node[tot].score = i;       }     }     sort(node, node + tot, cmp);     cout << tot <<   n ;     if (tot) {       for (long long i = 1; i <= tot; i++)         cout << node[i].set <<     << node[i].score <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3E5 + 5;   int n, m, sz, val, x, y, color[MAXN];   vector<int> v[MAXN], G[MAXN];   template <class T>   void read(T& x, T f = 1, char ch = getchar()) {     x = 0;     while (ch <  0  || ch >  9 ) f = (ch ==  -  ? -1 : 1), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     x *= f;   }   void dfs(int now, int f) {     map<int, int> vis;     for (int i = 0; i < v[now].size(); i++)       if (color[v[now][i]]) vis[color[v[now][i]]] = 1;     int l = 0;     for (int i = 0; i < v[now].size(); i++) {       if (!color[v[now][i]]) {         while (vis[++l])           ;         color[v[now][i]] = l;       }     }     for (int i = 0; i < G[now].size(); i++) {       int to = G[now][i];       if (to != f) dfs(to, now);     }   }   signed main() {     read(n), read(m);     int ans = 1;     for (int i = 1; i <= n; i++) {       read(sz);       for (int j = 1; j <= sz; j++) {         read(val);         v[i].push_back(val);       }       ans = max(ans, sz);     }     for (int i = 1; i <= n - 1; i++) {       read(x), read(y);       G[x].push_back(y), G[y].push_back(x);     }     dfs(1, 1);     printf( %d n , ans);     for (int i = 1; i <= m; i++) printf( %d  , color[i] ? color[i] : 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -O2 )   using namespace std;   const long long N = 500000 + 10;   const long long MOD = 1000000000 + 7;   const long long INF = 100000000000000010;   const long long LOG = 25;   long long dp[N], n, a[N], lazy[N << 2], m, b[N], seg[N << 2], p[N], koj[N];   void modify(long long id, long long x) {     seg[id] += x;     lazy[id] += x;   }   void shift(long long id) {     modify(id << 1, lazy[id]);     modify(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   void add(long long id, long long lq, long long rq, long long x, long long l,            long long r) {     if (rq <= l || r <= lq) return;     if (lq <= l && r <= rq) {       modify(id, x);       return;     }     long long md = (l + r) >> 1;     shift(id);     add(id << 1, lq, rq, x, l, md);     add(id << 1 | 1, lq, rq, x, md, r);     seg[id] = seg[id << 1] + seg[id << 1 | 1];   }   long long get(long long id, long long lq, long long rq, long long l,                 long long r) {     if (rq <= l || r <= lq) return 0;     if (lq <= l && r <= rq) return seg[id];     shift(id);     long long md = (l + r) >> 1;     return get(id << 1, lq, rq, l, md) + get(id << 1 | 1, lq, rq, md, r);   }   void Set(long long id, long long lq, long long rq, long long x, long long l,            long long r) {     if (rq <= l || r <= lq) return;     if (lq <= l && r <= rq) {       seg[id] = x;       return;     }     long long md = (l + r) >> 1;     shift(id);     Set(id << 1, lq, rq, x, l, md);     Set(id << 1 | 1, lq, rq, x, md, r);     seg[id] = seg[id << 1] + seg[id << 1 | 1];   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     for (long long i = 1; i <= n; i++) cin >> p[i];     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> b[i];       koj[b[i]] = i;     }     add(1, 1, m + 1, INF, 0, m + 1);     for (long long i = 1; i <= n; i++) {       if (koj[a[i]] == 0) {         long long x = lower_bound(b + 1, b + m + 1, a[i]) - b;         add(1, 0, x, p[i], 0, m + 1);         long long zed = min(0ll, p[i]);         add(1, x, m + 1, zed, 0, m + 1);       } else {         long long j = koj[a[i]];         long long zed = min(0ll, p[i]);         long long mn =             min(get(1, j - 1, j, 0, m + 1), get(1, j, j + 1, 0, m + 1) + zed);         Set(1, j, j + 1, mn, 0, m + 1);         add(1, 0, j, p[i], 0, m + 1);         add(1, j + 1, m + 1, zed, 0, m + 1);       }     }     long long ans = get(1, m, m + 1, 0, m + 1);     if (ans > 1000000000000000) return cout <<  NO , 0;     cout <<  YES n ;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 100;   double alpha[maxn], beta[maxn];   double a[maxn], b[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf , &beta[i]);     for (int i = 0; i < n; i++) scanf( %lf , &alpha[i]);     double Sa = 0, Sb = 0;     for (int i = 0; i < n; i++) {       double c = alpha[i] + beta[i];       double A = 1, B = -(c + (Sb - Sa)), C = beta[i] - c * Sa;       double x1 = (-B + sqrt(max(0., B * B - 4. * A * C))) / 2.;       double y1 = c - x1;       a[i] = x1;       b[i] = y1;       Sa += a[i];       Sb += b[i];     }     cout.precision(15);     for (int i = 0; i < n; i++) printf( %.9lf  , a[i]);     printf(  n );     for (int i = 0; i < n; i++) printf( %.9lf  , b[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   const int mod = 1e9 + 7;   const long long INF = 1e15;   int nex[N];   long long x[N], a[N], b[N], c[N], d[N];   int main() {     int n, s, e;     while (~scanf( %d%d%d , &n, &s, &e)) {       nex[s] = e;       for (int i = 1; i <= n; i++) scanf( %I64d , &x[i]);       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);       for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);       for (int i = 1l; i <= n; i++) scanf( %I64d , &c[i]);       for (int i = 1; i <= n; i++) scanf( %I64d , &d[i]);       for (int i = 1; i <= n; i++) {         if (i == s || i == e) continue;         long long mi = INF, id;         for (int j = s; j != e; j = nex[j]) {           long long tmpans = 0;           int from = j, to = i;           if (to < from)             tmpans += abs(x[from] - x[to]) + c[from] + b[to];           else             tmpans += abs(x[from] - x[to]) + d[from] + a[to];           from = i, to = nex[j];           if (to < from)             tmpans += abs(x[from] - x[to]) + c[from] + b[to];           else             tmpans += abs(x[from] - x[to]) + d[from] + a[to];           from = j, to = nex[j];           if (to < from)             tmpans -= abs(x[from] - x[to]) + c[from] + b[to];           else             tmpans -= abs(x[from] - x[to]) + d[from] + a[to];           if (mi > tmpans) {             mi = tmpans;             id = j;           }         }         int tmpnex = nex[id];         nex[id] = i;         nex[i] = tmpnex;       }       long long ans = 0;       for (int i = s; i != e; i = nex[i]) {         long long tmpans = 0;         int from = i, to = nex[i];         if (to < from)           tmpans += abs(x[from] - x[to]) + c[from] + b[to];         else           tmpans += abs(x[from] - x[to]) + d[from] + a[to];         ans += tmpans;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   long long int ceil(long long int r, long long int d) {     return (r / d) + (bool)(r % d);   }   void inputAArray(int siz, vector<int> &arr) {     for (int i = 0; i < siz; i++) arr[i] = 1 + rand();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = s.length();       if (n & 1) {         cout <<  NO  << endl;         continue;       }       if (s.substr(0, n / 2) == s.substr(n / 2))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double n, l, v1, v2, k;   bool c(double x) {     int num;     if ((int)n % (int)k == 0)       num = n / k;     else       num = n / k + 1;     if (num * x + (num - 1) * x * (v2 - v1) / (v2 + v1) <= x + (l - x * v2) / v1)       return 1;     return 0;   }   int main() {     scanf( %lf%lf%lf%lf%lf , &n, &l, &v1, &v2, &k);     double lb = 0, rb = 1000000001;     for (int i = 0; i < 100; i++) {       double m = (lb + rb) / 2;       if (c(m))         lb = m;       else         rb = m;     }     printf( %lf , rb + (l - rb * v2) / v1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, i, ans, a;   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       ans = 0;       for (i = 1; i <= n; i++) {         cin >> a;         ans += a;       }       if (ans == m)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int maxn = 1000100;   int n;   char a[maxn + 5];   inline bool check(int first) {     vector<int> man, aster;     for (int i = (0), i_end_ = (n); i < i_end_; ++i) {       if (a[i] ==  P )         man.push_back(i);       else if (a[i] ==  * )         aster.push_back(i);     }     int nman = (int((man).size())), naster = (int((aster).size()));     static bool dp[maxn + 5][2];     memset(dp, 0, sizeof dp);     int j = nman - 1;     dp[naster][0] = dp[naster][1] = 1;     for (int i = naster - 1; i >= 0; --i) {       j = min((int((man).size())) - 1, j + 1);       while (j >= 0 && man[j] > aster[i]) {         bool ok = 0;         if (man[j] - first <= aster[i]) {           int tmp = man[j];           if (j && man[j - 1] > aster[i]) chkmax(tmp, man[j - 1] + first);           int fir =               upper_bound((aster).begin(), (aster).end(), tmp) - aster.begin();           if (fir == naster ||               (j + 1 < (int((man).size())) && aster[fir] > man[j + 1]))             ok = dp[fir][1];           else             ok = dp[fir][0];         }         if (ok) {           dp[i][0] = 1;           break;         }         --j;       }       if (dp[i][0])         dp[i][1] = 1;       else {         if (j >= 0) {           int tmp = man[j] + first;           int fir =               upper_bound((aster).begin(), (aster).end(), tmp) - aster.begin();           if (fir == naster ||               (j + 1 < (int((man).size())) && aster[fir] > man[j + 1])) {             dp[i][1] = dp[fir][1];           } else             dp[i][1] = dp[fir][0];         }       }     }     return dp[0][1];   }   int main() {     scanf( %d , &n);     scanf( %s , a);     bool unique = 1;     int p = -1;     int Max = 0, Min = oo;     int tot = 0, left = 0;     for (int i = (0), i_end_ = (n); i < i_end_; ++i)       if (a[i] ==  P ) {         if (~p) {           unique = 0;         } else {           left = tot;           p = i;         }       } else if (a[i] ==  * ) {         ++tot;         chkmin(Min, i), chkmax(Max, i);       }     if (unique) {       int right = tot - left;       int left_dis = p - Min;       int right_dis = Max - p;       auto tmp = max(make_pair(left, -left_dis), make_pair(right, -right_dis));       tmp.second = -tmp.second;       printf( %d %d n , tmp.first, tmp.second);     } else {       int l = 0, r = n;       while (l < r) {         int mid = (l + r) >> 1;         if (check(mid))           r = mid;         else           l = mid + 1;       }       printf( %d %d n , tot, l);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   int N, M, dp[MAXN], res = 0;   vector<pair<int, int>> adj[MAXN];   int check(int v) {     if (dp[v]) return dp[v];     dp[v] = 1;     for (auto p : adj[v]) {       int n = p.first;       if (check(n) + 1 > dp[v]) {         dp[v] = dp[n] + 1;         res = max(res, p.second);       }     }     return dp[v];   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < M; i++) {       int a, b;       scanf( %d%d , &a, &b);       a -= 1, b -= 1;       adj[a].push_back({b, i + 1});     }     for (int i = 0; i < N; i++) {       if (check(i) == N) {         printf( %d , res);         return 0;       }     }     printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   template <typename T>   using V = std::vector<T>;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int main() {     int n, m, k;     scanf( %d , &n), scanf( %d , &m), scanf( %d , &k);     int d = gcd(n, k);     int n1 = n / d;     k /= d;     d = gcd(m, k);     int m1 = m / d;     k /= d;     if (k > 2) {       puts( NO );       return 0;     }     puts( YES );     if (k == 1) {       if (n1 * 2 <= n)         n1 *= 2;       else         m1 *= 2;     }     printf( 0 0 n0 %d n%d 0 n , m1, n1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     pair<string, string> arr[n];     for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second;     for (int i = 0; i < n; i++)       if (arr[i].second ==  rat ) cout << arr[i].first << endl;     for (int i = 0; i < n; i++)       if (arr[i].second ==  woman  || arr[i].second ==  child )         cout << arr[i].first << endl;     for (int i = 0; i < n; i++)       if (arr[i].second ==  man ) cout << arr[i].first << endl;     for (int i = 0; i < n; i++)       if (arr[i].second ==  captain ) cout << arr[i].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::map<long long, long long> factors;   void primeFactors(long long n) {     while (n % 2 == 0) {       factors[2]++;       n = n / 2;     }     for (long long i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         factors[i]++;         n = n / i;       }     }     if (n > 2) factors[n]++;   }   long long i, j;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long ans = 0;     for (i = 2; i <= n; i++) {       long long x = n / (i);       ans += (i) * (x - 1);     }     cout << ans * 4 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 21], *p1 = buf, *p2 = buf;   inline long long qread() {     register char c =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     register long long x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c - 48;       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     return x * f;   }   inline long long Abs(const long long& x) { return (x > 0 ? x : -x); }   inline long long Max(const long long& x, const long long& y) {     return (x > y ? x : y);   }   inline long long Min(const long long& x, const long long& y) {     return (x < y ? x : y);   }   long long n, l, wmax;   vector<long long> ml, mr;   inline long long Div(long long x, long long y) {     if (!y) {       if (x > 0)         return 2147483647;       else         return -2147483647;     }     if (x % y < 0) x -= (y + x % y);     return x / y;   }   inline void Read() {     n = qread();     l = qread();     wmax = qread();     for (register long long i = 1; i <= n; i++) {       register long long x = qread(), v = qread();       if (v == 1)         mr.push_back(x);       else         ml.push_back(x);     }   }   inline void Solve() {     register long long siz = ml.size();     register long long ans = 0;     for (register long long i = 0; i < siz; i++) {       auto lmost = lower_bound(mr.begin(), mr.end(), -ml[i] - l);       ans += upper_bound(                  mr.begin(), lmost,                  Min(Div((ml[i] + l) * (wmax + 1) - 1, wmax - 1), -ml[i] - l)) -              mr.begin();       ans +=           upper_bound(lmost, mr.end(),                       Min(Div((ml[i] + l) * (wmax - 1) - 1, wmax + 1), ml[i])) -           lmost;     }     printf( %lld , ans);   }   signed main() {     Read();     sort(ml.begin(), ml.end());     sort(mr.begin(), mr.end());     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   struct Node {     long long val[4], len;     Node() {       memset(val, 0, sizeof(val));       len = 0;     }   };   vector<Node> tree;   long long n, m;   string s;   long long ch[100];   long long choice(long long i, long long j = -1) {     long long res = s[i] -  0 ;     if (~j) res = res * 10 + s[j] -  0 ;     return ch[res];   }   Node join(Node &left, Node &right, long long l, long long r) {     Node res;     long long na = left.len == 1 ? 0 : 1;     long long nb = right.len == 1 ? 0 : 2;     res.len = left.len + right.len;     res.val[0] = left.val[na] * right.val[nb] % mod;     res.val[1] = left.val[na] * right.val[3] % mod;     res.val[2] = left.val[3] * right.val[nb] % mod;     res.val[3] = left.val[3] * right.val[3] % mod;     if (s[l] ==  1 ) {       na = left.len == 1 ? 2 : 0;       nb = right.len == 1 ? 1 : 0;       res.val[na + nb] += left.val[0] * right.val[0] % mod * choice(l, r) % mod;       res.val[na + 1] += left.val[0] * right.val[1] % mod * choice(l, r) % mod;       res.val[2 + nb] += left.val[2] * right.val[0] % mod * choice(l, r) % mod;       res.val[3] += left.val[2] * right.val[1] % mod * choice(l, r) % mod;     }     for (long long i = 0; i < 4; ++i) res.val[i] %= mod;     return res;   }   void build(long long node = 1, long long start = 0, long long end = n - 1) {     tree[node].len = end - start + 1;     if (start == end) {       tree[node].val[0] = 1;       tree[node].val[3] = s[start] -  0  + 1;       return;     }     long long mid = start + end >> 1;     build(node << 1, start, mid);     build(node << 1 | 1, mid + 1, end);     tree[node] = join(tree[node << 1], tree[node << 1 | 1], mid, mid + 1);   }   void update(long long id, long long val, long long node = 1,               long long start = 0, long long end = n - 1) {     if (start == end) {       s[id] = char(val +  0 );       tree[node].val[3] = val + 1;       return;     }     long long mid = start + end >> 1;     if (id <= mid)       update(id, val, node << 1, start, mid);     else       update(id, val, node << 1 | 1, mid + 1, end);     tree[node] = join(tree[node << 1], tree[node << 1 | 1], mid, mid + 1);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (long long i = 0; i <= 9; ++i) {       for (long long j = 0; j <= 9; ++j) ch[i + j]++;     }     cin >> n >> m;     cin >> s;     tree.resize((n + 10) << 2);     build();     while (m--) {       long long id, x;       cin >> id >> x;       id--;       update(id, x);       cout << tree[1].val[3] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     map<int, vector<int> > pos;     map<int, int> result;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (pos.find(t) == pos.end()) {         vector<int> temp;         temp.push_back(i + 1);         pos.insert(pair<int, vector<int> >(t, temp));       } else {         pos[t].push_back(i + 1);       }     }     for (map<int, vector<int> >::iterator iter = pos.begin(); iter != pos.end();          iter++) {       int len = iter->second.size();       if (len == 1) {         result.insert(pair<int, int>(iter->first, 0));         continue;       }       int count = 2;       int diff = iter->second[1] - iter->second[0];       for (int i = 1; i < len - 1; i++) {         if (diff != iter->second[i + 1] - iter->second[i]) break;         count++;       }       if (count == len) result.insert(pair<int, int>(iter->first, diff));     }     cout << result.size() << endl;     for (map<int, int>::iterator iter = result.begin(); iter != result.end();          iter++)       cout << iter->first <<     << iter->second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int trees(vector<vector<int> >& v, int a, int b, int y, int x) {     int trees = 0;     for (int i = y; i < (y + a); ++i) {       for (int j = x; j < (x + b); ++j) {         trees += v[i][j];       }     }     return trees;   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > v(n);     int totTree = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         int tmp;         cin >> tmp;         v[i].push_back(tmp);         totTree += tmp;       }     }     int a, b;     cin >> a >> b;     int minTree = totTree;     for (int i = 0; i + a - 1 < n; ++i) {       for (int j = 0; j + b - 1 < m; ++j) {         const int tr = trees(v, a, b, i, j);         if (tr < minTree) {           minTree = tr;         }       }     }     for (int i = 0; i + b - 1 < n; ++i) {       for (int j = 0; j + a - 1 < m; ++j) {         const int tr = trees(v, b, a, i, j);         if (tr < minTree) {           minTree = tr;         }       }     }     cout << minTree << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, inv2 = mod + 1 >> 1;   inline void add(int &a, int b) { (a += b) >= mod && (a -= mod); }   inline int Add(int a, int b) { return add(a, b), a; }   inline void sub(int &a, int b) { (a -= b) < 0 && (a += mod); }   inline int Sub(int a, int b) { return sub(a, b), a; }   inline void mul(int &a, int b) { a = 1ll * a * b % mod; }   inline int Mul(int a, int b) { return 1ll * a * b % mod; }   const int N = 40, M = 1 << 20;   int m, n, S, f[N][M], g[M], siz[M], x[M], y[M], res[M], ans[N];   long long b[M];   inline void XOR(int *a, int n, bool rev) {     for (int k = 2, m = 1; k <= n; k <<= 1, m <<= 1) {       for (int j = 0; j < n; j += k)         for (int i = 0; i < m; ++i) {           int x = a[j + i], y = a[j + i + m];           if (!rev) {             a[j + i] = Add(x, y);             a[j + i + m] = Sub(x, y);           } else {             a[j + i] = Mul(Add(x, y), inv2);             a[j + i + m] = Mul(Sub(x, y), inv2);           }         }     }   }   inline void FWT(int *a, int *b, int n) {     memcpy(x, a, sizeof(x)), memcpy(y, b, sizeof(y));     XOR(x, n, 0), XOR(y, n, 0);     for (int i = 0; i < n; ++i) res[i] = Mul(x[i], y[i]);     XOR(res, n, 1);   }   void dfs1(long long x, int y) {     if (y == m) return ++g[x], void();     dfs1(x, y + 1);     if (b[y]) dfs1(x ^ b[y], y + 1);   }   void dfs2(long long x, int y) {     if (y == n) return ++f[siz[x >> m]][x & (S - 1)], void();     dfs2(x, y + 1);     if (b[y]) dfs2(x ^ b[y], y + 1);   }   int main() {     scanf( %d%d , &m, &n);     int tot = 1;     for (int i = 1; i <= m; ++i) {       long long x;       scanf( %lld , &x), mul(tot, 2);       for (int k = n - 1; ~k; --k)         if (x >> k & 1) {           if (!b[k]) {             b[k] = x;             mul(tot, inv2);             break;           }           x ^= b[k];         }     }     m = n + 1 >> 1, S = 1 << m;     for (int i = 0; i < S; ++i) siz[i] = siz[i >> 1] + (i & 1);     dfs1(0, 0), dfs2(0, m);     for (int i = 0; i <= n - m; ++i) {       FWT(f[i], g, S);       for (int s = 0; s < S; ++s) add(ans[i + siz[s]], res[s]);     }     for (int i = 0; i <= n; ++i) printf( %d  , Mul(ans[i], tot));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[1005];   int a[1005], b[1005];   char s[1005];   vector<int> c, d;   int main() {     cin >> s + 1;     int len = strlen(s + 1);     int num = 0;     for (int i = 1; i <= len; i++) {       if (s[i] ==  ( ) {         a[i]++;         c.push_back(i);       }       a[i] += a[i - 1];     }     for (int i = len; i; i--) {       if (s[i] ==  ) ) {         d.push_back(i);         b[i]++;       }       b[i] += b[i - 1];     }     sort((d).begin(), (d).end());     int l = 0, r = d.size() - 1;     while (l < c.size() && r >= 0 && c[l] < d[r]) {       l++;       r--;       num++;     }     if (!num)       puts( 0 );     else {       puts( 1 );       cout << l + d.size() - r - 1 << endl;       for (int i = 0; i < l; i++) cout << c[i] <<    ;       for (int i = r + 1; i < d.size(); i++) cout << d[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long a, b, n, m;       cin >> a >> b >> n >> m;       if (a + b < n + m) {         cout <<  no               <<   n ;       } else {         long long v1 = min(a, b);         long long v2 = max(a, b);         if (v1 >= m) {           cout <<  yes                 <<   n ;         } else {           cout <<  no                 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int n;   char str[250000];   int main() {     while (~scanf( %d , &n)) {       scanf( %s , str);       int len = strlen(str);       int sum1 = 0, sum2 = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  < ) {           sum1++;         } else {           break;         }       }       for (int i = len - 1; i >= 0; i--) {         if (str[i] ==  > ) {           sum2++;         } else {           break;         }       }       printf( %d n , sum1 + sum2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100009;   unsigned long long a[MaxN], b[MaxN], c[MaxN];   int main() {     unsigned long long n, ans = 0, p, sum = 0, sum2 = 0;     cin >> n >> p;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       sum += a[i];       b[i] = sum % p;     }     for (int i = n - 1; i >= 0; i--) {       sum2 += a[i];       c[i] = sum2 % p;     }     for (int i = 0; i < n; i++) ans = max(ans, (b[i] + c[i + 1]));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   const long long MOD = 1e9 + 7;   long long n_bits(long long n) {     long long x = __builtin_popcount(n);     return x;   }   int pow(int a, int b, int m) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       int n, p;       cin >> n >> p;       long long sum = 0;       int a[n];       long long left = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       long long final = (sum - a[n - 1]) % p + a[n - 1] % p;       sum -= a[n - 1];       left = a[n - 1];       for (int i = n - 2; i > 0; i--) {         left += a[i];         sum -= a[i];         final = max(final, left % p + sum % p);       }       cout << final;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t, class u>   void chmax(t& first, u second) {     if (first < second) first = second;   }   template <class t, class u>   void chmin(t& first, u second) {     if (second < first) first = second;   }   template <class t>   using vc = vector<t>;   template <class t>   using vvc = vc<vc<t>>;   using pi = pair<ll, ll>;   using vi = vc<ll>;   template <class t, class u>   ostream& operator<<(ostream& os, const pair<t, u>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <class t>   ostream& operator<<(ostream& os, const vc<t>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   using uint = unsigned;   using ull = unsigned long long;   template <class t, size_t n>   ostream& operator<<(ostream& os, const array<t, n>& first) {     return os << vc<t>(first.begin(), first.end());   }   template <ll i, class T>   void print_tuple(ostream&, const T&) {}   template <ll i, class T, class H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <class... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   template <class t>   void print(t x, ll suc = 1) {     cout << x;     if (suc == 1) cout <<   n ;     if (suc == 2) cout <<    ;   }   ll read() {     ll i;     cin >> i;     return i;   }   vi readvi(ll n, ll off = 0) {     vi v(n);     for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;     return v;   }   template <class T>   void print(const vector<T>& v, ll suc = 1) {     for (ll i = ll(0); i < ll(v.size()); i++)       print(v[i], i == ll(v.size()) - 1 ? suc : 2);   }   string readString() {     string s;     cin >> s;     return s;   }   template <class T>   T sq(const T& t) {     return t * t;   }   void yes(bool ex = true) {     cout <<  Yes           <<   n ;     if (ex) exit(0);   }   void no(bool ex = true) {     cout <<  No           <<   n ;     if (ex) exit(0);   }   void possible(bool ex = true) {     cout <<  Possible           <<   n ;     if (ex) exit(0);   }   void impossible(bool ex = true) {     cout <<  Impossible           <<   n ;     if (ex) exit(0);   }   constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }   const ll infLL = LLONG_MAX / 3;   const ll inf = infLL;   ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }   ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }   ll popcount(signed t) { return __builtin_popcount(t); }   ll popcount(ll t) { return __builtin_popcountll(t); }   bool ispow2(ll i) { return i && (i & -i) == i; }   ll mask(ll i) { return (ll(1) << i) - 1; }   bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }   template <class t>   void mkuni(vc<t>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   ll rand_int(ll l, ll r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<ll>(l, r)(gen);   }   template <class t>   void myshuffle(vc<t>& first) {     for (ll i = ll(0); i < ll(ll(first.size())); i++)       swap(first[i], first[rand_int(0, i)]);   }   template <class t>   ll lwb(const vc<t>& v, const t& first) {     return lower_bound(v.begin(), v.end(), first) - v.begin();   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed << setprecision(20);     ll n, m;     cin >> n >> m;     vi lv = readvi(n, -1);     vi cost = readvi(n);     vi c = readvi(n + m);     void(0);     vvc<ll> dp(m);     for (ll i = ll(0); i < ll(n); i++) dp[lv[i]].push_back(-inf);     {       ll pre = 0;       for (ll i = ll(0); i < ll(m); i++) {         pre >>= 1;         pre += ll(dp[i].size());         if (ll(dp[i].size())) dp[i].resize(pre, -inf);       }     }     ll ans = 0;     for (ll i = ll(n) - 1; i >= ll(0); i--) {       for (ll j = ll(ll(dp[lv[i]].size()) - 1) - 1; j >= ll(0); j--)         chmax(dp[lv[i]][j + 1], dp[lv[i]][j] - cost[i]);       chmax(dp[lv[i]][0], -cost[i]);       for (ll j = ll(0); j < ll(lv[i]); j++) {         ll ad = 0;         for (ll k = ll(0); k < ll(ll(dp[j].size())); k++) {           ll u = popcount(k ^ (k + 1));           for (ll l = ll(0); l < ll(min(u, lv[i] - j)); l++) ad += c[j + l];           void(0);           void(0);           chmax(dp[lv[i]][(k + 1) >> min(ll(60), lv[i] - j)],                 dp[j][k] + ad - cost[i]);         }       }     }     void(0);     for (ll i = ll(0); i < ll(m); i++)       for (ll j = ll(0); j < ll(ll(dp[i].size())); j++) {         ll cur = i, cnt = j + 1;         ll val = dp[i][j];         void(0);         while (cnt) {           val += c[cur] * cnt;           cur++;           cnt >>= 1;         }         if (val == 7) {           void(0);           void(0);         }         chmax(ans, val);       }     print(ans);   }


#include <bits/stdc++.h>   using namespace std;   string s;   int x, y, len, a, b;   int main() {     cin >> s;     len = s.length();     for (int i = 0; i < len; ++i) {       if (s[i] ==  ( )         ++x;       else if (s[i] ==  ) )         --x;       else if (s[i] ==  # )         --x, ++y;       if (x < 0) {         puts( -1 );         exit(0);       }     }     for (int i = 0; i < len; ++i) {       if (s[i] ==  # ) {         ++a;         if (a == y) b -= x;         --b;       }       if (s[i] ==  ( )         ++b;       else if (s[i] ==  ) )         --b;       if (b < 0) {         puts( -1 );         exit(0);       }     }     for (int i = 1; i < y; ++i) puts( 1 );     printf( %d , x + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[105][105];   int sum[2][105];   bool inv[2][105];   int main() {     while (scanf( %d%d , &n, &m) == 2) {       memset(inv, false, sizeof(inv));       memset(sum, 0, sizeof(sum));       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           scanf( %d , a[i] + j);           sum[0][i] += a[i][j];           sum[1][j] += a[i][j];         }       }       while (1) {         int idx = -1;         for (int i = 0; i < n; i++) {           if (sum[0][i] < 0) {             idx = i;             break;           }         }         if (idx != -1) {           inv[0][idx] ^= 1;           sum[0][idx] = -sum[0][idx];           for (int i = 0; i < m; i++) {             sum[1][i] -= a[idx][i];             a[idx][i] = -a[idx][i];             sum[1][i] += a[idx][i];           }           continue;         }         for (int i = 0; i < m; i++) {           if (sum[1][i] < 0) {             idx = i;             break;           }         }         if (idx != -1) {           inv[1][idx] ^= 1;           sum[1][idx] = -sum[1][idx];           for (int i = 0; i < n; i++) {             sum[0][i] -= a[i][idx];             a[i][idx] = -a[i][idx];             sum[0][i] += a[i][idx];           }           continue;         }         break;       }       int cnt = 0;       for (int i = 0; i < n; i++)         if (inv[0][i]) cnt++;       printf( %d , cnt);       for (int i = 0; i < n; i++)         if (inv[0][i]) printf(  %d , i + 1);       printf(  n );       cnt = 0;       for (int i = 0; i < m; i++)         if (inv[1][i]) cnt++;       printf( %d , cnt);       for (int i = 0; i < m; i++)         if (inv[1][i]) printf(  %d , i + 1);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long INF = 8e18;   const int maxn = 2e5 + 5;   int n, k, cnt;   int a[maxn], b[maxn], p[maxn], fp[maxn], num[maxn];   vector<int> zz[maxn];   inline void init() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       ++num[x];     }     for (int i = 1; i <= k; ++i) {       int x;       cin >> x;       if (!p[x]) p[x] = ++cnt, fp[cnt] = x;       a[cnt] += num[i];       while (num[i]--) zz[cnt].push_back(i);     }     for (int i = 1; i <= cnt; ++i) b[i] = fp[i] - fp[i + 1];     int x = 0;     for (int i = cnt; i >= 1; --i) {       if (!a[i])         x += b[i];       else         b[i] += x, x = 0;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     init();     vector<vector<int> > ans;     vector<pair<int, int> > now, last;     for (int i = cnt; i >= 1; --i) {       if (!a[i]) continue;       last.push_back({i, a[i]});     }     while (!last.empty()) {       int val = 0, z = 0;       vector<int> res;       for (auto &x : last) {         int id = x.first, w = x.second;         val += b[id];         b[id] += z;         int mi = min(x.second, val);         w -= mi;         val -= mi;         while (mi--) res.push_back(id);         if (w)           now.push_back({id, w}), z = 0;         else           z = b[id];       }       ans.push_back(res);       last = now;       now.clear();     }     cout << ans.size() <<   n ;     for (auto &x : ans) {       cout << x.size() <<    ;       for (auto y : x) {         cout << zz[y].back() <<    ;         zz[y].pop_back();       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char BUFFER[100000 + 5];   bool readn(int &n) { return scanf( %d , &n) == 1; }   bool readl(long long &n) { return scanf( %I64d , &n) == 1; }   bool readd(double &n) { return scanf( %lf , &n) == 1; }   bool reads(string &s) {     s =   ;     int n = scanf( %s , BUFFER);     if (n == 1) s = BUFFER;     return n == 1;   }   bool readln(string &s) {     char *valid = gets(BUFFER);     if (valid) s = BUFFER;     return ((bool)valid);   }   int Print(long long a, long long b) {     cout << a <<     << b;     return 0;   }   void update(long long &su, long long n, long long mod) {     su *= n;     su %= mod;   }   int doit(long long n, long long mod) {     long long su = 1;     int i;     for (i = 1; i < n; i++) {       su *= 10;       su %= mod;     }     update(su, 3, mod);     update(su, 3, mod);     update(su, 5, mod);     update(su, 2, mod);     update(su, 3, mod);     update(su, 3, mod);     su++;     su %= mod;     long long a = 1, b = 1;     for (i = 0; i < n; i++) b *= 10;     if (0 == su) return Print(a, b);     su = mod - su;     return Print(a + su, b + su);   }   int main() {     long long a;     cin >> a;     doit(18, a);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long double PI = 4 * atan(1);   int n, r, val[2001], x, flag, ch[2001];   bool isChild[2001][2001];   pair<int, int> p[2001];   vector<int> v[2001];   queue<int> q1, q2, ans;   void solve(int i) {     int rem = ch[i] - p[i].second;     while (ans.size()) {       x = ans.front();       if (isChild[i][x]) {         if (rem > 0) {           val[x]++;           q2.push(x);         } else {           if (rem == 0) {             q2.push(i);             val[i] = val[x] + 1;           }           q2.push(x);         }         rem--;       } else {         q1.push(x);       }       ans.pop();     }     if (rem == 0 || !q2.size()) {       q2.push(i);       val[i] = 1;     }     while (q1.size() && q2.size()) {       if (val[q1.front()] >= val[q2.front()]) {         ans.push(q1.front());         q1.pop();       } else {         ans.push(q2.front());         q2.pop();       }     }     while (q1.size()) {       ans.push(q1.front());       q1.pop();     }     while (q2.size()) {       ans.push(q2.front());       q2.pop();     }   }   void dfs(int i, int p) {     for (int a : v[i]) {       if (a != p) {         dfs(a, i);       }     }     solve(i);     return;   }   void calc(int par, int i, int p) {     ch[par]++;     isChild[par][i] = true;     for (int a : v[i]) {       if (a != p) {         calc(par, a, i);       }     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> p[i].first >> p[i].second;       if (p[i].first != 0)         v[p[i].first].push_back(i);       else         r = i;     }     for (int i = 1; i < n + 1; i++) calc(i, i, p[i].first), ch[i]--;     for (int i = 1; i < n + 1; i++) {       if (p[i].second > ch[i]) {         cout <<  NO ;         return 0;       }     }     dfs(r, 0);     cout <<  YES n ;     for (int i = 1; i < n + 1; i++) cout << val[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50000 + 10;   struct query {     int type, x, y;   } qu[maxn];   int n, fa[maxn];   long long val[maxn], sz[maxn];   vector<int> v[maxn];   bool mark[maxn], have[maxn];   long long d[maxn];   int dfs(int x) {     sz[x] = 1;     int ret = 0;     for (auto i : v[x]) ret += dfs(i), sz[x] += sz[i];     for (auto i : v[x]) d[i] = (sz[x] - sz[i]) * val[x];     have[x] = ((ret || mark[x]) ? 1 : 0);     if (ret >= 2 || mark[x]) {       mark[x] = 1;       return 1;     } else       return ret;   }   struct P {     int to, ssum;     long long dsum;   };   vector<P> v2[maxn];   int fa2[maxn];   long long sz2[maxn], sz2sum[maxn];   long long pnum[maxn];   bool leaf[maxn];   void dfs2(int x, bool isfir = 0) {     if (v2[x].empty()) {       if (!isfir) return;       pnum[x] = sz[x] * sz[x];       for (auto i : v[x]) pnum[x] -= sz[i] * sz[i];       return;     }     sz[x] = 1 + sz2[x];     pnum[x] = 0;     for (auto i : v2[x])       dfs2(i.to, isfir), sz[x] += sz[i.to] + i.ssum,           pnum[x] -= (sz[i.to] + i.ssum) * (sz[i.to] + i.ssum);     pnum[x] += sz[x] * sz[x] - sz2sum[x];   }   int getid(int x, int y) {     for (int i = 0;; i++)       if (v2[x][i].to == y) return i;   }   void build_graph(int num) {     fill(mark, mark + n + 1, 0);     fill(have, have + n + 1, 0);     fill(leaf, leaf + n + 1, 1);     for (int i = 1; i <= n; i++) v[i].clear(), v2[i].clear();     for (int i = 2; i <= n; i++) v[fa[i]].push_back(i);     for (int i = 0; i < num; i++) {       mark[qu[i].x] = 1;       if (qu[i].type == 1) mark[qu[i].y] = 1;     }     mark[1] = 1;     dfs(1);     for (int i = 1; i <= n; i++)       if (mark[i]) {         sz2[i] = sz2sum[i] = 0;         for (auto j : v[i])           if (!have[j]) sz2[i] += sz[j], sz2sum[i] += sz[j] * sz[j];         if (i == 1) continue;         int j, ssum = 0;         long long dsum = 0LL;         for (j = i;; j = fa[j]) {           dsum += d[j];           if (mark[fa[j]]) break;         }         ssum = sz[j] - sz[i];         j = fa[j];         v2[j].push_back((P){i, ssum, dsum});         fa2[i] = j;         leaf[j] = 0;       }   }   bool first = 1;   void process(int num) {     build_graph(num);     long long nowans = 0LL, tot = (long long)n * n;     for (int i = 1; i <= n; i++) {       long long add = sz[i] * sz[i];       for (auto j : v[i]) add -= sz[j] * sz[j];       nowans += add * val[i];     }     if (first) printf( %.15f n , ((double)nowans) / tot), first = 0;     dfs2(1, 1);     for (int i = 0; i < num; i++) {       if (qu[i].type == 2) {         int x = qu[i].x, nval = qu[i].y;         nowans += pnum[x] * (nval - val[x]);         for (auto &j : v2[x])           j.dsum += (sz[x] - j.ssum - sz[j.to]) * (nval - val[x]);         val[x] = nval;         printf( %.15f n , ((double)nowans) / tot);         continue;       }       int x = qu[i].y, y = qu[i].x, id;       for (int j = x; j != 1; j = fa2[j])         if (j == y || y == 1) {           swap(x, y);           break;         }       fa[y] = x;       long long dif = 0LL;       for (int j = y; j != 1; j = fa2[j]) {         sz[fa2[j]] -= sz[y];         for (auto &k : v2[fa2[j]])           if (k.to != j)             k.dsum -= val[fa2[j]] * sz[y];           else             dif -= k.dsum;       }       int f = fa2[y];       id = getid(f, y);       sz2[f] += v2[f][id].ssum;       sz2sum[f] += (long long)v2[f][id].ssum * v2[f][id].ssum;       swap(v2[f][id], v2[f][v2[f].size() - 1]);       v2[f].pop_back();       v2[x].push_back((P){y, 0, val[x] * sz[x]});       fa2[y] = x;       if (v2[f].empty()) pnum[f] = sz[f] * sz[f] - sz2sum[f];       for (int j = y; j != 1; j = fa2[j]) {         sz[fa2[j]] += sz[y];         for (auto &k : v2[fa2[j]])           if (k.to != j)             k.dsum += val[fa2[j]] * sz[y];           else             dif += k.dsum;       }       nowans += 2 * dif * sz[y];       printf( %.15f n , ((double)nowans) / tot);       dfs2(1);     }   }   int main() {     scanf( %d , &n);     fa[1] = 1;     for (int i = 2; i <= n; i++) scanf( %d , &fa[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &val[i]);     int Q;     scanf( %d , &Q);     int sq = (int)sqrt(Q + 0.5);     for (int i = 0; i < Q; i++) {       char c[5];       scanf( %s%d%d , c, &qu[i % sq].x, &qu[i % sq].y);       qu[i % sq].type = (c[0] ==  P  ? 1 : 2);       if ((i % sq) == sq - 1 || i == Q - 1) process(i % sq + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, s;     scanf( %lld , &a);     a = a - 2;     if (a % 3 == 0) {       printf( 1 2 %lld , a - 1);     } else       printf( 1 1 %lld , a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int findGCD(int arr[], int n) {     int result = arr[0];     for (int i = 1; i < n; i++) {       result = gcd(arr[i], result);     }     return result;   }   void swap(int* a, int* b) {     int t = *a;     *a = *b;     *b = t;   }   void merge(int arr[], int l, int m, int r) {     int i, j, k;     int n1 = m - l + 1;     int n2 = r - m;     int L[n1], R[n2];     for (i = 0; i < n1; i++) {       L[i] = arr[l + i];     }     for (j = 0; j < n2; j++) {       R[j] = arr[m + 1 + j];     }     i = 0;     j = 0;     k = l;     while (i < n1 && j < n2) {       if (L[i] <= R[j]) {         arr[k] = L[i];         i++;       } else {         arr[k] = R[j];         j++;       }       k++;     }     while (i < n1) {       arr[k] = L[i];       i++;       k++;     }     while (j < n2) {       arr[k] = R[j];       j++;       k++;     }   }   void mergeSort(int arr[], int l, int r) {     if (l < r) {       int m = l + (r - l) / 2;       mergeSort(arr, l, m);       mergeSort(arr, m + 1, r);       merge(arr, l, m, r);     }   }   int main() {     int n, i, gcd, pointsToBeAdded = 0;     cin >> n;     int arr[n];     int differences[n - 1];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     mergeSort(arr, 0, n - 1);     for (i = 1; i < n; i++) {       differences[i - 1] = arr[i] - arr[i - 1];     }     gcd = findGCD(differences, n - 1);     for (i = 0; i < n - 1; i++) {       differences[i] /= gcd;       pointsToBeAdded += differences[i] - 1;     }     cout << pointsToBeAdded;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   using f64 = double;   using f80 = long double;   using pii = pair<int, int>;   using ptx = pair<f64, f64>;   const int N = 105;   bool f[N][N];   int n, m, first, second;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int tip = 1;     int a, b;     cin >> n >> m;     cin >> first >> second;     cout << first <<     << second <<   n ;     f[first][second] = true;     for (int j = 1; j <= m; ++j) {       if (!f[first][j]) {         cout << first <<     << j <<   n ;         f[first][j] = true;         a = first, b = j;       }     }     tip = -1;     for (int i = 1; i <= n; ++i)       if (!f[i][m] && !f[i][1]) {         for (a = i; true; b += tip) {           cout << a <<     << b <<   n ;           f[a][b] = true;           if (!(1 <= b + tip && b + tip <= m)) break;         }         tip *= -1;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[1003][1003], row[1003], col[1003];   int main() {     scanf( %d%d%d , &n, &m, &k);     int i, j;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (i = 0; i <= n; i++) row[i] = i;     for (i = 0; i <= m; i++) col[i] = i;     char s;     int x, y;     for (i = 0; i < k; i++) {       scanf(  n%c %d %d , &s, &x, &y);       if (s ==  g ) printf( %d n , a[row[x]][col[y]]);       if (s ==  c ) {         j = col[x];         col[x] = col[y];         col[y] = j;       }       if (s ==  r ) {         j = row[x];         row[x] = row[y];         row[y] = j;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long r(long long a) {     long long i = 0;     while (a % 2 == 0) {       a /= 2;       ++i;     }     return i;   }   void one_case() {     long long a, b;     cin >> a >> b;     auto ra = r(a);     auto rb = r(b);     a /= (1ll << ra);     b /= (1ll << rb);     if (a != b) {       cout <<  -1 n ;       return;     }     cout << (abs(ra - rb) + 2) / 3 <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int t = 1;     cin >> t;     while (t--) {       one_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int high[500005], ata[500005], cost[500005], par[500005], der[500005];   long long ans;   vector<int> v[500005];   int n, k, m, x, y, z;   vector<pair<int, pair<int, int> > > e;   int bul(int node, int ar[]) {     if (node == ar[node]) return node;     return ar[node] = bul(ar[node], ar);   }   void update(int a, int b, int cst) {     a = bul(a, high);     b = bul(b, high);     while (a != b) {       if (der[a] < der[b]) swap(a, b);       cost[a] = cst;       a = high[a] = bul(par[a], high);     }   }   void dfs(int node, int ata) {     par[node] = ata;     der[node] = der[ata] + 1;     for (int i : v[node])       if (i != ata) dfs(i, node);   }   int main() {     scanf( %d %d %d , &n, &k, &m);     for (int i = 1; i <= n; i++) ata[i] = i;     for (int i = 1; i <= k; i++) {       scanf( %d %d , &x, &y);       ata[bul(x, ata)] = bul(y, ata);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &x, &y, &z);       e.push_back({z, {x, y}});     }     sort(e.begin(), e.end());     for (int i = 0; i < m; i++) {       pair<int, pair<int, int> > edge = e[i];       if (bul(edge.second.first, ata) != bul(edge.second.second, ata)) {         v[edge.second.first].push_back(edge.second.second);         v[edge.second.second].push_back(edge.second.first);         ata[ata[edge.second.first]] = ata[edge.second.second];         ans -= edge.first;       }     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       high[i] = i;       cost[i] = 2000000000;     }     for (int i = 0; i < m; i++) {       pair<int, pair<int, int> > edge = e[i];       update(edge.second.first, edge.second.second, edge.first);     }     for (int i = 2; i <= n; i++) {       if (cost[i] == 2000000000) {         printf( -1 );         return 0;       }       ans += cost[i];     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int64_t inf = 1e18;   vector<vector<int64_t> > adj;   int64_t inp() {     int64_t x;     cin >> x;     return x;   }   vector<int64_t> level;   int64_t res = 0;   void dfs(int64_t u, int64_t LV = 0) {     level[u] = LV;     res = max(res, LV);     for (auto v : adj[u]) {       dfs(v, LV + 1);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int64_t _ = (1); _ >= (1); _--) {       int64_t n;       cin >> n;       adj.resize(n + 1);       level.resize(n + 1);       for (int64_t node = (1); node <= (n); node++)         adj[max(inp(), int64_t(0))].push_back(node);       dfs(0);       cout << res;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long po(long long a, long long x, long long m) {     if (x == 0) {       return 1;     }     long long ans = 1;     long long k = 1;     while (k <= x) {       if (x & k) {         ans = ((ans * a) % m);       }       k <<= 1;       a *= a;       a %= m;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string a, b;       cin >> a >> b;       bool f[n + 1][2];       for (long long i = 0; i < n; i++) {         if (a[i] ==  1  || a[i] ==  2 )           f[i][0] = false;         else           f[i][0] = true;         if (b[i] ==  1  || b[i] ==  2 )           f[i][1] = false;         else           f[i][1] = true;       }       long long bll = 0;       bool flag = true;       bool k = false;       for (long long i = 0; i < n; i++) {         if (i != n && !f[i][bll]) {           continue;         }         if (i != n && (f[i][0] && !f[i][1]) || (f[i][1] && !f[i][0])) {           flag = false;           break;         }         bll ^= 1;       }       if (flag && bll == 1)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 200100;   int N, M;   char S[MX];   int A[MX];   struct Segment {     int a, b, c, d, e;     int z, l, r;     void add(int x) { a += x, b += x, c -= x, d -= x, z += x; }   } T[MX << 2];   inline void PushUp(int i) {     Segment &t = T[i], &x = T[(i << 1)], &y = T[(i << 1 | 1)];     t.a = max(x.a, y.a);     t.b = min(x.b, y.b);     t.c = max(max(x.c, y.c), x.a - 2 * y.b);     t.d = max(max(x.d, y.d), y.a - 2 * x.b);     t.e = max(max(x.e, y.e), max(x.c + y.a, x.a + y.d));   }   inline void PushDown(int i) {     if (T[i].z) T[(i << 1)].add(T[i].z), T[(i << 1 | 1)].add(T[i].z), T[i].z = 0;   }   void Build(int i, int l, int r) {     T[i].l = l, T[i].r = r;     if (l == r) {       T[i].a = T[i].b = A[l], T[i].c = T[i].d = -A[l];       return;     }     int m = (l + r) >> 1;     Build((i << 1), l, m), Build((i << 1 | 1), m + 1, r);     PushUp(i);   }   void Add(int i, int a, int b, int x) {     if (a <= T[i].l && T[i].r <= b) {       T[i].add(x);       return;     }     PushDown(i);     if (a <= T[(i << 1)].r) Add((i << 1), a, b, x);     if (b >= T[(i << 1 | 1)].l) Add((i << 1 | 1), a, b, x);     PushUp(i);   }   int main() {     int n;     scanf( %d%d%s , &n, &M, S + 1), N = strlen(S + 1);     for (int i = (1); i <= (N); ++i) A[i] = A[i - 1] + (S[i] ==  (  ? 1 : -1);     Build(1, 0, N);     printf( %d n , T[1].e);     for (int i = (1); i <= (M); ++i) {       int l, r;       scanf( %d%d , &l, &r);       if (l > r) swap(l, r);       if (S[l] != S[r]) Add(1, l, r - 1, S[l] ==  (  ? -2 : 2), swap(S[l], S[r]);       printf( %d n , T[1].e);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   int a[maxn];   int n, l, t;   int main() {     scanf( %d%d%d , &n, &l, &t);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     double ans = 0;     int k = 2 * t / l, c = 2 * t % l;     for (int i = 0; i < n; i++) {       int w = a[i] - c;       int cnt = 0;       if (w >= 0) {         cnt = i - (lower_bound(a, a + n, w) - a);       } else {         cnt += i;         cnt += n - (lower_bound(a, a + n, l + w) - a);       }       ans += 0.5 * 0.5 * k * (n - 1) + 0.5 * 0.5 * cnt;     }     cout.setf(ios::fixed);     cout << setprecision(9) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > dist(51, vector<int>(3, 100));   int n, m;   int dp[51][8];   void calc_s(int i, string &s) {     for (int j = 0; j < s.length(); j++) {       if (s[j] ==  #  || s[j] ==  *  || s[j] ==  & ) {         dist[i][2] = min(dist[i][2], j);         dist[i][2] = min(dist[i][2], m - j);       } else if (s[j] >=  a  && s[j] <=  z ) {         dist[i][0] = min(dist[i][0], j);         dist[i][0] = min(dist[i][0], m - j);       } else if (s[j] >=  0  && s[j] <=  9 ) {         dist[i][1] = min(dist[i][1], j);         dist[i][1] = min(dist[i][1], m - j);       }     }   }   int calc(int i, int j) {     if (j == 7) return 0;     if (i == (n + 1)) return 100;     if (dp[i][j] != -1) return dp[i][j];     int x = 100;     for (int k = 0; k < 3; k++) {       x = min(x, dist[i][k] + calc(i + 1, (j | (1 << k))));     }     dp[i][j] = x;     return dp[i][j];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       calc_s(i, s);     }     memset(dp, -1, sizeof(dp));     cout << calc(1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b, int p = 1000000007) { return ((a % p) * (b % p)) % p; }   int multbig(int a, int b, int mod) {     if (a == 0 or b == 0) return 0;     if (a == 1 or b == 1) return (a * b) % mod;     int cur = multbig(a, b / 2, mod);     cur = (2 * cur) % mod;     if (b % 2) cur = (cur + a) % mod;     return cur;   }   int add(int a, int b, int p = 1000000007) { return (a % p + b % p) % p; }   int fpow(int n, int k, int p = 1000000007) {     int r = 1;     for (; k; k >>= 1LL) {       if (k & 1LL) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   int inv(int a, int p = 1000000007) { return fpow(a, p - 2, p); }   int inv_euclid(int a, int m = 1000000007) {     int m0 = m;     int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       int q = a / m;       int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   vector<pair<int, int>> vvv;   pair<int, int> aa[200003];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)m; i++) {       int p, q;       cin >> p >> q;       if (p > q) {         swap(p, q);       }       aa[i].first = p;       aa[i].second = q;       vvv.push_back(make_pair(p, q));     }     sort(vvv.begin(), vvv.end());     int f = 0;     for (int i = 2; i <= n; i++) {       if (n % i == 0) {         int lol = n / i;         vector<pair<int, int>> vv;         for (int i = 0; i < (int)m; i++) {           int p = aa[i].first + lol;           int q = aa[i].second + lol;           if (p > n) {             p = p - n;           }           if (q > n) {             q = q - n;           }           if (p > q) {             swap(p, q);           }           vv.push_back(make_pair(p, q));         }         sort(vv.begin(), vv.end());         if (vv == vvv) {           f = 1;           break;         }       }     }     if (f) {       cout <<  Yes n ;     } else       cout <<  No n ;   }


#include <bits/stdc++.h>   using namespace std;   void dice() {     int x, y;     cin >> x >> y;     x = max(x, y);     vector<string> str;     str = { 1/6 ,  1/3 ,  1/2 ,  2/3 ,  5/6 ,  1/1 };     x = 6 - x + 1;     cout << str[x - 1] << endl;   }   int main() { dice(); }