#include <bits/stdc++.h>   using namespace std;   struct tri {     tri(int x = 0, int y = 0, int z = 0) { a = x, b = y, c = z; }     int a, b, c;   } par[101][101][101];   char col[101][101];   string h[101];   int d[101][101][101];   queue<tri> q;   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     if (a == b || b == c || a == c) {       cout << -1;       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> h[i];       for (int j = 1; j <= n; j++) col[i][j] = h[i][j - 1];     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++) d[i][j][k] = 1e9;     d[a][b][c] = 0;     q.push(tri(a, b, c));     while (!q.empty()) {       tri cu = q.front();       q.pop();       int dis = d[cu.a][cu.b][cu.c];       int tmp[] = {cu.a, cu.b, cu.c};       sort(tmp, tmp + 3);       int A = tmp[0], B = tmp[1], C = tmp[2];       if (A == 1 && B == 2 && C == 3) {         cout << dis << endl;         vector<pair<int, int> > m;         for (int i = dis; i > 0; i--) {           tri pare = par[cu.a][cu.b][cu.c];           if (pare.a != cu.a) m.push_back(make_pair(pare.a, cu.a));           if (pare.b != cu.b) m.push_back(make_pair(pare.b, cu.b));           if (pare.c != cu.c) m.push_back(make_pair(pare.c, cu.c));           cu = pare;         }         for (int i = dis - 1; i >= 0; i--)           cout << m[i].first <<     << m[i].second << endl;         return 0;       }       A = cu.a, B = cu.b, C = cu.c;       for (int i = 1; i <= n; i++) {         if (i != A && i != B && i != C) {           if (d[i][B][C] == 1e9 && col[A][i] == col[B][C]) {             par[i][B][C] = tri(A, B, C);             d[i][B][C] = dis + 1;             q.push(tri(i, B, C));           }           if (d[A][i][C] == 1e9 && col[B][i] == col[A][C]) {             par[A][i][C] = tri(A, B, C);             d[A][i][C] = dis + 1;             q.push(tri(A, i, C));           }           if (d[A][B][i] == 1e9 && col[C][i] == col[A][B]) {             par[A][B][i] = tri(A, B, C);             d[A][B][i] = dis + 1;             q.push(tri(A, B, i));           }         }       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                            {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   const long long INF = 1000000000000000000;   struct SEG {     int siz = 1 << 19;     long long s[1 << 20];     long long t[1 << 20];     void init() {       for (int i = 0; i < 2 * siz - 1; i++) {         s[i] = 0;         t[i] = 0;       }     }     void add(int a, int b, long long x, int k, int l, int r) {       if (b <= l || r <= a) return;       if (a <= l && r <= b) {         s[k] += x;         t[k] += x;         return;       }       add(a, b, x, 2 * k + 1, l, (l + r) / 2);       add(a, b, x, 2 * k + 2, (l + r) / 2, r);       s[k] = min(s[2 * k + 1], s[2 * k + 2]) + t[k];     }     long long query(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return INF;       if (a <= l && r <= b) return s[k];       long long chl = query(a, b, 2 * k + 1, l, (l + r) / 2);       long long chr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return min(chl, chr) + t[k];     }   } seg;   int main() {     static int n, q;     static int p[500010];     static long long w[500010];     static int v[500010], l[500010], r[500010];     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++) {       scanf( %d%lld , &p[i], &w[i]);     }     for (int i = 0; i < q; i++) scanf( %d%d%d , &v[i], &l[i], &r[i]);     static int R[500010];     for (int i = 1; i <= n; i++) R[i] = i;     for (int i = n; i >= 2; --i) {       R[p[i]] = max(R[p[i]], R[i]);     }     seg.init();     static int cnt[500010] = {};     for (int i = 1; i <= n; i++) {       cnt[p[i]]++;     }     static long long d[500010];     d[1] = 0;     seg.add(1, 2, INF, 0, 0, seg.siz);     for (int i = 2; i <= n; i++) {       d[i] = d[p[i]] + w[i];       seg.add(i, i + 1, cnt[i] == 0 ? d[i] : INF, 0, 0, seg.siz);     }     static vector<pair<pair<int, int>, pair<int, int> > > Que;     for (int i = 0; i < q; i++)       Que.push_back(pair<pair<int, int>, pair<int, int> >(           pair<int, int>(v[i], i), pair<int, int>(l[i], r[i])));     sort(Que.begin(), Que.end());     static long long ans[500010];     int k = 0;     for (int i = 1; i <= n; i++) {       while (k < Que.size() && Que[k].first.first == i) {         ans[Que[k].first.second] = seg.query(             Que[k].second.first, Que[k].second.second + 1, 0, 0, seg.siz);         k++;       }       if (i == n) break;       int loc = i;       while (loc != p[i + 1]) {         seg.add(0, seg.siz, -w[loc], 0, 0, seg.siz);         seg.add(loc, R[loc] + 1, 2 * w[loc], 0, 0, seg.siz);         loc = p[loc];       }       seg.add(0, seg.siz, w[i + 1], 0, 0, seg.siz);       seg.add(i + 1, R[i + 1] + 1, -2 * w[i + 1], 0, 0, seg.siz);     }     for (int i = 0; i < q; i++) {       printf( %lld n , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 4e5 + 400;   int prime[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,                  43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101,                  103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,                  173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,                  241, 251, 257, 263, 269, 271, 277, 281, 283, 293};   long long poww(long long a, long long b) {     long long res = 1;     long long base = a;     while (b) {       if (b & 1) {         res *= base;         res %= mod;       }       base *= base;       base %= mod;       b >>= 1;     }     return res;   }   struct node {     int l, r;     long long mul;     long long p;     long long lazy;     long long lazy2;   } Node[maxn << 2];   void build(int l, int r, int step) {     Node[step].l = l;     Node[step].r = r;     Node[step].mul = Node[step].lazy = 1;     Node[step].p = Node[step].lazy2 = 0;     if (l == r) return;     build(l, (l + r) >> 1, step << 1);     build(((l + r) >> 1) + 1, r, step << 1 | 1);   }   void push_up(int step) {     Node[step].mul = Node[step << 1].mul * Node[step << 1 | 1].mul % mod;     Node[step].p = Node[step << 1].p | Node[step << 1 | 1].p;   }   void push_down(int step) {     if (Node[step].lazy != 1) {       Node[step << 1].lazy = Node[step << 1].lazy * Node[step].lazy % mod;       Node[step << 1].mul =           Node[step << 1].mul *           poww(Node[step].lazy, (Node[step << 1].r - Node[step << 1].l + 1)) %           mod;       Node[step << 1 | 1].lazy = Node[step << 1 | 1].lazy * Node[step].lazy % mod;       Node[step << 1 | 1].mul =           Node[step << 1 | 1].mul *           poww(Node[step].lazy,                (Node[step << 1 | 1].r - Node[step << 1 | 1].l + 1)) %           mod;       Node[step].lazy = 1;     }     if (Node[step].lazy2) {       Node[step << 1].lazy2 |= Node[step].lazy2;       Node[step << 1].p |= Node[step].lazy2;       Node[step << 1 | 1].lazy2 |= Node[step].lazy2;       Node[step << 1 | 1].p |= Node[step].lazy2;       Node[step].lazy2 = 0;     }   }   void update(int l, int r, int step, long long val) {     if (Node[step].l == l && Node[step].r == r) {       Node[step].mul = Node[step].mul * poww(val, (r - l + 1)) % mod;       int vval = val;       for (int i = 0; prime[i]; i++) {         while (vval % prime[i] == 0) {           Node[step].p |= (1ll << i);           Node[step].lazy2 |= (1ll << i);           vval /= prime[i];         }         if (vval == 1) break;       }       Node[step].lazy = Node[step].lazy * val % mod;       return;     }     push_down(step);     int mid = (Node[step].l + Node[step].r) >> 1;     if (mid >= r)       update(l, r, step << 1, val);     else if (mid < l)       update(l, r, step << 1 | 1, val);     else {       update(l, mid, step << 1, val);       update(mid + 1, r, step << 1 | 1, val);     }     push_up(step);   }   long long qqq = 0;   long long query(int l, int r, int step) {     if (Node[step].l == l && Node[step].r == r) {       long long val = Node[step].p;       long long res = 1;       qqq |= val;       res = res * Node[step].mul % mod;       return res;     }     push_down(step);     int mid = (Node[step].l + Node[step].r) >> 1;     if (mid >= r)       return query(l, r, step << 1);     else if (mid < l)       return query(l, r, step << 1 | 1);     else {       return (query(l, mid, step << 1) * query(mid + 1, r, step << 1 | 1)) % mod;     }   }   int n, q;   int main() {     scanf( %d%d , &n, &q);     build(1, n, 1);     for (int i = 1; i <= n; i++) {       long long a;       scanf( %lld , &a);       update(i, i, 1, a);     }     while (q--) {       char ss[20];       scanf( %s , ss);       if (ss[0] ==  M ) {         int l, r;         long long val;         scanf( %d%d%lld , &l, &r, &val);         update(l, r, 1, val);       } else {         int l, r;         scanf( %d%d , &l, &r);         qqq = 0;         long long ans = query(l, r, 1);         int tot = 0;         while (qqq) {           if (qqq & 1) {             ans *= (1 - poww(prime[tot], mod - 2));             ans %= mod;           }           qqq >>= 1;           tot++;         }         ans %= mod;         ans += mod;         ans %= mod;         printf( %lld n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 998244353;   long long power(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   long long add(long long a, long long b) { return (a % mod + b % mod) % mod; }   long long mul(long long a, long long b) { return (a % mod * b % mod) % mod; }   long long n, k;   const long long K = 210;   vector<long long> a(N);   vector<long long> b(N);   multiset<long long> st;   long long pow2[N];   void power_2() {     pow2[0] = 1;     long long x = 1;     long long cnt = 1;     while (cnt < 3e5) {       pow2[cnt] = mul(pow2[cnt - 1], 2);       cnt++;     }   }   int32_t main() {     long long nx, mx;     cin >> nx >> mx;     string s, t;     cin >> s >> t;     power_2();     long long temp = 0, ans = 0;     long long n = min(s.size(), t.size());     for (long long i = 0; i < mx; i++) {       if (i < nx and s[nx - i - 1] ==  1 ) temp = add(temp, pow2[i]);       if (t[mx - i - 1] ==  1 ) ans = add(ans, temp);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long n, m;   long long a[maxn], b[maxn];   bool cmp(long long a, long long b) { return a > b; }   int main() {     scanf( %lld %lld , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= m; i++) scanf( %lld , &b[i]);     sort(a + 1, a + n + 1, cmp);     sort(b + 1, b + m + 1, cmp);     if (a[1] > b[m]) {       cout << -1 << endl;       return 0;     }     long long ans = a[1], t = m - 1, bj = 1;     for (int i = 1; i <= m; i++) {       if (b[i] == a[1]) continue;       if (t == 0) {         bj++;         ans += a[bj];         t = m - 1;       }       ans += b[i];       t--;     }     for (int i = n; i > bj; i--) ans += (a[i] * m);     ans += t * a[bj];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, l;     cin >> k;     vector<int> a[k];     for (int i = 0; i < k; i++)       for (int j = 0; j < k; j++) cin >> l, a[i].push_back(l);     l = 0;     for (int i = 0; i < k; i++) l += a[k / 2][i];     for (int i = 0; i < k; i++) l += a[i][k / 2];     for (int i = 0; i < k; i++) l += a[i][i];     for (int i = 0; i < k; i++) l += a[i][k - i - 1];     cout << l - (3 * (a[k / 2][k / 2]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void fast_scan(T &number);   template <typename T>   inline void fast_scan(T *nums, size_t size);   size_t fast_scan_line(char *chars, size_t size);   size_t fast_scan_word(char *chars, size_t size);   inline void fast_write(int num);   inline void fast_write(char *str);   int comp_double(double a, double b);   vector<string> string_split(char *str, char *delimiter);   int n, m;   int p[101][2];   bool used[101];   unsigned int ex = 0;   void dfs(int c_node, int p_node, int &c) {     int *enemies = p[c_node];     if (used[c_node] || c_node == 0) return;     used[c_node] = true;     c++;     if (enemies[0] != p_node) {       if (used[enemies[0]] && enemies[1] == p_node) {         if (c & 1) {           ex++;         }       } else {         dfs(enemies[0], c_node, c);       }     }     if (enemies[1] != p_node) {       if (used[enemies[1]] && enemies[0] == p_node) {         if (c & 1) {           ex++;         }       } else {         dfs(enemies[1], c_node, c);       }     }   }   void read() {     fast_scan(n);     fast_scan(m);     int t1, t2;     for (int i = 0; i < m; ++i) {       fast_scan(t1);       fast_scan(t2);       if (p[t1][0] == 0) {         p[t1][0] = t2;       } else {         p[t1][1] = t2;       }       if (p[t2][0] == 0) {         p[t2][0] = t1;       } else {         p[t2][1] = t1;       }     }   }   void solve() {     for (int i = 1; i < n + 1; ++i) {       int c = 0;       dfs(i, 0, c);     }     if ((n - ex) & 1) {       cout << (ex + 1);     } else {       cout << ex;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     read();     solve();     return 0;   }   size_t fast_scan_word(char *chars, size_t size) {     char temp;     for (int i = 0; i < size; ++i) {       temp = (char)getchar();       if (temp ==   n  || temp ==     || temp ==   0 ) return i;       chars[i] = temp;     }   }   size_t fast_scan_line(char *chars, size_t size) {     char temp;     for (int i = 0; i < size; ++i) {       temp = (char)getchar();       if (temp ==   n  || temp ==   0 ) return i;       chars[i] = temp;     }   }   template <typename T>   void fast_scan(T &number) {     bool negative = false;     int c;     number = 0;     c = getchar();     if (c ==  - ) {       negative = true;       c = getchar();     }     for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;     if (negative) number *= -1;   }   template <typename T>   inline void fast_scan(T *nums, size_t size) {     for (size_t i = 0; i < size; ++i) fast_scan(nums[i]);   }   inline void fast_write(int num) {     int N = num, rev, count = 0;     rev = N;     if (N == 0) {       putchar( 0 );       putchar(  n );       return;     }     if (N < 0) {       putchar( - );       N *= -1;     }     while ((rev % 10) == 0) {       count++;       rev /= 10;     }     rev = 0;     while (N != 0) {       rev = (rev << 3) + (rev << 1) + N % 10;       N /= 10;     }     while (rev != 0) {       putchar(rev % 10 +  0 );       rev /= 10;     }     while (count--) putchar( 0 );   }   inline void fast_write(char *str) {     for (int i = 0; str[i]; i++) putchar(str[i]);   }   int comp_double(double a, double b) {     if (abs(a - b) <= 1e-9) return 0;     return a < b ? -1 : 1;   }   vector<string> string_split(char *str, char *delimiter) {     vector<string> tokens;     char *token = strtok(str, delimiter);     while (token != nullptr) {       tokens.emplace_back(token);       token = strtok(nullptr, delimiter);     }     return tokens;   }   vector<string> split(const string &s, char delimiter) {     vector<string> tokens;     string token;     istringstream tokenStream(s);     while (getline(tokenStream, token, delimiter)) {       tokens.push_back(token);     }     return tokens;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a != 0 && b != 0) {       if (a > b) {         a %= b;       } else if (a < b) {         b %= a;       } else {         return a;       }     }     return a + b;   }   long long divS(long long a) {     long long res = 0;     while (a > 0) {       res += a % 10;       a /= 10;     }     return res;   }   int distToSym(char a, char b) {     if (abs(int(a) - int(b)) <= 13)       return abs(int(a) - int(b));     else       return (26 % abs(int(a) - int(b)));   }   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s;     bool v = false, h = false;     for (auto& x : s) {       if (x ==  0 ) {         if (v)           cout <<  1 1 n ;         else           cout <<  3 1 n ;         v = !v;       } else {         if (h)           cout <<  1 1 n ;         else           cout <<  1 3 n ;         h = !h;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4010;   const int MAXT = 1 << 15;   int N, P, Q;   vector<pair<int, int> > qu[MAXT];   vector<pair<int, int> > items[2 * MAXT];   int ans[MAXT];   void update(int a, int b, pair<int, int> v, int cur = 1, int lt = 0,               int rt = MAXT) {     if (rt <= a || b <= lt) {       return;     }     if (a <= lt && rt <= b) {       items[cur].push_back(v);       return;     }     int mid = (lt + rt) / 2;     update(a, b, v, 2 * cur, lt, mid);     update(a, b, v, 2 * cur + 1, mid, rt);   }   int dp[17][MAXN];   void rec(int lt = 0, int rt = MAXT, int cur = 1, int dep = 0) {     if (dep) {       memcpy(dp[dep], dp[dep - 1], sizeof(dp[dep]));     }     for (pair<int, int> p : items[cur]) {       for (int i = MAXN - 1; i >= p.first; i--) {         dp[dep][i] = max(dp[dep][i], dp[dep][i - p.first] + p.second);       }     }     if (rt == lt + 1) {       for (pair<int, int> p : qu[lt]) {         ans[p.second] = dp[dep][p.first];       }     } else {       int mid = (lt + rt) / 2;       rec(lt, mid, 2 * cur, dep + 1);       rec(mid, rt, 2 * cur + 1, dep + 1);     }   }   int main() {     scanf( %d %d , &N, &P);     for (int i = 0; i < N; i++) {       int c, h, t;       scanf( %d %d %d , &c, &h, &t);       update(t, t + P, pair<int, int>(c, h));     }     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int t, b;       scanf( %d %d , &t, &b);       qu[t].push_back(pair<int, int>(b, i));     }     rec();     for (int i = 0; i < Q; i++) {       printf( %d n , ans[i]);     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   using namespace std;   int main() {     int tux;     cin >> tux;     int foo = 0;     int bar = 0;     int baz = 0;     int quz = 1;     for (int i = 0; i < tux; i++) {       int pur;       cin >> pur;       foo = foo + pur;       bar = bar + 1;       if (max(foo * quz, bar * baz) == foo * quz) {         baz = foo;         quz = bar;       }     }     printf( %.10lf n , (double)baz / quz);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 200005;   const int inf = 1234567890;   using namespace std;   int n, a, b;   int main(void) {     cin >> n >> a >> b;     double max_x = -1;     for (int i = ((1) > (n - b) ? (1) : (n - b));          i <= ((n - 1) < (a) ? (n - 1) : (a)); i++) {       double av1 = 1.0 * a / i;       double av2 = 1.0 * b / (n - i);       double cur_x = ((av1) < (av2) ? (av1) : (av2));       max_x = ((max_x) > (cur_x) ? (max_x) : (cur_x));     }     cout << (int)max_x << endl;     return 0;   }


#include <bits/stdc++.h>   static inline void setio(void);   int main(void) {     setio();     long long n;     std::cin >> n;     std::vector<long long> vec(n);     std::vector<char> neg(n);     for (long long i = 0; i < n; ++i) {       std::cin >> vec[i];       if (vec[i] < 0) {         neg[i] = true;         vec[i] = -vec[i];       }     }     std::vector<long long> primes;     std::vector<char> sieve(1000000, true);     for (long long i = 2; i < sieve.size(); ++i) {       if (!sieve[i]) continue;       primes.push_back(i * i);       if (primes.back() > 100000001LL) break;       for (long long j = i + i; j < sieve.size(); j += i) sieve[j] = false;     }     for (auto& num : vec) {       for (const auto& p : primes) {         if (p > num) break;         while (num % p == 0) num /= p;       }     }     for (long long i = 0; i < n; ++i)       if (neg[i]) vec[i] = -vec[i];     std::vector<long long> cnts(n + 1, 0);     std::vector<long long> last_time(n);     std::map<long long, long long> bleh;     for (long long i = 0; i < n; ++i) {       last_time[i] = bleh[vec[i]] - 1;       bleh[vec[i]] = i + 1;     }     bool seen_zero;     for (long long i = 0; i < n; ++i) {       long long count = 0;       seen_zero = false;       for (long long j = i; j < n; ++j) {         count += last_time[j] < i;         seen_zero = seen_zero || vec[j] == 0;         if (count == 1 && seen_zero)           cnts[count]++;         else if (count > 0)           cnts[count - (seen_zero)]++;       }     }     for (long long i = 1; i <= n; ++i) std::cout << cnts[i] <<    ;     std::cout <<   n ;     return 0;   }   static inline void setio(void) {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cout << std::fixed;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long x = max((3 * a) / 10, (a - ((a / 250) * c)));     long long y = max((3 * b) / 10, (b - ((b / 250) * d)));     string s =  Tie ;     if (x > y)       s =  Misha ;     else if (x < y)       s =  Vasya ;     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int seg[(long long int)3e5 * 3];   int laz[(long long int)3e5 * 3];   void build(int index, int a, int b, int *ar) {     if (a == b) {       seg[index] = ar[a];       return;     }     int mid = (a + b) / 2;     build(2 * index, a, mid, ar);     build(2 * index + 1, mid + 1, b, ar);     seg[index] = max(seg[2 * index], seg[2 * index + 1]);   }   void la(int l, int r, int index) {     seg[index] += laz[index];     int a = 2 * index;     int b = 2 * index + 1;     if (l < r) {       laz[a] += laz[index];       laz[b] += laz[index];     }     laz[index] = 0;   }   void upd(int val, int l, int r, int x, int y, int index) {     la(x, y, index);     if (x > r || l > y) return;     if (l <= x and r >= y) {       laz[index] += val;       la(x, y, index);       return;     }     int mid = (x + y) / 2;     upd(val, l, r, x, mid, 2 * index);     upd(val, l, r, mid + 1, y, 2 * index + 1);     seg[index] = max(seg[2 * index], seg[2 * index + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, p;     cin >> n >> m >> p;     vector<pair<int, int>> weap;     vector<pair<int, int>> armr;     vector<pair<int, pair<int, int>>> monst;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       weap.push_back({a, b});     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       armr.push_back({a, b});     }     for (int i = 0; i < p; i++) {       int a, b, c;       cin >> a >> b >> c;       monst.push_back({a, {b, c}});     }     sort(weap.begin(), weap.end());     sort(armr.begin(), armr.end());     sort(monst.begin(), monst.end());     int pt = 0;     int ar[(int)3e5];     for (int i = 0; i < m; i++) ar[i + 1] = -armr[i].second;     build(1, 1, m, ar);     int ans = -2 * (1e9 + 7);     for (int i = 0; i < n; i++) {       while (pt < p and weap[i].first > monst[pt].first) {         int l = upper_bound(armr.begin(), armr.end(),                             make_pair(monst[pt].second.first, (int)1e9 + 7)) -                 armr.begin();         l++;         if (l <= m) {           upd(monst[pt].second.second, l, m, 1, m, 1);         }         pt++;       }       ans = max(ans, (seg[1] - weap[i].second));     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ifstream ff( file.txt );     int n, m;     cin >> n >> m;     map<int, int> Mymap;     int u;     for (int i = 0; i < n; i++) {       cin >> u;       Mymap.insert(pair<int, int>(i + 1, u));     }     unsigned long long sum = 0;     vector<int> v2;     int z;     unsigned int sv;     for (int i = 0; i < m; i++) {       sv = v2.size();       cin >> z;       if (v2.empty()) {         v2.push_back(z);       } else {         for (int j = sv - 1; j >= 0; j--) {           if (v2[j] != z) {             sum += Mymap[v2[j]];           } else {             v2.erase(v2.begin() + j);             v2.push_back(z);             break;           }           if (j == 0) {             v2.push_back(z);           }         }       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long INF = (long)1e09;   int n, m, k, p = 0, id, inv, minv, ans, d = -2;   int main() {     scanf( %d , &n);     if (n == 3) {       cout << 5;       return 0;     }     if (n == 1) {       cout << 1;       return 0;     }     for (m = 3; (m * m + 1) / 2 < n; m += 2)       ;     printf( %d , m);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void getar(T a, int n, int m) {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; ++j) {         scanf( %d , &a[i][j]);       }   }   inline void getar(int *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , a + ii);     }   }   inline void getar(pair<int, int> *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( d , &a[ii].first, &a[ii].second);     }   }   inline void getar(long long *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , a + ii);     }   }   inline void getv(vector<int> &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , &a[ii]);     }   }   inline void getv(vector<long long> &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , &a[ii]);     }   }   inline void getv(vector<pair<int, int> > &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , &a[ii].first, &a[ii].second);     }   }   inline void getv(vector<pair<long long, long long> > &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , &a[ii].first, &a[ii].second);     }   }   inline void getvv(vector<vector<int> > &a, int n, int m) {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; ++j) {         scanf( %d , &a[i][j]);       }   }   inline void printa(int *a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %d  , a[ii]);     }   }   inline void printa(long long *a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %I64d  , a[ii]);     }   }   inline void printv(vector<int> &a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %d  , a[ii]);     }   }   inline void printv(vector<long long> &a, int n, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %I64d  , a[ii]);     }   }   inline long long max(long long a, long long b) { return (a > b) ? a : b; }   inline int max(int a, int b) { return (a > b) ? a : b; }   inline double max(double a, double b) { return (a > b) ? a : b; }   inline long long max(long long a, long long b, long long c) {     return max(a, max(b, c));   }   inline int max(int a, int b, int c) { return max(a, max(b, c)); }   inline double max(double a, double b, double c) { return max(a, max(b, c)); }   inline long long min(long long a, long long b) { return (a < b) ? a : b; }   inline int min(int a, int b) { return (a < b) ? a : b; }   inline double min(double a, double b) { return (a < b) ? a : b; }   inline long long min(long long a, long long b, long long c) {     return min(a, min(b, c));   }   inline int min(int a, int b, int c) { return min(a, min(b, c)); }   inline double min(double a, double b, double c) { return min(a, min(b, c)); }   inline long long pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res *= x;       x *= x;       n >>= 1;     }     return res;   }   inline long long powmod(long long x, long long n, long long _mod) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % _mod;       x = (x * x) % _mod;       n >>= 1;     }     return res;   }   inline long long gcd(long long a, long long b) {     long long t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline int gcd(int a, int b) {     int t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline long long lcm(int a, int b) { return a / gcd(a, b) * (long long)b; }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long gcd(long long a, long long b, long long c) {     return gcd(gcd(a, b), c);   }   inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }   inline long long lcm(long long a, long long b, long long c) {     return lcm(lcm(a, b), c);   }   inline long long lcm(int a, int b, int c) {     return lcm(lcm(a, b), (long long)c);   }   inline int bits_count(int v) {     v = v - ((v >> 1) & 0x55555555);     v = (v & 0x33333333) + ((v >> 2) & 0x33333333);     return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   inline int bits_count(long long v) {     long long t = v >> 32;     long long p = (v & ((1LL << 32) - 1));     return bits_count(t) + bits_count(p);   }   inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }   const char nl =   n ;   string s;   int n, k;   string rgb;   vector<vector<int> > dp;   void intialize_dp() {     for (int i = 0; i < 3; i++)       for (int j = 0; j < k; j++) dp[i][0] += (s[j] != rgb[(j + i) % 3]);   }   void solve() {     rgb =  RGB ;     cin >> n >> k;     cin >> s;     dp = vector<vector<int> >(3, vector<int>(n, 0));     intialize_dp();     bool prev_first, cur_last;     int ans = min(dp[0][0], dp[1][0], dp[2][0]);     for (int i = 0; i < 3; i++)       for (int j = 1; j < n - k + 1; j++) {         prev_first = (s[j - 1] != rgb[(j - 1 + i) % 3]);         cur_last = (s[j + k - 1] != rgb[(j + i + k - 1) % 3]);         dp[(i + j) % 3][j] = dp[(i + j - 1) % 3][j - 1] + cur_last - prev_first;         ans = min(ans, dp[(i + j) % 3][j]);       }     cout << ans << nl;   }   int main() {     clock_t clk = clock();     cerr <<  Hey P.. n ;     int t;     cin >> t;     while (t--) solve();     cerr <<  Look at the sky. n ;     cerr <<  Time (in ms):   << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   long long u, v, w, res;   map<long long, long long> a;   void cal(long long u, long long v, long long w) {     res = 0;     while (u != v) {       if (u < v) swap(u, v);       a[u] += w;       if (w == 0) res += a[u];       u >>= 1;     }   }   int main() {     cin >> n;     while (n-- > 0) {       cin >> p;       if (p == 1) {         cin >> u >> v >> w;         cal(u, v, w);       } else {         cin >> u >> v;         cal(u, v, 0);         cout << res << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long tc = 1;     cin >> tc;     while (tc--) {       long long n;       cin >> n;       set<long long> st;       for (long long i = 0; i < n; i++) {         long long a;         cin >> a;         st.insert(a);       }       if (st.size() > 1)         cout <<  1 n ;       else         cout << n <<   n ;     }   }


#include <bits/stdc++.h>   struct info {     int p, c;   };   bool vis[5010];   int check[10010], level = 1, I[5010], pair[10010], result[5010];   info input[5010];   std::vector<int> graph[10010];   bool dfs(int index) {     check[index] = level;     for (int i = 0; i < graph[index].size(); i++) {       int next = graph[index][i];       if (pair[next] == -1) {         pair[next] = index;         return true;       } else if (check[pair[next]] != level && dfs(pair[next])) {         pair[next] = index;         return true;       }     }     return false;   }   int main(void) {     int n, m, d;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &input[i].p);     for (int i = 1; i <= n; i++) scanf( %d , &input[i].c);     scanf( %d , &d);     for (int i = 1; i <= d; i++) {       scanf( %d , I + i);       vis[I[i]] = true;     }     for (int i = 1; i <= n; i++) {       if (vis[i] == false && input[i].p < m) {         graph[input[i].p].push_back(input[i].c + m - 1);       }     }     memset(pair, -1, sizeof(pair));     int r = 0;     while (r < m && dfs(r)) {       level++;       r++;     }     for (int i = d; i >= 1; i--) {       result[i] = r;       if (input[I[i]].p < m)         graph[input[I[i]].p].push_back(input[I[i]].c + m - 1);       level++;       while (r < m && dfs(r)) {         level++;         r++;       }     }     for (int i = 1; i <= d; i++) printf( %d n , result[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int maxn5 = 5e5 + 10;   const int maxnt = 1.2e6 + 10;   const int maxn3 = 1e3 + 10;   const long long mod = 1e9 + 7;   const long long inf = 2e18;   int st, cmp[maxn5], nxt[maxn5], pre[maxn5];   vector<int> adj[maxn5], ver[maxn5];   bool mark[maxn5];   void join(int a, int b) {     if (ver[a].size() > ver[b].size()) swap(a, b);     for (auto u : ver[a]) {       cmp[u] = b;       ver[b].push_back(u);     }     if (a == st) {       st = nxt[a];       pre[nxt[a]] = -1;     } else {       if (nxt[a] != -1) pre[nxt[a]] = pre[a];       nxt[pre[a]] = nxt[a];     }     ver[a].clear();     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       cmp[i] = i;       ver[i].push_back(i);       pre[i] = i == 1 ? -1 : i - 1;       nxt[i] = i == n ? -1 : i + 1;     }     st = 1;     for (int i = 1; i <= n; i++) {       int ind = st;       for (auto u : adj[i]) mark[u] = true;       while (ind != -1) {         if (ind == cmp[i]) {           ind = nxt[ind];           continue;         }         bool done = false;         for (auto u : ver[ind])           if (!mark[u]) {             int c = ind;             ind = nxt[ind];             done = true;             join(c, cmp[i]);             break;           }         if (!done) ind = nxt[ind];       }       for (auto u : adj[i]) mark[u] = false;     }     int cnt = 0, ind = st;     while (ind != -1) {       cnt++;       ind = nxt[ind];     }     cout << cnt <<   n ;     while (st != -1) {       cout << ver[st].size() <<    ;       for (auto u : ver[st]) cout << u <<    ;       cout <<   n ;       st = nxt[st];     }     return 0;   }


#include <bits/stdc++.h>   int x[2002], y[2002];   using namespace std;   int main() {     int n;     cin >> n;     set<int> S;     for (int i = 1; i <= n; ++i) {       cin >> x[i];       S.insert(x[i]);     }     for (int i = 1; i <= n; ++i) {       cin >> y[i];       S.insert(y[i]);     }     int val = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (S.find(x[i] ^ y[j]) != S.end()) val++;       }     }     if (val & 1)       cout <<  Koyomi n ;     else       cout <<  Karen n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e4;   long long a[maxn];   int v[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (long long i = 1; i < maxn; i++) {       a[i] = i * (i - 1) / 2;     }     int T;     cin >> T;     while (T--) {       long long n;       cin >> n;       int tn = 0;       for (int i = maxn - 1; i && n; i--) {         while (n >= a[i]) {           n -= a[i];           v[++tn] = i;         }       }       v[tn + 1] = 0;       for (int i = 1; i <= tn; i++) {         cout << 1;         for (int j = 0; j < v[i] - v[i + 1]; j++) cout << 3;       }       cout << 7 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   int n, x, y;   bool ask_1y(const vector<int>& a) {     if (a.empty()) {       return false;     }     cout <<  ?   << a.size();     for (int i : a) {       cout <<     << i + 1;     }     cout << endl;     int r;     cin >> r;     return r == y || r == (x ^ y);   }   bool same[11];   void solve(istream& cin, ostream& cout) {     cin >> n >> x >> y;     int hb = -1;     for (int i = 0; i < 10; i++) {       vector<int> a;       for (int j = (0); j < int(n); ++j) {         if ((((j) >> (i)) & 1)) {           a.push_back(j);         }       }       if (ask_1y(a)) {         hb = i;       } else {         same[i] = true;       }     }     int a = 0;     int b = 0;     for (int i = 0; i < 10; i++) {       if (i == hb) {         b |= (1 << (hb));         continue;       }       vector<int> v;       for (int j = (0); j < int(n); ++j) {         if (!(((j) >> (i)) & 1) && !(((j) >> (hb)) & 1)) {           v.push_back(j);         }       }       if (ask_1y(v)) {         if (!same[i]) {           b |= (1 << (i));         }       } else {         a |= (1 << (i));         if (same[i]) {           b |= (1 << (i));         }       }     }     cout <<  !   << a + 1 <<     << b + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve(cin, cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 7 + 5;   int n, a[maxn];   char str[maxn];   int main() {     cin >> n;     int ans = 0;     while (n--) {       cin >> str;       for (int i = 0; i < 7; i++) {         a[i] += str[i] -  0 ;         ans = max(ans, a[i]);       }     }     cout << ans << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int low, up, x, n;   int vec[16];   int recurse(int i, int a, int b, int s, int cnt) {     if (i == n) {       if (cnt >= 2 && low <= s && s <= up && a - b >= x) {         return 1;       }       return 0;     }     return recurse(i + 1, max(a, vec[i]), min(b, vec[i]), s + vec[i], cnt + 1) +            recurse(i + 1, a, b, s, cnt);   }   int main() {     scanf( %d , &n);     scanf( %d , &low);     scanf( %d , &up);     scanf( %d , &x);     for (int i = 0; i <= n - 1; ++i) scanf( %d , &vec[i]);     printf( %d n , recurse(0, INT_MIN, INT_MAX, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h << endl;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class Iterable,             class = typename enable_if<!is_same<string, Iterable>::value>::type>   auto operator<<(ostream &os, Iterable v) -> decltype(os << *begin(v)) {     os <<  [ ;     for (auto vv : v) os << vv <<  ,  ;     return os <<  ] ;   }   const int inf = 0x3f3f3f3f;   const long long infll = 0x3f3f3f3f3f3f3f3fll;   template <class T>   int sign(T x) {     return (x > 0) - (x < 0);   }   template <class T>   T abs(const T &x) {     return (x < T(0)) ? -x : x;   }   vector<int> graph[112345];   int c[112345][4];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n, a, b;     cin >> n;     for (int k = 1; k <= 3; k++)       for (int i = 1; i <= n; i++) cin >> c[i][k];     for (int i = 0; i + 1 < n; i++) {       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     int start;     for (int i = 1; i <= n; i++) {       if (graph[i].size() > 2) {         cout << -1 << endl;         return 0;       }       if (graph[i].size() == 1) start = i;     }     vector<int> pi = {1, 2, 3};     long long ans = infll;     vector<int> best_color;     vector<int> color(n + 1);     do {       long long tmp = 0;       int cur = start;       int prev = start;       for (int i = 0; i < n; i++) {         color[cur] = pi[i % 3];         tmp += c[cur][pi[i % 3]];         for (int j = 0; j < graph[cur].size(); j++)           if (graph[cur][j] != prev) {             prev = cur;             cur = graph[cur][j];             break;           }       }       if (tmp < ans) {         ans = min(ans, tmp);         best_color = color;       }     } while (next_permutation(pi.begin(), pi.end()));     cout << ans << endl;     for (int i = 1; i <= n; i++) cout << best_color[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n < 6)       cout << -1 << endl;     else {       for (int i = 2; i <= 4; i++) cout << 1 <<     << i << endl;       for (int i = 5; i <= n; i++) {         cout << 2 <<     << i << endl;       }     }     for (int i = 1; i < n; i++) {       cout << i <<     << i + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int>> adj;   vector<vector<int>> vis;   int dfs1(int a, int b) {     if (a == n - 1 and b == m - 1) return 1;     vis[a][b] = 1;     if (a + 1 < n and adj[a + 1][b] and !vis[a + 1][b])       if (dfs1(a + 1, b)) return 1;     if (b + 1 < m and adj[a][b + 1] and !vis[a][b + 1])       if (dfs1(a, b + 1)) return 1;     vis[a][b] = 2;     return 0;   }   int dfs2(int a, int b) {     if (a == n - 1 and b == m - 1) return 1;     vis[a][b] = 1;     if (a + 1 < n and adj[a + 1][b] and vis[a + 1][b] != 1)       if (dfs2(a + 1, b)) return 1;     if (b + 1 < m and adj[a][b + 1] and vis[a][b + 1] != 1)       if (dfs2(a, b + 1)) return 1;     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     adj = vector<vector<int>>(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < m; ++j) {         if (s[j] ==  . )           adj[i][j] = 1;         else           adj[i][j] = 0;       }     }     int a = 0;     vis = vector<vector<int>>(n, vector<int>(m, 0));     a += dfs1(0, 0);     a += dfs2(0, 0);     cout << a <<   n ;   }


#include <bits/stdc++.h>   long long cmpfunc(const void* a, const void* b) {     return (*(long long*)a - *(long long*)b);   }   int main(void) {     long long int test, i, j, n, count, flag = 0, o1 = 0, o2 = 0, b1, x, m, l,                                         max, sum2, min, f, r, o, sum1, sum = 0, y,                                         count1 = 0, a[1000000];     scanf( %lld , &n);     count = 0;     f = 0;     for (i = 0; i < n; i++) {       scanf( %lld , &x);       if (a[x] == 0 && x != 0) {         count++;         a[x]++;       }     }     printf( %lld n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b == 0) return b;     return gcd(b, a % b);   }   int v[11];   int main() {     int a, k = 0;     scanf( %d , &a);     for (int i = 2; i < a; i++) {       int t = a;       int pos = 0;       while (t) {         int mod = t % i;         k += mod;         t = (t - mod) / i;         if (!t) break;       }     }     int vbcd = gcd(k, a - 2);     printf( %d/%d , k / vbcd, (a - 2) / vbcd);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int min(long long int a, long long int b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long int max(long long int a, long long int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string str;       cin >> str;       if (n == 1) {         cout << 1 <<   n ;         continue;       }       if (n == 2) {         if (str[0] == str[1]) {           cout << 1 <<   n ;           continue;         }       }       vector<long long int> seg;       long long int curr_length = 1;       for (long long int i = 0; i < str.size() - 1; i++) {         if (str[i] == str[i + 1]) {           curr_length++;         } else {           seg.push_back(curr_length);           curr_length = 1;         }       }       seg.push_back(curr_length);       long long int segtillnow = 0;       long long int ans = 0;       for (long long int i = 0; i < seg.size(); i++) {         segtillnow++;         if (seg[i] == 1) {           continue;         } else if (seg[i] > 1) {           long long int operations = min(seg[i] - 1, segtillnow);           ans += operations;           segtillnow -= operations;         }       }       ans += ((segtillnow + 1) / 2);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string cad1;     string cad2;     cin >> cad1 >> cad2;     if (cad1 == cad2) {       cout <<  YES ;     } else {       if (cad1.size() != cad2.size()) {         cout <<  NO ;       } else {         int ceros = 0;         int unos = 0;         for (int i = 0; i < cad2.size(); ++i) {           if (cad2[i] ==  0 ) ceros++;           if (cad1[i] ==  1 ) unos++;         }         if (ceros == cad2.size())           cout <<  NO ;         else {           if (unos > 0)             cout <<  YES ;           else             cout <<  NO ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char phone[128];   int main() {     scanf( %d , &n);     scanf( %s , phone);     cnt = 0;     for (int i = 0; i < n; i++) {       if (cnt == 2 and n - i >= 2) {         printf( - );         cnt = 0;       }       printf( %c , phone[i]);       cnt++;     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double a, b;   int main() {     cin >> a >> b;     cout << fixed << a * pow((long double)1.000000011, b) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<string> s;     for (int i = n - 1; i >= 0; i--) {       if (s.find(a[i]) == s.end()) {         cout << a[i] <<   n ;       }       s.insert(a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long double EPS = 1e-10;   const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};   const int MAX_N = 400;   int ans[181];   void init() {     fill(ans, ans + 181, -1);     for (int i = 3; i <= MAX_N; ++i) {       double min_deg = 180.0 / i;       for (int deg = 1; deg <= 180; ++deg) {         if (ans[deg] != -1) continue;         if (deg - floor(deg / min_deg + EPS) * min_deg < EPS &&             deg <= min_deg * double(i - 2))           ans[deg] = i;       }     }   }   int main() {     init();     int t, deg;     cin >> t;     while (t--) {       cin >> deg;       cout << ans[deg] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   void solve(long long a, long long b, long long c, long long l) {     for (long long i = 0; i <= l; i++) {       long long x = min(a - b - c + i, l - i);       if (x >= 0) ans -= (x + 1) * (x + 2) / 2LL;     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     long long a, b, c, l;     cin >> a >> b >> c >> l;     ans = (l + 1) * (l + 2) * (l + 3) / 6LL;     solve(a, b, c, l);     solve(b, a, c, l);     solve(c, a, b, l);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T m, T n) {     while (n) {       T t = m % n;       m = n;       n = t;     };     return m;   }   template <typename T>   T exgcd(T a, T b, T& sa, T& ta) {     T q, r, sb = 0, tb = 1, sc, tc;     sa = 1, ta = 0;     if (b) do         q = a / b, r = a - q * b, a = b, b = r, sc = sa - q * sb, sa = sb,         sb = sc, tc = ta - q * tb, ta = tb, tb = tc;       while (b);     return a;   }   template <typename T>   T mul_inv(T a, T b) {     T t1 = a, t2 = b, t3;     T v1 = 1, v2 = 0, v3;     T x;     while (t2 != 1)       x = t1 / t2, t3 = t1 - x * t2, v3 = v1 - x * v2, t1 = t2, t2 = t3, v1 = v2,       v2 = v3;     return (v2 + b) % b;   }   template <typename T>   T powmod(T a, T b, T MOD) {     if (b < 0) return 0;     T rv = 1;     while (b) (b % 2) && (rv = (rv * a) % MOD), a = a * a % MOD, b /= 2;     return rv;   }   const int maxn = 2e5 + 7;   int n;   int L;   int a[maxn];   int b[maxn];   vector<int> to_remove[maxn];   vector<int> to_add[maxn];   int dist_tbl[maxn];   bool explored[maxn];   int dis(int x, int y) { return min(abs(x - y), L - abs(x - y)); }   int calc(int k) {     int& r = dist_tbl[k];     if (r >= 0) return r;     r = 0;     for (int i = 0; i < n; i++) r = max(r, dis(a[i], b[(i + k) % n]));     return r;   }   int main(int argc, char* argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n >> L;     {       clock_t time_start = clock();       clock_t time_end = time_start + CLOCKS_PER_SEC * 0.8;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       memset(dist_tbl, -1, sizeof(dist_tbl));       memset(explored, 0, sizeof(explored));       map<int, set<int> > values;       for (int i = 0, ij = max(1, n / 64); i < n; i += ij) {         values[calc(i)].insert(i);       }       int explore_values[] = {-4, -2, -1, 1, 2, 4, 0};       while (clock() < time_end && values.size() < n) {         vector<int> toExplore;         int nmin = 64;         for (auto it : values) {           if (it.second.empty()) --nmin;           for (int k : it.second) {             if (--nmin < 0) break;             if (!explored[k]) {               toExplore.push_back(k);               explored[k] = true;             }           }           if (nmin < 0) break;         }         if (toExplore.size() == 0) break;         int new_explore = 0;         for (int k : toExplore) {           values[calc(k)].erase(k);           for (int ei = 0; explore_values[ei]; ei++) {             int k2 = (k + n + explore_values[ei]) % n;             k2 = (k2 + n) % n;             if (dist_tbl[k2] < 0) {               new_explore++;               values[calc(k2)].insert(k2);             }           }         }         if (!new_explore) break;       }       cout << values.begin()->first << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fr() {     freopen( test_input.txt ,  r , stdin);     freopen( a.out ,  w , stdout);   }   const int N = 5e5 + 5;   const int MAX = 5e6 + 123;   const int INF = 2e9;   const int mod = 1e9 + 7;   const double pi = 3.1415926536;   double eps = 1e-10;   bool used1[N], used2[N];   void solve() {     int n;     string s1, s2;     map<int, int> cnt1, cnt2;     map<int, pair<int, int> > ans;     cin >> s1 >> s2;     cin >> n;     for (int i = 1; i <= n; i++) {       int t, m;       char p, c;       cin >> t >> p >> m >> c;       if (p ==  h ) {         if (c ==  y )           cnt1[m]++;         else           cnt1[m] += 2;         if (cnt1[m] >= 2 and !used1[m]) {           ans[t] = make_pair(0, m);           used1[m] = 1;         }       } else {         if (c ==  y )           cnt2[m]++;         else           cnt2[m] += 2;         if (cnt2[m] >= 2 and !used2[m]) {           ans[t] = make_pair(1, m);           used2[m] = 1;         }       }     }     for (int i = 1; i <= 90; i++) {       if (ans[i] != make_pair(0, 0)) {         if (ans[i].first == 0)           cout << s1 <<    ;         else           cout << s2 <<    ;         cout << ans[i].second <<     << i << endl;       }     }   }   int t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     int a[n];     for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i];     int fq[m];     for (__typeof((m)) i = (0); i < (m); i++) fq[i] = 0;     for (__typeof((n)) i = (0); i < (n); i++) {       fq[a[i] % m]++;     }     int flg = 0;     for (__typeof((m)) i = (0); i < (m); i++) {       if (fq[i] >= 2) {         flg = 1;         break;       }     }     if (flg == 1)       cout << 0 << endl;     else {       int prd = 1;       for (__typeof((n)) i = (0); i < (n); i++) {         for (int j = i + 1; j < n; j++)           prd = ((prd % m) * (abs(a[i] - a[j]) % m)) % m;       }       cout << prd << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2;     cin >> n1 >> n2;     int k, m;     cin >> k >> m;     long long a[n1], b[n2];     for (int i = 0; i < n1; i++) cin >> a[i];     for (int i = 0; i < n2; i++) cin >> b[i];     int count = 0;     for (int i = 0; i < n1; i++) {       if (a[i] >= b[n2 - m]) break;       count++;       if (count >= k) break;     }     if (count >= k && n2 >= m)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int color[400100];   int w[400100];   struct segment_tree {     long long a[1600100];     bool put[1600100];     void push(int x) {       if (put[x]) {         a[x * 2] = a[x * 2 + 1] = a[x];         put[x] = false;         put[x * 2] = put[x * 2 + 1] = true;       }     }     void calc(int x) { a[x] = a[x * 2] | a[x * 2 + 1]; }     void build(int x, int l, int r) {       if (l < r) {         int y = (l + r) >> 1;         build(x * 2, l, y);         build(x * 2 + 1, y + 1, r);         a[x] = a[x * 2] | a[x * 2 + 1];         put[x] = false;       } else {         a[x] = (1LL << color[w[l]]);         put[x] = true;       }     }     void modify(int x, int l, int r, int ll, int rr, long long v) {       if (r < ll || l > rr) return;       if (ll <= l && rr >= r) {         a[x] = v;         put[x] = true;         return;       }       push(x);       int y = (l + r) >> 1;       modify(x * 2, l, y, ll, rr, v);       modify(x * 2 + 1, y + 1, r, ll, rr, v);       calc(x);     }     long long get(int x, int l, int r, int ll, int rr) {       if (r < ll || l > rr) return 0LL;       if (ll <= l && rr >= r) {         return a[x];       }       push(x);       int y = (l + r) >> 1;       long long ret = get(x * 2, l, y, ll, rr);       ret |= get(x * 2 + 1, y + 1, r, ll, rr);       calc(x);       return ret;     }   } seg;   vector<int> ga[400100];   int u, v;   int din[400100], dout[400100];   int timer;   void dfs(int u, int p) {     timer++;     din[u] = timer;     w[timer] = u;     for (int i = 0; i < ga[u].size(); i++) {       int v = ga[u][i];       if (v != p) dfs(v, u);     }     dout[u] = timer;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> color[i];     for (int i = 1; i < n; i++) {       cin >> u >> v;       ga[u].push_back(v);       ga[v].push_back(u);     }     dfs(1, -1);     seg.build(1, 1, n);     int tp, aa, bb;     for (int i = 1; i <= m; i++) {       cin >> tp;       if (tp == 1) {         cin >> aa >> bb;         seg.modify(1, 1, n, din[aa], dout[aa], (1LL << bb));       } else {         cin >> aa;         cout << __builtin_popcountll(seg.get(1, 1, n, din[aa], dout[aa])) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string name[7];   int a, b, c, n, max_p, dexp, was[7];   bool p[7][7];   void perebor(int point, int num);   int main() {     name[0] =  Anka ;     name[1] =  Chapay ;     name[2] =  Cleo ;     name[3] =  Troll ;     name[4] =  Dracul ;     name[5] =  Snowy ;     name[6] =  Hexadecimal ;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       string name1, name2, s;       cin >> name1 >> s >> name2;       for (int j = 0; j < 7; j++) {         if (name[j] == name1) a = j;         if (name[j] == name2) b = j;       }       p[a][b] = true;     }     cin >> a >> b >> c;     dexp = (int)1e9 * 2 + 1;     max_p = -1;     perebor(1, 0);     cout << dexp <<     << max_p;     return 0;   }   void perebor(int point, int num) {     if (point == 4 && num != 7) return;     if (num == 7) {       int c_p = 0, t[4], ans;       for (int i = 0; i < 4; i++) t[i] = 0;       for (int i = 0; i < 7; i++) {         t[was[i]]++;         for (int j = 0; j < 7; j++)           if (was[i] == was[j] && p[i][j] == true && i != j) c_p++;       }       if (!(t[1] && t[2] && t[3]))         return;       else {         ans = max(ceil(a / t[1]), max(ceil(b / t[2]), ceil(c / t[3]))) -               min(ceil(a / t[1]), min(ceil(b / t[2]), ceil(c / t[3])));         if (ans <= dexp) {           if (ans < dexp) max_p = 0;           dexp = ans;           if (max_p < c_p) max_p = c_p;         }       }       return;     }     for (int i = 0; i < 7; i++)       if (was[i] == 0) {         was[i] = point;         perebor(point, num + 1);         perebor(point + 1, num + 1);         was[i] = 0;       }     return;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     double x, sum = 0;     cin >> t;     for (int i = 1; i <= t; i++) {       cin >> x;       sum += x;     }     cout << (sum / t) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   const int mod = 1e9 + 7;   struct pairNode {     char ch;     long long times;     pairNode(char ch = 0, long long times = 0) : ch(ch), times(times) {}     ~pairNode() = default;     bool operator==(const pairNode &rhs) const {       return ch == rhs.ch && times == rhs.times;     }     bool operator!=(const pairNode &rhs) const {       return ch != rhs.ch || times != rhs.times;     }     bool operator>=(const pairNode &rhs) const {       return ch == rhs.ch && times >= rhs.times;     }   };   int tS, tT;   vector<pairNode> S, T, newT;   int nxt[M];   inline void getInput(vector<pairNode> &S, int len) {     char cur = 0, ch[3];     long long curtimes = 0, times;     for (int i = 0; i < len; ++i) {       scanf( %I64d-%s , &times, ch);       if (ch[0] == cur) {         curtimes += times;       } else {         if (i) S.push_back(pairNode(cur, curtimes));         cur = ch[0];         curtimes = times;       }     }     S.push_back(pairNode(cur, curtimes));   }   int main() {     S.clear();     T.clear();     cin >> tS >> tT;     getInput(S, tS);     getInput(T, tT);     if (T.size() == 1) {       long long ans = 0;       for (int i = 0; i < S.size(); ++i)         if (S[i] >= T[0]) ans += S[i].times - T[0].times + 1;       cout << ans << endl;       return 0;     }     if (T.size() == 2) {       long long ans = 0;       for (int i = 0; i < S.size() - 1; ++i)         if (S[i] >= T[0] && S[i + 1] >= T[1]) ++ans;       cout << ans << endl;       return 0;     }     for (int i = 1; i < T.size() - 1; ++i) newT.push_back(T[i]);     nxt[0] = -1;     int k = -1;     for (int i = 1; i < newT.size(); ++i) {       while (k != -1 && newT[k + 1] != newT[i]) k = nxt[k];       if (newT[k + 1] == newT[i]) ++k;       nxt[i] = k;     }     long long ans = 0;     k = -1;     for (int i = 0; i < S.size(); ++i) {       while (k != -1 && newT[k + 1] != S[i]) k = nxt[k];       if (newT[k + 1] == S[i]) ++k;       if (k == newT.size() - 1) {         if (i >= newT.size() && i + 1 <= S.size() && S[i - newT.size()] >= T[0] &&             S[i + 1] >= T[T.size() - 1])           ++ans;         k = nxt[k];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>       #define ll long long int   #define ii pair<int,int>   #define int long long int       using namespace std;       const int inf = 0x3f3f3f3f;      int32_t main() {       int t; scanf( %lld ,&t);       while(t--) {           int n, m, x; scanf( %lld%lld%lld ,&n,&m,&x);           --x;              int c = (x/n);           int r = (x%n);                      int ans = r*m+c;           printf( %lld n ,ans+1);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sum, k, ans, c;   long long arr[1000000 + 5];   long long tmp[1000000 + 5];   vector<long long> frac;   signed main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> arr[i], sum += arr[i];     }     ans = 1e18;     for (long long i = 2; i <= sqrt(sum); i++) {       if (sum % i == 0) frac.push_back(i), frac.push_back(sum / i);     }     frac.push_back(1);     for (long long i : frac) {       k = sum / i, c = 0;       for (long long j = 0; j < n; j++) tmp[j] = 0;       for (long long j = 0; j < n; j++) {         tmp[j] += arr[j];         if (tmp[j] < 0) {           c += -tmp[j];           tmp[j + 1] += tmp[j];           tmp[j] = 0;         }         if (tmp[j] % k != 0) {           if (tmp[j] % k < k - tmp[j] % k) {             c += tmp[j] % k;             tmp[j + 1] += tmp[j] % k;           } else {             c += k - tmp[j] % k;             tmp[j + 1] -= k - tmp[j] % k;           }         }       }       ans = min(ans, c);     }     if (sum > 1)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long m[10000005], x = 0, n, k, i, j, a;   int main() {     cin >> a >> n;     for (i = 1; i < a + n; i++) {       m[i] = i;     }     for (i = 2; i < 3400; i++) {       k = 0;       for (j = i * i; j <= a + n; j = j + i * i) {         k++;         m[j] = k;       }     }     for (i = a; i < a + n; i++) x = x + m[i];     cout << x;   }


#include <bits/stdc++.h>   using namespace std;   long long big = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b;     cin >> a >> b;     int g = gcd(a, b);     a /= g;     b /= g;     int ctr = 0;     while (a % 2 == 0) {       ctr += 1;       a /= 2;     }     while (a % 3 == 0) {       ctr += 1;       a /= 3;     }     while (a % 5 == 0) {       ctr += 1;       a /= 5;     }     if (a != 1) {       cout << -1 <<   n ;       return 0;     }     while (b % 2 == 0) {       ctr += 1;       b /= 2;     }     while (b % 3 == 0) {       ctr += 1;       b /= 3;     }     while (b % 5 == 0) {       ctr += 1;       b /= 5;     }     if (b != 1) {       cout << -1 <<   n ;       return 0;     }     cout << ctr <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 10;   struct Edge {     int u, v, cost, idx;     bool operator<(const Edge& rhs) const { return cost < rhs.cost; }   } ed[MAX_N];   inline bool cmp_idx(const Edge& lhs, const Edge& rhs) {     return lhs.idx < rhs.idx;   }   map<pair<int, int>, int> ID;   int ver[MAX_N][19], maxCost[MAX_N][19], dep[MAX_N];   int par[MAX_N], _rank[MAX_N];   int n, m, ans[MAX_N];   bool inMST[MAX_N];   vector<pair<int, int> > g[MAX_N];   inline void init(int n) {     for (int i = 1; i <= n; i++) {       par[i] = i;       _rank[i] = 0;     }   }   int find(int x) {     if (par[x] == x) return x;     return par[x] = find(par[x]);   }   inline void unite(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     if (_rank[x] < _rank[y]) {       par[x] = y;     } else {       par[y] = x;       if (_rank[x] == _rank[y]) _rank[x]++;     }   }   inline bool same(int x, int y) { return find(x) == find(y); }   void dfs(int u, int fa, int d) {     dep[u] = d;     for (pair<int, int>& e : g[u]) {       int v = e.first, cost = e.second;       if (v != fa) {         ver[v][0] = u;         maxCost[v][0] = cost;         dfs(v, u, d + 1);       }     }   }   void initLca() {     memset(ver, -1, sizeof ver);     memset(maxCost, 0x8f, sizeof maxCost);     dfs(1, -1, 1);     for (int k = 1; k < 19; k++) {       for (int v = 1; v <= n; v++) {         if (ver[v][k - 1] != -1 && ver[ver[v][k - 1]][k - 1] != -1) {           maxCost[v][k] = max(maxCost[v][k - 1], maxCost[ver[v][k - 1]][k - 1]);           ver[v][k] = ver[ver[v][k - 1]][k - 1];         }       }     }   }   pair<int, int> find_lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     int res = -0x7fffffff;     for (int k = 18; k >= 0; k--) {       if (ver[v][k] != -1 && dep[ver[v][k]] >= dep[u]) {         res = max(res, maxCost[v][k]);         v = ver[v][k];       }     }     if (u == v) return pair<int, int>(res, v);     for (int k = 18; k >= 0; k--) {       if (ver[v][k] != ver[u][k]) {         res = max(res, max(maxCost[v][k], maxCost[u][k]));         v = ver[v][k];         u = ver[u][k];       }     }     res = max(res, max(maxCost[v][0], maxCost[u][0]));     return pair<int, int>(res, ver[v][0]);   }   void modify(int u, int v, int w) {     v = find(v);     while (dep[u] < dep[v]) {       int fa = ver[v][0], id = ID[pair<int, int>(fa, v)];       ans[id] = min(ans[id], w);       par[v] = find(fa);       v = find(v);     }   }   int main() {     int u, v, c;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &u, &v, &c);       ed[i] = (Edge){u, v, c, i};       ID[pair<int, int>(u, v)] = i;       ID[pair<int, int>(v, u)] = i;       ans[i] = 0x7fffffff;     }     sort(ed, ed + m);     init(n);     for (int i = 0; i < m; i++) {       Edge& e = ed[i];       if (!same(e.u, e.v)) {         unite(e.u, e.v);         g[e.u].push_back(pair<int, int>(e.v, e.cost));         g[e.v].push_back(pair<int, int>(e.u, e.cost));         inMST[i] = true;       }     }     initLca();     init(n);     for (int i = 0; i < m; i++) {       if (inMST[i]) continue;       Edge& e = ed[i];       pair<int, int> lca = find_lca(e.u, e.v);       ans[e.idx] = min(ans[e.idx], lca.first - 1);       modify(lca.second, e.u, e.cost - 1);       modify(lca.second, e.v, e.cost - 1);     }     for (int i = 0; i < m; i++) {       if (ans[i] == 0x7fffffff) ans[i] = -1;       printf( %d  , ans[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = (long long)((1e5) + 100);   long long cuberoot(long long x) {     long long lo = 1, hi = min(2000000ll, x);     while (hi - lo > 1) {       long long mid = (lo + hi) / 2;       if (mid * mid * mid < x) {         lo = mid;       } else         hi = mid;     }     if (hi * hi * hi <= x)       return hi;     else       return lo;   }   const long long dx[4] = {-1, 1, 0, 0};   const long long dy[4] = {0, 0, -1, 1};   long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};   long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const long long N = (long long)(1 * 1e6 + 10);   bool comp(pair<long long, pair<long long, long long>> p1,             pair<long long, pair<long long, long long>> p2) {     if (p1.first > p2.first)       return true;     else if (p1.second == p2.second) {       if (p1.second.first < p2.second.first) return true;     }     return false;   }   long long fact(long long n);   long long ncr(long long n, long long r) {     return fact(n) / (fact(r) * fact(n - r));   }   long long fact(long long n) {     long long res = 1;     for (long long i = 2; i <= n; i++) res = res * i;     return res % 1000000007;   }   const long long a = 1000000000;   long long nCr(long long n, long long r) {     long long fac1 = 1, fac2 = 1, fac;     for (long long i = r; i >= 1; i--, n--) {       fac1 = fac1 * n;       if (fac1 % i == 0)         fac1 = fac1 / i;       else         fac2 = fac2 * i;     }     fac = fac1 / fac2;     return fac % a;   }   const long long m = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   signed main() {     long long n;     cin >> n;     long long arr[n + 1];     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }     long long mx = 0;     vector<long long> v;     for (long long i = n - 1; i >= 0; i--) {       if (i == n - 1) {         v.push_back(0);         mx = arr[i];       } else {         long long ans = 0;         if (mx >= arr[i])           ans = max(mx, arr[i]) - arr[i] + 1;         else           ans = max(mx, arr[i]) - arr[i];         v.push_back(ans);         mx = max(mx, arr[i]);       }     }     for (long long i = n - 1; i >= 0; i--) cout << v[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 100000 + 1;   int N;   char buf[2000];   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a, b;       scanf( %s%d%d , buf, &a, &b);       if (a >= 2400 && b > a) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1005], b[1005], c[1005], d[1005], posa[1005], posb[1005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int q = 1; q <= n; q++) {       int x;       cin >> x;       a[x] = q;     }     for (int q = 1; q <= n; q++) {       int x;       cin >> x;       b[x] = q;     }     for (int q = 1; q <= n; q++) {       c[q] = d[q] = posa[q] = posb[q] = q;     }     vector<array<int, 4>> v;     for (int q = 1; q <= n; q++) {       if (c[q] == a[q] && d[q] == b[q]) continue;       v.push_back({q, posb[b[q]], posa[a[q]], q});       posb[d[q]] = posb[b[q]];       posa[c[q]] = posa[a[q]];       d[posb[d[q]]] = d[q];       c[posa[c[q]]] = c[q];     }     cout << ((int)((v).size())) <<   n ;     for (int q = 0; q < ((int)((v).size())); q++) {       for (int w = 0; w < 4; w++) cout << v[q][w] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[4 * 200005];   void update(int n, int st, int en, int index, int val) {     if (st == en) {       tree[n] = val;       return;     }     int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1;     if (index <= mid)       update(lc, st, mid, index, val);     else       update(rc, mid + 1, en, index, val);     tree[n] = max(tree[lc], tree[rc]);   }   int query(int n, int st, int en, int l, int r) {     if (r < st || en < l) return 0;     if (l <= st && en <= r) return tree[n];     int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1;     return max(query(lc, st, mid, l, r), query(rc, mid + 1, en, l, r));   }   vector<int> pos[200005 + 5];   int main() {     int n, inp;     scanf( %d , &n);     int mx = 0;     for (int i = 1; i < n + 1; i++) {       scanf( %d , &inp);       pos[inp].push_back(i);     }     for (int num = 1; num < 200005; num++) {       reverse(pos[num].begin(), pos[num].end());       for (auto position : pos[num]) {         if (position < num) continue;         int highestDeletePossible = position - num;         int maxAns = query(1, 0, 200005, 0, highestDeletePossible) + 1;         update(1, 0, 200005, highestDeletePossible, maxAns);       }     }     cout << query(1, 0, 200005, 0, 200005) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 111111;   vector<int> v[MAXM];   int n, m, lim, x, lower, upper;   inline bool check(int score) {     for (int i = 1; i <= m; ++i)       for (int j = score - 1; j < (int)v[i].size(); ++j) {         int k = j - score + 1;         if (v[i][j] - v[i][k] - lim <= score - 1) return true;       }     return false;   }   int main() {     scanf( %d %d %d , &n, &m, &lim);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       v[x].push_back(i);     }     lower = 0, upper = n;     while (lower < upper) {       int mid = (lower + upper + 1) / 2;       if (check(mid))         lower = mid;       else         upper = mid - 1;     }     printf( %d n , lower);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10, MAXL = 500 + 10;   int n, S, in[MAXN], out[MAXN], w[MAXN], s[MAXN], v[MAXN];   int id[MAXN], h[MAXN][MAXN], g[MAXN][MAXN], f[MAXL][MAXN], Tohka;   vector<int> l[MAXN];   bool cmp(int first, int second) {     if ((out[first] - in[first]) != (out[second] - in[second]))       return (out[first] - in[first]) < (out[second] - in[second]);     return (s[first] + w[first]) < (s[second] + w[second]);   }   int main() {     scanf( %d%d , &n, &S);     for (int i = 1; i <= n; ++i)       scanf( %d%d%d%d%d , &in[i], &out[i], &w[i], &s[i], &v[i]), ++in[i],           id[i] = i;     ++n;     in[n] = 1, out[n] = n * 2 + 1, w[n] = 0, s[n] = S;     id[n] = n;     sort(id + 1, id + n + 1, cmp);     for (int i = 1; i <= n; ++i) l[out[id[i]]].push_back(id[i]);     for (int t = 1; t <= n; ++t) {       int i = id[t], R = min(S - w[i], s[i]);       for (int k = 0; k <= R; ++k) g[in[i] - 1][k] = 0;       for (int j = in[i]; j <= out[i]; ++j) {         for (int k = 0; k <= R; ++k) g[j][k] = g[j - 1][k];         vector<int> &L = l[j];         for (int p = 0; p < (int)L.size() && L[p] != i && in[L[p]] >= in[i]; ++p)           for (int k = w[L[p]]; k <= R; ++k)             g[j][k] = max(g[j][k], g[in[L[p]] - 1][k] + f[L[p]][k]);       }       for (int k = R; k >= 0; --k)         f[i][k + w[i]] = g[out[i]][k] + v[i], Tohka = max(Tohka, f[i][k + w[i]]);       for (int k = 0; k < w[i]; ++k) f[i][k] = 0;       for (int k = 1; k <= S; ++k) f[i][k] = max(f[i][k], f[i][k - 1]);     }     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct flight {     int d, f, t, c;     flight() {}     flight(int d, int f, int t, int c) : d(d), f(f), t(t), c(c) {}     bool operator<(const flight& a) const { return d > a.d; }   };   int n, m, k;   priority_queue<flight> arr, dep;   priority_queue<pair<int, int> > cheap[100010];   long long minarr[100010], arrcost, depcost;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int d, f, t, c;       cin >> d >> f >> t >> c;       if (t == 0) {         arr.push(flight(d, f, t, c));       } else {         dep.push(flight(d, f, t, c));         cheap[t].push(make_pair(-c, d));       }     }     for (int i = 1; i <= n; i++) {       if (cheap[i].empty()) {         cout << -1 <<   n ;         return 0;       }       depcost += -cheap[i].top().first;     }     memset(minarr, -1, sizeof(minarr));     int num = 0;     long long ans = -1;     while (!arr.empty()) {       flight f = arr.top();       arr.pop();       int u = f.f;       if (minarr[u] == -1) {         num++;         minarr[u] = f.c;         arrcost += f.c;       } else if (f.c < minarr[u]) {         arrcost += f.c - minarr[u];         minarr[u] = f.c;       }       if (num < n) continue;       bool done = 0;       while (!dep.empty() && dep.top().d <= f.d + k) {         flight df = dep.top();         dep.pop();         depcost -= -cheap[df.t].top().first;         while (!cheap[df.t].empty() && cheap[df.t].top().second <= df.d)           cheap[df.t].pop();         if (cheap[df.t].empty()) {           done = 1;           break;         }         depcost += -cheap[df.t].top().first;       }       if (done) break;       if (ans == -1 || arrcost + depcost < ans) {         ans = arrcost + depcost;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   const int INF = (int)(1e9);   const long long INFLL = (long long)(1e18);   const double EPS = 1e-13;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<int> b(n);     for (int i = 0; i < n; i++) cin >> b[i];     vector<int> a;     for (int i = 0; i < n; i++)       if (b[i] == 0) a.push_back(i);     for (int i = n - 1; i >= 0; i--)       if (b[i] > 0) {         int cnt = 0;         int index = -1;         for (int j = 0; j < a.size(); j++) {           if (a[j] >= i + k) cnt++;           if (cnt == b[i]) {             index = j + 1;             break;           }         }         a.insert(a.begin() + index, i);       }     for (int i = 0; i < n; i++) cout << a[i] + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   const long double EPS = 1e-12;   const int INF = 1e9 + 10;   const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;   const int MN = 1e5 + 10;   vector<int> fir[MN], lst[MN];   int arr[MN];   int n, q, sz;   pair<int, int> inv[MN];   bool lz[4 * MN];   int seg[4 * MN];   void input() {     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n);     while (q--) {       int l, r;       cin >> l >> r;       int L = lower_bound(arr, arr + n, l) - arr;       int R = upper_bound(arr, arr + n, r) - arr;       if (L >= R) continue;       --R;       if (L == R) continue;       inv[sz++] = make_pair(L, R);       lst[R].push_back(sz - 1), fir[L].push_back(sz - 1);     }   }   void shift(int segnum, int left, int right) {     if (lz[segnum] == false) return;     int mid = (left + right) >> 1;     lz[2 * segnum] = !lz[2 * segnum], lz[2 * segnum + 1] = !lz[2 * segnum + 1];     lz[segnum] = false;     seg[2 * segnum] = (mid - left + 1) - seg[2 * segnum];     seg[2 * segnum + 1] = (right - mid) - seg[2 * segnum + 1];   }   void upd(int segnum, int left, int right, int l, int r) {     if (r < left || right < l) return;     if (l <= left && right <= r) {       lz[segnum] = !lz[segnum];       seg[segnum] = (right - left + 1) - seg[segnum];       return;     }     shift(segnum, left, right);     int mid = (left + right) >> 1;     upd(2 * segnum, left, mid, l, r);     upd(2 * segnum + 1, mid + 1, right, l, r);     seg[segnum] = seg[2 * segnum] + seg[2 * segnum + 1];   }   int get(int segnum, int left, int right, int l, int r) {     if (r < left || right < l) return 0;     if (l <= left && right <= r) return seg[segnum];     shift(segnum, left, right);     int mid = (left + right) >> 1;     return get(2 * segnum, left, mid, l, r) +            get(2 * segnum + 1, mid + 1, right, l, r);   }   void solve() {     long long ans = 1ll * n * (n - 1) * (n - 2) / 6;     for (int i = 0; i < n; ++i) {       upd(1, 0, n - 1, i, n - 1);       for (int j = 0; j < ((int)(fir[i]).size()); ++j)         upd(1, 0, n - 1, inv[fir[i][j]].first, inv[fir[i][j]].second);       if (i - 1 >= 0) {         for (int j = 0; j < ((int)(lst[i - 1]).size()); ++j)           upd(1, 0, n - 1, inv[lst[i - 1][j]].first, inv[lst[i - 1][j]].second);       }       int t = 0;       if (i - 1 >= 0) t += get(1, 0, n - 1, 0, i - 1);       if (i != n - 1) t += get(1, 0, n - 1, i + 1, n);       upd(1, 0, n - 1, i, n - 1);       long long val = 1ll * t * (t - 1) / 2;       ans -= val;     }     cout << ans <<   n ;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long QuickPow(long long x, long long y) {     long long Res = 1, Temp = x;     while (y) {       if (y & 1) Res = Res * Temp % 1000000007;       Temp = Temp * Temp % 1000000007;       y /= 2;     }     return Res;   }   inline void Swap(long long &x, long long &y) {     long long Temp = x;     x = y;     y = Temp;   }   inline long long Max(long long x, long long y) { return x > y ? x : y; }   inline long long Min(long long x, long long y) { return x < y ? x : y; }   inline void read(long long &x) {     x = 0;     long long f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   struct node {     long long v, Index;     node() {}     node(long long V, long long INDEX) {       v = V;       Index = INDEX;     }   };   set<long long> Ans, Bian[100005], Dian[100005];   set<long long>::iterator item;   stack<long long> S;   vector<node> G[100005];   bool InStack[100005];   long long Dfn[100005], Low[100005], Cnt, Col;   void Tarjan(long long x, long long Pre) {     Dfn[x] = Low[x] = ++Cnt;     int l = G[x].size();     for (register long long i = 0; i < l; ++i) {       long long to = G[x][i].v;       if (to == Pre) continue;       if (!Dfn[to]) {         S.push(to);         S.push(x);         S.push(G[x][i].Index);         Tarjan(to, x);         Low[x] = Min(Low[x], Low[to]);         if (Low[to] >= Dfn[x]) {           Col++;           long long u, v;           do {             Bian[Col].insert(S.top());             S.pop();             u = S.top();             S.pop();             v = S.top();             S.pop();             Dian[Col].insert(u);             Dian[Col].insert(v);           } while (u != x || v != to);         }       } else if (Dfn[to] < Dfn[x]) {         S.push(to);         S.push(x);         S.push(G[x][i].Index);         Low[x] = Min(Low[x], Dfn[to]);       }     }   }   int main() {     long long n, m;     read(n);     read(m);     for (register long long i = 1; i <= m; ++i) {       long long u, v;       read(u);       read(v);       G[u].push_back(node(v, i));       G[v].push_back(node(u, i));     }     for (register long long i = 1; i <= n; ++i)       if (!Dfn[i]) Tarjan(i, i);     for (register long long i = 1; i <= Col; ++i)       if (Bian[i].size() == Dian[i].size())         Ans.insert(Bian[i].begin(), Bian[i].end());     int l = Ans.size();     printf( %d n , l);     for (item = Ans.begin(); item != Ans.end(); item++) printf( %lld  , *item);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v, vv, vv2;   int main() {     int t, n, a[1000], k, f = 0;     cin >> n;     if (n == 3) {       for (int i = 1; i <= n; i++) {         if (i % 2 != 0) {           for (int j = 1; j <= n; j++) {             if (j % 2 != 0) {               cout <<  W ;             } else               cout <<  B ;           }           cout << endl;         } else {           for (int k = 0; k < n; k++) {             cout <<  B ;           }           cout << endl;         }       }     } else {       for (int i = 1; i <= n; i++) {         if (i % 2 != 0) {           for (int j = 1; j <= n; j++) {             if (j % 2 != 0)               cout <<  W ;             else               cout <<  B ;           }           cout << endl;         } else {           for (int j = 1; j <= n; j++) {             if (j % 2 != 0)               cout <<  B ;             else               cout <<  W ;           }           cout << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int tree[4 * MAXN];   int maxTree[4 * MAXN];   int p[MAXN];   int n;   void push(int v) {     if (tree[v]) {       tree[2 * v] += tree[v];       tree[2 * v + 1] += tree[v];       maxTree[2 * v] += tree[v];       maxTree[2 * v + 1] += tree[v];       tree[v] = 0;     }   }   void update(int v, int tl, int tr, int l, int r, int add) {     if (l > r) return;     if (tl == l && tr == r) {       tree[v] += add;       maxTree[v] += add;       return;     }     int tm = (tl + tr) >> 1;     push(v);     update(2 * v, tl, tm, l, min(r, tm), add);     update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, add);     maxTree[v] = max(maxTree[2 * v], maxTree[2 * v + 1]);   }   int findIndex(int v, int tl, int tr) {     if (tl == tr) return tl;     push(v);     int tm = (tl + tr) >> 1;     if (maxTree[2 * v] > 0) {       return findIndex(2 * v, tl, tm);     } else {       return findIndex(2 * v + 1, tm + 1, tr);     }   }   int main() {     for (int i = 0; i < 4 * MAXN; i++) {       tree[i] = 0;       maxTree[i] = 0;     }     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int pos, op;       scanf( %d %d , &pos, &op);       pos = n - pos + 1;       if (op) {         int number;         scanf( %d , &number);         p[pos] = number;         update(1, 1, n, pos, n, 1);       } else {         p[pos] = -1;         update(1, 1, n, pos, n, -1);       }       if (maxTree[1] > 0) {         int index = findIndex(1, 1, n);         printf( %d n , p[index]);       } else {         printf( -1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma optimize( SEX_ON_THE_BEACH )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 )   #pragma GCC optimize( fast-math )   using ll = long long int;   using ull = long long int;   using dd = double;   using ldd = long double;   namespace Hashes {   const int mod197 = 1e9 + 7;   const int mod199 = 1e9 + 9;   const int modfft = 998244353;   int MOD = mod197;   template <typename T = int>   struct Hash {     T me, mod;     Hash() {}     Hash(T _me, T _mod = MOD) {       me = _me, mod = _mod;       if (me >= mod) me %= mod;     }     Hash operator+(Hash to) {       to.me += me;       if (to.me >= to.mod) to.me -= to.mod;       return to;     }     Hash operator-(Hash to) {       to.me -= me;       to.me *= -1;       if (to.me < 0) to.me += to.mod;       return to;     }     Hash operator*(Hash to) {       to.me *= me;       to.me %= to.mod;       return to;     }     Hash& operator+=(Hash to) {       me += to.me;       if (me >= mod) me -= mod;       return *this;     }     Hash& operator-=(Hash to) {       me -= to.me;       if (me < 0) me += mod;       return *this;     }     Hash& operator*=(Hash to) {       me *= to.me;       me %= mod;       return *this;     }     bool operator==(Hash to) { return me == to.me; }     T operator*() { return me; }   };   }  // namespace Hashes   namespace someUsefull {   template <typename T1, typename T2>   inline void checkMin(T1& a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   inline void checkMax(T1& a, T2 b) {     if (a < b) a = b;   }   const int _popcount_size_ = 16;   char _bits_count_[1 << _popcount_size_];   inline void _build_bits_count_() {     for (int i = 1, j = 0; i < (1 << _popcount_size_); ++i) {       if (i & (1 << (j + 1))) ++j;       _bits_count_[i] = _bits_count_[i ^ (1 << j)] + 1;     }   }   template <typename T1 = int, typename T2 = int>   inline T1 popcnt(T2 x) {     T1 ans = 0;     while (x) {       ans += _bits_count_[x & (1 << _popcount_size_) - 1];       x >>= _popcount_size_;     }     return ans;   }   }  // namespace someUsefull   using namespace std;   using namespace Hashes;   using namespace someUsefull;   vector<vector<int>> gr;   vector<vector<pair<int, ll>>> hr;   set<pair<int, int>> br;   vector<int> tin, tout, cmp;   vector<int> was;   vector<ll> pr;   vector<ll> dp;   vector<ll> ans;   vector<int> cntST;   vector<int> isMe;   int TT;   int t = 0;   void dfs(int v, int p = -1) {     tin[v] = tout[v] = ++t;     was[v] = 1;     for (int to : gr[v]) {       if (to == p) continue;       if (was[to] == 1)         checkMin(tout[v], tin[to]);       else {         dfs(to, v);         checkMin(tout[v], tout[to]);         if (tout[to] > tin[v]) {           br.insert({v, to});           br.insert({to, v});         }       }     }   }   void dfs2(int v, int c) {     cmp[v] = c;     for (int to : gr[v])       if (!cmp[to] && br.count({v, to}) == 0) dfs2(to, c);   }   void dfs3(int v, int p = -1) {     cntST[v] = isMe[v];     for (pair<int, int> to : hr[v]) {       if (to.first == p) continue;       dfs3(to.first, v);       cntST[v] += cntST[to.first];     }   }   void dpC(int v, int p = -1) {     dp[v] += pr[v];     for (pair<int, int> to : hr[v]) {       if (to.first == p) continue;       dpC(to.first, v);       if (cntST[to.first] != 0 && cntST[to.first] != TT)         dp[v] += max(0ll, dp[to.first] - to.second);       else         dp[v] += dp[to.first];     }   }   void dpF(int v, int p = -1) {     ans[v] = dp[v];     for (pair<int, int> to : hr[v]) {       if (to.first == p) continue;       if (cntST[to.first] != 0 && cntST[to.first] != TT)         dp[v] -= max(0ll, dp[to.first] - to.second);       else         dp[v] -= dp[to.first];       cntST[v] -= cntST[to.first];       if (cntST[v] != 0 && cntST[v] != TT)         dp[to.first] += max(0ll, dp[v] - to.second);       else         dp[to.first] += dp[v];       cntST[to.first] += cntST[v];       dpF(to.first, v);       if (cntST[v] != 0 && cntST[v] != TT)         dp[to.first] -= max(0ll, dp[v] - to.second);       else         dp[to.first] -= dp[v];       cntST[to.first] -= cntST[v];       if (cntST[to.first] != 0 && cntST[to.first] != TT)         dp[v] += max(0ll, dp[to.first] - to.second);       else         dp[v] += dp[to.first];       cntST[v] += cntST[to.first];     }   }   void solve(int test) {     int n, k, m;     cin >> n >> m >> k;     vector<int> inter(k);     vector<ll> cc(n);     vector<ll> w(m);     for (int i = 0; i < k; ++i) cin >> inter[i];     for (int i = 0; i < n; ++i) cin >> cc[i];     for (int i = 0; i < m; ++i) cin >> w[i];     vector<pair<int, int>> ed;     gr.resize(n);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       ed.push_back({a, b});       gr[a].push_back(b);       gr[b].push_back(a);     }     tin.resize(n);     tout.resize(n);     cmp.resize(n);     was.resize(n);     dfs(0);     int c = 1;     for (int i = 0; i < n; ++i) {       if (cmp[i] == 0) {         dfs2(i, c);         c++;       }     }     for (int i = 0; i < n; ++i) --cmp[i];     --c;     hr.resize(c);     pr.resize(c);     dp.resize(c);     ans.resize(c);     cntST.resize(c);     isMe.resize(c);     for (int i : inter) isMe[cmp[i - 1]] = 1;     for (int i = 0; i < n; ++i) {       pr[cmp[i]] += cc[i];     }     for (int i = 0; i < m; ++i) {       if (br.count(ed[i])) {         hr[cmp[ed[i].first]].push_back({cmp[ed[i].second], w[i]});         hr[cmp[ed[i].second]].push_back({cmp[ed[i].first], w[i]});       }     }     dfs3(0);     TT = cntST[0];     dpC(0);     0;     ;     dpF(0);     for (int i = 0; i < n; ++i) {       cout << ans[cmp[i]] <<    ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     _build_bits_count_();     int t = 1;     for (int i = 0; i < t; ++i) {       solve(i + 1);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<pii>;   using vll = vector<pll>;   #define fi first   #define se second   #define sz(c)  ((int)(c).size())   #define all(c) (c).begin(), (c).end()   #define forn(i, m, n)  for (int i = m, nnnn = (n); i < nnnn; ++i)   #define pb  push_back   #define mp  make_pair   //using int128 = __int128_t;   ll P = 1000000007;       int main(){    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    int n, t;    cin >> n >> t;    ll prev = 0;    ll segmenttree[4*n];    forn(i, 0, 4*n) segmenttree[i] = -1;       while (t--){     int k;     cin >> k;     cout.flush();     ll low = 1, high = n, curr = 0, index = 1;     while (low <= high){      ll mid = (low + high)/2;      ll temp = segmenttree[index];      if (segmenttree[index] == -1){       cout <<  ?  <<     << low <<     << mid << endl;       cout.flush();       cin >> temp;       cout.flush();       segmenttree[index] = temp;      }       if ((mid - low + 1 - temp) + curr < k) {       curr += (mid - low + 1 - temp);       low = mid + 1;       index = index * 2 + 1;      } else {       high = mid - 1;       index *= 2;      }      //cout << low <<     << high <<   n ;     }     cout <<  !  <<     << low <<   n ;     cout.flush();     if(index % 2 == 0) segmenttree[index]++;     while (index != 0) {      bool add = (index % 2 == 0);      index /= 2;      if (add) segmenttree[index]++;     }    }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     char ch;     int Sum = 0, Count = 0;     n /= 2;     for (int i = 1; i <= n; i++) {       cin >> ch;       if (ch ==  4  || ch ==  7 ) {         Count++;       }       Sum += ch -  0 ;     }     for (int i = 1; i <= n; i++) {       cin >> ch;       if (ch ==  4  || ch ==  7 ) {         Count++;       }       Sum -= ch -  0 ;     }     cout << (Sum == 0 && Count == n * 2 ?  YES  :  NO );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<int> v[maxn];   int ma = 0;   int h = 0;   int f = 0;   int root = 0;   int g[maxn];   bool mark[maxn];   void dfs(int k) {     if (mark[k] == false) {       mark[k] = true;     } else {       return;     }     for (int i = 0; i < v[k].size(); i++) {       int child = v[k][i];       if (mark[child] == false) {         g[h]++;         dfs(child);       }     }     if (v[k].size() == 1 && root != k) {       if (g[h] + 1 > ma) {         ma = g[h] + 1;       }       f = 1;     }     if (f == 1) {       g[h]--;     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int u;       cin >> u;       if (u == -1) {         mark[i] = true;       } else {         v[i].push_back(u);         v[u].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       if (mark[i] == true) {         mark[i] = false;         root = i;         dfs(i);         h++;       }     }     if (ma == 0) {       cout << 1;       return 0;     }     cout << ma;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     map<long long, long long> cnt1, cnt2;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     long long run = 0;     for (long long i = 0; i < n; i++) {       if (a[i] == 0) {         if (run) {           cnt1[run]++;           run = 0;         }       } else {         run++;       }     }     if (run) {       cnt1[run]++;     }     run = 0;     for (long long i = 0; i < m; i++) {       if (b[i] == 0) {         if (run) {           cnt2[run]++;           run = 0;         }       } else {         run++;       }     }     if (run) {       cnt2[run]++;     }     long long ans = 0;     for (long long i = 1; i * i <= k; i++) {       if (k % i == 0) {         long long j = k / i;         auto it1 = cnt1.lower_bound(i);         auto it2 = cnt2.lower_bound(j);         while (it1 != cnt1.end()) {           auto it3 = it2;           long long x = (it1->first - i + 1) * it1->second;           while (it3 != cnt2.end()) {             long long y = (it3->first - j + 1) * it3->second;             ans += x * y;             it3++;           }           it1++;         }         if (i != j) {           it1 = cnt1.lower_bound(j);           it2 = cnt2.lower_bound(i);           while (it1 != cnt1.end()) {             auto it3 = it2;             long long x = (it1->first - j + 1) * it1->second;             while (it3 != cnt2.end()) {               long long y = (it3->first - i + 1) * it3->second;               ans += x * y;               it3++;             }             it1++;           }         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return (b != 0 ? gcd(b, a % b) : a); }   int lcm(int a, int b) { return (a / gcd(a, b) * b); }   int R[] = {1, -1, 0, 0, 1, -1, -1, 1};   int C[] = {0, 0, 1, -1, 1, -1, 1, -1};   int KR[] = {-2, -2, -1, 1, 2, 2, -1, 1};   int KC[] = {1, -1, 2, 2, 1, -1, -2, -2};   struct P {     double x, y;     P(double x = 0.0, double y = 0.0) {       this->x = x;       this->y = y;     }   };   P mkv(P ae, P be) { return P(be.x - ae.x, be.y - ae.y); }   double dtp(P ae, P be) { return (ae.x * be.x + ae.y * be.y); }   double crp(P ae, P be) { return (ae.x * be.y - ae.y * be.x); }   double val(P ae) { return sqrt(dtp(ae, ae)); }   P vresize(P ae, double llen) {     double v = val(ae);     return P(ae.x * llen / v, ae.y * llen / v);   }   double ART(P ae, P be) { return crp(ae, be) / 2.0; }   P rot(P ae, double ang) {     return P(ae.x * cos(ang) - ae.y * sin(ang),              ae.y * cos(ang) + ae.x * sin(ang));   }   int main() {     int a, b, c, d, h, m, n, p, x, y, i, j, k, l, q, r, t, cnt, sm, tmp;     scanf( %d %d %d %d , &a, &b, &c, &d);     sm = max((3.0 * a) / 10.0, a - (a * c / 250.0));     cnt = max((3.0 * b) / 10.0, b - (b * d / 250.0));     if (sm > cnt)       printf( Misha n );     else if (cnt > sm)       printf( Vasya n );     else       printf( Tie n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[11111111];   long long b[11111111];   int len = 0;   long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }   int counter(int x) {     int res = 0;     while (x) {       res++;       x /= 10;     }     return res;   }   void printK(int x, int k) {     int n = counter(x);     n = n - k + 1;     for (int i = 0; i < n - 1; i++) x /= 10;     cout << x % 10 <<   n ;   }   long long g(long long x) {     long long res = 0;     int len = 1;     long long tmp = 9;     while (x > tmp) {       res += tmp * len;       x -= tmp;       tmp *= 10;       len++;     }     res += x * len;     return res;   }   long long f(long long x) {     long long res = 0;     long long tmp = 0;     while (x >= 0) {       res += (1 + x) * x / 2;       if (tmp == 0)         tmp = 9;       else         tmp = tmp * 10;       x -= tmp;     }     return res;   }   int main() {     long long q, k;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> k;       long long m, l = 0, r = 2000000001;       while (l < r - 1) {         m = (l + r) >> 1;         if (f(m) < k) {           l = m;         } else {           r = m;         }       }       k -= f(l);       r = l + 2, l = 0;       while (l < r - 1) {         m = (l + r) >> 1;         if (g(m) < k) {           l = m;         } else {           r = m;         }       }       k -= g(l);       long long n = 0;       long long L = l + 1;       l++;       while (L) {         L /= 10;         n++;       }       n = n - k + 1;       for (int j = 0; j < n - 1; j++) l /= 10;       cout << l % 10 << endl;     }     return 0;   }