#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, maxn = 2e3 + 5;   long long f[maxn][maxn][2][2];   long long g[maxn];   long long n, m;   long long upd(const long long &x) {     if (x < 0) return x + mod;     if (x >= mod) return x - mod;     return x;   }   void add(long long &x, const long long &y) { x = upd(x + upd(y)); }   long long jc[maxn], inv[maxn];   long long ksm(long long x, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * x % mod;       x = x * x % mod;       k >>= 1;     }     return ans;   }   void init(long long n) {     jc[0] = 1;     for (long long i(1), endi(n); i <= endi; i++) jc[i] = jc[i - 1] * i % mod;     inv[n] = ksm(jc[n], mod - 2);     for (long long i(n - 1), endi(0); i >= endi; i--)       inv[i] = inv[i + 1] * (i + 1) % mod;   }   long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return jc[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     scanf( %lld%lld , &n, &m);     init(n);     f[1][0][0][0] = 1;     f[1][1][0][1] = 1;     for (long long i(2), endi(n); i <= endi; i++)       for (long long j(0), endj(n); j <= endj; j++) {         if (j) {           add(f[i][j][0][0], f[i - 1][j - 1][0][0]);           add(f[i][j][1][0], f[i - 1][j - 1][0][1]);           if (i != n) {             add(f[i][j][0][1], f[i - 1][j - 1][0][0] + f[i - 1][j - 1][1][0]);             add(f[i][j][1][1], f[i - 1][j - 1][0][1] + f[i - 1][j - 1][1][1]);           }         }         add(f[i][j][0][0], f[i - 1][j][0][0] + f[i - 1][j][1][0]);         add(f[i][j][1][0], f[i - 1][j][0][1] + f[i - 1][j][1][1]);       }     for (long long i(0), endi(n); i <= endi; i++) {       add(g[i], f[n][i][0][0] + f[n][i][1][0]);       g[i] = g[i] * jc[n - i] % mod;     }     long long ans = 0;     for (long long i(m), endi(n); i <= endi; i++) {       add(ans, ((i - m) & 1 ? -1 : 1) * g[i] * C(i, m) % mod);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chmax(T &x, const T &y) {     return (x < y) ? (x = y, true) : false;   };   template <typename T>   bool chmin(T &x, const T &y) {     return (x > y) ? (x = y, true) : false;   };   constexpr long long int MOD = 10;   constexpr long long int INF = 2e18;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<long long int> p(n);       for (long long int i = 0; i < (n); i++) cin >> p[i], p[i]--;       vector<long long int> cnt(n, 0);       for (long long int i = 0; i < (n); i++) {         cnt[(p[i] - i + n) % n]++;       }       vector<long long int> ans;       for (long long int i = 0; i < (n); i++) {         if (n - cnt[i] <= m) {           ans.push_back((-i + n) % n);         } else if (n - cnt[i] <= m * 2) {           int x = 0;           vector<long long int> q(n);           for (long long int j = 0; j < (n); j++) q[j] = p[(j - i + n) % n];           vector<long long int> f(n, 0);           for (long long int j = 0; j < (n); j++) {             if (f[j] == 0) {               int now = j;               while (f[now] == 0) {                 f[now] = 1;                 now = q[now];                 x++;               }               x--;             }           }           if (x <= m) ans.push_back((-i + n) % n);         }       }       sort(ans.begin(), ans.end());       cout << ans.size();       for (auto i : ans) cout <<     << i;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int K = 998244353;   long long int mu(long long int a, long long int n) {     if (n == 0) return 1;     long long int q = mu(a, n / 2);     if (n % 2 == 0) return q * q % K;     return q * q % K * a % K;   }   long long int d[55][55][55][55], inv[5305];   int isLiked[55], weight[55];   int n, m, total;   long long int a, b;   long long int calc(int w, int A, int B, int m, int i) {     if (w * isLiked[i] + weight[i] < 0 || A + a < 0 || b - B < 0) return 0;     if (m == 0) {       return w * isLiked[i] + weight[i];     }     if (d[w][A][B][m] != -1) return d[w][A][B][m];     long long int deno = inv[w * isLiked[i] + A - B + weight[i] + a + b];     long long int res = 0;     res += (A + a) * calc(w, A + 1, B, m - 1, i) % K;     res %= K;     res += (b - B) * calc(w, A, B + 1, m - 1, i) % K;     res %= K;     res += (weight[i] + w * isLiked[i]) * calc(w + 1, A, B, m - 1, i) % K;     res %= K;     res = res * deno % K;     return d[w][A][B][m] = res % K;   }   long long int solve(int i) {     memset(d, -1, sizeof(d));     a = 0, b = 0;     for (int j = 1; j <= n; j++) {       if (j == i) continue;       if (isLiked[j] == 1) {         a += weight[j];       } else {         b += weight[j];       }     }     return calc(0, 0, 0, m, i);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     for (int i = 1; i <= 5300; i++) {       inv[i] = mu(i, K - 2);     }     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> isLiked[i];       if (!isLiked[i]) isLiked[i] = -1;     }     for (int i = 1; i <= n; i++) {       cin >> weight[i];     }     for (int i = 1; i <= n; i++) {       cout << solve(i) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   void setIO(string name) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin.exceptions(istream::failbit);   }   const int inf = 0x3f3f3f3f, mod = 1e9 + 7, maxn = 1e5 + 5;   vector<vector<pair<int, int>>> adj;   vector<long long> pass, sub, weight, cost;   void dfs(int c, int p) {     if (p != -1 && adj[c].size() == 1) {       sub[c] = 1;     }     for (auto i : adj[c]) {       if (i.first != p) {         dfs(i.first, c);         pass[i.second] = sub[i.first];         sub[c] += sub[i.first];       }     }   }   int main() {     setIO( 1 );     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long s;       cin >> s;       adj = vector<vector<pair<int, int>>>(n);       pass = sub = weight = cost = vector<long long>(n);       for (int i = 0; i < n - 1; ++i) {         int a, b;         cin >> a >> b >> weight[i] >> cost[i];         --a, --b;         adj[a].push_back({b, i});         adj[b].push_back({a, i});       }       dfs(0, -1);       pair<long long, long long> total;       priority_queue<pair<long long, int>> one, two;       for (int i = 0; i < n - 1; ++i) {         if (cost[i] == 1) {           total.first += pass[i] * weight[i];           one.push({pass[i] * (weight[i] - weight[i] / 2), i});         } else {           total.second += pass[i] * weight[i];           two.push({pass[i] * (weight[i] - weight[i] / 2), i});         }       }       vector<long long> costs;       while (total.first) {         costs.push_back(total.first);         pair<long long, int> cur = one.top();         one.pop();         total.first -= cur.first;         weight[cur.second] /= 2;         one.push(             {pass[cur.second] * (weight[cur.second] - weight[cur.second] / 2),              cur.second});       }       costs.push_back(0);       long long sol = 1e18, cnt = 0;       while (total.second) {         long long lo = 0, hi = (int)costs.size() - 1, mid, res = -1;         while (lo <= hi) {           mid = (lo + hi) / 2;           if (costs[mid] + total.second <= s) {             res = mid;             hi = mid - 1;           } else {             lo = mid + 1;           }         }         if (res != -1) {           sol = min(sol, res + 2 * cnt);         }         pair<long long, int> cur = two.top();         two.pop();         total.second -= cur.first;         weight[cur.second] /= 2;         two.push(             {pass[cur.second] * (weight[cur.second] - weight[cur.second] / 2),              cur.second});         ++cnt;       }       long long lo = 0, hi = costs.size(), mid, res = -1;       while (lo <= hi) {         mid = (lo + hi) / 2;         if (costs[mid] <= s) {           res = mid;           hi = mid - 1;         } else {           lo = mid + 1;         }       }       if (res != -1) {         sol = min(sol, res + 2 * cnt);       }       cout << min(sol, res + 2 * cnt) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M[33][33];   int S[33][33];   int m;   int n;   int solve(int sid) {     memcpy(S, M, sizeof(int) * 33 * 33);     for (int i = 0; i < m; i++) {       if ((1 << i) & sid) {         for (int k = m - 1; k < n; k++) {           for (int l = i; l < i + m; l++) {             S[k][l] *= -1;           }         }       }     }     int ret = 0;     for (int i = 0; i < n; i++) ret += S[m - 1][i];     for (int i = 0; i < m - 1; i++) {       for (int j = 0; j < n; j++) {         S[i][j] += S[m + i][j];       }     }     for (int i = 0; i < m - 1; i++) {       int row1 = S[i][m - 1], row2 = S[i][m - 1] * -1;       for (int j = 0; j < m - 1; j++) {         row1 += abs(S[i][j] + S[i][m + j]);         row2 += abs(S[i][j] - S[i][m + j]);       }       ret += max(row1, row2);     }     return ret;   }   int main() {     cin >> n;     m = (n + 1) / 2;     for (size_t i = 0; i < n; ++i) {       for (size_t j = 0; j < n; ++j) {         cin >> M[i][j];       }     }     int sol = -10000000;     for (size_t i = 0; i < (1 << m); ++i) {       sol = max(solve(i), sol);     }     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int INF = 1 << 30;   const double eps = 1e-6;   const int mod = 1000000007;   string s;   void getVal(int& a, int& b, char x) {     a = b = -1;     for (int i = 0; i < s.size(); i++) {       if (s[i] != x) continue;       if (a == -1) a = i;       b = i;     }   }   int main() {     cin >> s;     int n = s.size();     int la, ra, lb, rb, lc, rc;     bool ok = true;     getVal(la, ra,  a );     if (la == -1 || ra == -1) ok = false;     getVal(lb, rb,  b );     if (lb == -1 || rb == -1) ok = false;     getVal(lc, rc,  c );     if (lc == -1 || rc == -1) ok = false;     if (ra + 1 != lb || rb + 1 != lc)       ok = false;     else if (rc - lc != rb - lb && rc - lc != ra - la)       ok = false;     puts(ok ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, i;   double H, K, x, y, xp, yp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> K >> x >> y;     for (i = 1; i < N; i++) {       cin >> xp >> yp;       H += sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y)) * K / 50;       x = xp;       y = yp;     }     cout << fixed << setprecision(12) << H <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:2000000 )   #pragma comment(linker,  /HEAP:2000000 )   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long m[n][n], a[n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> m[i][j];       }     }     long long x = sqrt((m[0][1] * m[0][2]) / m[1][2]);     cout << x <<    ;     for (int i = 1; i < n; i++) {       cout << m[0][i] / x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600, oo = 2e9;   int nn[N], mm[N], n, m;   int check() {     int mn = oo;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (nn[i] == mm[j]) mn = min(mn, nn[i]);       }     }     if (mn == oo) return -1;     return mn;   }   int main() {     ios::sync_with_stdio(false);     int mn1 = oo, mn2 = oo, mnb1 = oo, mnb2 = oo;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> nn[i];       mn1 = min(mn1, nn[i]);       if (nn[i]) mnb1 = min(mnb1, nn[i]);     }     for (int i = 0; i < m; ++i) {       cin >> mm[i];       mn2 = min(mn2, mm[i]);       if (mm[i]) mnb2 = min(mnb2, mm[i]);     }     int mini = min(mn1, mn2), maxi = max(mn1, mn2);     if (check() != -1)       cout << check();     else if (!mn1) {       cout << min(mn2 * 10, mnb1 * 10 + mn2);     } else if (!mn2)       cout << min(mn1 * 10, mnb2 * 10 + mn1);     else       cout << mini * 10 + maxi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t, temp;   bool check(int mid, vector<int>& v) {     temp = s;     for (int i = 0; i < mid; i++) {       temp[v[i]] =  # ;     }     int x = 0;     for (int i = 0; i < temp.size(); i++) {       if (t[x] == temp[i]) {         x++;       }       if (x == t.size()) return true;     }     return false;   }   int main() {     cin >> s >> t;     vector<int> v;     for (int i = 0; i < s.size(); i++) {       int a;       cin >> a;       v.push_back(a - 1);     }     int low = 0, high = s.size();     while (high - low > 1) {       int mid = low + (high - low) / 2;       if (check(mid, v))         low = mid;       else         high = mid;     }     cout << low << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int da[100010], db[100010], ida[100010], idb[100010];   map<int, int> mp;   map<int, int>::iterator it;   void solve(int n) {     for (int i = 1; i <= n; i++) {       int ret = 0x3fffffff;       it = mp.lower_bound(i - 1);       if (it != mp.end()) ret = min(ret, it->first - (i - 1));       if (it != mp.begin()) {         --it;         ret = min(ret, (i - 1) - it->first);       }       printf( %d n , ret);       mp[i - ida[db[i]]]--;       if (mp[i - ida[db[i]]] == 0) mp.erase(i - ida[db[i]]);       mp[i + n - ida[db[i]]]++;     }   }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       mp.clear();       for (int i = 1; i <= n; i++) {         scanf( %d , &da[i]);         ida[da[i]] = i;       }       for (int i = 1; i <= n; i++) {         scanf( %d , &db[i]);         idb[db[i]] = i;       }       for (int i = 1; i <= n; i++) mp[i - ida[db[i]]]++;       solve(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % 1000000007;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % 1000000007;       res %= 1000000007;     }     return res;   }   struct compare {     bool operator()(const pair<long long, long long> a,                     const pair<long long, long long> b) const {       return a.first < b.first;     }   };   const long long nax = 2005;   long long n, m;   vector<pair<long long, long long>> robber, light, moves;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     robber.assign(n, {0, 0});     light.assign(m, {0, 0});     for (long long i = 0; i < n; i++) {       cin >> robber[i].first >> robber[i].second;     }     for (long long i = 0; i < m; i++) {       cin >> light[i].first >> light[i].second;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         long long a = light[j].first - robber[i].first + 1;         long long b = light[j].second - robber[i].second + 1;         a = max(a, 0LL);         b = max(b, 0LL);         moves.push_back({a, b});       }     }     long long sz = moves.size();     sort(moves.begin(), moves.end());     vector<long long> suf(sz);     suf[sz - 1] = moves[sz - 1].second;     for (long long i = sz - 2; i >= 0; i--) {       suf[i] = max(suf[i + 1], moves[i].second);     }     long long ans = suf[0];     for (long long i = 0; i < sz; i++) {       ans = min(ans, moves[i].first + (i + 1 < sz ? suf[i + 1] : 0));     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   struct Ans {     long long a, b, c;   };   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long ans = 1e9;     auto x = Ans{a, b, c};     for (long long aa = 1; aa <= 2 * a; aa++) {       for (long long bb = aa; bb <= 2 * b; bb += aa) {         long long op1 = bb * (c / bb);         long long op2 = op1 + bb;         long long diff = abs(a - aa) + abs(b - bb);         long long y = diff + abs(c - op1);         long long z = diff + abs(c - op2);         if (y < ans) {           ans = y;           x.a = aa;           x.b = bb;           x.c = op1;         }         if (z < ans) {           ans = z;           x.a = aa;           x.b = bb;           x.c = op2;         }       }     }     cout << ans <<   n ;     cout << x.a <<     << x.b <<     << x.c <<   n ;   }   int main(int argc, char *argv[]) {     long long t;     ios::sync_with_stdio(0);     cin.tie(0);     std::cout << std::fixed;     std::cout << std::setprecision(15);     cin >> t;     for (long long z = 0; z < (long long)t; ++z) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       int a[n];       int ma = INT_MIN;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > ma) ma = a[i];       }       int m2 = INT_MIN;       vector<int> v1, v2;       for (int i = 0; i < n; i++) {         a[i] = ma - a[i];         if (m2 < a[i]) m2 = a[i];         v1.push_back(a[i]);       }       for (int i = 0; i < n; i++) {         a[i] = m2 - a[i];       }       if (k % 2) {         for (int i = 0; i < v1.size(); i++) cout << v1[i] <<    ;         cout << endl;       } else {         for (int i = 0; i < n; i++) cout << a[i] <<    ;         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > xy;   vector<pair<long long, long long> > ab;   vector<long long> x;   vector<long long> y;   string str, str1, str2, star[2000];   long long ara[200005], ara2[200005];   bool flagar[200005], flagar2[200005];   bool compare(pair<long long, long long> i, pair<long long, long long> j) {     return (i.first < j.first);   }   bool compare2(pair<long long, long long> i, pair<long long, long long> j) {     return (i.first > j.first);   }   long long gcd(long long a, long long b) {     if (a % b == 0) return b;     return gcd(b, a % b);   }   long long dp[2005][2005];   int main() {     long long int n, ans, temp, t, j, i, m, h, h2, m2, c, a, b, mx, d, k, x1, r,         l, mn;     cin >> str >> k;     n = str.length();     a = b = 0;     for (i = n - 1; i >= 0; i--) {       if (str[i] -  0  == 0)         a++;       else         b++;       if (a == k) {         cout << b;         return 0;       }     }     if (a < k) {       b = n - 1;     }     cout << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005, M = 200005;   struct node {     int x, y;   } d[N];   int h, w, n, mod = 1e9 + 7;   long long c[M] = {1, 1}, inv[M] = {1, 1}, ni[M] = {1, 1}, f[N];   long long quick_mod(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans;   }   void init() {     for (int i = 2; i < M; i++) {       c[i] = c[i - 1] * i % mod;       ni[i] = (mod - mod / i) * ni[mod % i] % mod;       inv[i] = ni[i] * inv[i - 1] % mod;     }   }   long long C(int n, int m) {     if (n < m) return 0;     if (n == m || m == 0) return 1;     return c[n] * inv[m] % mod * inv[n - m] % mod;   }   bool cmp(node a, node b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   int main() {     init();     scanf( %d%d%d , &h, &w, &n);     for (int i = 0; i < n; i++) scanf( %d%d , &d[i].x, &d[i].y);     sort(d, d + n, cmp);     d[n].x = h;     d[n].y = w;     for (int i = 0; i <= n; i++) {       f[i] = C(d[i].x + d[i].y - 2, d[i].x - 1);       for (int j = 0; j < i; j++) {         if (d[j].x > d[i].x || d[j].y > d[i].y) continue;         f[i] = (f[i] -                 f[j] * C(d[i].x - d[j].x + d[i].y - d[j].y, d[i].x - d[j].x)) %                mod;       }       f[i] = (f[i] + mod) % mod;     }     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXINT = 2147483647;   const long long MAXLL = 9223372036854775807LL;   const int MAX = 400000;   long long n, q, col, pref[MAX], l, r, sum, ans, t[MAX];   string s;   int main() {     cin >> n >> q;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) col++;       pref[i] = col;     }     t[0] = 0;     for (int i = 1; i <= 100005; i++)       t[i] = (t[i - 1] + t[i - 1] + 1) % 1000000007;     for (int i = 0; i < q; i++) {       ans = 0, col = 0;       cin >> l >> r;       l--, r--;       if (l == 0)         sum = pref[r];       else         sum = pref[r] - pref[l - 1];       if (t[r - l + 1] >= t[r - l + 1 - sum])         ans += t[r - l + 1] - t[r - l + 1 - sum];       else         ans += t[r - l + 1] + 1000000007 - t[r - l + 1 - sum];       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using vll = vector<ll>;   using vvll = vector<vll>;   using pll = pair<ll, ll>;   using vpll = vector<pll>;   ll a, n;   vll inp;   void func() {     cin >> a;     string s;     cin >> s;     n = s.length();     inp.resize(n);     for (ll i = 0; i < n; i++) {       inp[i] = s[i] -  0 ;     }     vll cnt(9 * n + 1, 0);     for (ll i = 0; i < n; i++) {       ll x = 0;       for (ll j = i; j < n; j++) {         x += inp[j];         cnt[x]++;       }     }     ll ans = 0;     if (a == 0) {       ll total = accumulate(cnt.begin(), cnt.end(), 0ll);       ans = 2 * (cnt[0] * total);       ans -= cnt[0] * cnt[0];     } else {       for (ll i = 1; i < 9 * n + 1; i++) {         if (i > a) break;         if (a % i == 0) {           ll j = a / i;           if (j < 9 * n + 1) {             ans += cnt[i] * cnt[j];           }         }       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     ll t = 1;     for (ll i = 1; i <= t; i++) {       func();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int maxn = 300007;   int n, a[maxn];   static pair<int, int> tree[maxn << 2][20];   inline int min(int u, int v) { return u > v ? v : u; }   inline int max(int u, int v) { return u > v ? u : v; }   inline void pushup(int num, int val) {     tree[num][val] = {         min(tree[num << 1][val].first, tree[num << 1 | 1][val].first),         max(tree[num << 1][val].second, tree[num << 1 | 1][val].second)};   }   pair<int, int> query(int num, int l, int r, int val, int L, int R) {     if (L <= l && r <= R) {       return tree[num][val];     }     int md = (l + r) >> 1;     if (md >= L && md >= R) {       return query(num << 1, l, md, val, L, R);     }     if (md < R && md < L) {       return query(num << 1 | 1, md + 1, r, val, L, R);     }     if (md < R && md >= L) {       pair<int, int> tmp = query(num << 1, l, md, val, L, R),                      tmp2 = query(num << 1 | 1, md + 1, r, val, L, R);       return {min(tmp.first, tmp2.first), max(tmp.second, tmp2.second)};     }   }   void build(int num, int l, int r, int val) {     if (l == r) {       if (!val) {         tree[num][0] = {max(l - a[l], 1), min(l + a[l], 3 * n)};       } else {         pair<int, int> rg = query(1, 1, 3 * n, val - 1, l, l);         tree[num][val] = query(1, 1, 3 * n, val - 1, rg.first, rg.second);       }       return;     }     int md = (l + r) >> 1;     build(num << 1, l, md, val);     build(num << 1 | 1, md + 1, r, val);     pushup(num, val);   }   inline int calc(int u) {     int ret = 0;     pair<int, int> cnt = {u, u};     for (int i = 16; i > -1; --i) {       pair<int, int> tmp = query(1, 1, 3 * n, i, cnt.first, cnt.second);       if (tmp.second - tmp.first < n - 1) {         ret += (1 << i);         cnt = tmp;       }     }     return ret;   }   int main() {     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       a[i + n] = a[i + 2 * n] = a[i];     }     for (int i = 0; i < 17; ++i) {       build(1, 1, 3 * n, i);     }     for (int i = n + 1; i <= 2 * n; ++i) {       printf( %d  , calc(i) + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, a[100005], fqn[100005], fqo[100005], mx, cur,       exc = 0, lesdan = 0, mnvl[100005], gmod = 0, rekt = 0;   int mc[100005], vl[100005];   vector<int> ok;   map<int, int> fq;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> a[i];       fq[a[i]]++;     }     sort(a, a + n + 1, greater<int>());     mx = a[0];     cur = max(mx - (n - 1), 0);     for (auto u : fq)       if (u.second >= p) exc++;     for (int i = 0; i < n; i++) {       if (a[i] < cur) break;       rekt = i;       vl[i] = n - (a[i] - cur) - i;       mnvl[i] = vl[i];       if (i != 0) mnvl[i] = min(mnvl[i], mnvl[i - 1]);       mc[((vl[i] % p) + p) % p]++;     }     int gp = n - 1 - rekt;     int cnt = 0;     while (cur < mx) {       while (a[rekt] < cur) {         mc[((vl[rekt] % p) + p) % p]--;         rekt--;         gp++;       }       if (mnvl[rekt] + cnt > 0 && (mc[gmod] + gp / p) == 0) ok.push_back(cur);       cur++;       gmod--;       gmod += p;       gmod %= p;       cnt++;     }     cout << ok.size() << endl;     for (auto u : ok) cout << u <<    ;     cout << endl;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct EDGE {     int to, w;     EDGE *las;   } e[100005];   int ne;   EDGE *last[100005];   void link(int u, int v, int w) {     e[ne] = {v, w, last[u]};     last[u] = e + ne++;   }   long long dis[100005], f[100005];   void adjust() {     for (int i = 1; i <= n; ++i)       for (EDGE *ei = last[i]; ei; ei = ei->las) ei->w += dis[i] - dis[ei->to];     for (int i = 1; i <= n; ++i) f[i] += dis[i];   }   void SP0() {     static priority_queue<pair<long long, int>, vector<pair<long long, int> >,                           greater<pair<long long, int> > >         q;     memset(dis, 127, sizeof(long long) * (n + 1));     dis[1] = 0;     q.push(make_pair(0, 1));     while (!q.empty()) {       int x = q.top().second;       long long s = q.top().first;       q.pop();       if (s != dis[x]) continue;       for (EDGE *ei = last[x]; ei; ei = ei->las)         if (s + ei->w < dis[ei->to]) {           dis[ei->to] = s + ei->w;           q.push(make_pair(dis[ei->to], ei->to));         }     }     adjust();   }   void SP1() {     static vector<int> b[100005];     memset(dis, 127, sizeof(long long) * (n + 1));     dis[1] = 0;     b[0].push_back(1);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < b[i].size(); ++j) {         int x = b[i][j];         if (dis[x] < i) continue;         for (EDGE *ei = last[x]; ei; ei = ei->las)           if (i + ei->w < n && i + ei->w < dis[ei->to]) {             dis[ei->to] = i + ei->w;             b[dis[ei->to]].push_back(ei->to);           }       }       b[i].clear();     }     adjust();   }   int main() {     int Q;     scanf( %d%d%d , &n, &m, &Q);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       link(u, v, w);     }     SP0();     while (Q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int v;         scanf( %d , &v);         printf( %lld n , dis[v] > 100000000000000 ? -1 : f[v]);       } else {         int c;         scanf( %d , &c);         for (int i = 0; i < c; ++i) {           int id;           scanf( %d , &id), --id;           e[id].w++;         }         SP1();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[105];   bool visited[105];   int df[1005];   int ans = 0, k = 0;   void dfs(int i, int parent) {     visited[i] = true;     for (int j = 0; j < adj[i].size(); j++) {       if (!visited[adj[i][j]]) dfs(adj[i][j], i);     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) k++, dfs(i, 0);     }     if (n == m && k == 1)       cout <<  FHTAGN! n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   long long m, n, x, y, p, q;   int main() {     cin >> n;     for (long long k = 0; k < n; k++) {       cin >> x >> y >> p >> q;       m += (p - x + 1) * (q - y + 1);     }     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int x;     int y;   };   int main() {     long long n;     cin >> n;     vector<data> info;     long long smallest = 9999999999;     long long largest2 = -1;     for (int i = 0; i < n; i++) {       data temp;       cin >> temp.x >> temp.y;       if (temp.y < smallest) {         smallest = temp.y;       }       if (temp.x > largest2) {         largest2 = temp.x;       }       info.push_back(temp);     }     long long m;     cin >> m;     vector<data> info2;     long long largest = -1;     long long smallest2 = 9999999999;     for (int i = 0; i < m; i++) {       data temp;       cin >> temp.x >> temp.y;       if (temp.x > largest) {         largest = temp.x;       }       if (temp.y < smallest2) {         smallest2 = temp.y;       }       info2.push_back(temp);     }     cout << max(max(largest - smallest, largest2 - smallest2), (long long)0)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   int n, t, pop = -1, p[2 * MAX], para[2 * MAX], odw[2 * MAX];   inline void dodaj_pare(int a, int b) {     para[a] = b;     para[b] = a;   }   void wczytaj_dane() {     int m;     cin >> n >> m;     for (int i = 0; i < (2 * n); i++) cin >> p[i];     fill(para, para + 2 * n, -1);     while (m--) {       int a, b;       cin >> a >> b;       dodaj_pare(a - 1, b - 1);     }     cin >> t;   }   void wypisz(int x) {     assert(!odw[x]);     odw[x] = true;     cout << (x + 1) <<   n ;     fflush(stdout);   }   int najsilniejszy_sparowany() {     int x = -1;     for (int i = 0; i < (2 * n); i++)       if ((!odw[i]) && para[i] != -1 && (x == -1 || p[x] < p[i])) x = i;     return x;   }   int najsilniejszy() {     int x = -1;     for (int i = 0; i < (2 * n); i++)       if ((!odw[i]) && (x == -1 || p[x] < p[i])) x = i;     assert(x != -1);     return x;   }   int rozwiaz() {     int x = najsilniejszy_sparowany();     if (x != -1) return x;     return najsilniejszy();   }   void moj_ruch() {     if (pop != -1 && para[pop] != -1 && (!odw[para[pop]])) {       wypisz(para[pop]);       return;     }     wypisz(rozwiaz());   }   inline int wczytaj() {     int x;     cin >> x;     if (x == -1) exit(1);     return x - 1;   }   void twoj_ruch() {     int x = wczytaj();     odw[x] = true;     pop = x;   }   void zrob_test() {     wczytaj_dane();     fill(odw, odw + 2 * n, false);     if (t == 1) {       for (int q = 0; q < (n); q++) {         moj_ruch();         twoj_ruch();       }     } else {       for (int q = 0; q < (n); q++) {         twoj_ruch();         moj_ruch();       }     }   }   int main() {     zrob_test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     static int X[100];     for (int i = 0; i < N; i++) scanf( %d , &X[i]);     vector<int> Ans;     for (int i = 0, Count = 0, First = 0; i < N; i++) {       if (X[i] < 0) Count++;       if (i == N - 1 || (Count == 2 && X[i + 1] < 0)) {         Ans.push_back(i - First + 1);         First = i + 1;         Count = 0;       }     }     int M = Ans.size();     printf( %d n , M);     for (int i = 0; i < M; i++) {       printf( %d , Ans[i]);       putchar((i + 1 == M) ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long m) {     if (p == 0) return 1;     long long my = bigmod(b, p / 2, m);     my *= my;     my %= m;     if (p & 1) my *= b, my %= m;     return my;   }   int setb(int n, int pos) { return n = n | (1 << pos); }   int resb(int n, int pos) { return n = n & ~(1 << pos); }   bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }   struct info {     int x, y, idx;     info() {}     info(int _x, int _y, int _idx) {       x = _x;       y = _y;       idx = _idx;     }     bool operator<(const info &p) const {       if (y == p.y)         return x < p.x;       else         return y < p.y;     }   };   info ara[200005];   bool taken[200005];   int n;   int last[2];   bool fuck() {     int i;     last[0] = last[1] = -1;     for (i = 1; i <= n; i++) {       if (last[0] > last[1]) swap(last[0], last[1]);       if (ara[i].x > last[1]) {         last[1] = ara[i].y;         continue;       }       if (ara[i].x > last[0]) {         last[0] = ara[i].y;         continue;       }       return 0;     }     return 1;   }   int main() {     int x, y, i;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       ara[i] = info(x, y, i);     }     sort(ara + 1, ara + n + 1);     bool f = fuck();     if (f)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string& a) {     for (int i = 1; i < a.size(); i++) {       if (abs(a[i] - a[i - 1]) == 1) return false;     }     return true;   }   string gen(string a) {     if (check(a)) return a;     while (next_permutation(a.begin(), a.end())) {       if (check(a)) return a;     }     return   ;   }   string print(string& t, map<char, int>& cnt) {     string res;     for (auto it : t) {       res += string(cnt[it], it);     }     return res;   }   void solve() {     string in;     cin >> in;     map<char, int> cnt;     for (char i : in) cnt[i]++;     string res;     for (auto it : cnt) {       res += it.first;     }     if (res.size() <= 8) {       string temp = gen(res);       if (temp.empty()) {         cout <<  No answer  << endl;         return;       }       cout << print(temp, cnt) << endl;       return;     }     string t;     for (int i = 0; i < res.size(); i += 2) {       t += res[i];     }     for (int i = 1; i < res.size(); i += 2) {       t += res[i];     }     cout << print(t, cnt) << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int max2[205][6005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fill_n(max2[0], 205 * 6005, -1);     max2[0][0] = 0;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       long long int a;       cin >> a;       int p2 = 0, p5 = 0;       while (a % 2 == 0) {         a /= 2;         p2++;       }       while (a % 5 == 0) {         a /= 5;         p5++;       }       for (int pos = k - 1; pos >= 0; pos--) {         for (int s = p5; s < 6005; s++) {           if (max2[pos][s - p5] != -1) {             max2[pos + 1][s] = max(max2[pos + 1][s], max2[pos][s - p5] + p2);           }         }       }     }     int best = 0;     for (int i = 0; i < 6005; i++) {       best = max(best, min(i, max2[k][i]));     }     cout << best <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= (ch ==  - ), ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   long long n, now[4][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};   inline long long find(long long x, long long y) {     return (x / 4) * (n / 4) + y / 4 + 1;   }   signed main() {     n = read();     for (register long long i = 0; i <= n - 1; i++) {       for (register long long j = 0; j <= n - 1; j++) {         long long at = find(i, j);         cout << (at - 1) * 16 + now[i % 4][j % 4] <<    ;       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int row[1010];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     memset(row, 0x3f3f3f3f, sizeof row);     long long ans = 0;     for (int i = (0); i < (n); ++i) {       int r, c;       scanf( %d %d , &r, &c);       row[r] = min(c, row[r]);     }     for (int i = 1; i <= m; ++i) ans += ((row[i] == 0x3f3f3f3f) ? 0 : row[i]);     cout << min(ans, (long long)k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const int inf = -INF;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   string s;   int pre[N];   int dp[N][2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       cin >> s;       pre[0] = 0;       for (int i = 0; i <= n; i++) {         dp[i][0] = dp[i][1] = 0;       }       s =     + s;       for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + s[i] -  0 ;       for (int i = 1; i <= n; i++) {         int t = max(0, i - k);         dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (s[i] ==  1 );         dp[i][1] =             min(pre[i - 1], dp[t][1] + pre[i - 1] - pre[t]) + (s[i] ==  0 );       }       int ans = min(dp[n][0], dp[n][1]);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     double d, l, v1, v2;     cin >> d >> l >> v1 >> v2;     printf( %.10lf , double((l - d) / (v1 + v2)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, rej = 0;     cin >> n;     vector<int> a(n);     for (size_t i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     for (int i = 0; i < n; i++)       if (a[i] == a[0] || a[i] == a[n - 1]) rej++;     cout << n - rej;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long read() {     long long x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f);     for (x = ch ^ 48; isdigit(ch = getchar());          x = (x << 3) + (x << 1) + (ch ^ 48))       ;     return x * f;   }   template <class T>   void Max(T &a, T b) {     a = a > b ? a : b;   }   template <class T>   void Min(T &a, T b) {     a = a < b ? a : b;   }   long long n, l[4], r[4], L[4], R[4], x[N], y[N], z[N];   bool check(long long p, bool type) {     for (long long i = 0; i <= 3; ++i) l[i] = -6e18, r[i] = 6e18;     for (long long i = 1; i <= n; ++i) {       Max(l[0], x[i] + y[i] + z[i] - p);       Min(r[0], x[i] + y[i] + z[i] + p);       Max(l[1], -x[i] + y[i] + z[i] - p);       Min(r[1], -x[i] + y[i] + z[i] + p);       Max(l[2], x[i] - y[i] + z[i] - p);       Min(r[2], x[i] - y[i] + z[i] + p);       Max(l[3], x[i] + y[i] - z[i] - p);       Min(r[3], x[i] + y[i] - z[i] + p);     }     for (long long i = 0; i <= 3; ++i)       if (l[i] > r[i]) return 0;     for (long long A = 0, flag; A <= 1; ++A) {       L[0] = l[0] - 3 * A, R[0] = r[0] - 3 * A;       for (long long i = 1; i <= 3; ++i) L[i] = l[i] - A, R[i] = r[i] - A;       for (long long i = 0; i <= 3; ++i) L[i] = (L[i] + 1) >> 1, R[i] >>= 1;       flag = 1;       for (long long i = 0; i <= 3; ++i)         if (L[i] > R[i]) {           flag = 0;           break;         }       if (flag == 0) continue;       long long L0 = L[1] + L[2] + L[3], R0 = R[1] + R[2] + R[3];       if (R[0] >= L0 && R0 >= L[0]) {         if (type) {           long long a = L[1], b = L[2], c = L[3];           if (a + b + c < L[0]) a += min(R[1] - L[1], L[0] - a - b - c);           if (a + b + c < L[0]) b += min(R[2] - L[2], L[0] - a - b - c);           if (a + b + c < L[0]) c += min(R[3] - L[3], L[0] - a - b - c);           printf( %lld %lld %lld n , b + c + A, a + c + A, a + b + A);         }         return 1;       }     }     return 0;   }   void solve() {     n = read();     for (long long i = 1; i <= n; ++i)       x[i] = read(), y[i] = read(), z[i] = read();     long long l = 0, r = 6e18, mid, ans;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid, 0))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     check(ans, 1);   }   signed main() {     long long T = read();     while (T-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int hell = 9223372036854775807;   bool a[40000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       for (long long int i = 1; i < 4000000; i++) {         a[i] = true;       }       for (long long int i = 2; i * i < 4000000; i++) {         if (a[i])           for (long long int j = i * i; j < 4000000; j = j + i) a[j] = false;       }       long long int n;       cin >> n;       vector<long long int> v;       long long int k = 0;       for (long long int i = 2; i * i <= n; i++) {         if (n % i == 0 && a[i]) {           v.push_back(i);           if (n % (i * i) == 0) v.push_back(i);         }         if (n % i == 0) k++;       }       if (k == 0)         cout << 1 << endl << 0;       else if (v.size() > 1) {         if (v[0] * v[1] < n)           cout <<  1  << endl << v[0] * v[1];         else           cout <<  2 ;       } else         cout <<  2 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5050;   const int inf = 0x37373737;   int L[N], R[N], size[N], tot, n, i, a, b, cnt, j, k;   int d[N], root;   int dp[N][N];   vector<pair<int, int> > vec[N];   vector<int> e[N];   void dfs(int x, int fa) {     int i, j, k;     if (e[x].size() == 1) size[x] = 1;     for (i = 0; i < e[x].size(); i++)       if (e[x][i] != fa) {         dfs(e[x][i], x);         for (j = size[x]; j >= 0; j--)           for (k = 0; k <= size[e[x][i]]; k++)             dp[x][j + k] = min(dp[x][j + k], dp[x][j] + dp[e[x][i]][k]);         size[x] += size[e[x][i]];       }     for (i = 0; i <= size[x]; i++)       dp[x][i] = min(dp[x][i], dp[x][size[x] - i] + 1);   }   int main() {     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);       d[a]++;       d[b]++;     }     if (n == 2) {       printf( 1 );       return 0;     }     for (i = 1; i <= n; i++)       if (d[i] != 1) break;     root = i;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) dp[i][j] = inf;     dfs(root, 0);     printf( %d n , dp[root][size[root] / 2]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     T f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     x *= f;   }   template <typename T>   void prll(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) prll(x / 10);     putchar(x % 10 +  0 );   }   struct Change {     int x, y, Ans;   } q[2005];   char s[2005][2005];   int up[2005][2005], down[2005][2005];   int dp[2005][2005];   int n, m, Q;   struct Deque {     int s, t, deq[2005];     Deque() { s = 1, t = 0; }     bool empty() { return s > t; }     void push_back(int x) { deq[++t] = x; }     void pop_back() { t--; }     void pop_front() { s++; }     void clear() { s = 1, t = 0; }     int front() { return deq[s]; }     int back() { return deq[t]; }   } q1, q2;   bool check(const int x, const int len) {     q1.clear();     q2.clear();     for (int i = 1; i < len; i++) {       while (!q1.empty() && up[x][q1.back()] >= up[x][i]) q1.pop_back();       q1.push_back(i);       while (!q2.empty() && down[x][q2.back()] >= down[x][i]) q2.pop_back();       q2.push_back(i);     }     for (int i = len; i <= m; i++) {       while (!q1.empty() && q1.front() <= i - len) q1.pop_front();       while (!q2.empty() && q2.front() <= i - len) q2.pop_front();       while (!q1.empty() && up[x][q1.back()] >= up[x][i]) q1.pop_back();       q1.push_back(i);       while (!q2.empty() && down[x][q2.back()] >= down[x][i]) q2.pop_back();       q2.push_back(i);       if (up[x][q1.front()] + down[x][q2.front()] - 1 >= len) return true;     }     return false;   }   int main() {     read(n);     read(m);     read(Q);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 1; i <= Q; i++) {       read(q[i].x);       read(q[i].y);       s[q[i].x][q[i].y] =  X ;       q[i].Ans = 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] !=  . ) s[i][j] = 0;         if (s[i][j]) up[i][j] = up[i - 1][j] + 1;       }     }     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= m; j++)         if (s[i][j]) down[i][j] = down[i + 1][j] + 1;     }     int res = 0;     for (int i = 1; i <= n; i++)       if (s[i][1]) dp[i][1] = 1, res = max(res, dp[i][1]);     for (int i = 1; i <= m; i++)       if (s[1][i]) dp[1][i] = 1, res = max(res, dp[i][1]);     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= m; j++)         if (s[i][j])           dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1,           res = max(res, dp[i][j]);     }     for (int i = Q; i >= 1; i--) {       q[i].Ans = res;       if (i == 1) break;       int x = q[i].x, y = q[i].y;       s[x][y] = 1;       for (int i = 1; i <= n; i++)         if (s[i][y]) up[i][y] = up[i - 1][y] + 1;       for (int i = n; i >= 1; i--)         if (s[i][y]) down[i][y] = down[i + 1][y] + 1;       int l = 0, r = m, mid, ans;       while (l <= r) {         mid = (l + r) >> 1;         if (check(x, mid))           l = mid + 1, ans = mid;         else           r = mid - 1;       }       res = max(ans, res);     }     for (int i = 1; i <= Q; i++) printf( %d n , q[i].Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, t = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) t = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * t;   }   const int N = 3005;   int n, m, T, K, w[N], s[N], U[N], pr[N], su[N];   long long Sum, Ans;   vector<int> G[N];   int C(int n) { return n * (n + 1) / 2; }   void Add(int i, int t) {     Sum += (1ll * (i - U[i]) * (su[i] - i) + C(su[i] - i - 1)) * t;   }   int main() {     n = read(), m = read(), T = read(), K = read();     for (int i = 1; i <= T; i++) {       int x = read(), y = read();       G[y].push_back(x);     }     if (K == 0) return cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2, 0;     for (int l = 1; l <= m; l++) {       memset(w, 0, sizeof(w)), Sum = 0;       for (int r = l; r <= m; r++)         for (auto x : G[r]) w[x]++;       for (int i = 1; i <= n; i++)         if (i == 1 || w[i]) {           U[i] = i, pr[i] = i - 1, su[i] = i + 1, s[i] = 0;           while (pr[i] && !w[pr[i]]) pr[i]--;           if (i > 1) pr[i] = max(pr[i], 1);           while (su[i] <= n && !w[su[i]]) su[i]++;           while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];           Add(i, +1);         }       for (int r = m; r >= l; r--) {         Ans += Sum;         for (auto x : G[r]) {           int t = x;           w[x]--;           if (x != 1 && !w[x]) {             t = su[x], pr[su[x]] = pr[x];             Add(x, -1), Add(pr[x], -1), su[pr[x]] = su[x], Add(pr[x], +1);           }           for (int j = 1, i = t; j <= K && i <= n; j++, i = su[i]) {             if (U[i] < x) s[i]--;             Add(i, -1);             while (U[i] && s[i] + w[U[i]] < K) s[i] += w[U[i]], U[i] = pr[U[i]];             Add(i, +1);           }         }       }     }     cout << 1ll * n * (n + 1) / 2 * m * (m + 1) / 2 - Ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   struct Node {     int x, y, w;   } a, b, c, g[6005];   int n, x, y, S, m[5][5], f[5][5][5];   long long now1, now2, ans1, ans2, ans3;   inline int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       g[i].x = read();       g[i].y = read();     }     for (int i = 1; i <= n; i++) {       memset(f, 0, sizeof f);       a.x = (g[i].x + 3) % 4 + 1;       a.y = (g[i].y + 3) % 4 + 1;       for (int j = 1; j <= n; j++) {         if (i != j) {           if (abs(g[i].x - g[j].x) * abs(g[i].y - g[j].y)) {             f[(g[j].x + 3) % 4 + 1][(g[j].y + 3) % 4 + 1]              [(gcd(abs(g[i].x - g[j].x), abs(g[i].y - g[j].y)) + 3) % 4 + 1]++;           } else {             f[(g[j].x + 3) % 4 + 1][(g[j].y + 3) % 4 + 1]              [(abs(g[i].x - g[j].x) + abs(g[i].y - g[j].y) + 3) % 4 + 1]++;           }         }       }       for (int j = 0; j < 16; j++) {         b.x = j / 4 + 1;         b.y = j % 4 + 1;         for (b.w = 1; b.w <= 4; b.w++) {           now1 = f[b.x][b.y][b.w];           f[b.x][b.y][b.w]--;           for (int k = 0; k < 16; k++) {             c.x = k / 4 + 1;             c.y = k % 4 + 1;             S = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);             if (S & 1) continue;             S /= 2;             for (c.w = (b.w + 1) % 2 + 1; c.w <= 4; c.w += 2) {               now2 = now1 * f[c.x][c.y][c.w];               a.w = gcd(abs(b.x - c.x) + 4, abs(b.y - c.y) + 4);               if ((S + (a.w + b.w + c.w) / 2) & 1) continue;               if (b.w % 2 + c.w % 2) {                 ans1 += now2;               } else {                 ans2 += now2;               }             }           }           f[b.x][b.y][b.w]++;         }       }     }     writeln(ans1 / 2 + ans2 / 6);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<stack<int>> ids;   vector<int> b;   string answer;   int segtree_size;   template <typename T>   struct segtree {     int segtree_size;     vector<T> segtree;     T identity;     T (*UpdateFn)(T, T);     void InitSegtree(int main_size, T (*UpdateFunction)(T, T), T fun_identity) {       segtree_size = 1;       while (segtree_size < main_size) segtree_size *= 2;       segtree_size *= 2;       segtree.resize(segtree_size);       UpdateFn = UpdateFunction;       this->identity = fun_identity;     }     void UpdateAllParents() {       for (int i = segtree_size / 2 - 1; i > 0; i--)         segtree[i] = UpdateFn(segtree[i * 2], segtree[i * 2 + 1]);     }     void ChangeValue(int index, T value) {       segtree[index + segtree_size / 2] = value;     }     T GetValue(int index) { return segtree[index + segtree_size / 2]; }     void Update(int pos, T value) {       for (segtree[pos += segtree_size / 2] = value; pos > 1; pos /= 2)         segtree[pos / 2] = UpdateFn(segtree[pos], segtree[pos ^ 1]);     }     T Query(int start, int finish) {       T ans = this->identity;       for (start += segtree_size / 2, finish += segtree_size / 2; start < finish;            start /= 2, finish /= 2) {         if (start % 2 == 1) ans = UpdateFn(ans, segtree[start++]);         if (finish % 2 == 0) ans = UpdateFn(ans, segtree[finish--]);       }       return UpdateFn(ans, segtree[start]);     }     void Destroy() { segtree.clear(); }   };   struct segtree<int> tree;   void In() {     cin >> n;     ids.resize(n + 1);     b.resize(n);     tree.InitSegtree(         n + 1, [](int a, int b) -> int { return max(a, b); }, INT_MIN);     int a;     for (int i = 0; i < n; i++) {       cin >> a;       tree.ChangeValue(i, a);     }     tree.UpdateAllParents();     for (int i = 0; i < n; i++) cin >> b[i];   }   void Solve() {     answer =  NO ;     for (int i = 0; i < n; i++) ids[tree.GetValue(i)].push(i);     for (int i = n - 1; i >= 0; i--) {       if (ids[b[i]].empty()) return;       int a_idx = ids[b[i]].top();       ids[b[i]].pop();       if (tree.Query(a_idx + 1, n) > b[i]) return;       tree.Update(a_idx, 0);     }     answer =  YES ;   }   void Out() {     cout << answer << endl;     tree.Destroy();     ids.clear();     b.clear();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       In();       Solve();       Out();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i;     cin >> n;     long long a[n + 1];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long ans = 0, sum = 0;     for (i = 0; i < n; i++) {       if (sum <= a[i]) {         ans++;         sum += a[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int dcmp(double a, double b) {     return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1;   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       int n;       scanf( %d , &n);       printf( %d n , n / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 4e18;   long long ver[305][305], hor[305][305], ver2[305][305], hor2[305][305];   int con[305][305];   pair<pair<int, int>, pair<int, int> > ans;   long long dif = inf, cur, a, b;   int main(void) {     memset(ver, 0, sizeof(ver));     memset(hor, 0, sizeof(hor));     memset(ver2, 0, sizeof(ver2));     memset(hor2, 0, sizeof(hor2));     int n, m, t, i, j, k, l, r, mid, it;     int eq, asc, des;     scanf( %d %d %d , &n, &m, &t);     scanf( %d %d %d , &eq, &asc, &des);     for ((i) = (1); (i) <= (n); ++(i)) {       for ((j) = (1); (j) <= (m); ++(j)) {         scanf( %d , &con[i][j]);         if (j > 1) {           hor[i][j] = hor[i][j - 1];           hor2[i][j] = hor2[i][j - 1];           if (con[i][j] == con[i][j - 1]) {             hor[i][j] += eq;             hor2[i][j] += eq;           } else if (con[i][j - 1] < con[i][j]) {             hor[i][j] += asc;             hor2[i][j] += des;           } else {             hor[i][j] += des;             hor2[i][j] += asc;           }         }         if (i > 1) {           ver[i][j] = ver[i - 1][j];           ver2[i][j] = ver2[i - 1][j];           if (con[i][j] == con[i - 1][j]) {             ver[i][j] += eq;             ver2[i][j] += eq;           } else if (con[i - 1][j] < con[i][j]) {             ver[i][j] += asc;             ver2[i][j] += des;           } else {             ver[i][j] += des;             ver2[i][j] += asc;           }         }       }     }     for ((i) = (1); (i) <= (n - 2); ++(i)) {       for ((j) = (1); (j) <= (m - 2); ++(j)) {         for ((k) = (i + 2); (k) <= (n); ++(k)) {           l = j + 2;           r = m;           while (l < r) {             mid = (l + r + 1) / 2;             a = hor[i][mid] - hor[i][j] + hor2[k][mid] - hor2[k][j];             b = ver2[k][j] - ver2[i][j] + ver[k][mid] - ver[i][mid];             cur = a + b;             if (cur < t)               l = mid;             else               r = mid - 1;           }           for ((it) = (l - 3); (it) <= (l + 3); ++(it)) {             if (it < j + 2)               continue;             else if (m < it)               break;             a = hor[i][it] - hor[i][j] + hor2[k][it] - hor2[k][j];             b = ver2[k][j] - ver2[i][j] + ver[k][it] - ver[i][it];             cur = a + b;             if (abs(cur - t) <= dif) {               dif = abs(cur - t);               ans = make_pair(make_pair(i, j), make_pair(k, it));               if (dif == 0) goto PRINT;             }           }         }       }     }   PRINT:;     printf( %d %d %d %d n , ans.first.first, ans.first.second, ans.second.first,            ans.second.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e6 + 2;   int a[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < (int)(n); ++i) cin >> a[i];     for (int i = 0; i < (int)((1 << n)); ++i) {       long long sum = 0;       for (int j = 0; j < (int)(n); ++j)         if (i & (1 << j))           sum += a[j];         else           sum -= a[j];       sum %= 360;       if (!sum) return cout <<  YES , 0;     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ft(1, 1LL);   int n, ans[3], hg, xxx = 0;   vector<int> graph[200005], vis(200005);   queue<int> q;   void dfs(int node, int par, int i, int h) {     if (h >= hg) hg = h, ans[i] = node;     for (auto child : graph[node])       if (child != par) dfs(child, node, i, h + 1);   }   int dfs2(int node, int par, int dest) {     if (node == dest) {       q.push(node);       vis[node] = 1;       return 1;     }     for (auto child : graph[node]) {       if (child == par) continue;       if (dfs2(child, node, dest)) {         q.push(node), vis[node] = 1;         return 1;       }     }     return 0;   }   void solve() {     cin >> n;     for (long long i = 0; i < n - 1; i++) {       int node1, node2;       cin >> node1 >> node2;       graph[node1].push_back(node2), graph[node2].push_back(node1);     }     dfs(1, 0, 0, 0);     hg = 0;     dfs(ans[0], 0, 1, 0);     xxx = hg;     dfs2(ans[0], 0, ans[1]);     hg = 0;     while (q.size()) {       int p = q.front();       if (vis[p] >= hg and p != ans[0] and p != ans[1]) hg = vis[p], ans[2] = p;       q.pop();       for (auto child : graph[p]) {         if (vis[child] == 0) vis[child] = vis[p] + 1, q.push(child);       }     }     cout << xxx + hg - 1 <<   n ;     cout << ans[1] <<     << ans[2] <<     << ans[0];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, maxn = 200007;   const long long MOD = 1004535809;   const long long LINF = 0x3f3f3f3f3f3f3f3fLL;   const long long P = 19260817;   char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = ((x << 3) + (x << 1) + ch -  0 ) % MOD, ch = getchar();     return x * f;   }   void write(int x) {     if (!x) putchar( 0 );     if (x < 0) x = -x, putchar( - );     static int sta[20];     register int tot = 0;     while (x) sta[tot++] = x % 10, x /= 10;     while (tot) putchar(sta[--tot] + 48);   }   int n;   char s[maxn];   int sump[maxn], sums[maxn];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     int f1 = 0, f2 = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( ) f2 = 1;       if (f2 == 1 && s[i] ==  ) ) f1 = 1;     }     if (f1 == 0) {       printf( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       sump[i] = sump[i - 1] + (s[i] ==  ( );     }     for (int i = n; i >= 1; i--) {       sums[i] = sums[i + 1] + (s[i] ==  ) );     }     for (int i = 1; i <= n; i++) {       if (sump[i] == sums[i]) {         printf( 1 n%d n , 2 * sump[i]);         for (int j = 1; j <= i; j++) {           if (s[j] ==  ( ) printf( %d  , j);         }         for (int j = i; j <= n; j++) {           if (s[j] ==  ) ) printf( %d  , j);         }         return 0;       }     }     for (int i = 1; i <= n; i++) {       if (sump[i] == sums[i + 1]) {         printf( 1 n%d n , 2 * sump[i]);         for (int j = 1; j <= i; j++) {           if (s[j] ==  ( ) printf( %d  , j);         }         for (int j = i + 1; j <= n; j++) {           if (s[j] ==  ) ) printf( %d  , j);         }         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool bysec(const pair<int64_t, int64_t> &a, pair<int64_t, int64_t> &b) {     return a.first > b.first;   }   void solve() {     int64_t n, x, an = 0;     cin >> n;     pair<int64_t, int64_t> A[n];     for (int64_t i = 0; i < n; i++) cin >> x, A[i] = {x, i + 1};     sort(A, A + n, bysec);     for (int64_t i = 0; i < n; i++) an += i * A[i].first + 1;     cout << an <<   n ;     for (int64_t i = 0; i < n; i++) cout << A[i].second <<    ;     cout <<   n ;   }   signed main() {     int64_t T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[100];     int n, t;     cin >> n >> t;     if (n == 1 && t == 10)       cout << -1;     else {       if (t < 10)         s[0] = t + 48;       else         s[0] =  1 ;       for (int i = 1; i < n; i++) {         s[i] =  0 ;       }       for (int i = 0; i < n; i++) {         cout << s[i];       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long sum = 0, ff = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();     return sum * ff;   }   const long long N = 16;   const long long mo = 1e9 + 7;   long long n, m, f[1 << N][5], g[1 << N], a[N], b[N], ans;   inline long long ksm(long long x, long long y) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % mo;       x = x * x % mo;       y >>= 1ll;     }     return ret;   }   signed main() {     n = read();     m = read();     for (long long i = 1; i <= n; i++) {       a[i] = read();       b[i] = read();     }     for (long long i = 1; i <= 3; i++) f[0][i] = 1;     for (long long i = 0; i < (1 << n); i++)       for (long long j = 1; j <= n; j++) {         if (i & (1 << j - 1)) continue;         for (long long k = 1; k <= 3; k++)           if (b[j] != k)             f[i | (1 << j - 1)][b[j]] =                 (f[i | (1 << j - 1)][b[j]] + f[i][k]) % mo;       }     for (long long i = 0; i < (1 << n); i++) {       long long tot = 0;       for (long long j = 1; j <= n; j++)         if (i & (1 << j - 1)) tot += a[j];       if (tot == m) ans = (ans + f[i][1] + f[i][2] + f[i][3]) % mo;     }     printf( %lld n , ans * ksm(2ll, mo - 2) % mo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct V {     vector<int> lnk;     int p;     int countBad();   };   V tab[400000];   int V::countBad() {     int c = 0;     for (__typeof((lnk).begin()) it = (lnk).begin(); it != (lnk).end(); ++it)       if (tab[*it].p == p) ++c;     return c;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int(i) = 0; (i) < (m); ++(i)) {       int a, b;       cin >> a >> b;       tab[a - 1].lnk.push_back(b - 1);       tab[b - 1].lnk.push_back(a - 1);     }     for (int(i) = 0; (i) < (n); ++(i)) tab[i].p = 0;     queue<int> Q;     for (int(i) = 0; (i) < (n); ++(i)) {       if (tab[i].countBad() > 1) Q.push(i);     }     while (!Q.empty()) {       int curr = Q.front();       Q.pop();       if (tab[curr].countBad() > 1) {         tab[curr].p ^= 1;         for (__typeof((tab[curr].lnk).begin()) it = (tab[curr].lnk).begin();              it != (tab[curr].lnk).end(); ++it)           Q.push(*it);       }     }     for (int(i) = 0; (i) < (n); ++(i)) {       printf( %d , tab[i].p);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char dir[200005];   int l[200005], r[200005], ll, rl;   int ans = 0x7fffffff;   int main() {     cin >> n;     getchar();     for (int i = 1; i <= n; i++) scanf( %c , &dir[i]);     for (int i = 1; i <= n; i++)       if (dir[i] ==  L )         scanf( %d , &l[++ll]);       else         scanf( %d , &r[++rl]);     if (ll == 0 || rl == 0) {       puts( -1 );       return 0;     }     int nowl = 1, nowr = 1;     for (nowl = 1; nowl <= ll; nowl++) {       do {         nowr++;       } while (nowr <= rl && r[nowr] < l[nowl]);       nowr--;       if (l[nowl] - r[nowr] > 0) ans = min(ans, l[nowl] - r[nowr]);     }     if (ans == 0x7fffffff) {       puts( -1 );       return 0;     } else       cout << (ans >> 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using ull = uint64_t;   using ld = long double;   using vi = vector<int64_t>;   using pii = pair<int64_t, int64_t>;   ll powr(ll a, ll b) {     ll res = 1;     while (b) {       if (b & 1) res = (res * a);       a = (a * a);       b >>= 1;     }     return res;   }   void solve() {     int64_t n, k;     cin >> n >> k;     k++;     int64_t a[n];     for (int64_t i = 0; i < n; i++) {       cin >> a[i];       a[i] = powr(10, a[i]);     }     sort(a, a + n);     int64_t ans = 0;     for (int64_t i = 0; i < n - 1 && k > 0; i++) {       int64_t den = min(k, (a[i + 1] / a[i]) - 1);       ans += a[i] * den;       k -= den;     }     if (k > 0) {       ans += a[n - 1] * k;     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int64_t t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     pair<long long int, long long int> a[100005];     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     if (n % 2 == 0) {       cout << n / 2 << endl;     } else {       cout << n / 2 + 1 << endl;     }     for (int i = 0; i < n; i += 2) {       cout << a[i].second <<    ;     }     cout << endl << n / 2 << endl;     for (int i = 1; i < n; i += 2) {       cout << a[i].second <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }     return f * ans;   }   const long long MAXN = 4e5 + 11;   long long phi[MAXN], N, A[MAXN], id[MAXN], pri[MAXN], mu[MAXN], v[MAXN],       inv[MAXN], V[MAXN];   vector<long long> vec[MAXN], Vec[MAXN];   void Init() {     mu[1] = 1, phi[1] = 1;     V[1] = 1;     for (long long i = 2; i <= N; i++) {       if (!v[i]) {         pri[++pri[0]] = i, v[i] = i, mu[i] = -1, phi[i] = i - 1;         V[i] = inv[i - 1] * i % 1000000007;       }       for (long long j = 1; j <= pri[0] && i <= N / pri[j]; j++) {         v[i * pri[j]] = pri[j];         if (!(i % pri[j])) {           phi[i * pri[j]] = phi[i] * pri[j];           V[i * pri[j]] = V[i];           mu[i * pri[j]] = 0;           break;         }         phi[i * pri[j]] = phi[i] * (pri[j] - 1);         mu[i * pri[j]] = -mu[i];         V[i * pri[j]] = V[i] * V[pri[j]] % 1000000007;       }     }     return;   }   long long ksm(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a, ans %= 1000000007;       a *= a, a %= 1000000007;       b >>= 1;     }     return ans;   }   long long in[MAXN], out[MAXN], rev[MAXN], dep[MAXN], tot, Log[MAXN], F[MAXN],       sta[MAXN], Q[MAXN], q[MAXN], f[MAXN];   vector<long long> C;   void dfs(long long u, long long fath) {     in[u] = ++tot, rev[tot] = u, dep[u] = dep[fath] + 1;     for (auto v : vec[u])       if (v != fath) {         dfs(v, u);         rev[++tot] = u;       }     out[u] = tot;   }   bool cmp(long long x, long long y) { return in[x] < in[y]; }   struct RMQ {     long long Minn[MAXN][21], ps[MAXN][21];     void init() {       for (long long i = 1; i <= tot; i++)         Minn[i][0] = dep[rev[i]], ps[i][0] = rev[i];       for (long long j = 1; (1 << j) <= tot; j++)         for (long long i = 1; i + (1 << j) - 1 <= tot; i++) {           if (Minn[i][j - 1] <= Minn[i + (1 << (j - 1))][j - 1])             Minn[i][j] = Minn[i][j - 1], ps[i][j] = ps[i][j - 1];           else             Minn[i][j] = Minn[i + (1 << (j - 1))][j - 1],             ps[i][j] = ps[i + (1 << (j - 1))][j - 1];         }       return;     }     long long Qlca(long long u, long long v) {       if (in[u] > in[v]) swap(u, v);       long long L = in[u], R = in[v], len = R - L + 1, k = Log[len];       long long w1 = Minn[L][k], w2 = Minn[R - (1 << k) + 1][k];       if (w1 <= w2) return ps[L][k];       return ps[R - (1 << k) + 1][k];     }   } S;   void ins(long long x) {     if (sta[0] == 1) {       if (sta[1] != x) sta[++sta[0]] = x;       return;     }     long long now = S.Qlca(x, sta[sta[0]]);     while (sta[0] > 1 && dep[sta[sta[0] - 1]] >= dep[now])       Vec[sta[sta[0] - 1]].push_back(sta[sta[0]]), sta[0]--;     if (dep[sta[sta[0]]] > dep[now]) Vec[now].push_back(sta[sta[0]]), sta[0]--;     if (sta[sta[0]] != now) sta[++sta[0]] = now;     sta[++sta[0]] = x;     return;   }   void build() {     sta[0] = 0;     sta[++sta[0]] = 1;     for (long long i = 1; i <= Q[0]; i++) ins(Q[i]);     while (sta[0] > 1) Vec[sta[sta[0] - 1]].push_back(sta[sta[0]]), sta[0]--;     return;   }   long long S1[MAXN], S2[MAXN], res, D;   void Clear() {     for (auto v : C) Vec[v].clear(), S1[v] = S2[v] = 0;     C.clear();     return;   }   void dfs1(long long u) {     long long now1 = 0, now2 = 0;     C.push_back(u);     for (auto v : Vec[u]) {       dfs1(v);       if (!(A[u] % D))         now2 += (S1[v] * phi[A[u]]) % 1000000007,             now2 -= phi[A[u]] * S2[v] % 1000000007 * dep[u] % 1000000007,             now2 = ((now2 % 1000000007) + 1000000007) % 1000000007;       now1 -= 2 * dep[u] * S2[u] % 1000000007 * S2[v] % 1000000007,           now1 = (now1 % 1000000007 + 1000000007) % 1000000007;       now1 += S1[u] * S2[v], now1 += S2[u] * S1[v], now1 %= 1000000007;       S1[u] += S1[v], S2[u] += S2[v];       S1[u] %= 1000000007, S2[u] %= 1000000007;     }     if (!(A[u] % D)) S1[u] += dep[u] * phi[A[u]] % 1000000007, S2[u] += phi[A[u]];     S1[u] %= 1000000007, S2[u] %= 1000000007;     res += (now1 + now2) * 2 % 1000000007;     return;   }   signed main() {     N = read();     for (long long i = 1; i <= N; i++) A[i] = read(), id[A[i]] = i;     inv[1] = 1;     for (long long i = 2; i <= N; i++)       inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;     for (long long i = 1; i < N; i++) {       long long u = read(), v = read();       vec[u].push_back(v), vec[v].push_back(u);     }     Init();     dfs(1, 0);     Log[0] = -1;     for (long long i = 1; i <= tot; i++) Log[i] = Log[i >> 1] + 1;     S.init();     for (long long i = 1; i <= N; i++) {       D = i;       Q[0] = 0, sta[0] = 0;       bool ff = 0;       for (long long j = i; j <= N; j += i) Q[++Q[0]] = id[j];       sort(Q + 1, Q + Q[0] + 1, cmp);       build();       res = 0;       dfs1(1);       F[i] = res;       Clear();     }     for (long long i = 1; i <= N; i++)       for (long long j = i; j <= N; j += i)         f[i] += mu[j / i] * F[j],             f[i] = (f[i] % 1000000007 + 1000000007) % 1000000007;     long long Ans = 0;     for (long long i = 1; i <= N; i++) Ans += V[i] * f[i], Ans %= 1000000007;     printf( %lld n ,            Ans * ksm(N * (N - 1) % 1000000007, 1000000007 - 2) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> v(n);     for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;     sort(v.begin(), v.end());     for (int i = 0; i < n - 1; i++) {       if (v[i].second > v[i + 1].second && v[i].first != v[i + 1].first) {         cout <<  Happy Alex ;         return 0;       }     }     cout <<  Poor Alex ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[2];   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     for (int i = s.size() - 1; i >= -1; i--) {       if (i > -1) cnt[s[i] -  0 ]++;       if (s[i] ==  1  && (i == 0 || s[i - 1] ==  0 )) {         int req = cnt[1] - cnt[0];         for (int j = i; j < s.size() && s[j] ==  1  && req > 0; j++) {           cnt[0]++;           req--;           s[j] =  0 ;         }       }     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 3e5 + 5;   int nxt[nax][20];   int reach[20];   int main() {     int n, q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     for (int bit = 0; bit < 19; bit++) reach[bit] = n;     for (int i = n - 1; i >= 0; i--) {       for (int bit = 0; bit < 19; bit++) {         nxt[i][bit] = n;       }       for (int bit = 0; bit < 19; bit++) {         if (arr[i] & (1 << bit)) {           nxt[i][bit] = min(nxt[i][bit], reach[bit]);           if (reach[bit] < n) {             for (int j = 0; j < 19; j++) {               nxt[i][j] = min(nxt[i][j], nxt[reach[bit]][j]);             }           }           reach[bit] = i;         }       }     }     while (q--) {       int x, y;       cin >> x >> y;       x--;       y--;       bool res = false;       for (int bit = 0; bit < 19; bit++) {         if (arr[y] & (1 << bit)) {           if (nxt[x][bit] <= y) {             res = true;             break;           }         }       }       (res ? cout <<  Shi n  : cout <<  Fou n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 100;   int n, k;   long long C[maxn][maxn];   void Init() {     C[0][0] = 1;     for (int i = 1; i < maxn; ++i) {       for (int j = 0; j <= i; ++j) {         if (j == 0 || j == i) {           C[i][j] = 1;         } else {           C[i][j] = C[i - 1][j - 1] + C[i - 1][j];         }       }     }   }   int main() {     ios::sync_with_stdio(false);     Init();     while (scanf( %d%d , &n, &k) != EOF) {       long long ans = 0;       if (k >= 1) {         ans += 1;       }       if (k >= 2) {         ans += C[n][2];       }       if (k >= 3) {         ans += C[n][3] * 2;       }       if (k >= 4) {         ans += C[n][4] * 9;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2147483647;   const long long LLINF = 9223372036854775807LL;   int l, r, p;   bool isprime(int x) {     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   const int maxn = 3000010;   int a[maxn];   int acnt = 0;   bool prime[110];   void gen(long long val, int lst) {     if (lst < p) gen(val, lst + 1);     if (prime[lst] && val * lst <= r) {       a[acnt++] = val * lst;       gen(val * lst, lst);     }   }   int dp[maxn];   bool can[maxn];   int cinf = 110;   int main() {     for (int i = 0; i < 110; ++i) prime[i] = isprime(i);     scanf( %d%d%d , &l, &r, &p);     a[acnt++] = 1;     gen(1, 2);     sort(a, a + acnt);     for (int i = 0; i < acnt; ++i) dp[i] = cinf;     dp[0] = 0;     for (int j = 0; j < p; ++j) {       int ptr = 0;       for (int i = 0; i < acnt; ++i) {         if (dp[i] > p) continue;         can[i] |= dp[i] <= p;         if (a[i] * (long long)j <= r) {           int needval = a[i] * j;           while (a[ptr] != needval) ++ptr;           int wh = ptr;           dp[wh] = min(dp[wh], dp[i] + 1);         }         ++dp[i];       }     }     int ans = 0;     for (int i = 0; i < acnt; ++i)       if (a[i] >= l) ans += can[i];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void speed() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void convertString(string &s, char t) {     if (t ==  L ) {       for (int i = 0; s[i] !=   0 ; i++)         if (s[i] >= 65 && s[i] <= 90) s[i] += 32;     } else {       for (int i = 0; s[i] !=   0 ; i++)         if (s[i] >= 97 && s[i] <= 122) s[i] -= 32;     }   }   int compare_two_values(double a, double b) {     if (fabs(a - b) <= 1e-10) return 0;     return a > b ? 1 : -1;   }   int main() {     speed();     short n, d, c = 0;     cin >> n >> d;     for (char i =  a ; n > 0; n--) {       cout << i;       c++;       if (c == 26 || c == d)         c = 0, i =  a ;       else         i++;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   struct Graph {     int head[N], v[N << 1], w[N << 1], next[N << 1], e;     void clear() {       e = 0;       memset(head, -1, sizeof(head));     }     void add(int u, int v, int w) {       this->v[e] = v;       this->w[e] = w;       next[e] = head[u];       head[u] = e++;     }   } G;   int n, a[N], ans[N], id[N];   long long pre[N];   void dfs(int u, int d, long long sum) {     id[d] = u;     pre[d] = sum;     int p = lower_bound(pre + 1, pre + 1 + d, sum - a[u]) - pre;     ans[id[d - 1]]++;     ans[id[p - 1]]--;     for (int e = G.head[u]; ~e; e = G.next[e]) {       int v = G.v[e], w = G.w[e];       dfs(v, d + 1, sum + w);       ans[u] += ans[v];     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     G.clear();     for (int i = 2; i <= n; i++) {       int p, w;       scanf( %d%d , &p, &w);       G.add(p, i, w);     }     dfs(1, 1, 0);     for (int i = 1; i <= n; i++) {       printf( %d%c , ans[i],    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     set<int> vals;     set<int> cur;     for (int i = 0; i < n; ++i) {       {         set<int> cur2;         transform(cur.begin(), cur.end(), inserter(cur2, cur2.end()),                   [&a, i](int x) { return x | a[i]; });         cur = cur2;       }       cur.insert(a[i]);       copy(cur.begin(), cur.end(), inserter(vals, vals.begin()));     }     cout << vals.size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     int i;     bool work = false;     cin >> p;     for (i = 0; i < p.size(); i++)       if (p[i] ==  H  || p[i] ==  Q  || p[i] ==  9 ) work = true;     if (work)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q;     cin >> q;     while (q--) {       long long int n, m;       cin >> n >> m;       char s[n][m];       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           cin >> s[i][j];         }       }       long long int r[n], c[m];       for (long long int i = 0; i < n; i++) {         long long int temp = 0;         for (long long int j = 0; j < m; j++) {           if (s[i][j] ==  * ) {             temp++;           }         }         r[i] = temp;       }       for (long long int i = 0; i < m; i++) {         long long int temp = 0;         for (long long int j = 0; j < n; j++) {           if (s[j][i] ==  * ) {             temp++;           }         }         c[i] = temp;       }       long long int ans = INT_MAX;       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           long long int temp;           temp = n + m - r[i] - c[j];           if (s[i][j] ==  . ) {             temp--;           }           ans = min(ans, temp);         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int Sum = 0;     for (int i = 1; i <= n; i++) Sum += a[i];     int indx = 0;     int Taken = 0;     while (Sum > 2 * Taken) {       indx++;       Taken += a[indx];     }     cout << indx << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, fl = 1;     char st = getchar();     while (st <  0  || st >  9 ) {       if (st ==  - ) fl = -1;       st = getchar();     }     while (st >=  0  && st <=  9 ) x = x * 10 + st -  0 , st = getchar();     return x * fl;   }   const int N = 1e6 + 10, mod = 1e9 + 9;   int n, b, w;   long long ans, fac[8005], invfac[8005];   inline long long ksm(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   inline long long C(int x, int y) {     return fac[x] * invfac[y] % mod * invfac[x - y] % mod;   }   int main() {     ans = 1;     n = read();     w = read();     b = read();     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i <= 8000; i++) fac[i] = fac[i - 1] * i % mod;     invfac[0] = invfac[1] = 1;     invfac[8000] = ksm(fac[8000], mod - 2);     for (int i = 7999; i >= 2; i--) {       invfac[i] = invfac[i + 1] * (i + 1) % mod;     }     ans = fac[w] * fac[b] % mod;     ans = ans * (w - 1) % mod;     ans = ans * C(w + b - 3, n - 3) % mod;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int w, b;     cin >> w >> b;     vector<int> ve;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       ve.push_back(x);     }     int res = 0;     for (int i = 0, j = n - 1; i <= j; i++, j--) {       if (ve[i] == ve[j] && ve[i] == 2) {         res += (i == j ? 1 : 2) * min(w, b);       } else if (ve[i] == ve[j])         continue;       else if (ve[i] != ve[j]) {         if (ve[i] == 2)           res += (ve[j] == 0 ? w : b);         else if (ve[j] == 2)           res += (ve[i] == 0 ? w : b);         else {           cout << -1 << endl;           return 0;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &t) {     t = 0;     char ch = getchar();     int f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     do {       (t *= 10) += ch -  0 ;       ch = getchar();     } while ( 0  <= ch && ch <=  9 );     t *= f;   }   template <typename T>   void write(T t) {     if (t < 0) {       putchar( - );       write(-t);       return;     }     if (t > 9) write(t / 10);     putchar( 0  + t % 10);   }   template <typename T>   void writeln(T t) {     write(t);     puts(  );   }   const int maxn = 610;   const int maxm = 300010;   int n, a[maxm];   namespace xyr {   const int maxm = 1000000;   int n, tot, head[maxn], id[610][610];   int nxt[maxm], to[maxm], ans;   void Add(int x, int y) {     tot++;     nxt[tot] = head[x];     head[x] = tot;     to[tot] = y;   }   void add(int x, int y, int z) {     if (id[x][y]) return;     id[x][y] = id[y][x] = z;     Add(x, y);     Add(y, x);   }   int match[maxn], pre[maxn], vis[maxn], fa[maxn];   queue<int> q;   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   int mk[maxn], cnt;   int lca(int x, int y) {     cnt++;     while (1) {       if (x) {         x = find(x);         if (mk[x] == cnt) return x;         mk[x] = cnt;         x = pre[match[x]];       }       swap(x, y);     }   }   void blossom(int x, int y, int z) {     while (find(x) != z) {       pre[x] = y;       y = match[x];       if (vis[y] == 2) vis[y] = 1, q.push(y);       if (find(x) == x) fa[x] = z;       if (find(y) == y) fa[y] = z;       x = pre[y];     }   }   int dfs(int s) {     for (int i = 1; i <= n; i++) vis[i] = pre[i] = 0, fa[i] = i;     q = queue<int>();     q.push(s);     vis[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = head[u], v; i; i = nxt[i]) {         v = to[i];         if (find(u) == find(v) || vis[v] == 2) continue;         if (!vis[v]) {           vis[v] = 2;           pre[v] = u;           if (!match[v]) {             for (int x = v, lst; x; x = lst)               lst = match[pre[x]], match[x] = pre[x], match[pre[x]] = x;             return 1;           }           vis[match[v]] = 1;           q.push(match[v]);         } else {           int z = lca(u, v);           blossom(u, v, z);           blossom(v, u, z);         }       }     }     return 0;   }   void solve() {     for (int i = n; i >= 1; i--)       if (!match[i]) ans += dfs(i);   }   };  // namespace xyr   bool ban[610];   int mx, used[maxm];   vector<pair<int, int>> V, V2;   namespace BF {   vector<int> g[610];   int tim[610];   queue<int> q;   void link(int x, int y) { g[x].push_back(y), g[y].push_back(x); }   void solve() {     for (int i = 1; i <= mx; i++) tim[i] = -1;     for (int i = 1; i <= mx; i++)       if (ban[i]) tim[i] = 0, q.push(i);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int &y : g[x])         if (tim[y] == -1) tim[y] = tim[x] + 1, q.push(y);     }   }   };  // namespace BF   int dir[maxm], bel[maxn];   bool MK[maxm];   namespace Forest {   bool oncyc[610], vis[610];   int fa[610], from[610];   vector<pair<int, int>> g[610];   void add(int x, int y, int z) {     g[x].push_back(make_pair(y, z)), g[y].push_back(make_pair(x, z));   }   int X, Y, Z;   vector<int> V[610];   int D[610], tot, S, dis[610];   void dfs(int x, int p, int w) {     vis[x] = 1;     fa[x] = p;     from[x] = w;     V[S].push_back(x);     dis[x] = dis[p] + 1;     for (auto [y, z] : g[x]) {       if (z == from[x]) continue;       if (vis[y]) {         if (dis[x] > dis[y]) Y = x, X = y, Z = z;       } else         dfs(y, x, z);     }   }   int VIS[610];   void DFS(int x, int f) {     VIS[x] = 1;     for (auto [y, z] : g[x])       if (!oncyc[y] && z != f && !VIS[y]) {         DFS(y, z);         dir[z] = y;       }   }   int TREE[610];   void solve() {     for (int i = 1; i <= mx; i++)       if (!vis[i]) {         X = Y = 0;         S = i;         dfs(i, 0, -1);         if (X) {           tot = 0;           dir[Z] = X;           while (1) {             D[++tot] = Y;             if (Y == X) break;             dir[from[Y]] = Y;             Y = fa[Y];           }           for (int j = 1; j <= tot; j++) oncyc[D[j]] = 1;           for (int j = 1; j <= tot; j++) DFS(D[j], 0);         } else {           TREE[i] = 1;           for (int &x : V[i]) {             bel[x] = i;           }         }       }     tot = 0;   }   int XYR[610];   void insert(int x) { XYR[bel[x]] = x; }   void insert(int x, int y) { insert(x), insert(y); }   void solve_again() {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= mx; i++)       if (bel[i] == i && TREE[i]) {         if (XYR[i]) {           S = i;           V[i].clear();           dfs(XYR[i], 0, -1);         } else           XYR[i] = i;         for (int &x : V[i])           if (x != XYR[i]) dir[from[x]] = x;       }   }   };  // namespace Forest   int now, R[maxm];   int GETNXT() {     while (used[now]) now++;     used[now] = 1;     return now;   }   int main() {     read(n);     int F1 = 1, F2 = 1;     for (int i = 1; i <= n; i++)       read(a[i]), R[i] = a[i], mx = max(mx, a[i]), used[a[i]] = 1,                   F1 &= (a[i] == 0), F2 &= (a[i] != 0);     if (F1) {       for (int i = 0; i < n; i++) printf( %d  , i / 2 + 1);       puts(  );       return 0;     }     if (F2) {       for (int i = 1; i <= n; i++) printf( %d  , a[i]);       puts(  );       return 0;     }     now = 1;     for (int l = 1, r; l <= n; l = r + 1)       if (!a[l]) {         r = l;         while (r < n && !a[r + 1]) r++;         int x = a[l - 1], y = a[r + 1], len = r - l + 1;         if (l == 1) {           if (len & 1) {             for (int i = 1; i < r; i += 2) a[i] = a[i + 1] = GETNXT();             a[r] = a[r + 1];           } else {             for (int i = 1; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();           }         } else if (r == n) {           if (len & 1) {             for (int i = l + 1; i <= n; i += 2) a[i] = a[i + 1] = GETNXT();             a[l] = a[l - 1];           } else {             for (int i = l; i <= n; i += 2) a[i] = a[i + 1] = GETNXT();           }         } else {           assert(x && y);           if (x == y) {             if (len & 1) {               a[l] = a[l - 1];               for (int i = l + 1; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();             } else {               for (int i = l; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();             }           } else {             V.push_back(make_pair(l, r));           }         }       } else         r = l;     for (int i = 1; i < n; i++)       if (a[i] && a[i + 1] && a[i] == a[i + 1] && a[i] <= mx) ban[a[i]] = 1;     for (pair<int, int> &A : V)       if ((A.second - A.first + 1) % 2 == 1)         BF::link(a[A.first - 1], a[A.second + 1]);     BF::solve();     for (int i = 1; i <= mx; i++) ban[i] = (BF::tim[i] != -1);     for (auto [l, r] : V) {       int x = a[l - 1], y = a[r + 1], len = r - l + 1;       if (ban[y] && (!ban[x] || BF::tim[y] <= BF::tim[x])) {         if (len & 1) {           for (int i = l + 1; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();           a[l] = a[l - 1];         } else {           for (int i = l; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();         }       } else if (ban[x] && (!ban[y] || BF::tim[y] >= BF::tim[x])) {         if (len & 1) {           for (int i = l; i < r; i += 2) a[i] = a[i + 1] = GETNXT();           a[r] = a[r + 1];         } else {           for (int i = l; i <= r; i += 2) a[i] = a[i + 1] = GETNXT();         }       } else         V2.push_back(make_pair(l, r));     }     for (int i = 0; i < V2.size(); i++) {       int l = V2[i].first, r = V2[i].second, x = a[l - 1], y = a[r + 1],           len = r - l + 1;       if (len & 1) Forest::add(x, y, i);     }     Forest::solve();     xyr::n = mx;     for (int i = 0; i < V2.size(); i++) {       int l = V2[i].first, r = V2[i].second, x = a[l - 1], y = a[r + 1],           len = r - l + 1;       if (len & 1 ^ 1) xyr::add(bel[x], bel[y], i + 1);     }     xyr::solve();     for (int i = 1; i <= mx; i++)       if (xyr::match[i] && xyr::match[i] < i) {         int z = xyr::id[i][xyr::match[i]] - 1;         MK[z] = 1;         int x = a[V2[z].first - 1], y = a[V2[z].second + 1];         Forest::insert(x, y);       }     Forest::solve_again();     for (int i = 0; i < V2.size(); i++) {       int l = V2[i].first, r = V2[i].second, x = a[l - 1], y = a[r + 1],           len = r - l + 1;       if (MK[i]) {         a[l] = a[l - 1], a[r] = a[r + 1];         for (int j = l + 1; j < r; j += 2) a[j] = a[j + 1] = GETNXT();       } else if (dir[i]) {         if (dir[i] == x) {           for (int j = l + 1; j <= r; j += 2) a[j] = a[j + 1] = GETNXT();           a[l] = a[l - 1];         } else {           for (int j = l; j < r; j += 2) a[j] = a[j + 1] = GETNXT();           a[r] = a[r + 1];         }       } else if (len & 1) {         for (int j = l; j < r; j += 2) a[j] = a[j + 1] = GETNXT();         a[r] = GETNXT();       } else {         for (int j = l; j <= r; j += 2) a[j] = a[j + 1] = GETNXT();       }     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100005];   int n, t, v[100005], c[100005];   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) cin >> a[i].first >> a[i].second;     for (int i = 0; i < n; ++i) cin >> c[i + 1];     for (int i = 0; i < n - 1; ++i) {       if (c[a[i].first] != c[a[i].second]) {         t++;         v[a[i].first]++;         v[a[i].second]++;       }     }     for (int i = 1; i <= n; ++i) {       if (v[i] == t) {         cout <<  YES n  << i <<   n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


//Shrey Dubey         #include<iostream>   #include<string>   #include<algorithm>   #include<map>   #include<unordered_map>   #include<vector>   #include<set>   #include<list>   #include<iomanip>   #include<queue>   #include<stack>   #include <math.h>   #include<climits>   #include<bitset>   #include<cstring>   #include<numeric>   #include<array>         using namespace std;   typedef long long ll;   typedef long double ld;      #define YES cout<< YES n    #define Yes cout<< Yes n    #define NO cout<< NO n    #define No cout<< No n    #define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers   #define pb push_back   #define ff first   #define sec second   #define umap unordered_map   #define mp make_pair   #define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define fo(n) for(ll i = 0; i<n; i++)   #define fnd(stl, data) find(stl.begin(), stl.end(), data)   #define forn(x,n) for(ll x = 0; x<n; x++)   #define imax INT_MAX   #define lmax LLONG_MAX   #define imin INT_MIN   #define lmin LLONG_MIN   #define vi vector<int>   #define vl vector<ll>   #define vp vector<pair<ll,ll> >   #define vs vector<string>   #define vb vector<bool>   #define pr(t) cout<<t<<  n    #define int long long   #define ql queue<ll>   #define qp queue<pair<ll,ll> >   #define endl   n    #define nl cout<<  n    #define re cin >>   #define pll pair<ll,ll>   #define FOR(a,b) for(ll i = a; i<=b; i++)   #define all(x) x.begin(),x.end()   #define LG 22      // ll dx[] = {1,0,-1,0};   // ll dy[] = {0,1,0,-1};      ll mod = 1e9 + 7;      ll cl(ld a){       if(a>(ll) a){           return (ll)a+1;       }       else{           return (ll)a;       }   }      ll flr(ld a){       if(a < 0.0){           return (ll) a - 1;       }       return (ll) a;   }      ll gcd(ll a, ll b){       if(b == 0) return a;       else return gcd(b,a%b);   }      //code starts here      ll n,q;   const ll M = 1e5+100;   ll nxt[M] = {0}, a[M];   ll dp[LG][M] = {0};   vl fact[M];   void solve(){       re n; re q;       fo(n) re a[i+1];       for(ll i = 2; i<M; i++){           if(!fact[i].empty()) continue;           for(ll j = i; j<M; j+=i){               nxt[i] = n+1;               fact[j].pb(i);           }       }       dp[0][n+1] = n+1;       for(ll i = n; i>=1; i--){           dp[0][i] = dp[0][i+1];           for(auto f: fact[a[i]]){               // if(i == 6 && f == 7) pr( here );               dp[0][i] = min(dp[0][i],nxt[f]);               nxt[f] = i;           }           // cout<<i<< () <<dp[0][i]<<  n ;       }          for(ll j = 1; j<20; j++){           for(ll i = 1; i<=n+1; i++){               ll k = dp[j-1][i];               dp[j][i] = dp[j-1][k];           }       }       while(q--){           ll l,r; re l; re r;           ll ans = 0;           for(ll i = 19; i>=0; i--){               if(dp[i][l] <= r){                   // cout<<l<< () n ;                   ans += (1<<i);                   l = dp[i][l];               }           }           pr(ans+1);       }   }      int32_t main(){       KOBE;       ll t;       t = 1;       // re t;       while(t--) solve();   }         //common errors   // row - n, col - m always and loop var   // see the freq of numbers carefully   // see if there s array overflow   // use map for large inputs   // always check for n = 1 condition   // check loop starting and end points :(      //problem ideas   //check piegonhole wherever possible   //there might be many instances of limited answers like 0,1,2 only   // see suffix and prefix   //don t be obsessed with binary search   // try to find repeating pattern in matrices


#include <bits/stdc++.h>   using namespace std;   const pair<int, int> DD[] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                                {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   template <class T>   T smin(T &a, T b) {     if (a > b) a = b;     return a;   }   template <class T>   T smax(T &a, T b) {     if (a < b) a = b;     return a;   }   int main(void) {     srand(time(0));     cout << fixed << setprecision(7);     cerr << fixed << setprecision(7);     int n;     cin >> n;     if ((n % 4) == 2 || (n % 4) == 3) return puts( NO ) * 0;     puts( YES );     auto go = [&](int a, int b) {       cout << min(a, b) <<     << max(a, b) <<   n ;     };     for (int i = 1; i + 3 <= n; i += 4) {       if (n % 4)         go(i, n), go(i, i + 1), go(i + 1, n), go(n, i + 2), go(i + 2, i + 3),             go(i + 3, n);       else         go(i, i + 1), go(i + 2, i + 3);       go(i + 1, i + 2);       go(i, i + 3);       go(i, i + 2);       go(i + 1, i + 3);     }     vector<pair<int, int> > v;     v.push_back(make_pair(3, 2));     v.push_back(make_pair(2, 2));     v.push_back(make_pair(3, 1));     v.push_back(make_pair(0, 1));     v.push_back(make_pair(1, 3));     v.push_back(make_pair(2, 3));     v.push_back(make_pair(1, 2));     v.push_back(make_pair(1, 1));     v.push_back(make_pair(3, 0));     v.push_back(make_pair(3, 3));     v.push_back(make_pair(0, 2));     v.push_back(make_pair(0, 3));     v.push_back(make_pair(2, 0));     v.push_back(make_pair(2, 1));     v.push_back(make_pair(1, 0));     v.push_back(make_pair(0, 0));     for (int i = 1; i + 3 <= n; i += 4)       for (int j = i + 4; j + 3 <= n; j += 4)         for (auto it : v) go(i + it.first, j + it.second);     cerr <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> v;   int bil;   void gen(long long int now) {     if (now > 1000000000LL) return;     if (now != 0) v.push_back(now);     gen(now * 10 + 4);     gen(now * 10 + 7);   }   int main(void) {     gen(0);     sort(v.begin(), v.end());     cin >> bil;     for (int i = 0; i < v.size(); i++) {       if (v[i] == bil) {         cout << i + 1 << endl;         return 0;       }     }   }


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


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