#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T maxs(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T mins(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long N = (1 << 21);   const long long M = N - 1;   pair<long long, long long> dp[N];   long long solve() {     long long n;     cin >> n;     vector<long long> a(n + 1);     auto add = [&](long long mask, long long j) {       if (dp[mask].first == -1)         dp[mask].first = j;       else if (dp[mask].second == -1) {         dp[mask].second = j;         if (dp[mask].second < dp[mask].first)           swap(dp[mask].first, dp[mask].second);       } else if (dp[mask].second < j) {         dp[mask].first = dp[mask].second;         dp[mask].second = j;       } else if (dp[mask].first < j && j != dp[mask].second) {         dp[mask].first = j;       }     };     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       add(a[i], i);     }     for (long long i = 0; i < 21; i++) {       for (long long mask = 0; mask < N; mask++) {         if ((mask) & (1 << i)) {           if (dp[mask].first != -1) add(mask ^ (1 << i), dp[mask].first);           if (dp[mask].second != -1) add(mask ^ (1 << i), dp[mask].second);         }       }     }     long long ans = 0;     for (long long i = 1; i < n + 1; i++) {       long long rev_mask = M - a[i];       long long best = 0;       for (long long j = 20; j >= 0; j--) {         if (rev_mask & (1 << j)) {           if (dp[best ^ (1 << j)].second != -1 && dp[best ^ (1 << j)].first > i) {             best ^= (1 << j);           }         }       }       if (i + 2 <= n) maxs(ans, a[i] + best);     }     cout << ans <<   n ;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string a(n,  0 );       string b(n,  0 );       int flag = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  2 ) {           if (flag == 0) {             a[i] =  1 ;             b[i] =  1 ;           } else {             a[i] =  0 ;             b[i] =  2 ;           }         }         if (s[i] ==  1 ) {           if (flag == 0) {             a[i] =  1 ;             flag = 1;           } else {             b[i] =  1 ;           }         }       }       cout << a <<   n ;       cout << b <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-12;   const int inf = 2000000000;   const long long int infLL = (long long int)1e18;   long long int MOD = 1000000007;   int MOD1 = 1000000007;   int MOD2 = 1000000009;   inline bool checkBit(long long int n, long long int i) {     return n & (1LL << i);   }   inline long long int setBit(long long int n, long long int i) {     return n | (1LL << i);     ;   }   inline long long int resetBit(long long int n, long long 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 int year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long int &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long int modMul(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long int modAdd(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long int modSub(long long int a, long long int b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long int modPow(long long int b, long long int p) {     long long int r = 1LL;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1LL;     }     return r;   }   inline long long int modDiv(long long int a, long long int b) {     return modMul(a, modPow(b, MOD - 2));   }   bool comp(const pair<long long int, pair<long long int, long long int> > &p1,             const pair<long long int, pair<long long int, long long int> > &p2) {     return p1.first > p2.first;   }   bool comp1(const pair<long long int, long long int> &p1,              const pair<long long int, long long int> &p2) {     if (p1.first == p2.first) {       return p1.second > p2.second;     }     return p1.first < p2.first;   }   long long int converter(string a) {     long long int i, mul = 1LL, r, t, ans = 0LL;     if (a.length() == 0) return 0;     for (i = a.length() - 1; i >= 0; i--) {       t = a[i] -  0 ;       r = t % 10;       ans += (mul * r);       mul = mul * 10;     }     return ans;   }   int msb(unsigned x) {     union {       double a;       int b[2];     };     a = x;     return (b[1] >> 20) - 1023;   }   const int MAX = 2e5 + 5;   int parent[MAX], sz[MAX];   set<int> s[MAX];   int n, t[MAX], ans[MAX];   void init() {     for (int i = 1; i < MAX; i++) {       parent[i] = i, sz[i] = 1, t[i] = 1;       s[i].insert(i);     }   }   int root(int u) {     while (parent[u] != u) u = parent[parent[u]];     return u;   }   void union_make(int u, int v) {     int root_u = root(u);     int root_v = root(v);     if (root_u == root_v) return;     if (sz[root_u] >= sz[root_v]) {       parent[root_v] = parent[root_u];       sz[root_u] += sz[root_v];     } else {       parent[root_u] = parent[root_v];       sz[root_v] += sz[root_u];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int x, y, i;     cin >> n;     init();     for (i = 1; i < n; ++i) {       cin >> x >> y;       int u = root(x);       int v = root(y);       if (sz[u] < sz[v]) swap(u, v);       long long int add = sz[u];       for (auto it : s[v]) {         s[u].insert(it);         t[it] += add;       }       s[v].clear();       union_make(x, y);     }     for (i = 1; i <= n; ++i) {       ans[t[i]] = i;     }     for (i = 1; i <= n; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6;   const long long MX = -1e7 - 3;   const long long MN = 1e7 + 3;   long long n, m, cnt, ans, x, y, mx = MX, mn = MN, a, b, c, d, T, l, r, k;   float p = 3.14159;   bool bl, bl1;   string str =   , s;   map<char, long long> mp, mp1;   vector<long long> v;   deque<long long> q;   bool used[N];   pair<long long, long long> pr[N];   pair<long long, char> pr1[N];   int main() {     cin >> T;     for (long long i = 0; i < T; i++) {       cin >> n >> x >> a >> b;       if (a > b) {         c = a;         a = b;         b = c;       }       if (a - x >= 1) {         a -= x;         x = 0;       } else {         x -= a - 1;         a = 1;       }       if (b + x <= n) {         b += x;         x = 0;       } else         b = n;       v.push_back(b - a);     }     for (long long i = 0; i < v.size(); i++) cout << v[i] <<   n ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long ts, tf, t;     cin >> ts >> tf >> t;     int n;     cin >> n;     map<long long, int> T;     for (int i = 0; i < n; ++i) {       long long t;       cin >> t;       ++T[t];     }     long long bt = 0, ans = ts + t;     for (const auto &s : T) {       if (ts + t > tf) break;       if (ts < s.first) {         bt = ts;         break;       }       if (s.first > 0) {         long long ta = s.first - 1;         if (ts + t - ta < ans) {           ans = ts + t - ta;           bt = ta;         }       }       ts += t * s.second;     }     if (ts + t <= tf) bt = ts;     cout << bt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200010, INF = 1e9;   int cnt[MAX];   int n, c, ans = INF;   int mx[MAX], v[MAX];   bool f[MAX];   vector<int> a;   bool ok(int x, int y) {     if (x == 0) return 1;     if (y == 0) return 0;     x -= a[y] * min(cnt[a[y]], x / a[y]);     if (mx[x] > y - 1)       return ok(x, y - 1);     else       return f[x];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> c >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;     }     a.push_back(0);     for (int i = 1; i <= c; i++)       if (cnt[i]) a.push_back(i);     a.push_back(c);     int cur = c;     for (int i = a.size() - 1; i >= 1; i--)       cur -= a[i] * min(cnt[a[i]], cur / a[i]), v[i] = cur;     memset(mx, -1, sizeof mx);     for (int i = 0; i < a.size() - 1; i++) {       for (int j = a[i]; j < a[i + 1]; j++) {         mx[j] = i;         f[j] = ok(j, i);       }     }     for (int i = 0; i < a.size() - 1; i++) {       for (int j = a[i]; j < a[i + 1]; j++) {         if (v[i + 1] >= j && !ok(v[i + 1] - j, i)) ans = min(ans, j);       }     }     if (ans != INF)       cout << ans << endl;     else       cout <<  Greed is good  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       s.insert(x);     }     set<int>::iterator it = s.begin();     int c = 0;     while (it != s.end()) {       if (*it == 0) c++;       it++;     }     cout << s.size() - c << endl;   }


#include <bits/stdc++.h>   inline int read() {     int data = 0, w = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) data = data * 10 + (ch ^ 48), ch = getchar();     return data * w;   }   const int N(205), LIM(20010), M(20000), INF(0x3f3f3f3f);   struct edge {     int next, to, cap;   } e[N * N * 2];   int n, A[N], not_prime[LIM], head[N], e_num = -1, lev[N], cur[N], S, T;   inline void Add(int from, int to, int cap) {     e[++e_num] = (edge){head[from], to, cap}, head[from] = e_num;     e[++e_num] = (edge){head[to], from, 0}, head[to] = e_num;   }   void Init() {     not_prime[1] = 1;     for (int i = 2; i <= M; i++)       if (!not_prime[i])         for (int j = i * i; j <= M; j += i) not_prime[j] = 1;   }   int bfs() {     std::queue<int> Q;     Q.push(S);     memset(lev, 0, (T + 1) << 2), lev[S] = 1;     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = head[x]; ~i; i = e[i].next) {         int to = e[i].to;         if (!e[i].cap || lev[to]) continue;         lev[to] = lev[x] + 1, Q.push(to);       }     }     return lev[T];   }   int dfs(int x, int f) {     if (x == T || !f) return f;     int ans = 0, cap;     for (int i = head[x]; ~i; i = e[i].next) {       int to = e[i].to;       if (e[i].cap && lev[to] == lev[x] + 1) {         cap = dfs(e[i].to, std::min(f - ans, e[i].cap));         e[i].cap -= cap, e[i ^ 1].cap += cap, ans += cap;         if (ans == f) break;       }     }     if (!ans) lev[x] = 0;     return ans;   }   int Dinic() {     int ans = 0;     while (bfs()) memcpy(cur, head, (T + 1) << 2), ans += dfs(S, INF);     return ans;   }   std::vector<int> cir[N];   int tot, vis[N];   void find(int x) {     if (1 <= x && x <= n) cir[tot].push_back(x);     vis[x] = 1;     for (int i = head[x]; ~i; i = e[i].next)       if (!vis[e[i].to] && e[i | 1].cap == 1) find(e[i].to);   }   int main() {     memset(head, -1, sizeof head);     Init(), n = read(), S = 0, T = n + 1;     int p = 0, q = 0;     for (int i = 1; i <= n; i++) A[i] = read(), ((A[i] & 1) ? ++p : ++q);     if (p != q) return puts( Impossible ), 0;     for (int i = 1; i <= n; i++)       if (A[i] & 1)         for (int j = (Add(S, i, 2), 1); j <= n; j++) {           if (!not_prime[A[i] + A[j]]) Add(i, j, 1);         }       else         Add(i, T, 2);     if (Dinic() != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; i++)       if (!vis[i]) ++tot, find(i);     printf( %d n , tot);     for (int i = 1; i <= tot; i++, puts(  )) {       printf( %lu  , cir[i].size());       for (int j : cir[i]) printf( %d  , j);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> vec(n);     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     if (n == 1) {       if (vec[0] == 15)         cout <<  DOWN  << endl;       else if (vec[0] == 0)         cout <<  UP  << endl;       else         cout <<  -1  << endl;     } else {       if (vec[n - 1] == 0 || (vec[n - 1] > vec[n - 2] && vec[n - 1] != 15))         cout <<  UP  << endl;       else         cout <<  DOWN  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], g, cnt;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       scanf( %d , &a[i]), g = g == 0 ? a[i] : gcd(a[i], g), cnt += a[i] & 1;     printf( %d n , cnt > 1 ? 0 : g);     string str, ans;     for (int i = 0; i < n; i++)       for (int j = 1; j <= a[i] / g / 2; j++) str = str + char( a  + i);     for (int i = 0; i < n; i++)       if (a[i] / g & 1) str = str + char(i +  a );     for (int i = n - 1; i >= 0; i--)       for (int j = 1; j <= a[i] / g / 2; j++) str = str + char(i +  a );     while (g--) ans = ans + str, reverse(str.begin(), str.end());     return cout << ans, 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> V;   void dfs(long long x) {     if (x < 1000000000) {       V.push_back(x);       dfs(x * 10 + 4);       dfs(x * 10 + 7);     }   }   int main() {     dfs(0);     V.push_back(INT_MAX);     sort(V.begin(), V.end());     int pl, pr, vl, vr, k;     cin >> pl >> pr >> vl >> vr >> k;     double cnt = 0;     double all = ((vr - vl) + 1.0) * ((pr - pl) + 1.0);     for (int i = 1; i < V.size() - k; i++) {       int hll = V[i - 1] + 1;       int hl = V[i];       int hr = V[(i + k) - 1];       int hrr = V[(i + k)] - 1;       if (pl <= hl && pr >= hll && vl <= hrr && vr >= hr) {         cnt += (min(pr, hl) - max(pl, hll) + 1.0) *                (min(vr, hrr) - max(vl, hr) + 1.0);       }       if (vl <= hl && vr >= hll && pl <= hrr && pr >= hr) {         cnt += (min(vr, hl) - max(vl, hll) + 1.0) *                (min(pr, hrr) - max(pl, hr) + 1.0);         if (k == 1) cnt -= 1.0;       }     }     printf( %.12f , cnt / all);   exit:     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int cnt = 0;     string ans =  1 ;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       while (str.size() && str.back() ==  0 ) str.pop_back(), cnt++;       if (str.size() == 0) {         cout <<  0 ;         exit(0);       }       if (str.size() != 1 || str.back() !=  1 ) ans = str;     }     cout << ans;     for (int i = 0; i < cnt; i++) cout <<  0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 16;   int n, a[maxn], b[maxn][maxn], ex;   bool mark[maxn];   vector<vector<int> > all;   void bt(int s = 0) {     if (s == n) {       for (int i = 0, sum = 0; i < n; i++, sum = 0) {         for (int j = 0; j < n; j++) sum += b[j][i];         if (sum != ex) return;       }       {         int sum = 0;         for (int i = 0; i < n; i++) sum += b[i][i];         if (sum != ex) return;       }       {         int sum = 0;         for (int i = 0; i < n; i++) sum += b[i][n - i - 1];         if (sum != ex) return;       }       for (int i = 0; i < n; i++, cout <<   n )         for (int j = 0; j < n; j++) cout << b[i][j] <<    ;       exit(0);     }     for (auto v : all) {       bool reval = 1;       for (auto x : v)         if (mark[x]) {           reval = 0;           break;         }       if (!reval) continue;       do {         for (int i = 0; i < n; i++) b[s][i] = a[v[i]], mark[v[i]] = 1;         bt(s + 1);         for (int i = 0; i < n; i++) mark[v[i]] = 0;       } while (next_permutation(v.begin(), v.end()));     }   }   int main() {     ios::sync_with_stdio(0), cin.tie();     cin >> n;     for (int i = 0; i < n * n; i++) cin >> a[i], ex += a[i];     ex /= n;     cout << ex <<   n ;     for (int i = 0; i < 1 << n * n; i++)       if (__builtin_popcount(i) == n) {         int sum = 0;         for (int j = 0; j < n * n; j++) sum += (i >> j & 1) * a[j];         if (sum == ex) {           all.push_back({});           for (int j = 0; j < n * n; j++)             if (i >> j & 1) all.back().push_back(j);           sort(all.back().begin(), all.back().end());         }       }     bt();     return 0;   }


#include <bits/stdc++.h>   int main() {     char p[1000001];     int n, m, y2;     int y1 = -1;     long long ans = 1;     scanf( %d %d , &n, &m);     scanf( %s , p);     int plen = strlen(p);     for (int i = 0; i < m; ++i) {       scanf( %d , &y2);       if (-1 == y1) {         n -= plen;       } else if (y2 - y1 < plen) {         if (p[y2 - y1] != p[0]) {           printf( 0 n );           return 0;         }         n -= y2 - y1;       } else {         n -= plen;       }       y1 = y2;     }     for (int i = 0; i < n; ++i) {       ans = ans * 26 % 1000000007;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int tcase;     for (scanf( %d , &tcase); tcase--;) {       long long l, r;       scanf( %lld%lld , &l, &r);       if (l == r) {         printf( %lld n , r);         continue;       }       int p = 63 - __builtin_clzll(l ^ r);       long long temp = 0;       for (int i = 63; i > p; --i)         if (l >> i & 1) temp |= 1LL << i;       long long a = (1LL << p) - 1, b = (1LL << (p + 1)) - 1;       a |= temp, b |= temp;       if (l <= b && b <= r) a = b;       printf( %lld n , a);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   struct dsu {     vector<int> par, rnk, size;     int c;     dsu(int n) : par(n + 1), rnk(n + 1, 0), size(n + 1, 1), c(n) {       for (int i = 1; i <= n; ++i) par[i] = i;     }     int find(int i) { return (par[i] == i ? i : (par[i] = find(par[i]))); }     bool same(int i, int j) { return find(i) == find(j); }     int get_size(int i) { return size[find(i)]; }     int count() { return c; }     int merge(int i, int j) {       if ((i = find(i)) == (j = find(j)))         return -1;       else         --c;       if (rnk[i] > rnk[j]) swap(i, j);       par[i] = j;       size[j] += size[i];       if (rnk[i] == rnk[j]) rnk[j]++;       return j;     }   };   const int N = 1e5 + 9;   long long d[N];   int near[N], vis[N];   vector<pair<int, int>> g[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<array<long long, 3>> edges, ed;     for (int i = 1; i <= m; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});       edges.push_back({u, v, w});     }     for (int i = 1; i <= n; i++) {       d[i] = inf;     }     int k;     cin >> k;     set<pair<long long, int>> se;     for (int i = 1; i <= k; i++) {       int u;       cin >> u;       se.insert({0, u});       near[u] = u;       d[u] = 0;     }     while (!se.empty()) {       auto x = *se.begin();       se.erase(se.begin());       int u = x.second;       if (vis[u]) continue;       vis[u] = 1;       for (auto e : g[u]) {         int v = e.first, w = e.second;         if (d[u] + w < d[v]) {           d[v] = d[u] + w;           near[v] = near[u];           se.insert({d[v], v});         }       }     }     for (auto e : edges) {       if (near[e[0]] == near[e[1]]) continue;       ed.push_back({d[e[0]] + d[e[1]] + e[2], near[e[0]], near[e[1]]});     }     sort(ed.begin(), ed.end());     dsu D(n);     long long ans = d[1];     for (auto e : ed) {       int u = e[1], v = e[2];       long long w = e[0];       if (D.same(u, v)) continue;       ans += w;       D.merge(u, v);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool b[31];   struct trie {     trie* nt[2];     int tot;     trie() {       nt[0] = nt[1] = NULL;       tot = 0;     }   };   trie* root = new trie();   void insert(trie* cur, int idx) {     if (idx == -1)       return;     else {       int x = b[idx];       if (cur->nt[x] == NULL) cur->nt[x] = new trie();       cur->nt[x]->tot++;       insert(cur->nt[x], idx - 1);     }   }   void del(trie* cur, int idx) {     if (idx == -1)       return;     else {       int x = b[idx];       del(cur->nt[x], idx - 1);       cur->nt[x]->tot--;       if (cur->nt[x]->tot == 0) cur->nt[x] = NULL;     }   }   int query(trie* cur, int idx) {     if (idx == -1)       return 0;     else {       int x = 1 - b[idx];       int add = 1 << idx;       if (cur->nt[x] == NULL) x = 1 - x, add = 0;       return query(cur->nt[x], idx - 1) + add;     }   }   int main() {     insert(root, 30);     int q;     scanf( %d , &q);     while (q--) {       char s[2];       int x;       scanf( %s%d , s, &x);       for (int i = 0; i <= 30; i++) {         b[i] = x % 2;         x /= 2;       }       if (s[0] ==  + )         insert(root, 30);       else if (s[0] ==  - )         del(root, 30);       else         printf( %d n , query(root, 30));     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000 + 100;   int n, m, sz, l, r;   int head[maxn], Next[maxn], to[maxn], in[maxn], out[maxn], deg[maxn], q[maxn];   void init() {     sz = 0;     memset(deg, 0, sizeof(deg));     memset(head, -1, sizeof(head));   }   void add_edge(int a, int b) {     ++sz;     to[sz] = b;     Next[sz] = head[a];     head[a] = sz;   }   struct Edge {     int from, to;   } edges[maxn];   int main() {     init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edges[i].from = a;       edges[i].to = b;       add_edge(a, b);       deg[b]++;     }     l = r = 0;     for (int i = 1; i <= n; i++) {       if (!deg[i]) {         q[r++] = i;       }     }     while (l < r) {       int u = q[l++];       if (l == r) {         out[u] = n - r;       } else if (l + 1 == r) {         int v = q[l];         int flag = 1;         for (int i = head[v]; i != -1; i = Next[i]) {           int vv = to[i];           if (deg[vv] == 1) {             flag = 0;             break;           }         }         if (!flag)           out[u] = -n;         else           out[u] = n - r;       } else         out[u] = -n;       for (int i = head[u]; i != -1; i = Next[i]) {         int v = to[i];         deg[v]--;         if (!deg[v]) q[r++] = v;       }     }     init();     for (int i = 1; i <= m; i++) {       add_edge(edges[i].to, edges[i].from);       deg[edges[i].from]++;     }     l = r = 0;     for (int i = 1; i <= n; i++) {       if (!deg[i]) {         q[r++] = i;       }     }     while (l < r) {       int u = q[l++];       if (l == r) {         in[u] = n - r;       } else if (l + 1 == r) {         int v = q[l];         int flag = 1;         for (int i = head[v]; i != -1; i = Next[i]) {           int vv = to[i];           if (deg[vv] == 1) {             flag = 0;             break;           }         }         if (!flag)           in[u] = -n;         else           in[u] = n - r;       } else         in[u] = -n;       for (int i = head[u]; i != -1; i = Next[i]) {         int vv = to[i];         deg[vv]--;         if (!deg[vv]) q[r++] = vv;       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (in[i] + out[i] >= n - 2) {         ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n == 1 || n == 2 || n == 3) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     if (n % 2 == 0) {       printf( 1 * 2 = 2 n );       printf( 2 * 3 = 6 n );       printf( 6 * 4 = 24 n );     } else {       printf( 3 - 1 = 2 n );       printf( 5 - 2 = 3 n );       printf( 2 * 3 = 6 n );       printf( 6 * 4 = 24 n );     }     if (n % 2 == 0) {       for (int i = n; i >= 6; i -= 2) {         printf( %d - %d = 1 n , i, i - 1);         printf( 24 * 1 = 24 n );       }     } else {       for (int i = n; i >= 7; i -= 2) {         printf( %d - %d = 1 n , i, i - 1);         printf( 24 * 1 = 24 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r[105][105], d[105][105], vis[105][105];   int w, h, n;   int bfs(int x, int y) {     queue<pair<int, int> > q;     q.push({x, y});     vis[x][y] = 1;     int area = 0;     while (!q.empty()) {       int cx = q.front().first, cy = q.front().second;       q.pop();       ++area;       if (!d[cx][cy] && cx > 1 && !vis[cx - 1][cy])         q.push({cx - 1, cy}), vis[cx - 1][cy] = 1;       if (!r[cx][cy] && cy < w && !vis[cx][cy + 1])         q.push({cx, cy + 1}), vis[cx][cy + 1] = 1;     }     return area;   }   int main() {     cin >> w >> h >> n;     int x1, x2, y1, y2;     for (int i = 1; i <= n; ++i) {       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2)         for (int j = y1 + 1; j <= y2; ++j) r[j][x1] = 1;       else         for (int j = x1 + 1; j <= x2; ++j) d[y1 + 1][j] = 1;     }     vector<int> ans;     for (int i = h; i >= 1; --i)       for (int j = 1; j <= w; ++j)         if (!vis[i][j]) ans.push_back(bfs(i, j));     sort(ans.begin(), ans.end());     for (auto& x : ans) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   struct data {     int points;     string name;     data(int p, string n) {       points = p;       name = n;     }     data() {       points = -1;       name =   ;     }   };   inline bool cmp(data d1, data d2) { return (d1.points > d2.points); }   int main() {     int n, m, r, points;     cin >> n >> m;     string name;     vector<vector<data>> reg(m);     for (auto i(0); i < n; ++i) {       cin >> name >> r >> points;       r--;       if (reg[r].size() < 3) {         reg[r].push_back(data(points, name));         sort(reg[r].begin(), reg[r].end(), cmp);       } else {         reg[r].push_back(data(points, name));         sort(reg[r].begin(), reg[r].end(), cmp);         reg[r].resize(3);       }     }     for (auto i(0); i < m; ++i) {       if (reg[i].size() == 2) {         cout << reg[i][0].name <<     << reg[i][1].name << endl;         ;       } else if (reg[i][1].points == reg[i][2].points) {         cout <<  ?  << endl;       } else {         cout << reg[i][0].name <<     << reg[i][1].name << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, M = 1e6 + 5;   long long T, l[N], dp[N], fen[M][2];   vector<int> adj[N];   int n, x[N], t[N];   void add(int p, int x) {     for (long long y = 1LL * x * p; p < M; p += p & -p)       fen[p][0] += x, fen[p][1] += y;   }   long long get(int p, int id) {     long long ans = 0;     for (; p; p -= p & -p) ans += fen[p][id];     return ans;   }   void dfs(int u) {     add(t[u], x[u]);     int L = 0, R = M;     while (L + 1 < R) {       int mid = L + R >> 1;       (T < 2 * l[u] + get(mid, 1) ? R : L) = mid;     }     long long mx[2] = {};     for (int v : adj[u]) {       l[v] += l[u], dfs(v);       dp[v] > mx[1] ? mx[0] = mx[1], mx[1] = dp[v] : mx[0] = max(mx[0], dp[v]);     }     dp[u] =         max(get(L, 0) + (R < M && T > 2 * l[u]) * (T - 2 * l[u] - get(L, 1)) / R,             mx[!u]);     add(t[u], -x[u]);   }   int main() {     cin >> n >> T;     for (int u = 0; u < n; u++) cin >> x[u];     for (int u = 0; u < n; u++) cin >> t[u];     for (int u = 1, v; u < n; u++) {       cin >> v >> l[u];       adj[--v].push_back(u);     }     dfs(0), cout << dp[0];   }


#include <bits/stdc++.h>   using namespace std;   long long f[(1 << 20) + 10], num[21], sum[21][21];   int main() {     int n, m = 20;     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       x--, num[x]++;       for (int j = 0; j < 20; j++) {         sum[j][x] += num[j];       }     }     memset(f, 0x3f, sizeof f);     f[0] = 0;     for (int i = 1; i < 1 << m; i++) {       for (int j = 0; j < m; j++) {         if (i >> j & 1) {           long long cur = 0;           for (int k = 0; k < m; k++) {             if ((i >> k & 1) && k != j) {               cur += sum[k][j];             }           }           f[i] = min(f[i], f[i ^ (1 << j)] + cur);         }       }     }     printf( %lld n , f[(1 << m) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[7];   long long T, X, Y, ans;   long long ABS(long long x) { return (x > 0) ? x : -x; }   int main() {     scanf( %lld , &T);     while (T--) {       scanf( %lld%lld , &X, &Y);       for (int i = 1; i <= 6; i++) scanf( %lld , &a[i]);       a[1] = min(a[1], a[6] + a[2]);       a[6] = min(a[6], a[5] + a[1]);       for (int i = 2; i <= 5; i++) {         a[i] = min(a[i], a[i - 1] + a[i + 1]);       }       if (X <= Y && X >= 0) {         X = ABS(X);         Y = ABS(Y);         ans = a[1] * X + a[2] * (Y - X);       } else if (X < 0 && Y >= 0) {         X = ABS(X);         Y = ABS(Y);         ans = a[2] * Y + a[3] * X;       } else if (X < 0 && -X >= -Y && Y < 0) {         X = ABS(X);         Y = ABS(Y);         ans = a[4] * Y + a[3] * (X - Y);       } else if (X <= 0 && Y < 0 && -X < -Y) {         X = ABS(X);         Y = ABS(Y);         ans = a[4] * X + a[5] * (Y - X);       } else if (X > 0 && Y <= 0) {         X = ABS(X);         Y = ABS(Y);         ans = a[6] * X + a[5] * Y;       } else {         X = ABS(X);         Y = ABS(Y);         ans = a[1] * Y + a[6] * (X - Y);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   bool check(int s) { return (int)sqrt(s) * (int)sqrt(s) == s; }   int main() {     int i, j, a, b, c, d, s1, s2, s3, s4;     scanf( %d%d , &n, &m);     for (a = 1; a <= 100; a++)       for (b = 1; b <= 100; b++)         for (c = 1; c <= 100; c++)           for (d = 1; d <= 100; d++) {             s1 = (m - 1) * a * a + b * b;             s2 = (n - 1) * a * a + c * c;             s3 = (n - 1) * b * b + d * d;             s4 = (m - 1) * c * c + d * d;             if (check(s1) && check(s2) && check(s3) && check(s4)) goto hhh;           }   hhh:     for (i = 1; i < n; i++) {       for (j = 1; j < m; j++) printf( %d  , a);       printf( %d n , b);     }     for (i = 1; i < m; i++) printf( %d  , c);     printf( %d n , d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<float> coordinates;     for (int i = 0; i < (int)(n); ++i) {       float a, b;       cin >> a >> b;       coordinates.push_back(a);       coordinates.push_back(b);     }     float sum = 0;     std::cout << fixed;     std::cout << setprecision(9);     for (int i = 0; i < coordinates.size() - 2; i += 2) {       sum += sqrt(pow(abs(coordinates[i] - coordinates[i + 2]), 2) +                   pow(abs(coordinates[i + 1] - coordinates[i + 3]), 2)) /              50;     }     cout << sum * k <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[300005], one[300005];   map<pair<int, int>, int> mp;   int size[300005], ji[300005], xx[300005], yy[300005];   char ans[300005];   void dfs1(int p, int fa) {     size[p] = 1;     ji[p]++;     for (int i = 0; i < v[p].size(); i++) {       int to = v[p][i];       if (to == fa || ji[to]) continue;       dfs1(to, p);       size[p] += size[to];     }     for (int i = 0; i < one[p].size(); i++) {       int to = one[p][i];       if (to == fa) continue;       mp[pair<int, int>(p, to)] = 1;       if (ji[to]) continue;       dfs1(to, p);       size[p] += size[to];     }   }   void dfs2(int p, int fa) {     size[p] = 1;     ji[p]++;     for (int i = 0; i < v[p].size(); i++) {       int to = v[p][i];       if (to == fa || ji[to]) continue;       dfs2(to, p);       size[p] += size[to];     }     for (int i = 0; i < one[p].size(); i++) {       int to = one[p][i];       if (to == fa) continue;       mp[pair<int, int>(to, p)] = 1;     }   }   int main() {     int n, m, s, tot = 0;     scanf( %d%d%d , &n, &m, &s);     for (int i = 0; i < m; i++) {       int f, x, y;       scanf( %d%d%d , &f, &x, &y);       if (f == 1)         v[x].push_back(y);       else {         one[x].push_back(y);         one[y].push_back(x);         xx[tot] = x;         yy[tot++] = y;       }     }     dfs1(s, 0);     printf( %d n , size[s]);     for (int i = 0; i < tot; i++) {       if (mp[pair<int, int>(xx[i], yy[i])])         printf( + );       else         printf( - );     }     printf(  n );     memset(ji, 0, sizeof(ji));     mp.clear();     dfs2(s, 0);     printf( %d n , size[s]);     for (int i = 0; i < tot; i++) {       if (mp[pair<int, int>(xx[i], yy[i])])         printf( + );       else         printf( - );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     vector<string> notes, names(55);     for (int i = 0; i <= n - k; i++) {       string m;       cin >> m;       notes.push_back(m);     }     for (int i = 0; i < 26; i++) {       names[i] = (i +  A );     }     if (n >= 26) {       for (int i = 26; i <= n; i++) {         names[i] = names[i - 26] +  a ;       }     }     for (int i = 0; i <= n - k; i++) {       if (notes[i] ==  NO ) names[i + k - 1] = names[i];     }     for (int i = 0; i < n; i++) {       cout << names[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     double d, h, v, e;     cin >> d >> h >> v >> e;     double ans = (3.14159265358979323846 * pow(d, 2) * h) /                  (4 * v - 3.14159265358979323846 * pow(d, 2) * e);     if (ans < 0)       cout <<  NO n ;     else {       cout <<  YES n ;       cout << setprecision(10) << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool taken[1001];   int a[1001], b[1001], ans[1001];   vector<int> problem;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       cin >> b[i];       if (b[i] == a[i])         ans[i] = b[i], taken[a[i]] = true;       else         problem.push_back(i);     }     if (problem.size() == 1) {       for (int i = 1; i <= n; ++i) {         if (!taken[i]) {           ans[problem[0]] = i;           break;         }       }     } else {       vector<int> possible[2];       for (int i = 1; i <= n; ++i) {         if (!taken[i]) {           if (a[problem[0]] == i || b[problem[0]] == i) possible[0].push_back(i);           if (a[problem[1]] == i || b[problem[1]] == i) possible[1].push_back(i);         }       }       if (possible[0].size() == possible[1].size()) {         if (possible[0].size() == 1) {           ans[problem[0]] = possible[0][0];           ans[problem[1]] = possible[1][0];         } else {           ans[problem[0]] = possible[0][0];           ans[problem[1]] = possible[1][1];         }       } else {         if (possible[0].size() == 1) {           ans[problem[0]] = possible[0][0];           ans[problem[1]] = (possible[0][0] == possible[1][0] ? possible[1][1]                                                               : possible[1][0]);         } else {           ans[problem[0]] = (possible[1][0] == possible[0][0] ? possible[0][1]                                                               : possible[0][0]);           ans[problem[1]] = possible[1][0];         }       }     }     for (int i = 0; i < n; ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     multiset<int> s;     s.insert(0);     int q;     cin >> q;     while (q--) {       char c;       int x;       cin >> c >> x;       if (c ==  + ) {         s.insert(x);       } else if (c ==  - ) {         s.erase(s.find(x));       } else {         int cur = 0;         for (int i = 30; i >= 0; i--) {           if (((1 << i) & x) == 0) {             cur |= (1 << i);             auto it = s.lower_bound(cur);             if (it == s.end() || (cur >> i) != (*it >> i)) cur ^= (1 << i);           } else {             auto it = s.lower_bound(cur);             if (it == s.end() || (cur >> i) != (*it >> i)) cur |= (1 << i);           }         }         cout << (x ^ cur) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int n;     long long mmax = 0;     long long sum = 0;     long long num;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> num;       sum += num;       mmax = max(mmax, num);     }     cout << 2 * mmax - sum + 1 << endl;   }


#include <bits/stdc++.h>   template <int MOD>   struct Integral {     int v_ = 0;     template <typename T>     Integral(T v) : v_(norm(v)) {       static_assert(std::is_integral<T>::value,  input should be an integral. );     }     Integral() = default;     ~Integral() = default;     template <typename T>     T norm(T v) const {       if (v >= MOD) v -= MOD;       if (v < 0) v += MOD;       if (v >= MOD || v < 0) v = (v % MOD + MOD) % MOD;       return v;     }     int val() const { return v_; }     Integral operator+(const Integral& rhs) const {       return Integral(val() + rhs.val());     }     Integral operator-(const Integral& rhs) const {       return Integral(val() - rhs.val());     }     Integral operator*(const Integral& rhs) const {       return Integral(val() * 1LL * rhs.val());     }     Integral operator/(const Integral& rhs) const { return *this * rhs.inv(); }     Integral& operator+=(const Integral& rhs) { return *this = *this + rhs; }     Integral& operator-=(const Integral& rhs) { return *this = *this - rhs; }     Integral& operator*=(const Integral& rhs) { return *this = *this * rhs; }     Integral& operator/=(const Integral& rhs) { return *this = *this / rhs; }     bool operator==(const Integral& rhs) const { return val() == rhs.val(); }     bool operator!=(const Integral& rhs) const { return !(*this == rhs); }     const Integral operator-() const { return Integral(-val()); }     const Integral operator++() {       v_ = norm(v_ + 1);       return *this;     }     const Integral operator++(int) {       Integral ret = *this;       ++(*this);       return ret;     }     const Integral operator--() {       v_ = norm(v_ - 1);       return *this;     }     const Integral operator--(int) {       Integral ret = *this;       --(*this);       return ret;     }     Integral power(long long b) const {       long long ret = 1 % MOD, a = v_;       for (; b; b >>= 1, a = a * a % MOD)         if (b & 1) ret = ret * a % MOD;       return ret;     }     Integral inv() const { return power(MOD - 2); }   };   template <int MOD>   std::string to_string(const Integral<MOD>& v) {     return std::string( Integral{v= ) + std::to_string(v.val()) +  } ;   }   template <int MOD, bool kAllowBruteForce = false>   struct Binomial {     std::vector<Integral<MOD>> factor, inv_factor;     explicit Binomial(int n = 0) : factor(n + 1), inv_factor(n + 1) {       factor[0] = 1;       for (int i = 1; i <= n; ++i) factor[i] = factor[i - 1] * i;       inv_factor[n] = factor[n].inv();       for (int i = n; i >= 1; --i) inv_factor[i - 1] = inv_factor[i] * i;     }     ~Binomial() = default;     template <typename T>     Integral<MOD> operator()(T a, T b) const {       if (a < b || b < 0) return 0;       if (a < factor.size()) return factor[a] * inv_factor[b] * inv_factor[a - b];       if constexpr (!kAllowBruteForce) {         throw std::out_of_range( Binomial );       } else {         b = std::min(b, a - b);         Integral<MOD> ret = 1;         for (T i = 1; i <= b; ++i) ret = ret * (a + 1 - i) / i;         return ret;       }     }   };   template <int MOD>   struct PowerTable {     std::vector<Integral<MOD>> arr;     PowerTable(int n, const Integral<MOD>& g) : arr(n + 1) {       arr[0] = 1;       arr[1] = g;       for (int i = 2; i < arr.size(); ++i) arr[i] = arr[i - 1] * arr[1];     }     template <typename T>     Integral<MOD> power(T index) const {       if (0 <= index && index < arr.size()) return arr[index];       return arr[1].power(index);     }   };   const int MOD = 1e9 + 7;   using Mint = Integral<MOD>;   using Binom = Binomial<MOD>;   Binom binom(200);   const int kN = 50 + 5;   const int kM = 2500 + 5;   Mint f[kN][kN][kM];   Mint g[kN][kN][kN][2];   Mint h[kN][kM];   Mint q[kN][kM];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::istream& reader = std::cin;     int n, T;     reader >> n >> T;     std::vector<std::vector<int>> ts(3);     for (int i = 0; i < n; ++i) {       int t, g;       reader >> t >> g;       ts[g - 1].emplace_back(t);     }     int m[3] = {};     for (int i = 0; i < 3; ++i) m[i] = ts[i].size();     f[0][0][0] = 1;     for (int t : ts[0]) {       for (int i = m[0] - 1; i >= 0; --i)         for (int k = T - t; k >= 0; --k) f[i + 1][0][k + t] += f[i][0][k];     }     for (int t : ts[1]) {       for (int j = m[1] - 1; j >= 0; --j)         for (int i = m[0]; i >= 0; --i)           for (int k = T - t; k >= 0; --k) f[i][j + 1][k + t] += f[i][j][k];     }     g[0][0][0][0] = 1;     for (int i = 0; i <= m[0]; ++i) {       for (int j = 0; j <= m[1]; ++j) {         for (int k = 0; k <= i + j; ++k) {           for (int r = 0; r < 2; ++r)             if (g[i][j][k][r].val()) {               Mint val = g[i][j][k][r].val();               g[i + 1][j][k + 1][0] += val;               g[i][j + 1][k + 1][1] += val;               if (k > 0) {                 if (r == 0) g[i][j + 1][k][1] += val;                 if (r == 1) g[i + 1][j][k][0] += val;               }             }         }       }     }     for (int i = 0; i <= m[0]; ++i) {       for (int j = 0; j <= m[1]; ++j) {         for (int k = 0; k <= i + j; ++k) {           for (int w = 0; w < 2; ++w)             if (g[i][j][k][w].val()) {               for (int r = 0; r <= T; ++r)                 if (f[i][j][r].val()) {                   q[k][r] += f[i][j][r] * g[i][j][k][w] * binom.factor[i] *                              binom.factor[j];                 }             }         }       }     }     h[0][0] = 1;     for (int t : ts[2]) {       for (int j = m[2] - 1; j >= 0; --j)         for (int k = T - t; k >= 0; --k) h[j + 1][k + t] += h[j][k];     }     Mint result = 0;     for (int k = 0; k <= m[0] + m[1]; ++k) {       for (int t = 0; t <= T; ++t)         if (q[k][t].val()) {           1145141919810;           for (int c = std::max(0, k - 1); c <= k + 1 && c <= m[2]; ++c) {             if (!h[c][T - t].val()) continue;             Mint coef = c == k ? 2 : 1;             result += coef * q[k][t] * h[c][T - t] * binom.factor[c];             1145141919810;           }         }     }     printf( %d n , result.val());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::cin.tie(0);     std::ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       int nn = n - (n % 2 == 1);       int mm = m - (m % 2 == 1);       long long maxx = (nn / 2) * (mm / 2) * 2;       if (n != nn) {         maxx += m / 2;         if (m / 2 > k || (k - m / 2) % 2 == 1) {           cout <<  NO  << endl;           continue;         }       } else {         if (k % 2 == 1) {           cout <<  NO  << endl;           continue;         }       }       if (maxx < k) {         cout <<  NO  << endl;         continue;       }       vector<vector<char>> l = {{ a ,  b ,  c ,  d }, { x ,  y ,  z ,  w }};       vector<char> let = { m ,  n };       int q = 0;       vector<vector<char>> ans(n, vector<char>(m));       if (n != nn) {         for (int i = 0; i < m; i += 2) {           k--;           ans[n - 1][i] = let[q];           ans[n - 1][i + 1] = let[q];           q = (q + 1) % 2;         }       }       q = 0;       if (m != mm) {         for (int i = 0; i < n; i += 2) {           ans[i][m - 1] = let[q];           ans[i + 1][m - 1] = let[q];           q = (q + 1) % 2;         }       }       q = 0;       for (int i = 0; i < nn; i += 2) {         int f = (i % 4 == 0);         q = 0;         for (int j = 0; j < mm; j += 2) {           if (k > 0) {             ans[i][j] = l[f][q];             ans[i][j + 1] = l[f][q];             q = (q + 1) % 4;             ans[i + 1][j] = l[f][q];             ans[i + 1][j + 1] = l[f][q];             q = (q + 1) % 4;             k -= 2;           } else {             ans[i][j] = l[f][q];             ans[i + 1][j] = l[f][q];             q = (q + 1) % 4;             ans[i][j + 1] = l[f][q];             ans[i + 1][j + 1] = l[f][q];             q = (q + 1) % 4;           }         }       }       cout <<  YES  << endl;       for (int i = int(0); i < int(n); i++) {         for (int j = int(0); j < int(m); j++) cout << ans[i][j];         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<vector<pair<long long, long long> > > g;   void fun() {     cin >> n >> m >> k;     g.resize(n);     map<pair<int, int>, int> index;     for (long long i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       x--;       y--;       g[x].push_back({y, z});       g[y].push_back({x, z});       index[{x, y}] = i + 1;       index[{y, x}] = i + 1;     }     vector<long long> dis(n, LLONG_MAX), par(n);     dis[0] = 0;     set<pair<long long, long long> > s;     s.insert({0, 0});     while (!s.empty()) {       pair<long long, long long> d = *s.begin();       s.erase(s.begin());       for (auto j : g[d.second]) {         if (dis[j.first] > dis[d.second] + j.second) {           s.erase({dis[j.first], j.first});           dis[j.first] = dis[d.second] + j.second;           par[j.first] = d.second;           s.insert({dis[j.first], j.first});         }       }     }     vector<pair<long long, int> > dissort;     for (int i = 0; i < n; i++) dissort.push_back({dis[i], i});     sort((dissort).begin(), (dissort).end());     cout << min(n - 1, k) <<   n ;     k = min(n - 1, k);     int j = 1;     while (k--) {       int x = dissort[j].second;       cout << index[{x, par[x]}] <<    ;       j++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     srand(time(0));     ;     int t = 1;     while (t--) fun();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long m, k;     scanf( %d%lld%lld , &n, &m, &k);     long long a[n], asum[n + 1];     asum[0] = 0;     for (int((i)) = (0); ((i)) < ((n)); ++((i))) {       scanf( %lld , &a[i]);       asum[i + 1] = asum[i] + a[i];     }     long long dp[m];     for (int((i)) = (0); ((i)) < ((m)); ++((i))) dp[i] = 1e18;     long long ans = 0;     for (int((i)) = (0); ((i)) < ((n)); ++((i))) {       dp[i % m] = min(dp[i % m] + k, asum[i] + k);       for (int((j)) = (0); ((j)) < ((m)); ++((j)))         ans = max(ans, asum[i + 1] - dp[j]);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int E9 = 1e9;   const int E8 = 1e8;   const int E7 = 1e7;   const int E6 = 1e6;   const int E5 = 1e5;   const int E4 = 1e4;   const int E3 = 1e3;   const int N = 5e5 + 7;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   int n;   bool dp[101][51][2][201];   string s;   void calc(int com, int kol, int dir, int pos) {     if (dp[com][kol][dir][pos]) {       return;     }     dp[com][kol][dir][pos] = 1;     if (com == (int)s.size()) {       return;     }     for (int i = 0; i <= n - kol; i++) {       if (i % 2 == 0) {         if (s[com] ==  F ) {           calc(com + 1, kol + i, dir, pos + (dir == 0 ? 1 : -1));         } else {           calc(com + 1, kol + i, (dir ^ 1), pos);         }       } else {         if (s[com] ==  T ) {           calc(com + 1, kol + i, dir, pos + (dir == 0 ? 1 : -1));         } else {           calc(com + 1, kol + i, (dir ^ 1), pos);         }       }     }   }   int main() {     cin >> s >> n;     calc(0, 0, 0, 100);     int sz = (int)s.size();     int mx = 0;     for (int i = 0; i <= 200; i++) {       if (dp[sz][n][0][i] || dp[sz][n][1][i]) {         mx = max(mx, abs(i - 100));       }     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long n, sum = 0;     cin >> n;     if (n % 2 == 0) {       if ((n / 2) % 2 == 0)         cout << 0 << endl;       else         cout << 1 << endl;     } else {       if ((n / 2) % 2 == 0)         cout << 1 << endl;       else         cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 1e9 + 7;   long long mod = 998244353;   using namespace std;   vector<long long> g[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T, N, i, j, k, L, l, m, n;     long long s;     cin >> N >> s;     for (i = 0; i < N - 1; i++) {       long long u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     long double ans = 0.0;     if (N == 2)       ans = (long double)s / 2.0;     else {       long long cnt = 0;       for (i = 0; i < N; i++) {         if (g[i].size() == 1) cnt++;       }       ans = (long double)s / (long double)cnt;     }     printf( %.12Lf n , 2 * ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<int> debt(n + 1, 0);     for (int i = 0; i < m; i++) {       int poor, rich, amt;       cin >> poor >> rich >> amt;       debt[poor] -= amt;       debt[rich] += amt;     }     int ans = 0;     for (int &it : debt) {       if (it < 0) {         ans += -it;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10, INF = 1e9;   double arr[maxn];   int main() {     int n;     double mina = 0, maxa = INF;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       mina = max(mina, arr[i] * 10 / (i + 1));       maxa = min(maxa, (arr[i] + 1) * (10) / (i + 1));     }     int k1, k2;     k1 = (mina) * (n + 1) / 10;     k2 = ceil((maxa) * (n + 1) - 1) / 10;     if (k1 != k2)       cout <<  not unique  << endl;     else {       cout <<  unique  << endl;       cout << k1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const int INF = 1e9;   vector<int> p[maxn];   bool vis[maxn];   int nmultiple[maxn], N, tag[maxn], a[maxn];   int gcd(int x, int y) { return x == 0 ? y : gcd(y % x, x); }   int main() {     for (int i = 2; i < maxn; ++i) {       if (!vis[i]) {         for (int j = i; j < maxn; j += i) {           vis[j] = 1;           p[j].push_back(i);         }       }     }     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d , &a[i]);       int x = 1;       for (int j : p[a[i]]) x *= j;       a[i] = x;       tag[a[i]] = 1;     }     if (tag[1]) {       printf( 1 n );       return 0;     }     int d = a[1];     for (int i = 1; i <= N; ++i) d = gcd(d, a[i]);     if (d > 1) {       printf( -1 n );       return 0;     }     for (int i = 1; i < maxn; ++i) {       for (int j = i; j < maxn; j += i) {         nmultiple[i] += tag[j];       }     }     int ans = INF;     for (int i = 1; i <= N; ++i) {       int v = a[i], sz = p[v].size(), up = (1 << sz) - 1;       vector<int> DP(up + 1, INF), mp(up + 1, 0);       vector<vector<int>> ways(up + 1, vector<int>(sz + 1));       for (int mask = 0; mask <= up; ++mask) {         int x = 1;         for (int j = 0; j < sz; ++j) {           if (mask >> j & 1) {             x *= p[v][j];           }         }         mp[mask] = x;         ways[mask][0] = nmultiple[x];       }       for (int j = 0; j < sz; ++j) {         for (int mask = 0; mask <= up; ++mask) {           int pmask = mask ^ (1 << j);           ways[pmask][j + 1] = ways[pmask][j];           if (mask >> j & 1) {             ways[pmask][j + 1] -= ways[mask][j];           }         }       }       DP[up] = 1;       for (int mask = up; mask >= 0; --mask) {         for (int pick = 0; pick <= up; ++pick) {           if (ways[pick][sz]) {             DP[mask & pick] = min(DP[mask & pick], DP[mask] + 1);           }         }       }       ans = min(ans, DP[0]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long f[203][203][2], g[203][203][2], A[203], B[203], C[203], SA[203],       SB[203], N, T, K;   int main() {     cin >> N >> T >> K;     for (int i = 1; i <= N; ++i) cin >> A[i] >> B[i] >> C[i];     ++N;     A[N] = C[N] = 1e15;     memset(f, 0x3f, sizeof(f));     memset(g, 0x3f, sizeof(g));     for (int i = 1; i <= N; ++i) {       SA[i] = SA[i - 1] + A[i];       SB[i] = SB[i - 1] + B[i];     }     memset(f[0], 0, sizeof(f[0]));     memset(g[0], 0, sizeof(g[0]));     for (int i = 1; i <= N; ++i)       for (int j = 0; j <= T; ++j)         for (int k = 0; k <= 1; ++k) {           if (k * A[i] + B[i] * j <= C[i] && f[i - 1][j][k] <= 1e15) {             f[i][j][k] = f[i - 1][j][k];             long long vl = (k * SA[i - 1] + j * SB[i - 1] + K - 1) / K;             if (vl * K <= k * SA[i] + j * SB[i]) g[i][j][k] = vl;           }           for (int l = 0; l < j; ++l) {             long long stp = g[i][l][k];             if (stp > 1e15) continue;             long long lft = SA[i] * k + SB[i] * l - stp * K,                       need = max((lft + (j - l) * B[i] - C[i] + K - 1) / K, 0ll);             if (need * K > lft) continue;             if (f[i - 1][j - l][0] > 1e15) continue;             f[i][j][k] = min(f[i][j][k], stp + need + f[i - 1][j - l][0]);             long long vl = ((j - l) * SB[i - 1] + K - 1) / K;             if (vl * K > lft - need * K + vl * SB[i]) continue;             g[i][j][k] = min(g[i][j][k], stp + need + vl);           }         }     cout << f[N][T][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100000];   void solve() {     int n;     cin >> n;     int prv = -1;     for (int i = 0; i < (n); i++) cin >> A[i];     int res = 1;     for (int i = 0; i < (n); i++) {       int x = A[i];       ;       ;       if (x == 0) {         if (prv == 0) {           cout <<  -1 n ;           return;         }       } else {         if (prv != 1) {           res++;         } else {           res += 5;         }       }       prv = x;     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10),         cin.tie(0), cout.tie(0);     ;     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, i, lim, cnt = 0, other = 0;     string str;     cin >> n >> str;     lim = str.size();     int petya = (n - 11) / 2;     for (i = 0; i < lim; i++) {       if (str[i] ==  8 )         cnt++;       else         other++;       if (cnt > petya) break;     }     if (cnt > petya && other <= petya)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a, b;     cin >> a >> b;     int ans = a;     while (a >= b) {       int t = a / b;       ans += t;       a = t + (a - b * t);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     if (s[a - 1] == s[b - 1])       cout << 0 <<   n ;     else {       cout << 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, a, b, x;     cin >> t;     while (t--) {       cin >> a >> b;       if (a == b) {         cout << 0 << endl;         continue;       }       if (a < b) {         x = (b / 10) - (a / 10);       } else {         x = (a / 10) - (b / 10);       }       if (a + x * 10 < b || b + x * 10 < a)         cout << x + 1 << endl;       else         cout << x << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 1007;   const int MAXS = 107;   const int MAXM = 13;   const int MAXL = 13;   const int BASE = 4;   const int MOD = 1e9 + 9;   int toid[128];   int n, m, kn, ml;   char s[MAXM][MAXL];   int nxt[MAXS][BASE], fail[MAXS], q[MAXS];   int ok[MAXS];   int tag[MAXS];   int dp[MAXN][MAXL][MAXS];   void init();   void input();   void work();   void trie_add(char s[]);   void buildac();   int main() {     init();     input();     work();   }   void init() {     ios::sync_with_stdio(false);     toid[ A ] = 0;     toid[ C ] = 1;     toid[ G ] = 2;     toid[ T ] = 3;   }   void input() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) scanf( %s , s[i]);   }   void work() {     kn = 1;     memset(nxt, -1, sizeof(nxt));     memset(tag, 0, sizeof(tag));     for (int i = 0; i < m; ++i)       trie_add(s[i]), ml = (((ml) > (strlen(s[i]))) ? (ml) : (strlen(s[i])));     buildac();     ++ml;     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     int v, nj, nl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < ml; ++j) {         for (int k = 0; k < kn; ++k) {           if (dp[i][j][k]) {             for (int nc = 0; nc < BASE; ++nc) {               v = nxt[k][nc];               nj = j + 1;               if (tag[v] || ok[v]) {                 if (tag[v])                   nl = tag[v];                 else                   nl = tag[ok[v]];                 if (nl >= nj) nj = 0;               }               dp[i + 1][nj][v] += dp[i][j][k];               dp[i + 1][nj][v] %= MOD;             }           }         }       }     }     int sum = 0;     for (int i = 0; i < kn; ++i) {       sum += dp[n][0][i];       sum %= MOD;     }     printf( %d n , sum);   }   void trie_add(char s[]) {     int len = strlen(s), now = 0, nc;     for (int i = 0; i < len; ++i) {       nc = toid[s[i]];       if (nxt[now][nc] ^ -1)         now = nxt[now][nc];       else         now = nxt[now][nc] = kn++;     }     tag[now] = len;   }   void buildac() {     int l = 0, r = 0, now, v, f;     q[r++] = 0;     fail[0] = 0;     while (l < r) {       now = q[l++];       for (int i = 0; i < BASE; ++i) {         if (nxt[now][i] ^ -1) {           v = nxt[now][i];           q[r++] = v;           f = fail[now];           while (f && nxt[f][i] == -1) f = fail[f];           fail[v] = (now && nxt[f][i] ^ -1) ? nxt[f][i] : 0;         } else           nxt[now][i] = (nxt[fail[now]][i] ^ -1) ? nxt[fail[now]][i] : 0;       }       f = fail[now];       while (f && !tag[f]) f = ok[f];       ok[now] = f;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k;     cin >> n >> m >> k;     long long int a[m];     for (int i = 0; i < m; i++) cin >> a[i];     long long int s = 0, S = 0;     for (int i = 0; i < m; i++) {       long long int d;       if ((a[i] - s) % k == 0)         d = (a[i] - s) / k - 1;       else         d = (a[i] - s) / k;       int z = i;       long long int K = s;       while (1) {         long long int D;         if ((a[z] - K) % k == 0)           D = (a[z] - K) / k - 1;         else           D = (a[z] - K) / k;         if (D != d) break;         s++;         z++;         if (z == m) break;       }       S++;       i = z - 1;     }     cout << S;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long mod = 998244353;   const long long sz = 2e5 + 9;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long BL[200002];   struct query {     long long l, r, idx;     bool operator<(const query &rhs) {       return (BL[l] == BL[rhs.l]) ? (r < rhs.r) : (BL[l] < BL[rhs.l]);     }   };   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void ruk_teri_maa_chodtha_hu() {     int n, m;     cin >> n;     vector<pair<long long, long long> > v(n);     for (long long i = 0; i < n; i++) {       cin >> m;       v[i] = {m, i};     }     long long prev = v[0].first, f = 0;     for (long long i = 1; i < n; i++) {       if (prev > v[i].first) {         f = 1;         break;       }       prev = v[i].first;     }     if (f == 0) {       cout << 0 <<   n ;       return;     }     sort(v.begin(), v.end());     long long ans = 0, c = 1;     for (long long i = 1; i < n; i++) {       if (v[i - 1].first <= v[i].first && v[i - 1].second < v[i].second)         c++;       else         c = 1;       ans = max(c, ans);     }     cout << n - ans <<   n ;   }   void solve() {     long long tc;     cin >> tc;     while (tc--) ruk_teri_maa_chodtha_hu();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     clock_t beg = clock();     solve();     clock_t end = clock();     fprintf(stderr,  %.3f sec, Copyright %c 2019 PyThor.  n ,             double(end - beg) / CLOCKS_PER_SEC, 184);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     const int MAX_N = (int)1e7;     vector<bool> isPrime(MAX_N, true);     isPrime[1] = false;     for (int i = 2; i < MAX_N; i++) {       if (isPrime[i]) {         for (int j = 2 * i; j < MAX_N; j += i) {           isPrime[j] = false;         }       }     }     int n, m;     cin >> n >> m;     long long sum = 0;     vector<set<int>> has(n + 10);     vector<int> u, v, w;     auto push = [&](int a, int b, int c) {       u.push_back(a);       v.push_back(b);       w.push_back(c);       has[a].insert(b);       has[b].insert(a);       m--;       sum += c;     };     push(1, n, 2);     for (int i = 1; i + 1 < n; i++) {       if (i + 1 == n - 1) {         int w = 2;         while (!isPrime[sum + w]) {           w++;         }         push(i, i + 1, w);         break;       }       push(i, i + 1, 2);     }     assert(isPrime[sum]);     cout << 2 <<     << sum <<   n ;     for (int i = 1; i <= n && m > 0; i++) {       for (int j = i + 1; j <= n && m > 0; j++) {         if (has[i].count(j)) {           continue;         }         const int MAX_VALUE = (int)1e8;         push(i, j, MAX_VALUE);       }     }     for (int i = 0; i < ((int)(u).size()); i++) {       cout << u[i] <<     << v[i] <<     << w[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   const int N = 1e2 + 9;   char s[N], t[N];   int dp[N][N], sz, n, k, par[N], pw[N];   pair<int, int> way[N][N];   int mod(long long x) {     while (x < 0) x += 1000000007;     return (x % 1000000007);   }   int get(int x, int y) {     if (x > y) return 0;     return mod(par[y] - mod(par[x - 1] * 1LL * pw[y - x + 1]));   }   int rec(int x, int y) {     if (x > sz) {       if (t[x - sz] ==  1  and y != sz) return 0;       if (t[x - sz] ==  0  and y == sz) return 0;     }     if (x > n) return 1;     int& ret = dp[x][y];     if (~ret) return ret;     ret = 0;     for (int i = 0; i < k; i++) {       int len = 0;       for (int j = min(y + 1, sz); j >= 1; j--)         if (mod(get(y - j + 2, y) * 27LL + i + 1) == par[j]) {           len = j;           break;         }       if (rec(x + 1, len)) {         way[x][y] = make_pair(i, len);         return ret = 1;       }     }     return 0;   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     sz = strlen(s + 1);     pw[0] = 1;     for (int i = 1; i <= sz; i++) {       par[i] = mod(par[i - 1] * 27LL + (s[i] -  a  + 1));       pw[i] = mod(pw[i - 1] * 27LL);     }     scanf( %s , t + 1);     if (!rec(1, 0)) return 0 * puts( No solution );     int now = 0;     for (int i = 1; i <= n; i++) {       printf( %c , char(way[i][now].first + 97));       now = way[i][now].second;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long kkk, kk, otv = 0;     string ss;     long long i, a;     cin >> a;     for (i = 0; i < a; i++) {       long long s1, s2, s3;       cin >> s1 >> s2 >> s3;       if ((s1 > s2 + s3 + 1) || (s2 > s1 + s3 + 1) || (s3 > s1 + s2 + 1))         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i;     while (scanf( %lld%lld , &n, &k) != EOF) {       long long a[k + 1];       vector<pair<long long, long long> > v;       for (i = 0; i < k; i++) {         cin >> a[i], v.push_back(make_pair((n % a[i]), i + 1));       }       sort(v.rbegin(), v.rend());       int j = v[k - 1].second;       cout << j <<     << (n / a[j - 1]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   const int maxn = 510;   const int inf32 = 1e9 + 10;   const long long inf64 = 1e18 + 10;   const int mod = 998244353;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int N;     cin >> N;     vector<long long> a(N), b(N);     for (int i = 0; i < N; ++i) cin >> a[i];     sort(a.begin(), a.end());     for (int i = 0; i < N; ++i) b[i] = a[N - 1] - a[i];     vector<vector<long long>> dp(65, vector<long long>(N + 1, inf64));     vector<vector<int>> sum(N + 1, vector<int>(2));     dp[0][0] = 0;     for (int i = 1; i <= 63; ++i) {       int current_bit = i - 1;       vector<int> p(N);       for (int j = 0; j < N; ++j) p[j] = j;       sort(p.begin(), p.end(), [&](int& l, int& r) {         return b[l] % (1ll << current_bit) < b[r] % (1ll << current_bit);       });       for (int j = 0; j <= N; ++j) {         for (int k = 0; k < 2; ++k) {           sum[j][k] = 0;         }       }       for (int j = 1; j <= N; ++j) {         ++sum[j][b[p[j - 1]] >> current_bit & 1];       }       for (int j = 1; j <= N; ++j) {         for (int k = 0; k < 2; ++k) {           sum[j][k] += sum[j - 1][k];         }       }       for (int j = 0; j <= N; ++j) {         int new_carry = sum[N][1] - sum[N - j][1];         int cost = sum[N - j][1] + sum[N][0] - sum[N - j][0];         dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);         new_carry =             sum[N][1] - sum[N - j][1] + sum[N][0] - sum[N - j][0] + sum[N - j][1];         cost = sum[N - j][0] + sum[N][1] - sum[N - j][1];         dp[i][new_carry] = min(dp[i][new_carry], dp[i - 1][j] + cost);       }     }     cout << dp[63][0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   bool bad[(1 << 20) + 10];   int belong[maxn], frequent[21];   int main() {     int n, m, d;     scanf( %d%d%d , &n, &m, &d);     for (int i = 0; i < m; i++) {       int s, x;       scanf( %d , &s);       while (s--) {         scanf( %d , &x);         belong[x] = i;       }     }     for (int i = 1; i <= n; i++) {       if (i > d) frequent[belong[i - d]]--;       frequent[belong[i]]++;       if (i >= d) {         int mask = 0;         for (int j = 0; j < m; j++) {           if (!frequent[j]) {             mask |= (1 << j);           }         }         bad[mask] = 1;       }     }     int ans = m + 1;     for (int i = (1 << m) - 1; i >= 0; i--) {       if (bad[i]) {         for (int j = 0; j < m; j++) {           if (i & (1 << j)) bad[i ^ (1 << j)] = 1;         }       } else         ans = min(ans, __builtin_popcount(i));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string a;       cin >> a;       int ans = 0;       vector<int> vc;       for (size_t i = 0; i < a.size(); i++) {         if (a[i] ==  w  && a[i - 1] ==  t  && a[i + 1] ==  o  &&             a[i + 2] ==  o  && i > 0 && i < a.size() - 2) {           ans++;           vc.push_back(i + ans);           a.erase(a.begin() + i);         } else if (a[i] ==  o  && a[i - 1] ==  w  && a[i - 2] ==  t  && i > 1) {           ans++;           vc.push_back(i + ans);           a.erase(a.begin() + i);         } else if (a[i] ==  n  && a[i - 1] ==  o  && a[i + 1] ==  e  &&                    i < a.size() - 1 && i) {           ans++;           vc.push_back(i + ans);           a.erase(a.begin() + i);         }       }       cout << ans << endl;       for (auto i : vc) {         cout << i <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct SD {     int x, y, c;   } p, pp;   int f[50000], bk[110][110];   int n, m, k, maxx, ans, cur, sum, x, y;   int minn;   int nex[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};   char mapp[1100][1100];   queue<struct SD> q;   int bfs(int x, int y) {     while (q.size()) q.pop();     p.x = x, p.y = y, p.c = 0;     q.push(p);     ans = 1;     memset(bk, 0, sizeof(bk));     ;     bk[x][y] = 1;     while (q.size()) {       p = q.front();       q.pop();       if (p.c > 1) return ans < sum;       for (int i = p.x; i < n; i++) {         if (mapp[i][p.y] ==  B ) {           if (bk[i][p.y]) continue;           pp.x = i, pp.y = p.y, pp.c = p.c + 1;           bk[pp.x][pp.y] = 1;           ans++;           q.push(pp);         } else           break;       }       for (int i = p.x; i >= 0; i--) {         if (mapp[i][p.y] ==  B ) {           if (bk[i][p.y]) continue;           ans++;           pp.x = i, pp.y = p.y, pp.c = p.c + 1;           bk[pp.x][pp.y] = 1;           q.push(pp);         } else           break;       }       for (int i = p.y; i < m; i++) {         if (mapp[p.x][i] ==  B ) {           if (bk[p.x][i]) continue;           pp.x = p.x, pp.y = i, pp.c = p.c + 1;           ans++;           bk[pp.x][pp.y] = 1;           q.push(pp);         } else           break;       }       for (int i = p.y; i >= 0; i--) {         if (mapp[p.x][i] ==  B ) {           if (bk[p.x][i]) continue;           pp.x = p.x, pp.y = i, pp.c = p.c + 1;           ans++;           bk[pp.x][pp.y] = 1;           q.push(pp);         } else           break;       }     }     return ans < sum;   }   int main() {     while (cin >> n >> m) {       cur = sum = 0;       for (int i = 0; i < n; i++) scanf( %s , mapp[i]);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (mapp[i][j] ==  B ) {             sum++;           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (mapp[i][j] ==  B ) {             if (bfs(i, j)) {               cur = 1;               break;             }           }         }         if (cur) break;       }       if (cur)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       string s;       cin >> s;       for (int i = 0; i < n; i++) {         if (s[i] !=  ? ) {           int j = i - 1;           while (j >= 0 && s[j] ==  ? ) {             if (s[j + 1] ==  R ) {               s[j] =  B ;             } else {               s[j] =  R ;             }             j--;           }         }       }       reverse((s).begin(), (s).end());       for (int i = 0; i < n; i++) {         if (s[i] !=  ? ) {           int j = i - 1;           while (j >= 0 && s[j] ==  ? ) {             if (s[j + 1] ==  R ) {               s[j] =  B ;             } else {               s[j] =  R ;             }             j--;           }         }       }       reverse((s).begin(), (s).end());       if (s[0] ==  ? ) {         for (int i = 0; i < n; i++) {           if (i % 2) {             s[i] =  R ;           } else {             s[i] =  B ;           }         }       }       cout << s <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long n, long long p) { return power(n, p - 2, p); }   long long nCrMODp(long long n, long long r, long long p) {     if (n < r) return 0;     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   void divisors(int n) {     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cout <<     << i;         else           cout <<     << i <<     << n / i;       }     }   }   void primeFactors(int n) {     while (n % 2 == 0) {       cout << 2 <<    ;       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         cout << i <<    ;         n = n / i;       }     }     if (n > 2) cout << n <<    ;   }   void solve() {     int t;     cin >> t;     cin.ignore();     while (t--) {       int i, x = 0, y = 0;       string str;       cin >> str;       for (i = 0; i < str.size(); i++) str[i] ==  B  ? x++ : y++;       y == x ? cout <<  YES n  : cout <<  NO n ;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     auto start1 = high_resolution_clock::now();     solve();     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, cnt = 0;       cin >> n;       string s[n];       long long int h1[10] = {}, h2[10] = {};       for (int i = 0; i < n; i++) {         cin >> s[i];         h1[s[i][3] -  0 ]++;       }       for (int i = 0; i < n - 1; i++) {         for (int j = i + 1; j < n; j++) {           if (s[i].compare(s[j]) == 0) {             int k;             cnt++;             for (k = 0; k < 10; k++) {               if (h1[k] == 0) {                 break;               }             }             h1[s[i][3] -  0 ]--;             h1[k]++;             s[i][3] = k +  0 ;           }         }       }       cout << cnt << endl;       for (int i = 0; i < n; i++) {         cout << s[i] << endl;       }     }     return 0;   }


#include<cstdio>   #include<iostream>   #include<cmath>   #include<cstring>   #include<vector>   #include<algorithm>   #define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)   #define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)   #define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])   #define Li inline   #define R register int   #define ls(x) ch[x][0]   #define rs(x) ch[x][1]   #define mpi(x,y) make_pair(x,y)   #define pi pair<int,int>   //#define int ll    using namespace std;   typedef long long ll;   template<typename T>   void read(T &x){    x=0;char ch=getchar();bool f=0;    while(ch< 0 ||ch> 9 ){     if(ch== - )f=1;     ch=getchar();    }    while(ch>= 0 &&ch<= 9 )x=(x<<1)+(x<<3)+ch- 0 ,ch=getchar();    x=f?-x:x;   }      const int N=3005;   const int inf=1e9+7;   int n,m;   int dp[N][N];   int a[N];      signed main(){    int T;read(T);while(T--){     read(n);fs(i,1,n)read(a[i]);     fs(i,2,n){      int cnt=0;      fs(j,2,n)dp[i][j]=inf;      fn(j,i-1,1){       if(j+a[j]<i)continue;       dp[i][j+a[j]]=min(dp[i][j+a[j]],dp[j][i-1]+cnt);++cnt;      }      fs(j,i+1,n)dp[i][j]=min(dp[i][j],dp[i][j-1]);     }     printf( %d n ,dp[n][n]);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6e4;   long long vis[N];   long long ans[N];   vector<long long> adj[N];   void dfs(long long i, long long pa) {     if (vis[i] == 1)       return;     else {       vis[i] = 1;       ans[i] = pa;       for (vector<long long>::iterator itr = adj[i].begin(); itr != adj[i].end();            itr++) {         if (vis[*itr] != 1) dfs(*itr, i);       }     }   }   int main() {     long long n, r1, r2;     cin >> n >> r1 >> r2;     long long arr[n + 1];     adj[0].push_back(9999);     for (long long i = 1; i <= n; i++) {       long long x;       if (i == r1) {         arr[i] = -1;       } else {         cin >> x;         arr[i] = x;         adj[i].push_back(x);         adj[x].push_back(i);       }     }     dfs(r2, -1);     ans[r2] = -1;     for (long long j = 1; j <= n; j++) {       if (ans[j] != -1) cout << ans[j] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int a, b, id;   } p[100005];   bool mark[100005];   bool cmp1(const Node &p1, const Node &p2) {     if (p1.b != p2.b)       return p1.b > p2.b;     else       return p1.a < p2.a;   }   bool cmp2(const Node &p1, const Node &p2) {     if (p1.a != p2.a)       return p1.a > p2.a;     else       return p1.b > p2.b;   }   int main() {     int n, p1, k;     cin >> n >> p1 >> k;     for (int i = 0; i < n; i++) {       scanf( %d%d , &p[i].a, &p[i].b);       p[i].id = i + 1;     }     sort(p, p + n, cmp1);     sort(p, p + n - p1 + k, cmp2);     for (int i = 0; i < k; i++) mark[p[i].id] = true;     sort(p, p + n - p1 + k, cmp1);     p1 -= k;     for (int i = 0; i < n; i++) {       if (k && mark[p[i].id])         --k;       else if (!k && p1) {         mark[p[i].id] = true;         --p1;       }     }     for (int i = 1; i <= n; i++)       if (mark[i]) printf( %d  , i);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const long long inf = 9223372036854775807;   const long long mod = 1000000007;   const double pi = acos(-1);   long long n = 0;   long long m = 0;   long long k = 0;   long long check(long long value) {     long long ans = 0;     for (int i = 1; i < n + 1; i++) {       ans += min((value) / i, m);     }     return ans;   }   bool ifExist(long long val) {     for (int i = 1; i < n + 1; i++) {       if (val % i == 0 && val / i >= 1 && val / i <= m) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     cin >> n >> m >> k;     long long l = 1, r = n * m;     long long mid = 1;     while (l < r) {       mid = (r + l) / 2;       long long val = check(mid);       if (val >= k) {         r = mid;       } else {         l = mid + 1;       }     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int expo(long long int base, long long int exponent,                      long long int mod) {     long long int ans = 1;     while (exponent != 0) {       if (exponent & 1) ans = (1LL * ans * base) % mod;       base = (1LL * base * base) % mod;       exponent >>= 1;     }     return ans % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int x, n;       cin >> x >> n;       long long int sx = sqrt(x) + 10;       map<long long int, long long int> ma;       for (long long int i = 2; i <= sx; i++) {         while (x % i == 0) {           x = x / i;           ma[i]++;         }       }       if (x != 1) ma[x]++;       vector<long long int> v;       for (auto i : ma) v.push_back(i.first);       long long int ans = 1;       for (auto i : v) {         long long int p = i;         long long int e = 0;         long long int nn = n;         for (long long int j = 1; true; j++) {           e += nn / p;           e = e % (1000000007 - 1);           nn = nn / p;           if (nn == 0) break;         }         long long int tmp = expo(i, e % (1000000007 - 1), 1000000007);         ans = (ans * tmp) % 1000000007;       }       cout << ans;     }     return 0;   }


// Problem: C. Minimum Ties   // Contest: Codeforces - Educational Codeforces Round 104 (Rated for Div. 2)   // URL: https://codeforces.com/contest/1487/problem/C   // Memory Limit: 256 MB   // Time Limit: 1000 ms   //    // Powered by CP Editor (https://cpeditor.org)      //Weakness disgust me   #include bits/stdc++.h                      #define fill(a)  memset(a, 0, sizeof (a))   #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);   #define rep(i,n) for(int i=0;i<n;i++)   typedef long long ll;   #define int ll   const ll MOD = 1e9 + 7;   using namespace std;   void solve()   {      ll n;    cin>>n;    ll res[n][n];    memset(res,0,sizeof(res));        for(int i=1;i<=((n-1)/2);i++)    {     for(int j=0;j<n;j++)     {      res[(j+i)%n][j]=-1;      res[j][(j+i)%n]=1;     }    }        for(int i=0;i<n;i++)    {     for(int j=i+1;j<n;j++)     {      cout<<res[i][j]<<   ;     }         }           }   signed main()   {        fast;       int t=1;       cin>>t;       while( t-- )       {             solve();           cout<<  n ;       }         }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double err = 1e-12;   const double PI = 3.141592653589793;   const int N = 2e5 + 5;   int n;   vector<int> V;   bool chk(int val) {     auto it = upper_bound((V).begin(), (V).end(), val);     for (; it != V.end(); it++) {       int aj = *it, ai = *it + val;       while (ai <= V.back()) {         auto tmp = lower_bound((V).begin(), (V).end(), ai);         if (tmp != V.end() && (*tmp) % aj >= val) return true;         ai += aj;       }     }     return false;   }   void solve() {     cin >> n;     V = vector<int>(n);     for (int i = 0; i < n; i++) cin >> V[i];     sort((V).begin(), (V).end());     V.erase(unique((V).begin(), (V).end()), V.end());     int l = 1, r = 1e6, ans = 0;     while (l <= r) {       int m = (l + r) / 2;       if (chk(m)) {         ans = m;         l = m + 1;       } else         r = m - 1;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     scanf( %d%d , &n, &m);     long long dp[m + 2];     int now = 0;     int c, sum = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &c);       sum += c;       dp[i] = sum;     }     dp[0] = -2147483647;     long long ans = -2147483647;     long long mm[m + 2];     for (int i = m - 1; i >= 0; i--) {       if (i == m - 1)         mm[i] = dp[i];       else         mm[i] = max(dp[i], mm[i + 1]);     }     for (int i = 1; i < n; i++) {       sum = 0;       now = 1 - now;       for (int j = 0; j < m; j++) {         scanf( %d , &c);         sum += c;         dp[j] = sum;       }       for (int j = 0; j < m; j++) {         if (i % 2 == 1) {           if (j < m - 1) {             dp[j] += mm[j + 1];           } else if (j == m - 1) {             dp[j] = -2147483647;           }         } else {           if (j == 0)             dp[j] = -2147483647;           else {             dp[j] += mm[j - 1];           }         }         if (i == n - 1) {           ans = max(ans, dp[j]);         }       }       if (i % 2 == 0) {         for (int j = m - 1; j >= 0; j--) {           if (j == m - 1)             mm[j] = dp[j];           else             mm[j] = max(dp[j], mm[j + 1]);         }       } else {         for (int j = 0; j < m; j++) {           if (j == 0)             mm[j] = dp[j];           else             mm[j] = max(dp[j], mm[j - 1]);         }       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (auto &first : v) cin >> first;     int z = 0;     for (auto first : v)       if (first == 0) z++;     if (z <= 1) {       cout <<  0 n ;       return;     }     vector<pair<int, int> > cnt(n, make_pair(0, 0));     int u = 0;     for (int i = 0; i < n; ++i) {       if (v[i] == 0)         u++;       else {         cnt[v[i] - 1].first = max(cnt[v[i] - 1].first, min(u, z / 2));       }       if (u > z - z / 2) {         break;       }     }     u = 0;     for (int i = 0; i < n; ++i) {       if (v[n - i - 1] == 0)         u++;       else {         cnt[v[n - i - 1] - 1].second =             max(cnt[v[n - i - 1] - 1].second, min(u, z / 2));       }       if (u > z - z / 2) {         break;       }     }     sort(cnt.begin(), cnt.end(), greater<pair<int, int> >());     int ans = 0;     multiset<int> rb;     int ptr = 0;     for (int i = z / 2; i > 0; i--) {       while (ptr < cnt.size() && cnt[ptr].first == i) {         rb.insert(cnt[ptr].second);         ptr++;       }       if (rb.size()) {         rb.erase(rb.begin());         ans++;       }     }     while (ptr < cnt.size()) {       rb.insert(cnt[ptr].second);       ptr++;     }     for (int i = 1; i <= z / 2; ++i) {       while (rb.size()) {         auto it = rb.begin();         auto val = (*it);         if (val < i)           rb.erase(it);         else           break;       }       if (rb.size()) {         rb.erase(rb.begin());         ans++;       }     }     cout << min(ans, z / 2) <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; ++i) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int x;     x = n % 4;     if (n == 0)       cout <<  1 ;     else if (x == 0)       cout <<  6 ;     else if (x == 1)       cout <<  8 ;     else if (x == 2)       cout <<  4 ;     else if (x == 3)       cout <<  2 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> grav[2050];   int n;   int m, k;   int mark[2050];   bool bad[2050];   int sz[2050];   void dfs(int v, int color) {     mark[v] = color;     for (int i = 0; i < (int)grav[v].size(); i++) {       int u = grav[v][i];       if (mark[u] == 0) dfs(u, color);     }   }   int main() {     int u, v;     cin >> n;     cin >> m;     for (int i = 0; i < (int)(m); i++) {       cin >> u >> v;       --u;       --v;       grav[u].push_back(v);       grav[v].push_back(u);     }     int color = 1;     for (int i = 0; i < (int)(n); i++) {       if (mark[i] == 0) dfs(i, color++);       sz[mark[i]]++;     }     cin >> k;     for (int i = 0; i < (int)(k); i++) {       cin >> u >> v;       --u;       --v;       if (mark[u] == mark[v]) bad[mark[u]] = true;     }     int mx = 0;     for (int c = 1; c < color; ++c) {       if (!bad[c] && (mx == 0 || sz[c] > sz[mx])) mx = c;     }     cout << sz[mx] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int arr[200005];   int count1[200005];   int count2[200005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     long long sum1 = 0;     long long sum2 = 0;     int cnt1 = 0;     int cnt2 = 0;     int j = 0;     for (int i = n - 1; i >= 0; i--) {       if (arr[i] == 0) {         cnt1++;       }       count1[i] = cnt1;     }     for (int i = 0; i < n; i++) {       if (arr[i] == 1) {         cnt2++;       }       count2[i] = cnt2;     }     for (int i = 0; i < n; i++) {       if (arr[i] == 1) sum2 += count1[i];     }     for (int i = 0; i < n; i++) {       if (arr[i] == 0) sum1 += count2[i];     }     if (sum1 >= sum2)       cout << sum2 << endl;     else       cout << sum1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000 * 2000 + 1;   int n, m, mark[N], mx, rep;   string s;   vector<int> adj[N];   bool circle(int v) {     mark[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (mark[u] == 1 || (!mark[u] && circle(u))) return true;     }     mark[v] = 2;     return false;   }   int dfs(int v) {     int res = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i], t = dfs(u);       res = max(res, t + 1);       if (t > mx)         mx = t, rep = false;       else if (t == mx)         rep = true;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       string t;       cin >> t;       s += t;     }     n *= m;     for (int i = 0; i < n; i++)       if (s[i] ==  ^ )         adj[i - m].push_back(i);       else if (s[i] ==  < )         adj[i - 1].push_back(i);       else if (s[i] ==  > )         adj[i + 1].push_back(i);       else if (s[i] ==  v )         adj[i + m].push_back(i);     for (int i = 0; i < n; i++)       if (circle(i)) {         cout << -1 <<   n ;         return 0;       }     fill(mark, mark + n, 0);     for (int i = 0; i < n; i++)       if (s[i] ==  # ) dfs(i);     cout << max(0, 2 * mx - !rep) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int a[maxn];   int n, m, ma, mi;   int sum[2000005], ans[2000005];   bool ok(int mid) {     int ans = 0, i;     for (i = mid; i <= ma; i += mid) {       ans += sum[i + m] - sum[i - 1];     }     if (ans == n) return true;     return false;   }   int main() {     int i, j;     scanf( %d %d , &n, &m);     ma = 1, mi = 1000006;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       mi = min(mi, a[i]);       ma = max(ma, a[i]);       sum[a[i]]++;     }     if (m >= mi) {       printf( %d n , mi);       return 0;     }     for (i = 1; i <= ma + m; i++) {       sum[i] += sum[i - 1];     }     for (i = mi; i > m; i--) {       if (ok(i)) break;     }     printf( %d n , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> arr(4 * n, 0);       for (int i = 0; i < 4 * n; i++) {         cin >> arr[i];       }       sort(arr.begin(), arr.end());       int f = 1, i = 0, j = 4 * n - 1, area = arr[i] * arr[j];       while (i < j) {         if ((arr[i + 1] != arr[i]) || (arr[j - 1] != arr[j]) ||             (arr[i] * arr[j] != area)) {           f = 0;           break;         }         i += 2;         j -= 2;       }       if (f) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


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


#pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #include<iostream>   #include<string>   #include<cstdio>   #include<vector>   #include<cmath>   #include<algorithm>   #include<functional>   #include<iomanip>   #include<queue>   #include<ciso646>   #include<random>   #include<map>   #include<set>   #include<bitset>   #include<stack>   #include<unordered_map>   #include<unordered_set>   #include<utility>   #include<cassert>   #include<complex>   #include<numeric>   #include<array>   using namespace std;      //#define int long long   typedef long long ll;      typedef unsigned long long ul;   typedef unsigned int ui;   constexpr ll mod = 10007;   const ll INF = mod * mod;   typedef pair<int, int>P;   #define stop char nyaa;cin>>nyaa;   #define rep(i,n) for(int i=0;i<n;i++)   #define per(i,n) for(int i=n-1;i>=0;i--)   #define Rep(i,sta,n) for(int i=sta;i<n;i++)   #define rep1(i,n) for(int i=1;i<=n;i++)   #define per1(i,n) for(int i=n;i>=1;i--)   #define Rep1(i,sta,n) for(int i=sta;i<=n;i++)   #define all(v) (v).begin(),(v).end()   typedef pair<ll, ll> LP;   typedef long double ld;   typedef pair<ld, ld> LDP;   const ld eps = 1e-12;   const ld pi = acosl(-1.0);      ll mod_pow(ll x, ll n, ll m = mod) {    if (n < 0) {     ll res = mod_pow(x, -n, m);     return mod_pow(res, m - 2, m);    }    if (abs(x) >= m)x %= m;    if (x < 0)x += m;    ll res = 1;    while (n) {     if (n & 1)res = res * x % m;     x = x * x % m; n >>= 1;    }    return res;   }   struct modint {    ll n;    modint() :n(0) { ; }    modint(ll m) :n(m) {     if (n >= mod)n %= mod;     else if (n < 0)n = (n % mod + mod) % mod;    }    operator int() { return n; }   };   bool operator==(modint a, modint b) { return a.n == b.n; }   modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }   modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }   modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }   modint operator+(modint a, modint b) { return a += b; }   modint operator-(modint a, modint b) { return a -= b; }   modint operator*(modint a, modint b) { return a *= b; }   modint operator^(modint a, ll n) {    if (n == 0)return modint(1);    modint res = (a * a) ^ (n / 2);    if (n % 2)res = res * a;    return res;   }      ll inv(ll a, ll p) {    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);   }   modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }   modint operator/=(modint& a, modint b) { a = a / b; return a; }   const int max_n = 1 << 1;   modint fact[max_n], factinv[max_n];   void init_f() {    fact[0] = modint(1);    for (int i = 0; i < max_n - 1; i++) {     fact[i + 1] = fact[i] * modint(i + 1);    }    factinv[max_n - 1] = modint(1) / fact[max_n - 1];    for (int i = max_n - 2; i >= 0; i--) {     factinv[i] = factinv[i + 1] * modint(i + 1);    }   }   modint comb(int a, int b) {    if (a < 0 || b < 0 || a < b)return 0;    return fact[a] * factinv[b] * factinv[a - b];   }   modint combP(int a, int b) {    if (a < 0 || b < 0 || a < b)return 0;    return fact[a] * factinv[a - b];   }      void solve() {    int n, m, x; cin >> n >> m >> x;    vector<int> h(n); rep(i, n)cin >> h[i];    vector<int> sum(m);    priority_queue<P, vector<P>, greater<P>> q;    rep(i, m)q.push({ 0,i });    vector<int> ans(n);    rep(i, n) {     P p = q.top(); q.pop();     int id = p.second;     ans[i] = id;     sum[id] += h[i];     q.push({ sum[id],id });    }    cout <<  YES n ;    rep(i, n) {     if (i > 0)cout <<    ;     cout << ans[i] + 1;    }    cout <<   n ;   }         signed main() {    ios::sync_with_stdio(false);    cin.tie(0);    //cout << fixed << setprecision(10);    //init_f();    //init();    //expr();    int t; cin >> t; rep(i, t)     solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, dd, q;     cin >> n >> dd >> q;     int arr[200001];     for (int i = 0; i < 200001; i++) {       arr[i] = 0;     }     for (int h = 0; h < n; h++) {       int t1, t2;       cin >> t1 >> t2;       arr[t1]++;       arr[t2 + 1]--;     }     int count = 0;     for (int k = 0; k < 200001; k++) {       count += arr[k];       arr[k] = count;     }     count = 0;     int ans[200001];     for (int k = 0; k <= 200000; k++) {       if (arr[k] >= dd) {         count++;       }       ans[k] = count;     }     for (int kk = 0; kk < q; kk++) {       int r1, r2;       cin >> r1 >> r2;       cout << ans[r2] - ans[r1 - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {       int t;       cin >> t;       while(t--){           int n;           cin >> n;           vector<int> arr(n,0);           for(int i = 0; i < n; i++){               cin >> arr[i];           }           vector<int> str;           str.push_back(arr[0]);           cout << str[0] << endl;           for(int i = 1; i < n; i++){               vector<int> temp;               if(arr[i] == 1){                   for(int i = 0; i < str.size(); i++){                       temp.push_back(str[i]);                   }                   // temp = str;                   temp.push_back(1);               }               else{                   for(int j = str.size() - 1; j >= 0; j--){                       if(str[j] == arr[i] - 1){                           for(int k = 0; k < j; k++){                               temp.push_back(str[k]);                           }                           temp.push_back(arr[i]);                           break;                       }                   }               }               str = {};               for(int i = 0; i < temp.size(); i++){                   str.push_back(temp[i]);               }               for(int i = 0; i < str.size(); i++){                   cout << str[i];                   if(i != str.size() - 1)                       cout <<  . ;               }               cout << endl;           }       }   }