#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1), eps = 1e-6;   const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};   const int N = 1e6 + 5, M = 2e6 + 5, mod = 1e9 + 7;   int n;   int p[N], c[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n;       bool success = true;       for (int i = 1, d = 0; i <= n; i++) {         cin >> p[i] >> c[i];         if (p[i] < c[i] || p[i] < p[i - 1] || c[i] < c[i - 1] || p[i] - c[i] < d)           success = false;         d = p[i] - c[i];       }       cout << (success ?  YES  :  NO ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 2e5 + 100;   int n, val[maxn];   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , val + i);     set<int> s;     for (int i = 0; i < n; i++) s.insert((((i + val[i]) % n) + n) % n);     puts((s.size() == n) ?  YES  :  NO );   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Timer {     chrono::time_point<chrono::high_resolution_clock> start, end;     chrono::duration<float> dur;     Timer() { start = chrono::high_resolution_clock::now(); }     ~Timer() {       end = chrono::high_resolution_clock::now();       dur = end - start;       cout <<   nTime Elapsed :   << dur.count() <<   s n ;     }   };   long long int sum() { return 0; }   template <typename T, typename... Args>   T sum(T a, Args... args) {     return a + sum(args...);   }   template <int D, typename T>   struct Vec : public vector<Vec<D - 1, T>> {     static_assert(D >= 1,  Vector dimension must be greater than zero! );     template <typename... Args>     Vec(int n = 0, Args... args)         : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}   };   template <typename T>   struct Vec<1, T> : public vector<T> {     Vec(int n = 0, T val = T()) : vector<T>(n, val) {}   };   template <typename T>   class SieveEuler {    public:     vector<T> primes;     vector<T> lp;     inline SieveEuler(int MAX = 1000000) {       lp.resize(MAX + 1, 0);       for (long long int i = 2; i <= MAX; i++) {         if (lp[i] == 0) {           lp[i] = i;           primes.push_back(i);         }         for (int j = 0;              j < primes.size() && i * primes[j] <= MAX && primes[j] <= lp[i];              ++j) {           if (primes[j] == lp[i]) {             lp[i * primes[j]] = primes[j];           } else {             lp[i * primes[j]] = primes[j];           }         }       }     }   };   long long int EulerPhi(long long int n) {     long long int result = n;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   template <typename T>   vector<vector<T>> matmul(const vector<vector<T>>& a,                            const vector<vector<T>>& b) {     int n = a.size(), m = b[0].size(), k = b.size();     vector<vector<T>> c(n, vector<T>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int l = 0; l < k; l++) c[i][j] += (a[i][k] * b[k][j]);       }     }     return c;   }   template <typename T>   bool isPrime(T n) {     if (n <= 1)       return false;     else if (n == 2 || n == 3)       return true;     else if (n % 2 == 0 || n % 3 == 0)       return false;     T x = 5;     T p = 2;     while (x * x <= n) {       if (n % x == 0) return true;       x += p;       p = 6 - p;     }     return true;   }   template <typename T>   class Graph {    public:     struct edge {       int from, to;       T cost;     };     vector<edge> edgeList;     vector<vector<int>> adj;     int n;     Graph(int _n) : n(_n) { adj.resize(n + 1); }     void add(int from, int to) {       adj[to].push_back(from);       adj[from].push_back(to);     }     void solve(int m) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         cnt += (adj[i].size() == 1);       }       cout << setprecision(9) << 2 * ((double)m / cnt) <<   n ;     }   };   bool isSubsequenceString(string x, string y) {     int i = 0, j = 0;     while (i < x.length() && j < y.length()) x[i] == y[j] ? i++, j++ : i++;     return (j == y.length());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int testCases = 1;     while (testCases--) {       int n, m;       cin >> n >> m;       Graph<int> g(n);       for (int i = 1; i <= n - 1; i++) {         int u, v;         cin >> u >> v;         g.add(u, v);       }       g.solve(m);     }   }


#include <bits/stdc++.h>   using namespace std;   int cnt[2][2];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin >> s;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         cnt[i][j] = 0;       }     }     for (int i = 0; i < s.length(); i++) {       cnt[i & 1][s[i] -  a ]++;     }     long long ans = 0;     for (int i = 0; i < 2; i++) {       ans += (long long)cnt[0][i] * cnt[1][i];     }     cout << ans <<    ;     ans = 0;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         ans += (long long)cnt[i][j] * (cnt[i][j] + 1) / 2;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const double pi = 3.14159265358979323846;   const long long mxN = 2e5 + 2;   void _print(long long t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(double t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   vector<long long> adj[27];   long long degree[27];   bool visited[27];   vector<long long> hold;   void dfs(long long src) {     visited[src] = true;     hold.push_back(src);     for (auto edge : adj[src]) {       if (!visited[edge]) dfs(edge);     }   }   void solve() {     string s;     cin >> s;     long long n = s.length();     memset(degree, 0, sizeof(degree));     memset(visited, false, sizeof(visited));     hold.clear();     vector<vector<long long>> hehe(26, vector<long long>(26, 0));     for (long long i = 0; i <= 25; i++) adj[i].clear();     for (long long i = 0; i < n - 1; i++) {       if (s[i] != s[i + 1] && hehe[s[i] -  a ][s[i + 1] -  a ] == 0) {         adj[s[i] -  a ].push_back(s[i + 1] -  a );         adj[s[i + 1] -  a ].push_back(s[i] -  a );         hehe[s[i] -  a ][s[i + 1] -  a ] = 1;         hehe[s[i + 1] -  a ][s[i] -  a ] = 1;         degree[s[i + 1] -  a ]++;         degree[s[i] -  a ]++;       }     }     long long onecount = 0;     long long pos = -1;     if (n == 1) pos = s[0] -  a ;     for (long long i = 0; i <= 25; i++) {       if (degree[i] > 2) {         cout <<  NO n ;         return;       }       if (degree[i] == 1) {         onecount++;         pos = i;       }     }     if (n != 1 && onecount != 2) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     dfs(pos);     for (long long i = 0; i < 26; i++) {       if (!visited[i]) hold.push_back(i);     }     for (auto x : hold) cout << char(x +  a );     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1024;   int size[MAXN], in[MAXN], deg[MAXN];   bitset<MAXN> a[MAXN], c;   vector<pair<int, int> > edges;   set<pair<int, int> > was;   int main() {     int n;     scanf( %d , &n);     bool star = 1;     for (int i = 0; (i) < (n); ++i) {       scanf( %d , &size[i]);       if (size[i] != n) star = 0;       for (int j = 0; (j) < (size[i]); ++j) {         int l;         scanf( %d , &l);         a[i][l - 1] = 1;       }     }     if (star) {       for (int i = 0; (i) < (n - 1); ++i) printf( %d %d n , i + 1, n);       return 0;     }     for (int i = 0; (i) < (n); ++i)       for (int j = (i + 1); (j) < (n); ++j) {         c = a[i] & a[j];         unsigned int *cur = (unsigned int *)&c;         vector<int> v;         for (int g = 0; (g) < (MAXN / 32); ++g) {           if (*cur != 0) {             for (int k = (32) - 1; (k) >= 0; --k)               if (((*cur) >> k) & 1) v.push_back(g * 32 + k);             if ((int)((v).size()) > 2) break;           }           cur++;         }         if ((int)((v).size()) == 2) edges.push_back(make_pair(v[0], v[1]));       }     sort((edges).begin(), (edges).end());     edges.resize(unique((edges).begin(), (edges).end()) - edges.begin());     for (auto edge : edges) {       in[edge.first] = in[edge.second] = 1;       deg[edge.first]++, deg[edge.second]++;       was.insert(make_pair(edge.first, edge.second));       was.insert(make_pair(edge.second, edge.first));     }     for (int i = 0; (i) < (n); ++i)       if (!in[i]) {         int minn = 2 * n, ind = -1;         for (int j = 0; (j) < (n); ++j)           if (a[j][i] == 1 && size[j] < minn) {             minn = min(minn, size[j]);             ind = j;           }         assert(ind != -1);         vector<int> vIn;         for (int j = 0; (j) < (n); ++j)           if (a[ind][j] && in[j]) vIn.push_back(j);         if ((int)((vIn).size()) > 2) {           for (int j = 0; (j) < ((int)((vIn).size())); ++j) {             bool ok = 1;             for (int g = 0; (g) < ((int)((vIn).size())); ++g) {               if (g != j && !was.count(make_pair(vIn[j], vIn[g]))) {                 ok = 0;                 break;               }             }             if (ok) {               edges.push_back(make_pair(vIn[j], i));               break;             }           }         } else {           assert((int)((vIn).size()) == 2);           assert(deg[vIn[0]] == 1 || deg[vIn[1]] == 1);           if (deg[vIn[0]] == 1 && deg[vIn[1]] == 1) {             int ind2 = -1;             for (int j = 0; (j) < (n); ++j)               if (size[j] != n) {                 ind2 = j;                 break;               }             assert(ind != -1);             if (a[ind2] == a[ind])               edges.push_back(make_pair(vIn[0], i));             else               edges.push_back(make_pair(vIn[1], i));           } else {             for (int j = 0; (j) < (2); ++j)               if (deg[vIn[j]] == 1) edges.push_back(make_pair(vIn[j], i));           }         }       }     for (auto edge : edges) printf( %d %d n , edge.first + 1, edge.second + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double PI = acos(-1);   const long long mod = 1e9 + 7;   const long long OO = 2e18;   const int N = 3e5 + 5;   int parent[N];   set<int> st;   set<int>::iterator it1, it2;   int n, m, l, r, x;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) st.insert(i);     st.insert(oo);     while (m--) {       cin >> l >> r >> x;       it1 = st.lower_bound(l);       while (*it1 <= r) {         if (*it1 != x) {           parent[*it1] = x;           it2 = it1;           it1++;           st.erase(it2);         } else           it1++;       }     }     for (int i = 1; i <= n; i++) {       cout << parent[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool dp[1001][1001];   int data[1001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     if (n > m) {       cout <<  YES             <<   n ;       return 0;     } else {       for (int i = 1; i <= n; i++) {         cin >> data[i], data[i] %= m;         if (!data[i]) {           cout <<  YES                 <<   n ;           return 0;         }       }       dp[0][0] = true;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= m; j++) {           dp[i][j] = dp[i - 1][j];           int var = j - data[i];           if (var < 0) var += m;           dp[i][j] |= dp[i - 1][var];         }         if (dp[i][m]) {           cout <<  YES                 <<   n ;           return 0;         }       }     }     cout <<  NO           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   vector<int> edges[N];   vector<int> a;   int n, m;   int main() {     while (cin >> n >> m) {       a.clear();       for (int i = 1; i <= n; ++i) edges[i].clear(), a.push_back(i);       for (int i = 0; i < m; ++i) {         int ac, b;         cin >> ac >> b;         edges[ac].push_back(b);         edges[b].push_back(ac);       }       bool t = true;       int u, v;       for (int i = 0; i < 500; ++i) {         random_shuffle(a.begin(), a.end());         bool flg = true;         for (int j = 0; j < m && flg; ++j) {           u = a[j];           v = a[(j + 1) % n];           for (int k = 0; k < edges[u].size(); ++k)             if (edges[u][k] == v) flg = false;         }         if (flg) {           for (int j = 0; j < m; ++j)             cout << a[j] <<     << a[(j + 1) % n] << endl;           t = false;           break;         }       }       if (t) cout << -1 << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int tot = 0;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       if (tot + a <= 500) {         tot += a;         cout <<  A ;       } else {         tot -= b;         cout <<  G ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());   const int maxn = 2e5 + 10;   const double pi = acos(-1);   int main() {     int cas;     cin >> cas;     double n;     while (cas--) {       cin >> n;       printf( %.10lf n , cos(pi / 4.0 / n) / sin(pi / 2.0 / n));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[1000001];   long long int b[1000001];   bool marked[1000001];   int main() {     long long int n, i, j, k, x, y, fin_ans = 0, sum = 0;     cin >> n >> k;     a[0] = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       fin_ans += a[i - 1] * a[i];     }     fin_ans += a[n] * a[1];     for (i = 0; i < k; i++) {       cin >> x;       b[i] = x;     }     long long val = 0;     for (j = 0; j < k; j++) {       marked[b[j]] = 1;       val += a[b[j]];       long long to_mul = 0;       if (b[j] != 1 && b[j] != n) {         to_mul = sum - val - a[b[j] + 1];         if (!marked[b[j] - 1]) {           to_mul -= a[b[j] - 1];         }       }       if (b[j] == 1) {         to_mul = sum - val - a[b[j] + 1];         to_mul -= a[n];       }       if (b[j] == n) {         to_mul = sum - val;         if (!marked[b[j] - 1]) to_mul -= a[b[j] - 1];         if (!marked[1]) to_mul -= a[1];       }       fin_ans += (a[b[j]] * to_mul);     }     cout << fin_ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> visited;   vector<vector<int>> adj;   vector<int> depth;   void dfs(int v, int d) {     if (visited[v]) {       return;     }     visited[v] = true;     depth[d]++;     for (int i : adj[v]) {       dfs(i, d + 1);     }   }   int main() {     int n;     cin >> n;     visited.resize(n + 1);     adj.resize(n + 1);     for (int i = 2; i <= n; i++) {       int to;       cin >> to;       adj[to].push_back(i);     }     depth.resize(n + 1);     dfs(1, 0);     int collected = 0;     for (int i : depth) {       collected += i % 2;     }     cout << collected << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int P[111111];   int sz[111111];   int find(int x) { return (P[x] == x ? x : P[x] = find(P[x])); }   void Union(int x, int y, int type) {     x = find(x), y = find(y);     if (sz[x] < sz[y]) swap(x, y);     if (x == y) {       if (type == -1) P[x] = 0;       return;     }     if (type == -1) return;     sz[x] += sz[y];     P[y] = x;   }   int main() {     int N, K;     cin >> N >> K;     for (int i = 1; i <= N; i++) P[i] = i, sz[i] = 1;     while (K--) {       int u, v;       cin >> u >> v;       Union(u, v, 1);     }     cin >> K;     while (K--) {       int u, v;       cin >> u >> v;       Union(u, v, -1);     }     int best = 0;     for (int i = 1; i <= N; i++)       if (find(i)) best = max(best, sz[find(i)]);     cout << best << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[5009], n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int cnt = 0;     int ans = 0;     int chk;     bool fs = false;     while (cnt < n) {       fs = false;       for (int i = n - 1; i >= 0; i--) {         if (!fs && arr[i]) {           chk = arr[i];           fs = true;           cnt++;           ans++;           arr[i] = 0;           continue;         }         if (arr[i] < chk && arr[i]) {           cnt++;           chk = arr[i];           arr[i] = 0;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   const long long LLINF = numeric_limits<long long>::max();   const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();   const double PI = acos(-1.0);   int sz = 1;   vector<int> compressed;   vector<pair<int, pair<int, int>>> queries;   map<int, int> order;   vector<int> t;   vector<set<int>> vert;   void build(int n) {     while (sz < n) sz <<= 1;     t.resize(sz + sz, 0);   }   void update(int i) {     i += sz;     if (vert[i - sz].size() == 0)       t[i] = 0;     else       t[i] = *vert[i - sz].rbegin();     while ((i >> 1) > 0) {       i >>= 1;       t[i] = max(t[i + i], t[i + i + 1]);     }   }   int query(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (tl == l && tr == r) return t[v];     int tm = (tl + tr) >> 1;     return max(query(v + v, tl, tm, l, min(r, tm)),                query(v + v + 1, tm + 1, tr, max(tm + 1, l), r));   }   int getX(int v, int tl, int tr, int l, int y) {     if (t[v] <= y) return INF;     if (tr <= l) return INF;     if (tl == tr) return tl;     int mid = (tl + tr) >> 1;     if (tl > l) {       if (t[v + v] > y)         return getX(v + v, tl, mid, l, y);       else         return getX(v + v + 1, mid + 1, tr, l, y);     }     return min(getX(v + v, tl, mid, l, y), getX(v + v + 1, mid + 1, tr, l, y));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     queries.resize(n);     set<int> d;     for (int i = 0; i < n; i++) {       string type;       cin >> type;       if (type ==  add )         queries[i].first = 0;       else if (type ==  remove )         queries[i].first = 1;       else         queries[i].first = 2;       cin >> queries[i].second.first >> queries[i].second.second;       queries[i].second.first, queries[i].second.second;       d.insert(queries[i].second.first);     }     for (auto k : d) {       order[k] = compressed.size();       compressed.push_back(k);     }     build(compressed.size());     vert.resize(compressed.size());     for (auto q : queries) {       if (q.first == 0) {         vert[order[q.second.first]].insert(q.second.second);         update(order[q.second.first]);       } else if (q.first == 1) {         vert[order[q.second.first]].erase(q.second.second);         update(order[q.second.first]);       } else {         int ans = getX(1, 0, sz - 1, order[q.second.first], q.second.second);         if (ans == INF)           cout <<  -1 n ;         else {           int y = *vert[ans].upper_bound(q.second.second);           cout << compressed[ans] <<     << y <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   const int OO = (int)1e9 + 7;   const int MAX = 109;   char c1, c2, c3;   string s1, s2, s3;   long long n, m, k, t, a, b, c, d, e, f, x, y, z, sol = 0, ans = 0;   long long ar[1000009];   map<long long, bool> vis;   int fun(int i) {     int ret = 0;     for (int i = 0; i < n; i++) {       if (ar[i] % m == 0 && vis[ar[i] / m]) continue;       vis[ar[i]] = 1;       ret++;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n);     cout << fun(0);     cout <<   n n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... Ts>   void do_nothing(Ts &&...vals) {}   constexpr long long MOD = 1000000007;   constexpr int INF = 0x7f7f7f7f;   constexpr double EPS = 1e-8;   long long fastPow(long long num, long long exp, long long modNum) {     if (exp == 0) return 1;     if (exp == 1)       return num;     else {       long long half = fastPow(num, exp / 2, modNum) % modNum;       if (exp % 2 == 1) {         return (((half * half) % modNum) * num) % modNum;       } else {         return (half * half) % modNum;       }     }   }   long long fastPow(long long num, long long exp) {     if (exp == 0) return 1;     if (exp == 1)       return num;     else {       long long half = fastPow(num, exp / 2);       if (exp % 2 == 1) {         return (((half * half)) * num);       } else {         return (half * half);       }     }   }   long long getReverse(long long y, long long modNum) {     return fastPow(y, modNum - 2, modNum) % modNum;   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     return (a % b == 0) ? b : gcd(b, a % b);   }   int main(int argn, char **argv) {     ios::sync_with_stdio(false);     cout.tie(nullptr);     cin.tie(nullptr);     const long long MOD = 1e9 + 7;     int T = 1;     cin >> T;     for (int(I) = (0); (I) <= ((T)-1); (I)++) {       long long n, x, y;       cin >> n >> x >> y;       vector<long long> arr(n);       vector<stack<long long>> places(n + 2);       for (int(i) = (0); (i) <= ((n)-1); (i)++) {         cin >> arr[i];         places[arr[i]].emplace(i);       }       priority_queue<pair<long long, long long>> pq;       long long except;       for (int(i) = (1); (i) <= (n + 1); (i)++) {         if (places[i].size() == 0) {           except = i;         } else {           pq.emplace(places[i].size(), i);         }       }       vector<long long> ans(n, 0);       for (int(i) = (0); (i) <= ((x)-1); (i)++) {         auto pa = pq.top();         pq.pop();         long long idx = places[pa.second].top();         places[pa.second].pop();         ans[idx] = pa.second;         pq.emplace(places[pa.second].size(), pa.second);       }       y -= x;       vector<long long> pos, val;       if (!pq.empty()) {         auto pa = pq.top();         pq.pop();         for (int(i) = (0); (i) <= ((pa.first) - 1); (i)++) {           val.emplace_back(pa.second);         }         while (!pq.empty()) {           auto next = pq.top();           pq.pop();           for (int(i) = (0); (i) <= ((next.first) - 1); (i)++) {             pos.emplace_back(places[next.second].top());             places[next.second].pop();             val.emplace_back(next.second);           }         }         for (int(i) = (0); (i) <= ((pa.first) - 1); (i)++) {           pos.emplace_back(places[pa.second].top());           places[pa.second].pop();         }       }       long long excount = n - x - y, id = 0;       while (y > 0) {         ans[pos[id]] = val[id];         if (ans[pos[id]] == arr[pos[id]]) {           if (excount > 0) {             excount--;             ans[pos[id]] = 0;           } else {             break;           }         } else {           y--;         }         id++;       }       if (y > 0) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       for (int(i) = (0); (i) <= ((n)-1); (i)++) {         if (ans[i] != 0) {           cout << ans[i] <<    ;         } else {           cout << except <<    ;         }       }       cout << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int a[110];   long long calc(long long first) {     if (first == 0) return 0;     int nn = 0;     while (first) {       a[nn++] = first % 2;       first /= 2;     }     reverse(a, a + nn);     int r = 0, ans = 0;     for (int i = 0; i < nn; i++)       if (!a[i]) r++;     if (r == 1) ans++;     r = 0;     a[nn] = 0;     for (int i = 0; i <= nn; i++)       if (a[i] == 0) {         r = i;         break;       }     ans += r - 1;     for (int i = 1; i < nn - 1; i++) ans += i;     return ans;   }   int main() {     long long first, second;     scanf( %I64d %I64d , &first, &second);     printf( %I64d n , calc(second) - calc(first - 1));   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[123490];   bool attacked[123490], visited[123490];   int n, m, parent[123490];   int dist, last;   void dfs(int u, int depth) {     if (attacked[u]) {       if (dist < depth) {         dist = depth;         last = u;       } else {         if (dist == depth) {           last = min(last, u);         }       }     }     visited[u] = true;     for (int i = (int)0; i <= (int)graph[u].size() - 1; i++) {       int v = graph[u][i];       if (!visited[v]) {         parent[v] = u;         dfs(v, depth + 1);       }     }   }   vector<int> path;   void augment_path(int v) {     visited[v] = true;     path.push_back(v);     if (parent[v] == -1) return;     augment_path(parent[v]);   }   int all = 0;   bool dfs2(int u) {     visited[u] = true;     int ans = 0;     for (int i = (int)0; i <= (int)graph[u].size() - 1; i++) {       int v = graph[u][i];       if (!visited[v]) {         ans |= dfs2(v);       }     }     if (attacked[u]) ans = 1;     all += ans;     return ans;   }   int main() {     cin >> n >> m;     int u, v;     for (int i = (int)1; i <= (int)n - 1; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     int tmp = 123490;     for (int i = (int)1; i <= (int)m; i++) {       cin >> u;       attacked[u] = true;       tmp = min(tmp, u);     }     dist = -1;     dfs(tmp, 0);     tmp = last;     memset(parent, -1, sizeof parent);     memset(visited, 0, sizeof visited);     dist = -1;     dfs(last, 0);     cout << min(tmp, last) << endl;     memset(visited, 0, sizeof visited);     dfs2(tmp);     cout << (all * 2) - 2 - dist << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[N], b[N], par[N], val[N], sz[N], lst[N];   vector<int> his;   pair<int, int> get(int v) {     if (par[v] == v) return make_pair(v, val[v]);     pair<int, int> g = get(par[v]);     g.second ^= val[v];     return g;   }   bool merge(int u, int v) {     pair<int, int> gu = get(u), gv = get(v);     u = gu.first;     v = gv.first;     if (u == v) return false;     if (sz[v] < sz[u]) swap(u, v), swap(gu, gv);     par[u] = v;     val[u] = gu.second ^ gv.second ^ 1;     sz[v] += sz[u];     his.push_back(u);     return true;   }   void undo(int cnt) {     while (cnt--) {       int u = his.back();       his.pop_back();       sz[par[u]] -= sz[u];       par[u] = u;       val[u] = 0;     }   }   void solve(int l, int r, int R) {     if (r < l) return;     int m = (l + r) >> 1, cnt = 0;     for (int i = l; i < m; i++)       if (merge(a[i], b[i])) cnt++;     if (l < r) {       bool f = merge(a[m], b[m]);       solve(m + 1, r, R);       if (f) undo(1);     }     lst[m] = m;     for (int i = R; i >= m; i--) {       if (get(a[i]) == get(b[i])) {         lst[m] = i;         break;       }       if (merge(a[i], b[i])) cnt++;     }     undo(cnt);     cnt = 0;     for (int i = R; i > lst[m]; i--)       if (merge(a[i], b[i])) cnt++;     solve(l, m - 1, lst[m]);     undo(cnt);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], lst[i] = m + 1;     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     int ptr = 1;     while (ptr <= m && get(a[ptr]) != get(b[ptr])) merge(a[ptr], b[ptr]), ptr++;     if (m < ptr) {       while (q--) cout <<  NO n ;       return 0;     }     undo(his.size());     solve(1, ptr, m);     while (q--) {       int l, r;       cin >> l >> r;       cout << (ptr < l || r < lst[l] ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005];   vector<int> all, empty;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       (x *= 10) += ch -  0 ;       ch = getchar();     }     return x * f;   }   vector<int> solve(int x) {     if (x > 19) return empty;     bool flag = false;     for (int v : all)       if (v & 1) {         flag = true;         break;       }     if (!flag) {       for (int &v : all) v >>= 1;       return solve(x + 1);     }     vector<int> backup, nega, posi, res;     backup = all;     for (int &v : all) {       if (v & 1)         v = (v + 1) >> 1;       else         v = v >> 1;     }     {       sort(all.begin(), all.end());       all.erase(unique(all.begin(), all.end()), all.end());     };     nega = solve(x + 1);     all = backup;     for (int &v : all) {       if (v & 1)         v = (v - 1) >> 1;       else         v = v >> 1;     }     {       sort(all.begin(), all.end());       all.erase(unique(all.begin(), all.end()), all.end());     };     posi = solve(x + 1);     nega.push_back(-(1 << x)), posi.push_back(1 << x);     return nega.size() < posi.size() ? nega : posi;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) all.push_back(read());     vector<int> res = solve(0);     sort(res.begin(), res.end());     printf( %lld n , res.size());     for (int v : res) printf( %d  , v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> g[100005];   vector<pair<long long int, long long int> > ed;   vector<long long int> w;   vector<long long int> eff;   long long int vis[100005];   long long int val[100005];   long long int rec(long long int i) {     if (vis[i] != 1) {       vis[i] = 1;       long long int cur = 1, j;       for (j = 0; j < g[i].size(); ++j) {         cur += rec(g[i][j]);       }       val[i] = cur;       return cur;     } else       return 0;   }   int main() {     long long int n, i, y, r, c;     cin >> n;     for (i = 0; i < n - 1; ++i) {       long long int t1, t2, t3;       cin >> t1 >> t2 >> t3;       g[t1].push_back(t2);       g[t2].push_back(t1);       ed.push_back(make_pair(t1, t2));       w.push_back(t3);     }     rec(1);     for (i = 0; i < n - 1; ++i) {       long long int ef = 0;       if (val[ed[i].first] > val[ed[i].second]) {         ef = val[ed[i].second] * (n - val[ed[i].second]);       } else {         ef = val[ed[i].first] * (n - val[ed[i].first]);       }       eff.push_back(ef);     }     double ans = 0;     for (i = 0; i < eff.size(); ++i) {       ans = ans + (eff[i] * (double)w[i]);     }     cin >> y;     for (i = 0; i < y; ++i) {       cin >> r >> c;       ans = ans - (eff[r - 1] * (double)(w[r - 1] - (double)c));       w[r - 1] = c;       printf( %0.8lf n , ans * ((n - 2) * 6) / (n * (n - 1) * (n - 2)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, a, b, t;   long long q[55][55];   long long g[55][55];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> q[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> g[i][j];         if (g[i][j] < q[i][j]) swap(g[i][j], q[i][j]);         if (q[i][j] <= q[i - 1][j] || q[i][j] <= q[i][j - 1]) t = 1;         if (g[i][j] <= g[i - 1][j] || g[i][j] <= g[i][j - 1]) t = 1;       }     if (t == 1)       cout <<  Impossible ;     else       cout <<  Possible ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, parent[2005] = {};   int ans = -1e9;   int solve(int x, int byk) {     byk += 1;     if (parent[x] == -1) return byk;     return solve(parent[x], byk);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> parent[i];     }     for (int i = 1; i <= n; i++) {       ans = max(ans, solve(i, 0));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   vector<long long> adj[200005];   void solve() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     vector<long long> cnt(n + 1);     vector<long long> a(n + 1);     queue<long long> q;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       if (!a[i]) q.push(i);     }     vector<long long> ans;     vector<long long> vis(n + 1);     while (!q.empty()) {       long long p = q.front();       q.pop();       cnt[p]++;       ans.push_back(p);       for (auto x : adj[p]) {         cnt[x]++;         if (cnt[x] == a[x]) q.push(x);       }     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     for (long long i = 0; i < t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       for (int i = n - 1; i >= 0; i--) cout << arr[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l[100005], r[100005];   signed main() {     scanf( %lld , &n);     long long ans = 0;     for (register long long i = 1; i <= n; i++) {       scanf( %lld%lld , &l[i], &r[i]);     }     sort(l + 1, l + n + 1);     sort(r + 1, r + n + 1);     for (register long long i = 1; i <= n; i++) {       ans += max(l[i], r[i]);     }     ans += n;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   int n, nxt[MAX], a[MAX];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     for (int l = 0; l < n; l++) {       for (int i = n - 2, j = n - 1; i >= 0; i--) {         while (i < j - a[j]) j--;         nxt[i] = j;       }       for (int i = 0; i < n - 1; i = nxt[i]) ans++;       rotate(a, a + n - 1, a + n);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return (long long)(x * x); }   long long my_abs(long long x) {     if (x < 0) return -x;     return x;   }   const int MN = 1000 * 1000 * 10;   int main() {     long long ans = 0;     long long n, m;     cin >> n >> m;     for (long long b = 1; b <= n; b++) {       long long mx_c = min(b * b, m);       long long tmp_ans = 2ll * (long long)(mx_c);       long long up = (long long)sqrt(sqr(b) - 1.0);       long long down = (long long)ceil(sqrt((double)(sqr(b) - (long long)mx_c)));       if (down > up) {         ans += tmp_ans;         continue;       }       tmp_ans -= 2ll * (up - down + 1ll);       ans += tmp_ans;     }     for (int x = -MN; x <= -1; x++) {       int tmp1, tmp2;       if (abs(x) % 2 == 0) {         tmp1 = abs(x - 2) / 2;         tmp2 = abs(x * 2);       } else {         tmp1 = abs(x - 1) / 2;         tmp2 = abs(x);       }       if (tmp1 <= n && tmp2 <= m) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int MOD = 1e6 + 3;   int main() {     int n, m;     scanf( %d%d , &n, &m);     char s[n][m + 1];     for (int i = (0); i < (int)(n); i++) scanf( %s , s[i]);     bool c[m][2];     bool r[n][2];     memset(c, 0, sizeof(c)), memset(r, 0, sizeof(r));     for (int i = (0); i < (int)(n); i++) {       for (int j = (0); j < (int)(m); j++) {         if (isdigit(s[i][j])) {           int first = s[i][j] -  1 ;           int R = (first / 2 + j) % 2;           int C = ((first + 1) % 4 / 2 + i) % 2;           r[i][R] = 1;           c[j][C] = 1;         }       }     }     int ans = 1;     for (int i = (0); i < (int)(m); i++) {       if (c[i][0] && c[i][1])         ans = 0;       else if (!c[i][0] && !c[i][1])         ans = ans * 2 % MOD;     }     for (int i = (0); i < (int)(n); i++) {       if (r[i][0] && r[i][1])         ans = 0;       else if (!r[i][0] && !r[i][1])         ans = ans * 2 % MOD;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   struct node {     long long x, y, sum;   } st[1200005];   int n, q, type, L, R, a[300005];   long long f[300005];   void build(int id, int l, int r) {     if (l == r) {       st[id].sum = a[l];       return;     }     int mid = l + r >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);     st[id].sum = (st[id << 1].sum + st[id << 1 | 1].sum) % mod;   }   void push(int id, int l, int r) {     if (st[id].x == 0 && st[id].y == 0) return;     int mid = l + r >> 1, pos = mid - l + 2;     long long x = st[id].x, y = st[id].y;     st[id << 1].x = (st[id << 1].x + x) % mod;     st[id << 1].y = (st[id << 1].y + y) % mod;     st[id << 1].sum =         (st[id << 1].sum + x * f[mid - l + 1] + y * (f[mid - l + 2] - 1)) % mod;     st[id << 1 | 1].x =         (st[id << 1 | 1].x + x * f[pos - 2] + y * f[pos - 1]) % mod;     st[id << 1 | 1].y = (st[id << 1 | 1].y + x * f[pos - 1] + y * f[pos]) % mod;     st[id << 1 | 1].sum =         (st[id << 1 | 1].sum + x * f[r - l + 1] + y * (f[r - l + 2] - 1) -          x * f[mid - l + 1] - y * (f[mid - l + 2] - 1) + mod) %         mod;     st[id].x = st[id].y = 0;   }   void update(int id, int l, int r, int u, int v) {     if (l > v or r < u) return;     if (u <= l && r <= v) {       st[id].x = (st[id].x + f[l - u + 1]) % mod;       st[id].y = (st[id].y + f[l - u + 2]) % mod;       st[id].sum = (st[id].sum + f[l - u + 1] * f[r - l + 1] % mod +                     f[l - u + 2] * (f[r - l + 2] - 1)) %                    mod;       return;     }     push(id, l, r);     int mid = l + r >> 1;     update(id << 1, l, mid, u, v);     update(id << 1 | 1, mid + 1, r, u, v);     st[id].sum = (st[id << 1].sum + st[id << 1 | 1].sum) % mod;   }   long long query(int id, int l, int r, int u, int v) {     if (l > v or r < u) return 0;     if (u <= l && r <= v) return st[id].sum;     push(id, l, r);     int mid = l + r >> 1;     return (query(id << 1, l, mid, u, v) + query(id << 1 | 1, mid + 1, r, u, v)) %            mod;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     f[1] = 1;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (i > 1) f[i] = (f[i - 1] + f[i - 2]) % mod;     }     f[n + 1] = (f[n] + f[n - 1]) % mod;     build(1, 1, n);     while (q--) {       cin >> type >> L >> R;       if (type == 1)         update(1, 1, n, L, R);       else         cout << (query(1, 1, n, L, R) + mod) % mod << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string makeCentered(int len) {     string output;     for (int i = 0; i < 27; i++) {       output.push_back( . );     }     for (int i = 0; i < len; i++) {       output[13 + i] =  X ;       output[13 - i] =  X ;     }     return output;   }   string blank() {     string output;     for (int i = 0; i < 27; i++) {       output.push_back( . );     }     return output;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string input;     cin >> input;     vector<int> target;     for (int i = 0; i < input.size(); i++) {       target.push_back(int(input[i]));     }     vector<string> output;     int val = 0;     for (int i = 0; i < target.size(); i++) {       int curTarget = target[i];       vector<int> triSizes;       int distance = curTarget - val;       if (i != 0) distance = val - curTarget;       while (distance < 0) distance += 256;       while (distance > 0) {         if (i == 0) {           for (int j = 12; j >= (i == 0 ? 1 : 2); j--) {             int next;             if (i != 0)               next = j * j - 1;             else               next = j * j;             if (next <= distance) {               for (int k = 1; k <= j + 1; k++) {                 cout << makeCentered(k) << endl;               }               distance -= next;               val += next;               val %= 256;               cout << blank() << endl;               break;             }           }         } else {           cout << makeCentered(1) << endl;           cout << blank() << endl;           distance -= 1;           val -= 1;           if (val < 0) val += 256;         }       }       cout << blank() << endl;       string curString = blank();       curString[0] =  X ;       curString[curString.size() - 1] =  X ;       cout << curString << endl;       curString[curString.size() - 1] =  . ;       cout << curString << endl;       cout << blank() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int INF = 0x3f3f3f3f;   int n, lm, rm;   int q[N], fa[N], sz[N];   bool use[N];   vector<pair<int, int> > g[N];   int getc(int u) {     int qn = 0;     fa[q[qn++] = u] = u;     for (int i = 0; i < qn; i++) {       u = q[i];       sz[u] = 1;       for (int j = 0; j < g[u].size(); j++) {         int v = g[u][j].first;         if (use[v] || v == fa[u]) continue;         fa[q[qn++] = v] = u;       }     }     for (int i = qn - 1; i >= 0; i--) {       int u = q[i];       if (sz[u] * 2 > qn) return u;       sz[fa[u]] += sz[u];     }   }   int dep[N];   void dfs(int u, int p) {     dep[u] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first;       if (v == p || use[v]) continue;       dfs(v, u);       dep[u] = max(dep[u], dep[v] + 1);     }   }   bool cmp(pair<int, int> a, pair<int, int> b) {     return dep[a.first] < dep[b.first];   }   int Maxc;   pair<int, int> f[N], ff[N];   int Q[N];   void dfs(int u, int p, int d, int val, int mid) {     f[d] = max(f[d], make_pair(val, u));     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first;       int w = g[u][i].second;       if (v == p || use[v]) continue;       dfs(v, u, d + 1, val + (w >= mid ? 1 : -1), mid);     }   }   pair<int, int> tmp;   bool judge(int u, int mid) {     int pre = 0;     for (int i = 0; i <= dep[u]; i++) ff[i] = make_pair(-INF, 0);     ff[0] = make_pair(0, u);     int ed = 0;     for (int ii = 0; ii < g[u].size(); ii++) {       int v = g[u][ii].first;       int w = g[u][ii].second;       if (use[v]) continue;       for (int i = 0; i <= dep[v]; i++) f[i] = make_pair(-INF, 0);       dfs(v, u, 1, w >= mid ? 1 : -1, mid);       int head = 0, rear = 0;       for (int i = 0; i <= dep[v]; i++) {         while (ed >= 0 && i + ed >= lm) {           while (head < rear && ff[Q[rear - 1]] < ff[ed]) rear--;           Q[rear++] = ed--;         }         while (head < rear && Q[head] + i > rm) head++;         if (head < rear && ff[Q[head]].first + f[i].first >= 0) {           tmp = make_pair(ff[Q[head]].second, f[i].second);           return true;         }       }       for (int i = 0; i <= dep[v]; i++) ff[i] = max(f[i], ff[i]);       ed = dep[v];     }     return false;   }   int ans = -1;   pair<int, int> an;   void cal(int u) {     dfs(u, u);     sort(g[u].begin(), g[u].end(), cmp);     int l = ans, r = Maxc;     while (l < r) {       int mid = (l + r) >> 1;       if (judge(u, mid))         l = mid + 1;       else         r = mid;     }     judge(u, l - 1);     if (ans < l - 1) {       ans = l - 1;       an = tmp;     }   }   void go(int c) {     int rt = getc(c);     use[rt] = true;     cal(rt);     for (int i = 0; i < g[rt].size(); i++) {       int v = g[rt][i].first;       if (use[v]) continue;       go(v);     }   }   int main() {     scanf( %d%d%d , &n, &lm, &rm);     int u, v, w;     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d%d , &u, &v, &w);       Maxc = max(Maxc, w + 1);       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));     }     go(1);     printf( %d %d n , an.first, an.second);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m;     double resn, resm;     scanf( %d%d , &n, &m);     resn = m / (double)n;     resm = log(m) / log(n);     if (resn > resm) {       printf( > n );     } else if (resn < resm) {       printf( < n );     } else       printf( = n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       a[i] = a[i - 1] + arr[i - 1];     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--;       cout << (a[r] - a[l]) / 10 << endl;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 700 + 7;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   int a[maxn];   int g[maxn][maxn];   int n;   struct as {     int l, r, v;     bool operator<(const as& b) const {       if (l < b.l) return true;       if (l > b.l) return false;       if (r < b.r) return true;       if (r > b.r) return false;       return v < b.v;     }   };   map<as, bool> mp;   int gcd(int x, int y) { return x == 0 ? y : gcd(y % x, x); }   void get() {     int i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= n; j++) {         if (i != j && gcd(a[i], a[j]) != 1) {           g[i][j] = 1;         }       }     }     return;   }   bool solve(int l, int r, int pos) {     if (l > r) return true;     if (mp.count(as{l, r, pos})) {       return mp[as{l, r, pos}];     }     int i, j;     for (i = l; i <= r; i++) {       if (g[pos][i]) {         if (solve(l, i - 1, i) && solve(i + 1, r, i)) {           mp[as{l, r, pos}] = true;           return true;         }       }     }     mp[as{l, r, pos}] = false;     return false;   }   int main() {     int i, j, m, t, z;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     get();     if (solve(1, n, 0)) {       puts( Yes );     } else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005], b[1000005];   int main() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[x]++;     }     for (int i = 1000000; i >= 1; i--) {       if (!a[i]) continue;       b[i] = 1;       for (int j = 2 * i; j <= 1000000; j += i) {         if (a[j] && b[i] < b[j] + 1) b[i] = b[j] + 1;       }       if (ans < b[i]) ans = b[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, vx, vy;   int refx, refy;   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long res = exgcd(b, a % b, y, x);     y -= (a / b) * x;     return res;   }   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &x, &y, &vx, &vy);     if (vx == 0) {       if (x == 0 || x == n) {         if (vy == 1)           printf( %d %d n , x, m);         else           printf( %d %d n , x, 0);       } else         puts( -1 );       return 0;     }     if (vy == 0) {       if (y == 0 || y == m) {         if (vx == 1)           printf( %d %d n , n, y);         else           printf( %d %d n , 0, y);       } else         puts( -1 );       return 0;     }     if (vx == -1) refx = 1, x = n - x;     if (vy == -1) refy = 1, y = m - y;     long long a, b, g;     g = exgcd(n, m, a, b);     if ((x - y) % g != 0) {       puts( -1 );       return 0;     }     long long t = (x - y) / g;     a *= t, b *= t;     int _m = m / g, _n = n / g;     long long _a = (a % _m + _m + _m - 1) % _m + 1, _b = -((x - y) - _a * n) / m;     long long ansx = n, ansy = m;     if (_a % 2 == 0) ansx = n - ansx;     if (_b % 2 == 0) ansy = m - ansy;     if (refx) ansx = n - ansx;     if (refy) ansy = m - ansy;     printf( %I64d %I64d , ansx, ansy);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const int sz = 1e5 + 3, inf = 1e9 + 10;   int a[sz], match[sz], c[sz];   int fr[sz];   bool vis[sz];   long long int x[sz];   void solve() {     memset(vis, 1, sizeof vis);     memset(match, 0, sizeof match);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       for (int j = 0; j < k; j++) cin >> a[j];       for (int j = 0; j < k; j++) {         if (vis[a[j]]) {           vis[a[j]] = 0;           match[i] = a[j];           break;         }       }     }     bool f = 0;     for (int i = 1; i <= n; i++) {       if (match[i]) continue;       for (int j = 1; j <= n; j++) {         if (vis[j]) {           cout <<  IMPROVE n ;           cout << i <<     << j <<   n ;           f = 1;           break;         }       }       if (f) break;     }     if (!f) cout <<  OPTIMAL n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 123;   long long a[maxn], b[maxn], n, m;   char s[maxn];   long long vis[20], t[20], sb[maxn];   void dfs(long long stp, long long sa) {     if (sa > sb[stp + 1]) return;     if (stp == 0) {       cout << sa << endl;       exit(0);     }     if (stp > n) {       dfs(stp - 1, sa);       return;     }     for (long long i = 9; i >= 0; i--)       if (vis[i] && sa * 10 + i <= sb[stp]) {         --vis[i];         dfs(stp - 1, sa * 10 + i);         ++vis[i];       }   }   int main() {     long long i;     scanf( %s , s + 1);     n = strlen(s + 1);     for (i = 1; i <= n; i++) a[i] = s[n - i + 1] -  0 ;     scanf( %s , s + 1);     m = strlen(s + 1);     for (i = 1; i <= m; i++) b[i] = s[m - i + 1] -  0 ;     for (i = m; i; i--) sb[i] = sb[i + 1] * 10 + b[i];     for (i = 1; i <= n; i++) ++vis[a[i]];     dfs(m, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, l[N], r[N], id[N];   bool cmp(int x, int y) { return r[x] == r[y] ? l[x] < l[y] : r[x] < r[y]; }   int main() {     cin >> n;     for (int x, w, i = 1; i <= n; ++i) {       cin >> x >> w;       l[i] = x - w, r[i] = x + w, id[i] = i;     }     sort(id + 1, id + n + 1, cmp);     int ans = 0, las = -2e9;     for (int i = 1; i <= n; ++i)       if (las <= l[id[i]]) ++ans, las = r[id[i]];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 110, VMAX = 1000100;   int T, N;   int number[NMAX], diff[NMAX * NMAX];   int b[NMAX];   bool val[VMAX];   int main() {     int i, j, k, t;     bool flag;     scanf( %d , &T);     for (t = 0; t < T; t += 1) {       memset(val, 0, sizeof(val));       memset(diff, 0, sizeof(diff));       flag = true;       scanf( %d , &N);       for (i = 1; i <= N; i += 1) {         scanf( %d , &number[i]);         if (val[number[i]]) flag = false;         val[number[i]] = true;       }       sort(number + 1, number + N + 1);       if (!flag)         printf( NO n );       else if (N == 1)         printf( YES n1 n );       else {         for (i = 1; i <= N; i += 1) {           for (j = i + 1; j <= N; j += 1) diff[++diff[0]] = number[j] - number[i];         }         memset(val, 0, sizeof(val));         sort(diff + 1, diff + diff[0] + 1);         diff[0] = unique(diff + 1, diff + diff[0] + 1) - diff - 1;         printf( YES n );         for (i = 1; i <= N; i += 1) {           for (j = b[i - 1] + 1; val[j]; j += 1)             ;           b[i] = j;           printf( %d%c , b[i],    n [i == N ? 1 : 0]);           for (k = 1; k <= diff[0]; k += 1) val[diff[k] + b[i]] = true;         }       }     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long bin_pow(long long a, long long b) {     if (b == 0) {       return 1;     }     long long res = bin_pow(a, b / 2);     res *= res;     res %= mod;     if (b % 2) {       res *= a;       res %= mod;     }     return res;   }   long long inv(long long x) { return bin_pow(x, mod - 2); }   int32_t main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     n *= 2;     vector<long long> a(n);     for (long long i = 0; i < (long long)(n); i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     long long ans = 0;     n /= 2;     for (long long i = 0; i < (long long)(n); i++) {       ans -= a[i];     }     for (long long i = 0; i < (long long)(n); i++) {       ans += a[i + n];     }     ans %= mod;     for (long long i = 0; i < (long long)(n); i++) {       ans *= n + 1 + i;       ans %= mod;     }     for (long long i = 0; i < (long long)(n); i++) {       ans *= inv(i + 1);       ans %= mod;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   int main(int argc, char const *argv[]) {     int n, i;     scanf( %d , &n);     getchar();     char row[n];     for (i = 0; i < n; ++i) {       row[i] = getchar();     }     if (n == 1 && row[0] ==  0 ) {       printf( No n );       return 0;     }     for (i = 1; i < n; ++i) {       if (row[i] ==  1  && row[i - 1] ==  1 ) {         printf( No n );         return 0;       }     }     int cantCero = 0;     if (row[0] ==  0 ) {       cantCero++;     }     for (i = 1; i < n; ++i) {       if (row[i] ==  0 ) {         if (row[i - 1] ==  0 ) {           cantCero++;         } else {           cantCero = 1;         }         if (cantCero == 2 && (i == 1 || i == n - 1)) {           printf( No n );           return 0;         }         if (cantCero == 3) {           printf( No n );           return 0;         }       } else {         cantCero = 0;       }     }     printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   template <typename T1, typename T2>   inline void chkmin(T1& x, const T2& y) {     if (y < x) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1& x, const T2& y) {     if (x < y) x = y;   }   const int N = 1e5 + 10;   const int B = 300;   struct Node {     int next_node;     int prev_node;     int jump;   };   int n, q;   Node nodes[N];   bool used[N];   int find_jump(int v) {     for (int i = 0; i < B; ++i) {       v = nodes[v].next_node;     }     return v;   }   void build() {     for (int i = 0; i < n; ++i) {       if (used[i]) continue;       int v = i;       int jump = find_jump(i);       while (!used[v]) {         used[v] = true;         nodes[v].jump = jump;         v = nodes[v].next_node;         jump = nodes[jump].next_node;       }     }   }   void relax_jumps(int v) {     int jump = v;     for (int i = 0; i < B; ++i) {       v = nodes[v].prev_node;     }     for (int i = 0; i <= B; ++i) {       nodes[v].jump = jump;       v = nodes[v].next_node;       jump = nodes[jump].next_node;     }   }   void upd(int i, int j) {     int next_i = nodes[i].next_node;     int next_j = nodes[j].next_node;     nodes[i].next_node = next_j;     nodes[j].next_node = next_i;     nodes[next_i].prev_node = j;     nodes[next_j].prev_node = i;     relax_jumps(i);     relax_jumps(j);   }   int getAns(int v, int k) {     while (k) {       if (k >= B) {         v = nodes[v].jump;         k -= B;       } else {         v = nodes[v].next_node;         --k;       }     }     return v;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout.precision(20), cout.setf(ios::fixed);     cin >> n >> q;     for (int i = 0; i < n; ++i) {       cin >> nodes[i].next_node;       --nodes[i].next_node;       nodes[nodes[i].next_node].prev_node = i;     }     build();     while (q--) {       int t;       cin >> t;       if (t == 1) {         int i, j;         cin >> i >> j;         --i;         --j;         upd(i, j);       } else if (t == 2) {         int v, k;         cin >> v >> k;         --v;         cout << getAns(v, k) + 1 <<   n ;       } else {         assert(false);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100 + 10;   pair<int, int> d[MAX];   int main() {     int i;     set<int> first, second;     for ((i) = (1); (i) <= (8); ++(i)) {       scanf( %d%d , &d[i].first, &d[i].second);       first.insert(d[i].first);       second.insert(d[i].second);     }     if (first.size() != 3 || second.size() != 3) {       cout <<  ugly  << endl;       return 0;     }     set<int>::iterator a, b;     for ((a) = (first.begin()); (a) != (first.end()); ++(a))       for ((b) = (second.begin()); (b) != (second.end()); ++(b)) {         int flag = 0;         for ((i) = (1); (i) <= (8); ++(i))           if (d[i].first == *a && d[i].second == *b) {             flag = 1;             break;           }         if (a == ++first.begin() && b == ++second.begin()) {           if (flag) {             cout <<  ugly  << endl;             return 0;           }         } else if (!flag) {           cout <<  ugly  << endl;           return 0;         }       }     cout <<  respectable  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long inf = 1e18 + 10;   long long dis[N], sid[N], mark[N], h[N], dp[N], c[N];   pair<pair<long long, long long>, long long> E[N];   vector<pair<long long, long long> > adj[N], jda[N], g[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       pq;   void dfs(long long v, long long id) {     mark[v] = 1;     dp[v] = inf;     for (pair<long long, long long> e : g[v]) {       long long u = e.first, ind = e.second;       if (ind == id) continue;       if (mark[u]) {         dp[v] = min(dp[v], h[u]);       } else {         h[u] = h[v] + 1;         dfs(u, ind);         dp[v] = min(dp[v], dp[u]);         if (h[v] < dp[u]) c[ind] = 1;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, s, t;     cin >> n >> m >> s >> t;     for (int i = 0; i < m; i++) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back({v, w});       jda[v].push_back({u, w});       E[i] = {{u, v}, w};     }     fill(dis, dis + N, inf);     dis[s] = 0;     pq.push({0, s});     while (!pq.empty()) {       long long d = pq.top().first, v = pq.top().second;       pq.pop();       if (d != dis[v]) continue;       for (pair<long long, long long> e : adj[v]) {         long long u = e.first, w = e.second;         if (d + w < dis[u]) {           dis[u] = d + w;           pq.push({d + w, u});         }       }     }     fill(sid, sid + N, inf);     sid[t] = 0;     pq.push({0, t});     while (!pq.empty()) {       long long d = pq.top().first, v = pq.top().second;       pq.pop();       if (d != sid[v]) continue;       for (pair<long long, long long> e : jda[v]) {         long long u = e.first, w = e.second;         if (d + w < sid[u]) {           sid[u] = d + w;           pq.push({d + w, u});         }       }     }     for (int i = 0; i < m; i++) {       long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;       if (dis[u] + w + sid[v] == dis[t]) {         g[u].push_back({v, i});         g[v].push_back({u, i});       }     }     dfs(s, -1);     for (int i = 0; i < m; i++) {       long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;       if (dis[u] + w + sid[v] == dis[t]) {         if (c[i])           cout <<  YES n ;         else if (1 < w)           cout <<  CAN  <<     << 1 <<   n ;         else           cout <<  NO n ;       } else {         long long cst = dis[u] + w + sid[v];         long long dif = cst - dis[t] + 1;         if (dif < w)           cout <<  CAN  <<     << dif <<   n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[2 * 100001], rnk[2 * 100001];   int cnt[2 * 100001];   long long pref[2 * 100001 + 5];   long long ans[2 * 100001 + 5];   vector<pair<int, int> > q;   struct Edge {     int a, b;     int w;     Edge(int a, int b, int w) : a(a), b(b), w(w) {}   };   vector<Edge> e;   bool comp(const Edge &one, const Edge &two) { return one.w < two.w; }   void init() {     pref[0] = 0;     for (int i = 1; i <= 2 * 100001; ++i) pref[i] = pref[i - 1] + (i - 1);   }   void dsu_init() {     for (int i = 0; i < 2 * 100001; ++i) {       p[i] = i;       rnk[i] = 0;       cnt[i] = 1;     }   }   int dsu_find(int v) {     if (p[v] == v) return v;     return p[v] = dsu_find(p[v]);   }   int dsu_meld(int a, int b, int &prev) {     a = dsu_find(a), b = dsu_find(b);     if (a == b) return 0;     if (rnk[a] < rnk[b]) swap(a, b);     p[b] = a;     cnt[a] += cnt[b];     prev = cnt[b];     if (rnk[a] == rnk[b]) ++rnk[a];     return cnt[a];   }   int main() {     cin.sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     init();     dsu_init();     cin >> n >> m;     int a, b, w;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b >> w;       --a, --b;       e.emplace_back(a, b, w);     }     sort(e.begin(), e.end(), comp);     for (int i = 0; i < m; ++i) {       cin >> a;       q.push_back({a, i});     }     sort(q.begin(), q.end());     long long sum = 0;     int bnd = 0;     int prev, now;     for (int i = 0; i < q.size(); ++i) {       for (int j = bnd; j < e.size(); ++j) {         if (e[j].w > q[i].first) break;         now = dsu_meld(e[j].a, e[j].b, prev);         sum -= pref[prev];         sum += (pref[now] - pref[now - prev]);         ++bnd;       }       ans[q[i].second] = sum;     }     for (int i = 0; i < m; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return (b) == 0 ? (a) : gcd((b), ((a) % (b)));   }   template <class T>   inline T lcm(T a, T b) {     return ((a) / gcd((a), (b)) * (b));   }   template <class T>   inline T BigMod(T Base, T power, T M = 1000000007) {     if (power == 0) return 1;     if (power & 1)       return ((Base % M) * (BigMod(Base, power - 1, M) % M)) % M;     else {       T y = BigMod(Base, power / 2, M) % M;       return (y * y) % M;     }   }   template <class T>   inline T ModInv(T A, T M = 1000000007) {     return BigMod(A, M - 2, M);   }   int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};   int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};   int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   double arr[111];   double dp[111];   double pre[111];   int main() {     int n, i, j;     double answer = 0;     cin >> n;     for (i = 1; i <= n; i++) cin >> arr[i];     sort(arr + 1, arr + n + 1);     dp[n] = arr[n];     pre[n] = (1 - arr[n]);     for (i = n - 1; i >= 1; i--) {       pre[i] = (1 - arr[i]) * pre[i + 1];       dp[i] = arr[i] * pre[i + 1] + dp[i + 1] * (1 - arr[i]);     }     for (i = 1; i <= n; i++) answer = max(answer, dp[i]);     printf( %.10f , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     s <<  [ ;     for (int i = 0; i < ((int)(t.size())) - 1; i++) s << t[i] <<  ,  ;     s << t[((int)(t.size())) - 1] <<  ] ;     return s;   }   const int MOD = 1e9 + 7;   template <typename T>   inline T gcD(T a, T b) {     if (a < b) swap(a, b);     while (b) {       a = a % b;       b ^= a;       a ^= b;       b ^= a;     };     return a;   }   template <typename T>   inline T pow_mod(T a, T b) {     T res = 1;     while (b) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return res;   }   struct Node {     int value, x, y;     bool operator<(const Node other) const {       if (value == other.value && x == other.x)         return y < other.y;       else if (value == other.value)         return x < other.x;       else         return value < other.value;     }   };   const int MAXN = 310;   int room[MAXN][MAXN];   int dis[MAXN][MAXN];   vector<Node> dp[MAXN * MAXN];   vector<Node> bfs;   int main() {     int n, m, p;     cin >> n >> m >> p;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> room[i][j];         if (room[i][j] == 1) {           dp[1].push_back({i + j, i, j});         } else           dp[room[i][j]].push_back({(int)1e9, i, j});       }     for (int i = 2; i < p + 1; i++) {       if (dp[i - 1].size() * dp[i].size() >= n * m) {         bfs.clear();         sort(dp[i - 1].begin(), dp[i - 1].end());         bfs.push_back(dp[i - 1][0]);         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++) dis[i][j] = (int)1e9;         dis[dp[i - 1][0].x][dp[i - 1][0].y] = dp[i - 1][0].value;         int pt = 1;         int j = 0;         while (j < bfs.size()) {           Node top = bfs[j++];           while (pt < dp[i - 1].size() && dp[i - 1][pt].value <= top.value)             bfs.push_back(dp[i - 1][pt++]);           for (int k = 0; k < 4; k++) {             int new_x = top.x + fx[k][0];             int new_y = top.y + fx[k][1];             if (new_x >= 0 && new_x < n && new_y >= 0 && new_y < m) {               if (dis[new_x][new_y] > top.value + 1) {                 dis[new_x][new_y] = top.value + 1;                 bfs.push_back({dis[new_x][new_y], new_x, new_y});               }             }           }         }         for (__typeof((dp[i]).begin()) v = (dp[i]).begin(); v != (dp[i]).end();              ++v) {           v->value = dis[v->x][v->y];         }       } else {         for (__typeof((dp[i]).begin()) v = (dp[i]).begin(); v != (dp[i]).end();              ++v) {           for (__typeof((dp[i - 1]).begin()) w = (dp[i - 1]).begin();                w != (dp[i - 1]).end(); ++w) {             v->value =                 min(v->value, w->value + abs(w->x - v->x) + abs(w->y - v->y));           }         }       }     }     cout << dp[p][0].value << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int a[100010];   int main() {     int i = 0, j = 0;     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       mp.clear();       int f;       for (i = 1; i <= n; ++i) {         scanf( %d , &f);         if (mp.find(f) != mp.end()) {           mp[f] = -2;         } else {           mp[f] = i;         }       }       int b;       bool flag1 = false;       bool flag2 = false;       for (i = 1; i <= m; ++i) {         scanf( %d , &b);         if (!flag1) {           if (mp.find(b) == mp.end()) {             flag1 = true;           } else if (-2 == mp[b]) {             flag2 = true;           } else {             a[i] = mp[b];           }         }       }       if (flag1) {         printf( Impossible n );       } else if (flag2) {         printf( Ambiguity n );       } else {         printf( Possible n );         for (int i = 1; i <= m; ++i) {           printf( %d  , a[i]);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[1500000 + 5], a[1000006], marked[1500000], pt = 2;   vector<int> v[1500000 + 5];   bool broken;   bool hoyKina(int x) {     for (int i = 0; i < v[x].size(); i++) {       if (marked[v[x][i]]) return false;     }     for (int i = 0; i < v[x].size(); i++) {       marked[v[x][i]] = 1;     }     return true;   }   int cal(int x) {     if (broken) {       while (1) {         if (hoyKina(pt)) return pt;         pt++;       }     }     while (1) {       if (hoyKina(x)) return x;       broken = true;       x++;     }   }   int main() {     for (int i = 2; i <= 1500000; i++) {       if (vis[i]) continue;       for (int j = i; j <= 1500000; j += i) {         vis[j] = 1;         v[j].push_back(i);       }     }     int n, x;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       printf( %d  , cal(x));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const bool debug = true;   const int MAXN = 100010;   int dp[MAXN], t[MAXN];   const int inf = 2000000010;   int n;   int first_lower(int x) {     if (x < 0) return 0;     return upper_bound(t + 1, t + n + 1, x) - t - 1;   }   struct node {     int mx;     int lazy;     node() {}     node(int _mx, int _lazy) {       mx = _mx;       lazy = _lazy;     }     node operator+(const node &a) const { return *(new node(max(mx, a.mx), 0)); }   } st[4 * MAXN];   int value[MAXN];   void propagate(int idx, int left, int right) {     if (st[idx].lazy == 0) return;     st[idx].mx += st[idx].lazy;     if (left != right) {       st[2 * idx].lazy += st[idx].lazy;       st[2 * idx + 1].lazy += st[idx].lazy;     }     st[idx].lazy = 0;   }   void update(int idx, int left, int right, int l, int r, int val) {     if (l <= left && right <= r) {       st[idx].lazy += val;       return;     }     propagate(idx, left, right);     if (r > (left + right) / 2)       update(2 * idx + 1, (left + right) / 2 + 1, right, l, r, val);     if (l <= (left + right) / 2)       update(2 * idx, left, (left + right) / 2, l, r, val);     propagate(2 * idx, left, (left + right) / 2);     propagate(2 * idx + 1, (left + right) / 2 + 1, right);     st[idx] = st[2 * idx] + st[2 * idx + 1];   }   int get(int idx, int left, int right) {     propagate(idx, left, right);     if (left != right) {       propagate(2 * idx, left, (left + right) / 2);       propagate(2 * idx + 1, (left + right) / 2 + 1, right);     }     if (left == right)       if (st[idx].mx > 0)         return value[left];       else         return -1;     if (st[2 * idx + 1].mx > 0)       return get(2 * idx + 1, (left + right) / 2 + 1, right);     else if (st[2 * idx].mx > 0)       return get(2 * idx, left, (left + right) / 2);     else       return -1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int p, type;       scanf( %d %d , &p, &type);       if (type == 1) {         int val;         scanf( %d , &val);         value[p] = val;         update(1, 1, n, 1, p, 1);       } else         update(1, 1, n, 1, p, -1);       printf( %d n , get(1, 1, n));     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   int getc_str(char str[]) {     unsigned int c, n = 0;     while ((c = getchar()) <=    )       ;     if (!~c) exit(0);     do {       str[n++] = c;     } while ((c = getchar()) >    );     str[n] =   0 ;     return n;   }   const long long MOD = 1000000007;   long long dp[123][2789];   int n;   char in[123];   int main() {     int i, j, k, tcc, tc = getint();     dp[0][0] = 1;     for (i = 0; i < 111; i++) {       for (j = 0; j <= 2600; j++) {         for (k = 0; k < 26; k++) {           (dp[i + 1][j + k] += dp[i][j]) %= MOD;         }       }     }     for (tcc = 0; tcc < tc; tcc++) {       n = getc_str(in);       int sum = 0;       for (i = 0; i < n; i++) sum += in[i] -  a ;       int res = (dp[n][sum] - 1 + MOD) % MOD;       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int x;     int y;     int w;   };   const int N = 200 + 7;   const int INF = (int)1e9;   int n;   int m;   int d[N][N];   struct T {     int f;     int s;   };   bool operator<(T a, T b) { return a.s - a.f < b.s - b.f; }   int solve(int x, int y, int w) {     vector<T> pts;     for (int i = 1; i <= n; i++) {       pts.push_back({d[x][i], d[y][i] + w});     }     sort(pts.begin(), pts.end());     vector<int> pre(n), suf(n);     pre[0] = pts[0].s;     for (int i = 1; i < n; i++) {       pre[i] = max(pre[i - 1], pts[i].s);     }     suf[n - 1] = pts[n - 1].f;     for (int i = n - 2; i >= 0; i--) {       suf[i] = max(suf[i + 1], pts[i].f);     }     vector<int> tt(n);     for (int i = 0; i < n; i++) {       tt[i] = (pts[i].s - pts[i].f) / 2;     }     int ret = INF;     for (int last = -1; last < n; last++) {       if (last == -1) {         int m_suf = suf[last + 1];         int t = tt[last + 1];         ret = min(ret, m_suf + t);         continue;       }       if (last == n - 1) {         int m_pre = pre[last];         int t = tt[last];         ret = min(ret, m_pre - t);         continue;       }       int t1 = tt[last];       int t2 = tt[last + 1];       int m_pre = pre[last];       int m_suf = suf[last + 1];       ret = min(ret, max(m_suf + t1, m_pre - t1));       ret = min(ret, max(m_suf + t2, m_pre - t2));       int t = (m_pre - m_suf) / 2;       if (t1 <= t && t <= t2) {         ret = min(ret, max(m_suf + t, m_pre - t));       }     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         d[i][j] = INF;       }       d[i][i] = 0;     }     vector<Edge> e(m);     for (int i = 0; i < m; i++) {       cin >> e[i].x >> e[i].y >> e[i].w;       e[i].w *= 2;       d[e[i].x][e[i].y] = d[e[i].y][e[i].x] = e[i].w;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           d[i][j] = min(d[i][j], d[i][k] + d[k][j]);         }       }     }     solve(e[0].x, e[0].y, e[0].w);     int ret = INF;     for (auto &it : e) {       ret = min(ret, solve(it.x, it.y, it.w));     }     if (ret % 2 == 0) {       cout << ret / 2 <<  .0 n ;     } else {       cout << ret / 2 <<  .5 n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   string a, b;   int n;   int x[MAXN], y[MAXN];   void pre() {     int cnt = 0, len = b.size();     for (int i = 0; i < n; i++) {       if (cnt == len) continue;       if (b[cnt] == a[i]) {         x[cnt] = i;         cnt++;       }     }     cnt = len - 1;     for (int i = n - 1; i >= 0; i--) {       if (cnt < 0) continue;       if (b[cnt] == a[i]) {         y[cnt] = n - 1 - i;         cnt--;       }     }   }   int bs(int val, int in) {     int s = 0, e = in, mid;     while (s <= e) {       mid = (s + e) / 2;       if (x[mid] < val)         s = mid + 1;       else if (x[mid] > val)         e = mid - 1;       else         return mid;     }     return e;   }   int main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cin >> a;     cin >> b;     n = a.size();     std::fill(x, x + b.size(), MAXN);     std::fill(y, y + b.size(), MAXN);     pre();     int ani = MAXN, len = b.size();     pair<int, int> ans = make_pair(-1, len);     for (int i = len - 1; i >= 0; i--) {       int an = bs(n - 1 - y[i], i - 1);       if (ani > i - an - 1) {         if (an == -1 && y[i] >= n) continue;         if (an != -1 && x[an] + y[i] + 1 >= n) continue;         ani = i - an - 1;         ans = make_pair(an, i);       }     }     for (int i = 0; i < len; i++)       if (x[i] < n && len - i - 1 < ani) {         ani = len - i - 1;         ans = make_pair(i, len);       }     if (ans.first == -1 && ans.second == len)       cout <<  - n ;     else {       if (ans.first != -1) cout << b.substr(0, ans.first + 1);       if (ans.second != len) cout << b.substr(ans.second, len - ans.second);       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct segtree {     int n;     vector<pair<int, int>> st;     segtree(int _n) {       n = _n;       st.assign(4 * n + 5, make_pair(0, 0));     }     pair<int, int> merge(pair<int, int> a, pair<int, int> b) {       pair<int, int> res = make_pair(min(a.first, b.first), 0);       if (a.first == res.first) res.second += a.second;       if (b.first == res.first) res.second += b.second;       if (res.second >= mod) res.second -= mod;       return res;     }     void update(int id, int l, int r, int pos, int val, int num) {       if (l > pos || r < pos) return;       if (l == r) {         st[id] = make_pair(val, num);         return;       }       int mid = (l + r) >> 1;       update(id << 1, l, mid, pos, val, num);       update(id << 1 | 1, mid + 1, r, pos, val, num);       st[id] = merge(st[id << 1], st[id << 1 | 1]);     }     pair<int, int> get(int id, int l, int r, int u, int v) {       if (l > v || r < u) return make_pair((int)2e9, 0);       if (l >= u && r <= v) return st[id];       int mid = (l + r) >> 1;       pair<int, int> lnode = get(id << 1, l, mid, u, v);       pair<int, int> rnode = get(id << 1 | 1, mid + 1, r, u, v);       return merge(lnode, rnode);     }     void update(int pos, int val, int num) { update(1, 1, n, pos, val, num); }     pair<int, int> get(int l, int r) { return get(1, 1, n, l, r); }   };   const int N = 2e5 + 5;   pair<int, int> a[N];   pair<int, int> dp[N];   int n;   int maxpre[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a + 1, a + n + 1);     segtree st(n);     for (int i = 1; i <= n; i++) {       swap(a[i].first, a[i].second);       int lo = 0;       int hi = i;       while (hi - lo > 1) {         int mid = (lo + hi) >> 1;         if (a[mid].second <= a[i].first)           lo = mid;         else           hi = mid;       }       if (!lo)         dp[i] = make_pair(a[i].first, 1);       else {         dp[i] = st.get(1, lo);         dp[i].first += a[i].first;       }       st.update(i, dp[i].first - a[i].second, dp[i].second);     }     pair<int, int> ans = make_pair((int)2e9, 0);     int mx = 0;     for (int i = n; i >= 1; i--)       if (a[i].second > mx) {         if (ans.first == dp[i].first) {           ans.second += dp[i].second;           if (ans.second >= mod) ans.second -= mod;         } else if (ans.first > dp[i].first)           ans = dp[i];         mx = max(mx, a[i].first);       }     cout << ans.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005], dp1[200005], dp2[200005];   int main() {     long long n, k, x;     int xx;     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) {       scanf( %d , &xx);       a[i] = xx;     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       if (i != 1) {         dp1[i] = dp1[i - 1] | a[i - 1];       }     }     for (int i = n; i >= 1; i--) {       dp2[i] = dp2[i + 1] | a[i + 1];     }     long long mx = 0;     long long pw = 1;     for (int i = 1; i <= k; i++) {       pw *= x;     }     for (int i = n; i >= 1; i--) {       mx = max(mx, ((pw * a[i]) | dp1[i] | dp2[i]));     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int fun(int x, int y, int z) {     return x * x + y * y + z * z + x * y + y * z + z * x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, n;     cin >> t;     while (t--) {       cin >> n;       int a[n];       int f = true;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 1; i < n - 1; i++) {         if (a[i] > a[i - 1] && a[i] > a[i + 1]) {           cout <<  YES  << endl;           f = false;           cout << i <<     << i + 1 <<     << i + 2 << endl;           break;         }       }       if (f) cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300010];   struct _ {     int val, rpos;   };   vector<_> min_, max_;   int vmin[1200010], cmin[1200010], add[1200010];   void pushup(int rt) {     if (vmin[rt << 1] == vmin[rt << 1 | 1]) {       vmin[rt] = vmin[rt << 1];       cmin[rt] = cmin[rt << 1] + cmin[rt << 1 | 1];     } else {       if (vmin[rt << 1] < vmin[rt << 1 | 1]) {         vmin[rt] = vmin[rt << 1];         cmin[rt] = cmin[rt << 1];       } else {         vmin[rt] = vmin[rt << 1 | 1];         cmin[rt] = cmin[rt << 1 | 1];       }     }   }   void build(int l, int r, int rt) {     if (l == r) {       cmin[rt] = 1;       return;     }     int m = l + r >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     pushup(rt);   }   void pushdown(int rt) {     if (add[rt]) {       add[rt << 1] += add[rt];       vmin[rt << 1] += add[rt];       add[rt << 1 | 1] += add[rt];       vmin[rt << 1 | 1] += add[rt];       add[rt] = 0;       return;     }   }   void update(int L, int R, int c, int l, int r, int rt) {     if (L <= l && r <= R) {       add[rt] += c;       vmin[rt] += c;       return;     }     int m = l + r >> 1;     pushdown(rt);     if (m >= L) update(L, R, c, l, m, rt << 1);     if (m < R) update(L, R, c, m + 1, r, rt << 1 | 1);     pushup(rt);   }   struct __ {     int v, c;     __ operator+(const __ &ob) const {       __ rv;       if (v == ob.v) {         rv.v = v;         rv.c = c + ob.c;       } else {         if (v < ob.v) {           rv.v = v;           rv.c = c;         } else {           rv.v = ob.v;           rv.c = ob.c;         }       }       return rv;     }   };   __ query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) return (__){vmin[rt], cmin[rt]};     int m = l + r >> 1;     pushdown(rt);     __ ans;     ans.v = 998244353;     if (m >= L) ans = ans + query(L, R, l, m, rt << 1);     if (m < R) ans = ans + query(L, R, m + 1, r, rt << 1 | 1);     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     build(1, n, 1);     int i;     int x, y;     for (i = 1; i <= n; ++i) {       cin >> x >> y;       a[x] = y;     }     min_.push_back((_){-1, 0});     max_.push_back((_){n + 1, 0});     long long ans = 0;     for (i = 1; i <= n; ++i) {       while (min_.back().val >= a[i]) {         update(min_[min_.size() - 2].rpos + 1, min_.back().rpos, min_.back().val,                1, n, 1);         min_.pop_back();       }       update(min_.back().rpos + 1, i, -a[i], 1, n, 1);       min_.push_back((_){a[i], i});       while (max_.back().val <= a[i]) {         update(max_[max_.size() - 2].rpos + 1, max_.back().rpos, -max_.back().val,                1, n, 1);         max_.pop_back();       }       update(max_.back().rpos + 1, i, a[i], 1, n, 1);       max_.push_back((_){a[i], i});       update(1, i, -1, 1, n, 1);       ans += query(1, i, 1, n, 1).c;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       string ss = s;       string tt = t;       sort(ss.begin(), ss.end());       sort(tt.begin(), tt.end());       int ans;       if (ss != tt)         ans = -1;       else {         ans = INT_MAX;         for (int i = 0; i < n; i++) {           int k = i;           for (int j = 0; j < n; j++) {             if (k < n and s[j] == t[k]) k++;           }           ans = min(ans, n - k + i);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long p, q, i, t, i1 = 0, i2 = 0, mx;     char c;     cin >> t;     long long a[368], b[368];     for (i = 0; i < 368; i++) {       a[i] = 0;       b[i] = 0;     }     for (i = 0; i < t; i++) {       cin >> c >> p >> q;       if (c ==  F ) {         b[p]++;         b[q + 1]--;       } else {         a[p]++;         a[q + 1]--;       }     }     mx = 0;     for (i = 1; i < 367; i++) {       a[i] += a[i - 1];       b[i] += b[i - 1];       mx = max(mx, (min(a[i], b[i]) * 2));     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   string s, t;   int mp[28], tempMap[28];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int i, j, len1, len2, can = -1;     cin >> s >> t;     len1 = (int)s.size(), len2 = (int)t.size();     for (i = 0; i < len1; i++) {       mp[s[i] -  a ]++;     }     int rng = min(len1, len2) - 1;     if (len1 > len2) rng++;     for (i = 0; i < rng; i++) {       if (mp[t[i] -  a ]) {         mp[t[i] -  a ]--;         for (j = 0; j < 26; j++) {           tempMap[j] = mp[j];         }         bool flag = false;         if (i == len2 - 1) {           if (len1 > len2 && i == rng - 1) flag = true, can = i;         } else {           for (j = t[i + 1] -  a  + 1; j < 26; j++) {             if (mp[j]) {               flag = true;               break;             }           }           if (flag) can = i;         }       } else {         break;       }     }     memset(mp, 0, sizeof mp);     for (i = 0; i < len1; i++) mp[s[i] -  a ]++;     if (can == -1) {       int found = -1;       for (i = t[0] -  a  + 1; i < 26; i++) {         if (mp[i]) {           found = i;           break;         }       }       if (found == -1)         cout << -1 << endl;       else {         cout << (char)(found +  a );         mp[found]--;         for (i = 0; i < 26; i++) {           for (j = 0; j < mp[i]; j++) {             cout << (char)(i +  a );           }         }         cout << endl;       }     } else {       for (i = 0; i <= can; i++) {         cout << t[i];         mp[t[i] -  a ]--;       }       if (len1 > len2 && can == len2 - 1) {         for (i = 0; i < 26; i++) {           for (j = 0; j < mp[i]; j++) {             cout << (char)(i +  a );           }         }         cout << endl;       } else {         for (i = t[can + 1] -  a  + 1; i < 26; i++) {           if (mp[i]) {             cout << (char)(i +  a );             mp[i]--;             break;           }         }         for (i = 0; i < 26; i++) {           for (j = 0; j < mp[i]; j++) {             cout << (char)(i +  a );           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, h, arr[1000], c = 0, i;     scanf( %d %d , &n, &h);     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (arr[i] > h)         c = c + 2;       else         c = c + 1;     }     printf( %d , c);     return 0;   }


#include <bits/stdc++.h>   const int M = 5004;   int n, m, a[55], b[55];   double p[55], eps = 1e-9;   double f[55][5005], cnt;   double chk(double x) {     for (int i = n; i >= 1; i--) {       for (int j = m + 1; j <= M; j++) f[i + 1][j] = x;       for (int j = 0; j <= m; j++) {         f[i][j] = (f[i + 1][j + a[i]] + a[i]) * p[i] +                   (f[i + 1][j + b[i]] + b[i]) * (1 - p[i]);         if (f[i][j] > x) f[i][j] = x;       }     }     return f[1][0];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d%lf , &a[i], &b[i], &p[i]);       p[i] = p[i] / 100;     }     double l = 0, r = 1e9;     while (l + eps < r) {       long double mid = (l + r) / 2.0;       if (chk(mid) < mid)         r = mid;       else         l = mid;       cnt++;       if (cnt > 128) break;     }     printf( %.9lf n , l);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     vector<string> input;     int n;     cin >> n;     bool flag = false;     for (int i = 0; i < n; i++) {       cin >> a;       if (!flag && a[0] == a[1] && a[0] ==  O ) {         a[0] =  + ;         a[1] =  + ;         flag = true;       }       if (!flag && a[3] == a[4] && a[3] ==  O ) {         a[3] =  + ;         a[4] =  + ;         flag = true;       }       input.push_back(a);     }     if (flag) {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         cout << input[i] << endl;       }     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lb = 1000;   void vrikodara(long long n = 12) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(n) << fixed;   }   void solve() {     string s, t;     cin >> s >> t;     vector<long long> v1(26, 0), v2(26, 0);     for (auto i : s) v1[i -  a ]++;     for (auto i : t) v2[i -  a ]++;     long long n = t.length();     long long a = n;     if (s.length() <= n) {       a = s.length();       a--;     }     t += 55;     for (long long i = a - 1; i >= -1; i--) {       vector<long long> v = v1;       bool flag = true;       string ans =   ;       for (long long j = 0; j <= i; j++) {         if (!v[t[j] -  a ]) {           flag = false;           break;         }         ans += t[j];         v[t[j] -  a ]--;       }       if (flag) {         char ch = t[i + 1];         flag = false;         for (long long i = 0; i < 26; i++) {           if (v[i] && (char)( a  + i) > ch) {             v[i]--;             char r = (char)(i +  a );             ans += r;             for (long long i = 0; i < 26; i++) {               while (v[i]--) {                 char r = (char)(i +  a );                 ans += r;               }             }             cout << ans;             return;           }         }       }     }     cout <<  -1 ;   }   int32_t main() {     vrikodara();     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> gaps(1e5 + 1);   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long a, b, c, n;       cin >> a >> b >> c;       n = (abs(b - a)) * 2;       long long ans = ((n / 2) + c);       if (ans > n) ans = ans % n;       if (n % 2 != 0 || c > n || a > n || b > n || ans > n || ans == a ||           ans == b)         ans = -1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(vector<T> v) {     for (T e : v) {       cout << e <<    ;     }     cout << endl;   }   template <typename T>   void print(vector<vector<T>> v) {     int n = v.size();     for (int i = 0; i < n; i++) {       cout << i <<  :  ;       for (T e : v[i]) {         cout << e <<    ;       }       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<int> a(6);     for (int i = 0; i < 6; i++) {       cin >> a[i];     }     cout << (int)(pow(a[0] + a[1] + a[2], 2) - a[0] * a[0] - a[2] * a[2] -                   a[4] * a[4])          << endl;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long maxn = 1000 + 10;   const int INF = 0x3f3f3f3f;   const double eps = 1e-10;   const double pi = acos(-1.0);   int g[maxn][maxn];   struct haha {     int x, y, w;   } p[maxn * 10], p0[maxn * 10];   struct Edge {     int from, to, dist;   };   struct HeapNode {     int d, u;     bool operator<(const HeapNode& rhs) const { return d > rhs.d; }   };   struct Dijkstra {     int n, m;     vector<Edge> edges;     vector<int> G[maxn];     bool done[maxn];     int d[maxn];     int p[maxn];     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, int 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;       p[s] = -1;       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] = e.from;             Q.push((HeapNode){d[e.to], e.to});           }         }       }     }   } dij;   int main() {     int n, m, L, s, t;     int cnt = 0, cnt2 = 0;     scanf( %d %d %d %d %d , &n, &m, &L, &s, &t);     dij.init(n);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       g[u][v] = g[v][u] = w;       if (w) {         p[cnt].x = u;         p[cnt].w = w;         p[cnt++].y = v;         dij.AddEdge(u, v, w);         dij.AddEdge(v, u, w);       } else {         p0[cnt2].x = u;         p0[cnt2].w = 0;         p0[cnt2++].y = v;       }     }     dij.dijkstra(s);     if (dij.d[t] < L) return 0 * puts( NO );     if (dij.d[t] == L) {       puts( YES );       for (int i = 0; i < cnt; ++i) {         printf( %d %d %d n , p[i].x, p[i].y, p[i].w);       }       for (int i = 0; i < cnt2; ++i) {         printf( %d %d %d n , p0[i].x, p0[i].y, INF);       }       return 0;     }     int pos = -1;     for (int i = 0; i < cnt2; ++i) {       dij.AddEdge(p0[i].x, p0[i].y, 1);       dij.AddEdge(p0[i].y, p0[i].x, 1);       dij.dijkstra(s);       if (dij.d[t] > L) continue;       pos = i;       break;     }     if (pos == -1) return 0 * puts( NO );     puts( YES );     for (int i = 0; i < cnt; ++i) {       printf( %d %d %d n , p[i].x, p[i].y, p[i].w);     }     for (int i = 0; i < pos; ++i) printf( %d %d %d n , p0[i].x, p0[i].y, 1);     printf( %d %d %d n , p0[pos].x, p0[pos].y, L - dij.d[t] + 1);     for (int i = pos + 1; i < cnt2; ++i)       printf( %d %d %d n , p0[i].x, p0[i].y, INF);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using int64 = long long int;   template <typename T>   void chmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   void chmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chadd(T &a, T b) {     a = a + b;   }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   const ll INF = 1001001001001001LL;   const ll MOD = 1000000007LL;   int main() {     int N;     scanf( %d , &N);     vector<int> A(N);     for (int i = 0; i < N; i++) scanf( %d , &A[i]);     sort(A.begin(), A.end());     ll ans = INF;     {       for (int x = 1; x * x <= A[0]; x++) {         int d = A[0] / x, m = A[0] % x;         for (int k = d; k >= d - (m == 0); k--) {           int mi = k, ma = k + 1;           ll sum = 0;           for (int i = 0; i < N; i++) {             ll b = (A[i] + ma - 1) / ma;             if (mi * b <= A[i])               sum += b;             else               sum = INF;           }           ans = min(ans, sum);         }       }     }     {       for (int x = 1; x * x <= A[0]; x++) {         int mi = x, ma = x + 1;         ll sum = 0;         for (int i = 0; i < N; i++) {           ll b = (A[i] + ma - 1) / ma;           if (mi * b <= A[i])             sum += b;           else             sum = INF;         }         ans = min(ans, sum);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 100010;   const int inf = 0x3f3f3f3f;   using namespace std;   map<string, int> A, B;   string y;   int solve(string x) {     y =   ;     int sz = x.size();     int a = 0, b = 0;     for (int i = 0; i < sz; i++) {       if (x[i] ==  * )         a++;       else if (x[i] ==  & )         b++;       else         y += x[i];     }     if (B[y] == 0 || A[y] == inf || (A[y] + a - b) < 0) return inf;     return A[y] + a - b;   }   int main() {     int n;     cin >> n;     A[ void ] = 0;     B[ void ] = 1;     for (int i = 0; i < n; i++) {       string a, b, c;       cin >> a >> b;       if (a ==  typedef ) {         cin >> c;         A[c] = solve(b);         B[c] = B[y];       } else {         A[b] = solve(b);         if (A[b] == inf)           puts( errtype );         else {           printf( void );           for (int j = 0; j < A[b]; j++) printf( * );           puts(  );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n + n / 2;     return 0;   }