#include <bits/stdc++.h>   using namespace std;   const long long INF = 10000000000000000;   const int maxN = 1000 + 10;   const int maxM = 20000 + 10;   long long d1;   int er[maxM];   vector<int> paths1;   struct Edge {     int from, to;     long long dist;   };   struct HeapNode {     long long d;     int u;     bool operator<(const HeapNode& rhs) const { return d > rhs.d; }   };   vector<Edge> edges;   vector<int> G[maxN];   bool done[maxN];   long long d[maxN];   int p[maxM];   struct Dijkstra {     int n, m;     void init(int n) {       this->n = n;       for (int i = 0; i < n; i++) G[i].clear();       edges.clear();     }     void AddEdge(int from, int to, long long dist) {       edges.push_back((Edge){from, to, dist});       m = edges.size();       G[from].push_back(m - 1);     }     void dijkstra(int s) {       priority_queue<HeapNode> Q;       for (int i = 0; i < n; i++) d[i] = INF;       d[s] = 0;       memset(done, 0, sizeof(done));       Q.push((HeapNode){0, s});       while (!Q.empty()) {         HeapNode x = Q.top();         Q.pop();         int u = x.u;         if (done[u]) continue;         done[u] = true;         for (int i = 0; i < G[u].size(); i++) {           Edge& e = edges[G[u][i]];           if (d[e.to] > d[u] + e.dist) {             d[e.to] = d[u] + e.dist;             p[e.to] = G[u][i];             Q.push((HeapNode){d[e.to], e.to});           }         }       }     }     void GetShortestPaths(int s, int u) {       dijkstra(s);       if (d[u] >= INF) {         d1 = d[u];         return;       }       for (int i = u; i <= u; i++) {         d1 = d[i];         paths1.clear();         int t = i;         paths1.push_back(t);         while (t != s) {           paths1.push_back(edges[p[t]].from);           t = edges[p[t]].from;         }         reverse(paths1.begin(), paths1.end());       }     }   };   Dijkstra solver;   Edge ei[10000 + 10];   int main() {     int n, m, s, t;     long long L;     while (~scanf( %d%d%lld%d%d , &n, &m, &L, &s, &t)) {       memset(er, 0, sizeof(er));       int er_cnt = 0;       for (long long i = 0; i < m; i++) {         scanf( %d%d%lld , &ei[i].from, &ei[i].to, &ei[i].dist);         if (ei[i].dist == 0) {           er[i] = ++er_cnt;         }       }       solver.init(n);       for (int i = 0; i < m; i++) {         if (er[i]) ei[i].dist = L;         solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist);         solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist);       }       solver.GetShortestPaths(s, t);       if (d1 < L)         printf( NO n );       else if (d1 == L) {         printf( YES n );         for (long long i = 0; i < m; i++)           printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist);       } else {         solver.init(n);         for (int i = 0; i < m; i++) {           if (er[i]) ei[i].dist = 1;           solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist);           solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist);         }         solver.GetShortestPaths(s, t);         if (d1 > L)           printf( NO n );         else if (d1 == L) {           printf( YES n );           for (int i = 0; i < m; i++)             printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist);         } else {           int x = 1, y = er_cnt, ans;           while (x <= y) {             int mid = (x + y) / 2;             solver.init(n);             for (int i = 0; i < m; i++) {               if (1 <= er[i] && er[i] <= mid)                 ei[i].dist = 1;               else if (er[i] > mid)                 ei[i].dist = L;               solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist);               solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist);             }             solver.GetShortestPaths(s, t);             if (d1 <= L) {               ans = mid;               y = mid - 1;             } else               x = mid + 1;           }           solver.init(n);           for (int i = 0; i < m; i++) {             if (1 <= er[i] && er[i] <= ans)               ei[i].dist = 1;             else if (er[i] > ans)               ei[i].dist = L;             solver.AddEdge(ei[i].from, ei[i].to, ei[i].dist);             solver.AddEdge(ei[i].to, ei[i].from, ei[i].dist);           }           solver.GetShortestPaths(s, t);           long long add = L - d1;           long long pre, cnt = 0, now;           printf( YES n );           for (int i = 0; i < m; i++) {             if (er[i] != ans)               printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist);             else               printf( %d %d %lld n , ei[i].from, ei[i].to, ei[i].dist + add);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > *e;   int *parent;   set<int> *v;   int fp(int a) {     if (parent[a] != a) parent[a] = fp(parent[a]);     return parent[a];   }   void dsu(int a, int b) {     a = fp(a);     b = fp(b);     if (a != b) {       if (v[a].size() < v[b].size()) swap(a, b);       for (set<int>::iterator i = v[b].begin(); i != v[b].end(); i++)         v[a].insert(*i);       v[b].clear();       parent[b] = a;     }   }   void add(int a, int b, int c) {     v[fp(a)].insert(b);     v[fp(b)].insert(a);     set<pair<int, int> >::iterator t = e[b].lower_bound(make_pair(c, -1));     if ((t == e[b].end()) || (t->first != c)) {       e[b].insert(make_pair(c, a));     } else {       dsu(a, t->second);     }     t = e[a].lower_bound(make_pair(c, -1));     if ((t == e[a].end()) || (t->first != c)) {       e[a].insert(make_pair(c, b));     } else {       dsu(b, t->second);     }   }   int main() {     int n, m, c, q;     int i;     char ch;     scanf( %d %d %d %d , &n, &m, &c, &q);     parent = new int[100010];     v = new set<int>[100010];     e = new set<pair<int, int> >[100010];     for (i = 0; i < n; i++) {       parent[i] = i;     }     int a, b, cl;     while (m--) {       scanf( %d %d %d , &a, &b, &cl);       add(a, b, cl);     }     while (q--) {       scanf(  %c , &ch);       if (ch ==  ? ) {         scanf( %d %d , &a, &b);         if (fp(a) == fp(b) || (v[fp(a)].find(b) != v[fp(a)].end()))           printf( Yes n );         else           printf( No n );       } else {         scanf( %d %d %d , &a, &b, &cl);         add(a, b, cl);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<pair<long long int, long long int>, long long int> m;     long long int ans = 0;     long long int n, count = 0;     cin >> n;     string s;     for (int i = 1; i <= n; i++) {       int l = 0, r = 0;       cin >> s;       for (int j = 0; j < s.length(); j++)         if (s[j] ==  ( )           l++;         else if (s[j] ==  )  && l > 0)           l--;         else           r++;       if (l > 0 && r > 0)         continue;       else if (l == 0 && r == 0) {         ans++;         continue;       } else if (l > 0)         m[make_pair(0, l)]++;       else         m[make_pair(1, r)]++;     }     ans = ans * ans;     count = 0;     for (map<pair<long long int, long long int>, long long int>::iterator it =              m.begin();          it != m.end(); it++)       count = count +               m[it->first] * m[make_pair(!(it->first.first), it->first.second)];     cout << ans + count / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int seq[100];   int ans;   vector<string> in;   void solve(int k, int l) {     if (k <= l) {       vector<int> buf(in.size());       for (int i = 0; i < (int)in.size(); ++i) {         buf[i] = 0;       }       for (int i = 0; i < (int)in.size(); ++i) {         for (int j = 0; j < k; ++j) {           buf[i] += in[i][seq[j]] * pow(10, j);         }       }       sort(buf.begin(), buf.end());       ans = min(ans, *(buf.rbegin()) - *(buf.begin()));       return;     }     for (int i = 0; i < k; ++i) {       if (seq[i] < 0) {         seq[i] = l;         solve(k, l + 1);         seq[i] = -1;       }     }   }   int main(void) {     int n, k;     while (cin >> n >> k) {       ans = (100000000);       for (int i = 0; i < 100; ++i) {         seq[i] = -1;       }       in.clear();       in.resize(n);       for (int i = 0; i < n; ++i) {         cin >> in[i];       }       solve(k, 0);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M = 1000000007;   long long n, m;   void solve() {}   void test() {     long long n;     cin >> n;     vector<int> a(n);     int count[101] = {         0,     };     for (long long i = 0; i < n; i++) {       cin >> a[i];       count[a[i]]++;     }     bool flag = 1;     int ans = 0;     for (long long i = 0; i < 101; i++) {       if (count[i] == 0 && flag) {         cout << 2 * i << endl;         return;       }       if (count[i] == 1 && flag) {         ans += i;         flag = 0;       }       if (count[i] == 0 && !flag) {         ans += i;         cout << ans << endl;         return;       }     }   }   int main() {     long long t;     cin >> t;     while (t--) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const long long inf = 1e9 + 5;   int n, m, a[maxn], b[maxn], nxt[maxn], prv[maxn];   long long gt, ct[maxn];   pair<int, int> sa[maxn];   set<pair<long long, int> > cross;   long long up(long long x) { return x + (n - x % n) % n; }   long long down(long long x) { return x - x % n; }   long long pos(int idx, long long p, long long v, long long t) {     long long ret = p + t / n * v;     if (idx < t % n) {       ret += v;     }     return ret;   }   long long time(int x) {     long long px = a[x], vx = b[x];     int y = nxt[x];     long long py = a[y], vy = b[y];     long long dx = pos(x, px, vx, gt);     long long dy = pos(y, py, vy, gt);     if (dy <= dx) {       py += (dx - dy) + (m - (dx - dy) % m) % m;     }     if (vx <= vy) {       if (x < gt % n) {         if (pos(y, py, vy, up(gt) + x + 1) <= pos(x, px, vx, up(gt) + x + 1)) {           return up(gt) + x + 1;         }       } else {         if (pos(y, py, vy, down(gt) + x + 1) <=             pos(x, px, vx, down(gt) + x + 1)) {           return down(gt) + x + 1;         }       }       return n * inf;     }     long long lo, hi = n * inf / (vx - vy) + 10;     if (x < gt % n) {       lo = up(gt) + x + 1;     } else {       lo = down(gt) + x + 1;     }     while (lo < hi) {       long long mid = (lo + hi) / 2;       long long cur;       if (x < mid % n) {         cur = down(mid) + x + 1;       } else {         cur = down(mid) - n + x + 1;       }       if (pos(y, py, vy, cur) <= pos(x, px, vx, cur)) {         hi = mid;       } else {         lo = mid + 1;       }     }     return lo;   }   void erase(int x) {     cross.erase({ct[x], x});     nxt[prv[x]] = nxt[x];     prv[nxt[x]] = prv[x];   }   int dist(int x, int y) { return (y - x + m) % m; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       --a[i];       sa[i] = {a[i], i};     }     sort(sa, sa + n);     for (int i = 0; i < n; i++) {       nxt[sa[i].second] = sa[(i + 1) % n].second;       prv[sa[(i + 1) % n].second] = sa[i].second;     }     for (int i = 0; i < n; i++) {       ct[i] = time(i);       cross.insert({ct[i], i});     }     while (cross.size() > 1 && cross.begin()->first < n * inf) {       long long t = cross.begin()->first;       int x = cross.begin()->second;       int px = pos(x, a[x], b[x], t - 1) % m;       int cnt = 0;       while (1) {         int y = nxt[x];         if (x == y) {           break;         } else {           int py = pos(y, a[y], b[y], t - 1) % m;           if (dist(px, py) <= b[x]) {             erase(y);             ++cnt;           } else {             break;           }         }       }       px = (px + b[x]) % m;       b[x] = max(b[x] - cnt, 0);       a[x] = (px - pos(x, 0, b[x], t)) % m;       if (a[x] < 0) {         a[x] += m;       }       int w = prv[x];       if (w == x) {         break;       }       cross.erase({ct[w], w});       cross.erase({ct[x], x});       ct[w] = time(w);       ct[x] = time(x);       cross.insert({ct[w], w});       cross.insert({ct[x], x});       gt = t;     }     cout << cross.size() <<   n ;     for (auto &f : cross) {       cout << f.second + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = (ans * a);       }       a = (a * a);       b >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a, b, i, l = 0, u;     cin >> a >> b;     if (a > b) {       cout <<  -1 ;       return 0;     }     if (a == 0 && b == 0) {       cout <<  0 ;       return 0;     }     if (a == 0 && b % 2 == 0) {       cout <<  2 n  << b / 2 <<     << b / 2;       return 0;     }     if (a == b) {       cout << 1 <<   n  << a;       return 0;     }     if (a % 2 != 0 && b % 2 != 0) {       long long d = b - a;       if (d == 0) {         cout <<  1 n  << 1;         return 0;       }       if ((a & (d / 2)) == 0) {         cout <<  2               <<   n ;         cout << a + d / 2 <<    ;         cout << d / 2;         return 0;       }       cout <<  3             <<   n ;       cout << a <<    ;       cout << d / 2 <<     << d / 2;       return 0;     }     if (a % 2 == 0 && b % 2 == 0) {       long long d = a;       vector<int> v;       while (d > 0) {         v.push_back(d & 1);         d = d >> 1;       }       while (v.size() <= 60) {         v.push_back(0);       }       for (i = 60; i >= 0; i--) {         if (v[i] == 0) {           u = power(2, i);           if (a + l + 2 * u == b) break;           if (a + l + 2 * u < b) {             l = l + 2 * u;           }         }       }       if (((a + l / 2 + u) ^ (l / 2 + u)) != a) {         long long d = b - a;         cout <<  3               <<   n ;         cout << a <<    ;         cout << d / 2 <<     << d / 2;         return 0;       }       cout <<  2 n ;       cout << a + l / 2 + u <<     << l / 2 + u <<   n ;       return 0;     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, k, l[N], r[N], f[2][N], q[N];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; ++i) scanf( %d%d , &l[i], &r[i]);     f[0][0] = 0;     for (int i = 1; i <= (n << 1); ++i) f[0][i] = 0x3f3f3f3f;     for (int i = 1; i <= k; ++i) {       int cur = i & 1, last = !cur;       memset(f[cur], 0x3f, sizeof(int) * (n + 1));       int L = 1, R = 0, now = 0;       for (int j = min(n, r[i]); j >= 0; --j) {         f[cur][j] = f[last][j];         int ql = l[i] - j, qr = min(r[i] - j, n);         while (now <= qr) {           while (L <= R && f[last][q[R]] > f[last][now]) --R;           q[++R] = now;           ++now;         }         while (L <= R && q[L] < ql) ++L;         f[cur][j] = min(f[cur][j], f[last][q[L]] + 1);       }       L = 1, R = 0;       now = 0;       for (int j = 0; j <= n && j <= r[i]; ++j) {         int ql = j + l[i] - r[i], qr = j;         while (now <= qr) {           while (L <= R && f[last][q[R]] > f[last][now]) --R;           q[++R] = now;           ++now;         }         while (L <= R && q[L] < ql) ++L;         f[cur][j] = min(f[cur][j], f[last][q[L]] + 2);       }     }     if (f[k & 1][n] == 0x3f3f3f3f) {       puts( Hungry );       return 0;     }     puts( Full );     printf( %d n , f[k & 1][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, x[100005];     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i];     sort(x + 1, x + 1 + n);     for (int i = 2; i <= n; i++)       if (x[i - 1] * 2 > x[i] && x[i - 1] != x[i]) return cout <<  YES , 0;     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool ylmin(T &a, T b) {     return a < b ? 0 : (a = b, 1);   }   template <class T>   inline bool ylmax(T &a, T b) {     return a > b ? 0 : (a = b, 1);   }   template <class T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   inline char read() {     static const int IO_LEN = 1024 * 1024;     static char buf[IO_LEN], *ioh, *iot;     if (ioh == iot) {       iot = (ioh = buf) + fread(buf, 1, IO_LEN, stdin);       if (ioh == iot) return -1;     }     return *ioh++;   }   template <class T>   inline void read(T &x) {     static int iosig;     static char ioc;     for (iosig = 0, ioc = read(); !isdigit(ioc); ioc = read())       if (ioc ==  - ) iosig = 1;     for (x = 0; isdigit(ioc); ioc = read()) x = (x << 1) + (x << 3) + (ioc ^  0 );     if (iosig) x = -x;   }   const int MAXN = 2e5 + 10;   long long T, n, a[MAXN], b[MAXN], id[MAXN];   inline bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     for (read(T); T; T--) {       read(n);       for (int i = (1); i <= (n); i++) read(a[i]), id[i] = i;       for (int i = (1); i <= (n); i++) read(b[i]);       sort(id + 1, id + n + 1, cmp);       long long sum = 0, ans = 1e9;       for (int i = (1); i <= (n); i++) sum += b[i];       for (int i = (0); i <= (n); i++) {         sum -= b[id[i]];         ylmin(ans, max(a[id[i]], sum));       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int temp, i, j, k, T;   long long pow_r(long long d, long long n) {     long long x = 1ll;     while (n > 0) {       if (n & 1) x = (x * d);       d = (d * d);       n >>= 1;     }     return x;   }   int n, da[6], db[6];   pair<int, pair<int, int> > a[8];   int dist(int p, int q) {     return (a[p].second.first - a[q].second.first) *                (a[p].second.first - a[q].second.first) +            (a[p].second.second - a[q].second.second) *                (a[p].second.second - a[q].second.second);   }   void check() {     da[0] = dist(0, 1);     da[1] = dist(1, 2);     da[2] = dist(2, 3);     da[3] = dist(3, 0);     da[4] = dist(0, 2);     da[5] = dist(1, 3);     db[0] = dist(4, 5);     db[1] = dist(5, 6);     db[2] = dist(6, 7);     db[3] = dist(7, 4);     db[4] = dist(4, 6);     db[5] = dist(5, 7);     if (da[0] == da[1] && da[1] == da[2] && da[2] == da[3] && da[4] == da[5] &&         db[0] == db[2] && db[1] == db[3] && db[4] == db[5]) {       puts( YES );       cout << a[0].first <<     << a[1].first <<     << a[2].first <<                << a[3].first << endl;       cout << a[4].first <<     << a[5].first <<     << a[6].first <<                << a[7].first << endl;       exit(0);     }   }   int main() {     n = 8;     i = 0;     while (n--) {       scanf( %d , &a[i].second.first);       scanf( %d , &a[i].second.second);       a[i].first = i + 1;       ++i;     }     n = 8;     sort(a, a + 8);     do {       check();     } while (next_permutation(a, a + 8));     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1e9 + 7;   inline int read() {     int neg = 1, num = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) neg = -1;     for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ;     return neg * num;   }   int n, cnt[200010];   inline int Pow(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = 1ll * x * x % p)       if (y & 1) res = 1ll * res * x % p;     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       int a = read();       if (a != -1) cnt[a]++;     }     int sum = 0;     for (int i = 1; i <= n; i++) sum = (sum + Pow(2, cnt[i]) - 1) % p;     sum = Pow(2, n - 1) - 1 - sum;     sum = (sum % p + p) % p;     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150;   const double eps = 1e-8;   struct point {     double x, y;     point() {}     point(double _x, double _y) : x(_x), y(_y) {}     friend bool operator<(const point &a, const point &b) {       if (fabs(a.x - b.x) < eps) {         return a.y < b.y;       }       return a.x < b.x;     }   };   vector<point> vec;   map<point, int> vis;   point square1;   point CircumCenter(point a, point b, point c) {     point cp;     double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1 * a1 + b1 * b1) / 2;     double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2 * a2 + b2 * b2) / 2;     double d = a1 * b2 - a2 * b1;     cp.x = a.x + (c1 * b2 - c2 * b1) / d;     cp.y = a.y + (a1 * c2 - a2 * c1) / d;     return cp;   }   double getDistance(point a, point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   double dianji(point veca, point vecb) {     return veca.x * vecb.x + veca.y * vecb.y;   }   bool isLenEqual(point a, point b, point c) {     if (fabs(getDistance(a, b) - getDistance(a, c)) < eps) return true;     return false;   }   int fdTriangle(point a, point b, point c) {     point vecOne = point(a.x - b.x, a.y - b.y);     point vecTwo = point(b.x - c.x, b.y - c.y);     point vecThree = point(c.x - a.x, c.y - a.y);     double dj1 = dianji(vecOne, vecTwo);     double dj2 = dianji(vecTwo, vecThree);     double dj3 = dianji(vecThree, vecOne);     if (fabs(dj1) < eps || fabs(dj2) < eps || fabs(dj3) < eps) {       if (fabs(dj1) < eps && isLenEqual(a, b, c)) {         square1 = a;         return 2;       } else if (fabs(dj2) < eps && isLenEqual(c, a, b)) {         square1 = c;         return 2;       } else if (fabs(dj3) < eps && isLenEqual(b, a, c)) {         square1 = b;         return 2;       }       return 0;     }     if (dj1 < 0 && dj2 < 0 && dj3 < 0) return 1;     return 0;   }   void compute() {     double mx = -1.0;     point all_ans;     int all_flag = 0;     for (int i = 0; i < vec.size(); i++) {       for (int j = 0; j < vec.size(); j++) {         for (int k = 0; k < vec.size(); k++) {           if (i == j || j == k || i == k) continue;           int flag = 0;           point pos_ans;           point a = vec[i], b = vec[j], c = vec[k];           if (!(fabs((b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)) <                 eps)) {             int type = fdTriangle(a, b, c);             if (type == 1) {               flag = 1;               pos_ans = CircumCenter(a, b, c);             } else if (type == 2) {               point cc = CircumCenter(a, b, c);               double X = 2 * cc.x - square1.x;               double Y = 2 * cc.y - square1.y;               if (vis[point(X, Y)] == 1) {                 flag = 1;                 pos_ans = cc;               }             }           }           if (flag == 1) {             double r = getDistance(pos_ans, a);             for (int z = 0; z < vec.size(); z++) {               point each = vec[z];               if (getDistance(pos_ans, each) + eps < r) {                 flag = 0;                 break;               }             }             if (flag == 1 && mx < r) {               mx = r;               all_flag = 1;               all_ans = pos_ans;             }           }         }       }     }     if (all_flag == 1) {       printf( %.6f n , mx);     } else {       printf( -1 n );     }   }   int main() {     int n;     while (cin >> n) {       vis.clear();       vec.clear();       for (int i = 0; i < n; i++) {         double x, y;         cin >> x >> y;         point p = point(x, y);         vec.push_back(p);         vis[p] = 1;       }       compute();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime(int x) {     int cnt = 0;     for (int i = 1; i <= x; i++)       if (x % i == 0) cnt++;     return (cnt <= 2);   }   void fl() { fflush(stdout); }   int kul[] = {4, 9, 25, 49};   char odg[5];   int main() {     int prosti = 1;     for (int i = 0; i < 4; i++) {       printf( %d n , kul[i]);       fl();       scanf( %s , odg);       if (odg[0] ==  y ) prosti = 0;     }     if (prosti) {       int cnt = 0;       for (int i = 2; i <= 50; i++) {         if (prime(i)) {           printf( %d n , i);           fl();           scanf( %s , odg);           if (odg[0] ==  y ) cnt++;         }       }       if (cnt >= 2) prosti = 0;     }     if (prosti == 1) {       printf( prime n );       fl();     } else {       printf( composite n );       fl();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   ostream &operator<<(ostream &out, pair<T, T1> obj) {     out <<  (  << obj.first <<  ,  << obj.second <<  ) ;     return out;   }   template <typename T, typename T1>   ostream &operator<<(ostream &out, map<T, T1> cont) {     typename map<T, T1>::const_iterator itr = cont.begin();     typename map<T, T1>::const_iterator ends = cont.end();     for (; itr != ends; ++itr) out << *itr <<    ;     out << endl;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, set<T> cont) {     typename set<T>::const_iterator itr = cont.begin();     typename set<T>::const_iterator ends = cont.end();     for (; itr != ends; ++itr) out << *itr <<    ;     out << endl;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, multiset<T> cont) {     typename multiset<T>::const_iterator itr = cont.begin();     typename multiset<T>::const_iterator ends = cont.end();     for (; itr != ends; ++itr) out << *itr <<    ;     out << endl;     return out;   }   template <typename T,             template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>   ostream &operator<<(ostream &out, CONT<T> cont) {     typename CONT<T>::const_iterator itr = cont.begin();     typename CONT<T>::const_iterator ends = cont.end();     for (; itr != ends; ++itr) out << *itr <<    ;     out << endl;     return out;   }   template <typename T, unsigned int N, typename CTy, typename CTr>   typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type   operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {     for (auto i = 0; i < N; ++i) out << arr[i] <<    ;     out << endl;     return out;   }   template <typename T>   T gcd(T a, T b) {     T min_v = min(a, b);     T max_v = max(a, b);     while (min_v) {       T temp = max_v % min_v;       max_v = min_v;       min_v = temp;     }     return max_v;   }   template <typename T>   T lcm(T a, T b) {     return (a * b) / gcd(a, b);   }   template <typename T>   T fast_exp_pow(T base, T exp, T mod) {     long long res = 1;     while (exp) {       if (exp & 1) {         res *= base;         res %= mod;       }       exp >>= 1;       base *= base;       base %= mod;     }     return res % mod;   }   int N, M, K, L, R;   long long C, answer = 99999999999999LL;   long long dp_solve[310][310];   long long min_cost[310][310];   int main() {     scanf( %d%d%d , &N, &M, &K);     for (auto i = 0; i < 310; ++i)       for (auto j = 0; j < 310; ++j)         dp_solve[i][j] = min_cost[i][j] = 99999999999999LL;     for (auto i = 0; i < M; ++i) {       scanf( %d%d%lld , &L, &R, &C);       min_cost[L][R] = min(min_cost[L][R], C);     }     for (auto r = 1; r <= N; ++r)       for (auto l = 1; l <= r; ++l)         min_cost[l][r] = min(min_cost[l][r], min_cost[l - 1][r]);     for (int l = N; l >= 1; --l)       for (int r = N; r >= l; --r)         min_cost[l][r] = min(min_cost[l][r], min_cost[l][r + 1]);     for (auto i = 0; i <= N; ++i) {       dp_solve[i][0] = 0;       for (auto j = 0; j <= i; ++j) {         if (dp_solve[i][j] == 99999999999999LL) continue;         dp_solve[i + 1][j] = min(dp_solve[i + 1][j], dp_solve[i][j]);         for (auto k = i + 1; k <= N; ++k)           dp_solve[k][j + (k - i)] =               min(dp_solve[k][j + (k - i)], dp_solve[i][j] + min_cost[i + 1][k]);       }     }     answer = dp_solve[N][K];     if (answer >= 99999999999999LL) answer = -1;     printf( %lld n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535;   double squared(double n) { return n * n; }   typedef struct {     int cx;     int cy;     int r;     int R;   } circle_t;   bool isBlack(double x, double y, circle_t c) {     double val = squared(x - (double)c.cx) + squared(y - (double)c.cy);     if (val > squared(c.R)) {       return false;     } else if (val >= squared(c.r)) {       return true;     } else {       return false;     }   }   int returnOkNum(circle_t c, circle_t c2) {     int blackOutNum = 0;     int blackInNum = 0;     int ret = 0;     const int DIVIDE = 100000;     for (int i = 0; i < DIVIDE; ++i) {       double xOut = (double)c.R * cos(2.0 * PI * i / DIVIDE) + c.cx;       double yOut = (double)c.R * sin(2.0 * PI * i / DIVIDE) + c.cy;       double xIn = (double)c.r * cos(2.0 * PI * i / DIVIDE) + c.cx;       double yIn = (double)c.r * sin(2.0 * PI * i / DIVIDE) + c.cy;       if (isBlack(xOut, yOut, c2)) {         ++blackOutNum;       }       if (isBlack(xIn, yIn, c2)) {         ++blackInNum;       }     }     if (blackOutNum <= 3) {       ++ret;     }     if (blackInNum <= 3) {       ++ret;     }     return ret;   }   int main(void) {     vector<circle_t> cs(2);     for (int i = 0; i < 2; ++i) {       cin >> cs[i].cx >> cs[i].cy >> cs[i].r >> cs[i].R;     }     int ret = returnOkNum(cs[0], cs[1]);     ret += returnOkNum(cs[1], cs[0]);     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     scanf( %d%d , &n, &x);     int i, j, ans = 0;     int a1[100002], a2[100002];     for (i = 1; i <= n; i++) {       scanf( %d%d , &a1[i], &a2[i]);       ans = ans + (a2[i] - a1[i] + 1) + (a1[i] - a2[i - 1] - 1) % x;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int M = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e18 + 10;   int a[N], st[N], ft[N], ind[N], lzy[4 * N], t, n, m;   vector<int> adj[N];   bitset<M> seg[4 * N], P, res, one;   void dfs(int v, int p) {     st[v] = t;     ind[t++] = v - 1;     for (int u : adj[v])       if (u != p) dfs(u, v);     ft[v] = t;   }   void build(int l = 0, int r = n, int id = 1) {     if (r - l == 1) {       seg[id][a[ind[l]]] = 1;       return;     }     int mid = (l + r) / 2;     build(l, mid, 2 * id);     build(mid, r, 2 * id + 1);     seg[id] = seg[2 * id] | seg[2 * id + 1];   }   void shift(int id) {     int x = lzy[id];     seg[2 * id] = (seg[2 * id] << x) & one | (seg[2 * id] >> (m - x));     seg[2 * id + 1] = (seg[2 * id + 1] << x) & one | (seg[2 * id + 1] >> (m - x));     lzy[2 * id] = (lzy[2 * id] + x) % m;     lzy[2 * id + 1] = (lzy[2 * id + 1] + x) % m;     lzy[id] = 0;   }   void upd(int l, int r, int x, int s = 0, int e = n, int id = 1) {     if (e <= l || r <= s) return;     if (l <= s && e <= r) {       seg[id] = (seg[id] << x) & one | (seg[id] >> (m - x));       lzy[id] = (lzy[id] + x) % m;       return;     }     shift(id);     int mid = (s + e) / 2;     upd(l, r, x, s, mid, 2 * id);     upd(l, r, x, mid, e, 2 * id + 1);     seg[id] = seg[2 * id] | seg[2 * id + 1];   }   void get(int l, int r, int s = 0, int e = n, int id = 1) {     if (e <= l || r <= s) return;     if (l <= s && e <= r) {       res |= seg[id];       return;     }     shift(id);     int mid = (s + e) / 2;     get(l, r, s, mid, 2 * id);     get(l, r, mid, e, 2 * id + 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i], a[i] %= m;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     build();     for (int i = 2; i < m; i++) P[i] = 1;     for (int i = 2; i < m; i++)       if (P[i])         for (int j = i * i; j < m; j += i) P[j] = 0;     for (int i = 0; i < m; i++) one[i] = 1;     int q;     cin >> q;     while (q--) {       int typ;       cin >> typ;       if (typ == 1) {         int v, x;         cin >> v >> x;         x %= m;         upd(st[v], ft[v], x);       } else {         int v;         cin >> v;         res &= 0;         get(st[v], ft[v]);         cout << (res & P).count() <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long int;   using P = pair<int, int>;   using PL = pair<lint, lint>;   constexpr int MOD = 1000000007;   constexpr lint B1 = 1532834020;   constexpr lint M1 = 2147482409;   constexpr lint B2 = 1388622299;   constexpr lint M2 = 2147478017;   constexpr int INF = 2147483647;   void yes(bool expr) { cout << (expr ?  Yes  :  No ) <<   n ; }   template <class T>   void chmax(T &a, const T &b) {     if (a < b) a = b;   }   template <class T>   void chmin(T &a, const T &b) {     if (b < a) a = b;   }   vector<int> csort(vector<int> &c, vector<int> &tmp) {     vector<int> ret;     int ptr = c.size();     for (int i = (tmp.size()) - 1, i_begin_ = (0); i >= i_begin_; i--) {       ptr -= tmp[i];       for (int j = (0), j_end_ = (tmp[i]); j < j_end_; j++)         ret.push_back(c[ptr + j]);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> c(n);     for (int i = (0), i_end_ = (n); i < i_end_; i++) cin >> c[i];     for (int i = (0), i_end_ = (n); i < i_end_; i++) c[i]--;     int opes = 0;     vector<vector<int>> ans;     while (true) {       bool comp = true;       for (int i = (0), i_end_ = (n); i < i_end_; i++)         if (c[i] != i) {           comp = false;           break;         }       if (comp) break;       vector<int> tmp;       for (int i = (0), i_end_ = (opes); i < i_end_; i++) tmp.push_back(1);       if ((n - opes) % 2 == 0) {         for (int i = (0), i_end_ = (n); i < i_end_; i++)           if (c[i] == opes) {             tmp.push_back(i + 1 - opes);             if (n - 1 - i > 0) tmp.push_back(n - 1 - i);             break;           }       } else {         for (int i = (0), i_end_ = (n); i < i_end_; i++)           if (c[i] == opes) {             tmp.push_back(n - opes - i);             if (i > 0) tmp.push_back(i);             break;           }         reverse((tmp).begin(), (tmp).end());       }       if (tmp.size() > 1) {         ans.push_back(tmp);         c = csort(c, tmp);       }       opes++;     }     cout << ans.size() << endl;     for (int i = (0), i_end_ = (ans.size()); i < i_end_; i++) {       cout << ans[i].size() <<    ;       for (int j = (0), j_end_ = (ans[i].size()); j < j_end_; j++)         cout << ans[i][j] << (j != ans[i].size() - 1 ?     :   );       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> m1;   long long query(long long a, long long b) {     long long ans = 0;     while (a != b) {       if (a > b) {         ans += m1[a];         a = a / 2;       } else {         ans += m1[b];         b = b / 2;       }     }     return ans;   }   void update(long long a, long long b, long long m) {     while (a != b) {       if (a > b) {         m1[a] += m;         a = a / 2;       } else {         m1[b] += m;         b = b / 2;       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long ch;       cin >> ch;       if (ch == 2) {         long long a, b;         cin >> a >> b;         cout << query(a, b) << endl;       } else {         long long a, b, m;         cin >> a >> b >> m;         update(a, b, m);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100003;   int l[maxn], r[maxn], L, R, K, n, cnt[maxn][30], sum[30], A[30], B[30];   char c[maxn], s[maxn];   int List[30][maxn], a[maxn], len[maxn], tot = 0;   inline int get() {     int f = 0, v = 0;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) break;     if (ch ==  - )       f = 1;     else       v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     if (f == 1)       return -v;     else       return v;   }   int check(int st, int ed) {     bool f = 0, g = 0;     for (int i = 0; i < 26; i++) {       int tp = cnt[ed][i] - cnt[st - 1][i];       if (tp > B[i]) g = 1;       if (tp < A[i]) f = 1;     }     if (f && g) return 2;     if (f) return -1;     if (g) return 1;     return 0;   }   void add(int st, int ed, int v) {     for (int i = st; i <= ed; i++) {       if (L <= a[i] && a[i] <= R) tot--;       a[i] += v;       if (L <= a[i] && a[i] <= R) tot++;     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     K = get();     L = get(), R = get();     for (int i = 1; i <= K; i++) scanf(  %c , &c[i]), l[i] = get(), r[i] = get();     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];       cnt[i][s[i] -  a ]++;     }     if (L == K && R == K) {       long long ans = 0;       for (int i = 0; i < 26; i++) A[i] = 0, B[i] = n + 1;       for (int i = 1; i <= K; i++) {         A[c[i] -  a ] = max(A[c[i] -  a ], l[i]);         B[c[i] -  a ] = min(B[c[i] -  a ], r[i]);         if (A[c[i] -  a ] > B[c[i] -  a ]) return puts( 0 ), 0;       }       for (int i = 1; i <= n; i++) {         bool flag = 1;         L = i, R = n;         int Left, Right;         while (L <= R) {           int mid = (L + R) / 2, t = check(i, mid);           if (t == 2) {             flag = 0;             break;           }           if (t == 1)             R = mid - 1;           else             L = mid + 1;         }         Right = R;         L = i, R = n;         while (L <= R) {           int mid = (L + R) / 2, t = check(i, mid);           if (t == 2) {             flag = 0;             break;           }           if (t == -1)             L = mid + 1;           else             R = mid - 1;         }         Left = L;         if (flag && Right >= Left) ans += Right - Left + 1;       }       cout << ans << endl;       return 0;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (L == 0) tot++;       int tp = s[i] -  a ;       List[tp][++len[tp]] = i;       for (int j = 1; j <= K; j++) {         if (l[j] == 0) add(i, i, 1);         if (c[j] != s[i]) continue;         if (len[tp] >= l[j] && l[j] != 0)           add(List[tp][len[tp] - l[j]] + 1, List[tp][len[tp] - l[j] + 1], 1);         if (len[tp] > r[j])           add(List[tp][len[tp] - r[j] - 1] + 1, List[tp][len[tp] - r[j]], -1);       }       ans += tot;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m;   struct Edge {     int x;     int y;     int t;     Edge(int x, int y, int t) : x(x), y(y), t(t) {}     void print() { cout << x <<     << y <<     << t << endl; }   };   vector<Edge> edges;   vector<int> edge_idx[200005];   int in_digree[200005];   queue<int> Q;   int order[200005];   int main() {     int i, j, k;     int x, y, z;     int t;     cin >> t;     while (0 < t--) {       edges.clear();       while (!Q.empty()) Q.pop();       for (i = 0; i < n; i++) edge_idx[i].clear();       memset(in_digree, 0, sizeof(in_digree));       cin >> n >> m;       for (i = 0; i < m; i++) {         cin >> z >> x >> y;         x--;         y--;         Edge e(x, y, z);         if (e.x != x || e.y != y || e.t != z) return -1;         edge_idx[x].push_back(edges.size());         edge_idx[y].push_back(edges.size());         edges.push_back(e);         if (z) {           in_digree[y] += 1;         }       }       for (i = 0; i < n; i++) {         if (in_digree[i] == 0) {           Q.push(i);         }       }       int cnt = 0;       k = 0;       while (!Q.empty()) {         x = Q.front();         Q.pop();         order[x] = k++;         cnt++;         for (i = 0; i < edge_idx[x].size(); i++) {           Edge e = edges[edge_idx[x][i]];           z = -1;           if (e.t == 1 && e.x == x) {             y = e.y;             if (--in_digree[y] == 0) Q.push(y);           }         }       }       if (cnt != n) {         cout <<  NO n ;       } else {         cout <<  YES n ;         for (i = 0; i < edges.size(); i++) {           Edge e = edges[i];           if (order[e.x] < order[e.y]) {             cout << e.x + 1 <<     << e.y + 1 << endl;           } else {             cout << e.y + 1 <<     << e.x + 1 << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long MOD = 1e9 + 7;   constexpr long double EPS = 0.0 + 1e-6;   void YES() {     cout <<  YES           <<   n ;   }   void NO() {     cout <<  NO           <<   n ;   }   bool search(const string& s, long long i, const string& t, long long j,               bool going_left, bool going_right, bool can_turn_left) {     if (j >= t.size()) return false;     if (i < 0 or i >= s.size()) return false;     if (s[i] != t[j]) return false;     if (s[i] == t[j] and j + 1 == t.size()) return true;     if (going_right and search(s, i + 1, t, j + 1, false, true, true))       return true;     if (going_right and can_turn_left and         search(s, i - 1, t, j + 1, true, false, false))       return true;     if (going_left and search(s, i - 1, t, j + 1, true, false, false))       return true;     return false;   }   void solve() {     string s;     cin >> s;     string t;     cin >> t;     for (long long i = 0; i < s.size(); ++i) {       if (search(s, i, t, 0, false, true, true)) return YES();     }     NO();   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int counter = 0;   int ans = 0;   vector<int> L[500000];   bool visited[500000];   bool cat[500000];   int main() {     int a, b, k1, k2;     deque<int> q1, q2, t1, t2;     set<pair<deque<int>, deque<int> > > st;     scanf( %d , &n);     scanf( %d , &k1);     for (int i = 1; i <= k1; i++) {       cin >> a;       q1.push_back(a);     }     scanf( %d , &k2);     for (int i = 1; i <= k2; i++) {       cin >> a;       q2.push_back(a);     }     int fight = 0;     int x, y;     t1 = q1;     t2 = q2;     bool loop = false;     int winner = 0;     st.insert(make_pair(q1, q2));     while (true) {       if (q1.empty()) {         winner = 2;         break;       }       if (q2.empty()) {         winner = 1;         break;       }       x = q1.front();       y = q2.front();       q1.pop_front();       q2.pop_front();       if (x > y)         q1.push_back(y), q1.push_back(x);       else         q2.push_back(x), q2.push_back(y);       fight++;       st.insert(make_pair(q1, q2));       if (t1 == q1 and t2 == q2 or (t2 == q1 and t1 == q2)) {         loop = true;         break;       }       if (st.size() != fight + 1) {         loop = true;         break;       }     }     if (!loop)       cout << fight <<     << winner << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void start() {}   vector<long int> g[200007];   map<long int, bool> vis;   long int siz = 0;   void dfs(long int x) {     vis[x] = 1;     siz++;     for (auto i : g[x]) {       if (!vis[i]) {         dfs(i);       }     }     return;   }   double dist(long int x, long int y, long int a, long int b) {     double ans = sqrt((a - x) * (a - x) + (b - y) * (b - y));     return ans;   }   void sober() {     double r, x, y, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double ans = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));     ans = ans / (2 * r);     cout << ceil(ans) <<   n ;   }   signed main() {     start();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long int t = 1;     while (t--) {       sober();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   vector<int> G[1000010];   int a[MAXN], s[MAXN], L[MAXN], R[MAXN];   int n, k;   long long ans;   int query(int k, int l, int r) {     return upper_bound(G[k].begin(), G[k].end(), r) -            lower_bound(G[k].begin(), G[k].end(), l);   }   int main() {     scanf( %d%d , &n, &k);     G[0].push_back(0);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = (s[i - 1] + a[i]) % k;       G[s[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       L[i] = i - 1;       while (L[i] && a[L[i]] < a[i]) L[i] = L[L[i]];     }     for (int i = n; i >= 1; i--) {       R[i] = i + 1;       while (R[i] <= n && a[R[i]] <= a[i]) R[i] = R[R[i]];     }     for (int i = 1; i <= n; i++) a[i] %= k;     for (int i = 1; i <= n; i++) {       if (i - L[i] < R[i] - i) {         for (int j = L[i] + 1; j <= i; j++)           ans += query((s[j - 1] + a[i]) % k, i, R[i] - 1);       } else {         for (int j = i; j < R[i]; j++)           ans += query((s[j] - a[i] + k) % k, L[i], i - 1);       }     }     printf( %lld n , ans - n);     return 0;   }


#include <bits/stdc++.h>   char s[200010];   int tree[26][200010 << 2];   bool vis[200010];   inline void PushUp(int t, int rt) {     tree[t][rt] = tree[t][rt << 1] + tree[t][rt << 1 | 1];   }   void Update(int t, int x, int L, int R, int rt) {     if (L == R)       tree[t][rt] = 1;     else {       int mid = (L + R) >> 1;       if (mid >= x)         Update(t, x, L, mid, rt << 1);       else         Update(t, x, mid + 1, R, rt << 1 | 1);       PushUp(t, rt);     }   }   int Find(int t, int x, int L, int R, int rt) {     if (L == R) {       tree[t][rt] = 0;       return L;     }     int ans, mid = (L + R) >> 1;     if (tree[t][rt << 1] >= x)       ans = Find(t, x, L, mid, rt << 1);     else {       x -= tree[t][rt << 1];       ans = Find(t, x, mid + 1, R, rt << 1 | 1);     }     PushUp(t, rt);     return ans;   }   int main() {     char ch;     int k, i, j, q, len, n;     while (~scanf( %d %s%d , &k, s + 1, &q)) {       memset(vis, false, sizeof(vis));       memset(tree, 0, sizeof(tree));       len = strlen(s + 1);       n = len * k;       for (j = len + 1; --k;) {         for (i = 1; i <= len; i++) s[j++] = s[i];       }       s[j] = 0;       for (i = 1; s[i]; i++) Update(s[i] -  a , i, 1, n, 1);       while (q--) {         scanf( %d %c , &i, &ch);         k = Find(ch -  a , i, 1, n, 1);         vis[k] = true;       }       for (i = 1; s[i]; i++) {         if (!vis[i]) putchar(s[i]);       }       putchar(  n );     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define forg(i,x) for(register int i=fir[x];i;i=nxt[i])   #define uu unsigned   #define scanf a14=scanf   #define rint register int   #define fre(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout)   typedef long long ll;   typedef uu long long ull;   typedef pair<int,int>pii;   int a14;   inline int rd(int l,int r){return rand()%(r-l+1)+l;}      const int mxn=1e5+3,sq=200,qs=320;   int n,b[mxn],lp[mxn],rp[mxn],kn,be[mxn],po[mxn],qn;   int ju[mxn/sq+2][mxn],ad[mxn/sq+2][mxn/qs+1];   int TG;   struct shu{       int a[mxn],tg[mxn];       void add(int x){for(;x<=n;x+=x&-x){if(tg[x]!=TG)tg[x]=TG,a[x]=0;++a[x];}}       int ask(int x){           int su=0,p=0;           for(int i=1<<16;i;i>>=1){               if(p+i>=n)continue;               p+=i;if(tg[p]!=TG)tg[p]=TG,a[p]=0;               if(p+a[p]+su>=x)p-=i;else su+=a[p];           }           return p+1;       }       void gb(int t){for(int i=1;i<=n;++i){if(tg[i]!=TG)a[i]=0;ju[t][i]=ju[t][i-(i&-i)]+a[i];}for(int i=1;i<=n;++i)ju[t][i]+=i;}   }ar;   void add2(int t,int x,int y){       int k=(x-1)/qs;       for(int i=x;i<=(k+1)*qs;++i)ju[t][i]+=y;       for(++k;k*qs+1<=n;++k)ad[t][k]+=y;   }   int main(){   //cout<<(sizeof(ju)>>20)<<endl;       scanf( %d ,&n);for(int i=1;i<=n;++i)scanf( %d ,b+i),b[i]=i-b[i];scanf( %d ,&qn);       for(int l=1,r;r!=n;l=r+1){r=min(l+sq-1,n);lp[++kn]=l,rp[kn]=r;for(int i=l;i<=r;++i)be[i]=kn;}       for(int t=1;t<=kn;++t){           ++TG; for(int i=lp[t];i<=rp[t];++i)po[i]=ar.ask(b[i]),ar.add(po[i]);           ar.gb(t);       }       while(qn--){           int o,x,y;scanf( %d%d ,&o,&x);if(o==1){               scanf( %d ,&y);b[x]=x-y;int k=be[x],ls;               ++TG;for(int i=lp[k];i<=rp[k];++i){                   if(i<x)ar.add(po[i]);else{                       ls=po[i],po[i]=ar.ask(b[i]),ar.add(po[i]);                       if(ls==po[i])continue;                       if(ls==po[i]-1){--ju[k][ls];continue;}                       if(ls==po[i]+1){++ju[k][po[i]];continue;}                       assert(i==x);                       add2(k,ls,-1),add2(k,po[i],1);                   }               }           }else{               int t=be[x],re=b[x];for(int i=x+1;i<=rp[t];++i)re+=b[i]<=re;               for(++t;t<=kn;++t)re=ju[t][re]+ad[t][(re-1)/qs];               printf( %d n ,re);           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MOD = 1e9 + 7;   vector<int> prefix_function(vector<int> s) {     int n = s.size();     vector<int> pi(n);     pi[0] = 0;     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) {         j = pi[j - 1];       }       if (s[i] == s[j]) {         ++j;       }       pi[i] = j;     }     return pi;   }   vector<int> res_vector(vector<int> s, vector<int> t) {     vector<int> res = s;     res.push_back(2 * INF);     for (int i = 0; i < t.size(); ++i) {       res.push_back(t[i]);     }     return res;   }   vector<int> process(vector<int> res, vector<int> pi, int n) {     vector<int> ans(res.size());     for (int i = n + 1; i < res.size(); ++i) {       ++ans[pi[i]];     }     for (int i = res.size() - 1; i >= n + 1; --i) {       ans[pi[i - 1]] += ans[i];     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     int n, w;     cin >> n >> w;     if (w == 1) {       cout << n << endl;       return 0;     }     vector<int> a(n - 1);     int last;     cin >> last;     for (int i = 0; i < n - 1; ++i) {       int temp;       cin >> temp;       a[i] = temp - last;       last = temp;     }     cin >> last;     vector<int> b(w - 1);     for (int i = 0; i < w - 1; ++i) {       int temp;       cin >> temp;       b[i] = temp - last;       last = temp;     }     vector<int> res = res_vector(b, a);     vector<int> pi = prefix_function(res);     vector<int> ans = process(res, pi, b.size());     cout << ans[w - 1] << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<char> v;     int i = 0;     int j = 1;     int sum = -1;     while (sum < n - 1) {       sum = sum + j;       v.push_back(s[sum]);       j++;     }     for (auto it = v.begin(); it != v.end(); it++) {       cout << *it;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long int N = 1000005;   struct segmenttree {     vector<long long int> st;     void init(long long int _n) {       st.clear();       st.resize(4 * _n);     }     void build(long long int l, long long int r, long long int node) {       if (l == r) {         return;       }       long long int mid = (l + r) / 2;       build(l, mid, node * 2 + 1);       build(mid + 1, r, node * 2 + 2);       st[node] = max(st[2 * node + 1], st[2 * node + 2]);     }     void update(long long int l, long long int r, long long int indup,                 long long int val, long long int node) {       if (l == r) {         st[node] = val;         return;       } else {         long long int mid = (l + r) / 2;         if (indup >= l && indup <= mid) {           update(l, mid, indup, val, node * 2 + 1);         } else {           update(mid + 1, r, indup, val, node * 2 + 2);         }         st[node] = max(st[2 * node + 1], st[2 * node + 2]);       }     }     long long int query(long long int si, long long int se, long long int l,                         long long int r, long long int node) {       if (se < l || si > r || l > r) {         return INT_MIN;       }       if (si >= l && se <= r) {         return st[node];       }       long long int mid = (si + se) / 2;       long long int q1 = query(si, mid, l, r, node * 2 + 1);       long long int q2 = query(mid + 1, se, l, r, node * 2 + 2);       return max(q1, q2);     }   };   segmenttree tree[N];   long long int sz[N], res[N], mx[N], n, m;   vector<long long int> pos[N];   long long int give(long long int row, long long int pos) {     long long int mn, mx, ret;     if (pos < sz[row]) {       mn = max(0ll, pos - (m - sz[row])), mx = pos;       if ((m - 1) - pos >= sz[row])         ret = 0;       else         ret = INT_MIN;     } else {       pos = sz[row] - (m - pos);       mn = pos, mx = max(sz[row] - 1, pos + (m - sz[row]));       if (pos >= sz[row])         ret = INT_MIN;       else         ret = 0;     }     return max(ret, tree[row].query(0, sz[row] - 1, mn, mx, 0));   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       long long int i, j, k, ans = 0, cnt = 0, sum = 0;       cin >> n >> m;       for (i = 0; i < n; i++) {         cin >> sz[i];         tree[i].init(sz[i]);         for (j = 0; j < sz[i]; j++) {           long long int x;           cin >> x;           mx[i] = max(mx[i], x);           tree[i].update(0, sz[i] - 1, j, x, 0);         }         for (j = 0; j < sz[i]; j++) pos[j].push_back(i);         for (j = max(sz[i], (m - sz[i])); j < m; j++) pos[j].push_back(i);       }       for (i = 0; i < n; i++) {         ans += mx[i];       }       for (i = 0; i < m; i++) {         res[i] = ans;         for (auto x : pos[i]) {           res[i] -= mx[x];           res[i] += give(x, i);         }       }       for (i = 0; i < m; i++) {         cout << res[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T prod(const T &a, const T &b, const T &mod) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename T>   T pow_(const T &a, const T &b) {     if (!b) return 1;     T p = pow_(a, b / 2);     p *= p;     return (b % 2) ? (p * a) : p;   }   template <typename T>   T modpow(const T &a, const T &b, const T &mod) {     if (!b) return 1;     T p = modpow(a, b / 2);     p = prod(p, p);     return (b % 2) ? (prod(p, a)) : p;   }   template <typename T>   T max(const T &a, const T &b, const T &c) {     return max(a, max(b, c));   }   template <typename T>   T min(const T &a, const T &b, const T &c) {     return min(a, min(b, c));   }   template <typename T>   void dbg(const vector<T> &a, int l, int r) {     for (long long int i = l; i <= r; i++) cout << a[i] <<    ;     cout << endl;   }   template <typename T>   void dbg(const vector<T> &a) {     for (long long int i = 0; i <= a.size() - 1; i++) cout << a[i] <<    ;     cout << endl;   }   void main_() {     long long int n;     cin >> n;     vector<long long int> a(n + 1, 0);     for (long long int i = 1; i <= n; i++) {       cin >> a[i];       a[i] += a[i - 1];     }     long long int x, y, z;     long long int res = -LLONG_MAX;     for (long long int i = 0; i <= n; i++) {       long long int m1 = -LLONG_MAX, m2 = -LLONG_MAX;       long long int y_, x_, z_;       y_ = i;       for (long long int j = 0; j <= i; j++) {         if (m1 < a[j]) {           m1 = a[j];           x_ = j;         }       }       for (long long int j = i; j <= n; j++) {         if (m2 < a[j]) {           m2 = a[j];           z_ = j;         }       }       long long int sum = 2 * (a[x_] + a[z_] - a[y_]) - a[n];       if (res < sum) {         res = sum;         x = x_;         y = y_;         z = z_;       }     }     cout << x <<     << y <<     << z << endl;   }   int main() {     { main_(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T, class U>   using Pa = pair<T, U>;   template <class T>   using vec = vector<T>;   template <class T>   using vvec = vector<vec<T>>;   template <typename Monoid, typename F>   class SegmentTree {    private:     int sz;     vector<Monoid> seg;     const F op;     const Monoid e;       public:     SegmentTree(int n, const F op, const Monoid &e) : op(op), e(e) {       sz = 1;       while (sz <= n) sz <<= 1;       seg.assign(2 * sz, e);     }     void set(int k, const Monoid &x) { seg[k + sz] = x; }     void build() {       for (int i = sz - 1; i > 0; i--) {         seg[i] = op(seg[2 * i], seg[2 * i + 1]);       }     }     void update(int k, const Monoid &x) {       k += sz;       seg[k] += x;       while (k >>= 1) {         seg[k] = op(seg[2 * k], seg[2 * k + 1]);       }     }     Monoid query(int l, int r) {       Monoid L = e, R = e;       for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {         if (l & 1) L = op(L, seg[l++]);         if (r & 1) R = op(seg[--r], R);       }       return op(L, R);     }     Monoid operator[](const int &k) const { return seg[k + sz]; }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N, M;     cin >> N >> M;     vvec<char> F(N, vec<char>(M));     vec<int> len(N + M);     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) {         cin >> F[i][j];         len[i + j]++;       }     vvec<int> L(N, vec<int>(M, 0));     vvec<int> R = L, D = L;     for (int i = N - 1; i >= 0; i--) {       for (int j = 0; j < M; j++) {         int c = (F[i][j] ==  z );         if (!c) {           L[i][j] = 0;           D[i][j] = 0;         } else {           L[i][j] = 1 + (j != 0 ? L[i][j - 1] : 0);           D[i][j] = 1 + ((j != 0 && i != N - 1) ? D[i + 1][j - 1] : 0);         }       }       for (int j = M - 1; j >= 0; j--) {         int c = (F[i][j] ==  z );         if (!c)           R[i][j] = 0;         else           R[i][j] = 1 + (j != M - 1 ? R[i][j + 1] : 0);       }     }     auto op = [](ll a, ll b) { return a + b; };     vec<SegmentTree<ll, decltype(op)>> segs;     for (int l = 0; l < N + M - 1; l++) {       SegmentTree<ll, decltype(op)> seg(M, op, 0);       segs.push_back(seg);     }     ll ans = 0;     for (int j = M - 1; j >= 0; j--) {       for (int i = 0; i < N; i++) {         int y = j;         while (y >= 0 && y + R[i][y] - 1 == j) {           segs[i + y].update(y, 1);           y--;         }       }       for (int i = 0; i < N; i++) {         int a = min(L[i][j], D[i][j]);         ans += segs[i + j].query(j - a + 1, j + 1);       }     }     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, top, len[100005], F1[1005][1005], F2[1005][1005];   pair<int, int> F[30];   char ans[30], dir[100005], a[1005][1005];   bool outside(int first, int second) {     return (first < 1 || first > n || second < 1 || second > m);   }   int tinh1(int first, int y1, int y2) {     if (y1 > y2) swap(y1, y2);     return F1[first][y2] - F1[first][y1 - 1];   }   int tinh2(int second, int x1, int x2) {     if (x1 > x2) swap(x1, x2);     return F2[x2][second] - F2[x1 - 1][second];   }   void tinh(int first, int second, int i, int& x2, int& y2) {     int dx = 0, dy = 0;     if (dir[i] ==  N )       dx = -1;     else if (dir[i] ==  S )       dx = 1;     else if (dir[i] ==  W )       dy = -1;     else if (dir[i] ==  E )       dy = 1;     x2 = first + dx * len[i], y2 = second + dy * len[i];   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %c , &a[i][j]);         if (a[i][j] >=  A  && a[i][j] <=  Z ) {           F[a[i][j]] = pair<int, int>(i, j);           a[i][j] =  . ;         }       }       scanf(  n );     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         F1[i][j] = F1[i][j - 1] + (a[i][j] ==  # );         F2[i][j] = F2[i - 1][j] + (a[i][j] ==  # );       }     int k;     scanf( %d n , &k);     for (int i = 1; i <= k; ++i) scanf( %c %d n , &dir[i], &len[i]);     for (char t =  A ; t <=  Z ; ++t)       if (F[t].first != 0) {         int first = F[t].first, second = F[t].second;         bool b = true;         for (int i = 1; i <= k; ++i) {           int x2, y2;           tinh(first, second, i, x2, y2);           if (outside(x2, y2) || (x2 == first && tinh1(first, second, y2) != 0) ||               (y2 == second && tinh2(second, first, x2) != 0)) {             b = false;             break;           }           first = x2, second = y2;         }         if (b) ans[++top] = t;       }     if (!top)       cout <<  no solution  << endl;     else {       for (int i = 1; i <= top; ++i) printf( %c , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int n;   int a[5001];   bool coutNO;   vector<int> check[5001];   int main() {     cin.tie(0);     cout.tie(0);     cin >> t;     for (int ct = 1; ct <= t; ct++) {       cin >> n;       coutNO = true;       for (int i = 1; i <= n; i++) check[i].clear();       for (int i = 1; i <= n; i++) {         cin >> a[i];         check[a[i]].push_back(i);         if (check[a[i]].size() >= 3) coutNO = false;       }       if (!coutNO) {         cout <<  YES  <<   n ;         continue;       }       for (int i = 1; i <= n; i++)         if (check[i].size() == 2) {           if (check[i][0] + 1 != check[i][1]) {             coutNO = false;             break;           }         }       if (coutNO)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int const lac = 100000;   long long int modmul(long long int a, long long int b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long int modadd(long long int a, long long int b) {     return (((a % 1000000007) + (b % 1000000007))) % 1000000007;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   class comp {    public:     bool operator()(int a, int b) const { return a > b; }   };   bool compa(int a, int b) { return a > b; }   void solve(long long int t1) {     long long int n;     cin >> n;     vector<long long int> arr(n + 1);     for (long long int i = 1; i <= n; i++) {       cin >> arr[i];     }     vector<long long int> prefix(n + 1, 0);     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       prefix[i] = prefix[i - 1] ^ i;       ans ^= arr[i];     }     if (n == 1) {       cout << ans <<   n ;       return;     }     for (long long int i = 1; i <= n - 1; i++) {       long long int temp = (n) / (i + 1);       long long int rem = n % i;       if (temp & 1) {         ans ^= prefix[i];       }       ans ^= prefix[rem];     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     for (long long int i = 1; i <= t; i++) {       solve(t);     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<double, double> p[301];   double a, b, c, den, len;   double area(int i) {     double num = abs(a * p[i].first + b * p[i].second + c);     return (num) / (2.0);   }   double f(int i, int j) {     a = (p[j].second - p[i].second);     b = (p[i].first - p[j].first);     c = 0 - p[i].second * b - p[i].first * a;     den = sqrtf(a * a + b * b);     len = sqrtf((p[i].first - p[j].first) * (p[i].first - p[j].first) +                 (p[i].second - p[j].second) * (p[i].second - p[j].second));     double m1 = -1, m2 = -1;     for (int k = 0; k < n; ++k) {       if (k == i or k == j) continue;       long long temp = a * p[k].first + b * p[k].second + c;       double flag = area(k);       if (temp >= 0)         m1 = max(m1, flag);       else         m2 = max(m2, flag);     }     if (m1 == -1 or m2 == -1) return 0;     return m1 + m2;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       double x, y;       scanf( %lf%lf , &x, &y);       p[i] = {x, y};     }     double ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         ans = max(ans, f(i, j));       }     }     printf( %0.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, s;   vector<long long> v(1001);   long long check(long long x) {     long long sum = 0;     for (long long i = 0; i < n; i++) {       if (v[i] < x) return 0;       sum += max((long long)0, v[i] - x);     }     return (sum >= s);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> s;     for (long long i = 0; i < n; i++) cin >> v[i];     long long l = 0;     long long r = 1e15;     while (l < r) {       long long mid = (l + r + 1) / 2;       if (check(mid))         l = mid;       else         r = mid - 1;     }     if (check(l))       cout << l;     else       cout << -1;   }


#include <bits/stdc++.h>   long long n, m, a, d, t[100007], old, ans, aind, firstA, stepD;   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     std::cout.tie(0);     std::cin >> n >> m >> a >> d;     for (int i = 0; i < m; ++i) std::cin >> t[i];     aind = d / a * a + a;     for (int i = 0; i < m; ++i) {       if (t[i] <= old) continue;       if (t[i] <= n * a) {         firstA = (old / a + 1) * a;         if (t[i] <= firstA) {           ++ans;           old = t[i] + d;         } else {           stepD = (t[i] - firstA) / aind + ((t[i] - firstA) % aind ? 1 : 0);           ans += stepD;           old = firstA + stepD * aind - (a - d % a);           if (old < t[i]) {             ++ans;             firstA = (old / a + 1) * a;             old = std::min(t[i], firstA) + d;           }         }       } else {         if (old < n * a) {           firstA = (old / a + 1) * a;           stepD = (n * a - firstA) / aind + ((n * a - firstA) % aind ? 1 : 0);           ans += stepD;           old = firstA + stepD * aind - (a - d % a);           if (old < n * a) {             ++ans;             firstA = (old / a + 1) * a;             old = firstA + d;           }         }         if (old < t[i]) {           ++ans;           old = t[i] + d;         }       }     }     if (old < a * n) {       firstA = (old / a + 1) * a;       stepD = (a * n - firstA) / aind + ((a * n - firstA) % aind ? 1 : 0);       ans += stepD;       old = firstA + stepD * aind - (a - d % a);       if (old < a * n) {         ++ans;       }     }     std::cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int inf = 50000000;   const int maxn = 2010;   int n, A[maxn][maxn], vis[maxn];   int bfs(int src, int d) {     queue<int> q;     q.push(src);     for (int i = 1; i <= n; i++) vis[i] = 0;     vis[src] = 1;     int ret = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 1; i <= n; i++) {         if (!d && !vis[i] && A[u][i] > 0) {           vis[i] = 1;           ret += 1;           q.push(i);         }         if (d && !vis[i] && A[i][u] > 0) {           vis[i] = 1;           ret += 1;           q.push(i);         }       }     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %d , &A[i][j]);       }     }     if (bfs(1, 0) == n && bfs(1, 1) == n)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   char str[20][N];   int n, m, des;   int dp[20][2];   int call(int flr, int side) {     if (flr == des) {       if (side == 0) {         int p = 0;         for (int i = 1; i <= m; i++)           if (str[flr][i] ==  1 ) p = i;         return p;       } else {         int p = m + 1;         for (int i = m; i >= 1; i--)           if (str[flr][i] ==  1 ) p = i;         return m + 1 - p;       }     }     if (dp[flr][side] != -1) return dp[flr][side];     int ret = 1e9;     if (side == 0) {       ret = min(ret, m + 2 + call(flr - 1, 1));       int p = 0;       for (int i = 1; i <= m; i++)         if (str[flr][i] ==  1 ) p = i;       ret = min(ret, 2 * p + 1 + call(flr - 1, 0));     } else {       ret = min(ret, m + 2 + call(flr - 1, 0));       int p = m + 1;       for (int i = m; i >= 1; i--)         if (str[flr][i] ==  1 ) p = i;       ret = min(ret, (m + 1 - p) * 2 + 1 + call(flr - 1, 1));     }     return dp[flr][side] = ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     memset(dp, -1, sizeof(dp));     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     des = n - 1;     for (int i = n - 1; i >= 0; i--) {       for (int j = 1; j <= m; j++)         if (str[i][j] ==  1 ) des = i;     }     cout << call(n - 1, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, sum, ans, T;   char c;   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       vector<int> v, b;       for (int i = 1; i <= n; i += 2) {         if (i + 1 > n) {           v.push_back(i);           b.push_back(i);         } else {           printf( ? %d %d n , i, i + 1);           fflush(stdout);           scanf(  %c , &c);           if (c ==  < )             v.push_back(i + 1), b.push_back(i);           else if (c ==  > )             v.push_back(i), b.push_back(i + 1);           else             v.push_back(i), b.push_back(i);         }       }       while (v.size() > 1) {         x = v[v.size() - 1];         v.pop_back();         y = v[v.size() - 1];         v.pop_back();         printf( ? %d %d n , x, y);         fflush(stdout);         scanf(  %c , &c);         if (c ==  < )           v.push_back(y);         else if (c ==  > )           v.push_back(x);         else           v.push_back(x);       }       while (b.size() > 1) {         x = b[b.size() - 1];         b.pop_back();         y = b[b.size() - 1];         b.pop_back();         printf( ? %d %d n , x, y);         fflush(stdout);         scanf(  %c , &c);         if (c ==  < )           b.push_back(x);         else if (c ==  > )           b.push_back(y);         else           b.push_back(x);       }       printf( ! %d %d n , b[0], v[0]);       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   vector<int> v;   set<double> S;   set<double>::iterator it, it2;   int main() {     int n, k;     cin >> n >> k;     cin >> s;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  0 ) v.push_back(i + 1);     int i = 0, j = 0;     for (i = 0; i <= k; i++) S.insert(v[i]);     j = i - 1;     i = 0;     int mn = INT_MAX;     n = v.size();     while (j < n) {       double x = (v[i] + v[j]) / 2.0;       it = S.lower_bound(x);       it2 = it;       it2--;       int a = max(v[j] - *it, *it - v[i]);       int b = max(*it2 - v[i], v[j] - *it2);       mn = min(mn, min(a, b));       j++;       if (j < n) {         S.erase(v[i]);         S.insert(v[j]);         i++;       }     }     cout << mn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int firstOne(string s) {     int len = s.length();     for (int i = len - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         return len - i;       }     }   }   int firstOneAfter(string s, int idx) {     int len = s.length();     for (int i = len - idx; i >= 0; i--) {       if (s[i] ==  1 ) {         return len - i;       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       string x, y;       cin >> x >> y;       int firstOneX = firstOne(x), firstOneY = firstOne(y);       if (firstOneX >= firstOneY) {         cout << firstOneX - firstOneY << endl;       } else {         cout << firstOneAfter(x, firstOneY) - firstOneY << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int val(vector<int> a) {     int cur = a[0];     for (int i = 1; i < a.size(); i++) {       cur = (a[i] | cur) - a[i];     }     return cur;   }   int brute(vector<int> a) {     vector<int> P(a.size());     for (int i = 0; i < a.size(); i++) {       P[i] = i;     }     int ans = 0;     vector<int> f;     do {       vector<int> b = a;       for (int i = 0; i < b.size(); i++) {         b[i] = a[P[i]];       }       if (ans < val(b)) f = b;       ans = max(ans, val(b));     } while (next_permutation((P).begin(), (P).end()));     return ans;   }   pair<long long, long long> vec(pair<long long, long long> P,                                  pair<long long, long long> Q) {     return {P.first - Q.first, P.second - Q.second};   }   bool okay(pair<long long, long long> P1, pair<long long, long long> P2,             pair<long long, long long> P3, pair<long long, long long> P4) {     return vec(P1, P2) == vec(P3, P4);   }   int main() {     int n;     cin >> n;     vector<pair<long long, long long> > P(n);     for (int i = 0; i < n; i++) {       cin >> P[i].first >> P[i].second;     }     if (n % 2) {       cout <<  no ;       return 0;     }     P.push_back(P[0]);     for (int i = 0; i < n / 2; i++) {       if (okay(P[i], P[i + 1], P[n / 2 + i + 1], P[n / 2 + i]) ||           okay(P[i], P[i + 1], P[n / 2 + i], P[n / 2 + i + 1])) {         continue;       }       cout <<  no ;       return 0;     }     cout <<  yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   using ll = long long;   int n, m, b[N];   ll a[N], c1, c2;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 2; i <= m * 2; i++) {       for (int j = 1; j <= n; j++) b[j] = a[j] % i;       sort(b + 1, b + n + 1);       b[n + 1] = m;       if (~i & 1) {         int t1 = 0;         for (int j = 1; j <= n; j++)           if (b[j] >= i / 2) t1 ^= 1;         if (t1) ++c2;       }       for (int j = 1; j <= n + 1; j++) {         int l = max(b[j - 1] + 1, i / 2 + 1), r = min(min(i - 1, m), b[j]);         if (r < l) continue;         int al = max(b[j - 1], b[n - 1] / 2), bl = max(l, i - al);         if (bl <= r) c1 += r - bl + 1, r = bl - 1;         if (r < l) continue;         if ((n - j + 1) & 1)           c2 += (r - l + 1) * 2;         else {           al = b[n - 1] / 2 + 1;           int ar = b[n] / 2;           bl = max(l, i - ar);           int br = min(r, i - al);           if (br >= bl) c1 += br - bl + 1;         }       }     }     cout << c1 <<     << c1 <<     << c2 <<     << m * 1ll * m - c1 * 2 - c2          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int T = 1 << 19;   int n, q, a[N];   long long s[N];   int p, x;   int tn = 1;   long long mx[T], sum[T];   long long tmx[T], tsum[T];   inline void pushup(int x) {     mx[x] = max(sum[x << 1] ? mx[x << 1] : -0x3f3f3f3f3f3f3f3f,                 sum[x << 1 ^ 1] ? mx[x << 1 ^ 1] : -0x3f3f3f3f3f3f3f3f);     sum[x] = sum[x << 1] + sum[x << 1 ^ 1];   }   inline void pushdown(int x) {     if (tmx[x]) {       if (mx[x << 1] != -0x3f3f3f3f3f3f3f3f) {         mx[x << 1] += tmx[x];       }       if (x << 1 ^ 1 != -0x3f3f3f3f3f3f3f3f) {         mx[x << 1 ^ 1] += tmx[x];       }       tmx[x << 1] += tmx[x];       tmx[x << 1 ^ 1] += tmx[x];       tmx[x] = 0;     }     if (tsum[x]) {       sum[x << 1] += tsum[x];       sum[x << 1 ^ 1] += tsum[x];       tsum[x << 1] += (tsum[x] >> 1);       tsum[x << 1 ^ 1] += (tsum[x] >> 1);       tsum[x] = 0;     }   }   void update(int l, int r, int x, int y, int nl = 1, int nr = tn, int cur = 1) {     if (l == nl && r == nr) {       if (mx[cur] != -0x3f3f3f3f3f3f3f3f) {         mx[cur] += x;       }       tmx[cur] += x;       sum[cur] += 1ll * y * (nr - nl + 1);       tsum[cur] += 1ll * y * (nr - nl + 1);       return;     }     pushdown(cur);     int mid = (nl + nr) >> 1;     if (r <= mid) {       update(l, r, x, y, nl, mid, cur << 1);     } else if (l > mid) {       update(l, r, x, y, mid + 1, nr, cur << 1 ^ 1);     } else {       update(l, mid, x, y, nl, mid, cur << 1);       update(mid + 1, r, x, y, mid + 1, nr, cur << 1 ^ 1);     }     pushup(cur);   }   int query(int l, int r, int x, int nl = 1, int nr = tn, int cur = 1) {     if (nl == nr) {       return (sum[cur] && (mx[cur] == x)) ? nl : -1;     }     pushdown(cur);     int mid = (nl + nr) >> 1;     if (l == nl && r == nr) {       int res = -1;       if (sum[cur << 1] > 0 && mx[cur << 1] >= x) {         res = max(res, query(nl, mid, x, nl, mid, cur << 1));       }       if (sum[cur << 1 ^ 1] > 0 && mx[cur << 1 ^ 1] >= x) {         res = max(res, query(mid + 1, nr, x, mid + 1, nr, cur << 1 ^ 1));       }       return res;     } else {       if (r <= mid) {         return query(l, r, x, nl, mid, cur << 1);       } else if (l > mid) {         return query(l, r, x, mid + 1, nr, cur << 1 ^ 1);       } else {         return max(query(l, mid, x, nl, mid, cur << 1),                    query(mid + 1, r, x, mid + 1, nr, cur << 1 ^ 1));       }     }   }   int query0(int* a) { return a[1] ? -1 : 1; }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s[i] = s[i - 1] + a[i];     }     while (tn < n) {       tn <<= 1;     }     for (int i = tn; i < tn + n; i++) {       mx[i] = a[i - tn + 1] - s[i - tn];       sum[i] = a[i - tn + 1];     }     for (int i = tn + n; i < tn + tn; i++) {       mx[i] = -0x3f3f3f3f3f3f3f3f;       sum[i] = 0;     }     for (int i = tn - 1; i; i--) {       pushup(i);     }     while (q--) {       scanf( %d%d , &p, &x);       update(p, p, x - a[p], x - a[p]);       if (p + 1 <= n) {         update(p + 1, n, -(x - a[p]), 0);       }       a[p] = x;       int ans = max(query(1, n, 0), query0(a));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 100010;   int N, M;   bool vis[MM];   int c[MM];   set<int> edge[MM];   void get_data() {     int i, j, k, a, b;     for (i = 1; i <= N; i++) {       edge[i].clear();       scanf( %d , &c[i]);     }     while (M--) {       scanf( %d%d , &a, &b);       if (c[b] != c[a]) {         edge[c[a]].insert(c[b]);         edge[c[b]].insert(c[a]);       }     }   }   void solve() {     int i, j, k, mx = -1, col = 100001;     int count;     sort(c + 1, c + N + 1);     for (i = 1; i <= N; i++) {       if (mx == -1 || mx < edge[c[i]].size()) mx = edge[c[i]].size(), col = c[i];     }     printf( %d n , col);   }   int main() {     while (scanf( %d%d , &N, &M) != EOF) get_data(), solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (1e6) + 5;   const int IT_MAX = 1 << 20;   const int INF = -1;   int bit[IT_MAX + 10];   void update(int p, int dv) {     for (; p <= IT_MAX; p += p & (-p)) bit[p] += dv;   }   int query(int p) {     int rv = 0;     for (; p; p -= p & (-p)) rv += bit[p];     return rv;   }   int largerpos(int v) {     if (bit[IT_MAX] <= v) return INF;     int p = 0;     int s = 0;     for (int i = 19; i >= 0; i--) {       if (s + bit[p + (1 << i)] <= v) {         s += bit[p + (1 << i)];         p |= (1 << i);       }     }     return p + 1;   }   vector<int> st[MAX], en[MAX];   int l[MAX], r[MAX];   int pa[MAX], sz[MAX];   int finPa(int p) { return pa[p] == p ? p : pa[p] = finPa(pa[p]); }   bool mergeNode(int u, int v) {     int r1 = finPa(u), r2 = finPa(v);     if (sz[r1] < sz[r2]) {       swap(r1, r2);     }     pa[r2] = r1;     sz[r1] += sz[r2];     return (r1 == r2);   }   int main() {     ios::sync_with_stdio(false);     for (int i = 1; i <= MAX; i++) {       sz[i] = 1;       pa[i] = i;     }     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> l[i] >> r[i];       st[l[i]].push_back(i);       en[r[i]].push_back(i);     }     for (int i = 1; i <= 2 * n; i++) {       for (int s : st[i]) {         update(l[s], 1);       }       for (int s : en[i]) {         int nex = largerpos(query(l[s]));         while (nex != -1) {           for (int ns : st[nex]) {             if (mergeNode(s, ns)) {               cout <<  NO  << endl;               return 0;             }           }           nex = largerpos(query(nex));         }       }       for (int s : en[i]) {         update(l[s], -1);       }     }     int p = finPa(1);     cout << ((sz[p] == n) ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   long long int Mod(long long int n) { return ((n % mod) + mod) % mod; }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long int f[200005];   long long int invfact[200005];   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) {         res = (res * x) % mod;       }       x = (x * x) % mod;       y >>= 1;     }     return res;   }   void precal() {     f[0] = 1;     invfact[0] = 1;     for (int i = 1; i < 200005; i++) {       f[i] = (f[i - 1] * i) % mod;       invfact[i] = power(f[i], mod - 2);     }   }   long long int fact(long long int n, long long int k) {     if (n < k) {       return 0;     }     return ((f[n] * invfact[k]) % mod * invfact[n - k]) % mod;   }   bool prime[10000011];   void primenumbers(long long int n) {     memset(prime, true, sizeof(prime));     for (long long int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long int modI(long long int a, long long int m) {     long long int m0 = m, y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m;       a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   int spf[100001];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 100001; i++) spf[i] = i;     for (int i = 4; i < 100001; i += 2) spf[i] = 2;     for (int i = 3; i * i < 100001; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   vector<int> getFactorization(int x) {     vector<int> ret;     while (x != 1) {       ret.push_back(spf[x]);       x = x / spf[x];     }     return ret;   }   const long long int mxn = 400010;   long long int st[mxn];   long long int a[mxn];   void build(long long int v, long long int l, long long int r) {     if (l == r) {       st[v] = a[l];     } else {       build(2 * v, l, (l + r) / 2);       build(2 * v + 1, (l + r) / 2 + 1, r);       st[v] = st[2 * v] * st[2 * v + 1];     }   }   void update(long long int v, long long int l, long long int r,               long long int pos, long long int val) {     if (pos < l || pos > r) {       return;     }     if (pos == l && pos == r) {       st[v] = val;     } else {       update(2 * v, l, (l + r) / 2, pos, val);       update(2 * v + 1, (l + r) / 2 + 1, r, pos, val);       st[v] = st[2 * v] * st[2 * v + 1];     }   }   long long int query(long long int v, long long int l, long long int r,                       long long int tl, long long int tr, long long int mo) {     if (tr < l || tl > r || tl > tr) {       return 1;     }     if (l == tl && r == tr) {       return st[v] % mo;     } else {       return (((query(2 * v, l, (l + r) / 2, tl, min(tr, (l + r) / 2), mo)) %                mo) *               ((query(2 * v + 1, (l + r) / 2 + 1, r, max(tl, (l + r) / 2 + 1), tr,                       mo)) %                mo)) %              mo;     }   }   long long int maxSubArraySum(vector<long long int> a, long long int size) {     long long int max_so_far = INT_MIN, max_ending_here = 0, start = 0, end = 0,                   s = 0;     for (long long int i = 0; i < size; i++) {       max_ending_here += a[i];       if (max_so_far < max_ending_here) {         max_so_far = max_ending_here;       }       if (max_ending_here < 0) {         max_ending_here = 0;         s = i + 1;       }     }     return max_so_far;   }   int main() {     fast();     long long int n, q;     cin >> n >> q;     vector<long long int> d(n + 1, 0);     for (long long int i = 1; i < n + 1; i++) {       cin >> d[i];     }     sort(d.begin(), d.end());     vector<long long int> pr(n + 2, 0);     while (q--) {       long long int x, y;       cin >> x >> y;       pr[x]++;       pr[y + 1]--;     }     vector<long long int> get(n + 1, 0);     for (long long int i = 1; i < n + 1; i++) {       get[i] = get[i - 1] + pr[i];     }     sort(get.begin(), get.end());     long long int ans = 0;     for (long long int i = 1; i < n + 1; i++) {       ans = ans + get[i] * d[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   using ld = long double;   const ld PI = 4 * atanl(1);   const ld EPS = 1e-12;   const int MN = 1e5 + 10;   struct vec {    public:     int x, y;     void in() { scanf( %d%d , &x, &y); }     ld mag() const { return hypotl(x, y); }     ld ang() const { return atan2l(y, x); }   };   struct Evt {    public:     ld t;     int v;     Evt(ld _t = 0, int _v = 0) : t(_t), v(_v) {}     bool operator<(const Evt& o) const { return t < o.t; }   };   struct BIT {    public:     int a[MN * 2], L;     void reset(int _L) {       memset(a, 0, L * sizeof *a);       L = _L;     }     void upd(int n, int v) {       for (++n; n <= L; n += -n & n) a[n - 1] += v;     }     int qry(int n) {       int f = 0;       for (; n; n -= -n & n) f += a[n - 1];       return f;     }     int qry(int l, int r) { return qry(r) - qry(l); }   };   int N, p[MN];   ll K;   vec a[MN];   std::vector<Evt> evt;   BIT bit;   ll count(ld d) {     ll f = (ll)N * (N - 1) / 2;     int ctr = 0;     for (int i = 0; i < N; ++i)       if (d < a[i].mag()) {         ld m = a[i].ang();         ld dif = acosl(d / a[i].mag());         ld s = m - dif, e = m + dif;         if (s + EPS < 0) s += 2 * PI, e += 2 * PI;         if (2 * PI < e + EPS) e -= 2 * PI;         if (e < s) std::swap(s, e);         evt.push_back({s, ctr});         evt.push_back({e, ctr});         ctr++;       }     std::sort(evt.begin(), evt.end());     memset(p, -1, ctr * sizeof *p);     bit.reset(ctr * 2);     for (int i = 0; i < evt.size(); ++i) {       int v = evt[i].v;       if (~p[v])         bit.upd(p[v], -1), f -= bit.qry(p[v] + 1, i);       else         p[v] = i, bit.upd(i, 1);     }     evt.clear();     return f;   }   int main() {     scanf( %d%lld , &N, &K);     for (int i = 0; i < N; ++i) a[i].in();     ld l = -logl(1e8), r = logl(2e4), m;     for (int i = 0; i < 100; ++i) {       ld m = (r + l) / 2;       if (count(exp(m)) < K)         l = m;       else         r = m;     }     printf( %.9lf n , (double)exp(r));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tot, a[1001000], ans[1001000 << 2], k[1001000];   long long s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]), s += a[i], k[i] = s % n;     k[m] = n;     sort(k + 1, k + m + 1);     for (int i = m; i; i--) k[i] -= k[i - 1];     for (int i = 1, j = 1; i <= m; ++i) {       int x = a[i];       while (x > 0) ans[++tot] = i, x -= k[j], j = j % m + 1;     }     while (tot % m) ans[++tot] = 1;     printf( %d n , tot / m);     for (int i = 1; i <= m; ++i) printf( %d  , k[i]);     puts(  );     for (int i = 1; i <= tot; ++i) {       printf( %d , ans[i]);       putchar(i % m ?     :   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int count = 0;     int min = a;     if (b < a) {       min = b;     }     int x = c / min;     for (int i = 0; i <= x; i++) {       for (int j = 0; j <= x; j++) {         if (count != 0) {           break;         }         if (a * i + b * j == c) {           count++;           cout <<  Yes ;         }       }     }     if (count == 0) {       cout <<  No ;     }   }


#include <bits/stdc++.h>   using namespace std;   void PT(long long a);   void PT1(long long a);   const long long M = 2 * (1e5) + 7;   long long a[M];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     {       long long n, k;       cin >> n >> k;       if (k * (k - 1) < n)         return cout <<  NO                      <<   n ,                0;       cout <<  YES             <<   n ;       vector<pair<long long, long long>> v;       long long i = 1, j = 2;       while (v.size() < n) {         if (v.size() == 0) {           v.push_back({i, j});           v.push_back({j, i});         } else if ((v.back()).first == i || (v.back()).second == j) {           v.push_back({j, i});           v.push_back({i, j});         } else {           v.push_back({i, j});           v.push_back({j, i});         }         if (j == k) {           i++;           j = i + 1;         } else           j++;       }       for (long long i = 0; i < n; i++) {         cout << v[i].first <<     << v[i].second <<   n ;       }     }     return 0;   }   void PT(long long a) { cout << a <<   n ; }   void PT1(long long a) { cout << a <<    ; }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v;   } e[200050 << 1];   int fa[200050];   int n, color[200050], s, d;   int cnt[2], dis[200050];   bool vis[200050];   vector<int> G[200050];   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   void _union(int x, int y) {     int f1 = find(x);     int f2 = find(y);     if (f1 == f2) return;     if (f1 < f2)       fa[f2] = f1;     else       fa[f1] = f2;   }   queue<int> q;   void bfs(int u) {     memset(vis, false, sizeof(vis));     memset(dis, 0, sizeof(dis));     while (!q.empty()) q.pop();     q.push(u);     vis[u] = true;     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i = 0; i < G[now].size(); i++) {         int v = G[now][i];         if (!vis[v]) {           q.push(v);           vis[v] = true;           s = v;           dis[v] = dis[now] + 1;         }       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &color[i]);       fa[i] = i;     }     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       e[2 * i - 1].u = u;       e[2 * i - 1].v = v;       e[i * 2].u = v;       e[i * 2].v = u;       if (color[u] == color[v]) _union(u, v);     }     for (int i = 1; i <= n; i++) fa[i] = find(i);     for (int i = 1; i < n; i++) {       int u = e[i * 2 - 1].u, v = e[i * 2 - 1].v;       if (fa[u] != fa[v]) {         G[fa[u]].push_back(fa[v]);         G[fa[v]].push_back(fa[u]);       }     }     int i = 1;     for (; G[i].size() == 0 && i <= n; i++)       ;     if (i > n) {       printf( 0 n );       return 0;     }     bfs(i);     bfs(s);     printf( %d n , (dis[s] + 1) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<int> g[100010];   const int inf = 1e9;   int d[100010], p[100010];   queue<int> Q;   void bfs(int x) {     for (int i = 1; i <= n; i++) d[i] = inf;     d[x] = 0;     while (!Q.empty()) Q.pop();     Q.push(x);     while (!Q.empty()) {       int y = Q.front();       Q.pop();       for (int z : g[y]) {         if (d[z] < inf) continue;         d[z] = d[y] + 1;         p[z] = y;         Q.push(z);       }     }   }   bool dfs(int x, int pa, int c) {     int d = g[x].size();     if (pa) d--;     if (c) {       if (d < 3) return 0;     } else {       if (d) return 0;     }     for (int y : g[x]) {       if (y == pa) continue;       if (!dfs(y, x, c - 1)) return 0;     }     return 1;   }   int main() {     cin >> n >> k;     for (int i = 1, x, y; i < n; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     bfs(1);     int x = max_element(d + 1, d + n + 1) - d;     bfs(x);     int y = max_element(d + 1, d + n + 1) - d;     int l = d[y];     while (2 * d[y] > l) y = p[y];     puts(dfs(y, 0, k) ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   void code() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long ans = 0;     for (long long i = 0; i < n; i++) {       if ((a[i] - a[0]) % k != 0) {         cout <<  -1  << endl;         return;       }       ans += ((a[i] - a[0]) / k);     }     cout << ans << endl;   }   signed main() { code(); }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   istream &operator>>(istream &in, pair<T1, T2> &P) {     in >> P.first >> P.second;     return in;   }   template <class T1, class T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &P) {     out <<  (  << P.first <<  ,   << P.second <<  ) ;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   template <class T>   istream &operator>>(istream &in, deque<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const deque<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   int f(int x, int y) {     if (x % y == 0) {       return f(x / y, y);     }     return x;   }   int n, k;   int32_t main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int u = 900000;     cin >> n >> k;     vector<int> v(n);     cin >> v;     vector<int> stv = v;     while (u--) {       vector<pair<int, int> > op;       stv = v;       while (v.size() > 1) {         shuffle(v.begin(), v.end(), rng);         pair<int, int> nv;         nv.first = v.back();         int second = v.back();         v.pop_back();         nv.second = v.back();         second += v.back();         v.pop_back();         op.push_back(nv);         v.push_back(f(second, k));       }       if (v[0] == 1) {         cout <<  YES  << endl;         for (auto w : op) {           cout << w.first <<     << w.second << endl;         }         return 0;       }       v = stv;     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long double tp, temp, temp2, div;     vector<long double> v;     map<long double, long long int> mp;     string in;     double storage;     cin >> t;     while (t--) {       cin >> in;       storage = 0;       temp = -1;       temp2 = -1;       for (int a1 = 0; a1 < in.size(); a1++) {         if (isdigit(in[a1])) {           storage *= 10;           storage += in[a1] -  0 ;         } else {           if (storage != 0) {             if (temp == -1) {               temp = storage;               storage = 0;               continue;             } else if (temp2 == -1) {               temp2 = storage;               storage = 0;               continue;             }           }         }       }       div = storage;       tp = (temp + temp2) / div;       v.push_back(tp);       mp[tp]++;     }     for (int a1 = 0; a1 < v.size(); a1++) {       if (a1 != v.size() - 1)         cout << mp[v[a1]] <<    ;       else         cout << mp[v[a1]] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<string, string>>::iterator findit(       vector<pair<string, string>>::iterator st,       vector<pair<string, string>>::iterator en, string s) {     while (st != en) {       if ((*st).second == s) {         return st;       } else {         ++st;       }     }     return en;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int q;     cin >> q;     string old, newi;     long long int i;     vector<pair<string, string>> v;     long long int count = 0;     for (i = 0; i < q; ++i) {       cin >> old >> newi;       vector<pair<string, string>>::iterator it = findit(v.begin(), v.end(), old);       if (it == v.end()) {         v.push_back(make_pair(old, newi));         count++;       } else {         (*it).second = newi;       }     }     cout << count <<   n ;     for (i = 0; i < count; ++i) {       cout << v[i].first <<     << v[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int last = 0;     int ans = 0;     string s =   ;     int l = 0, r = n - 1;     while (1) {       int k = INT_MAX;       if (arr[l] > last) {         k = arr[l];       }       if (arr[r] > last) {         k = min(k, arr[r]);       }       if (k != arr[l] && k != arr[r]) {         break;       }       ans++;       last = k;       if (k == arr[r] && k == arr[l]) {         int c1 = 0, c2 = 0;         for (int i = l + 1; i < r; i++) {           if (arr[i] > arr[i - 1]) {             c1++;           } else {             break;           }         }         c1++;         c2++;         for (int i = r - 1; i > l; i--) {           if (arr[i] > arr[i + 1]) {             c2++;           } else {             break;           }         }         ans += max(c1, c2);         cout << ans - 1 << endl;         cout << s;         if (c1 >= c2) {           for (int i = 0; i < c1; i++) {             cout <<  L ;           }         } else {           for (int i = 0; i < c2; i++) {             cout <<  R ;           }         }         return 0;       } else if (k == arr[r]) {         r--;         s +=  R ;       } else {         l++;         s +=  L ;       }       if (l > r) {         break;       }     }     cout << ans << endl;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     if (c <= b / 2 && c <= a / 2)       cout <<  First ;     else       cout <<  Second ;   }