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


#include <bits/stdc++.h>   using namespace std;   int inline read() {     int num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   const int maxn = 100010, mod = 1e9 + 7;   int n, m, ans = 2, f[maxn];   int main() {     n = read();     m = read();     if (n < m) swap(n, m);     f[1] = 4;     for (int i = 2; i <= m; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;     for (int i = 1; i < m; i++) ans = (ans + f[i]) % mod;     f[1] = 2;     for (int i = 2; i <= n; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;     for (int i = m + 1; i <= n; i++) ans = (ans + f[i - 1]) % mod;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[500005], l = 1, r, b[500005];   queue<int> Q;   bool flag = false;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) a[i] = i & -i;     for (int i = 1; i <= n; ++i) b[i] = 1;     r = n;     while (m--) {       int opt, x, y;       scanf( %d , &opt);       if (opt == 1) {         scanf( %d , &x);         if (flag)           x = r - x + 1;         else           x += l;         if (r - x + 1 > x - l)           while (l < x) {             int tmp = 0;             for (int j = l; j; j -= j & -j) tmp += a[j];             for (int j = l - 1; j; j -= j & -j) tmp -= a[j];             for (int j = l; j <= n; j += j & -j) a[j] -= tmp;             b[x + x - l - 1] += b[l];             b[l] = 0;             for (int j = x + x - l - 1; j <= n; j += j & -j) a[j] += tmp;             l++;             flag = false;           }         else           while (r >= x) {             for (int i = x; i <= r; ++i) {               int tmp = 0;               for (int j = i; j; j -= j & -j) tmp += a[j];               for (int j = i - 1; j; j -= j & -j) tmp -= a[j];               for (int j = i; j <= n; j += j & -j) a[j] -= tmp;               b[i] = 0;               Q.push(tmp);             }             for (int i = x - 1; i >= x - (r - x + 1); --i) {               int tmp = Q.front();               Q.pop();               for (int j = i; j <= n; j += j & -j) a[j] += tmp;               b[i] += tmp;             }             r = x - 1;             flag = true;           }       }       if (opt == 2) {         scanf( %d%d , &x, &y);         int xx, yy;         if (flag) {           xx = r - y;           yy = r - x;           x = xx, y = yy;         } else           x = x + l - 1, y = y + l - 1;         int ans = 0;         for (int j = y; j; j -= j & -j) ans += a[j];         for (int j = x; j; j -= j & -j) ans -= a[j];         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[500010];   pair<int, int> b[500010];   int c[500010];   int T, n, tot;   int main(void) {     T = 1;     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         b[i] = {a[i], -i};       }       sort(b + 1, b + 1 + n);       for (int i = 1; i <= n; ++i) {         if (-b[i].second >= b[i].first) {           int x = -(b[i].second + b[i].first);           int pos = upper_bound(c + 1, c + 1 + tot, x) - c;           c[pos] = x;           tot = max(pos, tot);         }       }       printf( %d n , tot);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   template <typename T>   T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   template <class T>   inline bool read(T &ret) {     char c = getchar();     int sgn;     if (c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (static_cast<void>(c = getchar()), c >=  0  && c <=  9 )       ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void write(T x) {     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1e5 + 5;   int x[4], y[4], an[N], n;   void doit(int j) {     int k = 0;     for (int i = 0; i < (int)(4); ++i) y[i] = x[i];     while (true) {       if (j == 4 || y[j] == 0) break;       an[k++] = j;       --y[j];       if (j > 0 && y[j - 1] > 0)         --j;       else         ++j;     }     if (k == n) {       cout <<  YES  << endl << an[0];       for (int i = 1; i < (int)(n); ++i) cout <<     << an[i];       cout << endl;       exit(0);     }   }   void solve(int times) {     for (int i = 0; i < (int)(4); ++i) cin >> x[i], n += x[i];     for (int j = 0; j < (int)(4); ++j) doit(j);     cout <<  NO  << endl;   }   void Init() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int times = 1;     {       solve(times++);       Init();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 0;     cin >> n;     int a[n], res[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       res[i] = 0;     }     for (int i = 0; i < n - 1; i++) {       if (i) res[i] = res[i - 1];       while (a[i]) {         int t = 0;         for (t = 0; i + (1 << t) < n; t++)           ;         t--;         a[i]--;         a[i + (1 << t)]++;         res[i]++;       }     }     for (int i = 0; i < n - 1; i++) cout << res[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n >> str;     int p = 0;     if (n % 2 == 1) {       p = 3;       cout << str.substr(0, 3);       if (n != 3) cout <<  - ;     }     for (int i = p; i < str.length(); i += 2) {       cout << str.substr(i, 2);       if (i != str.length() - 2) cout <<  - ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3030;   struct dsu {     int par[MAXN];     void clear() {       for (int i = 0; i < MAXN; ++i) par[i] = i;     }     int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }     bool join(int u, int v) {       if ((u = find(u)) == (v = find(v))) return false;       par[v] = u;       return true;     }   } dsu;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i], a[i]--;     int m;     cin >> m;     vector<pair<int, int>> moves;     int step = 0;     while (true) {       dsu.clear();       int cst = 0;       for (int i = 0; i < n; ++i) cst += dsu.join(i, a[i]);       vector<int> b(n);       for (int i = 0; i < n; ++i) b[a[i]] = i;       if (cst < m) {         int u = 0;         int v = 1;         while (dsu.find(u) == dsu.find(v)) v++;         moves.emplace_back(u, v);         swap(a[u], a[v]);       } else if (cst > m) {         int u = 0;         while (a[u] == u) u++;         int v = u + 1;         while (dsu.find(v) != dsu.find(u)) v++;         moves.emplace_back(u, v);         swap(a[u], a[v]);       } else         break;     }     cout << moves.size() <<   n ;     for (auto &p : moves) cout << p.first + 1 <<     << p.second + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   const int MAXK = 17;   int X[MAXN];   long long Y[MAXN];   int N, M;   int par[MAXN][MAXK];   int dpth[MAXN];   int Q[MAXN];   int ql = 0, qr = 0;   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 1; i <= N; ++i) {       cin >> X[i] >> Y[i];     }     for (int i = N; i > 0; --i) {       while (ql + 1 < qr) {         int a = Q[qr - 1], b = Q[qr - 2];         if ((Y[b] - Y[i]) * (X[a] - X[i]) > (Y[a] - Y[i]) * (X[b] - X[i])) {           --qr;         } else           break;       }       if (ql < qr) {         par[i][0] = Q[qr - 1];         dpth[i] = dpth[Q[qr - 1]] + 1;       } else         par[i][0] = i;       Q[qr] = i;       ++qr;     }     for (int k = 0; k + 1 < MAXK; ++k) {       for (int i = 1; i <= N; ++i) {         par[i][k + 1] = par[par[i][k]][k];       }     }     cin >> M;     for (int q = 0; q < M; ++q) {       int a, b;       cin >> a >> b;       if (dpth[a] < dpth[b]) swap(a, b);       for (int i = MAXK - 1; i >= 0; --i) {         if (dpth[par[a][i]] >= dpth[b]) {           a = par[a][i];         }       }       for (int i = MAXK - 1; i >= 0; --i) {         if (par[a][i] != par[b][i]) {           a = par[a][i];           b = par[b][i];         }       }       if (a != b) {         a = par[a][0];         b = par[b][0];       }       if (a != b) printf( what n );       printf( %d  , a);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   mt19937 rng;   ll MAX = 1e18;   const int MN = 1e3 + 100;   int get_rand(int x) {     return static_cast<int>(static_cast<ll>(rng()) * x /                             (static_cast<ll>(rng.max()) - rng.min() + 1));   }   int N;   ll L, E;   array<ll, 2> ans[MN];   ll get(int f, ll x) {     printf( ? %d %lld n , f, x);     fflush(stdout);     ll r;     scanf( %lld , &r);     return r;   }   ll loc(int f, ll v, ll l = 0, ll r = MAX) {     r++;     ll m;     while (r - l > 1) {       m = l + (r - l >> 1);       if (get(f, m) > v)         r = m;       else         l = m;     }     return l;   }   void solve(vector<int>& v, int l, int r, ll lp, ll rp) {     if (v.size() == 1) return ans[v[0]] = {lp, rp}, void();     random_shuffle(v.begin(), v.end(), get_rand);     int m = l + (r - l >> 1);     ll mp;     function<ll(vector<int>&, int)> kth_element = [&](vector<int>& x, int k) {       vector<int> a, b, c;       b.push_back(x.back());       ll t = loc(x.back(), m * E, lp, rp);       for (x.pop_back(); !x.empty(); x.pop_back()) {         ll q = get(x.back(), t);         if (m * E < q)           a.push_back(x.back());         else if (q < m * E)           c.push_back(x.back());         else           b.push_back(x.back());       }       if (k < a.size())         t = kth_element(a, k);       else if (a.size() + b.size() <= k)         t = kth_element(c, k - a.size() - b.size());       for (int i : a) x.push_back(i);       for (int i : b) x.push_back(i);       for (int i : c) x.push_back(i);       return t;     };     mp = kth_element(v, m - l);     vector<int> L, R;     for (int i = 0; i < m - l; i++) L.push_back(v[i]);     for (int i = m - l; i < r - l; i++) R.push_back(v[i]);     solve(L, l, m, lp, mp);     solve(R, m, r, mp, rp);   }   int main(void) {     srand(clock());     scanf( %d%lld , &N, &L);     E = L / N;     vector<int> a;     for (int i = 1; i <= N; i++) a.push_back(i);     solve(a, 0, N, 0, MAX);     printf( ! n );     for (int i = 1; i <= N; i++) printf( %lld %lld n , ans[i][0], ans[i][1]);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, u, r;   int a[31], b[31], k[31], p[31];   long long int s = -333;   void calc(vector<int> &v) {     int f[31];     for (int j = 0; j < n; j++) {       f[j] = a[j];     }     for (int j = 0; j < v.size(); j++) {       if (v[j]) {         for (int i = 0; i < n; i++) {           f[i] ^= b[i];         }       } else {         int g[31];         for (int i = 0; i < n; i++) {           g[i] = f[p[i] - 1] + r;         }         for (int j = 0; j < n; j++) {           f[j] = g[j];         }       }     }     long long int c = 0;     for (int j = 0; j < n; j++) {       c += k[j] * f[j];     }     if (s != -333) {       s = max(c, s);     } else {       s = c;     }   }   void func(vector<int> v) {     int d = v.size();     if (v[d - 1] == 0) {       for (int i = d; i < u; i++) {         vector<int> f = v;         f.push_back(1);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(f);         func(f);         for (int j = i + 1; j < u; j++) {           f.push_back(0);         }         calc(f);         v.push_back(0);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(v);       }     } else {       if (d < u) {         v.push_back(0);         if ((u - d - 1) % 2 == 0 && (u - d - 1 > 0)) calc(v);       }       for (int i = d + 1; i < u; i++) {         vector<int> f = v;         f.push_back(1);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(f);         func(f);         for (int j = i + 1; j < u; j++) {           f.push_back(0);         }         calc(f);         v.push_back(0);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(v);       }     }   }   int solve() {     cin >> n >> u >> r;     for (int j = 0; j < n; j++) {       cin >> a[j];     }     for (int j = 0; j < n; j++) {       cin >> b[j];     }     for (int j = 0; j < n; j++) {       cin >> k[j];     }     for (int j = 0; j < n; j++) {       cin >> p[j];     }     vector<int> v1, v2;     v1.push_back(0);     v2.push_back(1);     vector<int> v3, v4;     v3.push_back(1);     v4.push_back(0);     for (int j = 0; j < u - 1; j++) {       v3.push_back(0);       v4.push_back(0);     }     if (u % 2 == 0) {       s = 0;       for (int j = 0; j < n; j++) {         s += a[j] * k[j];       }     }     calc(v4);     calc(v3);     func(v1);     func(v2);     cout << s <<   n ;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010, oo = 1e9;   int n;   char s[maxn][maxn];   int f[maxn][maxn], fuck[maxn];   pair<int, int> pre[maxn][maxn];   vector<pair<int, int> > all, foo;   int main() {     scanf( %d , &n);     int m;     scanf( %d , &m);     for (int i = 1; i <= n; ++i) scanf( %s , s[i] + 1);     f[1][1] = (s[1][1] ==  a  ? 0 : 1);     if (m < f[1][1]) {       putchar(s[1][1]);       all.push_back(make_pair(1, 1));     } else {       int lst = 2;       for (int k = 3; k <= n + n; ++k) {         for (int i = 1; i <= n; ++i) {           int j = k - i;           if (j >= 1 && j <= n) {             f[i][j] = oo;             if (i > 1)               f[i][j] = min(f[i][j], f[i - 1][j] + (s[i][j] ==  a  ? 0 : 1));             if (j > 1)               f[i][j] = min(f[i][j], f[i][j - 1] + (s[i][j] ==  a  ? 0 : 1));             if (f[i][j] <= m) lst = k;           }         }       }       for (int i = 2; i <= lst; ++i) putchar( a );       if (lst == n + n) return 0;       for (int i = 1; i <= n; ++i) {         int j = lst - i;         if (j >= 1 && j <= n && f[i][j] <= m) all.push_back(make_pair(i, j));       }     }     int T = 0;     for (;;) {       if (all[0].first == n && all[0].second == n) break;       char mn =  z  + 1;       for (auto p : all) {         int x = p.first, y = p.second;         if (x + 1 <= n) mn = min(mn, s[x + 1][y]);         if (y + 1 <= n) mn = min(mn, s[x][y + 1]);       }       foo.clear();       ++T;       for (auto p : all) {         int x = p.first, y = p.second;         if (x + 1 <= n && s[x + 1][y] == mn) {           if (fuck[x + 1] != T)             fuck[x + 1] = T, foo.push_back(make_pair(x + 1, y)),                      pre[x + 1][y] = p;         }         if (y + 1 <= n && s[x][y + 1] == mn) {           if (fuck[x] != T)             fuck[x] = T, foo.push_back(make_pair(x, y + 1)), pre[x][y + 1] = p;         }       }       all = foo;     }     vector<char> ans;     for (int x = n, y = n; x && y;) {       auto t = pre[x][y];       if (!t.first || !t.second) break;       ans.push_back(s[x][y]);       x = t.first, y = t.second;     }     reverse(ans.begin(), ans.end());     for (auto c : ans) putchar(c);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > pq;   int dp[11][11];   void ini() {     int i, j;     for (int i = 0; i < 11; i++)       for (j = 0; j <= max(i, 10); j++) {         if (i == 0)           dp[i][j] = 0;         else if (i == j || j == 0)           dp[i][j] = 1;         else if (j == 1)           dp[i][j] = i;         else           dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];       }   }   int main() {     ini();     int b, i, n, t, m, sum, x, y;     string s1, s2;     cin >> s1;     cin >> s2;     int l = s1.length();     sum = 0;     x = 0;     y = 0;     for (int i = 0; i < l; i++)       if (s1[i] ==  + ) sum++;     int sum2 = 0;     for (int i = 0; i < l; i++) {       if (s2[i] ==  + )         sum2++;       else if (s2[i] ==  ? )         x++;     }     int anss = 0;     double answ = 0;     if (sum - sum2 < 0)       answ = 0;     else if (sum == sum2 && x == 0)       answ = 1;     else if (sum != sum2 && x == 0)       answ = 0;     else {       anss = dp[x][sum - sum2];       answ = (double)anss / pow(2, x);     }     printf( %0.11lf , answ);   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   int N, C;   vector<int> c[6];   vector<pair<int, int> > cl;   int seq[100008];   bool seen[100008];   struct Action {     int len;     int b[5];     int c[5];   };   vector<Action> act;   void cycle2action(int c, int l, Action &a, int p) {     a.c[p + l - 1] = a.b[p] = c;     for (int i = (1); i < (l); ++i) {       a.c[p + i - 1] = a.b[p + i] = seq[a.b[p + i - 1]];     }   }   int main() {     cin >> N;     for (int i = (1); i < (N + 1); ++i) cin >> seq[i];     fill_n(seen, N + 1, false);     C = 0;     for (int i = (1); i < (N + 1); ++i)       if (!seen[i]) {         seen[i] = true;         if (seq[i] == i) continue;         C++;         int len = 1;         for (int k = seq[i]; k != i; k = seq[k]) {           seen[k] = true;           len++;         }         if (len <= 5) {           c[len].push_back(i);           continue;         }         cl.push_back(pair<int, int>(i, len));       }     while (C > 0) {       while (!cl.empty()) {         int l = cl.back().second;         int k = cl.back().first;         cl.pop_back();         Action a;         a.len = 5;         cycle2action(k, 5, a, 0);         l -= 4;         seq[a.c[4]] = seq[a.b[4]];         if (l > 5)           cl.push_back(pair<int, int>(a.c[4], l));         else           c[l].push_back(a.c[4]);         act.push_back(a);       }       for (int l = (4); l < (6); ++l) {         while (!c[l].empty()) {           Action a;           a.len = l;           cycle2action(c[l].back(), l, a, 0);           c[l].pop_back();           act.push_back(a);           C--;           continue;         }       }       while (int((c[2]).size()) && int((c[3]).size())) {         Action a;         a.len = 5;         cycle2action(c[2].back(), 2, a, 0);         cycle2action(c[3].back(), 3, a, 2);         c[2].pop_back();         c[3].pop_back();         act.push_back(a);         C -= 2;         continue;       }       while (int((c[2]).size()) >= 2) {         Action a;         a.len = 4;         cycle2action(c[2].back(), 2, a, 0);         c[2].pop_back();         cycle2action(c[2].back(), 2, a, 2);         c[2].pop_back();         act.push_back(a);         C -= 2;       }       if (int((c[3]).size()) >= 2) {         Action a;         a.len = 5;         cycle2action(c[3].back(), 3, a, 0);         c[3].pop_back();         int k = c[3].back();         c[3].pop_back();         int l = seq[k];         int m = seq[l];         a.b[3] = a.c[4] = k;         a.b[4] = a.c[3] = m;         swap(seq[k], seq[m]);         c[2].push_back(l);         act.push_back(a);         C--;         continue;       }       if (int((c[3]).size()) == 1) {         Action a;         a.len = 3;         cycle2action(c[3].back(), 3, a, 0);         c[3].pop_back();         act.push_back(a);         C--;         continue;       }       if (int((c[2]).size()) == 1) {         Action a;         a.len = 2;         cycle2action(c[2].back(), 2, a, 0);         c[2].pop_back();         act.push_back(a);         C--;         continue;       }     }     cout << int((act).size()) << endl;     for (__typeof__((act).begin()) a = (act).begin(); a != (act).end(); ++a) {       cout << a->len << endl;       for (int i = (0); i < (a->len); ++i) cout << (i ?     :   ) << a->b[i];       cout << endl;       for (int i = (0); i < (a->len); ++i) cout << (i ?     :   ) << a->c[i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ko(int k, int y) {     string g =   ;     while (y > 0) {       g = char(y % k + 48) + g;       y = y / k;     }     return g;   }   int main() {     int k;     cin >> k;     int i, j;     for (i = 1; i <= k - 1; i++) {       for (j = 1; j <= k - 1; j++) {         cout << ko(k, i * j) <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     if (a == d || b == e || c == f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-6;   const long long oo = 1LL << 60;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int N = 100005;   struct segTree {     int num;     long long sum[5];   } node[N << 2];   struct Query {     int type, num;   } q[N];   void pushup(int rt) {     node[rt].num = (node[(rt << 1)].num + node[(rt << 1 | 1)].num) % 5;     int leftSonNum = node[(rt << 1)].num;     for (int i = 0; i < 5; ++i)       node[rt].sum[i] = node[(rt << 1)].sum[i] +                         node[(rt << 1 | 1)].sum[(i - leftSonNum + 5) % 5];   }   void update(int l, int r, int rt, int p, int v) {     if (l == r) {       node[rt].num = (v > 0);       node[rt].sum[1] = (v > 0 ? v : 0);       return;     }     if (p <= ((l + r) >> 1))       update(l, ((l + r) >> 1), (rt << 1), p, v);     else       update(((l + r) >> 1) + 1, r, (rt << 1 | 1), p, v);     pushup(rt);   }   vector<int> arr;   int pos[N];   int main() {     int n;     char s[5];     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       if (s[0] ==  a ) {         scanf( %d , &q[i].num);         q[i].type = 1;         arr.push_back(q[i].num);       } else if (s[0] ==  d ) {         scanf( %d , &q[i].num);         q[i].type = 2;       } else         q[i].type = 0;     }     sort((arr).begin(), (arr).end());     arr.erase(unique((arr).begin(), (arr).end()), arr.end());     for (int i = 0; i < n; ++i)       if (q[i].type)         pos[i] =             lower_bound((arr).begin(), (arr).end(), q[i].num) - arr.begin() + 1;     int siz = (int(arr.size()));     for (int i = 0; i < n; ++i) {       if (q[i].type == 1)         update(1, siz, 1, pos[i], q[i].num);       else if (q[i].type == 2)         update(1, siz, 1, pos[i], -q[i].num);       else         printf( %I64d n , node[1].sum[3]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100100], b[100100];   int id[100100], p[100100];   int main() {     int T = 1;     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         id[a[i]] = i;       }       for (int i = 1; i <= n; i++) {         scanf( %d , &b[i]);       }       for (int i = 1; i <= n; i++) {         int x = b[i];         int op = id[x];         p[i] = op;       }       for (int i = 1; i <= n; i++) printf( %d  , p[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int n, m, SG[55][55][55][55][2];   char mp[55][55];   int dfs(int x1, int y1, int x2, int y2, int type) {     if (x1 > x2 || y1 > y2) return 0;     if (SG[x1][y1][x2][y2][type] != -1) return SG[x1][y1][x2][y2][type];     bool vis[215];     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x = i + j, y = i - j + m;         if ((i + j) % 2 == type || x < x1 || x > x2 || y < y1 || y > y2) continue;         int nxt = 0;         if (mp[i][j] ==  L )           nxt = dfs(x + 1, y1, x2, y2, type) ^ dfs(x1, y1, x - 1, y2, type);         else if (mp[i][j] ==  R )           nxt = dfs(x1, y + 1, x2, y2, type) ^ dfs(x1, y1, x2, y - 1, type);         else           nxt = dfs(x + 1, y + 1, x2, y2, type) ^                 dfs(x1, y1, x - 1, y - 1, type) ^                 dfs(x + 1, y1, x2, y - 1, type) ^ dfs(x1, y + 1, x - 1, y2, type);         vis[nxt] = 1;       }     }     int res = 0;     while (vis[res]) ++res;     return SG[x1][y1][x2][y2][type] = res;   }   int main() {     memset(SG, -1, sizeof(SG));     n = read();     m = read();     for (int i = 1; i <= n; i++) scanf( %s , (mp[i] + 1));     int ans = (dfs(1, 1, n + m, n + m, 0) ^ dfs(1, 1, n + m, n + m, 1));     if (ans)       puts( WIN );     else       puts( LOSE );   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> v(n);     vector<long long> a;     for (long long i = 0; i < n; i++) {       cin >> v[i];       if (v[i] == 0) a.push_back(i);     }     for (long long i = 0; i < n; i++) {       long long k = upper_bound(a.begin(), a.end(), i) - a.begin();       long long ans = abs(i - a[k]);       if (k > 0) {         ans = min(ans, abs(i - a[k - 1]));       }       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct Point {     T x, y;     Point() {}     Point(T x_, T y_) : x(x_), y(y_) {}     using pair = std::pair<T, T>;     explicit operator pair() const { return pair(x, y); }     friend bool operator==(const Point& a, const Point& b) {       return pair(a) == pair(b);     }     friend bool operator!=(const Point& a, const Point& b) {       return pair(a) != pair(b);     }     friend bool operator<(const Point& a, const Point& b) {       return pair(a) < pair(b);     }     friend bool operator<=(const Point& a, const Point& b) {       return pair(a) <= pair(b);     }     friend bool operator>(const Point& a, const Point& b) {       return pair(a) > pair(b);     }     friend bool operator>=(const Point& a, const Point& b) {       return pair(a) >= pair(b);     }     friend std::ostream& operator<<(std::ostream& o, const Point& p) {       return o <<  (  << p.x <<  ,  << p.y <<  ) ;     }     friend std::istream& operator>>(std::istream& i, Point& p) {       return i >> p.x >> p.y;     }     Point& operator+=(const Point& p) {       x += p.x;       y += p.y;       return *this;     }     Point& operator-=(const Point& p) {       x -= p.x;       y -= p.y;       return *this;     }     friend Point operator+(const Point& a, const Point& b) {       return Point(a) += b;     }     friend Point operator-(const Point& a, const Point& b) {       return Point(a) -= b;     }     T cross(const Point& p) const { return x * p.y - y * p.x; }     T cross(const Point& p, const Point& q) const {       return (p - *this).cross(q - *this);     }   };   using Pt = Point<int>;   const int MAXN = 7000;   int A, B;   int N;   struct City {     Pt pt;     int id;     int deg;     friend bool operator<(const City& a, const City& b) { return a.pt < b.pt; }   } pts[MAXN];   int hsz;   int hull[MAXN];   void solve(int st, int en) {     if (st == en) return;     if (pts[st].deg == -1) return solve(st + 1, en);     if (pts[en].deg == -1) return solve(st, en - 1);     int len = 0;     int totdeg = 0;     for (int i = st; i <= en; i++) {       if (pts[i].deg == -1) continue;       len++;       totdeg += pts[i].deg;     }     assert(len);     assert(totdeg == len - 1);     assert(len >= 2);     {       hsz = 0;       for (int i = 0; i <= (en - st) * 2; i++) {         int cur = (i <= (en - st) ? (st + i) : (en + (en - st) - i));         if (pts[cur].deg == -1) continue;         while (hsz >= 2 && hull[hsz - 1] != en) {           if (pts[hull[hsz - 2]].pt.cross(pts[hull[hsz - 1]].pt, pts[cur].pt) <               0) {             break;           } else {             hsz--;           }         }         hull[hsz++] = cur;       }       hsz--;       assert(hsz >= 2);       assert(hull[hsz] == hull[0]);       for (int ind = 0; ind < hsz; ind++) {         int a = hull[ind], b = hull[ind + 1];         assert(pts[a].deg != -1 && pts[b].deg != -1);         if (pts[a].deg == 0 && pts[b].deg > 0) {           cout << pts[b].id <<     << pts[a].id <<   n ;           pts[b].deg--;           if (pts[b].deg == 0) {             pts[b].deg = -1;           } else {             pts[a].deg = -1;           }           return solve(st, en);         }       }     }     int pref = 0;     int lsz = 0;     for (int i = st; i <= en; i++) {       if (pts[i].deg == -1) continue;       int suff = pref + (pts[i].deg - 1);       lsz++;       if (lsz > 1 && lsz < len && (pref >= 0) != (suff >= 0)) {         int ldeg, rdeg;         if (pts[i].deg > 0) {           assert(pref < 0 && suff >= 0);           ldeg = -pref;           rdeg = suff + 1;           assert(ldeg + rdeg == pts[i].deg);         } else {           ldeg = 0;           rdeg = 0;         }         pts[i].deg = ldeg;         solve(st, i);         pts[i].deg = rdeg;         solve(i, en);         return;       }       pref = suff;     }     assert(false);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> A >> B;       N = A + B;       for (int i = 0; i < A; i++) {         pts[i].deg = 0;         pts[i].id = i + 1;       }       for (int i = A; i < A + B; i++) {         cin >> pts[i].deg;         assert(pts[i].deg > 0);         pts[i].id = i - A + 1;       }       for (int i = 0; i < N; i++) {         cin >> pts[i].pt;       }       sort(pts, pts + N);       cout <<  YES  <<   n ;       solve(0, N - 1);     }     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238;   using namespace std;   long long takeTurn(long long n) {     if (n % 2 == 1) return n - 1;     if (n % 4 == 0 && n > 4) return n - 1;     return n / 2;   }   void solve() {     long long n, res = 0;     cin >> n;     while (n > 0) {       long long t1 = takeTurn(n);       res += n - t1;       n = t1;       n = takeTurn(n);     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110][110];   int main() {     int n, m, i, j;     while (~scanf( %d %d , &n, &m)) {       for (i = 0; i < n; i++)         for (j = 0; j < m; j++) scanf( %d , &a[i]);       if (n & 1) {         cout << n << endl;         continue;       }       int vis;       for (i = 0; i < m; i++) {         for (j = 0, vis = 0; j < n; j++) {           if (a[j][i] != a[n - j - 1][i]) {             vis = 1;             break;           }         }         if (vis) break;       }       if (vis)         cout << n << endl;       else {         while (1) {           n /= 2;           if (n == 1 || (n & 1)) {             cout << n << endl;             break;           }           for (i = 0; i < m; i++) {             for (j = 0, vis = 0; j < n; j++) {               if (a[j][i] != a[n - j - 1][i]) {                 vis = 1;                 break;               }             }             if (vis) break;           }           if (vis) {             cout << n << endl;             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0;     int a, b, c;     string s1, s2, s3;     cin >> s1 >> s2 >> s3;     a = s1.size();     b = s2.size();     c = s3.size();     if ((a + b) != c) {       cout <<  NO ;       return 0;     }     s1 = s1 + s2;     for (int i = 0; i < c; i++) {       for (int j = 0; j < c; j++) {         if (s1[i] == s3[j]) {           k++;           s3[j] =  0 ;           break;         }       }     }     if (k == c)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


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


#include <bits/stdc++.h>   using std::cin;   using std::cout;   int dist(int from, int to, int count) {     if (from <= to) {       return to - from;     } else {       return dist(from, count - 1, count) + dist(0, to, count) + 1;     }   }   void output(const std::vector<int64_t>& boxes);   std::vector<int64_t> recover(const std::vector<int64_t>& boxes, int lastBox) {     std::vector<int64_t> result(boxes.size());     int minValue = *std::min_element(boxes.begin(), boxes.end());     int index = -1;     int minDist = -1;     for (size_t i = 0; i < boxes.size(); ++i) {       if (boxes[i] == minValue) {         if (index == -1 || minDist > dist(i, lastBox, boxes.size())) {           index = i;           minDist = dist(i, lastBox, boxes.size());         }       }     }     int64_t wasBalls =         boxes[index] * boxes.size() + dist(index, lastBox, boxes.size());     for (size_t i = 0; i < boxes.size(); ++i) {       if (i == index) {         result[i] = wasBalls;       } else {         int dst = dist(index, i, boxes.size()) - 1;         if (wasBalls >= dst) {           int64_t rem = wasBalls - dst;           int64_t add = rem / boxes.size();           if (rem % boxes.size() != 0) {             ++add;           }           result[i] = boxes[i] - add;           assert(result[i] >= 0);         } else {           result[i] = boxes[i];         }       }     }     return result;   }   void output(const std::vector<int64_t>& boxes) {     for (size_t i = 0; i < boxes.size(); ++i) {       cout << boxes[i] <<    ;     }     cout <<   n ;   }   void input(std::vector<int64_t>* boxes, int* lastBox) {     int count;     cin >> count >> *lastBox;     --(*lastBox);     boxes->resize(count);     for (int i = 0; i < count; ++i) {       cin >> (*boxes)[i];     }   }   void stressTest() {     int N = 10;     for (int tc = 0; tc < 1000; ++tc) {       std::vector<int64_t> a(N);       for (size_t i = 0; i < a.size(); ++i) {         if (rand() % 4 == 0) {           a[i] = 0;         } else {           a[i] = rand() % 1000;         }       }       int start = -1;       while (true) {         start = rand() % N;         if (a[start] == 0) {           continue;         }         break;       }       int cnt = a[start];       int realCnt = cnt;       a[start] = 0;       int i = (start + 1) % N;       for (; cnt > 0; cnt--, i = (i + 1) % N) {         ++a[i];       }       int end = (i + N - 1) % N;       std::vector<int64_t> b = recover(a, end);       assert(b[start] == realCnt);       b[start] = 0;       i = (start + 1) % N;       cnt = realCnt;       for (; cnt > 0; cnt--, i = (i + 1) % N) {         ++b[i];       }       if (a != b) {         cout << end + 1 <<   n ;         output(a);         output(b);         exit(0);       }       assert(a == b);     }   }   int main() {     std::ios_base::sync_with_stdio(false);     std::vector<int64_t> boxes;     int lastBox;     input(&boxes, &lastBox);     output(recover(boxes, lastBox));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, a, b;   void fn() {     cin >> a >> b;     if (a < b) swap(a, b);     a -= b;     int ans = a / 5;     a %= 5;     if (a == 1 || a == 2)       ans++;     else if (a == 3 || a == 4)       ans += 2;     cout << ans << endl;   }   int main() {     cin >> t;     while (t--) fn();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[300005];   void input() {     int i, l, r, x, cur, n, ne;     set<int> alive;     set<int>::iterator ite;     vector<int> xoa;     scanf( %d %d , &n, &ne);     for ((i) = (1); (i) <= (n); (i)++) alive.insert(i);     for ((i) = 0; (i) < (ne); (i)++) {       scanf( %d %d %d , &l, &r, &x);       xoa.clear();       ite = alive.lower_bound(l);       while (ite != alive.end()) {         cur = *ite;         if (cur > r) break;         if (cur != x) ans[cur] = x, xoa.push_back(cur);         ite++;       }       for (typeof(xoa.begin()) jte = xoa.begin(); jte != xoa.end(); jte++)         alive.erase(*jte);     }     for ((i) = (1); (i) <= (n); (i)++) printf( %d  , ans[i]);   }   int main() {     input();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     n = 2 * n + 1;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n - 1 && k; i++)       if (a[i - 1] + 1 < a[i] && a[i] > a[i + 1] + 1) {         a[i]--;         k--;       }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n + 1];     vector<pair<int, int>> c;     for (int i = 0; i < n; i++) cin >> a[i];     unordered_map<long long, long long> mp, mp1;     vector<vector<int>> v;     v.assign(n + 1, vector<int>());     for (int i = 0; i < n; i++) {       mp[a[i]]++;       v[n - a[i]].push_back(i + 1);     }     for (auto it : mp) {       c.push_back({it.second / (n - it.first), n - it.first});     }     int x = 0;     for (int i = 0; i < c.size(); i++) x += (c[i].first) * (c[i].second);     if (x != n)       cout <<  Impossible ;     else {       int y = 1;       cout <<  Possible n ;       for (auto it : c) {         for (int j = 0; j < it.first; j++) {           for (int k = 0; k < it.second; k++) {             x = *v[it.second].rbegin();             v[it.second].pop_back();             b[x] = y;           }           y += 1;         }       }       for (int i = 1; i <= n; i++) cout << b[i] <<    ;     }   }


#include <bits/stdc++.h>   int f[105][25][25], g[25][25], n, k, u, v;   std::vector<int> ch[105];   using ll = long long;   const int mod = 1e9 + 7;   void dfs(int u, int fa) {     f[u][0][1] = f[u][k][0] = 1;     for (int v : ch[u]) {       if (v == fa) continue;       dfs(v, u);       std::memcpy(g, f[u], sizeof(f[u]));       std::memset(f[u], 0, sizeof(f[u]));       for (int a = 0; a <= k; ++a)         for (int b = 0; b <= k; ++b)           for (int c = 0; c <= k; ++c)             for (int d = 0; d <= k; ++d) {               int d1 = b, d2 = d;               if (d1 <= c) d1 = 0;               if (d2 <= a) d2 = 0;               int i = std::max(a, c - 1);               int j = std::max(d1, d2 + (d2 != 0));               if (j <= k)                 f[u][i][j] = (f[u][i][j] + (ll)g[a][b] * f[v][c][d] % mod) % mod;             }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       ch[u].push_back(v);       ch[v].push_back(u);     }     dfs(1, 0);     int ans = 0;     for (int i = 0; i <= k; ++i) ans = (ans + f[1][i][0]) % mod;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   int a[30][2 * 100000 + 5], cnt[30];   char s[2 * 100000 + 5], t[2 * 100000 + 5];   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   int main() {     long long i, j, n, len, m, maxn;     scanf( %lld , &n);     scanf( %s , s);     for (i = 0; i < n; i++) {       cnt[s[i] -  a ]++;       a[s[i] -  a ][cnt[s[i] -  a ]] = i;     }     scanf( %lld , &m);     while (m--) {       memset(cnt, 0, sizeof(cnt));       scanf( %s , t);       len = strlen(t);       maxn = 0;       for (i = 0; i < len; i++) {         maxn = max(maxn, a[t[i] -  a ][cnt[t[i] -  a ] + 1] + 1);         cnt[t[i] -  a ]++;       }       printf( %lld n , maxn);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, a, b, c, d, t, input;     vector<int> vi;     for (i = 1; i <= 370; i++) {       t = i;       if (t <= 9) {         vi.push_back(t);       } else if (t >= 10 && t < 100) {         a = t % 10;         t = t / 10;         b = t;         vi.push_back(b);         vi.push_back(a);       } else if (t >= 100 && t < 1000) {         c = t % 10;         t = t / 10;         b = t % 10;         t = t / 10;         a = t;         vi.push_back(a);         vi.push_back(b);         vi.push_back(c);       } else if (t >= 1000) {         d = t % 10;         t /= 10;         c = t % 10;         t /= 10;         b = t % 10;         t /= 10;         a = t % 10;         vi.push_back(a);         vi.push_back(b);         vi.push_back(c);         vi.push_back(d);       }     }     while (cin >> input) {       cout << vi[input - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class DFS {     int N_, R_;     vector<vector<int> > G_;     vector<int> par_, dep_, dep_sub_;     void DFS_internal(int v) {       dep_sub_[v] = 0;       for (auto u : G_[v])         if (par_[u] == -1) {           par_[u] = v;           dep_[u] = dep_[v] + 1;           DFS_internal(u);           dep_sub_[v] = max(dep_sub_[v], dep_sub_[u] + 1);         }     }       public:     DFS(vector<vector<int> >& G, int R) : N_(G.size()), R_(R), G_(G) {       par_.resize(N_, -1);       dep_.resize(N_);       dep_sub_.resize(N_);       par_[R_] = R_;       dep_[R_] = 0;       DFS_internal(R_);     }     int max_dep_id() {       int ret = -1, max_dep = -1;       for (int i = 0; i < N_; i++)         if (max_dep < dep_[i]) {           max_dep = dep_[i];           ret = i;         }       return ret;     }     int dep(int v) { return dep_[v]; }     int par(int v) { return par_[v]; }     int dep_subtree(int v) { return dep_sub_[v]; }   };   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int N, K;     cin >> N >> K;     vector<vector<int> > G(N);     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       G[--u].push_back(--v);       G[v].push_back(u);     }     DFS DFS0(G, 0);     int R1 = DFS0.max_dep_id();     DFS DFS1(G, R1);     int R2 = DFS1.max_dep_id();     DFS DFS2(G, R2);     int D = DFS1.dep(R2);     if (K == 2) {       cout <<  Yes n ;       for (int i = 0; i < N; i++)         cout << DFS1.dep(i) % 2 + 1 << ((i == N - 1) ?   n  :    );       return 0;     }     vector<int> ans(N);     for (int i = 0; i < N; i++) {       if (DFS1.dep(i) + DFS2.dep(i) - D == 0) {         ans[i] = DFS1.dep(i) % K + 1;         continue;       }       int d1 = DFS1.dep_subtree(i) + DFS1.dep(i);       int d2 = DFS1.dep_subtree(i) + DFS2.dep(i);       if (min(d1, d2) >= K - 1) {         cout <<  No n ;         return 0;       }       if (max(d1, d2) < K - 1) {         ans[i] = 1;         continue;       }       if (d1 > d2)         ans[i] = DFS1.dep(i) % K + 1;       else         ans[i] = (D + K - DFS2.dep(i) % K) % K + 1;     }     cout <<  Yes n ;     for (int i = 0; i < N; i++) cout << ans[i] << ((i == N - 1) ?   n  :    );   }


#include <bits/stdc++.h>   #define ll long long    #define INF INT_MAX   #define pii pair<int,int>   using namespace std;      const int maxn=1e3+10;   const int mod=998244353;   int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll N,K;       cin>>N>>K;       vector<vector<ll>> p(maxn);       vector<ll> s1(maxn,0);       vector<ll> s2(maxn,0);       ll tem;       for(int i=0;i<K;i++){           for(int j=0;j<N;j++){               cin>>tem;               p[i].push_back(tem);               s1[i]+=tem;               s2[i]+=(tem*tem);           }       }       map<ll,ll> cnt;       map<ll,ll> cnt2;       ll tem2;          for(int i=1;i<=6;i++){           tem=s1[i]-s1[i-1];           tem2=s2[i-1]+s2[i+1]-2*s2[i];           if(cnt.find(tem)==cnt.end()){               cnt[tem]=0;           }           else               cnt[tem]++;           if(i!=6){               if(cnt2.find(tem2)==cnt2.end()){                   cnt2[tem2]=0;               }               else                   cnt2[tem2]++;           }       }       ll d,sq;       auto it=cnt.begin();       if(it->second>=3)       d=it->first;       else{           it++;           d=it->first;       }       auto it2=cnt2.begin();       if(it2->second>=2)       sq=it2->first;       else{           it2++;           sq=it2->first;       }       //cout<<sq<<  n ;       ll er;       for(int i=0;i<K-1;i++){           if(s1[i+1]-s1[i]!=d){               er=i+1;               break;           }       }       if(er==1 && s1[2]-s1[1]==d){           er=0;       }       ll dif,dif2;       tem=0;       for(int i=0;i<N;i++){           tem+=(p[er][i]*p[er][i]);       }       //cout<<tem<<  n ;       if(er==0)       dif=s1[er+1]-d-s1[er];       else       dif=s1[er-1]+d-s1[er];       //cout<<dif<<  n ;       ll ans=0;       for(int i=0;i<N;i++){           if(er<=K-3){               if(s2[er+2]-2*s2[er+1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){                   ans=p[er][i]+dif;                   break;               }           }           else{               if(s2[er-2]-2*s2[er-1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){                   ans=p[er][i]+dif;                   break;               }           }       }       cout<<er<<   <<ans<<  n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   struct T {     int a, b, i;     T() {}     T(int a, int b, int i) : a(a), b(b), i(i) {}     bool operator<(const T &other) const { return a > other.a; }   };   const int inf = 1e9;   int n, m, k, dp[N][N], f[N][N];   T a[N];   vector<int> ga, gb;   int fsolve(int i, int j) {     if (f[i][j] != -1) return f[i][j];     if (i > n) {       if (j == k)         f[i][j] = 0;       else         f[i][j] = -inf;       return f[i][j];     }     f[i][j] = fsolve(i + 1, j);     if (j < k) f[i][j] = max(f[i][j], fsolve(i + 1, j + 1) + a[i].b);     if (f[i][j] < 0) f[i][j] = -inf;     return f[i][j];   }   int solve(int i, int j) {     if (dp[i][j] != -1) return dp[i][j];     if (i > n) {       if (j == m)         dp[i][j] = 0;       else         dp[i][j] = -inf;       return dp[i][j];     }     int p = i - 1 - j;     if (j == m) {       dp[i][j] = fsolve(i, p);       return dp[i][j];     }     dp[i][j] = solve(i + 1, j + 1) + a[i].a;     if (p != k) dp[i][j] = max(dp[i][j], solve(i + 1, j) + a[i].b);     if (dp[i][j] < 0) dp[i][j] = -inf;     return dp[i][j];   }   void fsolve1(int i, int j) {     if (i > n) {       return;     }     if (f[i][j] == f[i + 1][j])       fsolve1(i + 1, j);     else {       gb.push_back(a[i].i);       fsolve1(i + 1, j + 1);     }   }   void solve1(int i, int j) {     if (i > n) {       return;     }     int p = i - 1 - j;     if (j == m) {       fsolve1(i, p);       return;     }     if (dp[i][j] == dp[i + 1][j + 1] + a[i].a) {       ga.push_back(a[i].i);       solve1(i + 1, j + 1);     } else {       gb.push_back(a[i].i);       solve1(i + 1, j);     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i].a;     for (int i = 1; i <= n; i++) cin >> a[i].b;     for (int i = 1; i <= n; i++) a[i].i = i;     sort(a + 1, a + n + 1);     memset(f, -1, sizeof(f));     memset(dp, -1, sizeof(dp));     cout << solve(1, 0) << endl;     solve1(1, 0);     for (int i = 0; i < ga.size(); i++) cout << ga[i] <<    ;     cout << endl;     for (int i = 0; i < gb.size(); i++) cout << gb[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, j, total, cnt;     cin >> n >> k;     double r, g, b;     r = ceil((n * 2.0) / k);     g = ceil((n * 5.0) / k);     b = ceil((n * 8.0) / k);     cout << int(r + g + b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x6fffffff;   const int MINF = 0x80000000;   const int mod = 1000000007;   const int cons = 100001;   const double pi = 3.141592653589793;   int dy2[2] = {1, 0};   int dx2[2] = {0, -1};   int dy1[2] = {0, 1};   int dx1[2] = {1, 0};   int n, m;   int main() {     vector<vector<bool> > M;     vector<vector<int> > km, lm;     scanf( %d%d , &n, &m);     M.resize(n + 1, vector<bool>(m + 1, false));     km.resize(n + 1, vector<int>(m + 1, -1));     lm.resize(n + 1, vector<int>(m + 1, -1));     vector<pair<int, int> > pos[10005];     queue<pair<int, int> > qu;     qu.push(make_pair(1, 1));     km[1][1] = 2;     pos[2].push_back(make_pair(1, 1));     while (!qu.empty()) {       int y = qu.front().first;       int x = qu.front().second;       qu.pop();       for (int i = 0; i < 2; i++) {         int ty = y + dy1[i];         int tx = x + dx1[i];         if (ty < 1 || ty > n || tx < 1 || tx > m) continue;         if (km[ty][tx] != -1) continue;         km[ty][tx] = km[y][x] + 1;         pos[km[ty][tx]].push_back(make_pair(ty, tx));         qu.push(make_pair(ty, tx));       }     }     qu.push(make_pair(1, m));     lm[1][m] = 2;     while (!qu.empty()) {       int y = qu.front().first;       int x = qu.front().second;       qu.pop();       for (int i = 0; i < 2; i++) {         int ty = y + dy2[i];         int tx = x + dx2[i];         if (ty < 1 || ty > n || tx < 1 || tx > m) continue;         if (lm[ty][tx] != -1) continue;         lm[ty][tx] = lm[y][x] + 1;         qu.push(make_pair(ty, tx));       }     }     map<int, int> K, L;     int k;     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       K[x]++;     }     int l;     scanf( %d , &l);     for (int i = k + 1; i <= l + k; i++) {       int x;       scanf( %d , &x);       L[x]++;     }     for (int i = n + m; i >= 2; i--) {       for (int j = 0; j < pos[i].size(); j++) {         int y = pos[i][j].first;         int x = pos[i][j].second;         int lvl = lm[y][x];         auto it = K.lower_bound(i);         auto it2 = L.lower_bound(lvl);         if (it == K.end() && it2 == L.end()) {           puts( NO );           return 0;         } else if (it == K.end()) {           it2->second--;           if (it2->second == 0) {             L.erase(it2);           }         } else if (it2 == L.end()) {           it->second--;           if (it->second == 0) {             K.erase(it);           }         } else {           it2->second--;           if (it2->second == 0) {             L.erase(it2);           }         }       }     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long dx[4] = {-1, 0, 1, 0};   const long long dy[4] = {0, -1, 0, 1};   const long long dxx[] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long dyy[] = {0, 1, 1, 1, 0, -1, -1, -1};   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long modexpo(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return modexpo((x * x) % M, n / 2, M);     else       return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M;   }   long long bexpo(long long x, long long n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return bexpo(x * x, n / 2);     else       return x * bexpo(x * x, (n - 1) / 2);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   const long long mod = 1e9 + 7;   const long long N = 4e5 + 5;   const long long INF = 1e18;   void solve() {     long long n;     cin >> n;     ;     string second;     cin >> second;     vector<long long> a;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       a.push_back(second[i] -  0 );     long long sum = 0;     for (__typeof(n - 1) k = (0) - ((0) > (n - 1));          k != (n - 1) - ((0) > (n - 1)); k += 1 - 2 * ((0) > (n - 1))) {       sum += a[k];       long long c_sum = 0;       for (__typeof(n) i = (k + 1) - ((k + 1) > (n)); i != (n) - ((k + 1) > (n));            i += 1 - 2 * ((k + 1) > (n))) {         if (a[i] == 0) {           continue;         }         if (c_sum == sum) {           c_sum = 0;         }         c_sum += a[i];         if (c_sum > sum) {           break;         }       }       if (c_sum == sum) {         cout <<  YES               <<   n ;         ;         return;       }     }     cout <<  NO           <<   n ;     ;   }   int32_t main() {     long long t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, x, k, mult = 1;     cin >> n >> k >> x;     while (k--) {       mult *= x;     }     vector<long long> pre(n + 1, 0), suf(n + 2, 0), v(n + 1, 0);     for (long long i = 1; i <= n; i++) {       cin >> v[i];       pre[i] = pre[i - 1] | v[i];     }     for (long long i = n; i >= 1; i--) suf[i] = suf[i + 1] | v[i];     long long ans = 0;     for (long long i = 1; i <= n; i++)       ans = max(ans, pre[i - 1] | (mult * v[i]) | suf[i + 1]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int lp[MAXN];   vector<int> pr;   int ans[MAXN];   int main() {     for (int i = 2; i < MAXN; ++i) {       ans[i] = 0;       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN;            ++j)         lp[i * pr[j]] = pr[j];     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int s;       cin >> s;       while (s > 1) {         int d = lp[s];         ans[d]++;         while (s % d == 0) {           s /= d;         }       }     }     int res = 0;     for (int i = 2; i < MAXN; i++) {       res = (res > ans[i] ? res : ans[i]);     }     cout << (res > 1 ? res : 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     int c;     for (int i = 0; i < n; i++) {       cin >> c;       v.push_back(c);     }     if (n == 1) {       if (v[0] == 1) {         cout <<  YES ;         return 0;       }     }     sort(v.begin(), v.end());     if (v[0] == 0 && v[1] == 1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, x;   long long eval(long long x) {     long long ret = 0;     if (x % 4 == 0) {       return x / 4;     } else {       if (x % 4 == 3) {         x -= 15;         ret++;         ret++;       } else if (x % 4 == 2) {         x -= 6;         ret++;       } else if (x % 4 == 1) {         x -= 9;         ret++;       }       if (x < 0)         return -1;       else         return ret + x / 4;     }   }   int main() {     cin >> n;     for (int i = 0; i < (n); ++i) {       cin >> x;       printf( %lld n , eval(x));     }   }


#include <bits/stdc++.h>   const int N = 1000;   int n, k;   struct point {     int x, y;     point operator-(const point &rhs) const {       return (point){x - rhs.x, y - rhs.y};     }   } a[7], b[N];   bool same_sgn(int x, int y) { return !x || !y || (x > 0) == (y > 0); }   bool collinear(point a, point b) {     return (long long)a.x * b.y == (long long)a.y * b.x && same_sgn(a.x, b.x) &&            same_sgn(a.y, b.y);   }   bool on_segment(point a, point b, point c) {     return collinear(a - b, c - b) && collinear(a - c, b - c);   }   std::vector<int> need[N][7];   bool unable[N][7], shot[N];   int p[7], id, ans;   bool dfs(int target) {     if (id == k) return 0;     int i = p[id++];     bool success = 1;     if (unable[target][i]) return 0;     for (int nxt : need[target][i])       if (!shot[nxt] && !dfs(nxt)) return 0;     return shot[target] = 1;   }   int main() {     std::ios::sync_with_stdio(0), std::cin.tie(0);     std::cin >> k >> n;     for (int i = 0; i < k; ++i) std::cin >> a[i].x >> a[i].y;     for (int i = 0; i < n; ++i) std::cin >> b[i].x >> b[i].y;     for (int i = 0; i < n; ++i)       for (int j = 0; j < k; ++j)         for (int p = 0; p < n; ++p)           if (p != i && on_segment(b[p], b[i], a[j])) {             need[i][j].emplace_back(p);             if (need[i][j].size() >= k) {               unable[i][j] = 1;               break;             }           }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < k; ++j) p[j] = j;       do         if (dfs((std::memset(shot, id = 0, sizeof shot), i))) {           ++ans;           break;         }       while (std::next_permutation(p, p + k));     }     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     cout << (n / 2) - (n % 2) * n << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 10;   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   std::vector<int> vec[N];   inline int calc(int n, int m) {     int sum = 0;     for (int i = 0; i < n - 1; ++i)       for (int j = 0; j < m - 1; ++j) {         int x = vec[i][j] + vec[i][j + 1] + vec[i + 1][j] + vec[i + 1][j + 1];         sum += x == 3 ? 1 : (x == 4 ? 4 : 0);       }     return sum;   }   inline void solve() {     int n = read(), m = read(), k = read(), flg = 0;     if (4LL * (n - 1) * (m - 1) < k) return puts( -1 ), void();     if (n > m) std::swap(n, m), flg = 1;     for (int i = 0; i < n; ++i) vec[i].resize(m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) vec[i][j] = 0;     if (m < 5) {       int suc = 0;       for (int s = 1; s < (1 << n * m); ++s) {         for (int i = 0; i < n; ++i)           for (int j = 0; j < m; ++j) vec[i][j] = s >> i * m + j & 1;         if (calc(n, m) == k) {           suc = 1;           break;         }       }       if (!suc) return puts( -1 ), void();     } else if (4LL * (n - 1) * (m - 1) == k + 8 && n == 3) {       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) vec[i][j] = 1;       vec[0][0] = vec[1][0] = vec[2][0] = 0;     } else {       int sum = 0, flg = k ? 0 : 1;       for (int i = 0; i < m; ++i) vec[0][i] = 1;       for (int i = 1; i < n && !flg; ++i)         for (int j = 0; j < m && !flg; ++j) {           int x = j == m - 1 ? 3 : (j ? 4 : 1);           if (sum + x > k) {             int w = k - sum;             if (w == 0) flg = 1;             if (w == 1) {               if (j != m - 1)                 vec[i][m - 1] = flg = 1;               else if (i != n - 1)                 vec[i + 1][0] = flg = 1;             }             if (w == 2) {               if (j <= m - 3)                 vec[i][m - 2] = flg = 1;               else if (i != n - 1)                 vec[i + 1][1] = flg = 1;             }             if (w == 3) {               if (j <= m - 4)                 vec[i][m - 1] = vec[i][m - 3] = flg = 1;               else if (i != n - 1 && j <= m - 3)                 vec[i][m - 2] = vec[i + 1][0] = flg = 1;               else if (i != n - 1 && j <= m - 2)                 vec[i][m - 1] = vec[i + 1][1] = flg = 1;               else if (i != n - 1)                 vec[i + 1][0] = vec[i + 1][2] = flg = 1;             }             if (flg == 0) return puts( -1 ), void();           } else             vec[i][j] = 1, sum += x;         }     }     if (flg) {       for (int i = 0; i < m; ++i, putchar(  n ))         for (int j = 0; j < n; ++j) putchar(vec[j][i] ?  *  :  . );     } else {       for (int i = 0; i < n; ++i, putchar(  n ))         for (int j = 0; j < m; ++j) putchar(vec[i][j] ?  *  :  . );     }   }   int main() {     for (int T = read(); T; putchar(  n ), --T) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 2;   const long long N = 1e6 + 1;   long long n;   set<int> Q;   int main() {     scanf( %d , &n);     int ans = 1;     while (n--) {       int x;       scanf( %d , &x);       while (!Q.insert(x).second) {         Q.erase(x);         x++;       }     }     printf( %d n , Q.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     while (cin >> a) {       bool f = false;       if (a.length() < 3) {         cout <<  No  << endl;         continue;       }       for (int i = 0; i <= a.length() - 3; i++) {         b = a.substr(i, 3);         if (b[0] !=  .  && b[1] !=  .  && b[2] !=  . ) {           if (b[0] != b[1] && b[1] != b[2] && b[2] != b[0]) {             f = true;             break;           }         }         b.clear();       }       if (f)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     ll n, k;     cin >> n >> k;     if (k == 1 || k == n) {       cout << (3 * n);     } else {       cout << min(2 + 3 * (k - 1) + k + 3 + 3 * (n - k - 1),                   6 + 3 * (n - k - 1) + n - k + 3 * (k - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int h, l;     scanf( %lld %lld , &h, &l);     printf( %.9f n , (l * l - h * h + 0.0) / (2 * h));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   const int T = 20010;   int n, p, q, c[N], h[N], t[N], cs[T], cd[T], b[T], rez[T];   int d[10010][N];   vector<int> v[T], v2[T], v3[T];   void sol(int pozs) {     int pozd = min(T - 1, pozs + 2 * p), mid = pozs + p;     vector<int>::iterator it;     int i, j;     for (i = pozs; i <= mid; ++i) memset(d[i - pozs], 0, sizeof(d[i - pozs]));     int din[N];     memset(din, 0, sizeof(din));     for (i = mid - 1; i >= pozs; --i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       memcpy(d[i - pozs], din, sizeof(din));     }     memset(din, 0, sizeof(din));     for (i = mid; i <= pozd; ++i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       for (it = v2[i - p].begin(); it != v2[i - p].end(); ++it)         for (j = 0; j <= b[*it]; ++j)           rez[*it] = max(rez[*it], d[i - p - pozs][j] + din[b[*it] - j]);     }   }   void sol1() {     int i, j;     int din[N];     memset(din, 0, sizeof(din));     vector<int>::iterator it;     for (i = 1; i <= p + 1; ++i) {       for (it = v[i].begin(); it != v[i].end(); ++it)         for (j = N - 1; j >= c[*it]; --j)           din[j] = max(din[j], din[j - c[*it]] + h[*it]);       for (it = v3[i].begin(); it != v3[i].end(); ++it) rez[*it] = din[b[*it]];     }   }   int main() {     int i, j, k;     cin >> n >> p;     --p;     for (i = 1; i <= n; ++i) {       cin >> c[i] >> h[i] >> t[i];       v[t[i]].push_back(i);     }     cin >> q;     for (i = 1; i <= q; ++i) {       cin >> cd[i] >> b[i];       cs[i] = max(1, cd[i] - p);       if (cs[i] == 1) {         v3[cd[i]].push_back(i);         continue;       }       v2[cs[i]].push_back(i);     }     sol1();     for (int t = 0; t + p < T; t += p) sol(t);     for (i = 1; i <= q; ++i) cout << rez[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     long long a[n];     long long maxi = LONG_LONG_MIN, mini = LONG_LONG_MAX;     map<long long, stack<long long> > ma;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i < 5) {         maxi = max(maxi, a[i]);         mini = min(mini, a[i]);       }       ma[a[i]].push(i);     }     sort(a, a + n);     long long dp[n];     long long parent[n];     dp[0] = a[0];     dp[1] = a[1] - a[0];     dp[2] = a[2] - a[0];     dp[3] = a[3] - a[0];     dp[4] = a[4] - a[0];     long long ctr = 2;     memset(parent, -1, sizeof(parent));     for (long long i = 5; i < n; i++) {       long long temp1, temp2, temp3;       if (i >= 7) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = dp[i - 4] + a[i] - a[i - 3];         temp3 = dp[i - 5] + a[i] - a[i - 4];       } else if (i == 6) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = dp[i - 4] + a[i] - a[i - 3];         temp3 = LONG_LONG_MAX;       } else if (i == 5) {         temp1 = dp[i - 3] + a[i] - a[i - 2];         temp2 = LONG_LONG_MAX;         temp3 = LONG_LONG_MAX;       }       if ((temp1 <= temp2) && (temp1 <= temp3)) {         parent[i] = i - 3;       } else if ((temp2 <= temp3) && (temp2 <= temp1)) {         parent[i] = i - 4;       } else {         parent[i] = i - 5;       }       dp[i] = min(temp1, min(temp2, temp3));     }     vector<long long> res;     long long x = n - 1;     while (parent[x] != -1) {       res.push_back(x);       x = parent[x];     }     res.push_back(x);     long long ans[n];     long long team[n];     ctr = 1;     long long j = 0;     reverse(res.begin(), res.end());     for (long long i = 0; i < n; i++) {       team[i] = ctr;       if (i == res[j]) {         j++;         ctr++;       }     }     for (long long i = 0; i < n; i++) {       ans[ma[a[i]].top()] = team[i];       ma[a[i]].pop();     }     cout << dp[n - 1] <<     << ctr - 1 <<   n ;     for (long long i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   const int mod = 1000000007;   long long f[2005][2005], g[2005][2005];   int main() {     for (int n, m; scanf( %d%d , &n, &m) != EOF;) {       memset(f, 0, sizeof(f));       memset(g, 0, sizeof(g));       for (int i = 1; i <= n; i++) {         long long sum = 0;         for (int j = 2; j <= m; j++) {           f[i][j] = (g[i - 1][j] + 1) % mod;           sum = (sum + f[i][j]) % mod;           g[i][j] = (g[i][j - 1] + sum) % mod;         }       }       long long ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 2; j <= m; j++) {           ans = ans + (f[i][j] * (g[n - i][j] - f[n - i][j] + 1) % mod) *                           (m - j + 1) % mod;           ans = ans % mod;         }       }       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int _xor(long long int a, long long int b) { return a ^ b; }   long long int _and(long long int a, long long int b) { return a & b; }   long long int _or(long long int a, long long int b) { return a | b; }   long long int _not(long long int a) { return ~a; }   long long int ai[1000], pi[2005];   long long int dp[100001];   int main() {     long long int b, c = 0, x, y, z, t, i, j, k, l1, l2, m, n, c1 = 0, c2 = 0, q,                      f = 0, ans = 0;     string str;     cin >> str;     dp[0] = 0;     for (i = 1; i < str.length(); i++) {       if (str[i] == str[i - 1]) {         dp[i] = dp[i - 1] + 1;       } else         dp[i] = dp[i - 1];     }     scanf( %lld , &m);     long long int low, up;     for (i = 0; i < m; i++) {       scanf( %lld , &low);       scanf( %lld , &up);       up--;       low--;       cout << dp[up] - dp[low] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void affiche(int t[], int n) {     for (int i = 0; i < n; i++) cout << t[i] <<    ;     cout <<   n ;   }   void afficheV(vector<int> t) {     for (int i = 0; i < t.size(); i++) cout << t[i] <<    ;   }   vector<vector<int> > adj(50005);   vector<bool> visited(50005, false);   int ans[50005];   int dp[50005];   int r1, r2;   void DFS(int node) {     visited[node] = true;     for (int i = 0; i < adj[node].size(); i++) {       int child = adj[node][i];       if (!visited[child]) {         ans[child] = node;         DFS(child);       }     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n >> r1 >> r2;     memset(dp, -1, sizeof dp);     for (int i = 1; i < n + 1; i++) {       if (i == r1) continue;       int x;       cin >> x;       adj[x].push_back(i);       adj[i].push_back(x);     }     DFS(r2);     for (int i = 1; i < n + 1; i++) {       if (i == r2) continue;       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n, m;   const int N = 2e5 + 5;   const double eps = 1e-10;   struct Node {     double x, t;   } a[N];   double sum, ans;   bool cmp(Node u, Node v) { return u.t < v.t; }   void work() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i].x);     for (int i = 1; i <= n; i++) {       scanf( %lf , &a[i].t), a[i].t -= m;       sum += a[i].x * a[i].t;     }     sort(a + 1, a + n + 1, cmp);     if (a[1].t > 0 || a[n].t < 0) {       puts( 0 );       return;     }     if (sum > 0) {       sum = 0;       for (int i = 1; i <= n; i++) {         if (sum + a[i].x * a[i].t > 0) {           ans = ans + sum / (-a[i].t);           break;         } else           ans += a[i].x, sum += a[i].x * a[i].t;       }     } else {       sum = 0;       for (int i = n; i; i--) {         if (sum + a[i].x * a[i].t < 0) {           ans = ans + sum / (-a[i].t);           break;         } else           ans += a[i].x, sum += a[i].x * a[i].t;       }     }     printf( %.12f , ans);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   struct modint {     long long x;     modint(long long o = 0) { x = o; }     modint &operator=(long long o) { return x = o, *this; }     modint &operator+=(modint o) {       return x = x + o.x >= 1000000007 ? x + o.x - 1000000007 : x + o.x, *this;     }     modint &operator-=(modint o) {       return x = x - o.x < 0 ? x - o.x + 1000000007 : x - o.x, *this;     }     modint &operator*=(modint o) { return x = 1ll * x * o.x % 1000000007, *this; }     modint &operator^=(long long b) {       modint a = *this, c = 1;       for (; b; b >>= 1, a *= a)         if (b & 1) c *= a;       return x = c.x, *this;     }     modint &operator/=(modint o) { return *this *= o ^= 1000000007 - 2; }     modint &operator+=(long long o) {       return x = x + o >= 1000000007 ? x + o - 1000000007 : x + o, *this;     }     modint &operator-=(long long o) {       return x = x - o < 0 ? x - o + 1000000007 : x - o, *this;     }     modint &operator*=(long long o) {       return x = 1ll * x * o % 1000000007, *this;     }     modint &operator/=(long long o) {       return *this *= ((modint(o)) ^= 1000000007 - 2);     }     template <class I>     friend modint operator+(modint a, I b) {       return a += b;     }     template <class I>     friend modint operator-(modint a, I b) {       return a -= b;     }     template <class I>     friend modint operator*(modint a, I b) {       return a *= b;     }     template <class I>     friend modint operator/(modint a, I b) {       return a /= b;     }     friend modint operator^(modint a, long long b) { return a ^= b; }     friend bool operator==(modint a, long long b) { return a.x == b; }     friend bool operator!=(modint a, long long b) { return a.x != b; }     bool operator!() { return !x; }     modint operator-() { return x ? 1000000007 - x : 0; }   };   long long n, m, k;   modint x, p[1505], sump[1505], fr[1505][1505], s[1505][1505], tmp[1505][1505];   modint fac[1000005], iv[1000005];   void pre(long long n) {     fac[0] = iv[0] = 1;     for (register long long i = (1); i <= (n); ++i)       fac[i] = fac[i - 1] * i, iv[i] = iv[i - 1] / i;   }   inline modint C(long long n, long long m) { return fac[n] * iv[m] * iv[n - m]; }   signed main() {     n = read(), m = read(), x = read(), x /= read(), k = read();     pre(1e6);     for (register long long i = (0); i <= (min(m, k)); ++i)       p[i] = C(k, i) * (x ^ i) * ((-x + 1) ^ (k - i));     for (register long long i = (1); i <= (m); ++i)       sump[i] = sump[i - 1] + p[i - 1];     fr[0][m] = s[0][m] = 1;     for (register long long i = (1); i <= (n); ++i)       for (register long long r = (1); r <= (m); ++r) {         fr[i][r] = p[m - r] *                    (sump[r] * (s[i - 1][m] - s[i - 1][m - r]) - tmp[i - 1][r]);         s[i][r] = s[i][r - 1] + fr[i][r];         tmp[i][r] = tmp[i][r - 1] + p[r - 1] * s[i][r - 1];       }     cout << s[n][m].x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<510> reach[510];   int n, p[510], use[510], i, j, wz[510];   char s[510];   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &p[i]), wz[p[i]] = i;     for (i = 1; i <= n; i++) {       scanf( %s , s + 1);       reach[i][i] = 1;       for (j = 1; j <= n; j++)         if (s[j] ==  1 ) reach[i][j] = 1;     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (reach[j][i]) reach[j] |= reach[i];     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++)         if (!use[j] && reach[i][wz[j]]) break;       use[j] = 1;       printf( %d  , j);     }   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, q, u, v;   pair<int, vector<int> > P[100011][25];   vector<int> residents[100011];   vector<int> adj[100001];   int parent[100001];   int L[100001];   int checker;   vector<int> mergevec(vector<int>& A, vector<int>& B, int sz) {     vector<int> sol;     int ap = 0, bp = 0;     while (sz != 0 && ap != A.size() && bp != B.size()) {       if (A[ap] < B[bp]) {         if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--;         ap++;       } else {         if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--;         bp++;       }     }     while (sz != 0 && ap != A.size()) {       if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--;       ap++;     }     while (sz != 0 && bp != B.size()) {       if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--;       bp++;     }     return sol;   }   void process() {     int i, j;     for (i = 1; i <= n; i++) {       for (j = 0; j <= 20; j++) {         P[i][j].first = -1;       }     }     for (i = 1; i <= n; i++) {       P[i][0].first = parent[i];       P[i][0].second = residents[i];     }     for (j = 1; 1 << j < n; j++) {       for (i = 1; i <= n; i++) {         if (P[i][j - 1].first != -1) {           P[i][j].first = P[P[i][j - 1].first][j - 1].first;           P[i][j].second = mergevec(P[i][j - 1].second,                                     P[P[i][j - 1].first][j - 1].second, 10);         }       }     }   }   int lca(int p, int q) {     int tmp, log, i;     if (L[p] < L[q]) tmp = p, p = q, q = tmp;     for (log = 1; 1 << log <= L[p]; log++)       ;     log--;     for (i = log; i >= 0; i--) {       if (L[p] - (1 << i) >= L[q]) {         p = P[p][i].first;       }     }     if (p == q) return p;     for (i = log; i >= 0; i--)       if (P[p][i].first != -1 && P[p][i].first != P[q][i].first)         p = P[p][i].first, q = P[q][i].first;     return parent[p];   }   vector<int> path(int u, int levelpar, int sz) {     vector<int> sol = residents[u];     for (int i = checker; i >= 0; i--) {       if (P[u][i].first != -1) {         if (L[P[u][i].first] >= levelpar) {           sol = mergevec(sol, P[u][i].second, sz);           u = P[u][i].first;         }       }     }     return sol;   }   void dfs(int start, int p) {     parent[start] = p;     if (p == -1)       L[start] = 1;     else       L[start] = L[p] + 1;     for (int i = 0; i < adj[start].size(); i++) {       if (adj[start][i] != p) {         dfs(adj[start][i], start);       }     }   }   int main() {     int a;     scanf( %d%d%d , &n, &m, &q);     checker = min((int)(log2(n) + 3), (int)20);     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < m; i++) {       scanf( %d , &u);       if (residents[u].size() < 10) residents[u].push_back(i + 1);     }     for (int i = 1; i <= 100000; i++)       sort(residents[i].begin(), residents[i].end());     dfs(1, -1);     process();     for (int i = 0; i < q; i++) {       scanf( %d%d%d , &u, &v, &a);       int lcaa = lca(u, v);       vector<int> v1 = path(u, L[lcaa], a), v2 = path(v, L[lcaa], a);       vector<int> sol = mergevec(v1, v2, a);       sol = mergevec(sol, residents[lcaa], a);       printf( %d  , (int)sol.size());       for (int j = 0; j < sol.size(); j++) {         printf( %d  , sol[j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int cnt[maxn], a[maxn], n, q;   signed main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         cnt[i] = 0;       }       vector<int> res;       for (int i = 1; cnt[i] < 3; i -= a[i])         if ((++cnt[i]) == 2)           res.push_back(i);         else if (cnt[i] == 3)           break;       printf( %d n , (int)res.size());       for (int u : res) printf( %d  , u);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[1003];   char s[1003];   int sign[1003];   int fi[1003];   int main() {     int n, m;     cin >> n >> m;     getchar();     int num = 0;     int ans = 1001;     for (int i = 0; i < n; i++) {       scanf( %c , &c[i]);     }     getchar();     for (int i = 0; i < m; i++) {       scanf( %c , &s[i]);     }     for (int j = 0; j < m - n + 1; j++) {       memset(sign, 0, sizeof(sign));       num = 0;       for (int q = 0; q < n; q++) {         if (s[j + q] != c[q]) {           sign[num++] = q + 1;         }       }       if (ans > num) {         ans = num;         memcpy(fi, sign, sizeof(int) * num);       }     }     printf( %d n , ans);     for (int i = 0; i < ans; i++) {       printf( %d  , fi[i]);     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const int MAXN = 1e5 + 10;   int v[MAXN];   int lis[MAXN];   int main() {     int n;     scanf( %d , &n);     for (int a = 0; a < n; ++a) scanf( %d , &v[a]);     memset(lis, INF, sizeof(lis));     for (int a = 0; a < n; ++a) {       int i = lower_bound(lis, lis + n, v[a]) - lis;       lis[i] = v[a];     }     int hi = 0;     for (int a = 0; a < n; ++a)       if (lis[a] != INF) hi = a;     printf( %d n , hi + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct road {     int x, next;   } r[100005 * 2];   int N, M, D, ans;   int vis[100005], p[100005];   int down[100005], up[100005];   int st[100005], w;   void add(int x, int y) {     r[++w].x = y, r[w].next = st[x];     st[x] = w;   }   void Make_Down(int x, int fr) {     int i, tmp;     if (vis[x])       down[x] = 0;     else       down[x] = -0x7ffffff;     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       Make_Down(tmp, x);       down[x] = max(down[x], down[tmp] + 1);     }   }   void Dfs(int x, int fr) {     int i, tmp;     int m1 = 0, m2 = 0;     if (vis[x]) up[x] = max(up[x], 0);     if (max(down[x], up[x]) <= D) ans++;     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       if (down[m1] <= down[tmp])         m2 = m1, m1 = tmp;       else if (down[m2] <= down[tmp])         m2 = tmp;     }     for (i = st[x]; i; i = r[i].next) {       tmp = r[i].x;       if (tmp == fr) continue;       if (tmp == m1)         up[tmp] = max(up[x] + 1, down[m2] + 2);       else         up[tmp] = max(up[x] + 1, down[m1] + 2);       Dfs(tmp, x);     }   }   int main() {     int i, j;     int fr, to;     scanf( %d %d %d , &N, &M, &D);     for (i = 1; i <= M; i++) scanf( %d , &p[i]), vis[p[i]] = 1;     for (i = 1; i < N; i++) {       scanf( %d %d , &fr, &to);       add(fr, to), add(to, fr);     }     down[0] = up[0] = -0x7ffffff;     memset(up, 200, sizeof(up));     Make_Down(1, 0);     Dfs(1, 0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(0);     int cases, caseno = 0, n, i, j, k, cnt, sum;     cin >> n >> j >> k;     for (i = 1; i <= 10000; i++) {       if (n == 2) {         cout <<  Final! ;         return 0;       }       if ((j + 1) / 2 == (k + 1) / 2) {         cout << i;         return 0;       }       j = (j + 1) / 2;       k = (k + 1) / 2;       n /= 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       int tot = 0;       vector<int> v;       for (int i = 1; i < n + 1; i++) {         if (tot + i > n) {           v.back() += n - tot;           break;         } else {           tot += i;           v.push_back(i);         }       }       cout << v.size() <<   n ;       for (int i = 0; i < v.size(); i++) {         cout << v[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   int n, m;   int main(void) {     while (cin >> n >> m && n && m) {       priority_queue<long long, vector<long long>, greater<long long> > que;       for (int i = 0; i < n; i++) {         long long a;         que.push((cin >> a, a));       }       for (int i = 0; i < m; i++) {         long long b;         cin >> b;         if (!que.empty() && que.top() <= b) que.pop();       }       cout << que.size() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e7 + 7;   const long long mo = 1e9 + 7;   long long n, m, k, p, q, r, mod, i, j, d = 0, ans;   long long wz;   int main() {     scanf( %lld %lld %lld , &n, &m, &k);     r = n - 1;     ans = r * m;     wz = 1;     if (ans < k || m > k)       printf( NO n );     else {       printf( YES n );       while (k - r > m - 1) {         if (d == 0)           wz = n;         else           wz = 1;         printf( %lld  , wz);         k -= r;         d ^= 1;         m--;       }       p = k - m + 1;       if (m > 0 && p != 0) {         m--;         if (d == 0)           wz = wz + p;         else           wz = wz - p;         printf( %lld  , wz);         d ^= 1;       }       while (m--) {         if (d == 0)           wz = wz + 1;         else           wz = wz - 1;         printf( %lld  , wz);         d ^= 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   long long pow_mod(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       n >>= 1;       x = x * x % mod;     }     return res;   }   long long inv(long long x) { return pow_mod(x, mod - 2); }   int main() {     long long n, a, b, k;     string s;     while (cin >> n >> a >> b >> k) {       cin >> s;       long long ans = 0;       for (long long i = 0; i < k; i++) {         if (s[i] ==  + )           ans = ((ans + pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod;         else           ans = ((ans - pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod;       }       long long m = (n + 1) / k;       long long q = pow_mod(b, k) * inv(pow_mod(a, k)) % mod;       if (q == 1)         ans = ans * m % mod;       else {         ans = ans * (1 - pow_mod(q, m)) % mod;         ans = ans * inv(1 - q) % mod;       }       cout << (ans + mod) % mod << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int find(vector<int>& par, int x) {     if (x != par[x]) return find(par, par[x]);     return x;   }   bool same(vector<int>& par, int x, int y) {     return find(par, x) == find(par, y);   }   void merge(vector<int>& par, vector<int>& sz, int x, int y) {     int X = find(par, x);     int Y = find(par, y);     if (sz[X] < sz[Y]) swap(X, Y);     par[Y] = X;     sz[X] += sz[Y];     return;   }   int main(int argc, char const* argv[]) {     cin.sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> sz(n);     vector<int> par(n);     for (int i = 0; i < n; i++) {       sz[i] = 1;       par[i] = i;     }     vector<vector<int> > l(m);     int maxk = -1;     int ind = -1;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       if (maxk < k) {         maxk = k;         ind = i;       }       for (int j = 0; j < k; j++) {         int lng;         cin >> lng;         lng--;         l[lng].push_back(i);       }     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < l[i].size(); j++) {         if (!same(par, l[i][0], l[i][j])) {           merge(par, sz, l[i][0], l[i][j]);         }       }     }     int ret = 0;     if (maxk == 0) {       cout << n;       return 0;     }     for (int i = 0; i < n; i++) {       if (!same(par, ind, i)) {         merge(par, sz, ind, i);         ret++;       }     }     cout << ret;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 200000;   int n;   int a[mxn], b[mxn], first[mxn], ff[mxn];   vector<int> v[mxn];   auto cmp = [](int x, int y) { return b[x] > b[y]; };   priority_queue<int, vector<int>, decltype(cmp)> pq(cmp);   map<int, int> second;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       a[i]--, b[i]--;       v[a[i]].push_back(i);     }     int p = -1, q = -1;     for (int i = 0; i < n; i++) {       for (int j : v[i]) pq.push(j);       int x = pq.top();       pq.pop();       first[i] = x, ff[x] = i + 1;       if (!~p) {         auto it = second.lower_bound(i);         if (it != second.end() && it->second >= a[x]) {           p = first[it->second], q = x;         } else {           it = second.insert({b[x], i}).first;           if (it->second < i) {             if (next(it) != second.end() && i <= next(it)->second)               it = second.erase(it);             while (it != second.begin() && (--it)->second <= i)               it = second.erase(it);           }         }       }     }     cout << (!~p ?  YES  :  NO ) <<   n ;     for (int i = 0; i < 1 + !!~p; i++) {       cout << ff[0];       for (int i = 1; i < n; i++) cout <<     << ff[i];       cout <<   n ;       if (~p) swap(ff[p], ff[q]);     }     return 0;   }


#include <bits/stdc++.h>   const long long MOD = 998244353;   const int N = 6000;   std::vector<long long> fact(N), revfact(N);   long long Pow(long long a, long long b) {     long long rt = 1;     while (b) {       if (b & 1) rt = (rt * a) % MOD;       a = (a * a) % MOD;       b /= 2;     }     return rt;   }   long long C(int n, int k) {     return (((fact[n] * revfact[k]) % MOD) * revfact[n - k]) % MOD;   }   int main() {     const int n = 3;     std::vector<int> a(n);     for (int i = 0; i < n; i++) std::cin >> a[i];     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = (fact[i - 1] * 1LL * i) % MOD;     }     for (int i = 0; i < N; i++) {       revfact[i] = Pow(fact[i], MOD - 2);       assert((fact[i] * revfact[i]) % MOD == 1);     }     long long ans = 1;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         long long cur = 0;         for (int k = 0; k <= std::min(a[i], a[j]); k++) {           cur = (cur + (C(a[i], k) * C(a[j], k) % MOD) * fact[k]) % MOD;         }         ans = (ans * cur) % MOD;       }     }     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<int> g[n + 1];     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     vector<vector<int>> dp(n + 1, vector<int>(k + 1));     int ans = 0;     function<void(int, int)> dfs;     dfs = [&](int u, int pre) {       dp[u][0] = 1;       for (auto v : g[u]) {         if (v != pre) {           dfs(v, u);           for (int j = 0; j < k; ++j) {             ans += dp[v][j] * dp[u][k - 1 - j];           }           for (int j = 1; j <= k; ++j) {             dp[u][j] += dp[v][j - 1];           }         }       }     };     dfs(1, 0);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   bool uax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cout << fixed;     int N, X, Y;     cin >> N >> X >> Y;     for (int i = 0; i < (int)(N); ++i) {       int A;       cin >> A;       long long l = 0, r = 1e18;       while (r - l > 1) {         long long m = (l + r) / 2;         long long hits = m / X + m / Y;         if (hits >= A)           r = m;         else           l = m;       }       if (r % Y == 0 && r % X == 0)         cout <<  Both n ;       else if (r % X)         cout <<  Vanya n ;       else if (r % Y)         cout <<  Vova n ;     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1e9 + 7;   using namespace std;   vector<int> par, rnk;   void make_set(int n) {     par[n] = n;     rnk[n] = 0;   }   int find_set(int a) {     if (par[a] == a) return a;     return par[a] = find_set(par[a]);   }   void union_set(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a == b) return;     if (rnk[a] > rnk[b]) {       par[b] = a;     } else if (rnk[a] < rnk[b]) {       par[a] = b;     } else {       par[b] = a;       rnk[a]++;     }   }   void solve() {     int n, a, b;     cin >> n >> a >> b;     par.assign(n, 0);     rnk.assign(n, 0);     if (a != 1 && b != 1) {       cout <<  NO n ;       return;     }     if (a == 1 && b == 1) {       if (n == 2 || n == 3) {         cout <<  NO n ;         return;       }       cout <<  YES n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (abs(i - j) == 1)             cout <<  1 ;           else             cout <<  0 ;         }         cout << endl;       }       return;     }     for (int i = 0; i < n; i++) make_set(i);     for (int i = 0; i < n - (max(a, b)); i++) {       union_set(i, i + 1);     }     int flag = 0;     if (a > 1) flag = 1;     cout <<  YES n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j)           cout <<  0 ;         else if (flag) {           if (find_set(i) == find_set(j))             cout <<  1 ;           else             cout <<  0 ;         } else {           if (find_set(i) != find_set(j))             cout <<  1 ;           else             cout <<  0 ;         }       }       cout << endl;     }   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   vector<int> v[maxn];   stack<int> s;   int low[maxn], dfn[maxn], vis[maxn], clk = 0;   int belong[maxn], tot = 0;   vector<int> Ws[maxn];   void tarjan(int x) {     s.push(x), vis[x] = 1;     low[x] = dfn[x] = ++clk;     for (auto &u : v[x]) {       if (!dfn[u]) {         tarjan(u);         low[x] = min(low[x], low[u]);       } else if (vis[u])         low[x] = min(low[x], dfn[u]);     }     if (low[x] == dfn[x]) {       int u;       tot++;       do {         u = s.top();         s.pop(), vis[u] = 0;         belong[u] = tot, Ws[tot].push_back(u);       } while (x != u);     }   }   int n, m, D;   vector<pair<int, int> > usedge[maxn];   int in[maxn];   pair<int, int> dp[maxn][55];   void buildnew() {     Ws[0].push_back(0), in[belong[1]]++;     belong[0] = 0, usedge[0].push_back({0, 1});     for (int i = 1; i <= n; ++i) {       for (auto &u : v[i]) {         if (belong[i] != belong[u]) {           usedge[belong[i]].push_back({i, u});           in[belong[u]]++;         }       }     }   }   char mp[maxn][55];   void calblock(int x, int time, int bx, int w) {     time %= D;     pair<int, int> &ret = dp[x][time];     if (ret.first) return;     ret = {1, w};     for (auto &u : v[x]) {       if (bx != belong[u]) continue;       calblock(u, time + 1, bx, w);     }   }   int val[maxn][55], ans[maxn][55];   int cal(int x, int p) {     if (val[x][p] != -1) return val[x][p];     val[x][p] = 0;     for (auto &u : Ws[x]) {       for (int i = 0; i < D; ++i) {         int ok = (dp[u][i].first && mp[u][i] ==  1  && dp[u][i].second == p);         val[x][p] += ok;         if (ok) break;       }     }     return val[x][p];   }   int dis[maxn];   void solve(int x) {     queue<int> q;     for (int i = 0; i <= tot; ++i)       if (!in[i]) q.push(i);     while (q.size()) {       int p = q.front();       q.pop();       for (auto &u : usedge[p]) {         int bx = belong[u.second];         for (int i = 0; i < D; ++i) {           if (dp[u.first][i].first) {             int tp = (i + 1) % D;             int go = (dis[u.second] + i + 1) % D;             calblock(u.second, (i + 1) % D, bx, go);             tp = dp[u.second][(i + 1) % D].second;             ans[bx][tp] =                 max(ans[bx][tp], ans[p][dp[u.first][i].second] + cal(bx, tp));           }         }         in[bx]--;         if (in[bx] == 0) q.push(bx);       }     }   }   void bfs(int x) {     int p = Ws[x][0];     queue<int> q;     q.push(p);     dis[p] = 0;     while (q.size()) {       int u = q.front();       q.pop();       for (auto r : v[u]) {         if (belong[r] != x || (dis[r] != -1)) continue;         dis[r] = dis[u] + 1;         q.push(r);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &D);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);     }     for (int i = 1; i <= n; ++i) {       scanf( %s , mp[i]);     }     for (int i = 1; i <= n; ++i) {       if (!dfn[i]) {         tarjan(i);       }     }     buildnew();     memset(val, -1, sizeof val);     memset(dis, -1, sizeof dis);     for (int i = 0; i <= tot; ++i) bfs(i);     dp[0][D - 1] = {1, D - 1};     solve(0);     int ret = 0;     for (int i = 1; i <= tot; ++i) {       for (int j = 1; j <= D; ++j) ret = max(ret, ans[i][j - 1]);     }     cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int i, a[n];       map<int, pair<int, int> > m;       for (i = 0; i < n; i++) {         cin >> a[i];       }       int vis[n + 1];       memset(vis, -1, sizeof(vis));       for (i = 0; i < n; i++) {         if (m.find(a[i]) == m.end()) {           pair<int, int> p;           p.first = i;           p.second = i + 1;           m[a[i]] = p;         } else {           pair<int, int> p = m[a[i]];           p.second = max(p.second, i - p.first);           p.first = i;           m[a[i]] = p;         }       }       map<int, pair<int, int> >::iterator it;       for (it = m.begin(); it != m.end(); it++) {         pair<int, int> p = it->second;         int i = p.first;         int x = max(p.second, n - i);         if (vis[x] == -1)           vis[x] = it->first;         else           vis[x] = min(vis[x], it->first);       }       for (i = 1; i <= n; i++) {         if (vis[i] == -1)           cout << vis[i] <<    ;         else {           int temp = vis[i];           while (i + 1 <= n && (vis[i + 1] == -1 || vis[i + 1] >= temp)) {             cout << temp <<    ;             i++;           }           cout << temp <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300001];   long long an[300001], dp[300001];   struct data {     int x, y, No;     void scan() { scanf( %d%d , &x, &y); }     bool operator<(data b) const {       if (y < b.y) return 0;       if (y > b.y) return 1;       int r1 = x % y, r2 = b.x % y;       if (r1 < r2) return 0;       if (r1 > r2) return 1;       return No < b.No;     }   } d[300001];   int main() {     int n, i, j, k, mi, p;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &p);     for (i = 0; i < p; i++) d[i].scan(), d[i].No = i;     sort(d, d + p);     for (i = 0; i < p; i += j) {       int tmp = d[i].x % d[i].y;       mi = n;       for (j = 0; i + j < p; j++) {         if (d[i].y != d[i + j].y || d[i + j].x % d[i].y != tmp) break;         mi = min(mi, d[i + j].x);       }       k = d[i].x + (n - d[i].x) / d[i].y * d[i].y;       dp[k] = a[k];       for (k -= d[i].y; k >= mi; k -= d[i].y) dp[k] = a[k] + dp[k + d[i].y];       for (k = 0; k < j; k++) an[d[i + k].No] = dp[d[i + k].x];     }     for (i = 0; i < p; i++) printf( %I64d n , an[i]);   }


#include <bits/stdc++.h>   using namespace std;   int a[100000], b, c, n, m, x, y, z, s;   int main() {     cin >> a[0] >> a[1] >> n;     if (n <= 1)       cout << a[n];     else {       for (int i = 2; i <= n; i++) {         a[i] = a[i - 1] + a[i - 2];       }       cout << a[n];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cnt[105];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     while (m--) {       long long l, r;       cin >> l >> r;       l--;       r--;       long long sm = 0;       for (long long i = l; i <= r; i++) sm += a[i];       if (sm > 0) ans += sm;     }     cout << ans <<   n ;     return 0;   }