#include <bits/stdc++.h>   using namespace std;   class UnionFind {    private:    public:     vector<int> p, rank, setSize, minn;     int numSets;     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       minn.resize(N);       for (int i = 0; i < N; i++) {         p[i] = i;         minn[i] = i;       }     }     int findSet(int i) {       if (p[i] == i)         return i;       else {         p[i] = findSet(p[i]);         minn[p[i]] = min(minn[p[i]], i);         return p[i];       }     }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];           minn[x] = min(minn[x], minn[y]);         } else {           p[x] = y;           setSize[y] += setSize[x];           minn[y] = min(minn[x], minn[y]);           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   class fenwick_tree {     vector<long> t;     long size;       public:     fenwick_tree(long n) {       t.assign(n + 1, 0);       size = n + 1;     }     long LSOne(long k) { return k & (-k); }     void update(long index, long val) {       for (; index < size; index += LSOne(index)) t[index] += val;     }     long query_full(long a, long b) {       return query(b) - ((a <= 1) ? 0 : query(a - 1));     }     long query(long b) {       if (b < 1) return 0;       long sum = 0;       for (; b; b -= LSOne(b)) sum += t[b];       return sum;     }   };   long long gcd(long long a, long long b) {     while (b != 0) {       long long t = b;       b = a % b;       a = t;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long w, h, i, j, k, ans, c, s;     cin >> w >> h;     ans = 0;     for (i = 1; i < w; i++) {       c = min(i, w - i);       s = 0;       for (j = 0; j < h; j++) s += (h - j) / 2;       ans += c * s;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-10;   const double PI = 3.1415926535897932384626433832795;   const int CLK = CLOCKS_PER_SEC;   int calc(int s, int f, int t, int m) {     if (s == f) return 0;     s--;     f--;     t %= (2 * (m - 1));     int tos;     int stof;     bool up = (t < m - 1);     int pos = (t < m - 1) ? t : (2 * m - 2) - t;     if (up) {       if (s >= pos) {         tos = s - pos;       } else {         tos = (2 * m - 2) - pos - s;         up = false;       }     } else {       if (s <= pos) {         tos = pos - s;       } else {         tos = pos + s;         up = true;       }     }     pos = s;     if (up) {       if (f >= pos) {         stof = f - pos;       } else {         stof = (2 * m - 2) - pos - f;       }     } else {       if (f <= pos) {         stof = pos - f;       } else {         stof = pos + f;       }     }     return tos + stof;   }   int main() {     int n, m;     int s, f, t;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s >> f >> t;       cout << calc(s, f, t, m) + t << endl;     }     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   const int MAXN = 1e3 + 10;   const int mod = 1e9 + 7;   const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   const int seed = 131;   int cases = 0;   char str[MAXN];   int mp[MAXN], col[MAXN], cnt[30], vis[MAXN], need[MAXN], ans[MAXN];   std::vector<int> primes, fac[MAXN], f[MAXN];   std::priority_queue<std::pair<int, int> > num;   std::vector<std::pair<int, int> > number_of_need;   void init() {     for (int i = 2; i < MAXN; i++)       if (!vis[i])         for (int j = i; j < MAXN; j += i) {           fac[j].push_back(i);           if (j != i) vis[j] = 1;         }     for (int i = 2; i < MAXN; i++)       if (!vis[i]) primes.push_back(i);   }   int find(int n) { return col[n] = n == col[n] ? n : find(col[n]); }   int main() {     init();     scanf( %s , str);     int len = strlen(str);     for (int i = 0; i < len; i++) cnt[str[i] -  a ]++;     for (int i = 0; i < 26; i++)       if (cnt[i]) num.push({cnt[i], i});     for (int i = 2; i <= len; i++) {       if ((int)fac[i].size() == 1)         col[i] = i;       else {         int v = find(fac[i][0]);         for (int j = 1; j < (int)fac[i].size(); j++) col[fac[i][j]] = v;       }     }     for (int pri : primes) {       if (pri > len) break;       find(pri);     }     for (int i = 2; i <= len; i++) f[col[fac[i][0]]].push_back(i);     for (int i = 2; i <= len; i++)       if (!f[i].empty()) {         if (num.empty() || num.top().first < (int)f[i].size()) {           puts( NO );           return 0;         }         std::pair<int, int> u = num.top();         num.pop();         for (int j : f[i]) str[j] = char(u.second +  a );         if (u.first - (int)f[i].size() > 0)           num.push({u.first - (int)f[i].size(), u.second});       }     if (num.empty()) {       puts( NO );       return 0;     }     str[1] = char(num.top().second +  a );     puts( YES );     printf( %s n , str + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long mod = 1000000007;   const int MX = 0x3f3f3f3f;   bool G[8][8];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     if (n <= 6) {       cout << m << endl;       return 0;     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       G[u][v] = G[v][u] = true;     }     int mini = INT_MAX;     for (int i = 1; i <= 7; i++) {       for (int j = 1; j <= 7; j++) {         if (j == i) continue;         int cur = 0;         for (int k = 1; k <= 7; k++) cur += G[i][k] & G[j][k];         mini = min(mini, cur);       }     }     cout << m - mini <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int mod = 1e9 + 7;   int a, b, c, d, n, m, x, y, z;   vector<int> v;   int arr[3];   int main() {     cin >> a >> b >> c;     for (int i = 0; i <= a; i++) {       x = c - i;       y = b - (a - i);       if (x >= 0 && y >= 0 && x == y) {         cout << a - i <<     << x <<     << i << endl;         return 0;       }     }     cout <<  Impossible  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100001];   int main() {     int n, mini, temp;     cin >> n;     cin >> mini;     int minindex = 0, maxindex = 0, flag = 1;     for (int i = 1; i < n; i++) {       cin >> temp;       if (mini == temp) {         maxindex = i;         a[flag] = i;         flag++;       }       if (temp < mini) {         mini = temp;         minindex = i;         maxindex = i;         flag = 0;         a[flag] = i;         flag++;       }     }     sort(a, a + flag);     for (int i = 0; i < flag - 1; i++) a[i] = a[i + 1] - a[i];     temp = a[0];     for (int i = 1; i < flag - 1; i++) {       if (temp > a[i]) temp = a[i];     }     cout << temp;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mod = 1e9 + 7;   const char nl =   n ;   const int N = int(2e5) + 99;   const int INF = int(1e9) + 99;   long long add(long long x, long long y) {     x += y;     if (x >= mod) return x - mod;     return x;   }   long long sub(long long x, long long y) {     x -= y;     if (x < 0) return x + mod;     return x;   }   long long mult(long long x, long long y) { return (x * y) % mod; }   long long bin_pow(long long x, long long p) {     if (p == 0) return 1;     if (p & 1) return mult(x, bin_pow(x, p - 1));     return bin_pow(mult(x, x), p / 2);   }   long long rev(long long x) { return bin_pow(x, mod - 2); }   long long gcd(long long x, long long y) { return (y == 0 ? x : gcd(y, x % y)); }   long long lcm(long long x, long long y) { return (x / gcd(x, y)) * y; }   string s, t;   int nxt[N][26];   void solve() {     int tc;     cin >> tc;     while (tc--) {       cin >> s >> t;       for (int i = 0; i < ((int)(s).size() + 5); i++) {         for (int j = 0; j < (26); j++) {           nxt[i][j] = INF;         }       }       for (int i = (int)(s).size() - 1; i >= 0; --i) {         for (int j = 0; j < (26); j++) {           nxt[i][j] = nxt[i + 1][j];         }         nxt[i][s[i] -  a ] = i;       }       int res = 1, pos = 0;       for (int i = 0; i < ((int)(t).size()); i++) {         if (pos == (int)(s).size()) {           pos = 0;           res++;         }         if (nxt[pos][t[i] -  a ] == INF) {           pos = 0;           ++res;         }         if (nxt[pos][t[i] -  a ] == INF && pos == 0) {           res = INF;           break;         }         pos = nxt[pos][t[i] -  a ] + 1;       }       if (res >= INF) {         cout << -1 << nl;       } else {         cout << res << nl;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int inf = 1e9 + 7;   int tem[N], va[N], ans;   int num[N << 2], mx[N << 2], mi[N << 2];   void build(int t, int l, int r) {     mx[t] = 0, mi[t] = inf;     if (l == r) return;     int mid = (l + r) >> 1;     build(t << 1, l, mid);     build(t << 1 | 1, mid + 1, r);   }   void update(int t, int l, int r, int pos, int d) {     if (l == r) {       num[t] = d;       if (num[t])         mx[t] = mi[t] = tem[l];       else         mx[t] = 0, mi[t] = inf;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update(t << 1, l, mid, pos, d);     else       update(t << 1 | 1, mid + 1, r, pos, d);     num[t] = num[t << 1] + num[t << 1 | 1];     mi[t] = min(mi[t << 1], mi[t << 1 | 1]);     mx[t] = max(mx[t << 1], mx[t << 1 | 1]);   }   void query_mi(int t, int l, int r, int ei, int ej) {     if (ei <= l && r <= ej) {       ans = min(ans, mi[t]);       return;     }     int mid = (l + r) >> 1;     if (ei <= mid) query_mi(t << 1, l, mid, ei, ej);     if (ej > mid) query_mi(t << 1 | 1, mid + 1, r, ei, ej);   }   void query_mx(int t, int l, int r, int ei, int ej) {     if (ei <= l && r <= ej) {       ans = max(ans, mx[t]);       return;     }     int mid = (l + r) >> 1;     if (ei <= mid) query_mx(t << 1, l, mid, ei, ej);     if (ej > mid) query_mx(t << 1 | 1, mid + 1, r, ei, ej);   }   int st[N << 2];   void modify(int t, int l, int r, int pos, int d) {     if (l == r) {       st[t] = d;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       modify(t << 1, l, mid, pos, d);     else       modify(t << 1 | 1, mid + 1, r, pos, d);     st[t] = max(st[t << 1], st[t << 1 | 1]);   }   bool tp[N];   int vb[N];   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     int cnt = 0;     for (int i = 1; i <= n; i++) {       cin >> va[i];       tem[++cnt] = va[i];     }     for (int i = 1; i <= m; i++) {       cin >> tp[i] >> vb[i];       if (tp[i]) tem[++cnt] = vb[i];     }     sort(tem + 1, tem + cnt + 1);     sort(va + 1, va + n + 1);     int ni = unique(tem + 1, tem + cnt + 1) - tem - 1;     build(1, 1, ni);     for (int i = 1; i <= n; i++)       va[i] = lower_bound(tem + 1, tem + ni + 1, va[i]) - tem;     for (int i = 1; i <= n; i++) {       update(1, 1, ni, va[i], 1);       if (i != n) modify(1, 1, ni, va[i + 1], tem[va[i + 1]] - tem[va[i]]);     }     cout << mx[1] - mi[1] - st[1] << endl;     for (int i = 1; i <= m; i++) {       int pos = lower_bound(tem + 1, tem + ni + 1, vb[i]) - tem;       if (tp[i]) {         ans = 0;         query_mx(1, 1, ni, 1, pos);         int a = ans;         ans = inf;         query_mi(1, 1, ni, pos, ni);         int b = ans;         update(1, 1, ni, pos, 1);         if (a) modify(1, 1, ni, pos, vb[i] - a);         if (b != inf) {           int c = lower_bound(tem + 1, tem + ni + 1, b) - tem;           modify(1, 1, ni, c, b - vb[i]);         }       } else {         update(1, 1, ni, pos, 0);         modify(1, 1, ni, pos, 0);         ans = 0;         query_mx(1, 1, ni, 1, pos);         int a = ans;         ans = inf;         query_mi(1, 1, ni, pos, ni);         int b = ans;         if (b != inf) {           int c = lower_bound(tem + 1, tem + ni + 1, b) - tem;           if (a)             modify(1, 1, ni, c, b - a);           else             modify(1, 1, ni, c, 0);         }       }       cout << max(mx[1] - mi[1] - st[1], 0) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     if (a < 0) {       a = -a;       putchar( - );     }     write(a);     puts(  );   }   const int mod = 1000000007, rev = (mod + 1) / 2, N = 20;   int ans, n, bit[1 << N];   long long a[1 << N], ycl[21];   char ch[(1 << N) + 5];   void FWT(long long *a, int n) {     for (int k = 1; k < n; k <<= 1) {       for (int i = 0; i < n; i += k << 1) {         for (register int j = 0; j < k; j++) {           long long x = a[i + j];           a[i + j] = a[i + j] + a[i + j + k];           a[i + j + k] = x - a[i + j + k];         }       }     }   }   int main() {     n = read();     scanf( %s , ch);     for (int i = 0; i < (1 << n); i++) a[i] = ch[i] -  0 ;     FWT(a, 1 << n);     for (int i = 0; i < (1 << n); i++) a[i] = a[i] * a[i] % mod;     FWT(a, 1 << n);     ycl[0] = 1;     for (int i = 1; i <= n; i++) ycl[i] = ycl[i - 1] * rev % mod;     for (int i = 0; i < (1 << n); i++) {       bit[i] = bit[i >> 1] + (i & 1);       ans = (ans + a[i] % mod * ycl[bit[i]]) % mod;     }     cout << (long long)(ans + mod) % mod * 3 % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool isValid(string s) {     bool valid = true;     if (s.length() < 1 || s.length() > 16) return false;     for (int i = 0; i < s.length(); i++) {       if (s[i] < 48 || (s[i] > 57 && s[i] < 65) || (s[i] > 90 && s[i] < 95) ||           (s[i] > 95 && s[i] < 97) || s[i] > 122) {         valid = false;         break;       }     }     return valid;   }   int main() {     string s;     cin >> s;     size_t f1, f2, f3;     f1 = s.find( @ );     if (f1 != string::npos) {       string t;       t = s.substr(0, int(f1));       if (isValid(t)) {         bool resource = false;         f2 = s.find( / );         if (f2 != string::npos && int(f2) > int(f1)) {           resource = true;           t = s.substr(int(f1) + 1, int(f2) - int(f1) - 1);         } else           t = s.substr(int(f1) + 1);         if (t.length() < 1 || t.length() > 32) {           cout <<  NO ;           return 0;         }         do {           f3 = t.find( . );           if (f3 != string::npos && int(f3) > 0) {             string aux = t.substr(0, int(f3));             if (isValid(aux))               t.erase(0, int(f3) + 1);             else {               cout <<  NO ;               return 0;             }           } else {             if (isValid(t)) {               if (resource) {                 string aux = s.substr(int(f2) + 1);                 if (isValid(aux))                   cout <<  YES ;                 else                   cout <<  NO ;                 return 0;               } else {                 cout <<  YES ;                 return 0;               }             } else {               cout <<  NO ;               return 0;             }           }         } while (f3 != string::npos);       } else {         cout <<  NO ;         return 0;       }     } else {       cout <<  NO ;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 201000;   int n, a[N], pos[N], l[N], r[N], C[N], idx[N], ans[N];   vector<int> nu[N];   void bitModify(int p) {     for (int i = p; i > 0; i -= i & -i) C[i]++;   }   int bitQuery(int p) {     int ret = 0;     for (int i = p; i <= n; i += i & -i) ret += C[i];     return ret;   }   bool cmp(int a, int b) { return r[a] < r[b]; }   int main() {     int nq;     scanf( %d%d , &n, &nq);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       pos[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; i * j <= n; j++) {         int a = pos[i];         int b = pos[i * j];         if (a > b) swap(a, b);         nu[b].push_back(a);       }     }     for (int i = 0; i < nq; i++) {       scanf( %d%d , &l[i], &r[i]);       idx[i] = i;     }     sort(idx, idx + nq, cmp);     int p = 0;     for (int i = 0; i < nq; i++) {       int ll = l[idx[i]];       int rr = r[idx[i]];       while (p < rr) {         p++;         for (int i = 0; i < (int)nu[p].size(); i++) {           bitModify(nu[p][i]);         }       }       ans[idx[i]] = bitQuery(ll);     }     for (int i = 0; i < nq; i++) {       printf( %d%c , ans[i],    n [i == nq - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, t;     cin >> n >> t;     vector<pair<long long, long long> > v(n);     double den = 0;     for (long long i = (0); i < (n); ++i) {       cin >> v[i].second;       den += v[i].second;     }     for (long long i = (0); i < (n); ++i) cin >> v[i].first;     sort(v.begin(), v.end());     double sm = 0;     for (long long i = (0); i < (n); ++i) {       sm += v[i].first * v[i].second;     }     if (sm / den == (double)t) {       cout << setprecision(8) << den;       exit(0);     }     if ((double)sm / den > t) {       for (long long i = n - 1; i >= 0; i--) {         if ((double)(sm - v[i].first * v[i].second) / (den - v[i].second) > t) {           sm -= v[i].first * v[i].second;           den -= v[i].second;           continue;         } else {           cout << setprecision(8)                << den + (double)(sm - t * den) / (t - v[i].first);           exit(0);         }       }     } else {       for (long long i = 0; i < n; i++) {         if ((double)(sm - v[i].first * v[i].second) / (den - v[i].second) < t) {           sm -= v[i].first * v[i].second;           den -= v[i].second;           continue;         } else {           cout << setprecision(8)                << den + (double)(sm - t * den) / (t - v[i].first);           exit(0);         }       }     }     cout <<  0 ;   }


#include <bits/stdc++.h>   using namespace std;   struct Rectangle {     int l, d, r, u;   };   const int maxn = 500000;   int n;   Rectangle rt[maxn];   int ans[maxn];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> rt[i].l >> rt[i].d >> rt[i].r >> rt[i].u;     for (int i = 0; i < n; i++) ans[i] = (rt[i].l & 1) * 2 + (rt[i].d & 1);     cout <<  YES  << endl;     for (int i = 0; i < n; i++) cout << ans[i] + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> ans;   int main() {     long long n;     cin >> n;     for (long long i = 1; i <= sqrt(n); i++)       if (n % i == 0) {         ans.push_back((n + 2 - i) * n / i / 2);         if (i * i != n) ans.push_back((i * n + 2 * i - n) / 2);       }     sort(ans.begin(), ans.end());     for (unsigned int i = 0; i < ans.size(); i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};   long long int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};   using namespace std;   int main() {     long long int n, p;     cin >> n >> p;     vector<bool> box(n, 0);     vector<pair<long long int, long long int>> ppl(p);     for (auto& i : ppl) cin >> i.first >> i.second;     bool res = 1;     for (int i = 0; i < n; ++i) {       cout << res;       res = !res;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int>> grid(n, vector<int>(m, 0));     vector<vector<int>> up(n, vector<int>(m, 0));     vector<vector<int>> down(n, vector<int>(m, 0));     vector<vector<int>> left(n, vector<int>(m, 0));     vector<vector<int>> right(n, vector<int>(m, 0));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> grid[i][j];       }     }     for (int i = 0; i < n; i++) {       left[i][0] = grid[i][0];       for (int j = 1; j < m; j++) {         left[i][j] = left[i][j - 1] + grid[i][j];       }     }     for (int i = 0; i < n; i++) {       right[i][m - 1] = grid[i][m - 1];       for (int j = m - 2; j >= 0; j--) {         right[i][j] = right[i][j + 1] + grid[i][j];       }     }     for (int j = 0; j < m; j++) {       up[0][j] = grid[0][j];       for (int i = 1; i < n; i++) {         up[i][j] = up[i - 1][j] + grid[i][j];       }     }     for (int j = 0; j < m; j++) {       down[n - 1][j] = grid[n - 1][j];       for (int i = n - 2; i >= 0; i--) {         down[i][j] = down[i + 1][j] + grid[i][j];       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (grid[i][j] == 1) continue;         if (up[i][j] - grid[i][j] > 0) ans++;         if (down[i][j] - grid[i][j] > 0) ans++;         if (left[i][j] - grid[i][j] > 0) ans++;         if (right[i][j] - grid[i][j] > 0) ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     set<pair<int, int> > st;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       st.insert({x, i});     }     int x = -1;     vector<int> ans;     while (x >= -1) {       auto it = st.lower_bound({x + 1, -1});       if (it != st.end() and it->first == x + 1) {         ans.emplace_back(it->second);         st.erase(it);         x++;       } else {         x -= 3;       }     }     if (st.empty()) {       cout <<  Possible n ;       for (const int &x : ans) printf( %d  , x + 1);     } else {       cout <<  Impossible n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-06;   const int MAXN = 25;   pair<int, int> r, r2, bk, wk;   int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};   char board[10][10];   bool valid(int x, int y) { return x >= 0 && y >= 0 && x < 8 && y < 8; }   bool ok(int x, int y) {     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         if (board[i][j] ==  R ) {           for (int k = 0; k < 4; k++) {             int nx = i, ny = j;             do {               nx = nx + dx[k], ny = ny + dy[k];             } while (valid(nx, ny) && board[nx][ny] ==  . );             if (valid(nx, ny) && board[nx][ny] ==  B ) return false;           }         }         if (board[i][j] ==  W ) {           for (int k = 0; k < 8; k++) {             int nx = i + dx[k], ny = j + dy[k];             if (valid(nx, ny) && board[nx][ny] ==  B ) return false;           }         }       }     }     return true;   }   bool check(int x, int y) {     if (ok(x, y)) return false;     bool mate = true;     for (int i = 0; i < 8; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (!valid(nx, ny)) continue;       char tmp = board[nx][ny];       board[nx][ny] =  B ;       board[x][y] =  . ;       if (ok(nx, ny)) mate = false;       board[nx][ny] = tmp;       board[x][y] =  B ;     }     return mate;   }   pair<int, int> get(string a) { return pair<int, int>( 8  - a[1], a[0] -  a ); }   int main() {     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) board[i][j] =  . ;     string tmp;     cin >> tmp, board[get(tmp).first][get(tmp).second] =  R ;     cin >> tmp, board[get(tmp).first][get(tmp).second] =  R ;     cin >> tmp, board[get(tmp).first][get(tmp).second] =  W ;     cin >> tmp, board[get(tmp).first][get(tmp).second] =  B ;     bool ret = false;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         if (board[i][j] ==  B ) ret = check(i, j);       }     }     if (ret)       cout <<  CHECKMATE  << endl;     else       cout <<  OTHER  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool a[300001];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, n, tmp, ans = 1, last;     cin >> n;     last = n;     cout << 1 <<    ;     for (i = 0; i < n; i++) {       cin >> tmp;       a[tmp] = 1;       ans++;       while (a[last]) {         last--, ans--;       }       cout << ans <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 20;   int c[MAX_N], d[MAX_N], num[MAX_N];   int dp[MAX_N][MAX_N * 100];   int n, m, c0, d0, a, b;   int main() {     while (scanf( %d%d%d%d , &n, &m, &c0, &d0) != EOF) {       for (int i = 1; i <= m; i++) {         scanf( %d%d , &a, &b);         num[i] = a / b;         scanf( %d%d , &c[i], &d[i]);       }       memset(dp, 0, sizeof dp);       for (int i = 0; i <= n; i++) dp[0][i] = i / c0 * d0;       for (int i = 1; i <= m; i++)         for (int j = 0; j <= n; j++)           for (int k = 0; k <= num[i]; k++) {             if (j / c[i] < k) break;             dp[i][j] = max(dp[i][j], dp[i - 1][j - c[i] * k] + d[i] * k);           }       int res = 0;       for (int i = 0; i <= n; i++) res = max(res, dp[m][i]);       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int hops[n + 1];     bool vis[n + 1];     int change[n + 1];     for (int i = 1; i <= n; ++i) {       cin >> hops[i];       vis[i] = 0;     }     int cnt = 0;     int cnt1 = 0;     for (int i = 1; i <= n; ++i) {       cin >> change[i];       if (change[i]) cnt1++;     }     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         int j = i;         cnt++;         while (vis[hops[j]] == false) {           j = hops[j];           vis[j] = true;         }       }     }     if (cnt1 % 2)       cnt1 = 0;     else       cnt1 = 1;     if (cnt == 1) cnt = 0;     cout << cnt + cnt1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   long long A[100100], sol;   map<long long, long long> M;   long long __grundy(long long n) {     if (n == 0) return 0;     if (((M).find(n) != (M).end())) return M[n];     long long r = __grundy(n - 1);     if (n % 2 != 0) return M[n] = ((r == 0) ? 1 : 0);     long long c = __grundy(n / 2);     if (r != 0 && K > 0 && c != 0) return M[n] = 0;     if (r != 1 && (K == 0 || c != 1)) return M[n] = 1;     return M[n] = 2;   }   long long g0(long long n) {     if (n == 0) return 0;     if (n == 1) return 1;     if (n == 2) return 2;     return ((n % 2) == 0) ? 1 : 0;   }   long long g1(long long n) {     if (n == 0) return 0;     if (n == 1) return 1;     if (n == 2) return 0;     if (n == 3) return 1;     if (n == 4) return 2;     if ((n % 2) == 1) return 0;     if (g1(n / 2) == 1) return 2;     return 1;   }   long long grundy(long long n) {     if (K)       return g1(n);     else       return g0(n);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     K = 0;     for (int I = 1; I <= 160; I++) {       assert(grundy(I) == __grundy(I));     }     M.clear();     K = 1;     for (int I = 1; I <= 160; I++) {       assert(grundy(I) == __grundy(I));     }     cin >> N >> K;     K %= 2;     for (long long I = 0; I < N; I++) {       cin >> A[I];       sol ^= grundy(A[I]);     }     if (sol == 0)       cout <<  Nicky  << endl;     else       cout <<  Kevin  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long int> s(n);     for (int i = 0; i < n; ++i) cin >> s[i];     int q;     cin >> q;     sort(s.begin(), s.end());     int slope0 = 1;     for (int i = 1; i < n; ++i)       if (s[i] != s[i - 1]) ++slope0;     map<long long int, int> freq;     for (int i = 1; i < n; ++i) {       long long int delta = s[i] - s[i - 1];       if (delta == 0) continue;       delta--;       if (freq.find(delta) == freq.end())         freq[delta] = 1;       else         freq[delta] = freq[delta] + 1;     }     map<long long int, int> slope;     map<long long int, long long int> obj;     long long int prev = slope0;     for (map<long long int, int>::iterator it = freq.begin(); it != freq.end();          ++it) {       slope[it->first] = prev - it->second;       prev = prev - it->second;     }     if (slope.find(0) == slope.end()) slope[0] = slope0;     for (map<long long int, int>::iterator it = slope.begin();          it != slope.end();) {       if (it->first == 0) obj[0] = slope0;       long long int y0 = obj[it->first];       long long int change = it->second;       long long int base = it->first;       ++it;       if (it != slope.end()) obj[it->first] = y0 + change * (it->first - base);     }     for (int i = 0; i < q; ++i) {       long long int l, r;       cin >> l >> r;       map<long long int, long long int>::iterator it = obj.lower_bound(r - l);       if (it->first == (r - l))         cout << it->second <<    ;       else {         it--;         long long int ans =             obj[it->first] + (r - l - it->first) * slope[it->first];         cout << ans <<    ;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const int maxn = 2e5 + 11;   const int maxm = 600 + 11;   const int mod = 1e9 + 7;   const double eps = 1e-5;   inline long long rd() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long qpow(long long a, long long b, long long p) {     long long res = 1;     while (b) {       if (b & 1) {         res *= a;         res %= p;       }       b >>= 1;       a = a * a % p;     }     return res;   }   inline long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   struct node {     long long a, b, c;     bool operator<(const node &o) const {       if (c != o.c) return c > o.c;       if (b != o.b) return b < o.b;       return a > o.a;     }   } t[maxn];   int n, k;   bool check(long long x) {     priority_queue<node> q;     for (int i = 1; i <= n; i++) {       q.push(t[i]);     }     for (int i = 0; i < k; i++) {       node o = q.top();       q.pop();       if (o.c < i) return false;       if (o.c >= k) return true;       o.a += x;       o.c = o.a / o.b;       q.push(o);     }     return true;   }   int main() {     n = rd(), k = rd();     for (int i = 1; i <= n; i++) {       t[i].a = rd();     }     for (int i = 1; i <= n; i++) {       t[i].b = rd();       t[i].c = t[i].a / t[i].b;     }     long long l = 0, r = 5e12, ans = -1;     while (l <= r) {       long long mid = l + r >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double R, r, k;     int tt;     scanf( %d , &tt);     while (tt--) {       scanf( %lf%lf%lf , &R, &r, &k);       double a = (R + r) / (4 * R * r), b = k * (R - r) / (2 * R * r);       double t = (R - r) / (4 * R * r);       double s = t / (a * a + b * b - t * t);       printf( %.9lf n , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200007;   string s;   int fa[maxn << 1];   map<string, int> aa;   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   string read() {     cin >> s;     return s;   }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= 2 * n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) aa[read()] = i;     for (int i = 1; i <= m; i++) {       int t;       scanf( %d , &t);       int x = aa[read()], y = aa[read()];       if (t == 1) {         if (find(x) != find(y + n) && find(x + n) != find(y))           fa[find(x)] = find(y), fa[find(x + n)] = find(y + n), printf( YES n );         else           printf( NO n );       } else {         if (find(x) != find(y) && find(x + n) != find(y + n))           fa[find(x)] = find(y + n), fa[find(x + n)] = find(y), printf( YES n );         else           printf( NO n );       }     }     for (int i = 1; i <= q; i++) {       int x = aa[read()], y = aa[read()];       if (find(x) == find(y))         printf( 1 n );       else if (find(x) == find(y + n))         printf( 2 n );       else         printf( 3 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> p;   map<string, string>::iterator it = p.begin();   int main() {     int q;     cin >> q;     while (q--) {       string s1, s2;       cin >> s1 >> s2;       if (!p.count(s1))         p[s2] = s1;       else {         p[s2] = p[s1];         p.erase(s1);       }     }     cout << p.size() << endl;     for (it = p.begin(); it != p.end(); it++)       cout << it->second <<     << it->first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const long long INF = 1e18;   inline int abs(int x) { return x > 0 ? x : -x; }   inline long long sqr(long long x) { return x * x; }   bool cmp(pair<int, int>& x, pair<int, int>& y) { return x.first < y.first; }   int n;   pair<int, int> p[N];   long long minY[N + 1][2], maxY[N + 1][2];   bool check(long long d) {     long long dY, sqrX, sqrY;     int l = 0, r = 0;     while (r < n) {       while (r < n && sqr((long long)p[r].first - p[l].first) <= d) {         sqrX = max(sqr((long long)p[r].first), sqr((long long)p[l].first));         sqrY = max(max(sqr(maxY[l][0]), sqr(maxY[n - r - 1][1])),                    max(sqr(minY[l][0]), sqr(minY[n - r - 1][1])));         dY = sqr(max(maxY[l][0], maxY[n - r - 1][1]) -                  min(minY[n - r - 1][1], minY[l][0]));         if (max(dY, sqrX + sqrY) <= d) {           if (d < 400) {           }           return true;         }         ++r;       }       while (r < n && l <= r && sqr((long long)p[r].first - p[l].first) > d) ++l;     }     return false;   }   long long solve() {     sort(p, p + n, cmp);     maxY[0][0] = maxY[0][1] = -INF;     minY[0][0] = minY[0][1] = INF;     for (int i = 1; i <= n; ++i) {       maxY[i][0] = max(maxY[i - 1][0], (long long)p[i - 1].second);       maxY[i][1] = max(maxY[i - 1][1], (long long)p[n - i].second);       minY[i][0] = min(minY[i - 1][0], (long long)p[i - 1].second);       minY[i][1] = min(minY[i - 1][1], (long long)p[n - i].second);     }     long long l = 0, r = INF, m;     while (l < r) {       m = (l + r) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     return min(l, sqr((long long)p[n - 1].first - p[0].first));   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d%d , &p[i].first, &p[i].second);     long long ans = solve();     for (int i = 0; i < n; ++i) swap(p[i].first, p[i].second);     ans = min(ans, solve());     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     long long k, time, maks, tot, ar[10005], ans, temp, m;     bool cek;     scanf( %d %I64d %I64d , &n, &m, &k);     for (i = 0; i < n; ++i) scanf( %I64d , &ar[i]);     if ((n % 2) == 0)       printf( 0 n );     else {       ans = 0;       time = (n + 1) / 2;       if (time > m)         printf( 0 n );       else {         temp = m / time;         maks = temp * k;         ans = ar[0];         for (i = 2; i < n; i += 2) ans = min(ans, ar[i]);         ans = min(ans, maks);         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str;   vector<int> graph[26], rgraph[26];   bool visited[26];   bool present[26];   void dfs(int i) {     visited[i] = true;     if (graph[i].size() >= 1 && !visited[graph[i][0]]) dfs(graph[i][0]);     str.insert(str.begin(), (char)( a  + i));   }   void rdfs(int i) {     visited[i] = true;     if (rgraph[i].size() >= 1 && !visited[rgraph[i][0]]) {       str.insert(str.begin(), (char)( a  + rgraph[i][0]));       rdfs(rgraph[i][0]);     }   }   int main() {     int n;     cin >> n;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     memset(present, false, sizeof(present));     for (int i = 0; i < n; i++) {       for (int j = 0; j < s[i].length() - 1; j++) {         graph[s[i][j] -  a ].push_back(s[i][j + 1] -  a );         rgraph[s[i][j + 1] -  a ].push_back(s[i][j] -  a );         present[s[i][j] -  a ] = true;       }       present[s[i][s[i].length() - 1] -  a ] = true;     }     memset(visited, 0, sizeof(visited));     for (int i = 0; i < 26; i++) {       if (present[i] && !visited[i]) {         dfs(i);         rdfs(i);       }     }     cout << str;   }


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


#include <bits/stdc++.h>   namespace mem {   namespace stdval {   using i32 = int;   using i64 = long long int;   using u32 = unsigned int;   using u64 = unsigned long long int;   using f32 = float;   using f64 = double;   using f96 = long double;   using i128 = __int128_t;   using u128 = __uint128_t;   }  // namespace stdval   namespace utils {   using std::accumulate;   using std::cerr;   using std::cin;   using std::cout;   using std::endl;   using std::function;   using std::get;   using std::lower_bound;   using std::make_pair;   using std::make_tuple;   using std::max_element;   using std::min_element;   using std::reverse;   using std::shuffle;   using std::sort;   using std::swap;   using std::tie;   using std::unique;   using std::upper_bound;   }  // namespace utils   namespace random {   const int LuckyNumber = 20040726;   std::mt19937 rng(LuckyNumber ^                    std::chrono::steady_clock::now().time_since_epoch().count());   std::mt19937_64 rng64(       LuckyNumber ^ std::chrono::steady_clock::now().time_since_epoch().count());   template <class T>   inline T rand(T l, T r) {     return std::uniform_int_distribution<T>(l, r)(rng);   }   template <class T>   inline T rand64(T l, T r) {     return std::uniform_int_distribution<T>(l, r)(rng);   }   }  // namespace random   namespace modint {   template <const int mod>   struct Z {     int x;     inline Z() { x = 0; }     inline Z(int t) { x = t; }     inline void operator-=(Z a) { (x -= a.x) < 0 && (x += mod); }     inline void operator+=(Z a) { (x += a.x) >= mod && (x -= mod); }     inline void operator*=(Z a) { x = (long long)x * a.x % mod; }     friend inline Z operator*(Z a, Z b) { return (long long)a.x * b.x % mod; }     friend inline Z operator-(Z a, Z b) {       return ((a.x -= b.x) < 0 && (a.x += mod)), a;     }     friend inline Z operator+(Z a, Z b) {       return ((a.x += b.x) >= mod && (a.x -= mod)), a;     }   };   template <const int mod>   inline Z<mod> finv(Z<mod> x) {     if (x.x < 2) return x;     return (mod - mod / x.x) * finv(mod % x.x);   }   template <const int mod>   inline Z<mod> fpow(Z<mod> a, int b) {     Z<mod> s = 1;     for (; b; b >>= 1, a = a * a)       if (b & 1) s = s * a;     return s;   }   template <const int mod>   inline void init_inverse(int n, Z<mod> *inv) {     inv[0] = inv[1] = 1;     for (int i = 2; i < n; i++) inv[i] = (mod - mod / i) * inv[mod % i];   }   template <const int mod>   inline void init_factorial(int n, Z<mod> *fac, Z<mod> *ifac) {     fac[0] = 1, init_inverse(n, ifac);     for (int i = 1; i < n; i++)       fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * ifac[i];   }   }  // namespace modint   namespace io {   template <const int mod>   inline void read(modint::Z<mod> &x) {     read(x.x);   }   template <const int mod>   inline void print(modint::Z<mod> x) {     print(x.x);   }   }  // namespace io   namespace math {   using std::max;   using std::min;   template <class T>   inline T abs(T x) {     return x < 0 ? -x : x;   }   template <class T>   inline T gcd(T n, T m) {     return m ? gcd(m, n % m) : n;   }   template <class T>   inline T lcm(T n, T m) {     return n / gcd(n, m) * m;   }   template <const stdval::u64 p>   struct FastDiv {     stdval::u64 t, i;     inline FastDiv() : t(stdval::u64(-1) / p), i(mul_inv(p)) {}     inline bool divide(stdval::u64 n) { return n * i <= t; }     inline bool divide(stdval::i64 n) {       return stdval::u64(n < 0 ? -n : n) * i <= t;     }     inline stdval::u64 mul_inv(stdval::u64 n) {       stdval::u64 x = n;       for (int i = 0; i < 5; ++i) x *= 2 - n * x;       return x;     }   };   template <const stdval::u64 b>   struct FastMod {     stdval::u64 m;     inline FastMod() : m(stdval::u64((stdval::u128(1) << 64) / b)) {}     inline stdval::u64 reduce(stdval::u64 a) {       stdval::u64 q = (stdval::u64)((stdval::u128(m) * a) >> 64);       stdval::u64 r = a - q * b;       return r >= b ? r - b : r;     }   };   }  // namespace math   namespace container {   using std::get;   using std::make_pair;   using std::make_tuple;   using std::map;   using std::pair;   using std::priority_queue;   using std::queue;   using std::set;   using std::stack;   using std::tie;   using std::tuple;   using std::unordered_map;   using std::unordered_set;   template <class T>   struct vector : std::vector<T> {     using std::vector<T>::vector;     vector() : std::vector<T>() {}     vector(const std::vector<T> &plain) : std::vector<T>(plain) {}     inline void sort() { std::sort(this->begin(), this->end()); }     inline void concat(const vector &rhs) {       this->insert(this->end(), rhs.begin(), rhs.end());     }     inline bool includes(const T &x) const {       return std::find(this->begin(), this->end(), x) != this->end();     }     template <class Function>     inline void forEach(Function func) {       for (const auto &it : *this) func(it);     }     inline vector slice(int l, int r) const {       if (l > r) return {};       if (r < this->size()) return vector(this->begin() + l, this->begin() + r);       vector<int> rsp = (this->begin() + l, this->end());       return rsp.resize(r - l), rsp;     }     inline void from(const std::set<T> &src) {       this->resize(src.size());       auto it = this->begin();       for (const T e : src) *it++ = e;     }     template <class R, class Function>     inline vector<R> _map(Function func) const {       vector<R> res(this->size());       for (size_t i = 0; i < this->size(); i++)         res[i] = func(this->operator[](i));       return res;     }     template <class R>     inline vector<R> map(R func(T)) const {       return this->_map<R>(func);     }     template <class R>     inline vector<R> map(const std::function<R(T)> &func) const {       return this->_map<R>(func);     }   };   struct string : std::string {     using std::string::string;     string() : std::string(  ) {}     string(const std::string &plain) : std::string(plain) {}     template <class T>     inline string join(const vector<T> &vet) const;     vector<string> split(const string &dim) const {       if (this->empty()) return {};       char *src = new char[this->length() + 1];       strcpy(src, this->c_str());       char *tar = new char[dim.length() + 1];       strcpy(tar, dim.c_str());       vector<string> rsp;       for (char *pos = strtok(src, tar); pos; pos = strtok(nullptr, tar))         rsp.push_back(string(pos));       delete[] src;       delete[] tar;       return rsp;     }     template <class... Args>     static inline string format(const char *fm, Args... args) {       int len = snprintf(nullptr, 0, fm, args...);       char *buf = new char[len + 1];       snprintf(buf, len + 1, fm, args...);       string str(buf);       delete[] buf;       return str;     }     template <class... Args>     static inline string format(const string &fm, Args... args) {       return format(fm.c_str(), args...);     }   };   inline string to_string(const float &x) { return std::to_string(x); }   inline string to_string(const double &x) { return std::to_string(x); }   inline string to_string(const long double &x) { return std::to_string(x); }   inline string to_string(const int &x) { return std::to_string(x); }   inline string to_string(const unsigned int &x) { return std::to_string(x); }   inline string to_string(const long long int &x) { return std::to_string(x); }   inline string to_string(const unsigned long long int &x) {     return std::to_string(x);   }   inline string to_string(const string &s) { return s; }   inline string to_string(const char *s) { return string(s); }   inline string to_string(const std::string &s) { return string(s); }   template <const int mod>   inline string to_string(const mem::modint::Z<mod> &v) {     return std::to_string(v.x);   }   template <class T>   inline string to_string(const vector<T> &ctn) {     return  [  + string( , ).join(ctn) +  ] ;   }   template <class T>   inline string to_string(const set<T> &ctn) {     string result =  { ;     bool flag = false;     for (const auto &it : ctn) {       if (flag) result +=  , ;       flag = true;       result += to_string(it);     }     return result +  } ;   }   template <class T1, class T2>   inline string to_string(const map<T1, T2> &ctn) {     string result =  { ;     bool flag = false;     for (const auto &it : ctn) {       if (flag) result +=  , ;       flag = true;       result += to_string(it.first) +  :  + to_string(it.second);     }     return result +  } ;   }   template <class T>   inline string string::join(const vector<T> &vet) const {     if (!vet.size()) return   ;     string res = to_string(vet[0]);     for (size_t i = 1; i < vet.size(); i++) {       res += *this;       res += to_string(vet[i]);     }     return res;   }   inline string operator   _s(const char *s) { return string(s); }   inline string operator   _s(const char *s, size_t len) {     return string(s, len);   }   inline string operator   _s(long double x) { return to_string(x); }   inline string operator   _s(unsigned long long int x) { return to_string(x); }   }  // namespace container   namespace io {   namespace fastio {   const int BUFFER = 1 << 18;   char ibuf[BUFFER], *iS, *iT;   inline int getc() {     if (iS == iT) {       iT = (iS = ibuf) + fread(ibuf, 1, BUFFER, stdin);       return iS == iT ? EOF : *iS++;     } else {       return *iS++;     }   }   char obuf[BUFFER], *oS = obuf, *oT = oS + BUFFER - 1;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(int x) {     *oS++ = x;     if (oS == oT) flush();   }   struct Flusher {     ~Flusher() { flush(); }   } flusher;   }  // namespace fastio   using fastio::getc;   using fastio::putc;   template <class T>   inline void readDigit(T &x) {     x = getc();     while (!isdigit(x)) x = getc();   }   inline int readDigit() {     int x;     readDigit(x);     return x;   }   template <class T>   inline void readAlpha(T &x) {     x = getc();     while (!isalpha(x)) x = getc();   }   inline int readAlpha() {     int x;     readAlpha(x);     return x;   }   inline void read(int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(unsigned int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(long long int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(unsigned long long int &x) {     x = 0;     bool f = 0;     char c = getc();     while (!isdigit(c)) f ^= c ==  - , c = getc();     while (isdigit(c)) x = x * 10 + c -  0 , c = getc();     if (f) x = -x;   }   inline void read(char &x) { x = getc(); }   inline void read(char *s) {     char c = getc();     while (~c && !isspace(c)) *s++ = c, c = getc();     *s++ =   0 ;   }   inline void read(container::string &s) {     char c = getc();     s =   ;     while (~c && !isspace(c)) s += c, c = getc();   }   template <class T = int>   inline T read() {     T x;     read(x);     return x;   }   template <class T, class... Args>   inline void read(T &x, Args &...args) {     read(x), read(args...);   }   inline void print(int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(unsigned int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(long long int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(unsigned long long int x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) print(x / 10);     putc( 0  + x % 10);   }   inline void print(char x) { putc(x); }   inline void print(const char *s) {     int len = strlen(s);     for (int i = 0; i < len; i++) putc(s[i]);   }   inline void print(const container::string &s) {     for (int i = 0; i < s.length(); i++) putc(s[i]);   }   template <class T, class... Args>   inline void print(const T &x, Args... args) {     print(x), print(args...);   }   template <class... Args>   inline void println(Args... args) {     print(args...), putc(  n );   }   template <class... Args>   inline void printfm(const char *formatter, Args... arguments) {     print(container::string().format(formatter, arguments...));   }   template <class... Args>   inline void printfm(const container::string &formatter, Args... arguments) {     print(container::string().format(formatter, arguments...));   }   }  // namespace io   namespace logger {   enum ConsoleColor {     NOPE = -1,     BLACK,     RED,     GREEN,     YELLOW,     BLUE,     PURPLE,     DEEPBLUE   };   template <const ConsoleColor color = NOPE, class... Args>   inline void log(const char *formatter, Args... args) {     if (~color) {       fprintf(stderr,   033[%dm , 30 + color);       fprintf(stderr, formatter, args...);       fprintf(stderr,   033[0m );     } else {       fprintf(stderr, formatter, args...);     }   }   template <const ConsoleColor color = NOPE, class... Args>   inline void logln(const char *formatter, Args... args) {     if (~color) {       fprintf(stderr,   033[%dm , 30 + color);       fprintf(stderr, formatter, args...);       fprintf(stderr,   033[0m n );     } else {       fprintf(stderr, formatter, args...);       fprintf(stderr,   n );     }   }   template <class T>   inline void logs(const T &x) {     fprintf(stderr, container::to_string(x).c_str());   }   template <class T, class... Args>   inline void logs(const T &x, Args... args) {     logs(x), logs(args...);   }   template <class... Args>   inline void logsln(Args... args) {     logs(args...);     fprintf(stderr,   n );   }   }  // namespace logger   using namespace io;   using namespace math;   using namespace utils;   using namespace modint;   using namespace random;   using namespace stdval;   using namespace logger;   using namespace container;   }  // namespace mem   using namespace mem;   const int N = 1e6 + 10;   const long long inf = 1e18;   int k, q, f[6], stk[N << 1];   long long dp[6][N];   inline int weight(int k) { return k % 3 == 0 ? k / 3 : 0; }   inline long long calc(int s) {     if ((s + 8) / 9 > k) {       return -inf;     }     int t = s / 9;     s -= t * 9;     if (t + 2 > k) {       return t * 3 + weight(s);     } else {       return t * 3 + s / 3;     }   }   inline vector<long long> transform(vector<long long> dp, int val) {     vector<vector<long long>> g(3, vector<long long>(dp.size(), -inf));     for (int r = 0; r < 9; r++)       for (int cas = 0; cas < 3; cas++) {         int u = 1, v = 0;         for (int j = r, l = 0; j < dp.size(); j += 9, l++) {           while (u <= v &&                  dp[j] - 3ll * l * val > dp[stk[v] * 9 + r] - 3ll * stk[v] * val)             --v;           stk[++v] = l;           while (u <= v && k - cas < l - stk[u]) ++u;           if (u <= v) {             g[cas][j] = 3ll * l * val + dp[stk[u] * 9 + r] - 3ll * val * stk[u];           }         }       }     for (int i = 0; i < dp.size(); i++) {       dp[i] = max(dp[i], g[0][i]);       for (int j = i; j >= max<int>(0, i - 9); j--) {         dp[i] = max(dp[i], g[1][j] + (long long)weight(i - j) * val);       }       for (int j = i; j >= max<int>(0, i - 9); j--) {         dp[i] = max(dp[i], g[2][j] + (long long)(i - j) / 3 * val);       }     }     return dp;   }   int32_t main() {     read(k);     for (int i = 0; i < 6; i++) {       read(f[i]);     }     for (int i = 0; i < 1000000; i++) {       long long t = calc(i);       if (t < 0) {         dp[0][i] = -inf;       } else {         dp[0][i] = (long long)t * f[0];       }     }     int w = 10;     for (int k = 1; k < 6; k++, w *= 10) {       for (int r = 0; r < w; r++) {         vector<long long> src;         for (int i = r; i < 1000000; i += w) {           src.push_back(dp[k - 1][i]);         }         vector<long long> rsp = transform(src, f[k]);         for (int i = r, j = 0; i < 1000000; i += w, j++) {           dp[k][i] = rsp[j];         }       }     }     read(q);     while (q-- > 0) {       int x;       read(x);       print(dp[5][x],   n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   char s[maxn];   int ans[maxn];   void solve() {     int n, k;     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     memset(ans, -1, sizeof(ans));     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) continue;       if (ans[i % k + 1] == -1)         ans[i % k + 1] = s[i] -  0 ;       else {         if (s[i] -  0  != ans[i % k + 1]) {           printf( No n );           return;         }       }     }     int cnt1 = 0, cnt0 = 0;     for (int i = 1; i <= k; i++) {       if (ans[i] == 1) cnt1++;       if (ans[i] == 0) cnt0++;     }     if (cnt1 > k / 2 || cnt0 > k / 2 || k & 1) {       printf( No n );       return;     }     printf( Yes n );   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, k, t, n;     cin >> t;     while (t--) {       cin >> i >> j >> k;       i = i + j + k;       cout << i / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int s[n];     int m[n];     string st;     cin >> st;     for (int i = 0; i < n; i++) s[i] = st[i] -  0 ;     cin >> st;     for (int i = 0; i < n; i++) m[i] = st[i] -  0 ;     sort(s, s + n);     sort(m, m + n);     int sher = 0;     int mor = 0;     int pos = 0;     for (int i = 0; i < n; i++) {       if (s[pos] < m[i]) {         sher++;         pos++;       }     }     pos = 0;     mor = n;     for (int i = 0; i < n; i++) {       if (m[i] >= s[pos]) mor--, pos++;     }     cout << mor <<   n  << sher;   }


#include <bits/stdc++.h>   using namespace std;   long long mpow(long long a, long long b) {     if (b == 1) return a;     if (b == 0) return 1;     return mpow(a, b - 1);   }   int main() {     long long n;     cin >> n;     cout << (n / 2520);   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   int power(int x, int y) {     int t = 1;     for (; y; y >>= 1, x = x * x % 1000000007)       if (y & 1) t = t * x % 1000000007;     return t;   }   long long n, m;   int main() {     n = read();     m = read();     if (min(n, m) == 1) {       long long ans = 6 * (max(n, m) / 6);       ans += max((long long)0, 2 * ((max(n, m) % 6) - 3));       cout << ans << endl;     } else if (min(n, m) == 2) {       if (max(n, m) == 3)         cout << 4 << endl;       else if (max(n, m) == 7)         cout << 12 << endl;       else if (max(n, m) == 2)         cout << 0 << endl;       else         cout << n * m << endl;     } else {       if ((n * m) % 2 == 0)         cout << n * m << endl;       else         cout << n * m - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[10] = {1, -1, 0, 0};   int dy[10] = {0, 0, 1, -1};   const long long mod = 1e9 + 7;   long long cur;   long long tich = 1;   vector<int> G[300005];   int n, h, m;   int a[105][105];   int b[105][105];   int ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> b[i][j];         if (b[i][j] < a[i][j]) {           int tmp = b[i][j];           b[i][j] = a[i][j];           a[i][j] = tmp;         }       }     for (int i = 1; i < n; i++)       for (int j = 1; j <= m; j++) {         if (a[i][j] >= a[i + 1][j]) {           cout <<  Impossible ;           return 0;         }         if (b[i][j] >= b[i + 1][j]) {           cout <<  Impossible ;           return 0;         }       }     for (int i = 1; i <= n; i++)       for (int j = 1; j < m; j++) {         if (a[i][j] >= a[i][j + 1]) {           cout <<  Impossible ;           return 0;         }         if (b[i][j] >= b[i][j + 1]) {           cout <<  Impossible ;           return 0;         }       }     cout <<  Possible ;   }


#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 = 300007;   const int MAX = 130;   int n;   int a[MAXN];   int ps[MAXN];   int pc[MAXN][2];   void init();   void input();   void work();   int main() {     init();     input();     work();   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d , &n);     long long x;     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &x);       a[i] = __builtin_popcountll(x);     }   }   void work() {     for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] + a[i];     int mx;     long long ans = 0;     for (int i = 1; i <= n; ++i) {       int j = i - 1;       mx = a[i];       for (; j && i - j <= MAX; --j) {         mx = (((mx) > (a[j])) ? (mx) : (a[j]));         if ((ps[i] & 1) == (ps[j - 1] & 1) && mx * 2 <= ps[i] - ps[j - 1]) ++ans;       }       ans += pc[j][ps[i] & 1];       pc[i][0] = pc[i - 1][0], pc[i][1] = pc[i - 1][1];       ++pc[i][ps[i - 1] & 1];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   struct edge {     int v, nxt;   } e[maxn << 1];   int head[maxn], ecnt = 0;   void add(int u, int v) { e[++ecnt] = (edge){v, head[u]}, head[u] = ecnt; }   vector<int> p[maxn];   int pos[maxn];   int tree[maxn];   void update(int x, int v) {     for (; x < maxn; x += x & -x) tree[x] += v;   }   long long query(int x) {     long long ret = 0;     for (; x; x -= x & -x) ret += tree[x];     return ret;   }   namespace ACAM {   int son[maxn][26], fail[maxn], cnt;   void insert(char *s, int id) {     int len = strlen(s + 1), u = 0;     p[id].push_back(u);     for (int i = 1; i <= len; i++) {       int c = s[i] -  a ;       if (!son[u][c]) son[u][c] = ++cnt;       u = son[u][c];       p[id].push_back(u);     }     pos[id] = u;   }   void build() {     queue<int> que;     for (int c = 0; c < 26; c++) {       int u = son[0][c];       if (u) que.push(u);     }     while (!que.empty()) {       int u = que.front();       que.pop();       for (int c = 0; c < 26; c++) {         int v = son[u][c];         if (!v)           son[u][c] = son[fail[u]][c];         else           fail[v] = son[fail[u]][c], que.push(v);       }     }     for (int i = 1; i <= cnt; i++) add(fail[i], i);   }   }  // namespace ACAM   int n, q, siz[maxn], dfn[maxn], idx = 0;   char s[maxn];   vector<pair<int, int> > op[maxn];   void dfs(int u) {     siz[u] = 1, dfn[u] = ++idx;     for (int i = head[u]; ~i; i = e[i].nxt) {       int v = e[i].v;       dfs(v);       siz[u] += siz[v];     }   }   long long ans[maxn];   int main() {     memset(head, -1, sizeof(head));     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       ACAM::insert(s, i);     }     ACAM::build();     for (int i = 1; i <= q; i++) {       int k, l, r;       scanf( %d%d%d , &l, &r, &k);       op[l - 1].push_back(make_pair(i, -k));       op[r].push_back(make_pair(i, k));     }     dfs(0);     for (int i = 1; i <= n; i++) {       for (auto t : p[i]) update(dfn[t], 1);       for (auto qr : op[i]) {         int id = qr.first, u = qr.second;         if (u < 0)           u = -u, u = pos[u],           ans[id] -= query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1);         else           u = pos[u], ans[id] += query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1);       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   void update(int* Bit, int index) {     for (; index <= 100000; index += (index & (-index))) {       Bit[index] += 1;     }   }   int query(int* Bit, int index) {     int sum = 0;     for (; index > 0; index -= (index & -index)) sum += Bit[index];     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int maxx;       for (int i = 31; i >= 0; i--) {         if (n & (1 << i)) {           maxx = i;           break;         }       }       long long ans = 1;       for (int i = 0; i < maxx; i++) {         ans = (ans + ans * (1 << i)) % m;       }       ans = (ans + m - 1) % m;       long long d = n - (1 << maxx) + 1;       ans = (((d + 1) * ans) % m + d) % m;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000];     int n, k;     scanf( %d , &n);     scanf( %d , &k);     for (int i = 0; i < 2 * n + 1; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < 2 * n + 1; i += 2) {       if (a[i] - 1 > a[i + 1] && a[i] - 1 > a[i - 1]) {         a[i]--;         k--;       }       if (k == 0) {         break;       }     }     for (int i = 0; i < 2 * n + 1; i++) {       if (i) {         printf(   );       }       printf( %d , a[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N];   int main() {     int i, j, k = 0, n;     cin >> n;     long long s = 0, t;     for (i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     if (s % 2 == 1) {       cout <<  0 n ;       return 0;     }     t = 0;     for (i = 1; i < n; i++) {       s -= a[i];       t += a[i];       if (s == t) k++;     }     cout << k << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 257, MOD = 1e9 + 7;   int pk[MAXN * MAXN], pk1[MAXN * MAXN], n, k, f[MAXN][MAXN], C[MAXN][MAXN];   int mul(int a, int b) { return 1LL * a * b % MOD; }   void add(int &a, const int &b) {     a += b;     if (a >= MOD) a -= MOD;   }   void sub(int &a, const int &b) {     a -= b;     if (a < 0) a += MOD;   }   int subs(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   int pw(int cs, int sm) {     if (sm == 0) return 1;     int hpw = pw(cs, sm >> 1);     hpw = 1LL * hpw * hpw % MOD;     if (sm & 1) hpw = 1LL * hpw * cs % MOD;     return hpw;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     pk[0] = pk1[0] = 1;     for (int i = 1; i <= n * n; ++i) {       pk[i] = 1LL * pk[i - 1] * k % MOD;       pk1[i] = 1LL * pk1[i - 1] * (k - 1) % MOD;     }     C[0][0] = 1;     for (int i = 1; i <= n; ++i) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;     }     int res = 0;     for (int i = 0; i <= n; ++i) {       int cur = mul(C[n][i], pw(subs(mul(pk[n - i], pk1[i]), pk1[n]), n));       if (i & 1)         sub(res, cur);       else         add(res, cur);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 100, M = 1e14 + 10;   long long int n, k, l, r, mid, x, y, f[N], p[N], a[N];   vector<long long int> v;   void add(long long int v, long long int c) {     if (v == 0) return;     for (; v < N; v += v & -v) f[v] += c;   }   long long int get(long long int ind) {     long long int ret = 0;     for (; ind; ind -= ind & -ind) ret += f[ind];     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     p[0] = M;     v.push_back(p[0]);     for (int i = 1; i <= n; i++) {       cin >> a[i];       p[i] = p[i - 1] + a[i];       v.push_back(p[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     l = -M;     r = M;     while (r - l > 1) {       mid = l + r >> 1;       y = 0;       fill(f, f + N, 0);       for (int i = n; i >= 0; i--) {         x = upper_bound(v.begin(), v.end(), p[i] + mid - 1) - v.begin();         y += get(N - 1) - get(x + 1);         x = upper_bound(v.begin(), v.end(), p[i]) - v.begin();         add(x + 1, 1);       }       if (y >= k)         l = mid;       else         r = mid;     }     cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     string s;     getline(cin, s);     set<char> st;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  {  || s[i] ==  }  || s[i] ==  ,  || s[i] ==    ) {         continue;       } else {         st.insert(s[i]);       }     }     cout << st.size();   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int per;   int main() {     cin >> n >> m >> k;     per = 2;     int flag = 0;     int sum = 0;     int ff = 0;     int a = 1;     for (int i = 1; i <= n; ++i) {       if (!flag) {         for (int j = 1; j <= m; ++j) {           if (sum % 2 == 0 && a == k) {             if (ff++) cout << endl;             cout << n * m - 2 * (k - 1);             a++;           }           if (sum % 2 == 0 && a < k) {             if (ff++) cout << endl;             cout <<  2 ;             a++;           }           cout <<     << i <<     << j;           sum++;         }         flag = 1;         continue;       }       if (flag) {         for (int j = m; j >= 1; --j) {           if (sum % 2 == 0 && a == k) {             if (ff++) cout << endl;             cout << n * m - 2 * (k - 1);             a++;           }           if (sum % 2 == 0 && a < k) {             if (ff++) cout << endl;             cout <<  2 ;             a++;           }           cout <<     << i <<     << j;           sum++;         }         flag = 0;         continue;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   long long ans = 0;   long long st[1000000 + 5];   long long dp[1000000 + 5];   vector<long long> d[1000000 + 5];   long long n;   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long l, r;       cin >> l >> r;       l--;       r--;       d[l].push_back(r);       d[r].push_back(l);     }     st[0] = 1;     for (long long i = 1; i <= n; i++) {       st[i] = st[i - 1] * 2;       st[i] %= md;     }     long long l = 0;     for (long long i = 0; i < n; i++) {       if (d[i].size() == 1) l++;     }     long long ans = l * st[n - l + 1] + (n - l) * st[n - l];     ans %= md;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const long long maxn = 2e5 + 1e2;   struct Node {     long long a, b, w;   };   struct stt {     long long f[4 * maxn];     long long add[4 * maxn];     long long val[4 * maxn];     void up(long long root) { f[root] = min(f[root << 1], f[root << 1 | 1]); }     void pushdown(long long root, long long l, long long r) {       if (add[root]) {         add[root << 1] += add[root];         add[root << 1 | 1] += add[root];         f[root << 1] += add[root];         f[root << 1 | 1] += add[root];         add[root] = 0;       }     }     void build(long long root, long long l, long long r) {       if (l == r) {         f[root] = val[l];         return;       }       long long mid = l + r >> 1;       build(root << 1, l, mid);       build(root << 1 | 1, mid + 1, r);       up(root);     }     void update(long long root, long long l, long long r, long long x,                 long long y, long long p) {       if (x <= l && r <= y) {         f[root] += p;         add[root] += p;         return;       }       pushdown(root, l, r);       long long mid = l + r >> 1;       if (x <= mid) update(root << 1, l, mid, x, y, p);       if (y > mid) update(root << 1 | 1, mid + 1, r, x, y, p);       up(root);     }   };   stt a, b;   Node ymh[maxn];   long long n, m, cnt;   long long pp[maxn];   long long q;   vector<pair<long long, long long> > v[maxn];   void print(long long x) {     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   signed main() {     n = read(), m = read();     q = read();     for (register long long i = 1; i < n; ++i)       a.val[i] = read(), pp[i] = a.val[i], b.val[i + 1] = read();     for (register long long i = 1; i <= m; ++i) {       ymh[i].a = read(), ymh[i].b = read(), ymh[i].w = read();       v[ymh[i].a].push_back(make_pair(ymh[i].b, ymh[i].w));     }     b.build(1, 1, n);     for (register long long i = 1; i <= n; ++i) {       for (register long long j = 0; j < v[i].size(); ++j) {         b.update(1, 1, n, 1, v[i][j].first, v[i][j].second);       }       a.val[i] += b.f[1];     }     a.build(1, 1, n);     cout << a.f[1] << endl;     for (long long i = 1; i <= q; i++) {       long long x = read(), y = read();       a.update(1, 1, n, x, x, y - pp[x]);       pp[x] = y;       print(a.f[1]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     cin >> n >> a >> b >> c;     int count = 0;     for (int i = 0; i <= b; i++) {       for (int j = 0; j <= c; j++) {         int num = n - i - 2 * j;         if (num >= 0 && 2 * num <= a) count++;       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 2e5 + 7;   const long long segN = 8e5 + 7;   const long long moD = 1e9 + 7;   struct query {     long long t, x, y;   };   long long n;   long long st[maxN], fi[maxN], sum[segN], deg[maxN], mul[segN], laz[segN],       val[maxN];   vector<long long> chi[maxN];   vector<query> que;   long long wop(long long x, long long y) {     if (y == 0) return 1;     long long res = wop(x, y / 2);     return res * res % moD * (y % 2 == 1 ? x : 1) % moD;   }   long long dfs(long long v) {     fi[v] = st[v] + 1;     for (long long u : chi[v]) {       st[u] = fi[v];       fi[v] = dfs(u);     }     return fi[v];   }   void merge(long long x) { sum[x] = (sum[x << 1] + sum[x << 1 | 1]) % moD; }   void upd(long long x, long long val) {     sum[x] = sum[x] * val % moD;     mul[x] = mul[x] * val % moD;     laz[x] = laz[x] * val % moD;   }   void shift(long long x) {     upd(x << 1, laz[x]);     upd(x << 1 | 1, laz[x]);     laz[x] = 1;   }   void add(long long idx, long long val, long long x = 1, long long xl = 0,            long long xr = n) {     if (xr - xl == 1) {       sum[x] = (sum[x] + val) % moD;       return;     }     long long xm = (xl + xr) >> 1;     shift(x);     if (idx < xm)       add(idx, val, x << 1, xl, xm);     else       add(idx, val, x << 1 | 1, xm, xr);     merge(x);   }   void mult(long long ql, long long qr, long long qv, long long x = 1,             long long xl = 0, long long xr = n) {     if (xl >= qr || xr <= ql) return;     if (ql <= xl && qr >= xr) {       sum[x] = sum[x] * qv % moD;       laz[x] = laz[x] * qv % moD;       mul[x] = mul[x] * qv % moD;       return;     }     shift(x);     long long xm = (xl + xr) >> 1;     mult(ql, qr, qv, x << 1, xl, xm);     mult(ql, qr, qv, x << 1 | 1, xm, xr);     merge(x);   }   long long get_mul(long long idx, long long x = 1, long long xl = 0,                     long long xr = n) {     if (xr - xl == 1) return mul[x];     long long xm = (xl + xr) >> 1;     shift(x);     if (idx < xm) return get_mul(idx, x << 1, xl, xm);     return get_mul(idx, x << 1 | 1, xm, xr);   }   long long get_sum(long long ql, long long qr, long long x = 1, long long xl = 0,                     long long xr = n) {     if (xl >= qr || xr <= ql) return 0;     if (ql <= xl && qr >= xr) return sum[x];     long long xm = (xl + xr) >> 1;     shift(x);     long long res = 0;     res += get_sum(ql, qr, x << 1, xl, xm);     res += get_sum(ql, qr, x << 1 | 1, xm, xr);     return res % moD;   }   long long inv(long long x) { return wop(x, moD - 2); }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long q;     cin >> val[0] >> q;     que.resize(q);     for (long long i = 0; i < q; ++i) {       cin >> que[i].t >> que[i].x;       que[i].x--;       if (que[i].t == 1) {         n++;         cin >> que[i].y;         chi[que[i].x].push_back(n);         val[n] = que[i].y;       }     }     n++;     for (long long i = 0; i < segN; ++i) laz[i] = mul[i] = 1;     dfs(0);     mul[0] = deg[0] = 1;     add(st[0], val[0]);     long long c = 0;     for (long long i = 0; i < q; ++i) {       long long v = que[i].x;       if (que[i].t == 1) {         c++;         deg[c] = 1;         mult(st[v], fi[v], inv(deg[v]) * (deg[v] + 1) % moD);         deg[v]++;         add(st[c], val[c] * get_mul(st[c]) % moD);       } else         cout << get_sum(st[v], fi[v]) * inv(get_mul(st[v])) % moD * deg[v] % moD              <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       string s, t;       cin >> s >> t;       vector<int> v, c;       for (int i = 1; i < n; i++) {         if (s[i] != s[i - 1]) v.push_back(i);       }       if (s[n - 1] != t[n - 1]) v.push_back(n);       for (int i = 1; i < n; i++) {         if (t[i] != t[i - 1]) c.push_back(i);       }       reverse(c.begin(), c.end());       cout << (int)v.size() + (int)c.size() <<    ;       for (int val : v) cout << val <<    ;       for (int val : c) cout << val <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LIM = 5e+5 + 10;   int sz[LIM];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> sz[i];     sort(sz, sz + n);     int pairs = 0;     int l = 0;     int lb = n / 2 + (n % 2);     int r = lb;     int rb = n;     while (l < lb && r < rb) {       if (sz[l] * 2 <= sz[r]) {         ++pairs;         ++l;         ++r;       } else {         ++r;       }     }     cout << n - pairs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (auto &x : v) in >> x;     return in;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {     out <<  [  << p.first <<  ,   << p.second <<  ]          <<   n ;     return out;   }   inline int gc() {     static const int BUF = 1e7;     static char buf[BUF], *bg = buf + BUF, *ed = bg;     if (bg == ed) fread(bg = buf, 1, BUF, stdin);     return *bg++;   }   inline int ri() {     int x = 0, f = 1, c = gc();     for (; c < 48 || c > 57; f = c ==  -  ? -1 : f, c = gc())       ;     for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc())       ;     return x * f;   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const long long ONE = 1;   const int maxN = 2e5 + 7;   int n, m, k, ans;   int a[maxN], sumA[2007];   pair<int, int> offers[maxN];   map<int, int> mii;   int dp[2007];   int getSum(int x, int y) {     if (x > y) return 0;     return sumA[y] - sumA[x - 1];   }   inline bool cmp1(const pair<int, int> &x, const pair<int, int> &y) {     return x.first < y.first;   }   inline bool cmp2(const pair<int, int> &x, const pair<int, int> &y) {     return x.first - x.second < y.first - y.second;   }   void CompletePack(int cost, int weight) {     for (int i = (cost); i <= (k); ++i) {       int x = dp[i - cost] + getSum(i - (cost - weight) + 1, i);       dp[i] = min(dp[i], x);     }   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     cin >> n >> m >> k;     for (int i = (1); i <= (n); ++i) cin >> a[i];     for (int i = (1); i <= (m); ++i) {       cin >> offers[i];       if (offers[i].first > k) {         --m;         --i;       } else if (mii.find(offers[i].first) != mii.end()) {         offers[mii[offers[i].first]].second =             max(offers[mii[offers[i].first]].second, offers[i].second);         --m;         --i;       } else {         mii[offers[i].first] = i;       }     }     sort(a + 1, a + n + 1);     n = k;     for (int i = (1); i <= (n); ++i) {       dp[i] = dp[i - 1] + a[i];       sumA[i] = dp[i];     }     sort(offers + 1, offers + m + 1, cmp1);     for (int i = (1); i <= (m); ++i) {       CompletePack(offers[i].first, offers[i].second);     }     sort(offers + 1, offers + m + 1, cmp2);     for (int i = (1); i <= (m); ++i) {       CompletePack(offers[i].first, offers[i].second);     }     cout << dp[k] << endl;     return 0;   }


#include<iostream>   #include<bits/stdc++.h>      using namespace std;      #define ll long long   #define pb push_back   #define mp make_pair   #define ff first   #define ss second   #define MOD 1000000007      // void func(){      // }      void solution(){     ll a,b; cin>>a>>b;     ll val = abs(a-b);     if(val==0){       cout<< 0 0 <<endl;       return;     }     ll count = min(val-(a%val),a%val);     cout<<val<<   <<count<<endl;   }      int main(){        ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);        #ifndef ONLINE_JUDGE     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);     #endif        int t;     cin>>t;     // func();     while(t--){       solution();     }        return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nm = 100010;   int n, k;   long long x[nm], y[nm];   set<pair<long long, int> > ngang, doc;   vector<int> xoa1, xoa2, xoa3, xoa4;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       x[i] = a + c;       y[i] = b + d;       ngang.insert(make_pair(y[i], i));       doc.insert(make_pair(x[i], i));     }     long long res = LONG_LONG_MAX;     for (int a = 0; a <= k; ++a) {       for (int i = 1; i <= a; ++i) {         int u = ngang.begin()->second;         xoa1.push_back(u);         ngang.erase(ngang.begin());         doc.erase(make_pair(x[u], u));       }       for (int b = 0; a + b <= k; ++b) {         for (int i = 1; i <= b; ++i) {           multiset<pair<long long, int> >::iterator it = ngang.end();           it--;           int u = it->second;           xoa2.push_back(u);           ngang.erase(it);           doc.erase(make_pair(x[u], u));         }         for (int c = 0; a + b + c <= k; ++c) {           for (int i = 1; i <= c; ++i) {             int u = doc.begin()->second;             xoa3.push_back(u);             doc.erase(doc.begin());             ngang.erase(make_pair(y[u], u));           }           int d = k - a - b - c;           for (int i = 1; i <= d; ++i) {             multiset<pair<long long, int> >::iterator it = doc.end();             it--;             int u = it->second;             xoa4.push_back(u);             doc.erase(it);             ngang.erase(make_pair(y[u], u));           }           multiset<pair<long long, int> >::iterator it = ngang.end();           it--;           long long A = it->first - ngang.begin()->first;           if (A & 1) A++;           if (A == 0) A = 2;           it = doc.end();           it--;           long long B = it->first - doc.begin()->first;           if (B & 1) B++;           if (B == 0) B = 2;           res = min(res, A * B);           for (int i = int(xoa4.size()) - 1; i >= 0; --i) {             int u = xoa4[i];             xoa4.pop_back();             doc.insert(make_pair(x[u], u));             ngang.insert(make_pair(y[u], u));           }           for (int i = int(xoa3.size()) - 1; i >= 0; --i) {             int u = xoa3[i];             xoa3.pop_back();             doc.insert(make_pair(x[u], u));             ngang.insert(make_pair(y[u], u));           }         }         for (int i = int(xoa2.size()) - 1; i >= 0; --i) {           int u = xoa2[i];           xoa2.pop_back();           doc.insert(make_pair(x[u], u));           ngang.insert(make_pair(y[u], u));         }       }       for (int i = int(xoa1.size()) - 1; i >= 0; --i) {         int u = xoa1[i];         xoa1.pop_back();         doc.insert(make_pair(x[u], u));         ngang.insert(make_pair(y[u], u));       }     }     printf( %I64d n , res / 4);   }


#include <bits/stdc++.h>   using namespace std;   int used[111111];   multiset<int> g[111111];   multiset<int> vertex;   vector<int> ans;   void dfs(int v) {     used[v] = 1;     vertex.erase(v);     ans.push_back(v);     for (auto i = g[v].begin(); i != g[v].end(); ++i)       if (!used[*i]) vertex.insert(*i);     if (vertex.size()) dfs(*vertex.begin());   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       g[x - 1].insert(y - 1);       g[y - 1].insert(x - 1);     }     dfs(0);     for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 <<    ;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   char a[N], b[N];   string arrange(string s) {     int n = s.size();     if (n & 1)       return s;     else {       int m = n / 2;       string s1 = s.substr(0, m), s2 = s.substr(m, m);       s1 = arrange(s1);       s2 = arrange(s2);       if (s1.compare(s2) <= 0)         return s1 + s2;       else         return s2 + s1;     }   }   int main() {     scanf( %s , a);     scanf( %s , b);     const char *ans = arrange(a) == arrange(b) ?  YES  :  NO ;     printf( %s n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a[2 * 100010] = {0};   int check(int x, int n) {     if (x == 1) return 0;     int cur = 0, ans = 0;     while (cur < a[n - 1]) {       cur += x;       int pos = lower_bound(a, a + n, cur) - a;       if (pos > 0 && a[pos - 1] >= x) ans = max(ans, a[pos - 1] % x);     }     return ans;   }   int Solve(int n) {     int ans = 0, m = 1;     sort(a, a + n);     for (int i = 1; i < n; i++)       if (a[m - 1] != a[i]) a[m++] = a[i];     for (int i = 0; i < m; i++) ans = max(ans, check(a[i], m));     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     printf( %d n , Solve(n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7f7f7f7f;   int BigMod(long long int B, long long int P, long long int M) {     long long int R = 1;     while (P > 0) {       if (P % 2 == 1) R = (R * B) % M;       P /= 2;       B = (B * B) % M;     }     return (int)R;   }   long long int maxDivide(long long int a, long long int b) {     while (a % b == 0) a = a / b;     return a;   }   long long int isUgly(long long int no) {     no = maxDivide(no, 2);     no = maxDivide(no, 3);     no = maxDivide(no, 5);     return (no == 1) ? 1 : 0;   }   long long int myXOR(long long int x, long long int y) {     long long int res = 0;     for (long long int i = 31; i >= 0; i--) {       bool b1 = x & (1 << i);       bool b2 = y & (1 << i);       bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);       res <<= 1;       res |= xoredBit;     }     return res;   }   long long int ar[110];   int main() {     long long int n, m, a, b, c, x, y;     cin >> n >> m;     x = 0;     for (long long int i = 1; i <= n; i++) {       cin >> ar[i];     }     y = 0;     for (long long int i = 1; i <= m; i++) {       cin >> a >> b;       x = 0;       for (long long int j = a; j <= b; j++) {         x += ar[j];       }       if (x > 0) y += x;     }     cout << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       int s, v1, v2, t1, t2;       cin >> s >> v1 >> v2 >> t1 >> t2;       int time1, time2;       time1 = (s * v1) + (2 * t1);       time2 = (s * v2) + (2 * t2);       if (time1 < time2)         cout <<  First  << endl;       else if (time2 < time1)         cout <<  Second  << endl;       else         cout <<  Friendship  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int N = 1e6 + 20;   vector<int> v[N];   map<int, int> mp, ml, mr;   long long n, m, k, a[N], b[N], f[N];   int num[N];   long long did[N];   string s;   long long s1, s2, ans, flag, tot, t, sum;   int cnt;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     long long x;     for (int i = 0; i < m; i++) {       cin >> x;       if (x == 0) return cout << -1, 0;       did[x] = 1;     }     for (int i = 1; i <= k; i++) cin >> a[i];     int cnt = 0;     for (int i = 0; i <= n; i++) {       if (did[i])         num[i] = num[i - 1] + 1;       else         num[i] = 0;       cnt = max(cnt, num[i]);     }     long long ans = inf;     for (int i = cnt + 1; i <= k; i++) {       long long sum = 0;       for (int j = 0; j < n; j += i) {         if (did[j]) {           j -= num[j];         }         sum++;       }       ans = min(ans, a[i] * sum);     }     if (ans >= inf)       cout << -1;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, q, t, x, y, b, c, d;   string s1, s2;   long long a[3];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s1 >> s2;       int l1 = s1.length();       int l2 = s2.length();       int j = 0, k = 0;       int ok = 1;       int lastok = -1;       while (j < l1 && k < l2) {         if (s1[j] == s2[k]) {           j++;           k++;           lastok++;         } else if (k && s2[k] == s2[k - 1]) {           int tmp = k;           while (tmp < l2 && s2[tmp] == s2[k]) tmp++;           if (tmp == l2) {             ok = 0;             break;           }           lastok = tmp - 1;           k = tmp;         } else if (lastok == k - 1) {           ok = 0;           break;         }       }       if (j < l1) ok = 0;       while (k < l2) {         if (k && s2[k] != s2[k - 1]) {           ok = 0;           break;         }         k++;       }       cout << (ok ?  YES  :  NO ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010;   int n, m;   int pos[maxn];   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   inline void read(int &k) {     int f = 1;     k = 0;     char c = getchar();     while (c <  0  || c >  9 ) c ==  -  && (f = -1), c = getchar();     while (c <=  9  && c >=  0 ) k = k * 10 + c -  0 , c = getchar();     k *= f;   }   bool check(int i, int j) {     int x = (i - 1) / m + 1, y = (i - 1) % m + 1, x2 = (j - 1) / m + 1,         y2 = (j - 1) % m + 1;     for (int k = 0; k < 4; k++)       if (x + dx[k] == x2 && y + dy[k] == y2) return 1;     return 0;   }   bool dfs(int i) {     if (i == n * m + 1) return 1;     int x = (i - 1) / m + 1, y = (i - 1) % m + 1;     for (int j = i; j <= n * m; j++) {       swap(pos[i], pos[j]);       if (x != 1 && check(pos[i], pos[(x - 2) * m + y])) continue;       if (y != 1 && check(pos[i], pos[(x - 1) * m + y - 1])) continue;       if (dfs(i + 1)) return 1;       swap(pos[i], pos[j]);     }     return 0;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) pos[(i - 1) * m + j] = (i - 1) * m + j;     if (!dfs(1)) return puts( NO ), 0;     puts( YES );     for (int i = 1; i <= n; i++, puts(  ))       for (int j = 1; j <= m; j++) printf( %d  , pos[(i - 1) * m + j]);   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, -1, 1};   int dy[] = {1, -1, 0, 0};   int main() {     int n;     char mp[100][100];     cin >> n;     for (int i = 0; i < n; ++i) cin >> mp[i];     auto isin = [&](int x) { return x >= 0 && x < n; };     auto isok = [&](int x, int y) {       for (int i = 0; i < 4; ++i) {         if (isin(x + dx[i]) && isin(y + dy[i])) {           if (mp[x + dx[i]][y + dy[i]] !=  . ) return 0;         } else           return 0;       }       mp[x][y] =  # ;       for (int i = 0; i < 4; ++i) {         mp[x + dx[i]][y + dy[i]] =  # ;       }       return 1;     };     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (mp[i][j] ==  . ) {           isok(i, j);         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (mp[i][j] ==  . ) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   vector<int> adj[N];   bool visited[N];   bool reach[N];   pair<int, int> has[N];   int cnt = 0;   void dfs(int s) {     if (!visited[s]) {       visited[s] = 1;       reach[s] = 1;       for (int i = 0; i < adj[s].size(); i++) {         dfs(adj[s][i]);       }     }   }   void dfs2(int s, int a) {     if (!visited[s]) {       visited[s] = 1;       if (reach[s] == 0) has[a].first++;       for (int i = 0; i < adj[s].size(); i++) {         dfs2(adj[s][i], a);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, s;     cin >> n >> m >> s;     s--;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);     }     dfs(s);     for (int i = 0; i < n; i++) {       has[i].second = i;     }     for (int i = 0; i < n; i++) {       if (!reach[i]) {         memset(visited, 0, sizeof(visited));         dfs2(i, i);       }     }     sort(has, has + N);     reverse(has, has + N);     int ans = 0;     cnt = 0;     memset(visited, 0, sizeof(visited));     for (int i = 0; i < n; i++) {       if (!reach[has[i].second]) {         dfs(has[i].second);         memset(visited, 0, sizeof(visited));         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<unsigned long long> v;     char x2[] =  47 ;     do {       v.push_back(stoi(x2));     } while (next_permutation(x2, x2 + 2));     char x4[] =  4477 ;     do {       v.push_back(stoi(x4));     } while (next_permutation(x4, x4 + 4));     char x6[] =  444777 ;     do {       v.push_back(stoi(x6));     } while (next_permutation(x6, x6 + 6));     char x8[] =  44447777 ;     do {       v.push_back(stoi(x8));     } while (next_permutation(x8, x8 + 8));     v.push_back(4444477777);     sort(v.begin(), v.end());     string s;     cin >> s;     unsigned long long q = stoi(s);     if (q <= v[0]) {       cout << v[0];       return 0;     } else       for (int i = 0; i < v.size() - 1; i++)         if (q == v[i + 1] || (q > v[i] && q < v[i + 1])) {           cout << v[i + 1];           return 0;         }     cout << v[98];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100][1000] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x, y;       cin >> n >> m >> x >> y;       for (long long int i = 1; i <= n; i++) {         for (long long int j = 1; j <= m; j++) {           cin >> a[i][j];         }       }       long long int ans = 0;       for (long long int i = 1; i <= n; i++) {         for (long long int j = 1; j <= m; j++) {           if (a[i][j] ==  . ) {             long long int pos = j;             for (long long int k = j; k <= m; k++) {               if (a[i][k] ==  . ) {                 pos = k;               } else {                 break;               }             }             long long int temp = pos - j + 1;             ans += min(temp * x, (temp / 2) * y + x * (temp % 2 == 1));             j = pos;           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int inf = int(1e9);   const int mod = inf + 7;   const double PI = acos(-1.0);   using namespace std;   const int N = 1e5 + 155;   template <typename T>   inline void read(T& x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   string toForm(char c, bool ok) {     string ans =   ;     ans += char(60);     if (!ok) ans += char(47);     ans += (c);     ans += char(62);     return ans;   }   void solve() {     string s;     cin >> s;     int cnt = 0;     for (int i = 1; i < s.size(); i++) {       if (s[i] !=  <  && s[i] !=  >  && s[i] !=  / ) {         if (s[i - 1] !=  / ) {           for (int i = 0; i < cnt; ++i) cout <<     ;           cout << toForm(s[i], true);           cout <<   n ;           cnt++;         } else {           for (int i = 0; i < cnt - 1; ++i) cout <<     ;           cout << toForm(s[i], false);           cout <<   n ;           cnt--;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 111111;   const int oo = (int)(1e9);   int MOD = 1000000007;   const long double PI = 3.141592653589793;   template <typename TT>   void read(TT &x) {     char ch;     for (ch = getchar(); ch >  9  || ch <  0 ; ch = getchar())       ;     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;   }   vector<pair<int, int> > A[2];   int n, a[111111], v[111111], nt[111111];   void work(vector<pair<int, int> > &B, vector<pair<int, int> > &C) {     C.clear();     sort(B.begin(), B.end());     for (int i = B.size() - 1; i >= 0; i--) {       int x = B[i].first, y = B[i].second;       if (v[x] + v[y] > 0) continue;       v[y] = 1;       while (v[nt[x]]) nt[x] = nt[nt[x]];       if (nt[x] < n && a[x] > a[nt[x]]) C.push_back(make_pair(x, nt[x]));     }   }   void Init() {     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     ;     for (int i = 0; i < n; i++) {       nt[i] = i + 1;       if (nt[i] < n && a[i] > a[nt[i]]) A[0].push_back(make_pair(i, nt[i]));     }     int k = 0, ans = 0;     memset(v, 0, sizeof(v));     ;     while (A[k].size()) {       ans++;       work(A[k], A[1 - k]);       k = 1 - k;     }     printf( %d , ans);     ;   }   int main() {     Init();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 15;   vector<int> g[N];   int n, m, b[N], r[N], a[N], res;   void dfs(int v, int pa) {     if (a[v] == 1)       r[v]++;     else if (a[v] == 2)       b[v]++;     for (int i : g[v]) {       if (i == pa) continue;       dfs(i, v);       b[v] += b[i];       r[v] += r[i];     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0, -1);     for (int i = 1; i < n; i++) {       if (b[i] && r[i]) continue;       int blue = b[0] - b[i], red = r[0] - r[i];       if (((!blue) && red) || (blue && (!red))) {         res++;       }     }     cout << res << endl;   }