#include <bits/stdc++.h>   using namespace std;   int n, ta;   long double x[1005][1005], tb, tc, td;   vector<int> y;   vector<long double> z;   bool used[1005];   int main() {     scanf( %d , &n);     for (int a = 0; a < n; a++)       for (int b = 0; b < n; b++) {         scanf( %d , &ta);         x[a][b] = ta;         x[a][b] /= 100;       }     y.push_back(n - 1);     z.push_back(0);     used[n - 1] = 1;     while (y.back() != 0) {       ta = -1;       for (int a = 0; a < n; a++)         if (!used[a]) {           tb = 0;           tc = 1;           for (int b = 0; b < y.size(); b++) {             tb += (z[b] + 1) * tc * x[a][y[b]];             tc *= 1 - x[a][y[b]];           }           if (abs(tc - 1) < 1e-11) continue;           tb = (tb + tc) / (1 - tc);           if (ta == -1 || tb < td) {             ta = a;             td = tb;           }         }       y.push_back(ta);       z.push_back(td);       for (int a = z.size() - 1; a >= 1; a--) {         if (z[a] >= z[a - 1]) break;         swap(z[a], z[a - 1]);         swap(y[a], y[a - 1]);       }       used[ta] = 1;     }     printf( %.15lf n , (double)z.back());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, n, m, a, b, tmp;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     cin >> n >> m >> a >> b;     tmp = n * m / gcd(n, m);     cout << b / tmp - (a - 1) / tmp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   vector<int> gr[N];   int ans = 0;   void dfs(int v, int p = -1) {     for (int to : gr[v])       if (to != p) {         dfs(to, v);         ans += (gr[to].size() - 1);       }     ans += ((gr[v].size() - (v != 1)) * (gr[v].size() - 1 - (v != 1))) / 2;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       gr[a].push_back(b);       gr[b].push_back(a);     }     dfs(1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using u64 = uint64_t;   using u32 = uint32_t;   struct Node {     int idx;     Node *left = nullptr, *right = nullptr;   };   int depth(Node* v) {     if (!v) return 0;     return max(depth(v->left), depth(v->right)) + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n);     for (auto& ai : a) cin >> ai;     auto it = min_element(begin(a), end(a));     int orig_shift = (n - (it - begin(a))) % n;     rotate(begin(a), it, end(a));     int left = 0, right = n;     vector<int> b(n);     vector<Node> nodes(n);     for (int i = 0; i < n; ++i) nodes[i].idx = i;     vector<Node*> stack;     int mind = n;     while (right - left > 1) {       for (auto& node : nodes) node.left = node.right = nullptr;       stack.clear();       int mid = (left + right) / 2;       int start = (n - mid) % n;       for (int i = start; i < n + start; ++i) {         Node* left = nullptr;         while (!stack.empty() && a[stack.back()->idx] > a[i % n]) {           left = stack.back();           stack.pop_back();         }         if (!stack.empty()) stack.back()->right = &nodes[i % n];         if (right) nodes[i % n].left = left;         stack.push_back(&nodes[i % n]);       }       Node* root = stack.front();       auto ldepth = depth(root->left);       auto rdepth = depth(root->right);       mind = min(mind, max(ldepth, rdepth) + 1);       if (ldepth == rdepth) {         cout << (ldepth + 1) <<     << ((n - mid - orig_shift + n) % n) <<   n ;         return 0;       } else if (ldepth > rdepth) {         right = mid;       } else {         left = mid;       }     }     cout << mind <<     << ((n - left - orig_shift + n) % n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   int main()   {          fastIO       int t;       cin>>t;       while(t--)       {           int x,y;           cin>>x>>y;              if (x==y)                cout<<x+y<<  n ;           else                 cout<<max(x,y)*2-1<<  n ;          }                                                }


#include <bits/stdc++.h>   using namespace std;   const int M = 500005;   int n, m, q;   struct Edge {     Edge() {}     Edge(int u_, int v_) : u(u_), v(v_) {}     int u, v;     bool operator<(const Edge &a) const {       if (v != a.v) return v < a.v;       return u > a.u;     }   } edge[M << 1];   int fa[M];   int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }   struct BIT {     int C[M];     void init() { memset(C, 0, n + 1 << 2); }     void update(int x, int f) {       for (; x; x -= x & -x) C[x] += f;     }     int query(int x) {       int res = 0;       for (; x <= n; x += x & -x) res += C[x];       return res;     }   } bit;   struct LCT {     static const int N = M * 3;     int fa[N], c[N][2], v[N], mn[N];     char rev[N];     void init() {       for (int i = 0; i <= n + m; i++) {         c[i][0] = c[i][1] = fa[i] = 0;         v[i] = (1 << 30);         mn[i] = i;       }     }     bool isroot(int x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; }     int cmp(int x, int y) { return v[x] < v[y] ? x : y; }     void up(int x) { mn[x] = cmp(cmp(mn[c[x][0]], mn[c[x][1]]), x); }     int query(int x, int y) {       makeroot(x);       access(y);       splay(y);       return mn[y];     }     void rotate(int x) {       int y = fa[x], z = fa[y], l, r;       if (c[y][0] == x)         l = 0;       else         l = 1;       r = l ^ 1;       if (!isroot(y)) {         if (c[z][0] == y)           c[z][0] = x;         else           c[z][1] = x;       }       fa[x] = z;       fa[y] = x;       fa[c[x][r]] = y;       c[y][l] = c[x][r];       c[x][r] = y;       up(y);     }     int q[N];     void down(int x) {       if (rev[x]) {         rev[c[x][0]] ^= 1;         rev[c[x][1]] ^= 1;         swap(c[x][0], c[x][1]);         rev[x] = 0;       }     }     void splay(int x) {       int top = 0;       q[++top] = x;       for (int i = x; !isroot(i); i = fa[i]) q[++top] = fa[i];       for (int i = top; i >= 1; i--) down(q[i]);       while (!isroot(x)) {         int y = fa[x], z = fa[y];         if (!isroot(y)) {           if (c[z][0] == y ^ c[y][0] == x)             rotate(x);           else             rotate(y);         }         rotate(x);       }       up(x);     }     void makeroot(int x) {       access(x);       splay(x);       rev[x] ^= 1;     }     void access(int x) {       for (int t = 0; x; t = x, x = fa[x]) {         splay(x);         c[x][1] = t;         up(x);       }     }     void cut(int x, int y) {       makeroot(x);       access(y);       splay(y);       c[y][0] = fa[x] = 0;     }     void link(int x, int y) {       makeroot(x);       fa[x] = y;     }   } lct;   int last[M], allc;   struct Query {     int to, l, nxt;   } que[M];   void ins(int l, int r, int id) {     que[allc].l = l;     que[allc].to = id;     que[allc].nxt = last[r];     last[r] = allc++;   }   int ans[M];   void solve() {     scanf( %d , &m);     int tmp = 0;     for (int u, v, i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       if (u == v) continue;       if (u > v) swap(u, v);       edge[++tmp] = Edge(u, v);     }     m = tmp;     sort(edge + 1, edge + m + 1);     for (int i = 1; i <= n; i++) fa[i] = i;     bit.init();     lct.init();     memset(last, -1, n + 1 << 2);     allc = 0;     scanf( %d , &q);     for (int l, r, i = 1; i <= q; i++) {       scanf( %d%d , &l, &r);       ins(l, r, i);     }     int pre = 1;     for (int i = 1; i <= n; i++) {       for (; pre <= m && edge[pre].v == i; pre++) {         int u = edge[pre].u, v = edge[pre].v;         if (get(u) == get(v)) {           int id = lct.query(u, v);           id -= n;           if (edge[id].u >= u) continue;           lct.cut(edge[id].u, id + n);           lct.cut(edge[id].v, id + n);           bit.update(edge[id].u, -1);           lct.v[pre + n] = u;           lct.link(u, pre + n);           lct.link(v, pre + n);           bit.update(u, 1);         } else {           lct.v[pre + n] = u;           lct.link(u, pre + n);           lct.link(v, pre + n);           bit.update(u, 1);           fa[get(u)] = get(v);         }       }       for (int j = last[i]; j != -1; j = que[j].nxt) {         int l = que[j].l, to = que[j].to;         ans[to] = (i - l + 1) - bit.query(l);       }     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);   }   int main() {     while (~scanf( %d%d , &n, &m)) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void print(char pt) { printf( %c n , pt); }   inline void print(int pt) { printf( %d n , pt); }   inline void print(long long pt) { printf( %I64d n , pt); }   inline void print(double pt) { printf( %.20f n , pt); }   inline void print(char pt[]) { printf( %s n , pt); }   inline void print() { printf(  n ); }   inline int scan(int &pt) { return scanf( %d , &pt); }   inline int scan(char &pt) { return scanf( %c , &pt); }   inline int scan(long long &pt) { return scanf( %I64d , &pt); }   inline int scan(double &pt) { return scanf( %lf , &pt); }   inline int scan(char pt[]) { return scanf( %s , pt); }   long long moda = 109098827479487ll;   using namespace std;   int n, k, m;   char stra[1000];   int a[300000];   int c[300000];   int main() {     scan(n);     int maxai = 0;     long long sums = 0;     for (int i = 0; i < n; i++) {       scan(a[i]);       sums += a[i];       c[a[i]]++;       maxai = max(a[i], maxai);     }     int maxn = min(maxai + 1, 200001);     for (int i = 1; i <= maxn; i++) {       c[i] += c[i - 1];     }     sort(a, a + n);     long long suma = 0;     long long maxa = 0;     for (int i = 0; i < n; i++) {       if (suma >= sums - maxa) break;       suma += a[i];       if (i && a[i] == a[i] - 1) {         continue;       }       long long nowa = 0;       for (int j = 1, tj = a[i];; j++, tj += a[i]) {         if (tj + a[i] - 1 >= maxn) {           nowa += 1ll * j * (c[maxn] - c[tj - 1]);           break;         }         nowa += 1ll * j * (c[tj + a[i] - 1] - c[tj - 1]);       }       nowa *= a[i];       maxa = max(maxa, nowa);     }     print(maxa);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   struct edge {     int v, nxt;   } g[N];   int tot = 0, head[N];   inline void add(int u, int v) {     g[++tot] = edge{v, head[u]};     head[u] = tot;   }   int n, m, fa[N], sz[N], son[N], top[N], dfn[N], tpos[N], dep[N], cnt = 0;   inline void dfs2(int u, int tp) {     dfn[++cnt] = u;     tpos[u] = cnt;     top[u] = tp;     if (son[u]) dfs2(son[u], tp);     for (int i = head[u]; i; i = g[i].nxt)       if (g[i].v != son[u]) dfs2(g[i].v, g[i].v);   }   int tree[N << 2], mx[N << 2], cov[N << 2];   inline void pushup(int o) {     tree[o] = tree[o << 1] + tree[o << 1 | 1];     mx[o] = max(mx[o << 1 | 1], max(mx[o << 1], 0) + tree[o << 1 | 1]);   }   inline void pushdown(int o, int l, int r) {     if (cov[o]) {       cov[o << 1] = cov[o << 1 | 1] = 1;       int mid = (l + r) >> 1;       tree[o << 1] = -(mid - l + 1);       tree[o << 1 | 1] = -(r - mid);       mx[o << 1] = mx[o << 1 | 1] = -1;       cov[o] = 0;     }   }   inline void update(int p, int o, int l, int r, int x) {     if (l == r) return (void)(tree[o] = mx[o] = x - 1);     int mid = (l + r) >> 1;     pushdown(o, l, r);     mid >= p ? update(p, o << 1, l, mid, x)              : update(p, o << 1 | 1, mid + 1, r, x);     pushup(o);   }   inline void upd(int xl, int xr, int o, int l, int r) {     if (xl <= l && r <= xr)       return (void)(cov[o] = 1, tree[o] = -(r - l + 1), mx[o] = -1);     int mid = (l + r) >> 1;     pushdown(o, l, r);     if (mid >= xl) upd(xl, xr, o << 1, l, mid);     if (mid < xr) upd(xl, xr, o << 1 | 1, mid + 1, r);     pushup(o);   }   struct node {     int tree, mx;   };   inline node operator+(node x, node y) {     node ans;     ans.tree = x.tree + y.tree;     ans.mx = max(y.mx, x.mx + y.tree);     return ans;   }   inline node query(int xl, int xr, int o, int l, int r) {     if (xl <= l && r <= xr) return (node){tree[o], mx[o]};     int mid = (l + r) >> 1;     pushdown(o, l, r);     if (mid >= xl && mid < xr)       return query(xl, xr, o << 1, l, mid) +              query(xl, xr, o << 1 | 1, mid + 1, r);     else if (mid >= xl)       return query(xl, xr, o << 1, l, mid);     else       return query(xl, xr, o << 1 | 1, mid + 1, r);   }   inline node qtree(int u, int v) {     if (!v) return (node){0, 0};     node ans;     bool b = 0;     while (top[u] ^ top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       if (b)         ans = query(tpos[top[u]], tpos[u], 1, 1, n) + ans;       else         ans = query(tpos[top[u]], tpos[u], 1, 1, n), b = 1;       u = fa[top[u]];     }     if (dep[u] < dep[v]) swap(u, v);     if (b)       ans = query(tpos[v], tpos[u], 1, 1, n) + ans;     else       ans = query(tpos[v], tpos[u], 1, 1, n), b = 1;     return ans;   }   inline void build(int o, int l, int r) {     if (l == r) return (void)(tree[o] = mx[o] = -1);     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     pushup(o);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; ++i) scanf( %d , &fa[i]), add(fa[i], i);     for (int i = n; i >= 1; --i) {       ++sz[i];       sz[fa[i]] += sz[i];       if (sz[i] > sz[son[fa[i]]]) son[fa[i]] = i;     }     for (int i = 1; i <= n; ++i) dep[i] = dep[fa[i]] + 1;     dfs2(1, 1);     build(1, 1, n);     while (m--) {       int t, v;       scanf( %d%d , &t, &v);       if (t == 1) {         node x = query(tpos[v], tpos[v], 1, 1, n);         update(tpos[v], 1, 1, n, x.tree + 2);       } else if (t == 2) {         node x = qtree(1, fa[v]);         upd(tpos[v], tpos[v] + sz[v] - 1, 1, 1, n);         update(tpos[v], 1, 1, n, min(-x.mx, 0));       } else if (t == 3) {         node ans = qtree(1, v);         puts(ans.mx >= 0 ?  black  :  white );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   string s, ans;   bool f, at;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s;     int n = s.size();     f = at = false;     for (int i = 0; i < n; i++) {       if (i < n - 3 && s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t ) {         if (f) {           ans +=  . ;           i += 2;         } else {           ans += s[i];           f = true;         }       } else if (i < n - 2 && s[i] ==  a  && s[i + 1] ==  t ) {         if (!at && f) {           ans +=  @ ;           i++;           at = true;         } else {           ans += s[i];         }       } else {         if (!f) f = true;         ans += s[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2e5 + 5;   int A[Nmax], start[Nmax];   long long cnt[Nmax];   bool cycle[Nmax];   int go[Nmax], where[Nmax], visited[Nmax];   vector<int> active[Nmax], when[Nmax];   int zz[Nmax], ans[Nmax];   int nrcomp, n, q, Nr;   vector<int> cyc[Nmax];   vector<int> query1[Nmax], query2[Nmax], to[Nmax];   int level[Nmax], L[Nmax], R[Nmax], Size[Nmax];   vector<int> cc[Nmax];   class AIB {     int a[Nmax];     int ub(int x) { return (x & (-x)); }     int query(int pos) {       int ans = 0;       for (; pos; pos -= ub(pos)) ans += a[pos];       return ans;     }       public:     void upd(int pos, int add) {       for (; pos <= Nr; pos += ub(pos)) a[pos] += add;     }     int query(int L, int R) {       assert(1 <= L && L <= R && R <= Nr);       return query(R) - query(L - 1);     }   } aib;   void dfs0(int node) {     visited[node] = 3;     where[node] = nrcomp;     cc[nrcomp].push_back(node);     L[node] = ++Nr;     for (auto it : to[node])       if (!cycle[it]) {         go[it] = go[node];         level[it] = level[node] + 1;         dfs0(it);       }     R[node] = Nr;   }   void find_comp(int root) {     int node = root;     vector<int> nodes;     while (!visited[node]) {       visited[node] = 1;       nodes.push_back(node);       node = A[node];     }     bool ww = 0;     for (auto it : nodes) {       if (it == node) ww = 1;       if (ww) ++Size[nrcomp], cycle[it] = 1;     }     for (auto it : nodes)       if (cycle[it]) cyc[nrcomp].push_back(it);     int i;     for (i = 0; i < cyc[nrcomp].size(); ++i) {       level[cyc[nrcomp][i]] = 0;       go[cyc[nrcomp][i]] = i;       dfs0(cyc[nrcomp][i]);     }   }   void find_graph() {     int i;     for (i = 1; i <= n; ++i)       if (!visited[i]) {         ++nrcomp;         find_comp(i);       }   }   void solve1(int id) {     for (auto node : cc[id]) active[level[node]].push_back(go[node]);     sort(query1[id].begin(), query1[id].end(),          [](int x, int y) { return cnt[x] < cnt[y]; });     if (id == 2) {     }     int i;     int j = 0, k;     for (i = 0; i < query1[id].size(); ++i) {       while (j < cc[id].size() && j <= cnt[query1[id][i]]) {         for (auto it : active[j]) {           int md = ((it - j) % Size[id] + Size[id]) % Size[id];           zz[md]++;         }         ++j;       }       int tmp =           (((long long)go[start[query1[id][i]]] - cnt[query1[id][i]]) % Size[id] +            Size[id]) %           Size[id];       ans[query1[id][i]] = zz[tmp];     }     for (i = 0; i < cc[id].size(); ++i) zz[i] = 0, active[i].clear();   }   void solve2(int id) {     for (auto it : query2[id])       if (level[start[it]] + cnt[it] < (long long)cc[id].size())         when[level[start[it]] + cnt[it]].push_back(it);     for (auto it : cc[id]) active[level[it]].push_back(L[it]);     int i;     for (i = 0; i < cc[id].size(); ++i) {       for (auto it : active[i]) aib.upd(it, 1);       for (auto it : when[i]) ans[it] = aib.query(L[start[it]], R[start[it]]);       for (auto it : active[i]) aib.upd(it, -1);     }     for (i = 0; i < cc[id].size(); ++i) active[i].clear(), when[i].clear();   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int i;     cin >> n;     for (i = 1; i <= n; ++i) cin >> A[i], to[A[i]].push_back(i);     cin >> q;     for (i = 1; i <= q; ++i) cin >> cnt[i] >> start[i];     find_graph();     for (i = 1; i <= q; ++i)       if (cycle[start[i]])         query1[where[start[i]]].push_back(i);       else         query2[where[start[i]]].push_back(i);     for (i = 1; i <= nrcomp; ++i) solve1(i);     for (i = 1; i <= nrcomp; ++i) solve2(i);     for (i = 1; i <= q; ++i) cout << ans[i] <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int,int>;      #define ff first   #define se second   #define pb push_back   #define all(x) (x).begin(),(x).end()      const int mod = 1e9+7;   const int inf = 1e9;   const int mx  = 1e6+5;      #define exitYes {cout<< Yes n ; return;}   #define exitNo  {cout<< No n ;  return;}      bool can(vector<ll> a){       for(int i=1; i<a.size(); i++){           if(a[i-1] > a[i]) return false;           a[i] -= a[i-1]; a[i-1] = 0;       }return (a.back() == 0);   }      void solve(int cs){   //    cout <<  Case   << cs <<  :  ;       int n; cin >> n;       vector<ll> v(n);       for(auto &u:v) cin >> u;          if(can(v)) exitYes       if(n == 1) exitNo          swap(v[0], v[1]);       if(can(v)) exitYes swap(v[0],v[1]);       swap(v[n-1], v[n-2]);   if(can(v)) exitYes swap(v[n-1], v[n-2]);          vector<ll> p(n), s(n), b = v;          p[0] = b[0];       for(int i=1; i<n; i++){           if(p[i-1]==-1 || b[i-1]>b[i]) p[i]=-1;           else b[i]-=b[i-1], b[i-1]=0, p[i]=b[i];       }b = v;          s[n-1] = b[n-1];       for(int i=n-2; i>=0; i--){           if(s[i+1]==-1 || b[i+1]>b[i]) s[i]=-1;           else b[i]-=b[i+1], b[i+1]=0, s[i]=b[i];       }          for(int i=1; i+2<n; i++){           if(p[i-1] == -1 || s[i+2]==-1) continue;           vector<ll> c = {p[i-1], v[i], v[i+1], s[i+2]};           swap(c[1], c[2]); if(can(c)) exitYes       }exitNo   }      int main(){          ios_base::sync_with_stdio(false);       cin.tie(nullptr); cout.tie(nullptr);          int tc = 1, cs = 1;       cin >> tc;       while(tc--) solve(cs++);          return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pr {     int type;     int k;     char dir;   };   struct point {     long long first;     long long second;   };   bool cmp(const point &a, const point &b) {     return sqrt(a.first * a.first + a.second * a.second) <            sqrt(b.first * b.first + b.second * b.second);   }   int main() {     int n;     cin >> n;     vector<point> cnt;     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       point ty;       ty.first = x;       ty.second = y;       cnt.push_back(ty);     }     sort(cnt.begin(), cnt.end(), cmp);     int ans = 0;     vector<pr> t;     for (int i = 0; i < n; i++) {       int x = cnt[i].first;       int y = cnt[i].second;       if (x == 0) {         ans += 4;         pr tt;         tt.type = 1;         tt.k = abs(y);         if (y > 0) {           tt.dir =  U ;         } else {           tt.dir =  D ;         }         t.push_back(tt);         tt.type = 2;         t.push_back(tt);         tt.type = 1;         tt.k = abs(y);         if (y > 0) {           tt.dir =  D ;         } else {           tt.dir =  U ;         }         t.push_back(tt);         tt.type = 3;         t.push_back(tt);       } else if (y == 0) {         ans += 4;         pr tt;         tt.type = 1;         tt.k = abs(x);         if (x > 0) {           tt.dir =  R ;         } else {           tt.dir =  L ;         }         t.push_back(tt);         tt.type = 2;         t.push_back(tt);         tt.type = 1;         tt.k = abs(x);         if (x > 0) {           tt.dir =  L ;         } else {           tt.dir =  R ;         }         t.push_back(tt);         tt.type = 3;         t.push_back(tt);       } else {         ans += 6;         if (x > 0 && y > 0) {           pr tt;           tt.type = 1;           tt.k = abs(x);           tt.dir =  R ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  U ;           t.push_back(tt);           tt.type = 2;           t.push_back(tt);           tt.type = 1;           tt.k = abs(x);           tt.dir =  L ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  D ;           t.push_back(tt);           tt.type = 3;           t.push_back(tt);         } else if (x > 0 && y < 0) {           pr tt;           tt.type = 1;           tt.k = abs(x);           tt.dir =  R ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  D ;           t.push_back(tt);           tt.type = 2;           t.push_back(tt);           tt.type = 1;           tt.k = abs(x);           tt.dir =  L ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  U ;           t.push_back(tt);           tt.type = 3;           t.push_back(tt);         } else if (x < 0 && y > 0) {           pr tt;           tt.type = 1;           tt.k = abs(x);           tt.dir =  L ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  U ;           t.push_back(tt);           tt.type = 2;           t.push_back(tt);           tt.type = 1;           tt.k = abs(x);           tt.dir =  R ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  D ;           t.push_back(tt);           tt.type = 3;           t.push_back(tt);         } else if (x < 0 && y < 0) {           pr tt;           tt.type = 1;           tt.k = abs(x);           tt.dir =  L ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  D ;           t.push_back(tt);           tt.type = 2;           t.push_back(tt);           tt.type = 1;           tt.k = abs(x);           tt.dir =  R ;           t.push_back(tt);           tt.type = 1;           tt.k = abs(y);           tt.dir =  U ;           t.push_back(tt);           tt.type = 3;           t.push_back(tt);         }       }     }     cout << ans << endl;     for (int i = 0; i < t.size(); i++) {       if (t[i].type == 1) {         printf( %d %d %c n , t[i].type, t[i].k, t[i].dir);       } else {         printf( %d n , t[i].type);       }     }     return 0;   }


#include<iostream>   using namespace std;   int main()   {    ios_base::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);    int a;    cin >> a;    cout << 2-a*a;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 303000;   int n, m, head[N], to[N], nxt[N], val[N], edgenum = 1;   inline void add(int u, int v, int w) {     to[++edgenum] = v;     val[edgenum] = w;     nxt[edgenum] = head[u];     head[u] = edgenum;   }   struct Gauss {     int v[32];     inline void add(int x) {       for (int i = 30; i >= 0; i--)         if ((x >> i) & 1)           if (!v[i]) {             v[i] = x;             break;           } else             x ^= v[i];     }     inline int query(int x) {       for (int i = 30; i >= 0; i--) x = (x ^ v[i]) < x ? x ^ v[i] : x;       return x;     }   } gauss;   int vis[N], tree[N], v[N];   inline void dfs(int u, int Val) {     vis[u] = 1;     v[u] = Val;     for (int i = head[u]; i != 0; i = nxt[i])       if (!vis[to[i]]) {         tree[i >> 1] = 1;         dfs(to[i], Val ^ val[i]);       } else if (!tree[i >> 1]) {         gauss.add(v[to[i]] ^ v[u] ^ val[i]);       }   }   int main() {     read(n);     read(m);     for (int i = 1; i <= m; i++) {       int a, b, c;       read(a);       read(b);       read(c);       add(a, b, c);       add(b, a, c);     }     dfs(1, 0);     printf( %d , gauss.query(v[n]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > points;   vector<pair<long long, pair<long long, long long> > > areas;   map<long long, vector<long long> > pm;   int main() {     int n, m, k;     scanf( %i%i%i , &n, &m, &k);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %i%i , &x, &y);       points.push_back(pair<long long, long long>(x, y));     }     for (int i = 0; i < m; i++) {       int c1, c2, r;       scanf( %i%i%i , &r, &c1, &c2);       areas.push_back(pair<long long, pair<long long, long long> >(           r, pair<long long, long long>(c1, c2)));     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if ((points[i].first - areas[j].second.first) *                     (points[i].first - areas[j].second.first) +                 (points[i].second - areas[j].second.second) *                     (points[i].second - areas[j].second.second) <             areas[j].first * areas[j].first) {           pm[i].push_back(j);         }       }       sort(pm[i].begin(), pm[i].end());     }     for (int i = 0; i < k; i++) {       int a, b;       scanf( %i%i , &a, &b);       a -= 1;       b -= 1;       vector<long long> tmp1 = pm[a];       vector<long long> tmp2 = pm[b];       int p = 0;       int cnt = 0;       for (int i = 0; i < tmp1.size(); i++) {         while (p < tmp2.size() && tmp2[p] < tmp1[i]) {           cnt++;           p++;         }         if (p == tmp2.size() || tmp2[p] != tmp1[i]) {           cnt++;         }         if (p != tmp2.size() && tmp2[p] == tmp1[i]) {           p++;         }       }       printf( %i n , cnt + (tmp2.size() - p));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[5010], n;   int solve(int l, int r, int h) {     int i, j, k;     if (l > r) return 0;     int ans = 0, val = 1000000007;     for (i = l; i <= r; i++) val = min(val, arr[i]);     int pos = l - 1;     ans = val - h;     for (i = l; i <= r; i++) {       if (arr[i] == val) {         ans += solve(pos + 1, i - 1, val);         pos = i;       }     }     ans += solve(pos + 1, r, val);     return min(r - l + 1, ans);   }   int main(void) {     int i, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &arr[i]);     k = solve(1, n, 0);     printf( %d  , k);     printf(  n );     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, u, r;   vector<int> a, b, k, p;   long long s, current;   int lastChoice;   void input();   void solve();   void go(int k);   int main() {     input();     solve();   }   void input() {     cin >> n >> u >> r;     a.resize(n);     b.resize(n);     k.resize(n);     p.resize(n);     int val;     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       a[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       b[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       k[i] = val;     }     for (int i = 0; i <= n - 1; ++i) {       cin >> val;       p[i] = val - 1;     }   }   void solve() {     s = (long long)(-1e12);     lastChoice = 1;     go(1);     cout << s;   }   void go(int x) {     if ((x - 1) % 2 == u % 2) {       long long sum = 0;       for (int i = 0; i <= n - 1; ++i) sum += a[i] * k[i];       s = max(s, sum);     }     if (x >= u + 1) {       return;     }     vector<int> _a(n);     int _lastChoice = lastChoice;     for (int i = 0; i <= n - 1; ++i) _a[i] = a[i];     lastChoice = 1;     for (int i = 0; i <= n - 1; ++i) {       a[i] = _a[p[i]] + r;     }     go(x + 1);     for (int i = 0; i <= n - 1; ++i) a[i] = _a[i];     lastChoice = _lastChoice;     if (lastChoice == 0) {       return;     } else {       _lastChoice = lastChoice;       for (int i = 0; i <= n - 1; ++i) _a[i] = a[i];       lastChoice = 0;       for (int i = 0; i <= n - 1; ++i) {         a[i] = (_a[i] ^ b[i]);       }       go(x + 1);       lastChoice = _lastChoice;       for (int i = 0; i <= n - 1; ++i) a[i] = _a[i];     }   }


#include <bits/stdc++.h>   using namespace std;   int ans[3][1010], dp[3][1010][55][55];   int n, p, k, r, s, x;   int teto(int a, int b) { return (a + b - 1) / b; }   int main() {     while (scanf( %d %d %d , &n, &p, &k) != EOF) {       memset(ans, 0, sizeof(ans));       scanf( %d , &r);       for (int i = 0; i < r; i++) {         scanf( %d , &x);         x--;         ans[0][x] = 1;       }       scanf( %d , &s);       for (int i = 0; i < s; i++) {         scanf( %d , &x);         x--;         ans[1][x] = 1;       }       if (p >= 2 * teto(n, k)) {         int cnt = 0;         for (int i = 0; i < n; i++) {           if (ans[0][i] == 1 || ans[1][i] == 1) {             cnt++;           }         }         printf( %d n , cnt);         continue;       }       int A = min(n, k), B = min(n, k);       for (int pos = n; pos >= 0; pos--) {         int pos1 = pos % 2, pos2 = (pos + 1) % 2;         for (int used = 0; used <= p; used++) {           for (int a = 0; a <= A; a++) {             for (int b = 0; b <= B; b++) {               if (pos == n) {                 dp[pos1][used][a][b] = 0;               } else {                 int max_ =                     dp[pos2][used][max(a - 1, 0)][max(b - 1, 0)] +                     max((a >= 1) * (ans[0][pos]), (b >= 1) * (ans[1][pos]));                 if (used + 1 <= p) {                   max_ =                       max(max_, dp[pos2][used + 1][k - 1][max(0, b - 1)] +                                     max(ans[0][pos], (b >= 1) * (ans[1][pos])));                   max_ =                       max(max_, dp[pos2][used + 1][max(a - 1, 0)][k - 1] +                                     max((a >= 1) * (ans[0][pos]), ans[1][pos]));                 }                 if (used + 2 <= p) {                   max_ = max(max_, dp[pos2][used + 2][k - 1][k - 1]);                 }                 dp[pos1][used][a][b] = max_;               }             }           }         }       }       printf( %d n , dp[0][0][0][0]);     }     return 0;   }


#include <bits/stdc++.h>   const int N = 25, Mod = 1e6 + 3;   const int n = 11;   int y[N], k, inv[Mod + 2];   int fm[] = {404910, 950915, 220896, 410947, 30845, 962989,               30845,  410947, 220896, 950915, 404910};   inline int po(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = 1ll * r * x % Mod;       x = 1ll * x * x % Mod, y >>= 1;     }     return r;   }   int judge(int k) {     int ans = 0, base = 1;     for (int i = 1; i <= n; ++i)       if (k != i) base = 1ll * base * (k - i) % Mod;     if (1 <= k && k <= 11)       return (1ll * base * fm[k - 1] % Mod * y[k] % Mod + Mod) % Mod;     base = (base + Mod) % Mod;     for (int i = 1; i <= n; ++i)       ans = (ans + 1ll * base * inv[(k - i + Mod) % Mod] % Mod * fm[i - 1] % Mod *                        y[i] % Mod) %             Mod;     return ans;   }   int main() {     for (int i = 1; i <= n; ++i) {       printf( ? %d n , i);       fflush(stdout);       scanf( %d , &y[i]);     }     inv[0] = inv[1] = 1;     for (int i = 2; i < Mod; ++i)       inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;     for (int k = 0; k < Mod; ++k)       if (!judge(k)) {         printf( ! %d n , k);         fflush(stdout);         return 0;       }     printf( ! -1 n );     fflush(stdout);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   #pragma warning(disable : 4996 4018)   using namespace std;   long long n, k, p;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> k >> p;     if ((n & 1) && k) {       n--;       k--;     }     while (p--) {       long long nm;       cin >> nm;       if (nm > n) {         cout <<  X ;         continue;       }       if (!k) {         cout <<  . ;         continue;       }       if (nm & 1) {         if (k > n / 2) {           long long rest = k - n / 2;           long long nd = n / 2;           long long val = nd - (nm / 2.0) + 1;           if (val <= rest)             cout <<  X ;           else             cout <<  . ;         } else           cout <<  . ;       } else {         long long nd = n / 2;         long long val = nd - (nm / 2) + 1;         if (val <= k)           cout <<  X ;         else           cout <<  . ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e5 + 5;   long long n, q, a[maxn], c[maxn];   long long read() {     long long res = 0, f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (!isdigit(ch));     do {       res = res * 10 + ch -  0 ;       ch = getchar();     } while (isdigit(ch));     return res * f;   }   long long check(long long x) {     if (!x) return 0;     return x > 0 ? 1 : -1;   }   struct SegmentTree {     long long mxlen[maxn << 2], lmost[maxn << 2], ltype[maxn << 2],         rmost[maxn << 2], rtype[maxn << 2], len[maxn << 2];     void pushup(long long rt, long long l, long long r) {       long long ls = rt << 1, rs = rt << 1 | 1, mx = max(mxlen[ls], mxlen[rs]),                 mid = (l + r) >> 1;       ltype[rt] = ltype[ls];       rtype[rt] = rtype[rs];       mx = max(mx, lmost[ls]);       mx = max(mx, rmost[rs]);       if (rtype[ls] && ltype[rs] && rtype[ls] >= ltype[rs]) {         mx = max(mx, rmost[ls] + lmost[rs]);         if (lmost[ls] == len[ls])           lmost[rt] = lmost[ls] + lmost[rs];         else           lmost[rt] = lmost[ls];         if (rmost[rs] == len[rs])           rmost[rt] = rmost[ls] + rmost[rs];         else           rmost[rt] = rmost[rs];       } else         lmost[rt] = lmost[ls], rmost[rt] = rmost[rs];       mxlen[rt] = mx;     }     void build(long long rt, long long l, long long r) {       len[rt] = r - l + 1;       if (l == r) {         ltype[rt] = rtype[rt] = lmost[rt] = rmost[rt] = 0;         if (a[l]) mxlen[rt] = 1;         if (a[l] > 0) {           ltype[rt] = 1;           lmost[rt] = 1;           rtype[rt] = 1;           rmost[rt] = 1;         } else if (a[l] < 0) {           ltype[rt] = -1;           lmost[rt] = 1;           rtype[rt] = -1;           rmost[rt] = 1;         }         return;       }       long long mid = (l + r) >> 1;       build(rt << 1, l, mid);       build(rt << 1 | 1, mid + 1, r);       pushup(rt, l, r);     }     void update(long long rt, long long l, long long r, long long x,                 long long val) {       if (l == r) {         a[l] += val;         ltype[rt] = rtype[rt] = lmost[rt] = rmost[rt] = 0;         if (a[l]) mxlen[rt] = 1;         if (a[l] > 0) {           ltype[rt] = 1;           lmost[rt] = 1;           rtype[rt] = 1;           rmost[rt] = 1;         } else if (a[l] < 0) {           ltype[rt] = -1;           lmost[rt] = 1;           rtype[rt] = -1;           rmost[rt] = 1;         }         return;       }       long long mid = (l + r) >> 1;       if (x <= mid)         update(rt << 1, l, mid, x, val);       else         update(rt << 1 | 1, mid + 1, r, x, val);       pushup(rt, l, r);     }   } T;   signed main() {     n = read();     for (long long i = (1); i <= (n); ++i) c[i] = read();     if (n == 1) {       q = read();       while (q--) {         long long l = read(), r = read(), x = read();         puts( 1 );       }       return 0;     }     for (long long i = (1); i <= (n - 1); ++i) a[i] = c[i + 1] - c[i];     T.build(1, 1, n - 1);     q = read();     while (q--) {       long long l = read(), r = read(), x = read();       if (l - 1 >= 1) T.update(1, 1, n - 1, l - 1, x);       if (r + 1 <= n) T.update(1, 1, n - 1, r, -x);       printf( %d n , T.mxlen[1] + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 * 2 + 152;   long long n, m, x, y, z, q, mark[maxn], k = 1, par1[maxn], sum[maxn], h[maxn];   pair<long long, long long> par[17][maxn];   vector<pair<long long, long long> > v[maxn];   pair<long long, pair<long long, long long> > edg[maxn];   void dfs(int x) {     mark[x] = k;     for (int i = 0; i < v[x].size(); i++)       if (!mark[v[x][i].first]) {         sum[k] += v[x][i].second;         par[0][v[x][i].first] = make_pair(x, v[x][i].second);         h[v[x][i].first] = h[x] + 1;         dfs(v[x][i].first);       }   }   int find_par(int x) {     if (x == par1[x]) return x;     return par1[x] = find_par(par1[x]);   }   long long LCA(int x, int y) {     if (h[x] > h[y]) swap(x, y);     long long fa = h[y] - h[x], jack = 0, MAX = 0;     for (int i = 0; i < 17; i++)       if ((1 << i) & fa) {         MAX = max(MAX, par[i][y].second);         y = par[i][y].first;       }     for (int i = 16; i >= 0; i--)       if (par[i][x].first != par[i][y].first) {         MAX = max(MAX, max(par[i][x].second, par[i][y].second));         x = par[i][x].first;         y = par[i][y].first;       }     if (x != y) MAX = max(MAX, max(par[0][x].second, par[0][y].second));     return MAX;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++)       cin >> edg[i].second.first >> edg[i].second.second >> edg[i].first;     for (int i = 1; i <= n; i++) par1[i] = i;     sort(edg, edg + m);     for (int i = 0; i < m; i++) {       int x = find_par(edg[i].second.first), y = find_par(edg[i].second.second);       if (x == y) continue;       v[edg[i].second.first].push_back(           make_pair(edg[i].second.second, edg[i].first));       v[edg[i].second.second].push_back(           make_pair(edg[i].second.first, edg[i].first));       par1[x] = y;     }     for (int i = 1; i <= n; i++)       if (!mark[i]) {         dfs(i);         k++;       }     for (int i = 1; i < 17; i++)       for (int j = 1; j <= n; j++)         par[i][j] = make_pair(             par[i - 1][par[i - 1][j].first].first,             max(par[i - 1][j].second, par[i - 1][par[i - 1][j].first].second));     cin >> q;     while (q--) {       cin >> x >> y;       if (k > 3 || (k == 3 && mark[x] == mark[y])) {         cout << -1 << endl;         continue;       }       if (k == 3) {         cout << sum[1] + sum[2] << endl;         continue;       }       long long jack = LCA(x, y);       cout << sum[1] - jack << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e4 + 5, inf = 0x3f3f3f3f;   int n, front, x, ans = -inf, nxt;   vector<int> interact(int _) {     printf( ? %d n , _);     fflush(stdout);     int a, b;     scanf( %d%d , &a, &b);     return vector<int>({a, b});   }   void give(int _) {     printf( ! %d n , _);     fflush(stdout);   }   int seed, seed2;   void srand(int x, int y) {     seed = x;     seed2 = y;   }   int frand() { return (seed *= 19260817) += ((seed2 += 114514) ^= 1919810); }   int rand() {     int res = frand();     while (res <= 0) res += n;     return res;   }   int main() {     srand(998244353, 1000000007);     scanf( %d%d%d , &n, &front, &x);     nxt = front;     for (int(i) = (1); (i) <= (min(n, 1000) - 1); (i)++) {       int pos = rand() % n + 1;       vector<int> res = interact(pos);       if (res[0] <= x && res[0] > ans) nxt = res[1], ans = res[0];     }     if (ans == x) return give(x), 0;     for (int(i) = (1); (i) <= (1000); (i)++) {       if (nxt == -1) break;       vector<int> res = interact(nxt);       if (res[0] >= x) return give(res[0]), 0;       ans = res[0];       nxt = res[1];     }     give(ans >= x ? ans : -1);     return 0;     int lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;     lll = 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<int, int> p1, pair<int, int> p2) { return p2.second < p1.second; }   vector<pair<int, int> > k;   vector<pair<int, int> > c;   vector<pair<int, int> > ans;   int main() {     int n, v;     int t, p;     cin >> n >> v;     for (int i = 0; i < n; i++) {       cin >> t >> p;       if (t == 1) {         k.push_back(make_pair(i + 1, p));       } else {         c.push_back(make_pair(i + 1, p));       }     }     sort(k.begin(), k.end(), cmp);     sort(c.begin(), c.end(), cmp);     int cur = 0;     while (v > 1 && cur < c.size()) {       ans.push_back(c[cur]);       v -= 2;       cur++;     }     int last = ans.size() - 1;     int nowk = 0;     while (v > 0 && nowk < k.size()) {       ans.push_back(k[nowk]);       v -= 1;       nowk++;     }     for (; nowk < k.size() - 1 && last >= 0; nowk += 2) {       if (k[nowk].second + k[nowk + 1].second > ans[last].second) {         ans.erase(ans.begin() + last);         ans.push_back(k[nowk]);         ans.push_back(k[nowk + 1]);         last--;       }     }     if (last >= 0 && nowk == k.size() - 1) {       if (k[nowk].second > ans[last].second) {         ans.erase(ans.begin() + last);         ans.push_back(k[nowk]);         last--;       }     }     if (ans.size() > 0) {       int tot = 0;       for (int i = 0; i < ans.size(); i++) tot += ans[i].second;       cout << tot << endl << ans[0].first << endl;       for (int i = 1; i < ans.size(); i++) cout << ans[i].first <<    ;       cout << endl;     } else {       cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 6e5 + 5;   const long long mod = 10000000000000007;   const long long nary = 9;   long long a;   int ans[100], n;   int main() {     while (scanf( %d%I64d , &n, &a) != EOF) {       n = 0;       while (a > 0) {         int d = (int)(a % 10);         a /= (long long)10;         if (d == 9) {           d -= 2;           ans[++n] = 3;           ans[++n] = 3;           ans[++n] = 2;         }         if (d == 8) {           d--;           ans[++n] = 2;           ans[++n] = 2;           ans[++n] = 2;         }         if (d == 6) {           d--;           ans[++n] = 3;         }         if (d == 4) {           d--;           ans[++n] = 2;           ans[++n] = 2;         }         if (d > 1) ans[++n] = d;       }       sort(ans + 1, ans + n + 1);       for (int i = n; i > 0; i--) printf( %d , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool square(long long g) {     long long k = sqrt(g);     return k * k == g;   }   int main() {     int i, q, k;     long long l, r, val;     set<long long> s;     for (i = 2; i <= 1000000; i++) {       int op = 18.0 / log10(i);       val = 1LL * i * i;       for (k = 3; k <= op; k++) {         val *= i;         if (!square(val)) s.insert(val);       }     }     vector<long long> v(s.begin(), s.end());     cin >> q;     for (i = 0; i < q; i++) {       cin >> l >> r;       long long a = floor(sqrtl(r));       long long b = ceil(sqrtl(l));       long long res =           upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);       long long res1 = a - b + 1;       cout << res + res1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[5001], n;   int dfs(int l, int r) {     int Min = a[l], ans = 0;     for (int i = l + 1; i <= r; i++) Min = min(Min, a[i]);     ans = Min;     for (int i = l; i <= r; i++) a[i] -= Min;     for (int i = l; i <= r; i++)       if (a[i]) {         int tmp = i + 1;         while (tmp <= r && a[tmp]) ++tmp;         ans += dfs(i, tmp - 1);         i = tmp - 1;       }     return min(ans, r - l + 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     printf( %d n , dfs(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   double A[100001];   double dp[100001];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %lf , A + i);     double ans = 0.0;     for (int i = 1; i <= N; i++)       ans += A[i] + 2 * (dp[i] = (dp[i - 1] + A[i - 1]) * A[i]);     printf( %.9f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10, M = 2e5 + 10;   struct upd {     int r, s, t, id;   } t;   vector<upd> v[M];   struct edge {     int x, y;   } e[M];   int ans[M], n, m, qi, f[N][N];   signed main() {     int x;     scanf( %d %d %d , &n, &m, &qi);     for (register int i = (1); i <= (m); ++i) scanf( %d %d , &e[i].x, &e[i].y);     for (register int i = (1); i <= (qi); ++i)       scanf( %d %d %d %d , &x, &t.r, &t.s, &t.t), t.id = i, v[x].push_back(t);     int p = qi;     memset(f, 0x3f, sizeof(f));     for (register int i = (m); i >= (1); --i) {       int x = e[i].x, y = e[i].y;       f[x][y] = f[y][x] = i;       for (register int j = (1); j <= (n); ++j)         f[x][j] = min(f[x][j], f[y][j]), f[y][j] = min(f[y][j], f[x][j]);       int l = v[i].size() - 1;       for (register int j = (0); j <= (l); ++j)         ans[v[i][j].id] = (f[v[i][j].s][v[i][j].t] <= v[i][j].r);     }     for (register int i = (1); i <= (qi); ++i) printf(ans[i] ?  Yes n  :  No n );     return 0;   }


#include <bits/stdc++.h>   using uint = unsigned int;   using cat = long long;   using dbl = long double;   constexpr dbl pi = 3.14159265358979323846;   using namespace std;   cat pw(cat a, cat e, cat mod) {     if (e <= 0) return 1;     cat x = pw(a, e / 2, mod);     x = x * x % mod;     return (e & 1) ? x * a % mod : x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     int N;     cin >> N;     vector<int> A(N);     int S = 0;     for (int i = 0; i < N; i++) {       cin >> A[i];       S += A[i];     }     if (S == 1) {       cout <<  0 n ;       return 0;     }     cat mod = 998244353;     vector<cat> inv(S + 1, 1);     for (int i = 1; i <= S; i++) {       if (i > 2 && i % 2 == 0)         inv[i] = inv[i / 2] * inv[2] % mod;       else if (i > 3 && i % 3 == 0)         inv[i] = inv[i / 3] * inv[3] % mod;       else         inv[i] = pw(i, mod - 2, mod);     }     cat iN = pw(N - 1, mod - 2, mod);     vector<cat> E(S + 1, 0), E_lf_c(S + 1, 0), E_lf_a(S + 1, 0);     E_lf_a[1] = 1;     for (int i = 1; i < S; i++) {       cat c1 = i * iN % mod;       cat c2 = S - i + c1;       E_lf_a[i + 1] =           (c2 * E_lf_a[i] - c1 * E_lf_a[i - 1]) % mod * inv[S - i] % mod;       E_lf_c[i + 1] =           (c2 * E_lf_c[i] - c1 * E_lf_c[i - 1] - S) % mod * inv[S - i] % mod;     }     E[1] = (N - 1 + E_lf_c[S - 1] - E_lf_c[S]) *            pw(E_lf_a[S] - E_lf_a[S - 1], mod - 2, mod) % mod;     for (int i = 2; i <= S; i++) E[i] = (E[1] * E_lf_a[i] + E_lf_c[i]) % mod;     cat E_cyc = E[S];     cat ans = 0;     for (int i = 0; i < N; i++) ans += E[S - A[i]];     ans = (ans - (N - 1) * E_cyc) % mod * pw(N, mod - 2, mod) % mod;     if (ans < 0) ans += mod;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(vector<T>& v) {     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   vector<int> z_function(string s) {     int n = (int)s.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int n = s.length();     int q;     cin >> q;     string sr = s;     reverse(sr.begin(), sr.end());     vector<int> v(n, n + 1);     while (q--) {       string t;       cin >> t;       int l = t.length();       for (int i = 0; i < n; i++) {         if (i + l > n) break;         if (s.substr(i, l) == t) {           v[i + l - 1] = min(v[i + l - 1], l);         }       }     }     int maxlen = (v[0] == 1) ? 0 : 1;     int index = 0;     int ans = maxlen;     for (int i = 1; i < n; i++) {       int len = min(v[i] - 1, ans + 1);       if (len > maxlen) {         maxlen = len;         index = i - len + 1;       }       ans = len;     }     cout << maxlen <<     << index <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 100010;   const long long MOD = 1000000007;   const long long INF = (long long)1e9;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const long double EPS = 1e-7;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, m;     cin >> n;     long long somaa0 = 0, somab0 = 0;     vector<long long> a(n);     for (long long i = 0; i < (long long)n; i++) {       cin >> a[i];       somaa0 += a[i];     }     cin >> m;     vector<long long> b(m);     for (long long i = 0; i < (long long)m; i++) {       cin >> b[i];       somab0 += b[i];     }     vector<pair<long long, long long> > res;     long long melhor = abs(somaa0 - somab0);     set<long long> setb;     for (long long i = 0; i < (long long)m; i++) {       for (long long j = i + 1; j <= m - 1; j++) {         setb.insert(2 * b[i] + 2 * b[j]);       }     }     for (long long i = 0; i < (long long)n; i++) {       for (long long j = 0; j < (long long)m; j++) {         long long somaa1 = somaa0 - a[i] + b[j];         long long somab1 = somab0 + a[i] - b[j];         if (abs(somaa1 - somab1) < melhor) {           melhor = abs(somaa1 - somab1);           res.clear();           res.push_back(make_pair(i, j));         }       }     }     bool win2 = false;     for (long long i = 0; i < a.size(); i++) {       for (long long j = i + 1; j < a.size(); j++) {         long long somaa2 = somaa0 - a[i] - a[j];         long long somab2 = somab0 + a[i] + a[j];         long long m = somab2 - somaa2;         auto it = setb.lower_bound(m);         if (it != setb.end()) {           long long val = *it;           if (abs(val + somaa2 - somab2) < melhor) {             melhor = abs(val + somaa2 - somab2);             win2 = true;             res.clear();             res.push_back(make_pair(i, j));           }         }         if (it != setb.begin()) {           auto it2 = prev(it);           long long val = *it2;           if (abs(val + somaa2 - somab2) < melhor) {             melhor = abs(val + somaa2 - somab2);             win2 = true;             res.clear();             res.push_back(make_pair(i, j));           }         }       }     }     if (win2) {       long long ia = res[0].first, ja = res[0].second;       long long somaa2 = somaa0 - a[ia] - a[ja];       long long somab2 = somab0 + a[ia] + a[ja];       for (long long i = 0; i < (long long)m; i++) {         for (long long j = i + 1; j <= m - 1; j++) {           if (abs(somaa2 + 2 * b[i] + 2 * b[j] - somab2) <= melhor) {             res.clear();             res.push_back(make_pair(ia, i));             res.push_back(make_pair(ja, j));           }         }       }     }     cout << melhor <<   n ;     cout << res.size() <<   n ;     for (auto val : res) {       cout << val.first + 1 <<     << val.second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct cmp {     bool operator()(const pair<ll, ll>& a, const pair<ll, ll>& b) {       return abs(a.first - a.second) > abs(b.first - b.second);     }   };   int main() {     ll n;     cin >> n;     vector<pair<ll, ll>> v(n);     multiset<pair<ll, ll>, cmp> s;     for (int i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       s.insert(v[i]);     }     int l = 0;     int r = n - 1;     ll ans = 0;     for (int i = 0; i < n; i++) {       pair<ll, ll> cur = *s.begin();       s.erase(s.begin());       if (cur.first <= cur.second) {         ans += cur.first * r + cur.second * (n - 1 - r);         r--;       } else {         ans += cur.first * l + cur.second * (n - 1 - l);         l++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 404;   int n, m;   vector<int> g[maxn];   vector<int> q, G;   int dis[maxn][maxn];   long double p[maxn], P;   pair<long double, int> mxp[maxn];   long double ans;   void bfs(int s) {     dis[s][s] = 0;     q.resize(0);     q.push_back(s);     for (int v, i = 0; i < q.size(); i++) {       v = q[i];       for (int u : g[v])         if (dis[s][v] + 1 < dis[s][u]) {           dis[s][u] = dis[s][v] + 1;           q.push_back(u);         }     }   }   long double f(int v) {     long double ret = 0;     for (int d = 0; d < n; d++) {       G.resize(0);       for (int i = 0; i < n; i++) p[i] = 0;       for (int i = 0; i < n; i++)         if (dis[v][i] == d) {           for (int j : g[i]) {             if (p[j] == 0) G.push_back(j);             p[j] += P / g[i].size();           }         }       if (!G.size()) break;       for (int i = 0; i < n; i++) mxp[i] = {0, -1};       long double X = P, x;       for (int u = 0; u < n; u++) {         x = 0;         for (int c : G) {           if (mxp[dis[u][c]].second == u) x -= mxp[dis[u][c]].first;           if (mxp[dis[u][c]].second != u or mxp[dis[u][c]].first < p[c])             mxp[dis[u][c]] = {p[c], u};           if (mxp[dis[u][c]].second == u) x += mxp[dis[u][c]].first;         }         X = max(X, x);       }       ret += X;     }     return ret;   }   int main() {     memset(dis, 127, sizeof dis);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int v, u, i = 0; i < m; i++) {       cin >> v >> u;       v--, u--;       g[v].push_back(u);       g[u].push_back(v);     }     for (int i = 0; i < n; i++) bfs(i);     P = 1.0 / n;     for (int i = 0; i < n; i++) {       ans = max(ans, f(i));     }     cout << setprecision(15) << fixed << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   const int inf = 6969696;   int dp[N][N];   int a[N];   int e[N];   int n, k;   int go(int pos, int left) {     if (left < 0) return -inf;     if (pos == n) return 0;     int &cur = dp[pos][left];     if (cur != -1) return cur;     cur = go(pos + 1, left);     cur = max(cur, e[pos] - pos + go(e[pos], left - 1));     return cur;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a, a + n);     int i = 0, ptr = 0;     while (i < n) {       while (ptr < n and a[ptr] <= a[i] + 5) ptr++;       e[i] = ptr;       i++;     }     memset(dp, -1, sizeof dp);     printf( %d n , go(0, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s =  abcd ;     string ans =   ;     int m = n / 4;     for (int i = 0; i < m; i++) {       ans += s;     }     int z = n % 4;     for (int i = 0; i < z; i++) {       ans += s[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1LL << 30) - 1;   const long long int LINF = (1LL << 62) - 1;   const int NMAX = (1e5) + 5;   int N, M;   int pile[NMAX];   bool check(long long int time) {     int i, k;     long long int curr;     int P[NMAX];     memcpy(P, pile, sizeof(pile));     for (i = N, k = 1; k <= M; k++) {       while (P[i] == 0 && i >= 1) i--;       if (i == 0) return 1;       curr = i;       while (curr < time) {         if (curr + P[i] <= time) {           curr += P[i];           P[i] = 0;         } else {           P[i] -= time - curr;           curr = time;         }         while (P[i] == 0 && i >= 1) i--;         if (i == 0) return 1;       }     }     return 0;   }   int main() {     int i;     long long int lo = 0, hi = 0, mi;     long long int sol;     cin.sync_with_stdio(false);     scanf( %d%d , &N, &M);     hi += N;     for (i = 1; i <= N; i++) {       scanf( %d , &pile[i]);       hi += pile[i];     }     sol = hi;     while (lo <= hi) {       mi = (lo + hi) / 2;       if (check(mi)) {         sol = min(sol, mi);         hi = mi - 1;       } else         lo = mi + 1;     }     printf( %lld n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lis(long long arr[], long long n) {     long long lis[n];     lis[0] = 1;     for (long long i = 1; i < n; i++) {       lis[i] = 1;       for (long long j = 0; j < i; j++)         if (arr[i] >= arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1;     }     return *max_element(lis, lis + n);   }   void solve() {     long long n, m;     cin >> n >> m;     long long a[n];     double d[n];     for (long long i = 0; i < (n); ++i) cin >> a[i] >> d[i];     cout << n - lis(a, n);   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, ma;     cin >> n;     int arr[n], b[n];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     ma = arr[n - 1];     b[n - 1] = 0;     for (i = n - 2; i >= 0; i--) {       if (arr[i] <= ma) {         b[i] = (ma - arr[i]) + 1;       } else {         b[i] = 0;         ma = arr[i];       }     }     for (i = 0; i < n; i++) {       cout << b[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(1E7 + 10);   vector<long long int> prime;   int l[kN], mu[kN], s[kN];   long long int n;   void pre() {     mu[1] = 1;     for (int i = 2; i <= n; i++) {       if (l[i] == 0) {         mu[i] = -1;         prime.push_back(l[i] = i);       }       for (int j : prime) {         if (i * j > n) break;         l[i * j] = min(l[i], j);         if (i % j == 0) {           mu[i * j] = 0;           break;         } else           mu[i * j] = -mu[i];       }     }     for (int i = 2; i <= n; i++) s[l[i]]++;     for (int i = 3; i <= n; i++) s[i] += s[i - 1];     return;   }   int main() {     long long int ans = 0, one = 0, two = 0, three = 0, zero = 0, cnt = 1;     scanf( %lld , &n);     pre();     for (int k = 1; k <= n; k++) one += mu[k] * (n / k) * (n / k);     one = n * (n - 1) / 2 - (one >> 1);     for (long long int i : prime)       if (i * i < n)         continue;       else if ((i << 1) > n)         cnt++;       else if (i > n / i)         three += s[i - 1] - s[n / i];     zero = (((n - 1) + (n - cnt)) * cnt) >> 1;     two = n * (n - 1) / 2 - zero - one - three;     ans = one + two * 2 + three * 3;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, mx = -1, n;     cin >> n;     while (n--) {       cin >> x;       mx = max(x, mx);     }     if (mx <= 25)       cout <<  0 n ;     else       cout << mx - 25 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxVal = 200005;   int arr[maxVal];   int tree[4 * maxVal];   void build(int node, int start, int endd, int k) {     if (start == endd) {       if (arr[start] >= k)         tree[node] = 1;       else         tree[node] = 0;     } else {       int mid = (start + endd) / 2;       build(2 * node, start, mid, k);       build(2 * node + 1, mid + 1, endd, k);       tree[node] = tree[2 * node] + tree[2 * node + 1];     }   }   int query(int node, int start, int endd, int l, int r) {     if (start > r || endd < l) {       return 0;     } else if (l <= start && endd <= r) {       return tree[node];     } else {       int mid = (start + endd) / 2;       int a1 = query(2 * node, start, mid, l, r);       int a2 = query(2 * node + 1, mid + 1, endd, l, r);       return a1 + a2;     }   }   int main() {     int n, m, k;     cin >> n >> k >> m;     int a, b;     for (int i = 0; i < n; i++) {       cin >> a >> b;       arr[a]++;       arr[b + 1]--;     }     for (int i = 1; i < maxVal; i++) {       arr[i] = arr[i] + arr[i - 1];     }     build(1, 0, maxVal, k);     for (int i = 0; i < m; i++) {       cin >> a >> b;       cout << query(1, 0, maxVal, a, b) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const long long p = 1e9 + 7;   int par[MAXN][2], size[MAXN][2], dist[MAXN][2], val[MAXN][2];   int groups, n, k;   pair<int, int> find(int e, int x) {     if (par[x][e] == x) {       return pair<int, int>(x, 0);     }     pair<int, int> t = find(e, par[x][e]);     t.second += dist[x][e];     t.second %= 2;     dist[x][e] = t.second;     par[x][e] = t.first;     return t;   }   bool assign(int e, int x, int v) {     find(e, x);     if (val[par[x][e]][e] == -1) {       val[par[x][e]][e] = (dist[x][e] + v) % 2;       --groups;       return true;     }     if (val[par[x][e]][e] != (dist[x][e] + v) % 2) return false;     return true;   }   bool addedge(int e, int x, int y, int v) {     find(e, x);     find(e, y);     if (par[x][e] == par[y][e]) return ((dist[x][e] + dist[y][e] + v) % 2 == 0);     v = (dist[x][e] + dist[y][e] + v) % 2;     x = par[x][e];     y = par[y][e];     if (size[x][e] > size[y][e]) swap(x, y);     par[x][e] = y;     dist[x][e] = v;     size[y][e] += size[x][e];     if (val[y][e] != -1 && val[x][e] != -1) {       if ((val[x][e] + val[y][e] + v) % 2 != 0) return false;       return true;     }     if (val[x][e] != -1) {       val[y][e] = (val[x][e] + v) % 2;       --groups;       return true;     }     --groups;     return true;   }   int main() {     cin >> n >> k;     groups = 2 * n - 1;     for (int i = 0; i < MAXN; ++i) {       par[i][0] = par[i][1] = i;       size[i][0] = size[i][1] = 1;       dist[i][0] = dist[i][1] = 0;       val[i][0] = val[i][1] = -1;     }     for (int i = 0; i < k; ++i) {       int x, y, v;       char j;       cin >> x >> y >> j;       v = (j ==  o );       x--;       y--;       if (abs(x - y) <= 1) {         if (!assign((x + y) % 2, min(x, y), v)) {           cout <<  0  << endl;           return 0;         }       } else {         if (x > y) swap(x, y);         if (!addedge((x + y) % 2, (y - x - (x + y) % 2) / 2 - 1,                      (y - x - (x + y) % 2) / 2 + x, v)) {           cout <<  0  << endl;           return 0;         }       }     }     for (int i = 0; i < n / 2; ++i) {       if (!addedge(0, i, n - 1 - i, 0)) {         cout <<  0  << endl;         return 0;       }     }     for (int i = 0; i < (n - 1) / 2; ++i) {       if (!addedge(1, i, n - 2 - i, 0)) {         cout <<  0  << endl;         return 0;       }     }     long long prod = 1;     for (int i = 0; i < groups; ++i) {       prod *= 2;       prod %= p;     }     cout << prod << endl;   }


#include <bits/stdc++.h>   const double eps = (1e-5);   using namespace std;   int dcmp(long double a, long double b) {     return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   long long getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }   long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }   void M() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   int arr[3009], E[4500009];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int cnt = 0;     while (1) {       int fl = 0;       for (int i = 0; i < n; i++) {         if (i + 1 < n && arr[i] > arr[i + 1])           swap(arr[i], arr[i + 1]), cnt++, fl = 1;       }       if (!fl) break;     }     E[1] = 1;     for (int i = 2; i <= cnt; i++) E[i] = 4 + E[i - 2];     cout << fixed << setprecision(9) << (double)E[cnt] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   const long long INF = 1e18;   struct node {     long long d, f, t, c;   } a[N];   long long b[N];   long long dp[1000006], dp1[1000005];   bool cmp(node p, node q) { return p.d < q.d; }   int main() {     int n, m, k;     long long x = 1000000, y = -1;     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       scanf( %lld%lld%lld%lld , &a[i].d, &a[i].f, &a[i].t, &a[i].c);     }     sort(a + 1, a + 1 + m, cmp);     for (int i = 1; i <= 1000001; i++) b[i] = -1, dp[i] = INF;     long long sum = 0, s = 0;     for (int i = 1; i <= m; i++) {       if (a[i].f == 0) continue;       if (b[a[i].f] == -1) {         s++;         b[a[i].f] = a[i].c;         sum += a[i].c;       } else {         if (b[a[i].f] > a[i].c) {           sum -= b[a[i].f];           sum += a[i].c;           b[a[i].f] = a[i].c;         }       }       if (s == n) {         dp[a[i].d] = sum;         x = min(x, a[i].d);       }     }     for (int i = 1; i <= 1000001; i++) b[i] = -1, dp1[i] = INF;     sum = 0;     s = 0;     for (int i = m; i >= 1; i--) {       if (a[i].t == 0) continue;       if (b[a[i].t] == -1) {         s++;         b[a[i].t] = a[i].c;         sum += a[i].c;       } else {         if (b[a[i].t] > a[i].c) {           sum -= b[a[i].t];           sum += a[i].c;           b[a[i].t] = a[i].c;         }       }       if (s == n) {         dp1[a[i].d] = sum;         y = max(y, a[i].d);       }     }     for (int i = x + 1; i <= 1000000; i++) dp[i] = min(dp[i - 1], dp[i]);     for (int i = y - 1; i >= 1; i--) dp1[i] = min(dp1[i + 1], dp1[i]);     long long ans = INF;     for (int i = 1; i <= 1000000 - k - 1; i++) {       if (dp[i] == INF || dp1[i + k + 1] == INF) continue;       if (ans > dp[i] + dp1[i + k + 1]) {         ans = dp[i] + dp1[i + k + 1];       }     }     if (ans == INF)       cout << -1 << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long sum[4];   int main(void) {     long long n, a, b, c, d, min_value = 1e14, max_value = 0, flag = 0;     scanf( %lld %lld %lld %lld %lld , &n, &a, &b, &c, &d);     sum[0] = a + b;     sum[1] = b + d;     sum[2] = c + d;     sum[3] = a + c;     for (int i = 0; i < 4; i++) {       min_value = min(min_value, sum[i]);       max_value = max(max_value, sum[i]);     }     if (max_value - min_value > n) flag = 1;     if (flag == 1)       printf( 0 );     else       printf( %lld , n * (n - (max_value - min_value)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const long long MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   long long power(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res *= a;       a *= a;       n /= 2;     }     return res;   }   long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); }   long long froot(long long x, long long* root) {     if (x == root[x])       return x;     else       root[x] = froot(root[x], root);   }   int32_t main() {     long long n;     cin >> n;     long long arr[n + 1], root[n + 1], cnt[n + 1];     for (long long i = 1; i <= n; i++) {       cnt[i] = 1;       root[i] = i;     }     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       long long x = froot(i, root);       long long y = froot(arr[i], root);       if (x < y) {         root[y] = x;         cnt[x] += cnt[y];       } else if (y < x) {         root[x] = y;         cnt[y] += cnt[x];       }     }     map<long long, long long> mp;     long long max1 = -1, max2 = -1, rm1 = -1, rm2 = -1;     for (long long i = 1; i <= n; i++) {       long long x = froot(i, root);       if (mp[x] == 0) {         mp[x]++;         if (cnt[x] >= max1) {           max2 = max1;           rm2 = rm1;           max1 = cnt[x];           rm1 = x;         } else if (cnt[x] > max2) {           max2 = cnt[x];           rm2 = x;         }       }     }     if (rm2 == -1) {       long long res;       long long x = froot(1, root);       x = cnt[x];       res = power(x, 2);       cout << res <<   n ;     } else {       long long res = 0;       root[rm2] = rm1;       cnt[rm1] += cnt[rm2];       map<long long, long long> mp1;       for (long long i = 1; i <= n; i++) {         long long x = froot(i, root);         if (mp1[x] == 0) {           mp1[x]++;           long long p = cnt[x];           res += power(p, 2);         }       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 710;   int n;   struct Tbig {     static const int bit = 10000;     int n, a[30];     Tbig(int x = 0) {       memset(a, 0, sizeof a);       for (n = 0; x; x /= bit) a[n++] = x % bit;       !n ? n = 1 : 0;     }     Tbig operator*(const Tbig &b) const {       int i, j;       Tbig c;       c.n = n + b.n;       for (i = 0; i < n; ++i)         for (j = 0; j < b.n; ++j) {           c.a[i + j] += a[i] * b.a[j];           c.a[i + j + 1] += c.a[i + j] / bit, c.a[i + j] %= bit;         }       for (; c.n > 0 && !c.a[c.n]; --c.n)         ;       ++c.n;       return c;     }     bool operator<(const Tbig &b) const {       int i;       if (n != b.n) return n < b.n;       for (i = n - 1; i >= 0; --i)         if (a[i] != b.a[i]) return a[i] < b.a[i];       return false;     }     void print() {       int i;       printf( %d , a[n - 1]);       for (i = n - 2; i >= 0; --i) printf( %04d , a[i]);       printf(  n );     }   };   struct Talt {     int tot;     struct Tsqy {       int s;       Tsqy *l;       inline void set(Tsqy *_l, int _s) { l = _l, s = _s; }     } * pos[maxn], buf[maxn * 2];     inline void add(int a, int b) {       buf[++tot].set(pos[a], b), pos[a] = buf + tot;       buf[++tot].set(pos[b], a), pos[b] = buf + tot;     }   } alt;   namespace Ninit {   void init() {     int i, a1, a2;     scanf( %d , &n);     for (i = 1; i < n; ++i) {       scanf( %d%d , &a1, &a2), alt.add(a1, a2);     }   }   }  // namespace Ninit   namespace Nsolve {   Tbig F[maxn][maxn], G[maxn], F_xi;   int S[maxn];   void dfs(int x, int f) {     Talt::Tsqy *p;     int i, j;     S[x] = 1, F[x][1] = 1;     for (p = alt.pos[x]; p; p = p->l)       if (p->s != f) {         dfs(p->s, x), S[x] += S[p->s];         for (i = S[x]; i >= 1; --i) {           F_xi = F[x][i];           for (j = min(S[p->s], i - 1); j > 0 && i - j <= S[x] - S[p->s]; --j)             F[x][i] = max(F[x][i], F[x][i - j] * F[p->s][j]);           F[x][i] = max(F[x][i], F_xi * G[p->s]);         }       }     for (i = 1; i <= S[x]; ++i) G[x] = max(G[x], F[x][i] * i);   }   void solve() {     dfs(1, 0);     G[1].print();   }   }  // namespace Nsolve   int main() {     Ninit::init();     Nsolve::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int size1;     string s;     vector<int> v;     int arr[200];     cin >> size1 >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  * ) v.push_back(i + 1);     }     for (int i = 0; i < v.size(); i++) {       for (int count1 = 1; count1 <= 100; count1++) {         int n = v[i] + count1;         int counttimes = 0;         for (int l = i + 1; l < v.size(); l++) {           if (counttimes == 4) {             cout <<  yes ;             return 0;           }           if (n == v[l]) {             n = v[l] + count1;             counttimes++;           }           if (v[l] > n) break;         }         if (counttimes == 4) {           cout <<  yes ;           return 0;         }       }     }     cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5;   long long int t[N];   string s;   long long int n, k;   bool chek(long long int x) {     for (long long int i = 0; i < n; i++) {       if (!(s[i] -  0 )) {         long long int en = i + x;         long long int st = i - x;         en = min(en, n - 1);         st = max((long long int)0, st);         long long int cur = t[en] - (st ? t[st - 1] : 0) - 1;         if (cur >= k) return true;       }     }     return false;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     cin >> s;     long long int x = 0;     for (long long int i = 0; i < s.size(); i++) {       if (!(s[i] -  0 )) x++;       t[i] = x;     }     long long int l = -1, r = n + 1;     while (r - l > 1) {       long long int mid = (r + l) / 2;       if (chek(mid))         r = mid;       else         l = mid;     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, n, m;   string s, v;   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;     }     for (int i = 1; i <= n; i++) {       if (i % 2 == 1) {         cout << 1;       } else {         cout << 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, x, y, w, m, Q, used[100500], start;   pair<pair<int, int>, int> a[100500];   vector<pair<int, int> > g[100500];   vector<int> f[100500];   long long d[100500];   long long hea[200500];   int new_w[100500], new_d[100500];   int hea2[200500];   int st[100500], sz[100500], cur_pos[100500];   pair<int, int> G[100500];   int heapSize;   void add(pair<long long, int> value) {     hea[heapSize++] = value.first;     int i = heapSize - 1;     hea2[i] = value.second;     int parent = ((i - 1) >> 1);     while (i > 0 && hea[parent] < hea[i]) {       swap(hea[i], hea[parent]);       swap(hea2[i], hea2[parent]);       i = parent;       parent = ((i - 1) >> 1);     }   }   void heapify(int i) {     int largestChild;     for (;;) {       largestChild = i;       if (hea[2 * i + 1] > hea[largestChild]) {         largestChild = 2 * i + 1;       }       if (hea[2 * i + 2] > hea[largestChild]) {         largestChild = 2 * i + 2;       }       if (largestChild == i) {         break;       }       swap(hea[i], hea[largestChild]);       swap(hea2[i], hea2[largestChild]);       i = largestChild;     }   }   pair<long long, int> getMax() {     pair<int, int> result = make_pair(hea[0], hea2[0]);     heapSize--;     hea[0] = hea[heapSize];     hea2[0] = hea2[heapSize];     hea[heapSize] = -(long long)1e+18;     heapify(0);     return result;   }   inline unsigned int readUInt() {     int c = getc(stdin);     unsigned int x = 0;     while (c <= 32) c = getc(stdin);     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getc(stdin);     return x;   }   int main() {     cin >> n >> m >> Q;     for (i = 0; i <= 200000; i++) hea[i] = -(long long)1e+18;     for (i = 0; i < m; i++) {       int x, y, z;       x = readUInt();       y = readUInt();       z = readUInt();       a[i] = make_pair(make_pair(x, y), z);     }     int s = 1;     for (i = 0; i < m; i++) {       g[a[i].first.first].push_back(make_pair(a[i].first.second, a[i].second));     }     st[1] = 0;     sz[1] = g[1].size();     for (i = 2; i <= n; i++) {       st[i] = st[i - 1] + g[i - 1].size();       sz[i] = g[i].size();     }     for (i = 1; i <= n; i++) d[i] = (long long)1e+18;     d[s] = 0;     for (i = 0; i < heapSize; i++) hea[i] = -(long long)1e+18;     heapSize = 0;     add(make_pair(0, s));     while (heapSize) {       pair<int, int> tmp = getMax();       int v = tmp.second;       long long cur_d = -tmp.first;       if (cur_d > d[v]) continue;       for (size_t j = 0; j < g[v].size(); ++j) {         int to = g[v][j].first;         long long len = g[v][j].second;         if (d[v] + len < d[to]) {           d[to] = d[v] + len;           add(make_pair(-d[to], to));         }       }     }     for (i = 0; i < m; i++)       new_w[i] = min(100000000LL,                      a[i].second + d[a[i].first.first] - d[a[i].first.second]);     for (int ii = 0; ii < Q; ii++) {       int test;       cin >> test;       if (test == 1) {         int t;         cin >> t;         if (d[t] == (long long)1e+18)           cout << -1 << endl;         else           cout << d[t] << endl;       } else {         cin >> x;         for (i = 0; i < x; i++) {           int y = readUInt();           new_w[y - 1]++;           a[y - 1].second++;         }         for (i = 1; i <= n; i++) cur_pos[i] = st[i];         for (i = 0; i < m; i++) {           G[cur_pos[a[i].first.first]++] = make_pair(a[i].first.second, new_w[i]);         }         for (i = 0; i <= n; i++) {           f[i].clear();           new_d[i] = (int)1e+9;         }         f[0].push_back(1);         new_d[1] = 0;         for (i = 0; i < n; i++) {           for (j = 0; j < f[i].size(); j++) {             int v = f[i][j];             if (new_d[v] == i) {               for (k = st[v]; k < st[v] + sz[v]; k++) {                 int to = G[k].first;                 int val = G[k].second;                 if (new_d[to] > i + val) {                   new_d[to] = min(100000000, i + val);                   if (new_d[to] <= n) f[new_d[to]].push_back(to);                 }               }             }           }         }         for (i = 1; i <= n; i++) {           d[i] += new_d[i];           if (d[i] > (long long)1e+18) d[i] = (long long)1e+18;         }         for (i = 0; i < m; i++)           new_w[i] = min(100000000LL, a[i].second + d[a[i].first.first] -                                           d[a[i].first.second]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[100010], mn = 1000000000, st, ans = 1000000000;   bool b;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       mn = min(mn, arr[i]);     }     for (int i = 0; i < n; ++i) {       if (arr[i] == mn && !b) {         st = i;         b = 1;       } else if (arr[i] == mn) {         ans = min(ans, i - st);         st = i;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; i++) a[i] = i + 1;     int cnt = (n / 2) * (n / 2);     if (n % 2 == 0) cnt -= n / 2;     if (cnt < m) {       cout << -1;       return 0;     }     int idx = n - 1;     while (m < cnt) {       if (cnt - (idx / 2) <= m) {         a[idx] += 2 * (cnt - m);         break;       } else {         cnt -= idx / 2;         if (idx + 1 == n)           a[idx] = 1000 * 1000 * 1000;         else           a[idx] = a[idx + 1] - 2 * n;       }       idx--;     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, nn[5], ma;   string s;   long long ans = 1;   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  A ) nn[0]++;       if (s[i] ==  C ) nn[1]++;       if (s[i] ==  G ) nn[2]++;       if (s[i] ==  T ) nn[3]++;     }     for (int i = 0; i < 4; i++) ma = max(ma, nn[i]);     int ct = 0;     for (int i = 0; i < 4; i++) {       if (nn[i] == ma) ct++;     }     for (int i = 0; i < n; i++) {       ans *= ct;       ans %= 1000000007;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   long long t, n, a[maxn];   int main() {     scanf( %d , &t);     while (t--) {       long long maxx = -1e18, ans = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > maxx) maxx = a[i];       }       for (int i = 0; i < n; i++) {         if (maxx == a[i]) {           if (i == 0 && a[0] > a[1]) {             ans = 1;             break;           } else if (i == n - 1 && a[n - 1] > a[n - 2]) {             ans = n;             break;           } else if (((i != 0) && a[i] > a[i - 1]) ||                      (i != n - 1 && a[i] > a[i + 1])) {             ans = i + 1;             break;           }         }       }       if (ans == 0)         cout << -1 << endl;       else         cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   char s[MAXN];   int main() {     int m;     scanf( %d , &m);     scanf( %s , s);     int n = strlen(s);     priority_queue<int, vector<int>, greater<int> > Q;     for (int k = 0; k < 26; k++) {       while (!Q.empty()) Q.pop();       bool flag;       for (int i = 0; i <= n - 1; i++) {         flag = 0;         int tmp = 0;         for (int j = i; j <= i + m - 1 && j < n; j++) {           if (s[j] -  a  < k) Q.push(s[j]), flag = 1, tmp = j;         }         if (i > n - m) {           flag = 1;           break;         }         if (!flag) {           for (int j = i + m - 1; j >= i; j--) {             if (s[j] -  a  == k) {               Q.push(s[j]), flag = 1;               tmp = j;               break;             }           }           if (!flag) break;         }         i = tmp;       }       if (flag) {         while (!Q.empty()) {           printf( %c , Q.top());           Q.pop();         }         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double PI = acos(-1);   long long power(long long x, long long y) {     if (y == 0)       return 1;     else if (y == 1)       return x;     long long r = power(x, y / 2);     if (y % 2 == 0)       return (r * r);     else       return (r * r * x);   }   bool primechecker(long long i) {     bool valid = true;     for (int j = 2; j <= sqrt(i); j++) {       if (i % j == 0) {         valid = false;         break;       }     }     if (valid && i != 1)       return true;     else       return false;   }   vector<bool> prime(10000001, true);   void sieveprime() {     prime[0] = false;     prime[1] = false;     for (int i = 2; i < prime.size(); i++) {       if (prime[i] == true) {         for (int j = i + i; j <= 10000000; j += i) prime[j] = false;       }     }     return;   }   int main() {     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       cout << (a ^ b) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int n, siz[N], s[N][N], ori[N][N], tot[N], pos[N];   vector<int> ans;   int read() {     int x = 0, f = 1;     char s;     while ((s = getchar()) >  9  || s <  0 )       if (s ==  - ) f = -1;     while (s >=  0  && s <=  9 )       x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();     return x * f;   }   bool ok() {     for (int i = 1; i <= n; ++i)       if (tot[i]) return 0;     return 1;   }   bool check() {     int maxx;     for (int i = 1; i <= n; ++i) pos[ans[n - i]] = i;     for (int i = 1; i < n; ++i) {       maxx = 0;       for (int j = 1; j <= n; ++j) tot[j] = 0;       for (int j = 1; j <= siz[i]; ++j)         maxx = max(maxx, pos[ori[i][j]]), ++tot[ori[i][j]];       if (maxx - siz[i] + 1 < 1) return 0;       for (int j = maxx; j >= maxx - siz[i] + 1; --j)         if (!tot[ans[n - j]]) return 0;     }     return 1;   }   int main() {     int x, sum;     bool flag;     for (int T = read(); T; --T) {       n = read();       for (int i = 1; i < n; ++i) {         siz[i] = read();         for (int j = 1; j <= siz[i]; ++j) ori[i][j] = read();       }       for (int num = 1; num <= n; ++num) {         ans.clear();         flag = 0;         for (int i = 1; i < n; ++i) {           for (int j = 1; j <= siz[i]; ++j) {             s[i][j] = ori[i][j];             if (s[i][j] == num) s[i][j] = 0;           }         }         while (233) {           sum = 0;           for (int i = 0; i <= n; ++i) tot[i] = 0;           for (int i = 1; i < n; ++i)             for (int j = 1; j <= siz[i]; ++j) ++tot[s[i][j]];           for (int i = 1; i <= n; ++i)             if (tot[i] == 1) ++sum, x = i;           if (ok()) break;           if (sum != 1) {             flag = 1;             break;           }           ans.push_back(x);           bool f;           for (int i = 1; i < n; ++i) {             f = 0;             for (int j = 1; j <= siz[i]; ++j)               if (s[i][j] == x) {                 f = 1;                 break;               }             if (f)               for (int j = 1; j <= siz[i]; ++j) s[i][j] = 0;           }         }         if (!flag) {           ans.push_back(num);           if (check()) break;         }       }       for (int i = ans.size() - 1; ~i; --i) printf( %d  , ans[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   inline void DoNothing() {}   template <typename T>   inline T Abs(const T a) {     return a < 0 ? -a : a;   }   template <typename T>   inline T Min(const T a, const T b) {     return a < b ? a : b;   }   template <typename T>   inline T Max(const T a, const T b) {     return a > b ? a : b;   }   static const long double eps = 1.0e-07;   template <typename T>   inline T IsEqual(const T a, const T b) {     return Abs(a - b) < eps;   }   template <typename T>   inline T IsGreater(const T a, const T b) {     return a > b + eps;   }   template <typename T>   inline T IsLess(const T a, const T b) {     return a + eps < b;   }   template <typename T>   inline void Print(const T& val) {     std::cout << val <<    ;   }   template <typename T>   inline std::string ToStr(const T& val) {     std::ostringstream ostr;     ostr << val;     return ostr.str();   }   template <typename T>   inline bool FromStr(const std::string& str, T& val) {     std::istringstream istr(str);     istr >> val;     return !!istr;   }   struct Rand {     unsigned long z_, w_;     unsigned long get32() {       z_ = 36969 * (z_ & 65535) + (z_ >> 16);       w_ = 18000 * (w_ & 65535) + (w_ >> 16);       return (z_ << 16) + (w_ & 65535);     }     void Reset() {       z_ = 1;       w_ = 1;     }     Rand() { Reset(); }   };   template <typename T>   inline std::vector<std::vector<T> > CreateVector2d(const size_t rowCnt,                                                      const size_t colCnt) {     return std::vector<std::vector<T> >(rowCnt, std::vector<T>(colCnt));   }   void Prepare();   class StopWatchEx {    public:     StopWatchEx();     ~StopWatchEx();       private:     struct Data;     Data* pData;   };   inline double CalcRk(const double rb, const double rs, size_t k) {     const double i_ds = 1 / (2 * rs);     const double i_db = 1 / (2 * rb);     const double i_d = i_ds - i_db;     const double i_xc = i_db + i_d / 2;     const double i_yc = i_d * (double)(k);     const double i_c = sqrt(i_yc * i_yc + i_xc * i_xc);     const double z1 = 1 / (i_c - i_d / 2);     const double z2 = 1 / (i_c + i_d / 2);     const double rk = (z1 - z2) / 2;     return rk;   }   bool Solve(bool bCheckInputStream = false) {     size_t n;     std::cin >> n;     if (bCheckInputStream && !std::cin) {       return false;     }     StopWatchEx _sw;     for (size_t i = 0; i < n; i++) {       size_t rb, rs, k;       std::cin >> rb >> rs >> k;       const double rk = CalcRk((double)rb, (double)rs, k);       std::cout << std::setprecision(8) << std::setw(12) << rk << std::endl;     }     return true;   }   int main() {     Prepare();     Solve();   }   struct StopWatchEx::Data {};   StopWatchEx::StopWatchEx() {}   StopWatchEx::~StopWatchEx() {}   void Prepare() {}


#include <bits/stdc++.h>   using namespace std;   int sumb[64];   int xorb[64];   long long s, r;   int maxx = 0;   void bits() {     int i = 0;     long long bf = s;     while (bf) {       sumb[i] = bf % 2;       ++i;       bf /= 2;     }     maxx = i;     bf = r;     i = 0;     while (bf) {       xorb[i] = bf % 2;       ++i;       bf /= 2;       maxx = max(maxx, i);     }   }   long long ansv[2][65][2][2];   bool ch[2][65][2][2];   long long calc(int ost, int pos, int f1, int f2) {     if (ch[ost][pos][f1][f2]) {       return ansv[ost][pos][f1][f2];     }     ch[ost][pos][f1][f2] = 1;     if (pos >= 64) {       if (ost == 0 && f1 == f2 && f2 == 1) {         return 1;       } else {         return 0;       }     }     long long ans = 0;     for (long long(x1) = 0; (x1) < (2); ++(x1)) {       for (long long(x2) = 0; (x2) < (2); ++(x2)) {         long long p;         if ((x1 + x2 + ost) % 2 == sumb[pos] &&             ((x1 == x2 && 0 == xorb[pos]) || (x1 != x2 && 1 == xorb[pos]))) {           p = calc(((x1 + x2 + ost) > 1), pos + 1, (x1 != 0) || f1,                    (x2 != 0) || f2);           ans += p;         }       }     }     return ansv[ost][pos][f1][f2] = ans;   }   int main() {     ios::sync_with_stdio(false);     cin >> s >> r;     bits();     cout << calc(0, 0, 0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;   }   inline long long mul(long long a, long long b) {     return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;   }   inline long long sub(long long a, long long b) {     return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %            1000000007LL;   }   long long dp[1001][2001];   long long findAns(long long i, long long j, long long n, long long k,                     long long a[], long long key[], long long p) {     if (i == n) {       return 0;     }     if (j >= k) {       return -1000000000000000000LL;     }     if (dp[i][j] != -1) {       return dp[i][j];     }     long long ret;     long long ret1 = findAns(i, j + 1, n, k, a, key, p);     long long ret2 = findAns(i + 1, j + 1, n, k, a, key, p);     if (ret1 == -1000000000000000000LL && ret2 == -1000000000000000000LL) {       ret = -1000000000000000000LL;     } else if (ret1 == -1000000000000000000LL) {       ret = max(abs(a[i] - key[j]) + abs(key[j] - p), ret2);     } else if (ret2 == -1000000000000000000LL) {       ret = ret1;     } else {       ret = min(ret1, max(abs(a[i] - key[j]) + abs(key[j] - p), ret2));     }     return dp[i][j] = ret;   }   void Flash() {     long long n, k, p;     cin >> n >> k >> p;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long key[k];     for (long long i = 0; i < k; i++) {       cin >> key[i];     }     sort(a, a + n), sort(key, key + k);     memset(dp, -1, sizeof(dp));     long long ans = findAns(0, 0, n, k, a, key, p);     cout << ans <<   n ;   }   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     ;     long long t = 1;     for (long long i = 1; i <= t; i++) {       Flash();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000007;   int v[N];   vector<int> pos[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> v[i];       pos[v[i]].push_back(i);     }     for (int i = 0; i < N; ++i) {       reverse(pos[i].begin(), pos[i].end());     }     set<int> s;     long long cnt = 0;     for (int i = 0; i < n; ++i) {       s.insert(v[i]);       cnt += s.size();     }     long long ans = 2ll * cnt;     long long cur = 0;     for (int l = 0; l < n; ++l) {       int x = v[l];       pos[x].pop_back();       int j = n;       if (pos[x].size()) j = pos[x].back();       cnt -= 1;       cnt -= (j - l - 1);       ans += 2ll * cnt;     }     ans -= n;     cout << fixed << setprecision(10)          << (ans / (1.0 * ((long long)n * (long long)n))) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m;     cin >> n >> m;     vector<string> xs(n);     for (int i = 0; i < n; i++) cin >> xs[i];     int cur = 0;     int curB = 0;     set<int> ans;     for (int i = 0; i < xs.size() - 1; i++) {       int j = 0;       while (j < xs[i].size()) {         if (xs[i][j] != xs[i + 1][j] && !ans.count(j)) {           break;         }         j++;       }       if (j < m && xs[i][j] > xs[i + 1][j]) {         ans.insert(j);         i = -1;       }     }     cout << ans.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int num = 200001;   long long a[401];   int main() {     int t, n;     cin >> t;     int str, cur;     int fl = 0;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) a[n + i] = a[i];       cur = 2 * n;       int first = 1;       for (int i = 0; i < cur; i++) {         if (a[i] == first) {           first++;         } else {           first = 1;         }         if (first == n) {           fl = 1;           break;         }       }       first = n;       for (int i = 0; i < cur; i++) {         if (a[i] == first)           first--;         else           first = n;         if (first == 1) {           fl = 1;           break;         }       }       if (fl)         cout <<  YES n ;       else         cout <<  NO n ;       fl = 0;       for (int i = 0; i < cur; i++) a[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int pw = 1 << 17;   const int maxn = 1e5 + 20;   int ans[maxn];   void work() {     int n, x;     cin >> n >> x;     if (n == 1) {       printf( YES n );       cout << x << endl;       return;     } else if (n == 2 && x == 0) {       printf( NO n );       return;     }     printf( YES n );     int t = x;     for (int i = 0; i < n; ++i) ans[i] = i;     for (int i = 0; i < n - 1; ++i) {       t ^= ans[i];     }     if (t <= n - 2) {       ans[t] ^= pw;       if (t == n - 2)         ans[t - 1] ^= pw;       else if (t == 0)         ans[t + 1] ^= pw;       else         ans[t + 1] ^= pw;     }     ans[n - 1] = t;     int res = 0;     for (int i = 0; i < n; ++i) {       printf( %d  , ans[i]);       res ^= ans[i];     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> st;     int x;     int sz = 0;     for (int i = 0; i < n; i++) {       cin >> x;       if (sz > 3) continue;       if (st.find(x) == st.end()) {         sz++;         st.insert(x);       }     }     if (sz > 3)       cout <<  NO  << endl;     else if (sz < 3)       cout <<  YES  << endl;     else {       auto it = st.begin();       int a, b, c;       a = *it;       it++;       b = *it;       it++;       c = *it;       if (b - a == c - b)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[105];   char temp[105];   int main() {     int n;     scanf( %d%*c , &n);     while (n--) {       int cnt = 0;       bool flag = false;       bool first = false;       gets(a);       int len = strlen(a);       for (int i = len - 5; i <= len; i++) temp[cnt++] = a[i];       if (strncmp(a,  miao. , 5) == 0) first = true;       if (strcmp(temp,  lala. ) == 0) flag = true;       if (first && !flag)         printf( Rainbow s n );       else if (!first && flag)         printf( Freda s n );       else         printf( OMG>.< I don t know! n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int X = 100000 + 5;   long long C[1005][1005];   long long n, m;   long long iis, ii, jjs, jj, cc;   void calc() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cc += C[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         ii += C[i][j] * (i * 4 + 2);         iis += (i * 4 + 2) * (i * 4 + 2) * C[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         jj += C[i][j] * (j * 4 + 2);         jjs += (j * 4 + 2) * (j * 4 + 2) * C[i][j];       }     }   }   long long dist(long long x, long long y) {     x *= 4;     y *= 4;     long long s = iis + x * x * cc - 2 * x * ii + jjs + y * y * cc - 2 * y * jj;     return s;   }   long long foo(long long x, long long& z) {     long long lo = 0, hi = m, mm = LLONG_MAX;     while (lo + 2 < hi) {       long long ml = lo + (hi - lo) / 3, mr = hi - (hi - lo) / 3;       long long l = dist(x, ml), r = dist(x, mr);       if (l <= r)         hi = mr;       else         lo = ml;     }     for (int i = 0; i <= 2; i++) {       long long cc = dist(x, lo + i);       if (cc < mm) {         mm = cc;         z = lo + i;       }     }     return mm;   }   void MAIN() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> C[i][j];       }     }     calc();     long long mm = LLONG_MAX, xx = -1, yy = -1;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         long long z = dist(i, j);         if (z < mm) {           mm = z;           xx = i;           yy = j;         }       }     }     cout << mm <<   n  << xx <<     << yy;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << setprecision(12);     MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2000], b[2000];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i] >> b[i];     }     int k = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; j++) {         if (j != i) {           if (a[i] == b[j]) {             k++;             break;           }         }       }     }     cout << n - k;     return 0;   }