#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void dout() { cerr << endl; }   template <typename Head, typename... Tail>   void dout(Head H, Tail... T) {     cerr << H <<    ;     dout(T...);   }   mt19937 rnd(time(0));   struct Node {     Node* left = nullptr;     Node* right = nullptr;     int prior;     int size = 1;     double val;     double sleft;     double sright;     double sum;     double mss;     Node(double v)         : prior(rnd()),           val(v),           sleft(max(0.0, v)),           sright(max(0.0, v)),           sum(v),           mss(max(0.0, v)) {}   };   int _size(Node* n) { return n ? n->size : 0; }   double _sleft(Node* n) { return n ? n->sleft : 0; }   double _sright(Node* n) { return n ? n->sright : 0; }   double _sum(Node* n) { return n ? n->sum : 0; }   double _mss(Node* n) { return n ? n->mss : 0; }   void update(Node* n) {     n->size = _size(n->left) + _size(n->right) + 1;     n->sum = _sum(n->left) + _sum(n->right) + n->val;     n->sleft = max(_sleft(n->left), _sum(n->left) + n->val + _sleft(n->right));     n->sright =         max(_sright(n->right), _sum(n->right) + n->val + _sright(n->left));     n->mss = max({_mss(n->left), _mss(n->right),                   _sright(n->left) + n->val + _sleft(n->right)});   }   struct Treap {     Node* root = nullptr;     pair<Node*, Node*> split(Node* n, int index) {       if (!n) return make_pair(nullptr, nullptr);       int sz = _size(n->left) + 1;       if (index < sz) {         auto [l, r] = split(n->left, index);         n->left = r;         update(n);         return make_pair(l, n);       } else {         auto [l, r] = split(n->right, index - sz);         n->right = l;         update(n);         return make_pair(n, r);       }     }     Node* merge(Node* l, Node* r) {       if (!l || !r) return l ? l : r;       if (l->prior > r->prior) {         l->right = merge(l->right, r);         update(l);         return l;       } else {         r->left = merge(l, r->left);         update(r);         return r;       }     }     void push_back(double v) { root = merge(root, new Node(v)); }     double max_subarray_sum(int left, int right) {       auto [x, r] = split(root, right);       auto [l, m] = split(x, left);       double ans = _mss(m);       root = merge(l, merge(m, r));       return ans;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, c;     cin >> n >> m >> c;     vector<double> x(n);     for (int i = 0; i < n; i++) {       cin >> x[i];     }     vector<double> p(n);     for (int i = 1; i < n; i++) {       cin >> p[i];       p[i] /= 100.0;     }     Treap treap;     treap.push_back(0);     for (int i = 1; i < n; i++) {       treap.push_back((x[i] - x[i - 1]) * 0.5 - p[i] * c);     }     double ans = 0.0;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       ans += treap.max_subarray_sum(l, r);     }     cout << fixed << setprecision(9) << ans;     return 0;   }


#include <bits/stdc++.h>   int k, i, n, t;   int main() {     std::cin >> t;     for (; t; i++) {       k = i;       n = 0;       while (k) {         n += k % 10;         k /= 10;       }       if (n == 10) t--;     }     std::cout << i - 1;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int inf = 0x3f3f3f3f;   const long long INF = 1e18;   const int maxn = 200000 + 10;   const int maxm = 1000000000 + 7;   const int mod = 1000000000 + 7;   int gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline long long read() {     char ch = getchar();     long long x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m;   long long a[maxn];   long long num[maxn];   int main() {     int T = read();     while (T--) {       n = read();       for (int i = 1; i <= n; ++i) a[i] = read(), num[i] = 0;       m = read();       for (int i = 1; i <= m; ++i) {         long long x = read(), y = read();         num[y] = max(num[y], x);       }       for (int i = n - 1; i >= 1; --i) {         num[i] = max(num[i], num[i + 1]);       }       bool ok = true;       int ans = 1;       int pos = 1;       long long maxx = 0;       for (int i = 1; i <= n; ++i) {         maxx = max(maxx, a[i]);         int len = i - pos + 1;         if (num[len] < maxx) {           ans++;           pos = i;           maxx = a[i];         }         if (num[1] < a[i]) ok = false;       }       if (ok)         printf( %d n , ans);       else         puts( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[5005];   long long dp[5005], mod = 998244353, bnd[5005], fac[5005], inv[5005];   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans;   }   int main() {     int T = 1;     while (T--) {       int n;       cin >> n;       fac[0] = inv[0] = 1;       for (int i = 1; i <= n; i++)         scanf( %lld , &a[i]), fac[i] = fac[i - 1] * i % mod,                               inv[i] = qpow(fac[i], mod - 2);       sort(a + 1, a + n + 1);       if (a[n - 1] * 2LL > a[n]) {         puts( 0 );         continue;       }       for (int i = 1; i <= n; i++)         for (int j = 1; j < i; j++)           if (a[j] * 2 <= a[i]) bnd[i]++;       for (int i = 1; i <= n; i++)         for (int j = 0; j <= bnd[i]; j++) {           if (j == 0)             dp[i] += fac[n - 1] * inv[n - 1 - bnd[i]] % mod;           else             dp[i] += dp[j] * fac[n - bnd[j] - 2] % mod *                      inv[n - bnd[j] - 2 - (bnd[i] - bnd[j] - 1)] % mod,                 dp[i] %= mod;         }       printf( %lld n , dp[n]);     }     return 0;   }


#include <bits/stdc++.h>   bool debug = 1;   const long long MOD = 1000000007;   const double PI = acos(-1.0);   const double eps = 1e-9;   using namespace std;   int main() {     int n, m;     int c[100100], a[100100];     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %d , &c[i]);     }     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);     }     int j = 0;     for (int i = 0; i < n; i++) {       if (j < m and c[i] <= a[j]) j++;     }     cout << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-10;   int n, q, t;   double plc[500005], ans[500005];   struct Point {     long double x, y;     Point() {}     Point(long double _x, long double _y) { x = _x, y = _y; }     Point operator+(Point p) { return Point(x + p.x, y + p.y); }   } P[500005], Q[500005];   struct Node {     long double x, m, c;     int d;     Node() {}     Node(long double _x, long double _m, long double _c, int _d) {       x = _x, m = _m, c = _c, d = _d;     }     bool operator<(const Node &p) const { return x < p.x; }   } V[500005];   void Add(Point a, Point b, int v) {     if (abs(b.x - a.x) < eps) return;     if (a.x > b.x) {       swap(a, b);       v *= -1;     }     long double m = (b.y - a.y) / (b.x - a.x), c = a.y - a.x * m;     V[++t] = Node(a.x, v * m, v * c, 0);     V[++t] = Node(b.x, -v * m, -v * c, 0);     return;   }   Point Calc(Point a, Point b, Point p) {     return Point((b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x, p.y);   }   int main() {     scanf( %d%d , &n, &q);     int p = 0;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       P[i] = Point(x, y);       if (P[i].y < P[p].y) p = i;     }     for (int i = 1; i <= q; i++) {       double x;       scanf( %lf , &x);       plc[i] = x;       V[i] = Node(x, -1, -1, i);     }     t = q;     long double all = 0;     for (int i = 0; i < n; i++) {       all += P[i].x * P[(i + 1) % n].y - P[(i + 1) % n].x * P[i].y;       if (P[i].y < P[(i + 1) % n].y)         Add(P[i], P[(i + 1) % n], -1);       else         Add(P[(i + 1) % n], P[i], -1);     }     all = abs(all / 2);     int s = 0;     for (int i = p; i < n; i++) Q[s++] = P[i];     for (int i = 0; i < p; i++) Q[s++] = P[i];     for (int i = 0; i < n; i++) P[i] = Q[i];     int lf = 0, rg = 0;     Point lst = P[0];     for (int i = 0; i < n - 1; i++) {       int L = (lf + 1) % n, R = (rg + n - 1) % n;       Point now;       if (P[L].y < P[R].y) {         Point tmp = Calc(P[rg], P[R], P[L]) + P[L];         now.x = tmp.x * 0.5, now.y = tmp.y * 0.5;         lf = L;       } else {         Point tmp = Calc(P[lf], P[L], P[R]) + P[R];         now.x = tmp.x * 0.5;         now.y = tmp.y * 0.5;         rg = R;       }       Add(lst, now, 2);       lst = now;     }     sort(V + 1, V + t + 1);     long double a = 0.0, b = 0.0;     for (int i = 1; i <= t; i++) {       long double x = V[i].x, m = V[i].m, c = V[i].c;       if (V[i].d > 0)         ans[V[i].d] = all + (0.5 * a * x * x + b * x);       else {         all -= 0.5 * m * x * x + c * x;         a += m, b += c;       }     }     for (int i = 1; i <= q; i++) printf( %.10lf n , (double)ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000020;   pair<int, int> a[N], b[N];   bool comp(int x, int y) { return a[x].second > a[y].second; }   int n, m, K;   vector<int> A[N], B[N];   int g[4 * N];   bool t[4 * N];   long long T[4 * N];   set<pair<int, int> > S;   set<pair<int, int> >::iterator it;   int sum(int v, int tl, int tr, int x) {     if (tl > x || tr <= x) return 0;     if (tl == tr - 1) return g[v];     int xy, yy;     xy = sum(v + v, tl, tl + tr >> 1, x);     yy = sum(v + v + 1, tl + tr >> 1, tr, x);     return max(xy, yy) + g[v];   }   void add(int v, int tl, int tr, int l, int r, int x) {     if (tl >= r || tr <= l) return;     if (l <= tl && tr <= r) {       g[v] += x;       return;     }     add(v + v, tl, tl + tr >> 1, l, r, x);     add(v + v + 1, tl + tr >> 1, tr, l, r, x);   }   void upd1(int v) {     if (t[v]) {       T[v + v] = T[v + v + 1] = T[v];       t[v + v + 1] = t[v + v] = t[v];       t[v] = false;     }   }   void update(int v, int tl, int tr, int l, int r, long long x) {     if (tl >= r || tr <= l) return;     upd1(v);     if (l <= tl && tr <= r) {       T[v] = x;       t[v] = true;       return;     }     update(v + v, tl, tl + tr >> 1, l, r, x);     update(v + v + 1, tl + tr >> 1, tr, l, r, x);     T[v] = (T[v + v] + T[v + v + 1]) % 1000000007ll;   }   long long get(int v, int tl, int tr, int l, int r) {     if (tl >= r || tr <= l) return 0;     upd1(v);     if (l <= tl && tr <= r) return T[v];     long long x, y;     x = get(v + v, tl, tl + tr >> 1, l, r);     y = get(v + v + 1, tl + tr >> 1, tr, l, r);     T[v] = (T[v + v] + T[v + v + 1]) % 1000000007ll;     return (x + y) % 1000000007ll;   }   int main() {     scanf( %d %d %d , &m, &n, &K);     for (int i = 0; i < K; ++i) {       scanf( %d %d , &b[i].first, &a[i].first);       scanf( %d %d , &b[i].second, &a[i].second);       A[b[i].first].push_back(i);       B[b[i].second + 1].push_back(i);     }     update(1, 1, n + 1, 1, 2, 1);     B[1].push_back(K);     a[K].second = n;     a[K].first = 1;     S.insert(make_pair(a[K].second, K));     add(1, 1, n + 1, 1, n + 1, 1);     for (int k = 1; k <= m; ++k) {       sort(A[k].begin(), A[k].end(), comp);       for (int i = 0; i < A[k].size(); ++i) {         int v = A[k][i];         int s = sum(1, 1, n + 1, a[v].second + 1);         if (s == 0) {           it = S.lower_bound(make_pair(a[v].second + 1, 0));           int l = 0;           if (it != S.begin()) {             it--;             l = (*it).first;           }           long long now = get(1, 1, n + 1, l + 1, a[v].second + 2);           now %= 1000000007ll;           update(1, 1, n + 1, a[v].second + 1, a[v].second + 2, now);         }         S.insert(make_pair(a[v].second, v));         add(1, 1, n + 1, a[v].first, a[v].second + 1, 1);         update(1, 1, n + 1, a[v].first, a[v].second + 1, 0);       }       for (int i = 0; i < B[k].size(); ++i) {         int v = B[k][i];         S.erase(make_pair(a[v].second, v));         add(1, 1, n + 1, a[v].first, a[v].second + 1, -1);       }     }     it = S.lower_bound(make_pair(n, 0));     int l = 0;     if (it != S.begin()) {       it--;       l = (*it).first;     }     long long answer = get(1, 1, n + 1, l + 1, n + 1) % 1000000007ll;     printf( %I64d n , answer);   }


#include <bits/stdc++.h>   using namespace std;   int const N = 22, M = 1 << 22;   inline int nextInt() {     char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     int n = 0, s = 1;     if (c ==  - ) s = -1, c = getchar();     while (c >=  0  && c <=  9 ) n *= 10, n += c -  0 , c = getchar();     return n * s;   }   int mx;   int parents[M];   int Find(int a) { return parents[a] < 0 ? a : parents[a] = Find(parents[a]); }   void Union(int a, int b) {     a = Find(a), b = Find(b);     if (a == b) return;     if (parents[a] < parents[b])       parents[a] += parents[b], parents[b] = a;     else       parents[b] += parents[a], parents[a] = b;   }   void init() { memset(parents, (0xff), sizeof parents); }   int q[M];   bool ck[M];   int vis[M];   int n, m;   queue<int> que;   void upd(int t) {     if (vis[t] != -1) return;     while (!que.empty()) que.pop();     que.push(t);     vis[t] = t;     while (!que.empty()) {       int x = que.front();       que.pop();       if (ck[x]) Union(t, ((1 << n) - 1) ^ x);       for (int j = 0; j < (n); ++j)         if ((x >> j & 1) == 0) {           int u = x ^ (1 << j);           if (ck[u]) Union(t, ((1 << n) - 1) ^ u);           if (vis[u] == -1) {             vis[u] = t;             que.push(u);           }         }     }   }   int main() {     n = nextInt();     m = nextInt();     for (int i = 0; i < (m); ++i) q[i] = nextInt();     init();     int mask = (1 << n) - 1;     memset(vis, (0xff), sizeof vis);     for (int i = 0; i < (m); ++i) {       int t = q[i];       if (vis[mask ^ t] != -1) {         Union(t, vis[mask ^ t]);       }       upd(t);       ck[mask ^ t] = 1;     }     int ans = 0;     for (int i = 0; i < (m); ++i)       if (q[i] == Find(q[i])) ++ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char ar[100];     int len, count = 0, i, j;     gets(ar);     len = strlen(ar);     if (isupper(ar[0]) && islower(ar[1])) {       cout << ar;     } else {       for (i = 0; ar[i] !=   0 ; i++) {         if (isupper(ar[i])) {           count++;         }       }       if (len == 1) {         if (islower(ar[0])) {           ar[0] = toupper(ar[0]);         } else if (isupper(ar[0])) {           ar[0] = tolower(ar[0]);         }       } else if (count == len) {         for (i = 0; ar[i] !=   0 ; i++) {           ar[i] = tolower(ar[i]);         }       } else if (count == len - 1) {         if (islower(ar[0])) {           for (i = 1; ar[i] !=   0 ; i++) {             ar[i] = tolower(ar[i]);             ar[0] = toupper(ar[0]);           }         }       }       cout << ar;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const long long CONST = 314000000LL;   const long long inf = (1LL << 60);   bool mark[MAXN], INF[MAXN], bad[MAXN];   int m, n, cntComp;   long long cnt[MAXN], func[MAXN], deg[MAXN], comp[MAXN], type[MAXN], len[MAXN];   long long mini[MAXN], maxi[MAXN];   vector<int> topol;   vector<int> adj[MAXN], bak[MAXN], Q[MAXN];   struct cmp {     inline bool operator()(const int &A, const int &B) {       return (mini[A] != mini[B]) ? (mini[A] < mini[B]) : (A < B);     }   };   inline void dfs(int v) {     if (mini[v] == inf) return;     mark[v] = true;     for (int i = 0; i < (int)adj[v].size(); i++)       if (!mark[adj[v][i]] && mini[adj[v][i]] != inf) dfs(adj[v][i]);     topol.push_back(v);   }   inline void DFS(int v) {     if (mini[v] == inf) return;     mark[v] = true;     comp[v] = cntComp;     for (int i = 0; i < (int)bak[v].size(); i++)       if (!mark[bak[v][i]] && mini[bak[v][i]] != inf) DFS(bak[v][i]);   }   inline bool cmp2(const int &A, const int &B) {     return comp[type[A]] > comp[type[B]];   }   int main() {     cin >> m >> n;     for (int i = 0; i < m; i++) {       cin >> type[i] >> len[i];       type[i]--;       for (int j = 0; j < len[i]; j++) {         int temp;         cin >> temp;         if (temp == -1)           deg[i]++, func[i]++;         else {           temp--;           Q[i].push_back(temp);           bak[temp].push_back(i);           cnt[i]++;         }       }     }     for (int i = 0; i < n; i++) mini[i] = inf;     set<int, cmp> SET;     for (int i = 0; i < m; i++)       if (cnt[i] == 0) {         if (deg[i] < mini[type[i]]) {           SET.erase(type[i]);           mini[type[i]] = deg[i];           SET.insert(type[i]);         }       }     while (!SET.empty()) {       int begin = *SET.begin();       SET.erase(SET.begin());       for (int i = 0; i < (int)bak[begin].size(); i++) {         int temp = bak[begin][i];         cnt[temp]--;         deg[temp] = min(CONST, deg[temp] + mini[begin]);         if (cnt[temp] == 0) {           if (deg[temp] < mini[type[temp]]) {             SET.erase(type[temp]);             mini[type[temp]] = deg[temp];             SET.insert(type[temp]);           }         }       }     }     for (int i = 0; i < n; i++) adj[i].clear(), bak[i].clear();     for (int i = 0; i < m; i++)       if (mini[type[i]] != inf) {         bad[i] = false;         for (int j = 0; j < (int)Q[i].size(); j++)           if (mini[Q[i][j]] == inf) bad[i] = true;         if (!bad[i]) {           for (int j = 0; j < (int)Q[i].size(); j++) {             adj[type[i]].push_back(Q[i][j]);             bak[Q[i][j]].push_back(type[i]);           }         }       }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs(i);     memset(mark, false, sizeof mark);     for (int i = (int)topol.size() - 1; i >= 0; i--)       if (!mark[topol[i]]) {         cntComp++;         DFS(topol[i]);       }     vector<int> perm;     for (int i = 0; i < m; i++) perm.push_back(i);     sort(perm.begin(), perm.end(), cmp2);     for (int o = 0; o < m; o++)       if (!bad[perm[o]]) {         int index = perm[o];         long long sum = min(CONST, func[index]);         for (int j = 0; j < (int)Q[index].size(); j++) {           int temp = Q[index][j];           if (comp[temp] == comp[type[index]])             INF[comp[type[index]]] = true;           else if (INF[comp[temp]])             INF[comp[type[index]]] = true;           else             sum = min(CONST, sum + maxi[temp]);         }         maxi[type[index]] = max(maxi[type[index]], sum);       }     for (int i = 0; i < n; i++) {       if (mini[i] == inf) {         cout << -1 <<     << -1 << endl;         continue;       }       cout << min(CONST, mini[i]) <<    ;       if (INF[comp[i]])         cout << -2 << endl;       else         cout << min(CONST, maxi[i]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     stack<int> s1;     int ans = 0;     int x = 1;     for (int i = 0; i < (2 * n); i++) {       char s[10];       scanf( %s , s);       if (strlen(s) == 3) {         int a;         scanf( %d , &a);         s1.push(a);       } else {         if (strlen(s) == 6 && !s1.empty() && s1.top() != x) {           while (!s1.empty()) s1.pop();           ans++;         } else {           if (!s1.empty()) s1.pop();         }         x++;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int data[(int)2e5];   int dp[5001][5001];   int used[5001][5001];   string s;   int magic(int l, int r) {     if (l > r) return 1;     if (used[l][r] != -1) return used[l][r];     if (l == r) {       data[1]++;       return used[l][r] = 1;     }     int lk, rk, k, flag = 1, middle = (l + r) / 2;     lk = magic(l, (r - l) % 2 == 0 ? (middle - 1) : middle);     rk = magic(middle + 1, r);     k = min(lk, rk) + 1;     if (s[l] == s[r] and magic(l + 1, r - 1)) {       for (int i = 1; i <= k; i++) data[i]++;       return used[l][r] = k;     }     return used[l][r] = 0;   }   int main() {     memset(used, -1, sizeof(used));     cin >> s;     int n = s.size() - 1;     for (int i = 0; i <= n; i++) {       for (int j = i; j <= n; j++) magic(i, j);     }     for (int i = 1; i <= s.size(); i++) cout << data[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, r, m, t, pr;   int poc, kraj, uk;   int drvo[2000], sveca[2000];   void apdejt(int a, int b) {     while (a <= 2000) {       drvo[a] += b;       a += (a & -a);     }   }   int koliko(int a) {     int zbir = 0;     while (a > 0) {       zbir += drvo[a];       a -= (a & -a);     }     return zbir;   }   void solve() {     cin >> m >> t >> r;     uk = 0;     for (int i = 0; i < m; i++) {       cin >> a;       a += 500;       if (koliko(a) >= r) continue;       kraj = r - koliko(a);       for (int j = 0; j < kraj; j++) {         x = -1;         for (int z = a - 1; z >= a - t; z--) {           if (sveca[z] == 0) {             sveca[z] = 1;             uk++;             apdejt(z, 1);             apdejt(z + t + 1, -1);             x = 1;             break;           }         }         if (x == -1) {           cout <<  -1  << endl;           return;         }       }     }     cout << (uk) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     cout << s;     for (int i = s.size() - 1; i >= 0; i--) {       cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   struct edge {     int u, v, w, num;   } e[N], c[N];   map<long long, int> mp;   int n, m, q, s, siz[N], fa[N];   long long L[N], R[N];   bool vis[N];   int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }   bool comp(edge x, edge y) { return x.w < y.w; }   int main() {     int i, j, k, x, num;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &c[i].u, &c[i].v, &c[i].w);       c[i].num = i;     }     sort(c + 1, c + 1 + m, comp);     for (i = 1; i <= m; i++) siz[c[i].num] = i;     for (i = 1; i <= m; i = j + 1) {       for (j = i; j < m && c[j + 1].w == c[i].w; j++)         ;       for (k = i; k <= j; k++)         L[c[k].num] = 1LL * c[k].w * m + find(c[k].u),         R[c[k].num] = 1LL * c[k].w * m + find(c[k].v);       for (k = i; k <= j; k++)         if (find(c[k].u) != find(c[k].v)) fa[find(c[k].u)] = find(c[k].v);     }     memset(fa, 0, sizeof(fa));     scanf( %d , &q);     for (i = 1; i <= q; i++) {       scanf( %d , &s);       mp.clear();       bool flag = true;       num = 0;       for (j = 1; j <= s; j++) {         scanf( %d , &x);         if (!mp[L[x]]) fa[mp[L[x]] = ++num] = 0;         if (!mp[R[x]]) fa[mp[R[x]] = ++num] = 0;         if (find(mp[L[x]]) == find(mp[R[x]]))           flag = 0;         else           fa[find(mp[L[x]])] = find(mp[R[x]]);       }       puts(flag ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const int sz = 3;   const double eps = 1e-9;   const int maxn = 1e3 + 500, base = 1e9 + 7, maxm = 10;   string second[maxn];   int main() {     ios_base::sync_with_stdio(0);     ;     cin.tie(0);     int n;     cin >> n;     if (n == 1) {       cout << 6 << endl;       return 0;     }     int k = inf;     for (int i = 0; i < n; i++) cin >> second[i];     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         int eq = 0;         for (int b = 0; b < 6; b++)           if (second[i][b] == second[j][b]) eq++;         if (eq == 0 || eq == 1) k = min(k, 2);         if (eq == 3 || eq == 2) k = min(k, 1);         if (eq >= 4) k = min(k, 0);       }     cout << k;   }


#include <bits/stdc++.h>   const long base = 151;   const long long MM = 1ll * 1000000007 * 1000000007;   using namespace std;   int BIT(int i, long long x) { return (x & (1 << i)); }   long long ONBIT(int i, long long x) { return (x | (1 << i)); }   long long OFFBIT(int i, long long x) { return (x & ~(1 << i)); }   long long FLIPBIT(int i, long long x) { return (x ^ (1 << i)); }   long long NUMBIT(long long x) { return __builtin_popcount(x); }   template <class T>   T GCD(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T LCM(T a, T b) {     return a / GCD(a, b) * b;   }   void read() {     int x, y, u, v;     long long ans = 1;     cin >> x >> y >> u >> v;     int s1 = u - x;     int s2 = v - y;     long long tmp = min(s1, s2) - 1;     ans += (tmp + 1) * (abs(s2 - s1) + 1);     ans += (tmp + 1) * tmp;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long te;     cin >> te;     while (te--) read();   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = 3.1415926535897932384626;   const double e = exp(1.0);   int main() {     int t;     double a, b, c;     double x, y, z;     double s;     while (~scanf( %lf , &s)) {       scanf( %lf%lf%lf , &a, &b, &c);       double tt = a + b + c;       if (tt == 0) {         x = y = 0;         z = s;       } else {         x = s * (a * 1.0 / tt);         y = s * (b * 1.0 / tt);         z = s * (c * 1.0 / tt);       }       printf( %.10lf %.10lf %.10lf n , x, y, z);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int nxt() {     int wow;     scanf( %d , &wow);     return wow;   }   inline long long int lxt() {     long long int wow;     scanf( %lld , &wow);     return wow;   }   inline double dxt() {     double wow;     scanf( %lf , &wow);     return wow;   }   int main() {     int n = nxt(), a[100];     for (int i = 1; i <= n; i++) a[i] = nxt();     if (a[n] == 15) {       puts( DOWN );       return 0;     }     if (a[n] == 0) {       puts( UP );       return 0;     }     if (n == 1) {       puts( -1 );       return 0;     }     if (a[n] > a[n - 1])       puts( UP );     else       puts( DOWN );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long RAND(long long n) { return abs((rand() << 15) + rand()) % n; }   bool check(int i, int j, int n) {     return ((i >= 0) && (j >= 0) && (i < n) && (j < n));   }   int move_x[] = {1, 0};   int move_y[] = {0, 1};   vector<vector<vector<vector<bool>>>> solve(vector<vector<int>> &a) {     int n = a.size();     vector<vector<vector<vector<bool>>>> ans(         n, vector<vector<vector<bool>>>(                n, vector<vector<bool>>(n, vector<bool>(n, false))));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         ans[i][j][i][j] = true;       }     }     for (int len = 1; len <= 2 * n - 2; ++len) {       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           for (int x = 0; x <= len; ++x) {             int k = i + x, t = j + len - x;             if (!check(k, t, n) || a[i][j] != a[k][t]) {               continue;             }             if ((abs(k - i) + abs(t - j)) == 1) {               ans[i][j][k][t] = true;               continue;             }             for (int i1 = 0; i1 < 2; ++i1) {               for (int i2 = 0; i2 < 2; ++i2) {                 int next_x = i + move_x[i1], next_y = j + move_y[i1];                 int prev_x = k - move_x[i2], prev_y = t - move_y[i2];                 if (!check(next_x, next_y, n) || !check(prev_x, prev_y, n)) {                   continue;                 }                 if (next_x > prev_x || next_y > prev_y) {                   continue;                 }                 if (ans[next_x][next_y][prev_x][prev_y]) {                   ans[i][j][k][t] = ans[next_x][next_y][prev_x][prev_y];                 }               }             }           }         }       }     }     return ans;   }   int query(int i, int j, int t, int k) {     i++;     j++;     t++;     k++;     cout <<  ?   << i <<     << j <<     << t <<     << k << endl << flush;     int ans;     cin >> ans;     if (ans == -1) {       exit(0);     }     return !ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<vector<int>> a(n, vector<int>(n, 0));     a[0][0] = 1;     a[n - 1][n - 1] = 0;     for (int i = 2; i < n; ++i) {       a[0][i] = a[0][i - 2] ^ query(0, i - 2, 0, i);     }     a[1][0] = a[0][1] ^ query(0, 1, 1, 2) ^ query(1, 0, 1, 2);     for (int i = 2; i < n; ++i) {       a[i][0] = a[i - 2][0] ^ query(i - 2, 0, i, 0);     }     for (int i = 1; i < n; ++i) {       for (int j = 1; j < n; ++j) {         a[i][j] = a[i - 1][j - 1] ^ query(i - 1, j - 1, i, j);       }     }     vector<vector<int>> b = a;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if ((i + j) % 2 == 1) {           b[i][j] = 1 - a[i][j];         }       }     }     vector<vector<vector<vector<bool>>>> A = solve(a);     vector<vector<vector<vector<bool>>>> B = solve(b);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         for (int k = i; k < n; ++k) {           for (int t = j; t < n; ++t) {             if ((abs(k - i) + abs(t - j)) < 2) {               continue;             }             if (A[i][j][k][t] ^ B[i][j][k][t]) {               if (!query(i, j, k, t) == A[i][j][k][t]) {                 cout <<  ! n ;                 for (int i = 0; i < n; ++i) {                   for (int j = 0; j < n; ++j) {                     cout << a[i][j];                   }                   cout << endl;                 }                 return 0;               } else {                 swap(a, b);                 cout <<  ! n ;                 for (int i = 0; i < n; ++i) {                   for (int j = 0; j < n; ++j) {                     cout << a[i][j];                   }                   cout << endl;                 }                 return 0;               }             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int d, n;     cin >> d >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int day = 0, res = 0;     for (int i = 0; i < n; i++) {       day = (day + a[i] - 1) % d + 1;       if (day != a[i]) {         if (day < a[i])           res += a[i] - day;         else           res += d - day + a[i];         day = a[i];       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void umin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T gcd(T a, T b) {     return __gcd(a, b);   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int inf = 1e9 + 143;   const long long longinf = 1e18 + 143;   inline int read() {     int x;     scanf(  %d , &x);     return x;   }   const int N = 1e6 + 100;   int p[N], sz[N];   int get(int x) {     if (x == p[x]) return x;     return p[x] = get(p[x]);   }   int main() {     int n = read();     int m = read();     int mod = read();     for (int i = 1; i <= n; i++) p[i] = i;     for (int i = 1; i <= m; i++) {       int a = read();       int b = read();       a = get(a);       b = get(b);       if (a != b) {         p[a] = b;       }     }     vector<int> trees;     for (int i = 1; i <= n; i++) {       sz[get(i)] += 1;     }     for (int i = 1; i <= n; i++) {       if (i == get(i)) {         trees.push_back(sz[i]);       }     }     if (trees.size() == 1) {       printf( %d n , 1 % mod);       return 0;     }     int res = 1;     for (int i = 1; i <= (int)trees.size() - 2; i++)       res = (long long)res * n % mod;     for (int i = 0; i < trees.size(); i++) res = (long long)res * trees[i] % mod;     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modular(long long int n, long long int pow, long long int N) {     long long int res = 1;     while (pow) {       if (pow & 1) res = (res % N * n % N) % N;       n = (n % N * n % N) % N;       pow = pow / 2;     }     return res;   }   long long int d, x, y;   void extendedEuclid(long long int A, long long int B) {     if (B == 0) {       d = A;       x = 1;       y = 0;     } else {       extendedEuclid(B, A % B);       long long int temp = x;       x = y;       y = temp - (A / B) * y;     }   }   long long int modInverse(long long int A, long long int N) {     extendedEuclid(A, N);     return (x % N + N) % N;   }   int main() {     long long int n, i;     cin >> n;     vector<pair<long long int, long long int>> v;     for (i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v.push_back({x, y});     }     long long int ans = min(v[n - 1].first, v[n - 1].second);     long long int flag = 0;     for (i = n - 2; i >= 0; i--) {       if (v[i].second >= ans && v[i].first >= ans)         ans = min(v[i].second, v[i].first);       else if (v[i].second >= ans)         ans = v[i].second;       else if (v[i].first >= ans)         ans = ans = v[i].first;       else {         flag = 1;         break;       }     }     if (flag == 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, m;   int head[N], nxt[N * 2], to[N * 2], tot;   int vis[N], stp[N];   int dp[N][20];   int dfn[N], low[N], dep = 0;   int stk[N * 5], top = 0;   int belong[N], block = 0;   int odd[N], col[N];   void init() {     memset(head, -1, sizeof(head));     tot = 0;   }   void add(int x, int y) {     to[tot] = y;     nxt[tot] = head[x];     head[x] = tot++;   }   void DFS_st(int u, int fa) {     vis[u] = 1;     stp[u] = stp[fa] + 1;     dp[u][0] = fa;     for (int i = 1; i < 20; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1];     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (!vis[v]) DFS_st(v, u);     }   }   void tarjan(int u, int fa) {     dfn[u] = low[u] = ++dep;     stk[top++] = u;     vis[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (v == fa) continue;       if (!dfn[v]) {         tarjan(v, u);         low[u] = min(low[u], low[v]);       } else if (vis[v])         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       block++;       do {         top--;         belong[stk[top]] = block;         vis[stk[top]] = 0;       } while (stk[top] != u);     }   }   void DFS(int u, int fa) {     vis[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (!vis[v]) {         col[v] += col[u];         DFS(v, u);       }     }   }   int LCA(int x, int y) {     if (stp[x] < stp[y]) swap(x, y);     int delta = stp[x] - stp[y];     for (int i = 0; i < 20; i++)       if (delta & (1 << i)) x = dp[x][i];     if (x == y) return x;     for (int i = 19; i >= 0; i--)       if (dp[x][i] != dp[y][i]) x = dp[x][i], y = dp[y][i];     return dp[x][0];   }   int main() {     init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int u = 1; u <= n; u++)       if (!vis[u]) DFS_st(u, 0);     memset(vis, 0, sizeof(vis));     for (int u = 1; u <= n; u++)       if (!dfn[u]) tarjan(u, 0);     for (int u = 1; u <= n; u++) {       if (!odd[belong[u]]) {         for (int i = head[u]; ~i; i = nxt[i]) {           int v = to[i];           if ((stp[u] + stp[v]) % 2 == 0 && belong[v] == belong[u]) {             odd[belong[u]] = 1;             break;           }         }       }     }     for (int u = 1; u <= n; u++)       if (belong[u] == belong[dp[u][0]] && dp[u][0] != 0 && odd[belong[u]])         col[u]++;     memset(vis, 0, sizeof(vis));     for (int u = 1; u <= n; u++)       if (!vis[u]) DFS(u, 0);     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       int lca = LCA(u, v);       if (lca == 0) {         printf( No n );       } else if ((stp[u] + stp[v] - stp[lca] * 2) % 2 == 1)         printf( Yes n );       else {         if (col[u] + col[v] != col[lca] * 2)           printf( Yes n );         else           printf( No n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p[8][10020];   int main() {     int n;     int l[8], r[8];     scanf( %d , &n);     double ex = 0;     double all = 1.0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &l[i], &r[i]);       all *= (r[i] - l[i] + 1);     }     for (int i = 1; i <= 10000; ++i) {       double cr = 0;       for (int j = 0; j < n; ++j) {         if (r[j] < i || l[j] > i) continue;         for (int k = 0; k < n; ++k) {           if (k == j) continue;           double t = 1.0;           if (k < j) {             if (r[k] < i) continue;             t *= (r[k] - max(i, l[k]) + 1);           } else {             if (r[k] <= i) continue;             t *= (r[k] - max(i + 1, l[k]) + 1);           }           for (int s = 0; s < n; ++s) {             if (s == j || s == k) continue;             if (s < j) {               if (l[s] >= i) {                 t = 0;                 break;               }               t *= (min(r[s], i - 1) - l[s] + 1);             } else {               if (l[s] > i) {                 t = 0;                 break;               }               t *= (min(r[s], i) - l[s] + 1);             }           }           if (t != 0) {           }           cr += t;         }       }       ex += cr / all * i;     }     printf( %.15lf n , ex);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n, m;     cin >> n >> m;     int a0, b0, x;     for (int i = 0; i < n + 1; i++) {       cin >> x;       if (!i) a0 = x;     }     for (int i = 0; i < m + 1; i++) {       cin >> x;       if (!i) b0 = x;     }     if (n > m) {       int sign;       if (a0 < 0 && b0 > 0 || a0 > 0 && b0 < 0) cout <<  - ;       cout <<  Infinity n ;     } else if (n < m) {       cout <<  0/1 n ;     } else {       int sign;       if (a0 < 0 && b0 < 0 || a0 > 0 && b0 > 0)         sign = 1;       else         sign = -1;       a0 = abs(a0);       b0 = abs(b0);       int g = gcd(a0, b0);       a0 /= g;       b0 /= g;       a0 *= sign;       cout << a0 <<  /  << b0 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MX = 2e5 + 1;   bool sieve[MX], in_graph[MX], vstd[MX];   vector<int> pos[MX], adj[MX];   int mu[MX];   ll res[MX];   void init() {     vector<int> primes;     mu[1] = 1;     for (int i = 2; i < MX; ++i) {       if (!sieve[i]) {         mu[i] = -1;         primes.push_back(i);       }       for (auto j : primes) {         if (i * j >= MX) break;         sieve[i * j] = true;         if (i % j == 0) {           mu[i * j] = 0;           break;         }         mu[i * j] = -mu[i];       }     }   }   int dfs(int u, int p) {     int res = 1;     vstd[u] = true;     for (auto c : adj[u]) {       if (c == p || !in_graph[c]) continue;       res += dfs(c, u);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       pos[a].push_back(i);     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i < MX; ++i) {       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           in_graph[k] = true;         }       }       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           if (!vstd[k]) {             ll cnt = dfs(k, 0);             res[i] += cnt * (cnt + 1) / 2;           }         }       }       for (int j = i; j < MX; j += i) {         for (auto k : pos[j]) {           in_graph[k] = false;           vstd[k] = false;         }       }     }     for (int i = 1; i < MX; ++i) {       ll ans = 0;       for (int j = 1; j * i < MX; ++j) {         ans += mu[j] * res[j * i];       }       if (ans) {         cout << i <<     << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, low, high, chs;   long long x1up, x2up, x1down, x2down, y1down, y2down, y1up, y2up;   int query(long long x, long long y, long long xx, long long yy) {     cout <<  ?   << x <<     << y <<     << xx <<     << yy << endl;     cout << flush;     int res;     cin >> res;     return res;   }   int query2(long long x, long long y, long long xx, long long yy) {     int res = query(x, y, xx, yy);     if (x <= x1down && y <= y1down && xx >= x1up && yy >= y1up) res--;     return res;   }   int main() {     cin >> n;     low = 1;     high = n;     while (low < high) {       chs = (low + high) / 2;       int res = query(1, 1, n, chs);       if (res == 0)         low = chs + 1;       else         high = chs;     }     y1up = low;     low = 1;     high = n;     while (low < high) {       chs = (low + high) / 2;       int res = query(1, 1, chs, y1up);       if (res == 0)         low = chs + 1;       else         high = chs;     }     x1up = low;     low = 1;     high = x1up;     while (low <= high) {       chs = (low + high) / 2;       int res = query(chs, 1, x1up, y1up);       if (res != 0) {         low = chs + 1;         x1down = chs;       } else         high = chs - 1;     }     low = 1;     high = y1up;     while (low <= high) {       chs = (low + high) / 2;       int res = query(x1down, chs, x1up, y1up);       if (res != 0) {         low = chs + 1;         y1down = chs;       } else         high = chs - 1;     }     low = 1;     high = n;     while (low < high) {       chs = (low + high) / 2;       int res = query2(1, 1, n, chs);       if (res == 0)         low = chs + 1;       else         high = chs;     }     y2up = low;     low = 1;     high = n;     while (low < high) {       chs = (low + high) / 2;       int res = query2(1, 1, chs, y2up);       if (res == 0)         low = chs + 1;       else         high = chs;     }     x2up = low;     low = 1;     high = x2up;     while (low <= high) {       chs = (low + high) / 2;       int res = query2(chs, 1, x2up, y2up);       if (res != 0) {         low = chs + 1;         x2down = chs;       } else         high = chs - 1;     }     low = 1;     high = y2up;     while (low <= high) {       chs = (low + high) / 2;       int res = query2(x2down, chs, x2up, y2up);       if (res != 0) {         low = chs + 1;         y2down = chs;       } else         high = chs - 1;     }     cout <<  !   << x1down <<     << y1down <<     << x1up <<     << y1up <<              << x2down <<     << y2down <<     << x2up <<     << y2up << endl;     cout << flush;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 998244353;   const long long int INF = 3e18;   long long int power(long long int base, long long int exp) {     long long int res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base);       base = (base * base);       exp /= 2;     }     return res;   }   long long int bitc(long long int n, long long int x) { return ((n >> x) & 1); }   long long int __gcd(long long int a, long long int b) {     return b == 0 ? a : __gcd(b, a % b);   }   long long int fsub(long long int a, long long int b, long long int p = MOD) {     return ((a % p) - (b % p) + p) % p;   }   long long int fmult(long long int a, long long int b, long long int p = MOD) {     return ((((a % p) * (b % p)) % p) + p) % p;   }   long long int fadd(long long int a, long long int b, long long int p = MOD) {     return ((a % p + b % p) % p + p) % p;   }   long long int fpow(long long int n, long long int k, long long int p = MOD) {     long long int r = 1;     while (k > 0) {       if (k & 1) r = r * n % p;       n = n * n % p;       k = k >> 1;     }     return r;   }   long long int inv(long long int a, long long int p = MOD) {     return fpow(a, p - 2, p);   }   long long int fdiv(long long int a, long long int b, long long int p = MOD) {     long long int yinv = inv(b);     long long int ans = (a * yinv) % p;     return ((ans) % p + p) % p;   }   long long int ceil(long long int a, long long int b) {     return ceil((long double)a / b);   }   template <typename T>   istream &operator>>(istream &in, vector<T> &a) {     for (auto &item : a) {       in >> item;     }     return in;   }   template <typename T, typename U>   ostream &operator<<(ostream &out, pair<T, U> &a) {     cout << a.first <<     << a.second;     return out;   }   template <typename T, typename U>   istream &operator>>(istream &out, pair<T, U> &a) {     cin >> a.first >> a.second;     return out;   }   template <typename T, typename U>   ostream &operator<<(ostream &out, map<T, U> &a) {     for (auto &item : a) {       out << item <<   n ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> &a) {     for (auto &item : a) {       out << item <<    ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, vector<vector<T>> &a) {     for (auto &item : a) {       out << item <<   n ;     }     return out;   }   template <int D, typename T>   struct Vec : public vector<Vec<D - 1, T>> {     static_assert(D >= 1,  Vector dimension must be greater than zero! );     template <typename... Args>     Vec(int n = 0, Args... args)         : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}   };   template <typename T>   struct Vec<1, T> : public vector<T> {     Vec(int n = 0, T val = T()) : vector<T>(n, val) {}   };   std::vector<bool> is_prime;   std::vector<long long int> primes;   void sieve(long long int n) {     is_prime.resize(n + 2, true);     primes.clear();     long long int p;     for (p = 2; p * p <= n; p++) {       if (is_prime[p]) {         long long int i;         for (i = p * p; i <= n; i += p) {           is_prime[i] = false;         }       }     }     is_prime[0] = is_prime[1] = false;     long long int i;     for (i = 2; i <= n; i++) {       if (is_prime[i]) {         primes.emplace_back(i);       }     }   }   map<long long int, long long int> prime_factors(long long int n) {     map<long long int, long long int> s;     long long int i;     long long int tc = 0;     while (n % 2 == 0) {       tc++;       n /= 2;     }     if (tc > 0) {       s[2] = tc;     }     for (i = 3; i <= sqrt(n); i += 2) {       tc = 0;       while (n % i == 0) {         tc++;         n /= i;       }       if (tc > 0) {         s[i] = tc;       }     }     if (n > 2) {       s[n] += 1;     }     return s;   }   std::vector<long long int> fact_vec;   void fact_fun(long long int n) {     fact_vec.resize(n + 10);     long long int i;     fact_vec[0] = 1;     for (i = 1; i <= n + 2; i++) {       fact_vec[i] = (fact_vec[i - 1] * i) % MOD;     }   }   std::vector<long long int> p2;   void power_2(long long int n, long long int m = MOD) {     long long int i;     p2.emplace_back(1);     for (i = 0; i < n; i++) {       p2.emplace_back(fmult(p2.back(), 2));     }   }   long long int ncr(long long int n, long long int r) {     if (r > n) return 0;     return fdiv(fact_vec[n], fmult(fact_vec[r], fact_vec[n - r]));   }   std::vector<long long int> spf;   void sieve2(long long int MAXN) {     MAXN += 10;     spf.resize(MAXN, 0);     spf[1] = 1;     for (long long int i = 2; i < MAXN; i++) spf[i] = i;     for (long long int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (long long int i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (long long int j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   const int mi[4] = {-1, 0, 1, 0}, mj[4] = {0, 1, 0, -1};   const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},             d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};   map<long long int, long long int> getFactorization(long long int x) {     map<long long int, long long int> ret;     while (x != 1) {       ret[spf[x]]++;       x = x / spf[x];     }     return ret;   }   class Sol {    public:     Sol() { long long int i, j; }   };   int main() {     long long int i, j;     ios::sync_with_stdio(false);     cin.tie(0);     long long int ti;     ti = 1;     while (ti--) {       long long int n;       cin >> n;       std::vector<long long int> v(n * 2);       cin >> v;       sort((v).begin(), (v).end());       fact_fun(3e5 + 3);       long long int tp = ncr(2 * n, n);       long long int f = 0;       long long int s = 0;       for (i = 0; i < n; i++) {         f += v[i];       }       for (i = n; i < 2 * n; i++) {         s += v[i];       }       s -= f;       tp = fmult(s, tp);       cout << tp <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, prindex, k, kingdom, ki, prince;     cin >> t;     for (int h = 0; h < t; h++) {       cin >> n;       vector<int> vec(n + 7, 0);       prindex = 0, k, kingdom, ki, prince = 1;       for (int i = 1; i <= n; i++) {         cin >> k;         ki = 0;         for (int j = 0; j < k; j++) {           cin >> kingdom;           if (ki == 0 and vec[kingdom] == 0) {             vec[kingdom]++;             ki++;           }         }         if (ki == 0) prindex = i;       }       for (int i = 1; i <= n and vec[i] != 0; i++) prince = i + 1;       if (prindex > 0)         cout <<  IMPROVE               <<   n               << prindex <<     << prince <<   n ;       else         cout <<  OPTIMAL               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = (int)2e6 + 1, inf = (int)2e9 + 1;   map<char, int> pidr;   int n, m, ans, cur, sz, a[maxn], b, l[maxn], r[maxn], x[maxn];   bool used[maxn];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       cin >> l[i] >> r[i] >> x[i];     }     for (int i = 1; i <= m; i++) {       cur = 0;       for (int j = l[i]; j <= r[i]; j++)         if (a[j] < a[x[i]]) cur++;       if (l[i] + cur == x[i])         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 7;   const long double EPS = 1e-8;   const long long MAXI = 20000;   const long long MOD = 16714589;   const long long MAXST = 2000000;   const long double PI = 3.14159265358979323;   ostream &operator<<(ostream &stream, const pair<long long, long long> &p) {     stream << p.first <<     << p.second <<    ;     return stream;   }   bool u[30];   signed main() {     {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout << fixed << setprecision(10);       cerr << fixed << setprecision(10);     };     long long n, m;     cin >> m >> n;     for (long long i = 0; i < n; i++) {       cout << m <<   n ;       cout.flush();       long long x;       cin >> x;       if (x == 0 || x == -2)         exit(0);       else if (x == 1)         u[i] = true;       else         u[i] = false;     }     long long left = 1, right = m;     for (long long i = 0; left < right - 1; i++) {       long long mid = (left + right) / 2;       cout << mid <<   n ;       cout.flush();       long long x;       cin >> x;       if (x == 0 || x == -2) exit(0);       if (u[i % n]) {         if (x == 1)           right = mid;         else           left = mid;       } else {         if (x == 1)           left = mid;         else           right = mid;       }     }     cout << left <<   n ;     cout.flush();     long long x;     cin >> x;     if (x == 0 || x == -2) exit(0);     cout << right <<   n ;     cout.flush();     cin >> x;     if (x == 0 || x == -2) exit(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool asdfill[1100000];   int main() {     int n;     cin >> n;     int last_known;     for (int i = 0; i < (n); ++i) {       int a;       cin >> a;       asdfill[a] = true;       last_known = a;     }     double min_alpha = 10;     double max_alpha = 1e200;     int fills_done = 1;     for (int p = 1;; ++p) {       double alpha = (p * 10 + 10.0) / fills_done;       if (p <= last_known) {         if (asdfill[p]) {           max_alpha = min(max_alpha, alpha);           ++fills_done;         } else {           min_alpha = max(min_alpha, alpha);         }       } else {         if (max_alpha <= alpha + 1e-8) {           cout <<  unique n  << p;           exit(0);         } else if (min_alpha <= alpha - 1e-8) {           cout <<  not unique ;           exit(0);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 100 * 1000 + 14;   vector<int> comp[MAXN], adj[MAXN];   set<int> res;   int ans = 0;   void dfs(int v) {     comp[ans].push_back(v);     auto it = res.begin();     while (it != res.end()) {       if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) {         int u = *it;         res.erase(u);         dfs(u);         it = res.upper_bound(u);       } else         it++;     }     return;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       adj[v].push_back(u);       adj[u].push_back(v);     }     for (int i = 1; i <= n; i++) res.insert(i);     while (!res.empty()) {       int v = *res.begin();       res.erase(v);       ans++;       dfs(v);     }     cout << ans <<   n ;     for (int i = 1; i <= ans; i++) {       cout << comp[i].size() <<    ;       for (auto u : comp[i]) cout << u <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<long long int> v;     for (int i = 0; i < n; i++) {       long long int x;       cin >> x;       v.push_back(x);     }     if (n > 1) {       cout <<  1 1  << endl;       cout << (long long int)(-1) * v[0] << endl;       cout <<  1   << n << endl;       cout <<  0  ;       for (int i = 1; i < n; i++) {         cout << (long long int)(-1) * n * v[i] <<    ;       }       cout << endl;       cout <<  2   << n << endl;       for (int i = 1; i < n; i++) {         cout << (long long int)(n - 1) * v[i] <<    ;       }       cout << endl;     } else {       cout <<  1 1  << endl;       cout << (-1) * v[0] << endl;       cout <<  1 1  << endl;       cout << 0 << endl;       cout <<  1 1  << endl;       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LIM = 200100;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> a(n);     int mini, maxi;     mini = 1e9 + 3;     maxi = 0;     for (auto &e : a) {       cin >> e;       mini = min(mini, e);       maxi = max(maxi, e);     }     cout << maxi - mini + 1 - n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   int n, a, b;   int main() {     cin >> n >> a >> b;     int table1_count = 0;     int table2_count = 0;     int one_two_count = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         bool is_sit = false;         if (table1_count < a) {           table1_count++;           is_sit = true;         }         if (!is_sit) {           if (table2_count < b) {             table2_count++;             one_two_count++;             is_sit = true;           }         }         if (!is_sit) {           if (one_two_count > 0) {             one_two_count--;             is_sit = true;           }         }         if (!is_sit) {           ans++;         }       } else {         if (table2_count < b) {           table2_count++;         } else {           ans += 2;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<bool> x;     vector<bool> y;     x.assign(n + 1, 1);     y.assign(n + 1, 1);     x[1] = 0;     y[1] = 0;     x[n] = 0;     y[n] = 0;     for (int i = 0; i < m; i++) {       int tmp_x, tmp_y;       scanf( %i %i , &tmp_x, &tmp_y);       x[tmp_x] = 0;       y[tmp_y] = 0;     }     int result = 0;     for (int i = 1; i <= n / 2; i++) {       if (i * 2 != n + 1) {         if (x[i] == 1) result++;         if (x[n - i + 1] == 1) result++;         if (y[i] == 1) result++;         if (y[n - i + 1] == 1) result++;       }     }     if (n % 2 == 1)       if ((x[n / 2 + 1] == 1) || (y[n / 2 + 1] == 1)) result++;     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 10;   const long long inf = 1ll << 60;   const long long mod = 1e9 + 7;   void GG() {     cout <<  Impossible n ;     exit(0);   }   long long mpow(long long a, long long n, long long mo = mod) {     long long re = 1;     while (n > 0) {       if (n & 1) re = re * a % mo;       a = a * a % mo;       n >>= 1;     }     return re;   }   long long inv(long long b, long long mo = mod) {     if (b == 1) return b;     return (mo - mo / b) * inv(mo % b, mo) % mo;   }   const int maxn = 1e6 + 5;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     long long a, b;     cin >> a >> b;     vector<pair<long long, long long> > re;     while (a != 1 || b != 1) {       if (a == b) {         GG();       }       if (a > b) {         long long tk = (a - 1) / b;         re.push_back({tk, 0});         a -= tk * b;       } else {         long long tk = (b - 1) / a;         re.push_back({tk, 1});         b -= tk * a;       }     }     for (int i = 0; i < (int)re.size(); ++i) {       cout << re[i].first << (re[i].second ?  B  :  A );     }   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int MAXN = 1e5 + 5, MAXSIZ = 3;   template <typename _T>   void read(_T &x) {     x = 0;     char s = getchar();     int f = 1;     while (s <  0  ||  9  < s) {       f = 1;       if (s ==  - ) f = -1;       s = getchar();     }     while ( 0  <= s && s <=  9 ) {       x = (x << 3) + (x << 1) + s -  0 , s = getchar();     }     x *= f;   }   template <typename _T>   void write(_T x) {     if (x < 0) {       putchar( - ), x = -x;     }     if (9 < x) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   struct matrix {     int mat[MAXSIZ][MAXSIZ], n, m;     matrix() { n = m = 0, memset(mat, 0, sizeof mat); }     matrix(const int N, const int M) { n = N, m = M, memset(mat, 0, sizeof mat); }     int *operator[](const int indx) { return mat[indx]; }     matrix operator*(matrix other) const {       matrix ret = matrix(n, other.m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if (mat[i][j])             for (int k = 1; k <= ret.m; k++) {               ret[i][k] += 1ll * mat[i][j] * other[j][k] % mod;               if (ret[i][k] > mod) ret[i][k] -= mod;             }       return ret;     }     bool operator==(matrix other) const {       if (n ^ other.n || m ^ other.m) return false;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if (mat[i][j] ^ other[i][j]) return false;       return true;     }     bool operator!=(matrix other) const { return !(*this == other); }     void operator*=(matrix other) { *this = *this * other; }   };   struct vector {     int vec[MAXSIZ], n;     vector() { n = 0, memset(vec, 0, sizeof vec); }     vector(const int N) { n = N, memset(vec, 0, sizeof vec); }     int &operator[](const int indx) { return vec[indx]; }     vector operator*(matrix other) const {       vector ret = vector(n);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= ret.n; j++) {           ret[i] += 1ll * vec[j] * other[j][i] % mod;           if (ret[i] > mod) ret[i] -= mod;         }       return ret;     }     vector operator+(vector other) const {       vector ret = *this;       for (int i = 1; i <= n; i++) {         ret[i] += other[i];         if (ret[i] > mod) ret[i] -= mod;       }       return ret;     }     void operator*=(matrix other) { *this = *this * other; }     void operator+=(vector other) { *this = *this + other; }   };   struct segmentTreeNode {     vector s;     matrix tag;   } segTree[MAXN << 2];   matrix I, B;   vector A;   int a[MAXN];   int N, M;   void upt(const int x) {     (segTree[x].s) = (segTree[x << 1].s) + (segTree[x << 1 | 1].s);   }   void prod(const int x, const matrix v) {     (segTree[x].s) *= v, (segTree[x].tag) *= v;   }   void normalize(const int x) {     if ((segTree[x].tag) != I)       prod(x << 1, (segTree[x].tag)), prod(x << 1 | 1, (segTree[x].tag)),           (segTree[x].tag) = I;   }   void init() {     I = matrix(2, 2);     for (int i = 1; i <= 2; i++) I[i][i] = 1;     B = matrix(2, 2);     B[1][1] = B[2][1] = B[1][2] = 1;     A = vector(2);     A[1] = 1;   }   matrix qkpow(matrix base, int indx) {     if (indx < 0) return I;     matrix ret = I;     while (indx) {       if (indx & 1) ret *= base;       base *= base, indx >>= 1;     }     return ret;   }   void build(const int u, const int l, const int r) {     if (l > r) return;     (segTree[u].tag) = I;     int mid = l + r >> 1;     if (l == r) {       (segTree[u].s) = A * qkpow(B, a[l] - 1);       return;     }     build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);     upt(u);   }   void update(const int x, const int l, const int r, const int segL,               const int segR, const matrix v) {     int mid = l + r >> 1;     if (segL <= l && r <= segR) {       prod(x, v);       return;     }     if (l == r) return;     normalize(x);     if (segL <= mid) update(x << 1, l, mid, segL, segR, v);     if (segR > mid) update(x << 1 | 1, mid + 1, r, segL, segR, v);     upt(x);   }   int query(const int x, const int l, const int r, const int segL,             const int segR) {     int mid = l + r >> 1, ret = 0;     if (segL <= l && r <= segR) return (segTree[x].s)[1];     if (l == r) return 0;     normalize(x);     if (segL <= mid) (ret += query(x << 1, l, mid, segL, segR)) %= mod;     if (segR > mid) (ret += query(x << 1 | 1, mid + 1, r, segL, segR)) %= mod;     return ret;   }   int main() {     matrix tmp;     int opt, optL, optR, optV;     init();     read(N), read(M);     for (int i = 1; i <= N; i++) read(a[i]);     build(1, 1, N);     while (M--) {       read(opt), read(optL), read(optR);       if (opt == 1) {         read(optV);         tmp = qkpow(B, optV);         update(1, 1, N, optL, optR, tmp);       } else         write(query(1, 1, N, optL, optR)), putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, x, y;   int main() {     cin >> a >> b;     x = a % b;     b = b - x;     cout << a + b;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 300002;   long long N;   int ans[MX], arr[MX], was[MX];   int take;   void f(int L, int R, int vL, int vR) {     if (L > R) return;     if (vL == vR) {       for (int i = L; i <= R; i++) {         ans[i] = vL;       }       return;     }     int mid = L + R, all = 0;     mid /= 2;     for (int i = 1; i <= N; i++) {       all++;       take++;       was[arr[i]] = take;       int now = 1;       while (i < N) {         if (was[arr[i + 1]] == take) {           i++;           continue;         }         if (now == mid) break;         now++;         was[arr[i + 1]] = take;         i += 1;       }     }     ans[mid] = all;     f(L, mid - 1, ans[mid], vR);     f(mid + 1, R, vL, ans[mid]);   }   int main() {     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> arr[i];     }     f(1, N, 1, N);     for (int i = 1; i <= N; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100010];   int sieve[100010];   int main() {     int n, i, j, m, x, a, b, ans, q, flag = 0, cnt = 0;     scanf( %d , &n);     for (i = 2; i <= n; i++) {       if (!sieve[i]) {         for (j = i * i; j <= n; j += i) sieve[j] = 1;         for (j = i; j <= n; j = j * i) {           arr[cnt++] = j;         }       }     }     printf( %d n , cnt);     for (i = 0; i < cnt; i++) printf( %d  , arr[i]);     if (cnt) printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a, b, k, v;   bool check(int x) { return min(x * k, (x + b)) * v >= a ? true : false; }   int main() {     scanf( %d%d%d%d , &k, &a, &b, &v);     for (int i = 1; i <= 1000; i++) {       if (check(i)) {         printf( %d n , i);         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void snum(long long &x) { scanf( %lld , &x); }   void snum(long long &x, long long &y) { scanf( %lld %lld , &x, &y); }   void snum(long long &x, long long &y, long long &z) {     scanf( %lld %lld %lld , &x, &y, &z);   }   vector<long long> adj[100100];   long long outDegree[100100];   long long out[100100];   bool vis[100100];   void dfs(long long u) {     vis[u] = true;     long long aux = 0;     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (!vis[v]) {         aux++;         dfs(v);       }     }     out[u] = outDegree[u] = aux;   }   long long n;   long long cant[100100];   long long need[100100];   void bfs() {     deque<long long> q;     for (long long i = 0; i < n; i++) {       if (outDegree[i] == 0) {         q.push_back(i);         cant[i]++;       }     }     while (!q.empty()) {       long long u = q.front();       q.pop_front();       for (long long i = 0; i < adj[u].size(); i++) {         long long v = adj[u][i];         outDegree[v]--;         if (outDegree[v] >= 0) {           cant[v] += cant[u];         }         if (outDegree[v] == 0) {           q.push_back(v);         }       }     }   }   void doit() {     snum(n);     for (long long i = 0; i < n - 1; i++) {       long long x;       snum(x);       x--;       adj[i + 1].push_back(x);       adj[x].push_back(i + 1);     }     dfs(0);     bfs();     for (long long i = 0; i < n; i++) {       need[cant[i]]++;     }     for (long long i = 1; i <= n; i++) {       long long x = need[i];       for (long long j = 0; j < x; j++) {         printf( %lld  , i);       }     }   }   int main() {     long long T = 1;     while (T--) {       doit();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     stack<int> s;     int n;     cin >> n;     int max_ = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       max_ = max(max_, a);       if (s.empty()) {         s.push(a);       } else {         if (a == s.top()) {           s.pop();         } else if (a < s.top()) {           s.push(a);         } else           break;       }     }     if (s.size() == 0)       cout <<  YES ;     else if (s.size() > 1)       cout <<  NO ;     else {       if (max_ == s.top())         cout <<  YES ;       else         cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, dp[2009][2009], cnt;   long long int solve(int pos, int mx) {     if (pos == k) return 1;     long long int &res = dp[pos][mx];     if (res != -1) return res;     res = 0;     int lim = mx;     if (lim == 0) lim = 1;     if (mx == 0) {       for (int i = lim; i <= n; i += lim) {         res += solve(pos + 1, i);         res %= 1000000007;       }     } else {       for (int i = lim; i <= n; i += lim) {         if (i % mx == 0) {           res += solve(pos + 1, i);           res %= 1000000007;         }       }     }     return res;   }   int main() {     cin >> n >> k;     memset(dp, -1, sizeof(dp));     long long int ans = solve(0, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const long double EPS = 1e-9;   vector<vector<int>> g;   vector<vector<int>> hlca;   vector<vector<int>> lca;   vector<vector<long long>> dp;   int N;   int get_num_bit(int mask) {     int cnt = 0;     while (mask) {       cnt += mask & 1;       mask >>= 1;     }     return cnt;   }   long long f(int root, int mask) {     if (dp[root][mask] != -1) return dp[root][mask];     if (get_num_bit(mask) == 1) {       return dp[root][mask] = 1;     }     long long res = 0;     int osnmask = mask - (1 << root);     int nmask = osnmask;     while (nmask) {       int nmask1 = mask ^ nmask;       for (int nr = 0; nr < N; ++nr) {         if (!((1 << nr) & nmask)) continue;         bool good = true;         for (int a = 0; a < N; ++a) {           for (int b = a + 1; b < N; ++b) {             if (lca[a][b] == -1) continue;             if ((nmask & (1 << a)) && (nmask1 & (1 << b)) ||                 (nmask & (1 << b)) && (nmask1 & (1 << a))) {               if (lca[a][b] != root) {                 good = false;                 break;               }             } else if ((nmask & (1 << a)) && (nmask & (1 << b))) {               if (!(nmask & (1 << lca[a][b]))) {                 good = false;                 break;               }             } else if ((nmask1 & (1 << a)) && (nmask1 & (1 << b))) {               if (!(nmask1 & (1 << lca[a][b]))) {                 good = false;                 break;               }             }           }           if (!good) break;         }         if (!good) continue;         for (int i = 0; i < N; ++i) {           if (g[root][i] && (nmask & (1 << i)) && nr != i) {             good = false;             break;           }         }         if (!good) continue;         for (int i = 0; i < N; ++i) {           for (int j = 0; j < N; ++j) {             if (i == root || j == root) continue;             if (g[i][j] && (nmask & (1 << i)) && ((mask ^ nmask) & (1 << j))) {               good = false;               break;             }           }         }         if (good) {           long long a = f(nr, nmask);           long long b = f(root, mask ^ nmask);           res += a * b;         }       }       if (get_num_bit(nmask) == 1) break;       nmask = osnmask & (nmask - 1);     }     return dp[root][mask] = res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, q;     cin >> n >> m >> q;     N = n;     g.assign(n, vector<int>(n, 0));     dp.assign(n, vector<long long>((1 << n), -1));     lca.assign(n, vector<int>(n, -1));     hlca.resize(n);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a][b] = g[b][a] = 1;     }     for (int i = 0; i < q; ++i) {       int a, b, w;       cin >> a >> b >> w;       if (a == b && a != w) {         cout << 0;         return 0;       } else if (a == b)         continue;       --a;       --b;       --w;       if (a > b) swap(a, b);       hlca[a].push_back(w);       hlca[b].push_back(w);       if (lca[a][b] != -1 && lca[a][b] != w) {         cout << 0;         return 0;       }       lca[a][b] = w;     }     cout << f(0, (1 << n) - 1);     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10;   char g[maxn][maxn];   long long dp[1 << maxn][1 << maxn];   int main() {     int n, mask1, mask2, i, j, m, k, a, b, count;     long long ans;     cin >> n >> m >> k;     for (i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       g[a][b] = g[b][a] = 1;       dp[(1 << a) | (1 << b)][(1 << a) | (1 << b)] = 2;     }     for (mask1 = 0; mask1 < (1 << n); mask1++)       for (mask2 = mask1; mask2; mask2 = (mask1 & (mask2 - 1))) {         if (!dp[mask1][mask2]) continue;         count = 0;         for (i = 0; i < n; i++)           if (mask2 & (1 << i)) count++;         dp[mask1][mask2] /= count;         for (i = 0; i < n; i++)           if (mask1 & (1 << i))             for (j = 0; j < n; j++)               if (g[i][j] && !(mask1 & (1 << j))) {                 if (mask2 & (1 << i))                   dp[mask1 ^ (1 << j)][mask2 ^ (1 << i) ^ (1 << j)] +=                       dp[mask1][mask2];                 else                   dp[mask1 ^ (1 << j)][mask2 ^ (1 << j)] += dp[mask1][mask2];               }       }     ans = 0;     for (i = 0; i < (1 << n); i++) {       count = 0;       for (j = 0; j < n; j++)         if (i & (1 << j)) count++;       if (count == k) ans += dp[(1 << n) - 1][i];     }     cout << ans;   }


#include<bits/stdc++.h>   using namespace std;   const int N=1505;   const int Q=11;      int read()   {    int s=0;    char c=getchar(),lc= + ;    while (c< 0 || 9 <c) lc=c,c=getchar();    while ( 0 <=c&&c<= 9 ) s=s*10+c- 0 ,c=getchar();    return lc== - ?-s:s;   }   void write(int x)   {    if (x<0) putchar( - ),x=-x;    if (x<10) putchar(x+ 0 );    else write(x/10),putchar(x%10+ 0 );   }   void print(int x,char c=  n )   {    write(x);    putchar(c);   }   bool vis[N*N];   int a[N][N],ans[N],n,q,f;   int cl[2][N][Q],cu[2][N][Q],clu[2][N][Q];//color   int dl[2][N][Q],du[2][N][Q],dlu[2][N][Q];//distance   int tl[2][N],tu[2][N],tlu[2][N];//total   inline void up(int *c,int *d,int x)   {    int tmpc=c[x],tmpd=d[x];    for (int i=x;i>=1;i--) c[i]=c[i-1],d[i]=d[i-1];    c[0]=tmpc;    d[0]=tmpd;   }   inline void insert(int *c,int *d,int &t,int x)   {    for (int i=0;i<t;i++) d[i]++;    for (int i=0;i<t;i++) if (c[i]==x) return d[i]=0,up(c,d,i),void();    if (t<=q) c[t]=x,d[t]=0,up(c,d,t),t++;      else c[t-1]=x,d[t-1]=0,up(c,d,t-1);   }   inline void merge(int *c1,int *d1,int &t1,int *c2,int *d2,int t2)   {    static int c[Q],d[Q],i,j,k;    for (i=0,j=0,k=0;i<t1&&j<t2&&k<=q;)    if (d1[i]<d2[j])    {     if (!vis[c1[i]])     {      vis[c1[i]]=1;      c[k]=c1[i];      d[k]=d1[i];      k++;     }     i++;    }    else    {     if (!vis[c2[j]])     {      vis[c2[j]]=1;      c[k]=c2[j];      d[k]=d2[j];      k++;     }     j++;    }    while (i<t1&&k<=q)    {     if (!vis[c1[i]])     {      vis[c1[i]]=1;      c[k]=c1[i];      d[k]=d1[i];      k++;     }     i++;    }    while (j<t2&&k<=q)    {     if (!vis[c2[j]])     {      vis[c2[j]]=1;      c[k]=c2[j];      d[k]=d2[j];      k++;     }     j++;    }    for (i=0;i<k;i++) vis[c[i]]=0;    memcpy(c1,c,sizeof(c));    memcpy(d1,d,sizeof(d));    t1=k;   }   //int de[N][N];      signed main()   {    n=read(),q=read();    for (int i=1;i<=n;i++)    for (int j=1;j<=n;j++) a[i][j]=read();    for (int i=1,p=0;i<=n;i++,p^=1)    for (int j=1;j<=n;j++)    {     /////////////////////////////////////////////row     memcpy(cl[p][j],cl[p][j-1],sizeof(cl[p][j]));     memcpy(dl[p][j],dl[p][j-1],sizeof(dl[p][j]));     tl[p][j]=tl[p][j-1];     insert(cl[p][j],dl[p][j],tl[p][j],a[i][j]);     /////////////////////////////////////////////column     memcpy(cu[p][j],cu[!p][j],sizeof(cu[p][j]));     memcpy(du[p][j],du[!p][j],sizeof(du[p][j]));     tu[p][j]=tu[!p][j];     insert(cu[p][j],du[p][j],tu[p][j],a[i][j]);     /////////////////////////////////////////////square     memcpy(clu[p][j],clu[!p][j-1],sizeof(clu[p][j]));     memcpy(dlu[p][j],dlu[!p][j-1],sizeof(dlu[p][j]));     tlu[p][j]=tlu[!p][j-1];     merge(clu[p][j],dlu[p][j],tlu[p][j],cl[p][j-1],dl[p][j-1],tl[p][j-1]);     merge(clu[p][j],dlu[p][j],tlu[p][j],cu[!p][j],du[!p][j],tu[!p][j]);     insert(clu[p][j],dlu[p][j],tlu[p][j],a[i][j]);     /////////////////////////////////////////////calculate     if (tlu[p][j]<=q) f=min(i,j);         else f=min(min(i,j),dlu[p][j][q]);     ans[f]++;   //  print(tlu[p][j],j==n?  n :   );   //  print(tlu[p][j], : );   //  for (int k=0;k<tlu[p][j];k++) print(clu[p][j][k],   );   //  putchar( , );   //  putchar(   );   //  for (int k=0;k<tlu[p][j];k++) print(dlu[p][j][k],   );   //  puts(  );   //  de[i][j]=f;    }   // for (int i=1;i<=n;i++)   // for (int j=1;j<=n;j++) print(de[i][j],j==n?  n :   );    for (int i=n;i>=1;i--) ans[i]+=ans[i+1];    for (int i=1;i<=n;i++) print(ans[i]);       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7, M = 20;   const double eps = 1e-10, pi = acos(-1.0);   double dis[N], op[N][M];   struct node {     long long x, y;   } e[N];   int n, k, f[N][M];   struct query {     double x, y;   } w[N];   inline int read() {     int num = 0;     char t =  + , g = getchar();     while (g < 48 || 57 < g) t = g, g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     if (t ==  - ) return 0 - num;     return num;   }   inline bool cmp(query a, query b) {     if (a.y == b.y) return a.x < b.x;     return a.y < b.y;   }   inline int getdis(int u) {     for (int i = 0; i <= 18; i++)       if ((1 << i) & k) u = f[u][i];     return u;   }   inline double abst(double u, int x) {     if (x < 0) return 2 * pi - u;     return u;   }   inline bool check(double u) {     for (int i = 1; i <= n; i++)       if (u > dis[i]) return false;     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++)       w[i].x = abst(acos(e[i].x / dis[i]), e[i].y) - acos(u / dis[i]),       w[i].y = abst(acos(e[i].x / dis[i]), e[i].y) + acos(u / dis[i]);     for (int i = 1; i <= n; i++) {       if (w[i].y >= pi * 2) w[i].y = w[i].y - 2 * pi, w[i].x = w[i].x - 2 * pi;     }     sort(w + 1, w + n + 1, cmp);     f[0][0] = 1;     for (int i = 1; i <= n; i++)       w[i + n].x = w[i].x + 2 * pi, w[i + n].y = w[i].y + 2 * pi;     for (int i = 1; i <= (n << 1); i++) {       f[i][0] = f[i - 1][0];       while (w[f[i][0]].x <= w[i].y && f[i][0] <= (n << 1)) f[i][0]++;     }     f[n << 1 | 1][0] = n << 1 | 1;     for (int x = 1; x <= 18; x++)       for (int i = 1; i <= (n << 1 | 1); i++) f[i][x] = f[f[i][x - 1]][x - 1];     for (int i = 1; i <= n; i++)       if (getdis(i) >= i + n) return true;     return false;   }   int main() {     n = read(), k = read();     double l = 0.00, r = 200000.00, ans = 0.00;     for (int i = 1; i <= n; i++) e[i].x = read(), e[i].y = read();     for (int i = 1; i <= n; i++)       dis[i] = sqrt(1.0 * e[i].x * e[i].x + 1.0 * e[i].y * e[i].y);     while (r - l > eps) {       double d = (l + r) / 2.0;       if (check(d))         ans = d, l = d;       else         r = d;     }     printf( %.7lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pli = pair<ll, int>;   const int INF = 0x3f3f3f3f, N = 3e3 + 5;   const ll LINF = 1e18 + 5;   int n;   vector<int> G[N];   int sz[N][N], f[N][N];   ll dp[N][N], maxn;   void dfs(int u, int fa, int rt) {     sz[rt][u] = 1;     f[rt][u] = fa;     for (int v : G[u]) {       if (v == fa) continue;       dfs(v, u, rt);       sz[rt][u] += sz[rt][v];     }   }   ll solve(int u, int v) {     if (~dp[u][v]) return dp[u][v];     if (u == v) return dp[u][v] = 0;     return dp[u][v] = max(solve(f[v][u], v), solve(u, f[u][v])) +                       1ll * sz[u][v] * sz[v][u];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= n; i++) dfs(i, 0, i);     memset(dp, -1, sizeof(dp));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) maxn = max(maxn, solve(i, j));     cout << maxn;     return 0;   }


#include <bits/stdc++.h>   constexpr int N = 55;   int n;   char a[N][N];   int f[N][N][N][N];   int dfs(int x, int y, int xx, int yy) {     if (~f[x][y][xx][yy]) {       return f[x][y][xx][yy];     } else {       if (x == xx && y == yy) {         return f[x][y][x][y] = (a[x][y] ==  # );       } else {         int res = std::max(xx - x + 1, yy - y + 1);         for (int i = x; i < xx; i++) {           res = std::min(res, dfs(x, y, i, yy) + dfs(i + 1, y, xx, yy));         }         for (int i = y; i < yy; i++) {           res = std::min(res, dfs(x, y, xx, i) + dfs(x, i + 1, xx, yy));         }         return f[x][y][xx][yy] = res;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     memset(f, -1, sizeof f);     std::cin >> n;     for (int i = 0; i < n; i++) {       std::cin >> a[i];     }     std::cout << dfs(0, 0, n - 1, n - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 2e5 + 10;   char s[3][N];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= 2; i++)         for (int j = 1; j <= n; j++) {           cin >> s[i][j];           if (s[i][j] ==  1  || s[i][j] ==  2 )             s[i][j] =  1 ;           else             s[i][j] =  2 ;         }       int flag = 0, x = 1, y = 1;       for (int i = 1; i <= n; i++) {         if (s[y][i] ==  1 ) {           x++;         } else if (s[y][i] ==  2 ) {           if (y == 1 && s[y + 1][i] ==  2 ) {             y++;             x++;           } else if (y == 2 && s[y - 1][i] ==  2 ) {             y--;             x++;           } else {             flag = 1;             break;           }         }       }       if (flag)         cout <<  NO  << endl;       else if (x == n + 1 && y == 2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int k, v, n, m, ans, sum, sum1, l, r, i, j, mx, mn, c, z, x, y,       a[111111], d[111111], t[111111];   string s, sos, ss;   char ch;   bool used[111111];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cout << (n - 1) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(vector<int> &a) { return a[0] + a[1] + a[2] == a[3] + a[4] + a[5]; }   signed main() {     int n;     cin >> n;     vector<int> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i], --a[i];     vector<int> used(n, 0);     int cnt = 0;     for (int i = n - 1; i > -1; --i) {       if (!used[i]) {         used[i] = 1;         int c = i;         while (a[c] > -1 && !used[a[c]]) used[a[c]] = 1, c = a[c];         ++cnt;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, arr[200001], ctr[200001];     set<long int> s;     vector<long int> s2;     list<long int> s1;     memset(ctr, 0, sizeof(ctr));     cin >> n;     for (long int i = 0; i < n; i++) {       cin >> arr[i];       s.insert(arr[i]);       ctr[arr[i]]++;     }     if (s.size() == n) {       cout << 0 <<   n ;       for (long int i = 0; i < n; i++) cout << arr[i] <<    ;       return 0;     }     for (long int i = 1; i <= n; i++) {       if (!ctr[i]) s2.push_back(i);     }     sort(s2.begin(), s2.end());     for (auto it : s2) {       s1.push_back(it);     }     vector<bool> visited(n + 1, false);     cout << s2.size() <<   n ;     for (long int i = 0; i < n; i++) {       if (s1.size() == 0) break;       if (ctr[arr[i]] > 1) {         if (s1.front() < arr[i]) {           ctr[arr[i]] = ctr[arr[i]] - 1;           arr[i] = s1.front();           s1.pop_front();         } else if (s1.front() > arr[i] && visited[arr[i]] == false)           visited[arr[i]] = true;         else if (s1.front() > arr[i] && visited[arr[i]] == true) {           ctr[arr[i]] = ctr[arr[i]] - 1;           arr[i] = s1.front();           s1.pop_front();         }       }     }     for (long int i = 0; i < n; i++) cout << arr[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <typename T, typename U>   ostream &operator<<(ostream &os, pair<T, U> p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename T, typename U>   istream &operator>>(istream &is, pair<T, U> &p) {     is >> p.first >> p.second;     return is;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (int i = 0; i < int(v.size()); ++i) is >> v[i];     return is;   }   template <typename T>   ostream &operator<<(ostream &os, vector<T> v) {     for (T x : v) os << x <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, set<T> s) {     for (T x : s) os << x <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, multiset<T> s) {     for (T x : s) os << x <<    ;     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, map<T, U> m) {     for (auto x : m) os << x <<    ;     return os;   }   template <typename T>   T sum(vector<T> v) {     T summ = 0;     for (int i = 0; i < int(int(v.size())); ++i) summ += v[i];     return summ;   }   long long mod_pow(long long a, long long b) {     long long sol = 1;     while (b) {       if (b & 1) {         sol = (sol * a) % mod;         b--;       } else {         a = (a * a) % mod;         b /= 2;       }     }     return sol;   }   long long rem(long long a, long long b) {     long long res = a % b;     return res < 0 ? res + b : res;   }   void test_case() {     int n;     cin >> n;     vector<pair<char, int>> ops(2 * n);     for (int i = 0; i < int(2 * n); ++i) {       char type;       cin >> type;       if (type ==  + ) {         ops[i].first =  + ;       } else {         ops[i].first =  - ;         cin >> ops[i].second;       }     }     stack<int> bought;     reverse(ops.begin(), ops.end());     vector<int> answer;     for (auto p : ops) {       char type = p.first;       int buy = p.second;       if (type ==  - ) {         if (!bought.empty() && buy > bought.top()) {           cout <<  NO n ;           return;         }         bought.push(buy);       } else {         if (bought.empty()) {           cout <<  NO n ;           return;         }         answer.push_back(bought.top());         bought.pop();       }     }     reverse(answer.begin(), answer.end());     cout <<  YES n  << answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int i = 0; i < int(t); ++i) test_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2005;   pair<int, int> q[MAX * MAX];   char a[MAX][MAX];   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, 1, 0, -1};   char tt[4] = { v ,  < ,  ^ ,  > };   int n, m;   bool isav(int x, int y) {     return (0 <= x && x < n && 0 <= y && y < m && a[x][y] ==  . );   }   int deg(int x, int y) {     int ans = 0;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (isav(nx, ny)) ans++;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     int h = 0, t = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (isav(i, j) && deg(i, j) == 1) q[t++] = make_pair(i, j);     while (h < t) {       int x = q[h].first, y = q[h].second;       h++;       for (int i = 0; i < 4; i++) {         int nx = x + dx[i];         int ny = y + dy[i];         if (isav(nx, ny)) {           a[x][y] = tt[i];           a[nx][ny] = tt[i ^ 2];           for (int j = 0; j < 4; j++) {             int nnx = nx + dx[j];             int nny = ny + dy[j];             if (isav(nnx, nny) && deg(nnx, nny) == 1)               q[t++] = make_pair(nnx, nny);           }           break;         }       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  . ) {           cout <<  Not unique  << endl;           return 0;         }     for (int i = 0; i < n; i++, cout << endl)       for (int j = 0; j < m; j++) cout << a[i][j];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   void extendgcd(long long a, long long b, long long *v) {     if (b == 0) {       v[0] = 1;       v[1] = 0;       v[2] = a;       return;     }     extendgcd(b, a % b, v);     long long x = v[1];     v[1] = v[0] - v[1] * (a / b);     v[0] = x;     return;   }   long long mminv(long long a, long long b) {     long long arr[3];     extendgcd(a, b, arr);     return arr[0];   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   bool revsort(long long a, long long b) { return a > b; }   void swap(int &x, int &y) {     int temp = x;     x = y;     y = temp;   }   long long combination(long long n, long long r, long long m, long long *fact,                         long long *ifact) {     long long val1 = fact[n];     long long val2 = ifact[n - r];     long long val3 = ifact[r];     return (((val1 * val2) % m) * val3) % m;   }   void google(int t) { cout <<  Case #  << t <<  :  ; }   vector<long long> sieve(int n) {     int *arr = new int[n + 1]();     vector<long long> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   long long phin(long long n) {     long long number = n;     if (n % 2 == 0) {       number /= 2;       while (n % 2 == 0) n /= 2;     }     for (long long i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         while (n % i == 0) n /= i;         number = (number / i * (i - 1));       }     }     if (n > 1) number = (number / n * (n - 1));     return number;   }   int isprime(int N) {     if (N < 2 || (!(N & 1) && N != 2)) return 0;     for (int i = 3; i * i <= N; i += 2) {       if (!(N % i)) return 0;     }     return 1;   }   int bin_pow(int ind, int power) {     if (power == 0) {       return 1;     }     if (power & 1) {       return ind * bin_pow(ind, power - 1) % 1000000007;     } else {       return bin_pow((ind * ind) % 1000000007, power / 2) % 1000000007;     }   }   int fact(int x) {     int ret = 1;     for (int i = 2; i <= x; i++) {       ret *= i;       ret %= 1000000007;     }     return ret;   }   int ncr(int n, int r) {     if (r > n) return 0;     return (fact(n) *             (bin_pow((fact(r) * fact(n - r)) % 1000000007, 1000000007 - 2))) %            1000000007;   }   void solve() {     int n;     cin >> n;     long long arr[200010], total = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (i > 0)         total += abs(arr[i] - arr[i - 1]);       else         total += abs(arr[i]);     }     cout << total << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     auto start1 = high_resolution_clock::now();     solve();     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[8][8], b[8][8];   long long get() {     char c = getchar();     long long x = 0LL;     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       x *= 10LL;       x += (c -  0 );       c = getchar();     }     return x;   }   int main() {     char c;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         cin >> c;         if (c ==  B ) a[i][j] = 1;       }     int ans = 16;     for (int i = 0; i < (1 << 8); i++)       for (int j = 0; j < (1 << 8); j++) {         for (int x = 0; x < 8; x++)           for (int y = 0; y < 8; y++) {             if (i & (1 << x) || j & (1 << y))               b[x][y] = 1;             else               b[x][y] = 0;           }         bool f = true;         for (int x = 0; x < 8; x++)           for (int y = 0; y < 8; y++)             if (b[x][y] != a[x][y]) f = false;         if (f) {           ans = min(ans, __builtin_popcount(i) + __builtin_popcount(j));         }       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int N = 5e5 + 2;   int seg[N * 4];   int lazy[N * 4];   int hi[N];   int h[N];   int n;   vector<int> g[N];   vector<int> y[N];   pair<int, int> t[N];   void dfs(int v, int p) {     t[v] = t[p];     if (hi[t[v].second] > hi[v]) {       t[v].second = v;     }     if (hi[t[v].second] < hi[t[v].first]) swap(t[v].second, t[v].first);     for (auto &u : g[v]) {       if (u == p) continue;       dfs(u, v);     }   }   void upd(int nod, int l, int r, int L, int R, int val) {     if (l >= R || L >= r) return;     if (l >= L && r <= R) {       seg[nod] += val;       lazy[nod] += val;       return;     }     int mid = (r + l) >> 1;     upd(nod << 1, l, mid, L, R, val);     upd(nod << 1 | 1, mid, r, L, R, val);     seg[nod] = min(seg[nod << 1], seg[nod << 1 | 1]) + lazy[nod];   }   inline bool check(int v, int val) {     for (auto &u : y[v]) {       int x = hi[t[u].first];       int y = min(hi[t[u].second], hi[t[u].first] + val);       int z = upper_bound(h + 1, h + n + 1, x) - h;       int e = upper_bound(h + 1, h + n + 1, y) - h;       upd(1, 1, N, z, e, +1);     }     bool p1 = 0;     if (seg[1] >= 0) p1 = 1;     for (auto &u : y[v]) {       int x = hi[t[u].first];       int y = min(hi[t[u].second], hi[t[u].first] + val);       int z = upper_bound(h + 1, h + n + 1, x) - h;       int e = upper_bound(h + 1, h + n + 1, y) - h;       upd(1, 1, N, z, e, -1);     }     return p1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &hi[i]);     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int k;     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       scanf( %d , &h[i]);     }     sort(h + 1, h + n + 1);     for (int i = n; i; i--) {       upd(1, 1, N, 1, i + 1, -1);     }     hi[0] = 1e9 + 100;     t[0] = {0, 0};     dfs(1, 0);     for (int i = 1; i <= n; i++) {       y[t[i].first].push_back(i);       int z = upper_bound(h + 1, h + n + 1, hi[t[i].first]) - h;       upd(1, 1, N, 1, z, +1);     }     int l1 = -1, r1 = 1e9 + 2;     for (int i = 1; i <= n; i++) {       int l = -1, r = r1;       if (!(check(i, r - 1))) continue;       while (r - l > 1) {         int mid = (r + l) / 2;         int z = check(i, mid);         if (z)           r = mid;         else           l = mid;       }       r1 = r;     }     if (r1 > 1e9) {       printf( %d , -1);       return 0;     }     printf( %d , r1);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   void solve() {     ll n, k;     cin >> n >> k;     vector<ll> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     ll dp[n][n];     for (int i = 1; i < n; i++) dp[0][i] = 0;     ll curr = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == (i + 1)) curr += 1;       dp[i][0] = curr;     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < n; j++) {         ll temp = (arr[i] == (i - j + 1));         dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j] + temp);       }     }     ll ans = -1;     for (int i = 0; i < n; i++) {       if (dp[n - 1][i] >= k) {         ans = i;         break;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 2e5 + 1;   void solve() {     string s, even, odd;     cin >> s;     for (long long int i = 0; i < s.length(); i++) {       long long int val = s[i] -  0 ;       if (val % 2 == 0)         even += s[i];       else         odd += s[i];     }     if (odd.length() == 0) {       cout << even <<   n ;     } else if (even.length() == 0) {       cout << odd <<   n ;     } else {       long long int n1 = odd.length(), n2 = even.length();       long long int i = 0, j = 0;       while (i < n1 && j < n2) {         if (odd[i] < even[j]) {           cout << odd[i];           i++;         } else if (odd[i] > even[j]) {           cout << even[j];           j++;         } else {           cout << odd[i] << even[j];           i++;           j++;         }       }       while (i < n1) {         cout << odd[i];         i++;       }       while (j < n2) {         cout << even[j];         j++;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int T = 1, p = 0;     cin >> T;     do {       solve();       p++;     } while (p < T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     int odd = 0;     for (auto &i : a) cin >> i, odd += i & 1;     if (odd > 0 && odd < n) sort(a.begin(), a.end());     for (auto &i : a) cout << i <<    n [&i == &a.back()];     return 0;   }