#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double num4, double b) { return fabs(num4 - b) < 1e-9; }   const int INF = 1 << 29;   inline int two(int len) { return 1 << len; }   inline int test(int len, int b) { return (len >> b) & 1; }   inline void set_bit(int &len, int b) { len |= two(b); }   inline void unset_bit(int &len, int b) { len &= ~two(b); }   inline int last_bit(int len) { return len & (-len); }   inline int ones(int len) {     int res = 0;     while (len && ++res) len -= len & (-len);     return res;   }   template <class T>   void chmax(T &num4, const T &b) {     num4 = max(num4, b);   }   template <class T>   void chmin(T &num4, const T &b) {     num4 = min(num4, b);   }   inline void add(int &numx, int y) {     numx += y;     if (numx >= 1000000007) numx -= 1000000007;     if (numx < 0) numx += 1000000007;   }   inline int mul(int numx, int y) { return ((long long)numx * y) % 1000000007; }   int gcd(int num4, int b) {     if (b) return gcd(b, num4 % b);     return num4;   }   int power(int num4, int pex) {     int ret = 1;     while (pex) {       if (pex & 1) ret = mul(ret, num4);       num4 = mul(num4, num4);       pex /= 2;     }     return ret;   }   int phi(int len) {     int ret = len;     int idxx = 2;     if (len % idxx == 0) {       ret -= ret / idxx;       while (len % idxx == 0) len /= idxx;     }     for (idxx = 3; idxx * idxx <= len; idxx++)       if (len % idxx == 0) {         ret -= ret / idxx;         while (len % idxx == 0) len /= idxx;       }     if (len > 1) ret -= ret / len;     return ret;   }   using namespace std;   int main() {     bool flags = true;     int num1, num2;     cin >> num1 >> num2;     int vals1 = num1 - 1, v2s = 0, v3s = 0, v4s = num2 - 1, bbs = 0;     for (int i = 0; i < num1; ++i)       for (int j = 0; j < num2; ++j) {         char chh;         cin >> chh;         if (chh ==  B ) {           vals1 = min(vals1, i);           v2s = max(v2s, i);           v4s = min(v4s, j);           v3s = max(v3s, j);           flags = false;           ++bbs;         }       }     if (flags) {       cout << 1;       return 0;     }     int weights = v3s - v4s + 1, h = v2s - vals1 + 1;     if (weights > num1 || h > num2) {       cout << -1;       return 0;     }     int len = max(weights, h);     cout << len * len - bbs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long INF = 1LL << 62;   const long long MINF = -(1LL << 62);   template <typename T>   T getint() {     T val = 0;     char c;     bool neg = false;     while ((c = getchar()) && !(c >=  0  && c <=  9 )) {       neg |= c ==  - ;     }     do {       val = (val * 10) + c -  0 ;     } while ((c = getchar()) && (c >=  0  && c <=  9 ));     return val * (neg ? -1 : 1);   }   const long long mod = 1e9 + 7;   const long long MAXN = 300010;   struct fenwick {     long long arr[MAXN];     fenwick() { memset(arr, 0, sizeof arr); }     void incr(int x, int by) {       for (; x < MAXN; x += (x & (-x))) {         arr[x] = (arr[x] + by) % mod;       }     }     int sum(int x) {       long long sum = 0;       for (; x > 0; x -= (x & (-x))) {         sum = (sum + arr[x]) % mod;       }       return sum;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> c;     vector<pair<long long, long long>> lst(m);     for (int i = 0; i < m; ++i) cin >> lst[i].first >> lst[i].second;     for (int i = 0; i < m; ++i) {       c.push_back(lst[i].first);       c.push_back(lst[i].second);     }     c.push_back(0);     c.push_back(n);     sort((c).begin(), (c).end());     c.resize(distance(c.begin(), unique((c).begin(), (c).end())));     for (int i = 0; i < m; ++i) {       lst[i].first =           lower_bound((c).begin(), (c).end(), lst[i].first) - c.begin();       lst[i].second =           lower_bound((c).begin(), (c).end(), lst[i].second) - c.begin();     }     int st = 0;     st = lower_bound((c).begin(), (c).end(), st) - c.begin();     n = lower_bound((c).begin(), (c).end(), n) - c.begin();     fenwick f;     sort((lst).begin(), (lst).end(),          [&](pair<long long, long long>& egyik, pair<long long, long long>& masik)              -> bool { return egyik.second < masik.second; });     f.incr(st + 1, 1);     for (auto i : lst) {       long long ways = f.sum(i.second) - f.sum(i.first);       f.incr(i.second + 1, ways);     }     cout << (f.sum(n + 1) - f.sum(n) + mod) % mod <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cur[100005];   int mark[100005];   int sol[400005];   int csol;   int n, m;   vector<int> E[100005];   inline void dfs(int u, int up) {     mark[u] = 1;     csol++;     sol[csol] = u;     cur[u] ^= 1;     int last = 0;     for (int i = 0; i < E[u].size(); i++)       if (E[u][i] != up && mark[E[u][i]] == 0) {         if (up == 0 && last != 0) {           csol++;           sol[csol] = u;           cur[u] ^= 1;         }         dfs(E[u][i], u);         last = 1;         if (up != 0) {           csol++;           sol[csol] = u;           cur[u] ^= 1;         }       }     if (cur[u])       if (up != 0) {         csol++;         sol[csol] = up;         csol++;         sol[csol] = u;         cur[u] ^= 1;         cur[up] ^= 1;       } else {         csol++;         sol[csol] = u;         cur[u] ^= 1;       }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int p, k;       scanf( %d%d , &p, &k);       E[p].push_back(k);       E[k].push_back(p);     }     for (int i = 1; i <= n; i++) scanf( %d , &cur[i]);     int st = 0;     for (int i = 1; i <= n; i++)       if (cur[i]) st = i;     if (st == 0) {       printf( 0 n );       return 0;     }     dfs(st, 0);     int ok = 1;     for (int i = 1; i <= n; i++)       if (cur[i]) ok = 0;     if (ok) {       printf( %d n , csol);       for (int i = 1; i <= csol; i++) printf( %d  , sol[i]);     } else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n], c[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     map<long long, long long> m;     map<long long, long long>::iterator it;     map<long long, long long>::iterator it1;     for (long long i = 0; i < n; i++) {       cin >> b[i];       m[b[i]]++;     }     for (long long i = 0; i < n; i++) {       it = m.lower_bound(n - a[i]);       it1 = m.lower_bound(0);       if (it != m.end()) {         c[i] = (it->first + a[i]) % n;         m[it->first]--;         if (m[it->first] == 0) m.erase(it);       } else if (it1 != m.end()) {         c[i] = (it1->first + a[i]) % n;         m[it1->first]--;         if (m[it1->first] == 0) m.erase(it1);       }     }     for (long long i = 0; i < n; i++) {       cout << c[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 2e5 + 100;   int t[20 * N], ls[20 * N], rs[20 * N], a[N], root[N];   int cur_size = 1;   void upd(int &v, int u, int l, int r, int pos, int x) {     v = cur_size++;     t[v] = t[u] + x, ls[v] = ls[u], rs[v] = rs[u];     if (l + 1 == r) {       return;     }     int mid = (l + r) / 2;     if (pos < mid)       upd(ls[v], ls[u], l, mid, pos, x);     else       upd(rs[v], rs[u], mid, r, pos, x);     t[v] = t[ls[v]] + t[rs[v]];   }   int get(int v, int l, int r, int ql, int qr) {     if (qr <= l || r <= ql) return 0;     if (ql <= l && r <= qr) return t[v];     int mid = (l + r) / 2;     return get(ls[v], l, mid, ql, qr) + get(rs[v], mid, r, ql, qr);   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     vector<int> pos[N];     for (int i = 1; i <= n; i++) {       cin >> a[i];       pos[a[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       int p =           lower_bound(pos[a[i]].begin(), pos[a[i]].end(), i) - pos[a[i]].begin();       upd(root[i], root[i - 1], 1, n + 1, i, 1);       if (p >= k) {         p -= k;         upd(root[i], root[i], 1, n + 1, pos[a[i]][p], -1);       }     }     int q;     cin >> q;     int ans = 0;     while (q--) {       int l, r;       cin >> l >> r;       l = (l + ans) % n + 1;       r = (r + ans) % n + 1;       if (l > r) swap(l, r);       ans = get(root[r], 1, n + 1, l, r + 1);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int ans;       long long int f = 0;       for (long long int i = 3; i <= 360; i++) {         if ((n * i) % 180 == 0 && (n * i) / 180 <= i - 2) {           f = 1;           ans = i;           break;         }       }       if (f == 1)         cout << ans << endl;       else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const int inf = 0x3f3f3f;   char s[maxn];   char str[4] =  RGB ;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int n, m;       scanf( %d%d , &n, &m);       scanf( %s , s);       int minn = inf;       n -= m;       for (int i = 0; i <= n; i++) {         for (int j = 0; j < 3; j++) {           int jishu = 0, temp;           temp = (j <= 1 ? j : 2);           for (int k = 0; k < m; k++) {             if (s[i + k] != str[(temp + k) % 3]) {               jishu++;             }           }           minn = min(minn, jishu);         }       }       printf( %d n , minn);     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   int A[2000000], B[2000000];   int l[2000000], r[2000000], c[2000000];   int main() {     scanf( %d , &N);     int mxi = 0;     for (int Ni = 0; Ni < N; Ni++) {       scanf( %d , &A[Ni]);       if (A[Ni] > A[mxi]) mxi = Ni;     }     for (int Ni = 0; Ni < N; Ni++) B[Ni] = A[(Ni + mxi) % N];     B[N] = B[0];     for (int Ni = N - 1; Ni >= 0; Ni--) {       r[Ni] = Ni + 1;       while (r[Ni] < N && B[Ni] > B[r[Ni]]) r[Ni] = r[r[Ni]];       if (r[Ni] < N && B[Ni] == B[r[Ni]]) c[Ni] = c[r[Ni]] + 1, r[Ni] = r[r[Ni]];     }     for (int Ni = 1; Ni < N; Ni++) {       l[Ni] = Ni - 1;       while (l[Ni] > 0 && B[Ni] > B[l[Ni]]) l[Ni] = l[l[Ni]];       if (l[Ni] > 0 && B[Ni] == B[l[Ni]]) l[Ni] = l[l[Ni]];     }     long long Ans = 0;     for (int Ni = 0; Ni < N; Ni++) {       if (B[Ni] == B[0])         ;       else if (l[Ni] == 0 && r[Ni] == N)         Ans++;       else         Ans += 2;       Ans += c[Ni];     }     printf( %I64d n , Ans);   }


#include <bits/stdc++.h>   using namespace std;   void start() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long ans = INT_MAX;   void solve(long long a, long long b, long long k, long long steps) {     if (a == 1 && b == 1) {       ans = min(ans, steps);       return;     }     if (a - b > 0) solve(a - b, b, k, steps + 1);     if (b - a > 0) solve(a, b - a, k, steps + 1);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     start();     long long n;     cin >> n;     for (long long i = 1; i < n; i++) {       solve(i, n - i, n, 1);     }     if (ans == INT_MAX)       cout <<  0             <<   n ;     else       cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   const long long LOG = 20;   long long n, q, Par[LOG][N], a[N], H[N], St[N], Fn[N], Lazy[N << 2], T, Fen[N],       Seg[N << 2], root = 1;   vector<long long> G[N];   void DFS(long long v = 1, long long par = 0) {     St[v] = T++;     Par[0][v] = par;     for (int i = 1; i < LOG; i++) Par[i][v] = Par[i - 1][Par[i - 1][v]];     for (auto u : G[v]) {       if (u == par) continue;       H[u] = H[v] + 1;       DFS(u, v);     }     Fn[v] = T;   }   void Shift(int id, int b, int e) {     long long val = Lazy[id];     Seg[(id << 1)] += (((b + e) >> 1) - b) * val;     Seg[((id << 1) | 1)] += (e - ((b + e) >> 1)) * val;     Lazy[(id << 1)] += val;     Lazy[((id << 1) | 1)] += val;     Lazy[id] = 0;   }   void Add(int l, int r, long long val = 0, int id = 1, int b = 0, int e = n) {     if (r <= b || e <= l) return;     if (l <= b && e <= r) {       Seg[id] += val * (e - b);       Lazy[id] += val;       return;     }     Shift(id, b, e);     Add(l, r, val, (id << 1), b, ((b + e) >> 1));     Add(l, r, val, ((id << 1) | 1), ((b + e) >> 1), e);     Seg[id] = Seg[(id << 1)] + Seg[((id << 1) | 1)];   }   long long Get(int l, int r, int id = 1, int b = 0, int e = n) {     if (r <= b || e <= l) return 0;     if (l <= b && e <= r) return Seg[id];     Shift(id, b, e);     return Get(l, r, (id << 1), b, ((b + e) >> 1)) +            Get(l, r, ((id << 1) | 1), ((b + e) >> 1), e);   }   bool is_par(long long v, long long u) {     return St[v] <= St[u] && Fn[u] <= Fn[v];   }   long long Up(long long v, long long h) {     for (int i = LOG - 1; ~i; i--)       if (h & (1 << i)) v = Par[i][v];     return v;   }   long long LLCA(long long v, long long u) {     if (H[v] < H[u]) swap(v, u);     v = Up(v, H[v] - H[u]);     if (v == u) return v;     for (int i = LOG - 1; ~i; i--) {       if (Par[i][v] ^ Par[i][u]) {         v = Par[i][v];         u = Par[i][u];       }     }     return Par[0][v];   }   long long LCA(long long v, long long u) {     if (is_par(root, v) && is_par(root, u)) return LLCA(v, u);     if (is_par(root, v) && !is_par(root, u)) return root;     if (is_par(root, u) && !is_par(root, v)) return root;     long long l = LLCA(v, u);     if (is_par(v, u)) {       long long x = LLCA(u, root);       if (is_par(v, x)) return x;       return v;     }     if (is_par(u, v)) {       long long x = LLCA(v, root);       if (is_par(u, x)) return x;       return u;     }     if (is_par(l, root)) {       long long f = LLCA(v, root);       long long f2 = LLCA(u, root);       if (H[f2] > H[f]) {         return f2;       }       return f;     }     return l;   }   void Inp() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       long long v, u;       cin >> v >> u;       G[v].push_back(u);       G[u].push_back(v);     }     DFS(1, 0);     for (int i = 1; i <= n; i++) {       Add(St[i], St[i] + 1, a[i]);     }   }   void Add_Sub(long long v, long long val) {     if (v == root) {       Add(0, n, val);       return;     }     if (is_par(root, v)) {       Add(St[v], Fn[v], val);       return;     }     if (is_par(v, root)) {       long long dif = H[root] - H[v] - 1;       long long rr = Up(root, dif);       Add(0, n, val);       Add(St[rr], Fn[rr], -val);       return;     }     Add(St[v], Fn[v], val);   }   long long Get_Sub(long long v) {     if (v == root) return Get(0, n);     if (is_par(root, v)) {       return Get(St[v], Fn[v]);     }     if (is_par(v, root)) {       long long dif = H[root] - H[v] - 1;       long long rr = Up(root, dif);       return Get(0, n) - Get(St[rr], Fn[rr]);     }     return Get(St[v], Fn[v]);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     Inp();     while (q--) {       long long t;       cin >> t;       if (t == 1) {         long long v;         cin >> v;         root = v;       }       if (t == 2) {         long long v, u, x;         cin >> v >> u >> x;         long long l = LCA(v, u);         Add_Sub(l, x);       }       if (t == 3) {         long long v;         cin >> v;         cout << Get_Sub(v) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, k;     cin >> n >> m >> k;     vector<pair<long long int, long long int> > F(n), S(m);     long long int maxDay = 0;     for (long long int i = 0; i < n; i++) {       cin >> F[i].first;       F[i].second = i + 1;       maxDay = max(maxDay, F[i].first);     }     for (long long int i = 0; i < m; i++) {       cin >> S[i].first;       S[i].second = i + 1;     }     long long int f_i = 0, s_i = 0;     sort(F.begin(), F.begin() + F.size());     sort(S.begin(), S.begin() + S.size());     vector<long long int> res;     for (long long int i = 0; i <= maxDay; i++) {       long long int use = 0;       while (use < k && f_i < F.size() && F[f_i].first == i) {         f_i++;         use++;       }       if (use == k && f_i < F.size() && F[f_i].first == i) {         cout <<  -1 ;         return 0;       }       while (s_i < S.size() && S[s_i].first < i) s_i++;       while (use < k && s_i < S.size() && S[s_i].first >= i) {         res.push_back(S[s_i].second);         use++;         s_i++;       }       while (use < k && f_i < F.size() && F[f_i].first > i) {         use++;         f_i++;       }     }     for (long long int i = maxDay + 1; s_i < S.size(); i++) {       long long int use = 0;       while (s_i < S.size() && S[s_i].first < i) s_i++;       while (use < k && s_i < S.size() && S[s_i].first >= i) {         res.push_back(S[s_i].second);         s_i++;         use++;       }     }     cout << res.size() <<   n ;     for (auto x : res) cout << x <<    ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:400000000 )   int n, m;   struct space {     int from, to, dist;     space(int f, int t) : from(f), to(t) {       if (f > t) {         dist = 0;       } else if (f == 1 || t == n) {         dist = t - f + 1;       } else {         dist = (t - f) / 2 + 1;       }     }     bool operator<(const space& b) const {       return dist > b.dist || dist == b.dist && from < b.from;     }   };   set<space> S;   int carP[1000010], carL[1000010], carR[1000010], posToCar[1000010];   int main() {     cin >> n >> m;     S.insert(space(1, n));     for (int i = 0; i < m + 1; i++) {       if (i == m) break;       int t, id;       cin >> t >> id;       if (t == 1) {         space sp = *S.begin();         S.erase(S.begin());         int F = sp.from, T = sp.to, pos;         if (F == 1 && T == n)           pos = 1;         else if (F == 1)           pos = 1;         else if (T == n)           pos = n;         else           pos = (F + T) / 2;         cout << pos << endl;         carP[id] = pos;         carL[id] = F - 1;         carR[id] = T + 1;         posToCar[pos] = id;         carR[posToCar[F - 1]] = pos;         carL[posToCar[T + 1]] = pos;         S.insert(space(F, pos - 1));         S.insert(space(pos + 1, T));       } else {         int F = carL[id], P = carP[id], T = carR[id];         S.erase(space(F + 1, P - 1));         S.erase(space(P + 1, T - 1));         carR[posToCar[F]] = T;         carL[posToCar[T]] = F;         S.insert(space(F + 1, T - 1));       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct dreapta {     ll a, b;     ll operator()(ll x) { return a * x + b; }   };   bool useless(dreapta a, dreapta b, dreapta c) {     assert(a.a >= b.a && b.a >= c.a);     return (double)(b.b - a.b) / (a.a - b.a) > (double)(c.b - b.b) / (b.a - c.a);   }   class merging_batch {     deque<dreapta> buf;       public:     merging_batch() {}     ll query(ll x) {       ll i = 0;       for (ll step = 1 << 23; step; step /= 2)         if (i + step < buf.size() && buf[i + step](x) <= buf[i + step - 1](x))           i += step;       assert(i == buf.size() - 1 || buf[i](x) <= buf[i + 1](x));       return buf[i](x);     }     void add_right(dreapta x) {       while (buf.size() > 1 && useless(buf.rbegin()[1], buf.back(), x))         buf.pop_back();       buf.push_back(x);     }     void add_left(dreapta x) {       while (buf.size() > 1 && useless(x, buf[0], buf[1])) buf.pop_front();       buf.push_front(x);     }     void swap_with(merging_batch& rhs) { swap(buf, rhs.buf); }     void merge_with(merging_batch& rhs) {       if (buf.size() < rhs.buf.size()) {         for (auto it = buf.rbegin(); it != buf.rend(); ++it) rhs.add_left(*it);         swap(buf, rhs.buf);       } else         for (auto x : rhs.buf) add_right(x);     }   };   class undo_batch {     ll top = 0;     vector<dreapta> st = vector<dreapta>(         1000000 + 10,         dreapta{1000ll * 1000 * 1000, 1000ll * 1000 * 1000 * 1000 * 1000});     struct modification {       ll old_top, old_pos;       dreapta d;     };     vector<modification> undo_st;       public:     undo_batch() { top = 1; }     void clear() { top = 1; }     void print() {       for (int i = 1; i < top; ++i) {         cerr <<  (  << st[i].a <<  ,  << st[i].b <<  )  ;       }       cerr << endl;     }     ll query(ll x) {       ll i = 0;       for (ll step = 1 << 23; step; step /= 2)         if (i + step < top && st[i + step](x) <= st[i + step - 1](x)) i += step;       assert(i == top - 1 || st[i](x) <= st[i + 1](x));       return st[i](x);     }     void undo() {       assert(!undo_st.empty());       top = undo_st.back().old_top;       st[undo_st.back().old_pos] = undo_st.back().d;       undo_st.pop_back();     }     void add_right(dreapta d) {       undo_st.push_back(modification{top, 0, 0});       ll ret = 0;       for (ll step = 1 << 23; step; step /= 2)         if (ret + step < top && (!useless(st[ret + step - 1], st[ret + step], d)))           ret += step;       top = ret + 2;       undo_st.back().old_pos = ret + 1;       undo_st.back().d = st[ret + 1];       st[ret + 1] = d;     }   };   void produce_state(const ll n, const vector<ll>& d, const vector<ll>& v,                      vector<ll>& ret) {     static vector<ll> posz;     static vector<merging_batch> mb;     static undo_batch ub;     posz.clear();     mb.clear();     ub.clear();     for (ll i = 0; i < n; ++i) {       merging_batch x;       x.add_right(dreapta{-i + 1, d[i]});       while (!posz.empty() && v[posz.back()] <= v[i]) {         mb.back().merge_with(x);         x.swap_with(mb.back());         mb.pop_back();         posz.pop_back();         ub.undo();       }       posz.push_back(i);       mb.push_back(move(x));       ub.add_right(dreapta{v[i], mb.back().query(v[i])});       ret[i + 1] = ub.query(i);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ll n, k;     cin >> n >> k;     vector<ll> v(n);     for (auto& x : v) cin >> x;     vector<ll> state(n + 1, (ll)1e9 * (ll)1e9), tmp(n + 1, 0);     state[0] = 0;     tmp[0] = 0;     for (ll i = 0; i < k; ++i) {       produce_state(n, state, v, tmp);       swap(state, tmp);     }     cout << state.back() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T, typename _T2>   string to_string(pair<_T, _T2> x) {     return  <  + to_string(x.first) +  ,   + to_string(x.second) +  > ;   }   template <typename _T>   string to_string(vector<_T> vec) {     string s =  [  ;     for (auto el : vec) s += to_string(el) +  ,  ;     s[s.size() - 1] =  ] ;     s[s.size() - 2] =    ;     return s;   }   template <typename _T>   string to_string(set<_T> vec) {     string s =  {  ;     for (auto el : vec) s += to_string(el) +  ,  ;     s[s.size() - 1] =  } ;     s[s.size() - 2] =    ;     return s;   }   template <typename _T, typename _T2>   string to_string(map<_T, _T2> vec) {     string s =  {  ;     for (auto el : vec)       s +=  mp[  + to_string(el.first) +  ]=   + to_string(el.second) +  ,  ;     s[s.size() - 1] =  } ;     s[s.size() - 2] =    ;     return s;   }   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << to_string(x) <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << to_string(x) <<   n ;     _DBG(s + 1, a...);   }   mt19937 rng___(chrono::steady_clock::now().time_since_epoch().count());   const long long MOD = 998244353;   const long long LLINF = 1e18 + 7;   const int N = 2e5 + 8;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int t;     cin >> t;     while (t--) {       int n[3], len;       cin >> n[0] >> n[1] >> n[2];       len = n[0] + n[1] + n[2] + 1;       string ans;       if (n[0] > 0) {         ans += string(n[0] + 1,  0 );         if (n[2] > 0) {           n[1]--;           ans += string(n[2] + 1,  1 );         }         while (n[1]--) {           if (ans.back() ==  1 )             ans +=  0 ;           else             ans +=  1 ;         }         cout << ans <<   n ;       } else {         ans += string(n[2] + 1,  1 );         while (n[1]--) {           if (ans.back() ==  1 )             ans +=  0 ;           else             ans +=  1 ;         }         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<int, int> PII;   long long qpow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % m;       a = a * a % m, b >>= 1;     }     return ans;   }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a;       a = a * a, b >>= 1;     }     return ans;   }   long long qmul(long long a, long long b, long long m) {     long long res = 0;     while (b > 0) {       if (b & 1) res = (res + a) % m;       a = (a + a) % m;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long inv(long long t, long long p) {     return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long r = exgcd(b, a % b, y, x);     y -= (a / b) * x;     return r;   }   long long inv1(long long a, long long p) {     long long d, x, y;     d = exgcd(a, p, x, y);     return d == 1 ? (x % p + p) % p : -1;   }   template <typename T, typename B>   T Add(T a, B b, long long m) {     return a + b >= m ? (a + b) % m : a + b;   }   template <typename T, typename B>   T Sub(T a, B b, long long m) {     return a - b < 0 ? (a - b + m) % m : a - b;   }   template <class T>   void _sf(T &x) {     cin >> x;   }   void _sf(int &x) { scanf( %d , &x); }   void _sf(long long &x) { scanf( %lld , &x); }   void _sf(double &x) { scanf( %lf , &x); }   void _sf(char &x) { scanf(  %c , &x); }   void _sf(char *x) { scanf( %s , x); }   void sf() {}   template <class T, class... U>   void sf(T &head, U &...tail) {     _sf(head);     sf(tail...);   }   template <class T>   void _pf(const T &x) {     cout << x;   }   void _pf(const int &x) { printf( %d , x); }   void _pf(const long long &x) { printf( %lld , x); }   void _pf(const double &x) { printf( %.16f , x); }   void _pf(const char &x) { putchar(x); }   void _pf(const char *x) { printf( %s , x); }   template <class T, class U>   void _pf(const pair<T, U> &x) {     pf(x.first);     putchar(   );     pf(x.second);   }   template <class T>   void _pf(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _pf(*i++))       if (i != x.cbegin()) putchar(   );   }   void pf() {}   template <class T, class... U>   void pf(const T &head, const U &...tail) {     _pf(head);     putchar(sizeof...(tail) ?     :   n );     pf(tail...);   }   template <typename T>   inline void read(T &x) {     x = 0;     static int p;     p = 1;     static char c;     c = getchar();     while (!isdigit(c)) {       if (c ==  - ) p = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c - 48);       c = getchar();     }     x *= p;   }   const bool IOS = false;   const double PI = acos(-1);   const double eps = 1e-8;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const long long INV2 = 500000004;   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int maxn = 400050 + 10;   bool vis[maxn];   int mi[maxn];   void Main();   int main() {     if (IOS) std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     Main();     0;     return 0;   }   void Main() {     int n, x;     sf(n, x);     for (int i = 0; i < x; ++i) mi[i] = i;     int ans = 0;     for (int i = 1; i <= n; ++i) {       int d;       sf(d);       d = d % x;       if (mi[d] <= n) {         vis[mi[d]] = 1;         while (vis[ans]) ans++;         mi[d] += x;       }       pf(ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     string s;     cin >> n >> m;     cin >> s;     int pos = 0;     for (int i = 1; i < n; i++) {       if (s.substr(0, i) == s.substr(n - i, i)) {         pos = i;       }     }     cout << s;     for (int i = 1; i < m; i++) {       cout << s.substr(pos);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& it : v) is >> it;     return is;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   | ;     __f(comma + 1, args...);   }   vector<int> hungarianMethod(vector<vector<int>> W) {     int n = ((int)(W).size()), m = ((int)(W[0]).size()), PHI = -1, NOL = -2,         INF = 1e9;     vector<vector<bool>> x(n, vector<bool>(m));     vector<bool> ss(n), st(m);     int f = 0;     for (int i = 0; i < n; i++) {       f = max(f, (*max_element(W[i].begin(), W[i].end())));     }     vector<int> u(n, f), v(m), p(m, INF), ls(n, PHI), lt(m, NOL), a(n, -1);     while (true) {       f = -1;       for (int i = 0; i < n and f == -1; i++) {         if (ls[i] != NOL and ss[i] == 0) {           f = i;         }       }       if (f != -1) {         ss[f] = true;         for (int j = 0; j < m; j++) {           if (x[f][j] == 0 and u[f] + v[j] - W[f][j] < p[j]) {             lt[j] = f;             p[j] = u[f] + v[j] - W[f][j];           }         }       } else {         for (int i = 0; i < m and f == -1; i++) {           if (lt[i] != NOL and st[i] == 0 and p[i] == 0) {             f = i;           }         }         if (f == -1) {           int d1 = INF, d2 = INF, d;           for (int i : u) {             d1 = min(d1, (i));           }           for (int i : p) {             if (i > 0) {               d2 = min(d2, (i));             }           }           d = min(d1, d2);           for (int i = 0; i < n; i++) {             if (ls[i] != NOL) {               u[i] -= d;             }           }           for (int i = 0; i < m; i++) {             if (p[i] == 0) {               v[i] += d;             }             if (p[i] > 0 and lt[i] != NOL) {               p[i] -= d;             }           }           if (d2 >= d1) {             break;           }         } else {           st[f] = true;           int s = -1;           for (int i = 0; i < n and s == -1; i++) {             if (x[i][f]) {               s = i;             }           }           if (s == -1) {             for (int l, r;; f = r) {               r = f;               l = lt[r];               if (r >= 0 and l >= 0) {                 x[l][r] = !x[l][r];               } else {                 break;               }               r = ls[l];               if (r >= 0 and l >= 0) {                 x[l][r] = !x[l][r];               } else {                 break;               }             }             fill(p.begin(), p.end(), INF);             fill(lt.begin(), lt.end(), NOL);             fill(ls.begin(), ls.end(), NOL);             fill(ss.begin(), ss.end(), false);             fill(st.begin(), st.end(), false);             for (int i = 0; i < n; i++) {               bool ex = true;               for (int j = 0; j < m and ex; j++) {                 ex = !x[i][j];               }               if (ex) {                 ls[i] = PHI;               }             }           } else {             ls[s] = f;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (x[i][j]) {           a[j] = i;         }       }     }     return a;   }   void solve() {     map<char, int> ind;     map<int, char> revInd;     for (char ch =  a ; ch <=  z ; ++ch) {       ind[ch] = ch -  a ;       revInd[ind[ch]] = ch;     }     for (char ch =  A ; ch <=  Z ; ++ch) {       ind[ch] = (ch -  A ) + 26;       revInd[ind[ch]] = ch;     }     int n, k;     cin >> n >> k;     string a, b;     cin >> a >> b;     vector<vector<int>> W(k, vector<int>(k, 1));     for (int i = 0; i < n; ++i) {       W[ind[a[i]]][ind[b[i]]]++;     }     vector<int> matching = hungarianMethod(W);     int ans = 0;     string res(k,  $ );     for (int i = 0; i < k; ++i) {       ans += W[matching[i]][i] - 1;       res[matching[i]] = revInd[i];     }     cout << ans <<   n  << res <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 7, n = 7, maxm = 101;   int m, cntblk = maxn, f[maxn], deg[maxn];   bool used[maxm];   class ed {    public:     int target, id;     char type;     ed(int t, int i, char ty) : target(t), id(i), type(ty){};   };   class ans {    public:     int id;     char type;     ans(int i, char ty) : id(i), type(ty){};   };   vector<ed> edge[maxn];   vector<ans> answer;   inline int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }   void euler(int x, int in_id, char in_type) {     for (vector<ed>::iterator vi = edge[x].begin(); vi != edge[x].end(); vi++) {       if (used[(*vi).id]) continue;       used[(*vi).id] = true;       euler((*vi).target, (*vi).id, (*vi).type);     }     if (in_id >= 0) answer.push_back(ans(in_id, in_type));   }   int main() {     cin >> m;     for (int i = 0; i < n; i++) f[i] = i, deg[i] = 0;     for (int i = 1, x, y; i <= m; i++) {       cin >> x >> y;       deg[x]++;       deg[y]++;       edge[x].push_back(ed(y, i,  + ));       edge[y].push_back(ed(x, i,  - ));       if (getf(x) == getf(y)) continue;       f[getf(x)] = getf(y);       cntblk--;     }     int tmp = 0, s = -1;     for (int i = 0; i < n; i++) {       cntblk -= (deg[i] == 0);       tmp += (deg[i] & 1);       if (deg[i] > 0 && (s == -1 || deg[i] & 1)) s = i;     }     if (cntblk != 1 || !(tmp == 0 || tmp == 2)) {       puts( No solution );       return 0;     }     memset(used, false, sizeof(used));     euler(s, -1,  + );     for (vector<ans>::reverse_iterator vi = answer.rbegin(); vi < answer.rend();          vi++) {       printf( %d %c n , (*vi).id, (*vi).type);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, less<int> > num;   int main() {     int n, x;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       num.push(x);     }     cout << ((num.top()) xor (x)) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200020;   int a[maxn], b[maxn], pos[maxn], ans;   unsigned long long hsh, qpow[200020] = {1}, sum;   int n, m;   struct node {     unsigned long long a, tot;   } tr[maxn << 2];   void pushup(int p) {     tr[p].tot = tr[p << 1].tot + tr[p << 1 | 1].tot;     tr[p].a = tr[p << 1].a * qpow[tr[p << 1 | 1].tot] + tr[p << 1 | 1].a;   }   void update(int l, int r, int pos, int p, int k) {     if (l == r) {       if (!k)         tr[p].tot -= 1;       else         tr[p].tot += 1;       tr[p].a = k;       return;     }     int mid = l + r >> 1;     if (pos <= mid) update(l, mid, pos, p << 1, k);     if (pos > mid) update(mid + 1, r, pos, p << 1 | 1, k);     pushup(p);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       hsh = hsh * 23 + a[i];       qpow[i] = qpow[i - 1] * 23;       sum += qpow[i - 1];     }     for (int i = 1; i <= m; i++) scanf( %lld , &b[i]), pos[b[i]] = i;     for (int i = 1; i <= m; i++) {       if (i > n) update(1, m, pos[i - n], 1, 0);       update(1, m, pos[i], 1, i);       int d = i - n;       if (d >= 0 && tr[1].a == d * sum + hsh) ++ans;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     if (n % 2 == 0)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       long long int b[(2 * n) + 1];       b[1] = 1;       b[2 * n] = 2 * n;       long long int i = n + 1;       long long int j = 2;       long long int k = 2;       long long int flag = 1;       while (k < 2 * n) {         if (flag == 1) {           b[i] = k;           b[i + 1] = k + 1;           k = k + 2;           i = i + 2;           flag = 0;         } else {           b[j] = k;           b[j + 1] = k + 1;           k = k + 2;           j = j + 2;           flag = 1;         }       }       for (long long int i = 1; i <= 2 * n; i++) cout << b[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 5;   const int MOD = 1e9 + 7;   long long cnt[N], x;   int n, tmp;   vector<vector<long long> > matMul(vector<vector<long long> > &A,                                     vector<vector<long long> > &B) {     vector<vector<long long> > C(N, vector<long long>(N, 0));     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         for (int k = 0; k < N; k++) {           C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % MOD) % MOD;         }       }     }     return C;   }   vector<vector<long long> > matPow(vector<vector<long long> > &A, int b) {     if (b == 1) return A;     vector<vector<long long> > ans = matPow(A, b >> 1);     ans = matMul(ans, ans);     if (b & 1) ans = matMul(ans, A);     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> tmp;       cnt[tmp]++;     }     if (x == 0) {       cout <<  1 n ;       return 0;     }     vector<vector<long long> > res(N, vector<long long>(N, 0));     for (int i = 1; i <= 100; i++) {       res[0][i - 1] = cnt[i];       if (i < 100) res[i][i - 1] = 1;     }     res[0][100] = 1;     res[100][100] = 1;     res = matPow(res, x);     long long ans = (res[0][0] + res[0][100]) % MOD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   const long long inf = 1e18;   inline int read() {     int x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return x;   }   int n, m, now;   long long ans, Pow[100];   bitset<N> f[2][64][N], g, tmp;   int main() {     n = read();     m = read();     int u, v, w;     for (int i = 1; i <= m; ++i) {       u = read();       v = read();       w = read();       f[w][0][u][v] = 1;     }     for (int i = 1; i <= 60; ++i)       for (int u = 1; u <= n; ++u)         for (int v = 1; v <= n; ++v) {           if (f[0][i - 1][u][v]) f[0][i][u] |= f[1][i - 1][v];           if (f[1][i - 1][u][v]) f[1][i][u] |= f[0][i - 1][v];         }     if (f[0][60][1].count()) {       puts( -1 );       return 0;     }     now = 0;     tmp[1] = 1;     Pow[0] = 1;     for (int i = 1; i <= 60; ++i) Pow[i] = Pow[i - 1] << 1;     for (int i = 60; i >= 0; --i) {       g.reset();       for (int j = 1; j <= n; ++j)         if (tmp[j]) g |= f[now][i][j];       if (g.count()) {         now ^= 1;         tmp = g;         ans += Pow[i];       }     }     if (ans > inf)       puts( -1 );     else       printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 5;   const int inf = 0x3f3f3f3f;   const int Max = 200000;   template <class T>   inline void getin(T& num) {     char c;     bool flag = 0;     num = 0;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag = 1;     while (c >=  0  && c <=  9 ) {       num = num * 10 + c - 48;       c = getchar();     }     if (flag) num = -num;   }   int n, k, a, x, y, m;   queue<int> num[N];   set<pair<int, int> > output;   vector<pair<int, int> > Ans;   int main() {     getin(n);     int sum = 0, ans = 0;     for (int i = 1; i <= n; i++) {       getin(k), getin(a), sum += k;       getin(x), getin(y), getin(m);       num[i].push(a);       int ret = 0;       for (int j = 2; j <= k; j++) {         int nxt = (1ll * a * x % m + y) % m;         if (nxt < a) ret++;         num[i].push(a = nxt);       }       ans = max(ans, ret);     }     printf( %d n , ans);     if (sum > Max) return 0;     for (int i = 1; i <= n; i++) {       output.insert(make_pair(num[i].front(), i));       num[i].pop();     }     int last = -inf, p;     for (int i = 1; i <= sum; i++) {       set<pair<int, int> >::iterator it =           output.lower_bound(make_pair(last, -inf));       if (it == output.end()) ans++, it = output.begin();       Ans.push_back(*it);       last = (*it).first;       p = (*it).second;       output.erase(it);       if (!num[p].empty()) {         output.insert(make_pair(num[p].front(), p));         num[p].pop();       }     }     for (int i = 0; i < sum; i++) printf( %d %d n , Ans[i].first, Ans[i].second);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 5;   const int oo = 1000000000;   bool u[N][N];   int n, m;   int ans = -1;   int a[N][N], l[N][N];   int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   char s[N];   struct pis {     int x, y;     pis() {}     pis(int x, int y) : x(x), y(y) {}   } f[10 * N * N];   inline int Solve(int x, int y) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) l[i][j] = oo;     int front = 0, top = 1;     f[1] = pis(x, y);     l[x][y] = 0;     while (front < top) {       pis p = f[++front];       u[p.x][p.y] = 0;       for (int i = 0; i < 4; i++) {         int dx = p.x + d[i][0];         int dy = p.y + d[i][1];         if (dx >= 1 && dx <= n && dy >= 1 && dy <= m) {           int dis = a[p.x][p.y] != a[dx][dy];           if (l[p.x][p.y] + dis < l[dx][dy]) {             l[dx][dy] = l[p.x][p.y] + dis;             if (!u[dx][dy]) {               u[dx][dy] = 1;               f[++top] = pis(dx, dy);             }           }         }       }     }     int MAX = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] && l[i][j] > MAX) MAX = l[i][j];     return MAX;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       for (int j = 1; j <= m; j++) {         if (s[j - 1] ==  B ) ans = oo;         a[i][j] = s[j - 1] ==  W  ? 0 : 1;       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) ans = min(ans, Solve(i, j));     printf( %d n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 1e5 + 7;   int n, x;   int main() {     cin >> n >> x;     int ans = 0, num = 0;     if (n == 2 && x == 0) {       puts( NO );       return 0;     }     puts( YES );     if (n == 1)       printf( %d , x);     else if (n == 2)       printf( %d %d , 0, x);     else if (n == 3) {       int t1 = 1 << 18;       int t2 = 1 << 19;       int t3 = x ^ t1 ^ t2;       printf( %d %d %d , t1, t2, t3);     } else {       for (int i = 1;; i++) {         if (i == x) continue;         ans ^= i;         printf( %d  , i);         num++;         if (num == n - 3) break;       }       int t1 = 1 << 18;       int t2 = 1 << 19;       int t3 = x ^ ans ^ t1 ^ t2;       printf( %d %d %d , t1, t2, t3);       ans ^= t1 ^ t2 ^ t3;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 mt_rand(time(0));   const int N = 105;   int t, n;   char a[N], b[N], c[N];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %s%s%s , a, b, c);       n = 0;       while (a[n]) n++;       bool ok = 1;       for (int i = 0; i < n; i++) {         if (c[i] == a[i] || c[i] == b[i])           ;         else           ok = 0;       }       if (!ok)         printf( NO n );       else         printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str;   int memo[100005][3];   int dp(int Idx, int prev) {     if (Idx == (int)str.size()) return 0;     int choice1 = 1000000;     if (memo[Idx][prev] != -1) return memo[Idx][prev];     if (prev == 0) {       if (isupper(str[Idx]))         choice1 = dp(Idx + 1, 0) + 1;       else         choice1 = dp(Idx + 1, 0);     } else {       if (isupper(str[Idx])) {         choice1 = min(dp(Idx + 1, 0) + 1, dp(Idx + 1, 1));       } else         choice1 = min(dp(Idx + 1, 0), dp(Idx + 1, 1) + 1);     }     return memo[Idx][prev] = choice1;   }   int main() {     cin >> str;     memset(memo, -1, sizeof(memo));     int ans = dp(0, 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   double p;   bool in_memo[200 + 1][230 + 1][2][1 << 8];   double memo[200 + 1][230 + 1][2][1 << 8];   double E(int k, int lead_count, bool lead_parity, int mask) {     double& ans = memo[k][lead_count][lead_parity][mask];     if (not in_memo[k][lead_count][lead_parity][mask]) {       if (k == 0) {         ans = mask ? __builtin_ctz(mask) : 8 + (lead_parity ? 0 : lead_count);       } else {         ans = p / 100 *                   E(k - 1,                     bool((mask & (1 << 7)) >> 7) == lead_parity ? lead_count + 1                                                                 : 1,                     (mask & (1 << 7)) >> 7, (mask * 2) & 0b11111111) +               (100 - p) / 100 *                   E(k - 1,                     mask == 0b11111111 ? (lead_parity ? lead_count : 1)                                        : lead_count,                     lead_parity ^ (mask == 0b11111111), (mask + 1) & 0b11111111);       }       in_memo[k][lead_count][lead_parity][mask] = true;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x, k;     cin >> x >> k >> p;     memset(in_memo, false, sizeof in_memo);     cout << fixed << setprecision(7)          << E(k, __builtin_ctz((x >> 8) & 1 ? (x >> 8) + 1 : x >> 8),               (x >> 8) & 1, x & 0b11111111)          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class S, class T>   ostream& operator<<(ostream& st, pair<S, T> p) {     st <<  (  << p.first <<  ,  << p.second <<  ) ;     return st;   }   template <class T>   ostream& operator<<(ostream& st, vector<T> v) {     st <<  [ ;     for (size_t i = 0; i < v.size(); ++i) {       if (i != 0) {         st <<  ,  ;       }       st << v[i];     }     st <<  ] ;     return st;   }   pair<int, int> get_parent_dsu(int v, vector<pair<int, int> >& parents) {     if (parents[v].first != v) {       pair<int, int> p = get_parent_dsu(parents[v].first, parents);       parents[v] = make_pair(p.first, p.second ^ parents[v].second);     }     return parents[v];   }   void union_dsu(int a, int b, int value, vector<int>& mass,                  vector<pair<int, int> >& parents) {     pair<int, int> a_parent = get_parent_dsu(a, parents);     pair<int, int> b_parent = get_parent_dsu(b, parents);     a = a_parent.first;     int a_dist = a_parent.second;     b = b_parent.first;     int b_dist = b_parent.second;     if (a != b) {       if (mass[a] > mass[b]) {         swap(a, b);         swap(a_dist, b_dist);       }       parents[a].first = b;       parents[a].second = value ^ a_dist ^ b_dist;       mass[b] += mass[a];     }   }   int perform_get_query(int a, int b, vector<pair<int, int> >& parents) {     pair<int, int> a_parent = get_parent_dsu(a, parents);     pair<int, int> b_parent = get_parent_dsu(b, parents);     int result;     if (a_parent.first == b_parent.first) {       result = a_parent.second ^ b_parent.second;     } else {       result = -1;     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(time(0));     int q;     cin >> q;     int mapper_size = 0;     map<int, int> mapper;     vector<int> mass;     vector<pair<int, int> > parents_dsu;     int last = 0;     for (int i = 0; i < q; ++i) {       int t;       cin >> t;       int l, r, value;       cin >> l >> r;       l = l ^ last;       r = r ^ last;       if (l > r) {         swap(l, r);       }       --l;       if (mapper.count(l) == 0) {         mass.push_back(1);         parents_dsu.push_back(make_pair(mapper_size, 0));         mapper[l] = mapper_size++;       }       if (mapper.count(r) == 0) {         mass.push_back(1);         parents_dsu.push_back(make_pair(mapper_size, 0));         mapper[r] = mapper_size++;       }       int a = mapper[l];       int b = mapper[r];       if (t == 1) {         cin >> value;         value = last ^ value;         union_dsu(a, b, value, mass, parents_dsu);       } else {         last = perform_get_query(a, b, parents_dsu);         cout << last << endl;         if (last == -1) {           last = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e5 + 7;   const int Inf = 1 << 30;   const long long INF = 1ll << 60;   int n;   int a[maxx];   vector<int> vec;   int pos[maxx];   map<int, int> mp;   int ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int cnt = 0;     int t = 0;     bool flg = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 1) {         if (!flg) pos[++t] = i;         flg = 1;         cnt++;       } else {         if (cnt) vec.push_back(cnt);         cnt = 0;         flg = 0;       }       if (i == n && a[i] == 1) vec.push_back(cnt);     }     for (int i = 0; i < vec.size(); i++) mp[pos[i + 1]] = vec[i];     int pp = pos[1] - 1;     int minx = min(pp, mp[pos[1]]);     ans = max(ans, 2 * minx);     for (int i = 1; i <= t; i++) {       int tmp;       if (i == 1)         tmp = minx;       else         tmp = pos[i] - (pos[i - 1] + mp[pos[i - 1]]);       int min1 = min(tmp, mp[pos[i]]);       int min2 = min(tmp, mp[pos[i - 1]]);       int minT = max(min1, min2);       ans = max(ans, 2 * minT);     }     int dd = n - (pos[t] + mp[pos[t]] - 1);     int min0 = min(dd, mp[pos[t]]);     ans = max(ans, 2 * min0);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 10;   int fac[MAXN], infac[MAXN];   long long pow_mod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return res;   }   int add(int a, int b) { return (a + b) % MOD; }   int mul(int a, int b) { return 1LL * a * b % MOD; }   int C(int a, int b) { return mul(fac[a], mul(infac[b], infac[a - b])); }   int A(int a, int b) { return mul(fac[a], infac[a - b]); }   int F(int a, int b) {     if (a == b) return 1;     return mul(b, pow_mod(a, a - b - 1));   }   int main() {     int n, m, a, b;     fac[0] = 1;     for (int i = 1; i <= 1000000; i++) {       fac[i] = mul(i, fac[i - 1]);     }     infac[1000000] = pow_mod(fac[1000000], MOD - 2);     for (int i = 1000000; i >= 1; i--) {       infac[i - 1] = mul(infac[i], i);     }     scanf( %d%d%d%d , &n, &m, &a, &b);     int ans = 0;     for (int i = 1; i <= n - 1; i++) {       if (i > m) {         continue;       }       ans = add(ans, mul(mul(pow_mod(m, n - 1 - i), F(n, i + 1)),                          mul(A(n - 2, i - 1), C(m - 1, i - 1))));     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5000 + 10];   int main() {     int n;     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     bool flag = false;     for (int i = 1; i < n; i++) {       if (a[a[a[i]]] == i) {         flag = true;         break;       }     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100004;   unsigned long long a, b, c = 0, x = 0, y = 0;   bool f = 1;   void solve() {     int c = 0;     for (int i = 0; i < 64; i++) {       if (b >> i & 1) y |= 1ll << i;     }     a -= y;     for (int i = 1; i < 64; i++) {       int r = a >> i & 1, s = b >> (i - 1) & 1;       if (r == 1) {         if (s == 0) {           x |= 1ll << (i - 1);           y |= 1ll << (i - 1);         } else {           f = 0;           break;         }       }     }   }   int main() {     cin >> a >> b;     solve();     if (!f)       puts( -1 );     else       printf( %llu %llu , x, y);   }


#include <bits/stdc++.h>   using namespace std;   long long nsd(long long a, long long b) {     while (b != 0) {       a = a % b;       swap(a, b);     }     return a;   }   long long nsk(long long a, long long b) { return a / nsd(a, b) * b; }   bool cmp(long long a, long long b) { return a > b; }   void sorts(string& str) { sort(str.begin(), str.end()); }   long long sumd(long long n) {     if (n < 0) {       n = -n;     }     long long s = 0;     while (n != 0) {       n /= 10;       s++;     }     return s;   }   int suma(long long n) {     int s = 0;     while (n != 0) {       s += n % 10;       n /= 10;     }     return s;   }   long long fact(long long n) {     if (n == 1)       return 1;     else       return n * fact(n - 1);   }   int factnum(int n) {     int c = 0;     for (int i = 5; n / i >= 1; i *= 5) c += n / i;     return c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     cout << abs(count(s.begin(), s.end(),  1 ) - count(s.begin(), s.end(),  0 ));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, n;     cin >> n;     long long int arr[n];     vector<long long int> vec[100010];     for (i = 0; i < n; i++) {       cin >> arr[i];       vec[arr[i]].push_back(i);     }     long long int y = 0, d;     for (i = 0; i < 100010; i++) {       long long int x = 0;       if (vec[i].size() >= 2) {         d = vec[i][1] - vec[i][0];         for (j = 1; j < vec[i].size(); j++) {           if (d == (vec[i][j] - vec[i][j - 1])) {             ++x;           }         }         if ((x + 1) == vec[i].size()) {           ++y;         }       } else if (vec[i].size() == 1) {         ++y;       } else {         continue;       }     }     cout << y << endl;     vector<long long int> vec1[100010];     long long int z = 0;     for (i = 0; i < 100010; i++) {       long long int x = 0;       d = 0;       if (vec[i].size() >= 2) {         d = vec[i][1] - vec[i][0];         for (j = 1; j < vec[i].size(); j++) {           if (d == (vec[i][j] - vec[i][j - 1])) {             ++x;           }         }         if ((x + 1) == vec[i].size()) {           cout << i <<     << d << endl;         }       } else if (vec[i].size() == 1) {         cout << i <<     << d << endl;       } else {         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1005];   int main() {     int n, f = 1;     char *p, *q;     scanf( %s , s);     n = strlen(s);     p = s;     q = s + n - 1;     while (p <= q) {       if (*p == *q) {         p++;         q--;       } else {         f = 0;         break;       }     }     printf( %s , s);     if (!f) {       for (int i = n - 1; i >= 0; i--) printf( %c , s[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T> &a, long long n) {     T x;     a.clear();     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }   }   template <class T>   void write(vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int T;     cin >> T;     while (T--) {       int n, m;       vector<int> a, b;       cin >> n >> n >> m;       read(a, n);       read(b, m);       sort(a.begin(), a.end());       sort(b.begin(), b.end());       if (a.back() > b.back())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 1e9 + 7;   long long minv[1 << 16];   long long numx[15], numy[15];   long long n, a[maxn], x, y, A, B, facy[15000], ans;   inline long long read() {     char ch = getchar();     long long u = 0, f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       u = u * 10 + ch - 48;       ch = getchar();     }     return u * f;   }   inline long long gcd(long long x, long long y) {     return y == 0 ? x : gcd(y, x % y);   }   inline long long mul(long long x, long long y, long long p) {     long long cnt = 0;     while (y) {       if (y & 1) cnt = (cnt + x) % p;       x = (x + x) % p;       y >>= 1;     }     return cnt;   }   inline long long ksm(long long x, long long k, long long p) {     long long cnt = 1;     while (k) {       if (k & 1) cnt = mul(cnt, x, p);       x = mul(x, x, p);       k >>= 1;     }     return cnt;   }   inline bool judge(long long a, long long p) {     long long q = p - 1;     int k = 0;     while (q % 2 == 0) ++k, q >>= 1;     long long v = ksm(a, q, p);     if (v == 1 || v == p - 1) return false;     while (k-- != 0) {       v = mul(v, v, p);       if (v == p - 1) return false;     }     return true;   }   inline bool miller_rabbin(long long p) {     if (p == 2) return true;     if (p % 2 == 0) return false;     for (register int i = 1; i <= 60; i++) {       long long a = rand() % (p - 1) + 1;       if (judge(a, p)) return false;     }     return true;   }   const int M = (1 << 7) - 1;   inline long long pollard_rho(long long n) {     if (n % 2 == 0) return 2;     if (n % 3 == 0) return 3;     long long x = 0, y = x, t = 1, q = 1, a = (rand() % (n - 1)) + 1;     for (int k = 2;; k <<= 1, y = x, q = 1) {       for (int i = 1; i <= k; ++i) {         x = (mul(x, x, n) + a) % n;         q = mul(q, abs(x - y), n);         if (!(i & M)) {           t = gcd(q, n);           if (t > 1) break;         }       }       if (t > 1 || (t = gcd(q, n)) > 1) break;     }     if (t == n) {       t = 1;       while (t == 1) t = gcd(abs((x = ((mul(x, x, n) + a) % n)) - y), n);     }     return t;   }   inline void findfac(long long x) {     if (x == 1) return;     if (miller_rabbin(x)) {       facy[++facy[0]] = x;       return;     }     long long p = x;     while (p >= x) p = pollard_rho(p);     findfac(p);     findfac(x / p);   }   inline void dEBUG(long long *x, long long len) {     cerr <<  ----------------------------------DEBUG-----------------------------               -----           << endl;     for (register int i = 0; i <= len; i++) cerr << x[i] <<    ;     cerr << endl;     cerr <<  ----------------------------------DEBUG-----------------------------               -----           << endl;   }   int main() {     srand(19260817);     n = read();     A = x = read();     B = y = read();     if (y % x != 0) {       cout << 0;       return 0;     }     for (register int i = 1; i <= n; i++) a[i] = read();     if (B != 100000000000123502ll) {       findfac(B);       sort(facy + 1, facy + 1 + facy[0]);       facy[0] = unique(facy + 1, facy + 1 + facy[0]) - facy - 1;     } else {       for (register int i = 2; 1ll * i * i <= B; i++) {         if (B % i == 0) facy[++facy[0]] = i;         while (B % i == 0) B /= i;       }       if (B != 1) facy[++facy[0]] = B;       B = y;     }     for (register int i = 1; i <= facy[0]; i++)       while (B % facy[i] == 0) B /= facy[i], numy[i]++;     for (register int i = 1; i <= facy[0]; i++)       while (A % facy[i] == 0) A /= facy[i], numx[i]++;     for (register int i = 1; i <= n; i++) {       if (a[i] % x != 0) continue;       int maskx = 0;       long long T = a[i];       for (register int k = 1; k <= facy[0]; k++) {         int p = 0;         if (numx[k] == numy[k]) continue;         while (T % facy[k] == 0) T /= facy[k], p++;         maskx |= ((p > numx[k]) << (k - 1));       }       minv[maskx]++;     }     for (register int i = 0; i < facy[0]; i++)       for (register int G = 0; G < (1 << facy[0]); G++)         if (G & (1 << i)) minv[G] += minv[G ^ (1 << i)];     int MK = (1 << facy[0]) - 1;     for (register int i = 1; i <= n; i++) {       if (y % a[i] != 0) continue;       int masky = 0;       long long T = a[i];       for (register int k = 1; k <= facy[0]; k++) {         int p = 0;         while (T % facy[k] == 0) T /= facy[k], p++;         masky |= ((p < numy[k]) << (k - 1));       }       ans += minv[masky ^ MK];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     long long a[n], sum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % 2 == 1 || n == 1) {       cout <<  NO ;     } else {       sum /= 2;       long long temp1 = 0, temp2;       map<long long, bool> m1, m2;       bool flag = false;       for (int i = 0, j = n - 1; i < n, j >= 0; i++, j--) {         temp1 += a[i];         temp2 += a[j];         if (temp1 == sum || temp2 == sum) {           flag = true;           break;         }         if (temp1 > sum) {           if (m1[temp1 - sum] == 1) {             flag = true;             break;           }         }         if (temp2 > sum) {           if (m2[temp2 - sum] == 1) {             flag = true;             break;           }         }         m1[a[i]] = 1;         m2[a[j]] = 1;       }       if (flag == true) {         cout <<  YES ;       } else {         cout <<  NO ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, c;     while (cin >> a >> b >> c) {       double m = a * c;       cout << ceil(m / b) - c << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   using ll = int64_t;   using Pii = pair<int, int>;   using ull = uint64_t;   using Vi = vector<int>;   void run();   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     run();     return 0;   }   int uplg(int n) { return 32 - __builtin_clz(n); }   int uplg(ll n) { return 64 - __builtin_clzll(n); }   int cmp(double a, double b, double eps = 1e-9) {     return (a > b + eps) - (a + eps < b);   }   constexpr ll MOD = 998244353;   struct Zp {     ll first;     Zp(ll a = 0) {       if (a < 0)         a = a % MOD + MOD;       else if (a >= MOD * 2)         a %= MOD;       else if (a >= MOD)         a -= MOD;       first = a;     }     Zp operator+(Zp r) const { return first + r.first; }     Zp operator-(Zp r) const { return first - r.first + MOD; }     Zp operator*(Zp r) const { return first * r.first; }     Zp operator/(Zp r) const { return first * r.inv().first; }     Zp operator-() const { return MOD - first; }     Zp inv() const { return pow(MOD - 2); }     Zp pow(ll e) const {       Zp t = 1, m = *this;       while (e) {         if (e & 1) t = t * m;         e >>= 1;         m = m * m;       }       return t;     }     Zp& operator+=(Zp r) { return *this = *this + r; }     Zp& operator-=(Zp r) { return *this = *this - r; }     Zp& operator*=(Zp r) { return *this = *this * r; }     Zp& operator/=(Zp r) { return *this = *this / r; }     void print() { cerr << first; }   };   struct Vert {     Vi E;     Zp f, g;   };   vector<Vert> G;   void dfs(int v, int par) {     Zp p = 1, sum = 0;     for (auto& e : (G[v].E))       if (e != par) {         dfs(e, v);         p *= Zp(1) - G[e].g / 2;         sum += G[e].f;       }     G[v].f = sum + 1 - p;     G[v].g = p;   }   void run() {     int n;     cin >> n;     G.resize(n);     for (int i = (1); i < (n); i++) {       int a, b;       cin >> a >> b;       G[a - 1].E.push_back(b - 1);       G[b - 1].E.push_back(a - 1);     }     dfs(0, -1);     cout << (G[0].f * Zp(2).pow(n)).first << endl;   }


#include <bits/stdc++.h>   using namespace std;   ifstream input;   ofstream output;   int main(int argc, char *argv[]) {     input.sync_with_stdio(false);     output.sync_with_stdio(false);     int n, tmp, tmp2;     priority_queue<int> y;     set<int> used;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tmp;       y.push(tmp);       used.insert(tmp);     }     while (1) {       tmp = y.top();       tmp2 = tmp;       y.pop();       while (tmp > 1) {         if (used.find(tmp / 2) == used.end()) {           used.insert(tmp / 2);           used.erase(tmp2);           y.push(tmp / 2);           break;         }         tmp /= 2;       }       if (tmp == 1) {         y.push(tmp2);         break;       }     }     while (y.size()) {       cout << y.top() <<    ;       y.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = INT_MAX;   const int MAX = 4e6 + 5;   const int N = 1e5 + 5;   long long dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};   long long dy[] = {0, 1, 0, -1, -1, 1, 1, -1};   char dir[] = { U ,  R ,  D ,  L };   long long power(long long a, long long b);   long long powmod(long long a, long long b, long long mod);   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long a[n];       set<long long> s;       for (long long i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       if (s.size() > k)         cout << -1 <<   n ;       else if (n == k) {         cout << k <<   n ;         for (long long i = 0; i < n; i++) cout << a[i] <<    ;         cout <<   n ;       } else {         vector<long long> tmp, res;         for (auto x : s) tmp.push_back(x);         long long m = tmp.size();         if (m < k) {           for (long long i = 0; i < k - m; i++) {             tmp.push_back(tmp[m - 1]);           }         }         m = tmp.size();         long long i = 0, j = 0;         while (i < n && j % m < m) {           if (a[i] == tmp[j % m]) {             res.push_back(a[i]);             i += 1;             j += 1;           } else {             res.push_back(tmp[j % m]);             j += 1;           }         }         cout << res.size() <<   n ;         for (auto x : res) cout << x <<    ;         cout <<   n ;       }     }   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2) res *= a;       b /= 2, a *= a;     }     return res;   }   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b % 2) res *= (a % mod);       b /= 2, a *= (a % mod);     }     return res % mod;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) : x(_x), y(_y) {}   };   struct Point p0, p1, p2;   double dist(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   double check(Point s, Point e, Point m, double t) {     if (dist(s, m) + dist(m, e) <= t + dist(s, e))       return dist(s, e) + t - dist(m, e);     double l = 0.0, r = 1.0, mid;     for (int i = 0; i <= 1000; i++) {       mid = (l + r) / 2;       Point p = Point{s.x + mid * (m.x - s.x), s.y + mid * (m.y - s.y)};       if (dist(s, p) + dist(p, e) <= t + dist(s, e))         l = mid;       else         r = mid;     }     return mid * dist(s, m);   }   int main() {     double t1, t2, x, y;     scanf( %lf%lf , &t1, &t2);     scanf( %lf%lf , &x, &y);     p0 = {x, y};     scanf( %lf%lf , &x, &y);     p1 = {x, y};     scanf( %lf%lf , &x, &y);     p2 = {x, y};     double ans = 0.0;     ans = max(ans, min(check(p0, p1, p1, t2), check(p0, p2, p1, t1)));     ans = max(ans, min(check(p0, p1, p2, t2), check(p0, p2, p2, t1)));     if (dist(p0, p2) + dist(p2, p1) <= t2 + dist(p0, p1)) {       ans = max(ans, min(dist(p0, p1) + t2, dist(p0, p2) + dist(p2, p1) + t1));     }     double low = 0.0, high = 1.0, mid, midd;     for (int i = 1; i <= 1000; i++) {       mid = low + (high - low) / 3;       midd = high - (high - low) / 3;       Point a = Point(p1.x + (p2.x - p1.x) * mid, p1.y + (p2.y - p1.y) * mid);       Point b = Point(p1.x + (p2.x - p1.x) * midd, p1.y + (p2.y - p1.y) * midd);       double r1 = min(check(p0, p1, a, t2), check(p0, p2, a, t1));       double r2 = min(check(p0, p1, b, t2), check(p0, p2, b, t1));       if (r1 > r2)         high = midd, ans = max(ans, r1);       else         low = mid, ans = max(ans, r2);     }     printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (2 * c < d || 2 * d < c || d >= b)       cout <<  -1 ;     else {       cout << 2 * a << endl << 2 * b << endl;       if (c > d)         cout << c;       else         cout << d;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     _() { ios_base::sync_with_stdio(0); }   } _;   template <class A, class B>   ostream &operator<<(ostream &o, pair<A, B> t) {     o <<  (  << t.first <<  ,   << t.second <<  ) ;     return o;   }   template <class T>   string tostring(T first, int len = 0, char c =  0 ) {     stringstream ss;     ss << first;     string r = ss.str();     if (r.length() < len) r = string(len - r.length(), c) + r;     return r;   }   template <class T>   void PV(T a, T b, int n = 0, int w = 0, string s =    ) {     int c = 0;     while (a != b) {       cout << tostring(*a++, w,    );       if (a != b && (n == 0 || ++c % n))         cout << s;       else         cout << endl;     }   }   template <class T>   inline bool chmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   inline bool chmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   }   const long long linf = 0x3f3f3f3f3f3f3f3fLL;   const int inf = 0x3f3f3f3f;   const int mod = int(1e9) + 7;   const int N = 111111;   vector<int> prime;   bool isp[N];   vector<int> oddPrime;   void generatePrime(int n = 1000000) {     memset(isp, 1, sizeof(isp));     ;     isp[0] = isp[1] = 0;     for (int i = 2; i <= n; i++) {       if (!isp[i]) continue;       prime.push_back(i);       for (int j = i + i; j <= n; j += i) {         isp[j] = 0;       }     }   }   int cnt[10000];   long long cc;   inline int isPrime(int *a, int n) {     int r = 0;     for (int i = 0; i < n; i++) r = 10 * r + a[i];     return isp[r];   }   int D[5][5], n, res;   void dfs(int r, int c) {     if (n <= 4 && r == n - 1) {       res++;       return;     }     if (n == 5 && r == n - 2) {       res += cnt[D[3][0] * 1000 + D[3][1] * 100 + D[3][2] * 10 + D[3][4]];       return;     }     for (int i = 0; i < 10; i++) {       D[r][c] = D[c][r] = i;       if (c == n - 2) {         if (isPrime(D[r], n)) dfs(r + 1, r + 1);       } else {         dfs(r, c + 1);       }       if (D[r][n - 1] == 2) break;     }   }   int main() {     generatePrime(100000);     for (int i : prime) {       int t = i;       int ok = 1;       while (t > 0) {         if (t % 10 != 2 && t % 2 == 0) ok = 0;         t /= 10;       }       if (ok) oddPrime.push_back(i);       int j = i / 100 * 10 + i % 10;       cnt[j]++;     }     int T;     cin >> T;     while (T--) {       int first;       cin >> first;       string s = tostring(first);       n = s.length();       res = 0;       for (int second : oddPrime) {         if (tostring(second).size() > n) continue;         for (int i = 0; i < n; i++) D[0][i] = D[i][0] = s[i] -  0 ;         string os = tostring(second, n);         if (os[0] != s[n - 1]) continue;         int ok = 1;         for (int i = 0; i < n; i++) {           int t = os[i] -  0 ;           D[i][n - 1] = D[n - 1][i] = t;           if (t % 2 == 0 && D[0][i] != 0) ok = 0;         }         if (ok) dfs(1, 1);       }       cout << res << endl;     }     cerr <<  [               0                ->                clock()               :            << 1e3 * (clock() - 0) / CLOCKS_PER_SEC <<  ms] n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> a;   vector<int> r;   vector<vector<pair<int, int>>> pre, suf;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       a = vector<vector<int>>(n, vector<int>(m));       r = vector<int>(n);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }         r[i] = i;       }       sort(r.begin(), r.end(), [&](int i, int j) { return a[i][0] > a[j][0]; });       pre = suf = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>(m));       for (int i = 0; i < n; i++) {         pre[i][0].first = pre[i][0].second = a[i][0];         for (int j = 1; j < m; j++) {           pre[i][j].first = min(pre[i][j - 1].first, a[i][j]);           pre[i][j].second = max(pre[i][j - 1].second, a[i][j]);         }         suf[i][m - 1].first = suf[i][m - 1].second = a[i][m - 1];         for (int j = m - 2; j >= 0; j--) {           suf[i][j].first = min(a[i][j], suf[i][j + 1].first);           suf[i][j].second = max(a[i][j], suf[i][j + 1].second);         }       }       for (int j = 0; j + 1 < m; j++) {         vector<pair<int, int>> izq(n), der(n);         izq[r[0]].first = pre[r[0]][j].first;         der[r[0]].second = suf[r[0]][j + 1].second;         for (int i = 1; i + 1 < n; i++) {           izq[r[i]].first = min(izq[r[i - 1]].first, pre[r[i]][j].first);           der[r[i]].second = max(der[r[i - 1]].second, suf[r[i]][j + 1].second);         }         izq[r[n - 1]].second = pre[r[n - 1]][j].second;         der[r[n - 1]].first = suf[r[n - 1]][j + 1].first;         for (int i = n - 2; i > 0; i--) {           izq[r[i]].second = max(izq[r[i + 1]].second, pre[r[i]][j].second);           der[r[i]].first = min(der[r[i + 1]].first, suf[r[i]][j + 1].first);         }         for (int i = 0; i + 1 < n; i++) {           if (izq[r[i]].first > izq[r[i + 1]].second &&               der[r[i + 1]].first > der[r[i]].second) {             cout <<  YES  <<   n ;             string s(n,  R );             for (int j = i + 1; j < n; j++) s[r[j]] =  B ;             cout << s <<     << j + 1 <<   n ;             goto out;           }         }       }       cout <<  NO  <<   n ;     out:;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     int n;     cin >> n;     int sp = -1, rmv = 0, ans = 0;     stack<int> st;     while (n--) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         sp = x;       } else if (t == 3) {         int x;         cin >> x;         st.push(x);       } else if (t == 2) {         ans += rmv;         rmv = 0;       } else if (t == 4) {         rmv = 0;       } else if (t == 5) {         while (st.size()) st.pop();       } else if (t == 6) {         rmv++;       }       while (st.size() && st.top() < sp) {         st.pop();         ans++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, a, counter = 0, ar[100000];     map<char, int> mp;     mp[ 6 ] = 1, mp[ 7 ] = 2, mp[ 8 ] = 3, mp[ 9 ] = 4, mp[ T ] = 5;     mp[ J ] = 6, mp[ Q ] = 7, mp[ K ] = 8, mp[ A ] = 9;     string str1, str2;     char trump;     cin >> trump;     cin >> str1 >> str2;     if (str1[1] == trump && str1[1] != str2[1])       cout <<  YES  << endl;     else if (str1[1] == str2[1] && mp[str1[0]] > mp[str2[0]])       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double ld;   typedef string str;      #define pb push_back   #define ppp pop_back   #define pii pair<int,int>   #define fi first   #define se second   #define stie std::tie   #define vec vector   #define forn(i, l, r) for (int i=l; i<=r; i++)   #define forb(i, r, l) for (int i=r; i>=l; i--)   #define emp empty   #define beg begin   #define ins insert   #define cle clear   #define era erase   #define que queue   #define pque priority_queue   #define mset multiset   #define deq deque   #define sta stack   #define con const   #define rsz resize   #define ass assign   #define lowb lower_bound   #define uppb upper_bound      template<class T> void mini(T& a, T b) { a = min(a, b); }   template<class T> void maxi(T& a, T b) { a = max(a, b); }   template<class T1, class T2> ostream& operator<<(ostream &out, pair<T1, T2> a) { return out << a.first <<     << a.second; }   template<class T> ostream& operator<<(ostream& out, vector<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T> ostream& operator<<(ostream& out, set<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T> ostream& operator<<(ostream& out, multiset<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T1, class T2> ostream& operator<<(ostream& out, map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; }   template<class T1, class T2> ostream& operator<<(ostream& out, unordered_map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; }   template<class T> ostream& operator<<(ostream& out, queue<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop(); } return out; }   template<class T> ostream& operator<<(ostream& out, deque<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop_front(); } return out; }   template<class T> ostream& operator<<(ostream& out, priority_queue<T> a) { while (!a.empty()) { out << a.top() <<   n ; a.pop(); } return out; }   template<class T> void out(T a) { cout << a << endl; }   template<class T1, class T2> void out(T1 a, T2 b) { cout << a <<     << b << endl; }   template<class T1, class T2, class T3> void out(T1 a, T2 b, T3 c) { cout << a <<     << b <<     << c << endl; }   template<class T1, class T2, class T3, class T4> void out(T1 a, T2 b, T3 c, T4 d) { cout << a <<     << b <<     << c <<     << d << endl; }   template<class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); }   template<class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] <<    ; cout << endl; }   void out() { cout <<  OK  << endl; }   template<class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); }   template<class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); }   template<class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; }   clock_t start_time; void start_timer() { start_time = clock(); }   double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }   #if __SIZEOF_INT128__ >= 16   typedef __int128 LL;   istream& operator>>(istream& in, __int128& a) { int64_t b; cin >> b; a = b; return in; }   ostream& operator<<(ostream& out, const __int128 a) {    unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c =  0123456789 [b % 10]; b /= 10; } while (b);    if (a < 0) { --c; *c =  - ; } int len = end(buf) - c; out.rdbuf()->sputn(c, len); return out;   }   #endif      vec<str> lets = { .      ,  . .    ,  ..     ,  .. .   ,  .  .   ,  ...    ,  ....   ,  . ..   ,   ..    ,   ...   ,  .   .  ,  . . .  ,  ..  .  ,  .. ..  ,  .  ..  ,  ... .  ,  .....  ,  . ...  ,   .. .  ,   ....  ,  .   .. ,  . . .. ,   ... . ,  ..  .. ,  .. ... ,  .  ... };      void Solve() {       int T;    cin >> T;    while (T--) {     vec<int> a(5);     forn(i, 0, 4) cin >> a[i];     int res = -1;     forn(i, 0, 25) {      vec<int> cur(5);      forn(j, 0, 5) {       if (lets[i][j] ==  . ) {        cur[j / 2]++;        cur[3 + j % 2]++;       }      }      if (cur == a) {       res = i;       break;      }     }     cout << char( a  + res);    }    cout <<   n ;   }      int main() {    ios_base::sync_with_stdio(0); cin.tie(0);   #ifdef LOCAL    freopen( input.txt ,  r , stdin);   #endif    start_timer();    Solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool y[200005];   long long n, m, k, j, i, p[2000005], q[2000005], haj[2000005], s, sum;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     p[1] = 0;     sum = n * (n + 1) / 2;     for (i = 1; i < n; i++) {       haj[i] = i;       cin >> q[i];       p[i + 1] = p[i] + q[i];       s += p[i + 1];     }     haj[n] = n;     sum -= s;     if (sum % n != 0) {       cout << -1 << endl;       return 0;     } else {       for (i = 1; i <= n; i++) p[i] += sum / n;       for (i = 1; i <= n; i++) {         if (p[i] < 0 || p[i] > n) {           cout << -1 << endl;           return 0;         } else if (y[p[i]]) {           cout << -1 << endl;           return 0;         } else {           y[p[i]] = true;         }       }       for (i = 1; i <= n; ++i) {         cout << p[i] << endl;       }       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ;   const double eps = 1e-8;   const int mod = 1000000007;   const int maxn = 1e5 + 7;   const double pi = acos(-1);   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f;   int n;   long long p;   struct node {     long long a, b;   } num[maxn];   bool check(double x) {     double ans = 0;     for (int i = 1; i <= n; i++) {       if (x * num[i].a - num[i].b > eps) {         ans += x * num[i].a - num[i].b;       }     }     return x * p - ans > eps;   }   int main() {     scanf( %d%lld , &n, &p);     long long sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &num[i].a, &num[i].b);       sum += num[i].a;     }     if (sum <= p) {       printf( -1 n );       return 0;     }     double ub = INF, lb = 0, mid;     for (int i = 0; i <= 100; i++) {       mid = (ub + lb) / 2;       if (check(mid))         lb = mid;       else         ub = mid;     }     printf( %.7f n , ub);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-11;   int countbit(int n) { return (n == 0) ? 0 : 1 + countbit(n & (n - 1)); }   int lowbit(int n) { return n & (n ^ (n - 1)); }   string toString(long long v) {     ostringstream sout;     sout << v;     return sout.str();   }   string toString(int v) {     ostringstream sout;     sout << v;     return sout.str();   }   int Rand16() { return rand(); }   int Rand32() { return rand() * rand(); }   double DRand() { return (double)rand() / RAND_MAX; }   int RandRange(int f, int r) { return f + (int)(DRand() * (r - f) + 0.5); }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     int i, j;     int ans = 0;     for (i = 2; i < n; i++) {       int tmp = n;       while (tmp) ans += tmp % i, tmp /= i;     }     int d = gcd(ans, n - 2);     int A = ans / d;     int B = (n - 2) / d;     cout << A <<  /  << B << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int N, Q;     scanf( %d%d , &N, &Q);     int et[N + 1];     memset(et, -1, sizeof(et));     while (Q-- > 0) {       int t, k, d;       scanf( %d%d%d , &t, &k, &d);       int ans = -1;       int as = 0;       for (int i = 1; i <= N; i++) {         if (t > et[i]) et[i] = -1;         if (et[i] == -1) as++;       }       if (as >= k) {         ans = 0;         for (int i = 1; i <= N && k > 0; i++) {           if (et[i] == -1) {             ans += i;             k--;             et[i] = t + d - 1;           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 0;   const int N = 100005;   vector<array<int, 2>> v[N];   vector<set<int>> g(N);   vector<int> depth(N, 0);   vector<vector<int>> p(N, vector<int>(17, 0));   vector<long long> up(N, 0);   vector<long long> down(N, 0);   vector<int> sz(N, 0);   vector<int> ch[N];   vector<int> st[N];   vector<long long> pw(N, 1);   vector<long long> inv(N, 1);   long long res = 0;   int root = 0;   void dfs(int a) {     depth[a] = depth[p[a][0]] + 1;     for (int i = 1; i < 17; i++) p[a][i] = p[p[a][i - 1]][i - 1];     for (auto [to, k] : v[a]) {       if (to == p[a][0]) continue;       p[to][0] = a;       down[to] = (10 * down[a] + k) % mod;       up[to] = (pw[depth[a] - 1] * k + up[a]) % mod;       dfs(to);     }   }   int lca(int a, int b) {     if (depth[a] > depth[b]) swap(a, b);     for (int i = 16; i >= 0; i--)       if (depth[p[b][i]] >= depth[a]) b = p[b][i];     if (a == b) return a;     for (int i = 16; i >= 0; i--) {       if (p[a][i] != p[b][i]) {         a = p[a][i];         b = p[b][i];       }     }     return p[a][0];   }   int dist(int a, int b) { return depth[a] + depth[b] - 2 * depth[lca(a, b)]; }   long long h(int a, int b) {     int l = lca(a, b);     long long x = (((up[a] - up[l] + mod) % mod) * inv[depth[l] - 1]) % mod;     long long y =         (((down[b] - pw[depth[b] - depth[l]] * down[l]) % mod) + mod) % mod;     long long z = (pw[depth[b] - depth[l]] * x + y) % mod;     return z;   }   void find_sz(int a, int par = 0) {     sz[a] = 1;     for (int to : g[a]) {       if (to == par) continue;       find_sz(to, a);       sz[a] += sz[to];     }   }   int find_centroid(int a, int par, int n) {     for (int to : g[a]) {       if (to == par) continue;       if (sz[to] > n / 2) return find_centroid(to, a, n);     }     return a;   }   void build_cd(int a, int par = 0) {     find_sz(a);     int n = sz[a];     int centroid = find_centroid(a, 0, n);     if (par == 0) root = centroid;     ch[par].push_back(centroid);     for (int to : g[centroid]) {       g[to].erase(centroid);       build_cd(to, centroid);     }   }   long long fpow(long long b, long long e) {     long long x = 1;     while (e) {       if (e & 1) x = (x * b) % mod;       b = (b * b) % mod;       e /= 2;     }     return x;   }   long long find_inv() {     long long x = mod;     long long tmp = mod;     for (long long i = 2; i * i <= tmp; i++) {       if ((tmp % i) == 0) {         x /= i;         x *= (i - 1);       }       while ((tmp % i) == 0) tmp /= i;     }     if (tmp > 1) {       x /= tmp;       x *= (tmp - 1);     }     return fpow(10, x - 1);   }   void solve(int a) {     map<int, int> m;     for (int to : ch[a]) {       solve(to);       for (int x : st[to]) {         m[h(x, a)]++;         st[a].push_back(x);       }     }     res += m[0];     st[a].push_back(a);     for (int to : ch[a]) {       for (int x : st[to]) m[h(x, a)]--;       for (int x : st[to]) {         long long z = h(a, x);         if (z == 0) res++;         long long val = (((-z * inv[dist(a, x)]) % mod) + mod) % mod;         res += m[val];       }       for (int x : st[to]) m[h(x, a)]++;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n >> mod;     for (int i = 0; i < n - 1; i++) {       int a, b, k;       cin >> a >> b >> k;       a++;       b++;       v[a].push_back({b, k});       v[b].push_back({a, k});       g[a].insert(b);       g[b].insert(a);     }     for (int i = 1; i <= n; i++) pw[i] = (10 * pw[i - 1]) % mod;     inv[1] = find_inv();     for (int i = 2; i <= n; i++) inv[i] = (inv[i - 1] * inv[1]) % mod;     dfs(1);     build_cd(1);     solve(root);     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int seq[100];   void display(const int n) {     for (int i = 0; i < n; ++i) printf( %d  , seq[i]);     putchar(  n );   }   int compute_sum(const int n) {     int sum = 0;     for (int i = 0; i < n; ++i) {       int x = seq[i];       for (int j = i; j < n; ++j) {         x = min(x, seq[j]);         sum += x;       }     }     return sum;   }   bool solve(const int n, int m) {     for (int i = 0; i < n; ++i) seq[i] = i + 1;     int best = 0;     do {       const int sum = compute_sum(n);       best = max(best, sum);     } while (next_permutation(seq, seq + n));     for (int i = 0; i < n; ++i) seq[i] = i + 1;     do {       const int sum = compute_sum(n);       if (sum == best) {         if (--m == 0) {           display(n);           return true;         }       }     } while (next_permutation(seq, seq + n));     return false;   }   void s(const long long x, const long long y, const int first) {     printf( visiting with x=%lld, y=%lld, first=%d n , x, y, first);     if (x <= 0) return;     assert(y < x);     long long delta = max(1LL, x >> 1);     long long index = 0;     int movements = 0;     for (;;) {       printf( index = %lld, delta = %lld, movements = %d n , index, delta,              movements);       if (index + delta <= y) {         movements += 1;         index += delta;       } else {         cout << first + movements <<     << endl;         s(x >> 1, y - index, first + 1);         break;       }       delta = max(1LL, delta >> 1);     }   }   vector<int> v;   void compute(const int l, const int r, long long m) {     if (l > r) return;     if (l == r) {       v.push_back(l);       return;     }     const long long x = 1LL << (r - l);     long long delta = max(1LL, x >> 1);     int movements = 0;     for (;;) {       const long long new_m = m - delta;       if (new_m >= 0) {         m = new_m;         movements += 1;         delta = max(1LL, delta >> 1);       } else {         const int first_digit = l + movements;         v.push_back(first_digit);         compute(first_digit + 1, r, m);         for (int i = l + movements - 1; i >= l; --i) v.push_back(i);         break;       }     }   }   void solve_fast(const int n, long long m) {}   void test() {     for (int n = 1; n <= 5; ++n) {       for (int m = 1; m <= 100; ++m) {         if (m <= 1LL << (n - 1)) {           if (solve(n, m)) {             v.clear();             compute(1, n, m - 1);             for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);             putchar(  n );           }         }       }       putchar(  n );     }   }   void run() {     int n;     long long m;     cin >> n >> m;     v.clear();     compute(1, n, m - 1);     for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);     putchar(  n );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   const int inf = 1039074182;   using namespace std;   int n, r, c;   string word[1000005];   int len[1000005];   int nxt[1000005];   pair<int, int> st[1000005][22];   int sum[1000005];   int calc(int start) {     int res = 0;     for (int i = 0; i < 22; i++) {       if ((1 << i) & r) {         res += st[start][i].second;         start = st[start][i].first;       }     }     return res;   }   void print(int start) {     for (int i = 0; i < r; i++) {       if (start == n) break;       for (int j = start; j < nxt[start]; j++) {         cout << word[j];         if (j != nxt[start] - 1) cout <<    ;       }       cout << endl;       start = nxt[start];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> r >> c;     for (int i = 0; i < n; i++) {       cin >> word[i];       len[i] = word[i].size();     }     sum[0] = len[0] + 1;     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + len[i] + 1;     }     for (int i = 0, j = 0; i < n; i++) {       while (j < n && sum[j] - (i ? sum[i - 1] : 0) - 1 <= c) j++;       nxt[i] = j;     }     for (int i = 0; i < n; i++) {       st[i][0] = make_pair(nxt[i], nxt[i] - i);     }     for (int i = 0; i < 22; i++) {       st[n][i] = make_pair(n, 0);     }     for (int k = 1; k < 22; k++) {       for (int i = 0; i < n; i++) {         st[i][k].first = st[st[i][k - 1].first][k - 1].first;         st[i][k].second =             st[i][k - 1].second + st[st[i][k - 1].first][k - 1].second;       }     }     int res = -1, maxk = -1;     int temp;     for (int i = 0; i < n; i++) {       temp = calc(i);       if (temp > res) {         res = temp;         maxk = i;       }     }     print(maxk);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string a, b, c, d, e;   vector<vector<int> > vals;   vector<vector<int> > forms(1);   map<string, int> getind;   int doop(int left, int right, int op) {     if (op == 2) return left ^ right;     if (op == 3)       return left & right;     else       return left | right;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     vals.resize(1, vector<int>(m, 0));     getind[ ? ] = 0;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       getind[a] = vals.size();       vals.resize(vals.size() + 1);       forms.resize(forms.size() + 1);       if (c[0] !=  1  && c[0] !=  0 ) {         cin >> d >> e;         int first = getind[c];         int sec = getind[e];         int op = 2;         if (d ==  AND )           op = 3;         else if (d ==  OR )           op = 4;         forms[forms.size() - 1].push_back(first);         forms[forms.size() - 1].push_back(op);         forms[forms.size() - 1].push_back(sec);         for (int j = 0; j < m; j++) {           vals[vals.size() - 1].push_back(doop(vals[first][j], vals[sec][j], op));         }       } else {         for (int j = 0; j < m; j++) {           if (c[j] ==  1 )             vals[vals.size() - 1].push_back(1);           else             vals[vals.size() - 1].push_back(0);         }       }     }     vector<int> best(m, 0);     vector<int> worst(m, 0);     for (int i = 0; i < m; i++) {       int curcnt = 0;       int rescnt = 0;       for (int j = 1; j <= n; j++) {         if (forms[j].size() > 0) {           curcnt += vals[j][i];         }       }       vals[0][i] = 1;       for (int j = 1; j <= n; j++) {         if (forms[j].size() > 0) {           int first = forms[j][0];           int sec = forms[j][2];           int op = forms[j][1];           int res = doop(vals[first][i], vals[sec][i], op);           vals[j][i] = res;           rescnt += res;         }       }       if (rescnt > curcnt) best[i] = 1;       if (rescnt < curcnt) worst[i] = 1;     }     for (int i = 0; i < m; i++) {       cout << worst[i];     }     cout <<   n ;     for (int i = 0; i < m; i++) {       cout << best[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r, c;   int main() {     int n;     scanf( %d , &n);     while (n--) {       scanf( %d %d , &r, &c);       for (int i = 0; i < r; i++) {         for (int j = 0; j < c; j++)           if (i == r - 1 && j == c - 1)             printf( W );           else             printf( B );         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * (100000) + 5;   int a[MAXN], b[MAXN];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     int res = 0;     int j = 0;     for (int i = 0; i < n && j < n; ++i) {       while (j < n && a[i] != b[j]) {         j++;         res++;       }       j++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n, long long m) {     long long x, y;     if (n > m) {       y = n;       x = m;     } else {       y = m;       x = n;     }     if (y % x == 0)       return x;     else {       return gcd(x, y % x);     }   }   int main() {     long long n;     cin >> n;     string str;     cin >> str;     long long m = n;     for (long long i = 0; i < n; i += 2) {       if (m - 2 == 1) {         cout << str[i] << str[i + 1] << str[i + 2];         break;       } else {         cout << str[i] << str[i + 1];         if (m - 2 != 0) cout <<  - ;       }       m -= 2;     }   }


#include <bits/stdc++.h>   int q, n;   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       int b = sqrt(2 * n + 4);       while ((b + 1) * (b + 2) / 2 > n) b--;       int a = n - (b + 1) * (b + 2) / 2;       printf( 133 );       for (int i = 1; i <= a; i++) printf( 7 );       for (int i = 1; i <= b; i++) printf( 3 );       printf( 7 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e;   int ar[200100];   int ar1[200100];   int main() {     vector<int> arr(200100);     string s, s1;     cin >> s;     cin >> s1;     a = min(s.length(), s1.length());     b = a;     c = 1;     while ((c <= a) && (s[s.length() - c] == s1[s1.length() - c])) ++c;     cout << (a - c + 1) + max(s.length(), s1.length()) - c + 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long t[n + 1], c[n + 1];     for (int i = 1; i <= n; i++) {       cin >> t[i] >> c[i];       t[i]++;       if (t[i] > n) {         t[i] = n;       }     }     long long dp[n + 1][n + 1];     for (int i = 1; i < n + 1; i++) {       dp[0][i] = 100000000000000;     }     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= 0; --j) {         dp[i][j] = dp[i - 1][j];         if (j >= t[i]) {           dp[i][j] = min(dp[i][j], dp[i - 1][j - t[i]] + c[i]);         }         if (j != n) {           dp[i][j] = min(dp[i][j], dp[i][j + 1]);         }       }     }     cout << dp[n][n];   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   const int mod = 998244353;   long long n, k, ans;   long long dp[N][N], dp2[N];   signed main() {     cin >> n >> k;     dp[0][0] = 1;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= i; j++) {         for (long long l = i - j; l <= i - 1; l++) {           dp[i][j] = (dp[i][j] + dp[l][min(l, j)]) % mod;         }       }     }     for (long long i = 1; i <= n; i++) {       dp2[i] = (dp[n][i] - dp[n][i - 1] + mod) % mod;     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         if (k > i * j) ans = (ans + (dp2[i] * dp2[j] % mod)) % mod;       }     }     cout << (ans * 2) % mod;     return 0;   }