#include <bits/stdc++.h>   inline int read(void) {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) f = c ==  -  ? -1 : 1, c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c & 15), c = getchar();     return x * f;   }   inline int getm(long long x, int mod) { return (x % mod + mod) % mod; }   const int N = 300005;   const int mod1 = 998244353, mod2 = 1000000007;   const int inv1 = 729486258, inv2 = 576923081;   int n, m;   int pw[N][2], inv[N][2];   char s[N];   struct Edge {     int to, nxt;   } E[N << 1];   int head[N], tot;   inline void add(int f, int t) {     E[++tot] = (Edge){t, head[f]}, head[f] = tot;     return;   }   int hh1[N][2], hh2[N][2];   int lg[N << 1], dep[N], fa[N][20], len[N], son[N], dfn[N], tt, st[N << 1][21];   int top[N], *up[N], *down[N];   void init(void) {     pw[0][0] = pw[0][1] = inv[0][0] = inv[0][1] = 1;     for (int i = 1; i <= n; ++i)       pw[i][0] = 26ll * pw[i - 1][0] % mod1,       pw[i][1] = 26ll * pw[i - 1][1] % mod2,       inv[i][0] = 1ll * inv1 * inv[i - 1][0] % mod1,       inv[i][1] = 1ll * inv2 * inv[i - 1][1] % mod2;     for (int i = 1; i <= n << 1; ++i) lg[i] = lg[i >> 1] + 1;     return;   }   void dfs1(int x, int from) {     dep[x] = dep[from] + 1, fa[x][0] = from, st[dfn[x] = ++tt][0] = x;     hh1[x][0] = (26ll * hh1[fa[x][0]][0] + (s[x] -  a )) % mod1;     hh1[x][1] =         (hh1[fa[x][0]][1] + 1ll * pw[dep[x] - 1][0] * (s[x] -  a )) % mod1;     hh2[x][0] = (26ll * hh2[fa[x][0]][0] + (s[x] -  a )) % mod2;     hh2[x][1] =         (hh2[fa[x][0]][1] + 1ll * pw[dep[x] - 1][1] * (s[x] -  a )) % mod2;     for (int i = 1; i < lg[dep[x]]; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];     for (int i = head[x]; i; i = E[i].nxt) {       int y = E[i].to;       if (y == from) continue;       dfs1(y, x);       st[++tt][0] = x, son[x] = len[son[x]] > len[y] ? son[x] : y;     }     len[x] = len[son[x]] + 1;     return;   }   void dfs2(int x, int tp) {     top[x] = tp;     if (tp == x) {       up[x] = new int[len[x] + 5], down[x] = new int[len[x] + 5];       for (int y = x, l = 0; y != 0 && l <= len[x]; y = fa[y][0], ++l)         up[x][l] = y;     }     down[tp][dep[x] - dep[tp]] = x;     if (son[x]) dfs2(son[x], tp);     for (int i = head[x]; i; i = E[i].nxt) {       int y = E[i].to;       if (y == fa[x][0] || y == son[x]) continue;       dfs2(y, y);     }     return;   }   inline void init_st(void) {     for (int k = 1; k < lg[tt]; ++k)       for (int i = 1; i + (1 << k) - 1 <= tt; ++i)         st[i][k] = dep[st[i][k - 1]] < dep[st[i + (1 << (k - 1))][k - 1]]                        ? st[i][k - 1]                        : st[i + (1 << (k - 1))][k - 1];     return;   }   inline int lca(int l, int r) {     l = dfn[l], r = dfn[r];     if (l > r) std::swap(l, r);     int k = lg[r - l + 1] - 1;     return dep[st[l][k]] < dep[st[r - (1 << k) + 1][k]] ? st[l][k]                                                         : st[r - (1 << k) + 1][k];   }   inline int kth(int x, int k) {     if (k == 0)       return x;     else if (k >= dep[x])       return 0;     x = fa[x][lg[k] - 1], k ^= 1 << (lg[k] - 1);     if (dep[top[x]] <= dep[x] - k)       return down[top[x]][dep[x] - k - dep[top[x]]];     else       return up[top[x]][dep[top[x]] - dep[x] + k];   }   inline std::pair<int, int> hashh(int a, int b, int k, int f, int l) {     int hash1 = 0, hash2 = 0;     int t = kth(a, k), tt = kth(b, l - k);     if (k <= dep[a] - dep[f] + 1)       hash1 = getm(hh1[a][0] - 1ll * pw[k][0] * hh1[t][0], mod1),       hash2 = getm(hh2[a][0] - 1ll * pw[k][1] * hh2[t][0], mod2);     else       hash1 =           (getm(hh1[a][0] - 1ll * pw[dep[a] - dep[f] + 1][0] * hh1[fa[f][0]][0],                 mod1) +            1ll * inv[dep[f]][0] * pw[dep[a] - dep[f] + 1][0] % mod1 *                getm(hh1[tt][1] - hh1[f][1], mod1) % mod1) %           mod1,       hash2 =           (getm(hh2[a][0] - 1ll * pw[dep[a] - dep[f] + 1][1] * hh2[fa[f][0]][0],                 mod2) +            1ll * inv[dep[f]][1] * pw[dep[a] - dep[f] + 1][1] % mod2 *                getm(hh2[tt][1] - hh2[f][1], mod2) % mod2) %           mod2;     return std::make_pair(hash1, hash2);   }   inline int solve(int a, int b, int c, int d) {     int f1 = lca(a, b), f2 = lca(c, d), l1 = dep[a] + dep[b] - dep[f1] * 2 + 1,         l2 = dep[c] + dep[d] - dep[f2] * 2 + 1;     int l = 1, r = std::min(l1, l2), res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (hashh(a, b, mid, f1, l1) == hashh(c, d, mid, f2, l2))         res = mid, l = mid + 1;       else         r = mid - 1;     }     return res;   }   int main(void) {     n = read();     scanf( %s , s + 1);     for (int i = 1, u, v; i < n; ++i)       u = read(), v = read(), add(u, v), add(v, u);     init();     dfs1(1, 0), dfs2(1, 1);     init_st();     m = read();     for (int i = 1, a, b, c, d; i <= m; ++i)       a = read(), b = read(), c = read(), d = read(),       printf( %d n , solve(a, b, c, d));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, d[200 + 5], nows[200 + 5], fr[200 + 5], en[200 + 5],       A[200 + 5], S, T, fa[200 + 5], now, Bh, Ch, B[200 + 5], C[200 + 5], H, un,       wn, ToT;   struct yyy {     int to, w, z;   } tmp;   struct ljb {     int head, h[200 + 5];     yyy f[1000 + 5 << 2];     inline void add(int x, int y, int z) {       f[head] = (yyy){y, z, h[x]};       h[x] = head++;     }   } s, G;   queue<int> Q;   struct ques {     int x, y, z;   } F[200 + 5];   inline bool cmp(ques x, ques y) { return x.z > y.z; }   inline void Get(int x, int y, int z) {     s.add(x, y, z);     s.add(y, x, z);   }   inline int bfs() {     while (!Q.empty()) Q.pop();     memset(d, 0x3f, sizeof(d));     d[S] = 0;     Q.push(S);     nows[S] = s.h[S];     while (!Q.empty()) {       now = Q.front();       Q.pop();       for (int i = s.h[now]; ~i; i = tmp.z) {         tmp = s.f[i];         if (!tmp.w || d[tmp.to] < 1e9) continue;         d[tmp.to] = d[now] + 1;         Q.push(tmp.to);         nows[tmp.to] = s.h[tmp.to];         if (tmp.to == T) return 1;       }     }     return 0;   }   inline int dfs(int x, int sum) {     if (x == T) return sum;     int i, k, pus = 0;     yyy tmp;     for (i = nows[x]; ~i; i = tmp.z) {       tmp = s.f[i];       nows[x] = i;       if (!tmp.w || d[tmp.to] != d[x] + 1) continue;       k = dfs(tmp.to, ((sum) < (tmp.w) ? (sum) : (tmp.w)));       if (!k) d[tmp.to] = 1e9;       pus += k;       sum -= k;       s.f[i].w -= k;       s.f[i ^ 1].w += k;       if (!sum) break;     }     return pus;   }   inline void build(int l, int r) {     if (l == r) return;     int Ans = 0, i;     S = A[l];     T = A[r];     s = G;     while (bfs()) Ans += dfs(S, 1e9);     F[++H] = (ques){S, T, Ans};     ToT += Ans;     Bh = Ch = 0;     for (i = l; i <= r; i++) (d[A[i]] < 1e9 ? B[++Bh] : C[++Ch]) = A[i];     for (i = l; i <= l + Bh - 1; i++) A[i] = B[i - l + 1];     for (i = l + Bh; i <= r; i++) A[i] = C[i - l - Bh + 1];     Ans = Bh;     build(l, l + Ans - 1);     build(l + Ans, r);   }   inline int Getfa(int x) { return x == fa[x] ? x : fa[x] = Getfa(fa[x]); }   int main() {     register int i;     scanf( %d%d , &n, &m);     memset(s.h, -1, sizeof(s.h));     for (i = 1; i <= m; i++) scanf( %d%d%d , &x, &y, &z), Get(x, y, z);     for (i = 1; i <= n; i++) A[i] = i;     G = s;     build(1, n);     sort(F + 1, F + n, cmp);     for (i = 1; i <= n; i++) fa[i] = en[i] = fr[i] = i;     for (i = 1; i < n; i++)       un = Getfa(F[i].x), wn = Getfa(F[i].y), en[un] = fr[wn], fr[wn] = fr[un],       fa[un] = wn;     now = fr[Getfa(1)];     printf( %d n , ToT);     while (en[now] ^ now) printf( %d  , now), now = en[now];     printf( %d n , now);   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int ans = 1;     for (int i = 2; i <= n; ++i) {       ans = 1LL * ans * i % M;     }     int two = 1;     for (int i = 1; i < n; ++i) {       two = (two + two) % M;     }     cout << (ans - two + M) % M <<   n ;   }


#include <bits/stdc++.h>   typedef int iarrN[100003][35];   struct IO {     template <typename T>     inline IO operator>>(T &n) {       n = 0;       char c = getchar();       while (c <  0  || c >  9 ) c = getchar();       while (c >=  0  && c <=  9 )         n = (n << 3) + (n << 1) + (c ^ 48), c = getchar();       return *this;     }   } cin;   constexpr int MX = 33, inf = 0x3f3f3f3f;   int N, son[100003][35], mnw[100003][35];   long long K, sw[100003][35];   void init() {     cin >> N >> K;     for (int i = 1; i <= N; ++i) cin >> son[i][0], ++son[i][0];     for (int i = 1; i <= N; ++i) cin >> mnw[i][0], sw[i][0] = mnw[i][0];     for (int j = 1; j <= MX; ++j)       for (int i = 1; i <= N; ++i) {         son[i][j] = son[son[i][j - 1]][j - 1];         sw[i][j] = sw[i][j - 1] + sw[son[i][j - 1]][j - 1];         mnw[i][j] = std::min(mnw[i][j - 1], mnw[son[i][j - 1]][j - 1]);       }   }   inline void query(int u) {     int ansmn = inf;     long long k = K, anss = 0;     for (int i = MX; i >= 0; --i)       if (k >= (1ll << i)) {         k -= 1ll << i;         anss += sw[u][i];         ansmn = std::min(ansmn, mnw[u][i]);         u = son[u][i];       }     printf( %I64d %d n , anss, ansmn);   }   int main() {     init();     for (int i = 1; i <= N; ++i) query(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     long long f = 1;     long long x = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   };   const int maxn = 1e4 + 5;   int res[maxn];   int main() {     int n = read(), d = read(), l = read();     int up, dw;     up = (n / 2 + (n & 1)) * l - (n / 2);     dw = (n / 2 + (n & 1)) - (n / 2) * l;     if (d < dw || d > up) {       printf( -1 );       return 0;     }     for (int i = 1, now = up; i <= n; ++i) {       if (now == d) {         printf( %d  , i & 1 ? l : 1);         continue;       }       int del = min(now - d, l - 1);       if (i & 1) {         printf( %d  , l - del);         now -= del;       } else {         printf( %d  , 1 + del);         now -= del;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE *in;   FILE *out;   const int MAX = 131072;   const int TREE = 262144;   int n;   int a[MAX];   int tree[TREE];   void update(int idx, int val) {     idx += (TREE >> 1);     while (idx) {       tree[idx] = max(tree[idx], val);       idx >>= 1;     }   }   int query(int idx) {     idx += (TREE >> 1);     int ret = tree[idx];     bool flag = !(idx & 1);     idx >>= 1;     while (idx) {       if (flag) ret = max(ret, tree[(idx << 1) + 1]);       flag = !(idx & 1);       idx >>= 1;     }     return ret;   }   int lis() {     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       int cur = query(a[i] + 1) + 1;       ans = max(ans, cur);       update(a[i], cur);     }     return ans;   }   int main(void) {     in = stdin;     out = stdout;     fscanf(in,  %d , &n);     for (int i = 0; i < n; i++) fscanf(in,  %d , &a[i]);     fprintf(out,  %d n , lis());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   int n, m, gx, gy, len, vis[15][15], ucs;   inline bool out(int x, int y) { return x < 0 || x >= n || y < 0 || y >= m; }   char s[15][15 + 1];   struct P {     int x[9], y[9], step, h;     P() { step = 0; }     void cal_h() { h = step + abs(gx - x[0]) + abs(gy - y[0]); }     int get_hsh() {       int hsh = 0;       for (int i = 0; i < len; i++) hsh = hsh * 131 + x[i] + 1;       for (int i = 0; i < len; i++) hsh = hsh * 131 + y[i] + 1;       return hsh;     }     bool operator<(const P &p) const { return h > p.h; }   };   int vc[15][15];   bool chk(int x, int y) {     vc[x][y] = 1;     if (s[x][y] ==  @ ) return 1;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (out(nx, ny) || vc[nx][ny] || s[nx][ny] ==  # ) continue;       if (chk(nx, ny)) return 1;     }     return 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (s[i][j] ==  @ ) gx = i, gy = j;     P p, np;     for (int i = 1; i <= 9; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < m; k++)           if (s[j][k] ==  0  + i) {             p.x[len] = j;             p.y[len] = k;             len++;           }     if (!chk(p.x[0], p.y[0])) return puts( -1 ), 0;     set<int> vs;     priority_queue<P> q;     p.cal_h();     q.push(p);     vs.insert(p.get_hsh());     while (!q.empty()) {       p = q.top();       q.pop();       ucs++;       for (int i = 0; i < len - 1; i++) vis[p.x[i]][p.y[i]] = ucs;       for (int i = 0; i < 4; i++) {         int hx = p.x[0] + dx[i], hy = p.y[0] + dy[i];         if (out(hx, hy)) continue;         if (vis[hx][hy] == ucs) continue;         if (s[hx][hy] ==  # ) continue;         if (s[hx][hy] ==  @ ) return printf( %d n , p.step + 1), 0;         np.x[0] = hx;         np.y[0] = hy;         np.step = p.step + 1;         memcpy(np.x + 1, p.x, (len - 1) * sizeof(int));         memcpy(np.y + 1, p.y, (len - 1) * sizeof(int));         if (vs.count(np.get_hsh())) continue;         vs.insert(np.get_hsh());         np.cal_h();         q.push(np);       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int customCeil(int k, int s) {     if (k % s == 0) return k / s;     return k / s + 1;   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     for (int i = (0); i < (n); ++i) {       cin >> arr[i];     }     long long int m;     cin >> m;     long long int c[m];     for (int i = (0); i < (n); ++i) {       cin >> c[i];     }     long long int sum = 0;     sort(arr, arr + n);     for (int i = (0); i < (n); ++i) {       sum += arr[i];     }     for (int i = (0); i < (m); ++i) {       cout << sum - arr[n - c[i]] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       double a, b;       cin >> a >> b;       cout << fixed << setprecision(15);       if (b == 0) {         cout << 1 << endl;       } else if (a == 0) {         cout << 0.5 << endl;       } else if (a > b * 4) {         cout << 1 - b / a << endl;       } else {         double remain = b - a / 4;         cout << 1 - (b + remain) / (4 * b) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(long long first) {     return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   template <typename T>   struct Fenwick {     explicit Fenwick(unsigned int N = 0, T t = T())         : N(1u << logceil(N)), F(this->N, t), t(t) {}     explicit Fenwick(const vector<T>& A, T t = T())         : N(1u << logceil(A.size())), F(A), t(t) {       F.resize(N);       fill(F.begin() + A.size(), F.end(), t);       for (int i = 0; i < N; i++) {         int j = i + lsb(i + 1);         if (j < N) F[j] += F[i];       }     }     void add(int i, T v) {       while (i <= N) {         F[i] += v;         i += lsb(i + 1);       }     }     T sum(int i) const {       T sum(t);       while (i) {         sum += F[i - 1];         i -= lsb(i);       }       return sum;     }     T range(int i, int j) const {       j++;       T s(t);       while (j > i) {         s += F[j - 1];         j -= lsb(j);       }       while (i > j) {         s -= F[i - 1];         i -= lsb(i);       }       return s;     }     T get(int i) const { return range(i, i); }     void set(int i, T v) { add(i, v - get(i)); }     constexpr int lsb(int i) const { return i & -i; }     unsigned int N;     vector<T> F;     T t;     int max_lower(T v) {       if (F[0] >= v) return 0;       if (F[N - 1] < v) return N - 1;       int first = 0;       T a = t;       for (int s = N >> 1; s > 0; s >>= 1)         if (a + F[first + s - 1] < v) {           a += F[first + s - 1];           first += s;         }       return first;     }   };   template <typename T>   struct Fenwick2 {     explicit Fenwick2(unsigned int N = 0, T t = T())         : N(1u << logceil(N)), F(this->N, this->N, t), t(t) {}     void add(int first, int second, T v) {       while (first <= N) {         int z = second;         while (z <= N) {           F[first][z] += v;           z += lsb(z + 1);         }         first += lsb(first + 1);       }     }     T sum(int first, int second) {       T sum(t);       while (first <= N) {         int z = second;         while (z <= N) {           sum += F[first][z];           z -= lsb(z + 1);         }         first -= lsb(first + 1);       }       return sum;     }     T range(int x1, int y1, int x2, int y2) {       T ans = sum(x2, y2);       if (x1) ans -= sum(x1 - 1, y2);       if (y1) ans -= sum(x2, y1 - 1);       if (x1 && y1) ans += sum(x1 - 1, y1 - 1);       return ans;     }     constexpr int lsb(int i) const { return i & -i; }     unsigned int N;     vector2<T> F;     T t;   };   class FNiyazAndSmallDegrees {    public:     int N, X;     vector<map<int, int>> E;     vector<map<int, int>> ZZ;     vector<int> D, V;     vector<Fenwick<int>> CNT;     vector<Fenwick<long long>> SUM;     void add(int hiDeg, int idInFenwick, int cost) {       CNT[hiDeg].add(idInFenwick, 1);       SUM[hiDeg].add(idInFenwick, cost);     }     long long sumLowest(int hiDeg, int cnt) {       if (cnt <= 0) return 0LL;       int id = CNT[hiDeg].max_lower(cnt);       if (id == CNT[hiDeg].N - 1) return 1e12;       return SUM[hiDeg].sum(id + 1);     }     pair<long long, long long> solve(int u, int p, long long parentCost) {       V[u] = X;       long long tot = 0;       vector<long long> Q;       for (std::pair<int, int> v : E[u]) {         if (v.first != p) {           auto sol = solve(v.first, u, v.second);           tot += sol.first;           Q.push_back(sol.second);         }       }       sort(Q.begin(), Q.end());       long long ans1 = 1e12, ans2 = 1e12, pref = 0;       vector<long long> sumL(Q.size() + 2);       int toRem = D[u] - X;       for (int i = 0; i <= Q.size() + 1; ++i) sumL[i] = sumLowest(u, toRem - i);       for (int i = 0; i <= Q.size(); ++i) {         ans1 = min(ans1, pref + sumL[i]);         ans2 = min(ans2, pref + sumL[i + 1]);         if (i != Q.size()) pref += Q[i];       }       return {tot + ans1, ans2 - ans1 + parentCost};     }     void solve(istream& cin, ostream& cout) {       cin >> N;       E.resize(N);       D.resize(N);       ZZ.resize(N);       for (int i = 0; i < N - 1; ++i) {         int a, b, c;         cin >> a >> b >> c;         --a;         --b;         E[a][b] = c;         E[b][a] = c;       }       map<int, vector<int>> ByDeg;       for (int i = 0; i < N; ++i) {         D[i] = E[i].size();         ByDeg[D[i]].push_back(i);         vector<std::pair<int, int>> ByCost;         for (std::pair<int, int> e : E[i]) ByCost.emplace_back(e.second, e.first);         sort(ByCost.begin(), ByCost.end());         for (int j = 0; j < D[i]; ++j) ZZ[i][ByCost[j].second] = j;         CNT.emplace_back(D[i], 0);         SUM.emplace_back(D[i], 0LL);       }       V.assign(N, -1);       vector<long long> Cost(N, 0LL);       for (X = 0; X < N; ++X) {         for (int v : ByDeg[X]) {           for (std::pair<int, int> q : E[v]) {             add(q.first, ZZ[q.first][v], q.second);             E[q.first].erase(v);           }         }         ByDeg.erase(X);         for (auto& bd : ByDeg) {           for (int v : bd.second) {             if (V[v] != X) {               auto ans = solve(v, -1, 1e12);               Cost[X] += ans.first + min(0LL, ans.second);             }           }         }       }       cout << Cost;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     FNiyazAndSmallDegrees solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MOD = 998244353;   const int64_t N = 2e5 + 5;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int64_t mpow(int64_t x, int64_t y) {     if (y == 0) return 1;     int64_t temp = mpow(x, y / 2);     temp *= temp;     temp %= MOD;     if (y & 1) return (x * temp) % MOD;     return temp;   }   int64_t inverse(int64_t x) { return mpow(x, MOD - 2); }   int64_t fact[N], ifact[N];   int64_t nCr(int64_t n, int64_t r) {     int64_t ans = fact[n];     ans *= ifact[r];     ans %= MOD;     ans *= ifact[n - r];     ans %= MOD;     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fact[0] = 1;     ifact[0] = 1;     for (int64_t i = 1; i < N; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= MOD;       ifact[i] = inverse(fact[i]);     }     int64_t n, k;     cin >> n >> k;     int64_t arr[n];     for (int64_t i = 0; i < n; i++) {       cin >> arr[i];     }     int64_t equal = 0;     for (int64_t i = 0; i < n; i++) {       if (arr[i] == arr[(i + 1) % n]) equal++;     }     int64_t ans = mpow(k, equal);     int64_t ans2 = 0;     for (int64_t i = 0; i <= n - equal - 1; i++) {       int64_t lol = mpow(k - 2, i);       if ((n - equal - i) % 2 == 1) {         lol *= mpow(2, n - equal - i - 1);         lol %= MOD;       } else {         int64_t rem = mpow(2, n - equal - i);         rem -= nCr(n - equal - i, (n - equal - i + 1) / 2);         rem = rem + 10 * MOD;         rem %= MOD;         rem *= inverse(2);         rem %= MOD;         lol *= rem;         lol %= MOD;       }       lol *= nCr(n - equal, i);       lol %= MOD;       ans2 += lol;       ans2 %= MOD;     }     ans *= ans2;     ans %= MOD;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout <<  ?   << 1 <<     << 3 << endl;     int ac;     cin >> ac;     cout <<  ?   << 1 <<     << 2 << endl;     int ab;     cin >> ab;     cout <<  ?   << 2 <<     << 3 << endl;     int bc;     cin >> bc;     int amc = ab - bc;     int a2 = ac + amc;     int a = a2 / 2;     int b = ab - a;     int c = bc - b;     vector<int> res = {a, b, c};     for (int i = 0; i < n - 3; i++) {       cout <<  ?   << 1 <<     << i + 4 << endl;       int tmp;       cin >> tmp;       res.push_back(tmp - a);     }     cout <<  !  ;     for (int val : res) cout << val <<    ;     cout << endl;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define srt(s) sort(s.begin(),s.end())   int main()   {       ll t;       cin>>t;       while(t--)       {           ll n;           cin>>n;           string s;           cin>>s;           ll x=0;           ll p=0,p1=0;           ll mark=0;           stack<char>st,st1;           for(int i=0; i<n; i++)           {               if(s[i]== M )               {                   x++;               }           }           if(3*x!=n)           {               mark=1;           }           for(int i=0; i<n; i++)           {               if(s[i]== T )               {                   st.push(s[i]);               }               else               {                   if(st.size()>0)                   {                       st.pop();                   }                   else                   {                       mark=1;                       break;                   }               }           }           for(int i=n-1; i>=0; i--)           {               if(s[i]== T )               {                   st1.push(s[i]);               }               else               {                   if(st1.size()>0)                   {                       st1.pop();                   }                   else                   {                       mark=1;                       break;                   }               }           }           if(mark==0)           {               cout<< YES <<endl;           }           else           {               cout<< NO <<endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int f, x;     cin >> f;     x = f + 1;     if (f == 0) {       f = 0;     } else if (x % 2 == 0) {       f = x / 2;     } else {       f++;     }     cout << f << endl;     return 0;   }


#include <bits/stdc++.h>   template <class T1, class T2>   inline bool cmin(T1 &a, const T2 &b) {     return b < a ? (a = b, true) : false;   }   template <class T1, class T2>   inline bool cmax(T1 &a, const T2 &b) {     return a < b ? (a = b, true) : false;   }   template <class Type>   Type read() {     Type a;     bool b;     unsigned char c;     while (c = getchar() - 48, (c > 9) & (c != 253))       ;     for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c)       ;     return b ? -a : a;   }   int (*rd)() = read<int>;   namespace G {   const int N = 2e5 + 10, M = 1e6 + 10;   int n, m, s, t, to[M], cap[M], head[N], next[M], deg[N], dis[N], cur[N];   void init(int v, int src, int dst) {     n = v, m = 0, s = src, t = dst;     memset(head, -1, n * sizeof(int));     memset(deg, 0, n * sizeof(int));   }   void edge(int u, int v, int w) {     to[m] = v, cap[m] = w, next[m] = head[u], head[u] = m++;     to[m] = u, cap[m] = 0, next[m] = head[v], head[v] = m++;   }   void add_edge(int u, int v, int min, int max) {     if (max > min) edge(u, v, max - min);     deg[u] += min;     deg[v] -= min;   }   bool bfs() {     static int queue[N];     int *qhead = queue, *qtail = queue;     memset(dis, -1, n * sizeof(int));     dis[ *qtail++ = t] = 0;     while (qhead != qtail) {       int u = *qhead++;       for (int i = head[u]; ~i; i = next[i])         if (cap[i ^ 1] && dis[to[i]] == -1) {           dis[ *qtail++ = to[i]] = dis[u] + 1;           if (to[i] == s) return true;         }     }     return false;   }   int dfs(int u, int lim) {     if (u == t) return lim;     int rem = lim;     for (int &i = cur[u]; ~i; i = next[i])       if (cap[i] && dis[to[i]] + 1 == dis[u]) {         int now = dfs(to[i], std::min(cap[i], rem));         cap[i] -= now;         cap[i ^ 1] += now;         if ((rem -= now) == 0) break;       }     return lim - rem;   }   int flow(int ss, int tt) {     int msave = m, ans = deg[ss];     edge(tt, ss, 1e9);     for (int i = 0; i < n; ++i) {       if (deg[i] < 0) edge(s, i, -deg[i]);       if (deg[i] > 0) edge(i, t, deg[i]);     }     while (bfs()) {       memcpy(cur, head, n * sizeof(int));       dfs(s, 1e9);     }     for (int i = head[s]; ~i; i = next[i])       if (cap[i]) return -1;     for (int i = 0; i < n; ++i)       while (~head[i] && head[i] >= msave) head[i] = next[head[i]];     s = ss, t = tt;     while (bfs()) {       memcpy(cur, head, n * sizeof(int));       dfs(s, 1e9);     }     for (int i = head[s]; ~i; i = next[i]) ans += cap[i ^ 1];     return ans;   }   }  // namespace G   const int N = 1e5;   int x[N], y[N], nx, ny, rx[N], ry[N], cnt[2 * N], lim[2 * N];   char ans[N + 1];   int main() {     int n, m, r, b;     bool rev = false;     n = rd(), m = rd(), r = rd(), b = rd();     if (r > b) rev = true, std::swap(r, b);     for (int i = 0; i < n; ++i) {       x[i] = rx[i] = rd();       y[i] = ry[i] = rd();     }     std::sort(rx, rx + n);     nx = std::unique(rx, rx + n) - rx;     std::sort(ry, ry + n);     ny = std::unique(ry, ry + n) - ry;     G::init(nx + ny + 4, nx + ny + 2, nx + ny + 3);     for (int i = 0; i < n; ++i) {       x[i] = std::lower_bound(rx, rx + nx, x[i]) - rx;       y[i] = std::lower_bound(ry, ry + ny, y[i]) - ry;       ++cnt[x[i]], ++cnt[nx + y[i]];       G::add_edge(x[i], nx + y[i], 0, 1);     }     std::fill(lim, lim + nx + ny, n);     while (m--) {       int t = rd(), l = rd(), d = rd();       if (t == 1) {         int i = std::lower_bound(rx, rx + nx, l) - rx;         if (rx[i] == l) cmin(lim[i], d);       } else {         int i = std::lower_bound(ry, ry + ny, l) - ry;         if (ry[i] == l) cmin(lim[nx + i], d);       }     }     for (int i = 0; i < nx + ny; ++i) {       lim[i] -= (lim[i] + cnt[i]) & 1;       if (lim[i] < 0) {         puts( -1 );         return 0;       }       int min = std::max(0, (cnt[i] - lim[i]) / 2), max = (lim[i] + cnt[i]) / 2;       if (i < nx)         G::add_edge(nx + ny, i, min, max);       else         G::add_edge(i, nx + ny + 1, min, max);     }     int f = G::flow(nx + ny, nx + ny + 1);     if (f == -1) {       puts( -1 );       return 0;     }     for (int i = 0; i < n; ++i) ans[i] =  rb [rev ^ G::cap[2 * i]];     printf( %lld n%s n , (long long)r * f + (long long)b * (n - f), ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       long long a, b, ans;       cin >> a >> b;       long long x;       x = min(a, b);       ans = max(max(a, b), 2 * x);       cout << ans * ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modpow(long long int a, long long int n, long long int temp) {     long long int res = 1;     while (n > 0) {       res = (res * res) % temp;       if (n & 1) res = (res * a) % temp;       n /= 2;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0)       return (b);     else       return (gcd(b % a, a));   }   void f(int a[][1001], int x, int y) {     if (a[x][y] >= 4) {       int t = a[x][y] / 4;       a[x][y + 1] += t;       a[x + 1][y] += t;       a[x - 1][y] += t;       a[x][y - 1] += t;       a[x][y] = a[x][y] % 4;       f(a, x + 1, y);       f(a, x - 1, y);       f(a, x, y + 1);       f(a, x, y - 1);     }   }   int main() {     int a[1001][1001] = {0};     int n, q, x, y;     cin >> n >> q;     a[500][500] = n;     f(a, 500, 500);     while (q--) {       cin >> x >> y;       x += 500;       y += 500;       if (x > 1000 || y > 1000 || x < 0 || y < 0)         cout << 0 << endl;       else         cout << a[x][y] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pi = 10000000;   vector<long long int> prime(pi), pri;   void seive() {     long long int i, j, k, l;     for (i = 4; i <= pi; i += 2) prime[i] = 1;     pri.push_back(2);     for (i = 3; i <= pi; i += 2) {       if (prime[i] == 0) pri.push_back(i);       for (j = i * i; j <= pi; j += i) {         if (prime[j] == 0) prime[j] = 1;       }     }     cout << pri.size() << endl;   }   int main() {     long long int n, i = 0, l = -2, k = INT_MAX, j, a = 0, f = 1, c = 0, b = 0,                      x = 100000000007, d = 0, y, m, zero = 0, one = 10,                      z = 1000000007;     string s =  qwertyuiopasdfghjkl;zxcvbnm,./ , mar =   , s2;     char ch[26] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                     j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                     s ,  t ,  u ,  v ,  w ,  x ,  y ,  z },          bo, an;     vector<long long int> vc, vct, vctt;     vector<pair<long long int, long long int>> pa;     map<char, char> mp;     double num, nr, radi;     stack<char> bra, bra2;     cin >> n >> m >> s;     for (i = 0; i < m; i++) {       cin >> bo >> an;       for (j = 0; j < 26; j++) {         if (ch[j] == bo)           ch[j] = an;         else if (ch[j] == an)           ch[j] = bo;       }     }     for (i = 0; i < n; i++) {       mar += ch[s[i] -  a ];     }     cout << mar << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s[70010];   map<pair<int, int>, int> m;   pair<int, int> ans[70010];   int main() {     int k = 64, p = 5;     int n, i, j, l;     cin >> n;     for (i = 1; i <= n; i++) cin >> s[i];     for (i = 1; i <= n; i++)       for (j = 0; j < 9; j++) {         int x = 0;         for (l = j; l < 9; l++) {           x = x * 10 + s[i][l] -  0 ;           if (m.find(pair<int, int>(x, l - j + 1)) != m.end() &&               m[pair<int, int>(x, l - j + 1)] != i)             m[pair<int, int>(x, l - j + 1)] = -1;           else             m[pair<int, int>(x, l - j + 1)] = i;         }       }     for (auto it = m.begin(); it != m.end(); it++) {       if (it->second == -1) continue;       if (ans[it->second].second == 0 ||           ans[it->second].second > it->first.second)         ans[it->second] = pair<int, int>(it->first.first, it->first.second);     }     for (i = 1; i <= n; i++) {       char s[10];       sprintf(s,  %%0%dd n , ans[i].second);       printf(s, ans[i].first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 10;   int f[MAX_N], g[MAX_N], h[MAX_N], pos[MAX_N];   vector<int> adj[MAX_N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int m = 0;     for (int i = 1; i <= n; i++) {       cin >> f[i];       if (adj[f[i]].empty()) {         m++;         h[m] = f[i];         pos[f[i]] = m;       }       adj[f[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < adj[i].size(); j++) {         if (g[adj[i][j]] != 0) {           cout <<  -1 n ;           return 0;         }         g[adj[i][j]] = pos[i];       }     }     for (int i = 1; i <= n; i++) {       if (!g[i]) {         cout <<  -1 n ;         return 0;       }     }     for (int i = 1; i <= m; i++) {       if (g[h[i]] != i) {         cout <<  -1 n ;         return 0;       }     }     cout << m <<   n ;     for (int i = 1; i <= n; i++) {       cout << g[i];       if (i < n) cout <<    ;     }     cout <<   n ;     for (int i = 1; i <= m; i++) {       cout << h[i];       if (i < m) cout <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, xa, ya, xb, yb;   int main() {     scanf( %d%d%d%d%d%d , &a, &b, &xa, &ya, &xb, &yb);     a <<= 1, b <<= 1;     int x1 = (xa + ya), y1 = (xa - ya), x2 = (xb + yb), y2 = (xb - yb);     int sector_1_x = (x1 / a) - (x1 < 0), sector_1_y = (y1 / b) - (y1 < 0);     int sector_2_x = (x2 / a) - (x2 < 0), sector_2_y = (y2 / b) - (y2 < 0);     printf( %d n ,            max(abs(sector_1_x - sector_2_x), abs(sector_1_y - sector_2_y)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M, n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long ttttt = 1;     while (ttttt--) {       cin >> M >> n;       long long a[n], ans[n];       cin >> a[0];       long long ok = -1;       if (a[0] <= M * -1) ok = 1;       for (long long i = 1; i < n; i++) {         cin >> a[i], a[i] += a[i - 1];         if (a[i] <= M * -1 && ok == -1) ok = i + 1;       }       if (ok != -1) {         cout << ok;         cout <<   n ;         return 0;       }       if (a[n - 1] >= 0) {         cout << -1;         cout <<   n ;         return 0;       }       for (long long i = 0; i < n; i++) {         long long x = M + a[i];         x = ceil(x / (a[n - 1] * -1.0));         ans[i] = x * n + i + 1;       }       for (long long i = 0; i < n; i++) ans[0] = min(ans[0], ans[i]);       cout << ans[0];       cout <<   n ;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mpow(int base, int exp);   void ipgraph(int m);   void dfs(int u, int par);   const int mod = 1000000007;   const int N = 1e6, M = N;   const int LN = 1e9;   long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   struct cmp {     bool operator()(const pair<int, int> &a, const pair<int, int> &b) {       int len1 = a.second - a.first + 1;       int len2 = b.second - b.first + 1;       if (len1 == len2) {         return a.first < b.first;       }       return len1 > len2;     }   };   long long fac[N], inv[N], b[N];   int mpow(int base, int exp) {     base %= mod;     int result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long)result * base) % mod;       base = ((long long)base * base) % mod;       exp >>= 1;     }     return result;   }   void pre() {     int i;     fac[0] = inv[0] = 1;     fac[1] = inv[1] = 1;     for (i = 2; 2 < N ? i < N : i > N; 2 < N ? i += 1 : i -= 1) {       fac[i] = (i * fac[i - 1]) % mod;       inv[i] = (mpow(i, mod - 2) * inv[i - 1]) % mod;     }   }   long long C(int n, int r) {     if (r > n) return 0;     long long ans = fac[n];     ans *= inv[r];     ans %= mod;     ans *= inv[n - r];     ans %= mod;     return ans;   }   long long n;   vector<vector<int>> arr(50, vector<int>(50));   vector<int> permutation;   int chosen[100] = {0};   long long power(long long a, long long b) {     long long ans = 1;     while (b--) ans *= a;     return ans;   }   long long k;   long long dp[N][2];   vector<int> adj[N];   long long m;   void solve() {     long long a, b, c, p = 0, q, d, r, s, l, t, x, h, y, z, avg, x1, x2, y1, y2,                        i, j, ii, jj, count = 0;     string s1, s2 =   , sa =   , sb =   , sc =   , ans =   ;     cin >> a >> b >> c;     if (a >= c) {       cout << -1 <<    ;     } else {       cout << 1 <<    ;     }     if (c < a * b) {       cout << b << endl;     } else       cout << -1 << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int const MOD = 1000000007;   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int f[42], when[42];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int s = 1;     int c = getchar();     while (c <= 32) {       c = getchar();     }     int cn = 0;     while (c > 32) {       int olds = s;       add(s, s);       add(s, MOD - f[c -  a ]);       f[c -  a ] = olds;       when[c -  a ] = ++cn;       c = getchar();     }     for (int i = 0; i < n; i++) {       int v = -1;       for (int j = 0; j < k; j++) {         if (v < 0 || when[v] > when[j]) {           v = j;         }       }       when[v] = ++cn;       int olds = s;       add(s, s);       add(s, MOD - f[v]);       f[v] = olds;     }     printf( %d n , s);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, d, v, g, r, tmu;     double tm, tmod;     scanf( %d%d%d%d%d , &l, &d, &v, &g, &r);     tmu = (int)((long double)(d / v) / (g + r));     tmod = (double)d / v - tmu * (g + r);     if (tmod < g)       tm = (double)l / v;     else       tm = (double)l / v + (r - tmod + g);     printf( %.8f n , tm);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a;     cin >> n >> m;     int l = 0, r = n + 1;     string s, s1;     for (int i = 0; i < m; i++) {       cin >> s >> s >> s1 >> s >> a;       if (s1[0] ==  r )         l = max(l, a);       else         r = min(a, r);     }     int ans = r - l - 1;     if (ans <= 0)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int j = i - x;       int k = i + y;       if (j < 0) j = 0;       if (k > n - 1) k = n - 1;       int min = INT_MAX, index = -1;       for (int l = j; l <= k; l++) {         if (min > a[l]) {           min = a[l];           index = l;         }       }       if (index == i) {         cout << index + 1 <<   n ;         break;       } else {         i = index - 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void reverseStr(string& str) {     int n = str.length();     for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]);   }   int main() {     string str, str1;     cin >> str;     cin >> str1;     reverseStr(str);     if (str == str1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> out(n);     long long leafs = n;     for (long long i = 0; i < m; ++i) {       long long x, y;       cin >> x >> y;       --x;       --y;       if (x > y) swap(x, y);       out[x]++;       if (out[x] == 1) --leafs;     }     long long q;     cin >> q;     while (q--) {       long long t;       cin >> t;       if (t == 3) {         cout << leafs << endl;       } else if (t == 1) {         long long u, v;         cin >> u >> v;         --u;         --v;         if (u > v) swap(u, v);         ++out[u];         if (out[u] == 1) --leafs;       } else {         long long u, v;         cin >> u >> v;         --u;         --v;         if (u > v) swap(u, v);         --out[u];         if (out[u] == 0) ++leafs;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << fixed << setprecision(15);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[3010];   int cycle[3010];   int cycle_size;   bool visited[3010];   bool found_cycle;   int dist[3010];   int b, e;   void dfs(int node, int father, int c) {     if (found_cycle) return;     visited[node] = true;     for (int i = 0; i < graph[node].size() && !found_cycle; i++) {       int nextn = graph[node][i];       if (visited[nextn] && nextn != father) {         cycle[c] = node;         cycle_size = c + 1;         while (cycle[c] != nextn) {           c--;         }         b = c;         found_cycle = true;         return;       }       if (nextn == father) continue;       cycle[c] = node;       dfs(nextn, node, c + 1);     }   }   void bfs() {     queue<pair<int, int> > q;     for (int i = b; i < cycle_size; i++) {       visited[cycle[i]] = true;       q.push(make_pair(cycle[i], 0));     }     while (!q.empty()) {       pair<int, int> aux = q.front();       q.pop();       dist[aux.first] = aux.second;       for (int i = 0; i < graph[aux.first].size(); i++) {         int nextn = graph[aux.first][i];         if (visited[nextn]) continue;         visited[nextn] = true;         q.push(make_pair(nextn, aux.second + 1));       }     }   }   int main() {     int n;     scanf( %d , &n);     int xi, yi;     for (int i = 0; i < n; i++) {       scanf( %d %d , &xi, &yi);       graph[xi].push_back(yi);       graph[yi].push_back(xi);     }     found_cycle = false;     memset(visited, false, sizeof(visited));     dfs(1, -1, 0);     memset(visited, false, sizeof(visited));     bfs();     for (int i = 1; i <= n; i++) printf( %d  , dist[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int N = 2e5 + 10;   int T, n, a[N], vis[N], d[N], mi, mx;   signed main() {     cin >> T;     while (T--) {       cin >> n;       mi = 0x3f3f3f3f, mx = -999;       for (int i = 1; i <= n; i++) scanf( %d , &a[i]), vis[a[i]] = i;       for (int i = 1; i <= n; i++) {         mi = min(mi, vis[i]), mx = max(mx, vis[i]);         if (mx - mi == i - 1)           putchar( 1 );         else           putchar( 0 );       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const int MOD = INF + 7;   const int XD = 100100;   int facts[XD << 1];   void calcFacts(int n) {     facts[0] = 1;     for (int i = 1; i <= n; ++i) {       facts[i] = 1LL * facts[i - 1] * i % MOD;     }   }   int exgcd(int a, int b, int &x, int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int xx, yy;     int d = exgcd(b % a, a, xx, yy);     x = yy - b / a * xx;     y = xx;     return d;   }   int getInv(int n) {     int x, y;     exgcd(n, MOD, x, y);     x = (x % MOD + MOD) % MOD;     return x;   }   int cnk(int n, int k) {     return 1LL * facts[n] * getInv(facts[n - k]) % MOD * getInv(facts[k]) % MOD;   }   int main() {     int zeroes, ones, sm;     cin >> zeroes >> ones >> sm;     if (zeroes == 0) {       if (sm == 1) {         cout << ((ones == 1) ? 1 : 0);       } else {         cout << ((ones == 1) ? 0 : 1);       }       return 0;     }     if (ones == 0) {       if (sm == 1) {         cout << ((zeroes & 1) ? 0 : 1);       } else {         cout << ((zeroes & 1) ? 1 : 0);       }       return 0;     }     calcFacts(zeroes + ones);     int res = 0;     for (int pos = 0; pos <= zeroes; ++pos) {       if (sm == 0 &&           (pos % 2 == 0 && (pos < zeroes || pos == zeroes && ones > 1) ||            pos % 2 == 1 && (pos == zeroes && ones == 1))) {         res += cnk(zeroes + ones - pos - 1, ones - 1);         res %= MOD;       }       if (sm == 1 &&           (pos % 2 == 1 && (pos < zeroes || pos == zeroes && ones > 1) ||            pos % 2 == 0 && (pos == zeroes && ones == 1))) {         res += cnk(zeroes + ones - pos - 1, ones - 1);         res %= MOD;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200][200], ans, n;   bool flag = true;   int main() {     ios::sync_with_stdio(false);     cin >> a[80][80] >> n;     while (flag) {       flag = false;       for (int i = 1; i < 160; i++)         for (int j = 1; j < 160; j++)           if (a[i][j] >= 4) {             flag = true;             int k = a[i][j] / 4;             a[i + 1][j] += k, a[i - 1][j] += k;             a[i][j + 1] += k, a[i][j - 1] += k;             a[i][j] -= 4 * k;           }     }     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (-80 < x && x < 80 && -80 < y && y < 80)         cout << a[x + 80][y + 80] <<   n ;       else         cout << 0 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, m, k;     cin >> n >> m >> k;     vector<long long int> ans;     if (k > 1) {       long long int last = 0;       for (long long int i = 0; i < k; i++) {         ans.push_back(0);       }       last = n - 1;       for (long long int i = 1; i < n + m; i++) {         if (i == last) {           ans.push_back(i);         } else if (i == last + 1) {           for (long long int j = 0; j < k - 1; j++) ans.push_back(i);           last = i + n - 1;         }       }     } else {       ans.push_back(0);       long long int last = n - 1;       for (long long int i = 1; i < n + m; i++) {         if (i == last) {           ans.push_back(i);           last = i + n - 1;         }       }     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[150005];   int Size[150005];   int forbid[150005];   int val[150005];   vector<int> stk;   void dfs(int first, int f) {     Size[first] = 1;     stk.push_back(first);     for (auto it : v[first]) {       if (it != f && !forbid[it]) {         dfs(it, first);         Size[first] += Size[it];       }     }   }   bool cmp(const int &a, const int &b) { return Size[a] < Size[b]; }   int find_cen(int first) {     stk.clear();     dfs(first, 0);     sort(stk.begin(), stk.end(), cmp);     for (auto it : stk) {       if (Size[it] >= Size[first] / 2) {         return it;       }     }   }   long long ans;   vector<pair<long long, long long> > vv;   void dfs2(int first, int f, long long sum, long long sum2, long long len) {     sum += val[first];     sum2 += sum;     vv.push_back(make_pair(len, sum2));     for (auto it : v[first]) {       if (it != f && !forbid[it]) {         dfs2(it, first, sum, sum2, len + 1);       }     }   }   void dfs3(int first, int f, long long sum, long long sum2, long long len) {     sum += val[first];     sum2 += val[first] * len;     vv.push_back(make_pair(sum, sum2));     for (auto it : v[first]) {       if (it != f && !forbid[it]) {         dfs3(it, first, sum, sum2, len + 1);       }     }   }   struct DATA {     long long first, second, st;   };   int op;   bool operator<(const DATA &p, const DATA &q) {     if (op == 0)       return p.first < q.first;     else       return p.st < q.st;   }   void go(int first) {     int cen = find_cen(first);     set<DATA> s;     for (int t = 0; t < 2; t++) {       s.insert({0, 0, -1000000000});       for (auto first : v[cen]) {         if (forbid[first]) continue;         dfs2(first, cen, val[cen], val[cen], 2);         op = 1;         for (auto p : vv) {           if (s.empty()) break;           auto it = prev(s.upper_bound({0, 0, p.first}));           ans = max(ans, p.first * it->first + it->second + p.second);         }         vv.clear();         dfs3(first, cen, 0, 0, 1);         op = 0;         for (auto p : vv) {           auto it = s.lower_bound({p.first, p.second, 0});           if (it != s.end() && it->first == p.first) {             if (it->second > p.second)               continue;             else {               s.erase(*it);               it = s.lower_bound({p.first, p.second, 0});             }           }           while (it != s.end()) {             DATA d = *it;             auto it2 = next(it);             s.erase(it);             it = it2;             long long st = (p.second - d.second) / (d.first - p.first);             d.st = st;             if (it == s.end() || it->st > st) {               s.insert(d);               break;             }           }           it = s.lower_bound({p.first, p.second, 0});           int st = -1e9;           while (it != s.begin()) {             DATA d = *prev(it);             st = (d.second - p.second) / (p.first - d.first);             if (st <= d.st) {               s.erase(d);             } else {               break;             }           }           if (it == s.end() || it->st > st) s.insert({p.first, p.second, st});         }         vv.clear();       }       reverse(v[cen].begin(), v[cen].end());       s.clear();     }     forbid[cen] = 1;     for (auto it : v[cen]) {       if (!forbid[it]) {         go(it);       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int first, second;       scanf( %d %d , &first, &second);       v[first].push_back(second);       v[second].push_back(first);     }     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     go(1);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   int a, b, c, d, n;   char s[4 << 20];   void output() {     for (int i = 0; i < n; ++i)       if (s[i] ==  4 )         a--;       else         b--;     for (int i = 0; i < n; ++i)       if (s[i] ==  4 ) {         while (a) {           printf( 4 );           a--;         }         printf( 4 );       } else {         while ((i + 2 >= n) && b) {           printf( 7 );           b--;         }         printf( 7 );       }     printf(  n );     exit(0);   }   void look(char c4, char c7, int a, int b, int c, int d) {     n = 0;     while (c) {       if (n) d--;       s[n++] = c4;       s[n++] = c7;       a--;       b--;       c--;     }     if (d > 0) {       s[n++] = c4;       a--;       d--;     }     if ((a < 0) || (b < 0) || (c != 0) || (d != 0)) return;     output();   }   int main() {     scanf( %d%d%d%d , &a, &b, &c, &d);     look( 4 ,  7 , a, b, c, d);     look( 7 ,  4 , b, a, d, c);     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int inf = 0x3f3f3f3f;   int n, m;   long long ans;   long long b[maxn], g[maxn];   bool cmp(int a, int b) { return a > b; }   int main() {     long long bmx = 0;     int flag = 1, cnt = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld , &b[i]);       ans += b[i] * m;       bmx = max(bmx, b[i]);     }     sort(b + 1, b + 1 + n, cmp);     for (int i = 1; i <= m; i++) {       scanf( %lld , &g[i]);       if (g[i] < bmx) flag = 0;       if (g[i] > bmx) {         cnt++;         ans += g[i] - b[1 + cnt / m];       }     }     if (flag) {       printf( %lld n , ans);     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n * 2];     for (int i = 0; i < n * 2; i++) {       cin >> a[i];     }     int room = 0;     for (int i = 0; i < n * 2; i++) {       if (i % 2 == 0) {         if (a[i + 1] - a[i] >= 2) {           room++;         }       }     }     cout << room;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int m, n;       scanf( %d %d , &m, &n);       if (m % n == 0)         printf( YES n );       else         printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s =   ;     int f[n];     f[0] = 1, f[1] = 1;     if (n > 1 && n < 5) {       for (int i = 2; i < 2 * n; i++) f[i] = f[i - 2] + f[i - 1];       int g = 1, k = 0;       while (g <= n) {         for (int j = 0; j < 2 * n; j++)           if (g == f[j]) {             k++;           }         if (k > 0)           s = s +  O ;         else if (k == 0)           s = s +  o ;         g++;         k = 0;       }     } else {       for (int i = 2; i < n; i++) f[i] = f[i - 2] + f[i - 1];       int g = 1, k = 0;       while (g <= n) {         for (int j = 0; j < n; j++)           if (g == f[j]) {             k++;           }         if (k > 0)           s = s +  O ;         else if (k == 0)           s = s +  o ;         g++;         k = 0;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long int arr1[], long long int arr2[], long long int m,              long long int n) {     sort(arr1, arr1 + n);     sort(arr2, arr2 + m);     for (int i = 0; i < n; i++)       if (arr1[i] != arr2[i]) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x, y;       cin >> n >> m >> x >> y;       char a[n][m], dp[n + 1][m + 1];       long long int c = 0, ans = 0;       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       memset(dp, 0, sizeof(dp));       dp[1][1] = x;       for (long long int i = 0; i < n; i++) {         c = 0;         for (long long int j = 0; j < m; j++) {           if (a[i][j] ==  .  && j + 1 < m && a[i][j + 1] ==  . ) {             ans += min(x * 2, y);             j++;           } else if (a[i][j] ==  . )             ans += x;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9 + 10;   int read() {     int xx = 0, ww = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ww = -ww;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = 10 * xx + ch - 48;       ch = getchar();     }     return xx * ww;   }   deque<int> q;   int n, k, a;   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) q.push_back(i);     for (int i = 1; i <= k; i++) {       a = read();       a %= q.size();       while (a--) {         q.push_back(q.front());         q.pop_front();       }       int v = q.front();       q.pop_front();       if (i != 1) printf(   );       printf( %d , v);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, x, ans[300300], tree[4 * 300300];   void build(int node, int st, int en) {     if (st == en) {       tree[node] = 1;       return;     }     build((node << 1), st, (st + en) / 2);     build((node << 1) + 1, ((st + en) / 2) + 1, en);     tree[node] = tree[(node << 1)] + tree[(node << 1) + 1];   }   void update(int node, int st, int en, int left, int right, int val) {     if (left > en || right < st) return;     if (tree[node] == 0) return;     if (st == en) {       tree[node] = (st == x ? 1 : 0);       ans[st] = val;       return;     }     update((node << 1), st, (st + en) / 2, left, right, val);     update((node << 1) + 1, ((st + en) / 2) + 1, en, left, right, val);     tree[node] = tree[(node << 1)] + tree[(node << 1) + 1];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     build(1, 1, n);     while (m--) {       cin >> l >> r >> x;       update(1, 1, n, l, r, x);     }     ans[x] = 0;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   struct Nodo {     int a;     int sgte;   } Nodo[100100];   long long aux[50010][510];   long long int cont;   int dir[50001];   int n, k;   void agregar(int x, int y, int c);   void busqueda(int fa, int u);   int main() {     int x, y, i, t, cargado = 0;     scanf( %d %d , &n, &k);     for (t = 0; t < 50010; t++) {       dir[t] = -1;     }     for (i = 0; i < (n - 1); i++) {       scanf( %d %d , &x, &y);       agregar(x, y, cargado);       cargado++;       agregar(y, x, cargado);       cargado++;     }     busqueda(0, 1);     printf( %I64d , cont);     return 0;   }   void busqueda(int ant, int act) {     int i = 0, v, j;     aux[act][0] = 1;     for (i = dir[act]; i != -1; i = Nodo[i].sgte) {       v = Nodo[i].a;       if (ant != v) {         busqueda(act, v);         for (j = 0; j < k; j++) {           cont += aux[act][j] * aux[v][k - j - 1];         }         for (j = 1; j <= k; j++) {           aux[act][j] += aux[v][j - 1];         }       }     }   }   void agregar(int x, int y, int c) {     Nodo[c].a = y;     Nodo[c].sgte = dir[x];     dir[x] = c;   }


#include <bits/stdc++.h>   using namespace std;   long long k;   long long maxi = 0, mini = 0;   vector<long long> v[200001];   long long dp[200001];   unordered_map<long long, unordered_map<long long, long long> > dis;   long long f(long long parent) {     if (dp[parent] > 0) return dp[parent];     dp[parent] = -1;     long long ans = 0;     for (long long i = 0; i < v[parent].size(); i++) {       long long child = v[parent][i];       if (dp[child] != -1) ans += f(child);     }     dp[parent] = ans + 1;     for (long long i = 0; i < v[parent].size(); i++) {       long long child = v[parent][i];       if (dp[child] != -1) {         maxi += (min(dp[child], 2 * k - dp[child]) * (dis[child][parent]));         if (dp[child] % 2 == 1 || 2 * k - dp[child] % 2 == 1)           mini += dis[child][parent];       }     }     return dp[parent];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       maxi = 0;       mini = 0;       long long start;       cin >> k;       for (long long i = 1; i <= 2 * k; i++) v[i].clear();       dp[2 * k - 1] = 0;       dp[2 * k] = 0;       for (long long i = 0; i < 2 * k - 1; i++) {         dp[i] = 0;         long long u1, u2, time;         cin >> u1 >> u2 >> time;         v[u1].push_back(u2);         v[u2].push_back(u1);         dis[u2][u1] = time;         dis[u1][u2] = time;       }       for (long long i = 1; i <= 2 * k; i++) {         if (v[i].size() == 1) {           start = i;           dp[i] = 1;         }       }       dp[start] = -1;       f(start);       cout << mini <<     << maxi << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int arr[1009];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int x1, y1, x2, y2;     for (int i = 0; i < n - 1; i++) {       x1 = min(arr[i], arr[i + 1]);       y1 = max(arr[i], arr[i + 1]);       for (int j = i + 1; j < n - 1; j++) {         x2 = min(arr[j], arr[j + 1]);         y2 = max(arr[j], arr[j + 1]);         if ((x1 < x2 && y1 > x2 && y2 > y1) || (x2 < x1 && y2 > x1 && y1 > y2)) {           printf( yes n );           return 0;         }       }     }     printf( no n );     return 0;   }


#include <bits/stdc++.h>   int a[4 * 4];   int n, n2;   std::map<int, int> sums[4 + 1];   void gens(int p, int cnt, int sum, std::map<int, int>& s) {     if (cnt == 0) {       std::map<int, int>::iterator it = s.find(sum);       if (it == s.end())         s[sum] = 1;       else         ++it->second;       return;     }     if (p >= n2) return;     gens(p + 1, cnt, sum, s);     gens(p + 1, cnt - 1, sum + a[p], s);   }   int m[4][4];   int hs[4], vs[4], ds1, ds2;   bool used[4 * 4];   int sum;   void doit(int i, int j, int v) {     hs[i] += v;     vs[j] += v;     if (i == j) ds1 += v;     if (i == n - j - 1) ds2 += v;   }   bool gen(int i, int j) {     if (i == n) return true;     for (int k = 0; k < n2; ++k)       if (!used[k]) {         int v = a[k];         m[i][j] = v;         doit(i, j, v);         if (i == n - 1 && vs[j] != sum) {           doit(i, j, -v);           continue;         }         if (j == n - 1 && hs[i] != sum) {           doit(i, j, -v);           continue;         }         if (i == n - 1 && j == 0 && ds2 != sum) {           doit(i, j, -v);           continue;         }         if (i == n - 1 && j == n - 1 && ds1 != sum) {           doit(i, j, -v);           continue;         }         if (hs[i] > sum || vs[j] > sum || ds1 > sum || ds2 > sum) {           doit(i, j, -v);           continue;         }         used[k] = true;         int i2 = i, j2 = j + 1;         if (j2 == n) {           ++i2;           j2 = 0;         }         if (gen(i2, j2)) return true;         used[k] = false;         doit(i, j, -v);       }     return false;   }   int main() {     scanf( %d , &n);     n2 = n * n;     int min = 0;     for (int i = 0; i < n2; ++i) {       scanf( %d , &a[i]);       if (a[i] < min) min = a[i];     }     min = -min;     for (int i = 0; i < n2; ++i) a[i] += min;     for (int i = 1; i <= n; ++i) {       gens(0, i, 0, sums[i]);     }     bool res = false;     for (std::map<int, int>::const_iterator i = sums[n].begin();          i != sums[n].end(); ++i) {       sum = i->first;       memset(hs, 0, sizeof(hs));       memset(vs, 0, sizeof(vs));       memset(used, 0, sizeof(used));       ds1 = 0;       ds2 = 0;       if (gen(0, 0)) {         res = true;         break;       }     }     if (!res) {       printf( sorry. i am failed );       return 0;     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) m[i][j] -= min;     int s = 0;     for (int i = 0; i < n; ++i) s += m[i][0];     printf( %d n , s);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (j > 0) printf(   );         printf( %d , m[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long x, long long y, long long m) {     long long ans;     if (y <= 0) return 1;     ans = bin_pow(x, y / 2, m);     if (y % 2 == 0) return (((ans % m) * (ans % m)) % m);     return (x % m * ((ans % m * ans % m))) % m;   }   long long mult(long long a, long long b, long long m) {     long long ans = ((a % m) * (b % m)) % m;     return ans;   }   long long sum(long long a, long long b, long long m) {     long long ans = (a % m + b % m) % m;     return ans;   }   long long diff(long long a, long long b, long long m) {     long long ans = ((a % m) - (b % m) + m) % m;     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void swap(long long &a, long long &b) {     long long tm = a;     a = b;     b = tm;   }   long long compute_lps_array(string s) {     string s1 = s;     reverse(s1.begin(), s1.end());     s = s +  $  + s1;     long long sz = s.size();     vector<long long> lps(sz + 1, 0);     lps[0] = 0;     for (long long i = 1; i < sz; i++) {       long long j = lps[i - 1];       while (j != 0 && (s[i] != s[j])) j = lps[j - 1];       if (s[i] == s[j]) j++;       lps[i] = j;     }     return lps[sz - 1];   }   long long nCr(long long n, long long r, long long m) {     long long tm1 = bin_pow(r, 998244353 - 2, 998244353);     long long tm2 = bin_pow(m, 998244353 - 2, 998244353);     long long tm3 = n % 998244353;     long long ans = mult(tm3, mult(tm1, tm2, 998244353), 998244353);     return ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       string s, t;       long long ans = 0;       cin >> s >> t;       long long sz1 = s.size();       long long sz2 = t.size();       vector<long long> pre(sz2 + 2, 0), sfx(sz2 + 2, 0);       long long j = 0;       for (long long i = 0; i < sz1; i++) {         if (s[i] == t[j]) {           pre[j] = i;           j++;           if (j >= sz2) break;         }       }       j = sz2 - 1;       for (long long i = sz1 - 1; i >= 0; i--) {         if (s[i] == t[j]) {           sfx[j] = i;           j--;           if (j == -1) break;         }       }       ans = max(sfx[0], sz1 - pre[sz2 - 1] - 1LL);       for (long long i = 0; i < sz2 - 1; i++) {         long long df = sfx[i + 1] - pre[i] - 1;         ans = max(ans, df);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   int num[10000];   int map[2000][2000];   int add(int a, int b, int c) { map[a][b] = 1, map[b][a] = 1; }   int vis[2000][2];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       memset(map, 0, sizeof(map));       memset(vis, 0, sizeof(vis));       int i, j;       int len = 0;       int ans = 0;       memset(map, 0, sizeof(map));       memset(num, 0, sizeof(num));       for (i = 0; i <= 30; i++) {         if (n & (1 << i)) {           num[i]++;           len = i;         }       }       int index = 3;       for (i = 0; i <= 30; i++) {         if (i != len) continue;         int x, y;         if (i == 0) {           add(1, 2, 1);           index = 3;           continue;         }         for (j = 1; j <= i; j++) {           if (j == 1) {             add(1, index++, 3);             add(1, index++, 4);             x = index - 1;             y = index - 2;           } else {             add(x, index, 5);             index++;             add(y, index, 6);             index++;             add(x, index - 1, 7);             add(y, index - 2, 8);             x = index - 1;             y = index - 2;           }           vis[j][0] = x;           vis[j][1] = y;         }         if (i == len) {           add(x, 2, 1);           add(y, 2, 1);           continue;         }       }       for (i = 0; i <= 30; i++) {         if (num[i] && i != len) {           int x = 1;           for (j = 1; j <= len - i; j++) {             add(x, index++, 1);             x = index - 1;           }           if (i == 0) {             add(x, 2, 1);             continue;           }           add(x, vis[len - i + 1][0], 1);           add(x, vis[len - i + 1][1], 1);         }       }       printf( %d n , index - 1);       for (i = 1; i < index; i++) {         for (j = 1; j < index; j++) {           if (map[i][j] == 1)             printf( Y );           else             printf( N );         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int del(int n) {     double q = n;     if (n % 2 == 0) return 2;     for (int i = 3; i < sqrt(q) + 1; i = i + 2) {       if (n % i == 0) return i;     }     return 1;   }   int main() {     int n;     cin >> n;     long int s;     s = n;     int de = n;     while (n != 1) {       de = del(n);       n = n / de;       if (de == 1) {         s++;         cout << s;         return 0;       };       s += n;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, m;     cin >> n >> m;     if (m == 0) {       cout << 0;       return 0;     }     vector<vector<long long int>> v[n + 1];     long long int in[n + 1];     memset(in, 0, sizeof(in));     for (long long int i = 0; i < m; i++) {       long long int x, y, z;       cin >> x >> y >> z;       v[x].push_back({y, z});       in[y] += 1;     }     queue<vector<long long int>> q;     for (long long int i = 1; i <= n; i++) {       if (in[i] == 0 && v[i].size()) {         q.push({i, INT_MAX, i});       }     }     vector<vector<long long int>> ans;     while (q.size()) {       vector<long long int> p = q.front();       q.pop();       if (p.size() && v[p[0]].size() == 0) {         ans.push_back({p[2], p[0], p[1]});       }       for (auto x : v[p[0]]) {         in[x[0]] -= 1;         if (in[x[0]] == 0) {           q.push({x[0], min(p[1], x[1]), p[2]});         }       }     }     cout << ans.size() <<   n ;     sort(ans.begin(), ans.end());     for (auto x : ans) {       for (auto y : x) cout << y <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     cin.tie(nullptr);     long long int n;     cin >> n;     bool prime = true;     for (long long int i = 2; i < n && i < 101010; ++i) {       if (n % i == 0) {         prime = false;       }     }     if (prime) {       cout <<  1 n ;       return 0;     }     if (n % 2 == 0) {       cout <<  2 n ;       return 0;     }     bool prime2 = true;     long long int n2 = n - 2;     for (long long int i = 2; i < n2 && i < 101010; ++i) {       if (n2 % i == 0) {         prime2 = false;       }     }     if (prime2) {       cout <<  2 n ;       return 0;     }     cout <<  3 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 13, M = 1e5 + 13;   inline int qread() {     int res = 0, flag = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (isdigit(c)) res = res * 10 + (c -  0 ), c = getchar();     return res * flag;   }   int n, m, a[N];   inline int Abs(const int &x) { return x < 0 ? -x : x; }   inline long long min(const long long &x, const long long &y) {     return x < y ? x : y;   }   inline int max(const int &x, const int &y) { return x > y ? x : y; }   struct BIT {     int t[M];     inline int lowbit(int x) { return x & -x; }     inline void add(int x, int y) {       while (x <= m) t[x] += y, x += lowbit(x);     }     inline int sum(int x) {       int res = 0;       while (x) res += t[x], x -= lowbit(x);       return res;     }   } T1, T2, T3;   int main() {     n = qread();     for (int i = 1, x; i <= n; ++i) {       x = qread();       a[i] = Abs(x);       ++a[i];       m = max(m, a[i]);     }     long long sum = 0;     for (int i = n; i >= 1; --i) {       sum += T1.sum(a[i] - 1);       T1.add(a[i], 1);     }     long long ans = sum, tot = 0;     for (int i = 1; i <= n; ++i) {       if (T2.sum(a[i] - 1) >= T1.sum(a[i] - 1) - T3.sum(a[i])) {         T1.add(a[i], -1);         T3.add(a[i], 1);         ++tot;       } else {         sum -= T1.sum(a[i] - 1) + tot - T3.sum(a[i]);         T1.add(a[i], -1);         sum += T2.sum(a[i] - 1) + tot;         T2.add(a[i], 1);         ans = min(ans, sum);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void manupulate(string &str) {     for (long long int i = 0; i < str.size(); ++i) str[i] -= 48;   }   bool isprime(long long int n) {     if (n <= 1) return false;     for (long long int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   long long int expo(long long int a, long long int n) {     if (n == 0) return 1;     if (n == 1) return a;     long long int tmp = expo(a, n / 2);     tmp = (tmp * tmp) % (long)(1e9 + 7);     if (n & 1) tmp = (tmp * a) % (long)(1e9 + 7);     return tmp;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       ;       long long int k;       cin >> k;       ;       long long int ar[n], br[n];       for (long long int i = 0; i < n; ++i) cin >> ar[i];       ;       for (long long int i = 0; i < n; ++i) cin >> br[i];       ;       sort(ar, ar + n);       sort(br, br + n, greater<long long int>());       long long int ans = 0;       long long int x = 0;       for (long long int i = 0; i < k; ++i) {         if (br[i] > ar[i]) {           ans += br[i];           ++x;         }       }       for (long long int i = x; i < n; ++i) ans += ar[i];       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   string i2s(T x) {     ostringstream o;     o << x;     return o.str();   }   int n, wt[100001], root;   bool visited[100001];   pair<long long, long long> mem[100001];   vector<int> adj[100001];   pair<long long, long long> go(int u) {     if (visited[u]) return mem[u];     visited[u] = true;     pair<long long, long long>& ret = mem[u];     wt[u]--;     vector<pair<long long, long long> > tmp;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (!visited[v]) {         tmp.push_back(go(v));       }     }     sort(tmp.begin(), tmp.end(), greater<pair<long long, long long> >());     long long l = 0, r = wt[u];     for (int i = 0; i < tmp.size() && i < wt[u]; ++i) {       l += tmp[i].first + 2;       r--;     }     if (r > 0) {       for (int i = 0; i < tmp.size() && r != 0; ++i) {         if (r >= tmp[i].second) {           l += tmp[i].second * 2;           r -= tmp[i].second;         } else {           l += r * 2;           r = 0;         }       }     }     ret = make_pair(l, r);     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       visited[i] = false;       scanf( %d , wt + i);     }     for (int i = 0; i < n - 1; ++i) {       int a, b;       scanf( %d %d , &a, &b);       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     scanf( %d , &root);     wt[--root]++;     printf( %I64d n , go(root).first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iINF = 0x3f3f3f3f;   const long long lINF = 0x3f3f3f3f3f3f3f3f;   inline void read(long long& x) {     int f = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (f = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= f;   }   inline void read(int& x) {     long long t;     read(t);     x = t;   }   const int MAXN = 1e5 + 10;   int n, k, m, t;   int main() {     cin >> n >> k >> m >> t;     while (t--) {       int opt, pos;       cin >> opt >> pos;       if (opt) {         if (pos <= k) k++;         n++;       } else {         if (pos < k) {           k -= pos;           n -= pos;         } else {           n -= n - pos;         }       }       cout << n <<     << k << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dot(complex<double> a, complex<double> b) { return real(conj(a) * b); }   double calcspeed(complex<double> p1, complex<double> p2, complex<double> w,                    double vmax) {     complex<double> r = p2 - p1;     double k =         dot(r, w) + sqrt(pow(dot(r, w), 2) - norm(r) * (norm(w) - vmax * vmax));     k /= abs(r);     return k;   }   double calc(complex<double> p1, complex<double> p2, complex<double> w,               double vmax) {     double speed = calcspeed(p1, p2, w, vmax);     return abs(p2 - p1) / speed;   }   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     double vmax, t;     cin >> vmax >> t;     int vx, vy, wx, wy;     cin >> vx >> vy >> wx >> wy;     if (x1 == x2 && y1 == y2) {       cout << 0 << endl;       return 0;     }     complex<double> r(x2, y2), v(vx, vy), w(wx, wy);     double ret = calc(complex<double>(x1, y1), complex<double>(x2, y2), v, vmax);     if (ret < t) {       printf( %.20f n , ret);       return 0;     }     r -= complex<double>(x1, y1);     v /= r;     w /= r;     vmax /= abs(r);     r /= r;     const double pi = acos(-1);     double low = -pi + 1e-6;     double high = pi - 1e-6;     double f = 0;     for (int i = (0); i < (200); i++) {       double mid1 = (low * 2 + high) / 3;       double mid2 = (low + high * 2) / 3;       complex<double> target1 = polar(200.0, mid1);       complex<double> target2 = polar(200.0, mid2);       complex<double> speed1 = calcspeed(complex<double>(0, 0), target1, v, vmax);       complex<double> speed2 = calcspeed(complex<double>(0, 0), target2, v, vmax);       complex<double> point1 = speed1 * target1 / abs(target1) * t;       complex<double> point2 = speed2 * target2 / abs(target2) * t;       double f1 = calc(point1, r, w, vmax);       double f2 = calc(point2, r, w, vmax);       if (f1 > f2) {         low = mid1;         f = f1;       } else {         high = mid2;         f = f2;       }     }     printf( %.20f n , f + t);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 5, P = 1e9 + 7;   long long n, k, m, res, l, T, ans, mi;   int dp[2][M], A[M], B[M], sum[M];   int main() {     cin >> n >> l >> k;     for (int i = 1; i <= n; i++) {       scanf( %d , A + i);       B[i] = A[i];     }     sort(B + 1, B + 1 + n);     m = unique(B + 1, B + 1 + n) - B - 1;     for (int i = 1; i <= n; i++) A[i] = lower_bound(B + 1, B + 1 + m, A[i]) - B;     T = l / n;     res = l % n;     for (int i = 1; i <= n; i++) dp[1][A[i]]++;     ans = l % P;     for (int i = 2; i <= m; i++) dp[1][i] += dp[1][i - 1];     for (int i = 1; i <= m; i++) sum[i] += dp[1][i];     for (int lop = 2; lop <= min(1ll * k, T); lop++) {       int c = lop & 1;       for (int i = 1; i <= m; i++) dp[c][i] = 0;       for (int i = 1; i <= n; i++)         dp[c][A[i]] = (1ll * (dp[c][A[i]] % P) + 1ll * (dp[!c][A[i]] % P)) % P;       for (int i = 2; i <= m; i++)         dp[c][i] = (1ll * (dp[c][i] % P) + 1ll * (dp[c][i - 1] % P)) % P;       if (lop < k)         for (int i = 1; i <= m; i++)           sum[i] = (1ll * (sum[i] % P) + 1ll * (dp[c][i] % P)) % P;       long long len = (T - lop + 1) % P;       ans = (1ll * (ans % P) + 1ll * (len * dp[c][m] % P)) % P;     }     if (k >= 2 && T >= 1)       for (int i = 1; i <= res; i++)         ans = (1ll * (ans % P) + 1ll * (sum[A[i]] % P)) % P;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N, M[55][55], C[55];   int main() {     cin >> N;     for (int i = 1; i <= N * (N - 1) / 2 - 1; ++i) {       int a, b;       cin >> a >> b;       M[a][b] = M[b][a] = 1;       C[a]++;     }     for (int i = 1; i <= N; ++i)       for (int j = i + 1; j <= N; ++j)         if (!M[i][j]) {           if (C[i] > C[j])             cout << i <<     << j <<   n ;           else             cout << j <<     << i <<   n ;         }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct line {     int x, l;   } c[105];   bool cmp(line a, line b) { return a.x < b.x; }   int f[105][105][2];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &c[i].x, &c[i].l);     sort(c + 1, c + n + 1, cmp);     c[0].x = -1e9;     int ans = 0;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= i; j++)         for (int p1 = 0; p1 <= 1; p1++) {           ans = max(ans, f[i][j][p1]);           int t = c[j].x + p1 * c[j].l, mx = -1e9, id = 0, y = 0;           for (int k = i + 1; k <= n; k++)             for (int p2 = 0; p2 <= 1; p2++) {               int o = c[k].x + p2 * c[k].l;               if (o > mx) mx = o, id = k, y = p2;               f[k][id][y] =                   max(f[k][id][y], f[i][j][p1] + min(o - t, c[k].l) + mx - o);             }         }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     vector<string> nums(n);     for (int i = 0; i < (int)(n); ++i) cin >> nums[i];     vector<long long> c(m, 1);     for (int i = 0; i < (int)(m); ++i) {       for (int j = 0; j < (int)(i); ++j) {         int match = 1;         for (int k = 0; k < (int)(n); ++k) {           if (nums[k][i] != nums[k][j]) {             match = 0;             break;           }         }         if (match) {           c[i] = 0;           c[j]++;           break;         }       }     }     vector<vector<long long> > choose(m + 1, vector<long long>(m + 1, 0));     for (int i = 0; i < (int)(m + 1); ++i) {       choose[i][0] = 1;       choose[i][i] = 1;       for (int j = 0; j < (int)(m + 1); ++j) {         if (i && j)           choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % 1000000007;       }     }     vector<long long> dp(m + 1);     dp[0] = 1;     for (int i = 0; i < (int)(m + 1); ++i) {       if (i) {         for (int j = 0; j < (int)(i); ++j) {           dp[i] += (choose[i - 1][j] * dp[i - 1 - j]) % 1000000007;           dp[i] %= 1000000007;         }       }     }     long long ans = 1;     for (int i = 0; i < (int)(m); ++i) {       if (c[i]) ans = (ans * dp[c[i]]) % 1000000007;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> visited;   vector<vector<long long> > adj;   vector<vector<long long> > rev;   vector<long long> order;   vector<char> col;   void dfs1(long long x) {     visited[x] = true;     for (auto y : adj[x]) {       if (!visited[y]) dfs1(y);     }     order.push_back(x);   }   void dfs2(long long x, char colour) {     visited[x] = true;     col[x] = colour;     for (auto y : rev[x]) {       if (!visited[y]) {         dfs2(y, colour);       }     }   }   int32_t main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j;     long long n, k;     cin >> n >> k;     adj.resize(n);     rev.resize(n);     long long p[n];     for (i = 0; i < n; i++) cin >> p[i];     for (i = 0; i < n - 1; i++) {       long long u = p[i + 1] - 1;       long long v = p[i] - 1;       adj[v].push_back(u);       rev[u].push_back(v);     }     for (i = 0; i < n; i++) cin >> p[i];     for (i = 0; i < n - 1; i++) {       long long u = p[i + 1] - 1;       long long v = p[i] - 1;       adj[v].push_back(u);       rev[u].push_back(v);     }     visited.assign(n, false);     for (long long i = 0; i < n; i++) {       if (!visited[i]) dfs1(i);     }     visited.assign(n, false);     reverse(order.begin(), order.end());     vector<long long> condensed[n];     char colour =  a ;     col.resize(n);     for (i = 0; i < n; i++) {       long long v = order[i];       if (!visited[v]) {         dfs2(v, colour);         if (colour !=  z ) ++colour;       }     }     set<long long> numCols;     for (i = 0; i < n; i++) {       numCols.insert(col[i]);     }     if (numCols.size() >= k)       cout <<  YES             <<   n ;     else {       cout <<  NO             <<   n ;       return 0;     }     for (auto ch : col) cout << ch;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[5000001];   int dp[5000000];   int main() {     gets(s);     unsigned long long a = 0, l = 0, r = 0, t = 1;     for (int i = 0; s[i]; i++) {       l = (l * 109) + s[i];       r = r + s[i] * t;       t *= 109;       if (l == r) dp[i + 1] = dp[(i + 1) / 2] + 1;       a += dp[i + 1];     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MAX = 1000000000;   long long MOD = 1000000007;   pair<long long, long long> p[100010];   void solve() {     long long n;     cin >> n;     long long d;     cin >> d;     ;     for (long long i = (0); i < (n); i++) {       long long in1;       cin >> in1;       long long in2;       cin >> in2;       ;       p[i] = {in1, in2};     }     sort(p, p + n);     long long j = 0, sum = 0, ans = 0;     for (long long i = (0); i < (n); i++) {       while (p[j].first - p[i].first < d and j < n) {         sum += p[j].second;         j++;       }       ans = max(ans, sum);       sum -= p[i].second;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long test = 1;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[100];     for (int i = 0; i < n; i++) cin >> a[i];     int num[101] = {0};     for (int i = 0; i < n; i++) num[a[i]]++;     int cnt = 0;     for (int i = 1; i <= 100; i++) cnt += num[i] / 2;     cout << cnt / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, poz, p[250];   double t, v[250], m[250], x[250], aux, mint, tempv1, tempv2;   bool fcomp(int a, int b) { return x[a] < x[b]; }   int main() {     scanf( %d , &n);     scanf( %lf , &t);     for (i = 1; i <= n; ++i)       scanf( %lf , &x[i]), scanf( %lf , &v[i]), scanf( %lf , &m[i]), p[i] = i;     sort(p + 1, p + n + 1, fcomp);     do {       mint = 250.0;       for (i = 1; i < n; ++i)         if (v[p[i]] > v[p[i + 1]]) {           aux = -(x[p[i]] - x[p[i + 1]]) / (v[p[i]] - v[p[i + 1]]);           if (aux < mint) mint = aux, poz = i;         }       if (mint >= t) break;       t -= mint;       for (i = 1; i <= n; ++i) x[i] += v[i] * mint;       tempv1 = (m[p[poz]] - m[p[poz + 1]]) * v[p[poz]] +                2 * m[p[poz + 1]] * v[p[poz + 1]];       tempv1 /= m[p[poz]] + m[p[poz + 1]];       tempv2 =           (m[p[poz + 1]] - m[p[poz]]) * v[p[poz + 1]] + 2 * m[p[poz]] * v[p[poz]];       tempv2 /= m[p[poz]] + m[p[poz + 1]];       v[p[poz]] = tempv1;       v[p[poz + 1]] = tempv2;     } while (1);     for (i = 1; i <= n; ++i) x[i] += v[i] * t, printf( %.9lf n , x[i]);   }


#include <bits/stdc++.h>   const long long mod = 1e6 + 3;   using namespace std;   int g = 0;   int vis[10];   int a[100005];   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 1; i <= n; i++) scanf( %d , a + i), s.insert(a[i]);     int p = s.size();     if (p <= 3) {       if (p == 1) {         printf( YES n );       } else if (p == 2) {         int b[3];         g = 0;         for (set<int>::iterator it = s.begin(); it != s.end(); it++)           g++, b[g] = (*it);         for (int i = 1; i <= n; i++) {           if (a[i] == b[1])             vis[1]++;           else             vis[2]++;         }         printf( YES n );       } else if (p == 3) {         int c[5];         g = 0;         for (set<int>::iterator it = s.begin(); it != s.end(); it++)           g++, c[g] = (*it);         sort(c + 1, c + 1 + g);         for (int i = 1; i <= n; i++) {           if (a[i] == c[1])             vis[1]++;           else if (a[i] == c[2])             vis[2]++;           else             vis[3]++;         }         if ((c[1] + c[3]) == 2 * c[2])           printf( YES n );         else           printf( NO n );       }     } else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long k;     cin >> k;     long long arr[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> arr[i];     }     set<long long> s;     for (long long i = k; i <= n; i++) {       s.insert(arr[i]);     }     if (s.size() != 1) {       cout << -1 << endl;     } else {       long long index = k;       while (index >= 1 && arr[index] == arr[k]) {         index--;       }       index++;       cout << index - 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, curbest;   int ans[5005], t[5005];   int cnt[5005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> t[i];     for (int i = 1; i <= n; i++) {       curbest = 0;       memset(cnt, 0, sizeof cnt);       for (int j = i; j <= n; j++) {         cnt[t[j]]++;         if (cnt[t[j]] > cnt[curbest] ||             cnt[t[j]] == cnt[curbest] && t[j] < curbest) {           curbest = t[j];         }         ans[curbest]++;       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i];       if (i != n)         cout <<    ;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mark[100005];   long long msum[100005];   long long sum[100005];   int c[100005];   long long cs;   int main() {     long long ans = 0;     int i, n, m, x;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %d , &c[i]);     for (i = 1; i <= m; ++i) {       scanf( %d , &x);       mark[x] = 1;     }     for (i = n; i > 0; --i) {       sum[i] = sum[i + 1] + c[i];       msum[i] = msum[i + 1] + c[i] * mark[i];     }     for (i = 1; i <= n; ++i)       if (mark[i])         ans += c[i] * sum[i + 1];       else {         ans += c[i] * msum[i + 1];         if (!mark[i + 1]) ans += (long long)c[i] * c[i + 1];         if (i == 1 && !mark[n]) ans += (long long)c[i] * c[n];       }     printf( %I64d n , ans);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 103;   const int mod = 1e9 + 7;   char s[N];   long long g[N], f[N][N][N];   long long qpow(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a % mod;       a = a * a % mod;       n >>= 1;     }     return ret;   }   int main() {     int n, m;     cin >> n >> m;     scanf( %s , s + 1);     g[0] = g[1] = 1;     for (int i = 2; i <= m; i++) (g[i] = g[i - 1] + g[i - 2]) %= (mod - 1);     for (int i = 0; i <= m; i++) g[i] = qpow(2, g[i]);     for (int i = 1; i <= n; i++) {       if (s[i] ==  1 )         f[1][i][i] = 1;       else         f[0][i][i] = 1;     }     for (int i = 2; i <= m; i++)       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           if (l == 1)             (f[i][l][r] += f[i - 2][l][r] * g[i - 1] % mod) %= mod;           else             (f[i][l][r] += f[i - 2][l][r]) %= mod;           if (r == n)             (f[i][l][r] += f[i - 1][l][r] * g[i - 2] % mod) %= mod;           else             (f[i][l][r] += f[i - 1][l][r]) %= mod;           for (int j = 1; j < r; j++) {             (f[i][l][r] += f[i - 1][l][j] * f[i - 2][j + 1][r] % mod) %= mod;           }         }     cout << f[m][1][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, k = 0, i = 0, j = 0;     char str[100];     cin >> n >> k;     cin >> str;     if (k <= n - k) {       for (i = 1; i < k; i++) {         cout <<  LEFT  << endl;       }       for (i = 0; i < strlen(str) - 1; i++) {         cout <<  PRINT   << str[i] << endl;         cout <<  RIGHT  << endl;       }       cout <<  PRINT   << str[strlen(str) - 1] << endl;     }     if (k > n - k) {       for (i = 0; i < n - k; i++) {         cout <<  RIGHT  << endl;       }       for (i = strlen(str) - 1; i > 0; i--) {         cout <<  PRINT   << str[i] << endl;         cout <<  LEFT  << endl;       }       cout <<  PRINT   << str[0] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   const int INF = 1e9;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1.0);   long long mod = 1e9 + 7;   int main() {     int n, a;     cin >> n >> a;     cout << 2 <<     << 1 <<     << max(3, min(n, ((n * a + 90) / 180 + 2)))          << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   bool is_prime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   vector<long long> fact(long long n) {     vector<long long> ans;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         ans.push_back(i);         while (n % i == 0) {           n /= i;         }       }     }     if (n > 1) ans.push_back(n);     return ans;   }   long long getPow(long long a, long long b) {     long long res = 1ll, tp = a;     while (b) {       if (b & 1ll) {         res *= tp;       }       tp *= tp;       b >>= 1ll;     }     return res;   }   long long vec_mult(long long x1, long long y1, long long x2, long long y2,                      long long x3, long long y3) {     return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));   }   void ok() {     cout <<  YES  << endl;     exit(0);   }   void no() {     cout <<  NO  << endl;     exit(0);   }   inline long long nxt() {     long long x;     cin >> x;     return x;   }   const long long N = 3000 + 5, inf = 2e16;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long n = nxt(), m = nxt(), k = nxt();     vector<long long> used(n, 1);     for (int i = 0; i < m; i++) {       long long x = nxt();       used[x] = 0;     }     vector<long long> a(k);     for (int i = 0; i < k; i++) {       a[i] = nxt();     }     if (!used[0]) {       return cout << -1, 0;     }     vector<long long> pos;     for (int i = 0; i < n; i++) {       if (used[i]) pos.push_back(i);     }     auto get = [&](long long l) {       long long ct = 0;       long long start = 0;       long long ind = 0;       if (!pos.size()) return inf;       while (true) {         ct++;         long long cur = start + l;         if (cur >= n) {           start = cur;           break;         }         long long cur_ind =             (upper_bound(pos.begin(), pos.end(), cur)) - pos.begin();         if (cur_ind == pos.size())           cur_ind--;         else if (pos[cur_ind] > cur) {           cur_ind--;         }         if (pos[cur_ind] == start) break;         if (cur < n) {           start = pos[cur_ind];         } else {           start = cur;           break;         }       }       if (start >= n)         return ct;       else         return inf;     };     long long ans = inf;     for (int i = 0; i < k; i++) {       long long ct = get(i + 1);       if (ct == inf) continue;       ans = min(ans, ct * a[i]);     }     if (ans >= inf)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000000], b[1000000];     int n;     cin >> n >> a;     int l = strlen(a);     for (int i = 1; i < n; i++) {       cin >> b;       for (int j = 0; j < l; j++) {         if (a[j] ==  ? )           a[j] = b[j];         else if (b[j] ==  ? )           continue;         else if (a[j] != b[j])           a[j] =  0 ;       }     }     for (int i = 0; i < l; i++) {       if (a[i] ==  0 )         a[i] =  ? ;       else if (a[i] ==  ? )         a[i] =  x ;     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000006;   int rnk[MAX], parent[MAX], ans[MAX], arr[MAX];   vector<int> comp[MAX];   priority_queue<int> q[MAX];   int find(int x) {     if (x == parent[x]) return x;     return parent[x] = find(parent[x]);   }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     if (rnk[x] > rnk[y])       parent[y] = x;     else {       parent[x] = y;       if (rnk[x] == rnk[y]) rnk[y]++;     }   }   int main() {     int n, m, a, b;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       parent[i] = i;       rnk[i] = 0;     }     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       a--, b--;       merge(a, b);     }     int maxc = 0;     for (int i = 0; i < n; i++) {       comp[find(i)].push_back(i);       maxc = max(maxc, find(i));       q[find(i)].push(arr[i]);     }     for (int i = 0; i <= maxc; i++) {       for (int j = 0; j < comp[i].size(); j++) {         ans[comp[i][j]] = q[i].top();         q[i].pop();       }     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }