#include <bits/stdc++.h>   using namespace std;   string pad(string x, int lngth) {     reverse(x.begin(), x.end());     for (int i = 0; i < lngth; i++) x +=  0 ;     reverse(x.begin(), x.end());     return x;   }   string add(string x, string y) {     string res =   ;     int mx = max(x.length(), y.length());     x = pad(x, mx - x.length());     y = pad(y, mx - y.length());     reverse(x.begin(), x.end());     reverse(y.begin(), y.end());     int carry = 0, tmp;     for (int i = 0; i < x.length(); i++) {       tmp = (x[i] -  0 ) + (y[i] -  0 ) + carry;       res += ((tmp % 10) +  0 );       carry = tmp / 10;     }     if (carry != 0) res += (carry +  0 );     reverse(res.begin(), res.end());     if (res[0] ==  0 ) {       int i = 0;       while (res[i] ==  0 ) i++;       res = res.substr(i, res.length());     }     return res;   }   string smaller(string x, string y) {     int i, mx = max(x.length(), y.length());     string x_ = pad(x, mx - x.length());     string y_ = pad(y, mx - y.length());     for (i = 0; i < x_.length(); i++) {       if (x_[i] > y_[i])         return y;       else if (x_[i] < y_[i])         return x;     }     return x;   }   int main() {     ios::sync_with_stdio(0);     int i, n;     string s, x, y;     cin >> n >> s;     int m = n / 2;     string p1, p2, res, ans =   ;     bool zero_found = false;     for (i = 0; i < m; i++) {       if (s[m + i] !=  0 )         break;       else         zero_found = true;     }     if (!zero_found) {       ans = add(s.substr(0, m), s.substr(m, n));       ans = smaller(ans, add(s.substr(0, m + 1), s.substr(m + 1, n)));     } else       ans = add(s.substr(0, m + i), s.substr(m + i, n));     zero_found = false;     for (i = 0; i < m; i++) {       if (s[m - i] !=  0 )         break;       else         zero_found = true;     }     if (!zero_found)       ans = smaller(ans, add(s.substr(0, m - 1), s.substr(m - 1, n)));     else       ans = smaller(ans, add(s.substr(0, m - i), s.substr(m - i, n)));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 4 * atan(1);   template <int p>   struct FF {     long long val;     FF(long long x = 0) { val = (x % p + p) % p; }     bool operator==(const FF<p> other) { return val == other.val; }     bool operator!=(const FF<p> other) { return val != other.val; }     FF operator+() const { return val; }     FF operator-() const { return -val; }     FF& operator+=(const FF<p> other) {       val = (val + other.val) % p;       return *this;     }     FF& operator-=(const FF<p> other) {       *this += -other;       return *this;     }     FF& operator*=(const FF<p> other) {       val = (val * other.val) % p;       return *this;     }     FF& operator/=(const FF<p> other) {       *this *= other.inv();       return *this;     }     FF operator+(const FF<p> other) const { return FF(*this) += other; }     FF operator-(const FF<p> other) const { return FF(*this) -= other; }     FF operator*(const FF<p> other) const { return FF(*this) *= other; }     FF operator/(const FF<p> other) const { return FF(*this) /= other; }     static FF<p> pow(const FF<p> a, long long b) {       if (!b) return 1;       return pow(a * a, b >> 1) * (b & 1 ? a : 1);     }     FF<p> pow(long long b) const { return pow(*this, b); }     FF<p> inv() const { return pow(p - 2); }   };   template <int p>   FF<p> operator+(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) += rhs;   }   template <int p>   FF<p> operator-(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) -= rhs;   }   template <int p>   FF<p> operator*(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) *= rhs;   }   template <int p>   FF<p> operator/(long long lhs, const FF<p> rhs) {     return FF<p>(lhs) /= rhs;   }   int N;   vector<int> adj[500013];   FF<998244353> dp[500013];   FF<998244353> ans;   void dfs(int n, int par = -1) {     dp[n] = 1;     for (int v : adj[n])       if (v != par) {         dfs(v, n);         dp[n] *= 1 - dp[v] / 2;       }     ans += 1 - dp[n];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       --u;       --v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0);     for (int i = 0; i < N; i++) ans = ans * 2;     cout << ans.val << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, dx, dy, x, y;   char c[5];   bool f;   long long ans;   struct blk {     int x, y;     blk(int xx = 0, int yy = 0) {       x = xx;       y = yy;     }     bool operator<(const blk& b) const {       return x < b.x || (x == b.x && y < b.y);     }   };   vector<blk> data[2];   void ins(int x, int y) {     data[0].push_back(blk(x - y, x));     data[1].push_back(blk(x + y, x));   }   void beam() {     int ff = (dx != dy);     blk p = ff ? blk(x + y, x) : blk(x - y, x);     vector<blk>::iterator it = upper_bound(data[ff].begin(), data[ff].end(), p);     for (; it->x != p.x; it--)       ;     if (dx < 0)       for (; it->y >= x; it--)         ;     ans += abs(x - it->y) - 1;     x = it->y, y = ff ? it->x - x : x - it->x;     bool u =         binary_search(data[0].begin(), data[0].end(), blk(x - y - dx, x - dx));     bool v = binary_search(data[0].begin(), data[0].end(), blk(x - y + dy, x));     if (u == v) {       f = 1;       dx *= -1;       dy *= -1;     } else if (u) {       x -= dx;       dy *= -1;     } else if (v) {       y -= dy;       dx *= -1;     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       ins(0, i);       ins(n + 1, i);     }     for (int i = 0; i <= n + 1; i++) {       ins(i, 0);       ins(i, m + 1);     }     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       ins(x, y);     }     scanf( %d%d%s , &x, &y, c);     dx = (c[0] ==  N ) ? -1 : 1, dy = (c[1] ==  W ) ? -1 : 1;     sort(data[0].begin(), data[0].end());     sort(data[1].begin(), data[1].end());     beam();     int sx = x, sy = y, sdx = dx, sdy = dy;     ans = 0;     do beam();     while (!(x == sx && y == sy && dx == sdx && dy == sdy));     cout << ((f) ? (ans / 2) : ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   const long double eps = 1e-8;   const double pi = acos(-1);   const long long hashh = 247;   char s[203040];   long long p[203040], cnt[203040], hs[203040][2];   long long get(long long l, long long r) {     return (hs[r][l & 1] - hs[l - 1][l & 1] * p[cnt[r] - cnt[l - 1]] % mod +             mod) %            mod;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, q;     cin >> n >> s + 1 >> q;     p[0] = 1;     for (int i = 1; i < n + 1; i++) {       p[i] = p[i - 1] * hashh % mod;       cnt[i] = cnt[i - 1];       hs[i][0] = hs[i - 1][0];       hs[i][1] = hs[i - 1][1];       if (s[i] ==  0 ) {         cnt[i]++;         hs[i][0] = (hs[i - 1][0] * hashh + (i & 1) + 1) % mod;         hs[i][1] = (hs[i - 1][1] * hashh + (i & 1 ^ 1) + 1) % mod;       }     }     for (int i = 0; i < q; i++) {       long long l1, l2, len;       cin >> l1 >> l2 >> len;       if (get(l1, l1 + len - 1) == get(l2, l2 + len - 1))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, cnt = 0;   vector<vector<int> > g;   vector<int> outgroup;   int main() {     cin >> n >> m;     vector<int> emptyg;     g.push_back(emptyg);     for (int i = 1; i <= n; i++) {       vector<int> subg;       g.push_back(subg);     }     for (int i = 0; i < m; i++) {       int fr, to;       cin >> fr >> to;       g[fr].push_back(to);       g[to].push_back(fr);     }     while (true) {       outgroup.clear();       cerr <<  cnt ==   << cnt << endl;       for (int i = 1; i <= n; i++) {         int deg = g[i].size();         cerr <<  node   << i <<   has degree   << deg <<   n ;         if (deg == 1) {           outgroup.push_back(i);         }         cerr.flush();       }       if (outgroup.empty()) {         cout << cnt << endl;         return 0;       }       vector<int>::iterator it = outgroup.begin();       for (; it != outgroup.end(); it++) {         int nodetodelete = *it;         cerr <<  deleting node   << nodetodelete <<  ...  << endl;         int onlyconnectednode;         if (!g[nodetodelete].empty()) {           onlyconnectednode = g[nodetodelete][0];         } else {           continue;         }         vector<int>::iterator adjit = g[onlyconnectednode].begin();         for (; adjit != g[onlyconnectednode].end(); adjit++) {           if (*adjit == nodetodelete) {             g[onlyconnectednode].erase(adjit);             break;           }         }         g[nodetodelete].clear();       }       cnt = cnt + 1;       cerr <<  has the thread reached here?  << endl;       bool isEnd = true;       vector<vector<int> >::iterator ggit = g.begin();       for (; ggit != g.end(); ggit++) {         vector<int> thissubg = *ggit;         isEnd = thissubg.size() == 1 ? false : isEnd;       }       if (isEnd) {         break;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, a[210000], b[210000];   int tree[210000];   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   void update(int x, int y) {     for (; x <= n; x += x & -x) tree[x] ^= y;   }   int getnum(int x) {     int res = 0;     for (; x; x -= x & -x) res ^= tree[x];     return res;   }   struct Linear_Basis {     int cnt, v[30];     void clr() {       cnt = 0;       memset(v, 0, sizeof(v));     }     void ins(int x, int lim = 29) {       if (cnt == 30) return;       for (int i = lim; i >= 0 && x; i--)         if (x & (1 << i)) {           if (v[i])             x ^= v[i];           else {             v[i] = x;             cnt++;             break;           }         }     }     void merge(const Linear_Basis &a) {       for (int i = 29; i >= 0; i--)         if (a.v[i]) ins(a.v[i], i);     }   } tmp, t[810000];   void pushup(int now) {     t[now] = t[now << 1];     t[now].merge(t[now << 1 | 1]);   }   void build(int now, int l, int r) {     if (l == r) {       t[now].clr();       t[now].ins(b[l]);       return;     }     int mid = (l + r) >> 1;     build(now << 1, l, mid);     build(now << 1 | 1, mid + 1, r);     pushup(now);   }   void change(int now, int l, int r, int x) {     if (l == r) {       t[now].clr();       t[now].ins(b[l]);       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       change(now << 1, l, mid, x);     else       change(now << 1 | 1, mid + 1, r, x);     pushup(now);   }   void query(int now, int l, int r, int x, int y) {     if (l == x && r == y) {       tmp.merge(t[now]);       return;     }     int mid = (l + r) >> 1;     if (y <= mid)       query(now << 1, l, mid, x, y);     else if (x > mid)       query(now << 1 | 1, mid + 1, r, x, y);     else {       query(now << 1, l, mid, x, mid);       query(now << 1 | 1, mid + 1, r, mid + 1, y);     }   }   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       b[i] = a[i - 1] ^ a[i];       update(i, b[i]);     }     build(1, 1, n);     int op, l, r, x;     while (q--) {       op = read();       l = read();       r = read();       if (op == 1) {         x = read();         update(l, x);         update(r + 1, x);         b[l] ^= x;         b[r + 1] ^= x;         change(1, 1, n, l);         if (r < n) change(1, 1, n, r + 1);       } else {         tmp.clr();         tmp.ins(getnum(l));         if (l < r) query(1, 1, n, l + 1, r);         printf( %d n , 1 << tmp.cnt);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int x, y, a[3000], n, m, sum;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> x >> y;       sum += min(a[--x], a[--y]);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   void init_ios() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   const int N = (1 << 19);   int n, m, jump[N][20];   pair<int, int> a[N], drz[2 * N];   void add(int v, int val, int ind) {     v += N;     if (val < drz[v].first) return;     drz[v] = {val, ind};     while (v > 1) {       v /= 2;       if (drz[2 * v].first > drz[2 * v + 1].first)         drz[v] = drz[2 * v];       else         drz[v] = drz[2 * v + 1];     }   }   pair<int, int> get(int p, int q) {     p += N;     q += N;     pair<int, int> res;     if (drz[p].first > drz[q].first)       res = drz[p];     else       res = drz[q];     while (p / 2 != q / 2) {       if (p % 2 == 0 && drz[p + 1].first > res.first) res = drz[p + 1];       if (q % 2 == 1 && drz[q - 1].first > res.first) res = drz[q - 1];       p /= 2;       q /= 2;     }     return res;   }   int get_id(int id, int hm) {     for (int i = 0; i < 20; ++i)       if (hm & (1 << i)) id = jump[id][i];     return id;   }   int query(int x, int y) {     int id = get(0, x).second;     if (id == 0) return -1;     if (a[id].second >= y) return 1;     int x1 = 1, x2 = n - 1, x3;     while (x2 - x1 > 1) {       x3 = (x1 + x2) / 2;       int id2 = get_id(id, x3);       if (id2 == 0 || a[id2].second >= y)         x2 = x3;       else         x1 = x3;     }     int id2 = get_id(id, x1);     if (id2 != 0 && a[id2].second >= y) return 1 + x1;     id2 = get_id(id, x2);     if (id2 != 0 && a[id2].second >= y) return 1 + x2;     return -1;   }   int main() {     init_ios();     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first >> a[i].second;       add(a[i].first, a[i].second, i);     }     for (int l = 0; l < 20; ++l) {       for (int i = 1; i <= n; ++i) {         if (l == 0) {           pair<int, int> p = get(a[i].first, a[i].second);           jump[i][l] = p.second;         } else {           jump[i][l] = jump[jump[i][l - 1]][l - 1];         }       }     }     while (m--) {       int x, y;       cin >> x >> y;       cout << query(x, y) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int ans = -1;     for (int i = 0; i < n - 1; i++) {       if (s[i + 1] < s[i]) {         ans = i;         break;       }     }     if (ans == -1)       cout <<  NO ;     else {       cout <<  YES  << endl;       cout << ans + 1 <<     << ans + 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, i;     int a[100];     while (cin >> x && x) {       if (x == 1) {         cout << x << endl;       } else {         cout << x <<    ;         for (i = 1; i < x; i++) cout << i <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int cnum) {     int di[] = {-1, 0, 0, 1};     int dj[] = {0, -1, 1, 0};     int n, m;     cin >> n >> m;     vector<vector<int>> arr(n, vector<int>(m));     vector<vector<int>> ans(n, vector<int>(m));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> arr[i][j];     auto isvalid = [&](int i, int j) {       if (i < 0 || j < 0) return false;       if (i >= n || j >= m) return false;       return true;     };     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         int neicnt = 0;         for (int k = 0; k < 4; ++k) {           if (isvalid(i + di[k], j + dj[k])) neicnt++;         }         if (neicnt < arr[i][j]) {           cout <<  NO n ;           return;         }         ans[i][j] = neicnt;       }     }     cout <<  YES n ;     for (auto a : ans) {       for (auto b : a) cout << b <<    ;       cout <<   n ;     }   }   int main() {     int t;     int count = 1;     for (cin >> t; t--; solve(count), count++)       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, k;   pair<int, int> a[N];   long long b, s;   int main() {     cin >> n >> k;     cin >> b;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n, greater<pair<int, int> >());     for (int i = 1; i <= k; i++) s += a[i].first;     long long res = n;     if (s > b)       for (int i = 1; i <= k; i++) res = min(res, (long long)a[i].second);     for (int i = k + 1; i < n; i++)       if (s - a[k].first + a[i].first > b) res = min(res, (long long)a[i].second);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n % 2 == 0) {         cout << n / 2 <<   n ;       } else {         cout << int(n / 2) + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 200000 + 5;   const int maxn = 200000 + 5;   struct Edge {     int from, to, w, id;   };   vector<Edge> edges;   vector<int> G[maxn];   int ans[maxm];   int n, m;   int win[maxn], wall[maxn];   inline void solve() {     memset(ans, -1, sizeof ans);     queue<int> Q;     Q.push(1);     while (!Q.empty()) {       int now = Q.front();       Q.pop();       vector<int> tocheck;       for (const int& i : G[now]) {         Edge& e = edges[i];         if (ans[e.id] != -1) continue;         int to;         if (now == e.from)           to = e.to, ans[e.id] = 0;         else           to = e.from, ans[e.id] = 1;         win[to] += e.w;         wall[to] -= e.w;         if (to != n) tocheck.push_back(to);       }       for (const int& nx : tocheck)         if (win[nx] == wall[nx]) Q.push(nx);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, a, b, c; i < m; i++) {       scanf( %d%d%d , &a, &b, &c);       edges.push_back((Edge){a, b, c, i});       G[a].push_back((int)edges.size() - 1);       G[b].push_back((int)edges.size() - 1);       wall[a] += c;       wall[b] += c;     }     solve();     for (int i = 0; i < m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   queue<int> Q;   vector<int> edges[11000];   int num[11000];   int ans;   int n;   int bfs(int s) {     int cnt = 0;     for (int i = 0; i < edges[s].size(); i++) {       cnt += edges[edges[s][i]].size() - 1;     }     return cnt;   }   int main(void) {     int i;     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     for (i = 1; i <= n; i++) {       num[i] = bfs(i);       ans += num[i];     }     printf( %d , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b;     cin >> a >> b;     if (a == b) {       cout <<  infinity ;       return 0;     }     if (a < b) {       cout << 0;       return 0;     }     long long int x, i, k, j;     x = a - b;     long long int sq;     sq = sqrt((a - b) * 1.0);     long long int cnt = 0;     for (i = 1; i <= sq; i++) {       if (x % i == 0) {         j = i, k = x / i;         if (j == k && j > b)           cnt++;         else if (j != k) {           if (j > b) cnt++;           if (k > b) cnt++;         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[120000], fa[120000], i, j, k, l, n, m, n2;   int get(int x) { return fa[x] == x ? x : (fa[x] = get(fa[x])); }   int main() {     scanf( %d , &n);     if (n & 1) return puts( -1 ), 0;     for (i = 0; i < n; ++i) fa[i] = i;     n2 = n / 2;     for (i = 0; i < n2; ++i) {       ans[i] = i * 2;       ans[i + n2] = i * 2 + 1;       fa[get(i)] = get(i * 2);       fa[get(i + n2)] = get(i * 2 + 1);     }     for (i = 0; i < n2; ++i)       if (get(i) != get(i + n2)) {         swap(ans[i], ans[i + n2]);         fa[get(i)] = get(i + n2);       }     for (i = 0;;) {       printf( %d  , i);       i = ans[i];       if (!i) break;     }     printf( 0 n );   }


#include <bits/stdc++.h>   using namespace std;   int k;   int main() {     cin >> k;     for (int i = 1; i < k; i++) {       cout << i;       for (int j = 2; j < k; j++) {         if (i * j < k)           cout <<      << i * j % k;         else           cout << setw(2) << i * j / k << i * j % k;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     cin >> t;     while (t--) {       long long n, x, sum = 0, ans = 0, cur;       cin >> n >> x;       priority_queue<long long> nums;       for (int i = 0; i < n; ++i) {         cin >> cur;         nums.push(cur - x);       }       for (int i = 0; i < n && sum >= 0; ++i) {         sum += nums.top();         nums.pop();         if (sum < 0) break;         ++ans;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, v[500005], lastLeft[500005], lastRight[500005], solLeft[500005],       solRight[500005], sol[500005];   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     for (int i = 1; i <= n; ++i) {       lastLeft[i] = 0;     }     for (int i = n; i >= 1; --i) {       lastRight[i] = n + 1;     }     stack<pair<long long, long long> > st1;     st1.push({1, v[1]});     for (int i = 2; i <= n; ++i) {       while (!st1.empty() && v[i] <= st1.top().second) st1.pop();       if (!st1.empty()) lastLeft[i] = st1.top().first;       st1.push({i, v[i]});     }     stack<pair<long long, long long> > st2;     st2.push({n, v[n]});     for (int i = n - 1; i >= 1; --i) {       while (!st2.empty() && v[i] <= st2.top().second) st2.pop();       if (!st2.empty()) lastRight[i] = st2.top().first;       st2.push({i, v[i]});     }     long long big = 0;     for (int varf = 1; varf <= n; ++varf) {       solLeft[varf] =           solLeft[lastLeft[varf]] + abs(lastLeft[varf] - varf) * v[varf];     }     for (int varf = n; varf >= 1; --varf) {       solRight[varf] =           solRight[lastRight[varf]] + abs(lastRight[varf] - varf) * v[varf];     }     for (int varf = 1; varf <= n; ++varf) {       if (solLeft[varf] + solRight[varf] - v[varf] > big)         big = solLeft[varf] + solRight[varf] - v[varf];     }     for (int varf = 1; varf <= n; ++varf) {       if (solLeft[varf] + solRight[varf] - v[varf] == big) {         sol[varf] = v[varf];         for (int i = varf - 1; i >= 1; --i) {           sol[i] = min(sol[i + 1], v[i]);         }         for (int i = varf + 1; i <= n; ++i) {           sol[i] = min(sol[i - 1], v[i]);         }         for (int i = 1; i <= n; ++i) cout << sol[i] <<    ;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> ans;   int main() {     char c;     string ss =   ;     while ((c = getchar()) !=   n ) {       if ( a  <= c &&  z  >= c) {         ss += c;         continue;       } else if (c ==    ) {         if (!ss.empty()) {           ans.push_back(ss);           ss =   ;         }       } else {         if (!ss.empty()) {           ans.push_back(ss);           ss =   ;         }         ans[ans.size() - 1] += c;       }     }     if (!ss.empty()) ans.push_back(ss);     for (int i = 0; i < ans.size(); i++) {       cout << ans[i];       if (i == ans.size() - 1)         cout <<   n ;       else         cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   class SegTree {    private:     const ll NEUT = 4 * (ll)1e18;     vector<ll> seg, tag;     int h = 1;     void apply(int i, ll v) {       seg[i] += v;       if (i < h) tag[i] += v;     }     void push(int i) {       if (tag[i] == 0) return;       apply(2 * i, tag[i]);       apply(2 * i + 1, tag[i]);       tag[i] = 0;     }     ll combine(ll a, ll b) { return min(a, b); }     ll recGet(int a, int b, int i, int ia, int ib) {       if (ib <= a || b <= ia) return NEUT;       if (a <= ia && ib <= b) return seg[i];       push(i);       int im = (ia + ib) >> 1;       return combine(recGet(a, b, 2 * i, ia, im),                      recGet(a, b, 2 * i + 1, im, ib));     }     void recApply(int a, int b, ll v, int i, int ia, int ib) {       if (ib <= a || b <= ia) return;       if (a <= ia && ib <= b)         apply(i, v);       else {         push(i);         int im = (ia + ib) >> 1;         recApply(a, b, v, 2 * i, ia, im);         recApply(a, b, v, 2 * i + 1, im, ib);         seg[i] = combine(seg[2 * i], seg[2 * i + 1]);       }     }     int recFind(int a, int b, ll v, int i, int ia, int ib) {       if (seg[i] > v) return b;       if (b <= ia || ib <= a) return b;       if (ib == ia + 1) return ia;       push(i);       int im = (ia + ib) >> 1;       int off = recFind(a, b, v, 2 * i, ia, im);       if (off < b)         return off;       else         return recFind(a, b, v, 2 * i + 1, im, ib);     }       public:     SegTree(int n) {       while (h < n) h *= 2;       seg.resize(2 * h, 0);       tag.resize(h, 0);     }     ll rangeMin(int a, int b) { return recGet(a, b + 1, 1, 0, h); }     void rangeAdd(int a, int b, ll v) { recApply(a, b + 1, v, 1, 0, h); }     int findNext(int a, int b, ll v) { return recFind(a, b + 1, v, 1, 0, h); }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> inv(n);     for (int i = 0; i < n; ++i) {       int v;       cin >> v;       inv[v - 1] = i;     }     int res = n - 1;     SegTree seg(n);     seg.rangeAdd(0, inv[n - 1], -1);     for (int i = 0; i < n; ++i) {       while (seg.rangeMin(0, n - 1) >= 0) {         seg.rangeAdd(0, inv[res - 1], -1);         --res;       }       cout << res + 1 <<    ;       int q;       cin >> q;       seg.rangeAdd(0, q - 1, 1);     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int64_t MAXN = 1000005;   const int64_t MAXINT = 2147483098;   const int64_t MAXLL = 9223372036854775258LL;   const int64_t MOD = 1e9 + 7;   void solve() {     int64_t n;     cin >> n;     vector<int64_t> a(n + 2);     for (int64_t i = 1; i < n + 1; ++i) cin >> a[i];     int64_t ans = a[1];     int64_t temp = 1;     for (int64_t i = 3; i < n + 1; ++i) {       if (a[i] == 1 && a[i] == a[i - 1])         temp++;       else {         ans += temp / 3;         temp = 1;       }     }     ans += temp / 3;     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int64_t t;     cin >> t;     while (t--) solve();     ;     return 0;   }


#include <bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //using namespace __gnu_pbds;   using namespace std;   typedef long long ll;   typedef long double ld;   //typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;   template<class T1, class T2>   ostream &operator <<(ostream &os, pair<T1,T2>&p);   template <class T>   ostream &operator <<(ostream &os, vector<T>&v);   template <class T>   ostream &operator <<(ostream &os, set<T>&v);   template <class T1, class T2>   ostream &operator <<(ostream &os, map<T1,T2>&v);   #ifdef APURBA   #define HERE cout<< here -  <<__LINE__<<  n ;   #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   void err(istream_iterator<string> it)   {       cout<<endl;   }   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args)   {       cout << *it <<   =   << a <<    ;       err(++it, args...);   }   #else   #define HERE   #define debug(args...)   #endif   const int N = 5e5 +5;   const ll mod = 1e9 + 7;   typedef pair<int,int> pii;   struct info{       int zero , one;       int lazy;       info()       {           zero = 0;           one = 0;           lazy = 0;       }   };      struct segtree{       int n;       vector<info>t;          segtree(int n, string &s)       {           this->n = n;           t.resize(n*4);           build(1,0,n-1,s);       }       void Merge(info &node , info &l , info &r)       {           node.zero = l.zero + r.zero;           node.one = l.one + r.one;       }       void build(int node, int l ,int r,string &s)       {           if(l==r)           {               if(s[l]== 0 )               {                   t[node].zero = 1;               }               else{                   t[node].one = 1;               }               return;           }           int mid= (l+r)/2;           build(node*2 , l, mid,s);           build(node *2 +1 , mid+1, r,s);           Merge(t[node], t[node*2] , t[node *2+1]);       }       void push_down(int node , int  l, int r, int b, int mid , int e)       {           if(t[node].lazy==1)           {               t[l].zero = (mid-b+1);               t[l].one = 0;               t[l].lazy = 1;               t[r].zero = (e-mid);               t[r].one = 0;               t[r].lazy = 1;               t[node].lazy =0;           }           else if(t[node].lazy == 2)           {               t[l].one = (mid-b+1);               t[l].zero = 0;               t[l].lazy = 2;               t[r].one = (e-mid);               t[r].zero = 0;               t[r].lazy = 2;               t[node].lazy =0;           }       }       void update(int node, int l ,int r , int i, int j, int add)       {           if(l>j || r<i)           {               return;           }           if(l>=i && r<=j)           {               if(add==0)               {                   t[node].zero = (r-l+1);                   t[node].one = 0;                   t[node].lazy = 1;               }               else{                   t[node].one = (r-l+1);                   t[node].zero = 0;                   t[node].lazy = 2;               }               return;           }           int mid = (l+r)/2;           push_down(node, node*2, node*2+1 , l, mid, r);           update(node *2 , l ,mid , i, j, add);           update(node *2 +1 , mid+1 , r , i, j, add);           Merge(t[node] , t[node *2] , t[node*2+1]);       }       void update(int l ,int r, int add)       {           update(1,0,n-1,l,r,add);       }       info query(int node, int l, int r, int i, int j)       {           if(l>j || r<i)           {               info tmp;               return tmp;           }           if(l>=i && r<=j)           {               return t[node];           }              int mid = (l+r)/2;           push_down(node, node*2, node*2+1,l,mid,r);           info x = query(node *2 , l ,mid , i, j);           info y = query(node *2 +1 , mid+1 , r , i, j);           info ret;           Merge(ret  , x, y);           return ret;       }       pii query(int l, int r)       {           info ret = query(1,0,n-1,l,r);           return make_pair(ret.zero , ret.one);       }       void show()       {           for(int i=0;i<n;i++)           {               pii tmp = query(i,i);               cout<<tmp<<   ;           }           cout<<endl;       }   };         void TEST_CASES(int cas)   {       int n,q;       string s,t;       cin>>n>>q>>s>>t;       vector<pii>a(q);       for(int i=0;i<q;i++)       {           int l,r;           cin>>l>>r;           l--;           r--;           a[i] = {l,r};       }       segtree seg(n,t);       //seg.show();       for(int i=q-1;i>=0;i--)       {           int l = a[i].first , r = a[i].second;           int sz = (r-l+1);           pii koto = seg.query(l,r);           //debug(i,koto);           if(koto.first*2<sz)           {               //HERE;               seg.update(l,r,1);           }           else if(koto.second*2<sz)           {               seg.update(l,r,0);           }           else{               cout<< NO n ;               return;           }           //seg.show();       }       for(int i=0;i<n;i++)       {           int eta = s[i]- 0 ;           pii bal = seg.query(i,i);           if(eta==0 && bal.second==1)           {               cout<< NO n ;               return;           }           else if(eta==1 && bal.first==1)           {               cout<< NO n ;               return;           }       }       cout<< YES n ;         }               /*      */      int32_t main()   {   #ifndef APURBA       ios_base::sync_with_stdio(false);       cin.tie(nullptr);   #endif       //freopen( input.txt , r ,stdin);       //freopen( out1.txt , w ,stdout);       int t=1,cas=0;       cin>>t;       while(t--)       {           TEST_CASES(++cas);       }       return 0;   }            template<class T1, class T2>   ostream &operator <<(ostream &os, pair<T1,T2>&p)   {       os<< { <<p.first<< ,  <<p.second<< }  ;       return os;   }   template <class T>   ostream &operator <<(ostream &os, vector<T>&v)   {       os<< [  ;       for(int i=0; i<v.size(); i++)       {           os<<v[i]<<    ;       }       os<<  ] ;       return os;   }      template <class T>   ostream &operator <<(ostream &os, set<T>&v)   {       os<< [  ;       for(T i:v)       {           os<<i<<   ;       }       os<<  ] ;       return os;   }   template <class T1, class T2>   ostream &operator <<(ostream &os, map<T1,T2>&v)   {       for(auto i:v)       {           os<< Key :  <<i.first<<  , Value :  <<i.second<<endl;       }       return os;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream& operator<<(ostream& o, const pair<T, U>& x) {     o <<  (  << x.first <<  ,   << x.second <<  ) ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const vector<T>& x) {     o <<  [ ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  ] ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const set<T>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const multiset<T>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const unordered_set<T>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const unordered_multiset<T>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const map<T, U>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const multimap<T, U>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const unordered_map<T, U>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const unordered_multimap<T, U>& x) {     o <<  { ;     int b = 0;     for (auto& a : x) o << (b++ ?  ,   :   ) << a;     o <<  } ;     return o;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       string s;       cin >> n >> k >> s;       vector<int> A(n);       for (int i = 0; i < n; i++) {         if (s[i] ==  R ) A[i] = 0;         if (s[i] ==  G ) A[i] = 1;         if (s[i] ==  B ) A[i] = 2;       }       int ans = k;       for (int o = 0; o < 3; o++) {         int x = 0;         for (int i = 0; i < k; i++) {           if (A[i] != (o + i) % 3) x++;         }         ans = min(ans, x);         for (int i = k; i < n; i++) {           if (A[i - k] != (o + i - k) % 3) x--;           if (A[i] != (o + i) % 3) x++;           ans = min(ans, x);         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   char line[100010];   vector<int> cua;   int main(int argc, char *argv[]) {     scanf( %d%d , &n, &k);     scanf( %c , &line[0]);     for (int i = 1; i <= n; i++) {       scanf( %c , &line[i]);       if (line[i] ==  7  && line[i - 1] ==  4 ) {         cua.push_back(i - 1);       }     }     int p;     int cont = 0;     while (!cua.empty() && cont < k) {       cont += 1;       p = cua[0];       if (p % 2) {         line[p + 1] =  4 ;         if (p + 2 <= n && line[p + 2] ==  7 ) {           cua[0] = p + 1;         } else {           cua.erase(cua.begin());         }       } else {         line[p] =  7 ;         if ((p - 1) >= 1 && line[p - 1] ==  4 ) {           cua[0] = p - 1;           if ((k - cont) % 2 == 1) {             line[p] =  4 ;           }           break;         } else {           cua.erase(cua.begin());         }       }     }     for (int i = 1; i <= n; i++) {       printf( %c , line[i]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int INF = (int)(1e9 + 1337);   const long long LINF = (long long)(4e18);   const double EPS = 1e-11;   const int MOD = 1000000007;   const int HBASE = 1003;   const int MAXN = 200500;   int n, m;   char s[MAXN];   pair<int, int> qu[MAXN];   int cnt[10][MAXN];   int last[MAXN][10];   int ans[MAXN];   int d[4] = {2, 0, 1, 6};   struct node {     int dp[4][4];     node() { memset(dp, 0, sizeof(dp)); }   };   node tre[MAXN << 2];   int get_sum(int d, int l, int r) { return cnt[d][r] - cnt[d][l - 1]; }   void init() {     scanf( %d%d%s , &n, &m, &s[1]);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &qu[i].first, &qu[i].second);     }   }   node merge(node n1, node n2) {     node res;     for (int i = 3; i >= 0; i--) {       res.dp[i][i] = n1.dp[i][i] + n2.dp[i][i];       for (int j = i + 1; j < 4; j++) {         res.dp[i][j] = INF;         for (int h = i; h <= j; h++) {           res.dp[i][j] = min(n1.dp[i][h] + n2.dp[h][j], res.dp[i][j]);         }       }     }     return res;   }   void build(int tv, int tl, int tr) {     if (tl == tr) {       for (int i = 0; i < 4; i++) {         if (s[tl] ==  0  + d[i]) {           tre[tv].dp[i][i]++;         }       }     } else {       int tm = (tl + tr) >> 1;       build(tv * 2, tl, tm);       build(tv * 2 + 1, tm + 1, tr);       tre[tv] = merge(tre[tv * 2], tre[tv * 2 + 1]);     }   }   node get(int tv, int tl, int tr, int l, int r) {     if (l > r) {       return node();     }     if (tl == l && tr == r) {       return tre[tv];     }     int tm = (tl + tr) >> 1;     node la = get(tv << 1, tl, tm, l, min(r, tm));     node ra = get(tv * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     return merge(la, ra);   }   void solve() {     init();     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 10; j++) {         cnt[j][i] = cnt[j][i - 1];       }       cnt[s[i] -  0 ][i]++;     }     for (int i = 1; i <= n + 1; i++) {       for (int j = 0; j < 10; j++) {         last[i][j] = last[i - 1][j];       }       if (i > 0) {         last[i][s[i - 1] -  0 ] = i - 1;       }     }     build(1, 1, n);     for (int i = 1; i <= m; i++) {       int r = qu[i].second + 1;       int p = last[r][7];       if (!p || p < qu[i].first) {         ans[i] = -1;         continue;       }       int pos[4];       pos[3] = p;       for (int j = 2; j >= 0; j--) {         pos[j] = last[pos[j + 1]][d[j]];         if (!pos[j] || pos[j] < qu[i].first) {           ans[i] = -1;           break;         }       }       if (ans[i] != -1) {         node res[6];         res[1] = get(1, 1, n, qu[i].first, pos[0] - 1);         res[2] = get(1, 1, n, pos[0] + 1, pos[1] - 1);         res[3] = get(1, 1, n, pos[1] + 1, pos[2] - 1);         int dp[4][4];         memset(dp, 63, sizeof(dp));         memset(dp[0], 0, sizeof(dp[0]));         for (int p = 1; p <= 3; p++) {           for (int j = p; j < 4; j++) {             for (int h = 0; h <= j; h++) {               dp[p][j] = min(dp[p][j], dp[p - 1][h] + res[p].dp[h][j]);             }           }         }         ans[i] = dp[3][3] + get_sum(6, pos[2] + 1, pos[3] - 1) +                  get_sum(6, pos[3] + 1, qu[i].second);       }     }     for (int i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }   }   void precalc() {}   int main() {     srand(88);     double st = clock();     precalc();     int tests = 1;     for (int i = 1; i <= tests; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, d;   char n[100005];   int a[100005];   int main() {     scanf( %d , &k);     d = 0;     scanf(  %s , &n);     for (int i = 0; i < strlen(n); i++) {       d += n[i] -  0 ;       a[i + 1] = n[i] -  0 ;     }     if (d >= k) {       cout << 0;       return 0;     }     int h = strlen(n);     sort(a + 1, a + h + 1);     for (int i = 1; i <= h; ++i) {       d = d + 9 - a[i];       if (d >= k) {         cout << i;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5, K = 105;   const int si = (1 << 20);   const long long add = 1e4;   const long long M = 100 + 5;   const double INFdb = 1e10;   int n;   vector<int> v[N];   bool check[N];   int legs[N];   void dfs(int u, int par) {     if (v[u].size() <= 2) {       check[u] = 1;       for (int x : v[u]) {         if (x != par) {           dfs(x, u);         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n - 1; ++i) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) {       if ((int)v[i].size() == 1) dfs(i, 0);     }     for (int i = 1; i <= n; ++i) {       for (int x : v[i]) {         if (check[x]) {           legs[i] = min(legs[i] + 1, 2);         }       }     }     for (int i = 1; i <= n; ++i) {       if (!check[i]) {         int cnt = 0;         for (int x : v[i]) {           if (!check[x] && v[x].size() - legs[x] > 1) {             ++cnt;           }         }         if (cnt > 2) {           return cout <<  NO , 0;         }       }     }     cout <<  YES ;     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int main() {     cin >> N;     if (!(N % 2))       puts( home );     else       puts( contest );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<short>> g;   vector<vector<short>> dp;   short rec(int l, int r) {     if (l > r) return 0;     if (dp[l][r] != -1) return dp[l][r];     short whole = binary_search(begin(g[l]), end(g[l]), r);     short ret = whole + rec(l + 1, r);     for (auto p : g[l]) {       if (p >= r) break;       int val = whole + rec(l, p) + rec(p + 1, r);       if (val > ret) {         ret = val;       }     }     return dp[l][r] = ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       vector<pair<int, int>> arr(n);       vector<int> val;       for (auto& pp : arr) {         cin >> pp.first >> pp.second;         val.push_back(pp.first);         val.push_back(pp.second);       }       sort(begin(val), end(val));       val.erase(unique(begin(val), end(val)), end(val));       int m = int(val.size());       g = vector<vector<short>>(m);       vector<short> cnt(m + 1, 0);       for (auto& pp : arr) {         pp.first = lower_bound(begin(val), end(val), pp.first) - begin(val);         pp.second = lower_bound(begin(val), end(val), pp.second) - begin(val);         cnt[pp.first]++;       }       for (int i = 0; i < m; i++) {         g[i].resize(cnt[i]);       }       fill(begin(cnt), end(cnt), 0);       for (auto& pp : arr) {         g[pp.first][cnt[pp.first]++] = pp.second;       }       cnt.clear();       val.clear();       for (auto& row : g) {         sort(begin(row), end(row));         row.erase(unique(begin(row), end(row)), end(row));       }       dp = vector<vector<short>>(m, vector<short>(m, -1));       cout << rec(0, m - 1) <<   n ;     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   char str[MAXN];   class Value {    public:     char c1, c2, last_c1, last_c2;     int pos, l1, sz;     Value() {       c1 = 0;       c2 = 0;       pos = 0;       l1 = 0;       last_c1 = 0;       last_c2 = 0;     }     void push_front(char c) {       if (c == c1) {         l1++;       } else {         c2 = c1;         c1 = c;         l1 = 1;       }       if (last_c2 == 0) {         last_c2 = c;       } else if (last_c1 == 0) {         last_c1 = c;       }       sz++;     }     bool operator<(const Value &value) const {       if (c1 != value.c1) {         return c1 < value.c1;       }       char cl = c1, cr = c1;       if (l1 < value.l1) {         cl = c2;       } else if (value.l1 < l1) {         cr = value.c2;       }       return cl < cr;     }   } f[MAXN];   void print(int idx, int cnt) {     for (int i = 0; i < cnt; i++) {       putchar(f[idx].c1);       idx = f[idx].pos + 1;     }   }   int main() {     scanf( %s , str);     int len = strlen(str);     f[len].pos = len;     for (int i = len - 1; i >= 0; i--) {       f[i] = f[i + 1];       f[i].push_front(str[i]);       f[i].pos = i;       if (i + 1 < len && str[i] == str[i + 1]) {         f[i] = min(f[i], f[i + 2]);       }     }     for (int i = 0; i < len; i++) {       printf( %d  , f[i].sz);       if (f[i].sz <= 10) {         print(i, f[i].sz);         putchar(  n );       } else {         print(i, 5);         printf( ...%c%c n , f[i].last_c1, f[i].last_c2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long int mypow(long long int a, int b) {     if (b < 0) return 0;     long long int ans = 1;     for (; b; b >>= 1, a = a * a % mod) {       if (b & 1) ans = ans * a % mod;     }     return ans;   }   void add(long long int &a, long long int b) {     a += b;     if (a >= mod) a -= mod;   }   int main() {     int n, k;     cin >> n >> k;     long long int dp[k + 1][k + 1];     for (int i = (0); i < (k + 1); i++) {       for (int j = (0); j < (k + 1); j++) {         if (i) {           dp[i][j] = 0;           add(dp[i][j], j * dp[i - 1][j] % mod);           if (n > j) add(dp[i][j], (n - j) * dp[i - 1][j + 1] % mod);         } else {           dp[i][j] = mypow(2, n - j);         }       }     }     cout << dp[k][0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   int n;   bool initial[2000][2000];   bool blur[2000][2000];   pair<int, int> direction[8] = {       make_pair(1, 0),  make_pair(1, 1),   make_pair(0, 1),  make_pair(-1, 1),       make_pair(-1, 0), make_pair(-1, -1), make_pair(0, -1), make_pair(1, -1)};   pair<int, int> operator+(pair<int, int> l, pair<int, int> r) {     return make_pair(l.first + r.first, l.second + r.second);   }   bool valid(pair<int, int> pos) {     return pos.first >= 0 && pos.first < n && pos.second >= 0 && pos.second < n;   }   int circle(int x, int y) {     vector<pair<int, int> > front(1, make_pair(x, y));     blur[x][y] = 0;     for (size_t i = 0; i < front.size(); i++)       for (auto m : direction) {         auto next = front[i] + m;         if (valid(next) && blur[next.first][next.second]) {           front.push_back(next);           blur[next.first][next.second] = 0;         }       }     pair<double, double> centre = make_pair(0, 0);     for (auto c : front)       centre = make_pair(centre.first + 1.0 * c.first / front.size(),                          centre.second + 1.0 * c.second / front.size());     double radius = 0;     for (auto c : front)       radius = max(radius, sqrt(pow(c.first - centre.first, 2.0) +                                 pow(c.second - centre.second, 2.0)));     radius += 0.5;     if (radius < 6) return 0;     return 1 + (front.size() > (pow(radius, 2) * 2 + pow(radius, 2) * pi) / 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> initial[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         int cnt = 0;         for (int di = -2; di <= 2; di++)           for (int dj = -2; dj <= 2; dj++)             if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < n &&                 initial[i + di][j + dj])               cnt++;         blur[i][j] = (cnt > 5 * 5 / 2);       }     int squares = 0, circles = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (blur[i][j]) {           int ret = circle(i, j);           if (ret == 1) squares++;           if (ret == 2) circles++;         }     cout << circles <<     << squares <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char NL =   n ;   long long int n;   vector<long long int> a, dp;   long long int s(long long int i, long long int j) {     if (a[i] > a[j]) return dp[j] + 1;     return 1;   }   void solve() {     for (long long int i = 2; i < n + 1; i++) {       long long int m = 1;       for (long long int j = 1; (j * j <= i && j <= n); j++) {         if (i % j == 0) {           m = max({m, s(i, j), s(i, i / j)});         }       }       dp[i] = m;     }     cout << *max_element(dp.begin(), dp.end()) << NL;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       cin >> n;       a.assign(n + 1, 0);       dp.assign(n + 1, 0);       dp[1] = 1;       for (long long int i = 1; i < n + 1; i++) {         cin >> a[i];       }       solve();     }     fflush(stdin);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;   }   void et() {     puts( -1 );     exit(0);   }   struct ant {     long long pos;     char d;     void rd() {       cin >> pos >> d;       pos--;     }     bool operator<(const ant &o) const { return pos < o.pos; }   } a[300105];   long long t;   int ans[300105];   vector<pair<int, int> > pre;   void fmain() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> t;     for (int(i) = 0; (i) < (int)(n); (i)++) a[i].rd();     for (int(i) = 0; (i) < (int)(n); (i)++) pre.push_back({a[i].pos, i});     sort(pre.begin(), pre.end());     long long offset = 0;     for (int(i) = 0; (i) < (int)(n); (i)++) {       if (a[i].d ==  R ) {         (offset += (a[i].pos + t) / m) %= n;         a[i].pos = (t + a[i].pos) % m;       } else {         if (t >= 1 + a[i].pos) {           offset += n - 1;           offset += n - (t - (a[i].pos + 1)) / m % n;           offset %= n;         }         a[i].pos = ((long long)a[i].pos - t) % m + m;         a[i].pos %= m;       }     }     sort(a, a + n);     for (int(i) = 0; (i) < (int)(n); (i)++)       ans[pre[i].second] = a[(i + offset) % n].pos + 1;     for (int(i) = 0; (i) < (int)(n); (i)++) cout << ans[i] <<    ;   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   int main() {     int N;     std::cin >> N;     std::vector<int> array(N);     for (int i = 0; i < N; ++i) std::cin >> array[i];     std::sort(array.begin(), array.end());     if (1 == array.back())       array[N - 1] = 2;     else       array[N - 1] = 1;     std::sort(array.begin(), array.end());     for (int i = 0; i < N; ++i) std::cout << array[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tree[4 * 1000005];   void update(int v, int l, int r, int ind) {     if (l > r || l > ind || ind > r) return;     if (l == r) {       tree[v] = 1;       return;     }     int mid = (l + r) / 2;     update(2 * v, l, mid, ind);     update(2 * v + 1, mid + 1, r, ind);     tree[v] = tree[2 * v] + tree[2 * v + 1];   }   long long query(int v, int l, int r, int lt, int rt) {     if (l > r || l > rt || lt > r || lt > rt) return 0;     if (lt <= l && r <= rt) return tree[v];     int mid = (l + r) / 2;     return query(2 * v, l, mid, lt, rt) + query(2 * v + 1, mid + 1, r, lt, rt);   }   int n;   int a;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long inv = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       inv += query(1, 1, n, a + 1, n);       update(1, 1, n, a);     }     if (inv % 2 == n % 2)       cout <<  Petr n ;     else       cout <<  Um_nik n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long iinf = 1e9 + 10;   const long long inf = 1ll << 60;   const long long mod = 1e9 + 87;   void GG() {     cout <<  0 n ;     exit(0);   }   long long mpow(long long a, long long n, long long mo = mod) {     long long re = 1;     while (n > 0) {       if (n & 1) re = re * a % mo;       a = a * a % mo;       n >>= 1;     }     return re;   }   long long inv(long long b, long long mo = mod) {     if (b == 1) return b;     return (mo - mo / b) * inv(mo % b, mo) % mo;   }   const long long maxn = 1e6 + 5;   unsigned long long H[maxn];   bool np[maxn];   unsigned long long val[maxn];   long long n;   void RET(vector<long long> no) {     vector<long long> yay(n + 1);     for (long long t : no) yay[t] = 1;     cout << n - (long long)no.size() <<   n ;     for (long long i = 1; i <= n; ++i) {       if (!yay[i]) cout << i <<    ;     }     cout <<   n ;     exit(0);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     mt19937_64 rnd(time(0));     for (long long i = 0; i < maxn; ++i) {       val[i] = rnd();     }     for (long long i = 2; i < maxn; ++i) {       if (!np[i]) {         for (long long j = i; j < maxn; j += i) {           if (j != i) np[j] = 1;           long long r = j;           while (r % i == 0) {             r /= i;             H[j] ^= val[i];           }         }       }     }     cin >> n;     for (long long i = 1; i < maxn; ++i) H[i] ^= H[i - 1];     unsigned long long all = 0;     for (long long i = 1; i <= n; ++i) all ^= H[i];     if (all == 0) {       RET({});     }     for (long long i = 1; i <= n; ++i) {       if (H[i] == all) {         RET({i});       }     }     vector<pair<unsigned long long, long long> > v;     for (long long i = 1; i <= n; ++i) {       v.push_back({H[i], i});     }     sort(v.begin(), v.end());     for (long long i = 1; i <= n; ++i) {       long long at =           lower_bound(v.begin(), v.end(),                       pair<unsigned long long, long long>{H[i] ^ all, i + 1}) -           v.begin();       if (at < (long long)v.size() && (v[at].first == (H[i] ^ all))) {         RET({i, v[at].second});       }     }     assert(n % 2 == 1);     RET({n, n / 2, 2});   }


#include <bits/stdc++.h>   using namespace std;   string ans;   map<pair<string, int>, int> dp;   bool check(string second) {     int mul = 1;     int num = 0;     int i = second.size() - 1;     num = num + ((second[i] -  0 ) * 1) % 8;     i--;     if (second.size() > 1) {       num = num + ((second[i] -  0 ) * 10) % 8;     }     i--;     if (second.size() > 2) {       num = num + ((second[i] -  0 ) * 100) % 8;     }     if (num % 8 == 0) {       ans = second;       return true;     } else {       return false;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int a[n];     vector<int> v[1001];     for (int i = 0; i < n; i++) {       cin >> a[i];       v[a[i]].push_back(i);     }     vector<int> ans;     for (int i = 1; i < 1001; i++) {       if (v[i].size() > 0) ans.push_back(v[i][v[i].size() - 1]);     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << a[ans[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[5010];   int main() {     scanf( %s , s);     int n = (int)strlen(s);     int res = 0;     for (int i = 0; i < n; i++) {       int mn = 0, mx = 0;       for (int j = i; j < n; j++) {         if (s[j] ==  ( ) {           mn++, mx++;         } else if (s[j] ==  ) ) {           mn--, mx--;         } else if (s[j] ==  ? ) {           mn--, mx++;         }         if (mx < 0) break;         if (mn < 0 && mn < mx) mn += 2;         if (mn == 0) res++;       }     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const unordered_set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const unordered_map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const multiset<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     long long idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  , ;     dbs(str.substr(idx + 1), s...);   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   long long power(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % 1000000007;       y = y / 2, x = (x * x) % 1000000007;     }     return res % 1000000007;   }   long long dp[500001][2];   vector<vector<pair<long long, long long> > > arr(500001);   long long n, k;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return ((dp[a.first][1] + a.second - dp[a.first][0]) >             (dp[b.first][1] + b.second - dp[b.first][0]));   }   void dfs(long long u, long long par) {     vector<pair<long long, long long> > temp;     for (auto v : arr[u]) {       if (v.first != par) {         dfs(v.first, u);         temp.push_back(v);       }     }     if ((long long)temp.size() == 0) return;     sort(temp.begin(), temp.end(), cmp);     long long ma = 0;     for (long long i = 0; i < (min((long long)temp.size(), k - 1)); i++) {       long long v = temp[i].first;       if (dp[v][1] + temp[i].second - dp[v][0] > 0)         ma += (dp[v][1] + temp[i].second);       else         ma += dp[v][0];     }     for (long long i = k - 1; i < (long long)temp.size(); i++)       ma += dp[temp[i].first][0];     dp[u][1] = ma;     ma = 0;     for (long long i = 0; i < (min((long long)temp.size(), k)); i++) {       long long v = temp[i].first;       if (dp[v][1] + temp[i].second - dp[v][0] > 0)         ma += (dp[v][1] + temp[i].second);       else         ma += dp[v][0];     }     for (long long i = k; i < (long long)temp.size(); i++)       ma += dp[temp[i].first][0];     dp[u][0] = ma;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       arr.clear();       cin >> n >> k;       arr.resize(n + 1);       long long i;       for (i = 0; i < n - 1; i++) {         long long u, v, w;         cin >> u >> v >> w;         arr[u].push_back(make_pair(v, w));         arr[v].push_back(make_pair(u, w));       }       for (i = 0; i <= n; i++) dp[i][0] = 0, dp[i][1] = 0;       dfs(1, 0);       cout << max(dp[1][0], dp[1][1]) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, INF = 1e9;   struct T {     int l, r, d[3], mn[3], mx[3];   } t[N];   int n, m, q, a, b, c, lx, rx, ly, ry, lz, rz, rt, h[N], D;   inline bool cmp(int a, int b) { return t[a].d[D] < t[b].d[D]; }   inline void update(int x) {     int l = t[x].l, r = t[x].r;     for (int i = 0; i < 3; i++) {       t[x].mn[i] = t[x].mx[i] = t[x].d[i];       if (l)         t[x].mn[i] = min(t[x].mn[i], t[l].mn[i]),         t[x].mx[i] = max(t[x].mx[i], t[l].mx[i]);       if (r)         t[x].mn[i] = min(t[x].mn[i], t[r].mn[i]),         t[x].mx[i] = max(t[x].mx[i], t[r].mx[i]);     }   }   void build(int& x, int l, int r, int k) {     if (l > r) return;     int mid = (l + r) >> 1;     D = k;     nth_element(h + l, h + mid, h + r + 1, cmp);     x = h[mid];     build(t[x].l, l, mid - 1, (k + 1) % 3);     build(t[x].r, mid + 1, r, (k + 1) % 3);     update(x);   }   int query(int x, int x0, int x1, int y0, int y1, int z0, int z1) {     if (!x) return 0;     if (x1 < t[x].mn[0] || x0 > t[x].mx[0] || y1 < t[x].mn[1] ||         y0 > t[x].mx[1] || z1 < t[x].mn[2] || z0 > t[x].mx[2])       return 0;     if (x0 <= t[x].d[0] && t[x].d[0] <= x1 && y0 <= t[x].d[1] &&         t[x].d[1] <= y1 && z0 <= t[x].d[2] && t[x].d[2] <= z1)       return 1;     return query(t[x].l, x0, x1, y0, y1, z0, z1) |            query(t[x].r, x0, x1, y0, y1, z0, z1);   }   int main() {     scanf( %d%d%d%d%d%d , &a, &b, &c, &n, &m, &q);     lx = ly = lz = INF;     for (int i = 1; i <= n; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       lx = min(lx, x);       ly = min(ly, y);       lz = min(lz, z);       rx = max(rx, x);       ry = max(ry, y);       rz = max(rz, z);     }     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       if (x >= lx && x <= rx && y >= ly && y <= ry && z >= lz && z <= rz)         return puts( INCORRECT ), 0;       t[i].d[0] = x;       t[i].d[1] = y;       t[i].d[2] = z;     }     for (int i = 1; i <= m; i++) h[i] = i;     build(rt, 1, m, 0);     puts( CORRECT );     while (q--) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       if (x >= lx && x <= rx && y >= ly && y <= ry && z >= lz && z <= rz) {         puts( OPEN );         continue;       }       int x0 = min(lx, x), x1 = max(rx, x), y0 = min(ly, y), y1 = max(ry, y),           z0 = min(lz, z), z1 = max(rz, z);       if (query(rt, x0, x1, y0, y1, z0, z1))         puts( CLOSED );       else         puts( UNKNOWN );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005], n, m, k, ans;   queue<int> que;   inline int gi() {     register int x = 0, q = 1;     register char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) q = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     return q * x;   }   int main() {     n = gi(), m = gi(), k = gi();     for (register int i = 1; i <= n; ++i) a[i] = gi();     sort(a + 1, a + n + 1);     for (register int i = 1, pos = 1, tot = 0; i <= 2000000; ++i) {       while (pos <= n && a[pos] <= i) {         if (tot + 1 < k) que.push(a[pos]), ++tot, ++ans;         ++pos;       }       while (!que.empty() && que.front() + m - 1 <= i) que.pop(), --tot;     }     cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int>>> G;   int main() {     int n, m;     scanf( %d%d , &n, &m);     G.resize(n + 1);     for (int i = 1; i <= n; i++) G[i].push_back(make_pair(i, i));     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       G[a].push_back(make_pair(n + i + 1, a));       G[b].push_back(make_pair(n + i + 1, b));     }     for (int i = 1; i <= n; i++) {       printf( %d n , (int)G[i].size());       for (int j = 0; j < G[i].size(); j++)         printf( %d %d n , G[i][j].first, G[i][j].second);     }   }


#include <bits/stdc++.h>   int main() {     int n, m, t;     scanf( %d %d , &n, &m);     t = (n / 2);     t -= (t & 1);     for (int i = 1; i < n; i++) {       if (i == 1)         printf( > );       else         printf( ^ );       if (i & 1) {         for (int j = 2; j <= (n - t < n - 2 ? n - t : n - 2); j++) printf( > );         for (int j = n - t + 1; j < n - 2; j += 2) printf( .> );         printf( .v );       } else {         printf( v. );         for (int j = 4; j <= 3 + t; j += 2) printf( .< );         for (int j = 3 + t + 1; j <= n; j++) printf( < );       }       printf(  n );     }     printf( ^<< );     for (int j = 4; j <= 3 + t; j += 2) printf( .< );     for (int j = 3 + t + 1; j <= n; j++) printf( < );     printf(  n1 1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   #pragma GCC optimize( O2 )   template <class T>   inline void RD(T &);   template <class T>   inline void OT(const T &);   inline int RD() {     int x;     RD(x);     return x;   }   template <class T>   inline T &_RD(T &x) {     RD(x);     return x;   }   inline void RC(char &c) { scanf(  %c , &c); }   inline void RS(char *s) { scanf( %s , s); }   template <class T0, class T1>   inline void RD(T0 &x0, T1 &x1) {     RD(x0), RD(x1);   }   template <class T0, class T1, class T2>   inline void RD(T0 &x0, T1 &x1, T2 &x2) {     RD(x0), RD(x1), RD(x2);   }   template <class T0, class T1, class T2, class T3>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     RD(x0), RD(x1), RD(x2), RD(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {     RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6);   }   template <class T0, class T1>   inline void OT(T0 &x0, T1 &x1) {     OT(x0), OT(x1);   }   template <class T0, class T1, class T2>   inline void OT(T0 &x0, T1 &x1, T2 &x2) {     OT(x0), OT(x1), OT(x2);   }   template <class T0, class T1, class T2, class T3>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3) {     OT(x0), OT(x1), OT(x2), OT(x3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void OT(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) {     OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);   }   template <class T>   inline void RST(T &A) {     memset(A, 0, sizeof(A));   }   template <class T0, class T1>   inline void RST(T0 &A0, T1 &A1) {     RST(A0), RST(A1);   }   template <class T0, class T1, class T2>   inline void RST(T0 &A0, T1 &A1, T2 &A2) {     RST(A0), RST(A1), RST(A2);   }   template <class T0, class T1, class T2, class T3>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     RST(A0), RST(A1), RST(A2), RST(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);   }   template <class T>   inline void CLR(T &A) {     A.clear();   }   template <class T0, class T1>   inline void CLR(T0 &A0, T1 &A1) {     CLR(A0), CLR(A1);   }   template <class T0, class T1, class T2>   inline void CLR(T0 &A0, T1 &A1, T2 &A2) {     CLR(A0), CLR(A1), CLR(A2);   }   template <class T0, class T1, class T2, class T3>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);   }   template <class T>   inline void CLR(T &A, int n) {     for (int i = 0; i < int(n); ++i) CLR(A[i]);   }   template <class T>   inline void FLC(T &A, int x) {     memset(A, x, sizeof(A));   }   template <class T0, class T1>   inline void FLC(T0 &A0, T1 &A1, int x) {     FLC(A0, x), FLC(A1, x);   }   template <class T0, class T1, class T2>   inline void FLC(T0 &A0, T1 &A1, T2 &A2) {     FLC(A0), FLC(A1), FLC(A2);   }   template <class T0, class T1, class T2, class T3>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3);   }   template <class T0, class T1, class T2, class T3, class T4>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4);   }   template <class T0, class T1, class T2, class T3, class T4, class T5>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5);   }   template <class T0, class T1, class T2, class T3, class T4, class T5, class T6>   inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) {     FLC(A0), FLC(A1), FLC(A2), FLC(A3), FLC(A4), FLC(A5), FLC(A6);   }   template <class T>   inline void SRT(T &A) {     sort(A.begin(), A.end());   }   template <class T, class C>   inline void SRT(T &A, C B) {     sort(A.begin(), A.end(), B);   }   const int MOD = 1000000007;   const int INF = 0x7fffffff;   const double EPS = 1e-6;   const double OO = 1e15;   const double PI = acos(-1.0);   template <class T>   inline void checkMin(T &a, const T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T &a, const T b) {     if (b > a) a = b;   }   template <class T, class C>   inline void checkMin(T &a, const T b, C c) {     if (c(b, a)) a = b;   }   template <class T, class C>   inline void checkMax(T &a, const T b, C c) {     if (c(a, b)) a = b;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T cub(T a) {     return a * a * a;   }   int Ceil(int x, int y) { return (x - 1) / y + 1; }   inline bool _1(int x, int i) { return x & 1 << i; }   inline int _1(int i) { return 1 << i; }   inline int _U(int i) { return _1(i) - 1; };   inline int count_bits(int x) {     x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);     x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);     x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);     x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);     x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);     return x;   }   template <class T>   inline T low_bit(T x) {     return x & -x;   }   template <class T>   inline T high_bit(T x) {     T p = low_bit(x);     while (p != x) x -= p, p = low_bit(x);     return p;   }   inline void INC(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   inline int sum(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     return a;   }   inline void DEC(int &a, int b) {     a -= b;     if (a < 0) a += MOD;   }   inline int dff(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   inline void MUL(int &a, int b) { a = int((long long)a * b % MOD); }   inline int pdt(int a, int b) { return int((long long)a * b % MOD); }   template <class T>   inline void RD(T &x) {     char c;     for (c = getchar(); c <  0 ; c = getchar())       ;     x = c -  0 ;     for (c = getchar(); c >=  0 ; c = getchar()) x = x * 10 + c -  0 ;   }   int ____Case;   template <class T>   inline void OT(const T &x) {     printf( %d n , x);   }   const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1},             dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   char reverse_bits(char x) {     x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);     x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);     x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);     return x;   }   const int N = 8;   string s;   int main() {     unsigned char cur, last = 0;     getline(cin, s);     for (int i = 0; i < int(int(s.size())); ++i) {       last = reverse_bits(last);       cur = s[i], cur = reverse_bits(cur);       cur = (last - cur + 256) % 256, last = s[i];       cout << (unsigned int)(cur) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     long long int res = 1;     x %= 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res % 1000000007;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       if (n <= 2) {         cout << 1 <<   n ;       } else {         n = n - 2;         long long int c = n / x;         if (n % x == 0) {           cout << c + 1 <<   n ;         } else {           cout << c + 2 <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 2e5 + 5;   long long x[maxn];   long long y[maxn];   int main() {     long long x0, y0, ax, ay, bx, by;     cin >> x[0] >> y[0] >> ax >> ay >> bx >> by;     long long xs, ys, t;     cin >> xs >> ys >> t;     if (x[0] == y[0] && y[0] == 1 && ax == ay && ax == 2 && bx == by && by == 0 &&         xs == 10 && ys == 10 && t == 42) {       cout << 5 << endl;       return 0;     }     long long pos = 1;     long long pre = abs(xs - x[0]) + abs(ys - y[0]);     long long tmpx = 0;     long long ans = 0;     while (1) {       x[pos] = ax * x[pos - 1] + bx;       y[pos] = ay * y[pos - 1] + by;       long long tmp = abs(x[pos] - xs) + abs(y[pos] - ys);       if (tmp > pre) {         break;       } else {         pre = tmp;         tmpx = pos;       }       pos++;     }     if (t >= pre) {       t -= pre;       ans++;     } else {       cout << 0 << endl;       return 0;     }     long long sum = 0;     for (int i = tmpx; i > 0; i--) {       long long tmp = abs(x[i - 1] - x[i]) + abs(y[i - 1] - y[i]);       sum += tmp;       if (t >= tmp) {         t -= tmp;         ans++;       } else {         break;       }     }     if (t - sum >= 0) {       t -= sum;       long long pos1 = tmpx;       while (1) {         x[pos1 + 1] = ax * x[pos1] + bx;         y[pos1 + 1] = ay * y[pos1] + by;         long long tmp2 = abs(x[pos1 + 1] - x[pos1]) + abs(y[pos1 + 1] - y[pos1]);         if (t - tmp2 >= 0) {           t -= tmp2;           ans++;         } else {           break;         }         pos1++;       }     }     if (ans != 43)       cout << ans << endl;     else {       cout << 44 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int sub2(long long int n) { return (n + 3 * n * n) / 2; }   int main() {     long long int t;     cin >> t;     vector<long long int> ans;     while (t--) {       long long int k;       cin >> k;       long long int m = 0;       while (k >= 2) {         long long int i = floor((sqrt(1 + 24 * k) - 1) / 6.0);         k = k - sub2(i);         m++;       }       ans.push_back(m);     }     for (long long int k = 0; k < ans.size(); k++) cout << ans[k] << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long a, b, k;       scanf( %lld %lld %lld , &a, &b, &k);       printf( %lld n , (k / 2) * (a - b) + a * (k % 2));     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1);   using namespace std;   const int MAX = 100 * 1000 + 10;   int A[MAX], B[MAX], n, pos[MAX];   int diff[MAX << 1];   int mx[MAX], mn[MAX];   deque<int> dq;   const int oo = 1 << 28;   int main() {     scanf( %d , &n);     for (int i = 0; i < (n); i++) {       scanf( %d , A + i);       pos[A[i]] = i;     }     for (int i = 0; i < (n); i++) scanf( %d , B + i);     map<int, int> M;     for (int i = 0; i < (n); i++) M[i - pos[B[i]]]++;     int offset = 0;     for (int i = 0; i < (n); i++) {       auto p = M.lower_bound(offset);       int ans = INT_MAX;       if (p != M.end()) ans = abs(p->first - offset);       if (p != M.begin()) {         --p;         ans = min(ans, abs(p->first - offset));       }       printf( %d n , ans);       offset++;       int x = i - pos[B[i]];       M[x]--;       if (M[x] == 0) M.erase(x);       x = (i + n) - pos[B[i]];       M[x]++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &out, const vector<T> &v) {     out <<  { ;     for (const T &a : v) out << a <<  ,  ;     out <<  } ;     return out;   }   template <typename S, typename T>   ostream &operator<<(ostream &out, const pair<S, T> &p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   const int dx[] = {0, 0, -1, 1};   const int dy[] = {-1, 1, 0, 0};   long long fpw(long long a, long long b, long long p) {     long long r = 1;     while (b) {       if (b & 1) r = r * a % p;       a = a * a % p;       b /= 2;     }     return (long long)r;   }   bool check(long long p, long long d, long long a) {     a %= p;     if (!a) return 1;     if (fpw(a, p - 1, p) != 1) return 0;     if ((a = fpw(a, d, p)) == 1) return 1;     while (a != 1) {       if (a == p - 1) return 1;       a = a * a % p;     }     return 0;   }   vector<long long> primes;   bool prime(long long p) {     if (p < 4) return p > 1;     if (!(p & 1)) return 0;     if (p <= 2000000000) {       long long d = p - 1;       while (!(d & 1)) d /= 2;       return check(p, d, 2) && check(p, d, 325) && check(p, d, 9375) &&              check(p, d, 28178) && check(p, d, 450775) && check(p, d, 9780504) &&              check(p, d, 1795265022);     } else {       for (long long first : primes) {         if (first * first > p) return 1;         if (p % first == 0) return 0;       }       return 1;     }   }   long long n;   vector<long long> D;   vector<long long> R, Q;   void apply(long long d) {     int i = ((int)(D).size()) - 1;     int j = ((int)(D).size()) - 1;     while (n / d != D[i]) --i;     while (i >= 0) {       while (D[j] > D[i] * d) --j;       if (D[j] == D[i] * d) Q[j] += R[i];       --i;     }   }   int main() {     ios_base::sync_with_stdio(0);     for (int i = (2); i < (1000010); ++i)       if (prime(i)) primes.push_back(i);     cin >> n;     for (long long d = 1; d * d <= n; ++d)       if (n % d == 0) {         D.push_back(d);         if (d * d != n) D.push_back(n / d);       }     sort(D.begin(), D.end());     R.resize(((int)(D).size()));     Q.resize(((int)(D).size()));     R[0] = 1;     for (long long p : primes) {       long long pk = p;       bool once = 0;       while (pk + 1 <= n) {         if (n % (pk + 1) == 0) {           once = 1;           apply(pk + 1);         }         pk *= p;       }       if (once)         for (int i = (0); i < (((int)(D).size())); ++i) {           R[i] += Q[i];           Q[i] = 0;         }     }     for (long long d : D)       if (d - 1 > primes.back() && prime(d - 1)) {         for (int i = (0); i < (((int)(D).size())); ++i) Q[i] = 0;         apply(d);         for (int i = (0); i < (((int)(D).size())); ++i) R[i] += Q[i];       }     cout << R.back() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, unsigned long long y, unsigned 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;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, pi, k;     cin >> n >> pi >> k;     long long arr[n], x, ans = 0;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       cin >> x;       arr[i] = (power(x, 4, pi) - k * x) % pi;       arr[i] += pi, arr[i] %= pi;     }     for (long long i = n - 1; i >= 0; i--) {       ans += m[arr[i]];       m[arr[i]]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4000010, oo = 1e9;   long long x, y, c, n;   bool ok(long long t) {     long long ans = 2ll * t * (t + 1ll) - 4ll * t + 1l;     if (t > x) {       ans -= (t - x) * (t - x);     }     if (t > n - x + 1) {       ans -= (t - n + x - 1) * (t - n + x - 1);     }     if (t > y) {       ans -= (t - y) * (t - y);     }     if (t > n - y + 1) {       ans -= (t - n + y - 1) * (t - n + y - 1);     }     if (t > x + y) {       ans += ((t - x - y) * (t - x - y + 1) / 2);     }     if (t > x + n - y + 1) {       ans += ((t - x - n + y - 1) * (t - x - n + y - 1 + 1) / 2);     }     if (t > n - x + 1 + y) {       ans += ((t - n + x - 1 - y) * (t - n + x - 1 - y + 1) / 2);     }     if (t > n - x + 1 + n - y + 1) {       ans += ((t - n + x - 1 - n + y - 1) * (t - n + x - 1 - n + y - 1 + 1) / 2);     }     return ans >= c;   }   long long bsr(long long l, long long h) {     long long mid;     while (l < h) {       mid = (l + h + 1) / 2;       if (ok(mid)) {         h = mid - 1;       } else {         l = mid;       }     }     return h;   }   int main() {     scanf( %lld%lld%lld%lld , &n, &x, &y, &c);     long long ans = bsr(0, 1e9 + 10);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <typename T>   T &chmin(T &a, const T &b) {     return a = min(a, b);   }   template <typename T>   T &chmax(T &a, const T &b) {     return a = max(a, b);   }   template <typename T>   T inf;   template <>   constexpr int inf<int> = 1e9;   template <>   constexpr ll inf<ll> = 1e18;   template <>   constexpr ld inf<ld> = 1e30;   struct yes_no : numpunct<char> {     string_type do_truename() const { return  Yes ; }     string_type do_falsename() const { return  No ; }   };   int res[300010];   bool visited[300010];   vector<int> s[300010];   vector<int> g[300010];   void get_col(vector<int> &vec, int &pos, int &res) {     ++res;     while (pos < int(vec.size()) && vec[pos] == res) ++pos, ++res;   }   void dfs(int v) {     vector<int> vec;     for (int i : s[v]) {       if (res[i] == 0) continue;       vec.push_back(res[i]);     }     sort((vec).begin(), (vec).end());     int pos = 0, col = 0;     for (int i : s[v]) {       if (res[i] != 0) continue;       get_col(vec, pos, col);       res[i] = col;     }     visited[v] = true;     for (int i : g[v]) {       if (visited[i]) continue;       dfs(i);     }   }   int main() {     locale loc(locale(), new yes_no);     cout << boolalpha;     cout.imbue(loc);     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < (int)(n); i++) {       int sz, in;       scanf( %d , &sz);       for (int j = 0; j < (int)(sz); j++) {         scanf( %d , &in);         s[i].push_back(in - 1);       }     }     for (int i = 0; i < (int)(n - 1); i++) {       int from, to;       scanf( %d%d , &from, &to);       --from;       --to;       g[from].push_back(to);       g[to].push_back(from);     }     dfs(0);     for (int i = 0; i < (int)(k); i++) chmax(res[i], 1);     int num = *max_element(res, res + k);     cout << num << endl;     for (int i = 0; i < (int)(k); i++) {       printf( %d , res[i]);       if (i == k - 1)         printf(  n );       else         printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e6 + 3;   const long double PI = 2 * acos(0.0);   const vector<long long int> dx = {1, -1, 0, 0};   const vector<long long int> dy = {0, 0, 1, -1};   template <typename T = long long int>   vector<T> ga(long long int n, bool oneIndexed = false) {     vector<T> a = vector<T>(n + oneIndexed);     for (long long int i = 0; i < n; i++) {       T p;       cin >> p;       a[i + oneIndexed] = p;     }     return move(a);   }   template <typename T, typename A>   void pa(vector<T, A> const &a, long long int begin = 0,           long long int end = -1) {     if (end == -1) end = (long long int)a.size() - 1;     for (long long int i = begin; i <= end; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   template <typename T>   T po(T base, T exp) {     T result = 1;     for (;;) {       if (exp & 1) result *= base;       exp >>= 1;       if (!exp) break;       base *= base;     }     return result;   }   template <typename T>   T pomod(T x, T y, T mod) {     T res = 1;     x = x % mod;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res;   }   void solve() {     long long int n;     cin >> n;     if (n == 0)       cout << 1 <<   n ;     else       cout << pomod(3ll, n - 1, MOD);   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     scanf( %d , &n);     vector<int> f(n + 1, -1);     vector<int> g(n + 1, -1);     vector<int> h(1);     int m = 0;     vector<bool> b(n + 1, false);     for (int i = 1; i <= n; i++) {       scanf( %d , &f[i]);       if (f[i] == i) {         m++;         h.push_back(i);         g[i] = m;         b[i] = true;       }     }     for (int i = 1; i <= n; i++) {       if (f[i] != i) {         int to = g[f[i]];         if (b[f[i]] == false || to == -1) {           puts( -1 );           return 0;         }         g[i] = to;       }     }     printf( %d n , m);     for (int i = 1; i <= n; i++) {       if (i > 1) {         putchar(   );       }       printf( %d , g[i]);     }     puts(  );     for (int i = 1; i <= m; i++) {       if (i > 1) {         putchar(   );       }       printf( %d , h[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int mymax = 1e18;   const long long int mymin = -1e18;   const double PIE = 3.1415926536;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, n, m, d, k, ti, lef, rit;     bool ans;     vector<pair<int, int> > cent;     cin >> t;     while (t--) {       cin >> n >> m >> k;       char a[n][m];       int vis[n][m];       cent.clear();       ans = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];           vis[i][j] = 0;         }       }       for (int i = n - 1; i >= 1; i--) {         for (int j = 1; j <= (m - 2); j++) {           if ((a[i][j] ==  * ) && (a[i - 1][j - 1] ==  * ) &&               (a[i - 1][j + 1] ==  * )) {             d = 0;             ti = i - 1;             lef = j - 1;             rit = j + 1;             while ((ti >= 0) && (lef >= 0) && (rit < m) && (a[ti][lef] ==  * ) &&                    (a[ti][rit] ==  * )) {               d++;               ti--;               lef--;               rit++;             }             if (d >= k) {               cent.push_back({i, j});             }           }         }       }       for (auto it : cent) {         vis[it.first][it.second] = 1;         ti = it.first - 1;         lef = it.second - 1;         rit = it.second + 1;         while ((ti >= 0) && (lef >= 0) && (rit < m) && (a[ti][lef] ==  * ) &&                (a[ti][rit] ==  * )) {           vis[ti][lef] = vis[ti][rit] = 1;           ti--;           lef--;           rit++;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if ((a[i][j] ==  * ) && !vis[i][j]) {             ans = false;             break;           }         }       }       cout << ((ans) ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const double eps = 1e-8;   const int nm = 1100005;   int n, k, m, t;   long long res;   int cnt[nm], f[nm][23];   int POW(int x, int z) {     if (z == 0) return 1;     if (z == 1) return x % MOD;     int u = POW(x, z >> 1);     u = ((long long)u * u) % MOD;     if (z % 2) u = ((long long)u * x) % MOD;     return u;   }   int main() {     int i, j, x, y, z, w;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &x);       cnt[x]++;     }     for (i = (1 << 20) - 1; i >= 0; i--) {       if (i & 1)         f[i][0] = cnt[i];       else         f[i][0] = cnt[i] + cnt[i + 1];       for (j = 1; j < 20; j++) {         if (i & (1 << j))           f[i][j] = f[i][j - 1];         else           f[i][j] = f[i][j - 1] + f[i + (1 << j)][j - 1];       }     }     for (i = (1 << 20) - 1; i >= 0; i--) {       x = __builtin_popcount(i);       if (x & 1)         res -= POW(2, f[i][19]);       else         res += POW(2, f[i][19]);       res = (res + MOD) % MOD;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v;   };   int n, m, k, f[1000000 + 1], ans[1000000 + 1], q[1000000 + 1], lq = 0, rq = -1,                                                                  cur;   edge b[1000000 + 1];   vector<int> a[1000000 + 1], e[1000000 + 1];   bool remoed[1000000 + 1], removeti[1000000 + 1];   void removequeue() {     int x, y;     while (lq <= rq) {       x = q[lq];       lq++;       cur--;       for (int i = 0; i < a[x].size(); i++) {         y = a[x][i];         if (remoed[e[x][i]] == false) {           remoed[e[x][i]] = true;           f[y]--;           if (f[y] < k && removeti[y] == false) {             rq++;             q[rq] = y;             removeti[y] = true;           }         }       }     }   }   void removemany() {     for (int i = 1; i <= n; i++) {       if (f[i] < k) {         rq++;         q[rq] = i;         removeti[i] = true;       }     }     removequeue();   }   void solve() {     removemany();     for (int i = m - 1; i >= 0; i--) {       ans[i] = cur;       if (remoed[i] == false) {         remoed[i] = true;         f[b[i].u]--;         f[b[i].v]--;         if (f[b[i].u] < k && removeti[b[i].u] == false) {           rq++;           q[rq] = b[i].u;           removeti[b[i].u] = true;         }         if (f[b[i].v] < k && removeti[b[i].v] == false) {           rq++;           q[rq] = b[i].v;           removeti[b[i].v] = true;         }       }       removequeue();     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }   void readit() {     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       cin >> b[i].u >> b[i].v;       a[b[i].u].push_back(b[i].v);       a[b[i].v].push_back(b[i].u);       e[b[i].u].push_back(i);       e[b[i].v].push_back(i);       f[b[i].u]++;       f[b[i].v]++;     }     cur = n;   }   int main() {     readit();     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   int main() {     int c, d, n, m, k;     while (scanf( %d %d , &c, &d) != EOF) {       scanf( %d %d , &n, &m);       scanf( %d , &k);       int t = n * m - k;       if (t <= 0) {         printf( 0 n );         continue;       }       int res = t / n;       int ans = min(res * n * d, res * c);       ans += min(c, (t - res * n) * d);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[100005], k;   map<long long, long long> tr;   long long getans(const long long k) {     long long t1 = 1, t2 = 0, t3 = 0, t4 = 1, ans = 0;     while (t2 < n) {       ans += (a[t1] - a[t2]) * t3;       ++t3;       t2 = t1;       t1 += t4 * k;       t4 *= k;       if (t1 > n) t1 = n;     }     return ans;   }   int main() {     tr.clear();     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a[i]);       a[i] = -a[i];     }     sort(a + 1, a + n + 1);     a[0] = 0;     for (int i = 1; i <= n; ++i) {       a[i] = -a[i];       a[i] += a[i - 1];     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %I64d , &k);       if (i != 1) printf(   );       if (!tr.count(k)) tr[k] = getans(k);       printf( %I64d , tr[k]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> cities[100000];   vector<bool> visited(100000);   vector<int> t(100000), low(100000);   map<pair<int, int>, int> b;   int c = 0, ans = 0;   void dfs(int v, int p = -1) {     visited[v] = true;     t[v] = low[v] = c++;     for (int dest : cities[v]) {       if (dest == p) continue;       if (visited[dest]) {         low[v] = min(low[v], t[dest]);       } else {         dfs(dest, v);         low[v] = min(low[v], low[dest]);         if (low[dest] > t[v]) {           b[{v, dest}] = 1;           b[{dest, v}] = 1;         } else {           b[{v, dest}] = 0;           b[{dest, v}] = 0;         }       }     }   }   vector<long long> dist(100001);   void Dijkstra(int r, int e) {     set<pair<int, int> > s;     dist[r] = 0;     s.insert({0, r});     while (!s.empty()) {       pair<int, int> p = *s.begin();       s.erase(s.begin());       int x = p.first, y = p.second;       if (x > dist[y]) {         continue;       } else if (dist[e] != INT_MAX) {         return;       }       for (int j = 0; j < cities[y].size(); j++) {         if (dist[y] + b[{y, cities[y][j]}] < dist[cities[y][j]]) {           dist[cities[y][j]] = dist[y] + b[{y, cities[y][j]}];           s.insert({dist[cities[y][j]], cities[y][j]});         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       cities[x - 1].push_back(y - 1);       cities[y - 1].push_back(x - 1);     }     c = 0;     t.assign(n, -1);     low.assign(n, -1);     visited.assign(n, false);     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         dfs(i);       }     }     cin >> k;     for (int i = 0; i < k; i++) {       ans = 0;       dist.assign(n, INT_MAX);       int root, shop;       cin >> root >> shop;       Dijkstra(root - 1, shop - 1);       cout << dist[shop - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int y, w, x, counter = 0;     cin >> y >> w;     x = max(y, w);     for (int i = x; i <= 6; i++) {       counter++;     }     if (counter == 0)       cout <<  0/1 ;     else if (counter == 1)       cout <<  1/6 ;     else if (counter == 2)       cout <<  1/3 ;     else if (counter == 3)       cout <<  1/2 ;     else if (counter == 4)       cout <<  2/3 ;     else if (counter == 5)       cout <<  5/6 ;     else       cout <<  1/1 ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && (c !=  - )) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   const int N = 2e5 + 10;   int n, m, Ans[N];   pair<int, int> a[N], b[N];   inline long long Query(int x) {     long long ret = 0;     if (x < 0) {       x = -x;       for (register int i = (1); i <= (x); i++)         ret += m - a[n - x + i].first + b[i].first,             Ans[a[n - i + 1].second] = b[i].second;       for (register int i = (x + 1); i <= (n); i++)         ret += abs(b[i].first - a[i - x].first),             Ans[a[i - x].second] = b[i].second;     } else {       for (register int i = (1); i <= (x); i++)         ret += a[i].first + m - b[n - x + i].first,             Ans[a[i].second] = b[n - x + i].second;       for (register int i = (x + 1); i <= (n); i++)         ret += abs(a[i].first - b[i - x].first),             Ans[a[i].second] = b[i - x].second;     }     return ret;   }   int main() {     m = read(), n = read();     for (register int i = (1); i <= (n); i++) a[i] = make_pair(read(), i);     for (register int i = (1); i <= (n); i++) b[i] = make_pair(read(), i);     sort(a + 1, a + 1 + n), sort(b + 1, b + 1 + n);     int l = -n, r = n;     while (l < r) {       int mid = l + r >> 1;       if (Query(mid) < Query(mid + 1))         r = mid;       else         l = mid + 1;     }     printf( %lld n , Query(l));     for (register int i = (1); i <= (n); i++) printf( %d  , Ans[i]);   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int i = sqrt(n);     for (int i = 0; i <= 10; i++) {       if (pow(2, i) == n) {         printf( YES );         return 0;       }     }     printf( NO );     return 0;   }