#include <bits/stdc++.h>   using namespace std;   struct mat {     int num[4][4];   };   mat m1 = {{{1, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}},       m2 = {{{1, 1, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}};   mat mult(mat &a, mat &b) {     mat ret;     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) {         long long t = 0;         for (int k = 0; k < 4; k++) t += 1ll * a.num[i][k] * b.num[k][j];         ret.num[i][j] = t % 1000000007;       }     return ret;   }   int cal(string &s, string &q) {     int ret = 0;     for (int i = 0; i + q.size() <= s.size(); i++)       if (s.substr(i, q.size()) == q) ret++;     return ret;   }   int query(long long n, string &q) {     if (n == 1) {       return q ==  a  ? 1 : 0;     }     if (n == 2) {       return q ==  b  ? 1 : 0;     }     string s1 =  a , s2 =  b , s =  b ;     for (n -= 2; n && s1.size() < q.size(); n--, s1 = s2, s2 = s) s = s2 + s1;     int f1 = cal(s1, q), f2 = cal(s, q);     if (!n) return f2;     s = s2.substr(s2.size() - q.size() + 1, q.size() - 1) +         s2.substr(0, q.size() - 1);     int t1 = cal(s, q);     s = s1.substr(s1.size() - q.size() + 1, q.size() - 1) +         s1.substr(0, q.size() - 1);     int t2 = cal(s, q);     mat res, t = mult(m2, m1);     bool flag = 0;     if (n % 2) res = m1, flag = 1;     for (n /= 2; n; n >>= 1, t = mult(t, t))       if (n & 1) {         if (!flag)           res = t, flag = 1;         else           res = mult(res, t);       }     return (1ll * res.num[0][0] * f2 + 1ll * res.num[0][1] * f1 +             1ll * res.num[0][2] * t1 + 1ll * res.num[0][3] * t2) %            1000000007;   }   int main() {     long long n, m;     cin >> n >> m;     string s;     while (m--) cin >> s, cout << query(n, s) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   string a, b;   map<pair<string, string>, int> m;   int f(string aa, string bb) {     if (aa == bb) return 2;     if (aa.size() % 2) return 1;     if (m[{aa, bb}] != 0) return m[{aa, bb}];     string a1, b1, a2, b2;     for (int i = 0; i < aa.size(); i++) {       if (i < aa.size() / 2) {         a1.push_back(aa[i]);         b1.push_back(bb[i]);       } else {         a2.push_back(aa[i]);         b2.push_back(bb[i]);       }     }     if (f(a1, b1) == 2 && f(a2, b2) == 2) return m[{aa, bb}] = 2;     if (f(a1, b2) == 2 && f(a2, b1) == 2) return m[{aa, bb}] = 2;     return m[{aa, bb}] = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> a >> b;     if (f(a, b) == 2)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 102, M = 102 * 102;   int n, m;   vector<pair<int, int> > g[N];   char ans[N][N];   char dp[N][N][28] = {0};   void input() {     cin >> n >> m;     for (int i = (0); i < (m); ++i) {       int u, v;       char ch;       cin >> u >> v >> ch;       u--, v--;       g[u].push_back(make_pair(v, ch -  a ));     }   }   int dfs(int u, int v, char c) {     if (dp[u][v][c] != 0) return dp[u][v][c];     for (auto x : g[u]) {       int h = x.first;       char k = x.second;       int win = 0;       if (k >= c) {         win = dfs(v, h, k);         if (win == 2) {           dp[u][v][c] = 1;           return 1;         }       }     }     dp[u][v][c] = 2;     return 2;   }   void solve() {     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (n); ++j) {         ans[i][j] = ((dfs(i, j, 0) == 1) ?  A  :  B );       }     }   }   void output() {     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (n); ++j) {         cout << ans[i][j];       }       cout <<   n ;     }   }   int main() {     input();     solve();     output();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 7;   const int inf = 1e9 + 7;   int T, n, dp[N][N], cnt[N], qzs[N][26], qzt[N][26];   char s[N], t[N];   void Min(int &x, int y) {     if (x > y) x = y;   }   void Main() {     fill(cnt, cnt + 26, 0);     scanf( %d , &n);     for (int i = 0, iE = n; i <= iE; i++)       for (int j = 0, jE = n; j <= jE; j++) dp[i][j] = inf;     scanf( %s%s , s + 1, t + 1);     for (int i = 1, iE = n; i <= iE; i++) cnt[s[i] -  a ]++, cnt[t[i] -  a ]--;     for (int i = 0, iE = 25; i <= iE; i++)       if (cnt[i]) return puts( -1 ), void();     for (int i = 1, iE = n; i <= iE; i++)       for (int j = 0, jE = 25; j <= jE; j++)         qzs[i][j] = qzs[i - 1][j] + (s[i] ==  a  + j),         qzt[i][j] = qzt[i - 1][j] + (t[i] ==  a  + j);     for (int i = 0, iE = n; i <= iE; i++) dp[0][i] = 0;     for (int i = 1, iE = n; i <= iE; i++)       for (int j = i, jE = n; j <= jE; j++) {         Min(dp[i][j], dp[i - 1][j] + 1);         if (s[i] == t[j]) Min(dp[i][j], dp[i - 1][j - 1]);         if (qzs[i][t[j] -  a ] < qzt[j][t[j] -  a ]) Min(dp[i][j], dp[i][j - 1]);       }     printf( %d n , dp[n][n]);   }   int main() {     scanf( %d , &T);     while (T--) Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s[1000006], top, a[1000006];   int solve(int n, int mul) {     if (n == 1) return s[++top] = mul;     if (n == 2) return s[++top] = mul, s[++top] = mul * 2;     if (n == 3) return s[++top] = mul, s[++top] = mul, s[++top] = mul * 3;     for (int i = 1; i <= (n - n / 2); i++) s[++top] = mul;     for (int i = 1; i <= n / 2; i++) a[i] = a[i * 2] / 2;     solve(n / 2, mul << 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) a[i] = i;     solve(n, 1);     for (int i = 1; i <= n; i++) printf( %d  , s[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int SCALE = 101;   int g[SCALE * 2][SCALE * 2];   int tx, ty;   int stepr[4] = {0, -1, 0, 1};   int stepc[4] = {-1, 0, 1, 0};   string s;   bool BuildMap(const string& s) {     int x = 0;     int y = 0;     memset(g, 0, sizeof(g));     g[(x + SCALE)][(y + SCALE)] = 1;     for (int i = 0; i < s.size(); ++i) {       int d = 0;       switch (s[i]) {         case  L :           d = 0;           break;         case  U :           d = 1;           break;         case  R :           d = 2;           break;         case  D :           d = 3;           break;       }       x += stepr[d];       y += stepc[d];       if (g[(x + SCALE)][(y + SCALE)] == 1) {         return false;       } else {         g[(x + SCALE)][(y + SCALE)] = 1;       }     }     tx = x;     ty = y;     return true;   }   int Dfs(int x, int y, int cost) {     if (x == tx && y == ty) return cost;     int v = 10000;     for (int i = 0; i < 4; ++i) {       int tmpx = x + stepr[i];       int tmpy = y + stepc[i];       int& tmpg = g[(tmpx + SCALE)][(tmpy + SCALE)];       if (tmpg == 1) {         tmpg = -1;         int tv = Dfs(tmpx, tmpy, cost + 1);         v = min(tv, v);         tmpg = 1;       }     }     return v;   }   bool CheckShort() {     g[(0 + SCALE)][(0 + SCALE)] = -1;     int cost = Dfs(0, 0, 0);     if (cost < s.size() - 1) {       return false;     }     return true;   }   int main() {     while (cin >> s) {       bool b = BuildMap(s);       if (b == false) {         cout <<  BUG  << endl;         continue;       }       b = CheckShort();       if (b == false) {         cout <<  BUG  << endl;         continue;       }       cout <<  OK  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& a) {     for (T& ai : a) is >> ai;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> const& a) {     os <<  [  ;     for (const T& ai : a) os << ai <<    ;     return os <<  ] ;   }   template <typename T1, typename T2>   istream& operator>>(istream& is, pair<T1, T2>& a) {     return is >> a.first >> a.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& os, pair<T1, T2> const& a) {     return os <<  (  << a.first <<  ,   << a.second <<  ) ;   }   int f() {     int n, h, l, r;     cin >> n >> h >> l >> r;     vector<int> a(n), b(h, -1);     cin >> a;     b[0] = 0;     for (int ai : a) {       vector<int> c(h, -1);       for (int i = 0; i < h; ++i) {         if (b[i] < 0) continue;         int j = i + ai - 1;         if (j >= h) j -= h;         c[j] = max(c[j], b[i] + (l <= j && j <= r));         if (++j >= h) j -= h;         c[j] = max(c[j], b[i] + (l <= j && j <= r));       }       b.swap(c);     }     return *max_element((b).begin(), (b).end());   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << f() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct basis {     int vis[29 + 1];     void ins(int x) {       for (int i = 29; i >= 0; i--)         if ((1 << i) & x) {           if (vis[i])             x ^= vis[i];           else {             vis[i] = x;             break;           }         }     }     int minimize(int x) {       for (int i = 29; i >= 0; i--) {         if ((x ^ vis[i]) < x) x ^= vis[i];       }       return x;     }   };   void merge(basis &a, basis b) {     for (int i = 0; i <= 29; i++) a.ins(b.vis[i]);   }   namespace violet {   int pa[65536 * 4];   int size[65536 * 4];   basis bas[65536 * 4];   int topa[65536 * 4];   vector<int> dex, desize, depa, detopa;   vector<basis> debas;   void init() {     for (int i = 0; i < 65536 * 4; i++) pa[i] = i, size[i] = 1;   }   int findpa(int x) {     if (pa[x] == x) return x;     return findpa(pa[x]);   }   int findtopa(int x) {     if (pa[x] == x) return 0;     return topa[x] ^ findtopa(pa[x]);   }   void save(int x) {     dex.push_back(x), desize.push_back(size[x]);     depa.push_back(pa[x]);     detopa.push_back(topa[x]);     debas.push_back(bas[x]);   }   void link(int x, int y, int w) {     int rx = findpa(x);     int ry = findpa(y);     if (size[rx] > size[ry]) swap(x, y), swap(rx, ry);     save(rx);     save(ry);     if (rx == ry) {       bas[rx].ins(w ^ findtopa(x) ^ findtopa(y));     } else {       size[ry] += size[rx];       merge(bas[ry], bas[rx]);       pa[rx] = ry;       topa[rx] = w ^ findtopa(x) ^ findtopa(y);     }   }   void deop() {     int x = dex[dex.size() - 1];     size[x] = desize[desize.size() - 1];     pa[x] = depa[depa.size() - 1];     topa[x] = detopa[detopa.size() - 1];     bas[x] = debas[debas.size() - 1];     dex.pop_back();     desize.pop_back();     depa.pop_back();     detopa.pop_back();     debas.pop_back();   }   int ask(int x, int y) {     return bas[findpa(x)].minimize(findtopa(x) ^ findtopa(y));   }   };  // namespace violet   int n, m, q;   int output[65536 * 4];   int askx[65536 * 4], asky[65536 * 4];   vector<int> ow[65536 * 4 * 2], ox[65536 * 4 * 2], oy[65536 * 4 * 2];   void modi(int a, int b, int l, int r, int id, int &x, int &y, int &w) {     if (l >= a and r <= b) {       ox[id].push_back(x);       oy[id].push_back(y);       ow[id].push_back(w);       return;     }     int mid = (l + r) / 2;     if (a <= mid) modi(a, b, l, mid, id << 1, x, y, w);     if (b > mid) modi(a, b, mid + 1, r, id << 1 | 1, x, y, w);   }   vector<int> newid, oldid;   void ask(int x, int l, int r, int id) {     newid.push_back(id);     if (l == r) return;     int mid = (l + r) / 2;     if (x <= mid)       ask(x, l, mid, id << 1);     else       ask(x, mid + 1, r, id << 1 | 1);   }   map<pair<int, int>, int> edge, ew;   void redo(int id) {     for (int i = 0; i < ox[id].size(); i++) violet::deop(), violet::deop();   }   void doit(int id) {     for (int i = 0; i < ox[id].size(); i++)       violet::link(ox[id][i], oy[id][i], ow[id][i]);   }   int main() {     scanf( %d%d , &n, &m);     violet::init();     while (m--) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       if (x > y) swap(x, y);       edge[make_pair(x, y)] = 1, ew[make_pair(x, y)] = z;     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, y, w;         scanf( %d%d%d , &x, &y, &w);         if (x > y) swap(x, y);         edge[make_pair(x, y)] = i;         ew[make_pair(x, y)] = w;       } else if (op == 2) {         int x, y;         scanf( %d%d , &x, &y);         if (x > y) swap(x, y);         modi(edge[make_pair(x, y)], i, 1, 65536 * 4, 1, x, y,              ew[make_pair(x, y)]);         edge[make_pair(x, y)] = 0;       } else {         output[i] = 1;         scanf( %d%d , &askx[i], &asky[i]);       }     }     for (map<pair<int, int>, int>::iterator it = edge.begin(); it != edge.end();          it++) {       if (it->second) {         pair<int, int> p = it->first;         modi(it->second, q, 1, 65536 * 4, 1, p.first, p.second, ew[p]);       }     }     for (int i = 1; i <= q; ++i)       if (output[i]) {         newid.clear();         ask(i, 1, 65536 * 4, 1);         int st = 0;         for (int j = 0; j < oldid.size() and j < newid.size(); j++)           if (oldid[j] == newid[j])             st = j + 1;           else             break;         while (oldid.size() > st) redo(oldid[oldid.size() - 1]), oldid.pop_back();         for (int i = st; i < newid.size(); i++) {           doit(newid[i]);           oldid.push_back(newid[i]);         }         printf( %d n , violet::ask(askx[i], asky[i]));       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m;   vector<long long> b(N, 0);   void add(int x, int k) {     while (x < N) {       b[x] += k;       x += x & -x;     }   }   long long sum(int x) {     long long ret = 0;     while (x) {       ret += b[x];       x -= x & -x;     }     return ret;   }   void add(int l, int r, int k) {     if (l > r) return;     add(l, k);     add(r + 1, -k);   }   int main() {     scanf( %d%d , &n, &m);     vector<int> x(m + 1, 0);     for (int i = 0, y; i < m; i++) {       scanf( %d , &x[i]);     }     for (int i = 1; i < m; i++) {       long long sum = 0;       int u = x[i - 1];       int v = x[i];       if (u == v) continue;       if (u < v) swap(u, v);       add(1, v - 1, u - v);       add(u + 1, n, u - v);       add(v + 1, u - 1, u - v - 1);       add(v, v, u - 1);       add(u, u, v);     }     for (int i = 1; i <= n; i++) {       printf( %lld%c , sum(i),    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   const double PI =       3.141592653589793238462643383279502884197169399375105820974944;   using namespace std;   long long arr[] = {0,     9,      90,      900,      9000,                      90000, 900000, 9000000, 90000000, 900000000};   long long arr1[] = {0,     9,      99,      999,      9999,                       99999, 999999, 9999999, 99999999, 999999999};   void solve() {     long long n;     cin >> n;     int digits = 0;     long long temp = n;     while (temp != 0) {       ++digits;       temp = temp / 10;     }     long long ans = 0;     for (long long i = 0; i < digits; ++i) {       ans += arr[i] * (i);     }     ans += (n - arr1[digits - 1]) * (digits);     cout << ans <<   n ;   }   int main() {     bool testing = false;     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (testing) {       freopen( test.txt ,  rt , stdin);       int start = clock();       solve();       int end = clock();       cout <<  time:   << (end - start) / (double)(CLOCKS_PER_SEC)*1000            <<   milliseconds n ;     } else {       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   const long long MAXN = 1e5 + 7;   void check() {     long long a[1000] = {0}, b[1000] = {0}, ans = 0;     string s1, s2;     cin >> s1 >> s2;     for (long long i = 0; i < s1.size(); i++) a[s1[i]]++, b[s2[i]]++;     for (long long i = 0; i < s1.size(); i++) {       if (s2[i] != s1[i]) {         if (a[s2[i]] < b[s2[i]]) {           ans++;           a[s2[i]]++;           a[s1[i]]--;           s1[i] = s2[i];         }       }     }     long long cnt = 0;     for (long long i = 0; i < s1.size(); i++) cnt += (s1[i] != s2[i]);     cnt /= 2;     cout << ans + cnt;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int i = 1; i <= t; i++) {       check();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(const string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cout << to_string(H) <<   |  ;     dbgm(T...);   }   const long long INF = 1e9;   struct Dinic {     int nodes, src, dst;     vector<int> dist, q, work;     struct edge {       int to, rev;       long long f, cap;     };     vector<vector<edge>> g;     Dinic(int x) : nodes(x), g(x), dist(x), q(x), work(x) {}     void add_edge(int s, int t, long long cap) {       g[s].push_back((edge){t, ((int)g[t].size()), 0, cap});       g[t].push_back((edge){s, ((int)g[s].size()) - 1, 0, 0});     }     bool dinic_bfs() {       fill(dist.begin(), dist.end(), -1);       dist[src] = 0;       int qt = 0;       q[qt++] = src;       for (int qh = 0; qh < qt; qh++) {         int u = q[qh];         for (int i = 0; i < ((int)g[u].size()); i++) {           edge &e = g[u][i];           int v = g[u][i].to;           if (dist[v] < 0 && e.f < e.cap) dist[v] = dist[u] + 1, q[qt++] = v;         }       }       return dist[dst] >= 0;     }     long long dinic_dfs(int u, long long f) {       if (u == dst) return f;       for (int &i = work[u]; i < ((int)g[u].size()); i++) {         edge &e = g[u][i];         if (e.cap <= e.f) continue;         int v = e.to;         if (dist[v] == dist[u] + 1) {           long long df = dinic_dfs(v, min(f, e.cap - e.f));           if (df > 0) {             e.f += df;             g[v][e.rev].f -= df;             return df;           }         }       }       return 0;     }     long long max_flow(int _src, int _dst) {       src = _src;       dst = _dst;       long long result = 0;       while (dinic_bfs()) {         fill(work.begin(), work.end(), 0);         while (long long delta = dinic_dfs(src, INF)) result += delta;       }       return result;     }   };   long long cost(long long a, long long b) { return a * a - b * b; }   int N;   int n, h, m;   int getPos(int i, int j) {     if (j == 0) return N;     if (j >= h + 1) return N + 1;     return i * (h + 1) + j;   }   int getPos(int i) { return n * (h + 1) + i; }   int main() {     cin >> n >> h >> m;     N = n * (h + 1) + m;     Dinic din(N + 2);     for (int i = 0; i < n; i++) {       int node = i * (h + 1);       for (int j = 0; j < h + 1; j++) {         int left = getPos(i, j);         int right = getPos(i, j + 1);         din.add_edge(left, right, cost(h, j));       }     }     for (int i = 0; i < m; i++) {       int l, r, x, c;       cin >> l >> r >> x >> c;       int node = getPos(i);       din.add_edge(node, N + 1, c);       for (int j = l - 1; j < r; j++) {         din.add_edge(getPos(j, x + 1), node, INF);       }     }     cout << h * h * n - din.max_flow(N, N + 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n;     cin >> t;     while (t--) {       cin >> n;       if (n % 2)         cout << (n + 1) / 2 << endl;       else         cout << n / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int ans[2010][2], n;   bool vis[510][510];   bool query(int x1, int y1, int x2, int y2) {     printf( ? %d %d %d %d n , x1, y1, x2, y2);     fflush(stdout);     char ch[5];     scanf( %s , ch);     if (ch[0] ==  Y )       return 1;     else       return 0;   }   void out() {     int x = 1, y = 1;     printf( !  );     while ((x != n) || (y != n)) {       if ((x != n) && (vis[x + 1][y])) {         printf( D );         x++;       } else {         printf( R );         y++;       }     }     printf(  n );     fflush(stdout);   }   int main() {     int now = 1;     scanf( %d , &n);     int x = 1, y = 1;     memset(vis, 0, sizeof(vis));     vis[0][0] = 1;     vis[n][n] = 1;     ans[1][0] = 1;     ans[1][1] = 1;     while (x + y <= n) {       bool flag = query(x + 1, y, n, n);       if (flag) {         x++;         vis[x][y] = 1;       } else {         y++;         vis[x][y] = 1;       }       now++;       ans[now][0] = x;       ans[now][1] = y;     }     x = n;     y = n;     now--;     while (x + y > n + 1) {       if (query(ans[now][0], ans[now][1], x, y - 1))         y--;       else         x--;       vis[x][y] = 1;       now--;     }     out();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long m, f[1005][105][2];   long long dfs(int Index, int y, int now, int flag) {     if (Index > n) return (flag == 0);     if (f[Index][y][flag] != -1) return f[Index][y][flag];     int st = Index == n ? 1 : 0, y1;     long long res = 0;     for (int i = st; i <= 9; i++) {       y1 = (y + now * i % k) % k;       res =           (res + dfs(Index + 1, y1, now * 10 % k, (flag && (y1 != 0 || !i)))) % m;     }     f[Index][y][flag] = res;     return res;   }   int main() {     scanf( %d %d %lld , &n, &k, &m);     memset(f, -1, sizeof f);     printf( %lld n , dfs(1, 0, 1, 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100001];   int a, b, n, best;   int main() {     bool dima = true;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       arr[a] = b;     }     for (int i = 0; i < 100001; ++i) {       if (arr[i] > 0)         if (arr[i] > best)           best = arr[i];         else {           dima = false;           break;         }     }     if (dima)       printf( Poor Alex );     else       printf( Happy Alex );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;   struct P {     long long x, y;     P() {}     P(long long x, long long y) : x(x), y(y) {}     P rotate() { return P(-y, x); }     P operator-(const P& rhs) const { return P(x - rhs.x, y - rhs.y); }     long long operator*(const P& rhs) const { return x * rhs.x + y * rhs.y; }     bool operator==(const P& rhs) const { return x == rhs.x && y == rhs.y; }   };   bool judge(P& u, P& v) {     if (v == P(0, 0)) return u == P(0, 0);     long long w = v.x * v.x + v.y * v.y;     return u * v % w == 0 && u * v.rotate() % w == 0;   }   P a, b, c;   int main() {     ios_base::sync_with_stdio(0);     while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y) {       bool ok = false;       for (int i = 0; i < 4; ++i) {         P d = b - a;         if (judge(d, c)) {           ok = true;           break;         }         a = a.rotate();       }       cout << (ok ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int lcm(int x, int y) { return x * y / gcd(x, y); }   long long int gcd(long long int x, long long int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long int lcm(long long int x, long long int y) {     return x * y / gcd(x, y);   }   void swap(long long int& x, long long int& y) {     long long int temp = x;     x = y;     y = temp;   }   long long int binpow(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int binpowM(long long int a, long long int b) {     a %= 100000007;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % 100000007;       a = a * a % 100000007;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     int n, ans = 0, k;     cin >> n;     vector<int> a(3);     for (int i = 0; i < 3; i++) {       cin >> a[i];     }     sort(a.begin(), a.end(), greater<int>());     int i = 0, j, l = n / a[1], m = n / a[0];     while (i <= m) {       j = 0;       while (j <= l) {         k = n - i * a[0] - j * a[1];         if (k % a[2] == 0) {           ans = max(i + j + k / a[2], ans);         }         j++;       }       i++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   long long A, B, N;   long long l, t, m;   int main() {     cin >> A >> B >> N;     for (int i = 1; i <= N; i++) {       cin >> l >> t >> m;       if (t < A + (l - 1) * B) {         cout << -1 << endl;         continue;       }       long long L = 1, R = 10000000, M;       while (L <= R) {         M = (L + R) / 2;         if ((2 * A + (l + M - 2) * B) * (M - l + 1) > t * m * 2)           R = M - 1;         else           L = M + 1;       }       cout << min(R, (t - A + B) / B) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 265000;   int n, q, a[N];   double s;   int main() {     scanf( %d%d , &n, &q);     for (int i = (0); i <= (int)(1 << n) - 1; i++) scanf( %d , &a[i]), s += a[i];     printf( %.10lf n , 1.0 * s / (1 << n));     for (int i = (1); i <= (int)q; i++) {       int x, y;       scanf( %d%d , &x, &y);       s += y - a[x];       a[x] = y;       printf( %.10lf n , 1.0 * s / (1 << n));     }   }


#include <bits/stdc++.h>   using namespace std;   int n, p, q, r, now;   int a[500050], b[500050], c[500050], id[500050], mxx[500050], mxy[500050];   long long ans;   struct seg {     int mark[500050 << 2], mx[500050 << 2], mn[500050 << 2];     long long sum[500050 << 2];     void push_up(int id) {       sum[id] = sum[id << 1] + sum[id << 1 | 1];       mx[id] = max(mx[id << 1], mx[id << 1 | 1]);       mn[id] = min(mn[id << 1], mn[id << 1 | 1]);     }     void make_con(int l, int r, int id, int val) {       mark[id] = val;       sum[id] = 1ll * val * (r - l + 1);       mx[id] = mn[id] = val;     }     void push_down(int l, int r, int id) {       if (mark[id]) {         int m = l + r >> 1;         make_con(l, m, id << 1, mark[id]);         make_con(m + 1, r, id << 1 | 1, mark[id]);         mark[id] = 0;       }     }     void modify(int L, int R, int val, int l, int r, int id) {       if (r < L || R < l) return;       if (L <= l && r <= R) {         make_con(l, r, id, val);         return;       }       push_down(l, r, id);       int m = l + r >> 1;       modify(L, R, val, l, m, id << 1);       modify(L, R, val, m + 1, r, id << 1 | 1);       push_up(id);     }     long long sumquery(int L, int R, int l, int r, int id) {       if (r < L || R < l) return 0;       if (L <= l && r <= R) {         return sum[id];       }       push_down(l, r, id);       int m = l + r >> 1;       return sumquery(L, R, l, m, id << 1) +              sumquery(L, R, m + 1, r, id << 1 | 1);     }     int lquery(int val, int l, int r, int id) {       if (l == r) return l;       push_down(l, r, id);       int m = l + r >> 1;       if (mn[id << 1] < val) return lquery(val, l, m, id << 1);       return lquery(val, m + 1, r, id << 1 | 1);     }     int rquery(int val, int l, int r, int id) {       if (l == r) return l;       push_down(l, r, id);       int m = l + r >> 1;       if (mx[id << 1 | 1] >= val) return rquery(val, m + 1, r, id << 1 | 1);       return rquery(val, l, m, id << 1);     }   } ST;   bool cmp(int x, int y) { return a[x] < a[y]; }   void modify(int x, int y) {     if (ST.mn[1] >= y) return;     int l = ST.lquery(y, 1, q, 1);     if (l <= x) ST.modify(l, x, y, 1, q, 1);   }   long long query(int x, int y) {     long long rtn = 1ll * (q - x + 1) * (r - y + 1);     if (ST.mx[1] < y) return rtn;     int r = ST.rquery(y, 1, q, 1);     if (x <= r) rtn -= ST.sumquery(x, r, 1, q, 1) - 1ll * (r - x + 1) * (y - 1);     return rtn;   }   int main() {     scanf( %d %d %d %d , &n, &p, &q, &r);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &a[i], &b[i], &c[i]);       id[i] = i;     }     sort(id, id + n, cmp);     mxx[n] = mxy[n] = 1;     for (int i = n - 1; i >= 0; i--) {       mxx[i] = max(mxx[i + 1], b[id[i]] + 1);       mxy[i] = max(mxy[i + 1], c[id[i]] + 1);     }     for (int i = 1; i <= p; i++) {       while (now < n && a[id[now]] < i) modify(b[id[now]], c[id[now]]), now++;       ans += query(mxx[now], mxy[now]);     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n;   int info[200005], sz[200005], Prev[200005 << 1], to[200005 << 1],       cst[200005 << 1], cnt_e;   void Node(int u, int v, int c) {     Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = c;   }   long long G, B;   void dfs(int u, int ff) {     sz[u] = 1;     for (int i = info[u], v; i; i = Prev[i])       if ((v = to[i]) != ff) {         dfs(v, u), sz[u] += sz[v];         G += (sz[v] & 1) * cst[i], B += 1ll * cst[i] * min(sz[v], 2 * n - sz[v]);       }   }   int main() {     int T;     scanf( %d , &T);     for (; T--;) {       scanf( %d , &n);       for (int i = 1, u, v, c; i < 2 * n; i++)         scanf( %d%d%d , &u, &v, &c), Node(u, v, c), Node(v, u, c);       B = G = 0, dfs(1, 0);       for (int i = 1; i <= 2 * n; i++) info[i] = 0;       cnt_e = 0;       printf( %lld %lld n , G, B);     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, k;     scanf( %lld%lld , &n, &k);     long long coin = 0, sum = 0;     for (long long i = 1; i <= k; i++) {       long long a, b;       scanf( %lld%lld , &a, &b);       sum = (sum + a * b) % n;       coin += b;     }     if (coin > n) {       printf( -1 );       return 0;     }     if (coin < n) {       printf( 1 );       return 0;     }     if (sum == n * (n + 1) / 2 % n) {       printf( 1 );       return 0;     }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000009, N = 4005;   int cal[N][N], fac[N];   inline int add(int a, int b) {     if (a < 0) a += mod;     if (b < 0) b += mod;     int ret = a + b;     if (ret >= mod)       return ret %= mod;     else       return ret;   }   inline int mul(int a, int b) {     if (a < 0) a += mod;     if (b < 0) b += mod;     long long ret = (long long)a * b;     if (ret >= mod)       return ret % mod;     else       return ret;   }   int main() {     memset(cal, 0, sizeof(cal));     cal[0][0] = 1;     fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = mul(fac[i - 1], i);       cal[i][0] = cal[i][i] = 1;       for (int j = 1; j < i; j++) {         cal[i][j] = add(cal[i - 1][j], cal[i - 1][j - 1]);       }     }     int n, a, b, ans = 0;     scanf( %d%d%d , &n, &a, &b);     for (int i = 1; i < n - 1; i++) {       for (int j = i + 2; j <= n; j++) {         int cntb = j - i - 1, cnta = n - cntb;         if (cntb > b) break;         if (cnta > a) continue;         ans = add(ans, mul(mul(cal[a - 1][cnta - 1], fac[a]),                            mul(cal[b - 1][cntb - 1], fac[b])));       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 5005;   int type[mx], dp[mx];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       double x;       cin >> type[i] >> x;     }     for (int i = 1; i <= n; i++) {       int j = type[i];       for (int k = j; k >= 1; k--) dp[j] = max(dp[j], 1 + dp[k]);     }     int ret = 0;     for (int i = 1; i <= n; i++) ret = max(ret, dp[i]);     cout << n - ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pci = pair<char, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vpii = vector<pii>;   const ll infll = 1e18 + 3;   const int maxn = 1e6 + 77;   const int nmax = 1e6 + 77;   const ll basell = 1e18 + 3;   const int mod = 1e9 + 7;   const ld eps = 1e-7;   const int inf = 1009000999;   const int nv = 100505;   const int baseint = 1000200013;   const ld PI = acos(-1.0);   inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; }   struct lis {     int x, y, z;   };   vector<lis> ans;   int vis[2 * nv];   int used[2 * nv];   vi g[2 * nv];   int h[2 * nv];   void dfs(int v, int p) {     vis[v] = 1;     vector<int> q;     for (int u : g[v]) {       if (u == p) continue;       if (!vis[u]) {         h[u] = h[v] + 1;         dfs(u, v);         if (!used[u]) q.push_back(u);       } else {         if (h[u] > h[v]) q.push_back(u);       }     }     for (int i = 0; i + 1 < ((int)(q).size()); i += 2) {       ans.push_back({q[i], v, q[i + 1]});     }     if (((int)(q).size()) % 2 == 1 && p != -1) {       ans.push_back({q.back(), v, p});       used[v] = 1;     }   }   int inline solve() {     ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);     ;     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       g[a - 1].push_back(b - 1);       g[b - 1].push_back(a - 1);     }     for (int i = 0; i < n; ++i) {       if (!vis[i]) dfs(i, -1);     }     cout << ((int)(ans).size()) <<   n ;     for (lis u : ans) cout << u.x + 1 <<     << u.y + 1 <<     << u.z + 1 <<   n ;     return 0;   }   int32_t main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   vector<string> text;   vector<int> lens;   bool check(int w) {     int c = 0, lines = 1;     for (int i = 0; i < (int)(lens).size(); i++) {       if (lens[i] > w) return false;       if (c + lens[i] > w) {         lines++;         i--;         c = 0;       } else         c += lens[i];     }     return lines <= n;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     while (cin >> s) text.push_back(s);     int c;     for (int i = 0; i < (int)(text).size(); i++) {       c = 0;       for (int j = 0; j < (int)(text[i]).size(); j++) {         c++;         if (text[i][j] ==     || text[i][j] ==  - ) {           lens.push_back(c);           c = 0;         }       }       if (c) {         if (i != (int)(text).size() - 1)           lens.push_back(c + 1);         else           lens.push_back(c);       }     }     int s = 0, e = 1e9, mid;     while (e - s > 1) {       mid = (s + e) >> 1;       if (check(mid))         e = mid;       else         s = mid;     }     cout << e <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n;   long long a[200200];   long long mn = 21000000000;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mn = min(mn, a[i]);     }     int id;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == mn) {         id = i;         break;       }     }     for (int i = 0; i < n; i++) {       ans += mn;       a[i] -= mn;     }     long long s = 0, c = -1;     for (int i = (id + 1) % n; i != id; i = (i + 1) % n) {       if (a[i] == 0) {         c = max(c, s);         s = 0LL;         a[i]--;       } else {         s++;       }     }     c = max(c, s);     cout << ans + c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[200003],mMst[200003],mMdr[200003],Mmst[200003],Mmdr[200003];   int aib[200003];   int lsb (int x)   {       return x&-x;   }   void reset ()   {       for(int i=1;i<=200000;++i)           aib[i]=0;   }   void upd (int pz, int val)   {       for(int i=pz;i<=200000;i+=lsb(i))           aib[i]+=val;   }   int query (int pz)   {       int rz=0;       for(int i=pz;i>0;i-=lsb(i))           rz+=aib[i];       return rz;   }   int main()   {       ios_base::sync_with_stdio(false);       #ifdef HOME       ifstream cin( date.in );       ofstream cout( date.out );       #endif // HOME       long long t,a,k,x,b,i,n,j;       cin>>n;       for(i=1;i<=n;++i)           cin>>v[i];       /// <= - > la st:       for(i=1;i<=n;++i)       {           mMst[i]=query(v[i]);           upd(v[i],2);           int pz=0;           int pas=(1<<17);           while(pas)           {               if(pz+pas<=200000 && aib[pz+pas]==0)                   pz+=pas;               pas>>=1;           }           upd(pz+1,-1);       }       reset();       for(i=n;i>=1;--i)       {           mMdr[i]=query(v[i]);           upd(v[i],2);           int pz=0;           int pas=(1<<17);           while(pas)           {               if(pz+pas<=200000 && aib[pz+pas]==0)                   pz+=pas;               pas>>=1;           }           upd(pz+1,-1);       }       reset();       for(i=1;i<=n;++i)           v[i]=n+1-v[i];       for(i=1;i<=n;++i)       {           Mmst[i]=query(v[i]);           upd(v[i],2);           int pz=0;           int pas=(1<<17);           while(pas)           {               if(pz+pas<=200000 && aib[pz+pas]==0)                   pz+=pas;               pas>>=1;           }           upd(pz+1,-1);       }       reset();       for(i=n;i>=1;--i)       {           Mmdr[i]=query(v[i]);           upd(v[i],2);           int pz=0;           int pas=(1<<17);           while(pas)           {               if(pz+pas<=200000 && aib[pz+pas]==0)                   pz+=pas;               pas>>=1;           }           upd(pz+1,-1);       }       for(i=1;i<=n;++i)       {           int a=mMst[i]+mMdr[i];           int rz=a/2;           a=Mmst[i]+Mmdr[i];           rz=max(rz,(a+1)/2);           cout<<rz<<   ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 131072 | 5, mod = 998244353;   int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }   void ADD(int &x, int y) { (x += y) >= mod ? x -= mod : 0; }   int qpow(int a, int b) {     int ans = 1;     for (; b >= 1; b >>= 1, a = (long long)a * a % mod)       if (b & 1) ans = (long long)ans * a % mod;     return ans;   }   int rev[N], W[N];   int getn(int len) {     int n = 1;     while (n < len) n <<= 1;     return n;   }   void prework(int n) {     for (int i = 1; i < n; i <<= 1) {       W[i] = 1;       int w = qpow(3, (mod - 1) / (i << 1));       for (int j = 1; j < i; j++) W[i + j] = (long long)W[i + j - 1] * w % mod;     }   }   void NTT(vector<int> &a, int n, int op) {     a.resize(n);     for (int i = 1; i < n; i++)       if (i < (rev[i] = (rev[i >> 1] >> 1) | (i & 1 ? n >> 1 : 0)))         swap(a[i], a[rev[i]]);     for (int i = 1; i < n; i <<= 1) {       for (int j = 0; j < n; j += i << 1) {         for (int k = 0; k < i; k++) {           int q = (long long)W[i + k] * a[j + k + i] % mod;           a[j + k + i] = add(a[j + k], mod - q);           ADD(a[j + k], q);         }       }     }     if (op == 1) return;     reverse(a.begin() + 1, a.end());     int inv = mod - (mod - 1) / n;     for (int i = 0; i <= n - 1; ++i) a[i] = (long long)a[i] * inv % mod;   }   vector<int> operator*(vector<int> a, vector<int> b) {     int t = a.size() + b.size() - 1, n = getn(t);     NTT(a, n, 1);     NTT(b, n, 1);     for (int i = 0; i <= n - 1; ++i) a[i] = (long long)a[i] * b[i] % mod;     NTT(a, n, -1);     a.resize(t);     return a;   }   vector<int> fix(vector<int> a, int n) {     a.resize(n);     return a;   }   vector<int> Inv(vector<int> a) {     int sz = a.size();     vector<int> c(1, qpow(a[0], mod - 2)), t;     for (int i = 1; i < sz; i <<= 1) {       NTT(t = fix(a, i << 1), i << 2, 1);       NTT(c, i << 2, 1);       for (int j = 0; j < (i << 2); j++)         c[j] = (2 * c[j] - (long long)t[j] * c[j] % mod * c[j] % mod + mod) % mod;       NTT(c, i << 2, -1);       c.resize(i << 1);     }     c.resize(sz);     return c;   }   int main() {     int n;     scanf( %d , &n);     const int m = max(n + 1, 32);     vector<int> a = {0,         0,   0,  24,  4,        144, mod - 4, 348,                      mod - 128, 240, 28, 188, mod - 68, 16,  0,       4};     vector<int> b = {1,        0,       mod - 4, mod - 8, 1,        mod - 16,                      10,       mod - 4, 12,      48,      mod - 26, 44,                      mod - 15, 16,      4,       4,       1};     a.resize(m);     b.resize(m);     prework(2 * m);     a = a * Inv(b);     printf( %d n , a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h, k;     cin >> n >> m >> h >> k;     cout << ((n > m) ?  First  :  Second ) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int B) { return (unsigned long long)rng() % B; }   const int N = 51;   int vld[N][N][N][N];   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int h, w, q;     cin >> h >> w >> q;     vector<string> s(h);     for (int i = 0; i < h; i++) {       cin >> s[i];     }     vector<vector<int>> sum(h + 1, vector<int>(w + 1));     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         sum[i + 1][j + 1] = (s[i][j] ==  0 );       }     }     for (int i = 0; i < h; i++) {       for (int j = 0; j <= w; j++) {         sum[i + 1][j] += sum[i][j];       }     }     for (int j = 0; j < w; j++) {       for (int i = 0; i <= h; i++) {         sum[i][j + 1] += sum[i][j];       }     }     for (int i = 1; i <= h; i++) {       for (int j = 1; j <= w; j++) {         for (int k = i; k <= h; k++) {           for (int l = j; l <= w; l++) {             if ((l - j + 1) * (k - i + 1) ==                 sum[k][l] - sum[i - 1][l] - sum[k][j - 1] + sum[i - 1][j - 1]) {               vld[i][j][k][l] = 1;             }           }         }       }     }     for (int i = 0; i < h; i++) {       for (int j = 0; j <= w; j++) {         for (int k = 0; k <= h; k++) {           for (int l = 0; l <= w; l++) {             vld[i + 1][j][k][l] += vld[i][j][k][l];           }         }       }     }     for (int i = 0; i <= h; i++) {       for (int j = 0; j < w; j++) {         for (int k = 0; k <= h; k++) {           for (int l = 0; l <= w; l++) {             vld[i][j + 1][k][l] += vld[i][j][k][l];           }         }       }     }     for (int i = 0; i <= h; i++) {       for (int j = 0; j <= w; j++) {         for (int k = 0; k < h; k++) {           for (int l = 0; l <= w; l++) {             vld[i][j][k + 1][l] += vld[i][j][k][l];           }         }       }     }     for (int i = 0; i <= h; i++) {       for (int j = 0; j <= w; j++) {         for (int k = 0; k <= h; k++) {           for (int l = 0; l < w; l++) {             vld[i][j][k][l + 1] += vld[i][j][k][l];           }         }       }     }     while (q--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       printf( %d n , vld[c][d][c][d] - vld[a - 1][d][c][d] - vld[c][b - 1][c][d] +                          vld[a - 1][b - 1][c][d]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, a[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int s = 0;     for (int i = 1; i <= n; i++) s ^= a[i];     if (n % 2 == 0) {       if (s != 0) {         cout <<  NO n ;         return 0;       }       n--;     }     cout <<  YES n ;     cout << n - 2 <<   n ;     for (int i = 1; i <= n - 2; i += 2)       cout << i <<     << i + 1 <<     << i + 2 <<   n ;     for (int i = 1; i <= n - 4; i += 2)       cout << i <<     << i + 1 <<     << n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nums[105];   int main() {     int n, m, mayor;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> nums[i];     }     sort(nums, nums + n);     reverse(nums, nums + n);     int maximo = nums[0] + m;     mayor = nums[0];     for (int i = 0; i < n; i++) {       m -= mayor - nums[i];       nums[0] = mayor;     }     int i = 0;     while (m > 0) {       m--;       nums[i % n]++;       i++;     }     int minimo = nums[0];     cout << minimo <<     << maximo <<   n ;   }


#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f;   template <typename T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <typename T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <typename T>   T read(T &first) {     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (first = 0; isdigit(ch); ch = getchar()) first = 10 * first + ch -  0 ;     return first *= f;   }   template <typename T>   void write(T first) {     if (first == 0) {       putchar( 0 );       return;     }     if (first < 0) {       putchar( - );       first = -first;     }     static char s[20];     int top = 0;     for (; first; first /= 10) s[++top] = first % 10 +  0 ;     while (top) putchar(s[top--]);   }   const int MAXN = 2e5 + 5;   const int CNT = 60;   int N;   std::pair<int, int> A[MAXN];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   inline int count(int i, int j) {     return gcd(std::abs(A[j].first - A[i].first),                std::abs(A[j].second - A[i].second));   }   inline long long cross(const std::pair<int, int> &a,                          const std::pair<int, int> &b) {     return (long long)a.first * b.second - (long long)a.second * b.first;   }   void input() {     read(N);     for (int i = 0; i < N; ++i) {       read(A[i].first);       read(A[i].second);     }   }   void solve() {     memcpy(A + N, A, sizeof(*A) * N);     long long a = 0, b = 0;     for (int i = 0; i < N; ++i) {       a += cross(A[i], A[i + 1]);       b += count(i, i + 1);     }     long double coef[MAXN];     long double tnn = pow((long double)2, -N);     for (int i = 2; i <= CNT && i < N - 1; ++i) {       coef[i] = pow((long double)2, -i - 1) - tnn;     }     long double ans = 0.5 * a - 0.5 * b + 1;     long double contrib = 0;     for (int i = 0; i < N; ++i) {       a = cross(A[i], A[i + 1]);       b = count(i, i + 1);       for (int k = 2; k <= CNT && k < N - 1; ++k) {         int j = i + k;         a += cross(A[j - 1], A[j]);         b += count(j - 1, j);         long long a0 = cross(A[j], A[i]);         long long b0 = count(j, i);         contrib += (0.5 * (a + a0) - 0.5 * (b + b0) + b0) * coef[k];       }     }     ans -= contrib / (1 - tnn - N * tnn - (long long)N * (N - 1) / 2 * tnn);     printf( %.15f n , (double)ans);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long F[401000], Mod = 998244353, InvF[401000];   long long Pow(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = r * a % Mod;       a = a * a % Mod;       b >>= 1;     }     return r;   }   int A[201000], n, K;   long long S[201000], res;   long long Comb(int a, int b) {     return F[a] * InvF[b] % Mod * InvF[a - b] % Mod;   }   int main() {     int i;     F[0] = 1;     for (i = 1; i <= 400000; i++) F[i] = F[i - 1] * i % Mod;     InvF[i - 1] = Pow(F[i - 1], Mod - 2);     for (i = i - 1; i >= 1; i--) InvF[i - 1] = InvF[i] * i % Mod;     scanf( %d%d , &n, &K);     for (i = 0; i < n; i++) {       scanf( %d , &A[i]);     }     int c2 = 0, c1 = 0;     for (i = 0; i < n; i++) {       if (A[i] == A[(i + 1) % n])         c2++;       else         c1++;     }     for (i = 0; i <= c1; i++) {       if (i % 2 == 1) {         S[i] = Pow(2, i - 1) % Mod;       } else {         S[i] = (Pow(2, i) - Comb(i, i / 2) + Mod) * (Mod / 2 + 1) % Mod;       }     }     for (i = 0; i <= c1; i++) {       if (K >= 2 || i == c1) {         res = (res + Pow(K - 2, c1 - i) * S[i] % Mod * Comb(c1, i)) % Mod;       }     }     res = res * Pow(K, c2) % Mod;     printf( %lld n , res);   }


#include <bits/stdc++.h>   int n, p[110], i, j, cnt;   char s[110];   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &p[i]);     gets(s);     for (i = 0; i < n; i++) {       gets(s);       cnt = 0;       for (j = 0; s[j]; j++)         if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  ||             s[j] ==  u  || s[j] ==  y )           cnt++;       if (cnt != p[i]) goto fuck;     }     puts( YES );     return 0;   fuck:     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 7;   long long n, q;   long long a[N];   long long l[N], r[N];   void read() {     cin >> n >> q;     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < q; ++i) cin >> l[i];     for (long long i = 0; i < q; ++i) cin >> r[i];     for (long long i = 0; i < q; ++i) {       --l[i];       --r[i];     }   }   long long ans[N];   long long link[N];   vector<long long> add[N], del[N];   long long f[N], fcnt[N];   void addf(long long i) {     long long t = i;     for (; i < N; i |= (i + 1)) {       f[i] += t;     }   }   void addfcnt(long long i) {     for (; i < N; i |= (i + 1)) {       fcnt[i]++;     }   }   void add_(long long i) {     addf(i);     addfcnt(i);   }   long long getsum(long long i) {     long long ans = 0;     for (; i >= 0; i = (i & (i + 1)) - 1) {       ans += f[i];     }     return ans;   }   long long getcnt(long long i) {     long long ans = 0;     for (; i >= 0; i = (i & (i + 1)) - 1) {       ans += fcnt[i];     }     return ans;   }   long long getmax(long long x) {     return getcnt(x) * x + getsum(N - 1) - getsum(x);   }   long long pref[N];   void kek() {     for (long long i = 0; i < N; ++i) {       f[i] = fcnt[i] = 0;     }     for (long long i = 0; i < q; ++i) {       ans[i] += pref[r[i] + 1] - pref[l[i]];     }     for (long long i = 0; i < N; ++i) f[i] = fcnt[i] = 0;     for (long long i = 0; i < n; ++i) {       add[i].clear();       del[i].clear();     }     for (long long i = 0; i < n; ++i) link[i] = -1;     vector<long long> st;     for (long long i = n - 1; i >= 0; --i) {       while (st.size() && a[i] > a[st.back()]) {         link[st.back()] = i;         st.pop_back();       }       st.push_back(i);     }     for (long long i = 0; i < q; ++i) {       add[r[i]].push_back(i);       if (l[i]) del[l[i] - 1].push_back(i);     }     for (long long i = 0; i < n; ++i) {       add_(link[i] + 1);       for (long long e : add[i]) {         ans[e] -= getmax(l[e]);       }       for (long long e : del[i]) {         ans[e] += getmax(l[e]);       }     }   }   void solve() {     for (long long i = 0; i < n; ++i) {       pref[i + 1] = pref[i] + i;     }     for (long long i = 0; i < q; ++i) {       ans[i] = r[i] - l[i] + 1;     }     kek();     reverse(a, a + n);     for (long long i = 0; i < q; ++i) {       l[i] = n - 1 - l[i];       r[i] = n - 1 - r[i];       swap(l[i], r[i]);     }     kek();   }   void print() {     for (long long i = 0; i < q; ++i) cout << ans[i] <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     read();     solve();     print();   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   inline t read(t &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0) {       putchar( - ), write(-x);     } else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int N = 1e5 + 5;   int n, x[N], y[N], px, py;   signed main() {     read(n);     if (n & 1) {       puts( NO );       return 0;     }     for (int i = 1; i <= n; i++) read(x[i]), read(y[i]);     px = x[1] + x[n / 2 + 1];     py = y[1] + y[n / 2 + 1];     for (int i = 1, j = n / 2 + 1; j <= n; i++, j++)       if (x[i] + x[j] != px || y[i] + y[j] != py) {         puts( NO );         return 0;       }     puts( YES );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, s;     scanf( %d%d%d , &a, &b, &s);     int req = abs(a) + abs(b);     if (req > s) {       printf( No n );     } else {       int cur = s - req;       if (cur & 1) {         printf( No n );       } else {         printf( Yes n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};   int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};   int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};   long long poww(long long a, long long b) {     if (b == 0) return 1;     long long x = poww(a, b / 2);     x = x * x;     if (b % 2 == 1) x = x * a;     return x;   }   long long bigmod(long long a, long long b, long long c) {     if (b == 0) return 1 % c;     long long x = bigmod(a, b / 2, c);     x = x * x % c;     if (b % 2 == 1) x = x * a % c;     return x;   }   long long mod_inverse(long long a, long long mod) {     return bigmod(a, mod - 2, mod);   }   int a[100005 * 3], sp[20][100005 * 3], lg[100005 * 3], n;   int spp[20][100005 * 3];   void logcal() {     int cnt = 0;     int p = 2;     while (p <= 300000) {       lg[p] = 1;       p *= 2;     }     for (int i = 0; i <= 300000; i++) {       if (lg[i]) {         cnt++;       }       lg[i] = cnt;     }   }   long long query1(int l, int r) {     int ln = lg[r - l + 1];     int k = 1 << ln;     int df = r - l + 1 - k;     return (min(sp[ln][l], sp[ln][l + df]));   }   long long query2(int l, int r) {     int ln = lg[r - l + 1];     int k = 1 << ln;     int df = r - l + 1 - k;     return (max(spp[ln][l], spp[ln][l + df]));   }   long long dp[100005 * 3];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     logcal();     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       sp[0][i] = a[i];       spp[0][i] = a[i];     }     for (int i = 1; 1 << i <= n; i++) {       for (int j = 1; j + (1 << i) <= n + 1; j++) {         sp[i][j] = min(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);         spp[i][j] = max(spp[i - 1][j], spp[i - 1][j + (1 << (i - 1))]);       }     }     for (int i = 1; i <= n; i++) dp[i] = 2134567891;     int N = n;     for (int i = 1; i <= N; i++) {       dp[i] = min(dp[i - 1] + 1, dp[i]);       int lw = 1, hi = i - 1, ans = 0, mid;       while (lw <= hi) {         int mid = (lw + hi) / 2;         int mx = query2(mid, i - 1);         if (mx >= a[i]) {           lw = mid + 1;           ans = mid;         } else {           hi = mid - 1;         }       }       if (ans > 0) {         dp[i] = min(dp[ans] + 1, dp[i]);       }       lw = i + 1, hi = n, ans = 0, mid;       while (lw <= hi) {         int mid = (lw + hi) / 2;         int mx = query2(i + 1, mid);         if (mx >= a[i]) {           ans = mid;           hi = mid - 1;         } else {           lw = mid + 1;         }       }       if (ans <= n && ans > 0) {         dp[ans] = min(dp[ans], dp[i] + 1);       }       lw = 1, hi = i - 1, ans = 0, mid;       while (lw <= hi) {         int mid = (lw + hi) / 2;         int mn = query1(mid, i - 1);         if (mn > a[i]) {           hi = mid - 1;         } else {           lw = mid + 1;           ans = mid;         }       }       if (ans > 0) {         dp[i] = min(dp[ans] + 1, dp[i]);       }       lw = i + 1, hi = n, ans = 0, mid;       while (lw <= hi) {         int mid = (lw + hi) / 2;         int mn = query1(i + 1, mid);         if (mn > a[i]) {           lw = mid + 1;         } else {           hi = mid - 1;           ans = mid;         }       }       if (ans <= n && ans > 0) {         dp[ans] = min(dp[ans], dp[i] + 1);       }     }     cout << dp[n] - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;     int num;   };   node point[303];   char str[5][105];   int t, n, k;   int flag = 0;   int Flag[5][105];   queue<node> Q;   void bfs() {     while (!Q.empty()) {       node D = Q.front(), R;       Q.pop();       if (D.x >= n) {         flag = 1;       }       if (D.num == 1 && str[D.y][D.x + 1] ==  . ) {         for (int j = D.y - 1; j <= D.y + 1; j++) {           if (str[j][D.x + 1] ==  .  && Flag[j][D.x + 1] == 0) {             R.num = 2;             R.x = D.x + 1;             R.y = j;             Q.push(R);             Flag[j][D.x + 1] = 1;           }         }       } else if (D.num == 2 && str[D.y][D.x + 1] ==  .  &&                  str[D.y][D.x + 2] ==  . ) {         R.num = 1;         R.x = D.x + 2;         R.y = D.y;         Q.push(R);       }     }   }   int main() {     int u, v;     scanf( %d , &t);     while (t--) {       memset(Flag, 0, sizeof(Flag));       flag = 0;       scanf( %d%d , &n, &k);       for (int j = 1; j <= 3; j++) scanf( %s , str[j] + 1);       for (int i = 1; i <= 3; i++) {         if (str[i][1] ==  s ) u = i;       }       for (int i = 1; i <= n + 1; i++) {         str[0][i] =  A ;         str[4][i] =  A ;       }       for (int i = 0; i <= 4; i++) str[i][n + 1] =  . ;       node W;       W.x = 1;       W.y = u;       W.num = 1;       Q.push(W);       bfs();       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (0); i < (b); i++) {       multiply *= a;     }     return multiply;   }   int n, q, type, l, r, k, a[100002], blockSZ;   vector<int> v[318];   int sz, cnt[100002][318];   void Shift(int to, int from) {     int b1 = -1, b2 = -1;     int s = 0, idx1, idx2;     if (to == from) return;     for (int i = (0); i < (sz + 1); i++) {       if (b1 == -1 && s + (int)v[i].size() > from) {         b1 = from - s;         idx1 = i;       }       if (b2 == -1 && s + (int)v[i].size() > to) {         b2 = to - s;         idx2 = i;       }       s += v[i].size();     }     int val = v[idx1][b1];     v[idx1].erase(v[idx1].begin() + b1);     v[idx2].insert(v[idx2].begin() + b2, val);     cnt[val][idx1]--;     cnt[val][idx2]++;   }   int Query(int from, int to, int x) {     int s = 0, idx1 = -1, idx2 = -1, b1 = -1, b2 = -1;     for (int i = (0); i < (sz + 1); i++) {       if (idx1 == -1 && s + (int)v[i].size() > from) {         idx1 = i;         b1 = from - s;       }       if (idx2 == -1 && s + (int)v[i].size() > to) {         idx2 = i;         b2 = to - s;       }       s += v[i].size();     }     int ret = 0;     for (int i = (idx1 + 1); i < (idx2); i++) {       ret += cnt[x][i];     }     if (idx1 != idx2) {       for (int i = (b1); i < (v[idx1].size()); i++) {         if (v[idx1][i] == x) ret++;       }       for (int i = (0); i < (b2 + 1); i++) {         if (v[idx2][i] == x) ret++;       }     } else {       for (int i = (b1); i < (b2 + 1); i++) {         if (v[idx1][i] == x) ret++;       }     }     return ret;   }   void Rebuild() {     vector<int> temp;     for (int i = (0); i < (sz + 1); i++) {       for (int j = (0); j < (v[i].size()); j++) {         temp.push_back(v[i][j]);         cnt[v[i][j]][i]--;       }       v[i].clear();     }     sz = 0;     for (int i = (0); i < (n); i++) {       v[sz].push_back(temp[i]);       cnt[temp[i]][sz]++;       if (i + 1 < n && (i + 1) % blockSZ == 0) sz++;     }   }   void Print() {     cout <<  All numbers:  ;     for (int i = (0); i < (sz + 1); i++) {       for (int j = (0); j < (v[i].size()); j++) cout << v[i][j] <<    ;     }     cout <<   n ;     cout <<  All vectors:            <<   n ;     for (int i = (0); i < (sz + 1); i++) {       for (int J = (0); J < (v[i].size()); J++) cout << v[i][J] <<    ;       cout <<   n ;     }   }   int main() {     int test, cases = 1;     scanf( %d , &n);     blockSZ = 700;     for (int i = (0); i < (n); i++) {       scanf( %d , &a[i]);     }     for (int i = (0); i < (n); i++) {       v[sz].push_back(a[i]);       cnt[a[i]][sz]++;       if (i + 1 < n && (i + 1) % blockSZ == 0) sz++;     }     scanf( %d , &q);     int last = 0, shift = 0;     while (q--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d%d , &l, &r);         l = ((l + last - 1) % n) + 1;         r = ((r + last - 1) % n) + 1;         l--, r--;         if (l > r) swap(l, r);         Shift(l, r);         shift++;       } else {         scanf( %d%d%d , &l, &r, &k);         l = ((l + last - 1) % n) + 1;         r = ((r + last - 1) % n) + 1;         k = ((k + last - 1) % n) + 1;         l--, r--;         if (l > r) swap(l, r);         last = Query(l, r, k);         printf( %d n , last);       }       if (shift == 1200) {         Rebuild();         shift = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 32768 - 1;   int ans[100500];   bool use[100500];   int res;   string s =   ;   int eval_num(int n, int &i);   int eval_product(int n, int &i);   int eval_sum(int n, int &i);   bool eval_logick(int n, int &i);   int eval_op(int n, int &i);   int eval_opseq(int n, int &i);   int eval_func(int n, int &i);   int run(int n);   const string dels =     n ;   const string ops =  (){}+-*/;<> ;   bool has(string t, char c) {     for (int i = 0; i < t.length(); ++i)       if (t[i] == c) return true;     return false;   }   string getlex(int &i) {     string t =   ;     while (has(dels, s[i])) ++i;     if (has(ops, s[i])) {       t += s[i++];       return t;     }     if (s[i] ==  =  && s[i + 1] ==  = ) {       t +=  == ;       i += 2;       return t;     }     while (!((has(dels, s[i]) || has(ops, s[i]) || s[i] ==  = ))) t += s[i++];     return t;   }   int norm(int x) {     while (x < 0) x += MAXN + 1;     return x % (MAXN + 1);   }   int eval_num(int n, int &i) {     string sw = getlex(i);     if (sw ==  n ) return n;     if (sw ==  f ) {       getlex(i);       int t = eval_sum(n, i);       getlex(i);       return run(t);     }     return atoi(sw.c_str());   }   int eval_product(int n, int &i) {     int sum = eval_num(n, i);     int j = i;     string op = getlex(j);     while (op ==  *  || op ==  / ) {       int t = eval_num(n, j);       i = j;       if (op ==  * )         sum *= t;       else         sum /= t;       sum = norm(sum);       op = getlex(j);     }     return sum;   }   int eval_sum(int n, int &i) {     int sum = eval_product(n, i);     int j = i;     string op = getlex(j);     while (op ==  +  || op ==  - ) {       int t = eval_product(n, j);       i = j;       if (op ==  + )         sum += t;       else         sum -= t;       sum = norm(sum);       op = getlex(j);     }     return sum;   }   bool eval_logick(int n, int &i) {     int e1 = eval_sum(n, i);     string op = getlex(i);     int e2 = eval_sum(n, i);     if (op ==  > ) return (e1 > e2);     if (op ==  < ) return (e1 < e2);     if (op ==  == ) return (e1 == e2);     exit(0);     return false;   }   int eval_op(int n, int &i) {     string sw = getlex(i);     if (sw ==  if ) {       string t = getlex(i);       if (t !=  ( ) exit(0);       bool b = eval_logick(n, i);       t = getlex(i);       if (b) {         getlex(i);       } else {         while (s[i] !=  ; ) ++i;         ++i;         return -1;       }     }     int ret = eval_sum(n, i);     getlex(i);     return ret;   }   int eval_func(int n, int &i) {     while (s[i] !=  { ) ++i;     ++i;     int ret = -1;     while (ret < 0) {       ret = eval_op(n, i);     }     return ret;   }   int run(int n) {     int j = 0;     if (use[n]) return ans[n];     use[n] = true;     ans[n] = eval_func(n, j);     return ans[n];   }   int main() {     cin >> res;     string t;     while (!feof(stdin)) {       getline(cin, t);       s += t +    ;     }     s +=    ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;     for (int i = 0; i <= MAXN; ++i) run(i);     int mx = -1;     for (int i = 0; i <= MAXN; ++i)       if (ans[i] == res) mx = i;     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int mod = 1000 * 1000 * 1000 + 7;   const long long inf = 1e18;   void rd(int &x) { scanf( %d , &x); }   void rd(long long &x) { scanf( %lld , &x); }   void rd(double &x) { scanf( %lf , &x); }   void rd(int &x, int &y) { scanf( %d%d , &x, &y); }   void rd(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void rd(int &x, int &y, int &z) { scanf( %d%d%d , &x, &y, &z); }   void rd(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void rd(double &x, double &y) { scanf( %lf%lf , &x, &y); }   void rd(double &x, double &y, double &z) { scanf( %lf%lf%lf , &x, &y, &z); }   void rd(char *s) { scanf( %s , s); }   void rd(char &s) { scanf( %c , &s); }   void rd(string &s) { getline(cin, s); }   void pf(int x) { printf( %d n , x); }   void pf(int x, int y) { printf( %d %d n , x, y); }   void pf(long long x) { printf( %lld n , x); }   void pf(char x) { printf( %c n , x); }   void pf(char *x) { printf( %s n , x); }   void pf(string x) { cout << x << endl; }   int main() {     int n, m, k, x = 0, y = 0, f = 1, p, q, ans = 0;     cin >> n >> m >> k;     if (k == 1) {       cout << m * n <<    ;       for (int i = 1; i <= (n); i++)         for (int j = 1; j <= (m); j++) {           if (i % 2 == 1) {             cout << i <<     << j <<    ;           } else {             cout << i <<     << m - j + 1 <<    ;           }         }       return 0;     }     cout <<  2  ;     for (int i = 1; i <= (n); i++)       for (int j = 1; j <= (m); j++) {         if (i % 2 == 1) {           cout << i <<     << j <<    ;           x++;           ans++;         } else {           cout << i <<     << m - j + 1 <<    ;           x++;           ans++;         }         if (x == 2 && f) {           x = 0;           y++;           if (y != k - 1) cout <<   n2  ;         }         if (y == k - 1 && f != 0) {           f = 0;           cout <<   n  << m * n - ans <<    ;         }       }   }


#include <bits/stdc++.h>   using namespace std;   const int __ = 1000000;   bool pri[__ + 5];   int num[__ + 5];   void era() {     int x = (int)sqrt(__ + 0.01);     for (int i = 2; i <= x; i++)       if (!pri[i]) {         num[++num[0]] = i;         for (int j = i * i; j <= __; j += i) pri[j] = true;       }     for (int i = x + 1; i <= __; i++)       if (!pri[i]) num[++num[0]] = i;   }   int main() {     era();     int n;     scanf( %d , &n);     int m = n, maxx = 0;     for (int i = 2; i * i <= m; i++)       if (m % i == 0)         for (maxx = i; m % i == 0; m /= i)           ;     if (m != 1) maxx = m;     int x1 = n - maxx + 1, ans = INT_MAX;     for (int i = (1); i <= (num[0]); i++) {       int p = num[i];       int x0 = (x1 + p - 1) / p * p - (p - 1);       int x = (x0 + p - 1) / p * p;       if (x0 > p && x0 >= 3 && x <= n) ans = min(ans, x0);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     while (cin >> s1) {       string s2 =   ;       for (int i = 0; i < s1.size(); i++) {         if (s1[i] !=  + ) s2 += s1[i];       }       sort(s2.begin(), s2.end());       for (int i = 0; i < s2.size(); i++) {         if (i) cout <<  + ;         cout << s2[i];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ara[200005];   long long aray[200005];   int main() {     long long a, b, c, d, t, i, j, k, n, m;     cin >> t;     while (t--) {       long long ans = 0;       cin >> n >> m >> k;       a = n / k;       if (m > a) {         m -= a;         if (m % (k - 1) == 0) {           ans = a - ((m / (k - 1)));         } else {           ans = a - ((m / (k - 1))) - 1;         }       } else {         ans = m;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum = 0, n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       sum += (n - i) * (i - 1) + i;     }     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   const double error = 1e-7;   double v, r;   bool puede(double t, double dist) {     dist -= v * t;     if (dist <= 0) return true;     double tvuelta = r * 2 * M_PI / v;     t -= int(t / tvuelta) * tvuelta;     double a = t * v / r;     return dist <= 2 * r * sin(a / 2.0);   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     int n;     cin >> n >> r >> v;     for (int cas = 0; cas < n; cas++) {       int s, f;       cin >> s >> f;       double inf = 0;       double sup = 2000000000;       double d = f - s;       while (inf + error < sup) {         double med = (inf + sup) / 2.0;         if (puede(med, d))           sup = med;         else           inf = med;       }       cout << inf << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, v1, v2, k;   int main() {     cin >> n >> l >> v1 >> v2 >> k;     long long g = (n + k - 1) / k;     double le = 0, ri = l / (double)v1;     while ((ri - le) >= 5e-7) {       double mid = (le + ri) / 2;       double t = 0;       for (int i = 1; i <= g; i++) {         double x = ((double)l - v1 * mid) / (v2 - v1);         t += x;         if (i != g) {           double y = x * (v2 - v1) / (v1 + v2);           t += y;         }       }       if (mid > t)         ri = mid;       else         le = mid;     }     cout << setprecision(9) << le << endl;     return 0;   }


#include <bits/stdc++.h>      using namespace std;      #define ll long long   typedef pair<ll, ll> pll;   typedef pair<ll, int> pli;   typedef pair<int, ll> pil;   typedef pair<int, int> pii;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<bool> vb;   typedef vector<vb> vvb;   typedef vector<char> vc;   typedef vector<vc> vvc;   typedef vector<string> vs;   typedef vector<vs> vvs;   typedef vector<ll> vll;   typedef vector<vll> vvll;   typedef vector<pii> vpii;   typedef vector<vpii> vvpii;   typedef vector<pll> vpll;   typedef vector<vpll> vvpll;   typedef set<int> si;   typedef set<vi> svi;   typedef set<ll> sll;   typedef set<vll> svll;   typedef set<pii> spii;   typedef set<vpii> svpii;   typedef set<pll> spll;   typedef set<vpll> svpll;   typedef vector<si> vsi;   typedef vector<sll> vsll;   typedef vector<spii> vspii;   typedef vector<spll> vspll;   #define ft first   #define sc second   #define pb push_back   #define ins insert   #define io                                ios_base::sync_with_stdio(false);     cin.tie(NULL);                        cout.tie(NULL)   #define all(v) v.begin(), v.end()   #define Sort(v) sort(all(v))   #define sortarr(a, n) sort(a, a + n)   #define tt         ll tc;         cin >> tc;     while (tc--)   #define rep(var, start, end, interval) for (ll var = start; (interval > 0 and var < end) or (interval < 0 and var > end); var += interval)   #define each(x, v) for (auto x : v)   #define takearr0(a, n) rep(z, 0, n, 1) cin >> a[z];   #define takearr1(a, n) rep(z, 1, n + 1, 1) cin >> a[z];      const ll max_n = 2e3 + 5;   const ll inf = 1e16;      ll n, m, w;   vvll a;      vpll neighbours(pll p)   {    vpll vec;    if (p.ft > 0 and a[p.ft - 1][p.sc] >= 0)     vec.pb({p.ft - 1, p.sc});    if (p.ft < n - 1 and a[p.ft + 1][p.sc] >= 0)     vec.pb({p.ft + 1, p.sc});    if (p.sc > 0 and a[p.ft][p.sc - 1] >= 0)     vec.pb({p.ft, p.sc - 1});    if (p.sc < m - 1 and a[p.ft][p.sc + 1] >= 0)     vec.pb({p.ft, p.sc + 1});    return vec;   }      int main()   {    io;    cin >> n >> m >> w;    a.resize(n);    a.assign(n, vll(m));    rep(i, 0, n, 1) takearr0(a[i], m);    // each(vec, a)    // {    //  each(x, vec) cout << setw(18) << x <<    ;    //  cout << endl;    // }    // cout << endl;    vvb v(n, vb(m, false));    vvll dists(n, vll(m, inf));    queue<pll> q;    q.push({0, 0});    v[0][0] = true;    dists[0][0] = 0;    while (!q.empty())    {     pll p = q.front();     q.pop();     vpll nb = neighbours(p);     each(pr, nb) if (!v[pr.ft][pr.sc])     {      dists[pr.ft][pr.sc] = dists[p.ft][p.sc] + w;      v[pr.ft][pr.sc] = true;      q.push(pr);     }    }    rep(i, 0, n, 1) rep(j, 0, m, 1) v[i][j] = false;    vvll distt(n, vll(m, inf));    q.push({n - 1, m - 1});    v[n - 1][m - 1] = true;    distt[n - 1][m - 1] = 0;    while (!q.empty())    {     pll p = q.front();     q.pop();     vpll nb = neighbours(p);     each(pr, nb) if (!v[pr.ft][pr.sc])     {      distt[pr.ft][pr.sc] = distt[p.ft][p.sc] + w;      v[pr.ft][pr.sc] = true;      q.push(pr);     }    }    ll pors = inf, port = inf;    rep(i, 0, n, 1) rep(j, 0, m, 1) if (a[i][j] > 0)    {     pors = min(pors, dists[i][j] + a[i][j]);     port = min(port, distt[i][j] + a[i][j]);    }    ll ans = min(dists[n - 1][m - 1], pors + port);    if (ans >= inf)     cout << -1 << endl;    else     cout << ans << endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, o;       string s;       cin >> n >> s;       o = s[n - 1] -  0 ;       for (int i = 0; i < n - 1; i++) o += (s[i] ==  0  ? 0 : s[i] - 47);       cout << o << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 9999999999999999;   int t, n;   vector<long long> ans;   vector<long long> graphSize;   vector<long long> aToFirst, aToLast, bToFirst, bToLast;   void countLength(vector<long long> &toFirst, vector<long long> &toLast,                    long long v, int n) {     if (n == 0) {       toFirst[0] = 0;       toLast[0] = 0;       return;     }     if (n == 1) {       toFirst[1] = v == 2;       toLast[1] = v == 1;       return;     }     if (v <= graphSize[n - 1]) {       countLength(toFirst, toLast, v, n - 1);       toFirst[n] = min(toFirst[n - 1], toLast[n - 1] + 2);       toLast[n] = min(toFirst[n - 1], toLast[n - 1]) + (n - 1) / 2 + 1;     } else {       countLength(toFirst, toLast, v - graphSize[n - 1], n - 2);       toFirst[n] = toFirst[n - 2] + 1;       toLast[n] = toLast[n - 2];     }   }   long long findMinLength(long long a, long long b, int n) {     if (a == b) return 0;     if (n <= 2) return 1;     if (a <= graphSize[n - 1]) {       if (b >= graphSize[n - 1] + 1) {         return min(aToFirst[n - 1], aToLast[n - 1]) + bToFirst[n - 2] + 1;       } else {         long long d1 = min(aToFirst[n - 1] + bToLast[n - 1] + 2,                            aToLast[n - 1] + bToFirst[n - 1] + 2);         return min(d1, findMinLength(a, b, n - 1));       }     } else {       return findMinLength(a - graphSize[n - 1], b - graphSize[n - 1], n - 2);     }   }   int main() {     cin >> t >> n;     graphSize.push_back(1);     graphSize.push_back(2);     int iMax = 2;     for (; graphSize.back() < MAX; ++iMax) {       graphSize.push_back(graphSize[iMax - 1] + graphSize[iMax - 2]);     }     for (int i = 1; i <= t; ++i) {       long long a, b;       cin >> a >> b;       if (a > b) swap(a, b);       aToFirst.resize(min(n, iMax) + 1);       aToLast.resize(min(n, iMax) + 1);       bToFirst.resize(min(n, iMax) + 1);       bToLast.resize(min(n, iMax) + 1);       countLength(aToFirst, aToLast, a, min(n, iMax));       countLength(bToFirst, bToLast, b, min(n, iMax));       ans.push_back(findMinLength(a, b, min(n, iMax)));     }     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Reduced_Indexs {     vector<int> idxs;     int n;       public:     Reduced_Indexs() = default;     template <typename InputIterator>     Reduced_Indexs(InputIterator first, InputIterator last) {       idxs = vector<int>(first, last);       sort(idxs.begin(), idxs.end());       n = unique(idxs.begin(), idxs.end()) - idxs.begin();       idxs.resize(n);     }     int size();     int get_idx(int);     int get_value(int);   };   int Reduced_Indexs::size() { return n; }   int Reduced_Indexs::get_idx(int x) {     auto p = lower_bound(idxs.begin(), idxs.end(), x);     return (p != idxs.end() && *p == x) ? (p - idxs.begin()) : -1;   }   int Reduced_Indexs::get_value(int i) { return idxs[i]; }   const int N = 100000;   const long long MOD = 1000000007LL;   long long pow2[N + 2];   int xs[N], ys[N];   Reduced_Indexs xidxs, yidxs;   vector<int> xeq[N], yeq[N];   bool checked[N];   set<int> xused, yused;   int cnt;   void check(int);   int main() {     pow2[0] = 1LL;     for (int i = 1; i <= N + 1; ++i) {       pow2[i] = (pow2[i - 1] * 2) % MOD;     }     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &xs[i], &ys[i]);     }     xidxs = Reduced_Indexs(xs, xs + n);     yidxs = Reduced_Indexs(ys, ys + n);     for (int i = 0; i < n; ++i) {       xeq[xidxs.get_idx(xs[i])].push_back(i);       yeq[yidxs.get_idx(ys[i])].push_back(i);     }     long long ans = 1LL;     for (int i = 0; i < n; ++i) {       xused.clear();       yused.clear();       cnt = 0;       check(i);       int total = xused.size() + yused.size();       ans = (ans * (pow2[total] - (cnt < total))) % MOD;     }     printf( %lld n , ans);     exit(EXIT_SUCCESS);   }   void check(int u) {     if (checked[u]) {       return;     }     checked[u] = true;     ++cnt;     int x = xs[u], y = ys[u];     if (!xused.count(x)) {       xused.insert(x);       for (int v : xeq[xidxs.get_idx(x)]) {         check(v);       }     }     if (!yused.count(y)) {       yused.insert(y);       for (int v : yeq[yidxs.get_idx(y)]) {         check(v);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, ar[3100], cur;   vector<int> v;   bool valid, used[10000];   pair<int, string> tab[3100];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tab[i].second >> tab[i].first;     }     sort(tab, tab + n);     valid = true;     for (int i = 0; i < n; i++) {       if (tab[i].first > i) valid = false;     }     if (valid) {       cur = tab[0].first;       for (int i = 0; i < n; i++) {         ar[i] = 10;         if (tab[i].first > cur) {           for (int j = 0; j < v.size(); j++) {             ar[v[j]]++;           }           int bil = tab[i].first - cur;           int j = i;           while (bil > 0) {             j--;             if (used[j]) continue;             used[j] = true;             v.push_back(j);             bil--;           }           cur = tab[i].first;         }       }       for (int j = 0; j < v.size(); j++) {         ar[v[j]]++;       }       for (int i = 0; i < n; i++) {         cout << tab[i].second <<     << ar[i] << endl;       }     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[500010], n, ans = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int x = 1;     while (x < n) {       while ((x < n) && (a[x] == a[x + 1])) x++;       int y = x;       while ((x < n) && (a[x] != a[x + 1])) x++;       if (x - y >= 2) {         if (a[y] == a[x]) {           for (int i = y; i <= x; i++) a[i] = a[y];           ans = max(ans, (x - y) / 2);         } else {           for (int i = y; i <= (x + y) / 2; i++) a[i] = a[y];           for (int i = ((x + y) / 2) + 1; i <= x; i++) a[i] = a[x];           ans = max(ans, (x - y) / 2);         }       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   void readInput() {}   void solve() {}   priority_queue<pair<int, int>> pq;   int n, x, y, res, a[100004], b[100004], T, cnt, vitri[100004];   vector<int> pos[100004], ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     readInput();     solve();     cin >> T;     while (T--) {       cin >> n >> x >> y;       for (int i = 1; i <= n + 1; i++) {         pos[i].clear();         b[i] = 0;         vitri[i] = 0;       }       ans.clear();       while (!pq.empty()) pq.pop();       for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]].push_back(i);       cnt = 1;       for (int i = 1; i <= n + 1; i++) {         pq.push({pos[i].size(), i});         if (pos[i].size() == 0) res = i;       }       while (cnt <= x) {         pair<int, int> u = pq.top();         pq.pop();         b[pos[u.second].back()] = u.second;         vitri[pos[u.second].back()] = 1;         pos[u.second].pop_back();         cnt++;         pq.push({pos[u.second].size(), u.second});       }       pair<int, int> u = pq.top();       if (2 * u.first > n - x + n - y) {         cout <<  NO  <<   n ;         continue;       } else {         cout <<  YES  <<   n ;         for (int i = 1; i <= n + 1; i++) {           for (auto v : pos[i]) ans.push_back(v);         }         cnt = 1;         for (int i = 0; i < ans.size(); i++) {           b[ans[i]] = a[ans[(i + ans.size() / 2) % (ans.size())]];         }         cnt = 1;         for (int i = 1; i <= n; i++) {           if (vitri[i] == 0 && b[i] == a[i]) {             vitri[i] = 1;             cnt++;             b[i] = res;           }         }         for (int i = 1; i <= n; i++) {           if (vitri[i] == 0 && cnt <= n - y) b[i] = res, cnt++;         }         for (int i = 1; i <= n; i++) cout << b[i] <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXLEN = 200;   char s[MAXLEN + 1];   int n;   void run() {     scanf( %d%s , &n, s);     n = strlen(s);     int ret = 0;     for (int at = 0, to = at; at < n; at = to) {       if (isupper(s[to])) {         ++to;         continue;       }       while (to < n && islower(s[to])) ++to;       int mask = 0, cnt = 0;       for (int i = (at); i < (to); ++i) {         int x = s[i] -  a ;         if (((mask >> x) & 1) == 0) mask |= 1 << x, ++cnt;       }       ret = max(ret, cnt);     }     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, c, l, r, i, j, x1, x2, x3, x, r_y, r_y1, r_y2, r_y3, k, g, sum,       maxy, maxx, qy, qx;   long long kk;   long long fact(long long a) {     unsigned long long k = 1, i;     for (i = 1; i <= a; i++) k *= i;     return k;   }   int main() {     cin >> x1 >> r_y1 >> x2 >> r_y2;     x = x2 - x1;     r_y = r_y2 - r_y1;     maxy = (2 + r_y) / 2;     qy = (2 + r_y) % 2;     maxx = x + 1;     qx = maxx % 2;     if (qy == 1)       cout << maxx * maxy;     else {       cout << (maxx / 2 + qx) * maxy + (maxx / 2) * (maxy - 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int cor[n], wro[m];     for (int i = 0; i < n; i++) cin >> cor[i];     for (int i = 0; i < m; i++) cin >> wro[i];     int tl;     sort(cor, cor + n);     sort(wro, wro + m);     int v = max(2 * cor[0], cor[n - 1]);     if (v < wro[0])       cout << v;     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   const int maxm = 500000 + 10;   struct Edge {     int next, v;     Edge() {}     Edge(int next, int v) : next(next), v(v) {}   } e[maxm << 1];   int n, m, timer, num, len;   int head[maxm], cnt;   int dfn[maxn], low[maxn], belo[maxn];   bool inst[maxn], used[maxn];   int st[maxm], top, q[maxm], front, tail;   char org[27], s[maxn], ans[maxn], res[maxn];   int val[128];   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   inline void AddEdge(int u, int v) {     e[++cnt] = Edge(head[u], v);     head[u] = cnt;   }   void tarjan(int u) {     dfn[u] = low[u] = ++timer;     st[++top] = u;     inst[u] = 1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].v;       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (inst[v])         low[u] = min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       num++;       int v;       do {         v = st[top--];         belo[v] = num;         inst[v] = 0;       } while (u != v);     }   }   inline bool judge(int tot) {     for (int i = 2; i <= tot; i++)       if (!dfn[i]) tarjan(i);     for (int i = 2; i < tot; i += 2)       if (belo[i] == belo[i + 1]) return 0;     return 1;   }   inline char find(int pos, char ch) {     for (int i = pos + 1; i < len; i++)       if (org[i] == ch) return  a  + i;     return -1;   }   int main() {     scanf( %s , org);     len = strlen(org);     for (int i = 0; i < len; i++)       if (org[i] ==  C ) val[ a  + i] = 1;     n = read(), m = read();     char op1[10], op2[10];     int x, y;     while (m--) {       x = read(), scanf( %s , op1);       y = read(), scanf( %s , op2);       x = x << 1 | (op1[0] ==  C );       y = y << 1 | (op2[0] ==  C );       AddEdge(x, y);       AddEdge(y ^ 1, x ^ 1);     }     scanf( %s , s + 1);     if (!judge(n << 1 | 1)) {       puts( -1 );       return 0;     }     bool exis = 0;     res[1] = -1;     for (int pos = n + 1; pos >= 1; pos--) {       for (int a = pos << 1; a <= (pos << 1 | 1); a++) {         strcpy(ans + 1, s + 1);         if (pos <= n) {           char tp = find(s[pos] -  a , a & 1 ?  V  :  C );           if (tp == -1) continue;           ans[pos] = tp;         }         for (int i = pos + 1; i <= n; i++) ans[i] =  a ;         bool flag = 1;         memset(used, 0, sizeof(used));         for (int i = 1; i <= n && flag; i++) {           x = i << 1 | val[ans[i]];           if (used[x]) continue;           used[x] = 1;           front = tail = 0;           q[++tail] = x;           while (front != tail) {             x = q[++front];             used[x] = 1;             if (used[x ^ 1]) {               flag = 0;               break;             }             if ((x >> 1) <= pos && val[ans[x >> 1]] != (x & 1)) {               flag = 0;               break;             }             if ((x >> 1) > pos) {               char tp = find(-1, x & 1 ?  C  :  V );               if (tp == -1) {                 flag = 0;                 break;               }               ans[x >> 1] = tp;             }             for (int j = head[x]; j; j = e[j].next) {               int v = e[j].v;               if (!used[v]) q[++tail] = v;             }           }         }         if (!flag) continue;         exis = 1;         if (res[1] == -1)           strcpy(res + 1, ans + 1);         else if (strcmp(res + 1, ans + 1) > 0)           strcpy(res + 1, ans + 1);       }       if (exis) break;     }     if (exis)       puts(res + 1);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 3009;   long long x[MX], par[MX], num[MX], ans = 0;   pair<long long, pair<long long, long long> > edg[MX];   void MS(long long v) {     par[v] = -1;     num[v] = x[v];   }   long long FS(long long v) {     if (par[v] < 0) return v;     return par[v] = FS(par[v]);   }   void US(long long a, long long b) {     a = FS(a), b = FS(b);     if (a == b) return;     if (par[a] > par[b]) swap(a, b);     par[a] += par[b];     par[b] = a;     num[a] += num[b];   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long u, v, w;       cin >> u >> v >> w;       edg[i] = {w, {u, v}};     }     for (long long i = 1; i <= n; i++) cin >> x[i];     for (long long i = 1; i <= n; i++) MS(i);     sort(edg, edg + n - 1);     for (long long i = 0; i < n - 1; i++) {       long long u = edg[i].second.first, v = edg[i].second.second,                 w = edg[i].first;       long long maxx = 0, sum = 0, res = 1;       for (long long j = 1; j <= n; j++) {         if (par[j] < 0) {           maxx = max(maxx, -par[j]);           sum += num[j];         }       }       for (long long j = 1; j <= n; j++) {         if (par[j] < 0) {           if (sum - num[j] < -par[j]) res = 0;         }       }       if (res) ans = w;       US(u, v);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   unordered_map<int, int> dp;   int msb(int x) { return __builtin_clz(1) - __builtin_clz(x); }   int solve(int mask) {     if (mask <= 1) return 0;     if (dp.count(mask)) return dp[mask];     int maxi = msb(mask);     vector<int> mex;     for (int i = 1; i <= maxi; i++) {       int at = mask;       for (int j = i; j <= maxi; j++)         if (mask & (1 << j)) {           at ^= (1 << j);           if (i != j) at |= (1 << (j - i));         }       mex.push_back(solve(at));     }     sort(mex.begin(), mex.end());     vector<int>::iterator it = unique(mex.begin(), mex.end());     mex.resize(distance(mex.begin(), it));     int g = 0;     int i = 0;     for (auto k : mex) {       if (g == k)         g++;       else         break;     }     return dp[mask] = g;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, vector<int>> mp;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       for (int i = 2; i * i <= a; i++)         if (a % i == 0) {           int at = 0;           while (a % i == 0) a /= i, at++;           mp[i].push_back(at);         }       if (a != 1) mp[a].push_back(1);     }     int ans = 0;     for (auto x : mp) {       sort(x.second.begin(), x.second.end());       vector<int>::iterator it = unique(x.second.begin(), x.second.end());       x.second.resize(distance(x.second.begin(), it));       int at = 0;       for (int k : x.second) {         at += 1 << k;       }       ans ^= solve(at);     }     if (ans == 0)       cout <<  Arpa  << endl;     else       cout <<  Mojtaba  << endl;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[200001];   int cnt[200001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     bool flag;     int T;     cin >> T;     while (T--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < n; i++) {         cnt[i] = 0;       }       for (int i = 0; i < n; i++) {         arr[i] = (arr[i] + i + n * 2147483647) % n;         cnt[arr[i]]++;       }       flag = 1;       for (int i = 0; i < n; i++) {         if (cnt[i] != 1) {           flag = 0;         }       }       if (flag == 1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int pos, neg, tmp, x, y, len;   int main() {     scanf( %d%d , &n, &m);     pos = 0;     neg = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &tmp);       if (tmp > 0)         ++pos;       else         ++neg;     }     while (m--) {       scanf( %d%d , &x, &y);       len = y - x + 1;       if (len & 1)         printf( 0 n );       else {         if (len / 2 <= min(pos, neg))           printf( 1 n );         else           printf( 0 n );       }     }     return 0;   }