#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   const long long N = 1e6 + 7;   long long n, a[N], del;   void input() {     cin >> n;     for (long long i = (1); i <= (n); i++) {       cin >> a[i];     }   }   void solve() {     map<long long, long long> mp;     for (long long i = (1); i <= (n); i++) {       while (mp[a[i]]) {         a[mp[a[i]]] = 0;         mp[a[i]] = 0;         a[i] *= 2;         del++;       }       mp[a[i]] = i;     }   }   void output() {     cout << n - del << endl;     for (long long i = (1); i <= (n); i++) {       if (a[i]) cout << a[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[200002], v1, v2, ans[200002], mx, subtr[200002];   vector<long long> g[200002];   void dfs(int v, int d, int p) {     ans[1] += a[v] * d;     for (int to : g[v]) {       if (to == p) continue;       dfs(to, d + 1, v);     }   }   void dfs2(int v, int p) {     long long curr = a[v];     for (int to : g[v]) {       if (to == p) continue;       dfs2(to, v);       curr += subtr[to];     }     subtr[v] = curr;   }   void dfs3(int v, int p) {     for (int to : g[v]) {       if (to == p) continue;       ans[to] = ans[v] + subtr[1] - 2 * subtr[to];       dfs3(to, v);     }     mx = max(mx, ans[v]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) {       cin >> v1 >> v2;       g[v1].push_back(v2);       g[v2].push_back(v1);     }     dfs(1, 0, -1);     dfs2(1, -1);     dfs3(1, -1);     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int& x) {     bool fu = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) fu = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (fu) x = -x;   };   char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   const int N = 100010;   const int inf = 1000000000;   int n, m, d, i, j, k, l, p, x, y, ans;   bool have[N];   int edge, e[N * 2], b[N * 2], fir[N], last[N];   void clear() {     edge = 0;     memset(fir, -1, sizeof(fir));     memset(b, -1, sizeof(b));   }   void adde(int x, int y) {     e[edge] = y;     if (fir[x] == -1)       fir[x] = edge;     else       b[last[x]] = edge;     last[x] = edge++;   }   int st[N], ed[N], ti, fa[N], dep[N], home[N];   void dfs(int i) {     st[i] = ++ti;     home[ti] = i;     int k;     for (k = fir[i]; k >= 0; k = b[k])       if (e[k] != fa[i]) {         fa[e[k]] = i;         dep[e[k]] = dep[i] + 1;         dfs(e[k]);       }     ed[i] = ti;   }   int key[N * 4], add[N * 4];   void padd(int i, int s) {     add[i] += s;     key[i] += s;   }   void pdown(int i) {     if (add[i]) padd(i * 2, add[i]), padd(i * 2 + 1, add[i]), add[i] = 0;   }   void upd(int i) { key[i] = max(key[i * 2], key[i * 2 + 1]); }   void build(int i, int x, int y) {     if (x != y) {       build(i * 2, x, (x + y) / 2);       build(i * 2 + 1, (x + y) / 2 + 1, y);       upd(i);     } else       key[i] = (have[home[x]]) ? dep[home[x]] : -inf;   }   void find(int i, int x, int y, int l, int r, int s) {     if (y < l || x > r) return;     if (x >= l && y <= r) {       padd(i, s);       return;     }     pdown(i);     find(i * 2, x, (x + y) / 2, l, r, s);     find(i * 2 + 1, (x + y) / 2 + 1, y, l, r, s);     upd(i);   }   void doit(int l, int r, int s) {     find(1, 1, n, l, r, s);     if (l > 1) find(1, 1, n, 1, l - 1, -s);     if (r < n) find(1, 1, n, r + 1, n, -s);   }   void go(int i) {     if (key[1] <= d) ans++;     int k;     for (k = fir[i]; k >= 0; k = b[k])       if (e[k] != fa[i]) {         doit(st[e[k]], ed[e[k]], -1);         go(e[k]);         doit(st[e[k]], ed[e[k]], 1);       }   }   int main() {     read(n);     read(m);     read(d);     for (i = 1; i <= m; i++) read(x), have[x] = 1;     clear();     for (i = 1; i <= n - 1; i++) read(x), read(y), adde(x, y), adde(y, x);     dfs(1);     build(1, 1, n);     go(1);     printf( %d n , ans);     scanf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:667772160 )   using namespace std;   struct __isoff {     __isoff() {       if (0) freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout);       srand( C  +  T  +  A  +  C  +  Y  +  M  +  B  +  A );     }     ~__isoff() {}   } __osafwf;   const unsigned long long p1 = 31;   const unsigned long long p2 = 29;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int infi = 1e9 + 7;   const long long inf = 1e18 + 7;   const long long dd = 7e5 + 7;   const long long mod = 1e9 + 7;   const long long mod2 = 1e6 + 3;   long long fac[dd], ifac[dd];   long long pows(long long x, int p) {     if (p == 0) return 1;     if (p % 2) return pows(x, p - 1) * x % mod2;     x = pows(x, p / 2);     return x * x % mod2;   }   long long cnk(long long a, long long b) {     return fac[a] * ifac[b] % mod2 * ifac[a - b] % mod2;   }   const int fd = 1e3 + 7;   int H[dd], IH[dd], dp[fd];   int main() {     fac[0] = ifac[0] = 1;     for (int i = 1; i < dd; i++) {       fac[i] = fac[i - 1] * i % mod2;       ifac[i] = ifac[i - 1] * pows(i, mod2 - 2) % mod2;     }     int c, h, w;     cin >> c >> w >> h;     {       H[0] = 1;       for (int i = 1; i < dd; i++) {         H[i] = (H[i - 1] * h) % mod2;       }       IH[0] = 1;       for (int i = 1; i < dd; i++) {         IH[i] = (IH[i - 1] * pows(h, mod2 - 2)) % mod2;       }     }     dp[0] = 1;     deque<long long> G;     G.push_back(1);     G.push_back(1);     long long t = h + 1;     for (int i = 1; i <= c; i++) {       if (0) {         long long p = 1;         for (int j = i - 1, l = 0; j >= -1 && l <= w; j--, l++) {           long long t = 1;           if (j >= 0) {             t = dp[j];           }           dp[i] = (dp[i] + t * p) % mod2;           p = (p * h) % mod2;         }       }       {         G.push_back(t);         t = (t * h + t) % mod2;         if (G.size() > w + 1) {           t = ((t - G.front() * H[w + 1]) % mod2 + mod2) % mod2;           G.pop_front();         }       }     }     cout << G.back();   }


#include <bits/stdc++.h>   using namespace std;   int expo(int x, int y) {     int res = 1;     while (y) {       if (y % 2) res = (res * x % 1000000007) % 1000000007;       x = (x * x) % 1000000007;       y /= 2;     }     return res;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long nextPrime(long long N) {     if (N <= 1) return 2;     long long prime = N;     bool found = false;     while (!found) {       prime++;       if (isPrime(prime)) found = true;     }     return prime;   }   long long cl(long long n, long long d) { return (n + d - 1) / d; }   long long binToDec(string s) { return bitset<64>(s).to_ullong(); }   string decToBin(long long a) { return bitset<64>(a).to_string(); }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }   void print(pair<long long, long long> a) {     cout << a.first <<     << a.second;     cout << endl;     ;   }   void print(long long a) {     cout << a;     cout << endl;   }   void print(std::vector<long long> a) {     for (auto i : a) cout << i <<    ;     cout << endl;     ;   }   void print(string s) {     cout << s;     cout << endl;     ;   }   void printr(std::vector<long long> a, long long start, long long end) {     for (long long i = start; i < end; i++) cout << a[i] <<    ;     cout << endl;     ;   }   void print(long long a, long long b) { cout << a <<     << b; }   void amax(long long &a, long long b) { a = max(a, b); }   void amin(long long &a, long long b) { a = min(a, b); }   long long madd(long long a, long long b) {     return ((a % 1000000007) + (b % 1000000007)) % 1000000007;   }   long long mmul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long msub(long long a, long long b) {     return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007;   }   long long fpow(long long x, long long y, long long p = 1000000007) {     x %= p;     long long sum = 1;     while (y) {       if (y & 1) sum = sum * x;       sum %= p;       y = y >> 1;       x = x * x;       x %= p;     }     return sum;   }   bool isPerSquare(long double a) {     if (a < 0) return false;     long long sr = sqrt(a);     return (sr * sr == a);   }   bool isPalindrome(string str) {     long long low = 0, high = long long(str.size()) - 1;     while (low < high) {       if (str[low] != str[high]) return false;       low++, high--;     }     return true;   }   void solve() {     long long n;     cin >> n;     ;     vector<set<long long>> vp(n + 1);     for (__typeof(n + 1) i = (1) - ((1) > (n + 1));          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {       long long x;       cin >> x;       ;       set<long long> temp;       for (__typeof(x) i = (0) - ((0) > (x)); i != (x) - ((0) > (x));            i += 1 - 2 * ((0) > (x))) {         long long y;         cin >> y;         ;         temp.insert(y);       }       vp[i] = temp;     }     vector<vector<long long>> dependent(n + 1);     set<long long> books;     for (long long i = 1; i <= n; i++) {       for (auto j : vp[i]) {         dependent[j].push_back(i);       }     }     long long ans = 1;     for (long long i = 1; i <= n; i++) {       if (long long(vp[i].size()) == 0) {         books.insert(i);       }     }     long long rem = 0;     while (long long(books.size())) {       bool added = false, erased = false;       std::vector<long long> add;       auto i = *books.begin();       while (1) {         if (!added && long long(dependent[i].size()) && dependent[i][0] < i) {           added = true;           ans++;         }         for (long long j = 0; j < long long(dependent[i].size()); j++) {           vp[dependent[i][j]].erase(i);           if (long long(vp[dependent[i][j]].size()) == 0) {             books.insert(dependent[i][j]);           }         }         dependent[i].clear();         rem++;         books.erase(i);         if (rem == n) {           print(ans);           return;         }         if (books.upper_bound(i) == books.end()) {           break;         } else {           i = *books.upper_bound(i);         }       }     }     print(-1);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   void solve() {     long long int n, i, j, ans = 0;     cin >> n;     long long int a[n];     for (auto &x : a) {       cin >> x;     };     map<long long int, long long int> cnt;     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         cnt[a[i] + a[j]]++;         ans = max(ans, cnt[a[i] + a[j]]);       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s[3010], c[3010], ans = 1e10;     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < n; i++) {       long long min1 = 1e10, min2 = 1e10;       for (int j = 0; j < i; j++) {         if (s[j] < s[i]) min1 = min(min1, c[j]);       }       for (int j = i; j < n; j++) {         if (s[j] > s[i]) min2 = min(min2, c[j]);       }       ans = min(ans, min1 + c[i] + min2);     }     if (ans >= 1e10)       puts( -1 );     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     unordered_map<string, string> d;     for (int i = 0; i < m; i++) {       string x, y;       cin >> x >> y;       if ((int)x.size() > (int)y.size()) swap(x, y);       d[y] = d[x] = x;     }     for (int i = 0; i < n; i++) {       string x;       cin >> x;       cout << d[x] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h;   long long n;   long long dfs(int d, long long n, int lr) {     if (d == h) return 0;     long long tmp = 1ll << (h - d - 1);     if (!lr && n <= tmp) return dfs(d + 1, n, !lr) + 1;     if (!lr && n > tmp) return (tmp << 1) + dfs(d + 1, n - tmp, 0);     if (lr && n <= tmp) return (tmp << 1) + dfs(d + 1, n, lr);     if (lr && n > tmp) return dfs(d + 1, n - tmp, 0) + 1;   }   int main() {     cin >> h >> n;     cout << dfs(0, n, 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 100010;   int n, s[MAXN];   int main() {     scanf( %d , &n);     printf( %d , n / 5 + (n % 5 != 0));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, i = 0;     cin >> n >> s;     std::vector<int> v(n);     std::vector<bool> cycle(n);     for (int i = 0; i < n; i++) cin >> v[i];     for (i = 0; i < n;) {       if (i <= -1 || i >= n) break;       if (cycle[i] == true)         break;       else {         cycle[i] = true;         if (s[i] ==  < )           i -= v[i];         else           i += v[i];       }     }     if (i <= -1 || i >= n)       cout <<  FINITE n ;     else       cout <<  INFINITE n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   long long int inf = -1e15;   long long int seg[maxn << 2], lazy[maxn << 2];   int n, m, p;   vector<long long int> espadas, armaduras;   vector<pair<int, int> > monstros[maxn];   void update(int x, long long int val) {     seg[x] += val;     lazy[x] += val;   }   void propaga(int x) {     if (!lazy[x]) return;     update(x * 2, lazy[x]);     update(x * 2 + 1, lazy[x]);     lazy[x] = 0;   }   void add(int i, int j, int x, int l, int r, int val) {     if (i >= j || l >= r || i >= r || j <= l) return;     if (i >= l && j <= r) {       update(x, val);       return;     }     propaga(x);     int md = (i + j) >> 1;     add(i, md, x * 2, l, r, val);     add(md, j, x * 2 + 1, l, r, val);     seg[x] = max(seg[x * 2], seg[x * 2 + 1]);   }   void build(int i, int j, int no) {     int l = 2 * no;     int r = l + 1;     if (i + 1 == j) {       if (armaduras[i])         seg[no] = -armaduras[i];       else         seg[no] = inf;       return;     }     int mid = (i + j) >> 1;     build(i, mid, l);     build(mid, j, r);     seg[no] = max(seg[l], seg[r]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     long long int ans = inf;     espadas.resize(maxn);     armaduras.resize(maxn);     cin >> n >> m >> p;     int atk, def;     long long int gold;     for (int i = 1; i <= n; i++) {       cin >> atk >> gold;       atk--;       if (!espadas[atk])         espadas[atk] = gold;       else         espadas[atk] = min(espadas[atk], gold);     }     for (int i = 1; i <= m; i++) {       cin >> def >> gold;       if (!armaduras[def])         armaduras[def] = gold;       else         armaduras[def] = min(armaduras[def], gold);     }     build(1, maxn, 1);     for (int i = 1; i <= p; i++) {       cin >> def >> atk >> gold;       monstros[def].push_back(pair<int, int>(atk, gold));     }     for (int i = 0; i <= maxn - 1; i++) {       for (auto a : monstros[i]) add(1, maxn, 1, a.first + 1, maxn, a.second);       if (espadas[i]) ans = max(ans, seg[1] - espadas[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt2 = 0;   int en = 0;   struct Dinic {     static const int MXN = 100000;     struct Edge {       int v, f, re;       Edge(int a, int b, int c) : v(a), f(b), re(c) {}     };     int n, s, t, level[MXN];     vector<Edge> E[MXN];     void init(int _n, int _s, int _t) {       n = _n;       s = _s;       t = _t;       for (int i = 0; i <= n; i++) E[i].clear();     }     void add_edge(int u, int v, int f, int flag = 0) {       en += 2;       if (flag) {         E[u].push_back(Edge(v, f, E[v].size()));         E[v].push_back(Edge(u, f, E[u].size() - 1));       } else {         E[u].push_back(Edge(v, f, E[v].size()));         E[v].push_back(Edge(u, 0, E[u].size() - 1));       }     }     bool BFS() {       memset(level, -1, sizeof(level));       queue<int> que;       que.push(s);       level[s] = 0;       while (!que.empty()) {         int u = que.front();         que.pop();         for (auto &it : E[u]) {           cnt2++;           if (it.f > 0 && level[it.v] == -1) {             level[it.v] = level[u] + 1;             que.push(it.v);           }         }       }       return level[t] != -1;     }     int DFS(int u, int nf) {       if (u == t) return nf;       int res = 0;       for (auto &it : E[u]) {         cnt2++;         if (it.f > 0 && level[it.v] == level[u] + 1) {           int tf = DFS(it.v, min(nf, it.f));           res += tf;           nf -= tf;           it.f -= tf;           E[it.v][it.re].f += tf;           if (nf == 0) return res;         }       }       if (!res) level[u] = -1;       return res;     }     int flow(int res = 0) {       while (BFS()) {         res += DFS(s, 2147483647);       }       return res;     }   } flow;   int vis[100005];   bool dfs(int first) {     if (vis[first]) return false;     if (first == 0) return true;     vis[first] = 1;     for (auto &it : flow.E[first]) {       cnt2++;       if (it.f && dfs(it.v)) {         it.f--;         flow.E[it.v][it.re].f++;         return true;       }     }     return false;   }   bool dfs2(int first) {     if (vis[first]) return false;     if (first == flow.t) return true;     vis[first] = 1;     for (auto &it : flow.E[first]) {       cnt2++;       if (it.f && dfs2(it.v)) {         it.f--;         flow.E[it.v][it.re].f++;         return true;       }     }     return false;   }   void solve() {     int n;     scanf( %d , &n);     int a[205][205];     flow.init(n * n * 2 + 2, 0, n * n * 2 + 1);     int X[4] = {0, 0, -1, 1};     int Y[4] = {1, -1, 0, 0};     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[i][j] != -1) {           flow.add_edge(i * n + j + 1, i * n + j + n * n + 1, 1000000, 1);           for (int k = 0; k < 4; k++) {             int first = X[k] + i, second = Y[k] + j;             if (first >= 0 && first < n && second >= 0 && second < n &&                 a[first][second] != -1 &&                 (a[i][j] == 0 || a[first][second] == 0)) {               flow.add_edge(i * n + j + 1, first * n + second + n * n + 1, 1);             }           }         }       }     }     vector<pair<int, pair<int, int> > > v;     for (int i = 1; i < n - 1; i++) {       v.push_back(make_pair(a[0][i], make_pair(0, i)));       flow.add_edge(n * n + i + 1, n * n * 2 + 1, 1);       v.push_back(make_pair(a[n - 1][i], make_pair(n - 1, i)));       flow.add_edge(n * n + i + (n - 1) * n + 1, n * n * 2 + 1, 1);       v.push_back(make_pair(a[i][0], make_pair(i, 0)));       flow.add_edge(n * n + i * n + 1, n * n * 2 + 1, 1);       v.push_back(make_pair(a[i][n - 1], make_pair(i, n - 1)));       flow.add_edge(n * n + i * n + n - 1 + 1, n * n * 2 + 1, 1);     }     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       ans += abs(a[0][i + 1] - a[0][i]);       ans += abs(a[i][0] - a[i + 1][0]);       ans += abs(a[n - 1][i] - a[n - 1][i + 1]);       ans += abs(a[i][n - 1] - a[i + 1][n - 1]);     }     sort(v.begin(), v.end());     long long now = 0;     long long last = 0;     int tot = 0;     int cnt = 0;     for (auto it : v) {       fill(vis, vis + 100005, 0);       while (dfs2(0)) {         now++;         fill(vis, vis + 100005, 0);       }       ans += now * (it.first - last);       last = it.first;       int first = it.second.first * n + it.second.second + 1;       flow.add_edge(0, first, 1);       for (auto &it : flow.E[first + n * n]) {         if (it.v == n * n * 2 + 1) {           if (it.f == 1) {             it.f = 0;           } else {             flow.E[it.v][it.re].f = 0;             now--;             fill(vis, vis + 100005, 0);             dfs(first + n * n);           }         }       }     }     printf( %lld n , ans);   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e7;   const long long maxm = 1e7;   const long long INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   long long uu[maxn];   int main() {     long long n, a, b;     cin >> n >> a >> b;     for (long long i = 0; i < n; i++) scanf( %lld , &uu[i]);     long long ans = -1;     long long mxb = b;     for (long long i = 0; i < n; i++) {       if (a == 0 && b == 0) {         ans = i;         break;       }       if (uu[i] == 0) {         if (b > 0)           b--;         else           a--;       }       if (uu[i] == 1) {         if (b == mxb) {           b--;         } else if (a > 0) {           a--;           b++;           if (b > mxb) b = mxb;         } else           b--;       }     }     if (ans == -1) ans = n;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e8;   int n, m;   char s[22][22];   int x[22][22], dp[1 << 20], state[30], sum[30], maxN[30];   vector<int> sta[22];   vector<int> cost[22];   int bit[1 << 20];   void initialIt() {     for (int i = 0; i < 20; i++) {       bit[1 << i] = i;     }     for (int i = 0; i < m; i++) {       memset(state, 0, sizeof(state));       memset(sum, 0, sizeof(sum));       memset(maxN, 0, sizeof(maxN));       for (int j = 0; j < n; j++) {         int ch = (int)s[j][i] -  a ;         state[ch] |= 1 << j;         sum[ch] += x[j][i];         maxN[ch] = max(maxN[ch], x[j][i]);       }       for (int j = 0; j < 26; j++) {         for (int k = 0; k < n; k++)           if ((state[j] >> k) & 1) {             sta[k].push_back(state[j]);             cost[k].push_back(sum[j] - maxN[j]);           }       }     }     for (int i = 0; i < n; i++) {       int minCost = INF;       for (int j = 0; j < m; j++) {         minCost = min(minCost, x[i][j]);       }       sta[i].push_back(1 << i);       cost[i].push_back(minCost);     }   }   int lowBit(int x) { return x & (-x); }   void calcIt() {     for (int i = 0; i < (1 << n); i++) {       dp[i] = INF;     }     dp[0] = 0;     for (int i = 0; i < (1 << n); i++) {       int curI = bit[lowBit(i)], curS = i;       for (int j = 0; j < (int)cost[curI].size(); j++) {         int C = cost[curI][j], S = sta[curI][j];         int preS = curS - (curS & S);         if (dp[preS] + C < dp[curS]) {           dp[curS] = dp[preS] + C;         }       }     }     int final = (1 << n) - 1;     printf( %d n , dp[final]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &x[i][j]);       }     }     initialIt();     calcIt();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     char s[200050];     map<int, map<int, int>> vis, cnt;     scanf( %d , &t);     while (t--) {       vis.clear();       cnt.clear();       int l = -5, r = 0x3f3f3f3f;       scanf( %d%s , &n, s);       int x = 0, y = 0;       vis[x][y] = 1;       cnt[x][y] = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  L ) {           x -= 1;         } else if (s[i] ==  R ) {           x += 1;         } else if (s[i] ==  D ) {           y -= 1;         } else {           y += 1;         }         if (vis[x][y] && i - cnt[x][y] < r - l) {           l = cnt[x][y] + 1;           r = i + 1;         }         cnt[x][y] = i + 1;         vis[x][y] = 1;       }       if (l != -5)         printf( %d %d n , l, r);       else         printf( -1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   long sz(char *a) {     long i = 0;     while (*(a + i) !=   0 ) i++;     return i;   }   int main() {     char *a = (char *)malloc(sizeof(char) * 1000001);     char *b = (char *)malloc(sizeof(char) * 1000001);     scanf( %1000000s , a);     scanf( %1000000s , b);     long a_size = sz(a);     long b_size = sz(b);     long j, i, a_adj, b_adj;     for (i = 0; i < a_size; i++)       if (a[i] !=  0 ) break;     a_size -= i;     a_adj = i;     i = 0;     for (i = 0; i < b_size; i++)       if (b[i] !=  0 ) break;     b_size -= i;     b_adj = i;     if (a_size > b_size) {       printf( > n );       return 0;       ;     }     if (b_size > a_size) {       printf( < n );       return 0;       ;     }     for (i = a_adj, j = b_adj; i <= a_size + a_adj, j <= b_size + b_adj;          i++, j++) {       if (a[i] > b[j]) {         printf( > n );         return 0;         ;       }       if (a[i] < b[j]) {         printf( < n );         return 0;         ;       }     }     printf( = n );     free(a);     free(b);     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int aa[N + 1];   int main() {     int n;     cin >> n;     long long ans = 0;     for (int i = 0; i <= n; i++) aa[i] = i;     int n_ = n;     for (int h = 20; n_ > 0;) {       while (h >= 0 && (n_ & 1 << h) == 0) h--;       int m = n_ - ((1 << h) - 1);       reverse(aa + n_ - m * 2 + 1, aa + n_ + 1);       n_ -= m * 2;       ans += m * 2LL * ((1 << h + 1) - 1);     }     cout << ans <<   n ;     for (int i = 0; i <= n; i++) cout << aa[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     using namespace std;     int q;     cin >> q;     while (q--) {       long long n;       cin >> n;       int len = 0;       char num[40] = {0};       while (n) {         num[len] = n % 3 +  0 ;         n /= 3;         len++;       }       int x;       for (x = len - 1; x >= 0; x--) {         if (num[x] ==  2 ) {           break;         }       }       if (x >= 0) {         for (int i = 0; i <= x; i++) {           num[i] =  0 ;         }         if (num[x + 1]) {           num[x + 1]++;         } else {           num[x + 1] =  1 ;         }         for (int i = x + 1; i < len; i++) {           if (num[i] ==  2 ) {             num[i] =  0 ;             if (num[i + 1]) {               num[i + 1]++;             } else {               num[i + 1] =  1 ;             }           }         }       }       long long m = 0, t = 1;       for (int i = 0; num[i]; i++) {         m += t * (num[i] -  0 );         t *= 3;       }       cout << m << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[5][5];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) scanf( %c , &a[i][j]);       getchar();     }     int flag = 0;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         if (a[i][j] != a[2 - i][2 - j]) flag = 1;       }     if (flag == 0)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5010;   int n;   int a[maxn], f[maxn];   long long b[maxn];   int main() {     int i, ans = 0, j;     long long w;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %I64d , &w);       while (w % 2 == 0) ++a[i], w /= 2;       b[i] = w;     }     for (i = 1; i <= n; ++i) {       for (j = 1; j < i; ++j)         if ((a[i] == a[j] + i - j || a[i] < i - j) && b[j] % b[i] == 0)           f[i] = max(f[i], f[j]);       ans = max(ans, ++f[i]);     }     printf( %d , n - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pi = pair<int, int>;   using pl = pair<ll, ll>;   using pld = pair<ld, ld>;   using vi = vector<int>;   using vl = vector<ll>;   using vb = vector<bool>;   using vld = vector<ld>;   using vs = vector<string>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vpld = vector<pld>;   int clz(unsigned long long N) { return N ? 63 - __builtin_clzll(N) : -1; }   int arr[300010];   int acum[300010];   int n, q;   void solvetask() {     cin >> n >> q;     for (int i = 0; i < n; i++) {       char c;       cin >> c;       if (c ==  + )         arr[i] = (i & 1) ? -1 : 1;       else         arr[i] = (i & 1) ? 1 : -1;     }     for (int i = 1; i <= n; i++) acum[i] = acum[i - 1] + arr[i - 1];     while (q--) {       int l, r;       cin >> l >> r;       int soma = acum[r] - acum[l - 1];       if (soma == 0)         cout <<  0 n ;       else if (abs(soma) % 2 == 1)         cout <<  1 n ;       else         cout <<  2 n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) solvetask();   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   bool debug = 1;   int main() {     int n, m;     scanf( %d %d , &n, &m);     int amn[n + 1];     vector<vector<int> > v;     v.resize(n + 1);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);       amn[a]++;       amn[b]++;     }     bool fs[n + 1];     fill(fs, fs + n + 1, 0);     if (0)       for (int i = 1; i <= n; i++)         if (v[i].size() == 1) fs[i] = 1;     int k = 0;     bool is;     do {       bool nfs[n + 1];       for (int i = 1; i <= n; i++) nfs[i] = fs[i];       is = 0;       k++;       for (int i = 1; i <= n; i++) {         if (fs[i]) continue;         int amnoth = 0;         for (int j = 0; j < v[i].size(); j++) {           int oth = v[i][j];           if (!fs[oth]) amnoth++;         }         if (amnoth == 1) {           nfs[i] = 1;           is = 1;         }       }       for (int i = 1; i <= n; i++) fs[i] = nfs[i];     } while (is);     printf( %d n , k - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int MAXN = 200010;   vector<int> x[MAXN], y[MAXN];   int v[MAXN], out[MAXN], sg[MAXN];   int xr[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> v[i];     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       x[a].push_back(b);       y[b].push_back(a);       ++out[a];     }     queue<int> Q;     for (int i = 0; i < n; ++i) {       if (out[i] == 0) Q.push(i);     }     int maxsg = 0;     while (!Q.empty()) {       int a = Q.front();       Q.pop();       for (int b : y[a]) {         --out[b];         if (out[b] == 0) {           Q.push(b);         }       }       set<int> s;       for (int b : x[a]) s.insert(sg[b]);       for (int i = 0; i < n; ++i) {         if (s.find(i) == s.end()) {           sg[a] = i;           break;         }       }       maxsg = max(maxsg, sg[a]);     }     for (int i = 0; i < n; ++i) {       xr[sg[i]] ^= v[i];     }     bool win = false;     for (int i = maxsg; i >= 0; --i) {       if (xr[i] != 0) {         win = true;         int p = -1;         for (int j = 0; j < n; ++j) {           if (sg[j] != i) continue;           if (p == -1) {             p = j;             continue;           }           if ((v[j] ^ xr[i]) <= v[j]) p = j;         }         xr[i] ^= v[p];         v[p] = xr[i];         xr[i] = 0;         for (int b : x[p]) {           if (xr[sg[b]] != 0) {             v[b] ^= xr[sg[b]];             xr[sg[b]] = 0;           }         }         break;       }     }     if (win) {       cout <<  WIN n ;       for (int i = 0; i < n; ++i) cout << v[i] <<    ;       cout <<   n ;     } else {       cout <<  LOSE n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, i, sum = 0, max;     cin >> N;     int A[N];     for (i = 0; i <= N - 1; i++) cin >> A[i];     max = *max_element(A, A + N);     for (i = 0; i <= N - 1; i++) sum += (max - A[i]);     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(339264);   const long long MOD = 998244353;   const double eps = 1e-7;   int main() {     cout << fixed << setprecision(20);     int n, w, m;     cin >> n >> w >> m;     if (2 * n < m) {       cout <<  NO ;       return 0;     }     int left = m;     int j = 0;     vector<vector<pair<int, int>>> ans(m);     for (int i = 0; i < m; i++) {       int need = n;       if (left < m && left > n) {         cout <<  NO ;         return 0;       }       while (need >= left) {         ans[i].push_back({j, left});         need -= left;         left = m;         j++;       }       if (need > 0) {         ans[i].push_back({j, need});         left -= need;       }     }     cout <<  YES  << endl;     for (int i = 0; i < m; i++) {       for (auto &p : ans[i]) {         cout << p.first + 1 <<     << (p.second * w) / ((double)m) <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct node {     int v, w;     node() {}     node(int x, int y) : v(x), w(y) {}     bool operator<(const node& tl) const { return (v - w) < (tl.v - tl.w); }   } z[105], f[105];   bool cmp(node aa, node bb) { return aa.v < bb.v; }   int dp[30005 * 2] = {0};   int main() {     int n, m, tot1, tot2;     cin >> n >> m;     tot1 = tot2 = 1;     for (int i = 1; i < n + 1; ++i) {       int x, y;       cin >> x >> y;       if (y < 0)         f[tot2++] = node(x, -y);       else         z[tot1++] = node(x, y);     }     sort(z + 1, z + tot1, cmp);     int ans = 0;     for (int i = 1; i < tot1; ++i) {       if (z[i].v <= m) {         m += z[i].w;         ++ans;       }     }     sort(f + 1, f + tot2);     int sum = 0;     for (int i = 1; i < tot2; ++i) {       for (int j = m; j >= max(f[i].v, f[i].w); --j) {         dp[j] = max(dp[j], dp[j - f[i].w] + 1);       }     }     cout << ans + dp[m] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int test, n, mx, i;   double l, r, m, eps = 0.000001, a[100005];   double pref(double tm) {     double pos = 0, speed = 1;     for (int i = 0; i < n; i++) {       if ((a[i] - pos) <= tm * speed)         tm -= (a[i] - pos) / speed, pos = a[i], speed += 1;       else {         pos += speed * tm;         tm = 0;         break;       }     }     pos += speed * tm;     return pos;   }   double suff(double tm) {     double pos = mx, speed = 1;     for (int i = n - 1; i >= 0; i--) {       if ((pos - a[i]) <= tm * speed)         tm -= (pos - a[i]) / speed, pos = a[i], speed += 1;       else {         pos -= speed * tm;         tm = 0;         break;       }     }     pos -= speed * tm;     return pos;   }   int main() {     scanf( %d , &test);     while (test--) {       cin >> n >> mx;       for (i = 0; i < n; i++) cin >> a[i];       l = 0., r = 2000000000.;       while (r - l > eps) {         m = (l + r) / 2.;         if (pref(m) <= suff(m))           l = m;         else           r = m - eps;       }       cout << fixed << setprecision(9) << l <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, s, c, ans, t;   int main() {     cin >> t;     while (t--) {       cin >> s >> a >> b >> c;       ans = ((s / (a * c)) * (a + b)) + (s % (a * c)) / c;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 77;   int T, n, L, R, par[N], fa[N][20];   int dep[N], son[N], tid[N], sz[N];   pair<int, int> mx[N][3];   vector<int> G[N];   void dfs1(int v, int fa) {     mx[v][0] = {0, v}, mx[v][1] = mx[v][2] = {-1, 0};     for (int u : G[v])       if (u ^ fa) {         dfs1(u, v);         pair<int, int> p = {mx[u][0].first + 1, u};         if (p > mx[v][0]) swap(p, mx[v][0]);         if (p > mx[v][1]) swap(p, mx[v][1]);         if (p > mx[v][2]) swap(p, mx[v][2]);       }   };   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d %d %d , &n, &L, &R);       for (int i = 1; i <= n; i++) {         G[i].clear();       }       for (int i = 1, u, v; i < n; i++) {         scanf( %d %d , &u, &v);         G[u].push_back(v), G[v].push_back(u);       }       dfs1(1, 0);       function<void(int, int)> dfs2 = [&](int v, int fa) {         for (int u : G[v])           if (u ^ fa) {             par[u] = max(par[v],                          mx[v][0].second == u ? mx[v][1].first : mx[v][0].first) +                      1,             dfs2(u, v);           }       };       memset(par, 0, sizeof(par)), dfs2(1, 0);       auto find = [&](int u, int v) {         static int dist[N];         fill(dist + 1, dist + n + 1, -1);         queue<int> q;         q.push(u), dist[u] = 0;         while (!q.empty()) {           int x = q.front();           q.pop();           for (int y : G[x])             if (!~dist[y]) {               q.push(y), dist[y] = dist[x] + 1;             }         }         return dist[v];       };       int rt = -1, len = find(L, R);       for (int i = 1; i <= n; i++) {         int cnt = 0;         if (mx[i][0].first >= len) cnt++;         if (mx[i][1].first >= len) cnt++;         if (mx[i][2].first >= len) cnt++;         if (par[i] >= len) cnt++;         if (cnt >= 3) {           rt = i;           break;         }       }       if (!~rt) {         printf( NO n );         continue;       }       int tim = 0;       function<void(int)> dfs3 = [&](int v) {         son[v] = v, tid[v] = ++tim, sz[v] = 1;         for (int i = 1; i < 20; i++) {           fa[v][i] = fa[fa[v][i - 1]][i - 1];         }         for (int u : G[v])           if (u ^ fa[v][0]) {             fa[u][0] = v, dep[u] = dep[v] + 1;             dfs3(u), sz[v] += sz[u];             if (dep[son[u]] > dep[son[v]]) son[v] = son[u];           }       };       fa[rt][0] = rt, dep[rt] = 0, dfs3(rt);       bool flag = 0;       for (int t = 1; t <= n; t++) {         auto chk = [&](int u, int v) {           return tid[v] >= tid[u] && tid[v] < tid[u] + sz[u];         };         if (chk(L, R) || chk(R, L)) {           flag = 1;           break;         }         auto get = [&](int v, int k) {           for (int i = 19; ~i; i--) {             if (k >> i & 1) v = fa[v][i];           }           return v;         };         int num = dep[son[L]] - dep[L];         L = son[L], R = get(R, num), swap(L, R);       }       printf( %s n , flag ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maximize(T &a, T b) {     if (a < b) a = b;   }   const int maxN = 305;   int n, a[maxN][maxN], f[2][maxN][maxN];   void solve() {     for (int i = 1; i <= n; ++i) fill(f[0][i] + 1, f[0][i] + n + 1, INT_MIN);     f[0][1][1] = a[1][1];     for (int d = 2; d < n + n; ++d) {       for (int i = 1; i <= n; ++i)         fill(f[(d + 1) & 1][i] + 1, f[(d + 1) & 1][i] + n + 1, INT_MIN);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j)           if (f[d & 1][i][j] > INT_MIN)             for (int ni = i; ni < i + 2; ++ni)               if (ni <= n && d - ni + 1 <= n)                 for (int nj = j; nj < j + 2; ++nj)                   if (nj <= n && d - nj + 1 <= n) {                     int t = f[d & 1][i][j] + a[ni][d - ni + 1];                     if (ni != nj) t += a[nj][d - nj + 1];                     maximize(f[(d + 1) & 1][ni][nj], t);                   }     }   }   int main() {     ios_base::sync_with_stdio(false);     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf( %d , &a[i][j]);     solve();     printf( %d n , f[0][n][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pi = pair<int, int>;   void setIO(string name =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int main() {     setIO();     int a, b, c, d;     cin >> a >> b >> c >> d;     int pv = max(3 * a / 10, a - a / 250 * c);     int pm = max(3 * b / 10, b - b / 250 * d);     if (pv == pm) {       cout <<  Tie ;     } else if (pv > pm) {       cout <<  Misha ;     } else {       cout <<  Vasya ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vec;   void update() {     int x;     scanf( %d , &x);     vector<pair<int, int> > a, b;     a.push_back({1000010, 0});     b.push_back({1000010, 0});     a.push_back({0, 0});     b.push_back({0, 0});     int sz = vec.size();     for (int i = 0; i + 1 < sz; i++) {       int p = x - vec[i].first;       if (p > 0) a.push_back({p, vec[i + 1].second});       if (p < 0) b.push_back({-p, vec[i].second});     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vec.clear();     int i = 0, j = 0;     int as = a.size(), bs = b.size();     while (i < as || j < bs) {       if (a[i].first == b[j].first) {         vec.push_back({a[i].first, a[i].second + b[j].second});         i++, j++;       } else if (a[i].first < b[j].first) {         vec.push_back({a[i].first, a[i].second + b[j].second});         i++;       } else {         vec.push_back({b[j].first, a[i].second + b[j].second});         j++;       }     }     vec[0].second = 0;     return;   }   void qry() {     int s, e, ans = 0;     scanf( %d %d , &s, &e);     int sz = vec.size();     for (auto cur : vec) {       if (e > cur.first) {         if (cur.first > s) {           ans += cur.second * (cur.first - s);           s = cur.first;         }       } else {         ans += cur.second * (e - s);         break;       }     }     printf( %d n , ans);     return;   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     vec.push_back({0, 0});     vec.push_back({n, 1});     vec.push_back({1000010, 0});     while (q--) {       int type;       scanf( %d , &type);       if (type == 1)         update();       else         qry();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int in, x = 0;     int cnt = 0, p = 1, ans = 0;     cin >> in;     for (int i = in; i > 0; i /= 10) {       if (i % 10 == 7) ans += p;       p *= 2;       cnt++;     }     if (cnt != 0) x = pow(2, cnt) - 2;     cout << ans + x + 1;   }


#include <bits/stdc++.h>   using namespace std;   int a[100 + 5];   int b[100 + 5];   int main() {     int m, n;     int l, r;     while (scanf( %d%d , &m, &n) != EOF) {       int sum = 0;       for (int i = 1; i <= m; i++) cin >> a[i];       for (int i = 1; i <= n; i++) {         cin >> l >> r;         int sum1 = 0;         for (int i = l; i <= r; i++) {           sum1 += a[i];         }         if (sum1 > 0) sum += sum1;       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int xx[] = {0, 0, 1, -1, 1, -1, 1, -1};   int yy[] = {1, -1, 0, 0, 1, -1, -1, 1};   double PI = 3.1415926535897932384626433832795;   const long long oo = (long long)1e9 + 1;   const double eps = 1e-9;   const long long mod = 1000000009;   string a, b;   bool good(int l, string s) {     for (int i = 0; i < ((long long)s.size()); i++) {       if (a[i % l] != s[i]) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b;     int res = 0;     for (int i = 1; i <= min(((long long)a.size()), ((long long)b.size())); i++) {       if (((long long)a.size()) % i == 0 && ((long long)b.size()) % i == 0 &&           good(i, a) && good(i, b))         res++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string t;   long long cnt1[3000001];   int main() {     ios_base::sync_with_stdio(0);     cin >> t;     cnt1[0] = 0;     int n = (int)t.length();     for (int i = 0; i <= n - 4; ++i) {       if (t.substr(i, 5) ==  heavy ) ++cnt1[i + 1];       cnt1[i + 1] += cnt1[i];     }     long long ans = 0;     for (int i = 0; i <= n - 4; ++i)       if (t.substr(i, 5) ==  metal ) ans += cnt1[i];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class wwj {    public:     wwj(int x);     int klz();     int pdly(int k);       private:     int x;   };   wwj::wwj(int x) { this->x = x; }   int wwj::klz() {     int i, sum = 0;     double SM = 0;     if (x == 0) return 0;     SM = (-1 + sqrt(1.0 + 8 * abs(x))) / 2;     if (int(SM) == SM)       i = int(SM);     else       i = int(SM + 1);     while (1) {       if (pdly(i))         return i;       else         ++i;     }   }   int wwj::pdly(int k) {     int s;     s = k * (1 + k) / 2;     x = abs(x);     if (x % 2 == s % 2) return 1;     return 0;   }   int main() {     int x;     cin >> x;     wwj LR(x);     cout << LR.klz() << endl;     ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long power(long long x, long long y, long long m) {     if (y == 0) return 1;     long long p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long modInverse(long long a, long long m) {     long long g = gcd(a, m);     if (g != 1)       cout <<  Inverse doesn t exist ;     else {       return power(a, m - 2, m);     }   }   long long log_a_b(long long a, long long b) {     return (a > b - 1) ? 1 + log_a_b(a / b, b) : 0;   }   int t;   vector<vector<long long> > graph;   vector<long long> tin, tout;   vector<bool> vis;   vector<vector<long long> > up;   void dfs(int v, int p, int l) {     vis[v] = true;     tin[v] = ++t;     up[v][0] = p;     for (int(i) = (1); (i) < (l + 1); (i)++) {       up[v][i] = up[v][i - 1] < 0 ? -1 : up[up[v][i - 1]][i - 1];     }     for (int x : graph[v])       if (!vis[x]) dfs(x, v, l);     tout[v] = ++t;   }   bool isan(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }   int lca(int u, int v, int l) {     if (isan(u, v)) return u;     if (isan(v, u)) return v;     for (int(i) = (l); (i) >= (0); (i)--) {       if (up[u][i] == -1) continue;       if (!isan(up[u][i], v)) u = up[u][i];     }     return up[u][0];   }   bool sum(long long n, long long i, long long s, long long cnt,            vector<long long> &a) {     if (i >= n && cnt > 0) {       if (s != 0)         return 0;       else         return 1;     }     if (i >= n && cnt == 0) return 0;     bool a1 = sum(n, i + 1, s, cnt, a);     bool b = sum(n, i + 1, s - a[i], cnt + 1, a);     bool c = sum(n, i + 1, s + a[i], cnt + 1, a);     bool d = (a1 | b | c);     return d;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.precision(15);     long long T;     cin >> T;     while (T--) {       long long n, q, k, m, u, v, w, x;       string s, t;       cin >> n >> m;       long long ans = 0;       m++;       vector<long long> a(31), b(31);       for (int(i) = (0); (i) < (31); (i)++) {         a[i] = n % 2;         b[i] = m % 2;         n /= 2;         m /= 2;       }       reverse((a).begin(), (a).end());       reverse((b).begin(), (b).end());       for (int(i) = (0); (i) < (31); (i)++) {         if (a[i] && !b[i]) break;         if (!a[i] && b[i]) ans = ans | (1 << (30 - i));       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int two(int n) { return 1 << n; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   int dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0};   const int md = 1000000007;   int dcmp(double a, double b) {     return fabs(a - b) <= 1e-9 ? 0 : (a > b) ? 1 : -1;   }   int arr[1009], tmp[1009] = {0};   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, r, sum = 0;     cin >> n >> r;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];       sum += arr[i];       if (arr[i] == 1) {         for (int j = i - r + 1; j <= i + r - 1; ++j) {           if (j >= 1 && j <= n) tmp[j]++;         }       }     }     int cnt = 0;     for (int i = 1; i <= n; ++i) {       if (tmp[i] < 1) return cout << -1, 0;     }     for (int i = 1; i <= n; ++i) {       bool ok = false;       if (arr[i] == 1) {         for (int j = i - r + 1; j <= i + r - 1; ++j) {           if (j >= 1 && j <= n)             if (tmp[j] == 1) {               ok = true;               break;             }         }         if (!ok) {           cnt++;           for (int j = i - r + 1; j <= i + r - 1; ++j) {             if (j >= 1 && j <= n) tmp[j]--;           }         }       }     }     cout << sum - cnt;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0), cout.tie(0);     ios::sync_with_stdio(false);     string a, b;     while (cin >> a >> b) {       unsigned int len = a.size();       int ans = 0;       bool OK = true;       map<int, int> dic;       for (unsigned int i = 0; i < len; ++i) {         if (a.at(i) != b.at(i)) {           if (!dic.count(a.at(i)) && !dic.count(b.at(i))) {             ++ans;             dic[a.at(i)] = b.at(i);             dic[b.at(i)] = a.at(i);           } else if (dic[a.at(i)] != b.at(i) || dic[b.at(i)] != a.at(i)) {             cout << -1 << endl;             OK = false;             break;           }         } else {           if (!dic.count(a.at(i))) {             dic[a.at(i)] = a.at(i);           } else if (dic[a.at(i)] != a.at(i)) {             cout << -1 << endl;             OK = false;             break;           }         }       }       if (OK) {         cout << ans << endl;         int vis[1000] = {0};         if (ans != 0) {           for (char c =  a ; c <=  z ; ++c) {             if (!vis[(int)c] && dic[c] != 0 && dic[c] != c) {               cout << c <<     << (char)dic[c] << endl;               vis[dic[c]] = c;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 * 100 + 15;   int n, mark[maxn], h[maxn], d[maxn], g[2], cnt, c, w;   vector<int> ad[maxn];   void dfs(int v) {     mark[v] = 1;     for (auto u : ad[v]) {       if (mark[u] == 0) {         h[u] = h[v] + 1;         dfs(u);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       ad[u].push_back(v);       ad[v].push_back(u);       d[u]++;       d[v]++;     }     dfs(1);     for (int i = 1; i <= n; i++) {       cnt = 0;       if (d[i] <= 1) {         g[h[i] % 2] = 1;       }       for (auto u : ad[i]) {         if (d[u] == 1) cnt++;       }       if (cnt > 1) {         c++;         w += cnt;       }     }     if (g[0] && g[1])       cout << 3;     else       cout << 1;     cout <<    ;     cout << n - 1 + c - w;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long n, k;     cin >> n >> k;     unsigned long long lo = 0, hi = min(n / 2, n / k + 1), mid;     while (lo < hi) {       mid = lo + (hi - lo + 1) / 2;       if (mid + mid * k <= n / 2)         lo = mid;       else         hi = mid - 1;     }     cout << lo <<     << lo * k <<     << n - (lo + lo * k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> lol1;   vector<long long> lol2;   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       lol1.push_back(x);     }     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       lol2.push_back(x);     }     long long s1 = lol1[0], s2 = lol2[0];     long long x = 1, y = 1;     long long ans = 0;     while (true) {       if (s1 < s2) {         if (x == n) break;         s1 += lol1[x];         x++;       }       if (s2 < s1) {         if (y == m) break;         s2 += lol2[y];         y++;       }       if (s1 == s2) {         ans++;         s1 = lol1[x];         s2 = lol2[y];         x++;         y++;         if (x > n && y > m) break;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   inline long long getnum() {     register long long r = 0;     register bool ng = 0;     register char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) ng = 1, c = getchar();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = getchar();     if (ng) r = -r;     return r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline void putsp() { putchar(   ); }   inline void putendl() { putchar(  n ); }   inline char mygetchar() {     register char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   int n, c;   int a[200111];   set<pair<int, int> > s;   vector<pair<int, int> > tmps;   bool used[200111];   int cnt[200111];   int main() {     c = getnum(), n = getnum();     s.insert(make_pair(-c, 0));     for (int i = 1; i <= n; i++) {       a[i] = getnum();     }     sort(a + 1, a + n + 1);     for (int i = n; i >= 1; i--) {       tmps.clear();       while (s.size() > 0 && -s.begin()->first > a[i]) {         int x = s.begin()->second, y = -s.begin()->first + x;         s.erase(s.begin());         tmps.push_back(make_pair(-a[i], x));         tmps.push_back(make_pair(-(y - (x + a[i])), x + a[i]));       }       for (int j = 0; j < tmps.size(); j++) {         s.insert(tmps[j]);       }     }     for (auto x : s) {       used[x.second] = 1;     }     int tmp = c;     for (int i = n; i >= 1; i--) {       if (tmp >= a[i]) {         cnt[a[i]]++;         cnt[tmp + 1]--;         tmp -= a[i];       }     }     int sum = 0;     for (int i = 1; i <= c; i++) {       sum += cnt[i];       if (sum > 0 && !used[c - i]) {         cout << i << endl;         return 0;       }     }     puts( Greed is good );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     vector<int> g;     while (cin >> n) {       int xi, xf;       xi = -1;       xf = -1;       bool init = false;       g = vector<int>(n);       for (int i = 0; i < n; i++) {         cin >> g[i];         if (init == false && g[i] == 1) {           xi = i;           xf = i;           init = true;         } else if (init == true && g[i] == 1)           xf = max(xf, i);       }       if (xi == -1 || xf == -1)         cout << 0 << endl;       else {         int ceros = 0;         for (int i = xi; i < xf;) {           if (g[i] == 0 && g[i + 1] == 0) {             i += 2;             ceros += 2;             int b = i;             for (int q = b; q <= xf; q++)               if (g[q] == 0) {                 ceros++;                 b = max(b, q);               } else                 break;             i = b + 1;           } else             i++;         }         cout << (xf - xi + 1) - ceros << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   bool Check(int x, int y) {     if (gcd(x, y) > 1) return false;     if (gcd(x + 1, y) > 1) return false;     if (gcd(x + 2, y) > 1) return false;     return true;   }   vector<int> ans[10010];   int main() {     int n, k;     cin >> n >> k;     int x = 1;     for (int i = 0; i < (n); i++) {       ans[i].push_back(x * k);       ans[i].push_back((x + 1) * k);       ans[i].push_back((x + 2) * k);       int y = x + 4;       while (!Check(x, y)) y += 2;       ans[i].push_back(y * k);       x = y + 2;     }     cout << (x - 2) * k << endl;     for (int i = 0; i < (n); i++)       cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] <<                << ans[i][3] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int N = 1e5 + 10, INFI = 1e9 + 10;   int val[12];   unordered_set<int> s;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < 12; i++) {       s.clear();       for (int a = 0; a <= i + 1; a++) {         for (int b = 0; b <= i + 1 - a; b++) {           for (int c = 0; c <= i + 1 - a - b; c++) {             for (int d = 0; d <= i + 1 - a - b - c; d++) {               if (a + b + c + d == i + 1) {                 s.insert((a * 1) + (b * 5) + (c * 10) + (d * 50));               }             }           }         }       }       val[i] = s.size();     }     if (n <= 12) {       cout << val[n - 1] << endl;     } else {       cout << val[11] + 1LL * 49 * (n - 12) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010], n, S, T;   vector<int> A;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i), S += a[i];     for (int i = 0; i < n; i++)       if (S - a[i] == (long long)a[i] * (n - 1)) A.push_back(i + 1);     printf( %d n , (int)A.size());     for (int i = 0; i < (int)A.size(); i++)       printf( %d%c , A[i], i == (int)A.size() - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> primes(100006, false);   void sieve() {     for (long long i = 3; i <= 100006; i += 2) {       primes[i] = 1;     }     for (long long i = 3; i <= 100006; i += 2) {       if (primes[i] == 1) {         for (long long j = i * i; j <= 100006; j += i) {           primes[j] = 0;         }       }     }     primes[2] = 1;     primes[0] = primes[1] = 0;   }   int recpow(int x, int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return recpow((x * x), n / 2);     else       return (x * recpow((x * x), (n - 1) / 2));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long k, a, b;     cin >> k >> a >> b;     long long count = 0;     count = a / k;     count += b / k;     if (count == 0)       cout << -1 << endl;     else if (a % k > 0 and b / k == 0)       cout << -1 << endl;     else if (b % k > 0 and a / k == 0)       cout << -1 << endl;     else       cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int r, c, p;     node() {}     node(int _r, int _c, int _p) { r = _r, c = _c, p = _p; }   };   const int MAXN = 1005;   char g[MAXN][MAXN];   int dist[MAXN][MAXN];   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   int to_int(const char& c) { return c -  0 ; }   bool is_digit(const char& c) {     if ( 1  <= c && c <=  9 ) return true;     return false;   }   void bfs(const int& r, const int& c, node s) {     queue<node> q;     q.push(s);     memset(dist, -1, sizeof dist);     dist[s.r][s.c] = 0;     int xx, yy;     while (!q.empty()) {       s = q.front();       q.pop();       for (int i = 0; i < 4; ++i) {         xx = dx[i] + s.r;         yy = dy[i] + s.c;         if (xx < 0 || xx >= r || yy < 0 || yy >= c || g[xx][yy] ==  T  ||             dist[xx][yy] != -1)           continue;         dist[xx][yy] = dist[s.r][s.c] + 1;         q.emplace(xx, yy, s.p);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int r, c, best, ans;     vector<node> b;     node s, f;     while (cin >> r >> c) {       for (int i = 0; i < r; ++i) {         for (int j = 0; j < c; ++j) {           cin >> g[i][j];           if (is_digit(g[i][j])) b.emplace_back(i, j, to_int(g[i][j]));           if (g[i][j] ==  S ) s = node(i, j, 0);           if (g[i][j] ==  E ) f = node(i, j, 0);         }       }       bfs(r, c, f);       ans = 0;       best = dist[s.r][s.c];       for (node i : b)         if (dist[i.r][i.c] <= best && dist[i.r][i.c] != -1) ans += i.p;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   int n;   int a[N];   void solve() {     n = read();     int sum = 0;     for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i];     for (int i = 2; i * i <= sum; i++) {       if (sum % i == 0) {         printf( %d n , n);         for (int i = 1; i <= n; i++) printf( %d  , i);         puts(  );         return;       }     }     printf( %d n , n - 1);     bool ok = 0;     for (int i = 1; i <= n; i++) {       if (!ok && a[i] % 2 == 1) {         ok = 1;         continue;       }       printf( %d  , i);     }     puts(  );   }   int main() {     int T = read();     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int base = 1e9;   const int MAX = 1e5;   const double EPS = 1e-9;   const double PI = acos(-1.);   int main() {     char x;     string s1, s2, res;     vector<char> v(10000);     int c1, c2, cnt = 0, i = 0;     cin >> s1 >> s2;     if ((s1.length() - 1 + s2.length()) % 2 == 1) {       cout <<  Impossible ;       return 0;     }     for (int i = 0; i < s1.length(); i++) {       if (s1.substr(i, 1) ==  | ) {         c1 = cnt;         cnt = 0;       } else {         cnt++;       }     }     c2 = cnt;     if (max(c1, c2) > (s1.length() - 1 + s2.length()) / 2) {       cout <<  Impossible ;       return 0;     }     if (c1 > c2) {       res.append(s2, 0, (s2.length() - (c1 - c2)) / 2);       res.append(s1);       res.append(s2, (s2.length() - (c1 - c2)) / 2,                  (s2.length() + (c1 - c2)) / 2);     } else {       res.append(s2, 0, (s2.length() + (c2 - c1)) / 2);       res.append(s1);       res.append(s2, (s2.length() + (c2 - c1)) / 2,                  (s2.length() - (c2 - c1)) / 2);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long int arr[100050];   vector<vector<long long int>> v(100050);   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> arr[i];     for (int i = 1; i <= m; i++) {       if (i > 1 && arr[i - 1] != arr[i]) v[arr[i]].push_back(arr[i - 1]);       if (i < m && arr[i] != arr[i + 1]) v[arr[i]].push_back(arr[i + 1]);     }     long long int sum = 0, ans;     for (int i = 1; i < m; i++) sum += abs(arr[i] - arr[i + 1]);     ans = sum;     for (int i = 1; i <= n; i++) {       if (v[i].size() == 0) continue;       sort(v[i].begin(), v[i].end());       long long int y = v[i][v[i].size() / 2];       long long int before = 0, after = 0;       for (int x : v[i]) {         before += abs(x - i);         after += abs(y - x);       }       ans = min(ans, sum - before + after);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prices;   int main() {     long long int n, p, s = 0;     cin >> n;     for (long long int a = 0; a < n; a++) {       cin >> p;       prices.push_back(p);       s += p;     }     sort(prices.rbegin(), prices.rend());     cin >> n;     for (long long int a = 0; a < n; a++) {       cin >> p;       cout << s - prices[p - 1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[212345];   int color[212345];   bool vis[212345];   map<int, int> m;   int r = 0;   int dfs(int i) {     if (vis[i]) return 0;     vis[i] = true;     m[color[i]]++;     if (m[r] < m[color[i]]) r = color[i];     int cont = 0;     for (int v : g[i]) {       cont += dfs(v);     }     return 1 + cont;   }   int solve(int i) {     r = -1;     m[-1] = 0;     int cont = dfs(i);     int rr = cont - m[r];     m.clear();     return rr;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) cin >> color[i];     for (int i = 0; i < m; ++i) {       int l, r;       cin >> l >> r;       l--;       r--;       g[l].push_back(r);       g[r].push_back(l);     }     memset(vis, false, sizeof vis);     int cont = 0;     for (int i = 0; i < n; ++i) {       if (vis[i]) continue;       cont += solve(i);     }     cout << cont << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long base = 71;   const long long mod = 1e9 + 9;   int convert(char a) {     if (a >=  a  && a <=  z ) return (a -  a ) + 1;     if (a >=  A  && a <=  Z ) return (a -  A ) + 27;     return (a -  0 ) + 53;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     int n = (int)s.length();     long long ans = 0;     vector<long long> V(n);     long long H = 0;     long long I = 0;     long long p = 1;     V[0] = 1ll;     for (int i = 0; i < n; ++i) {       H = (H * base % mod + (long long)convert(s[i])) % mod;       I = (I + p * (long long)convert(s[i]) % mod) % mod;       p = (p * base) % mod;       if (i && H == I) V[i] = V[(i - 1) / 2] + 1ll;       ans += V[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, q, a[N], c[N], l[N], r[N];   vector<int> s[N], p[N], b;   set<int> s1, s2, s3, s4, s5, s6, s7;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &l[i], &r[i]);       p[l[i]].push_back(i);     }     for (int i = n; i; i--) {       int x;       while (s1.size() && a[x = *s1.begin()] < a[i]) {         s6.insert(x);         c[x]--;         if (!c[x]) s5.insert(x);         s1.erase(x);       }       while (s2.size() && a[x = *s2.begin()] > a[i]) {         s7.insert(x);         c[x]--;         if (!c[x]) s5.insert(x);         s2.erase(x);       }       while (s3.size() && a[x = *s3.begin()] <= a[i]) s3.erase(x);       while (s4.size() && a[x = *s4.begin()] >= a[i]) s4.erase(x);       if (s3.size() && s4.size()) {         auto it = s5.lower_bound(max(*s3.begin(), *s4.begin()));         if (it != s5.end() && (!b.size() || *it < b.back())) {           b = {i, *it};           auto it2 = s1.lower_bound(*it);           it2--;           b.push_back(*it2);           it2 = s2.lower_bound(*it);           it2--;           b.push_back(*it2);           sort(b.begin(), b.end());         }       }       for (int j : p[i]) {         if (b.size() && b.back() <= r[j])           s[j] = b;         else {           if (s3.size()) {             auto it = s6.lower_bound(*s3.begin());             if (it != s6.end() && *it <= r[j]) s[j] = {i, *it - 1, *it};           }           if (s4.size()) {             auto it = s7.lower_bound(*s4.begin());             if (it != s7.end() && *it <= r[j]) s[j] = {i, *it - 1, *it};           }         }       }       c[i] = 2;       s1.insert(i), s2.insert(i), s3.insert(i), s4.insert(i);     }     for (int i = 1; i <= q; i++) {       printf( %d n , s[i].size());       for (auto j : s[i]) printf( %d  , j);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 10;   const int NQ = 160000;   int n, k, q;   int v[NQ];   pair<int, int> lg[K];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     cin >> n >> k >> q;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = 0; i < k; i++) {       lg[i].first = -1;       lg[i].second = -1;     }     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       y--;       if (x == 1) {         if (lg[0].first == -1 || lg[0].first < v[y]) {           lg[0] = make_pair(v[y], y);           sort(lg, lg + k);         }       } else {         bool flag = false;         for (int i = 0; i < k; i++) {           if (lg[i].second == y) {             flag = true;           }         }         cout << (flag ?  YES  :  NO ) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   vector<vector<int>> ga;   vector<vector<int>> gb;   vector<int> comp;   vector<bool> used;   void dfsa(int v) {     used[v] = true;     comp.push_back(v);     for (int u : ga[v]) {       if (!used[u]) {         dfsa(u);       }     }   }   int main() {     int n, m, a, b;     while (scanf( %d%d%d%d , &n, &m, &a, &b) == 4) {       ga = gb = vector<vector<int>>(n);       for (int i = 0; i < m; i++) {         int x, y, c;         scanf( %d%d%d , &x, &y, &c);         --x, --y;         auto& g = (c == a) ? ga : gb;         g[x].push_back(y);         g[y].push_back(x);       }       vector<pair<int, int>> order;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           order.emplace_back(i, j);         }       }       sort(order.begin(), order.end(),            [&](const pair<int, int>& x, const pair<int, int>& y) {              return x.first * a + x.second * b < y.first * a + y.second * b;            });       vector<int> comp_id(n, -1);       used = vector<bool>(n, false);       int cc = 0;       int cc2 = -2;       for (int i = 0; i < n; i++) {         if (comp_id[i] == -1) {           comp.clear();           dfsa(i);           int cid = (comp.size() >= 4 ? cc++ : cc2--);           for (int x : comp) {             comp_id[x] = cid;           }         }       }       vector<vector<vector<pair<int, int>>>> vs(           n, vector<vector<pair<int, int>>>(n));       vector<vector<int>> dp((1 << cc), vector<int>(n, 1 << 30));       int init_id = (comp_id[0] < 0) ? 0 : (1 << comp_id[0]);       dp[init_id][0] = 0;       vs[0][0].emplace_back(init_id, 0);       vector<int> ans(n, 1 << 30);       for (auto& [cnta, cntb] : order) {         for (auto& [mask, v] : vs[cnta][cntb]) {           if (dp[mask][v] != cnta * a + cntb * b) continue;           ans[v] = min(ans[v], dp[mask][v]);           for (int u : ga[v]) {             if (dp[mask][u] > dp[mask][v] + a) {               assert(comp_id[u] == comp_id[v]);               dp[mask][u] = dp[mask][v] + a;               vs[cnta + 1][cntb].emplace_back(mask, u);             }           }           for (int u : gb[v]) {             if (comp_id[u] == comp_id[v]) continue;             int nmask = mask;             if (comp_id[u] >= 0) {               nmask |= (1 << comp_id[u]);               if (mask == nmask) continue;             }             if (dp[nmask][u] > dp[mask][v] + b) {               dp[nmask][u] = dp[mask][v] + b;               vs[cnta][cntb + 1].emplace_back(nmask, u);             }           }         }       }       for (int i = 0; i < n; i++) {         printf( %d  , ans[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool d[400];   void input() {     int i, n, nk, nc, x;     scanf( %d %d , &n, &nk);     scanf( %d , &nc);     for ((i) = 0; (i) < (nc); (i)++) scanf( %d , &x), d[x] = true;     int res = 0, cnt = 0;     for ((i) = (1); (i) <= (n); (i)++) {       cnt++;       if (cnt == nk || d[i]) {         res++;         cnt = 0;       }     }     printf( %d , res);   }   int main() {     input();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, next;   };   bool islucky[100010];   bool vis[100010];   int A[100010], C[100010];   edge e[2 * 100010];   int beg[100010], f[100010];   int n, m, cnt, tot, ne;   void dfs(int x) {     if (x >= 100010) return;     islucky[x] = true;     dfs(x * 10 + 4);     dfs(x * 10 + 7);   }   void pre_cal() {     memset(islucky, 0, sizeof(islucky));     dfs(0);     islucky[0] = false;   }   void dfs2(int x) {     vis[x] = true;     cnt++;     for (int i = beg[x]; i != -1; i = e[i].next)       if (!vis[e[i].v]) {         dfs2(e[i].v);       }   }   void add(int x, int y) {     e[ne].v = y;     e[ne].next = beg[x];     beg[x] = ne++;   }   void input() {     int x, y;     ne = 0;     memset(beg, 255, sizeof(beg));     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     memset(vis, 0, sizeof(vis));     memset(C, 0, sizeof(C));     for (int i = 1; i <= n; i++)       if (!vis[i]) {         cnt = 0;         dfs2(i);         C[cnt]++;       }     tot = 0;     for (int i = 1; i <= n; i++)       if (C[i]) {         A[tot] = i;         C[tot++] = C[i];       }   }   void dp() {     fill(f, f + n + 1, 0x3fffffff);     f[0] = 0;     for (int j = 0; j < tot; j++) {       int num = C[j];       int k = 0;       for (k = 0; (1 << k) <= num; k++) {         for (int i = n; i >= (1 << k) * A[j]; i--)           f[i] = min(f[i], f[i - (1 << k) * A[j]] + (1 << k));         num -= (1 << k);       }       if (num > 0)         for (int i = n; i >= num * A[j]; i--)           f[i] = min(f[i], f[i - num * A[j]] + num);     }     int ans = 0x3fffffff;     for (int i = 1; i <= n; i++)       if (islucky[i] && f[i] < ans) ans = f[i];     if (ans == 0x3fffffff)       printf( -1 n );     else       printf( %d n , ans - 1);   }   int main() {     pre_cal();     while (scanf( %d%d , &n, &m) != EOF) {       input();       dp();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   class Graph {     long long n;     vector<long long> f, par, ans, sz, depth, value, size, fst, to, next;     long long l;     void swapUtil(long long &, long long &);     long long getP(long long);     long long dfsUtil(long long);     void setDFS();     void setsz();     void setf();     void setAns(long long);       public:     Graph();     Graph(long long);     void addEdge(long long, long long);     void setSolve(long long);     void solve(long long, long long, long long);     void printAns();   };   void Graph ::swapUtil(long long &u, long long &v) {     long long t = u;     u = v;     v = t;   }   long long Graph ::getP(long long u) {     if (f[u] == u)       return f[u];     else {       f[u] = getP(f[u]);       return f[u];     }   }   long long Graph ::dfsUtil(long long u) {     depth[u] = depth[par[u]] + 1;     for (long long i = fst[u]; i; i = next[i])       if (to[i] != par[u]) {         par[to[i]] = u;         long long t = dfsUtil(to[i]);         value[u] += size[u] * t * 2;         size[u] += t;       }     value[u] += size[u] * (n - size[u] - 1) * 2;     ans[0] += value[u];     size[u]++;     return size[u];   }   void Graph ::setDFS() { dfsUtil(1); }   void Graph ::setsz() {     for (long long i = 1; i < n + 1; i++) sz[i] = 1;   }   void Graph ::setf() {     for (long long i = 1; i < n + 1; i++) f[i] = i;   }   void Graph ::setAns(long long M) { ans.resize(M + 1); }   Graph ::Graph() {}   Graph ::Graph(long long N) {     n = N - 1;     f.resize(N);     par.resize(N);     ans.resize(N);     sz.resize(N);     depth.resize(N);     value.resize(N);     size.resize(N);     fst.resize(N);     to.resize(2 * N);     next.resize(2 * N);     l = 0;   }   void Graph ::addEdge(long long u, long long v) {     to[++l] = v;     next[l] = fst[u];     fst[u] = l;     to[++l] = u;     next[l] = fst[v];     fst[v] = l;   }   void Graph ::setSolve(long long m) {     setAns(m);     setf();     setsz();     setDFS();   }   void Graph ::solve(long long u, long long v, long long i) {     ans[i] = ans[i - 1];     u = getP(u);     v = getP(v);     while (u != v) {       if (depth[u] < depth[v]) swap(u, v);       long long t = getP(par[u]);       ans[i] +=           sz[t] * sz[u] * (size[u] - sz[u]) * 2 + sz[t] * sz[u] * (sz[u] - 1);       ans[i] +=           sz[u] * sz[t] * (n - size[u] - sz[t]) * 2 + sz[u] * sz[t] * (sz[t] - 1);       ans[i] += sz[t] * (value[u] - (n - size[u]) * (size[u] - sz[u]) * 2);       ans[i] += sz[u] * (value[t] - size[u] * (n - size[u] - sz[t]) * 2);       value[t] = value[t] - sz[u] * (n - size[u] - sz[t]) * 2 + value[u] -                  (size[u] - sz[u]) * (n - size[u]) * 2;       sz[t] += sz[u];       f[u] = t;       u = t;     }   }   void Graph ::printAns() {     for (long long i = 0; i < ans.size(); i++) cout << ans[i] << endl;   }   signed main() {     long long n;     cin >> n;     Graph g(n + 1);     for (long long i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       g.addEdge(u, v);     }     long long m;     cin >> m;     g.setSolve(m);     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       g.solve(u, v, i + 1);     }     g.printAns();     return 0;   }


#include <bits/stdc++.h>   long long n;   long long check(long long x) {     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) return 1;     return 0;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     long long g = a;     if (b == 0)       x = 1, y = 0;     else       g = exgcd(b, a % b, y, x), y -= (a / b) * x;     return g;   }   int main() {     scanf( %lld , &n);     if (n == 1) return !printf( YES n1 n );     if (n == 4) return !printf( YES n1 3 2 4 n );     if (check(n)) return !printf( NO n );     printf( YES n1 n );     for (register long long i = 2; i <= n - 1; ++i) {       long long x, y;       exgcd(i - 1, n, x, y);       printf( %lld n , ((x * i) % n + n) % n);     }     printf( %lld n , n);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   const int maxn = (int)1e5 + 10;   vector<int> ed[maxn];   int sz[maxn];   void dfs(int v, int p) {     sz[v] = 1;     for (int u : ed[v]) {       if (u != p) {         dfs(u, v);         sz[v] += sz[u];       }     }   }   int h[maxn];   vector<pair<pair<int, int>, int> > g[maxn];   long long sum = 0;   set<int> vert[maxn];   int tt = -1;   int tin[maxn], tout[maxn];   void build(int v, int p, int pr, int hh) {     tt++;     tin[v] = tt;     vert[pr].insert(v);     sum += hh;     h[v] = hh;     sz[v] = 1;     vector<int> a;     for (int u : ed[v]) {       if (u == p) {         continue;       }       build(u, v, pr, hh + 1);       sz[v] += sz[u];       if (sz[u] & 1) {         a.push_back(u);       }     }     while ((int)a.size() >= 2) {       int x = a.back();       a.pop_back();       int y = a.back();       a.pop_back();       g[pr].push_back(make_pair(make_pair(x, y), hh));     }     if (!a.empty()) {       g[pr].push_back(make_pair(make_pair(a.back(), v), hh));     }     tout[v] = tt;   }   bool is_anc(int x, int y) { return tin[x] <= tin[y] && tout[y] <= tout[x]; }   int main() {     int n;     long long k;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       ed[x].push_back(y);       ed[y].push_back(x);     }     dfs(0, -1);     int v = 0;     while (true) {       bool ok = true;       for (int u : ed[v]) {         if (sz[u] < sz[v] && 2 * sz[u] > n) {           v = u;           ok = false;           break;         }       }       if (ok) {         break;       }     }     for (int u : ed[v]) {       build(u, v, u, 1);       reverse((g[u]).begin(), (g[u]).end());     }     if (k > sum) {       cout <<  NO n  <<   n ;       return 0;     }     set<pair<int, int> > s;     for (int u : ed[v]) {       s.insert(make_pair(sz[u], u));     }     vector<pair<int, int> > res;     if ((k - sum) & 1) {       cout <<  NO n  <<   n ;       return 0;     }     while (!s.empty() && sum != k) {       int u = s.rbegin()->second;       s.erase(*s.rbegin());       if (sz[u] == 1) {         cout <<  NO n  <<   n ;         return 0;       }       if (sum - 2 * g[u].back().second >= k) {         sum -= 2 * g[u].back().second;         sz[u] -= 2;         s.insert(make_pair(sz[u], u));         res.push_back(g[u].back().first);         vert[u].erase(g[u].back().first.first);         vert[u].erase(g[u].back().first.second);         g[u].pop_back();         continue;       }       int x = g[u].back().first.first;       int y = -1;       for (int z : vert[u]) {         if (sum - 2 * h[z] == k && is_anc(z, x)) {           y = z;           break;         }       }       assert(y != -1);       res.push_back(make_pair(x, y));       vert[u].erase(x);       vert[u].erase(y);       break;     }     cout <<  YES n ;     s.clear();     for (int u : ed[v]) {       if (vert[u].size()) {         s.insert(make_pair(vert[u].size(), u));       }     }     while ((int)s.size() > 1) {       int x = s.rbegin()->second;       s.erase(*s.rbegin());       int y = s.rbegin()->second;       s.erase(*s.rbegin());       int a = *vert[x].begin();       vert[x].erase(a);       int b = *vert[y].begin();       vert[y].erase(b);       res.push_back(make_pair(a, b));       if (vert[x].size()) {         s.insert(make_pair(vert[x].size(), x));       }       if (vert[y].size()) {         s.insert(make_pair(vert[y].size(), y));       }     }     int x = s.begin()->second;     assert((int)vert[x].size() == 1);     res.push_back(make_pair(v, *vert[x].begin()));     for (pair<int, int> f : res) {       printf( %d %d n , f.first + 1, f.second + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long long INF = 2 * 1000 * 1000 + 200;   const long long MAXN = 100 * 1000 + 1;   const long long MLOG = 18;   const long long NMAX = 1 * 1000;   signed main() {     long long n, m, a[200];     a[0] = 0;     long long x, y;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     cin >> m;     for (long long i = 0; i < m; i++) {       cin >> x >> y;       a[x - 1] += y - 1;       a[x + 1] += a[x] - y;       a[x] = 0;     }     for (long long i = 1; i <= n; i++) cout << a[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   ofstream out( biconex.out );   ifstream in( biconex.in );   struct Edge {     int node;     bool is_critic;   };   const int N_MAX = 100000;   vector<Edge> neighbours[1 + N_MAX];   stack<int> component;   int n, m, h, minim = N_MAX + 1, node_ans, Depth, root_sons, depth[1 + N_MAX],                height[1 + N_MAX], main_hour[1 + N_MAX], color[1 + N_MAX];   bool visited[1 + N_MAX], not_in_subgraph[1 + N_MAX], is_critic[1 + N_MAX],       on_stack[1 + N_MAX];   void read() {     cin >> n >> m >> h;     for (int i = 1; i <= n; i++) cin >> main_hour[i];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       if (main_hour[x] - main_hour[y] == 1 |           (main_hour[x] == 0 & main_hour[y] == h - 1))         neighbours[y].push_back({x, false});       if (main_hour[y] - main_hour[x] == 1 |           (main_hour[y] == 0 & main_hour[x] == h - 1))         neighbours[x].push_back({y, false});     }     for (int i = 1; i <= n; i++) depth[i] = -1;   }   void DFS(int node, int root) {     depth[node] = height[node] = Depth;     component.push(node);     on_stack[node] = true;     Depth++;     for (Edge& son : neighbours[node]) {       if (depth[son.node] == -1) {         DFS(son.node, root);         height[node] = min(height[node], height[son.node]);       } else if (on_stack[son.node])         height[node] = min(height[node], depth[son.node]);     }     if (height[node] == depth[node]) {       int son;       do {         son = component.top();         color[son] = node;         component.pop();         on_stack[son] = false;       } while (son != node);     }   }   int DFS2(int node, int cnt, bool possible_ans) {     cnt++;     visited[node] = true;     for (Edge son : neighbours[node]) {       if (color[node] != color[son.node]) {         possible_ans = false;         continue;       }       if (visited[son.node]) continue;       cnt = DFS2(son.node, cnt, possible_ans);       if (!cnt) possible_ans = false;     }     if (!possible_ans) cnt = 0;     return cnt;   }   void solution() {     for (int i = 1; i <= n; i++)       if (depth[i] == -1) DFS(i, i);     for (int i = 1; i <= n; i++) visited[i] = false;     for (int i = 1; i <= n; i++) {       if (visited[i]) continue;       int cnt = DFS2(i, 0, true);       if (cnt)         if (minim > cnt) {           minim = cnt;           node_ans = i;         }     }   }   void DFS_print(int node) {     cout << node <<    ;     visited[node] = true;     for (Edge son : neighbours[node]) {       if (!visited[son.node]) DFS_print(son.node);     }   }   void print() {     cout << minim <<   n ;     for (int i = 1; i <= n; i++) visited[i] = false;     DFS_print(node_ans);   }   int main() {     read();     solution();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 9;   long long wei[N], p[N], in[N], ans[N], par[N][22], mx[N][22], h[N];   pair<long long, long long> edge[N];   vector<pair<long long, long long> > vec, adj[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       hp[N];   long long FS(long long v) {     if (p[v] < 0) return v;     return p[v] = FS(p[v]);   }   void US(long long u, long long v, long long id) {     long long a = FS(u), b = FS(v);     if (a == b) return;     if (p[a] > p[b]) swap(a, b);     p[a] += p[b];     p[b] = a;     adj[u].push_back({v, id});     adj[v].push_back({u, id});     in[id] = 1;   }   void DFS1(long long u) {     for (pair<long long, long long> v : adj[u])       if (v.first != par[u][0]) {         h[v.first] = h[u] + 1;         par[v.first][0] = u;         mx[v.first][0] = wei[v.second];         for (long long i = 1; i < 22; i++)           par[v.first][i] = par[par[v.first][i - 1]][i - 1];         for (long long i = 1; i < 22; i++)           mx[v.first][i] =               max(mx[v.first][i - 1], mx[par[v.first][i - 1]][i - 1]);         DFS1(v.first);       }   }   pair<long long, long long> LYFT(long long v, long long dis) {     long long maxx = 0;     for (long long i = 21; i >= 0; i--)       if (h[v] - (1 << i) >= dis) maxx = max(maxx, mx[v][i]), v = par[v][i];     return {v, maxx};   }   long long LCA(long long u, long long v) {     if (h[u] > h[v]) swap(u, v);     v = LYFT(v, h[u]).first;     if (u == v) return v;     for (long long i = 21; i >= 0; i--)       if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];     return par[u][0];   }   void DFS2(long long u) {     for (pair<long long, long long> v : adj[u])       if (v.first != par[u][0]) {         DFS2(v.first);         if (hp[v.first].size()) ans[v.second] = hp[v.first].top().first - 1;         if (hp[v.first].size() > hp[u].size()) swap(hp[u], hp[v.first]);         while (hp[v.first].size()) {           pair<long long, long long> x = hp[v.first].top();           hp[v.first].pop();           if (x.second < h[u]) hp[u].push(x);         }       }     while (hp[u].size() && hp[u].top().second >= h[u]) hp[u].pop();   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     fill(p, p + N, -1);     for (long long i = 0; i < m; i++) {       cin >> edge[i].first >> edge[i].second >> wei[i];       vec.push_back({wei[i], i});     }     sort(vec.begin(), vec.end());     for (long long i = 0; i < m; i++)       US(edge[vec[i].second].first, edge[vec[i].second].second, vec[i].second);     fill(ans, ans + N, -1);     DFS1(1);     for (long long i = 0; i < m; i++)       if (!in[i]) {         long long u = edge[i].first, v = edge[i].second, x = LCA(u, v);         ans[i] = max(LYFT(u, h[x]).second, LYFT(v, h[x]).second) - 1;         hp[u].push({wei[i], h[x]});         hp[v].push({wei[i], h[x]});       }     DFS2(1);     for (long long i = 0; i < m; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 1 << 30;   long long INFL = 1LL << 60;   int main() {     int n;     cin >> n;     string w;     cin >> w;     int ile = 0;     for (int i = 1; i < n; i += 2) {       if (w[i] ==  a  && w[i - 1] ==  a ) {         w[i] =  b ;         ile++;       }       if (w[i] ==  b  && w[i - 1] ==  b ) {         w[i] =  a ;         ile++;       }     }     cout << ile <<   n  << w;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     string s;     cin >> s;     vector<int> stars, pacmans;     for (int i = 0; i < n; i++) {       if (s[i] ==  * )         stars.push_back(i);       else if (s[i] ==  P )         pacmans.push_back(i);     }     stars.push_back(1e9);     int l = 1, r = 2 * n, ok = 1;     while (l <= r) {       int mid = (l + r) / 2;       int start = stars[0];       int curr = 0;       bool f = true;       for (int x : pacmans) {         if (start < x - mid)           f = false;         else if (start < x) {           curr = max(x + mid - (x - start) * 2, x + (mid - x + start) / 2);         } else {           curr = x + mid;         }         start = *upper_bound(stars.begin(), stars.end(), curr);       }       if (!f or start != 1e9) {         l = mid + 1;       } else {         ok = mid;         r = mid - 1;       }     }     cout << ok << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool used[10000001];   int n, m, second = 0, ds[1000001], ans[1000001], str[1000001], sv[1000001];   struct o {     int x, i, j;   };   o d[1000001];   vector<vector<int> > a;   bool comp(o a, o b) {     if (a.x == b.x) return a.i < b.i;     return a.x < b.x;   }   bool fcomp(o a, o b) {     if (a.x == b.x) return a.j < b.j;     return a.x < b.x;   }   int FS(int v) {     if (ds[v] == v) return v;     return ds[v] = FS(ds[v]);   }   void US(int a, int b) {     a = FS(a);     b = FS(b);     ds[a] = ds[b];     return;   }   vector<pair<int, int> > tt[1000001];   pair<int, int> dd(int v) {     int i = (v - 1) / m;     ++i;     int j = v % m;     if (j == 0) j = m;     return {i, j};   }   int main() {     cin >> n >> m;     a.resize(n + 1);     for (int k = 1; k <= n; ++k) {       a[k].resize(m + 1);     }     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= m; ++i) {         cin >> a[k][i];         ds[(k - 1) * m + i] = (k - 1) * m + i;         o w;         w.x = a[k][i];         w.i = k;         w.j = i;         d[++second] = w;       }     sort(d + 1, d + second + 1, comp);     for (int k = 1; k < second; ++k)       if (d[k].x == d[k + 1].x) {         if (d[k].i == d[k + 1].i)           US((d[k].i - 1) * m + d[k].j, (d[k + 1].i - 1) * m + d[k + 1].j);       }     sort(d + 1, d + second + 1, fcomp);     for (int k = 1; k < second; ++k)       if (d[k].x == d[k + 1].x) {         if (d[k].j == d[k + 1].j) {           US((d[k].i - 1) * m + d[k].j, (d[k + 1].i - 1) * m + d[k + 1].j);         }       }     for (int k = 1; k <= n * m; ++k) tt[FS(ds[k])].push_back(dd(k));     for (int k = 1; k <= second; ++k) {       int i = d[k].i;       int j = d[k].j;       if (used[(i * m - m) + j]) continue;       int cm = FS(ds[(i * m - m) + j]);       int cnt = 0;       for (int i = 0; i < tt[cm].size(); ++i) {         int ii = tt[cm][i].first;         int jj = tt[cm][i].second;         used[ii * (m)-m + jj] = 1;         cnt = max(str[ii], cnt);         cnt = max(sv[jj], cnt);       }       for (int i = 0; i < tt[cm].size(); ++i) {         int ii = tt[cm][i].first;         int jj = tt[cm][i].second;         ans[ii * (m)-m + jj] = cnt + 1;         sv[jj] = max(cnt + 1, sv[jj]);         str[ii] = max(cnt + 1, str[ii]);       }     }     for (int k = 1; k <= n; ++k) {       for (int i = 1; i <= m; ++i) cout << ans[(k - 1) * m + i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (((n * (n - 1)) / 2) <= k)       cout <<  no solution ;     else {       while (n--) cout <<  0   << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int n, m, t, k;   int d[((int)1e5 + 5)];   int countt[105];   int l = 1;   int r = 100;   void lbulma() {     while (countt[l] == 0) l++;     return;   }   void rbulma() {     while (countt[r] == 0) r--;     return;   }   int asal[4] = {2, 3, 5, 7};   int main() {     long long int sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> d[i];       sum += d[i];       countt[d[i]]++;     }     lbulma();     rbulma();     long long minn = INT_MAX;     for (int j = 100; j >= l; --j) {       if (countt[j])         for (int i = 10; i >= 2; --i) {           if (j % i == 0 && (j / i) + (l * i) < j + l) {             long long int tmp = sum - ((j + l) - ((j / i) + (l * i)));             minn = min(minn, tmp);           }         }     }     cout << min(minn, sum) << endl;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = acosl(-1);   bool compare_int(int a, int b) { return (a > b); }   bool compare_string(string a, string b) { return a.size() < b.size(); }   bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second)       return a.first > b.first;     else       return (a.second > b.second);   }   long long int fact(long long int n) {     if (n == 0 || n == 1)       return 1;     else       return n * fact(n - 1);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s, st;     long long int x = 0, temp = 0, ans = 0;     cin >> s;     if (s.size() == 1) {       cout << s << endl;       return 0;     }     for (int i = 1; i < s.size(); i++) st +=  9 ;     stringstream ss(s);     ss >> x;     stringstream sm(st);     sm >> temp;     long long int te = x - temp;     while (te) {       ans += (te % 10);       te /= 10;     }     cout << ans + (s.size() - 1) * 9 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long num(string str) {     long long out = 0;     for (int i = 0; i < str.length(); i++) {       out *= 26;       out += str.at(i) -  A  + 1;     }     return out;   }   string pb26(long long n) {     string reverse =   ;     while (n > 0) {       int d = (n - 1) % 26 + 1;       char c = d +  A  - 1;       reverse.push_back(c);       n -= d;       n /= 26;     }     string out =   ;     for (int i = reverse.length() - 1; i > -1; i--) out.push_back(reverse.at(i));     return out;   }   int main() {     long long N;     cin >> N;     for (int t = 0; t < N; t++) {       string S;       cin >> S;       bool rc = S.at(0) ==  R ;       if (rc) {         int i = 0;         while (i < S.length() && S.at(i) !=  C ) i++;         rc = i < S.length() && i > 1;         if (rc) {           for (int j = 1; j < i && rc; j++) {             char c = S.at(j);             if (c <  0  || c >  9 ) rc = false;           }           if (rc) {             long long row = stoll(S.substr(1, i - 1)),                       col = stoll(S.substr(i + 1));             cout << pb26(col) << row <<   n ;           }         }       }       if (!rc) {         int i = 0;         while (true) {           char c = S.at(i);           if (c >=  0  && c <=  9 ) break;           i++;         }         string col = S.substr(0, i);         long long row = stoll(S.substr(i));         cout <<  R  << row <<  C  << num(col) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<double, int> &a, pair<double, int> &b) {     if (a.first != b.first) return a.first > b.first;     return a.second < b.second;   }   void solve() {     int n;     double t1, t2, k;     cin >> n >> t1 >> t2 >> k;     vector<pair<double, int>> p(n);     for (int i = 0; i < (n); i++) {       double a, b;       cin >> a >> b;       p[i].second = i + 1;       p[i].first = max(a * t1 - (a * t1 * k) / 100 + b * t2,                        b * t1 - (b * t1 * k) / 100 + a * t2);     }     sort(p.begin(), p.end(), comp);     for (auto x : p)       cout << x.second <<     << setprecision(2) << fixed << x.first <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long n, x;   map<long long, long long> mp;   map<long long, long long> nums;   long long grund(long long x) {     if (x <= 1) return 0;     if (mp[x]) return mp[x];     for (long long i = 31; i >= 0; i--) {       if ((x & (1 << i))) {         set<long long> second;         second.clear();         for (long long j = i; j >= 1; j--) {           long long y = x % (1 << j);           for (long long k = j; k <= i; k++) {             if (x & (1 << k)) y |= (1 << (k - j));           }           second.insert(grund(y));         }         for (long long j = 0; j <= 31; j++)           if (second.find(j) == second.end()) return mp[x] = j;       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> x;       long long y = x;       for (long long j = 2; j <= sqrt(x); j++) {         if (!(y % j)) {           long long cnt = 0;           while (!(y % j)) {             cnt++;             y /= j;           }           nums[j] |= (1 << cnt);         }       }       if (y > 1) nums[y] |= 2;     }     if (!nums.size()) {       cout <<  Arpa ;       return 0;     }     long long g = 0;     for (map<long long, long long>::iterator it = nums.begin(); it != nums.end();          it++) {       g ^= grund(it->second);     }     if (!g)       cout <<  Arpa ;     else       cout <<  Mojtaba ;   }