#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     int blackweight = 0;     int whiteweight = 0;     int i = 0;     while (cin >> c) {       i++;       switch (c) {         case  Q :           whiteweight += 9;           break;         case  R :           whiteweight += 5;           break;         case  B :           whiteweight += 3;           break;         case  N :           whiteweight += 3;           break;         case  P :           whiteweight += 1;           break;         case  q :           blackweight += 9;           break;         case  r :           blackweight += 5;           break;         case  b :           blackweight += 3;           break;         case  n :           blackweight += 3;           break;         case  p :           blackweight += 1;           break;       }       if (i == 64) {         if (blackweight > whiteweight) cout <<  Black  << endl;         if (blackweight == whiteweight) cout <<  Draw  << endl;         if (blackweight < whiteweight) cout <<  White  << endl;         blackweight = whiteweight = i = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     return (a % p + b % p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1LL) {       if (k & 1LL) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   void self_max(int &a, int &b) { a = max(a, b); }   void self_min(int &a, int &b) { a = min(a, b); }   bool isPrime(long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long power(int first, unsigned int second, int p) {     long long res = 1;     first = first % p;     while (second > 0) {       if (second & 1) res = (res * first) % p;       second = second >> 1;       first = (first * first) % p;     }     return res;   }   void solve() {     string s1, s2;     cin >> s1 >> s2;     int n = s1.length();     int m = s2.length();     vector<int> pos[26];     for (int i = 0; i < n; i++) {       pos[s1[i] -  a ].push_back(i);     }     int ans = 0, p, flag = 0, k;     for (int i = 0; i < m; i++) {       if ((int)pos[s2[i] -  a ].size() == 0) {         cout << -1 <<   n ;         return;       } else if (flag == 0) {         p = pos[s2[i] -  a ][0];         flag = 1;       } else {         auto t =             upper_bound((pos[s2[i] -  a ]).begin(), (pos[s2[i] -  a ]).end(), p);         k = t - pos[s2[i] -  a ].begin();         if (k == (int)pos[s2[i] -  a ].size()) {           ans++;           i--;           flag = 0;         }         p = pos[s2[i] -  a ][k];       }     }     ans++;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(20);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 5;   const int INF = (int)1e9 + 7;   const double EPS = 1e-9;   const int hh[4] = {1, -1, 0, 0};   const int hc[4] = {0, 0, 1, -1};   void nhap();   void process();   int n;   int res;   int f[1000006];   int main() {     int nTest = 1;     for (int test = 1; test <= nTest; ++test) {       nhap();       process();     }   }   void nhap() {     int v;     cin >> v;     int a[10];     for (int i = 1; i <= 9; ++i) cin >> a[i];     for (int i = 1; i <= v; ++i)       for (int j = 9; j > 0; --j)         if (i >= a[j]) f[i] = max(f[i], f[i - a[j]] + 1);     if (f[v] == 0)       cout << -1;     else       while (1) {         bool ok = 1;         for (int i = 9; i > 0; --i)           if (v >= a[i] && f[v] == f[v - a[i]] + 1) {             cout << i;             v -= a[i];             ok = 0;             break;           }         if (ok) break;       }   }   void process() {}


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, x, t, c;     cin >> n >> t >> c;     vector<int> sizes;     int curr = 0;     long long ans = 0;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x > t) {         if (curr != 0) {           sizes.emplace_back(curr);           curr = 0;         }       } else {         curr++;       }     }     if (curr != 0) {       sizes.emplace_back(curr);     }     for (auto sz : sizes) {       ans += max(sz - c + 1, 0);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e4 + 5;   const int maxk = 505;   int N, d;   int dp[maxn][maxk], gem[maxn], vis[maxn][maxk];   int dfs(int pos, int prev) {     int jj = prev - (d - 250);     if (pos > 30000) return 0;     if (vis[pos][jj]) return dp[pos][jj];     vis[pos][jj] = 1;     int ans = 0;     if (prev == 1)       ans = max(ans, max(dfs(pos + 1, 1), dfs(pos + 2, 2)));     else       ans = max(ans,                 max(dfs(pos + prev - 1, prev - 1),                     max(dfs(pos + prev, prev), dfs(pos + prev + 1, prev + 1))));     return dp[pos][jj] = ans + gem[pos];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> N >> d;     for (int i = 1; i <= N; i++) {       int p;       cin >> p;       gem[p]++;     }     cout << dfs(d, d) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, j = 0, oo = 1;     cin >> n >> k;     while (k != j) {       oo *= 10;       j++;     }     long long int prod = oo * n;     while (oo != n) {       if (oo > n) {         oo %= n;         if (oo == 0) oo = n;       } else {         n %= oo;         if (n == 0) n = oo;       }     }     cout << prod / oo;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100100;   long long n, m, k;   vector<long long> g[maxn];   long long mark[maxn];   long long d[maxn];   vector<long long> q;   bool check(long long x, bool print = false) {     for (long long i = 0; i < n; i++)       if (mark[i] != 1) mark[i] = 0;     q.resize(0);     for (long long i = 0; i < n; i++) d[i] = 0;     for (long long i = 0; i < n; i++)       for (long long u : g[i])         if (!mark[u]) d[i]++;     for (long long i = 0; i < n; i++)       if (!mark[i] and d[i] * 1000000000 < g[i].size() * x)         q.push_back(i), mark[i] = 2;     for (long long i = 0; i < q.size(); i++) {       long long v = q[i];       mark[v] = 2;       for (long long u : g[v])         if (!mark[u]) {           d[u]--;           if (d[u] * 1000000000 < g[u].size() * x and !mark[u])             q.push_back(u), mark[u] = 2;         }     }     long long cnt = 0;     for (long long i = 0; i < n; i++) cnt += !mark[i];     if (print) {       cout << cnt << endl;       for (long long i = 0; i < n; i++)         if (!mark[i]) cout << i + 1 <<    ;       cout << endl;     }     return cnt;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (long long v, i = 0; i < k; i++) {       cin >> v;       v--;       mark[v] = 1;     }     for (long long v, u, i = 0; i < m; i++) {       cin >> v >> u;       v--, u--;       g[v].push_back(u);       g[u].push_back(v);     }     for (long long i = 0; i < n; i++)       if (!g[i].size()) mark[i] = 1;     long long l = 0, r = 1000000000 + 1, mid;     for (long long c = 100; c--;) {       mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     check(l, 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1.0);   using namespace std;   const double EPS = 1e-9;   const int N = 2e5 + 9;   int a[N], n, p, k;   long long sum[N], v[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> p >> k;       for (int i = 1; i <= n; i++) cin >> a[i], v[i] = 0;       sort(a + 1, a + 1 + n);       for (int i = 1; i <= n; i++) sum[i] = a[i] + sum[i - 1];       for (int i = k; i <= n; i++) {         v[i] = a[i] + v[i - k];       }       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (v[i] + sum[i % k] <= p) ans = i;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[150];   int main() {     int n, k, i, j, ans = 0, curr, temp;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &curr);       arr[curr]++;     }     for (i = 1; i <= 100; i++) {       ans += (arr[i] / 2);     }     ans /= 2;     printf( %d n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 100;   int k;   long long a[20][maxn];   int nk[20];   map<long long, pair<int, int> > mp;   long long sum = 0;   bool _is[1 << 17];   long long tol[20];   bool _a[20][maxn];   vector<pair<int, int> > que;   vector<vector<pair<int, int> > > dp[1 << 17];   pair<int, int> ans[20];   void dfs(int fir, int i, int j, int sta, int &flag) {     if (a[i][j] == fir) {       if (_a[i][j] && !_is[sta]) {         _is[sta] = 1;         flag = 1;         dp[sta].push_back(que);         return;       }     }     if (_a[i][j]) return;     long long tmp = sum - (tol[i] - a[i][j]);     if (mp.find(tmp) == mp.end()) {       return;     }     int tfir = mp[tmp].first;     int tsec = mp[tmp].second;     if (sta >> tfir & 1) {       return;     }     _a[i][j] = 1;     que.push_back({tmp, i});     dfs(fir, tfir, tsec, sta | 1 << tfir, flag);     que.pop_back();     if (!flag) _a[i][j] = 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k;     for (int i = 0; i < k; ++i) {       cin >> nk[i];       for (int j = 0; j < nk[i]; ++j) {         cin >> a[i][j];         mp[a[i][j]] = {i, j};         sum += a[i][j];         tol[i] += a[i][j];       }     }     if (sum % k) {       cout <<  No  << endl;     } else {       sum /= k;       for (int i = 0; i < k; ++i) {         for (int j = 0; j < nk[i]; ++j) {           if (_a[i][j]) continue;           int tmp = 0;           dfs(a[i][j], i, j, 0, tmp);         }       }       for (int i = 1; i < 1 << k; ++i) {         if (!_is[i]) {           for (int j = i; j; j = j - 1 & i) {             if (_is[j] && _is[i ^ j]) {               for (auto l : dp[j]) {                 dp[i].push_back(l);               }               for (auto l : dp[i ^ j]) {                 dp[i].push_back(l);               }               _is[i] = 1;               break;             }           }         }       }       if (_is[(1 << k) - 1]) {         cout <<  Yes  << endl;         for (auto i : dp[(1 << k) - 1]) {           for (auto j : i) {             ans[mp[j.first].first] = j;           }         }         for (int i = 0; i < k; ++i) {           cout << ans[i].first <<     << ans[i].second + 1 << endl;         }       } else {         cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l;     float p, q, t, res;     cin >> l >> p >> q;     t = l / (p + q);     res = p * t;     printf( %.4f , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 200005, M = 1000000007, K = 1000006;   int ast(int x, int n) {     int ans = 1;     while (n) {       if (n % 2 == 1) ans = (ans * 1LL * x) % M;       x = (x * 1LL * x) % M;       n /= 2;     }     return ans;   }   int u[K];   int f[K], rf[K], r[K];   void pre() {     for (int i = 2; i < K; ++i) {       if (u[i]) continue;       for (int j = i; j < K; j += i) {         if (!u[j]) u[j] = i;       }     }     f[0] = 1;     for (int i = 1; i < K; ++i) f[i] = (f[i - 1] * 1LL * i) % M;     rf[K - 1] = ast(f[K - 1], M - 2);     for (int i = K - 2; i >= 0; --i) rf[i] = (rf[i + 1] * 1LL * (i + 1)) % M;     for (int i = 1; i < K; ++i) r[i] = (rf[i] * 1LL * f[i - 1]) % M;   }   int n;   int a[N];   vector<pair<int, int> > v[N];   int t[N * 4];   void bil(int tl, int tr, int pos) {     if (tl == tr) {       t[pos] = a[tl];       return;     }     int m = (tl + tr) / 2;     bil(tl, m, pos * 2);     bil(m + 1, tr, pos * 2 + 1);     t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M;   }   void ubd(int tl, int tr, int x, int y, int pos) {     if (tl == tr) {       t[pos] = (t[pos] * 1LL * y) % M;       return;     }     int m = (tl + tr) / 2;     if (x <= m)       ubd(tl, m, x, y, pos * 2);     else       ubd(m + 1, tr, x, y, pos * 2 + 1);     t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M;   }   int qry(int tl, int tr, int l, int r, int pos) {     if (l > r) return 1;     if (tl == l && tr == r) return t[pos];     int m = (tl + tr) / 2;     return (qry(tl, m, l, min(m, r), pos * 2) * 1LL *             qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)) %            M;   }   int h[K];   int ans[N];   void solv() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     int qq;     scanf( %d , &qq);     for (int i = 0; i < qq; ++i) {       int l, r;       scanf( %d%d , &l, &r);       v[r].push_back(make_pair(l, i));     }     bil(1, n, 1);     for (int i = 1; i <= n; ++i) {       int x = a[i];       while (x > 1) {         if (h[u[x]]) ubd(1, n, h[u[x]], (u[x] * 1LL * r[u[x] - 1]) % M, 1);         h[u[x]] = i;         ubd(1, n, h[u[x]], (1 - r[u[x]] + M) % M, 1);         x /= u[x];       }       for (int j = 0; j < v[i].size(); ++j) {         ans[v[i][j].second] = qry(1, n, v[i][j].first, i, 1);       }     }     for (int i = 0; i < qq; ++i) printf( %d n , ans[i]);   }   int main() {     pre();     solv();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 505;   const int mod = 1e9 + 7;   long long int dp[1005][1005] = {0};   int main() {     long long int n, m, k;     cin >> n >> m >> k;     if (2 * k > n - 1 || 2 * k > m - 1)       cout << 0 << endl;     else {       dp[0][0] = 1;       for (int i = 1; i <= 1000; i++) {         dp[i][0] = 1;         dp[i][i] = 1;         for (int j = 1; j <= i; j++) {           dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;         }       }       cout << ((dp[n - 1][2 * k] % mod) * (dp[m - 1][2 * k] % mod)) % mod << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     int weight[n + 1];     int stacked[m + 1];     for (int i = 1; i <= n; i++) {       cin >> weight[i];     }     for (int i = 1; i <= m; i++) {       cin >> stacked[i];     }     bool vis[n + 1];     memset(vis, false, sizeof(vis));     int ans = 0;     for (int i = 2; i <= m; i++) {       memset(vis, false, sizeof(vis));       for (int j = i - 1; j >= 1; j--) {         if (stacked[j] == stacked[i]) break;         if (!vis[stacked[j]]) {           ans += weight[stacked[j]];           vis[stacked[j]] = true;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   inline long long sub(long long &a, long long b) {     a -= b;     if (a < 0) {       a += MOD;     }   }   inline long long mult(long long a, long long b) { return (a * 1ll * b) % MOD; }   inline long long b_pow(long long a, long long p) {     long long cur = a, ans = 1;     while (p > 0) {       if (p & 1) {         ans = mult(ans, cur);       }       p /= 2;       cur = mult(cur, cur);     }     return ans;   }   const long long lim = 1e6;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, p;       cin >> n >> p;       if (p == 1) {         for (long long i = 0; i < n; i++) {           long long x;           cin >> x;         }         cout << (n & 1) <<   n ;         continue;       }       map<long long, long long> cnt;       for (long long i = 0; i < n; i++) {         long long x;         cin >> x;         cnt[x]++;       }       auto it = --cnt.end();       long long ans = 0, need = 0;       for (;;) {         if (it->second >= need) {           it->second -= need;           need = 0;           ans = 0;         } else {           sub(ans, mult(it->second, b_pow(p, it->first)));           need -= it->second;           it->second = 0;         }         if (it->second & 1) {           need = 1;           ans = b_pow(p, it->first);         }         if (it == cnt.begin()) {           break;         } else {           long long was = it->first;           it--;           if (need > 0) {             while (need < 1e6 && was != it->first) {               need *= p;               was--;             }           }         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct superset {     multiset<int> m;     void insert(int x) { m.insert(x); }     void erase(int x) { m.erase(m.find(x)); }     int query() { return *m.begin(); }   };   int n, m;   int val[65536 * 4];   superset cl[65536 * 4];   vector<int> g[65536 * 4];   vector<int> lis[65536 * 4];   int dfn[65536 * 4];   int DFN;   int low[65536 * 4];   int st[65536 * 4], stsiz;   int tot;   vector<int> v[65536 * 4];   void addedge(int x, int y) {     v[x].push_back(y);     v[y].push_back(x);   }   void tarjan(int x, int p) {     st[++stsiz] = x;     dfn[x] = low[x] = ++DFN;     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i];       if (y == p) continue;       if (!dfn[y]) {         tarjan(y, x);         if (low[y] >= dfn[x]) {           ++tot;           while (st[stsiz] != y) lis[tot].push_back(st[stsiz--]);           stsiz--;           lis[tot].push_back(y);           lis[tot].push_back(x);           for (int j = 0; j < lis[tot].size(); j++) addedge(lis[tot][j], tot);         }         low[x] = min(low[x], low[y]);       } else         low[x] = min(low[x], dfn[y]);     }   }   struct segmenttree {     int tree[65536 * 4 * 2 + 10];     void up(int id) { tree[id] = min(tree[id << 1], tree[id << 1 | 1]); }     void update(int x, int y) {       x = x + 65536 * 4 - 1;       tree[x] = y;       x = x / 2;       while (x) up(x), x = x / 2;     }     int query(int a, int b, int l, int r, int id) {       if (l >= a and r <= b) return tree[id];       if (b <= (l + r) / 2)         return query(a, b, l, (l + r) / 2, id << 1);       else if (a > (l + r) / 2)         return query(a, b, (l + r) / 2 + 1, r, id << 1 | 1);       else         return min(query(a, b, l, (l + r) / 2, id << 1),                    query(a, b, (l + r) / 2 + 1, r, id << 1 | 1));     }     int query(int a, int b) { return query(a, b, 1, 65536 * 4, 1); }   } trcyx;   int pa[65536 * 4];   int son[65536 * 4];   int siz[65536 * 4];   int lead[65536 * 4];   int len[65536 * 4];   int dep[65536 * 4];   void dfs1(int x, int p) {     siz[x] = 1;     dep[x] = dep[p] + 1;     for (int i = 0; i < v[x].size(); i++) {       if (v[x][i] == p) continue;       dfs1(v[x][i], x);       siz[x] += siz[v[x][i]];       if (siz[v[x][i]] > siz[son[x]]) son[x] = v[x][i];     }   }   void dfs2(int x, int p, int leader) {     dfn[x] = ++DFN;     pa[x] = p;     if (!leader) leader = x;     lead[x] = leader, len[leader]++;     if (son[x]) dfs2(son[x], x, leader);     for (int i = 0; i < v[x].size(); i++)       if (v[x][i] != son[x] and v[x][i] != p) dfs2(v[x][i], x, 0);     if (lis[x].size()) {       for (int i = 0; i < lis[x].size(); i++)         if (lis[x][i] != pa[x]) cl[x].insert(val[lis[x][i]]);       val[x] = cl[x].query();     }     trcyx.update(dfn[x], val[x]);   }   void build() {     tot = n;     tarjan(1, 0);     dfs1(1, 0);     memset(dfn, 0, sizeof(dfn));     DFN = 0;     dfs2(1, 0, 0);   }   int solve(int x, int y) {     int ans = 1e9;     while (lead[x] != lead[y]) {       if (dep[lead[x]] < dep[lead[y]]) swap(x, y);       ans = min(ans, trcyx.query(dfn[lead[x]], dfn[x]));       x = pa[lead[x]];     }     if (dfn[x] > dfn[y]) swap(x, y);     ans = min(ans, trcyx.query(dfn[x], dfn[y]));     if (lis[x].size()) ans = min(ans, val[pa[x]]);     return ans;   }   void change(int x, int y) {     if (pa[x]) {       cl[pa[x]].erase(val[x]);       cl[pa[x]].insert(y);       val[pa[x]] = cl[pa[x]].query();       trcyx.update(dfn[pa[x]], val[pa[x]]);     }     val[x] = y;     trcyx.update(dfn[x], y);   }   int main() {     int T;     scanf( %d%d%d , &n, &m, &T);     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     build();     while (T--) {       char ctrl[10];       scanf( %s , ctrl);       int x, y;       scanf( %d%d , &x, &y);       if (ctrl[0] ==  A )         printf( %d n , solve(x, y));       else         change(x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n;     while (scanf( %d , &n) != EOF) {       if (n & 1)         printf( black n );       else         printf( white n1 2 n );     }     return 0;   }


#include <bits/stdc++.h>   const double Pi = acos(-1.0);   using namespace std;   const int maxN = 100005;   const long long mod = 1000000009;   int n, m;   int par[maxN];   int findpar(int x) {     if (par[x] != x) par[x] = findpar(par[x]);     return par[x];   }   int main(int argc, char** argv) {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) par[i] = i;     long long ans = 1;     int a, b;     while (m--) {       scanf( %d %d , &a, &b);       int pa = findpar(a), pb = findpar(b);       if (pa == pb)         ans = (ans * 2) % mod;       else         par[pb] = pa;       printf( %lld n , ans - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void BFS(vector<vector<long long> > &graph, long long n,            vector<long long> &order) {     vector<long long> vis(n + 1);     set<long long> PQ;     PQ.insert(1);     while (!PQ.empty()) {       long long x = *PQ.begin();       PQ.erase(PQ.begin());       order.push_back(x);       vis[x] = 1;       for (long long i = 0; i < graph[x].size(); i++) {         if (vis[graph[x][i]] == 0) PQ.insert(graph[x][i]);       }     }   }   int main() {     long long n, m, i, j, k, l, w, u, v, t_sum = 0;     cin >> n >> m;     vector<vector<long long> > graph(n + 1);     for (i = 1; i <= m; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     vector<long long> order;     BFS(graph, n, order);     for (i = 0; i < order.size(); i++) cout << order[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 10005;   int f[N][2005];   int main() {     int _;     scanf( %d , &_);     for (int j = 1; j <= 1000; j++) {       f[0][j] = INF;     }     while (_--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         for (int j = 0; j <= 2000; j++) {           f[i][j] = INF;         }         for (int j = 0; j <= 2000; j++) {           f[i][max(0, j - x)] = min(f[i][max(0, j - x)], f[i - 1][j] + x);           if (j + x <= 2000)             f[i][j + x] = min(f[i][j + x], max(0, f[i - 1][j] - x));         }       }       int ans = INF;       for (int j = 0; j <= 1000; j++) {         ans = min(ans, f[n][j] + j);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     int res = 0, fh = 1;     char ch = getchar();     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return fh * res;   }   string s;   int like[20];   int main() {     int F = getint(), I = getint(), T = getint();     for (int i = 1; i <= F; i++) {       getline(cin, s);       for (int j = 0; j < I; j++) like[j + 1] += (s[j] ==  Y );     }     int ans = 0;     for (int i = 1; i <= I; i++)       if (like[i] >= T) ans++;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 5e6 + 3;   long long dp[N];   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     string str;     unsigned long long temp = 1, p = 0, q = 0;     cin >> str;     long long ans = 0;     long long pppp = str.size();     for (int i = 0; i < str.size(); i++) {       p = (p * 131 + str[i]) % mod;       q = (temp * (str[i]) + q) % mod;       ;       temp *= 131;       temp %= mod;       if (p == q) {         if (i == 0)           dp[i]++, ans += dp[i];         else {           dp[i] = dp[(i - 1) / 2] + 1;           ans += dp[i];         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 100005, inf = 1000000005, MOD = 1000000007;   const long long INF = 1000000000000000005LL;   int t[100];   int suma(int i) {     int y = min(t[i], t[i + 2]), a = t[i + 1];     int res = (y + a) * (y + a) - a * a;     int d = max(t[i], t[i + 2]) - y;     res += (d * (a + y));     return res;   }   int main() {     for (int i = 1; i <= 6; ++i) scanf( %d , &t[i]);     int ans = suma(1) + suma(4);     printf( %d , ans);   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int   #define endl   n    void solve()   {       int n,start=0;       cin>>n;       int end=n;       int arr[n],pos[n+1];       for(int i=0 ; i<n;i++)       {       cin>>arr[i];       pos[arr[i]]=i;       }       for(int i=n;i>0;i--)       {           start = pos[i];           if(end>start)           {               for(int j=start ; j<end ; j++)               {                   cout<<arr[j]<<   ;               }           end = start;           }       }       cout<<endl;   }      int main()   {   int t;   cin>>t;   while(t--)   {   solve();   }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, ans(0);     read(n);     vector<long long> arr(n + 1, 0);     for (long long i = 1; i < n + 1; ++i) {       read(arr[i]);       arr[i] += arr[i - 1];     }     long long start(0), end(0);     set<long long> s = {0};     while (start < n) {       while (end < n && !s.count(arr[end + 1])) {         ++end;         s.insert(arr[end]);       }       ans += end - start;       s.erase(arr[start]);       ++start;     }     cout << ans <<   n ;     arr.clear();     s.clear();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6;   int n, m, p, a[mxN];   long long s1[1 << 21];   vector<long long> s2[1 << 21];   void bld(int i = 1, int l = 0, int r = n - 1) {     if (l == r) {       s1[i] = a[l];       s2[i] = {p - a[l], 1ll << 60};       return;     }     int m = (l + r) / 2;     bld(2 * i, l, m);     bld(2 * i + 1, m + 1, r);     s1[i] = s1[2 * i] + s1[2 * i + 1];     long long cs = s1[2 * i];     for (int i1 = 0, i2 = 0;          i1 < s2[2 * i].size() - 1 || i2 < s2[2 * i + 1].size() - 1;) {       if (s2[2 * i][i1] + cs < s2[2 * i + 1][i2]) {         if (s2[i].size() && s2[i].back() > s2[2 * i][i1] - p)           s2[i].push_back(s2[i].back() + p);         else           s2[i].push_back(s2[2 * i][i1]);         cs -= p;         ++i1;       } else         s2[i].push_back(s2[2 * i + 1][i2++] - cs);     }     s2[i].push_back(1ll << 60);   }   long long qry(int l1, int r1, long long x, int i = 1, int l2 = 0,                 int r2 = n - 1) {     if (l1 <= l2 && r2 <= r1)       return x + s1[i] -              (long long)(upper_bound(s2[i].begin(), s2[i].end(), x) -                          s2[i].begin()) *                  p;     int m2 = (l2 + r2) / 2;     if (r1 <= m2) return qry(l1, r1, x, 2 * i, l2, m2);     if (m2 < l1) return qry(l1, r1, x, 2 * i + 1, m2 + 1, r2);     return qry(l1, r1, qry(l1, r1, x, 2 * i, l2, m2), 2 * i + 1, m2 + 1, r2);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> p;     for (int i = 0; i < n; ++i) cin >> a[i];     bld();     for (int l, r; m--;) {       cin >> l >> r, --l, --r;       cout << qry(l, r, 0) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 405;   double f[maxn], g[maxn], ans;   int n, m, dis[maxn][maxn], q[maxn];   int main() {     scanf( %d%d , &n, &m);     memset(dis, 127 / 3, sizeof(dis));     for (int i = 1; i <= n; i++) {       dis[i][i] = 0;     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       dis[u][v] = dis[v][u] = 1;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);         }       }     }     for (int i = 1; i <= n; i++) {       double temp = 0;       for (int j = 0; j < n; j++) {         int u = 0;         memset(f, 0, sizeof(f));         for (int k = 1; k <= n; k++) {           if (dis[i][k] == j) {             u++;             int x = 0;             for (int kk = 1; kk <= n; kk++) {               if (dis[k][kk] == 1) {                 x++;               }             }             for (int kk = 1; kk <= n; kk++) {               if (dis[k][kk] == 1) {                 f[kk] += 1.0 / x;               }             }           }         }         int v = 0;         for (int k = 1; k <= n; k++) {           if (abs(dis[i][k] - j) <= 1) {             q[++v] = k;           }         }         double res = 0;         for (int k = 1; k <= n; k++) {           for (int kk = 1; kk <= v; kk++) {             if (f[q[kk]] > g[dis[k][q[kk]]]) {               g[dis[k][q[kk]]] = f[q[kk]];             }           }           double w = 0;           for (int kk = 1; kk <= v; kk++) {             w += g[dis[k][q[kk]]];             g[dis[k][q[kk]]] = 0;           }           res = max(res, w);         }         if (u) {           res = max(res, 1.0);         }         temp += res / n;       }       ans = max(ans, temp);     }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> g[(long long)3e5], a((long long)3e5);   long long i, n, x, y, r;   void b(long long p, long long q, long long m) {     a[p]++, r += m;     for (auto j : g[p])       if (j != q) b(j, p, m ^ 1), a[p] += a[j];   }   int main() {     for (cin >> n, i = 1; i < n; i++)       cin >> x >> y, g[x].push_back(y), g[y].push_back(x);     b(1, 0, 0), r *= (n - r);     for (i = 1; i <= n; i++) r += a[i] * (n - a[i]);     cout << r / 2;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x7fffffffffffffff;   const double eps = 1e-8;   unsigned int seed = 19260817;   const unsigned int _RAND_MAX_ = 4294967295u;   __inline__ __attribute__((always_inline)) unsigned int Rand() {     return seed = seed * 998244353u + 1000000007u;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a > 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) {     return a < b ? b : a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) {     return a < b ? a : b;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (a > b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a,                                                       const _Tp &b) {     return abs(a - b) <= eps;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     register char ch(getchar());     bool f(false);     while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (ch >= 48 && ch <= 57)       x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     register char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     register char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 1200005;   struct node {     bool l, r;     int ans;     __inline__ __attribute__((always_inline)) node operator+(         const node &o) const {       return (node){l, o.r, ans + o.ans - (r == o.l)};     }   };   int L[N], R[N];   int t[N];   int a[N];   struct seg_tr {     struct Node {       int ls, rs;       node val1, val2;       bool tag;     } f[N << 1];     int node_cnt;     __inline__ __attribute__((always_inline)) void PushUp(int x) {       f[x].val1 = f[f[x].ls].val1 + f[f[x].rs].val1;       f[x].val2 = f[f[x].ls].val2 + f[f[x].rs].val2;     }     int build(int l, int r) {       int cur = ++node_cnt;       f[cur].tag = 0;       if (l == r) {         f[cur].ls = f[cur].rs = 0;         f[cur].val1 = (node){a[l] == 0, a[l] == 0, 1};         f[cur].val2 = (node){a[l] == 1, a[l] == 1, 1};         return cur;       }       int mid = (l + r) >> 1;       f[cur].ls = build(l, mid);       f[cur].rs = build(mid + 1, r);       PushUp(cur);       return cur;     }     __inline__ __attribute__((always_inline)) void upd(int cur) {       f[cur].tag ^= 1;       std::swap(f[cur].val1, f[cur].val2);     }     __inline__ __attribute__((always_inline)) void PushDown(int cur) {       if (f[cur].tag) {         upd(f[cur].ls);         upd(f[cur].rs);         f[cur].tag = 0;       }     }     void Update(int L, int R, int l, int r, int cur) {       if (L <= l && r <= R) {         upd(cur);         return;       }       PushDown(cur);       int mid = (l + r) >> 1;       if (L <= mid) Update(L, R, l, mid, f[cur].ls);       if (R > mid) Update(L, R, mid + 1, r, f[cur].rs);       PushUp(cur);     }     __inline__ __attribute__((always_inline)) int Query() {       return f[1].val1.ans;     }   } tr;   void MAIN() {     tr.node_cnt = 0;     int n;     read(n);     int len = 0;     for (int i = 1; i <= n; ++i) {       read(L[i], R[i]);       t[++len] = L[i];       t[++len] = R[i];     }     std::sort(t + 1, t + len + 1);     len = std::unique(t + 1, t + len + 1) - t - 1;     memset(a, 0, 8 * (len + 2));     for (int i = 1; i <= n; ++i) {       L[i] = std::lower_bound(t + 1, t + len + 1, L[i]) - t;       R[i] = std::lower_bound(t + 1, t + len + 1, R[i]) - t;       L[i] <<= 1;       R[i] <<= 1;       ++a[L[i]];       --a[R[i] + 1];     }     len <<= 1;     for (int i = 1; i <= len; ++i) a[i] += a[i - 1];     int root = tr.build(1, len);     int ans = 0;     for (int i = 1; i <= n; ++i) {       tr.Update(L[i], R[i], 1, len, root);       chmax(ans, tr.Query() >> 1);       tr.Update(L[i], R[i], 1, len, root);     }     printf( %d n , ans);   }   int main() {     int _;     read(_);     while (_--) MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tests;     cin >> tests;     while (tests--) {       int n, s, t;       cin >> n >> s >> t;       cout << min(max(s, t) + 1 - (s + t - n), n + (n - s - t) + 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200010];   int n, m, head[200010], o = 0, x[2], id[200010], sz[200010], cnt = 0,                           tree[800010], tag[800010];   bool isnt_rt[200010];   vector<vector<int> > w;   struct edge {     int to, link;   } e[200010];   struct seg {     int x, l, r, id;     bool operator<(const seg &b) const { return x < b.x; }   } sg[200010];   void add_edge(int u, int v) {     e[++o].to = v, e[o].link = head[u], head[u] = o, isnt_rt[v] = true;   }   void dfs(int u, int k) {     id[u] = ++x[k], sz[u] = 1;     for (int i = head[u]; i; i = e[i].link) {       dfs(e[i].to, k);       sz[u] += sz[e[i].to];     }   }   void pushup(int l, int r, int t) {     if (tag[t] > 0) return tree[t] = (r - l + 1), void();     if (l == r) return tree[t] = 0, void();     tree[t] = tree[t << 1] + tree[t << 1 | 1];   }   void add(int ll, int rr, int l, int r, int t, int c) {     if (ll <= l && r <= rr) {       tag[t] += c;       pushup(l, r, t);       return;     }     int mid = (l + r) >> 1;     if (ll <= mid) add(ll, rr, l, mid, t << 1, c);     if (mid < rr) add(ll, rr, mid + 1, r, t << 1 | 1, c);     pushup(l, r, t);   }   int main() {     scanf( %d%d , &n, &m), w.resize(n + 1);     for (int i = 1; i <= n; i++) {       w[i].resize(m + 1);       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) {         if (s[j] ==  L ) w[i][j] = 1;         if (s[j] ==  U ) w[i][j] = 2;         if (s[j] ==  L  && j + 2 <= m)           add_edge(((i)-1) * m + (j + 2), ((i)-1) * m + (j));         if (s[j] ==  R  && j - 2 >= 1)           add_edge(((i)-1) * m + (j - 2), ((i)-1) * m + (j));         if (s[j] ==  U  && i + 2 <= n)           add_edge(((i + 2) - 1) * m + (j), ((i)-1) * m + (j));         if (s[j] ==  D  && i - 2 >= 1)           add_edge(((i - 2) - 1) * m + (j), ((i)-1) * m + (j));       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (isnt_rt[((i)-1) * m + (j)]) continue;         dfs(((i)-1) * m + (j), (i + j) & 1);       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int u, v;         if (w[i][j] == 1) {           u = ((i)-1) * m + (j), v = ((i)-1) * m + (j + 1);           if ((i + j) & 1) swap(u, v);         } else if (w[i][j] == 2) {           u = ((i)-1) * m + (j), v = ((i + 1) - 1) * m + (j);           if ((i + j) & 1) swap(u, v);         } else           continue;         sg[++cnt] = (seg){id[u], id[v], id[v] + sz[v] - 1, 1};         sg[++cnt] = (seg){id[u] + sz[u], id[v], id[v] + sz[v] - 1, -1};       }     sort(sg + 1, sg + cnt + 1);     long long ans = 0;     for (int i = 1, j = 1; i <= x[0]; i++) {       while (sg[j].x <= i && j <= cnt) {         add(sg[j].l, sg[j].r, 1, x[1], 1, sg[j].id);         j++;       }       ans += tree[1];     }     printf( %lld n , ans);   }


/*   ``````````````````$$$$$   `````````````$$$$$$´´´´$$$$$$   ``````````$$$´´´´´´´´´´´´´´´´$$$   ````````$`$$´´´´´´´´´´´´´´´´´´´´$$   ```````$´$$$´´´´´´´´´´´´´´´´´´´´´$$$$   `````$´´$$$$´´´´´´´´´´´´´´´´´´´´´´´´´´$   ````$´´$$$$$´´´´´´´´´´$$$$$$$´´´´´´´´´$$   ```$´´´$$$$$$$´´´$$$$$$$$$$$$$$$$$´´´´´$$   ``$´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´´´$$   `$´´´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´$   `$´´´´´´$$$$$$$$$$$´´´´$$$$$$$$$$$$$$$$$$$   $´´´´´´´´$$$$$$$$´´´´´´´´$$$$$$$´´´´´´´´$$   $´´´´´´´´´$$$$$$´´´´´´´´´´$$$$´´´´´´´´´´´$   `$´´´´´´´´´$$$$$´´´´´´´´´´$$$´´´´´´´´´´´$   `$´´´´´´´´´´$$$$$´´´´´´´´$$$$´´´´´´´´´´´$   `$´´´´´´´´´´´$$$$$$´´´´$$$$$´´´´´´´´´´´$$   ``$´´´´´´´´´´´$$$$$$$$$$$$$$´´´´´´´´´´´$   ``$$´´´´´´´´´´´´$$$$$$$$$$$$´´´´´´´´´´$$   ```$$´´´´´´´´´´´´$$$$$$$$$$´´´´´´´´´´$$   ````$´´´´´´´´´´´´$$$$$$$$$´´´´´´´´´´´$   `````$´´´´´´´´´´´$$$$$$$$´´´´´´´´´´´$   ``````$$´´´´´´´´´$$$$$$´´´´´´´´´´´$$   ````````$$´´´´´´$$$$$´´´´´´´´´´´$$   ``````````$$$´$$$$´´´´´´´´´´´$$$   `````````````$$$$$´´´´´´$$$$$   ``````````````````$$$$$$   */   #include  bits/stdc++.h        #define ll long long int   #define pb push_back   #define F first   #define S second   #define vi vector<ll>   #define vs vector<string>   #define input(v,n) for(ll VAL=0;VAL<n;VAL++){ll VALUE;cin>>VALUE;v.pb(VALUE);}   #define mi map<ll,ll>   #define FOR(i,a,b) for(ll i=a;i<b;i++)   #define mi map<ll,ll>   #define print(v) for(ll printing=0;printing<v.size();printing++){cout<<v[printing]<<   ;}   #define TestCase ll testcase;cin>>testcase;while(testcase--)   #define bin(n) bitset<32>(n).to_string();   #define maxv(v) *max_element(v.begin(),v.end())   #define minv(v) *min_element(v.begin(),v.end())   #define decimal(s) stoll(s,nullptr,2)   #define rmLead(str) str.erase(0, min(str.find_first_not_of( 0 ), str.size()-1));   using namespace std;      void solve(){       ll n,c;cin>>n>>c;       vi a(n),b(n-1);       for(auto &i:a)  cin>>i;       for(auto &i:b)  cin>>i;       b.pb(0);       ll prev_val = 0,prev_day=0;       ll ans = 1e18;       for(ll i=0;i<n;i++){           ll x = (c-prev_val+a[i]-1)/a[i];           ans = min(prev_day+max(x,(ll)0),ans);           x = max((ll)0,(b[i]-prev_val+a[i]-1)/a[i]);              prev_day+=x+1;           prev_val+=x*a[i]-b[i];         }       // ll x = (c-prev_val+a[n-1]-1)/a[n-1];       // ans = min(ans,prev_day+max(x,(ll)0));       //print(dp);       cout<<ans<<  n ;      }       int main(){   ios_base::sync_with_stdio(false);    cin.tie(NULL);   cout.tie(NULL);   TestCase   solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, f, h = 0, z = 0, x = 0;     char a[100];     cin >> t;     for (int i = 0; i < t; i++) {       cin >> a[i];     }     while (t > 0) {       z++;       t = t - z;     }     for (int y = 0; y < z; y++) {       h = h + y;       cout << a[h];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline bool isIntege(double num) { return (num == (int)num); }   inline bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) {     return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2);   }   inline double coDist(double x1, double y1, double x2, double y2) {     return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));   }   inline void normal(long long &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long modMul(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long modAdd(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long modSub(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   struct edge {     int u, v, w;   };   bool cmp(edge &a, edge &b) { return a.w < b.w; }   string to_s(int t) {     stringstream ss;     ss << t;     return ss.str();   }   bool seive[1010000];   vector<int> prime;   void seiveGen(int limit) {     limit += 100;     int sqrtn = sqrt(limit);     for (int i = 3; i <= sqrtn; i += 2) {       if (!seive[i >> 1]) {         for (int j = i * i; j < limit; j += i + i) {           seive[j >> 1] = 1;         }       }     }     prime.push_back(2);     for (int i = 3; i < limit; i += 2) {       if (!seive[i >> 1]) prime.push_back(i);     }   }   vector<int> PrimeF;   void primeFactorize(int n) {     for (int i = 0; prime[i] * prime[i] <= n; i++) {       if (n % prime[i] == 0) {         while (n % prime[i] == 0) {           n /= prime[i];           PrimeF.push_back(prime[i]);         }       }     }     if (n > 1) {       PrimeF.push_back(n);     }   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   clock_t tStart = clock();   void faltu() { cerr <<   n ; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long s1, s2, x = 0;     s1 = (n * (n + 1)) / 2;     seiveGen(sqrt(s1 + 10000));     primeFactorize(s1);     if (n <= 2) {       return cout <<  No  <<   n , 0;     } else {       sort(PrimeF.begin(), PrimeF.end());       for (int i = 0; i < PrimeF.size(); i++) {         if (PrimeF[i] != n) {           s2 = PrimeF[i];           x = 1;           break;         }       }       if (x == 0) return cout <<  No  <<   n , 0;       cout <<  Yes  <<   n ;       cout << 1 <<     << s2 <<   n ;       cout << n - 1 <<    ;       for (int i = 1; i <= n; i++) {         if (i != s2) cout << i <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxval = 2e6 + 6;   int b[maxval];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       b[a] = a;     }     for (int i = 0; i < maxval; i++)       if (!b[i]) b[i] = b[i - 1];     int ans = 0;     for (int i = 2; i < maxval / 2; i++) {       if (b[i] == i) {         for (int j = i - 1; j < maxval; j += i) {           if (j < maxval && i <= b[j] && ans < b[j] % i) ans = b[j] % i;         }       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i, m, j, x;     cin >> n >> m;     long long a[n][m], lowR[n][m], highR[n][m], lowC[n][m], highC[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cin >> a[i][j];     }     for (i = 0; i < n; i++) {       vector<long long> v, v1;       for (j = 0; j < m; j++) {         v.push_back(a[i][j]);       }       sort(v.begin(), v.end());       v1.push_back(v[0]);       for (j = 1; j < v.size(); j++) {         if (v[j] != v[j - 1]) v1.push_back(v[j]);       }       for (j = 0; j < m; j++) {         lowR[i][j] = lower_bound(v1.begin(), v1.end(), a[i][j]) - v1.begin();         highR[i][j] = v1.size() - lowR[i][j] - 1;       }     }     for (i = 0; i < m; i++) {       vector<long long> v, v1;       for (j = 0; j < n; j++) {         v.push_back(a[j][i]);       }       sort(v.begin(), v.end());       v1.push_back(v[0]);       for (j = 1; j < v.size(); j++) {         if (v[j] != v[j - 1]) v1.push_back(v[j]);       }       for (j = 0; j < n; j++) {         lowC[j][i] = lower_bound(v1.begin(), v1.end(), a[j][i]) - v1.begin();         highC[j][i] = v1.size() - lowC[j][i] - 1;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++)         cout << max(lowR[i][j], lowC[i][j]) + max(highR[i][j], highC[i][j]) + 1              <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 310;   int mod[3];   int n;   string s[maxn];   long long ha[maxn][3];   int prel[maxn];   int main() {     ios::sync_with_stdio(false);     mod[0] = 1e9 + 7;     mod[1] = 1e9 + 9;     mod[2] = 19260817;     cin >> n;     int ans = 0;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int l = s[i].size();       for (int j = l - 1; j >= 0; j--) {         for (int k = 0; k < 3; k++) {           ha[i][k] = (ha[i][k] * 131 + s[i][j]) % mod[k];         }       }       prel[i] = prel[i - 1] + l;     }     ans = prel[n] + n - 1;     int res = 0;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         int len = j - i + 1, cnt = 0;         for (int k = j + 1; k + len - 1 <= n; k++) {           bool f = 1;           for (int l = 0; l < len; l++) {             if (ha[i + l][0] != ha[k + l][0] || ha[i + l][1] != ha[k + l][1] ||                 ha[i + l][2] != ha[k + l][2]) {               f = 0;               break;             }           }           if (f) cnt++, k += len - 1;         }         if (cnt == 0) continue;         res = max(res, (cnt + 1) * (prel[j] - prel[i - 1] - 1));       }     }     cout << ans - res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, v, x;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> v;     if ((((n - 1) * (n - 2) / 2) + 1 < m) || (m < (n - 1)))       return cout << -1 <<   n , 0;     for (int i = 1; i <= n; i++)       if (i != v) cout << v <<     << i <<   n , x = i;     m -= (n - 1);     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (!m) return 0;         if (i != x && j != x && i != v && j != v)           cout << i <<     << j <<   n , m--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 6;   struct Edge {     int next, en;   } edge[maxn];   int head[maxn], cnt;   void init() {     memset(head, -1, sizeof(head));     cnt = 0;   }   void add(int x, int y) {     edge[cnt].en = y;     edge[cnt].next = head[x];     head[x] = cnt++;   }   int ans[maxn], siz[maxn], fa[maxn], maxsiz[maxn];   void dfs(int x) {     siz[x] = maxsiz[x] = 1;     ans[x] = x;     for (int i = head[x]; i + 1; i = edge[i].next) {       int v = edge[i].en;       fa[v] = x;       dfs(v);       siz[x] += siz[v];       maxsiz[x] = max(maxsiz[x], siz[v]);     }     for (int i = head[x]; i + 1; i = edge[i].next) {       int v = edge[i].en;       int p = ans[v];       while (p != x) {         if (maxsiz[p] * 2 <= siz[x] && (siz[x] - siz[p]) * 2 <= siz[x]) {           ans[x] = p;           break;         }         p = fa[p];       }     }   }   int main() {     int n, q, d;     scanf( %d%d , &n, &q);     init();     for (int i = 2; i <= n; i++) {       scanf( %d , &d);       add(d, i);     }     dfs(1);     while (q--) {       scanf( %d , &d);       printf( %d n , ans[d]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 152;   const int MAX2 = 11300;   const int INF = 1e9 + 10;   int a[MAX];   int r[MAX][MAX2];   int t[MAX][MAX2];   int main() {     int n, k, s;     cin >> n >> k >> s;     s = min(s, MAX2 - 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++) {       for (int p = 1; p <= s; p++) {         r[i][p] = INF;       }     }     for (int q = 1; q <= k; q++) {       for (int i = 0; i <= n; i++) {         for (int p = 0; p <= s; p++) {           t[i][p] = INF;         }       }       for (int i = q; i <= n; i++) {         for (int p = 0; p <= s; p++) {           if (p >= i - q)             t[i][p] = min(r[i - 1][p - (i - q)] + a[i], t[i - 1][p]);           else             t[i][p] = t[i - 1][p];         }       }       for (int i = 0; i <= n; i++) {         for (int p = 0; p <= s; p++) {           r[i][p] = t[i][p];         }       }     }     int res = INF;     for (int p = 0; p <= s; p++) {       res = min(res, r[n][p]);     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010];   bool f[1000010];   int main() {     int i, l, ans = 0, ans2 = 0, j, sta;     scanf( %s , &s);     l = strlen(s);     sta = 0;     while (s[sta] == s[(sta + 1) % l]) {       sta = (sta + 1) % l;     }     ++sta;     memset(f, false, sizeof(bool) * l);     i = sta;     while (!f[i]) {       f[i] = true;       i = (i + l - 1) % l;       while (s[(i + l - 1) % l] == s[i]) {         f[i] = true;         i = (i + l - 1) % l;       }       f[i] = true;       i = (i + l - 1) % l;       ++ans;     }     memset(f, false, sizeof(bool) * l);     i = sta;     while (!f[i]) {       f[i] = true;       while (s[(i + 1) % l] == s[i]) {         i = (i + 1) % l;         f[i] = true;       }       f[(i + 1) % l] = true;       i = (i + 2) % l;       ++ans2;     }     printf( %d n , ans < ans2 ? ans : ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vll = vector<ll>;   using ull = unsigned long long;   using int2 = pair<ll, ll>;   using int3 = tuple<ll, ll, ll>;   template <typename A>   string to_string(const A& v);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(const pair<A, B>& p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(const tuple<A, B, C>& p) {     return  (  + to_string(std::get<0>(p)) +  ,   + to_string(std::get<1>(p)) +             ,   + to_string(std::get<2>(p)) +  ) ;   }   template <typename A>   string to_string(const A& v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename T>   void sort(vector<T>& val) {     sort(val.begin(), val.end());   }   template <typename T>   void reverse(vector<T>& val) {     reverse(val.begin(), val.end());   }   template <typename T>   void sort_b(vector<T>& val) {     sort(val.begin(), val.end(), greater<T>());   }   template <typename T>   T pair_sum(pair<T, T>& val) {     return val.first + val.second;   }   template <typename T>   T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <typename T>   T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <typename T>   T mul_mod(T a, T b, T mod) {     T res = 0;     a %= mod;     while (b) {       if (b & 1) {         res = (res + a) % mod;       }       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   class mytask {    public:     mytask() {}     int solve() {       ll t;       cin >> t;       for (ll i_t = 0; i_t < t; i_t++) {         ll n;         cin >> n;         vll a(n);         ll last_val = -2;         vll neighbors;         ll max_diff = 0;         for (ll i = 0; i < n; i++) {           ll val;           cin >> val;           if (val == -1) {             if (last_val >= 0) {               neighbors.push_back(last_val);             }           } else {             if (last_val == -1) {               neighbors.push_back(val);             }             if (last_val >= 0) {               max_diff = max(max_diff, abs(last_val - val));             }           }           last_val = val;         };         ;         if (neighbors.size() == 0) {           cout << max_diff <<     << 0 << endl;           continue;         }         ll min_n = *min_element(neighbors.begin(), neighbors.end());         ll max_n = *max_element(neighbors.begin(), neighbors.end());         if (min_n == 0 && max_n == 0) {           cout << max_diff <<     << 0 << endl;           continue;         }         ll res = (min_n + max_n) / 2;         ll res_max = max(res - min_n, max_n - res);         ;         ;         res_max = max(res_max, max_diff);         cout << res_max <<     << res << endl;       }       return 0;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     auto task = mytask();     task.solve();     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   const int N_ = (int)2e6 + 2;   long long n;   char a[N_], b[N_];   double res;   long long T;   int main() {     scanf( %lld , &n);     scanf( %s , a + 1);     scanf( %s , b + 1);     for (char cur =  A ; cur <=  Z ; cur++) {       long long S = 0;       for (int i = 1; i <= n; i++) {         if (a[i] == cur) S += i;         if (b[i] == cur) res += S * (n - i + 1);       }       S = 0;       for (int i = 0; i <= n; i++) {         if (a[i] == cur) res += S * (n - i + 1);         if (b[i] == cur) S += i;       }     }     for (int i = 1; i <= n; i++) T += (n - i + 1) * (n - i + 1);     printf( %.9lf , res / T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pnt {     int x, y;   };   struct pr {     int d, q;     pr() {}     pr(int d, int q) : d(d), q(q) {}     friend bool operator<(pr a, pr b) {       if (a.d != b.d) return a.d < b.d;       return a.q < b.q;     }   };   const int N = 200000 + 20;   bool ok[N];   int t[4 * N];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = -1;       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     t[v] = -1;   }   void upd(int v, int tl, int tr, int wh, int vl) {     while (tl < tr) {       int tm = (tl + tr) / 2;       if (wh <= tm) {         tr = tm;         v = 2 * v;       } else {         tl = tm + 1;         v = 2 * v + 1;       }     }     t[v] = vl;     v /= 2;     while (v >= 1) {       t[v] = min(t[2 * v], t[2 * v + 1]);       v >>= 1;     }   }   const int INF = 1e9 + 7;   int mn(int v, int tl, int tr, int l, int r) {     if (l > r) return INF;     if (tl == l && r == tr) return t[v];     int tm = (tl + tr) / 2;     return min(mn(2 * v, tl, tm, l, min(tm, r)),                mn(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));   }   int main() {     int n, m, k, q;     scanf( %d %d %d %d , &n, &m, &k, &q);     swap(n, m);     vector<pnt> lad(k);     for (int i = 0; i < k; ++i) {       scanf( %d %d , &lad[i].x, &lad[i].y);       --lad[i].x;       --lad[i].y;     }     vector<pr> r(q), d(q);     vector<int> x1(q), x2(q), y1(q), y2(q);     for (int i = 0; i < q; ++i) {       scanf( %d %d %d %d , &x1[i], &y1[i], &x2[i], &y2[i]);       --y1[i];       --y2[i];       --x1[i];       --x2[i];       r[i].d = x2[i];       r[i].q = i;       d[i].d = y2[i];       d[i].q = i;     }     for (int i = 0; i < k; ++i) {       r.push_back(pr(lad[i].x, -i - 1));       d.push_back(pr(lad[i].y, -i - 1));     }     sort(r.begin(), r.end());     sort(d.begin(), d.end());     build(1, 0, n - 1);     for (int i = 0; i < r.size(); ++i) {       if (r[i].q < 0)         upd(1, 0, n - 1, lad[-r[i].q - 1].y, r[i].d);       else {         int t = mn(1, 0, n - 1, y1[r[i].q], y2[r[i].q]);         if (t >= x1[r[i].q]) ok[r[i].q] = true;       }     }     build(1, 0, m - 1);     for (int i = 0; i < d.size(); ++i) {       if (d[i].q < 0)         upd(1, 0, m - 1, lad[-d[i].q - 1].x, d[i].d);       else {         int t = mn(1, 0, m - 1, x1[d[i].q], x2[d[i].q]);         if (t >= y1[d[i].q]) ok[d[i].q] = true;       }     }     for (int i = 0; i < q; ++i) printf((ok[i] ?  YES n  :  NO n ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s[1001], d[1001], i, a, S;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s[i] >> d[i];     }     S = s[1];     for (i = 2; i <= n; i++) {       if (s[i] <= S) {         int x = ((S - s[i]) / d[i]) + 1;         S = s[i] + d[i] * x;       } else         S = s[i];     }     cout << S;   }


#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int N = 1e6;   const long long inf = 1e9;   int n;   vector<string> s;   string ans, cur;   vector<int> g[200];   bool was[N];   map<string, bool> wass;   void dfs(int v) {     was[v] = 1;     bool flag = 0;     bool flag2 = ((int)cur.find(s[v]) > -1);     if (!flag2) {       for (int i = s[v].size(); i > 0; i--) {         string t1 = s[v].substr(0, i);         string t2 = s[v].substr(i, s[v].size() - i);         if ((int)cur.find(t1) > -1) {           cur += t2;           flag = 1;           break;         }       }     }     if (!flag && !flag2) {       for (int i = 1; i <= s[v].size(); i++) {         string t1 = s[v].substr(0, i);         string t2 = s[v].substr(i, s[v].size() - i);         if ((int)cur.find(t2) > -1) {           cur = t1 + cur;           break;         }       }     }     for (int i = 0; i < g[v].size(); i++) {       if (!was[g[v][i]]) {         dfs(g[v][i]);       }     }   }   bool cmp(string a, string b) { return a.size() > b.size(); }   int main() {     boost();     cin >> n;     s.push_back( 0 );     for (int i = 1; i <= n; i++) {       string x;       cin >> x;       if (!wass.count(x)) {         s.push_back(x);       }       wass[x] = 1;     }     n = s.size() - 1;     sort(s.begin() + 1, s.end(), cmp);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) {           for (int k = 0; k < s[j].size(); k++) {             if ((int)s[i].find(s[j][k]) > -1) {               g[i].push_back(j);               g[j].push_back(i);               break;             }           }         }       }     }     for (int i = 1; i <= n; i++) {       if (!was[i]) {         cur =   ;         dfs(i);         ans += cur;       }     }     for (int i = 0; i < ans.size(); i++) {       for (int j = 0; j < ans.size(); j++) {         if (ans[i] == ans[j] && i != j) {           cout << i <<     << j << endl;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 1e9 + 7;   long long n, m, k, w;   long long dp1[maxn];   long long dp2[maxn];   int d1[maxn];   int d2[maxn];   long long a, b;   inline int low_bit(int x) { return x & (-x); }   inline void upd1(int p, int x) {     while (p <= n) {       dp1[p] += x;       p += low_bit(p);     }     return;   }   inline void upd2(int p, int x) {     while (p <= n) {       dp2[p] += x;       p += low_bit(p);     }     return;   }   inline int query1(int p) {     int sum = 0;     while (p > 0) {       sum += dp1[p];       p -= low_bit(p);     }     return sum;   }   inline int query2(int p) {     int sum = 0;     while (p > 0) {       sum += dp2[p];       p -= low_bit(p);     }     return sum;   }   inline int query(int p) {     return query1(p - 1) + query2(n) - query2(p + k - 1);   }   int main() {     long long ans = 0;     cin >> n >> k >> a >> b >> m;     for (int i = 1; i <= m; i++) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, y;         scanf( %d%d , &x, &y);         int p1 = d1[x];         int p2 = d2[x];         int to1 = 0, to2 = 0;         to1 = b - p1;         to2 = a - p2;         upd1(x, y > to1 ? to1 : y);         upd2(x, y > to2 ? to2 : y);         d1[x] += y > to1 ? to1 : y;         d2[x] += y > to2 ? to2 : y;       } else {         int x;         scanf( %d , &x);         cout << query(x) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 305;   int a[maxn][maxn], b[maxn][maxn];   int main(int argc, char const *argv[]) {     int t;     scanf( %d , &t);     while (t--) {       int n, m;       scanf( %d %d , &n, &m);       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           scanf( %d , &a[i][j]);         }       }       bool good = 1;       b[1][1] = b[1][m] = b[n][1] = b[n][m] = 2;       if (a[1][1] > 2 or a[1][m] > 2 or a[n][1] > 2 or a[n][m] > 2) {         printf( NO n );         continue;       }       for (int i = 2; i < m; ++i) {         if (a[1][i] > 3 or a[n][i] > 3) {           good = 0;         }         b[1][i] = b[n][i] = 3;       }       for (int i = 2; i < n; ++i) {         if (a[i][1] > 3 or a[i][m] > 3) {           good = 0;         }         b[i][1] = b[i][m] = 3;       }       if (!good) {         printf( NO n );         continue;       }       for (int i = 2; i < n; ++i) {         for (int j = 2; j < m; ++j) {           if (a[i][j] > 4) {             good = 0;           }           b[i][j] = 4;         }       }       if (!good) {         printf( NO n );       } else {         printf( YES n );         for (int i = 1; i <= n; ++i) {           for (int j = 1; j <= m; ++j) {             printf( %d  , b[i][j]);           }           printf(  n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void JIZZ(string output =   ) {     cout << output;     exit(0);   }   const long double PI = 3.14159265358979323846264338327950288;   const long double eps = 1e-10;   const long long mod = 1e9 + 7;   void solve() {     string s, t;     cin >> s >> t;     for (int st = 0; st < (int)s.size(); ++st) {       string cur;       for (int ri = st; ri < (int)s.size(); ++ri) {         cur += s[ri];         if (cur == t) {           cout <<  YES  << endl;           return;         }         string cc = cur;         for (int i = ri - 1; i >= 0 && cur.size() < t.size(); --i) {           cc += s[i];           if (cc.size() == t.size()) {             if (cc == t) {               cout <<  YES  << endl;               return;             }             break;           }         }       }     }     cout <<  NO  <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   const long double EPS = 1e-12;   struct Point {     long double x, y;     Point() {}     Point(long double x, long double y) : x(x), y(y) {}     Point(const Point &p) : x(p.x), y(p.y) {}     Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }     Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }     Point operator*(long double c) const { return Point(x * c, y * c); }     Point operator/(long double c) const { return Point(x / c, y / c); }   };   long double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; }   long double dist2(Point p, Point q) { return dot(p - q, p - q); }   long double cross(Point p, Point q) { return p.x * q.y - p.y * q.x; }   ostream &operator<<(ostream &os, const Point &p) {     os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   bool operator<(const Point &a, const Point &b) {     return make_pair(a.x, a.y) < make_pair(b.x, b.y);   }   bool operator==(const Point &a, const Point &b) {     return abs(a.x - b.x) < EPS && abs(a.y - b.y) < EPS;   }   Point RotateCCW90(Point p) { return Point(-p.y, p.x); }   Point RotateCW90(Point p) { return Point(p.y, -p.x); }   Point RotateCCW(Point p, long double t) {     return Point(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t));   }   Point ProjectPointLine(Point a, Point b, Point c) {     return a + (b - a) * dot(c - a, b - a) / dot(b - a, b - a);   }   Point ProjectPointSegment(Point a, Point b, Point c) {     long double r = dot(b - a, b - a);     if (fabs(r) < EPS) return a;     r = dot(c - a, b - a) / r;     if (r < 0) return a;     if (r > 1) return b;     return a + (b - a) * r;   }   pair<Point, Point> Perpendicularline(Point a, Point b, Point c) {     c = ProjectPointLine(a, b, c);     if (a == c) a = b;     return make_pair(c, c + RotateCW90(a - c));   }   long double DistancePointSegment(Point a, Point b, Point c) {     return sqrt(dist2(c, ProjectPointSegment(a, b, c)));   }   long double DistancePointPlane(long double x, long double y, long double z,                                  long double a, long double b, long double c,                                  long double d) {     return fabs(a * x + b * y + c * z - d) / sqrt(a * a + b * b + c * c);   }   bool LinesParallel(Point a, Point b, Point c, Point d) {     return fabs(cross(b - a, c - d)) < EPS;   }   bool LinesCollinear(Point a, Point b, Point c, Point d) {     return LinesParallel(a, b, c, d) && fabs(cross(a - b, a - c)) < EPS &&            fabs(cross(c - d, c - a)) < EPS;   }   bool SegmentsIntersect(Point a, Point b, Point c, Point d) {     if (LinesCollinear(a, b, c, d)) {       if (dist2(a, c) < EPS || dist2(a, d) < EPS || dist2(b, c) < EPS ||           dist2(b, d) < EPS)         return true;       if (dot(c - a, c - b) > 0 && dot(d - a, d - b) > 0 && dot(c - b, d - b) > 0)         return false;       return true;     }     if (cross(d - a, b - a) * cross(c - a, b - a) > 0) return false;     if (cross(a - c, d - c) * cross(b - c, d - c) > 0) return false;     return true;   }   Point ComputeLineIntersection(Point a, Point b, Point c, Point d) {     b = b - a;     d = c - d;     c = c - a;     assert(dot(b, b) > EPS && dot(d, d) > EPS);     return a + b * cross(c, d) / cross(b, d);   }   Point ComputeCircleCenter(Point a, Point b, Point c) {     b = (a + b) / 2;     c = (a + c) / 2;     return ComputeLineIntersection(b, b + RotateCW90(a - b), c,                                    c + RotateCW90(a - c));   }   bool PointInPolygon(const vector<Point> &p, Point q) {     bool c = 0;     for (int i = 0; i < p.size(); i++) {       int j = (i + 1) % p.size();       if ((p[i].y <= q.y && q.y < p[j].y || p[j].y <= q.y && q.y < p[i].y) &&           q.x < p[i].x + (p[j].x - p[i].x) * (q.y - p[i].y) / (p[j].y - p[i].y))         c = !c;     }     return c;   }   bool PointOnPolygon(const vector<Point> &p, Point q) {     for (int i = 0; i < p.size(); i++)       if (dist2(ProjectPointSegment(p[i], p[(i + 1) % p.size()], q), q) < EPS)         return true;     return false;   }   vector<Point> CircleLineIntersection(Point a, Point b, Point c, long double r) {     vector<Point> ret;     b = b - a;     a = a - c;     long double A = dot(b, b);     long double B = dot(a, b);     long double C = dot(a, a) - r * r;     long double D = B * B - A * C;     if (D < -EPS) return ret;     ret.push_back(c + a + b * (-B + sqrt(D + EPS)) / A);     if (D > EPS) ret.push_back(c + a + b * (-B - sqrt(D)) / A);     return ret;   }   vector<Point> CircleCircleIntersection(Point a, Point b, long double r,                                          long double R) {     vector<Point> ret;     long double d = sqrt(dist2(a, b));     if (d > r + R || d + min(r, R) < max(r, R)) return ret;     long double x = (d * d - R * R + r * r) / (2 * d);     long double y = sqrt(r * r - x * x);     Point v = (b - a) / d;     ret.push_back(a + v * x + RotateCCW90(v) * y);     if (y > 0) ret.push_back(a + v * x - RotateCCW90(v) * y);     return ret;   }   long double ComputeSignedArea(const vector<Point> &p) {     long double area = 0;     for (int i = 0; i < p.size(); i++) {       int j = (i + 1) % p.size();       area += p[i].x * p[j].y - p[j].x * p[i].y;     }     return area / 2.0;   }   long double ComputeArea(const vector<Point> &p) {     return fabs(ComputeSignedArea(p));   }   Point ComputeCentroid(const vector<Point> &p) {     Point c(0, 0);     long double scale = 6.0 * ComputeSignedArea(p);     for (int i = 0; i < p.size(); i++) {       int j = (i + 1) % p.size();       c = c + (p[i] + p[j]) * (p[i].x * p[j].y - p[j].x * p[i].y);     }     return c / scale;   }   bool IsSimple(const vector<Point> &p) {     for (int i = 0; i < p.size(); i++) {       for (int k = i + 1; k < p.size(); k++) {         int j = (i + 1) % p.size();         int l = (k + 1) % p.size();         if (i == l || j == k) continue;         if (SegmentsIntersect(p[i], p[j], p[k], p[l])) return false;       }     }     return true;   }   long double area2(Point a, Point b, Point c) { return cross(b - a, c - a); }   void ConvexHull(vector<Point> &pts) {     sort(pts.begin(), pts.end());     pts.erase(unique(pts.begin(), pts.end()), pts.end());     vector<Point> up, dn;     for (int i = 0; i < pts.size(); i++) {       while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) >= 0)         up.pop_back();       while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) <= 0)         dn.pop_back();       up.push_back(pts[i]);       dn.push_back(pts[i]);     }     pts = dn;     for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]);   }   bool in_convex(vector<Point> &l, Point p) {     int a = 1, b = l.size() - 1, c;     if (((l[a].x - l[0].x) * (l[b].y - l[0].y) -          (l[a].y - l[0].y) * (l[b].x - l[0].x)) > 0)       swap(a, b);     if (((l[a].x - l[0].x) * (p.y - l[0].y) -          (l[a].y - l[0].y) * (p.x - l[0].x)) >= 0 ||         ((l[b].x - l[0].x) * (p.y - l[0].y) -          (l[b].y - l[0].y) * (p.x - l[0].x)) <= 0)       return false;     while (abs(a - b) > 1) {       c = (a + b) / 2;       if (((l[c].x - l[0].x) * (p.y - l[0].y) -            (l[c].y - l[0].y) * (p.x - l[0].x)) > 0)         b = c;       else         a = c;     }     return ((l[b].x - l[a].x) * (p.y - l[a].y) -             (l[b].y - l[a].y) * (p.x - l[a].x)) <= 0;   }   vector<pair<Point, Point> > find_tangent(Point a, Point b, long double r1,                                            long double r2) {     vector<pair<Point, Point> > Q;     if (dist2(a, b) <= (r1 - r2) * (r1 - r2)) return Q;     int f = 0;     if (r2 > r1) swap(a, b), swap(r1, r2), f = 1;     if (abs(r2 - r1) <= EPS) {       pair<Point, Point> m = Perpendicularline(a, b, a),                          n = Perpendicularline(a, b, b);       vector<Point> l1 = CircleLineIntersection(m.first, m.second, a, r1),                     l2 = CircleLineIntersection(n.first, n.second, b, r2);       assert(l1.size() == 2 && l2.size() == 2);       if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) < 0)         swap(l2[0], l2[1]);       Q.push_back(make_pair(l1[0], l2[0]));       Q.push_back(make_pair(l1[1], l2[1]));     } else {       Point out = (b * r1 - a * r2) / (r1 - r2);       assert(dist2(out, a) >= r1 && dist2(out, b) >= r2);       vector<Point> l1 = CircleCircleIntersection(                         a, out, r1, sqrt(dist2(out, a) - (r1) * (r1))),                     l2 = CircleCircleIntersection(                         b, out, r2, sqrt(dist2(out, b) - (r2) * (r2)));       assert(l1.size() == 2 && l2.size() == 2);       if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) < 0)         swap(l2[0], l2[1]);       Q.push_back(make_pair(l1[0], l2[0]));       Q.push_back(make_pair(l1[1], l2[1]));     }     if (dist2(a, b) > (r1 + r2) * (r1 + r2) + EPS) {       Point out = (b * r1 + a * r2) / (r1 + r2);       assert(dist2(out, a) >= r1 && dist2(out, b) >= r2);       vector<Point> l1 = CircleCircleIntersection(                         a, out, r1, sqrt(dist2(out, a) - (r1) * (r1))),                     l2 = CircleCircleIntersection(                         b, out, r2, sqrt(dist2(out, b) - (r2) * (r2)));       assert(l1.size() == 2 && l2.size() == 2);       if (cross(b - a, l1[0] - b) * cross(b - a, l2[0] - b) > 0)         swap(l2[0], l2[1]);       Q.push_back(make_pair(l1[0], l2[0]));       Q.push_back(make_pair(l1[1], l2[1]));     } else if (abs((r1 + r2) * (r1 + r2) - dist2(a, b)) < EPS) {       Point out = (b * r1 + a * r2) / (r1 + r2);       Q.push_back(Perpendicularline(a, b, out));     }     if (f == 1) {       for (int i = 0; i < Q.size(); ++i) swap(Q[i].first, Q[i].second);     }     return Q;   }   long double error = 1e-8;   Point rect;   vector<pair<Point, long double> > circ;   bool inpoly(vector<Point> &a, Point b) {     int n = a.size();     for (int i = 0; i < a.size(); ++i) {       if (DistancePointSegment(a[i], a[(i + 1) % n], b) < error) return 1;     }     return in_convex(a, b);   }   bool outcircle(Point cen, long double rad, Point a) {     if (dist2(cen, a) > rad * rad - error) return 1;     return 0;   }   Point bottom;   bool cmp(Point a, Point b) {     long double val = cross(a - bottom, b - a);     if (fabs(val) < EPS) {       return dist2(bottom, b) > dist2(bottom, a);     }     return val > EPS;   }   int myconvexhull(vector<Point> &pts) {     sort(pts.begin(), pts.end());     pts.resize(unique(pts.begin(), pts.end()) - pts.begin());     bottom = pts[0];     sort(pts.begin() + 1, pts.end(), cmp);     vector<Point> hull;     hull.clear();     for (int i = 0; i < pts.size(); ++i) {       while (hull.size() >= 2 &&              cross(hull[hull.size() - 2] - hull[hull.size() - 1],                    pts[i] - hull[hull.size() - 1]) >= -1 * EPS) {         hull.pop_back();       }       hull.push_back(pts[i]);     }     pts.clear();     for (int i = 0; i < hull.size(); ++i) {       pts.push_back(hull[i]);     }     return 0;   }   vector<Point> vec;   long double getslope(int a, int b) {     if (abs(vec[a].x - vec[b].x) < EPS) {       return INF;     }     long double val = vec[a].y - vec[b].y;     val /= vec[a].x - vec[b].x;     return val;   }   Point get(long double sl, int a, int b, int c) {     if (abs(sl - INF) < EPS) {       if (vec[b].y != vec[a].y) {         return Point(vec[a].x, vec[b].y);       } else {         return Point(vec[a].x, vec[c].y);       }     }     if (vec[b].x == vec[a].x) {       b = c;     }     long double y2 = vec[a].y + sl * (vec[b].x - vec[a].x);     return Point(vec[b].x, y2);   }   int main() {     std::ios::sync_with_stdio(false);     int n, i, j, k, a, b, c;     long long iinf = INF;     iinf *= INF;     long double x, y, area = iinf;     long long s;     cin >> n >> s;     for (int i = 0; i < n; ++i) {       cin >> x >> y;       vec.push_back(Point(x, y));     }     myconvexhull(vec);     n = vec.size();     for (int i = 0; i < n; ++i) {       k = (i + 2) % n;       for (j = (i + 1) % n; j != i; j = (j + 1) % n) {         while (-1.0 * area2(vec[i], vec[j], vec[k]) +                    area2(vec[i], vec[j], vec[(k + 1) % n]) >                EPS) {           k = (k + 1) % n;         }         if (area2(vec[i], vec[j], vec[k]) - area > EPS) {           area = area2(vec[i], vec[j], vec[k]);           a = i;           b = j;           c = k;         }       }     }     long double slopeab, slopebc, slopeac;     Point p1, p2, p3, ans1, ans2, ans3;     slopeab = getslope(a, b);     slopebc = getslope(b, c);     slopeac = getslope(a, c);     p1 = get(slopeab, c, a, b);     p2 = get(slopebc, a, b, c);     p3 = get(slopeac, b, a, c);     ans1 = ComputeLineIntersection(p1, vec[c], p2, vec[a]);     ans2 = ComputeLineIntersection(p1, vec[c], p3, vec[b]);     ans3 = ComputeLineIntersection(p2, vec[a], p3, vec[b]);     cout << setprecision(30) << round(ans1.x) <<     << round(ans1.y) << endl;     cout << setprecision(30) << round(ans2.x) <<     << round(ans2.y) << endl;     cout << setprecision(30) << round(ans3.x) <<     << round(ans3.y) << endl;   }


#include <bits/stdc++.h>   char map[55][55];   int cov[55][55];   int fx[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};   int ok, sx, sy;   int steps[55][55];   int n, m;   int in(int x, int y) {     if (x >= 1 && x <= n && y >= 1 && y <= m) return 1;     return 0;   }   void dfs(int x, int y, int step) {     steps[x][y] = step;     if (ok) return;     for (int i = 0; i < 4; i++) {       int xx = x + fx[i][0];       int yy = y + fx[i][1];       if (in(xx, yy) && map[xx][yy] == map[sx][sy]) {         if (cov[xx][yy]) {           if (step - steps[xx][yy] >= 3) {             ok = 1;             return;           }           continue;         }         cov[xx][yy] = 1;         dfs(xx, yy, step + 1);       }     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; i++) {         scanf( %s , map[i] + 1);       }       ok = 0;       memset(cov, 0, sizeof(cov));       memset(steps, 0, sizeof(steps));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (cov[i][j]) continue;           ok = 0;           sx = i;           sy = j;           steps[i][j] = 1;           cov[i][j] = 1;           dfs(i, j, 1);           if (ok) break;         }         if (ok) break;       }       if (ok)         printf( Yes n );       else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check_lucky(long long num) {     while (num) {       if ((num % 10) == 8) return 1;       num /= 10;     }     return 0;   }   int main() {     long long num;     cin >> num;     int flag = 0, ans = 1, f2 = 0;     if (num < 0) {       flag = 1;       num *= (-1);     }     if (flag) {       num--;       while (1) {         if (num == 0) {           f2 = 1;         }         if (f2) {           ans++;           if (!num) {             num++;             continue;           }           if (check_lucky(num)) {             cout << ans - 1 << endl;             return 0;           }           num++;         } else {           ans++;           if (check_lucky(num)) {             cout << ans - 1 << endl;             return 0;           }           num--;         }       }     } else {       num++;       while (1) {         ans++;         if (!num) continue;         if (check_lucky(num)) {           cout << ans - 1 << endl;           return 0;         }         num++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans, a[300123], maxx[300123], minx[300123], box[800123];   void dopart(long long l, long long r) {     if (l == r) {       ans++;       return;     }     long long mid = (l + r) / 2;     dopart(l, mid);     dopart(mid + 1, r);     maxx[mid] = a[mid], minx[mid] = a[mid];     for (long long i = mid - 1; i >= l; i--) {       maxx[i] = max(maxx[i + 1], a[i]), minx[i] = min(minx[i + 1], a[i]);     }     maxx[mid + 1] = a[mid + 1], minx[mid + 1] = a[mid + 1];     for (long long i = mid + 2; i <= r; i++) {       maxx[i] = max(maxx[i - 1], a[i]), minx[i] = min(minx[i - 1], a[i]);     }     for (long long i = mid; i >= l; i--) {       long long now = maxx[i] - minx[i];       if (i + now <= mid || i + now > r) continue;       if (maxx[now + i] <= maxx[i] && minx[now + i] >= minx[i]) ans++;     }     for (long long i = mid + 1; i <= r; i++) {       long long now = maxx[i] - minx[i];       if (i - now >= mid + 1 || i - now < l) continue;       if (maxx[i - now] <= maxx[i] && minx[i - now] >= minx[i]) ans++;     }     long long you1 = mid + 1, you2 = mid + 1;     for (long long i = mid; i >= l; i--) {       while (you2 <= r && maxx[you2] < maxx[i]) box[minx[you2] + you2]++, you2++;       while (you1 < you2 && minx[you1] > minx[i])         box[minx[you1] + you1]--, you1++;       ans = ans + box[i + maxx[i]];     }     for (long long i = you1; i < you2; i++) box[minx[i] + i]--;     long long zuo1 = mid, zuo2 = mid;     for (long long i = mid + 1; i <= r; i++) {       while (zuo1 >= l && maxx[zuo1] < maxx[i])         box[minx[zuo1] - zuo1 + n + 1]++, zuo1--;       while (zuo2 > zuo1 && minx[zuo2] > minx[i])         box[minx[zuo2] - zuo2 + n + 1]--, zuo2--;       ans = ans + box[maxx[i] - i + n + 1];     }     for (long long i = zuo2; i > zuo1; i--) box[minx[i] - i + n + 1]--;   }   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       long long p, q;       cin >> p >> q;       a[p] = q;     }     dopart(1, n);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int fx[] = {0, 0, +1, -1};   int fy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 998244353;     (a < 0) && (a += 998244353);   }   inline long long modMul(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a * b) % 998244353;   }   inline long long modAdd(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     return (a + b) % 998244353;   }   inline long long modSub(long long a, long long b) {     a %= 998244353, b %= 998244353;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 998244353 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   inline bool isInside(pair<int, int> p, long long n, long long m) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m);   }   inline bool isInside(pair<int, int> p, long long n) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n);   }   inline bool isSquare(long long x) {     long long s = sqrt(x);     return (s * s == x);   }   inline bool isFib(long long x) {     return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);   }   inline bool isPowerOfTwo(long long x) {     return ((1LL << (long long)log2(x)) == x);   }   struct func {     bool operator()(pair<int, int> const &a, pair<int, int> const &b) {       if (a.first == b.first) return (a.second < b.second);       return (a.first < b.first);     }   };   long long corner(long long n, long long i) {     return (((n - i - 1ll) >= 0) ? modMul(180ll, modPow(10ll, n - i - 1ll)) : 0);   }   long long middle(long long n, long long i) {     return (((n - i - 2) >= 0)                 ? modMul(n - i - 1, modMul(810ll, modPow(10ll, n - i - 2)))                 : 0);   }   long long getResult(long long n, long long i) {     if (i == n) return 10;     return modAdd(corner(n, i), middle(n, i));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cout << getResult(n, i) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int modu = 1e9 + 7;   long long int mod(long long int n) { return (n % modu); }   bool cmp(long long int a, long long int b) { return a > b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int N, a, b, c, d, x = 0;     pair<int, int> P[205], s;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> P[i].first >> P[i].second;     }     for (int i = 0; i < N; i++) {       a = b = c = d = 0;       s.first = P[i].first;       s.second = P[i].second;       for (int j = 0; j < N; j++) {         if (i != j) {           if (P[j].first > s.first && P[j].second == s.second)             a = 1;           else if (P[j].first < s.first && P[j].second == s.second)             b = 1;           else if (P[j].first == s.first && P[j].second > s.second)             c = 1;           else if (P[j].first == s.first && P[j].second < s.second)             d = 1;         }       }       if (a == 1 && b == 1 && c == 1 && d == 1) x++;     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, q = 0, z = 0;     cin >> a >> b >> n;     for (int i = 0; n >= 0; ++i) {       for (int j = a; j >= 1; --j) {         if (a % j == 0 && n % j == 0) {           q = n;           n = n - j;           break;         }       }       if (n >= 0) {         for (int c = b; c >= 1; --c) {           if (b % c == 0 && n % c == 0) {             z = n;             n = n - c;             break;           }         }       }     }     if (z == 0) {       cout <<  0 ;     }     if (q == 0) {       cout <<  1 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3077;   int n, m, p, k, s[N], t[N], ls[N], nxt[N];   long long ans;   vector<int> P[N];   int main() {     scanf( %d%d%d%d , &n, &m, &p, &k);     for (int i = 1; i <= p; i++) {       int x, y;       scanf( %d%d , &x, &y);       P[x].push_back(y);     }     for (int u = n; u >= 1; u--) {       for (int i = 0; i < P[u].size(); i++) ++s[P[u][i]];       int l = 1, r = 0, yjy = 0;       long long aii = 0;       while (1) {         while (r + 1 <= m && yjy < k) yjy += s[++r];         if (yjy < k) break;         while (l <= r && yjy >= k) yjy -= s[l++], aii += m - r + 1;       }       for (int i = 1; i <= m; i++) t[i] = s[i];       for (int i = 0; i <= m + 1; i++) ls[i] = i - 1, nxt[i] = i + 1;       for (int i = 1; i <= m; i++)         if (!s[i]) ls[nxt[i]] = ls[i], nxt[ls[i]] = nxt[i];       for (int d = n; d >= u; d--) {         ans += aii;         for (int i = 0; i < P[d].size(); i++) {           int s = P[d][i], sl = t[s], sr = 0;           l = r = s;           while (nxt[r] <= m && sl + sr + t[nxt[r]] <= k) sr += t[r = nxt[r]];           while (1) {             if (sl + sr == k) aii -= (l - ls[l]) * (nxt[r] - r);             sl += t[l = ls[l]];             if (!l || sl > k) break;             while (sl + sr > k) sr -= t[r], r = ls[r];           }           --t[s];           if (!t[s]) ls[nxt[s]] = ls[s], nxt[ls[s]] = nxt[s];         }       }     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   const long long mod = 998244353;   using namespace std;   pair<long long, long long> dp[20][2][1 << 10];   int k;   int s[20];   long long pw[20];   pair<long long, long long> solve(int i, bool U, int mask) {     if (i < 0) return {0, 1};     pair<long long, long long> &ret = dp[i][U][mask];     if (ret.first + 1) return ret;     ret = {0, 0};     int L = U ? 9 : s[i];     for (int e = 0; e <= L; e++) {       int Mask = mask | (mask > 0 ? (1 << e) : ((e > 0) * (1 << e)));       if (__builtin_popcount(Mask) > k) continue;       pair<long long, long long> temp = solve(i - 1, U || e < s[i], Mask);       ret.first += temp.first + temp.second * e % mod * pw[i] % mod;       ret.first %= mod;       ret.second += temp.second;       ret.second %= mod;     }     return ret;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     pw[0] = 1;     for (int i = 1; i <= 18; i++) pw[i] = pw[i - 1] * 10LL % mod;     long long l, r;     cin >> l >> r >> k;     for (int i = 0; i < 18; i++) s[i] = r % 10, r /= 10;     memset(dp, -1, sizeof dp);     long long ans = solve(17, 0, 0).first;     l--;     for (int i = 0; i < 18; i++) s[i] = l % 10, l /= 10;     memset(dp, -1, sizeof dp);     cout << ((ans - solve(17, 0, 0).first) % mod + mod) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   long long cnt[3000005], pre[3000005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     long long n;     scanf( %lld , &n);     long long a;     for (long long i = 0; i < n; i++) {       scanf( %lld , &a);       cnt[a]++;     }     for (long long i = 1; i < 3000005; i++) {       for (long long j = 1; i * j < 3000005; j++) {         if (i == j)           pre[i * j] += (cnt[i] * (cnt[i] - 1));         else           pre[i * j] += cnt[i] * cnt[j];       }     }     for (long long i = 1; i < 3000005; i++) pre[i] += pre[i - 1];     long long m, p, an = 0, tot = (n * (n - 1));     scanf( %lld , &m);     for (long long i = 0; i < m; i++) {       scanf( %lld , &p);       an = tot - pre[p - 1];       printf( %lld n , an);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> darmo;   vector<pair<int, int> > tab;   vector<bool> done;   vector<int> wolne;   int n, k;   int main() {     scanf( %d %d , &n, &k);     darmo.resize(n);     tab.resize(n);     done.resize(k + 1, false);     long long res = 0;     for (int i = 0; i < n; i++) scanf( %d , &darmo[i]);     for (int i = 0; i < n; i++) {       scanf( %d , &tab[i].first);       tab[i].second = i;     }     sort(tab.begin(), tab.end());     reverse(tab.begin(), tab.end());     for (int i = 0; i < n; i++) {       if (!done[darmo[tab[i].second]]) {         done[darmo[tab[i].second]] = true;       } else         wolne.push_back(tab[i].first);     }     sort(wolne.begin(), wolne.end());     int x = 0;     for (int i = 1; i < k + 1; i++)       if (!done[i]) {         res += (long long)wolne[x];         x++;       }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, res[111][111];   pair<int, int> pos[111][111];   int type, r, c, x;   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) pos[i][j] = pair<int, int>(i, j);     while (q--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d , &r);         for (int i = 0; i < m; ++i) pos[r][i] = pos[r][i + 1];         pos[r][m] = pos[r][0];       } else if (type == 2) {         scanf( %d , &c);         for (int i = 0; i < n; ++i) pos[i][c] = pos[i + 1][c];         pos[n][c] = pos[0][c];       } else {         scanf( %d %d %d , &r, &c, &x);         res[pos[r][c].first][pos[r][c].second] = x;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) printf( %d  , res[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   char mp[3][N], tmp[3][N], g[55][3][N];   bool vis[55][3][N];   int n, k;   void getNext(int id) {     memcpy(g[id], mp, sizeof(mp));     for (int i = int(0); i <= int((3) - 1); i++)       for (int j = int(1); j <= int(n - 3); j++) tmp[i][j] = mp[i][j + 3];     for (int i = int(0); i <= int((3) - 1); i++)       tmp[i][n - 2] = tmp[i][n - 1] = tmp[i][n] =  . ;     memcpy(mp, tmp, sizeof(tmp));   }   int dx[] = {0, -1, 1}, dy[] = {0, 0, 0};   bool good(int now, int x, int y) {     return x >= 0 && x < 3 && g[now][x][y] ==  .  && g[now - 1][x][y + 1] ==  . ;   }   bool bfs(int sx, int sy) {     memset(vis, 0, sizeof(vis));     int now = 0, x = sx, y = sy;     queue<int> q;     q.push(now), q.push(x);     while (q.size()) {       now = q.front();       q.pop();       x = q.front();       q.pop();       if (now > 50) {         return 1;       }       for (int i = int(0); i <= int((3) - 1); i++) {         if (g[now][x][y + 1] !=  . ) continue;         int tx = x + dx[i];         if (good(now + 1, tx, y)) {           if (!vis[now + 1][tx][y]) {             q.push(now + 1), q.push(tx);             vis[now + 1][tx][y] = 1;           }         }       }     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = int(0); i <= int((3) - 1); i++) {         cin >> (mp[i] + 1);       }       int sx, sy;       for (int i = int(0); i <= int((3) - 1); i++) {         for (int j = int(1); j <= int(n); j++)           if (mp[i][j] ==  s ) {             sx = i, sy = j;             mp[i][j] =  . ;           }       }       for (int i = int(0); i <= int((54) - 1); i++) getNext(i);       if (bfs(sx, sy))         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   char num[maxn];   char num2[maxn];   vector<int> vec;   queue<int> que;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     int n = read(), sx = read(), sy = read();     int s1 = 0, s2 = 0, s3 = 0, s4 = 0;     int u = 0, d = 0, l = 0, r = 0;     for (int i = 1; i <= n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       if (x < sx) {         if (y < sy) {           s2++;           s4++;         } else if (y > sy) {           s2++;           s3++;         } else if (y == sy) {           d++;         }       } else if (x > sx) {         if (y < sy) {           s1++;           s4++;         } else if (y > sy) {           s1++;           s3++;         } else {           u++;         }       } else if (x == sx) {         if (y < sy) {           l++;         } else if (y > sy) {           r++;         } else {           continue;         }       }     }     int num1 = s1 + u;     int num2 = s3 + r;     int num3 = s2 + d;     int num4 = s4 + l;     if (num1 >= num2 && num1 > num3 && num1 >= num4) {       printf( %d n , num1);       printf( %d %d n , sx + 1, sy);     } else if (num2 >= num1 && num2 > num3 && num2 >= num4) {       cout << num2 << endl;       printf( %d %d n , sx, sy + 1);     } else if (num3 >= num2 && num3 > num1 && num3 >= num4) {       cout << num3 << endl;       printf( %d %d n , sx - 1, sy);     } else if (num4 >= num2 && num4 > num3 && num4 >= num1) {       cout << num4 << endl;       printf( %d %d n , sx, sy - 1);     }     return 0;   }