#include <bits/stdc++.h>   using namespace std;   template <typename T, typename T1>   T amax(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T &a, T1 b) {     if (b < a) a = b;     return a;   }   bool isPrime(long long x) {     if (x == 1) return false;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long gcdByBit(long long a, long long b) {     if (!a || !b) return a | b;     unsigned shift = __builtin_ctz(a | b);     a >>= __builtin_ctzl(a);     do {       b >>= __builtin_ctzl(b);       if (a > b) {         swap(a, b);       }       b -= a;     } while (b);     return a << shift;   }   long long powerMod(long long n, long long p) {     long long res = 1;     while (p) {       if (p % 2 == 0) {         n = n * 1ll * n % 1000000007;         p /= 2;       } else {         res = res * 1ll * n % 1000000007;         p--;       }     }     return res;   }   long long powerMod2(long long b, long long p, long long m) {     if (p == 0) return 1;     return (b * powerMod2(b, p - 1, m) % m) % m;   }   long long fact(long long n) {     long long res = 1;     for (long long i = 1; i <= n; i++) {       res = res * 1ll * i % 1000000007;     }     return res;   }   long long nCr(long long n, long long r) {     return fact(n) * 1ll * powerMod(fact(r), 1000000007 - 2) % 1000000007 * 1ll *            powerMod(fact(n - r), 1000000007 - 2) % 1000000007;   }   long long arr[300005];   long long ans[300005];   long long parent(long long x) {     if (arr[x] != x) arr[x] = parent(arr[x]);     return arr[x];   }   void Chaliye_Shuru_Karte_Hai() {     for (long long i = 0; i < 300005; i++) arr[i] = i;     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       for (long long j = parent(a); j <= b; j = parent(j + 1)) {         if (j != c) ans[j] = c, arr[j] = j + 1;       }     }     for (long long i = 1; i < n + 1; i++) cout << ans[i] <<    ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tc = 1;     while (tc--) {       Chaliye_Shuru_Karte_Hai();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int M = 101;   const double EPS = 1e-9;   const int INF = 1e9;   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 * b / gcd(a, b); }   double getDist(complex<double> a, complex<double> b) {     return sqrt((a.real() - b.real()) * (a.real() - b.real()) +                 (a.imag() - b.imag()) * (a.imag() - b.imag()));   }   int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }   long long mod = 1000000007, fib[N], dp[N][N];   long long power(long long base, int p) {     if (!p) return 1;     long long ret = power(base, p / 2);     ret *= ret;     ret %= mod;     if (p & 1) ret *= base, ret %= mod;     return ret;   }   long long modInverse(int a) { return power(a, mod - 2); }   long long ncr(int n, int r) {     return (((fib[n] * modInverse(fib[r])) % mod) * modInverse(fib[n - r])) % mod;   }   bool emty[N], taken[N];   long long solve(int n, int k) {     if (k == 0) return fib[n];     if (k == 1) return (fib[n] * n) % mod;     if (dp[n][k] != -1) return dp[n][k];     long long ret =         (solve(n, k - 1) * n) % mod + (solve(n + 1, k - 2) * (k - 1)) % mod;     return dp[n][k] = ret % mod;   }   int main() {     fib[0] = fib[1] = 1;     for (int i = 2; i < N; i++) fib[i] = (fib[i - 1] * i) % mod;     int n, free = 0, k = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       if (a == -1)         emty[i] = 1;       else         taken[a] = 1;     }     for (int i = 1; i <= n; i++) {       if (emty[i] == 1) {         if (taken[i] == 1)           free++;         else           k++;       }     }     memset(dp, -1, sizeof(dp));     cout << solve(free, k);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long N;   long long i, j;   vector<long long> v;   map<long long, long long> mp;   long long arr[200];   int main() {     scanf( %lld , &N);     for (i = 0; i < N; i++) scanf( %lld , &arr[i]);     sort(arr, arr + N);     long long ans = 0;     for (i = 0; i < N; i++) {       long long get = arr[i];       if (mp[arr[i]] == 1) {         continue;       } else {         ans++;         for (j = 1; j < 200; j++) {           mp[get * j] = 1;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxd = 1e6 + 10;   int a[maxd];   long long sum, ans = 1e18;   vector<long long> b;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) sum += a[i];     if (sum == 1) {       printf( -1 n );       return 0;     }     for (long long i = 2; i * i <= sum; i++) {       if (sum % i == 0) {         b.push_back(i);         sum /= i;         i--;       }     }     b.push_back(sum);     for (auto x : b) {       long long res = 0;       sum = 0;       for (int i = 1; i <= n; i++) {         sum += a[i];         sum %= x;         res += min(sum, x - sum);       }       ans = min(res, ans);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a;   vector<int> q;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       bool w = true;       for (int j = 0; j < n; j++) {         scanf( %d , &a);         if (a == 1 || a == 3) w = false;       }       if (w) q.push_back(i + 1);     }     printf( %d n , q.size());     for (int i = 0; i < q.size(); i++) printf( %d  , q[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool can(bool print, int t, long long S, const vector<pair<int, int> >& bugs,            const vector<pair<int, pair<int, int> > >& st) {     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         pq;     int ind = bugs.size() - 1;     int stind = st.size() - 1;     vector<int> ans(bugs.size());     long long cost = 0;     while (ind >= 0) {       while (stind >= 0 and st[stind].first >= bugs[ind].first) {         pq.push(pair<int, int>(st[stind].second.first, st[stind].second.second));         --stind;       }       if (pq.empty()) return false;       long long c = pq.top().first;       int indans = pq.top().second;       pq.pop();       cost += c;       if (cost > S) return false;       for (int i = 0; ind >= 0 and i < t; ++i) {         ans[bugs[ind].second] = indans;         --ind;       }     }     if (print) {       for (int i = 0; i < int(bugs.size()); ++i) cout << (i ?     :   ) << ans[i];       cout << endl;     }     return true;   }   int main() {     int n, m, s;     cin >> n >> m >> s;     vector<pair<int, int> > bugs(m);     for (int i = 0; i < m; ++i) {       cin >> bugs[i].first;       bugs[i].second = i;     }     vector<pair<int, pair<int, int> > > st(n);     for (int i = 0; i < n; ++i) cin >> st[i].first;     for (int i = 0; i < n; ++i) {       cin >> st[i].second.first;       st[i].second.second = i + 1;     }     sort(bugs.begin(), bugs.end());     sort(st.begin(), st.end());     int low = 1, hi = m + 1;     while (low < hi) {       int mid = (low + hi) / 2;       if (can(false, mid, s, bugs, st))         hi = mid;       else         low = mid + 1;     }     if (low == m + 1)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       can(true, low, s, bugs, st);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 10;   int n, m, q, pos[MAX], bit[MAX], res[MAX], XOR[MAX];   pair<int, int> cache[MAX], a[MAX], b[MAX];   struct Node {     int lef, rig, tt;     bool operator<(const Node& other) const { return this->lef < other.lef; }   };   Node query[MAX];   void up(int i) {     int val = a[i].first;     while (i <= n) {       bit[i] ^= val;       i += i & (-i);     }   }   int get(int i) {     int res = 0;     while (i) {       res ^= bit[i];       i -= i & (-i);     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &cache[i].first);       a[i].first = cache[i].first;       cache[i].second = i;     }     sort(cache + 1, cache + 1 + n);     for (int i = 1; i <= n; ++i) {       if (i == 1 || cache[i].first > cache[i - 1].first) ++m;       a[cache[i].second].second = m;     }     for (int i = 1; i <= n; ++i) {       b[i] = pair<int, int>(pos[a[i].second], i);       pos[a[i].second] = i;       XOR[i] = XOR[i - 1] ^ a[i].first;     }     sort(b + 1, b + 1 + n);     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       scanf( %d %d , &query[i], &query[i].rig);       query[i].tt = i;     }     sort(query + 1, query + 1 + q);     int j = 1;     for (int i = 1; i <= q; ++i) {       while (j <= n && b[j].first < query[i].lef) up(b[j++].second);       res[query[i].tt] = XOR[query[i].rig] ^ XOR[query[i].lef - 1];       res[query[i].tt] ^= get(query[i].rig) ^ get(query[i].lef - 1);     }     for (int i = 1; i <= q; ++i) printf( %d n , res[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, l[101], r[101], k;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     cin >> k;     for (int i = 0; i < n; i++) {       if (k <= r[i]) {         a++;       }     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> ans1, ans2;       string a, b;       cin >> a >> b;       a = a +  0 ;       b = b +  0 ;       for (int i = 0; i < n; i++) {         if (a[i] != a[i + 1]) ans1.push_back(i);       }       for (int i = 0; i < n; i++) {         if (b[i] != b[i + 1]) ans2.push_back(i);       }       cout << ans1.size() + ans2.size() <<    ;       for (int i = 0; i < ans1.size(); i++) cout << ans1[i] + 1 <<    ;       for (int i = ans2.size() - 1; i >= 0; i--) cout << ans2[i] + 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p, x, a, b, ni, ans;   void e_gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     e_gcd(b, a % b, x, y);     int tmp = x;     x = y;     y = tmp - (a / b) * y;     return;   }   int main() {     cin >> a >> b >> p >> x;     long long i, j, s;     e_gcd(a, p, ni, s);     a = 1;     for (j = 1; j <= p - 1; j++) {       a = a * ni % p;       i = (j - b * a % p + p) % p;       long long n = i * (p - 1) + j;       if (n <= x) ans += (x - n) / (p * (p - 1)) + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int *a = new int[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int m;     scanf( %d , &m);     int bred[10000];     for (int i = 0; i < 10000; i++) bred[i] = 0;     for (int i = 0; i < m; i++) {       int b;       scanf( %d , &b);       for (int j = 0; j < n; j++) {         if (b % a[j] != 0) continue;         bred[b / a[j]]++;       }     }     for (int i = 9999; i >= 0; i--) {       if (bred[i] != 0) {         printf( %d , bred[i]);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   inline int rd(int f = 1, int x = 0, char ch =    ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 1e5 + 5;   int n, a[N], ans;   int main() {     for (int T = rd(); T--;) {       n = rd(), ans = 0;       for (int i = 1; i <= n; ++i) a[i] = rd();       for (int i = 2; i <= n; ++i) ans |= a[i - 1] <= a[i];       puts(ans ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int INF = 2e9;   int main() {     int t;     t = 1;     while (t--) {       int n;       string s;       cin >> n;       cin >> s;       int res = 0;       for (int d = 25; d >= 0; d--) {         string tmp =   ;         for (int i = 0; i < s.size(); i++) {           int now = s[i] -  a ;           if (now != d) {             tmp += s[i];           } else {             if (tmp.back() -  a  == d - 1) {               res++;             } else {               tmp += s[i];             }           }         }         swap(s, tmp);         tmp =   ;         for (int i = s.size() - 1; i >= 0; i--) {           int now = s[i] -  a ;           if (now != d) {             tmp += s[i];           } else {             if (tmp.back() -  a  == d - 1) {               res++;             } else {               tmp += s[i];             }           }         }         reverse(tmp.begin(), tmp.end());         swap(s, tmp);       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 2e5 + 5;   int n, k, d, ansL = 1, ansR = 1, top1, top2;   int a[MAXN], st1[MAXN], st2[MAXN];   map<int, int> lst;   namespace SegmentTree {   struct Tree {     int l, r;     int w, tag;   } tree[MAXN << 2];   void update(int k) { tree[k].w = min(tree[k << 1].w, tree[k << 1 | 1].w); }   void apply(int k, int val) {     tree[k].w += val;     tree[k].tag += val;   }   void down(int k) {     if (tree[k].tag != 0) {       apply(k << 1, tree[k].tag);       apply(k << 1 | 1, tree[k].tag);       tree[k].tag = 0;     }   }   void Build(int k, int l, int r) {     tree[k].l = l;     tree[k].r = r;     if (l == r) {       tree[k].w = l;       return;     }     int mid = (l + r) >> 1;     Build(k << 1, l, mid);     Build(k << 1 | 1, mid + 1, r);     update(k);   }   void Modify(int k, int l, int r, int val) {     if (tree[k].l >= l && tree[k].r <= r) {       apply(k, val);       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (l <= mid) Modify(k << 1, l, r, val);     if (r > mid) Modify(k << 1 | 1, l, r, val);     update(k);   }   void Delete(int k, int x) {     if (tree[k].l == tree[k].r) {       tree[k].w = INF;       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (x <= mid)       Delete(k << 1, x);     else       Delete(k << 1 | 1, x);     update(k);   }   int Query(int k, int l, int r, int x) {     if (tree[k].w > x) return INF;     if (tree[k].l == tree[k].r) return tree[k].l;     if (tree[k].l >= l && tree[k].r <= r) {       down(k);       if (tree[k << 1].w <= x)         return Query(k << 1, l, r, x);       else         return Query(k << 1 | 1, l, r, x);     } else {       down(k);       int mid = (tree[k].l + tree[k].r) >> 1;       int res;       if (l <= mid) {         res = Query(k << 1, l, r, x);         if (res != INF) return res;       }       if (r > mid) {         res = Query(k << 1 | 1, l, r, x);         if (res != INF) return res;       }       return -1;     }   }   }  // namespace SegmentTree   int main() {     scanf( %d%d%d , &n, &k, &d);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] += INF;     }     if (d == 0) {       for (int i = 1; i <= n; i++) {         int l = i;         while (a[i] == a[i + 1] && i < n) i += 1;         if (i - l + 1 > ansR - ansL + 1) {           ansL = l;           ansR = i;         }       }       printf( %d %d n , ansL, ansR);       return 0;     }     SegmentTree::Build(1, 1, n);     int L = 1;     for (int R = 1; R <= n; R++) {       int tmp = L;       if (a[R] % d == a[R - 1] % d)         L = max(lst[a[R]] + 1, L);       else         L = R;       lst[a[R]] = R;       while (tmp < L) {         SegmentTree::Delete(1, tmp);         tmp += 1;       }       while (top1 && st1[top1] >= L && a[st1[top1]] >= a[R]) {         SegmentTree::Modify(1, max(L, st1[top1 - 1] + 1), st1[top1],                             a[st1[top1]] / d);         top1 -= 1;       }       SegmentTree::Modify(1, max(L, st1[top1] + 1), R, -a[R] / d);       st1[++top1] = R;       while (top2 && st2[top2] >= L && a[st2[top2]] <= a[R]) {         SegmentTree::Modify(1, max(L, st2[top2 - 1] + 1), st2[top2],                             -a[st2[top2]] / d);         top2 -= 1;       }       SegmentTree::Modify(1, max(L, st2[top2] + 1), R, a[R] / d);       st2[++top2] = R;       int pos = SegmentTree::Query(1, L, R, k + R);       if (R - pos + 1 > ansR - ansL + 1) {         ansL = pos;         ansR = R;       }     }     printf( %d %d n , ansL, ansR);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long add(long long a, long long b, long long mod) {     return (a % mod + b % mod) % mod;   }   long long sub(long long a, long long b, long long mod) {     return (a % mod - b % mod + mod) % mod;   }   long long mul(long long a, long long b, long long mod) {     return (a % mod * b % mod) % mod;   }   long long sumodd(long long num, long long mod) { return mul(num, num, mod); }   long long sumeven(long long num, long long mod) {     return mul(num, num + 1, mod);   }   long long sumrange(long long st, long long en, long long num) {     return (num * (st + en) / 2);   }   long long gcd(long long a, long long b) {     while (b != 0) {       long long a2 = a;       a = b;       b = a2 % b;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   string makeitbinary(long long n) {     string s;     while (n) {       s = s + (char)((n % 2) +  0 );       n /= 2;     }     reverse(s.begin(), s.end());     return s;   }   bool bit(int num, int i) { return ((num >> i) & 1); }   long long fastpowermod(long long b, long long p, long long mod) {     long long ans = 1;     while (p) {       if (p % 2) {         ans = mul(ans, b, mod);       }       b = mul(b, b, mod);       p /= 2;     }     return ans;   }   long long fastpower(long long b, long long p) {     long long ans = 1;     while (p) {       if (p % 2) {         ans = ans * b;       }       b = b * b;       p /= 2;     }     return ans;   }   double fastpower_double(double b, long long p) {     double ans = 1;     while (p) {       if (p % 2) {         ans = ans * b;       }       b = b * b;       p /= 2;     }     return ans;   }   long long summation_formula(long long n) { return (n * (n + 1) / 2); }   bool lower_vowel(char c) {     return (c ==  i  || c ==  o  || c ==  u  || c ==  a  || c ==  e );   }   string bigint_mini(string s1, string s2) {     if (s1.size() > s2.size()) {       return s2;     } else if (s2.size() > s1.size()) {       return s1;     }     for (int i = 0; i < s1.size(); i++) {       if ((s1[i] -  0 ) > (s2[i] -  0 )) {         return s2;       } else if ((s2[i] -  0 ) > (s1[i] -  0 )) {         return s1;       }     }     return s1;   }   double polygon_area(int n, vector<double> X, vector<double> Y) {     double area = 0.0;     int j = n - 1;     for (int i = 0; i < n; i++) {       area += (X[j] + X[i]) * (Y[j] - Y[i]);       j = i;     }     return abs(area / 2.0);   }   long long sum_of_digits(string s) {     long long sum = 0;     for (int i = 0; i < s.size(); i++) {       sum += s[i] -  0 ;     }     return sum;   }   string makeitbase(long long num, long long base) {     string s;     while (num) {       long long mod = num % base;       s += (mod +  0 );       num /= base;     }     reverse(s.begin(), s.end());     return s;   }   bool intersect(long long l1, long long r1, long long l2, long long r2) {     return (max(l1, l2) <= min(r1, r2));   }   pair<long long, long long> find_intersection(long long l1, long long r1,                                                long long l2, long long r2) {     return {max(l1, l2), min(r1, r2)};   }   long long sum_ranges(long long l, long long r) {     return summation_formula(r) - summation_formula(l);   }   double power_2(double num) { return num * num; }   struct point {     int x, y;   };   long long dist(point p1, point p2) {     return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);   }   bool square(point p1, point p2, point p3, point p4) {     long long d2 = dist(p1, p2);     long long d3 = dist(p1, p3);     long long d4 = dist(p1, p4);     if (d2 == d3 && 2 * d2 == d4 && 2 * dist(p2, p4) == dist(p2, p3)) {       return true;     }     if (d3 == d4 && 2 * d3 == d2 && 2 * dist(p3, p2) == dist(p3, p4)) {       return true;     }     if (d2 == d4 && 2 * d2 == d3 && 2 * dist(p2, p3) == dist(p2, p4)) {       return true;     }     return false;   }   const int sz = 1e6 + 1;   long long M = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k, m, t;     cin >> n >> k >> m >> t;     while (t--) {       int x, y;       cin >> x >> y;       if (x == 1) {         if (y <= k) {           k++;         }         n++;       } else {         if (k >= 1 && k <= y) {           n -= (n - y);         } else {           n -= y;           k -= y;         }       }       cout << n <<     << k << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int f = n * 1.0 / 3 + 0.5;     cout << f / 12 <<     << f % 12 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX1 = 3e5 + 10;   long long a, b, c, d, e, cnt, x, y, z, l, r, flag, num[MAX1], mod = 1e10 + 7;   string s;   char p[MAX1];   long long sta(long long n) {     for (int i = 1; i < 1000000; ++i) {       if (i * (i - 1) / 2 == n) return i;     }     return 0;   }   int main() {     cin >> a >> b >> c >> d;     x = sta(a);     y = sta(d);     if (a == 0) {       if (b == 0 && c == 0 && x && y) {         for (int i = 0; i < y; ++i) cout << 1;         return 0;       } else         x = 1;     }     if (d == 0) {       if (b == 0 && c == 0 && x && y) {         for (int i = 0; i < x; ++i) cout << 0;         return 0;       } else         y = 1;     }     if (x == 0 || y == 0) {       cout <<  Impossible ;       return 0;     }     if (x * y != b + c) {       cout <<  Impossible ;       return 0;     }     cnt = b / y;     b -= cnt * y;     x -= cnt;     for (long long i = 0; i < cnt; ++i) cout << 0;     for (long long i = 0; i < y - b; ++i) cout << 1;     y -= y - b;     if (x && b) cout << 0, --x;     for (long long i = 0; i < y; ++i) cout << 1;     for (long long i = 0; i < x; ++i) cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigpow(long long x, long long n) {     if (n == 0) return 1;     long long temp = bigpow(x, n / 2);     return n % 2 == 0 ? (temp * temp) % 1000000009                       : (x * ((temp * temp) % 1000000009)) % 1000000009;   }   int main() {     long long n, m, k, x, t, p, q, gaps, groups;     cin >> n >> m >> k;     gaps = n - m;     groups = m % (k - 1) == 0 ? m / (k - 1) : m / (k - 1) + 1;     if (gaps >= groups - 1)       cout << m << endl;     else {       x = n - gaps * k;       t = 2 * (bigpow(2, x / k) - 1) * k + x % k;       t += gaps * (k - 1);       cout << t % 1000000009 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 0;   int a[5], m;   long long sum(int len, int x) {     return 1LL * len * x - 1LL * (x + 1) * x / 2 + x;   }   long long cal(int x, int y, int bar, int len) {     if (len < 0) return 0;     int R = min(bar - y, len), L = min(len - (bar - x), R);     long long ans = 0;     if (L >= 0)       ans += 1LL * (L + 1) * (bar - x + 1);     else       L = -1;     ans += sum(len, R) - sum(len, L);     return ans;   }   long long solve(int x, int y, int z, int len) {     int tmp = max(max(y, z) + 1, x);     len -= tmp - x;     x = tmp;     long long ans = 0;     for (auto i = 0; i <= len; i++) {       int cur = x + i, rem = min(2 * (cur - 1) - y - z, len - i);       if (rem > cur - y - z)         ans += cal(y, z, cur - 1, rem) - cal(y, z, cur - 1, (cur - y - z));     }     return ans;   }   long long solve2(int x, int y, int z, int len) {     int tmp = max(x, y);     len -= 2 * tmp - x - y;     x = tmp;     if (x <= z) len -= 2 * (z + 1 - x), x = z + 1;     long long ans = 0;     if (len >= 0)       for (auto i = 0; i <= len / 2; i++) {         int rem = len - 2 * i;         ans += min(x + i - 1 - z, rem) + 1;       }     return ans;   }   int main() {     for (auto i = 0; i <= 2; i++) cin >> a[i];     cin >> m;     long long ans = 0;     for (auto i = 0; i <= 2; i++)       ans += solve(a[i], a[(i + 1) % 3], a[(i + 2) % 3], m);     for (auto i = 0; i <= 2; i++)       ans += solve2(a[i], a[(i + 1) % 3], a[(i + 2) % 3], m);     int tmp = *max_element(a, a + 3), v = 0;     for (auto i = 0; i <= 2; i++) v += tmp - a[i];     if (v <= m) ans += (m - v) / 3 + 1;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[k];     for (int i = 0; i < k; i++) cin >> a[i];     list<int> leader;     for (int i = 1; i <= n; i++) leader.insert(leader.end(), i);     int l = 1;     int i = 0;     int begin = 0;     while (k--) {       l = (leader.size() + a[i] + begin) % leader.size();       list<int>::iterator pnlist = leader.begin();       advance(pnlist, l);       if (k == 0)         cout << *pnlist << endl;       else         cout << *pnlist <<    ;       leader.erase(pnlist);       begin = l;       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     int n;     cin >> n;     vector<int> q(n);     for (int i = 0; i < n; ++i) cin >> q[i];     vector<int> cost(n, -1);     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       if (cost[b - 1] == -1 || cost[b - 1] > c) {         cost[b - 1] = c;       }     }     int ans = 0, head = 0;     for (int i = 0; i < n; ++i) {       if (cost[i] != -1)         ans += cost[i];       else         head++;     }     if (head > 1)       cout << -1 << endl;     else {       if (!head) {         int maxx = cost[0];         for (int i = 1; i < n; ++i) maxx = max(maxx, cost[i]);         ans -= maxx;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[200002];   vector<pair<int, pair<int, int> > > first[200002];   int lvl[200002];   int p[20][200002];   int h[20][200002];   int d[200002][2];   inline int lca(int v1, int v2) {     if (lvl[v1] < lvl[v2]) swap(v1, v2);     for (int i = 20 - 1; i >= 0; --i) {       if (lvl[p[i][v1]] >= lvl[v2]) {         v1 = p[i][v1];       }     }     if (v1 == v2) return v1;     for (int i = 20 - 1; i >= 0; --i) {       if (p[i][v1] != p[i][v2]) {         v1 = p[i][v1];         v2 = p[i][v2];       }     }     return p[0][v1];   }   void dfs(int v = 0, int level = 0, int pr = 0) {     lvl[v] = level;     p[0][v] = pr;     for (int i = 1; i < 20; ++i) p[i][v] = p[i - 1][p[i - 1][v]];     for (const int& v2 : g[v]) {       dfs(v2, level + 1, v);     }   }   inline int getit(int v, int k) {     if (h[k][v] != -1) return h[k][v];     return h[k][v] = getit(p[k - 1][v], k - 1) + getit(v, k - 1);   }   inline int get(int v, int k) {     if (k < 0) return 0;     int res = 0;     for (int i = 20 - 1; i >= 0; --i) {       if ((k & (1 << i)) > 0) {         res += getit(v, i);         k ^= (1 << i);         v = p[i][v];       }     }     return res;   }   void go(int v = 0) {     for (const int& v2 : g[v]) {       go(v2);       d[v][0] += max(d[v2][0], d[v2][1]);     }     for (const int& v2 : g[v]) {       h[0][v2] = d[v][0] - max(d[v2][0], d[v2][1]);     }     for (const auto& t : first[v]) {       int cost = t.first;       int v1 = t.second.first;       int v2 = t.second.second;       int w = -d[v][0] + get(v1, lvl[v1] - lvl[v]) + get(v2, lvl[v2] - lvl[v]) +               d[v1][0] + d[v2][0] + cost;       d[v][1] = max(d[v][1], w);     }   }   int main() {     memset(h, -1, sizeof(h));     scanf( %d%d , &n, &m);     for (int i = 0; i < n - 1; ++i) {       int t;       scanf( %d , &t);       --t;       g[t].push_back(i + 1);     }     dfs();     for (int i = 0; i < m; ++i) {       int v1, v2, cost;       scanf( %d%d%d , &v1, &v2, &cost);       --v1, --v2;       int lcav = lca(v1, v2);       first[lcav].push_back(make_pair(cost, make_pair(v1, v2)));     }     go();     printf( %d n , max(d[0][0], d[0][1]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[2000002];   int longestPrefix(string &s) {     t[0] = 0;     for (int pos = 1; pos < s.length(); ++pos) {       int prev = t[pos - 1];       while (prev > 0 && s[pos] != s[prev]) {         prev = t[prev - 1];       }       if (s[pos] == s[prev]) {         t[pos] = prev + 1;       } else {         t[pos] = prev;       }     }     return t[s.length() - 1];   }   int main() {     int t;     cin >> t;     while (t-- > 0) {       string s;       cin >> s;       int lindex = 0, rindex = s.length();       while (lindex < rindex && s[lindex] == s[rindex - 1]) {         ++lindex;         --rindex;       }       if (lindex >= rindex) {         cout << s << endl;         continue;       }       string mid = s.substr(lindex, rindex - lindex);       string rmid = mid;       reverse(rmid.begin(), rmid.end());       string pre = mid +  *  + rmid;       string suf = rmid +  *  + mid;       int pref = longestPrefix(pre);       int suff = longestPrefix(suf);       int len = max(pref, suff);       for (int i = 0; i < lindex; ++i) {         cout << s[i];       }       if (pref >= suff) {         for (int i = lindex; i < lindex + pref; ++i) {           cout << s[i];         }       } else {         for (int i = rindex - suff; i < rindex; ++i) {           cout << s[i];         }       }       for (int i = rindex; i < s.length(); ++i) {         cout << s[i];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int V[200010];   char vowel[] =  aeiouAEIOU ;   int v(int a, int k) {     if (k == 0) return 0;     int x = V[a + k - 1];     if (a > 0) x -= V[a - 1];     return x;   }   int f(int a, int k) { return 2 * k - 3 * v(a, k); }   int g(int k) { return f(0, k); }   bool Good(int a, int k) { return f(a, k) >= 0; }   bool is_vowel(char c) {     for (int i = 0; i < 10; i++) {       if (vowel[i] == c) return true;     }     return false;   }   bool sf(const int& a, const int& b) {     if (g(a) < g(b)) return true;     if (g(a) > g(b)) return false;     return a < b;   }   int Q[200010];   vector<int> P;   int R[200010];   int my_bin_search(int s, string S) {     int a = 0;     int b = P.size() - 1;     while (a <= b) {       int k = (a + b) / 2;       if (P[k] == s)         return k;       else if (sf(P[k], s))         a = k + 1;       else         b = k - 1;     }     throw  element not found ;   }   void create_data(string S) {     int N = S.length();     for (int a = 0; a <= N; a++) {       P.push_back(a);     }     sort(P.begin(), P.end(), sf);     for (int x = 0; x < P.size(); x++) {       R[P[x]] = x;     }     Q[0] = P[0];     for (unsigned int x = 1; x < P.size(); x++) {       Q[x] = min(Q[x - 1], P[x]);     }   }   int main() {     string S;     cin >> S;     int N = S.length();     V[0] = 0;     for (unsigned int i = 0; i < S.length(); i++) {       if (i > 0) V[i] = V[i - 1];       if (is_vowel(S[i])) V[i]++;     }     create_data(S);     int bestk = 0;     for (int a = 0; a <= N; a++) {       int x = R[a];       int b = Q[x];       bestk = max(bestk, a - b);     }     if (bestk == 0) {       cout <<  No solution  << endl;       return 0;     }     int found = 0;     for (int a = 0; (a + bestk) <= N; a++) {       if (Good(a, bestk)) {         found++;       }     }     cout << bestk <<     << found << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   void read(int& x) {     x = 0;     int f = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) f = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   int n, f[200005], g[200005], els[200005];   vector<int> E[200005];   int power(int a, int b, int p) {     int s = 1, w = a;     while (b) {       if (b & 1) s = (long long)s * w % p;       w = (long long)w * w % p;       b >>= 1;     }     return s;   }   vector<int> F[200005], B[200005];   void dfs(int now) {     f[now] = 1;     for (int i = (0); i < (E[now].size()); i++) {       dfs(E[now][i]),           f[now] = (long long)f[now] * (f[E[now][i]] + 1) % 1000000007;       F[now].push_back(f[E[now][i]] + 1), B[now].push_back(f[E[now][i]] + 1);     }     for (int i = (1); i < (E[now].size()); i++)       F[now][i] = (long long)F[now][i - 1] * F[now][i] % 1000000007;     for (int i = (E[now].size() - 2); i >= (0); i--)       B[now][i] = (long long)B[now][i + 1] * B[now][i] % 1000000007;     if (E[now].size() == 1) {       els[E[now][0]] = 1;       return;     }     for (int i = (0); i < (E[now].size()); i++) {       if (i == 0)         els[E[now][i]] = B[now][i + 1];       else if (i + 1 == E[now].size())         els[E[now][i]] = F[now][i - 1];       else         els[E[now][i]] = (long long)B[now][i + 1] * F[now][i - 1] % 1000000007;     }   }   void work(int now) {     for (int i = (0); i < (E[now].size()); i++) {       g[E[now][i]] = ((long long)g[now] * els[E[now][i]] + 1) % 1000000007;       work(E[now][i]);     }   }   int main() {     read(n);     for (int i = (2); i <= (n); i++) {       int x;       read(x);       E[x].push_back(i);     }     dfs(1);     g[1] = 1;     work(1);     for (int i = (1); i <= (n); i++)       printf( %lld  , (long long)f[i] * g[i] % 1000000007);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string n;   int i, j, a[9][7], x, y;   int main() {     cin >> n;     for (i = n.size() - 1; i >= 0; i--) {       x = n[i] - 48;       y = max(y, x);       for (j = 0; j < x; j++) a[j][7 + i - n.size()] = 1;     }     cout << y << endl;     for (i = 0; i < y; cout <<    , i++)       for (j = 0, x = 0; j < 7; j++) {         if (a[i][j] != 0) x = 1;         if (x != 0) cout << a[i][j];       }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     register char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();     return s * w;   }   long long n;   string s;   signed main() {     n = read();     cin >> s;     for (register long long i = 2; i <= n; i++) {       if (n % i) continue;       for (register long long j = 0; j < i / 2; j++) swap(s[j], s[i - j - 1]);     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int D = 505;   const int N = 5005;   pair<int, int> pre[D][N];   int ans[D][N];   void solve() {     memset(pre, -1, sizeof(pre));     memset(ans, -1, sizeof(ans));     int d, s;     cin >> d >> s;     queue<pair<int, int> > que;     que.push(pair<int, int>(0, 0));     vector<int> vec;     while (!que.empty()) {       pair<int, int> u = que.front();       que.pop();       if (u.first == 0 && u.second == s) {         pair<int, int> cur = u;         while (!(cur.first == 0 && cur.second == 0)) {           vec.push_back(ans[cur.first][cur.second]);           cur = pre[cur.first][cur.second];         }         break;       }       for (int i = 0; i <= 9; i++) {         pair<int, int> v = pair<int, int>((u.first * 10 + i) % d, u.second + i);         if (v.second <= s && ans[v.first][v.second] == -1) {           ans[v.first][v.second] = i;           pre[v.first][v.second] = u;           que.push(v);         }       }     }     if (!vec.size())       printf( -1 n );     else {       reverse(vec.begin(), vec.end());       for (auto i : vec) putchar(i +  0 );       printf(  n );     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5, MOD = 998244353;   int m, n, k;   long long res;   int free_Row, free_Col, line_vert, line_hori;   int Num_Row[N], Num_Row2[N][2], Num_Col[N], Num_Col2[N][2];   int c[2][2];   map<pair<int, int>, int> M;   long long power(long long x, int k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * x % MOD;       x = x * x % MOD;       k >>= 1;     }     return ans;   }   void Calculate() {     res = 0;     if (line_vert && line_hori) return;     if (!line_vert) (res += power(2, free_Row)) %= MOD;     if (!line_hori) (res += power(2, free_Col)) %= MOD;     if (!line_vert && !line_vert) {       if (c[0][0] == 0 && c[1][1] == 0) (res += MOD - 1) %= MOD;       if (c[0][1] == 0 && c[1][0] == 0) (res += MOD - 1) %= MOD;     }   }   void Delete(int x, int y) {     if (!M.count({x, y})) return;     int z = M[{x, y}];     M.erase({x, y});     --c[z][(x + y) & 1];     if (--Num_Row[x] == 0) ++free_Row;     if (--Num_Row2[x][z ^ (y & 1)] == 0 && Num_Row[x]) --line_vert;     if (--Num_Col[y] == 0) ++free_Col;     if (--Num_Col2[y][z ^ (x & 1)] == 0 && Num_Col[y]) --line_hori;   }   void Add(int x, int y, int z) {     M[{x, y}] = z;     ++c[z][(x + y) & 1];     if (Num_Row[x]++ == 0) --free_Row;     if (Num_Row2[x][z ^ (y & 1)]++ == 0 && Num_Row[x] > 1) ++line_vert;     if (Num_Col[y]++ == 0) --free_Col;     if (Num_Col2[y][z ^ (x & 1)]++ == 0 && Num_Col[y] > 1) ++line_hori;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> m >> n >> k;     free_Row = m;     free_Col = n;     line_hori = 0;     line_vert = 0;     int x, y, z;     while (k--) {       cin >> x >> y >> z;       Delete(x, y);       if (z >= 0) Add(x, y, z);       Calculate();       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10000;   vector<int> vec(N);   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     sort(vec.begin(), vec.begin() + n);     int sum = 0;     for (int i = 0; i < m; i++) {       sum += vec[i];     }     cout << sum << endl;   }


#include <bits/stdc++.h>   namespace algo {   using std::swap;   const long double PI = 3.141592653589793238462643383279502884L;   const long double E = 2.718281828459045235360287471352662498L;   const long double EPS = 1e-12L;   template <typename T1, typename T2>   T1 bin_pow(T1 a, T2 n) {     T1 r{1};     while (n > 0) {       if (n % 2 == 1) r *= a;       a *= a;       n /= 2;     }     return r;   }   template <typename T1, typename T2>   T1 bin_pow(T1 a, T2 n, const T1& m) {     if (m == 1) return 0;     T1 r{1};     while (n > 0) {       if (n % 2 == 1) {         r *= a;         r %= m;       }       a *= a;       a %= m;       n /= 2;     }     return r;   }   template <typename T>   T gcd(const T& a, const T& b) {     if (b == 0) return a < 0 ? -a : a;     return gcd(b, a % b);   }   template <typename T>   T gcd(const T& a, const T& b, T& x, T& y) {     if (b == 0) {       x = a < 0 ? -1 : 1;       y = 0;       return x * a;     }     T d{gcd(b, a % b, y, x)};     y -= (a / b) * x;     return d;   }   template <typename T>   T lcm(const T& a, const T& b) {     T r{a / gcd(a, b) * b};     return r < 0 ? -r : r;   }   template <typename T>   T mod_add(const T& a, const T& b, const T& m) {     if (a < m - b) return a + b;     return a - (m - b);   }   template <typename T>   T mod_sub(const T& a, const T& b, const T& m) {     if (a < b) return a + (m - b);     return a - b;   }   template <typename T>   T mod_mul(T a, T b, const T& m) {     if (b > a) swap(a, b);     T r{0};     while (b > 0) {       if (b % 2 == 1) r = mod_add(r, a, m);       a = mod_add(a, a, m);       b /= 2;     }     return r;   }   template <typename T1, typename T2>   T1 mod_pow(T1 a, T2 n, const T1& m) {     if (m == 1) return 0;     T1 r{1};     while (n > 0) {       if (n % 2 == 1) r = mod_mul(r, a, m);       a = mod_mul(a, a, m);       n /= 2;     }     return r;   }   template <typename T>   T mod_inv(const T& a, const T& m) {     T x, y;     T d{gcd(a, m, x, y)};     if (d != 1) return 0;     if (x < 0) x += m;     return x;   }   template <typename T>   T phi(T n) {     T t = std::sqrt(n) + EPS;     T r = n;     for (T i = 2; i <= t; ++i) {       if (n % i == 0) {         r -= r / i;         do {           n /= i;         } while (n % i == 0);         t = std::sqrt(n) + EPS;       }     }     if (n > 1) r -= r / n;     return r;   }   class LinearPhi {    public:     LinearPhi(uint32_t n = 1 << 20) : size_{n} {       assert(size_ > 0 &&  Size should be nonzero );       assert(size_ <= INT32_MAX &&  Size should fit into an 32-bit signed int );       uint32_t sz = (size_ + 1) / 2;       phi_ = new int32_t[sz];       mark_.assign(sz, false);       phi_[0] = 1;       if (size_ > 1) primes_.push_back(2);       for (uint32_t i = 1; i < sz; ++i) {         uint32_t val = i << 1 | 1;         if (!mark_[i]) {           phi_[i] = val - 1;           primes_.push_back(val);         }         if (val < sz) {           for (uint32_t j = 1; j < primes_.size(); ++j) {             uint32_t t = val * primes_[j];             if (t > size_) break;             mark_[t >> 1] = true;             if (val % primes_[j] == 0) {               phi_[t >> 1] = phi_[i] * primes_[j];               break;             }             phi_[t >> 1] = phi_[i] * (primes_[j] - 1);           }         }       }     }     LinearPhi(const LinearPhi&) = delete;     LinearPhi& operator=(const LinearPhi&) = delete;     ~LinearPhi() {       delete[] phi_;       phi_ = nullptr;     }     const uint32_t& size() const { return size_; }     int32_t phi(int32_t i) const {       int32_t r = 1;       int k = __builtin_ctz(i);       if (k > 0) {         i >>= k;         r <<= k - 1;       }       return r * phi_[i >> 1];     }     int32_t operator[](int32_t i) const { return phi(i); }     const std::vector<int32_t>& primes() const { return primes_; }       private:     int32_t* phi_ = nullptr;     std::vector<bool> mark_;     uint32_t size_;     std::vector<int32_t> primes_;   };   class Sieve {    public:     Sieve(uint32_t n = 1 << 20) : size_{n} {       assert(size_ > 0 &&  Size should be nonzero );       assert(size_ <= INT32_MAX &&  Size should fit into an 32-bit signed int );       uint32_t sz = (size_ + 1) / 2;       prime_.assign(sz, true);       prime_[0] = false;       for (uint32_t i = 1; i < sz; ++i) {         uint32_t val = i << 1 | 1;         if (prime_[i] && val * 1ULL * val <= size_)           for (uint32_t j = val * val; j <= size_; j += 2 * val)             prime_[j >> 1] = false;       }     }     Sieve(const Sieve&) = delete;     Sieve& operator=(const Sieve&) = delete;     const uint32_t& size() const { return size_; }     bool isPrime(const int32_t& i) const {       if (i % 2 == 0) return i == 2;       return prime_[i >> 1];     }     bool operator[](const int32_t& i) const { return isPrime(i); }       private:     uint32_t size_;     std::vector<bool> prime_;   };   class LinearSieve {    public:     LinearSieve(uint32_t n = 1 << 20) : size_{n} {       assert(size_ > 0 &&  Size should be nonzero );       assert(size_ <= INT32_MAX &&  Size should fit into an 32-bit signed int );       uint32_t sz = (size_ + 1) / 2;       lpf_ = new uint16_t[sz];       std::fill(lpf_, lpf_ + sz, 0);       lpf_[0] = 1;       if (size_ > 1) primes_.push_back(2);       for (uint32_t i = 1; i < sz; ++i) {         uint32_t val = i << 1 | 1;         if (!lpf_[i]) primes_.push_back(val);         if (val < sz) {           for (uint32_t j = 1; j < primes_.size(); ++j) {             uint32_t t = val * primes_[j];             if (t > size_) break;             lpf_[t >> 1] = static_cast<uint16_t>(primes_[j]);             if (lpf_[t >> 1] == (lpf_[i] ? lpf_[i] : val)) break;           }         }       }     }     LinearSieve(const LinearSieve&) = delete;     LinearSieve& operator=(const LinearSieve&) = delete;     ~LinearSieve() {       delete[] lpf_;       lpf_ = nullptr;     }     const uint32_t& size() const { return size_; }     bool isPrime(const int32_t& i) const {       if (i % 2 == 0) return i == 2;       return !lpf_[i >> 1];     }     bool operator[](const int32_t& i) const { return isPrime(i); }     int32_t lpf(const int32_t& i) const {       if (i % 2 == 0) return 2;       if (!lpf_[i >> 1]) return i;       return lpf_[i >> 1];     }     int32_t phi(int32_t i) const {       int32_t r = 1;       int k = __builtin_ctz(i);       if (k > 0) {         i >>= k;         r <<= k - 1;       }       int32_t n, t = lpf_[i >> 1] ? lpf_[i >> 1] : i;       while (t != 1) {         r *= (t - 1);         i /= t;         n = lpf_[i >> 1] ? lpf_[i >> 1] : i;         while (n == t) {           r *= n;           i /= t;           n = lpf_[i >> 1] ? lpf_[i >> 1] : i;         }         t = n;       }       return r;     }     const std::vector<int32_t>& primes() const { return primes_; }       private:     uint16_t* lpf_ = nullptr;     uint32_t size_;     std::vector<int32_t> primes_;   };   }  // namespace algo   using namespace std;   using namespace algo;   namespace task {   int x1, y1, x2, y2, x3, y3;   int main() {     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     cout << 3 <<   n ;     cout << x3 - x1 + x2 <<     << y3 - y1 + y2 <<   n ;     cout << x1 - x2 + x3 <<     << y1 - y2 + y3 <<   n ;     cout << x2 - x3 + x1 <<     << y2 - y3 + y1 <<   n ;     return 0;   }   }  // namespace task   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(11);     cout.setf(ios::fixed);     return task::main();   }


#include <bits/stdc++.h>   using namespace std;   bool BeauYear(int y) {     int a = y % 10;     int b = (y / 10) % 10;     int c = (y / 100) % 10;     int d = (y / 1000) % 10;     if (a != b && a != c && a != d && b != c && b != d && c != d) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int year;     cin >> year;     for (int i = year + 1; i <= 9012; i++) {       if (BeauYear(i) == true) {         cout << i;         i = 9013;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, a, b, q, p[N], d[N];   vector<pair<int, int> > g[N];   int dp[N][17], v, ud[N], ans[N];   bool vis[N];   void dfs(int u) {     vis[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       v = g[u][i].first;       if (!vis[v]) {         p[v] = u;         d[v] = d[u] + 1;         dfs(v);       }     }   }   int lca(int a, int b) {     if (d[a] < d[b]) swap(a, b);     int log = 0;     for (; (1 << log) <= d[a]; ++log)       ;     --log;     for (int i = log; i >= 0; --i) {       if (d[a] - (1 << i) >= d[b]) a = dp[a][i];     }     if (a == b) return a;     for (int i = log; i >= 0; --i) {       if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];       }     }     return p[a];   }   int DFS(int u) {     vis[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i].first;       if (!vis[v]) {         ud[u] += DFS(v);         ans[g[u][i].second] = ud[v];       }     }     return ud[u];   }   int main(int argc, char **argv) {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       g[a].push_back(make_pair(b, i));       g[b].push_back(make_pair(a, i));     }     memset(p, -1, sizeof p);     memset(dp, -1, sizeof dp);     dfs(1);     for (int i = 0; i <= n; ++i) dp[i][0] = p[i];     for (int j = 1; (1 << j) <= n; ++j) {       for (int i = 0; i <= n; ++i) {         if (dp[i][j - 1] != -1) dp[i][j] = dp[dp[i][j - 1]][j - 1];       }     }     scanf( %d , &q);     int LCA;     while (q--) {       scanf( %d%d , &a, &b);       LCA = lca(a, b);       ++ud[a], ++ud[b], ud[LCA] -= 2;     }     memset(vis, 0, sizeof vis);     DFS(1);     for (int i = 1; i < n; ++i) {       if (i > 1) printf(   );       printf( %d , ans[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string tobinary(long long x) {     string ret;     char ch;     while (x) ch =  0  + (x % 2), ret = ch + ret, x /= 2;     return ret;   }   long long todecimal(string s) {     int sz = s.size();     long long ret = 0;     for (int i = 0; i < sz; i++) ret = 2 * ret + (s[i] -  0 );     return ret;   }   bool _greater(string s, string t) {     int n = s.size(), m = t.size();     if (n > m) return true;     if (n < m) return false;     for (int i = 0; i < n; i++) {       if (s[i] > t[i])         return true;       else if (s[i] < t[i])         return false;     }     return false;   }   long long eval(long long l, long long r) {     string s = tobinary(l), t = tobinary(r), ret = s;     while (1) {       if (_greater(s, t)) break;       ret = s;       int sz = s.size();       bool ok = false;       for (int i = sz - 1; i >= 0; i--)         if (s[i] ==  0 ) {           s[i] =  1 ;           ok = true;           break;         }       if (!ok) {         s =  1  + s;         int n = s.size(), m = t.size();         if (n > m) break;       }     }     return todecimal(ret);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     while (n--) {       long long l, r;       cin >> l >> r;       cout << eval(l, r) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > points;   pair<int, int> dif(pair<int, int> pa, pair<int, int> pb) {     pair<int, int> res;     res.first = pb.first - pa.first;     res.second = pb.second - pa.second;     return res;   }   int dot(pair<int, int> a, pair<int, int> b) {     return a.first * b.first + a.second * b.second;   }   double dist(pair<int, int> a, pair<int, int> b) {     return ((double)((a.first - b.first) * (a.first - b.first) +                      (a.second - b.second) * (a.second - b.second)));   }   double len(pair<int, int> a) { return dist(a, make_pair(0, 0)); }   int main() {     for (int i = 0; i < 8; i++) {       int x, y;       cin >> x >> y;       points.push_back(make_pair(x, y));     }     vector<int> perm;     for (int i = 0; i < 8; i++) perm.push_back(i);     int cnt = 0;     bool found = false;     do {       cnt++;       bool fs = false, ss = false;       bool fis = true, sif = true;       pair<int, int> a = points[perm[0]];       pair<int, int> b = points[perm[1]];       pair<int, int> c = points[perm[2]];       pair<int, int> d = points[perm[3]];       pair<int, int> e = points[perm[4]];       pair<int, int> f = points[perm[5]];       pair<int, int> g = points[perm[6]];       pair<int, int> h = points[perm[7]];       pair<int, int> ab = dif(a, b);       pair<int, int> bc = dif(b, c);       pair<int, int> cd = dif(c, d);       pair<int, int> da = dif(d, a);       fs = (dot(ab, bc) == 0 && dot(bc, cd) == 0 && dot(cd, da) == 0 &&             dot(da, ab) == 0 && fabs(len(ab) - len(bc)) < 0.01 &&             fabs(len(bc) - len(cd)) < 0.01 && fabs(len(cd) - len(da)) < 0.01);       pair<int, int> ef = dif(e, f);       pair<int, int> fg = dif(f, g);       pair<int, int> gh = dif(g, h);       pair<int, int> he = dif(h, e);       ss = (dot(ef, fg) == 0 && dot(fg, gh) == 0 && dot(gh, he) == 0 &&             dot(he, ef) == 0 && fabs(len(ef) - len(gh)) < 0.01 &&             fabs(len(fg) - len(he)) < 0.01);       if (ss && fs) {         found = true;         break;       }     } while (next_permutation(perm.begin(), perm.end()));     if (found) {       cout <<  YES  << endl;       for (int i = 0; i < 4; i++) {         if (i != 0) cout <<    ;         cout << perm[i] + 1;       }       cout << endl;       for (int i = 4; i < 8; i++) {         if (i != 4) cout <<    ;         cout << perm[i] + 1;       }       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   char s[5001];   int dp[5001][5001];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf(  n%c , &s[i]);     }     dp[1][0] = 1;     for (int j = 1; j <= n; ++j) {       dp[1][j] = 0;     }     for (int i = 2; i <= n; ++i) {       if (s[i - 1] ==  f ) {         for (int j = 1; j <= n; ++j) {           dp[i][j] = dp[i - 1][j - 1];         }       } else {         int x = 0;         for (int j = n; j >= 0; --j) {           x += dp[i - 1][j];           if (x >= mod) {             x -= mod;           }           dp[i][j] = x;         }       }     }     int res = 0;     for (int i = 0; i <= n; ++i) {       res += dp[n][i];       if (res >= mod) {         res -= mod;       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long;   using Double = long double;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s[9][3];     for (int i = 0; i < 9; ++i) {       for (int j = 0; j < 3; ++j) {         cin >> s[i][j];       }     }     int x, y, cnt = 0;     cin >> x >> y, --x, --y;     for (auto c : s[x % 3 * 3][y % 3]) cnt += c ==  . ;     for (auto c : s[x % 3 * 3 + 1][y % 3]) cnt += c ==  . ;     for (auto c : s[x % 3 * 3 + 2][y % 3]) cnt += c ==  . ;     if (cnt == 0) {       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 3; ++j) {           for (auto c : s[i][j]) {             cout << (c ==  .  ?  !  : c);           }           cout <<    n [j == 2];         }         if (i % 3 == 2) cout <<   n ;       }     } else {       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 3; ++j) {           for (auto c : s[i][j]) {             cout << (c ==  .  and i / 3 == x % 3 and j == y % 3 ?  !  : c);           }           cout <<    n [j == 2];         }         if (i % 3 == 2) cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 2e5 + 10;   set<int> g;   queue<set<int> > q;   int m, n, x, y;   int dfs(int top) {     if (abs(top) <= 1) return 0;     int now = 0;     if ((-top) % 2 == 0)       now = top / 2;     else       now = (top + 1) / 2;     if (g.find(now) == g.end()) {       g.erase(top);       g.insert(now);       return 1;     } else       return dfs(now);   }   int main() {     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> x;       g.insert(-x);     }     for (;;) {       int top = *g.begin();       if (!dfs(top)) break;     }     for (auto e : g) cout << -e <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int qtd[100001];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       v.push_back(a);     }     sort(v.begin(), v.end());     int cont = 0;     for (int i = 1, tmp = 0; i < n; i++) {       if (v[i] > v[i - 1]) {         cont += i - tmp;         tmp = i;       }       qtd[i] = cont;     }     int ans = 0;     int used = 0;     for (int i = 0; i < n; i++) {       if (qtd[i] > used) {         used++;         ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct W {     int t, l, r;   } w[100010];   int n, m, s, f;   int main() {     while (cin >> n >> m >> s >> f) {       for (int i = (0); i < (m); i++) {         cin >> w[i].t >> w[i].l >> w[i].r;       }       int t = 1, p = 0;       int dir = f > s ? 1 : -1;       while (s != f) {         if (p < m && w[p].t == t &&             ((w[p].l <= s && s <= w[p].r) ||              (w[p].l <= s + dir && s + dir <= w[p].r))) {           cout <<  X ;         } else {           s += dir;           cout << (dir == 1 ?  R  :  L );         }         if (++t > w[p].t) p++;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   int t, cnt[N];   int mx;   int check(int row, int col, int n, int m) {     if (row < 0 || row >= n || col < 0 || col >= m) return 0;     int i = 0, j = 0, ok = 1;     for (; i < n; i++) {       for (j = 0; j < m; j++) {         if (!cnt[abs(row - i) + abs(col - j)]--) {           ok = 0;           break;         }       }       if (!ok) break;     }     if (ok) {       cout << n <<     << m << endl;       cout << row + 1 <<     << col + 1 << endl;       return 1;     }     for (int a = 0; a <= i; a++)       for (int b = 0; b < m && (a != i || b <= j); b++)         ++cnt[abs(row - a) + abs(col - b)];     return 0;   }   bool solve(int row, int n, int m, int mxi, int mxj) {     if (check(row, mxj - (mx - abs(row - mxi)), n, m)) return 1;     return check(row, mxj + (mx - abs(row - mxi)), n, m);   }   int main() {     scanf( %d , &t);     for (int i = 0; i < t; ++i) {       int v;       scanf( %d , &v);       ++cnt[v];       mx = max(mx, v);     }     if (cnt[0] != 1) return puts( -1 );     int a;     if (cnt[1] != 4)       a = 0;     else {       a = 1;       while (cnt[a + 1] == (a + 1) * 4) a++;     }     for (int n = 1; n * n <= t; n++) {       if (t % n) continue;       int m = t / n;       if (solve(a, n, m, 0, 0)) return 0;       if (solve(a, n, m, 0, m - 1)) return 0;       if (solve(a, n, m, n - 1, 0)) return 0;       if (solve(a, n, m, n - 1, m - 1)) return 0;       if (solve(a, m, n, 0, 0)) return 0;       if (solve(a, m, n, 0, n - 1)) return 0;       if (solve(a, m, n, m - 1, 0)) return 0;       if (solve(a, m, n, m - 1, n - 1)) return 0;     }     return puts( -1 );   }


#include <bits/stdc++.h>   int main() {     int i, j;     int str[6];     int num[6];     char ch;     for (i = 0; i < 6; i++) {       str[i] = 0;       num[i] = 0;     }     for (i = 0; i < 6; i++) {       scanf( %c , &ch);       switch (ch) {         case  R :           str[0]++;           break;         case  O :           str[1]++;           break;         case  Y :           str[2]++;           break;         case  G :           str[3]++;           break;         case  B :           str[4]++;           break;         case  V :           str[5]++;           break;       }     }     for (j = 0; j < 6; j++) {       num[str[j]]++;     }     switch (num[0]) {       case 0:         printf( 30 n );         break;       case 1:         printf( 15 n );         break;       case 2:         switch (num[1]) {           case 2:             printf( 8 n );             break;           case 3:             printf( 5 n );             break;         }         break;       case 3:         switch (num[1]) {           case 2:             printf( 2 n );             break;           case 1:             printf( 3 n );             break;           case 0:             printf( 6 n );             break;         }         break;       case 4:         switch (num[1]) {           case 1:             printf( 1 n );             break;           case 0:             printf( 2 n );             break;         }         break;       case 5:         printf( 1 n );         break;     }   }


#include <bits/stdc++.h>   using namespace std;   int Head[1000010], Next[1000010], Go[1000010], Val[1000010], iscut[1000010],       Len[1000010], Dep[1000010], Fa[400010][21], Cnt = 1, n, m, q;   int Head2[1000010], Next2[1000010], Go2[1000010], Val2[1000010], Cnt2 = 1;   int DFN[1000010], MIN[1000010], ins[1000010], Bel[1000010], vis[1000010],       tim = 0, tt = 0;   vector<int> S;   void addedge(int x, int y) {     Go[++Cnt] = y;     Next[Cnt] = Head[x];     Head[x] = Cnt;   }   void addedge2(int x, int y, int v) {     Go2[++Cnt2] = y;     Next2[Cnt2] = Head2[x];     Head2[x] = Cnt2;     Val2[Cnt2] = v;   }   void Tarjan(int x, int f = 0) {     ins[x] = 1;     S.push_back(x);     DFN[x] = ++tim;     MIN[x] = DFN[x];     int las = x;     for (int T = Head[x]; T; T = Next[T])       if (Go[T] != f) {         if (!DFN[Go[T]]) {           Tarjan(Go[T], x);           MIN[x] = min(MIN[x], MIN[Go[T]]);           if (DFN[x] <= MIN[Go[T]]) {             tt++;             for (;;) {               if (S.back() == las) break;               addedge2(tt + n + 1, S.back(), 1);               addedge2(S.back(), tt + n + 1, 1);               S.pop_back();             }             addedge2(x, tt + n + 1, 1);             addedge2(tt + n + 1, x, 1);           } else             las = S.back();         } else if (ins[Go[T]])           MIN[x] = min(MIN[x], DFN[Go[T]]);       }     ins[x] = 0;   }   void DFS2(int x, int dep = 1, int len = 0) {     vis[x] = 1;     Len[x] = len;     Dep[x] = dep;     for (int T = Head[x]; T; T = Next[T])       if (!vis[Go[T]]) {         Fa[Go[T]][0] = x;         DFS2(Go[T], dep + 1, len + Val[T]);       }   }   int lca(int x, int y) {     if (Dep[x] < Dep[y]) swap(x, y);     int det = Dep[x] - Dep[y];     for (int i = 18; i >= 0; i--)       if ((det >> i) & 1) x = Fa[x][i];     if (x == y) return x;     for (int i = 18; i >= 0; i--)       if (Fa[x][i] != Fa[y][i]) x = Fa[x][i], y = Fa[y][i];     return Fa[x][0];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       addedge(a, b);       addedge(b, a);     }     for (int i = 1; i <= n; i++)       if (!DFN[i]) Tarjan(i);     memcpy(Head, Head2, sizeof Head);     memcpy(Next, Next2, sizeof Next);     memcpy(Go, Go2, sizeof Go);     memcpy(Val, Val2, sizeof Val);     for (int i = 1; i <= n + tt + 1; i++)       if (!vis[i]) DFS2(i);     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= n + tt + 1; j++) Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];     for (int i = 1; i <= q; i++) {       int a, b;       scanf( %d%d , &a, &b);       printf( %d n , (Len[a] + Len[b] - 2 * Len[lca(a, b)]) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) -  0  + ch;       ch = getchar();     }     return x * f;   }   int main() {     priority_queue<int> q;     int n = read(), T = read();     int ans = 0;     for (int i = 1; i <= n; i++) {       int x = read();       x = max(x, i);       while (!q.empty() && q.top() >= T - i) {         q.pop();       }       if (x < T) q.push(x - i);       ans = max(ans, (int)q.size());     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int a[1005];   int b[1005];   int h;   bool cmp(int x, int y) { return x > y; }   bool check(int x) {     for (int i = 1; i <= x; i++) {       b[i] = a[i];     }     sort(b + 1, b + x + 1, cmp);     long long sum = 0;     for (int i = 1; i <= x; i += 2) {       sum += (long long)(b[i]);     }     if (sum <= h) {       return 1;     } else {       return 0;     }   }   int main() {     int n;     cin >> n >> h;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int l = 1, r = n, mid;     while (l < r) {       mid = (l + r + 1) / 2;       if (check(mid)) {         l = mid;       } else {         r = mid - 1;       }     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   template <typename T>   inline istream& operator>>(istream& i, vector<T>& v) {     for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(const vector<T>& v) {     stringstream s;     for (int i = 0; i < ((int)(v).size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   inline ostream& operator<<(ostream& o, const vector<T>& v) {     if ((int)(v).size()) o << join(v);     return o;   }   template <typename T1, typename T2>   inline istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {     return o << v.first <<  ,  << v.second;   }   template <typename T>   inline long long int suma(const vector<T>& a) {     long long int res(0);     for (auto&& x : a) res += x;     return res;   }   const double eps = 1e-10;   const long long int LINF = 1001002003004005006ll;   const int INF = 1001001001;   const int MX = 200005;   int n, m;   int dp[55][55][55];   struct Q {     int l, r, x, c;     int cost(int i, int h) {       if (l <= i && i < r && h > x) return c;       return 0;     }   };   vector<Q> q;   int dfs(int l, int r, int h) {     if (l == r) return 0;     int& now = dp[l][r][h];     if (now != -1) return now;     now = 0;     if (h) now = dfs(l, r, h - 1);     for (int i = l; i < r; ++i) {       int c = h * h;       for (int k = 0; k < (m); ++k) {         if (l <= q[k].l && q[k].r <= r) c -= q[k].cost(i, h);       }       c += dfs(l, i, h) + dfs(i + 1, r, h);       (now = max(now, c));     }     return now;   }   int main() {     int h;     cin >> n >> h >> m;     q = vector<Q>(m);     for (int i = 0; i < (m); ++i) {       int l, r, x, c;       scanf( %d%d%d%d , &l, &r, &x, &c);       --l;       q[i] = (Q){l, r, x, c};     }     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (n + 1); ++j)         for (int k = 0; k < (h + 1); ++k) dp[i][j][k] = -1;     int ans = dfs(0, n, h);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } p[8];   int cmp(node a, node b) {     if (a.x == b.x) return (a.y < b.y);     return a.x < b.x;   }   int main() {     while (scanf( %d %d , &p[0].x, &p[0].y) != EOF) {       int cnt1 = 0;       int cnt2 = 0;       int cnt3 = 0;       int cnt4 = 0;       for (int i = 1; i < 8; i++) {         scanf( %d %d , &p[i].x, &p[i].y);       }       sort(p, p + 8, cmp);       node zuoshang = p[0];       node youxia = p[7];       for (int i = 1; i < 7; i++) {         if (p[i].x == zuoshang.x) cnt1++;         if (p[i].y == zuoshang.y) cnt2++;         if (p[i].x == youxia.x) cnt3++;         if (p[i].y == youxia.y) cnt4++;       }       if (cnt1 == 2 && cnt2 == 2 && cnt3 == 2 && cnt4 == 2 && p[1].y == p[6].y &&           p[4].x == p[3].x)         puts( respectable );       else         puts( ugly );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       double x, y, z, a, b, c, sq;       cin >> x;       a = 1.0, b = x, c = x;       z = (b * b) - (4 * a * c);       if (z < 0) {         cout <<  N  << endl;         continue;       }       y = ((-b + (sqrt((b * b) - (4 * a * c)))) / 2 * a);       if (y != 0) y = -1 * y;       cout << fixed << setprecision(9) <<  Y   << (x - y) <<     << y << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 789;   const int M = 2e5 + 5;   const int NN = 1e5 + 55;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const long long INF = 1LL << 62;   bitset<2000> P[N], S[N], T;   char ms[N][N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     P[0].reset();     for (int i = 0; i < n; i++) {       cin >> ms[i];       if (i) P[i] = P[i - 1];       for (int j = 0; j < m; j++) {         if (ms[i][j] ==  1 ) P[i][j] = 1;       }     }     for (int i = n - 1; i >= 0; i--) {       if (i != n - 1) S[i] = S[i + 1];       for (int j = 0; j < m; j++) {         if (ms[i][j] ==  1 ) S[i][j] = 1;       }     }     bool f = 0;     for (int i = 0; i < n; i++) {       T.reset();       if (i - 1 >= 0) T |= P[i - 1];       if (i + 1 < n) T |= S[i + 1];       if (T.count() == m) f = 1;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void Boost() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int NMax = 1e6 + 50;   string convert(const string &s) {     string ret =  @ ;     for (int i = 0; i < (int)s.size(); ++i) {       ret +=  #  + s.substr(i, 1);     }     ret +=  #$ ;     return ret;   }   int P[NMax * 2];   void Solve() {     string s;     cin >> s;     int n = (int)s.size();     int a = 0;     int b = n - 1;     while (a <= b) {       if (a == b) {         cout << s <<   n ;         return;       }       if (s[a] == s[b]) {         ++a;         --b;         if (a > b) {           cout << s <<   n ;           return;         }       } else {         string nw = convert(s);         int cen = 0, r = 0;         for (int i = 0; i < (int)nw.size(); ++i) P[i] = 0;         for (int i = 1; i < (int)nw.size() - 1; ++i) {           int mir = cen - (i - cen);           if (r > i) {             P[i] = min(r - i, P[mir]);           }           while (nw[i + 1 + P[i]] == nw[i - 1 - P[i]]) {             P[i]++;           }           if (i + P[i] > r) {             cen = i;             r = i + P[i];           }         }         int best = 0;         int pos = 0;         for (int i = 1; i < (int)nw.size() - 1; i++) {           int start = (i - 1 - P[i]) / 2;           int fin = start + P[i] - 1;           if (start < a) {             int mv = a - start;             start += mv;             fin -= mv;           }           if (fin > b) {             int mv = fin - b;             start += mv;             fin -= mv;           }           if (start != a && fin != b) continue;           if (start <= fin && (fin - start + 1) > best) {             best = fin - start + 1;             pos = start;           }         }         for (int i = 0; i < a; ++i) cout << s[i];         for (int i = pos; i < pos + best; ++i) cout << s[i];         for (int i = a - 1; i >= 0; --i) cout << s[i];         cout <<   n ;         return;       }     }   }   int main() {     Boost();     int t;     cin >> t;     while (t--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool is_prefix(string s, string comp) {     bool res = false;     int sz = s.size();     int comp_sz = comp.size();     if (sz > comp_sz)       return res;     else {       res = true;       for (int i = 0; i < sz; i++) {         if (s[i] != comp[i]) {           res = false;           break;         }       }     }     return res;   }   int main(int argc, char* argv[]) {     int n;     string s;     vector<string> res;     cin >> s;     cin >> n;     for (int i = 0; i < n; i++) {       string t;       cin >> t;       if (is_prefix(s, t)) res.push_back(t);     }     if (res.size() == 0) {       cout << s;     } else {       sort(res.begin(), res.end());       cout << res[0];     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100001;   int n, val[maxn], cL[maxn], cR[maxn], ord[maxn], tot, in[maxn], out[maxn],       bit[maxn], ans;   bool vis[maxn];   void dfs(int u) {     if (u == -1) return;     in[u] = ++tot;     dfs(cL[u]);     dfs(cR[u]);     out[u] = tot;   }   void bit_add(int x, int v) {     for (; x <= n; x += x & -x) bit[x] += v;   }   int bit_sum(int x) {     int ret = 0;     for (; x > 0; x -= x & -x) ret += bit[x];     return ret;   }   bool cmp(int const &x, int const &y) { return val[x] < val[y]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d , val + i, cL + i, cR + i);       if (cL[i] != -1) vis[cL[i]] = 1;       if (cR[i] != -1) vis[cR[i]] = 1;       ord[i] = i;     }     std::sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; ++i)       if (!vis[i]) dfs(i);     for (int i = 1; i <= n; ++i)       if (cR[i] != -1) {         bit_add(in[cR[i]], 1);         bit_add(out[cR[i]] + 1, -1);       }     for (int i = 1, j = 1; i <= n;) {       for (; j <= n && val[ord[j]] <= val[ord[i]]; ++j) {         int u = ord[j];         if (cL[u] != -1) {           bit_add(in[cL[u]], 1);           bit_add(out[cL[u]] + 1, -1);         }         if (cR[u] != -1) {           bit_add(in[cR[u]], -1);           bit_add(out[cR[u]] + 1, 1);         }       }       int cnt = 0, flg = 0;       for (int v = val[ord[i]]; i <= n && val[ord[i]] == v; ++i, ++cnt)         flg |= !bit_sum(in[ord[i]]);       if (!flg) ans += cnt;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 210;   int n, m, x;   long long dp[maxn][maxn], v[maxn], ans = -1;   void read_and_parse() {     scanf( %d%d%d , &n, &m, &x);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);   }   void solve() {     memset(dp, 0xcf, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= x; j++)         for (int k = max(0, i - m); k < i; k++)           dp[i][j] = max(dp[i][j], dp[k][j - 1] + v[i]);     for (int i = n - m + 1; i <= n; i++) ans = max(ans, dp[i][x]);     printf( %lld n , ans);   }   int main() {     read_and_parse();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void checkDefine();   string x;   string y;   string z;   int main() {     cin >> x >> y;     long long int n = x.size();     for (int i = (0), _b = (n - 1); i <= _b; i++) {       if (x[i] < y[i]) {         cout << -1;         return 0;       }     }     cout << y;     return 0;   }   void checkDefine() {     long long int n, a[200005];     map<long long int, long long int> m;     cin >> n;     for (int i = (0), _b = (n - 1); i <= _b; i++) {       cin >> a[i];       m[a[i]]++;     }     string s;     cin >> s;     {       cout <<  s             <<   =  ;       cout << (s) << endl;     };     {       cout <<  a             <<   =  ;       for (int _ = 0, _a = (n); _ < _a; _++) cout << a[_] <<    ;       cout << endl;     };     {       cout <<   ------------              <<   =  ;       cout << ( ------------ ) << endl;     };     for (__typeof(m.begin()) it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << it->second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> P) {     for (auto const &vv : P) os <<  (  << vv.first <<  ,  << vv.second <<  ) ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> V) {     os <<  [ ;     for (auto const &vv : V) os << vv <<  , ;     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto const &vv : V) os << vv <<  , ;     os <<  ] ;     return os;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     os <<  (  << P.first <<  ,  << P.second <<  ) ;     return os;   }   inline int fstoi(const string &str) {     auto it = str.begin();     bool neg = 0;     int num = 0;     if (*it ==  - )       neg = 1;     else       num = *it -  0 ;     ++it;     while (it < str.end()) num = num * 10 + (*it++ -  0 );     if (neg) num *= -1;     return num;   }   inline void getch(char &x) {     while (x = getchar_unlocked(), x < 33) {       ;     }   }   inline void getstr(string &str) {     str.clear();     char cur;     while (cur = getchar_unlocked(), cur < 33) {       ;     }     while (cur > 32) {       str += cur;       cur = getchar_unlocked();     }   }   template <typename T>   inline bool sc(T &num) {     bool neg = 0;     int c;     num = 0;     while (c = getchar_unlocked(), c < 33) {       if (c == EOF) return false;     }     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;     if (neg) num *= -1;     return true;   }   template <typename T, typename... Args>   inline void sc(T &num, Args &...args) {     bool neg = 0;     int c;     num = 0;     while (c = getchar_unlocked(), c < 33) {       ;     }     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;     if (neg) num *= -1;     sc(args...);   }   int getsum(int a, int b) {     int oor, oand;     cout <<  and   << a <<     << b << endl;     cin >> oand;     cout <<  or   << a <<     << b << endl;     cin >> oor;     return oor + oand;   }   int main() {     int n, k;     cin >> n >> k;     int cr;     int x, y, z;     x = getsum(1, 2);     y = getsum(1, 3);     z = getsum(2, 3);     int a[n + 1];     a[3] = (y + z - x) / 2;     a[2] = (-y + z + x) / 2;     a[1] = (y - z + x) / 2;     for (auto i = (4); i <= (n); ++i) {       int wh = getsum(1, i);       a[i] = wh - a[1];     }     sort(a + 1, a + n + 1);     cout <<  finish   << a[k] << endl;     cout << a[k] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   const int N = 2e5 + 100;   int tr_min[4 * N][1 << 5];   int tr_max[4 * N][1 << 5];   vector<int> cara[N];   int n, k;   void build(int node, int b, int e) {     if (b == e) {       for (int cord = 0; cord < (1 << k); cord++) {         long long x = 0;         for (int i = 0; i < k; i++) {           if (cord & (1 << i))             x += cara[b][i];           else             x -= cara[b][i];         }         tr_max[node][cord] = tr_min[node][cord] = x;       }     } else {       int mid = (b + e) / 2;       build(2 * node, b, mid);       build(2 * node + 1, mid + 1, e);       for (int i = 0; i < (1 << k); i++) {         tr_max[node][i] = max(tr_max[2 * node][i], tr_max[2 * node + 1][i]);         tr_min[node][i] = min(tr_min[2 * node][i], tr_min[2 * node + 1][i]);       }     }   }   void update(int node, int b, int e, int i, vector<int> &cara) {     if (e < i or b > i) return;     if (b == e and b == i) {       for (int cord = 0; cord < (1 << k); cord++) {         long long x = 0;         for (int i = 0; i < k; i++) {           if (cord & (1 << i))             x += cara[i];           else             x -= cara[i];         }         tr_max[node][cord] = tr_min[node][cord] = x;       }       return;     }     int mid = (b + e) / 2;     update(2 * node, b, mid, i, cara);     update(2 * node + 1, mid + 1, e, i, cara);     for (int i = 0; i < (1 << k); i++) {       tr_max[node][i] = max(tr_max[2 * node][i], tr_max[2 * node + 1][i]);       tr_min[node][i] = min(tr_min[2 * node][i], tr_min[2 * node + 1][i]);     }   }   int query(int node, int b, int e, int i, int j, int cord) {     if (e < i or b > j) return -INF;     if (i <= b and j >= e) {       return tr_max[node][cord];     }     int mid = (b + e) / 2;     return max(query(2 * node, b, mid, i, j, cord),                query(2 * node + 1, mid + 1, e, i, j, cord));   }   int query2(int node, int b, int e, int i, int j, int cord) {     if (e < i or b > j) return INF;     if (i <= b and j >= e) {       return tr_min[node][cord];     }     int mid = (b + e) / 2;     return min(query2(2 * node, b, mid, i, j, cord),                query2(2 * node + 1, mid + 1, e, i, j, cord));   }   int proc(int cord, int l, int r) {     int maxi = query(1, 1, n, l, r, cord);     int mini = query2(1, 1, n, l, r, cord);     return abs(mini - maxi);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       for (int j = 0; j < k; j++) {         int x;         scanf( %d , &x);         cara[i].push_back(x);       }     }     int q;     build(1, 1, n);     scanf( %d , &q);     while (q--) {       int op;       scanf( %d , &op);       if (op == 1) {         int idx;         scanf( %d , &idx);         vector<int> val;         for (int j = 0; j < k; j++) {           int x;           scanf( %d , &x);           val.push_back(x);         }         update(1, 1, n, idx, val);       } else {         int l, r;         scanf( %d %d , &l, &r);         int resp = 0;         for (int i = 0; i < (1 << k); i++) resp = max(proc(i, l, r), resp);         printf( %d n , resp);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   bool operator<(pair<int, int> lhs, pair<int, int> rhs) {     return (lhs.first != rhs.first) ? (lhs.first < rhs.first)                                     : (lhs.second < rhs.second);   }   set<pair<int, int> > inqUp, inqDown, pendUp, pendDown;   int N, M, prsis, rci;   long long T, Ans[MAXN];   struct User {     int id, ar, f, t;   };   bool cmp_Useraraz(User lhs, User rhs) { return lhs.ar < rhs.ar; }   User u[MAXN], ru[MAXN];   int Where;   void Unload() {     while ((inqUp.size()) && (inqUp.begin()->first == Where)) {       Ans[inqUp.begin()->second] = T;       inqUp.erase(inqUp.begin());       rci++;     }     while (((inqDown.size()) && (--inqDown.end())->first == Where)) {       Ans[(--inqDown.end())->second] = T;       inqDown.erase(--inqDown.end());       rci++;     }   }   void Request() {     while ((prsis != N) && (u[prsis + 1].ar == T)) {       prsis++;       if (u[prsis].f >= Where)         pendUp.insert(make_pair(u[prsis].f, u[prsis].id));       else         pendDown.insert(make_pair(u[prsis].f, u[prsis].id));     }   }   void Load(int id) {     if (ru[id].t >= Where)       inqUp.insert(make_pair(ru[id].t, id));     else       inqDown.insert(make_pair(ru[id].t, id));   }   void Load() {     while ((pendUp.size()) && (pendUp.begin()->first == Where)) {       Load(pendUp.begin()->second);       pendUp.erase(pendUp.begin());     }     while ((pendDown.size()) && ((--pendDown.end())->first == Where)) {       Load((--pendDown.end())->second);       pendDown.erase(--pendDown.end());     }   }   int main() {     scanf( %d%d , &N, &M);     int i;     for (i = 1; i <= N; i++) {       scanf( %d%d%d , &u[i].ar, &u[i].f, &u[i].t);       u[i].id = i;       ru[i] = u[i];     }     sort(u + 1, u + N + 1, cmp_Useraraz);     inqUp.clear();     inqDown.clear();     pendUp.clear();     pendDown.clear();     Where = 1;     T = 0;     prsis = rci = 0;     while (rci < N) {       Unload();       Request();       Load();       int pUp = inqUp.size() + pendUp.size();       int pDown = inqDown.size() + pendDown.size();       int Action = (pUp + pDown) ? ((pUp >= pDown) ? 1 : -1) : 0;       int timePass = (prsis == N) ? M : (u[prsis + 1].ar - T);       if (Action == 1) {         if (pendUp.size())           timePass = min(timePass, pendUp.begin()->first - Where);         if (inqUp.size()) timePass = min(timePass, inqUp.begin()->first - Where);       }       if (Action == -1) {         if (pendDown.size())           timePass = min(timePass, Where - (--pendDown.end())->first);         if (inqDown.size())           timePass = min(timePass, Where - (--inqDown.end())->first);       }       T += timePass;       Where += timePass * Action;     }     for (i = 1; i <= N; i++) printf( %I64d n , Ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   map<char, char> mp;   string check(string s) {     for (int i = 0; i <= s.size() / 2; i++)       if (s[i] != mp[s[s.size() - 1 - i]]) return  NIE ;     return  TAK ;   }   int main() {     mp[ A ] =  A ;     mp[ b ] =  d ;     mp[ d ] =  b ;     mp[ H ] =  H ;     mp[ I ] =  I ;     mp[ M ] =  M ;     mp[ O ] =  O ;     mp[ o ] =  o ;     mp[ p ] =  q ;     mp[ q ] =  p ;     mp[ T ] =  T ;     mp[ U ] =  U ;     mp[ V ] =  V ;     mp[ v ] =  v ;     mp[ W ] =  W ;     mp[ w ] =  w ;     mp[ X ] =  X ;     mp[ x ] =  x ;     mp[ Y ] =  Y ;     string s;     cin >> s;     cout << check(s) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000;   const long long mod = 1e9 + 7;   long long fac[maxn + 5], inv[maxn + 5];   long long f[2005];   struct node {     long long x, y;   } data[2005];   long long qmod(long long a, long long b) {     long long ans = 1;     a = a % mod;     while (b) {       if (b & 1) {         ans = (ans * a) % mod;       }       b = b / 2;       a = (a * a) % mod;     }     return ans;   }   void init() {     fac[0] = 1;     for (long long i = 1; i <= maxn; i++) {       fac[i] = (fac[i - 1] * i) % mod;     }   }   long long com(long long n, long long m) {     if (n < m)       return 0;     else if (n == m)       return 1;     else       return (fac[n] * qmod(fac[m] * fac[n - m], mod - 2)) % mod;   }   long long Lucas(long long n, long long m) {     if (m == 0)       return 1;     else       return (com(n % mod, m % mod) * Lucas(n / mod, m / mod)) % mod;   }   bool cmp(node a, node b) {     if (a.x < b.x)       return true;     else if (a.x == b.x) {       if (a.y < b.y)         return true;       else         return false;     } else       return false;   }   int main(int argc, char const *argv[]) {     long long h, w, n;     init();     scanf( %lld %lld %lld , &h, &w, &n);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &data[i].x, &data[i].y);     }     sort(data + 1, data + 1 + n, cmp);     memset(f, 0, sizeof(f));     n++;     data[n].x = h;     data[n].y = w;     for (int i = 1; i <= n; i++) {       long long dx, dy;       dx = data[i].x - 1;       dy = data[i].y - 1;       f[i] = Lucas(dx + dy, dx);       for (int j = 1; j < i; j++) {         if (data[i].x >= data[j].x && data[i].y >= data[j].y) {           dx = data[i].x - data[j].x;           dy = data[i].y - data[j].y;           f[i] = f[i] - (f[j] * Lucas(dx + dy, dx)) % mod;           f[i] = (f[i] + mod) % mod;         }       }     }     cout << (f[n] + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x[100], s[100];   struct par {     int v, id;     bool operator<(const par &r) const { return v < r.v; }   };   vector<par> v;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       v.push_back({x[i], i});     }     sort(v.begin(), v.end());     vector<par> v1 = v;     rotate(v1.begin(), v1.begin() + 1, v1.end());     for (int i = 0; i < (int)v.size(); i++) s[v[i].id] = v1[i].v;     for (int i = 0; i < n; i++) {       printf( %d , s[i]);       i == n - 1 ? printf(  n ) : printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 3e5 + 7;   unordered_map<int, vector<int>> values[2];   int t, n, q, a[oo], p[oo];   vector<int> ans;   int psum(int l, int r) { return p[r] - (l ? p[l - 1] : 0); }   int first(vector<int>& list, int val) {     int l = 0, r = list.size();     while (l < r) {       int s = (l + r) / 2;       if (list[s] >= val)         r = s;       else         l = s + 1;     }     if (l == list.size()) return n * 2;     return list[l];   }   void problem(int l, int r) {     int sum = psum(l, r);     if (sum == 0) return;     if (sum % 2 == 0) {       ans.push_back(r);       problem(l, r - 1);       return;     }     int pl = p[l] - a[l];     int vals[2] = {pl + (sum + 1) / 2 - 1, pl + (sum - 1) / 2 + 1};     for (int i = 0; i < 2; i++) {       int pans = first(values[i][vals[i]], l);       if (pans <= r) {         ans.push_back(pans);         return;       }     }     throw 69;   }   void solve() {     cin >> n >> q;     string ss;     cin >> ss;     for (int i = 0; i < n; i++)       a[i] = (ss[i] ==  +  ? 1 : -1) * (i % 2 == 0 ? -1 : 1);     p[0] = a[0];     for (int i = 1; i < n; i++) p[i] = p[i - 1] + a[i];     for (int i = 0; i < n; i++) values[(a[i] + 1) / 2][p[i]].push_back(i);     while (q--) {       int l, r;       cin >> l >> r;       l--, r--;       problem(l, r);       cout << ans.size() << endl;       for (int e : ans) cout << e + 1 <<    ;       cout << endl;       ans.clear();     }     values[0].clear();     values[1].clear();   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int a[1050], b[1050];   int main() {     int n, m, s = 0, d = 0;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     for (int i = 1; i <= n; i++) {       sort(a, a + m);       for (int j = 0; j < m; j++) {         if (a[j] > 0) {           s += a[j];           a[j]--;           break;         }       }     }     for (int i = 1; i <= n; i++) {       sort(b, b + m);       for (int j = m - 1; j >= 0; j--) {         if (b[j] > 0) {           d += b[j];           b[j]--;           break;         }       }     }     cout << d <<     << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mx(long long a, long long b) { return a >= b ? a : b; }   long long mn(long long a, long long b) { return a <= b ? a : b; }   string a[3] = {( twone ), ( two ), ( one )};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, x;     cin >> t;     while (t--) {       string str, str2;       long long ans = 0;       vector<long long> v;       cin >> str;       if (str.size() <= 2) {         cout << 0 <<   n               <<   n ;         continue;       }       for (long long i = 0; i < str.size() - 2; i++) {         if (str[i] ==  t  and str[i + 1] ==  w  and str[i + 2] ==  o  and             str[i + 3] ==  n  and str[i + 4] ==  e )           str[i + 2] =  l , ans++, v.push_back(i + 3);         if (str[i] ==  t  and str[i + 1] ==  w  and str[i + 2] ==  o )           ans++, str[i + 1] =  l , v.push_back(i + 2);         if (str[i] ==  o  and str[i + 1] ==  n  and str[i + 2] ==  e )           ans++, str[i + 1] =  l , v.push_back(i + 2);       }       cout << ans <<   n ;       for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     int max = 0;     vector<int> b;     int x;     for (int i = 0; i < a; i++) {       cin >> x;       b.push_back(x);     }     sort(b.begin() + 1, b.end());     int count = 0;     if (b[0] > b[b.size() - 1]) {       cout <<  0 ;     } else {       while (1) {         b[b.size() - 1]--;         count++;         b[0] = b[0] + 1;         sort(b.begin() + 1, b.end());         if (b[0] > b[b.size() - 1]) {           cout << count;           break;         }       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vet[1010], dp[2][1010];   const int mod = 998244353;   long long soma(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> vet[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         dp[1][j] = dp[0][j];       }       if (vet[i] < n and vet[i] > 0) {         dp[1][vet[i]] = soma(soma(dp[0][0], 1), dp[1][vet[i]]);       }       for (int k = 0; k < n; k++) {         dp[1][k] = soma(dp[1][k], dp[0][k + 1]);       }       swap(dp[0], dp[1]);     }     cout << dp[0][0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class node>   struct link_cut_tree {     bool connected(node* u, node* v) { return lca(u, v) != NULL; }     int depth(node* u) {       access(u);       return get_sz(u->ch[0]);     }     node* get_root(node* u) {       access(u);       while (u->ch[0]) u = u->ch[0], u->push();       return access(u), u;     }     node* ancestor(node* u, int k) {       k = depth(u) - k;       for (;; u->push()) {         int sz = get_sz(u->ch[0]);         if (sz == k) return access(u), u;         if (sz < k)           k -= sz + 1, u = u->ch[1];         else           u = u->ch[0];       }     }     node* lca(node* u, node* v) {       if (u == v) return u;       access(u);       access(v);       if (!u->p) return NULL;       u->splay();       return u->p ?: u;     }     void link(node* u, node* v) {       make_root(v);       access(u);       set_link(v, u, 0);       v->update();     }     void cut(node* u) {       access(u);       u->ch[0]->p = NULL;       u->ch[0] = NULL;       u->update();     }     void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); }     void make_root(node* u) {       access(u);       u->rev ^= 1;       access(u);     }     void access(node* u) {       for (node *v = u, *pre = NULL; v; v = v->p) {         v->splay();         if (pre) v->update_vsub(pre, false);         if (v->ch[1]) v->update_vsub(v->ch[1], true);         v->ch[1] = pre;         v->update();         pre = v;       }       u->splay();     }     node* operator[](int i) { return &data[i]; }     int operator[](node* i) { return i - &data[0]; }     vector<node> data;     link_cut_tree(int n) : data(n) {}   };   template <typename pnode>   struct splay_tree {     pnode ch[2], p;     bool rev;     int sz;     splay_tree() {       ch[0] = ch[1] = p = NULL;       rev = 0;       sz = 1;     }     friend int get_sz(pnode u) { return u ? u->sz : 0; }     virtual void update() {       if (ch[0]) ch[0]->push();       if (ch[1]) ch[1]->push();       sz = 1 + get_sz(ch[0]) + get_sz(ch[1]);     }     virtual void push() {       if (rev) {         if (ch[0]) ch[0]->rev ^= 1;         if (ch[1]) ch[1]->rev ^= 1;         swap(ch[0], ch[1]);         rev = 0;       }     }     int dir() {       if (!p) return -2;       if (p->ch[0] == this) return 0;       if (p->ch[1] == this) return 1;       return -1;     }     bool is_root() { return dir() < 0; }     friend void set_link(pnode u, pnode v, int d) {       if (v) v->p = u;       if (d >= 0) u->ch[d] = v;     }     void rotate() {       int x = dir();       pnode g = p;       set_link(g->p, static_cast<pnode>(this), g->dir());       set_link(g, ch[x ^ 1], x);       set_link(static_cast<pnode>(this), g, x ^ 1);       g->update();       update();     }     void splay() {       while (!is_root() && !p->is_root()) {         p->p->push(), p->push(), push();         dir() == p->dir() ? p->rotate() : rotate();         rotate();       }       if (!is_root()) p->push(), push(), rotate();       push();     }   };   struct node;   node* root;   bool capture;   vector<pair<int, int>> vec;   struct node : splay_tree<node*> {     using splay_tree::ch;     int val, lazy;     node() : splay_tree() {       val = -1e9;       lazy = -1;     }     void update() override { splay_tree::update(); }     void update_vsub(node* v, bool add) {       if (!add && capture) vec.push_back({this - root, val});     }     void push() override {       splay_tree::push();       if (lazy != -1) {         val = lazy;         if (ch[0]) ch[0]->lazy = lazy;         if (ch[1]) ch[1]->lazy = lazy;         lazy = -1;       }     }   };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<pair<int, int>>> adj(n);     for (int i = 1, u, v, w; i < n; ++i) {       cin >> u >> v >> w;       --u, --v;       adj[u].push_back({v, w});     }     vector<long long> dist(n);     vec.reserve(n);     link_cut_tree<node> lct(n);     function<void(int)> dfs_access = [&](int u) {       for (auto v : adj[u]) {         dist[v.first] = dist[u] + v.second;         lct.link(lct[u], lct[v.first]);         dfs_access(v.first);       }     };     dfs_access(0);     root = lct[0];     vector<pair<long long, long long>> s;     for (int i = 0, d, t; i < m; ++i) {       cin >> d >> t;       --d;       auto u = lct[d], v = u;       while (!v->is_root()) v = v->p, v->push();       while (v->ch[1]) v = v->ch[1], v->push();       vec.clear();       capture = true;       lct.access(u);       capture = false;       for (auto x : vec)         s.push_back({dist[x.first] + x.second, dist[x.first] + t});       int val = u->val;       u->lazy = t;       u->push();       u->val = val;       lct.access(v);     }     long long explosion = -1, changes = s.size();     sort(s.begin(), s.end());     priority_queue<long long, vector<long long>, greater<long long>> pq;     for (long long t = 1, i = 0; i < s.size() || !pq.empty();) {       if (pq.empty() && t <= s[i].first) t = s[i].first + 1;       while (i < s.size() && s[i].first < t) pq.push(s[i].second), ++i;       if (t > pq.top()) {         explosion = t - 1;         break;       }       pq.pop();       ++t;     }     if (explosion != -1)       changes -= count_if(s.begin(), s.end(), [&](pair<long long, long long> x) {         return x.second >= explosion;       });     cout << explosion <<     << changes <<   n ;     return 0;   }